librashader-runtime-d3d9 0.10.1

RetroArch shaders for all.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
use std::ffi::c_void;
use windows::core::{Param, HRESULT, PCSTR};
use windows::Win32::Graphics::Direct3D::{ID3DBlob, ID3DInclude, D3D_SHADER_MACRO};

const D3DERR_INVALIDCALL: u32 = 0x8876086c;

type BOOL = i32;

#[allow(dead_code)]
pub mod raw {
    use super::*;

    #[link(name = "D3DX9_43", kind = "raw-dylib")]
    extern "system" {
        pub fn D3DXGetShaderVersion(p_function: *const c_void) -> u32;
        pub fn D3DXGetShaderSize(p_function: *const c_void) -> u32;
        pub fn D3DXGetShaderConstantTable(
            p_function: *const c_void,
            ppconstanttable: *mut *mut c_void,
        ) -> windows::core::HRESULT;

        pub(super) fn D3DXCompileShader(
            psrcdata: *const c_void,
            srcdatasize: usize,
            pdefines: *const D3D_SHADER_MACRO,
            pinclude: *mut c_void,
            pfunctionname: PCSTR,
            pprofile: PCSTR,
            flags: u32,
            ppcode: *mut *mut c_void,
            pperrormsgs: *mut *mut c_void,
            ppconstantable: *mut *mut c_void,
        ) -> windows::core::HRESULT;
    }
}

#[allow(dead_code)]
#[allow(non_snake_case)]
#[inline]
pub unsafe fn D3DXCompileShader<P1, P2, P3>(
    psrcdata: *const c_void,
    srcdatasize: usize,
    pdefines: Option<*const D3D_SHADER_MACRO>,
    pinclude: P1,
    pfunctioname: P2,
    pprofile: P3,
    flags: u32,
    ppcode: *mut Option<ID3DBlob>,
    pperrormsgs: Option<*mut Option<ID3DBlob>>,
    ppconstanttable: Option<*mut Option<ID3DXConstantTable>>,
) -> ::windows::core::Result<()>
where
    P1: Param<ID3DInclude>,
    P2: Param<PCSTR>,
    P3: Param<PCSTR>,
{
    raw::D3DXCompileShader(
        psrcdata,
        srcdatasize,
        ::core::mem::transmute(pdefines.unwrap_or(::std::ptr::null())),
        pinclude.param().abi(),
        pfunctioname.param().abi(),
        pprofile.param().abi(),
        flags,
        ::core::mem::transmute(ppcode),
        ::core::mem::transmute(pperrormsgs.unwrap_or(::std::ptr::null_mut())),
        ::core::mem::transmute(ppconstanttable.unwrap_or(::std::ptr::null_mut())),
    )
    .ok()
}

windows::core::imp::define_interface!(
    ID3DXConstantTable,
    ID3DXConstantTable_Vtbl,
    0xab3c758f_93e_4356_b7_62_4d_b1_8f_1b_3a1
);

#[allow(dead_code)]
impl ID3DXConstantTable {
    #[allow(non_snake_case)]
    pub unsafe fn GetShaderConstantTable(
        p_function: *const c_void,
    ) -> windows::core::Result<ID3DXConstantTable> {
        let mut result__ = ::std::mem::zeroed();
        raw::D3DXGetShaderConstantTable(p_function, &mut result__)
            .and_then(|| windows::core::Type::from_abi(result__))
    }

    #[allow(non_snake_case)]
    pub unsafe fn GetBufferPointer(&self) -> *mut c_void {
        (windows::core::Interface::vtable(self).GetBufferPointer)(windows::core::Interface::as_raw(
            self,
        ))
    }

    #[allow(non_snake_case)]
    pub unsafe fn GetBufferSize(&self) -> usize {
        (windows::core::Interface::vtable(self).GetBufferSize)(windows::core::Interface::as_raw(
            self,
        ))
    }

    #[allow(non_snake_case)]
    pub unsafe fn GetDesc(&self) -> windows::core::Result<D3DXCONSTANTTABLE_DESC> {
        let mut result__ = ::std::mem::MaybeUninit::<D3DXCONSTANTTABLE_DESC>::zeroed();
        (windows::core::Interface::vtable(self).GetDesc)(
            windows::core::Interface::as_raw(self),
            result__.as_mut_ptr(),
        )
        .ok()?;

        Ok(result__.assume_init())
    }

