d3dcompiler: Implement d3d10 reflection GetResourceBindingDesc() method.
[wine/zf.git] / dlls / d3dcompiler_43 / reflection.c
blob02210df7d5e6764968a07c94ec1a9c695eb66fc3
1 /*
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
21 #include "initguid.h"
22 #include "d3dcompiler_private.h"
23 #include "winternl.h"
24 #include "d3d10.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
28 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE
30 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6 = 6,
31 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7 = 7,
34 #define D3DCOMPILER_SHADER_TARGET_VERSION_MASK 0xffff
35 #define D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK 0xffff0000
37 struct d3dcompiler_shader_signature
39 D3D11_SIGNATURE_PARAMETER_DESC *elements;
40 UINT element_count;
41 char *string_data;
44 struct d3dcompiler_shader_reflection_type
46 ID3D11ShaderReflectionType ID3D11ShaderReflectionType_iface;
48 DWORD id;
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;
55 char *name;
58 struct d3dcompiler_shader_reflection_type_member
60 char *name;
61 DWORD offset;
62 struct d3dcompiler_shader_reflection_type *type;
65 struct d3dcompiler_shader_reflection_variable
67 ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable_iface;
69 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffer;
70 struct d3dcompiler_shader_reflection_type *type;
72 char *name;
73 UINT start_offset;
74 UINT size;
75 UINT flags;
76 void *default_value;
79 struct d3dcompiler_shader_reflection_constant_buffer
81 ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer_iface;
83 struct d3dcompiler_shader_reflection *reflection;
85 char *name;
86 D3D_CBUFFER_TYPE type;
87 UINT variable_count;
88 UINT size;
89 UINT flags;
91 struct d3dcompiler_shader_reflection_variable *variables;
94 /* ID3D11ShaderReflection */
95 struct d3dcompiler_shader_reflection
97 ID3D11ShaderReflection ID3D11ShaderReflection_iface;
98 ID3D10ShaderReflection ID3D10ShaderReflection_iface;
99 LONG refcount;
101 DWORD target;
102 char *creator;
103 UINT flags;
104 UINT version;
105 UINT bound_resource_count;
106 UINT constant_buffer_count;
108 UINT mov_instruction_count;
109 UINT conversion_instruction_count;
110 UINT instruction_count;
111 UINT emit_instruction_count;
112 D3D_PRIMITIVE_TOPOLOGY gs_output_topology;
113 UINT gs_max_output_vertex_count;
114 D3D_PRIMITIVE input_primitive;
115 UINT cut_instruction_count;
116 UINT dcl_count;
117 UINT static_flow_control_count;
118 UINT float_instruction_count;
119 UINT temp_register_count;
120 UINT int_instruction_count;
121 UINT uint_instruction_count;
122 UINT temp_array_count;
123 UINT array_instruction_count;
124 UINT texture_normal_instructions;
125 UINT texture_load_instructions;
126 UINT texture_comp_instructions;
127 UINT texture_bias_instructions;
128 UINT texture_gradient_instructions;
129 UINT dynamic_flow_control_count;
130 UINT c_control_points;
131 D3D_TESSELLATOR_OUTPUT_PRIMITIVE hs_output_primitive;
132 D3D_TESSELLATOR_PARTITIONING hs_prtitioning;
133 D3D_TESSELLATOR_DOMAIN tessellator_domain;
135 struct d3dcompiler_shader_signature *isgn;
136 struct d3dcompiler_shader_signature *osgn;
137 struct d3dcompiler_shader_signature *pcsg;
138 char *resource_string;
139 D3D11_SHADER_INPUT_BIND_DESC *bound_resources;
140 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers;
141 struct wine_rb_tree types;
144 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset);
146 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl;
147 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl;
148 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl;
150 /* null objects - needed for invalid calls */
151 static struct d3dcompiler_shader_reflection_constant_buffer null_constant_buffer = {{&d3dcompiler_shader_reflection_constant_buffer_vtbl}};
152 static struct d3dcompiler_shader_reflection_type null_type = {{&d3dcompiler_shader_reflection_type_vtbl}};
153 static struct d3dcompiler_shader_reflection_variable null_variable = {{&d3dcompiler_shader_reflection_variable_vtbl},
154 &null_constant_buffer, &null_type};
156 static BOOL copy_name(const char *ptr, char **name)
158 size_t name_len;
160 if (!ptr) return TRUE;
162 name_len = strlen(ptr) + 1;
163 if (name_len == 1)
165 return TRUE;
168 *name = HeapAlloc(GetProcessHeap(), 0, name_len);
169 if (!*name)
171 ERR("Failed to allocate name memory.\n");
172 return FALSE;
175 memcpy(*name, ptr, name_len);
177 return TRUE;
180 static BOOL copy_value(const char *ptr, void **value, DWORD size)
182 if (!ptr || !size) return TRUE;
184 *value = HeapAlloc(GetProcessHeap(), 0, size);
185 if (!*value)
187 ERR("Failed to allocate value memory.\n");
188 return FALSE;
191 memcpy(*value, ptr, size);
193 return TRUE;
196 static int d3dcompiler_shader_reflection_type_compare(const void *key, const struct wine_rb_entry *entry)
198 const struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3dcompiler_shader_reflection_type, entry);
199 const DWORD *id = key;
201 return *id - t->id;
204 static void free_type_member(struct d3dcompiler_shader_reflection_type_member *member)
206 if (member)
208 HeapFree(GetProcessHeap(), 0, member->name);
212 static void d3dcompiler_shader_reflection_type_destroy(struct wine_rb_entry *entry, void *context)
214 struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
215 unsigned int i;
217 TRACE("reflection type %p.\n", t);
219 if (t->members)
221 for (i = 0; i < t->desc.Members; ++i)
223 free_type_member(&t->members[i]);
225 HeapFree(GetProcessHeap(), 0, t->members);
228 heap_free(t->name);
229 HeapFree(GetProcessHeap(), 0, t);
232 static void free_signature(struct d3dcompiler_shader_signature *sig)
234 TRACE("Free signature %p\n", sig);
236 HeapFree(GetProcessHeap(), 0, sig->elements);
237 HeapFree(GetProcessHeap(), 0, sig->string_data);
240 static void free_variable(struct d3dcompiler_shader_reflection_variable *var)
242 if (var)
244 HeapFree(GetProcessHeap(), 0, var->name);
245 HeapFree(GetProcessHeap(), 0, var->default_value);
249 static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer *cb)
251 if (cb->variables)
253 unsigned int i;
255 for (i = 0; i < cb->variable_count; ++i)
257 free_variable(&cb->variables[i]);
259 HeapFree(GetProcessHeap(), 0, cb->variables);
262 HeapFree(GetProcessHeap(), 0, cb->name);
265 static void reflection_cleanup(struct d3dcompiler_shader_reflection *ref)
267 TRACE("Cleanup %p\n", ref);
269 if (ref->isgn)
271 free_signature(ref->isgn);
272 HeapFree(GetProcessHeap(), 0, ref->isgn);
275 if (ref->osgn)
277 free_signature(ref->osgn);
278 HeapFree(GetProcessHeap(), 0, ref->osgn);
281 if (ref->pcsg)
283 free_signature(ref->pcsg);
284 HeapFree(GetProcessHeap(), 0, ref->pcsg);
287 if (ref->constant_buffers)
289 unsigned int i;
291 for (i = 0; i < ref->constant_buffer_count; ++i)
293 free_constant_buffer(&ref->constant_buffers[i]);
297 wine_rb_destroy(&ref->types, d3dcompiler_shader_reflection_type_destroy, NULL);
298 HeapFree(GetProcessHeap(), 0, ref->constant_buffers);
299 HeapFree(GetProcessHeap(), 0, ref->bound_resources);
300 HeapFree(GetProcessHeap(), 0, ref->resource_string);
301 HeapFree(GetProcessHeap(), 0, ref->creator);
304 /* IUnknown methods */
306 static inline struct d3dcompiler_shader_reflection *impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection *iface)
308 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D11ShaderReflection_iface);
311 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, REFIID riid, void **object)
313 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
315 if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection)
316 || IsEqualGUID(riid, &IID_IUnknown))
318 IUnknown_AddRef(iface);
319 *object = iface;
320 return S_OK;
323 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
325 *object = NULL;
326 return E_NOINTERFACE;
329 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection *iface)
331 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
332 ULONG refcount = InterlockedIncrement(&This->refcount);
334 TRACE("%p increasing refcount to %u\n", This, refcount);
336 return refcount;
339 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection *iface)
341 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
342 ULONG refcount = InterlockedDecrement(&This->refcount);
344 TRACE("%p decreasing refcount to %u\n", This, refcount);
346 if (!refcount)
348 reflection_cleanup(This);
349 HeapFree(GetProcessHeap(), 0, This);
352 return refcount;
355 /* ID3D11ShaderReflection methods */
357 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection *iface, D3D11_SHADER_DESC *desc)
359 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
361 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
363 if (!desc)
365 WARN("Invalid argument specified\n");
366 return E_FAIL;
369 desc->Version = This->version;
370 desc->Creator = This->creator;
371 desc->Flags = This->flags;
372 desc->ConstantBuffers = This->constant_buffer_count;
373 desc->BoundResources = This->bound_resource_count;
374 desc->InputParameters = This->isgn ? This->isgn->element_count : 0;
375 desc->OutputParameters = This->osgn ? This->osgn->element_count : 0;
376 desc->InstructionCount = This->instruction_count;
377 desc->TempRegisterCount = This->temp_register_count;
378 desc->TempArrayCount = This->temp_array_count;
379 desc->DefCount = 0;
380 desc->DclCount = This->dcl_count;
381 desc->TextureNormalInstructions = This->texture_normal_instructions;
382 desc->TextureLoadInstructions = This->texture_load_instructions;
383 desc->TextureCompInstructions = This->texture_comp_instructions;
384 desc->TextureBiasInstructions = This->texture_bias_instructions;
385 desc->TextureGradientInstructions = This->texture_gradient_instructions;
386 desc->FloatInstructionCount = This->float_instruction_count;
387 desc->IntInstructionCount = This->int_instruction_count;
388 desc->UintInstructionCount = This->uint_instruction_count;
389 desc->StaticFlowControlCount = This->static_flow_control_count;
390 desc->DynamicFlowControlCount = This->dynamic_flow_control_count;
391 desc->MacroInstructionCount = 0;
392 desc->ArrayInstructionCount = This->array_instruction_count;
393 desc->CutInstructionCount = This->cut_instruction_count;
394 desc->EmitInstructionCount = This->emit_instruction_count;
395 desc->GSOutputTopology = This->gs_output_topology;
396 desc->GSMaxOutputVertexCount = This->gs_max_output_vertex_count;
397 desc->InputPrimitive = This->input_primitive;
398 desc->PatchConstantParameters = This->pcsg ? This->pcsg->element_count : 0;
399 desc->cGSInstanceCount = 0;
400 desc->cControlPoints = This->c_control_points;
401 desc->HSOutputPrimitive = This->hs_output_primitive;
402 desc->HSPartitioning = This->hs_prtitioning;
403 desc->TessellatorDomain = This->tessellator_domain;
404 desc->cBarrierInstructions = 0;
405 desc->cInterlockedInstructions = 0;
406 desc->cTextureStoreInstructions = 0;
408 return S_OK;
411 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByIndex(
412 ID3D11ShaderReflection *iface, UINT index)
414 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
416 TRACE("iface %p, index %u\n", iface, index);
418 if (index >= This->constant_buffer_count)
420 WARN("Invalid argument specified\n");
421 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
424 return &This->constant_buffers[index].ID3D11ShaderReflectionConstantBuffer_iface;
427 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByName(
428 ID3D11ShaderReflection *iface, const char *name)
430 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
431 unsigned int i;
433 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
435 if (!name)
437 WARN("Invalid argument specified\n");
438 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
441 for (i = 0; i < This->constant_buffer_count; ++i)
443 struct d3dcompiler_shader_reflection_constant_buffer *d = &This->constant_buffers[i];
445 if (!strcmp(d->name, name))
447 TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d);
448 return &d->ID3D11ShaderReflectionConstantBuffer_iface;
452 WARN("Invalid name specified\n");
454 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
457 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDesc(
458 ID3D11ShaderReflection *iface, UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc)
460 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
462 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
464 if (!desc || index >= This->bound_resource_count)
466 WARN("Invalid argument specified\n");
467 return E_INVALIDARG;
470 *desc = This->bound_resources[index];
472 return S_OK;
475 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetInputParameterDesc(
476 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
478 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
480 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
482 if (!desc || !reflection->isgn || index >= reflection->isgn->element_count)
484 WARN("Invalid argument specified\n");
485 return E_INVALIDARG;
488 *desc = reflection->isgn->elements[index];
490 return S_OK;
493 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetOutputParameterDesc(
494 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
496 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
498 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
500 if (!desc || !reflection->osgn || index >= reflection->osgn->element_count)
502 WARN("Invalid argument specified\n");
503 return E_INVALIDARG;
506 *desc = reflection->osgn->elements[index];
508 return S_OK;
511 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
512 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
514 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D11ShaderReflection(iface);
516 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
518 if (!desc || !reflection->pcsg || index >= reflection->pcsg->element_count)
520 WARN("Invalid argument specified\n");
521 return E_INVALIDARG;
524 *desc = reflection->pcsg->elements[index];
526 return S_OK;
529 static struct ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetVariableByName(
530 ID3D11ShaderReflection *iface, const char *name)
532 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
533 unsigned int i, k;
535 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
537 if (!name)
539 WARN("Invalid name specified\n");
540 return &null_variable.ID3D11ShaderReflectionVariable_iface;
543 for (i = 0; i < This->constant_buffer_count; ++i)
545 struct d3dcompiler_shader_reflection_constant_buffer *cb = &This->constant_buffers[i];
547 for (k = 0; k < cb->variable_count; ++k)
549 struct d3dcompiler_shader_reflection_variable *v = &cb->variables[k];
551 if (!strcmp(v->name, name))
553 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
554 return &v->ID3D11ShaderReflectionVariable_iface;
559 WARN("Invalid name specified\n");
561 return &null_variable.ID3D11ShaderReflectionVariable_iface;
564 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDescByName(
565 ID3D11ShaderReflection *iface, const char *name, D3D11_SHADER_INPUT_BIND_DESC *desc)
567 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
568 unsigned int i;
570 TRACE("iface %p, name %s, desc %p\n", iface, debugstr_a(name), desc);
572 if (!desc || !name)
574 WARN("Invalid argument specified\n");
575 return E_INVALIDARG;
578 for (i = 0; i < This->bound_resource_count; ++i)
580 D3D11_SHADER_INPUT_BIND_DESC *d = &This->bound_resources[i];
582 if (!strcmp(d->Name, name))
584 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d);
585 *desc = *d;
586 return S_OK;
590 WARN("Invalid name specified\n");
592 return E_INVALIDARG;
595 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovInstructionCount(
596 ID3D11ShaderReflection *iface)
598 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
600 TRACE("iface %p\n", iface);
602 return This->mov_instruction_count;
605 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovcInstructionCount(
606 ID3D11ShaderReflection *iface)
608 FIXME("iface %p stub!\n", iface);
610 return 0;
613 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConversionInstructionCount(
614 ID3D11ShaderReflection *iface)
616 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
618 TRACE("iface %p\n", iface);
620 return This->conversion_instruction_count;
623 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
624 ID3D11ShaderReflection *iface)
626 FIXME("iface %p stub!\n", iface);
628 return 0;
631 static D3D_PRIMITIVE STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetGSInputPrimitive(
632 ID3D11ShaderReflection *iface)
634 FIXME("iface %p stub!\n", iface);
636 return 0;
639 static BOOL STDMETHODCALLTYPE d3dcompiler_shader_reflection_IsSampleFrequencyShader(
640 ID3D11ShaderReflection *iface)
642 FIXME("iface %p stub!\n", iface);
644 return FALSE;
647 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetNumInterfaceSlots(
648 ID3D11ShaderReflection *iface)
650 FIXME("iface %p stub!\n", iface);
652 return 0;
655 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMinFeatureLevel(
656 ID3D11ShaderReflection *iface, D3D_FEATURE_LEVEL *level)
658 FIXME("iface %p, level %p stub!\n", iface, level);
660 return E_NOTIMPL;
663 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetThreadGroupSize(
664 ID3D11ShaderReflection *iface, UINT *sizex, UINT *sizey, UINT *sizez)
666 FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface, sizex, sizey, sizez);
668 return 0;
671 static UINT64 STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetRequiresFlags(
672 ID3D11ShaderReflection *iface)
674 FIXME("iface %p stub!\n", iface);
676 return 0;
679 static const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl =
681 /* IUnknown methods */
682 d3dcompiler_shader_reflection_QueryInterface,
683 d3dcompiler_shader_reflection_AddRef,
684 d3dcompiler_shader_reflection_Release,
685 /* ID3D11ShaderReflection methods */
686 d3dcompiler_shader_reflection_GetDesc,
687 d3dcompiler_shader_reflection_GetConstantBufferByIndex,
688 d3dcompiler_shader_reflection_GetConstantBufferByName,
689 d3dcompiler_shader_reflection_GetResourceBindingDesc,
690 d3dcompiler_shader_reflection_GetInputParameterDesc,
691 d3dcompiler_shader_reflection_GetOutputParameterDesc,
692 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc,
693 d3dcompiler_shader_reflection_GetVariableByName,
694 d3dcompiler_shader_reflection_GetResourceBindingDescByName,
695 d3dcompiler_shader_reflection_GetMovInstructionCount,
696 d3dcompiler_shader_reflection_GetMovcInstructionCount,
697 d3dcompiler_shader_reflection_GetConversionInstructionCount,
698 d3dcompiler_shader_reflection_GetBitwiseInstructionCount,
699 d3dcompiler_shader_reflection_GetGSInputPrimitive,
700 d3dcompiler_shader_reflection_IsSampleFrequencyShader,
701 d3dcompiler_shader_reflection_GetNumInterfaceSlots,
702 d3dcompiler_shader_reflection_GetMinFeatureLevel,
703 d3dcompiler_shader_reflection_GetThreadGroupSize,
704 d3dcompiler_shader_reflection_GetRequiresFlags,
707 /* ID3D11ShaderReflectionConstantBuffer methods */
709 static inline struct d3dcompiler_shader_reflection_constant_buffer *impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer *iface)
711 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_constant_buffer, ID3D11ShaderReflectionConstantBuffer_iface);
714 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetDesc(
715 ID3D11ShaderReflectionConstantBuffer *iface, D3D11_SHADER_BUFFER_DESC *desc)
717 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
719 TRACE("iface %p, desc %p\n", iface, desc);
721 if (This == &null_constant_buffer)
723 WARN("Null constant buffer specified\n");
724 return E_FAIL;
727 if (!desc)
729 WARN("Invalid argument specified\n");
730 return E_FAIL;
733 desc->Name = This->name;
734 desc->Type = This->type;
735 desc->Variables = This->variable_count;
736 desc->Size = This->size;
737 desc->uFlags = This->flags;
739 return S_OK;
742 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex(
743 ID3D11ShaderReflectionConstantBuffer *iface, UINT index)
745 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
747 TRACE("iface %p, index %u\n", iface, index);
749 if (index >= This->variable_count)
751 WARN("Invalid index specified\n");
752 return &null_variable.ID3D11ShaderReflectionVariable_iface;
755 return &This->variables[index].ID3D11ShaderReflectionVariable_iface;
758 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByName(
759 ID3D11ShaderReflectionConstantBuffer *iface, const char *name)
761 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
762 unsigned int i;
764 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
766 if (!name)
768 WARN("Invalid argument specified\n");
769 return &null_variable.ID3D11ShaderReflectionVariable_iface;
772 for (i = 0; i < This->variable_count; ++i)
774 struct d3dcompiler_shader_reflection_variable *v = &This->variables[i];
776 if (!strcmp(v->name, name))
778 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
779 return &v->ID3D11ShaderReflectionVariable_iface;
783 WARN("Invalid name specified\n");
785 return &null_variable.ID3D11ShaderReflectionVariable_iface;
788 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl =
790 /* ID3D11ShaderReflectionConstantBuffer methods */
791 d3dcompiler_shader_reflection_constant_buffer_GetDesc,
792 d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex,
793 d3dcompiler_shader_reflection_constant_buffer_GetVariableByName,
796 /* ID3D11ShaderReflectionVariable methods */
798 static inline struct d3dcompiler_shader_reflection_variable *impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable *iface)
800 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_variable, ID3D11ShaderReflectionVariable_iface);
803 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetDesc(
804 ID3D11ShaderReflectionVariable *iface, D3D11_SHADER_VARIABLE_DESC *desc)
806 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
808 TRACE("iface %p, desc %p\n", iface, desc);
810 if (This == &null_variable)
812 WARN("Null variable specified\n");
813 return E_FAIL;
816 if (!desc)
818 WARN("Invalid argument specified\n");
819 return E_FAIL;
822 desc->Name = This->name;
823 desc->StartOffset = This->start_offset;
824 desc->Size = This->size;
825 desc->uFlags = This->flags;
826 desc->DefaultValue = This->default_value;
828 return S_OK;
831 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetType(
832 ID3D11ShaderReflectionVariable *iface)
834 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
836 TRACE("iface %p\n", iface);
838 return &This->type->ID3D11ShaderReflectionType_iface;
841 static ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetBuffer(
842 ID3D11ShaderReflectionVariable *iface)
844 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
846 TRACE("iface %p\n", iface);
848 return &This->constant_buffer->ID3D11ShaderReflectionConstantBuffer_iface;
851 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetInterfaceSlot(
852 ID3D11ShaderReflectionVariable *iface, UINT index)
854 FIXME("iface %p, index %u stub!\n", iface, index);
856 return 0;
859 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl =
861 /* ID3D11ShaderReflectionVariable methods */
862 d3dcompiler_shader_reflection_variable_GetDesc,
863 d3dcompiler_shader_reflection_variable_GetType,
864 d3dcompiler_shader_reflection_variable_GetBuffer,
865 d3dcompiler_shader_reflection_variable_GetInterfaceSlot,
868 /* ID3D11ShaderReflectionType methods */
870 static inline struct d3dcompiler_shader_reflection_type *impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType *iface)
872 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_type, ID3D11ShaderReflectionType_iface);
875 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetDesc(
876 ID3D11ShaderReflectionType *iface, D3D11_SHADER_TYPE_DESC *desc)
878 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
880 TRACE("iface %p, desc %p\n", iface, desc);
882 if (This == &null_type)
884 WARN("Null type specified\n");
885 return E_FAIL;
888 if (!desc)
890 WARN("Invalid argument specified\n");
891 return E_FAIL;
894 *desc = This->desc;
896 return S_OK;
899 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByIndex(
900 ID3D11ShaderReflectionType *iface, UINT index)
902 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
904 TRACE("iface %p, index %u\n", iface, index);
906 if (index >= This->desc.Members)
908 WARN("Invalid index specified\n");
909 return &null_type.ID3D11ShaderReflectionType_iface;
912 return &This->members[index].type->ID3D11ShaderReflectionType_iface;
915 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByName(
916 ID3D11ShaderReflectionType *iface, const char *name)
918 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
919 unsigned int i;
921 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
923 if (!name)
925 WARN("Invalid argument specified\n");
926 return &null_type.ID3D11ShaderReflectionType_iface;
929 for (i = 0; i < This->desc.Members; ++i)
931 struct d3dcompiler_shader_reflection_type_member *member = &This->members[i];
933 if (!strcmp(member->name, name))
935 TRACE("Returning ID3D11ShaderReflectionType %p.\n", member->type);
936 return &member->type->ID3D11ShaderReflectionType_iface;
940 WARN("Invalid name specified\n");
942 return &null_type.ID3D11ShaderReflectionType_iface;
945 static const char * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeName(
946 ID3D11ShaderReflectionType *iface, UINT index)
948 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
950 TRACE("iface %p, index %u\n", iface, index);
952 if (This == &null_type)
954 WARN("Null type specified\n");
955 return "$Invalid";
958 if (index >= This->desc.Members)
960 WARN("Invalid index specified\n");
961 return NULL;
964 return This->members[index].name;
967 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsEqual(
968 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
970 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
972 TRACE("iface %p, type %p\n", iface, type);
974 if (This == &null_type)
976 WARN("Null type specified\n");
977 return E_FAIL;
980 if (iface == type)
981 return S_OK;
983 return S_FALSE;
986 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetSubType(
987 ID3D11ShaderReflectionType *iface)
989 FIXME("iface %p stub!\n", iface);
991 return NULL;
994 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetBaseClass(
995 ID3D11ShaderReflectionType *iface)
997 FIXME("iface %p stub!\n", iface);
999 return NULL;
1002 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetNumInterfaces(
1003 ID3D11ShaderReflectionType *iface)
1005 FIXME("iface %p stub!\n", iface);
1007 return 0;
1010 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetInterfaceByIndex(
1011 ID3D11ShaderReflectionType *iface, UINT index)
1013 FIXME("iface %p, index %u stub!\n", iface, index);
1015 return NULL;
1018 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsOfType(
1019 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
1021 FIXME("iface %p, type %p stub!\n", iface, type);
1023 return E_NOTIMPL;
1026 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_ImplementsInterface(
1027 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *base)
1029 FIXME("iface %p, base %p stub!\n", iface, base);
1031 return E_NOTIMPL;
1034 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl =
1036 /* ID3D11ShaderReflectionType methods */
1037 d3dcompiler_shader_reflection_type_GetDesc,
1038 d3dcompiler_shader_reflection_type_GetMemberTypeByIndex,
1039 d3dcompiler_shader_reflection_type_GetMemberTypeByName,
1040 d3dcompiler_shader_reflection_type_GetMemberTypeName,
1041 d3dcompiler_shader_reflection_type_IsEqual,
1042 d3dcompiler_shader_reflection_type_GetSubType,
1043 d3dcompiler_shader_reflection_type_GetBaseClass,
1044 d3dcompiler_shader_reflection_type_GetNumInterfaces,
1045 d3dcompiler_shader_reflection_type_GetInterfaceByIndex,
1046 d3dcompiler_shader_reflection_type_IsOfType,
1047 d3dcompiler_shader_reflection_type_ImplementsInterface,
1050 static HRESULT d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1052 const char *ptr = data;
1053 DWORD size = data_size >> 2;
1055 TRACE("Size %u\n", size);
1057 read_dword(&ptr, &r->instruction_count);
1058 TRACE("InstructionCount: %u\n", r->instruction_count);
1060 read_dword(&ptr, &r->temp_register_count);
1061 TRACE("TempRegisterCount: %u\n", r->temp_register_count);
1063 skip_dword_unknown(&ptr, 1);
1065 read_dword(&ptr, &r->dcl_count);
1066 TRACE("DclCount: %u\n", r->dcl_count);
1068 read_dword(&ptr, &r->float_instruction_count);
1069 TRACE("FloatInstructionCount: %u\n", r->float_instruction_count);
1071 read_dword(&ptr, &r->int_instruction_count);
1072 TRACE("IntInstructionCount: %u\n", r->int_instruction_count);
1074 read_dword(&ptr, &r->uint_instruction_count);
1075 TRACE("UintInstructionCount: %u\n", r->uint_instruction_count);
1077 read_dword(&ptr, &r->static_flow_control_count);
1078 TRACE("StaticFlowControlCount: %u\n", r->static_flow_control_count);
1080 read_dword(&ptr, &r->dynamic_flow_control_count);
1081 TRACE("DynamicFlowControlCount: %u\n", r->dynamic_flow_control_count);
1083 skip_dword_unknown(&ptr, 1);
1085 read_dword(&ptr, &r->temp_array_count);
1086 TRACE("TempArrayCount: %u\n", r->temp_array_count);
1088 read_dword(&ptr, &r->array_instruction_count);
1089 TRACE("ArrayInstructionCount: %u\n", r->array_instruction_count);
1091 read_dword(&ptr, &r->cut_instruction_count);
1092 TRACE("CutInstructionCount: %u\n", r->cut_instruction_count);
1094 read_dword(&ptr, &r->emit_instruction_count);
1095 TRACE("EmitInstructionCount: %u\n", r->emit_instruction_count);
1097 read_dword(&ptr, &r->texture_normal_instructions);
1098 TRACE("TextureNormalInstructions: %u\n", r->texture_normal_instructions);
1100 read_dword(&ptr, &r->texture_load_instructions);
1101 TRACE("TextureLoadInstructions: %u\n", r->texture_load_instructions);
1103 read_dword(&ptr, &r->texture_comp_instructions);
1104 TRACE("TextureCompInstructions: %u\n", r->texture_comp_instructions);
1106 read_dword(&ptr, &r->texture_bias_instructions);
1107 TRACE("TextureBiasInstructions: %u\n", r->texture_bias_instructions);
1109 read_dword(&ptr, &r->texture_gradient_instructions);
1110 TRACE("TextureGradientInstructions: %u\n", r->texture_gradient_instructions);
1112 read_dword(&ptr, &r->mov_instruction_count);
1113 TRACE("MovInstructionCount: %u\n", r->mov_instruction_count);
1115 skip_dword_unknown(&ptr, 1);
1117 read_dword(&ptr, &r->conversion_instruction_count);
1118 TRACE("ConversionInstructionCount: %u\n", r->conversion_instruction_count);
1120 skip_dword_unknown(&ptr, 1);
1122 read_dword(&ptr, &r->input_primitive);
1123 TRACE("InputPrimitive: %x\n", r->input_primitive);
1125 read_dword(&ptr, &r->gs_output_topology);
1126 TRACE("GSOutputTopology: %x\n", r->gs_output_topology);
1128 read_dword(&ptr, &r->gs_max_output_vertex_count);
1129 TRACE("GSMaxOutputVertexCount: %u\n", r->gs_max_output_vertex_count);
1131 skip_dword_unknown(&ptr, 2);
1133 /* old dx10 stat size */
1134 if (size == 28) return S_OK;
1136 skip_dword_unknown(&ptr, 1);
1138 /* dx10 stat size */
1139 if (size == 29) return S_OK;
1141 skip_dword_unknown(&ptr, 1);
1143 read_dword(&ptr, &r->c_control_points);
1144 TRACE("cControlPoints: %u\n", r->c_control_points);
1146 read_dword(&ptr, &r->hs_output_primitive);
1147 TRACE("HSOutputPrimitive: %x\n", r->hs_output_primitive);
1149 read_dword(&ptr, &r->hs_prtitioning);
1150 TRACE("HSPartitioning: %x\n", r->hs_prtitioning);
1152 read_dword(&ptr, &r->tessellator_domain);
1153 TRACE("TessellatorDomain: %x\n", r->tessellator_domain);
1155 skip_dword_unknown(&ptr, 3);
1157 /* dx11 stat size */
1158 if (size == 37) return S_OK;
1160 FIXME("Unhandled size %u\n", size);
1162 return E_FAIL;
1165 static HRESULT d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection *ref,
1166 struct d3dcompiler_shader_reflection_type_member *member, const char *data, const char **ptr)
1168 DWORD offset;
1170 read_dword(ptr, &offset);
1171 if (!copy_name(data + offset, &member->name))
1173 ERR("Failed to copy name.\n");
1174 return E_OUTOFMEMORY;
1176 TRACE("Member name: %s.\n", debugstr_a(member->name));
1178 read_dword(ptr, &offset);
1179 TRACE("Member type offset: %x\n", offset);
1181 member->type = get_reflection_type(ref, data, offset);
1182 if (!member->type)
1184 ERR("Failed to get member type\n");
1185 HeapFree(GetProcessHeap(), 0, member->name);
1186 return E_FAIL;
1189 read_dword(ptr, &member->offset);
1190 TRACE("Member offset %x\n", member->offset);
1192 return S_OK;
1195 static HRESULT d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type *type, const char *data, DWORD offset)
1197 const char *ptr = data + offset;
1198 DWORD temp;
1199 D3D11_SHADER_TYPE_DESC *desc;
1200 unsigned int i;
1201 struct d3dcompiler_shader_reflection_type_member *members = NULL;
1202 HRESULT hr;
1203 DWORD member_offset;
1205 desc = &type->desc;
1207 read_dword(&ptr, &temp);
1208 desc->Class = temp & 0xffff;
1209 desc->Type = temp >> 16;
1210 TRACE("Class %s, Type %s\n", debug_d3dcompiler_shader_variable_class(desc->Class),
1211 debug_d3dcompiler_shader_variable_type(desc->Type));
1213 read_dword(&ptr, &temp);
1214 desc->Rows = temp & 0xffff;
1215 desc->Columns = temp >> 16;
1216 TRACE("Rows %u, Columns %u\n", desc->Rows, desc->Columns);
1218 read_dword(&ptr, &temp);
1219 desc->Elements = temp & 0xffff;
1220 desc->Members = temp >> 16;
1221 TRACE("Elements %u, Members %u\n", desc->Elements, desc->Members);
1223 read_dword(&ptr, &member_offset);
1224 TRACE("Member Offset %u\n", member_offset);
1226 if ((type->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1227 skip_dword_unknown(&ptr, 4);
1229 if (desc->Members)
1231 const char *ptr2 = data + member_offset;
1233 members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*members) * desc->Members);
1234 if (!members)
1236 ERR("Failed to allocate type memory.\n");
1237 return E_OUTOFMEMORY;
1240 for (i = 0; i < desc->Members; ++i)
1242 hr = d3dcompiler_parse_type_members(type->reflection, &members[i], data, &ptr2);
1243 if (hr != S_OK)
1245 FIXME("Failed to parse type members.\n");
1246 goto err_out;
1251 if ((type->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1253 read_dword(&ptr, &offset);
1254 if (!copy_name(data + offset, &type->name))
1256 ERR("Failed to copy name.\n");
1257 heap_free(members);
1258 return E_OUTOFMEMORY;
1260 desc->Name = type->name;
1261 TRACE("Type name: %s.\n", debugstr_a(type->name));
1264 type->members = members;
1266 return S_OK;
1268 err_out:
1269 for (i = 0; i < desc->Members; ++i)
1271 free_type_member(&members[i]);
1273 HeapFree(GetProcessHeap(), 0, members);
1274 return hr;
1277 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset)
1279 struct d3dcompiler_shader_reflection_type *type;
1280 struct wine_rb_entry *entry;
1281 HRESULT hr;
1283 entry = wine_rb_get(&reflection->types, &offset);
1284 if (entry)
1286 TRACE("Returning existing type.\n");
1287 return WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
1290 type = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*type));
1291 if (!type)
1292 return NULL;
1294 type->ID3D11ShaderReflectionType_iface.lpVtbl = &d3dcompiler_shader_reflection_type_vtbl;
1295 type->id = offset;
1296 type->reflection = reflection;
1298 hr = d3dcompiler_parse_type(type, data, offset);
1299 if (FAILED(hr))
1301 ERR("Failed to parse type info, hr %#x.\n", hr);
1302 HeapFree(GetProcessHeap(), 0, type);
1303 return NULL;
1306 if (wine_rb_put(&reflection->types, &offset, &type->entry) == -1)
1308 ERR("Failed to insert type entry.\n");
1309 HeapFree(GetProcessHeap(), 0, type);
1310 return NULL;
1313 return type;
1316 static HRESULT d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer *cb,
1317 const char *data, DWORD data_size, const char *ptr)
1319 struct d3dcompiler_shader_reflection_variable *variables;
1320 unsigned int i;
1321 HRESULT hr;
1323 variables = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb->variable_count * sizeof(*variables));
1324 if (!variables)
1326 ERR("Failed to allocate variables memory.\n");
1327 return E_OUTOFMEMORY;
1330 for (i = 0; i < cb->variable_count; i++)
1332 struct d3dcompiler_shader_reflection_variable *v = &variables[i];
1333 DWORD offset;
1335 v->ID3D11ShaderReflectionVariable_iface.lpVtbl = &d3dcompiler_shader_reflection_variable_vtbl;
1336 v->constant_buffer = cb;
1338 read_dword(&ptr, &offset);
1339 if (!copy_name(data + offset, &v->name))
1341 ERR("Failed to copy name.\n");
1342 hr = E_OUTOFMEMORY;
1343 goto err_out;
1345 TRACE("Variable name: %s.\n", debugstr_a(v->name));
1347 read_dword(&ptr, &v->start_offset);
1348 TRACE("Variable offset: %u\n", v->start_offset);
1350 read_dword(&ptr, &v->size);
1351 TRACE("Variable size: %u\n", v->size);
1353 read_dword(&ptr, &v->flags);
1354 TRACE("Variable flags: %u\n", v->flags);
1356 read_dword(&ptr, &offset);
1357 TRACE("Variable type offset: %x\n", offset);
1358 v->type = get_reflection_type(cb->reflection, data, offset);
1359 if (!v->type)
1361 ERR("Failed to get type.\n");
1362 hr = E_FAIL;
1363 goto err_out;
1366 read_dword(&ptr, &offset);
1367 TRACE("Variable default value offset: %x\n", offset);
1368 if (!copy_value(data + offset, &v->default_value, offset ? v->size : 0))
1370 ERR("Failed to copy name.\n");
1371 hr = E_OUTOFMEMORY;
1372 goto err_out;
1375 if ((cb->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1376 skip_dword_unknown(&ptr, 4);
1379 cb->variables = variables;
1381 return S_OK;
1383 err_out:
1384 for (i = 0; i < cb->variable_count; i++)
1386 free_variable(&variables[i]);
1388 HeapFree(GetProcessHeap(), 0, variables);
1389 return hr;
1392 static HRESULT d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1394 const char *ptr = data;
1395 DWORD size = data_size >> 2;
1396 DWORD offset, cbuffer_offset, resource_offset, creator_offset;
1397 unsigned int i, string_data_offset, string_data_size;
1398 char *string_data = NULL, *creator = NULL;
1399 D3D11_SHADER_INPUT_BIND_DESC *bound_resources = NULL;
1400 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers = NULL;
1401 HRESULT hr;
1403 TRACE("Size %u\n", size);
1405 read_dword(&ptr, &r->constant_buffer_count);
1406 TRACE("Constant buffer count: %u\n", r->constant_buffer_count);
1408 read_dword(&ptr, &cbuffer_offset);
1409 TRACE("Constant buffer offset: %#x\n", cbuffer_offset);
1411 read_dword(&ptr, &r->bound_resource_count);
1412 TRACE("Bound resource count: %u\n", r->bound_resource_count);
1414 read_dword(&ptr, &resource_offset);
1415 TRACE("Bound resource offset: %#x\n", resource_offset);
1417 read_dword(&ptr, &r->target);
1418 TRACE("Target: %#x\n", r->target);
1420 read_dword(&ptr, &r->flags);
1421 TRACE("Flags: %u\n", r->flags);
1423 read_dword(&ptr, &creator_offset);
1424 TRACE("Creator at offset %#x.\n", creator_offset);
1426 if (!copy_name(data + creator_offset, &creator))
1428 ERR("Failed to copy name.\n");
1429 return E_OUTOFMEMORY;
1431 TRACE("Creator: %s.\n", debugstr_a(creator));
1433 /* todo: Parse RD11 */
1434 if ((r->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1436 skip_dword_unknown(&ptr, 8);
1439 if (r->bound_resource_count)
1441 /* 8 for each bind desc */
1442 string_data_offset = resource_offset + r->bound_resource_count * 8 * sizeof(DWORD);
1443 string_data_size = (cbuffer_offset ? cbuffer_offset : creator_offset) - string_data_offset;
1445 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1446 if (!string_data)
1448 ERR("Failed to allocate string data memory.\n");
1449 hr = E_OUTOFMEMORY;
1450 goto err_out;
1452 memcpy(string_data, data + string_data_offset, string_data_size);
1454 bound_resources = HeapAlloc(GetProcessHeap(), 0, r->bound_resource_count * sizeof(*bound_resources));
1455 if (!bound_resources)
1457 ERR("Failed to allocate resources memory.\n");
1458 hr = E_OUTOFMEMORY;
1459 goto err_out;
1462 ptr = data + resource_offset;
1463 for (i = 0; i < r->bound_resource_count; i++)
1465 D3D11_SHADER_INPUT_BIND_DESC *desc = &bound_resources[i];
1467 read_dword(&ptr, &offset);
1468 desc->Name = string_data + (offset - string_data_offset);
1469 TRACE("Input bind Name: %s\n", debugstr_a(desc->Name));
1471 read_dword(&ptr, &desc->Type);
1472 TRACE("Input bind Type: %#x\n", desc->Type);
1474 read_dword(&ptr, &desc->ReturnType);
1475 TRACE("Input bind ReturnType: %#x\n", desc->ReturnType);
1477 read_dword(&ptr, &desc->Dimension);
1478 TRACE("Input bind Dimension: %#x\n", desc->Dimension);
1480 read_dword(&ptr, &desc->NumSamples);
1481 TRACE("Input bind NumSamples: %u\n", desc->NumSamples);
1483 read_dword(&ptr, &desc->BindPoint);
1484 TRACE("Input bind BindPoint: %u\n", desc->BindPoint);
1486 read_dword(&ptr, &desc->BindCount);
1487 TRACE("Input bind BindCount: %u\n", desc->BindCount);
1489 read_dword(&ptr, &desc->uFlags);
1490 TRACE("Input bind uFlags: %u\n", desc->uFlags);
1494 if (r->constant_buffer_count)
1496 constant_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, r->constant_buffer_count * sizeof(*constant_buffers));
1497 if (!constant_buffers)
1499 ERR("Failed to allocate constant buffer memory.\n");
1500 hr = E_OUTOFMEMORY;
1501 goto err_out;
1504 ptr = data + cbuffer_offset;
1505 for (i = 0; i < r->constant_buffer_count; i++)
1507 struct d3dcompiler_shader_reflection_constant_buffer *cb = &constant_buffers[i];
1509 cb->ID3D11ShaderReflectionConstantBuffer_iface.lpVtbl = &d3dcompiler_shader_reflection_constant_buffer_vtbl;
1510 cb->reflection = r;
1512 read_dword(&ptr, &offset);
1513 if (!copy_name(data + offset, &cb->name))
1515 ERR("Failed to copy name.\n");
1516 hr = E_OUTOFMEMORY;
1517 goto err_out;
1519 TRACE("Name: %s.\n", debugstr_a(cb->name));
1521 read_dword(&ptr, &cb->variable_count);
1522 TRACE("Variable count: %u\n", cb->variable_count);
1524 read_dword(&ptr, &offset);
1525 TRACE("Variable offset: %x\n", offset);
1527 hr = d3dcompiler_parse_variables(cb, data, data_size, data + offset);
1528 if (hr != S_OK)
1530 FIXME("Failed to parse variables.\n");
1531 goto err_out;
1534 read_dword(&ptr, &cb->size);
1535 TRACE("Cbuffer size: %u\n", cb->size);
1537 read_dword(&ptr, &cb->flags);
1538 TRACE("Cbuffer flags: %u\n", cb->flags);
1540 read_dword(&ptr, &cb->type);
1541 TRACE("Cbuffer type: %#x\n", cb->type);
1545 r->creator = creator;
1546 r->resource_string = string_data;
1547 r->bound_resources = bound_resources;
1548 r->constant_buffers = constant_buffers;
1550 return S_OK;
1552 err_out:
1553 for (i = 0; i < r->constant_buffer_count; ++i)
1555 free_constant_buffer(&constant_buffers[i]);
1557 HeapFree(GetProcessHeap(), 0, constant_buffers);
1558 HeapFree(GetProcessHeap(), 0, bound_resources);
1559 HeapFree(GetProcessHeap(), 0, string_data);
1560 HeapFree(GetProcessHeap(), 0, creator);
1562 return hr;
1565 static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, struct dxbc_section *section, DWORD target)
1567 D3D11_SIGNATURE_PARAMETER_DESC *d;
1568 unsigned int string_data_offset;
1569 unsigned int string_data_size;
1570 const char *ptr = section->data;
1571 char *string_data;
1572 unsigned int i;
1573 DWORD count;
1574 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size;
1576 switch (section->tag)
1578 case TAG_OSG5:
1579 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7;
1580 break;
1582 case TAG_ISGN:
1583 case TAG_OSGN:
1584 case TAG_PCSG:
1585 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1586 break;
1588 default:
1589 FIXME("Unhandled section %s!\n", debugstr_an((const char *)&section->tag, 4));
1590 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1591 break;
1594 read_dword(&ptr, &count);
1595 TRACE("%u elements\n", count);
1597 skip_dword_unknown(&ptr, 1);
1599 d = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*d));
1600 if (!d)
1602 ERR("Failed to allocate signature memory.\n");
1603 return E_OUTOFMEMORY;
1606 /* 2 DWORDs for the header, element_size for each element. */
1607 string_data_offset = 2 * sizeof(DWORD) + count * element_size * sizeof(DWORD);
1608 string_data_size = section->data_size - string_data_offset;
1610 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1611 if (!string_data)
1613 ERR("Failed to allocate string data memory.\n");
1614 HeapFree(GetProcessHeap(), 0, d);
1615 return E_OUTOFMEMORY;
1617 memcpy(string_data, section->data + string_data_offset, string_data_size);
1619 for (i = 0; i < count; ++i)
1621 UINT name_offset;
1622 DWORD mask;
1624 #if D3D_COMPILER_VERSION >= 46
1625 /* FIXME */
1626 d[i].MinPrecision = D3D_MIN_PRECISION_DEFAULT;
1627 #endif
1628 if (element_size == D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7)
1630 read_dword(&ptr, &d[i].Stream);
1632 else
1634 d[i].Stream = 0;
1637 read_dword(&ptr, &name_offset);
1638 d[i].SemanticName = string_data + (name_offset - string_data_offset);
1639 read_dword(&ptr, &d[i].SemanticIndex);
1640 read_dword(&ptr, &d[i].SystemValueType);
1641 read_dword(&ptr, &d[i].ComponentType);
1642 read_dword(&ptr, &d[i].Register);
1643 read_dword(&ptr, &mask);
1644 d[i].ReadWriteMask = (mask >> 8) & 0xff;
1645 d[i].Mask = mask & 0xff;
1647 /* pixel shaders have a special handling for SystemValueType in the output signature */
1648 if (((target & D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK) == 0xffff0000) && (section->tag == TAG_OSG5 || section->tag == TAG_OSGN))
1650 TRACE("Pixelshader output signature fixup.\n");
1652 if (d[i].Register == 0xffffffff)
1654 if (!_strnicmp(d[i].SemanticName, "sv_depth", -1))
1655 d[i].SystemValueType = D3D_NAME_DEPTH;
1656 else if (!_strnicmp(d[i].SemanticName, "sv_coverage", -1))
1657 d[i].SystemValueType = D3D_NAME_COVERAGE;
1658 else if (!_strnicmp(d[i].SemanticName, "sv_depthgreaterequal", -1))
1659 d[i].SystemValueType = D3D_NAME_DEPTH_GREATER_EQUAL;
1660 else if (!_strnicmp(d[i].SemanticName, "sv_depthlessequal", -1))
1661 d[i].SystemValueType = D3D_NAME_DEPTH_LESS_EQUAL;
1663 else
1665 d[i].SystemValueType = D3D_NAME_TARGET;
1669 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
1670 "type %u, register idx: %u, use_mask %#x, input_mask %#x, stream %u\n",
1671 debugstr_a(d[i].SemanticName), d[i].SemanticIndex, d[i].SystemValueType,
1672 d[i].ComponentType, d[i].Register, d[i].Mask, d[i].ReadWriteMask, d[i].Stream);
1675 s->elements = d;
1676 s->element_count = count;
1677 s->string_data = string_data;
1679 return S_OK;
1682 static HRESULT d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1684 const char *ptr = data;
1686 read_dword(&ptr, &r->version);
1687 TRACE("Shader version: %u\n", r->version);
1689 /* todo: Check if anything else is needed from the shdr or shex blob. */
1691 return S_OK;
1694 static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection *reflection,
1695 const void *data, SIZE_T data_size)
1697 struct dxbc src_dxbc;
1698 HRESULT hr;
1699 unsigned int i;
1701 wine_rb_init(&reflection->types, d3dcompiler_shader_reflection_type_compare);
1703 hr = dxbc_parse(data, data_size, &src_dxbc);
1704 if (FAILED(hr))
1706 WARN("Failed to parse reflection\n");
1707 return hr;
1710 for (i = 0; i < src_dxbc.count; ++i)
1712 struct dxbc_section *section = &src_dxbc.sections[i];
1714 switch (section->tag)
1716 case TAG_RDEF:
1717 hr = d3dcompiler_parse_rdef(reflection, section->data, section->data_size);
1718 if (FAILED(hr))
1720 WARN("Failed to parse RDEF section.\n");
1721 goto err_out;
1723 break;
1725 case TAG_ISGN:
1726 reflection->isgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->isgn));
1727 if (!reflection->isgn)
1729 ERR("Failed to allocate ISGN memory.\n");
1730 hr = E_OUTOFMEMORY;
1731 goto err_out;
1734 hr = d3dcompiler_parse_signature(reflection->isgn, section, reflection->target);
1735 if (FAILED(hr))
1737 WARN("Failed to parse section ISGN.\n");
1738 goto err_out;
1740 break;
1742 case TAG_OSG5:
1743 case TAG_OSGN:
1744 reflection->osgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->osgn));
1745 if (!reflection->osgn)
1747 ERR("Failed to allocate OSGN memory.\n");
1748 hr = E_OUTOFMEMORY;
1749 goto err_out;
1752 hr = d3dcompiler_parse_signature(reflection->osgn, section, reflection->target);
1753 if (FAILED(hr))
1755 WARN("Failed to parse section OSGN.\n");
1756 goto err_out;
1758 break;
1760 case TAG_PCSG:
1761 reflection->pcsg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->pcsg));
1762 if (!reflection->pcsg)
1764 ERR("Failed to allocate PCSG memory.\n");
1765 hr = E_OUTOFMEMORY;
1766 goto err_out;
1769 hr = d3dcompiler_parse_signature(reflection->pcsg, section, reflection->target);
1770 if (FAILED(hr))
1772 WARN("Failed to parse section PCSG.\n");
1773 goto err_out;
1775 break;
1777 case TAG_SHEX:
1778 case TAG_SHDR:
1779 hr = d3dcompiler_parse_shdr(reflection, section->data, section->data_size);
1780 if (FAILED(hr))
1782 WARN("Failed to parse SHDR section.\n");
1783 goto err_out;
1785 break;
1787 case TAG_STAT:
1788 hr = d3dcompiler_parse_stat(reflection, section->data, section->data_size);
1789 if (FAILED(hr))
1791 WARN("Failed to parse section STAT.\n");
1792 goto err_out;
1794 break;
1796 default:
1797 FIXME("Unhandled section %s!\n", debugstr_an((const char *)&section->tag, 4));
1798 break;
1802 dxbc_destroy(&src_dxbc);
1804 return hr;
1806 err_out:
1807 reflection_cleanup(reflection);
1808 dxbc_destroy(&src_dxbc);
1810 return hr;
1813 /* d3d10 reflection methods. */
1814 #if !D3D_COMPILER_VERSION
1815 static inline struct d3dcompiler_shader_reflection *impl_from_ID3D10ShaderReflection(ID3D10ShaderReflection *iface)
1817 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D10ShaderReflection_iface);
1820 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_QueryInterface(ID3D10ShaderReflection *iface,
1821 REFIID riid, void **object)
1823 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1825 if (IsEqualGUID(riid, &IID_ID3D10ShaderReflection) || IsEqualGUID(riid, &IID_IUnknown))
1827 IUnknown_AddRef(iface);
1828 *object = iface;
1829 return S_OK;
1832 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
1834 *object = NULL;
1835 return E_NOINTERFACE;
1838 static ULONG STDMETHODCALLTYPE d3d10_shader_reflection_AddRef(ID3D10ShaderReflection *iface)
1840 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1841 ULONG refcount = InterlockedIncrement(&reflection->refcount);
1843 TRACE("%p increasing refcount to %u.\n", reflection, refcount);
1845 return refcount;
1848 static ULONG STDMETHODCALLTYPE d3d10_shader_reflection_Release(ID3D10ShaderReflection *iface)
1850 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1851 ULONG refcount = InterlockedDecrement(&reflection->refcount);
1853 TRACE("%p decreasing refcount to %u.\n", reflection, refcount);
1855 if (!refcount)
1856 heap_free(reflection);
1858 return refcount;
1861 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_GetDesc(ID3D10ShaderReflection *iface,
1862 D3D10_SHADER_DESC *desc)
1864 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1866 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
1868 if (!desc)
1870 WARN("Invalid argument specified.\n");
1871 return E_FAIL;
1874 desc->Version = reflection->version;
1875 desc->Creator = reflection->creator;
1876 desc->Flags = reflection->flags;
1877 desc->ConstantBuffers = reflection->constant_buffer_count;
1878 desc->BoundResources = reflection->bound_resource_count;
1879 desc->InputParameters = reflection->isgn ? reflection->isgn->element_count : 0;
1880 desc->OutputParameters = reflection->osgn ? reflection->osgn->element_count : 0;
1881 desc->InstructionCount = reflection->instruction_count;
1882 desc->TempRegisterCount = reflection->temp_register_count;
1883 desc->TempArrayCount = reflection->temp_array_count;
1884 desc->DefCount = 0;
1885 desc->DclCount = reflection->dcl_count;
1886 desc->TextureNormalInstructions = reflection->texture_normal_instructions;
1887 desc->TextureLoadInstructions = reflection->texture_load_instructions;
1888 desc->TextureCompInstructions = reflection->texture_comp_instructions;
1889 desc->TextureBiasInstructions = reflection->texture_bias_instructions;
1890 desc->TextureGradientInstructions = reflection->texture_gradient_instructions;
1891 desc->FloatInstructionCount = reflection->float_instruction_count;
1892 desc->IntInstructionCount = reflection->int_instruction_count;
1893 desc->UintInstructionCount = reflection->uint_instruction_count;
1894 desc->StaticFlowControlCount = reflection->static_flow_control_count;
1895 desc->DynamicFlowControlCount = reflection->dynamic_flow_control_count;
1896 desc->MacroInstructionCount = 0;
1897 desc->ArrayInstructionCount = reflection->array_instruction_count;
1898 desc->CutInstructionCount = reflection->cut_instruction_count;
1899 desc->EmitInstructionCount = reflection->emit_instruction_count;
1900 desc->GSOutputTopology = reflection->gs_output_topology;
1901 desc->GSMaxOutputVertexCount = reflection->gs_max_output_vertex_count;
1903 return S_OK;
1906 static struct ID3D10ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3d10_shader_reflection_GetConstantBufferByIndex(
1907 ID3D10ShaderReflection *iface, UINT index)
1909 FIXME("iface %p, index %u stub!\n", iface, index);
1911 return NULL;
1914 static struct ID3D10ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3d10_shader_reflection_GetConstantBufferByName(
1915 ID3D10ShaderReflection *iface, const char *name)
1917 FIXME("iface %p, name %s stub!\n", iface, debugstr_a(name));
1919 return NULL;
1922 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_GetResourceBindingDesc(ID3D10ShaderReflection *iface,
1923 UINT index, D3D10_SHADER_INPUT_BIND_DESC *desc)
1925 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1927 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
1929 if (!desc || index >= reflection->bound_resource_count)
1931 WARN("Invalid argument specified.\n");
1932 return E_INVALIDARG;
1935 memcpy(desc, &reflection->bound_resources[index], sizeof(*desc));
1937 return S_OK;
1940 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_GetInputParameterDesc(ID3D10ShaderReflection *iface,
1941 UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc)
1943 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1945 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
1947 if (!desc || !reflection->isgn || index >= reflection->isgn->element_count)
1949 WARN("Invalid argument specified.\n");
1950 return E_INVALIDARG;
1953 memcpy(desc, &reflection->isgn->elements[index], sizeof(*desc));
1955 return S_OK;
1958 static HRESULT STDMETHODCALLTYPE d3d10_shader_reflection_GetOutputParameterDesc(ID3D10ShaderReflection *iface,
1959 UINT index, D3D10_SIGNATURE_PARAMETER_DESC *desc)
1961 struct d3dcompiler_shader_reflection *reflection = impl_from_ID3D10ShaderReflection(iface);
1963 TRACE("iface %p, index %u, desc %p.\n", iface, index, desc);
1965 if (!desc || !reflection->osgn || index >= reflection->osgn->element_count)
1967 WARN("Invalid argument specified.\n");
1968 return E_INVALIDARG;
1971 memcpy(desc, &reflection->osgn->elements[index], sizeof(*desc));
1973 return S_OK;
1976 static const struct ID3D10ShaderReflectionVtbl d3d10_shader_reflection_vtbl =
1978 d3d10_shader_reflection_QueryInterface,
1979 d3d10_shader_reflection_AddRef,
1980 d3d10_shader_reflection_Release,
1981 d3d10_shader_reflection_GetDesc,
1982 d3d10_shader_reflection_GetConstantBufferByIndex,
1983 d3d10_shader_reflection_GetConstantBufferByName,
1984 d3d10_shader_reflection_GetResourceBindingDesc,
1985 d3d10_shader_reflection_GetInputParameterDesc,
1986 d3d10_shader_reflection_GetOutputParameterDesc,
1989 HRESULT WINAPI D3D10ReflectShader(const void *data, SIZE_T data_size, ID3D10ShaderReflection **reflector)
1991 struct d3dcompiler_shader_reflection *object;
1992 HRESULT hr;
1994 TRACE("data %p, data_size %lu, reflector %p.\n", data, data_size, reflector);
1996 if (!(object = heap_alloc_zero(sizeof(*object))))
1998 ERR("Failed to allocate D3D10 shader reflection object memory.\n");
1999 return E_OUTOFMEMORY;
2002 object->ID3D10ShaderReflection_iface.lpVtbl = &d3d10_shader_reflection_vtbl;
2003 object->refcount = 1;
2005 hr = d3dcompiler_shader_reflection_init(object, data, data_size);
2006 if (FAILED(hr))
2008 WARN("Failed to initialize shader reflection.\n");
2009 HeapFree(GetProcessHeap(), 0, object);
2010 return hr;
2013 *reflector = &object->ID3D10ShaderReflection_iface;
2015 TRACE("Created ID3D10ShaderReflection %p.\n", object);
2017 return S_OK;
2019 #endif
2021 HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void **reflector)
2023 struct d3dcompiler_shader_reflection *object;
2024 HRESULT hr;
2025 const DWORD *temp = data;
2027 TRACE("data %p, data_size %lu, riid %s, blob %p\n", data, data_size, debugstr_guid(riid), reflector);
2029 if (!data || data_size < 32)
2031 WARN("Invalid argument supplied.\n");
2032 return D3DERR_INVALIDCALL;
2035 if (temp[6] != data_size)
2037 WARN("Wrong size supplied.\n");
2038 #if D3D_COMPILER_VERSION >= 46
2039 return D3DERR_INVALIDCALL;
2040 #else
2041 return E_FAIL;
2042 #endif
2045 if (!IsEqualGUID(riid, &IID_ID3D11ShaderReflection))
2047 WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid), debugstr_guid(&IID_ID3D11ShaderReflection));
2048 #if D3D_COMPILER_VERSION >= 46
2049 return E_INVALIDARG;
2050 #else
2051 return E_NOINTERFACE;
2052 #endif
2055 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2056 if (!object)
2057 return E_OUTOFMEMORY;
2059 object->ID3D11ShaderReflection_iface.lpVtbl = &d3dcompiler_shader_reflection_vtbl;
2060 object->refcount = 1;
2062 hr = d3dcompiler_shader_reflection_init(object, data, data_size);
2063 if (FAILED(hr))
2065 WARN("Failed to initialize shader reflection\n");
2066 HeapFree(GetProcessHeap(), 0, object);
2067 return hr;
2070 *reflector = object;
2072 TRACE("Created ID3D11ShaderReflection %p\n", object);
2074 return S_OK;