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"
25 #include "d3dcompiler_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler
);
30 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE
32 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
= 6,
33 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
= 7,
36 #define D3DCOMPILER_SHADER_TARGET_VERSION_MASK 0xffff
37 #define D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK 0xffff0000
39 struct d3dcompiler_shader_signature
41 D3D11_SIGNATURE_PARAMETER_DESC
*elements
;
46 struct d3dcompiler_shader_reflection_type
48 ID3D11ShaderReflectionType ID3D11ShaderReflectionType_iface
;
51 struct wine_rb_entry entry
;
53 struct d3dcompiler_shader_reflection
*reflection
;
55 D3D11_SHADER_TYPE_DESC desc
;
56 struct d3dcompiler_shader_reflection_type_member
*members
;
59 struct d3dcompiler_shader_reflection_type_member
63 struct d3dcompiler_shader_reflection_type
*type
;
66 struct d3dcompiler_shader_reflection_variable
68 ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable_iface
;
70 struct d3dcompiler_shader_reflection_constant_buffer
*constant_buffer
;
71 struct d3dcompiler_shader_reflection_type
*type
;
80 struct d3dcompiler_shader_reflection_constant_buffer
82 ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer_iface
;
84 struct d3dcompiler_shader_reflection
*reflection
;
87 D3D_CBUFFER_TYPE type
;
92 struct d3dcompiler_shader_reflection_variable
*variables
;
95 /* ID3D11ShaderReflection */
96 struct d3dcompiler_shader_reflection
98 ID3D11ShaderReflection ID3D11ShaderReflection_iface
;
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
;
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
)
160 if (!ptr
) return TRUE
;
162 name_len
= strlen(ptr
) + 1;
168 *name
= HeapAlloc(GetProcessHeap(), 0, name_len
);
171 ERR("Failed to allocate name memory.\n");
175 memcpy(*name
, ptr
, name_len
);
180 static BOOL
copy_value(const char *ptr
, void **value
, DWORD size
)
182 if (!ptr
|| !size
) return TRUE
;
184 *value
= HeapAlloc(GetProcessHeap(), 0, size
);
187 ERR("Failed to allocate value memory.\n");
191 memcpy(*value
, ptr
, size
);
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
;
204 static void free_type_member(struct d3dcompiler_shader_reflection_type_member
*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
);
217 TRACE("reflection type %p.\n", t
);
221 for (i
= 0; i
< t
->desc
.Members
; ++i
)
223 free_type_member(&t
->members
[i
]);
225 HeapFree(GetProcessHeap(), 0, t
->members
);
228 HeapFree(GetProcessHeap(), 0, t
);
231 static void free_signature(struct d3dcompiler_shader_signature
*sig
)
233 TRACE("Free signature %p\n", sig
);
235 HeapFree(GetProcessHeap(), 0, sig
->elements
);
236 HeapFree(GetProcessHeap(), 0, sig
->string_data
);
239 static void free_variable(struct d3dcompiler_shader_reflection_variable
*var
)
243 HeapFree(GetProcessHeap(), 0, var
->name
);
244 HeapFree(GetProcessHeap(), 0, var
->default_value
);
248 static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer
*cb
)
254 for (i
= 0; i
< cb
->variable_count
; ++i
)
256 free_variable(&cb
->variables
[i
]);
258 HeapFree(GetProcessHeap(), 0, cb
->variables
);
261 HeapFree(GetProcessHeap(), 0, cb
->name
);
264 static void reflection_cleanup(struct d3dcompiler_shader_reflection
*ref
)
266 TRACE("Cleanup %p\n", ref
);
270 free_signature(ref
->isgn
);
271 HeapFree(GetProcessHeap(), 0, ref
->isgn
);
276 free_signature(ref
->osgn
);
277 HeapFree(GetProcessHeap(), 0, ref
->osgn
);
282 free_signature(ref
->pcsg
);
283 HeapFree(GetProcessHeap(), 0, ref
->pcsg
);
286 if (ref
->constant_buffers
)
290 for (i
= 0; i
< ref
->constant_buffer_count
; ++i
)
292 free_constant_buffer(&ref
->constant_buffers
[i
]);
296 wine_rb_destroy(&ref
->types
, d3dcompiler_shader_reflection_type_destroy
, NULL
);
297 HeapFree(GetProcessHeap(), 0, ref
->constant_buffers
);
298 HeapFree(GetProcessHeap(), 0, ref
->bound_resources
);
299 HeapFree(GetProcessHeap(), 0, ref
->resource_string
);
300 HeapFree(GetProcessHeap(), 0, ref
->creator
);
303 /* IUnknown methods */
305 static inline struct d3dcompiler_shader_reflection
*impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection
*iface
)
307 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection
, ID3D11ShaderReflection_iface
);
310 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection
*iface
, REFIID riid
, void **object
)
312 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
314 if (IsEqualGUID(riid
, &IID_ID3D11ShaderReflection
)
315 || IsEqualGUID(riid
, &IID_IUnknown
))
317 IUnknown_AddRef(iface
);
322 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
325 return E_NOINTERFACE
;
328 static ULONG STDMETHODCALLTYPE
d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection
*iface
)
330 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
331 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
333 TRACE("%p increasing refcount to %u\n", This
, refcount
);
338 static ULONG STDMETHODCALLTYPE
d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection
*iface
)
340 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
341 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
343 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
347 reflection_cleanup(This
);
348 HeapFree(GetProcessHeap(), 0, This
);
354 /* ID3D11ShaderReflection methods */
356 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection
*iface
, D3D11_SHADER_DESC
*desc
)
358 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
360 FIXME("iface %p, desc %p partial stub!\n", iface
, desc
);
364 WARN("Invalid argument specified\n");
368 desc
->Version
= This
->version
;
369 desc
->Creator
= This
->creator
;
370 desc
->Flags
= This
->flags
;
371 desc
->ConstantBuffers
= This
->constant_buffer_count
;
372 desc
->BoundResources
= This
->bound_resource_count
;
373 desc
->InputParameters
= This
->isgn
? This
->isgn
->element_count
: 0;
374 desc
->OutputParameters
= This
->osgn
? This
->osgn
->element_count
: 0;
375 desc
->InstructionCount
= This
->instruction_count
;
376 desc
->TempRegisterCount
= This
->temp_register_count
;
377 desc
->TempArrayCount
= This
->temp_array_count
;
379 desc
->DclCount
= This
->dcl_count
;
380 desc
->TextureNormalInstructions
= This
->texture_normal_instructions
;
381 desc
->TextureLoadInstructions
= This
->texture_load_instructions
;
382 desc
->TextureCompInstructions
= This
->texture_comp_instructions
;
383 desc
->TextureBiasInstructions
= This
->texture_bias_instructions
;
384 desc
->TextureGradientInstructions
= This
->texture_gradient_instructions
;
385 desc
->FloatInstructionCount
= This
->float_instruction_count
;
386 desc
->IntInstructionCount
= This
->int_instruction_count
;
387 desc
->UintInstructionCount
= This
->uint_instruction_count
;
388 desc
->StaticFlowControlCount
= This
->static_flow_control_count
;
389 desc
->DynamicFlowControlCount
= This
->dynamic_flow_control_count
;
390 desc
->MacroInstructionCount
= 0;
391 desc
->ArrayInstructionCount
= This
->array_instruction_count
;
392 desc
->CutInstructionCount
= This
->cut_instruction_count
;
393 desc
->EmitInstructionCount
= This
->emit_instruction_count
;
394 desc
->GSOutputTopology
= This
->gs_output_topology
;
395 desc
->GSMaxOutputVertexCount
= This
->gs_max_output_vertex_count
;
396 desc
->InputPrimitive
= This
->input_primitive
;
397 desc
->PatchConstantParameters
= This
->pcsg
? This
->pcsg
->element_count
: 0;
398 desc
->cGSInstanceCount
= 0;
399 desc
->cControlPoints
= This
->c_control_points
;
400 desc
->HSOutputPrimitive
= This
->hs_output_primitive
;
401 desc
->HSPartitioning
= This
->hs_prtitioning
;
402 desc
->TessellatorDomain
= This
->tessellator_domain
;
403 desc
->cBarrierInstructions
= 0;
404 desc
->cInterlockedInstructions
= 0;
405 desc
->cTextureStoreInstructions
= 0;
410 static struct ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConstantBufferByIndex(
411 ID3D11ShaderReflection
*iface
, UINT index
)
413 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
415 TRACE("iface %p, index %u\n", iface
, index
);
417 if (index
>= This
->constant_buffer_count
)
419 WARN("Invalid argument specified\n");
420 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
423 return &This
->constant_buffers
[index
].ID3D11ShaderReflectionConstantBuffer_iface
;
426 static struct ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConstantBufferByName(
427 ID3D11ShaderReflection
*iface
, const char *name
)
429 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
432 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
436 WARN("Invalid argument specified\n");
437 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
440 for (i
= 0; i
< This
->constant_buffer_count
; ++i
)
442 struct d3dcompiler_shader_reflection_constant_buffer
*d
= &This
->constant_buffers
[i
];
444 if (!strcmp(d
->name
, name
))
446 TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d
);
447 return &d
->ID3D11ShaderReflectionConstantBuffer_iface
;
451 WARN("Invalid name specified\n");
453 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
456 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetResourceBindingDesc(
457 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SHADER_INPUT_BIND_DESC
*desc
)
459 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
461 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
463 if (!desc
|| index
>= This
->bound_resource_count
)
465 WARN("Invalid argument specified\n");
469 *desc
= This
->bound_resources
[index
];
474 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetInputParameterDesc(
475 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SIGNATURE_PARAMETER_DESC
*desc
)
477 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
479 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
481 if (!desc
|| !This
->isgn
|| index
>= This
->isgn
->element_count
)
483 WARN("Invalid argument specified\n");
487 *desc
= This
->isgn
->elements
[index
];
492 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetOutputParameterDesc(
493 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SIGNATURE_PARAMETER_DESC
*desc
)
495 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
497 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
499 if (!desc
|| !This
->osgn
|| index
>= This
->osgn
->element_count
)
501 WARN("Invalid argument specified\n");
505 *desc
= This
->osgn
->elements
[index
];
510 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
511 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SIGNATURE_PARAMETER_DESC
*desc
)
513 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
515 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
517 if (!desc
|| !This
->pcsg
|| index
>= This
->pcsg
->element_count
)
519 WARN("Invalid argument specified\n");
523 *desc
= This
->pcsg
->elements
[index
];
528 static struct ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetVariableByName(
529 ID3D11ShaderReflection
*iface
, const char *name
)
531 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
534 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
538 WARN("Invalid name specified\n");
539 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
542 for (i
= 0; i
< This
->constant_buffer_count
; ++i
)
544 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= &This
->constant_buffers
[i
];
546 for (k
= 0; k
< cb
->variable_count
; ++k
)
548 struct d3dcompiler_shader_reflection_variable
*v
= &cb
->variables
[k
];
550 if (!strcmp(v
->name
, name
))
552 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v
);
553 return &v
->ID3D11ShaderReflectionVariable_iface
;
558 WARN("Invalid name specified\n");
560 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
563 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetResourceBindingDescByName(
564 ID3D11ShaderReflection
*iface
, const char *name
, D3D11_SHADER_INPUT_BIND_DESC
*desc
)
566 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
569 TRACE("iface %p, name %s, desc %p\n", iface
, debugstr_a(name
), desc
);
573 WARN("Invalid argument specified\n");
577 for (i
= 0; i
< This
->bound_resource_count
; ++i
)
579 D3D11_SHADER_INPUT_BIND_DESC
*d
= &This
->bound_resources
[i
];
581 if (!strcmp(d
->Name
, name
))
583 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d
);
589 WARN("Invalid name specified\n");
594 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMovInstructionCount(
595 ID3D11ShaderReflection
*iface
)
597 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
599 TRACE("iface %p\n", iface
);
601 return This
->mov_instruction_count
;
604 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMovcInstructionCount(
605 ID3D11ShaderReflection
*iface
)
607 FIXME("iface %p stub!\n", iface
);
612 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConversionInstructionCount(
613 ID3D11ShaderReflection
*iface
)
615 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
617 TRACE("iface %p\n", iface
);
619 return This
->conversion_instruction_count
;
622 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
623 ID3D11ShaderReflection
*iface
)
625 FIXME("iface %p stub!\n", iface
);
630 static D3D_PRIMITIVE STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetGSInputPrimitive(
631 ID3D11ShaderReflection
*iface
)
633 FIXME("iface %p stub!\n", iface
);
638 static BOOL STDMETHODCALLTYPE
d3dcompiler_shader_reflection_IsSampleFrequencyShader(
639 ID3D11ShaderReflection
*iface
)
641 FIXME("iface %p stub!\n", iface
);
646 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetNumInterfaceSlots(
647 ID3D11ShaderReflection
*iface
)
649 FIXME("iface %p stub!\n", iface
);
654 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMinFeatureLevel(
655 ID3D11ShaderReflection
*iface
, D3D_FEATURE_LEVEL
*level
)
657 FIXME("iface %p, level %p stub!\n", iface
, level
);
662 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetThreadGroupSize(
663 ID3D11ShaderReflection
*iface
, UINT
*sizex
, UINT
*sizey
, UINT
*sizez
)
665 FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface
, sizex
, sizey
, sizez
);
670 static UINT64 STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetRequiresFlags(
671 ID3D11ShaderReflection
*iface
)
673 FIXME("iface %p stub!\n", iface
);
678 static const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl
=
680 /* IUnknown methods */
681 d3dcompiler_shader_reflection_QueryInterface
,
682 d3dcompiler_shader_reflection_AddRef
,
683 d3dcompiler_shader_reflection_Release
,
684 /* ID3D11ShaderReflection methods */
685 d3dcompiler_shader_reflection_GetDesc
,
686 d3dcompiler_shader_reflection_GetConstantBufferByIndex
,
687 d3dcompiler_shader_reflection_GetConstantBufferByName
,
688 d3dcompiler_shader_reflection_GetResourceBindingDesc
,
689 d3dcompiler_shader_reflection_GetInputParameterDesc
,
690 d3dcompiler_shader_reflection_GetOutputParameterDesc
,
691 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc
,
692 d3dcompiler_shader_reflection_GetVariableByName
,
693 d3dcompiler_shader_reflection_GetResourceBindingDescByName
,
694 d3dcompiler_shader_reflection_GetMovInstructionCount
,
695 d3dcompiler_shader_reflection_GetMovcInstructionCount
,
696 d3dcompiler_shader_reflection_GetConversionInstructionCount
,
697 d3dcompiler_shader_reflection_GetBitwiseInstructionCount
,
698 d3dcompiler_shader_reflection_GetGSInputPrimitive
,
699 d3dcompiler_shader_reflection_IsSampleFrequencyShader
,
700 d3dcompiler_shader_reflection_GetNumInterfaceSlots
,
701 d3dcompiler_shader_reflection_GetMinFeatureLevel
,
702 d3dcompiler_shader_reflection_GetThreadGroupSize
,
703 d3dcompiler_shader_reflection_GetRequiresFlags
,
706 /* ID3D11ShaderReflectionConstantBuffer methods */
708 static inline struct d3dcompiler_shader_reflection_constant_buffer
*impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer
*iface
)
710 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_constant_buffer
, ID3D11ShaderReflectionConstantBuffer_iface
);
713 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetDesc(
714 ID3D11ShaderReflectionConstantBuffer
*iface
, D3D11_SHADER_BUFFER_DESC
*desc
)
716 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
718 TRACE("iface %p, desc %p\n", iface
, desc
);
720 if (This
== &null_constant_buffer
)
722 WARN("Null constant buffer specified\n");
728 WARN("Invalid argument specified\n");
732 desc
->Name
= This
->name
;
733 desc
->Type
= This
->type
;
734 desc
->Variables
= This
->variable_count
;
735 desc
->Size
= This
->size
;
736 desc
->uFlags
= This
->flags
;
741 static ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex(
742 ID3D11ShaderReflectionConstantBuffer
*iface
, UINT index
)
744 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
746 TRACE("iface %p, index %u\n", iface
, index
);
748 if (index
>= This
->variable_count
)
750 WARN("Invalid index specified\n");
751 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
754 return &This
->variables
[index
].ID3D11ShaderReflectionVariable_iface
;
757 static ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetVariableByName(
758 ID3D11ShaderReflectionConstantBuffer
*iface
, const char *name
)
760 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
763 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
767 WARN("Invalid argument specified\n");
768 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
771 for (i
= 0; i
< This
->variable_count
; ++i
)
773 struct d3dcompiler_shader_reflection_variable
*v
= &This
->variables
[i
];
775 if (!strcmp(v
->name
, name
))
777 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v
);
778 return &v
->ID3D11ShaderReflectionVariable_iface
;
782 WARN("Invalid name specified\n");
784 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
787 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl
=
789 /* ID3D11ShaderReflectionConstantBuffer methods */
790 d3dcompiler_shader_reflection_constant_buffer_GetDesc
,
791 d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex
,
792 d3dcompiler_shader_reflection_constant_buffer_GetVariableByName
,
795 /* ID3D11ShaderReflectionVariable methods */
797 static inline struct d3dcompiler_shader_reflection_variable
*impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable
*iface
)
799 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_variable
, ID3D11ShaderReflectionVariable_iface
);
802 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetDesc(
803 ID3D11ShaderReflectionVariable
*iface
, D3D11_SHADER_VARIABLE_DESC
*desc
)
805 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
807 TRACE("iface %p, desc %p\n", iface
, desc
);
809 if (This
== &null_variable
)
811 WARN("Null variable specified\n");
817 WARN("Invalid argument specified\n");
821 desc
->Name
= This
->name
;
822 desc
->StartOffset
= This
->start_offset
;
823 desc
->Size
= This
->size
;
824 desc
->uFlags
= This
->flags
;
825 desc
->DefaultValue
= This
->default_value
;
830 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetType(
831 ID3D11ShaderReflectionVariable
*iface
)
833 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
835 TRACE("iface %p\n", iface
);
837 return &This
->type
->ID3D11ShaderReflectionType_iface
;
840 static ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetBuffer(
841 ID3D11ShaderReflectionVariable
*iface
)
843 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
845 TRACE("iface %p\n", iface
);
847 return &This
->constant_buffer
->ID3D11ShaderReflectionConstantBuffer_iface
;
850 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetInterfaceSlot(
851 ID3D11ShaderReflectionVariable
*iface
, UINT index
)
853 FIXME("iface %p, index %u stub!\n", iface
, index
);
858 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl
=
860 /* ID3D11ShaderReflectionVariable methods */
861 d3dcompiler_shader_reflection_variable_GetDesc
,
862 d3dcompiler_shader_reflection_variable_GetType
,
863 d3dcompiler_shader_reflection_variable_GetBuffer
,
864 d3dcompiler_shader_reflection_variable_GetInterfaceSlot
,
867 /* ID3D11ShaderReflectionType methods */
869 static inline struct d3dcompiler_shader_reflection_type
*impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType
*iface
)
871 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_type
, ID3D11ShaderReflectionType_iface
);
874 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetDesc(
875 ID3D11ShaderReflectionType
*iface
, D3D11_SHADER_TYPE_DESC
*desc
)
877 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
879 TRACE("iface %p, desc %p\n", iface
, desc
);
881 if (This
== &null_type
)
883 WARN("Null type specified\n");
889 WARN("Invalid argument specified\n");
898 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeByIndex(
899 ID3D11ShaderReflectionType
*iface
, UINT index
)
901 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
903 TRACE("iface %p, index %u\n", iface
, index
);
905 if (index
>= This
->desc
.Members
)
907 WARN("Invalid index specified\n");
908 return &null_type
.ID3D11ShaderReflectionType_iface
;
911 return &This
->members
[index
].type
->ID3D11ShaderReflectionType_iface
;
914 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeByName(
915 ID3D11ShaderReflectionType
*iface
, const char *name
)
917 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
920 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
924 WARN("Invalid argument specified\n");
925 return &null_type
.ID3D11ShaderReflectionType_iface
;
928 for (i
= 0; i
< This
->desc
.Members
; ++i
)
930 struct d3dcompiler_shader_reflection_type_member
*member
= &This
->members
[i
];
932 if (!strcmp(member
->name
, name
))
934 TRACE("Returning ID3D11ShaderReflectionType %p.\n", member
->type
);
935 return &member
->type
->ID3D11ShaderReflectionType_iface
;
939 WARN("Invalid name specified\n");
941 return &null_type
.ID3D11ShaderReflectionType_iface
;
944 static const char * STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeName(
945 ID3D11ShaderReflectionType
*iface
, UINT index
)
947 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
949 TRACE("iface %p, index %u\n", iface
, index
);
951 if (This
== &null_type
)
953 WARN("Null type specified\n");
957 if (index
>= This
->desc
.Members
)
959 WARN("Invalid index specified\n");
963 return This
->members
[index
].name
;
966 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_IsEqual(
967 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*type
)
969 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
971 TRACE("iface %p, type %p\n", iface
, type
);
973 if (This
== &null_type
)
975 WARN("Null type specified\n");
985 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetSubType(
986 ID3D11ShaderReflectionType
*iface
)
988 FIXME("iface %p stub!\n", iface
);
993 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetBaseClass(
994 ID3D11ShaderReflectionType
*iface
)
996 FIXME("iface %p stub!\n", iface
);
1001 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetNumInterfaces(
1002 ID3D11ShaderReflectionType
*iface
)
1004 FIXME("iface %p stub!\n", iface
);
1009 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetInterfaceByIndex(
1010 ID3D11ShaderReflectionType
*iface
, UINT index
)
1012 FIXME("iface %p, index %u stub!\n", iface
, index
);
1017 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_IsOfType(
1018 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*type
)
1020 FIXME("iface %p, type %p stub!\n", iface
, type
);
1025 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_ImplementsInterface(
1026 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*base
)
1028 FIXME("iface %p, base %p stub!\n", iface
, base
);
1033 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl
=
1035 /* ID3D11ShaderReflectionType methods */
1036 d3dcompiler_shader_reflection_type_GetDesc
,
1037 d3dcompiler_shader_reflection_type_GetMemberTypeByIndex
,
1038 d3dcompiler_shader_reflection_type_GetMemberTypeByName
,
1039 d3dcompiler_shader_reflection_type_GetMemberTypeName
,
1040 d3dcompiler_shader_reflection_type_IsEqual
,
1041 d3dcompiler_shader_reflection_type_GetSubType
,
1042 d3dcompiler_shader_reflection_type_GetBaseClass
,
1043 d3dcompiler_shader_reflection_type_GetNumInterfaces
,
1044 d3dcompiler_shader_reflection_type_GetInterfaceByIndex
,
1045 d3dcompiler_shader_reflection_type_IsOfType
,
1046 d3dcompiler_shader_reflection_type_ImplementsInterface
,
1049 static HRESULT
d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection
*r
, const char *data
, DWORD data_size
)
1051 const char *ptr
= data
;
1052 DWORD size
= data_size
>> 2;
1054 TRACE("Size %u\n", size
);
1056 read_dword(&ptr
, &r
->instruction_count
);
1057 TRACE("InstructionCount: %u\n", r
->instruction_count
);
1059 read_dword(&ptr
, &r
->temp_register_count
);
1060 TRACE("TempRegisterCount: %u\n", r
->temp_register_count
);
1062 skip_dword_unknown(&ptr
, 1);
1064 read_dword(&ptr
, &r
->dcl_count
);
1065 TRACE("DclCount: %u\n", r
->dcl_count
);
1067 read_dword(&ptr
, &r
->float_instruction_count
);
1068 TRACE("FloatInstructionCount: %u\n", r
->float_instruction_count
);
1070 read_dword(&ptr
, &r
->int_instruction_count
);
1071 TRACE("IntInstructionCount: %u\n", r
->int_instruction_count
);
1073 read_dword(&ptr
, &r
->uint_instruction_count
);
1074 TRACE("UintInstructionCount: %u\n", r
->uint_instruction_count
);
1076 read_dword(&ptr
, &r
->static_flow_control_count
);
1077 TRACE("StaticFlowControlCount: %u\n", r
->static_flow_control_count
);
1079 read_dword(&ptr
, &r
->dynamic_flow_control_count
);
1080 TRACE("DynamicFlowControlCount: %u\n", r
->dynamic_flow_control_count
);
1082 skip_dword_unknown(&ptr
, 1);
1084 read_dword(&ptr
, &r
->temp_array_count
);
1085 TRACE("TempArrayCount: %u\n", r
->temp_array_count
);
1087 read_dword(&ptr
, &r
->array_instruction_count
);
1088 TRACE("ArrayInstructionCount: %u\n", r
->array_instruction_count
);
1090 read_dword(&ptr
, &r
->cut_instruction_count
);
1091 TRACE("CutInstructionCount: %u\n", r
->cut_instruction_count
);
1093 read_dword(&ptr
, &r
->emit_instruction_count
);
1094 TRACE("EmitInstructionCount: %u\n", r
->emit_instruction_count
);
1096 read_dword(&ptr
, &r
->texture_normal_instructions
);
1097 TRACE("TextureNormalInstructions: %u\n", r
->texture_normal_instructions
);
1099 read_dword(&ptr
, &r
->texture_load_instructions
);
1100 TRACE("TextureLoadInstructions: %u\n", r
->texture_load_instructions
);
1102 read_dword(&ptr
, &r
->texture_comp_instructions
);
1103 TRACE("TextureCompInstructions: %u\n", r
->texture_comp_instructions
);
1105 read_dword(&ptr
, &r
->texture_bias_instructions
);
1106 TRACE("TextureBiasInstructions: %u\n", r
->texture_bias_instructions
);
1108 read_dword(&ptr
, &r
->texture_gradient_instructions
);
1109 TRACE("TextureGradientInstructions: %u\n", r
->texture_gradient_instructions
);
1111 read_dword(&ptr
, &r
->mov_instruction_count
);
1112 TRACE("MovInstructionCount: %u\n", r
->mov_instruction_count
);
1114 skip_dword_unknown(&ptr
, 1);
1116 read_dword(&ptr
, &r
->conversion_instruction_count
);
1117 TRACE("ConversionInstructionCount: %u\n", r
->conversion_instruction_count
);
1119 skip_dword_unknown(&ptr
, 1);
1121 read_dword(&ptr
, &r
->input_primitive
);
1122 TRACE("InputPrimitive: %x\n", r
->input_primitive
);
1124 read_dword(&ptr
, &r
->gs_output_topology
);
1125 TRACE("GSOutputTopology: %x\n", r
->gs_output_topology
);
1127 read_dword(&ptr
, &r
->gs_max_output_vertex_count
);
1128 TRACE("GSMaxOutputVertexCount: %u\n", r
->gs_max_output_vertex_count
);
1130 skip_dword_unknown(&ptr
, 2);
1132 /* old dx10 stat size */
1133 if (size
== 28) return S_OK
;
1135 skip_dword_unknown(&ptr
, 1);
1137 /* dx10 stat size */
1138 if (size
== 29) return S_OK
;
1140 skip_dword_unknown(&ptr
, 1);
1142 read_dword(&ptr
, &r
->c_control_points
);
1143 TRACE("cControlPoints: %u\n", r
->c_control_points
);
1145 read_dword(&ptr
, &r
->hs_output_primitive
);
1146 TRACE("HSOutputPrimitive: %x\n", r
->hs_output_primitive
);
1148 read_dword(&ptr
, &r
->hs_prtitioning
);
1149 TRACE("HSPartitioning: %x\n", r
->hs_prtitioning
);
1151 read_dword(&ptr
, &r
->tessellator_domain
);
1152 TRACE("TessellatorDomain: %x\n", r
->tessellator_domain
);
1154 skip_dword_unknown(&ptr
, 3);
1156 /* dx11 stat size */
1157 if (size
== 37) return S_OK
;
1159 FIXME("Unhandled size %u\n", size
);
1164 static HRESULT
d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection
*ref
,
1165 struct d3dcompiler_shader_reflection_type_member
*member
, const char *data
, const char **ptr
)
1169 read_dword(ptr
, &offset
);
1170 if (!copy_name(data
+ offset
, &member
->name
))
1172 ERR("Failed to copy name.\n");
1173 return E_OUTOFMEMORY
;
1175 TRACE("Member name: %s.\n", debugstr_a(member
->name
));
1177 read_dword(ptr
, &offset
);
1178 TRACE("Member type offset: %x\n", offset
);
1180 member
->type
= get_reflection_type(ref
, data
, offset
);
1183 ERR("Failed to get member type\n");
1184 HeapFree(GetProcessHeap(), 0, member
->name
);
1188 read_dword(ptr
, &member
->offset
);
1189 TRACE("Member offset %x\n", member
->offset
);
1194 static HRESULT
d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type
*type
, const char *data
, DWORD offset
)
1196 const char *ptr
= data
+ offset
;
1198 D3D11_SHADER_TYPE_DESC
*desc
;
1200 struct d3dcompiler_shader_reflection_type_member
*members
= NULL
;
1202 DWORD member_offset
;
1206 read_dword(&ptr
, &temp
);
1207 desc
->Class
= temp
& 0xffff;
1208 desc
->Type
= temp
>> 16;
1209 TRACE("Class %s, Type %s\n", debug_d3dcompiler_shader_variable_class(desc
->Class
),
1210 debug_d3dcompiler_shader_variable_type(desc
->Type
));
1212 read_dword(&ptr
, &temp
);
1213 desc
->Rows
= temp
& 0xffff;
1214 desc
->Columns
= temp
>> 16;
1215 TRACE("Rows %u, Columns %u\n", desc
->Rows
, desc
->Columns
);
1217 read_dword(&ptr
, &temp
);
1218 desc
->Elements
= temp
& 0xffff;
1219 desc
->Members
= temp
>> 16;
1220 TRACE("Elements %u, Members %u\n", desc
->Elements
, desc
->Members
);
1222 read_dword(&ptr
, &member_offset
);
1223 TRACE("Member Offset %u\n", member_offset
);
1225 if ((type
->reflection
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1226 skip_dword_unknown(&ptr
, 4);
1230 const char *ptr2
= data
+ member_offset
;
1232 members
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*members
) * desc
->Members
);
1235 ERR("Failed to allocate type memory.\n");
1236 return E_OUTOFMEMORY
;
1239 for (i
= 0; i
< desc
->Members
; ++i
)
1241 hr
= d3dcompiler_parse_type_members(type
->reflection
, &members
[i
], data
, &ptr2
);
1244 FIXME("Failed to parse type members.\n");
1250 type
->members
= members
;
1255 for (i
= 0; i
< desc
->Members
; ++i
)
1257 free_type_member(&members
[i
]);
1259 HeapFree(GetProcessHeap(), 0, members
);
1263 static struct d3dcompiler_shader_reflection_type
*get_reflection_type(struct d3dcompiler_shader_reflection
*reflection
, const char *data
, DWORD offset
)
1265 struct d3dcompiler_shader_reflection_type
*type
;
1266 struct wine_rb_entry
*entry
;
1269 entry
= wine_rb_get(&reflection
->types
, &offset
);
1272 TRACE("Returning existing type.\n");
1273 return WINE_RB_ENTRY_VALUE(entry
, struct d3dcompiler_shader_reflection_type
, entry
);
1276 type
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*type
));
1280 type
->ID3D11ShaderReflectionType_iface
.lpVtbl
= &d3dcompiler_shader_reflection_type_vtbl
;
1282 type
->reflection
= reflection
;
1284 hr
= d3dcompiler_parse_type(type
, data
, offset
);
1287 ERR("Failed to parse type info, hr %#x.\n", hr
);
1288 HeapFree(GetProcessHeap(), 0, type
);
1292 if (wine_rb_put(&reflection
->types
, &offset
, &type
->entry
) == -1)
1294 ERR("Failed to insert type entry.\n");
1295 HeapFree(GetProcessHeap(), 0, type
);
1302 static HRESULT
d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer
*cb
,
1303 const char *data
, DWORD data_size
, const char *ptr
)
1305 struct d3dcompiler_shader_reflection_variable
*variables
;
1309 variables
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, cb
->variable_count
* sizeof(*variables
));
1312 ERR("Failed to allocate variables memory.\n");
1313 return E_OUTOFMEMORY
;
1316 for (i
= 0; i
< cb
->variable_count
; i
++)
1318 struct d3dcompiler_shader_reflection_variable
*v
= &variables
[i
];
1321 v
->ID3D11ShaderReflectionVariable_iface
.lpVtbl
= &d3dcompiler_shader_reflection_variable_vtbl
;
1322 v
->constant_buffer
= cb
;
1324 read_dword(&ptr
, &offset
);
1325 if (!copy_name(data
+ offset
, &v
->name
))
1327 ERR("Failed to copy name.\n");
1331 TRACE("Variable name: %s.\n", debugstr_a(v
->name
));
1333 read_dword(&ptr
, &v
->start_offset
);
1334 TRACE("Variable offset: %u\n", v
->start_offset
);
1336 read_dword(&ptr
, &v
->size
);
1337 TRACE("Variable size: %u\n", v
->size
);
1339 read_dword(&ptr
, &v
->flags
);
1340 TRACE("Variable flags: %u\n", v
->flags
);
1342 read_dword(&ptr
, &offset
);
1343 TRACE("Variable type offset: %x\n", offset
);
1344 v
->type
= get_reflection_type(cb
->reflection
, data
, offset
);
1347 ERR("Failed to get type.\n");
1352 read_dword(&ptr
, &offset
);
1353 TRACE("Variable default value offset: %x\n", offset
);
1354 if (!copy_value(data
+ offset
, &v
->default_value
, offset
? v
->size
: 0))
1356 ERR("Failed to copy name.\n");
1361 if ((cb
->reflection
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1362 skip_dword_unknown(&ptr
, 4);
1365 cb
->variables
= variables
;
1370 for (i
= 0; i
< cb
->variable_count
; i
++)
1372 free_variable(&variables
[i
]);
1374 HeapFree(GetProcessHeap(), 0, variables
);
1378 static HRESULT
d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection
*r
, const char *data
, DWORD data_size
)
1380 const char *ptr
= data
;
1381 DWORD size
= data_size
>> 2;
1382 DWORD offset
, cbuffer_offset
, resource_offset
, creator_offset
;
1383 unsigned int i
, string_data_offset
, string_data_size
;
1384 char *string_data
= NULL
, *creator
= NULL
;
1385 D3D11_SHADER_INPUT_BIND_DESC
*bound_resources
= NULL
;
1386 struct d3dcompiler_shader_reflection_constant_buffer
*constant_buffers
= NULL
;
1389 TRACE("Size %u\n", size
);
1391 read_dword(&ptr
, &r
->constant_buffer_count
);
1392 TRACE("Constant buffer count: %u\n", r
->constant_buffer_count
);
1394 read_dword(&ptr
, &cbuffer_offset
);
1395 TRACE("Constant buffer offset: %#x\n", cbuffer_offset
);
1397 read_dword(&ptr
, &r
->bound_resource_count
);
1398 TRACE("Bound resource count: %u\n", r
->bound_resource_count
);
1400 read_dword(&ptr
, &resource_offset
);
1401 TRACE("Bound resource offset: %#x\n", resource_offset
);
1403 read_dword(&ptr
, &r
->target
);
1404 TRACE("Target: %#x\n", r
->target
);
1406 read_dword(&ptr
, &r
->flags
);
1407 TRACE("Flags: %u\n", r
->flags
);
1409 read_dword(&ptr
, &creator_offset
);
1410 TRACE("Creator at offset %#x.\n", creator_offset
);
1412 if (!copy_name(data
+ creator_offset
, &creator
))
1414 ERR("Failed to copy name.\n");
1415 return E_OUTOFMEMORY
;
1417 TRACE("Creator: %s.\n", debugstr_a(creator
));
1419 /* todo: Parse RD11 */
1420 if ((r
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1422 skip_dword_unknown(&ptr
, 8);
1425 if (r
->bound_resource_count
)
1427 /* 8 for each bind desc */
1428 string_data_offset
= resource_offset
+ r
->bound_resource_count
* 8 * sizeof(DWORD
);
1429 string_data_size
= (cbuffer_offset
? cbuffer_offset
: creator_offset
) - string_data_offset
;
1431 string_data
= HeapAlloc(GetProcessHeap(), 0, string_data_size
);
1434 ERR("Failed to allocate string data memory.\n");
1438 memcpy(string_data
, data
+ string_data_offset
, string_data_size
);
1440 bound_resources
= HeapAlloc(GetProcessHeap(), 0, r
->bound_resource_count
* sizeof(*bound_resources
));
1441 if (!bound_resources
)
1443 ERR("Failed to allocate resources memory.\n");
1448 ptr
= data
+ resource_offset
;
1449 for (i
= 0; i
< r
->bound_resource_count
; i
++)
1451 D3D11_SHADER_INPUT_BIND_DESC
*desc
= &bound_resources
[i
];
1453 read_dword(&ptr
, &offset
);
1454 desc
->Name
= string_data
+ (offset
- string_data_offset
);
1455 TRACE("Input bind Name: %s\n", debugstr_a(desc
->Name
));
1457 read_dword(&ptr
, &desc
->Type
);
1458 TRACE("Input bind Type: %#x\n", desc
->Type
);
1460 read_dword(&ptr
, &desc
->ReturnType
);
1461 TRACE("Input bind ReturnType: %#x\n", desc
->ReturnType
);
1463 read_dword(&ptr
, &desc
->Dimension
);
1464 TRACE("Input bind Dimension: %#x\n", desc
->Dimension
);
1466 read_dword(&ptr
, &desc
->NumSamples
);
1467 TRACE("Input bind NumSamples: %u\n", desc
->NumSamples
);
1469 read_dword(&ptr
, &desc
->BindPoint
);
1470 TRACE("Input bind BindPoint: %u\n", desc
->BindPoint
);
1472 read_dword(&ptr
, &desc
->BindCount
);
1473 TRACE("Input bind BindCount: %u\n", desc
->BindCount
);
1475 read_dword(&ptr
, &desc
->uFlags
);
1476 TRACE("Input bind uFlags: %u\n", desc
->uFlags
);
1480 if (r
->constant_buffer_count
)
1482 constant_buffers
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, r
->constant_buffer_count
* sizeof(*constant_buffers
));
1483 if (!constant_buffers
)
1485 ERR("Failed to allocate constant buffer memory.\n");
1490 ptr
= data
+ cbuffer_offset
;
1491 for (i
= 0; i
< r
->constant_buffer_count
; i
++)
1493 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= &constant_buffers
[i
];
1495 cb
->ID3D11ShaderReflectionConstantBuffer_iface
.lpVtbl
= &d3dcompiler_shader_reflection_constant_buffer_vtbl
;
1498 read_dword(&ptr
, &offset
);
1499 if (!copy_name(data
+ offset
, &cb
->name
))
1501 ERR("Failed to copy name.\n");
1505 TRACE("Name: %s.\n", debugstr_a(cb
->name
));
1507 read_dword(&ptr
, &cb
->variable_count
);
1508 TRACE("Variable count: %u\n", cb
->variable_count
);
1510 read_dword(&ptr
, &offset
);
1511 TRACE("Variable offset: %x\n", offset
);
1513 hr
= d3dcompiler_parse_variables(cb
, data
, data_size
, data
+ offset
);
1516 FIXME("Failed to parse variables.\n");
1520 read_dword(&ptr
, &cb
->size
);
1521 TRACE("Cbuffer size: %u\n", cb
->size
);
1523 read_dword(&ptr
, &cb
->flags
);
1524 TRACE("Cbuffer flags: %u\n", cb
->flags
);
1526 read_dword(&ptr
, &cb
->type
);
1527 TRACE("Cbuffer type: %#x\n", cb
->type
);
1531 r
->creator
= creator
;
1532 r
->resource_string
= string_data
;
1533 r
->bound_resources
= bound_resources
;
1534 r
->constant_buffers
= constant_buffers
;
1539 for (i
= 0; i
< r
->constant_buffer_count
; ++i
)
1541 free_constant_buffer(&constant_buffers
[i
]);
1543 HeapFree(GetProcessHeap(), 0, constant_buffers
);
1544 HeapFree(GetProcessHeap(), 0, bound_resources
);
1545 HeapFree(GetProcessHeap(), 0, string_data
);
1546 HeapFree(GetProcessHeap(), 0, creator
);
1551 static HRESULT
d3dcompiler_parse_signature(struct d3dcompiler_shader_signature
*s
, struct dxbc_section
*section
, DWORD target
)
1553 D3D11_SIGNATURE_PARAMETER_DESC
*d
;
1554 unsigned int string_data_offset
;
1555 unsigned int string_data_size
;
1556 const char *ptr
= section
->data
;
1560 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size
;
1562 switch (section
->tag
)
1565 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
;
1571 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
;
1575 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion
->tag
, 4));
1576 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
;
1580 read_dword(&ptr
, &count
);
1581 TRACE("%u elements\n", count
);
1583 skip_dword_unknown(&ptr
, 1);
1585 d
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(*d
));
1588 ERR("Failed to allocate signature memory.\n");
1589 return E_OUTOFMEMORY
;
1592 /* 2 DWORDs for the header, element_size for each element. */
1593 string_data_offset
= 2 * sizeof(DWORD
) + count
* element_size
* sizeof(DWORD
);
1594 string_data_size
= section
->data_size
- string_data_offset
;
1596 string_data
= HeapAlloc(GetProcessHeap(), 0, string_data_size
);
1599 ERR("Failed to allocate string data memory.\n");
1600 HeapFree(GetProcessHeap(), 0, d
);
1601 return E_OUTOFMEMORY
;
1603 memcpy(string_data
, section
->data
+ string_data_offset
, string_data_size
);
1605 for (i
= 0; i
< count
; ++i
)
1610 if (element_size
== D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
)
1612 read_dword(&ptr
, &d
[i
].Stream
);
1619 read_dword(&ptr
, &name_offset
);
1620 d
[i
].SemanticName
= string_data
+ (name_offset
- string_data_offset
);
1621 read_dword(&ptr
, &d
[i
].SemanticIndex
);
1622 read_dword(&ptr
, &d
[i
].SystemValueType
);
1623 read_dword(&ptr
, &d
[i
].ComponentType
);
1624 read_dword(&ptr
, &d
[i
].Register
);
1625 read_dword(&ptr
, &mask
);
1626 d
[i
].ReadWriteMask
= (mask
>> 8) & 0xff;
1627 d
[i
].Mask
= mask
& 0xff;
1629 /* pixel shaders have a special handling for SystemValueType in the output signature */
1630 if (((target
& D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK
) == 0xffff0000) && (section
->tag
== TAG_OSG5
|| section
->tag
== TAG_OSGN
))
1632 TRACE("Pixelshader output signature fixup.\n");
1634 if (d
[i
].Register
== 0xffffffff)
1636 if (!_strnicmp(d
[i
].SemanticName
, "sv_depth", -1))
1637 d
[i
].SystemValueType
= D3D_NAME_DEPTH
;
1638 else if (!_strnicmp(d
[i
].SemanticName
, "sv_coverage", -1))
1639 d
[i
].SystemValueType
= D3D_NAME_COVERAGE
;
1640 else if (!_strnicmp(d
[i
].SemanticName
, "sv_depthgreaterequal", -1))
1641 d
[i
].SystemValueType
= D3D_NAME_DEPTH_GREATER_EQUAL
;
1642 else if (!_strnicmp(d
[i
].SemanticName
, "sv_depthlessequal", -1))
1643 d
[i
].SystemValueType
= D3D_NAME_DEPTH_LESS_EQUAL
;
1647 d
[i
].SystemValueType
= D3D_NAME_TARGET
;
1651 TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
1652 "type %u, register idx: %u, use_mask %#x, input_mask %#x, stream %u\n",
1653 debugstr_a(d
[i
].SemanticName
), d
[i
].SemanticIndex
, d
[i
].SystemValueType
,
1654 d
[i
].ComponentType
, d
[i
].Register
, d
[i
].Mask
, d
[i
].ReadWriteMask
, d
[i
].Stream
);
1658 s
->element_count
= count
;
1659 s
->string_data
= string_data
;
1664 static HRESULT
d3dcompiler_parse_shdr(struct d3dcompiler_shader_reflection
*r
, const char *data
, DWORD data_size
)
1666 const char *ptr
= data
;
1668 read_dword(&ptr
, &r
->version
);
1669 TRACE("Shader version: %u\n", r
->version
);
1671 /* todo: Check if anything else is needed from the shdr or shex blob. */
1676 static HRESULT
d3dcompiler_shader_reflection_init(struct d3dcompiler_shader_reflection
*reflection
,
1677 const void *data
, SIZE_T data_size
)
1679 struct dxbc src_dxbc
;
1683 reflection
->ID3D11ShaderReflection_iface
.lpVtbl
= &d3dcompiler_shader_reflection_vtbl
;
1684 reflection
->refcount
= 1;
1686 wine_rb_init(&reflection
->types
, d3dcompiler_shader_reflection_type_compare
);
1688 hr
= dxbc_parse(data
, data_size
, &src_dxbc
);
1691 WARN("Failed to parse reflection\n");
1695 for (i
= 0; i
< src_dxbc
.count
; ++i
)
1697 struct dxbc_section
*section
= &src_dxbc
.sections
[i
];
1699 switch (section
->tag
)
1702 hr
= d3dcompiler_parse_rdef(reflection
, section
->data
, section
->data_size
);
1705 WARN("Failed to parse RDEF section.\n");
1711 reflection
->isgn
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->isgn
));
1712 if (!reflection
->isgn
)
1714 ERR("Failed to allocate ISGN memory.\n");
1719 hr
= d3dcompiler_parse_signature(reflection
->isgn
, section
, reflection
->target
);
1722 WARN("Failed to parse section ISGN.\n");
1729 reflection
->osgn
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->osgn
));
1730 if (!reflection
->osgn
)
1732 ERR("Failed to allocate OSGN memory.\n");
1737 hr
= d3dcompiler_parse_signature(reflection
->osgn
, section
, reflection
->target
);
1740 WARN("Failed to parse section OSGN.\n");
1746 reflection
->pcsg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->pcsg
));
1747 if (!reflection
->pcsg
)
1749 ERR("Failed to allocate PCSG memory.\n");
1754 hr
= d3dcompiler_parse_signature(reflection
->pcsg
, section
, reflection
->target
);
1757 WARN("Failed to parse section PCSG.\n");
1764 hr
= d3dcompiler_parse_shdr(reflection
, section
->data
, section
->data_size
);
1767 WARN("Failed to parse SHDR section.\n");
1773 hr
= d3dcompiler_parse_stat(reflection
, section
->data
, section
->data_size
);
1776 WARN("Failed to parse section STAT.\n");
1782 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion
->tag
, 4));
1787 dxbc_destroy(&src_dxbc
);
1792 reflection_cleanup(reflection
);
1793 dxbc_destroy(&src_dxbc
);
1798 HRESULT WINAPI
D3DReflect(const void *data
, SIZE_T data_size
, REFIID riid
, void **reflector
)
1800 struct d3dcompiler_shader_reflection
*object
;
1802 const DWORD
*temp
= data
;
1804 TRACE("data %p, data_size %lu, riid %s, blob %p\n", data
, data_size
, debugstr_guid(riid
), reflector
);
1806 if (!data
|| data_size
< 32)
1808 WARN("Invalid argument supplied.\n");
1809 return D3DERR_INVALIDCALL
;
1812 if (temp
[6] != data_size
)
1814 WARN("Wrong size supplied.\n");
1818 if (!IsEqualGUID(riid
, &IID_ID3D11ShaderReflection
))
1820 WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid
), debugstr_guid(&IID_ID3D11ShaderReflection
));
1821 return E_NOINTERFACE
;
1824 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1826 return E_OUTOFMEMORY
;
1828 hr
= d3dcompiler_shader_reflection_init(object
, data
, data_size
);
1831 WARN("Failed to initialize shader reflection\n");
1832 HeapFree(GetProcessHeap(), 0, object
);
1836 *reflector
= object
;
1838 TRACE("Created ID3D11ShaderReflection %p\n", object
);