    #[allow(non_snake_case)]
    pub unsafe fn GetConstant(
        &self,
        hconstant: Option<D3DXHANDLE>,
        index: u32,
    ) -> windows::core::Result<D3DXHANDLE> {
        let handle = (windows::core::Interface::vtable(self).GetConstant)(
            windows::core::Interface::as_raw(self),
            hconstant.unwrap_or(D3DXHANDLE(std::ptr::null())),
            index,
        );

        if handle.0 as u32 == D3DERR_INVALIDCALL {
            return Err(HRESULT(D3DERR_INVALIDCALL as i32).into());
        }

        Ok(handle)
    }

    #[allow(non_snake_case)]
    pub unsafe fn GetConstantDesc(
        &self,
        handle: D3DXHANDLE,
        pdesc: *mut D3DXCONSTANT_DESC,
        pcount: *mut u32,
    ) -> windows::core::Result<()> {
        (windows::core::Interface::vtable(self).GetConstantDesc)(
            windows::core::Interface::as_raw(self),
            handle,
            pdesc,
            pcount,
        )
        .ok()
    }

    #[allow(non_snake_case)]
    pub unsafe fn GetConstantByName<P>(
        &self,
        hconstant: Option<D3DXHANDLE>,
        pname: P,
    ) -> windows::core::Result<D3DXHANDLE>
    where
        P: Param<PCSTR>,
    {
        let handle = (windows::core::Interface::vtable(self).GetConstantByName)(
            windows::core::Interface::as_raw(self),
            hconstant.unwrap_or(D3DXHANDLE(std::ptr::null())),
            pname.param().abi(),
        );

        if handle.0 as u32 == D3DERR_INVALIDCALL {
            return Err(HRESULT(D3DERR_INVALIDCALL as i32).into());
        }

        Ok(handle)
    }

    #[allow(non_snake_case)]
    pub unsafe fn GetConstantElement(
        &self,
        hconstant: D3DXHANDLE,
        index: u32,
    ) -> windows::core::Result<D3DXHANDLE> {
        let handle = (windows::core::Interface::vtable(self).GetConstantElement)(
            windows::core::Interface::as_raw(self),
            hconstant,
            index,
        );

        if handle.0 as u32 == D3DERR_INVALIDCALL {
            return Err(HRESULT(D3DERR_INVALIDCALL as i32).into());
        }

        Ok(handle)
    }

    #[allow(non_snake_case)]
    pub unsafe fn GetSamplerIndex(&self, hconstant: Option<D3DXHANDLE>) -> u32 {
        (windows::core::Interface::vtable(self).GetSamplerIndex)(
            windows::core::Interface::as_raw(self),
            hconstant.unwrap_or(D3DXHANDLE(std::ptr::null())),
        )
    }
}

#[repr(C)]
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
pub struct ID3DXConstantTable_Vtbl {
    pub base__: windows::core::IUnknown_Vtbl,
    #[allow(non_snake_case)]
    pub GetBufferPointer: unsafe extern "system" fn(this: *mut c_void) -> *mut c_void,
    #[allow(non_snake_case)]
    pub GetBufferSize: unsafe extern "system" fn(this: *mut c_void) -> usize,
    #[allow(non_snake_case)]
    pub GetDesc: unsafe extern "system" fn(
        this: *mut c_void,
        pdesc: *mut D3DXCONSTANTTABLE_DESC,
    ) -> windows::core::HRESULT,
    #[allow(non_snake_case)]
    pub GetConstantDesc: unsafe extern "system" fn(
        this: *mut c_void,
        hconstant: D3DXHANDLE,
        pdesc: *mut D3DXCONSTANT_DESC,
        pcount: *mut u32,
    ) -> windows::core::HRESULT,
    #[allow(non_snake_case)]
    pub GetSamplerIndex: unsafe extern "system" fn(this: *mut c_void, hconstant: D3DXHANDLE) -> u32,
    #[allow(non_snake_case)]
    pub GetConstant: unsafe extern "system" fn(
        this: *mut c_void,
        hconstant: D3DXHANDLE,
        index: u32,
    ) -> D3DXHANDLE,
    #[allow(non_snake_case)]
    pub GetConstantByName: unsafe extern "system" fn(
        this: *mut c_void,
        hconstant: D3DXHANDLE,
        pname: PCSTR,
    ) -> D3DXHANDLE,
    #[allow(non_snake_case)]
    pub GetConstantElement: unsafe extern "system" fn(
        this: *mut c_void,
        hconstant: D3DXHANDLE,
        index: u32,
    ) -> D3DXHANDLE,
    #[allow(non_snake_case)]
    pub SetDefaults: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
    ) -> windows::core::HRESULT,
    #[allow(non_snake_case)]
    pub SetValue: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        hconstant: D3DXHANDLE,
        pdata: *mut c_void,
        bytes: u32,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetBool:
        unsafe extern "system" fn(this: *mut c_void, pdevice: *mut c_void, b: BOOL) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetBoolArray: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        b: *const BOOL,
        count: u32,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetInt:
        unsafe extern "system" fn(this: *mut c_void, pdevice: *mut c_void, n: i32) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetIntArray: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        n: *const i32,
        count: u32,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetFloat: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        f: f32,
    ) -> windows::core::HRESULT,
    #[allow(non_snake_case)]
    pub SetFloatArray: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        b: *const f32,
        count: u32,
    ) -> windows::core::HRESULT,
    #[allow(non_snake_case)]
    pub SetVector: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        pvector: *const ::windows_numerics::Vector4,
    ) -> windows::core::HRESULT,
    #[allow(non_snake_case)]
    pub SetVectorArray: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        pvector: *const ::windows_numerics::Vector4,
        count: u32,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetMatrix: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        pmatrix: *const ::windows_numerics::Matrix4x4,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetMatrixArray: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        pmatrix: *const ::windows_numerics::Matrix4x4,
        count: u32,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetMatrixPointerArray: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        ppmatrix: *const *const ::windows_numerics::Matrix4x4,
        count: u32,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetMatrixTranspose: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        pmatrix: *const ::windows_numerics::Matrix4x4,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetMatrixTransposeArray: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        pmatrix: *const ::windows_numerics::Matrix4x4,
        count: u32,
    ) -> HRESULT,
    #[allow(non_snake_case)]
    pub SetMatrixTransposePointerArray: unsafe extern "system" fn(
        this: *mut c_void,
        pdevice: *mut c_void,
        ppmatrix: *const *const ::windows_numerics::Matrix4x4,
        count: u32,
    ) -> HRESULT,
}

