2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 * Copyright 2010 Rico Schüller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "d3dcompiler_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler
);
27 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE
29 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
= 6,
30 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
= 7,
33 #define D3DCOMPILER_SHADER_TARGET_VERSION_MASK 0xffff
34 #define D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK 0xffff0000
36 struct d3dcompiler_shader_signature
38 D3D11_SIGNATURE_PARAMETER_DESC
*elements
;
43 struct d3dcompiler_shader_reflection_type
45 ID3D11ShaderReflectionType ID3D11ShaderReflectionType_iface
;
46 ID3D10ShaderReflectionType ID3D10ShaderReflectionType_iface
;
49 struct wine_rb_entry entry
;
51 struct d3dcompiler_shader_reflection
*reflection
;
53 D3D11_SHADER_TYPE_DESC desc
;
54 struct d3dcompiler_shader_reflection_type_member
*members
;
58 struct d3dcompiler_shader_reflection_type_member
62 struct d3dcompiler_shader_reflection_type
*type
;
65 struct d3dcompiler_shader_reflection_variable
67 ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable_iface
;
68 ID3D10ShaderReflectionVariable ID3D10ShaderReflectionVariable_iface
;
70 struct d3dcompiler_shader_reflection_constant_buffer
*constant_buffer
;
71 struct d3dcompiler_shader_reflection_type
*type
;
80 struct d3dcompiler_shader_reflection_constant_buffer
82 ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer_iface
;
83 ID3D10ShaderReflectionConstantBuffer ID3D10ShaderReflectionConstantBuffer_iface
;
85 struct d3dcompiler_shader_reflection
*reflection
;
88 D3D_CBUFFER_TYPE type
;
93 struct d3dcompiler_shader_reflection_variable
*variables
;
96 enum D3DCOMPILER_REFLECTION_VERSION
98 D3DCOMPILER_REFLECTION_VERSION_D3D10
,
99 D3DCOMPILER_REFLECTION_VERSION_D3D11
,
100 D3DCOMPILER_REFLECTION_VERSION_D3D12
,
103 /* ID3D11ShaderReflection */
104 struct d3dcompiler_shader_reflection
106 ID3D11ShaderReflection ID3D11ShaderReflection_iface
;
107 ID3D10ShaderReflection ID3D10ShaderReflection_iface
;
110 enum D3DCOMPILER_REFLECTION_VERSION interface_version
;
116 UINT bound_resource_count
;
117 UINT constant_buffer_count
;
119 UINT mov_instruction_count
;
120 UINT conversion_instruction_count
;
121 UINT instruction_count
;
122 UINT emit_instruction_count
;
123 D3D_PRIMITIVE_TOPOLOGY gs_output_topology
;
124 UINT gs_max_output_vertex_count
;
125 D3D_PRIMITIVE input_primitive
;
126 UINT cut_instruction_count
;
129 UINT static_flow_control_count
;
130 UINT float_instruction_count
;
131 UINT temp_register_count
;
132 UINT int_instruction_count
;
133 UINT uint_instruction_count
;
134 UINT temp_array_count
;
135 UINT array_instruction_count
;
136 UINT texture_normal_instructions
;
137 UINT texture_load_instructions
;
138 UINT texture_comp_instructions
;
139 UINT texture_bias_instructions
;
140 UINT texture_gradient_instructions
;
141 UINT dynamic_flow_control_count
;
142 UINT macro_instruction_count
;
143 UINT c_control_points
;
144 D3D_TESSELLATOR_OUTPUT_PRIMITIVE hs_output_primitive
;
145 D3D_TESSELLATOR_PARTITIONING hs_partitioning
;
146 D3D_TESSELLATOR_DOMAIN tessellator_domain
;
148 struct d3dcompiler_shader_signature
*isgn
;
149 struct d3dcompiler_shader_signature
*osgn
;
150 struct d3dcompiler_shader_signature
*pcsg
;
151 char *resource_string
;
152 D3D12_SHADER_INPUT_BIND_DESC
*bound_resources
;
153 struct d3dcompiler_shader_reflection_constant_buffer
*constant_buffers
;
154 struct wine_rb_tree types
;
157 static struct d3dcompiler_shader_reflection_type
*get_reflection_type(struct d3dcompiler_shader_reflection
*reflection
, const char *data
, DWORD offset
);
159 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl
;
160 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl
;
161 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl
;
163 static const struct ID3D10ShaderReflectionConstantBufferVtbl d3d10_shader_reflection_constant_buffer_vtbl
;
164 static const struct ID3D10ShaderReflectionVariableVtbl d3d10_shader_reflection_variable_vtbl
;
165 static const struct ID3D10ShaderReflectionTypeVtbl d3d10_shader_reflection_type_vtbl
;
167 /* null objects - needed for invalid calls */
168 static struct d3dcompiler_shader_reflection_constant_buffer null_constant_buffer
=
170 {&d3dcompiler_shader_reflection_constant_buffer_vtbl
},
171 {&d3d10_shader_reflection_constant_buffer_vtbl
}
173 static struct d3dcompiler_shader_reflection_type null_type
=
175 {&d3dcompiler_shader_reflection_type_vtbl
},
176 {&d3d10_shader_reflection_type_vtbl
}
178 static struct d3dcompiler_shader_reflection_variable null_variable
=
180 {&d3dcompiler_shader_reflection_variable_vtbl
},
181 {&d3d10_shader_reflection_variable_vtbl
},
182 &null_constant_buffer
,
186 static BOOL
copy_name(const char *ptr
, char **name
)
190 if (!ptr
) return TRUE
;
192 name_len
= strlen(ptr
) + 1;
198 *name
= HeapAlloc(GetProcessHeap(), 0, name_len
);
201 ERR("Failed to allocate name memory.\n");
205 memcpy(*name
, ptr
, name_len
);
210 static BOOL
copy_value(const char *ptr
, void **value
, DWORD size
)
212 if (!ptr
|| !size
) return TRUE
;
214 *value
= HeapAlloc(GetProcessHeap(), 0, size
);
217 ERR("Failed to allocate value memory.\n");
221 memcpy(*value
, ptr
, size
);
226 static int d3dcompiler_shader_reflection_type_compare(const void *key
, const struct wine_rb_entry
*entry
)
228 const struct d3dcompiler_shader_reflection_type
*t
= WINE_RB_ENTRY_VALUE(entry
, const struct d3dcompiler_shader_reflection_type
, entry
);
229 const DWORD
*id
= key
;
234 static void free_type_member(struct d3dcompiler_shader_reflection_type_member
*member
)
238 HeapFree(GetProcessHeap(), 0, member
->name
);
242 static void d3dcompiler_shader_reflection_type_destroy(struct wine_rb_entry
*entry
, void *context
)
244 struct d3dcompiler_shader_reflection_type
*t
= WINE_RB_ENTRY_VALUE(entry
, struct d3dcompiler_shader_reflection_type
, entry
);
247 TRACE("reflection type %p.\n", t
);
251 for (i
= 0; i
< t
->desc
.Members
; ++i
)
253 free_type_member(&t
->members
[i
]);
255 HeapFree(GetProcessHeap(), 0, t
->members
);
259 HeapFree(GetProcessHeap(), 0, t
);
262 static void free_signature(struct d3dcompiler_shader_signature
*sig
)
264 TRACE("Free signature %p\n", sig
);
266 HeapFree(GetProcessHeap(), 0, sig
->elements
);
267 HeapFree(GetProcessHeap(), 0, sig
->string_data
);
270 static void free_variable(struct d3dcompiler_shader_reflection_variable
*var
)
274 HeapFree(GetProcessHeap(), 0, var
->name
);
275 HeapFree(GetProcessHeap(), 0, var
->default_value
);
279 static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer
*cb
)
285 for (i
= 0; i
< cb
->variable_count
; ++i
)
287 free_variable(&cb
->variables
[i
]);
289 HeapFree(GetProcessHeap(), 0, cb
->variables
);
292 HeapFree(GetProcessHeap(), 0, cb
->name
);
295 static void reflection_cleanup(struct d3dcompiler_shader_reflection
*ref
)
297 TRACE("Cleanup %p\n", ref
);
301 free_signature(ref
->isgn
);
302 HeapFree(GetProcessHeap(), 0, ref
->isgn
);
307 free_signature(ref
->osgn
);
308 HeapFree(GetProcessHeap(), 0, ref
->osgn
);
313 free_signature(ref
->pcsg
);
314 HeapFree(GetProcessHeap(), 0, ref
->pcsg
);
317 if (ref
->constant_buffers
)
321 for (i
= 0; i
< ref
->constant_buffer_count
; ++i
)
323 free_constant_buffer(&ref
->constant_buffers
[i
]);
327 wine_rb_destroy(&ref
->types
, d3dcompiler_shader_reflection_type_destroy
, NULL
);
328 HeapFree(GetProcessHeap(), 0, ref
->constant_buffers
);
329 HeapFree(GetProcessHeap(), 0, ref
->bound_resources
);
330 HeapFree(GetProcessHeap(), 0, ref
->resource_string
);
331 HeapFree(GetProcessHeap(), 0, ref
->creator
);
334 /* IUnknown methods */
336 static inline struct d3dcompiler_shader_reflection
*impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection
*iface
)
338 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection
, ID3D11ShaderReflection_iface
);
341 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection
*iface
, REFIID riid
, void **object
)
343 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
345 if (IsEqualGUID(riid
, &IID_ID3D11ShaderReflection
)
346 || IsEqualGUID(riid
, &IID_IUnknown
)
347 || (D3D_COMPILER_VERSION
>= 47 && IsEqualGUID(riid
, &IID_ID3D12ShaderReflection
)))
349 IUnknown_AddRef(iface
);
354 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
357 return E_NOINTERFACE
;
360 static ULONG STDMETHODCALLTYPE
d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection
*iface
)
362 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
363 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
365 TRACE("%p increasing refcount to %u\n", This
, refcount
);
370 static ULONG STDMETHODCALLTYPE
d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection
*iface
)
372 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
373 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
375 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
379 reflection_cleanup(This
);
380 HeapFree(GetProcessHeap(), 0, This
);
386 /* ID3D11ShaderReflection methods */
388 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection
*iface
, D3D11_SHADER_DESC
*desc
)
390 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
392 FIXME("iface %p, desc %p partial stub!\n", iface
, desc
);
396 WARN("Invalid argument specified\n");
400 desc
->Version
= This
->version
;
401 desc
->Creator
= This
->creator
;
402 desc
->Flags
= This
->flags
;
403 desc
->ConstantBuffers
= This
->constant_buffer_count
;
404 desc
->BoundResources
= This
->bound_resource_count
;
405 desc
->InputParameters
= This
->isgn
? This
->isgn
->element_count
: 0;
406 desc
->OutputParameters
= This
->osgn
? This
->osgn
->element_count
: 0;
407 desc
->InstructionCount
= This
->instruction_count
;
408 desc
->TempRegisterCount
= This
->temp_register_count
;
409 desc
->TempArrayCount
= This
->temp_array_count
;
411 desc
->DclCount
= This
->dcl_count
;
412 desc
->TextureNormalInstructions
= This
->texture_normal_instructions
;
413 desc
->TextureLoadInstructions
= This
->texture_load_instructions
;
414 desc
->TextureCompInstructions
= This
->texture_comp_instructions
;
415 desc
->TextureBiasInstructions
= This
->texture_bias_instructions
;
416 desc
->TextureGradientInstructions
= This
->texture_gradient_instructions
;
417 desc
->FloatInstructionCount
= This
->float_instruction_count
;
418 desc
->IntInstructionCount
= This
->int_instruction_count
;
419 desc
->UintInstructionCount
= This
->uint_instruction_count
;
420 desc
->StaticFlowControlCount
= This
->static_flow_control_count
;
421 desc
->DynamicFlowControlCount
= This
->dynamic_flow_control_count
;
422 desc
->MacroInstructionCount
= 0;
423 desc
->ArrayInstructionCount
= This
->array_instruction_count
;
424 desc
->CutInstructionCount
= This
->cut_instruction_count
;
425 desc
->EmitInstructionCount
= This
->emit_instruction_count
;
426 desc
->GSOutputTopology
= This
->gs_output_topology
;
427 desc
->GSMaxOutputVertexCount
= This
->gs_max_output_vertex_count
;
428 desc
->InputPrimitive
= This
->input_primitive
;
429 desc
->PatchConstantParameters
= This
->pcsg
? This
->pcsg
->element_count
: 0;
430 desc
->cGSInstanceCount
= 0;
431 desc
->cControlPoints
= This
->c_control_points
;
432 desc
->HSOutputPrimitive
= This
->hs_output_primitive
;
433 desc
->HSPartitioning
= This
->hs_partitioning
;
434 desc
->TessellatorDomain
= This
->tessellator_domain
;
435 desc
->cBarrierInstructions
= 0;
436 desc
->cInterlockedInstructions
= 0;
437 desc
->cTextureStoreInstructions
= 0;
442 static struct ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConstantBufferByIndex(
443 ID3D11ShaderReflection
*iface
, UINT index
)
445 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
447 TRACE("iface %p, index %u\n", iface
, index
);
449 if (index
>= This
->constant_buffer_count
)
451 WARN("Invalid argument specified\n");
452 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
455 return &This
->constant_buffers
[index
].ID3D11ShaderReflectionConstantBuffer_iface
;
458 static struct ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConstantBufferByName(
459 ID3D11ShaderReflection
*iface
, const char *name
)
461 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
464 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
468 WARN("Invalid argument specified\n");
469 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
472 for (i
= 0; i
< This
->constant_buffer_count
; ++i
)
474 struct d3dcompiler_shader_reflection_constant_buffer
*d
= &This
->constant_buffers
[i
];
476 if (!strcmp(d
->name
, name
))
478 TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d
);
479 return &d
->ID3D11ShaderReflectionConstantBuffer_iface
;
483 WARN("Invalid name specified\n");
485 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
488 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetResourceBindingDesc(
489 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SHADER_INPUT_BIND_DESC
*desc
)
491 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D11ShaderReflection(iface
);
493 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
495 if (!desc
|| index
>= reflection
->bound_resource_count
)
497 WARN("Invalid argument specified\n");
501 memcpy(desc
, &reflection
->bound_resources
[index
],
502 reflection
->interface_version
== D3DCOMPILER_REFLECTION_VERSION_D3D12
503 ? sizeof(D3D12_SHADER_INPUT_BIND_DESC
) : sizeof(D3D11_SHADER_INPUT_BIND_DESC
));
508 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetInputParameterDesc(
509 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SIGNATURE_PARAMETER_DESC
*desc
)
511 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D11ShaderReflection(iface
);
513 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
515 if (!desc
|| !reflection
->isgn
|| index
>= reflection
->isgn
->element_count
)
517 WARN("Invalid argument specified\n");
521 *desc
= reflection
->isgn
->elements
[index
];
526 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetOutputParameterDesc(
527 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SIGNATURE_PARAMETER_DESC
*desc
)
529 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D11ShaderReflection(iface
);
531 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
533 if (!desc
|| !reflection
->osgn
|| index
>= reflection
->osgn
->element_count
)
535 WARN("Invalid argument specified\n");
539 *desc
= reflection
->osgn
->elements
[index
];
544 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
545 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SIGNATURE_PARAMETER_DESC
*desc
)
547 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D11ShaderReflection(iface
);
549 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
551 if (!desc
|| !reflection
->pcsg
|| index
>= reflection
->pcsg
->element_count
)
553 WARN("Invalid argument specified\n");
557 *desc
= reflection
->pcsg
->elements
[index
];
562 static struct ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetVariableByName(
563 ID3D11ShaderReflection
*iface
, const char *name
)
565 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
568 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
572 WARN("Invalid name specified\n");
573 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
576 for (i
= 0; i
< This
->constant_buffer_count
; ++i
)
578 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= &This
->constant_buffers
[i
];
580 for (k
= 0; k
< cb
->variable_count
; ++k
)
582 struct d3dcompiler_shader_reflection_variable
*v
= &cb
->variables
[k
];
584 if (!strcmp(v
->name
, name
))
586 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v
);
587 return &v
->ID3D11ShaderReflectionVariable_iface
;
592 WARN("Invalid name specified\n");
594 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
597 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetResourceBindingDescByName(
598 ID3D11ShaderReflection
*iface
, const char *name
, D3D11_SHADER_INPUT_BIND_DESC
*desc
)
600 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D11ShaderReflection(iface
);
603 TRACE("iface %p, name %s, desc %p\n", iface
, debugstr_a(name
), desc
);
607 WARN("Invalid argument specified\n");
611 for (i
= 0; i
< reflection
->bound_resource_count
; ++i
)
613 D3D12_SHADER_INPUT_BIND_DESC
*d
= &reflection
->bound_resources
[i
];
615 if (!strcmp(d
->Name
, name
))
617 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d
);
618 memcpy(desc
, d
, reflection
->interface_version
== D3DCOMPILER_REFLECTION_VERSION_D3D12
619 ? sizeof(D3D12_SHADER_INPUT_BIND_DESC
) : sizeof(D3D11_SHADER_INPUT_BIND_DESC
));
624 WARN("Invalid name specified\n");
629 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMovInstructionCount(
630 ID3D11ShaderReflection
*iface
)
632 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
634 TRACE("iface %p\n", iface
);
636 return This
->mov_instruction_count
;
639 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMovcInstructionCount(
640 ID3D11ShaderReflection
*iface
)
642 FIXME("iface %p stub!\n", iface
);
647 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConversionInstructionCount(
648 ID3D11ShaderReflection
*iface
)
650 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
652 TRACE("iface %p\n", iface
);
654 return This
->conversion_instruction_count
;
657 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
658 ID3D11ShaderReflection
*iface
)
660 FIXME("iface %p stub!\n", iface
);
665 static D3D_PRIMITIVE STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetGSInputPrimitive(
666 ID3D11ShaderReflection
*iface
)
668 FIXME("iface %p stub!\n", iface
);
673 static BOOL STDMETHODCALLTYPE
d3dcompiler_shader_reflection_IsSampleFrequencyShader(
674 ID3D11ShaderReflection
*iface
)
676 FIXME("iface %p stub!\n", iface
);
681 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetNumInterfaceSlots(
682 ID3D11ShaderReflection
*iface
)
684 FIXME("iface %p stub!\n", iface
);
689 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMinFeatureLevel(
690 ID3D11ShaderReflection
*iface
, D3D_FEATURE_LEVEL
*level
)
692 FIXME("iface %p, level %p stub!\n", iface
, level
);
697 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetThreadGroupSize(
698 ID3D11ShaderReflection
*iface
, UINT
*sizex
, UINT
*sizey
, UINT
*sizez
)
700 FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface
, sizex
, sizey
, sizez
);
705 static UINT64 STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetRequiresFlags(
706 ID3D11ShaderReflection
*iface
)
708 FIXME("iface %p stub!\n", iface
);
713 static const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl
=
715 /* IUnknown methods */
716 d3dcompiler_shader_reflection_QueryInterface
,
717 d3dcompiler_shader_reflection_AddRef
,
718 d3dcompiler_shader_reflection_Release
,
719 /* ID3D11ShaderReflection methods */
720 d3dcompiler_shader_reflection_GetDesc
,
721 d3dcompiler_shader_reflection_GetConstantBufferByIndex
,
722 d3dcompiler_shader_reflection_GetConstantBufferByName
,
723 d3dcompiler_shader_reflection_GetResourceBindingDesc
,
724 d3dcompiler_shader_reflection_GetInputParameterDesc
,
725 d3dcompiler_shader_reflection_GetOutputParameterDesc
,
726 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc
,
727 d3dcompiler_shader_reflection_GetVariableByName
,
728 d3dcompiler_shader_reflection_GetResourceBindingDescByName
,
729 d3dcompiler_shader_reflection_GetMovInstructionCount
,
730 d3dcompiler_shader_reflection_GetMovcInstructionCount
,
731 d3dcompiler_shader_reflection_GetConversionInstructionCount
,
732 d3dcompiler_shader_reflection_GetBitwiseInstructionCount
,
733 d3dcompiler_shader_reflection_GetGSInputPrimitive
,
734 d3dcompiler_shader_reflection_IsSampleFrequencyShader
,
735 d3dcompiler_shader_reflection_GetNumInterfaceSlots
,
736 d3dcompiler_shader_reflection_GetMinFeatureLevel
,
737 d3dcompiler_shader_reflection_GetThreadGroupSize
,
738 d3dcompiler_shader_reflection_GetRequiresFlags
,
741 /* ID3D11ShaderReflectionConstantBuffer methods */
743 static inline struct d3dcompiler_shader_reflection_constant_buffer
*impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer
*iface
)
745 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_constant_buffer
, ID3D11ShaderReflectionConstantBuffer_iface
);
748 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetDesc(
749 ID3D11ShaderReflectionConstantBuffer
*iface
, D3D11_SHADER_BUFFER_DESC
*desc
)
751 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
753 TRACE("iface %p, desc %p\n", iface
, desc
);
755 if (This
== &null_constant_buffer
)
757 WARN("Null constant buffer specified\n");
763 WARN("Invalid argument specified\n");
767 desc
->Name
= This
->name
;
768 desc
->Type
= This
->type
;
769 desc
->Variables
= This
->variable_count
;
770 desc
->Size
= This
->size
;
771 desc
->uFlags
= This
->flags
;
776 static ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex(
777 ID3D11ShaderReflectionConstantBuffer
*iface
, UINT index
)
779 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
781 TRACE("iface %p, index %u\n", iface
, index
);
783 if (index
>= This
->variable_count
)
785 WARN("Invalid index specified\n");
786 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
789 return &This
->variables
[index
].ID3D11ShaderReflectionVariable_iface
;
792 static ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetVariableByName(
793 ID3D11ShaderReflectionConstantBuffer
*iface
, const char *name
)
795 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
798 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
802 WARN("Invalid argument specified\n");
803 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
806 for (i
= 0; i
< This
->variable_count
; ++i
)
808 struct d3dcompiler_shader_reflection_variable
*v
= &This
->variables
[i
];
810 if (!strcmp(v
->name
, name
))
812 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v
);
813 return &v
->ID3D11ShaderReflectionVariable_iface
;
817 WARN("Invalid name specified\n");
819 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
822 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl
=
824 /* ID3D11ShaderReflectionConstantBuffer methods */
825 d3dcompiler_shader_reflection_constant_buffer_GetDesc
,
826 d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex
,
827 d3dcompiler_shader_reflection_constant_buffer_GetVariableByName
,
830 /* ID3D11ShaderReflectionVariable methods */
832 static inline struct d3dcompiler_shader_reflection_variable
*impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable
*iface
)
834 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_variable
, ID3D11ShaderReflectionVariable_iface
);
837 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetDesc(
838 ID3D11ShaderReflectionVariable
*iface
, D3D11_SHADER_VARIABLE_DESC
*desc
)
840 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
842 TRACE("iface %p, desc %p\n", iface
, desc
);
844 if (This
== &null_variable
)
846 WARN("Null variable specified\n");
852 WARN("Invalid argument specified\n");
856 desc
->Name
= This
->name
;
857 desc
->StartOffset
= This
->start_offset
;
858 desc
->Size
= This
->size
;
859 desc
->uFlags
= This
->flags
;
860 desc
->DefaultValue
= This
->default_value
;
862 /* TODO test and set proper values for texture. */
863 desc
->StartTexture
= 0xffffffff;
864 desc
->TextureSize
= 0;
865 desc
->StartSampler
= 0xffffffff;
866 desc
->SamplerSize
= 0;
871 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetType(
872 ID3D11ShaderReflectionVariable
*iface
)
874 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
876 TRACE("iface %p\n", iface
);
878 return &This
->type
->ID3D11ShaderReflectionType_iface
;
881 static ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetBuffer(
882 ID3D11ShaderReflectionVariable
*iface
)
884 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
886 TRACE("iface %p\n", iface
);
888 return &This
->constant_buffer
->ID3D11ShaderReflectionConstantBuffer_iface
;
891 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetInterfaceSlot(
892 ID3D11ShaderReflectionVariable
*iface
, UINT index
)
894 FIXME("iface %p, index %u stub!\n", iface
, index
);
899 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl
=
901 /* ID3D11ShaderReflectionVariable methods */
902 d3dcompiler_shader_reflection_variable_GetDesc
,
903 d3dcompiler_shader_reflection_variable_GetType
,
904 d3dcompiler_shader_reflection_variable_GetBuffer
,
905 d3dcompiler_shader_reflection_variable_GetInterfaceSlot
,
908 /* ID3D11ShaderReflectionType methods */
910 static inline struct d3dcompiler_shader_reflection_type
*impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType
*iface
)
912 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_type
, ID3D11ShaderReflectionType_iface
);
915 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetDesc(
916 ID3D11ShaderReflectionType
*iface
, D3D11_SHADER_TYPE_DESC
*desc
)
918 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
920 TRACE("iface %p, desc %p\n", iface
, desc
);
922 if (This
== &null_type
)
924 WARN("Null type specified\n");
930 WARN("Invalid argument specified\n");
939 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeByIndex(
940 ID3D11ShaderReflectionType
*iface
, UINT index
)
942 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
944 TRACE("iface %p, index %u\n", iface
, index
);
946 if (index
>= This
->desc
.Members
)
948 WARN("Invalid index specified\n");
949 return &null_type
.ID3D11ShaderReflectionType_iface
;
952 return &This
->members
[index
].type
->ID3D11ShaderReflectionType_iface
;
955 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeByName(
956 ID3D11ShaderReflectionType
*iface
, const char *name
)
958 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
961 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
965 WARN("Invalid argument specified\n");
966 return &null_type
.ID3D11ShaderReflectionType_iface
;
969 for (i
= 0; i
< This
->desc
.Members
; ++i
)
971 struct d3dcompiler_shader_reflection_type_member
*member
= &This
->members
[i
];
973 if (!strcmp(member
->name
, name
))
975 TRACE("Returning ID3D11ShaderReflectionType %p.\n", member
->type
);
976 return &member
->type
->ID3D11ShaderReflectionType_iface
;
980 WARN("Invalid name specified\n");
982 return &null_type
.ID3D11ShaderReflectionType_iface
;
985 static const char * STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeName(
986 ID3D11ShaderReflectionType
*iface
, UINT index
)
988 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
990 TRACE("iface %p, index %u\n", iface
, index
);
992 if (This
== &null_type
)
994 WARN("Null type specified\n");
998 if (index
>= This
->desc
.Members
)
1000 WARN("Invalid index specified\n");
1004 return This
->members
[index
].name
;
1007 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_IsEqual(
1008 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*type
)
1010 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
1012 TRACE("iface %p, type %p\n", iface
, type
);
1014 if (This
== &null_type
)
1016 WARN("Null type specified\n");
1026 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetSubType(
1027 ID3D11ShaderReflectionType
*iface
)
1029 FIXME("iface %p stub!\n", iface
);
1034 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetBaseClass(
1035 ID3D11ShaderReflectionType
*iface
)
1037 FIXME("iface %p stub!\n", iface
);
1042 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetNumInterfaces(
1043 ID3D11ShaderReflectionType
*iface
)
1045 FIXME("iface %p stub!\n", iface
);
1050 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetInterfaceByIndex(
1051 ID3D11ShaderReflectionType
*iface
, UINT index
)
1053 FIXME("iface %p, index %u stub!\n", iface
, index
);
1058 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_IsOfType(
1059 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*type
)
1061 FIXME("iface %p, type %p stub!\n", iface
, type
);
1066 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_ImplementsInterface(
1067 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*base
)
1069 FIXME("iface %p, base %p stub!\n", iface
, base
);
1074 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl
=
1076 /* ID3D11ShaderReflectionType methods */
1077 d3dcompiler_shader_reflection_type_GetDesc
,
1078 d3dcompiler_shader_reflection_type_GetMemberTypeByIndex
,
1079 d3dcompiler_shader_reflection_type_GetMemberTypeByName
,
1080 d3dcompiler_shader_reflection_type_GetMemberTypeName
,
1081 d3dcompiler_shader_reflection_type_IsEqual
,
1082 d3dcompiler_shader_reflection_type_GetSubType
,
1083 d3dcompiler_shader_reflection_type_GetBaseClass
,
1084 d3dcompiler_shader_reflection_type_GetNumInterfaces
,
1085 d3dcompiler_shader_reflection_type_GetInterfaceByIndex
,
1086 d3dcompiler_shader_reflection_type_IsOfType
,
1087 d3dcompiler_shader_reflection_type_ImplementsInterface
,
1090 static HRESULT
d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection
*r
, const char *data
, DWORD data_size
)
1092 const char *ptr
= data
;
1093 DWORD size
= data_size
>> 2;
1095 TRACE("Size %u\n", size
);
1097 r
->instruction_count
= read_dword(&ptr
);
1098 TRACE("InstructionCount: %u\n", r
->instruction_count
);
1100 r
->temp_register_count
= read_dword(&ptr
);
1101 TRACE("TempRegisterCount: %u\n", r
->temp_register_count
);
1103 r
->def_count
= read_dword(&ptr
);
1104 TRACE("DefCount: %u\n", r
->def_count
);
1106 r
->dcl_count
= read_dword(&ptr
);
1107 TRACE("DclCount: %u\n", r
->dcl_count
);
1109 r
->float_instruction_count
= read_dword(&ptr
);
1110 TRACE("FloatInstructionCount: %u\n", r
->float_instruction_count
);
1112 r
->int_instruction_count
= read_dword(&ptr
);
1113 TRACE("IntInstructionCount: %u\n", r
->int_instruction_count
);
1115 r
->uint_instruction_count
= read_dword(&ptr
);
1116 TRACE("UintInstructionCount: %u\n", r
->uint_instruction_count
);
1118 r
->static_flow_control_count
= read_dword(&ptr
);
1119 TRACE("StaticFlowControlCount: %u\n", r
->static_flow_control_count
);
1121 r
->dynamic_flow_control_count
= read_dword(&ptr
);
1122 TRACE("DynamicFlowControlCount: %u\n", r
->dynamic_flow_control_count
);
1124 r
->macro_instruction_count
= read_dword(&ptr
);
1125 TRACE("MacroInstructionCount: %u\n", r
->macro_instruction_count
);
1127 r
->temp_array_count
= read_dword(&ptr
);
1128 TRACE("TempArrayCount: %u\n", r
->temp_array_count
);
1130 r
->array_instruction_count
= read_dword(&ptr
);
1131 TRACE("ArrayInstructionCount: %u\n", r
->array_instruction_count
);
1133 r
->cut_instruction_count
= read_dword(&ptr
);
1134 TRACE("CutInstructionCount: %u\n", r
->cut_instruction_count
);
1136 r
->emit_instruction_count
= read_dword(&ptr
);
1137 TRACE("EmitInstructionCount: %u\n", r
->emit_instruction_count
);
1139 r
->texture_normal_instructions
= read_dword(&ptr
);
1140 TRACE("TextureNormalInstructions: %u\n", r
->texture_normal_instructions
);
1142 r
->texture_load_instructions
= read_dword(&ptr
);
1143 TRACE("TextureLoadInstructions: %u\n", r
->texture_load_instructions
);
1145 r
->texture_comp_instructions
= read_dword(&ptr
);
1146 TRACE("TextureCompInstructions: %u\n", r
->texture_comp_instructions
);
1148 r
->texture_bias_instructions
= read_dword(&ptr
);
1149 TRACE("TextureBiasInstructions: %u\n", r
->texture_bias_instructions
);
1151 r
->texture_gradient_instructions
= read_dword(&ptr
);
1152 TRACE("TextureGradientInstructions: %u\n", r
->texture_gradient_instructions
);
1154 r
->mov_instruction_count
= read_dword(&ptr
);
1155 TRACE("MovInstructionCount: %u\n", r
->mov_instruction_count
);
1157 skip_dword_unknown(&ptr
, 1);
1159 r
->conversion_instruction_count
= read_dword(&ptr
);
1160 TRACE("ConversionInstructionCount: %u\n", r
->conversion_instruction_count
);
1162 skip_dword_unknown(&ptr
, 1);
1164 r
->input_primitive
= read_dword(&ptr
);
1165 TRACE("InputPrimitive: %x\n", r
->input_primitive
);
1167 r
->gs_output_topology
= read_dword(&ptr
);
1168 TRACE("GSOutputTopology: %x\n", r
->gs_output_topology
);
1170 r
->gs_max_output_vertex_count
= read_dword(&ptr
);
1171 TRACE("GSMaxOutputVertexCount: %u\n", r
->gs_max_output_vertex_count
);
1173 skip_dword_unknown(&ptr
, 2);
1175 /* old dx10 stat size */
1176 if (size
== 28) return S_OK
;
1178 skip_dword_unknown(&ptr
, 1);
1180 /* dx10 stat size */
1181 if (size
== 29) return S_OK
;
1183 skip_dword_unknown(&ptr
, 1);
1185 r
->c_control_points
= read_dword(&ptr
);
1186 TRACE("cControlPoints: %u\n", r
->c_control_points
);
1188 r
->hs_output_primitive
= read_dword(&ptr
);
1189 TRACE("HSOutputPrimitive: %x\n", r
->hs_output_primitive
);
1191 r
->hs_partitioning
= read_dword(&ptr
);
1192 TRACE("HSPartitioning: %x\n", r
->hs_partitioning
);
1194 r
->tessellator_domain
= read_dword(&ptr
);
1195 TRACE("TessellatorDomain: %x\n", r
->tessellator_domain
);
1197 skip_dword_unknown(&ptr
, 3);
1199 /* dx11 stat size */
1200 if (size
== 37) return S_OK
;
1202 FIXME("Unhandled size %u\n", size
);
1207 static HRESULT
d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection
*ref
,
1208 struct d3dcompiler_shader_reflection_type_member
*member
, const char *data
, const char **ptr
)
1212 offset
= read_dword(ptr
);
1213 if (!copy_name(data
+ offset
, &member
->name
))
1215 ERR("Failed to copy name.\n");
1216 return E_OUTOFMEMORY
;
1218 TRACE("Member name: %s.\n", debugstr_a(member
->name
));
1220 offset
= read_dword(ptr
);
1221 TRACE("Member type offset: %x\n", offset
);
1223 member
->type
= get_reflection_type(ref
, data
, offset
);
1226 ERR("Failed to get member type\n");
1227 HeapFree(GetProcessHeap(), 0, member
->name
);
1231 member
->offset
= read_dword(ptr
);
1232 TRACE("Member offset %x\n", member
->offset
);
1237 static HRESULT
d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type
*type
, const char *data
, DWORD offset
)
1239 const char *ptr
= data
+ offset
;
1241 D3D11_SHADER_TYPE_DESC
*desc
;
1243 struct d3dcompiler_shader_reflection_type_member
*members
= NULL
;
1245 DWORD member_offset
;
1249 temp
= read_dword(&ptr
);
1250 desc
->Class
= temp
& 0xffff;
1251 desc
->Type
= temp
>> 16;
1252 TRACE("Class %s, Type %s\n", debug_d3dcompiler_shader_variable_class(desc
->Class
),
1253 debug_d3dcompiler_shader_variable_type(desc
->Type
));
1255 temp
= read_dword(&ptr
);
1256 desc
->Rows
= temp
& 0xffff;
1257 desc
->Columns
= temp
>> 16;
1258 TRACE("Rows %u, Columns %u\n", desc
->Rows
, desc
->Columns
);
1260 temp
= read_dword(&ptr
);
1261 desc
->Elements
= temp
& 0xffff;
1262 desc
->Members
= temp
>> 16;
1263 TRACE("Elements %u, Members %u\n", desc
->Elements
, desc
->Members
);
1265 member_offset
= read_dword(&ptr
);
1266 TRACE("Member Offset %u\n", member_offset
);
1268 if ((type
->reflection
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1269 skip_dword_unknown(&ptr
, 4);
1273 const char *ptr2
= data
+ member_offset
;
1275 members
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*members
) * desc
->Members
);
1278 ERR("Failed to allocate type memory.\n");
1279 return E_OUTOFMEMORY
;
1282 for (i
= 0; i
< desc
->Members
; ++i
)
1284 hr
= d3dcompiler_parse_type_members(type
->reflection
, &members
[i
], data
, &ptr2
);
1287 FIXME("Failed to parse type members.\n");
1293 if ((type
->reflection
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1295 offset
= read_dword(&ptr
);
1296 if (!copy_name(data
+ offset
, &type
->name
))
1298 ERR("Failed to copy name.\n");
1300 return E_OUTOFMEMORY
;
1302 desc
->Name
= type
->name
;
1303 TRACE("Type name: %s.\n", debugstr_a(type
->name
));
1306 type
->members
= members
;
1311 for (i
= 0; i
< desc
->Members
; ++i
)
1313 free_type_member(&members
[i
]);
1315 HeapFree(GetProcessHeap(), 0, members
);
1319 static struct d3dcompiler_shader_reflection_type
*get_reflection_type(struct d3dcompiler_shader_reflection
*reflection
, const char *data
, DWORD offset
)
1321 struct d3dcompiler_shader_reflection_type
*type
;
1322 struct wine_rb_entry
*entry
;
1325 entry
= wine_rb_get(&reflection
->types
, &offset
);
1328 TRACE("Returning existing type.\n");
1329 return WINE_RB_ENTRY_VALUE(entry
, struct d3dcompiler_shader_reflection_type
, entry
);
1332 type
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*type
));
1336 type
->ID3D11ShaderReflectionType_iface
.lpVtbl
= &d3dcompiler_shader_reflection_type_vtbl
;
1337 type
->ID3D10ShaderReflectionType_iface
.lpVtbl
= &d3d10_shader_reflection_type_vtbl
;
1339 type
->reflection
= reflection
;
1341 hr
= d3dcompiler_parse_type(type
, data
, offset
);
1344 ERR("Failed to parse type info, hr %#x.\n", hr
);
1345 HeapFree(GetProcessHeap(), 0, type
);
1349 if (wine_rb_put(&reflection
->types
, &offset
, &type
->entry
) == -1)
1351 ERR("Failed to insert type entry.\n");
1352 HeapFree(GetProcessHeap(), 0, type
);
1359 static HRESULT
d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer
*cb
,
1360 const char *data
, DWORD data_size
, const char *ptr
)
1362 struct d3dcompiler_shader_reflection_variable
*variables
;
1366 variables
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, cb
->variable_count
* sizeof(*variables
));
1369 ERR("Failed to allocate variables memory.\n");
1370 return E_OUTOFMEMORY
;
1373 for (i
= 0; i
< cb
->variable_count
; i
++)
1375 struct d3dcompiler_shader_reflection_variable
*v
= &variables
[i
];
1378 v
->ID3D11ShaderReflectionVariable_iface
.lpVtbl
= &d3dcompiler_shader_reflection_variable_vtbl
;
1379 v
->ID3D10ShaderReflectionVariable_iface
.lpVtbl
= &d3d10_shader_reflection_variable_vtbl
;
1380 v
->constant_buffer
= cb
;
1382 offset
= read_dword(&ptr
);
1383 if (!copy_name(data
+ offset
, &v
->name
))
1385 ERR("Failed to copy name.\n");
1389 TRACE("Variable name: %s.\n", debugstr_a(v
->name
));
1391 v
->start_offset
= read_dword(&ptr
);
1392 TRACE("Variable offset: %u\n", v
->start_offset
);
1394 v
->size
= read_dword(&ptr
);
1395 TRACE("Variable size: %u\n", v
->size
);
1397 v
->flags
= read_dword(&ptr
);
1398 TRACE("Variable flags: %u\n", v
->flags
);
1400 offset
= read_dword(&ptr
);
1401 TRACE("Variable type offset: %x\n", offset
);
1402 v
->type
= get_reflection_type(cb
->reflection
, data
, offset
);
1405 ERR("Failed to get type.\n");
1410 offset
= read_dword(&ptr
);
1411 TRACE("Variable default value offset: %x\n", offset
);
1412 if (!copy_value(data
+ offset
, &v
->default_value
, offset
? v
->size
: 0))
1414 ERR("Failed to copy name.\n");
1419 if ((cb
->reflection
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1420 skip_dword_unknown(&ptr
, 4);
1423 cb
->variables
= variables
;
1428 for (i
= 0; i
< cb
->variable_count
; i
++)
1430 free_variable(&variables
[i
]);
1432 HeapFree(GetProcessHeap(), 0, variables
);
1436 static HRESULT
d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection
*r
, const char *data
, DWORD data_size
)
1438 struct d3dcompiler_shader_reflection_constant_buffer
*constant_buffers
= NULL
;
1439 DWORD offset
, cbuffer_offset
, resource_offset
, creator_offset
;
1440 unsigned int i
, string_data_offset
, string_data_size
;
1441 D3D12_SHADER_INPUT_BIND_DESC
*bound_resources
= NULL
;
1442 char *string_data
= NULL
, *creator
= NULL
;
1443 DWORD size
= data_size
>> 2;
1444 const char *ptr
= data
;
1445 DWORD target_version
;
1448 TRACE("Size %u\n", size
);
1450 r
->constant_buffer_count
= read_dword(&ptr
);
1451 TRACE("Constant buffer count: %u\n", r
->constant_buffer_count
);
1453 cbuffer_offset
= read_dword(&ptr
);
1454 TRACE("Constant buffer offset: %#x\n", cbuffer_offset
);
1456 r
->bound_resource_count
= read_dword(&ptr
);
1457 TRACE("Bound resource count: %u\n", r
->bound_resource_count
);
1459 resource_offset
= read_dword(&ptr
);
1460 TRACE("Bound resource offset: %#x\n", resource_offset
);
1462 r
->target
= read_dword(&ptr
);
1463 TRACE("Target: %#x\n", r
->target
);
1465 target_version
= r
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
;
1467 #if D3D_COMPILER_VERSION < 47
1468 if (target_version
>= 0x501)
1470 WARN("Target version %#x is not supported in d3dcompiler %u.\n", target_version
, D3D_COMPILER_VERSION
);
1471 return E_INVALIDARG
;
1475 r
->flags
= read_dword(&ptr
);
1476 TRACE("Flags: %u\n", r
->flags
);
1478 creator_offset
= read_dword(&ptr
);
1479 TRACE("Creator at offset %#x.\n", creator_offset
);
1481 if (!copy_name(data
+ creator_offset
, &creator
))
1483 ERR("Failed to copy name.\n");
1484 return E_OUTOFMEMORY
;
1486 TRACE("Creator: %s.\n", debugstr_a(creator
));
1488 /* todo: Parse RD11 */
1489 if (target_version
>= 0x500)
1491 skip_dword_unknown(&ptr
, 8);
1494 if (r
->bound_resource_count
)
1496 /* 8 for each bind desc */
1497 string_data_offset
= resource_offset
+ r
->bound_resource_count
* 8 * sizeof(DWORD
);
1498 string_data_size
= (cbuffer_offset
? cbuffer_offset
: creator_offset
) - string_data_offset
;
1500 string_data
= HeapAlloc(GetProcessHeap(), 0, string_data_size
);
1503 ERR("Failed to allocate string data memory.\n");
1507 memcpy(string_data
, data
+ string_data_offset
, string_data_size
);
1509 bound_resources
= HeapAlloc(GetProcessHeap(), 0, r
->bound_resource_count
* sizeof(*bound_resources
));
1510 if (!bound_resources
)
1512 ERR("Failed to allocate resources memory.\n");
1517 ptr
= data
+ resource_offset
;
1518 for (i
= 0; i
< r
->bound_resource_count
; i
++)
1520 D3D12_SHADER_INPUT_BIND_DESC
*desc
= &bound_resources
[i
];
1522 offset
= read_dword(&ptr
);
1523 desc
->Name
= string_data
+ (offset
- string_data_offset
);
1524 TRACE("Input bind Name: %s\n", debugstr_a(desc
->Name
));
1526 desc
->Type
= read_dword(&ptr
);
1527 TRACE("Input bind Type: %#x\n", desc
->Type
);
1529 desc
->ReturnType
= read_dword(&ptr
);
1530 TRACE("Input bind ReturnType: %#x\n", desc
->ReturnType
);
1532 desc
->Dimension
= read_dword(&ptr
);
1533 TRACE("Input bind Dimension: %#x\n", desc
->Dimension
);
1535 desc
->NumSamples
= read_dword(&ptr
);
1536 TRACE("Input bind NumSamples: %u\n", desc
->NumSamples
);
1538 desc
->BindPoint
= read_dword(&ptr
);
1539 TRACE("Input bind BindPoint: %u\n", desc
->BindPoint
);
1541 desc
->BindCount
= read_dword(&ptr
);
1542 TRACE("Input bind BindCount: %u\n", desc
->BindCount
);
1544 desc
->uFlags
= read_dword(&ptr
);
1545 TRACE("Input bind uFlags: %u\n", desc
->uFlags
);
1547 if (target_version
>= 0x501)
1549 desc
->Space
= read_dword(&ptr
);
1550 TRACE("Input bind Space %u.\n", desc
->Space
);
1551 desc
->uID
= read_dword(&ptr
);
1552 TRACE("Input bind uID %u.\n", desc
->uID
);
1557 desc
->uID
= desc
->BindPoint
;
1562 if (r
->constant_buffer_count
)
1564 constant_buffers
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, r
->constant_buffer_count
* sizeof(*constant_buffers
));
1565 if (!constant_buffers
)
1567 ERR("Failed to allocate constant buffer memory.\n");
1572 ptr
= data
+ cbuffer_offset
;
1573 for (i
= 0; i
< r
->constant_buffer_count
; i
++)
1575 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= &constant_buffers
[i
];
1577 cb
->ID3D11ShaderReflectionConstantBuffer_iface
.lpVtbl
= &d3dcompiler_shader_reflection_constant_buffer_vtbl
;
1578 cb
->ID3D10ShaderReflectionConstantBuffer_iface
.lpVtbl
= &d3d10_shader_reflection_constant_buffer_vtbl
;
1581 offset
= read_dword(&ptr
);
1582 if (!copy_name(data
+ offset
, &cb
->name
))
1584 ERR("Failed to copy name.\n");
1588 TRACE("Name: %s.\n", debugstr_a(cb
->name
));
1590 cb
->variable_count
= read_dword(&ptr
);
1591 TRACE("Variable count: %u\n", cb
->variable_count
);
1593 offset
= read_dword(&ptr
);
1594 TRACE("Variable offset: %x\n", offset
);
1596 hr
= d3dcompiler_parse_variables(cb
, data
, data_size
, data
+ offset
);
1599 FIXME("Failed to parse variables.\n");
1603 cb
->size
= read_dword(&ptr
);
1604 TRACE("Cbuffer size: %u\n", cb
->size
);
1606 cb
->flags
= read_dword(&ptr
);
1607 TRACE("Cbuffer flags: %u\n", cb
->flags
);
1609 cb
->type
= read_dword(&ptr
);
1610 TRACE("Cbuffer type: %#x\n", cb
->type
);
1614 r
->creator
= creator
;
1615 r
->resource_string
= string_data
;
1616 r
->bound_resources
= bound_resources
;
1617 r
->constant_buffers
= constant_buffers
;
1622 for (i
= 0; i
< r
->constant_buffer_count
; ++i
)
1624 free_constant_buffer(&constant_buffers
[i
]);
1626 HeapFree(GetProcessHeap(), 0, constant_buffers
);
1627 HeapFree(GetProcessHeap(), 0, bound_resources
);
1628 HeapFree(GetProcessHeap(), 0, string_data
);
1629 HeapFree(GetProcessHeap(), 0, creator
);
1634 static HRESULT
d3dcompiler_parse_signature(struct d3dcompiler_shader_signature
*s
, struct dxbc_section
*section
)
1636 D3D11_SIGNATURE_PARAMETER_DESC
*d
;
1637 unsigned int string_data_offset
;
1638 unsigned int string_data_size
;
1639 const char *ptr
= section
->data
;
1643 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size
;
1645 switch (section
->tag
)
1648 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
;
1654 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
;
1658 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion
->tag
, 4));
1659 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
;
1663 count
= read_dword(&ptr
);
1664 TRACE("%u elements\n", count
);
1666 skip_dword_unknown(&ptr
, 1);
1668 d
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(*d
));
1671 ERR("Failed to allocate signature memory.\n");
1672 return E_OUTOFMEMORY
;
1675 /* 2 DWORDs for the header, element_size for each element. */
1676 string_data_offset
= 2 * sizeof(DWORD
) + count
* element_size
* sizeof(DWORD
);
1677 string_data_size
= section
->data_size
- string_data_offset
;
1679 string_data
= HeapAlloc(GetProcessHeap(), 0, string_data_size
);
1682 ERR("Failed to allocate string data memory.\n");
1683 HeapFree(GetProcessHeap(), 0, d
);
1684 return E_OUTOFMEMORY
;
1686 memcpy(string_data
, section
->data
+ string_data_offset
, string_data_size
);
1688 for (i
= 0; i
< count
; ++i
)
1693 #if D3D_COMPILER_VERSION >= 46
1695 d
[i
].MinPrecision
= D3D_MIN_PRECISION_DEFAULT
;
1697 if (element_size
== D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
)
1699 d
[i
].Stream
= read_dword(&ptr
);
1706 name_offset
= read_dword(&ptr
);
1707 d
[i
].SemanticName
= string_data
+ (name_offset
- string_data_offset
);
1708 d
[i
].SemanticIndex
= read_dword(&ptr
);
1709 d
[i
].SystemValueType
= read_dword(&ptr
);
1710 d
[i
].ComponentType
= read_dword(&ptr
);
1711 d
[i
].Register
= read_dword(&ptr
);
1712 mask
= read_dword(&ptr
);
1713 d
[i
].ReadWriteMask
= (mask
>> 8) & 0xff;
1714 d
[i
].Mask
= mask
& 0xff;
1716 if (!stricmp(d
[i
].SemanticName
, "sv_depth"))
1717 d
[i
].SystemValueType
= D3D_NAME_DEPTH
;
1718 else if (!stricmp(d
[i
].SemanticName
, "sv_coverage"))
1719 d
[i
].SystemValueType
= D3D_NAME_COVERAGE
;
1720 else if (!stricmp(d
[i
].SemanticName
, "sv_depthgreaterequal"))
1721 d
[i
].SystemValueType
= D3D_NAME_DEPTH_GREATER_EQUAL
;
1722 else if (!stricmp(d
[i
].SemanticName
, "sv_depthlessequal"))
1723 d
[i
].SystemValueType
= D3D_NAME_DEPTH_LESS_EQUAL
;
1724 else if (!stricmp(d
[i
].SemanticName
, "sv_target"))
1725 d
[i
].SystemValueType
= D3D_NAME_TARGET
;
1727 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
1728 "type %u, register idx: %u, use_mask %#x, input_mask %#x, stream %u\n",
1729 debugstr_a(d
[i
].SemanticName
), d
[i
].SemanticIndex
, d
[i
].SystemValueType
,
1730 d
[i
].ComponentType
, d
[i
].Register
, d
[i
].Mask
, d
[i
].ReadWriteMask
, d
[i
].Stream
);
1734 s
->element_count
= count
;
1735 s
->string_data
= string_data
;
1740 static HRESULT
d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection
*r
, const char *data
, DWORD data_size
)
1742 const char *ptr
= data
;
1744 r
->version
= read_dword(&ptr
);
1745 TRACE("Shader version: %u\n", r
->version
);
1747 /* todo: Check if anything else is needed from the shdr or shex blob. */
1752 static HRESULT
d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection
*reflection
,
1753 const void *data
, SIZE_T data_size
)
1755 struct dxbc src_dxbc
;
1759 wine_rb_init(&reflection
->types
, d3dcompiler_shader_reflection_type_compare
);
1761 hr
= dxbc_parse(data
, data_size
, &src_dxbc
);
1764 WARN("Failed to parse reflection\n");
1768 for (i
= 0; i
< src_dxbc
.count
; ++i
)
1770 struct dxbc_section
*section
= &src_dxbc
.sections
[i
];
1772 switch (section
->tag
)
1775 hr
= d3dcompiler_parse_rdef(reflection
, section
->data
, section
->data_size
);
1778 WARN("Failed to parse RDEF section.\n");
1784 reflection
->isgn
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->isgn
));
1785 if (!reflection
->isgn
)
1787 ERR("Failed to allocate ISGN memory.\n");
1792 hr
= d3dcompiler_parse_signature(reflection
->isgn
, section
);
1795 WARN("Failed to parse section ISGN.\n");
1802 reflection
->osgn
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->osgn
));
1803 if (!reflection
->osgn
)
1805 ERR("Failed to allocate OSGN memory.\n");
1810 hr
= d3dcompiler_parse_signature(reflection
->osgn
, section
);
1813 WARN("Failed to parse section OSGN.\n");
1819 reflection
->pcsg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->pcsg
));
1820 if (!reflection
->pcsg
)
1822 ERR("Failed to allocate PCSG memory.\n");
1827 hr
= d3dcompiler_parse_signature(reflection
->pcsg
, section
);
1830 WARN("Failed to parse section PCSG.\n");
1837 hr
= d3dcompiler_parse_shdr(reflection
, section
->data
, section
->data_size
);
1840 WARN("Failed to parse SHDR section.\n");
1846 hr
= d3dcompiler_parse_stat(reflection
, section
->data
, section
->data_size
);
1849 WARN("Failed to parse section STAT.\n");
1855 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion
->tag
, 4));
1860 dxbc_destroy(&src_dxbc
);
1865 reflection_cleanup(reflection
);
1866 dxbc_destroy(&src_dxbc
);
1871 /* d3d10 reflection methods. */
1872 #if !D3D_COMPILER_VERSION
1873 static inline struct d3dcompiler_shader_reflection
*impl_from_ID3D10ShaderReflection(ID3D10ShaderReflection
*iface
)
1875 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection
, ID3D10ShaderReflection_iface
);
1878 static HRESULT STDMETHODCALLTYPE
d3d10_shader_reflection_QueryInterface(ID3D10ShaderReflection
*iface
,
1879 REFIID riid
, void **object
)
1881 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
1883 if (IsEqualGUID(riid
, &IID_ID3D10ShaderReflection
) || IsEqualGUID(riid
, &IID_IUnknown
))
1885 IUnknown_AddRef(iface
);
1890 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
1893 return E_NOINTERFACE
;
1896 static ULONG STDMETHODCALLTYPE
d3d10_shader_reflection_AddRef(ID3D10ShaderReflection
*iface
)
1898 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D10ShaderReflection(iface
);
1899 ULONG refcount
= InterlockedIncrement(&reflection
->refcount
);
1901 TRACE("%p increasing refcount to %u.\n", reflection
, refcount
);
1906 static ULONG STDMETHODCALLTYPE
d3d10_shader_reflection_Release(ID3D10ShaderReflection
*iface
)
1908 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D10ShaderReflection(iface
);
1909 ULONG refcount
= InterlockedDecrement(&reflection
->refcount
);
1911 TRACE("%p decreasing refcount to %u.\n", reflection
, refcount
);
1914 heap_free(reflection
);
1919 static HRESULT STDMETHODCALLTYPE
d3d10_shader_reflection_GetDesc(ID3D10ShaderReflection
*iface
,
1920 D3D10_SHADER_DESC
*desc
)
1922 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D10ShaderReflection(iface
);
1924 TRACE("iface %p, desc %p.\n", iface
, desc
);
1928 WARN("Invalid argument specified.\n");
1932 desc
->Version
= reflection
->version
;
1933 desc
->Creator
= reflection
->creator
;
1934 desc
->Flags
= reflection
->flags
;
1935 desc
->ConstantBuffers
= reflection
->constant_buffer_count
;
1936 desc
->BoundResources
= reflection
->bound_resource_count
;
1937 desc
->InputParameters
= reflection
->isgn
? reflection
->isgn
->element_count
: 0;
1938 desc
->OutputParameters
= reflection
->osgn
? reflection
->osgn
->element_count
: 0;
1939 desc
->InstructionCount
= reflection
->instruction_count
;
1940 desc
->TempRegisterCount
= reflection
->temp_register_count
;
1941 desc
->TempArrayCount
= reflection
->temp_array_count
;
1942 desc
->DefCount
= reflection
->def_count
;
1943 desc
->DclCount
= reflection
->dcl_count
;
1944 desc
->TextureNormalInstructions
= reflection
->texture_normal_instructions
;
1945 desc
->TextureLoadInstructions
= reflection
->texture_load_instructions
;
1946 desc
->TextureCompInstructions
= reflection
->texture_comp_instructions
;
1947 desc
->TextureBiasInstructions
= reflection
->texture_bias_instructions
;
1948 desc
->TextureGradientInstructions
= reflection
->texture_gradient_instructions
;
1949 desc
->FloatInstructionCount
= reflection
->float_instruction_count
;
1950 desc
->IntInstructionCount
= reflection
->int_instruction_count
;
1951 desc
->UintInstructionCount
= reflection
->uint_instruction_count
;
1952 desc
->StaticFlowControlCount
= reflection
->static_flow_control_count
;
1953 desc
->DynamicFlowControlCount
= reflection
->dynamic_flow_control_count
;
1954 desc
->MacroInstructionCount
= reflection
->macro_instruction_count
;
1955 desc
->ArrayInstructionCount
= reflection
->array_instruction_count
;
1956 desc
->CutInstructionCount
= reflection
->cut_instruction_count
;
1957 desc
->EmitInstructionCount
= reflection
->emit_instruction_count
;
1958 desc
->GSOutputTopology
= reflection
->gs_output_topology
;
1959 desc
->GSMaxOutputVertexCount
= reflection
->gs_max_output_vertex_count
;
1964 static struct ID3D10ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3d10_shader_reflection_GetConstantBufferByIndex(
1965 ID3D10ShaderReflection
*iface
, UINT index
)
1967 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D10ShaderReflection(iface
);
1969 TRACE("iface %p, index %u.\n", iface
, index
);
1971 if (index
>= reflection
->constant_buffer_count
)
1973 WARN("Invalid argument specified.\n");
1974 return &null_constant_buffer
.ID3D10ShaderReflectionConstantBuffer_iface
;
1977 return &reflection
->constant_buffers
[index
].ID3D10ShaderReflectionConstantBuffer_iface
;
1980 static struct ID3D10ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3d10_shader_reflection_GetConstantBufferByName(
1981 ID3D10ShaderReflection
*iface
, const char *name
)
1983 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D10ShaderReflection(iface
);
1986 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
1990 WARN("Invalid argument specified.\n");
1991 return &null_constant_buffer
.ID3D10ShaderReflectionConstantBuffer_iface
;
1994 for (i
= 0; i
< reflection
->constant_buffer_count
; ++i
)
1996 struct d3dcompiler_shader_reflection_constant_buffer
*d
= &reflection
->constant_buffers
[i
];
1998 if (!strcmp(d
->name
, name
))
2000 TRACE("Returning ID3D10ShaderReflectionConstantBuffer %p.\n", d
);
2001 return &d
->ID3D10ShaderReflectionConstantBuffer_iface
;
2005 WARN("Invalid name specified.\n");
2007 return &null_constant_buffer
.ID3D10ShaderReflectionConstantBuffer_iface
;
2010 static HRESULT STDMETHODCALLTYPE
d3d10_shader_reflection_GetResourceBindingDesc(ID3D10ShaderReflection
*iface
,
2011 UINT index
, D3D10_SHADER_INPUT_BIND_DESC
*desc
)
2013 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D10ShaderReflection(iface
);
2015 TRACE("iface %p, index %u, desc %p.\n", iface
, index
, desc
);
2017 if (!desc
|| index
>= reflection
->bound_resource_count
)
2019 WARN("Invalid argument specified.\n");
2020 return E_INVALIDARG
;
2023 memcpy(desc
, &reflection
->bound_resources
[index
], sizeof(*desc
));
2028 static HRESULT STDMETHODCALLTYPE
d3d10_shader_reflection_GetInputParameterDesc(ID3D10ShaderReflection
*iface
,
2029 UINT index
, D3D10_SIGNATURE_PARAMETER_DESC
*desc
)
2031 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D10ShaderReflection(iface
);
2033 TRACE("iface %p, index %u, desc %p.\n", iface
, index
, desc
);
2035 if (!desc
|| !reflection
->isgn
|| index
>= reflection
->isgn
->element_count
)
2037 WARN("Invalid argument specified.\n");
2038 return E_INVALIDARG
;
2041 memcpy(desc
, &reflection
->isgn
->elements
[index
], sizeof(*desc
));
2046 static HRESULT STDMETHODCALLTYPE
d3d10_shader_reflection_GetOutputParameterDesc(ID3D10ShaderReflection
*iface
,
2047 UINT index
, D3D10_SIGNATURE_PARAMETER_DESC
*desc
)
2049 struct d3dcompiler_shader_reflection
*reflection
= impl_from_ID3D10ShaderReflection(iface
);
2051 TRACE("iface %p, index %u, desc %p.\n", iface
, index
, desc
);
2053 if (!desc
|| !reflection
->osgn
|| index
>= reflection
->osgn
->element_count
)
2055 WARN("Invalid argument specified.\n");
2056 return E_INVALIDARG
;
2059 memcpy(desc
, &reflection
->osgn
->elements
[index
], sizeof(*desc
));
2064 static const struct ID3D10ShaderReflectionVtbl d3d10_shader_reflection_vtbl
=
2066 d3d10_shader_reflection_QueryInterface
,
2067 d3d10_shader_reflection_AddRef
,
2068 d3d10_shader_reflection_Release
,
2069 d3d10_shader_reflection_GetDesc
,
2070 d3d10_shader_reflection_GetConstantBufferByIndex
,
2071 d3d10_shader_reflection_GetConstantBufferByName
,
2072 d3d10_shader_reflection_GetResourceBindingDesc
,
2073 d3d10_shader_reflection_GetInputParameterDesc
,
2074 d3d10_shader_reflection_GetOutputParameterDesc
,
2077 static inline struct d3dcompiler_shader_reflection_constant_buffer
*impl_from_ID3D10ShaderReflectionConstantBuffer(
2078 ID3D10ShaderReflectionConstantBuffer
*iface
)
2080 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_constant_buffer
,
2081 ID3D10ShaderReflectionConstantBuffer_iface
);
2084 static HRESULT STDMETHODCALLTYPE
d3d10_shader_reflection_constant_buffer_GetDesc(
2085 ID3D10ShaderReflectionConstantBuffer
*iface
, D3D10_SHADER_BUFFER_DESC
*desc
)
2087 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= impl_from_ID3D10ShaderReflectionConstantBuffer(iface
);
2089 TRACE("iface %p, desc %p.\n", iface
, desc
);
2091 if (cb
== &null_constant_buffer
)
2093 WARN("Null constant buffer specified.\n");
2099 WARN("Invalid argument specified.\n");
2103 desc
->Name
= cb
->name
;
2104 desc
->Type
= cb
->type
;
2105 desc
->Variables
= cb
->variable_count
;
2106 desc
->Size
= cb
->size
;
2107 desc
->uFlags
= cb
->flags
;
2112 static ID3D10ShaderReflectionVariable
* STDMETHODCALLTYPE
d3d10_shader_reflection_constant_buffer_GetVariableByIndex(
2113 ID3D10ShaderReflectionConstantBuffer
*iface
, UINT index
)
2115 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= impl_from_ID3D10ShaderReflectionConstantBuffer(iface
);
2117 TRACE("iface %p, index %u.\n", iface
, index
);
2119 if (index
>= cb
->variable_count
)
2121 WARN("Invalid index specified.\n");
2122 return &null_variable
.ID3D10ShaderReflectionVariable_iface
;
2125 return &cb
->variables
[index
].ID3D10ShaderReflectionVariable_iface
;
2128 static ID3D10ShaderReflectionVariable
* STDMETHODCALLTYPE
d3d10_shader_reflection_constant_buffer_GetVariableByName(
2129 ID3D10ShaderReflectionConstantBuffer
*iface
, const char *name
)
2131 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= impl_from_ID3D10ShaderReflectionConstantBuffer(iface
);
2134 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
2138 WARN("Invalid argument specified.\n");
2139 return &null_variable
.ID3D10ShaderReflectionVariable_iface
;
2142 for (i
= 0; i
< cb
->variable_count
; ++i
)
2144 struct d3dcompiler_shader_reflection_variable
*v
= &cb
->variables
[i
];
2146 if (!strcmp(v
->name
, name
))
2148 TRACE("Returning ID3D10ShaderReflectionVariable %p.\n", v
);
2149 return &v
->ID3D10ShaderReflectionVariable_iface
;
2153 WARN("Invalid name specified.\n");
2155 return &null_variable
.ID3D10ShaderReflectionVariable_iface
;
2158 static const struct ID3D10ShaderReflectionConstantBufferVtbl d3d10_shader_reflection_constant_buffer_vtbl
=
2160 d3d10_shader_reflection_constant_buffer_GetDesc
,
2161 d3d10_shader_reflection_constant_buffer_GetVariableByIndex
,
2162 d3d10_shader_reflection_constant_buffer_GetVariableByName
,
2165 static inline struct d3dcompiler_shader_reflection_variable
*impl_from_ID3D10ShaderReflectionVariable(ID3D10ShaderReflectionVariable
*iface
)
2167 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_variable
, ID3D10ShaderReflectionVariable_iface
);
2170 static HRESULT STDMETHODCALLTYPE
d3d10_shader_reflection_variable_GetDesc(ID3D10ShaderReflectionVariable
*iface
,
2171 D3D10_SHADER_VARIABLE_DESC
*desc
)
2173 struct d3dcompiler_shader_reflection_variable
*var
= impl_from_ID3D10ShaderReflectionVariable(iface
);
2175 TRACE("iface %p, desc %p.\n", iface
, desc
);
2177 if (var
== &null_variable
)
2179 WARN("Null variable specified.\n");
2185 WARN("Invalid argument specified.\n");
2189 desc
->Name
= var
->name
;
2190 desc
->StartOffset
= var
->start_offset
;
2191 desc
->Size
= var
->size
;
2192 desc
->uFlags
= var
->flags
;
2193 desc
->DefaultValue
= var
->default_value
;
2198 static ID3D10ShaderReflectionType
* STDMETHODCALLTYPE
d3d10_shader_reflection_variable_GetType(
2199 ID3D10ShaderReflectionVariable
*iface
)
2201 struct d3dcompiler_shader_reflection_variable
*var
= impl_from_ID3D10ShaderReflectionVariable(iface
);
2203 TRACE("iface %p.\n", iface
);
2205 return &var
->type
->ID3D10ShaderReflectionType_iface
;
2208 static const struct ID3D10ShaderReflectionVariableVtbl d3d10_shader_reflection_variable_vtbl
=
2210 d3d10_shader_reflection_variable_GetDesc
,
2211 d3d10_shader_reflection_variable_GetType
,
2214 static inline struct d3dcompiler_shader_reflection_type
*impl_from_ID3D10ShaderReflectionType(
2215 ID3D10ShaderReflectionType
*iface
)
2217 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_type
, ID3D10ShaderReflectionType_iface
);
2220 static HRESULT STDMETHODCALLTYPE
d3d10_shader_reflection_type_GetDesc(ID3D10ShaderReflectionType
*iface
,
2221 D3D10_SHADER_TYPE_DESC
*desc
)
2223 struct d3dcompiler_shader_reflection_type
*type
= impl_from_ID3D10ShaderReflectionType(iface
);
2225 TRACE("iface %p, desc %p.\n", iface
, desc
);
2227 if (type
== &null_type
)
2229 WARN("Null type specified.\n");
2235 WARN("Invalid argument specified.\n");
2239 memcpy(desc
, &type
->desc
, sizeof(*desc
));
2244 static ID3D10ShaderReflectionType
* STDMETHODCALLTYPE
d3d10_shader_reflection_type_GetMemberTypeByIndex(
2245 ID3D10ShaderReflectionType
*iface
, UINT index
)
2247 struct d3dcompiler_shader_reflection_type
*type
= impl_from_ID3D10ShaderReflectionType(iface
);
2249 TRACE("iface %p, index %u.\n", iface
, index
);
2251 if (index
>= type
->desc
.Members
)
2253 WARN("Invalid index specified.\n");
2254 return &null_type
.ID3D10ShaderReflectionType_iface
;
2257 return &type
->members
[index
].type
->ID3D10ShaderReflectionType_iface
;
2260 static ID3D10ShaderReflectionType
* STDMETHODCALLTYPE
d3d10_shader_reflection_type_GetMemberTypeByName(
2261 ID3D10ShaderReflectionType
*iface
, const char *name
)
2263 struct d3dcompiler_shader_reflection_type
*type
= impl_from_ID3D10ShaderReflectionType(iface
);
2266 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
2270 WARN("Invalid argument specified.\n");
2271 return &null_type
.ID3D10ShaderReflectionType_iface
;
2274 for (i
= 0; i
< type
->desc
.Members
; ++i
)
2276 struct d3dcompiler_shader_reflection_type_member
*member
= &type
->members
[i
];
2278 if (!strcmp(member
->name
, name
))
2280 TRACE("Returning ID3D10ShaderReflectionType %p.\n", member
->type
);
2281 return &member
->type
->ID3D10ShaderReflectionType_iface
;
2285 WARN("Invalid name specified.\n");
2287 return &null_type
.ID3D10ShaderReflectionType_iface
;
2290 static const char * STDMETHODCALLTYPE
d3d10_shader_reflection_type_GetMemberTypeName(
2291 ID3D10ShaderReflectionType
*iface
, UINT index
)
2293 struct d3dcompiler_shader_reflection_type
*type
= impl_from_ID3D10ShaderReflectionType(iface
);
2295 TRACE("iface %p, index %u.\n", iface
, index
);
2297 if (type
== &null_type
)
2299 WARN("Null type specified.\n");
2303 if (index
>= type
->desc
.Members
)
2305 WARN("Invalid index specified.\n");
2309 return type
->members
[index
].name
;
2312 static const struct ID3D10ShaderReflectionTypeVtbl d3d10_shader_reflection_type_vtbl
=
2314 d3d10_shader_reflection_type_GetDesc
,
2315 d3d10_shader_reflection_type_GetMemberTypeByIndex
,
2316 d3d10_shader_reflection_type_GetMemberTypeByName
,
2317 d3d10_shader_reflection_type_GetMemberTypeName
,
2320 HRESULT WINAPI
D3D10ReflectShader(const void *data
, SIZE_T data_size
, ID3D10ShaderReflection
**reflector
)
2322 struct d3dcompiler_shader_reflection
*object
;
2325 TRACE("data %p, data_size %lu, reflector %p.\n", data
, data_size
, reflector
);
2327 if (!(object
= heap_alloc_zero(sizeof(*object
))))
2329 ERR("Failed to allocate D3D10 shader reflection object memory.\n");
2330 return E_OUTOFMEMORY
;
2333 object
->ID3D10ShaderReflection_iface
.lpVtbl
= &d3d10_shader_reflection_vtbl
;
2334 object
->interface_version
= D3DCOMPILER_REFLECTION_VERSION_D3D10
;
2335 object
->refcount
= 1;
2337 hr
= d3dcompiler_shader_reflection_init(object
, data
, data_size
);
2340 WARN("Failed to initialize shader reflection.\n");
2341 HeapFree(GetProcessHeap(), 0, object
);
2345 *reflector
= &object
->ID3D10ShaderReflection_iface
;
2347 TRACE("Created ID3D10ShaderReflection %p.\n", object
);
2353 HRESULT WINAPI
D3DReflect(const void *data
, SIZE_T data_size
, REFIID riid
, void **reflector
)
2355 struct d3dcompiler_shader_reflection
*object
;
2357 const DWORD
*temp
= data
;
2359 TRACE("data %p, data_size %lu, riid %s, blob %p\n", data
, data_size
, debugstr_guid(riid
), reflector
);
2361 if (!data
|| data_size
< 32)
2363 WARN("Invalid argument supplied.\n");
2364 return D3DERR_INVALIDCALL
;
2367 if (temp
[6] != data_size
)
2369 WARN("Wrong size supplied.\n");
2370 #if D3D_COMPILER_VERSION >= 46
2371 return D3DERR_INVALIDCALL
;
2377 if (!IsEqualGUID(riid
, &IID_ID3D11ShaderReflection
)
2378 && (D3D_COMPILER_VERSION
< 47 || !IsEqualGUID(riid
, &IID_ID3D12ShaderReflection
)))
2380 WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid
), debugstr_guid(&IID_ID3D11ShaderReflection
));
2381 #if D3D_COMPILER_VERSION >= 46
2382 return E_INVALIDARG
;
2384 return E_NOINTERFACE
;
2388 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2390 return E_OUTOFMEMORY
;
2392 object
->ID3D11ShaderReflection_iface
.lpVtbl
= &d3dcompiler_shader_reflection_vtbl
;
2393 object
->refcount
= 1;
2394 object
->interface_version
= IsEqualGUID(riid
, &IID_ID3D12ShaderReflection
)
2395 ? D3DCOMPILER_REFLECTION_VERSION_D3D12
: D3DCOMPILER_REFLECTION_VERSION_D3D11
;
2397 hr
= d3dcompiler_shader_reflection_init(object
, data
, data_size
);
2400 WARN("Failed to initialize shader reflection\n");
2401 HeapFree(GetProcessHeap(), 0, object
);
2405 *reflector
= object
;
2407 TRACE("Created ID3D11ShaderReflection %p\n", object
);