2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 * Copyright 2010 Rico Schüller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "d3dcompiler_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler
);
25 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE
27 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
= 6,
28 D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
= 7,
31 #define D3DCOMPILER_SHADER_TARGET_VERSION_MASK 0xffff
32 #define D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK 0xffff0000
34 struct d3dcompiler_shader_signature
36 D3D11_SIGNATURE_PARAMETER_DESC
*elements
;
41 struct d3dcompiler_shader_reflection_type
43 ID3D11ShaderReflectionType ID3D11ShaderReflectionType_iface
;
46 struct wine_rb_entry entry
;
48 struct d3dcompiler_shader_reflection
*reflection
;
50 D3D11_SHADER_TYPE_DESC desc
;
51 struct d3dcompiler_shader_reflection_type_member
*members
;
54 struct d3dcompiler_shader_reflection_type_member
58 struct d3dcompiler_shader_reflection_type
*type
;
61 struct d3dcompiler_shader_reflection_variable
63 ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable_iface
;
65 struct d3dcompiler_shader_reflection_constant_buffer
*constant_buffer
;
66 struct d3dcompiler_shader_reflection_type
*type
;
75 struct d3dcompiler_shader_reflection_constant_buffer
77 ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer_iface
;
79 struct d3dcompiler_shader_reflection
*reflection
;
82 D3D_CBUFFER_TYPE type
;
87 struct d3dcompiler_shader_reflection_variable
*variables
;
90 /* ID3D11ShaderReflection */
91 struct d3dcompiler_shader_reflection
93 ID3D11ShaderReflection ID3D11ShaderReflection_iface
;
100 UINT bound_resource_count
;
101 UINT constant_buffer_count
;
103 UINT mov_instruction_count
;
104 UINT conversion_instruction_count
;
105 UINT instruction_count
;
106 UINT emit_instruction_count
;
107 D3D_PRIMITIVE_TOPOLOGY gs_output_topology
;
108 UINT gs_max_output_vertex_count
;
109 D3D_PRIMITIVE input_primitive
;
110 UINT cut_instruction_count
;
112 UINT static_flow_control_count
;
113 UINT float_instruction_count
;
114 UINT temp_register_count
;
115 UINT int_instruction_count
;
116 UINT uint_instruction_count
;
117 UINT temp_array_count
;
118 UINT array_instruction_count
;
119 UINT texture_normal_instructions
;
120 UINT texture_load_instructions
;
121 UINT texture_comp_instructions
;
122 UINT texture_bias_instructions
;
123 UINT texture_gradient_instructions
;
124 UINT dynamic_flow_control_count
;
125 UINT c_control_points
;
126 D3D_TESSELLATOR_OUTPUT_PRIMITIVE hs_output_primitive
;
127 D3D_TESSELLATOR_PARTITIONING hs_prtitioning
;
128 D3D_TESSELLATOR_DOMAIN tessellator_domain
;
130 struct d3dcompiler_shader_signature
*isgn
;
131 struct d3dcompiler_shader_signature
*osgn
;
132 struct d3dcompiler_shader_signature
*pcsg
;
133 char *resource_string
;
134 D3D11_SHADER_INPUT_BIND_DESC
*bound_resources
;
135 struct d3dcompiler_shader_reflection_constant_buffer
*constant_buffers
;
136 struct wine_rb_tree types
;
139 static struct d3dcompiler_shader_reflection_type
*get_reflection_type(struct d3dcompiler_shader_reflection
*reflection
, const char *data
, DWORD offset
);
141 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl
;
142 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl
;
143 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl
;
145 /* null objects - needed for invalid calls */
146 static struct d3dcompiler_shader_reflection_constant_buffer null_constant_buffer
= {{&d3dcompiler_shader_reflection_constant_buffer_vtbl
}};
147 static struct d3dcompiler_shader_reflection_type null_type
= {{&d3dcompiler_shader_reflection_type_vtbl
}};
148 static struct d3dcompiler_shader_reflection_variable null_variable
= {{&d3dcompiler_shader_reflection_variable_vtbl
},
149 &null_constant_buffer
, &null_type
};
151 static BOOL
copy_name(const char *ptr
, char **name
)
155 if (!ptr
) return TRUE
;
157 name_len
= strlen(ptr
) + 1;
163 *name
= HeapAlloc(GetProcessHeap(), 0, name_len
);
166 ERR("Failed to allocate name memory.\n");
170 memcpy(*name
, ptr
, name_len
);
175 static BOOL
copy_value(const char *ptr
, void **value
, DWORD size
)
177 if (!ptr
|| !size
) return TRUE
;
179 *value
= HeapAlloc(GetProcessHeap(), 0, size
);
182 ERR("Failed to allocate value memory.\n");
186 memcpy(*value
, ptr
, size
);
191 static void *d3dcompiler_rb_alloc(size_t size
)
193 return HeapAlloc(GetProcessHeap(), 0, size
);
196 static void *d3dcompiler_rb_realloc(void *ptr
, size_t size
)
198 return HeapReAlloc(GetProcessHeap(), 0, ptr
, size
);
201 static void d3dcompiler_rb_free(void *ptr
)
203 HeapFree(GetProcessHeap(), 0, ptr
);
206 static int d3dcompiler_shader_reflection_type_compare(const void *key
, const struct wine_rb_entry
*entry
)
208 const struct d3dcompiler_shader_reflection_type
*t
= WINE_RB_ENTRY_VALUE(entry
, const struct d3dcompiler_shader_reflection_type
, entry
);
209 const DWORD
*id
= key
;
214 static void free_type_member(struct d3dcompiler_shader_reflection_type_member
*member
)
218 HeapFree(GetProcessHeap(), 0, member
->name
);
222 static void d3dcompiler_shader_reflection_type_destroy(struct wine_rb_entry
*entry
, void *context
)
224 struct d3dcompiler_shader_reflection_type
*t
= WINE_RB_ENTRY_VALUE(entry
, struct d3dcompiler_shader_reflection_type
, entry
);
227 TRACE("reflection type %p.\n", t
);
231 for (i
= 0; i
< t
->desc
.Members
; ++i
)
233 free_type_member(&t
->members
[i
]);
235 HeapFree(GetProcessHeap(), 0, t
->members
);
238 HeapFree(GetProcessHeap(), 0, t
);
241 static const struct wine_rb_functions d3dcompiler_shader_reflection_type_rb_functions
=
243 d3dcompiler_rb_alloc
,
244 d3dcompiler_rb_realloc
,
246 d3dcompiler_shader_reflection_type_compare
,
249 static void free_signature(struct d3dcompiler_shader_signature
*sig
)
251 TRACE("Free signature %p\n", sig
);
253 HeapFree(GetProcessHeap(), 0, sig
->elements
);
254 HeapFree(GetProcessHeap(), 0, sig
->string_data
);
257 static void free_variable(struct d3dcompiler_shader_reflection_variable
*var
)
261 HeapFree(GetProcessHeap(), 0, var
->name
);
262 HeapFree(GetProcessHeap(), 0, var
->default_value
);
266 static void free_constant_buffer(struct d3dcompiler_shader_reflection_constant_buffer
*cb
)
272 for (i
= 0; i
< cb
->variable_count
; ++i
)
274 free_variable(&cb
->variables
[i
]);
276 HeapFree(GetProcessHeap(), 0, cb
->variables
);
279 HeapFree(GetProcessHeap(), 0, cb
->name
);
282 static void reflection_cleanup(struct d3dcompiler_shader_reflection
*ref
)
284 TRACE("Cleanup %p\n", ref
);
288 free_signature(ref
->isgn
);
289 HeapFree(GetProcessHeap(), 0, ref
->isgn
);
294 free_signature(ref
->osgn
);
295 HeapFree(GetProcessHeap(), 0, ref
->osgn
);
300 free_signature(ref
->pcsg
);
301 HeapFree(GetProcessHeap(), 0, ref
->pcsg
);
304 if (ref
->constant_buffers
)
308 for (i
= 0; i
< ref
->constant_buffer_count
; ++i
)
310 free_constant_buffer(&ref
->constant_buffers
[i
]);
314 wine_rb_destroy(&ref
->types
, d3dcompiler_shader_reflection_type_destroy
, NULL
);
315 HeapFree(GetProcessHeap(), 0, ref
->constant_buffers
);
316 HeapFree(GetProcessHeap(), 0, ref
->bound_resources
);
317 HeapFree(GetProcessHeap(), 0, ref
->resource_string
);
318 HeapFree(GetProcessHeap(), 0, ref
->creator
);
321 /* IUnknown methods */
323 static inline struct d3dcompiler_shader_reflection
*impl_from_ID3D11ShaderReflection(ID3D11ShaderReflection
*iface
)
325 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection
, ID3D11ShaderReflection_iface
);
328 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_QueryInterface(ID3D11ShaderReflection
*iface
, REFIID riid
, void **object
)
330 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
332 if (IsEqualGUID(riid
, &IID_ID3D11ShaderReflection
)
333 || IsEqualGUID(riid
, &IID_IUnknown
))
335 IUnknown_AddRef(iface
);
340 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
343 return E_NOINTERFACE
;
346 static ULONG STDMETHODCALLTYPE
d3dcompiler_shader_reflection_AddRef(ID3D11ShaderReflection
*iface
)
348 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
349 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
351 TRACE("%p increasing refcount to %u\n", This
, refcount
);
356 static ULONG STDMETHODCALLTYPE
d3dcompiler_shader_reflection_Release(ID3D11ShaderReflection
*iface
)
358 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
359 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
361 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
365 reflection_cleanup(This
);
366 HeapFree(GetProcessHeap(), 0, This
);
372 /* ID3D11ShaderReflection methods */
374 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetDesc(ID3D11ShaderReflection
*iface
, D3D11_SHADER_DESC
*desc
)
376 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
378 FIXME("iface %p, desc %p partial stub!\n", iface
, desc
);
382 WARN("Invalid argument specified\n");
386 desc
->Version
= This
->version
;
387 desc
->Creator
= This
->creator
;
388 desc
->Flags
= This
->flags
;
389 desc
->ConstantBuffers
= This
->constant_buffer_count
;
390 desc
->BoundResources
= This
->bound_resource_count
;
391 desc
->InputParameters
= This
->isgn
? This
->isgn
->element_count
: 0;
392 desc
->OutputParameters
= This
->osgn
? This
->osgn
->element_count
: 0;
393 desc
->InstructionCount
= This
->instruction_count
;
394 desc
->TempRegisterCount
= This
->temp_register_count
;
395 desc
->TempArrayCount
= This
->temp_array_count
;
397 desc
->DclCount
= This
->dcl_count
;
398 desc
->TextureNormalInstructions
= This
->texture_normal_instructions
;
399 desc
->TextureLoadInstructions
= This
->texture_load_instructions
;
400 desc
->TextureCompInstructions
= This
->texture_comp_instructions
;
401 desc
->TextureBiasInstructions
= This
->texture_bias_instructions
;
402 desc
->TextureGradientInstructions
= This
->texture_gradient_instructions
;
403 desc
->FloatInstructionCount
= This
->float_instruction_count
;
404 desc
->IntInstructionCount
= This
->int_instruction_count
;
405 desc
->UintInstructionCount
= This
->uint_instruction_count
;
406 desc
->StaticFlowControlCount
= This
->static_flow_control_count
;
407 desc
->DynamicFlowControlCount
= This
->dynamic_flow_control_count
;
408 desc
->MacroInstructionCount
= 0;
409 desc
->ArrayInstructionCount
= This
->array_instruction_count
;
410 desc
->CutInstructionCount
= This
->cut_instruction_count
;
411 desc
->EmitInstructionCount
= This
->emit_instruction_count
;
412 desc
->GSOutputTopology
= This
->gs_output_topology
;
413 desc
->GSMaxOutputVertexCount
= This
->gs_max_output_vertex_count
;
414 desc
->InputPrimitive
= This
->input_primitive
;
415 desc
->PatchConstantParameters
= This
->pcsg
? This
->pcsg
->element_count
: 0;
416 desc
->cGSInstanceCount
= 0;
417 desc
->cControlPoints
= This
->c_control_points
;
418 desc
->HSOutputPrimitive
= This
->hs_output_primitive
;
419 desc
->HSPartitioning
= This
->hs_prtitioning
;
420 desc
->TessellatorDomain
= This
->tessellator_domain
;
421 desc
->cBarrierInstructions
= 0;
422 desc
->cInterlockedInstructions
= 0;
423 desc
->cTextureStoreInstructions
= 0;
428 static struct ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConstantBufferByIndex(
429 ID3D11ShaderReflection
*iface
, UINT index
)
431 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
433 TRACE("iface %p, index %u\n", iface
, index
);
435 if (index
>= This
->constant_buffer_count
)
437 WARN("Invalid argument specified\n");
438 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
441 return &This
->constant_buffers
[index
].ID3D11ShaderReflectionConstantBuffer_iface
;
444 static struct ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConstantBufferByName(
445 ID3D11ShaderReflection
*iface
, const char *name
)
447 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
450 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
454 WARN("Invalid argument specified\n");
455 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
458 for (i
= 0; i
< This
->constant_buffer_count
; ++i
)
460 struct d3dcompiler_shader_reflection_constant_buffer
*d
= &This
->constant_buffers
[i
];
462 if (!strcmp(d
->name
, name
))
464 TRACE("Returning ID3D11ShaderReflectionConstantBuffer %p.\n", d
);
465 return &d
->ID3D11ShaderReflectionConstantBuffer_iface
;
469 WARN("Invalid name specified\n");
471 return &null_constant_buffer
.ID3D11ShaderReflectionConstantBuffer_iface
;
474 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetResourceBindingDesc(
475 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SHADER_INPUT_BIND_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
|| index
>= This
->bound_resource_count
)
483 WARN("Invalid argument specified\n");
487 *desc
= This
->bound_resources
[index
];
492 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetInputParameterDesc(
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
->isgn
|| index
>= This
->isgn
->element_count
)
501 WARN("Invalid argument specified\n");
505 *desc
= This
->isgn
->elements
[index
];
510 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetOutputParameterDesc(
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
->osgn
|| index
>= This
->osgn
->element_count
)
519 WARN("Invalid argument specified\n");
523 *desc
= This
->osgn
->elements
[index
];
528 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetPatchConstantParameterDesc(
529 ID3D11ShaderReflection
*iface
, UINT index
, D3D11_SIGNATURE_PARAMETER_DESC
*desc
)
531 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
533 TRACE("iface %p, index %u, desc %p\n", iface
, index
, desc
);
535 if (!desc
|| !This
->pcsg
|| index
>= This
->pcsg
->element_count
)
537 WARN("Invalid argument specified\n");
541 *desc
= This
->pcsg
->elements
[index
];
546 static struct ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetVariableByName(
547 ID3D11ShaderReflection
*iface
, const char *name
)
549 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
552 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
556 WARN("Invalid name specified\n");
557 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
560 for (i
= 0; i
< This
->constant_buffer_count
; ++i
)
562 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= &This
->constant_buffers
[i
];
564 for (k
= 0; k
< cb
->variable_count
; ++k
)
566 struct d3dcompiler_shader_reflection_variable
*v
= &cb
->variables
[k
];
568 if (!strcmp(v
->name
, name
))
570 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v
);
571 return &v
->ID3D11ShaderReflectionVariable_iface
;
576 WARN("Invalid name specified\n");
578 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
581 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetResourceBindingDescByName(
582 ID3D11ShaderReflection
*iface
, const char *name
, D3D11_SHADER_INPUT_BIND_DESC
*desc
)
584 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
587 TRACE("iface %p, name %s, desc %p\n", iface
, debugstr_a(name
), desc
);
591 WARN("Invalid argument specified\n");
595 for (i
= 0; i
< This
->bound_resource_count
; ++i
)
597 D3D11_SHADER_INPUT_BIND_DESC
*d
= &This
->bound_resources
[i
];
599 if (!strcmp(d
->Name
, name
))
601 TRACE("Returning D3D11_SHADER_INPUT_BIND_DESC %p.\n", d
);
607 WARN("Invalid name specified\n");
612 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMovInstructionCount(
613 ID3D11ShaderReflection
*iface
)
615 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
617 TRACE("iface %p\n", iface
);
619 return This
->mov_instruction_count
;
622 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMovcInstructionCount(
623 ID3D11ShaderReflection
*iface
)
625 FIXME("iface %p stub!\n", iface
);
630 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetConversionInstructionCount(
631 ID3D11ShaderReflection
*iface
)
633 struct d3dcompiler_shader_reflection
*This
= impl_from_ID3D11ShaderReflection(iface
);
635 TRACE("iface %p\n", iface
);
637 return This
->conversion_instruction_count
;
640 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetBitwiseInstructionCount(
641 ID3D11ShaderReflection
*iface
)
643 FIXME("iface %p stub!\n", iface
);
648 static D3D_PRIMITIVE STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetGSInputPrimitive(
649 ID3D11ShaderReflection
*iface
)
651 FIXME("iface %p stub!\n", iface
);
656 static BOOL STDMETHODCALLTYPE
d3dcompiler_shader_reflection_IsSampleFrequencyShader(
657 ID3D11ShaderReflection
*iface
)
659 FIXME("iface %p stub!\n", iface
);
664 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetNumInterfaceSlots(
665 ID3D11ShaderReflection
*iface
)
667 FIXME("iface %p stub!\n", iface
);
672 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetMinFeatureLevel(
673 ID3D11ShaderReflection
*iface
, D3D_FEATURE_LEVEL
*level
)
675 FIXME("iface %p, level %p stub!\n", iface
, level
);
680 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_GetThreadGroupSize(
681 ID3D11ShaderReflection
*iface
, UINT
*sizex
, UINT
*sizey
, UINT
*sizez
)
683 FIXME("iface %p, sizex %p, sizey %p, sizez %p stub!\n", iface
, sizex
, sizey
, sizez
);
688 static const struct ID3D11ShaderReflectionVtbl d3dcompiler_shader_reflection_vtbl
=
690 /* IUnknown methods */
691 d3dcompiler_shader_reflection_QueryInterface
,
692 d3dcompiler_shader_reflection_AddRef
,
693 d3dcompiler_shader_reflection_Release
,
694 /* ID3D11ShaderReflection methods */
695 d3dcompiler_shader_reflection_GetDesc
,
696 d3dcompiler_shader_reflection_GetConstantBufferByIndex
,
697 d3dcompiler_shader_reflection_GetConstantBufferByName
,
698 d3dcompiler_shader_reflection_GetResourceBindingDesc
,
699 d3dcompiler_shader_reflection_GetInputParameterDesc
,
700 d3dcompiler_shader_reflection_GetOutputParameterDesc
,
701 d3dcompiler_shader_reflection_GetPatchConstantParameterDesc
,
702 d3dcompiler_shader_reflection_GetVariableByName
,
703 d3dcompiler_shader_reflection_GetResourceBindingDescByName
,
704 d3dcompiler_shader_reflection_GetMovInstructionCount
,
705 d3dcompiler_shader_reflection_GetMovcInstructionCount
,
706 d3dcompiler_shader_reflection_GetConversionInstructionCount
,
707 d3dcompiler_shader_reflection_GetBitwiseInstructionCount
,
708 d3dcompiler_shader_reflection_GetGSInputPrimitive
,
709 d3dcompiler_shader_reflection_IsSampleFrequencyShader
,
710 d3dcompiler_shader_reflection_GetNumInterfaceSlots
,
711 d3dcompiler_shader_reflection_GetMinFeatureLevel
,
712 d3dcompiler_shader_reflection_GetThreadGroupSize
,
715 /* ID3D11ShaderReflectionConstantBuffer methods */
717 static inline struct d3dcompiler_shader_reflection_constant_buffer
*impl_from_ID3D11ShaderReflectionConstantBuffer(ID3D11ShaderReflectionConstantBuffer
*iface
)
719 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_constant_buffer
, ID3D11ShaderReflectionConstantBuffer_iface
);
722 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetDesc(
723 ID3D11ShaderReflectionConstantBuffer
*iface
, D3D11_SHADER_BUFFER_DESC
*desc
)
725 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
727 TRACE("iface %p, desc %p\n", iface
, desc
);
729 if (This
== &null_constant_buffer
)
731 WARN("Null constant buffer specified\n");
737 WARN("Invalid argument specified\n");
741 desc
->Name
= This
->name
;
742 desc
->Type
= This
->type
;
743 desc
->Variables
= This
->variable_count
;
744 desc
->Size
= This
->size
;
745 desc
->uFlags
= This
->flags
;
750 static ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex(
751 ID3D11ShaderReflectionConstantBuffer
*iface
, UINT index
)
753 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
755 TRACE("iface %p, index %u\n", iface
, index
);
757 if (index
>= This
->variable_count
)
759 WARN("Invalid index specified\n");
760 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
763 return &This
->variables
[index
].ID3D11ShaderReflectionVariable_iface
;
766 static ID3D11ShaderReflectionVariable
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_constant_buffer_GetVariableByName(
767 ID3D11ShaderReflectionConstantBuffer
*iface
, const char *name
)
769 struct d3dcompiler_shader_reflection_constant_buffer
*This
= impl_from_ID3D11ShaderReflectionConstantBuffer(iface
);
772 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
776 WARN("Invalid argument specified\n");
777 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
780 for (i
= 0; i
< This
->variable_count
; ++i
)
782 struct d3dcompiler_shader_reflection_variable
*v
= &This
->variables
[i
];
784 if (!strcmp(v
->name
, name
))
786 TRACE("Returning ID3D11ShaderReflectionVariable %p.\n", v
);
787 return &v
->ID3D11ShaderReflectionVariable_iface
;
791 WARN("Invalid name specified\n");
793 return &null_variable
.ID3D11ShaderReflectionVariable_iface
;
796 static const struct ID3D11ShaderReflectionConstantBufferVtbl d3dcompiler_shader_reflection_constant_buffer_vtbl
=
798 /* ID3D11ShaderReflectionConstantBuffer methods */
799 d3dcompiler_shader_reflection_constant_buffer_GetDesc
,
800 d3dcompiler_shader_reflection_constant_buffer_GetVariableByIndex
,
801 d3dcompiler_shader_reflection_constant_buffer_GetVariableByName
,
804 /* ID3D11ShaderReflectionVariable methods */
806 static inline struct d3dcompiler_shader_reflection_variable
*impl_from_ID3D11ShaderReflectionVariable(ID3D11ShaderReflectionVariable
*iface
)
808 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_variable
, ID3D11ShaderReflectionVariable_iface
);
811 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetDesc(
812 ID3D11ShaderReflectionVariable
*iface
, D3D11_SHADER_VARIABLE_DESC
*desc
)
814 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
816 TRACE("iface %p, desc %p\n", iface
, desc
);
818 if (This
== &null_variable
)
820 WARN("Null variable specified\n");
826 WARN("Invalid argument specified\n");
830 desc
->Name
= This
->name
;
831 desc
->StartOffset
= This
->start_offset
;
832 desc
->Size
= This
->size
;
833 desc
->uFlags
= This
->flags
;
834 desc
->DefaultValue
= This
->default_value
;
839 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetType(
840 ID3D11ShaderReflectionVariable
*iface
)
842 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
844 TRACE("iface %p\n", iface
);
846 return &This
->type
->ID3D11ShaderReflectionType_iface
;
849 static ID3D11ShaderReflectionConstantBuffer
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetBuffer(
850 ID3D11ShaderReflectionVariable
*iface
)
852 struct d3dcompiler_shader_reflection_variable
*This
= impl_from_ID3D11ShaderReflectionVariable(iface
);
854 TRACE("iface %p\n", iface
);
856 return &This
->constant_buffer
->ID3D11ShaderReflectionConstantBuffer_iface
;
859 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_variable_GetInterfaceSlot(
860 ID3D11ShaderReflectionVariable
*iface
, UINT index
)
862 FIXME("iface %p, index %u stub!\n", iface
, index
);
867 static const struct ID3D11ShaderReflectionVariableVtbl d3dcompiler_shader_reflection_variable_vtbl
=
869 /* ID3D11ShaderReflectionVariable methods */
870 d3dcompiler_shader_reflection_variable_GetDesc
,
871 d3dcompiler_shader_reflection_variable_GetType
,
872 d3dcompiler_shader_reflection_variable_GetBuffer
,
873 d3dcompiler_shader_reflection_variable_GetInterfaceSlot
,
876 /* ID3D11ShaderReflectionType methods */
878 static inline struct d3dcompiler_shader_reflection_type
*impl_from_ID3D11ShaderReflectionType(ID3D11ShaderReflectionType
*iface
)
880 return CONTAINING_RECORD(iface
, struct d3dcompiler_shader_reflection_type
, ID3D11ShaderReflectionType_iface
);
883 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetDesc(
884 ID3D11ShaderReflectionType
*iface
, D3D11_SHADER_TYPE_DESC
*desc
)
886 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
888 TRACE("iface %p, desc %p\n", iface
, desc
);
890 if (This
== &null_type
)
892 WARN("Null type specified\n");
898 WARN("Invalid argument specified\n");
907 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeByIndex(
908 ID3D11ShaderReflectionType
*iface
, UINT index
)
910 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
912 TRACE("iface %p, index %u\n", iface
, index
);
914 if (index
>= This
->desc
.Members
)
916 WARN("Invalid index specified\n");
917 return &null_type
.ID3D11ShaderReflectionType_iface
;
920 return &This
->members
[index
].type
->ID3D11ShaderReflectionType_iface
;
923 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeByName(
924 ID3D11ShaderReflectionType
*iface
, const char *name
)
926 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
929 TRACE("iface %p, name %s\n", iface
, debugstr_a(name
));
933 WARN("Invalid argument specified\n");
934 return &null_type
.ID3D11ShaderReflectionType_iface
;
937 for (i
= 0; i
< This
->desc
.Members
; ++i
)
939 struct d3dcompiler_shader_reflection_type_member
*member
= &This
->members
[i
];
941 if (!strcmp(member
->name
, name
))
943 TRACE("Returning ID3D11ShaderReflectionType %p.\n", member
->type
);
944 return &member
->type
->ID3D11ShaderReflectionType_iface
;
948 WARN("Invalid name specified\n");
950 return &null_type
.ID3D11ShaderReflectionType_iface
;
953 static const char * STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetMemberTypeName(
954 ID3D11ShaderReflectionType
*iface
, UINT index
)
956 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
958 TRACE("iface %p, index %u\n", iface
, index
);
960 if (This
== &null_type
)
962 WARN("Null type specified\n");
966 if (index
>= This
->desc
.Members
)
968 WARN("Invalid index specified\n");
972 return This
->members
[index
].name
;
975 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_IsEqual(
976 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*type
)
978 struct d3dcompiler_shader_reflection_type
*This
= impl_from_ID3D11ShaderReflectionType(iface
);
980 TRACE("iface %p, type %p\n", iface
, type
);
982 if (This
== &null_type
)
984 WARN("Null type specified\n");
994 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetSubType(
995 ID3D11ShaderReflectionType
*iface
)
997 FIXME("iface %p stub!\n", iface
);
1002 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetBaseClass(
1003 ID3D11ShaderReflectionType
*iface
)
1005 FIXME("iface %p stub!\n", iface
);
1010 static UINT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetNumInterfaces(
1011 ID3D11ShaderReflectionType
*iface
)
1013 FIXME("iface %p stub!\n", iface
);
1018 static ID3D11ShaderReflectionType
* STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_GetInterfaceByIndex(
1019 ID3D11ShaderReflectionType
*iface
, UINT index
)
1021 FIXME("iface %p, index %u stub!\n", iface
, index
);
1026 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_IsOfType(
1027 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*type
)
1029 FIXME("iface %p, type %p stub!\n", iface
, type
);
1034 static HRESULT STDMETHODCALLTYPE
d3dcompiler_shader_reflection_type_ImplementsInterface(
1035 ID3D11ShaderReflectionType
*iface
, ID3D11ShaderReflectionType
*base
)
1037 FIXME("iface %p, base %p stub!\n", iface
, base
);
1042 static const struct ID3D11ShaderReflectionTypeVtbl d3dcompiler_shader_reflection_type_vtbl
=
1044 /* ID3D11ShaderReflectionType methods */
1045 d3dcompiler_shader_reflection_type_GetDesc
,
1046 d3dcompiler_shader_reflection_type_GetMemberTypeByIndex
,
1047 d3dcompiler_shader_reflection_type_GetMemberTypeByName
,
1048 d3dcompiler_shader_reflection_type_GetMemberTypeName
,
1049 d3dcompiler_shader_reflection_type_IsEqual
,
1050 d3dcompiler_shader_reflection_type_GetSubType
,
1051 d3dcompiler_shader_reflection_type_GetBaseClass
,
1052 d3dcompiler_shader_reflection_type_GetNumInterfaces
,
1053 d3dcompiler_shader_reflection_type_GetInterfaceByIndex
,
1054 d3dcompiler_shader_reflection_type_IsOfType
,
1055 d3dcompiler_shader_reflection_type_ImplementsInterface
,
1058 static HRESULT
d3dcompiler_parse_stat(struct d3dcompiler_shader_reflection
*r
, const char *data
, DWORD data_size
)
1060 const char *ptr
= data
;
1061 DWORD size
= data_size
>> 2;
1063 TRACE("Size %u\n", size
);
1065 read_dword(&ptr
, &r
->instruction_count
);
1066 TRACE("InstructionCount: %u\n", r
->instruction_count
);
1068 read_dword(&ptr
, &r
->temp_register_count
);
1069 TRACE("TempRegisterCount: %u\n", r
->temp_register_count
);
1071 skip_dword_unknown(&ptr
, 1);
1073 read_dword(&ptr
, &r
->dcl_count
);
1074 TRACE("DclCount: %u\n", r
->dcl_count
);
1076 read_dword(&ptr
, &r
->float_instruction_count
);
1077 TRACE("FloatInstructionCount: %u\n", r
->float_instruction_count
);
1079 read_dword(&ptr
, &r
->int_instruction_count
);
1080 TRACE("IntInstructionCount: %u\n", r
->int_instruction_count
);
1082 read_dword(&ptr
, &r
->uint_instruction_count
);
1083 TRACE("UintInstructionCount: %u\n", r
->uint_instruction_count
);
1085 read_dword(&ptr
, &r
->static_flow_control_count
);
1086 TRACE("StaticFlowControlCount: %u\n", r
->static_flow_control_count
);
1088 read_dword(&ptr
, &r
->dynamic_flow_control_count
);
1089 TRACE("DynamicFlowControlCount: %u\n", r
->dynamic_flow_control_count
);
1091 skip_dword_unknown(&ptr
, 1);
1093 read_dword(&ptr
, &r
->temp_array_count
);
1094 TRACE("TempArrayCount: %u\n", r
->temp_array_count
);
1096 read_dword(&ptr
, &r
->array_instruction_count
);
1097 TRACE("ArrayInstructionCount: %u\n", r
->array_instruction_count
);
1099 read_dword(&ptr
, &r
->cut_instruction_count
);
1100 TRACE("CutInstructionCount: %u\n", r
->cut_instruction_count
);
1102 read_dword(&ptr
, &r
->emit_instruction_count
);
1103 TRACE("EmitInstructionCount: %u\n", r
->emit_instruction_count
);
1105 read_dword(&ptr
, &r
->texture_normal_instructions
);
1106 TRACE("TextureNormalInstructions: %u\n", r
->texture_normal_instructions
);
1108 read_dword(&ptr
, &r
->texture_load_instructions
);
1109 TRACE("TextureLoadInstructions: %u\n", r
->texture_load_instructions
);
1111 read_dword(&ptr
, &r
->texture_comp_instructions
);
1112 TRACE("TextureCompInstructions: %u\n", r
->texture_comp_instructions
);
1114 read_dword(&ptr
, &r
->texture_bias_instructions
);
1115 TRACE("TextureBiasInstructions: %u\n", r
->texture_bias_instructions
);
1117 read_dword(&ptr
, &r
->texture_gradient_instructions
);
1118 TRACE("TextureGradientInstructions: %u\n", r
->texture_gradient_instructions
);
1120 read_dword(&ptr
, &r
->mov_instruction_count
);
1121 TRACE("MovInstructionCount: %u\n", r
->mov_instruction_count
);
1123 skip_dword_unknown(&ptr
, 1);
1125 read_dword(&ptr
, &r
->conversion_instruction_count
);
1126 TRACE("ConversionInstructionCount: %u\n", r
->conversion_instruction_count
);
1128 skip_dword_unknown(&ptr
, 1);
1130 read_dword(&ptr
, &r
->input_primitive
);
1131 TRACE("InputPrimitive: %x\n", r
->input_primitive
);
1133 read_dword(&ptr
, &r
->gs_output_topology
);
1134 TRACE("GSOutputTopology: %x\n", r
->gs_output_topology
);
1136 read_dword(&ptr
, &r
->gs_max_output_vertex_count
);
1137 TRACE("GSMaxOutputVertexCount: %u\n", r
->gs_max_output_vertex_count
);
1139 skip_dword_unknown(&ptr
, 3);
1141 /* dx10 stat size */
1142 if (size
== 29) return S_OK
;
1144 skip_dword_unknown(&ptr
, 1);
1146 read_dword(&ptr
, &r
->c_control_points
);
1147 TRACE("cControlPoints: %u\n", r
->c_control_points
);
1149 read_dword(&ptr
, &r
->hs_output_primitive
);
1150 TRACE("HSOutputPrimitive: %x\n", r
->hs_output_primitive
);
1152 read_dword(&ptr
, &r
->hs_prtitioning
);
1153 TRACE("HSPartitioning: %x\n", r
->hs_prtitioning
);
1155 read_dword(&ptr
, &r
->tessellator_domain
);
1156 TRACE("TessellatorDomain: %x\n", r
->tessellator_domain
);
1158 skip_dword_unknown(&ptr
, 3);
1160 /* dx11 stat size */
1161 if (size
== 37) return S_OK
;
1163 FIXME("Unhandled size %u\n", size
);
1168 static HRESULT
d3dcompiler_parse_type_members(struct d3dcompiler_shader_reflection
*ref
,
1169 struct d3dcompiler_shader_reflection_type_member
*member
, const char *data
, const char **ptr
)
1173 read_dword(ptr
, &offset
);
1174 if (!copy_name(data
+ offset
, &member
->name
))
1176 ERR("Failed to copy name.\n");
1177 return E_OUTOFMEMORY
;
1179 TRACE("Member name: %s.\n", debugstr_a(member
->name
));
1181 read_dword(ptr
, &offset
);
1182 TRACE("Member type offset: %x\n", offset
);
1184 member
->type
= get_reflection_type(ref
, data
, offset
);
1187 ERR("Failed to get member type\n");
1188 HeapFree(GetProcessHeap(), 0, member
->name
);
1192 read_dword(ptr
, &member
->offset
);
1193 TRACE("Member offset %x\n", member
->offset
);
1198 static HRESULT
d3dcompiler_parse_type(struct d3dcompiler_shader_reflection_type
*type
, const char *data
, DWORD offset
)
1200 const char *ptr
= data
+ offset
;
1202 D3D11_SHADER_TYPE_DESC
*desc
;
1204 struct d3dcompiler_shader_reflection_type_member
*members
= NULL
;
1206 DWORD member_offset
;
1210 read_dword(&ptr
, &temp
);
1211 desc
->Class
= temp
& 0xffff;
1212 desc
->Type
= temp
>> 16;
1213 TRACE("Class %s, Type %s\n", debug_d3dcompiler_shader_variable_class(desc
->Class
),
1214 debug_d3dcompiler_shader_variable_type(desc
->Type
));
1216 read_dword(&ptr
, &temp
);
1217 desc
->Rows
= temp
& 0xffff;
1218 desc
->Columns
= temp
>> 16;
1219 TRACE("Rows %u, Columns %u\n", desc
->Rows
, desc
->Columns
);
1221 read_dword(&ptr
, &temp
);
1222 desc
->Elements
= temp
& 0xffff;
1223 desc
->Members
= temp
>> 16;
1224 TRACE("Elements %u, Members %u\n", desc
->Elements
, desc
->Members
);
1226 read_dword(&ptr
, &member_offset
);
1227 TRACE("Member Offset %u\n", member_offset
);
1229 if ((type
->reflection
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1230 skip_dword_unknown(&ptr
, 4);
1234 const char *ptr2
= data
+ member_offset
;
1236 members
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*members
) * desc
->Members
);
1239 ERR("Failed to allocate type memory.\n");
1240 return E_OUTOFMEMORY
;
1243 for (i
= 0; i
< desc
->Members
; ++i
)
1245 hr
= d3dcompiler_parse_type_members(type
->reflection
, &members
[i
], data
, &ptr2
);
1248 FIXME("Failed to parse type members.\n");
1254 type
->members
= members
;
1259 for (i
= 0; i
< desc
->Members
; ++i
)
1261 free_type_member(&members
[i
]);
1263 HeapFree(GetProcessHeap(), 0, members
);
1267 static struct d3dcompiler_shader_reflection_type
*get_reflection_type(struct d3dcompiler_shader_reflection
*reflection
, const char *data
, DWORD offset
)
1269 struct d3dcompiler_shader_reflection_type
*type
;
1270 struct wine_rb_entry
*entry
;
1273 entry
= wine_rb_get(&reflection
->types
, &offset
);
1276 TRACE("Returning existing type.\n");
1277 return WINE_RB_ENTRY_VALUE(entry
, struct d3dcompiler_shader_reflection_type
, entry
);
1280 type
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*type
));
1284 type
->ID3D11ShaderReflectionType_iface
.lpVtbl
= &d3dcompiler_shader_reflection_type_vtbl
;
1286 type
->reflection
= reflection
;
1288 hr
= d3dcompiler_parse_type(type
, data
, offset
);
1291 ERR("Failed to parse type info, hr %#x.\n", hr
);
1292 HeapFree(GetProcessHeap(), 0, type
);
1296 if (wine_rb_put(&reflection
->types
, &offset
, &type
->entry
) == -1)
1298 ERR("Failed to insert type entry.\n");
1299 HeapFree(GetProcessHeap(), 0, type
);
1306 static HRESULT
d3dcompiler_parse_variables(struct d3dcompiler_shader_reflection_constant_buffer
*cb
,
1307 const char *data
, DWORD data_size
, const char *ptr
)
1309 struct d3dcompiler_shader_reflection_variable
*variables
;
1313 variables
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, cb
->variable_count
* sizeof(*variables
));
1316 ERR("Failed to allocate variables memory.\n");
1317 return E_OUTOFMEMORY
;
1320 for (i
= 0; i
< cb
->variable_count
; i
++)
1322 struct d3dcompiler_shader_reflection_variable
*v
= &variables
[i
];
1325 v
->ID3D11ShaderReflectionVariable_iface
.lpVtbl
= &d3dcompiler_shader_reflection_variable_vtbl
;
1326 v
->constant_buffer
= cb
;
1328 read_dword(&ptr
, &offset
);
1329 if (!copy_name(data
+ offset
, &v
->name
))
1331 ERR("Failed to copy name.\n");
1335 TRACE("Variable name: %s.\n", debugstr_a(v
->name
));
1337 read_dword(&ptr
, &v
->start_offset
);
1338 TRACE("Variable offset: %u\n", v
->start_offset
);
1340 read_dword(&ptr
, &v
->size
);
1341 TRACE("Variable size: %u\n", v
->size
);
1343 read_dword(&ptr
, &v
->flags
);
1344 TRACE("Variable flags: %u\n", v
->flags
);
1346 read_dword(&ptr
, &offset
);
1347 TRACE("Variable type offset: %x\n", offset
);
1348 v
->type
= get_reflection_type(cb
->reflection
, data
, offset
);
1351 ERR("Failed to get type.\n");
1356 read_dword(&ptr
, &offset
);
1357 TRACE("Variable default value offset: %x\n", offset
);
1358 if (!copy_value(data
+ offset
, &v
->default_value
, offset
? v
->size
: 0))
1360 ERR("Failed to copy name.\n");
1365 if ((cb
->reflection
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1366 skip_dword_unknown(&ptr
, 4);
1369 cb
->variables
= variables
;
1374 for (i
= 0; i
< cb
->variable_count
; i
++)
1376 free_variable(&variables
[i
]);
1378 HeapFree(GetProcessHeap(), 0, variables
);
1382 static HRESULT
d3dcompiler_parse_rdef(struct d3dcompiler_shader_reflection
*r
, const char *data
, DWORD data_size
)
1384 const char *ptr
= data
;
1385 DWORD size
= data_size
>> 2;
1386 DWORD offset
, cbuffer_offset
, resource_offset
, creator_offset
;
1387 unsigned int i
, string_data_offset
, string_data_size
;
1388 char *string_data
= NULL
, *creator
= NULL
;
1389 D3D11_SHADER_INPUT_BIND_DESC
*bound_resources
= NULL
;
1390 struct d3dcompiler_shader_reflection_constant_buffer
*constant_buffers
= NULL
;
1393 TRACE("Size %u\n", size
);
1395 read_dword(&ptr
, &r
->constant_buffer_count
);
1396 TRACE("Constant buffer count: %u\n", r
->constant_buffer_count
);
1398 read_dword(&ptr
, &cbuffer_offset
);
1399 TRACE("Constant buffer offset: %#x\n", cbuffer_offset
);
1401 read_dword(&ptr
, &r
->bound_resource_count
);
1402 TRACE("Bound resource count: %u\n", r
->bound_resource_count
);
1404 read_dword(&ptr
, &resource_offset
);
1405 TRACE("Bound resource offset: %#x\n", resource_offset
);
1407 read_dword(&ptr
, &r
->target
);
1408 TRACE("Target: %#x\n", r
->target
);
1410 read_dword(&ptr
, &r
->flags
);
1411 TRACE("Flags: %u\n", r
->flags
);
1413 read_dword(&ptr
, &creator_offset
);
1414 TRACE("Creator at offset %#x.\n", creator_offset
);
1416 if (!copy_name(data
+ creator_offset
, &creator
))
1418 ERR("Failed to copy name.\n");
1419 return E_OUTOFMEMORY
;
1421 TRACE("Creator: %s.\n", debugstr_a(creator
));
1423 /* todo: Parse RD11 */
1424 if ((r
->target
& D3DCOMPILER_SHADER_TARGET_VERSION_MASK
) >= 0x500)
1426 skip_dword_unknown(&ptr
, 8);
1429 if (r
->bound_resource_count
)
1431 /* 8 for each bind desc */
1432 string_data_offset
= resource_offset
+ r
->bound_resource_count
* 8 * sizeof(DWORD
);
1433 string_data_size
= (cbuffer_offset
? cbuffer_offset
: creator_offset
) - string_data_offset
;
1435 string_data
= HeapAlloc(GetProcessHeap(), 0, string_data_size
);
1438 ERR("Failed to allocate string data memory.\n");
1442 memcpy(string_data
, data
+ string_data_offset
, string_data_size
);
1444 bound_resources
= HeapAlloc(GetProcessHeap(), 0, r
->bound_resource_count
* sizeof(*bound_resources
));
1445 if (!bound_resources
)
1447 ERR("Failed to allocate resources memory.\n");
1452 ptr
= data
+ resource_offset
;
1453 for (i
= 0; i
< r
->bound_resource_count
; i
++)
1455 D3D11_SHADER_INPUT_BIND_DESC
*desc
= &bound_resources
[i
];
1457 read_dword(&ptr
, &offset
);
1458 desc
->Name
= string_data
+ (offset
- string_data_offset
);
1459 TRACE("Input bind Name: %s\n", debugstr_a(desc
->Name
));
1461 read_dword(&ptr
, &desc
->Type
);
1462 TRACE("Input bind Type: %#x\n", desc
->Type
);
1464 read_dword(&ptr
, &desc
->ReturnType
);
1465 TRACE("Input bind ReturnType: %#x\n", desc
->ReturnType
);
1467 read_dword(&ptr
, &desc
->Dimension
);
1468 TRACE("Input bind Dimension: %#x\n", desc
->Dimension
);
1470 read_dword(&ptr
, &desc
->NumSamples
);
1471 TRACE("Input bind NumSamples: %u\n", desc
->NumSamples
);
1473 read_dword(&ptr
, &desc
->BindPoint
);
1474 TRACE("Input bind BindPoint: %u\n", desc
->BindPoint
);
1476 read_dword(&ptr
, &desc
->BindCount
);
1477 TRACE("Input bind BindCount: %u\n", desc
->BindCount
);
1479 read_dword(&ptr
, &desc
->uFlags
);
1480 TRACE("Input bind uFlags: %u\n", desc
->uFlags
);
1484 if (r
->constant_buffer_count
)
1486 constant_buffers
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, r
->constant_buffer_count
* sizeof(*constant_buffers
));
1487 if (!constant_buffers
)
1489 ERR("Failed to allocate constant buffer memory.\n");
1494 ptr
= data
+ cbuffer_offset
;
1495 for (i
= 0; i
< r
->constant_buffer_count
; i
++)
1497 struct d3dcompiler_shader_reflection_constant_buffer
*cb
= &constant_buffers
[i
];
1499 cb
->ID3D11ShaderReflectionConstantBuffer_iface
.lpVtbl
= &d3dcompiler_shader_reflection_constant_buffer_vtbl
;
1502 read_dword(&ptr
, &offset
);
1503 if (!copy_name(data
+ offset
, &cb
->name
))
1505 ERR("Failed to copy name.\n");
1509 TRACE("Name: %s.\n", debugstr_a(cb
->name
));
1511 read_dword(&ptr
, &cb
->variable_count
);
1512 TRACE("Variable count: %u\n", cb
->variable_count
);
1514 read_dword(&ptr
, &offset
);
1515 TRACE("Variable offset: %x\n", offset
);
1517 hr
= d3dcompiler_parse_variables(cb
, data
, data_size
, data
+ offset
);
1520 FIXME("Failed to parse variables.\n");
1524 read_dword(&ptr
, &cb
->size
);
1525 TRACE("Cbuffer size: %u\n", cb
->size
);
1527 read_dword(&ptr
, &cb
->flags
);
1528 TRACE("Cbuffer flags: %u\n", cb
->flags
);
1530 read_dword(&ptr
, &cb
->type
);
1531 TRACE("Cbuffer type: %#x\n", cb
->type
);
1535 r
->creator
= creator
;
1536 r
->resource_string
= string_data
;
1537 r
->bound_resources
= bound_resources
;
1538 r
->constant_buffers
= constant_buffers
;
1543 for (i
= 0; i
< r
->constant_buffer_count
; ++i
)
1545 free_constant_buffer(&constant_buffers
[i
]);
1547 HeapFree(GetProcessHeap(), 0, constant_buffers
);
1548 HeapFree(GetProcessHeap(), 0, bound_resources
);
1549 HeapFree(GetProcessHeap(), 0, string_data
);
1550 HeapFree(GetProcessHeap(), 0, creator
);
1555 static HRESULT
d3dcompiler_parse_signature(struct d3dcompiler_shader_signature
*s
, struct dxbc_section
*section
, DWORD target
)
1557 D3D11_SIGNATURE_PARAMETER_DESC
*d
;
1558 unsigned int string_data_offset
;
1559 unsigned int string_data_size
;
1560 const char *ptr
= section
->data
;
1564 enum D3DCOMPILER_SIGNATURE_ELEMENT_SIZE element_size
;
1566 switch (section
->tag
)
1569 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
;
1575 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
;
1579 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion
->tag
, 4));
1580 element_size
= D3DCOMPILER_SIGNATURE_ELEMENT_SIZE6
;
1584 read_dword(&ptr
, &count
);
1585 TRACE("%u elements\n", count
);
1587 skip_dword_unknown(&ptr
, 1);
1589 d
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(*d
));
1592 ERR("Failed to allocate signature memory.\n");
1593 return E_OUTOFMEMORY
;
1596 /* 2 DWORDs for the header, element_size for each element. */
1597 string_data_offset
= 2 * sizeof(DWORD
) + count
* element_size
* sizeof(DWORD
);
1598 string_data_size
= section
->data_size
- string_data_offset
;
1600 string_data
= HeapAlloc(GetProcessHeap(), 0, string_data_size
);
1603 ERR("Failed to allocate string data memory.\n");
1604 HeapFree(GetProcessHeap(), 0, d
);
1605 return E_OUTOFMEMORY
;
1607 memcpy(string_data
, section
->data
+ string_data_offset
, string_data_size
);
1609 for (i
= 0; i
< count
; ++i
)
1614 if (element_size
== D3DCOMPILER_SIGNATURE_ELEMENT_SIZE7
)
1616 read_dword(&ptr
, &d
[i
].Stream
);
1623 read_dword(&ptr
, &name_offset
);
1624 d
[i
].SemanticName
= string_data
+ (name_offset
- string_data_offset
);
1625 read_dword(&ptr
, &d
[i
].SemanticIndex
);
1626 read_dword(&ptr
, &d
[i
].SystemValueType
);
1627 read_dword(&ptr
, &d
[i
].ComponentType
);
1628 read_dword(&ptr
, &d
[i
].Register
);
1629 read_dword(&ptr
, &mask
);
1630 d
[i
].ReadWriteMask
= (mask
>> 8) & 0xff;
1631 d
[i
].Mask
= mask
& 0xff;
1633 /* pixel shaders have a special handling for SystemValueType in the output signature */
1634 if (((target
& D3DCOMPILER_SHADER_TARGET_SHADERTYPE_MASK
) == 0xffff0000) && (section
->tag
== TAG_OSG5
|| section
->tag
== TAG_OSGN
))
1636 TRACE("Pixelshader output signature fixup.\n");
1638 if (d
[i
].Register
== 0xffffffff)
1640 if (!strcasecmp(d
[i
].SemanticName
, "sv_depth")) d
[i
].SystemValueType
= D3D_NAME_DEPTH
;
1641 if (!strcasecmp(d
[i
].SemanticName
, "sv_coverage")) d
[i
].SystemValueType
= D3D_NAME_COVERAGE
;
1642 if (!strcasecmp(d
[i
].SemanticName
, "sv_depthgreaterequal")) d
[i
].SystemValueType
= D3D_NAME_DEPTH_GREATER_EQUAL
;
1643 if (!strcasecmp(d
[i
].SemanticName
, "sv_depthlessequal")) 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 if (wine_rb_init(&reflection
->types
, &d3dcompiler_shader_reflection_type_rb_functions
) == -1)
1688 ERR("Failed to initialize type rbtree.\n");
1692 hr
= dxbc_parse(data
, data_size
, &src_dxbc
);
1695 WARN("Failed to parse reflection\n");
1699 for (i
= 0; i
< src_dxbc
.count
; ++i
)
1701 struct dxbc_section
*section
= &src_dxbc
.sections
[i
];
1703 switch (section
->tag
)
1706 hr
= d3dcompiler_parse_rdef(reflection
, section
->data
, section
->data_size
);
1709 WARN("Failed to parse RDEF section.\n");
1715 reflection
->isgn
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->isgn
));
1716 if (!reflection
->isgn
)
1718 ERR("Failed to allocate ISGN memory.\n");
1723 hr
= d3dcompiler_parse_signature(reflection
->isgn
, section
, reflection
->target
);
1726 WARN("Failed to parse section ISGN.\n");
1733 reflection
->osgn
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->osgn
));
1734 if (!reflection
->osgn
)
1736 ERR("Failed to allocate OSGN memory.\n");
1741 hr
= d3dcompiler_parse_signature(reflection
->osgn
, section
, reflection
->target
);
1744 WARN("Failed to parse section OSGN.\n");
1750 reflection
->pcsg
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*reflection
->pcsg
));
1751 if (!reflection
->pcsg
)
1753 ERR("Failed to allocate PCSG memory.\n");
1758 hr
= d3dcompiler_parse_signature(reflection
->pcsg
, section
, reflection
->target
);
1761 WARN("Failed to parse section PCSG.\n");
1768 hr
= d3dcompiler_parse_shdr(reflection
, section
->data
, section
->data_size
);
1771 WARN("Failed to parse SHDR section.\n");
1777 hr
= d3dcompiler_parse_stat(reflection
, section
->data
, section
->data_size
);
1780 WARN("Failed to parse section STAT.\n");
1786 FIXME("Unhandled section %s!\n", debugstr_an((const char *)§ion
->tag
, 4));
1791 dxbc_destroy(&src_dxbc
);
1796 reflection_cleanup(reflection
);
1797 dxbc_destroy(&src_dxbc
);
1802 HRESULT WINAPI
D3DReflect(const void *data
, SIZE_T data_size
, REFIID riid
, void **reflector
)
1804 struct d3dcompiler_shader_reflection
*object
;
1806 const DWORD
*temp
= data
;
1808 TRACE("data %p, data_size %lu, riid %s, blob %p\n", data
, data_size
, debugstr_guid(riid
), reflector
);
1810 if (!data
|| data_size
< 32)
1812 WARN("Invalid argument supplied.\n");
1813 return D3DERR_INVALIDCALL
;
1816 if (temp
[6] != data_size
)
1818 WARN("Wrong size supplied.\n");
1822 if (!IsEqualGUID(riid
, &IID_ID3D11ShaderReflection
))
1824 WARN("Wrong riid %s, accept only %s!\n", debugstr_guid(riid
), debugstr_guid(&IID_ID3D11ShaderReflection
));
1825 return E_NOINTERFACE
;
1828 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1830 return E_OUTOFMEMORY
;
1832 hr
= d3dcompiler_shader_reflection_init(object
, data
, data_size
);
1835 WARN("Failed to initialize shader reflection\n");
1836 HeapFree(GetProcessHeap(), 0, object
);
1840 *reflector
= object
;
1842 TRACE("Created ID3D11ShaderReflection %p\n", object
);