#[repr(C)]
#[derive(Clone, Debug)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
pub struct D3DXCONSTANTTABLE_DESC {
    pub Creator: PCSTR,
    pub Version: u32,
    pub Constants: u32,
}

#[repr(C)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
#[derive(Debug)]
pub struct D3DXCONSTANT_DESC {
    pub Name: PCSTR,
    pub RegisterSet: D3DXREGISTER_SET,
    pub RegisterIndex: u32,
    pub RegisterCount: u32,
    pub Class: D3DXPARAMETER_CLASS,
    pub Type: D3DXPARAMETER_TYPE,
    pub Rows: u32,
    pub Columns: u32,
    pub Elements: u32,
    pub StructMembers: u32,
    pub Bytes: u32,
    pub DefaultValue: *const c_void,
}

#[repr(u32)]
#[derive(PartialEq, Eq, Debug)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
#[allow(dead_code)]
pub enum D3DXREGISTER_SET {
    D3DXRS_BOOL = 0,
    D3DXRS_INT4 = 1,
    D3DXRS_FLOAT4 = 2,
    D3DXRS_SAMPLER = 3,
    D3DXRS_FORCE_DWORD = 0x7fffffff,
}

#[repr(u32)]
#[derive(PartialEq, Eq, Debug)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
#[allow(dead_code)]
pub enum D3DXPARAMETER_CLASS {
    D3DXPC_SCALAR = 0,
    D3DXPC_VECTOR = 1,
    D3DXPC_MATRIX_ROWS = 2,
    D3DXPC_MATRIX_COLUMNS = 3,
    D3DXPC_OBJECT = 4,
    D3DXPC_STRUCT = 5,
    D3DXPC_FORCE_DWORD = 0x7fffffff,
}

#[repr(u32)]
#[derive(Debug)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
#[allow(dead_code)]
pub enum D3DXPARAMETER_TYPE {
    D3DXPT_VOID = 0,
    D3DXPT_BOOL = 1,
    D3DXPT_INT = 2,
    D3DXPT_FLOAT = 3,
    D3DXPT_STRING = 4,
    D3DXPT_TEXTURE = 5,
    D3DXPT_TEXTURE1D = 6,
    D3DXPT_TEXTURE2D = 7,
    D3DXPT_TEXTURE3D = 8,
    D3DXPT_TEXTURECUBE = 9,
    D3DXPT_SAMPLER = 10,
    D3DXPT_SAMPLER1D = 11,
    D3DXPT_SAMPLER2D = 12,
    D3DXPT_SAMPLER3D = 13,
    D3DXPT_SAMPLERCUBE = 14,
    D3DXPT_PIXELSHADER = 15,
    D3DXPT_VERTEXSHADER = 16,
    D3DXPT_PIXELFRAGMENT = 17,
    D3DXPT_VERTEXFRAGMENT = 18,
    D3DXPT_UNSUPPORTED = 19,
    D3DXPT_FORCE_DWORD = 0x7fffffff,
}

#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct D3DXHANDLE(pub *const c_void);