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 "wine/port.h"
24 #include "d3dcompiler_private.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;
44 struct d3dcompiler_shader_reflection_type
46 ID3D11ShaderReflectionType ID3D11ShaderReflectionType_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;
57 struct d3dcompiler_shader_reflection_type_member
61 struct d3dcompiler_shader_reflection_type *type;
64 struct d3dcompiler_shader_reflection_variable
66 ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable_iface;
68 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffer;
69 struct d3dcompiler_shader_reflection_type *type;
78 struct d3dcompiler_shader_reflection_constant_buffer
80 ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer_iface;
82 struct d3dcompiler_shader_reflection *reflection;
85 D3D_CBUFFER_TYPE type;
90 struct d3dcompiler_shader_reflection_variable *variables;
93 /* ID3D11ShaderReflection */
94 struct d3dcompiler_shader_reflection
96 ID3D11ShaderReflection ID3D11ShaderReflection_iface;
103 UINT bound_resource_count;
104 UINT constant_buffer_count;
106 UINT mov_instruction_count;
107 UINT conversion_instruction_count;
108 UINT instruction_count;
109 UINT emit_instruction_count;
110 D3D_PRIMITIVE_TOPOLOGY gs_output_topology;
111 UINT gs_max_output_vertex_count;
112 D3D_PRIMITIVE input_primitive;
113 UINT cut_instruction_count;
115 UINT static_flow_control_count;
116 UINT float_instruction_count;
117 UINT temp_register_count;
118 UINT int_instruction_count;
119 UINT uint_instruction_count;
120 UINT temp_array_count;
121 UINT array_instruction_count;
122 UINT texture_normal_instructions;
123 UINT texture_load_instructions;
124 UINT texture_comp_instructions;
125 UINT texture_bias_instructions;
126 UINT texture_gradient_instructions;
127 UINT dynamic_flow_control_count;
128 UINT c_control_points;
129 D3D_TESSELLATOR_OUTPUT_PRIMITIVE hs_output_primitive;
130 D3D_TESSELLATOR_PARTITIONING hs_prtitioning;
131 D3D_TESSELLATOR_DOMAIN tessellator_domain;
133 struct d3dcompiler_shader_signature *isgn;
134 struct d3dcompiler_shader_signature *osgn;
135 struct d3dcompiler_shader_signature *pcsg;
136 char *resource_string;
137 D3D11_SHADER_INPUT_BIND_DESC *bound_resources;
138 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers;
139 struct wine_rb_tree types;
142 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset);
144 const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl;
145 const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl;
146 const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl;
148 /* null objects - needed for invalid calls */
149 static struct d3dcompiler_shader_reflection_constant_buffer null_constant_buffer = {{&d3dcompiler_shader_reflection_constant_buffer_vtbl}};
150 static struct d3dcompiler_shader_reflection_type null_type = {{&d3dcompiler_shader_reflection_type_vtbl}};
151 static struct d3dcompiler_shader_reflection_variable null_variable = {{&d3dcompiler_shader_reflection_variable_vtbl},
152 &null_constant_buffer, &null_type};
154 static BOOL copy_name(const char *ptr, char **name)
158 if (!ptr) return TRUE;
160 name_len = strlen(ptr) + 1;
166 *name = HeapAlloc(GetProcessHeap(), 0, name_len);
169 ERR("Failed to allocate name memory.\n");
173 memcpy(*name, ptr, name_len);
178 static BOOL copy_value(const char *ptr, void **value, DWORD size)
180 if (!ptr || !size) return TRUE;
182 *value = HeapAlloc(GetProcessHeap(), 0, size);
185 ERR("Failed to allocate vlaue memory.\n");
189 memcpy(*value, ptr, size);
194 static void *d3dcompiler_rb_alloc(size_t size)
196 return HeapAlloc(GetProcessHeap(), 0, size);
199 static void *d3dcompiler_rb_realloc(void *ptr, size_t size)
201 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
204 static void d3dcompiler_rb_free(void *ptr)
206 HeapFree(GetProcessHeap(), 0, ptr);
209 static int d3dcompiler_shader_reflection_type_compare(const void *key, const struct wine_rb_entry *entry)
211 const struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3dcompiler_shader_reflection_type, entry);
212 const DWORD *id = key;
217 static void free_type_member(struct d3dcompiler_shader_reflection_type_member *member)
221 HeapFree(GetProcessHeap(), 0, member->name);
225 static void d3dcompiler_shader_reflection_type_destroy(struct wine_rb_entry *entry, void *context)
227 struct d3dcompiler_shader_reflection_type *t = WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
230 TRACE("reflection type %p.\n", t);
234 for (i = 0; i < t->desc.Members; ++i)
236 free_type_member(&t->members[i]);
240 HeapFree(GetProcessHeap(), 0, t);
243 static const struct wine_rb_functions d3dcompiler_shader_reflection_type_rb_functions =
245 d3dcompiler_rb_alloc,
246 d3dcompiler_rb_realloc,
248 d3dcompiler_shader_reflection_type_compare,
251 static void free_signature(struct d3dcompiler_shader_signature *sig)
253 TRACE("Free signature %p\n", sig);
255 HeapFree(GetProcessHeap(), 0, sig->elements);
256 HeapFree(GetProcessHeap(), 0, sig->string_data);
259 static void free_variable(struct d3dcompiler_shader_reflection_variable *var)
263 HeapFree(GetProcessHeap(), 0, var->name);
264 HeapFree(GetProcessHeap(), 0, var->default_value);
268 static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer *cb)
274 for (i = 0; i < cb->variable_count; ++i)
276 free_variable(&cb->variables[i]);
278 HeapFree(GetProcessHeap(), 0, cb->variables);
281 HeapFree(GetProcessHeap(), 0, cb->name);
284 static void reflection_cleanup(struct d3dcompiler_shader_reflection *ref)
286 TRACE("Cleanup %p\n", ref);
290 free_signature(ref->isgn);
291 HeapFree(GetProcessHeap(), 0, ref->isgn);
296 free_signature(ref->osgn);
297 HeapFree(GetProcessHeap(), 0, ref->osgn);
302 free_signature(ref->pcsg);
303 HeapFree(GetProcessHeap(), 0, ref->pcsg);
306 if (ref->constant_buffers)
310 for (i = 0; i < ref->constant_buffer_count; ++i)
312 free_constant_buffer(&ref->constant_buffers[i]);
316 wine_rb_destroy(&ref->types, d3dcompiler_shader_reflection_type_destroy, NULL);
317 HeapFree(GetProcessHeap(), 0, ref->constant_buffers);
318 HeapFree(GetProcessHeap(), 0, ref->bound_resources);
319 HeapFree(GetProcessHeap(), 0, ref->resource_string);
320 HeapFree(GetProcessHeap(), 0, ref->creator);
323 /* IUnknown methods */
325 static inline struct d3dcompiler_shader_reflection *impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection *iface)
327 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection, ID3D11ShaderReflection_iface);
330 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection *iface, REFIID riid, void **object)
332 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
334 if (IsEqualGUID(riid, &IID_ID3D11ShaderReflection)
335 || IsEqualGUID(riid, &IID_IUnknown))
337 IUnknown_AddRef(iface);
342 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
345 return E_NOINTERFACE;
348 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection *iface)
350 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
351 ULONG refcount = InterlockedIncrement(&This->refcount);
353 TRACE("%p increasing refcount to %u\n", This, refcount);
358 static ULONG STDMETHODCALLTYPE d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection *iface)
360 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
361 ULONG refcount = InterlockedDecrement(&This->refcount);
363 TRACE("%p decreasing refcount to %u\n", This, refcount);
367 reflection_cleanup(This);
368 HeapFree(GetProcessHeap(), 0, This);
374 /* ID3D11ShaderReflection methods */
376 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection *iface, D3D11_SHADER_DESC *desc)
378 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
380 FIXME("iface %p, desc %p partial stub!\n", iface, desc);
384 WARN("Invalid argument specified\n");
388 desc->Version = This->version;
389 desc->Creator = This->creator;
390 desc->Flags = This->flags;
391 desc->ConstantBuffers = This->constant_buffer_count;
392 desc->BoundResources = This->bound_resource_count;
393 desc->InputParameters = This->isgn ? This->isgn->element_count : 0;
394 desc->OutputParameters = This->osgn ? This->osgn->element_count : 0;
395 desc->InstructionCount = This->instruction_count;
396 desc->TempRegisterCount = This->temp_register_count;
397 desc->TempArrayCount = This->temp_array_count;
399 desc->DclCount = This->dcl_count;
400 desc->TextureNormalInstructions = This->texture_normal_instructions;
401 desc->TextureLoadInstructions = This->texture_load_instructions;
402 desc->TextureCompInstructions = This->texture_comp_instructions;
403 desc->TextureBiasInstructions = This->texture_bias_instructions;
404 desc->TextureGradientInstructions = This->texture_gradient_instructions;
405 desc->FloatInstructionCount = This->float_instruction_count;
406 desc->IntInstructionCount = This->int_instruction_count;
407 desc->UintInstructionCount = This->uint_instruction_count;
408 desc->StaticFlowControlCount = This->static_flow_control_count;
409 desc->DynamicFlowControlCount = This->dynamic_flow_control_count;
410 desc->MacroInstructionCount = 0;
411 desc->ArrayInstructionCount = This->array_instruction_count;
412 desc->CutInstructionCount = This->cut_instruction_count;
413 desc->EmitInstructionCount = This->emit_instruction_count;
414 desc->GSOutputTopology = This->gs_output_topology;
415 desc->GSMaxOutputVertexCount = This->gs_max_output_vertex_count;
416 desc->InputPrimitive = This->input_primitive;
417 desc->PatchConstantParameters = This->pcsg ? This->pcsg->element_count : 0;
418 desc->cGSInstanceCount = 0;
419 desc->cControlPoints = This->c_control_points;
420 desc->HSOutputPrimitive = This->hs_output_primitive;
421 desc->HSPartitioning = This->hs_prtitioning;
422 desc->TessellatorDomain = This->tessellator_domain;
423 desc->cBarrierInstructions = 0;
424 desc->cInterlockedInstructions = 0;
425 desc->cTextureStoreInstructions = 0;
430 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByIndex(
431 ID3D11ShaderReflection *iface, UINT index)
433 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
435 TRACE("iface %p, index %u\n", iface, index);
437 if (index >= This->constant_buffer_count)
439 WARN("Invalid argument specified\n");
440 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
443 return &This->constant_buffers[index].ID3D11ShaderReflectionConstantBuffer_iface;
446 static struct ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConstantBufferByName(
447 ID3D11ShaderReflection *iface, LPCSTR name)
449 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
452 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
456 WARN("Invalid argument specified\n");
457 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
460 for (i = 0; i < This->constant_buffer_count; ++i)
462 struct d3dcompiler_shader_reflection_constant_buffer *d = &This->constant_buffers[i];
464 if (!strcmp(d->name, name))
466 TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d);
467 return &d->ID3D11ShaderReflectionConstantBuffer_iface;
471 WARN("Invalid name specified\n");
473 return &null_constant_buffer.ID3D11ShaderReflectionConstantBuffer_iface;
476 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDesc(
477 ID3D11ShaderReflection *iface, UINT index, D3D11_SHADER_INPUT_BIND_DESC *desc)
479 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
481 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
483 if (!desc || index >= This->bound_resource_count)
485 WARN("Invalid argument specified\n");
489 *desc = This->bound_resources[index];
494 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetInputParameterDesc(
495 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
497 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
499 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
501 if (!desc || !This->isgn || index >= This->isgn->element_count)
503 WARN("Invalid argument specified\n");
507 *desc = This->isgn->elements[index];
512 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetOutputParameterDesc(
513 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
515 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
517 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
519 if (!desc || !This->osgn || index >= This->osgn->element_count)
521 WARN("Invalid argument specified\n");
525 *desc = This->osgn->elements[index];
530 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
531 ID3D11ShaderReflection *iface, UINT index, D3D11_SIGNATURE_PARAMETER_DESC *desc)
533 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
535 TRACE("iface %p, index %u, desc %p\n", iface, index, desc);
537 if (!desc || !This->pcsg || index >= This->pcsg->element_count)
539 WARN("Invalid argument specified\n");
543 *desc = This->pcsg->elements[index];
548 static struct ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetVariableByName(
549 ID3D11ShaderReflection *iface, LPCSTR name)
551 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
554 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
558 WARN("Invalid name specified\n");
559 return &null_variable.ID3D11ShaderReflectionVariable_iface;
562 for (i = 0; i < This->constant_buffer_count; ++i)
564 struct d3dcompiler_shader_reflection_constant_buffer *cb = &This->constant_buffers[i];
566 for (k = 0; k < cb->variable_count; ++k)
568 struct d3dcompiler_shader_reflection_variable *v = &cb->variables[k];
570 if (!strcmp(v->name, name))
572 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
573 return &v->ID3D11ShaderReflectionVariable_iface;
578 WARN("Invalid name specified\n");
580 return &null_variable.ID3D11ShaderReflectionVariable_iface;
583 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetResourceBindingDescByName(
584 ID3D11ShaderReflection *iface, LPCSTR name, D3D11_SHADER_INPUT_BIND_DESC *desc)
586 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
589 TRACE("iface %p, name %s, desc %p\n", iface, debugstr_a(name), desc);
593 WARN("Invalid argument specified\n");
597 for (i = 0; i < This->bound_resource_count; ++i)
599 D3D11_SHADER_INPUT_BIND_DESC *d = &This->bound_resources[i];
601 if (!strcmp(d->Name, name))
603 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d);
609 WARN("Invalid name specified\n");
614 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovInstructionCount(
615 ID3D11ShaderReflection *iface)
617 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
619 TRACE("iface %p\n", iface);
621 return This->mov_instruction_count;
624 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMovcInstructionCount(
625 ID3D11ShaderReflection *iface)
627 FIXME("iface %p stub!\n", iface);
632 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetConversionInstructionCount(
633 ID3D11ShaderReflection *iface)
635 struct d3dcompiler_shader_reflection *This = impl_from_ID3D11ShaderReflection(iface);
637 TRACE("iface %p\n", iface);
639 return This->conversion_instruction_count;
642 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
643 ID3D11ShaderReflection *iface)
645 FIXME("iface %p stub!\n", iface);
650 static D3D_PRIMITIVE STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetGSInputPrimitive(
651 ID3D11ShaderReflection *iface)
653 FIXME("iface %p stub!\n", iface);
658 static BOOL STDMETHODCALLTYPE d3dcompiler_shader_reflection_IsSampleFrequencyShader(
659 ID3D11ShaderReflection *iface)
661 FIXME("iface %p stub!\n", iface);
666 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetNumInterfaceSlots(
667 ID3D11ShaderReflection *iface)
669 FIXME("iface %p stub!\n", iface);
674 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetMinFeatureLevel(
675 ID3D11ShaderReflection *iface, D3D_FEATURE_LEVEL *level)
677 FIXME("iface %p, level %p stub!\n", iface, level);
682 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_GetThreadGroupSize(
683 ID3D11ShaderReflection *iface, UINT *sizex, UINT *sizey, UINT *sizez)
685 FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface, sizex, sizey, sizez);
690 const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl =
692 /* IUnknown methods */
693 d3dcompiler_shader_reflection_QueryInterface,
694 d3dcompiler_shader_reflection_AddRef,
695 d3dcompiler_shader_reflection_Release,
696 /* ID3D11ShaderReflection methods */
697 d3dcompiler_shader_reflection_GetDesc,
698 d3dcompiler_shader_reflection_GetConstantBufferByIndex,
699 d3dcompiler_shader_reflection_GetConstantBufferByName,
700 d3dcompiler_shader_reflection_GetResourceBindingDesc,
701 d3dcompiler_shader_reflection_GetInputParameterDesc,
702 d3dcompiler_shader_reflection_GetOutputParameterDesc,
703 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc,
704 d3dcompiler_shader_reflection_GetVariableByName,
705 d3dcompiler_shader_reflection_GetResourceBindingDescByName,
706 d3dcompiler_shader_reflection_GetMovInstructionCount,
707 d3dcompiler_shader_reflection_GetMovcInstructionCount,
708 d3dcompiler_shader_reflection_GetConversionInstructionCount,
709 d3dcompiler_shader_reflection_GetBitwiseInstructionCount,
710 d3dcompiler_shader_reflection_GetGSInputPrimitive,
711 d3dcompiler_shader_reflection_IsSampleFrequencyShader,
712 d3dcompiler_shader_reflection_GetNumInterfaceSlots,
713 d3dcompiler_shader_reflection_GetMinFeatureLevel,
714 d3dcompiler_shader_reflection_GetThreadGroupSize,
717 /* ID3D11ShaderReflectionConstantBuffer methods */
719 static inline struct d3dcompiler_shader_reflection_constant_buffer *impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer *iface)
721 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_constant_buffer, ID3D11ShaderReflectionConstantBuffer_iface);
724 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetDesc(
725 ID3D11ShaderReflectionConstantBuffer *iface, D3D11_SHADER_BUFFER_DESC *desc)
727 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
729 TRACE("iface %p, desc %p\n", iface, desc);
731 if (This == &null_constant_buffer)
733 WARN("Null constant buffer specified\n");
739 WARN("Invalid argument specified\n");
743 desc->Name = This->name;
744 desc->Type = This->type;
745 desc->Variables = This->variable_count;
746 desc->Size = This->size;
747 desc->uFlags = This->flags;
752 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex(
753 ID3D11ShaderReflectionConstantBuffer *iface, UINT index)
755 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
757 TRACE("iface %p, index %u\n", iface, index);
759 if (index >= This->variable_count)
761 WARN("Invalid index specified\n");
762 return &null_variable.ID3D11ShaderReflectionVariable_iface;
765 return &This->variables[index].ID3D11ShaderReflectionVariable_iface;
768 static ID3D11ShaderReflectionVariable * STDMETHODCALLTYPE d3dcompiler_shader_reflection_constant_buffer_GetVariableByName(
769 ID3D11ShaderReflectionConstantBuffer *iface, LPCSTR name)
771 struct d3dcompiler_shader_reflection_constant_buffer *This = impl_from_ID3D11ShaderReflectionConstantBuffer(iface);
774 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
778 WARN("Invalid argument specified\n");
779 return &null_variable.ID3D11ShaderReflectionVariable_iface;
782 for (i = 0; i < This->variable_count; ++i)
784 struct d3dcompiler_shader_reflection_variable *v = &This->variables[i];
786 if (!strcmp(v->name, name))
788 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v);
789 return &v->ID3D11ShaderReflectionVariable_iface;
793 WARN("Invalid name specified\n");
795 return &null_variable.ID3D11ShaderReflectionVariable_iface;
798 const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl =
800 /* ID3D11ShaderReflectionConstantBuffer methods */
801 d3dcompiler_shader_reflection_constant_buffer_GetDesc,
802 d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex,
803 d3dcompiler_shader_reflection_constant_buffer_GetVariableByName,
806 /* ID3D11ShaderReflectionVariable methods */
808 static inline struct d3dcompiler_shader_reflection_variable *impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable *iface)
810 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_variable, ID3D11ShaderReflectionVariable_iface);
813 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetDesc(
814 ID3D11ShaderReflectionVariable *iface, D3D11_SHADER_VARIABLE_DESC *desc)
816 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
818 TRACE("iface %p, desc %p\n", iface, desc);
820 if (This == &null_variable)
822 WARN("Null variable specified\n");
828 WARN("Invalid argument specified\n");
832 desc->Name = This->name;
833 desc->StartOffset = This->start_offset;
834 desc->Size = This->size;
835 desc->uFlags = This->flags;
836 desc->DefaultValue = This->default_value;
841 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetType(
842 ID3D11ShaderReflectionVariable *iface)
844 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
846 TRACE("iface %p\n", iface);
848 return &This->type->ID3D11ShaderReflectionType_iface;
851 static ID3D11ShaderReflectionConstantBuffer * STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetBuffer(
852 ID3D11ShaderReflectionVariable *iface)
854 struct d3dcompiler_shader_reflection_variable *This = impl_from_ID3D11ShaderReflectionVariable(iface);
856 TRACE("iface %p\n", iface);
858 return &This->constant_buffer->ID3D11ShaderReflectionConstantBuffer_iface;
861 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_variable_GetInterfaceSlot(
862 ID3D11ShaderReflectionVariable *iface, UINT index)
864 FIXME("iface %p, index %u stub!\n", iface, index);
869 const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl =
871 /* ID3D11ShaderReflectionVariable methods */
872 d3dcompiler_shader_reflection_variable_GetDesc,
873 d3dcompiler_shader_reflection_variable_GetType,
874 d3dcompiler_shader_reflection_variable_GetBuffer,
875 d3dcompiler_shader_reflection_variable_GetInterfaceSlot,
878 /* ID3D11ShaderReflectionType methods */
880 static inline struct d3dcompiler_shader_reflection_type *impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType *iface)
882 return CONTAINING_RECORD(iface, struct d3dcompiler_shader_reflection_type, ID3D11ShaderReflectionType_iface);
885 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetDesc(
886 ID3D11ShaderReflectionType *iface, D3D11_SHADER_TYPE_DESC *desc)
888 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
890 TRACE("iface %p, desc %p\n", iface, desc);
892 if (This == &null_type)
894 WARN("Null type specified\n");
900 WARN("Invalid argument specified\n");
909 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByIndex(
910 ID3D11ShaderReflectionType *iface, UINT index)
912 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
914 TRACE("iface %p, index %u\n", iface, index);
916 if (index >= This->desc.Members)
918 WARN("Invalid index specified\n");
919 return &null_type.ID3D11ShaderReflectionType_iface;
922 return &This->members[index].type->ID3D11ShaderReflectionType_iface;
925 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeByName(
926 ID3D11ShaderReflectionType *iface, LPCSTR name)
928 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
931 TRACE("iface %p, name %s\n", iface, debugstr_a(name));
935 WARN("Invalid argument specified\n");
936 return &null_type.ID3D11ShaderReflectionType_iface;
939 for (i = 0; i < This->desc.Members; ++i)
941 struct d3dcompiler_shader_reflection_type_member *member = &This->members[i];
943 if (!strcmp(member->name, name))
945 TRACE("Returning ID3D11ShaderReflectionType %p.\n", member->type);
946 return &member->type->ID3D11ShaderReflectionType_iface;
950 WARN("Invalid name specified\n");
952 return &null_type.ID3D11ShaderReflectionType_iface;
955 static LPCSTR STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetMemberTypeName(
956 ID3D11ShaderReflectionType *iface, UINT index)
958 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
960 TRACE("iface %p, index %u\n", iface, index);
962 if (This == &null_type)
964 WARN("Null type specified\n");
968 if (index >= This->desc.Members)
970 WARN("Invalid index specified\n");
974 return This->members[index].name;
977 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsEqual(
978 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
980 struct d3dcompiler_shader_reflection_type *This = impl_from_ID3D11ShaderReflectionType(iface);
982 TRACE("iface %p, type %p\n", iface, type);
984 if (This == &null_type)
986 WARN("Null type specified\n");
996 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetSubType(
997 ID3D11ShaderReflectionType *iface)
999 FIXME("iface %p stub!\n", iface);
1004 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetBaseClass(
1005 ID3D11ShaderReflectionType *iface)
1007 FIXME("iface %p stub!\n", iface);
1012 static UINT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetNumInterfaces(
1013 ID3D11ShaderReflectionType *iface)
1015 FIXME("iface %p stub!\n", iface);
1020 static ID3D11ShaderReflectionType * STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_GetInterfaceByIndex(
1021 ID3D11ShaderReflectionType *iface, UINT index)
1023 FIXME("iface %p, index %u stub!\n", iface, index);
1028 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_IsOfType(
1029 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *type)
1031 FIXME("iface %p, type %p stub!\n", iface, type);
1036 static HRESULT STDMETHODCALLTYPE d3dcompiler_shader_reflection_type_ImplementsInterface(
1037 ID3D11ShaderReflectionType *iface, ID3D11ShaderReflectionType *base)
1039 FIXME("iface %p, base %p stub!\n", iface, base);
1044 const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl =
1046 /* ID3D11ShaderReflectionType methods */
1047 d3dcompiler_shader_reflection_type_GetDesc,
1048 d3dcompiler_shader_reflection_type_GetMemberTypeByIndex,
1049 d3dcompiler_shader_reflection_type_GetMemberTypeByName,
1050 d3dcompiler_shader_reflection_type_GetMemberTypeName,
1051 d3dcompiler_shader_reflection_type_IsEqual,
1052 d3dcompiler_shader_reflection_type_GetSubType,
1053 d3dcompiler_shader_reflection_type_GetBaseClass,
1054 d3dcompiler_shader_reflection_type_GetNumInterfaces,
1055 d3dcompiler_shader_reflection_type_GetInterfaceByIndex,
1056 d3dcompiler_shader_reflection_type_IsOfType,
1057 d3dcompiler_shader_reflection_type_ImplementsInterface,
1060 static HRESULT d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1062 const char *ptr = data;
1063 DWORD size = data_size >> 2;
1065 TRACE("Size %u\n", size);
1067 read_dword(&ptr, &r->instruction_count);
1068 TRACE("InstructionCount: %u\n", r->instruction_count);
1070 read_dword(&ptr, &r->temp_register_count);
1071 TRACE("TempRegisterCount: %u\n", r->temp_register_count);
1073 skip_dword_unknown(&ptr, 1);
1075 read_dword(&ptr, &r->dcl_count);
1076 TRACE("DclCount: %u\n", r->dcl_count);
1078 read_dword(&ptr, &r->float_instruction_count);
1079 TRACE("FloatInstructionCount: %u\n", r->float_instruction_count);
1081 read_dword(&ptr, &r->int_instruction_count);
1082 TRACE("IntInstructionCount: %u\n", r->int_instruction_count);
1084 read_dword(&ptr, &r->uint_instruction_count);
1085 TRACE("UintInstructionCount: %u\n", r->uint_instruction_count);
1087 read_dword(&ptr, &r->static_flow_control_count);
1088 TRACE("StaticFlowControlCount: %u\n", r->static_flow_control_count);
1090 read_dword(&ptr, &r->dynamic_flow_control_count);
1091 TRACE("DynamicFlowControlCount: %u\n", r->dynamic_flow_control_count);
1093 skip_dword_unknown(&ptr, 1);
1095 read_dword(&ptr, &r->temp_array_count);
1096 TRACE("TempArrayCount: %u\n", r->temp_array_count);
1098 read_dword(&ptr, &r->array_instruction_count);
1099 TRACE("ArrayInstructionCount: %u\n", r->array_instruction_count);
1101 read_dword(&ptr, &r->cut_instruction_count);
1102 TRACE("CutInstructionCount: %u\n", r->cut_instruction_count);
1104 read_dword(&ptr, &r->emit_instruction_count);
1105 TRACE("EmitInstructionCount: %u\n", r->emit_instruction_count);
1107 read_dword(&ptr, &r->texture_normal_instructions);
1108 TRACE("TextureNormalInstructions: %u\n", r->texture_normal_instructions);
1110 read_dword(&ptr, &r->texture_load_instructions);
1111 TRACE("TextureLoadInstructions: %u\n", r->texture_load_instructions);
1113 read_dword(&ptr, &r->texture_comp_instructions);
1114 TRACE("TextureCompInstructions: %u\n", r->texture_comp_instructions);
1116 read_dword(&ptr, &r->texture_bias_instructions);
1117 TRACE("TextureBiasInstructions: %u\n", r->texture_bias_instructions);
1119 read_dword(&ptr, &r->texture_gradient_instructions);
1120 TRACE("TextureGradientInstructions: %u\n", r->texture_gradient_instructions);
1122 read_dword(&ptr, &r->mov_instruction_count);
1123 TRACE("MovInstructionCount: %u\n", r->mov_instruction_count);
1125 skip_dword_unknown(&ptr, 1);
1127 read_dword(&ptr, &r->conversion_instruction_count);
1128 TRACE("ConversionInstructionCount: %u\n", r->conversion_instruction_count);
1130 skip_dword_unknown(&ptr, 1);
1132 read_dword(&ptr, &r->input_primitive);
1133 TRACE("InputPrimitive: %x\n", r->input_primitive);
1135 read_dword(&ptr, &r->gs_output_topology);
1136 TRACE("GSOutputTopology: %x\n", r->gs_output_topology);
1138 read_dword(&ptr, &r->gs_max_output_vertex_count);
1139 TRACE("GSMaxOutputVertexCount: %u\n", r->gs_max_output_vertex_count);
1141 skip_dword_unknown(&ptr, 3);
1143 /* dx10 stat size */
1144 if (size == 29) return S_OK;
1146 skip_dword_unknown(&ptr, 1);
1148 read_dword(&ptr, &r->c_control_points);
1149 TRACE("cControlPoints: %u\n", r->c_control_points);
1151 read_dword(&ptr, &r->hs_output_primitive);
1152 TRACE("HSOutputPrimitive: %x\n", r->hs_output_primitive);
1154 read_dword(&ptr, &r->hs_prtitioning);
1155 TRACE("HSPartitioning: %x\n", r->hs_prtitioning);
1157 read_dword(&ptr, &r->tessellator_domain);
1158 TRACE("TessellatorDomain: %x\n", r->tessellator_domain);
1160 skip_dword_unknown(&ptr, 3);
1162 /* dx11 stat size */
1163 if (size == 37) return S_OK;
1165 FIXME("Unhandled size %u\n", size);
1170 static HRESULT d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection *ref,
1171 struct d3dcompiler_shader_reflection_type_member *member, const char *data, const char **ptr)
1175 read_dword(ptr, &offset);
1176 if (!copy_name(data + offset, &member->name))
1178 ERR("Failed to copy name.\n");
1179 return E_OUTOFMEMORY;
1181 TRACE("Member name: %s.\n", debugstr_a(member->name));
1183 read_dword(ptr, &offset);
1184 TRACE("Member type offset: %x\n", offset);
1186 member->type = get_reflection_type(ref, data, offset);
1189 ERR("Failed to get member type\n");
1190 HeapFree(GetProcessHeap(), 0, member->name);
1194 read_dword(ptr, &member->offset);
1195 TRACE("Member offset %x\n", member->offset);
1200 static HRESULT d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type *type, const char *data, DWORD offset)
1202 const char *ptr = data + offset;
1204 D3D11_SHADER_TYPE_DESC *desc;
1206 struct d3dcompiler_shader_reflection_type_member *members;
1208 DWORD member_offset;
1212 read_dword(&ptr, &temp);
1213 desc->Class = temp & 0xffff;
1214 desc->Type = temp >> 16;
1215 TRACE("Class %s, Type %s\n", debug_d3dcompiler_shader_variable_class(desc->Class),
1216 debug_d3dcompiler_shader_variable_type(desc->Type));
1218 read_dword(&ptr, &temp);
1219 desc->Rows = temp & 0xffff;
1220 desc->Columns = temp >> 16;
1221 TRACE("Rows %u, Columns %u\n", desc->Rows, desc->Columns);
1223 read_dword(&ptr, &temp);
1224 desc->Elements = temp & 0xffff;
1225 desc->Members = temp >> 16;
1226 TRACE("Elements %u, Members %u\n", desc->Elements, desc->Members);
1228 read_dword(&ptr, &member_offset);
1229 TRACE("Member Offset %u\n", member_offset);
1231 if ((type->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1232 skip_dword_unknown(&ptr, 4);
1236 const char *ptr2 = data + member_offset;
1238 members = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*members));
1241 ERR("Failed to allocate type memory.\n");
1242 return E_OUTOFMEMORY;
1245 for (i = 0; i < desc->Members; ++i)
1247 hr = d3dcompiler_parse_type_members(type->reflection, &members[i], data, &ptr2);
1250 FIXME("Failed to parse type members.");
1256 type->members = members;
1261 for (i = 0; i < desc->Members; ++i)
1263 free_type_member(&members[i]);
1265 HeapFree(GetProcessHeap(), 0, members);
1269 static struct d3dcompiler_shader_reflection_type *get_reflection_type(struct d3dcompiler_shader_reflection *reflection, const char *data, DWORD offset)
1271 struct d3dcompiler_shader_reflection_type *type;
1272 struct wine_rb_entry *entry;
1275 entry = wine_rb_get(&reflection->types, &offset);
1278 TRACE("Returning existing type.\n");
1279 return WINE_RB_ENTRY_VALUE(entry, struct d3dcompiler_shader_reflection_type, entry);
1282 type = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*type));
1285 ERR("Failed to allocate type memory.\n");
1289 type->ID3D11ShaderReflectionType_iface.lpVtbl = &d3dcompiler_shader_reflection_type_vtbl;
1291 type->reflection = reflection;
1293 hr = d3dcompiler_parse_type(type, data, offset);
1296 ERR("Failed to parse type info, hr %#x.\n", hr);
1297 HeapFree(GetProcessHeap(), 0, type);
1301 if (wine_rb_put(&reflection->types, &offset, &type->entry) == -1)
1303 ERR("Failed to insert type entry.\n");
1304 HeapFree(GetProcessHeap(), 0, type);
1311 static HRESULT d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer *cb,
1312 const char *data, DWORD data_size, const char *ptr)
1314 struct d3dcompiler_shader_reflection_variable *variables;
1318 variables = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb->variable_count * sizeof(*variables));
1321 ERR("Failed to allocate variables memory.\n");
1322 return E_OUTOFMEMORY;
1325 for (i = 0; i < cb->variable_count; i++)
1327 struct d3dcompiler_shader_reflection_variable *v = &variables[i];
1330 v->ID3D11ShaderReflectionVariable_iface.lpVtbl = &d3dcompiler_shader_reflection_variable_vtbl;
1331 v->constant_buffer = cb;
1333 read_dword(&ptr, &offset);
1334 if (!copy_name(data + offset, &v->name))
1336 ERR("Failed to copy name.\n");
1340 TRACE("Variable name: %s.\n", debugstr_a(v->name));
1342 read_dword(&ptr, &v->start_offset);
1343 TRACE("Variable offset: %u\n", v->start_offset);
1345 read_dword(&ptr, &v->size);
1346 TRACE("Variable size: %u\n", v->size);
1348 read_dword(&ptr, &v->flags);
1349 TRACE("Variable flags: %u\n", v->flags);
1351 read_dword(&ptr, &offset);
1352 TRACE("Variable type offset: %x\n", offset);
1353 v->type = get_reflection_type(cb->reflection, data, offset);
1356 ERR("Failed to get type.\n");
1361 read_dword(&ptr, &offset);
1362 TRACE("Variable default value offset: %x\n", offset);
1363 if (!copy_value(data + offset, &v->default_value, offset ? v->size : 0))
1365 ERR("Failed to copy name.\n");
1370 if ((cb->reflection->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1371 skip_dword_unknown(&ptr, 4);
1374 cb->variables = variables;
1379 for (i = 0; i < cb->variable_count; i++)
1381 free_variable(&variables[i]);
1383 HeapFree(GetProcessHeap(), 0, variables);
1387 static HRESULT d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1389 const char *ptr = data;
1390 DWORD size = data_size >> 2;
1391 DWORD offset, cbuffer_offset, resource_offset, creator_offset;
1392 unsigned int i, string_data_offset, string_data_size;
1393 char *string_data = NULL, *creator = NULL;
1394 D3D11_SHADER_INPUT_BIND_DESC *bound_resources = NULL;
1395 struct d3dcompiler_shader_reflection_constant_buffer *constant_buffers = NULL;
1398 TRACE("Size %u\n", size);
1400 read_dword(&ptr, &r->constant_buffer_count);
1401 TRACE("Constant buffer count: %u\n", r->constant_buffer_count);
1403 read_dword(&ptr, &cbuffer_offset);
1404 TRACE("Constant buffer offset: %#x\n", cbuffer_offset);
1406 read_dword(&ptr, &r->bound_resource_count);
1407 TRACE("Bound resource count: %u\n", r->bound_resource_count);
1409 read_dword(&ptr, &resource_offset);
1410 TRACE("Bound resource offset: %#x\n", resource_offset);
1412 read_dword(&ptr, &r->target);
1413 TRACE("Target: %#x\n", r->target);
1415 read_dword(&ptr, &r->flags);
1416 TRACE("Flags: %u\n", r->flags);
1418 read_dword(&ptr, &creator_offset);
1419 TRACE("Creator at offset %#x.\n", creator_offset);
1421 if (!copy_name(data + creator_offset, &creator))
1423 ERR("Failed to copy name.\n");
1424 return E_OUTOFMEMORY;
1426 TRACE("Creator: %s.\n", debugstr_a(creator));
1428 /* todo: Parse RD11 */
1429 if ((r->target & D3DCOMPILER_SHADER_TARGET_VERSION_MASK) >= 0x500)
1431 skip_dword_unknown(&ptr, 8);
1434 if (r->bound_resource_count)
1436 /* 8 for each bind desc */
1437 string_data_offset = resource_offset + r->bound_resource_count * 8 * sizeof(DWORD);
1438 string_data_size = (cbuffer_offset ? cbuffer_offset : creator_offset) - string_data_offset;
1440 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1443 ERR("Failed to allocate string data memory.\n");
1447 memcpy(string_data, data + string_data_offset, string_data_size);
1449 bound_resources = HeapAlloc(GetProcessHeap(), 0, r->bound_resource_count * sizeof(*bound_resources));
1450 if (!bound_resources)
1452 ERR("Failed to allocate resources memory.\n");
1457 ptr = data + resource_offset;
1458 for (i = 0; i < r->bound_resource_count; i++)
1460 D3D11_SHADER_INPUT_BIND_DESC *desc = &bound_resources[i];
1462 read_dword(&ptr, &offset);
1463 desc->Name = string_data + (offset - string_data_offset);
1464 TRACE("Input bind Name: %s\n", debugstr_a(desc->Name));
1466 read_dword(&ptr, &desc->Type);
1467 TRACE("Input bind Type: %#x\n", desc->Type);
1469 read_dword(&ptr, &desc->ReturnType);
1470 TRACE("Input bind ReturnType: %#x\n", desc->ReturnType);
1472 read_dword(&ptr, &desc->Dimension);
1473 TRACE("Input bind Dimension: %#x\n", desc->Dimension);
1475 read_dword(&ptr, &desc->NumSamples);
1476 TRACE("Input bind NumSamples: %u\n", desc->NumSamples);
1478 read_dword(&ptr, &desc->BindPoint);
1479 TRACE("Input bind BindPoint: %u\n", desc->BindPoint);
1481 read_dword(&ptr, &desc->BindCount);
1482 TRACE("Input bind BindCount: %u\n", desc->BindCount);
1484 read_dword(&ptr, &desc->uFlags);
1485 TRACE("Input bind uFlags: %u\n", desc->uFlags);
1489 if (r->constant_buffer_count)
1491 constant_buffers = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, r->constant_buffer_count * sizeof(*constant_buffers));
1492 if (!constant_buffers)
1494 ERR("Failed to allocate constant buffer memory.\n");
1499 ptr = data + cbuffer_offset;
1500 for (i = 0; i < r->constant_buffer_count; i++)
1502 struct d3dcompiler_shader_reflection_constant_buffer *cb = &constant_buffers[i];
1504 cb->ID3D11ShaderReflectionConstantBuffer_iface.lpVtbl = &d3dcompiler_shader_reflection_constant_buffer_vtbl;
1507 read_dword(&ptr, &offset);
1508 if (!copy_name(data + offset, &cb->name))
1510 ERR("Failed to copy name.\n");
1514 TRACE("Name: %s.\n", debugstr_a(cb->name));
1516 read_dword(&ptr, &cb->variable_count);
1517 TRACE("Variable count: %u\n", cb->variable_count);
1519 read_dword(&ptr, &offset);
1520 TRACE("Variable offset: %x\n", offset);
1522 hr = d3dcompiler_parse_variables(cb, data, data_size, data + offset);
1525 FIXME("Failed to parse variables.");
1529 read_dword(&ptr, &cb->size);
1530 TRACE("Cbuffer size: %u\n", cb->size);
1532 read_dword(&ptr, &cb->flags);
1533 TRACE("Cbuffer flags: %u\n", cb->flags);
1535 read_dword(&ptr, &cb->type);
1536 TRACE("Cbuffer type: %#x\n", cb->type);
1540 r->creator = creator;
1541 r->resource_string = string_data;
1542 r->bound_resources = bound_resources;
1543 r->constant_buffers = constant_buffers;
1548 for (i = 0; i < r->constant_buffer_count; ++i)
1550 free_constant_buffer(&constant_buffers[i]);
1552 HeapFree(GetProcessHeap(), 0, constant_buffers);
1553 HeapFree(GetProcessHeap(), 0, bound_resources);
1554 HeapFree(GetProcessHeap(), 0, string_data);
1555 HeapFree(GetProcessHeap(), 0, creator);
1560 static HRESULT d3dcompiler_parse_signature(struct d3dcompiler_shader_signature *s, struct dxbc_section *section, DWORD target)
1562 D3D11_SIGNATURE_PARAMETER_DESC *d;
1563 unsigned int string_data_offset;
1564 unsigned int string_data_size;
1565 const char *ptr = section->data;
1569 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size;
1571 switch (section->tag)
1574 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7;
1580 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1584 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion->tag, 4));
1585 element_size = D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6;
1589 read_dword(&ptr, &count);
1590 TRACE("%u elements\n", count);
1592 skip_dword_unknown(&ptr, 1);
1594 d = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*d));
1597 ERR("Failed to allocate signature memory.\n");
1598 return E_OUTOFMEMORY;
1601 /* 2 DWORDs for the header, element_size for each element. */
1602 string_data_offset = 2 * sizeof(DWORD) + count * element_size * sizeof(DWORD);
1603 string_data_size = section->data_size - string_data_offset;
1605 string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
1608 ERR("Failed to allocate string data memory.\n");
1609 HeapFree(GetProcessHeap(), 0, d);
1610 return E_OUTOFMEMORY;
1612 memcpy(string_data, section->data + string_data_offset, string_data_size);
1614 for (i = 0; i < count; ++i)
1619 if (element_size == D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7)
1621 read_dword(&ptr, &d[i].Stream);
1628 read_dword(&ptr, &name_offset);
1629 d[i].SemanticName = string_data + (name_offset - string_data_offset);
1630 read_dword(&ptr, &d[i].SemanticIndex);
1631 read_dword(&ptr, &d[i].SystemValueType);
1632 read_dword(&ptr, &d[i].ComponentType);
1633 read_dword(&ptr, &d[i].Register);
1634 read_dword(&ptr, &mask);
1635 d[i].ReadWriteMask = (mask >> 8) & 0xff;
1636 d[i].Mask = mask & 0xff;
1638 /* pixel shaders have a special handling for SystemValueType in the output signature */
1639 if (((target & D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK) == 0xffff0000) && (section->tag == TAG_OSG5 || section->tag == TAG_OSGN))
1641 TRACE("Pixelshader output signature fixup.\n");
1643 if (d[i].Register == 0xffffffff)
1645 if (!strcasecmp(d[i].SemanticName, "sv_depth")) d[i].SystemValueType = D3D_NAME_DEPTH;
1646 if (!strcasecmp(d[i].SemanticName, "sv_coverage")) d[i].SystemValueType = D3D_NAME_COVERAGE;
1647 if (!strcasecmp(d[i].SemanticName, "sv_depthgreaterequal")) d[i].SystemValueType = D3D_NAME_DEPTH_GREATER_EQUAL;
1648 if (!strcasecmp(d[i].SemanticName, "sv_depthlessequal")) d[i].SystemValueType = D3D_NAME_DEPTH_LESS_EQUAL;
1652 d[i].SystemValueType = D3D_NAME_TARGET;
1656 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
1657 "type %u, register idx: %u, use_mask %#x, input_mask %#x, stream %u\n",
1658 debugstr_a(d[i].SemanticName), d[i].SemanticIndex, d[i].SystemValueType,
1659 d[i].ComponentType, d[i].Register, d[i].Mask, d[i].ReadWriteMask, d[i].Stream);
1663 s->element_count = count;
1664 s->string_data = string_data;
1669 static HRESULT d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection *r, const char *data, DWORD data_size)
1671 const char *ptr = data;
1673 read_dword(&ptr, &r->version);
1674 TRACE("Shader version: %u\n", r->version);
1676 /* todo: Check if anything else is needed from the shdr or shex blob. */
1681 static HRESULT d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection *reflection,
1682 const void *data, SIZE_T data_size)
1684 struct dxbc src_dxbc;
1688 reflection->ID3D11ShaderReflection_iface.lpVtbl = &d3dcompiler_shader_reflection_vtbl;
1689 reflection->refcount = 1;
1691 if (wine_rb_init(&reflection->types, &d3dcompiler_shader_reflection_type_rb_functions) == -1)
1693 ERR("Failed to initialize type rbtree.\n");
1697 hr = dxbc_parse(data, data_size, &src_dxbc);
1700 WARN("Failed to parse reflection\n");
1704 for (i = 0; i < src_dxbc.count; ++i)
1706 struct dxbc_section *section = &src_dxbc.sections[i];
1708 switch (section->tag)
1711 hr = d3dcompiler_parse_rdef(reflection, section->data, section->data_size);
1714 WARN("Failed to parse RDEF section.\n");
1720 reflection->isgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->isgn));
1721 if (!reflection->isgn)
1723 ERR("Failed to allocate ISGN memory.\n");
1728 hr = d3dcompiler_parse_signature(reflection->isgn, section, reflection->target);
1731 WARN("Failed to parse section ISGN.\n");
1738 reflection->osgn = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->osgn));
1739 if (!reflection->osgn)
1741 ERR("Failed to allocate OSGN memory.\n");
1746 hr = d3dcompiler_parse_signature(reflection->osgn, section, reflection->target);
1749 WARN("Failed to parse section OSGN.\n");
1755 reflection->pcsg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*reflection->pcsg));
1756 if (!reflection->pcsg)
1758 ERR("Failed to allocate PCSG memory.\n");
1763 hr = d3dcompiler_parse_signature(reflection->pcsg, section, reflection->target);
1766 WARN("Failed to parse section PCSG.\n");
1773 hr = d3dcompiler_parse_shdr(reflection, section->data, section->data_size);
1776 WARN("Failed to parse SHDR section.\n");
1782 hr = d3dcompiler_parse_stat(reflection, section->data, section->data_size);
1785 WARN("Failed to parse section STAT.\n");
1791 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion->tag, 4));
1796 dxbc_destroy(&src_dxbc);
1801 reflection_cleanup(reflection);
1802 dxbc_destroy(&src_dxbc);
1807 HRESULT WINAPI D3DReflect(const void *data, SIZE_T data_size, REFIID riid, void **reflector)
1809 struct d3dcompiler_shader_reflection *object;
1811 const DWORD *temp = data;
1813 TRACE("data %p, data_size %lu, riid %s, blob %p\n", data, data_size, debugstr_guid(riid), reflector);
1815 if (!data || data_size < 32)
1817 WARN("Invalid argument supplied.\n");
1818 return D3DERR_INVALIDCALL;
1821 if (temp[6] != data_size)
1823 WARN("Wrong size supplied.\n");
1827 if (!IsEqualGUID(riid, &IID_ID3D11ShaderReflection))
1829 WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid), debugstr_guid(&IID_ID3D11ShaderReflection));
1830 return E_NOINTERFACE;
1833 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1836 ERR("Failed to allocate D3D compiler shader reflection object memory\n");
1837 return E_OUTOFMEMORY;
1840 hr = d3dcompiler_shader_reflection_init(object, data, data_size);
1843 WARN("Failed to initialize shader reflection\n");
1844 HeapFree(GetProcessHeap(), 0, object);
1848 *reflector = object;
1850 TRACE("Created ID3D11ShaderReflection %p\n", object);