1 module aurora.directx.d3d11.d3d11shadertracing;
2 
3 version(Windows):
4 
5 public import aurora.directx.d3d.d3dcommon;
6 
7 public:
8 
9 ///
10 /// Constants
11 ///
12 
13 enum int COMPONENT_X = 0x1;
14 enum int COMPONENT_Y = 0x2;
15 enum int COMPONENT_Z = 0x4;
16 enum int COMPONENT_W = 0x8;
17 
18 enum int D3D11_SHADER_TRACE_FLAG_RECORD_REGISTER_WRITES = 0x1;
19 enum int D3D11_SHADER_TRACE_FLAG_RECORD_REGISTER_READS = 0x2;
20 
21 alias ubyte COMPONENT_MASK;
22 
23 enum int D3D11_TRACE_MISC_GS_EMIT = 0x1;
24 enum int D3D11_TRACE_MISC_GS_CUT = 0x2; 
25 enum int D3D11_TRACE_MISC_PS_DISCARD = 0x4; 
26 enum int D3D11_TRACE_MISC_GS_EMIT_STREAM = 0x8; 
27 enum int D3D11_TRACE_MISC_GS_CUT_STREAM = 0x10; 
28 enum int D3D11_TRACE_MISC_HALT = 0x20; 
29 enum int D3D11_TRACE_MISC_MESSAGE = 0x40; 
30 
31 alias ushort D3D11_TRACE_MISC_OPERATIONS_MASK;
32 
33 ///
34 /// Functions
35 ///
36 
37 extern(Windows) {
38     HRESULT D3DDisassemble11Trace(const void *pSrcData, size_t SrcDataSize, ID3D11ShaderTrace pTrace, uint StartStep, uint NumSteps, uint Flags, ID3D10Blob* ppDisassembly);
39 }
40 
41 ///
42 /// Enumerations
43 ///
44 
45 enum D3D11_SHADER_TYPE
46 {
47     D3D11_VERTEX_SHADER	= 1,
48     D3D11_HULL_SHADER = 2,
49     D3D11_DOMAIN_SHADER	= 3,
50     D3D11_GEOMETRY_SHADER = 4,
51     D3D11_PIXEL_SHADER = 5,
52     D3D11_COMPUTE_SHADER = 6
53 }
54 
55 enum D3D11_TRACE_GS_INPUT_PRIMITIVE
56 {
57     UNDEFINED	= 0,
58     POINT	= 1,
59     LINE	= 2,
60     TRIANGLE	= 3,
61     LINE_ADJ	= 6,
62     TRIANGLE_ADJ	= 7
63 }
64 
65 enum D3D11_TRACE_REGISTER_TYPE
66 {
67     OUTPUT_NULL_REGISTER	= 0,
68     INPUT_REGISTER	= ( OUTPUT_NULL_REGISTER + 1 ) ,
69     INPUT_PRIMITIVE_ID_REGISTER	= ( INPUT_REGISTER + 1 ) ,
70     IMMEDIATE_CONSTANT_BUFFER	= ( INPUT_PRIMITIVE_ID_REGISTER + 1 ) ,
71     TEMP_REGISTER	= ( IMMEDIATE_CONSTANT_BUFFER + 1 ) ,
72     INDEXABLE_TEMP_REGISTER	= ( TEMP_REGISTER + 1 ) ,
73     OUTPUT_REGISTER	= ( INDEXABLE_TEMP_REGISTER + 1 ) ,
74     OUTPUT_DEPTH_REGISTER	= ( OUTPUT_REGISTER + 1 ) ,
75     CONSTANT_BUFFER	= ( OUTPUT_DEPTH_REGISTER + 1 ) ,
76     IMMEDIATE32	= ( CONSTANT_BUFFER + 1 ) ,
77     SAMPLER	= ( IMMEDIATE32 + 1 ) ,
78     RESOURCE	= ( SAMPLER + 1 ) ,
79     RASTERIZER	= ( RESOURCE + 1 ) ,
80     OUTPUT_COVERAGE_MASK	= ( RASTERIZER + 1 ) ,
81     STREAM	= ( OUTPUT_COVERAGE_MASK + 1 ) ,
82     THIS_POINTER	= ( STREAM + 1 ) ,
83     OUTPUT_CONTROL_POINT_ID_REGISTER	= ( THIS_POINTER + 1 ) ,
84     INPUT_FORK_INSTANCE_ID_REGISTER	= ( OUTPUT_CONTROL_POINT_ID_REGISTER + 1 ) ,
85     INPUT_JOIN_INSTANCE_ID_REGISTER	= ( INPUT_FORK_INSTANCE_ID_REGISTER + 1 ) ,
86     INPUT_CONTROL_POINT_REGISTER	= ( INPUT_JOIN_INSTANCE_ID_REGISTER + 1 ) ,
87     OUTPUT_CONTROL_POINT_REGISTER	= ( INPUT_CONTROL_POINT_REGISTER + 1 ) ,
88     INPUT_PATCH_CONSTANT_REGISTER	= ( OUTPUT_CONTROL_POINT_REGISTER + 1 ) ,
89     INPUT_DOMAIN_POINT_REGISTER	= ( INPUT_PATCH_CONSTANT_REGISTER + 1 ) ,
90     UNORDERED_ACCESS_VIEW	= ( INPUT_DOMAIN_POINT_REGISTER + 1 ) ,
91     THREAD_GROUP_SHARED_MEMORY	= ( UNORDERED_ACCESS_VIEW + 1 ) ,
92     INPUT_THREAD_ID_REGISTER	= ( THREAD_GROUP_SHARED_MEMORY + 1 ) ,
93     INPUT_THREAD_GROUP_ID_REGISTER	= ( INPUT_THREAD_ID_REGISTER + 1 ) ,
94     INPUT_THREAD_ID_IN_GROUP_REGISTER	= ( INPUT_THREAD_GROUP_ID_REGISTER + 1 ) ,
95     INPUT_COVERAGE_MASK_REGISTER	= ( INPUT_THREAD_ID_IN_GROUP_REGISTER + 1 ) ,
96     INPUT_THREAD_ID_IN_GROUP_FLATTENED_REGISTER	= ( INPUT_COVERAGE_MASK_REGISTER + 1 ) ,
97     INPUT_GS_INSTANCE_ID_REGISTER	= ( INPUT_THREAD_ID_IN_GROUP_FLATTENED_REGISTER + 1 ) ,
98     OUTPUT_DEPTH_GREATER_EQUAL_REGISTER	= ( INPUT_GS_INSTANCE_ID_REGISTER + 1 ) ,
99     OUTPUT_DEPTH_LESS_EQUAL_REGISTER	= ( OUTPUT_DEPTH_GREATER_EQUAL_REGISTER + 1 ) ,
100     IMMEDIATE64	= ( OUTPUT_DEPTH_LESS_EQUAL_REGISTER + 1 ) ,
101     INPUT_CYCLE_COUNTER_REGISTER	= ( IMMEDIATE64 + 1 ) ,
102     INTERFACE_POINTER	= ( INPUT_CYCLE_COUNTER_REGISTER + 1 ) 
103 }
104 
105 ///
106 /// Structures
107 ///
108 
109 struct D3D11_TRACE_REGISTER
110 {
111     D3D11_TRACE_REGISTER_TYPE RegType;
112     union 
113         {
114         ushort Index1D;
115         ushort[2] Index2D;
116         };
117     ubyte OperandIndex;
118     ubyte Flags;
119 }
120 
121 struct D3D11_VERTEX_SHADER_TRACE_DESC
122 {
123     ulong Invocation;
124 }
125 
126 struct D3D11_HULL_SHADER_TRACE_DESC
127 {
128     ulong Invocation;
129 }
130 
131 struct D3D11_DOMAIN_SHADER_TRACE_DESC
132 {
133     ulong Invocation;
134 }
135 
136 struct D3D11_GEOMETRY_SHADER_TRACE_DESC
137 {
138     ulong Invocation;
139 }
140 
141 struct D3D11_PIXEL_SHADER_TRACE_DESC
142 {
143     ulong Invocation;
144     int X;
145     int Y;
146     ulong SampleMask;
147 }
148 
149 struct D3D11_COMPUTE_SHADER_TRACE_DESC
150 {
151     ulong Invocation;
152     uint[3] ThreadIDInGroup;
153     uint[3] ThreadGroupID;
154 }
155 
156 struct D3D11_SHADER_TRACE_DESC
157 {
158     D3D11_SHADER_TYPE Type;
159     uint Flags;
160     union 
161     {
162         D3D11_VERTEX_SHADER_TRACE_DESC VertexShaderTraceDesc;
163         D3D11_HULL_SHADER_TRACE_DESC HullShaderTraceDesc;
164         D3D11_DOMAIN_SHADER_TRACE_DESC DomainShaderTraceDesc;
165         D3D11_GEOMETRY_SHADER_TRACE_DESC GeometryShaderTraceDesc;
166         D3D11_PIXEL_SHADER_TRACE_DESC PixelShaderTraceDesc;
167         D3D11_COMPUTE_SHADER_TRACE_DESC ComputeShaderTraceDesc;
168     };
169 }
170 
171 struct D3D11_TRACE_STATS
172 {
173     D3D11_SHADER_TRACE_DESC TraceDesc;
174     ubyte NumInvocationsInStamp;
175     ubyte TargetStampIndex;
176     uint NumTraceSteps;
177     COMPONENT_MASK[32] InputMask;
178     COMPONENT_MASK[32] OutputMask;
179     ushort NumTemps;
180     ushort MaxIndexableTempIndex;
181     ushort[4096] IndexableTempSize;
182     ushort ImmediateConstantBufferSize;
183     uint[4][2] PixelPosition;
184     ulong[4] PixelCoverageMask;
185     ulong[4] PixelDiscardedMask;
186     ulong[4] PixelCoverageMaskAfterShader;
187     ulong[4] PixelCoverageMaskAfterA2CSampleMask;
188     ulong[4] PixelCoverageMaskAfterA2CSampleMaskDepth;
189     ulong[4] PixelCoverageMaskAfterA2CSampleMaskDepthStencil;
190     bool PSOutputsDepth;
191     bool PSOutputsMask;
192     D3D11_TRACE_GS_INPUT_PRIMITIVE GSInputPrimitive;
193     bool GSInputsPrimitiveID;
194     COMPONENT_MASK[32] HSOutputPatchConstantMask;
195     COMPONENT_MASK[32] DSInputPatchConstantMask;
196 }
197 
198 struct D3D11_TRACE_VALUE
199 {
200     uint[4] Bits;
201     COMPONENT_MASK ValidMask;
202 }
203 
204 struct D3D11_TRACE_STEP
205 {
206     uint ID;
207     bool InstructionActive;
208     ubyte NumRegistersWritten;
209     ubyte NumRegistersRead;
210     D3D11_TRACE_MISC_OPERATIONS_MASK MiscOperations;
211     uint OpcodeType;
212     ulong CurrentGlobalCycle;
213 }
214 
215 ///
216 /// Interfaces
217 ///
218 
219 mixin(uuid!(ID3D11ShaderTrace, "36b013e6-2811-4845-baa7-d623fe0df104"));
220 public interface ID3D11ShaderTrace : IUnknown
221 {
222 extern(Windows):
223     HRESULT GetInitialRegisterContents(D3D11_TRACE_REGISTER *pRegister, D3D11_TRACE_VALUE *pValue);
224     HRESULT GetReadRegister(uint stepIndex, uint readRegisterIndex, D3D11_TRACE_REGISTER *pRegister, D3D11_TRACE_VALUE *pValue);
225     HRESULT GetStep(uint stepIndex, D3D11_TRACE_STEP *pTraceStep);
226     HRESULT GetTraceStats(D3D11_TRACE_STATS *pTraceStats);
227     HRESULT GetWrittenRegister(uint stepIndex, uint writtenRegisterIndex, D3D11_TRACE_REGISTER *pRegister, D3D11_TRACE_VALUE *pValue);
228     HRESULT PSSelectStamp(uint stampIndex);
229     void ResetTrace();
230     HRESULT TraceReady(ulong *pTestCount);
231 }
232 
233 mixin(uuid!(ID3D11ShaderTraceFactory, "1fbad429-66ab-41cc-9617-667ac10e4459"));
234 public interface ID3D11ShaderTraceFactory : IUnknown
235 {
236 extern(Windows):
237     HRESULT CreateShaderTrace(IUnknown pShader, D3D11_SHADER_TRACE_DESC *pTraceDesc, ID3D11ShaderTrace *ppShaderTrace);
238 }