1 /**************************************************************************
2 *
3 * Copyright 2012-2021 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 **************************************************************************/
27
28 /*
29 * State.h --
30 * State declarations.
31 */
32
33
34 #include "DriverIncludes.h"
35 #include "util/u_hash_table.h"
36
37
38 #define SUPPORT_MSAA 0
39 #define SUPPORT_D3D10_1 0
40 #define SUPPORT_D3D11 0
41
42
43 struct Adapter
44 {
45 struct pipe_screen *screen;
46 };
47
48
49 static inline Adapter *
CastAdapter(D3D10DDI_HADAPTER hAdapter)50 CastAdapter(D3D10DDI_HADAPTER hAdapter)
51 {
52 return static_cast<Adapter *>(hAdapter.pDrvPrivate);
53 }
54
55 struct Shader
56 {
57 void *handle;
58 uint type;
59 struct pipe_shader_state state;
60 unsigned output_mapping[PIPE_MAX_SHADER_OUTPUTS];
61 boolean output_resolved;
62 };
63
64 struct Query;
65
66 struct Device
67 {
68 struct pipe_context *pipe;
69
70 struct pipe_framebuffer_state fb;
71 struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
72 struct pipe_resource *index_buffer;
73 unsigned restart_index;
74 unsigned index_size;
75 unsigned ib_offset;
76 void *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
77 struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
78
79 void *empty_fs;
80 void *empty_vs;
81
82 enum pipe_prim_type primitive;
83
84 struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_BUFFERS];
85 struct pipe_stream_output_target *draw_so_target;
86 Shader *bound_empty_gs;
87 Shader *bound_vs;
88
89 unsigned max_dual_source_render_targets;
90
91 D3D10DDI_HRTCORELAYER hRTCoreLayer;
92
93 HANDLE hDevice;
94 HANDLE hContext;
95
96 D3DDDI_DEVICECALLBACKS KTCallbacks;
97 D3D10DDI_CORELAYER_DEVICECALLBACKS UMCallbacks;
98 DXGI_DDI_BASE_CALLBACKS *pDXGIBaseCallbacks;
99
100 INT LastEmittedQuerySeqNo;
101 INT LastFinishedQuerySeqNo;
102
103 Query *pPredicate;
104 BOOL PredicateValue;
105 };
106
107
108 static inline Device *
CastDevice(D3D10DDI_HDEVICE hDevice)109 CastDevice(D3D10DDI_HDEVICE hDevice)
110 {
111 return static_cast<Device *>(hDevice.pDrvPrivate);
112 }
113
114
115 static inline struct pipe_context *
CastPipeContext(D3D10DDI_HDEVICE hDevice)116 CastPipeContext(D3D10DDI_HDEVICE hDevice)
117 {
118 Device *pDevice = CastDevice(hDevice);
119 return pDevice ? pDevice->pipe : NULL;
120 }
121
122
123 static inline Device *
CastDevice(DXGI_DDI_HDEVICE hDevice)124 CastDevice(DXGI_DDI_HDEVICE hDevice)
125 {
126 return reinterpret_cast<Device *>(hDevice);
127 }
128
129
130 static inline struct pipe_context *
CastPipeDevice(DXGI_DDI_HDEVICE hDevice)131 CastPipeDevice(DXGI_DDI_HDEVICE hDevice)
132 {
133 Device *pDevice = CastDevice(hDevice);
134 return pDevice ? pDevice->pipe : NULL;
135 }
136
137
138 static inline void
SetError(D3D10DDI_HDEVICE hDevice,HRESULT hr)139 SetError(D3D10DDI_HDEVICE hDevice, HRESULT hr)
140 {
141 if (FAILED(hr)) {
142 Device *pDevice = CastDevice(hDevice);
143 pDevice->UMCallbacks.pfnSetErrorCb(pDevice->hRTCoreLayer, hr);
144 }
145 }
146
147
148 struct Resource
149 {
150 DXGI_FORMAT Format;
151 UINT MipLevels;
152 UINT NumSubResources;
153 struct pipe_resource *resource;
154 struct pipe_transfer **transfers;
155 struct pipe_stream_output_target *so_target;
156 };
157
158
159 static inline Resource *
CastResource(D3D10DDI_HRESOURCE hResource)160 CastResource(D3D10DDI_HRESOURCE hResource)
161 {
162 return static_cast<Resource *>(hResource.pDrvPrivate);
163 }
164
165
166 static inline Resource *
CastResource(DXGI_DDI_HRESOURCE hResource)167 CastResource(DXGI_DDI_HRESOURCE hResource)
168 {
169 return reinterpret_cast<Resource *>(hResource);
170 }
171
172
173 static inline struct pipe_resource *
CastPipeResource(D3D10DDI_HRESOURCE hResource)174 CastPipeResource(D3D10DDI_HRESOURCE hResource)
175 {
176 Resource *pResource = CastResource(hResource);
177 return pResource ? pResource->resource : NULL;
178 }
179
180
181 static inline struct pipe_resource *
CastPipeResource(DXGI_DDI_HRESOURCE hResource)182 CastPipeResource(DXGI_DDI_HRESOURCE hResource)
183 {
184 Resource *pResource = CastResource(hResource);
185 return pResource ? pResource->resource : NULL;
186 }
187
188
189 static inline struct pipe_resource *
CastPipeBuffer(D3D10DDI_HRESOURCE hResource)190 CastPipeBuffer(D3D10DDI_HRESOURCE hResource)
191 {
192 Resource *pResource = CastResource(hResource);
193 if (!pResource) {
194 return NULL;
195 }
196 return static_cast<struct pipe_resource *>(pResource->resource);
197 }
198
199
200 struct RenderTargetView
201 {
202 struct pipe_surface *surface;
203 D3D10DDI_HRTRENDERTARGETVIEW hRTRenderTargetView;
204 };
205
206
207 static inline RenderTargetView *
CastRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)208 CastRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)
209 {
210 return static_cast<RenderTargetView *>(hRenderTargetView.pDrvPrivate);
211 }
212
213
214 static inline struct pipe_surface *
CastPipeRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)215 CastPipeRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)
216 {
217 RenderTargetView *pRenderTargetView = CastRenderTargetView(hRenderTargetView);
218 return pRenderTargetView ? pRenderTargetView->surface : NULL;
219 }
220
221
222 struct DepthStencilView
223 {
224 struct pipe_surface *surface;
225 D3D10DDI_HRTDEPTHSTENCILVIEW hRTDepthStencilView;
226 };
227
228
229 static inline DepthStencilView *
CastDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)230 CastDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)
231 {
232 return static_cast<DepthStencilView *>(hDepthStencilView.pDrvPrivate);
233 }
234
235
236 static inline struct pipe_surface *
CastPipeDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)237 CastPipeDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)
238 {
239 DepthStencilView *pDepthStencilView = CastDepthStencilView(hDepthStencilView);
240 return pDepthStencilView ? pDepthStencilView->surface : NULL;
241 }
242
243
244 struct BlendState
245 {
246 void *handle;
247 };
248
249
250 static inline BlendState *
CastBlendState(D3D10DDI_HBLENDSTATE hBlendState)251 CastBlendState(D3D10DDI_HBLENDSTATE hBlendState)
252 {
253 return static_cast<BlendState *>(hBlendState.pDrvPrivate);
254 }
255
256
257 static inline void *
CastPipeBlendState(D3D10DDI_HBLENDSTATE hBlendState)258 CastPipeBlendState(D3D10DDI_HBLENDSTATE hBlendState)
259 {
260 BlendState *pBlendState = CastBlendState(hBlendState);
261 return pBlendState ? pBlendState->handle : NULL;
262 }
263
264
265 struct DepthStencilState
266 {
267 void *handle;
268 };
269
270
271 static inline DepthStencilState *
CastDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)272 CastDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)
273 {
274 return static_cast<DepthStencilState *>(hDepthStencilState.pDrvPrivate);
275 }
276
277
278 static inline void *
CastPipeDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)279 CastPipeDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)
280 {
281 DepthStencilState *pDepthStencilState = CastDepthStencilState(hDepthStencilState);
282 return pDepthStencilState ? pDepthStencilState->handle : NULL;
283 }
284
285
286 struct RasterizerState
287 {
288 void *handle;
289 };
290
291
292 static inline RasterizerState *
CastRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)293 CastRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)
294 {
295 return static_cast<RasterizerState *>(hRasterizerState.pDrvPrivate);
296 }
297
298
299 static inline void *
CastPipeRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)300 CastPipeRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)
301 {
302 RasterizerState *pRasterizerState = CastRasterizerState(hRasterizerState);
303 return pRasterizerState ? pRasterizerState->handle : NULL;
304 }
305
306
307 static inline Shader *
CastShader(D3D10DDI_HSHADER hShader)308 CastShader(D3D10DDI_HSHADER hShader)
309 {
310 return static_cast<Shader *>(hShader.pDrvPrivate);
311 }
312
313
314 static inline void *
CastPipeShader(D3D10DDI_HSHADER hShader)315 CastPipeShader(D3D10DDI_HSHADER hShader)
316 {
317 Shader *pShader = static_cast<Shader *>(hShader.pDrvPrivate);
318 return pShader ? pShader->handle : NULL;
319 }
320
321
322 struct ElementLayout
323 {
324 void *handle;
325 };
326
327
328 static inline ElementLayout *
CastElementLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)329 CastElementLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)
330 {
331 return static_cast<ElementLayout *>(hElementLayout.pDrvPrivate);
332 }
333
334 static inline void *
CastPipeInputLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)335 CastPipeInputLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)
336 {
337 ElementLayout *pElementLayout = CastElementLayout(hElementLayout);
338 return pElementLayout ? pElementLayout->handle : NULL;
339 }
340
341
342 struct SamplerState
343 {
344 void *handle;
345 };
346
347
348 static inline SamplerState *
CastSamplerState(D3D10DDI_HSAMPLER hSampler)349 CastSamplerState(D3D10DDI_HSAMPLER hSampler)
350 {
351 return static_cast<SamplerState *>(hSampler.pDrvPrivate);
352 }
353
354
355 static inline void *
CastPipeSamplerState(D3D10DDI_HSAMPLER hSampler)356 CastPipeSamplerState(D3D10DDI_HSAMPLER hSampler)
357 {
358 SamplerState *pSamplerState = CastSamplerState(hSampler);
359 return pSamplerState ? pSamplerState->handle : NULL;
360 }
361
362
363 struct ShaderResourceView
364 {
365 struct pipe_sampler_view *handle;
366 };
367
368
369 static inline ShaderResourceView *
CastShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)370 CastShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)
371 {
372 return static_cast<ShaderResourceView *>(hShaderResourceView.pDrvPrivate);
373 }
374
375
376 static inline struct pipe_sampler_view *
CastPipeShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)377 CastPipeShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)
378 {
379 ShaderResourceView *pSRView = CastShaderResourceView(hShaderResourceView);
380 return pSRView ? pSRView->handle : NULL;
381 }
382
383
384 struct Query
385 {
386 D3D10DDI_QUERY Type;
387 UINT Flags;
388
389 unsigned pipe_type;
390 struct pipe_query *handle;
391 INT SeqNo;
392 UINT GetDataCount;
393
394 D3D10_DDI_QUERY_DATA_PIPELINE_STATISTICS Statistics;
395 };
396
397
398 static inline Query *
CastQuery(D3D10DDI_HQUERY hQuery)399 CastQuery(D3D10DDI_HQUERY hQuery)
400 {
401 return static_cast<Query *>(hQuery.pDrvPrivate);
402 }
403
404
405 static inline struct pipe_query *
CastPipeQuery(D3D10DDI_HQUERY hQuery)406 CastPipeQuery(D3D10DDI_HQUERY hQuery)
407 {
408 Query *pQuery = CastQuery(hQuery);
409 return pQuery ? pQuery->handle : NULL;
410 }
411
412