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 bool buffer;
154 struct pipe_resource *resource;
155 struct pipe_transfer **transfers;
156 struct pipe_stream_output_target *so_target;
157 };
158
159
160 static inline Resource *
CastResource(D3D10DDI_HRESOURCE hResource)161 CastResource(D3D10DDI_HRESOURCE hResource)
162 {
163 return static_cast<Resource *>(hResource.pDrvPrivate);
164 }
165
166
167 static inline Resource *
CastResource(DXGI_DDI_HRESOURCE hResource)168 CastResource(DXGI_DDI_HRESOURCE hResource)
169 {
170 return reinterpret_cast<Resource *>(hResource);
171 }
172
173
174 static inline struct pipe_resource *
CastPipeResource(D3D10DDI_HRESOURCE hResource)175 CastPipeResource(D3D10DDI_HRESOURCE hResource)
176 {
177 Resource *pResource = CastResource(hResource);
178 return pResource ? pResource->resource : NULL;
179 }
180
181
182 static inline struct pipe_resource *
CastPipeResource(DXGI_DDI_HRESOURCE hResource)183 CastPipeResource(DXGI_DDI_HRESOURCE hResource)
184 {
185 Resource *pResource = CastResource(hResource);
186 return pResource ? pResource->resource : NULL;
187 }
188
189
190 static inline struct pipe_resource *
CastPipeBuffer(D3D10DDI_HRESOURCE hResource)191 CastPipeBuffer(D3D10DDI_HRESOURCE hResource)
192 {
193 Resource *pResource = CastResource(hResource);
194 if (!pResource) {
195 return NULL;
196 }
197 return static_cast<struct pipe_resource *>(pResource->resource);
198 }
199
200
201 struct RenderTargetView
202 {
203 struct pipe_surface *surface;
204 D3D10DDI_HRTRENDERTARGETVIEW hRTRenderTargetView;
205 };
206
207
208 static inline RenderTargetView *
CastRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)209 CastRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)
210 {
211 return static_cast<RenderTargetView *>(hRenderTargetView.pDrvPrivate);
212 }
213
214
215 static inline struct pipe_surface *
CastPipeRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)216 CastPipeRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)
217 {
218 RenderTargetView *pRenderTargetView = CastRenderTargetView(hRenderTargetView);
219 return pRenderTargetView ? pRenderTargetView->surface : NULL;
220 }
221
222
223 struct DepthStencilView
224 {
225 struct pipe_surface *surface;
226 D3D10DDI_HRTDEPTHSTENCILVIEW hRTDepthStencilView;
227 };
228
229
230 static inline DepthStencilView *
CastDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)231 CastDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)
232 {
233 return static_cast<DepthStencilView *>(hDepthStencilView.pDrvPrivate);
234 }
235
236
237 static inline struct pipe_surface *
CastPipeDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)238 CastPipeDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)
239 {
240 DepthStencilView *pDepthStencilView = CastDepthStencilView(hDepthStencilView);
241 return pDepthStencilView ? pDepthStencilView->surface : NULL;
242 }
243
244
245 struct BlendState
246 {
247 void *handle;
248 };
249
250
251 static inline BlendState *
CastBlendState(D3D10DDI_HBLENDSTATE hBlendState)252 CastBlendState(D3D10DDI_HBLENDSTATE hBlendState)
253 {
254 return static_cast<BlendState *>(hBlendState.pDrvPrivate);
255 }
256
257
258 static inline void *
CastPipeBlendState(D3D10DDI_HBLENDSTATE hBlendState)259 CastPipeBlendState(D3D10DDI_HBLENDSTATE hBlendState)
260 {
261 BlendState *pBlendState = CastBlendState(hBlendState);
262 return pBlendState ? pBlendState->handle : NULL;
263 }
264
265
266 struct DepthStencilState
267 {
268 void *handle;
269 };
270
271
272 static inline DepthStencilState *
CastDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)273 CastDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)
274 {
275 return static_cast<DepthStencilState *>(hDepthStencilState.pDrvPrivate);
276 }
277
278
279 static inline void *
CastPipeDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)280 CastPipeDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)
281 {
282 DepthStencilState *pDepthStencilState = CastDepthStencilState(hDepthStencilState);
283 return pDepthStencilState ? pDepthStencilState->handle : NULL;
284 }
285
286
287 struct RasterizerState
288 {
289 void *handle;
290 };
291
292
293 static inline RasterizerState *
CastRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)294 CastRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)
295 {
296 return static_cast<RasterizerState *>(hRasterizerState.pDrvPrivate);
297 }
298
299
300 static inline void *
CastPipeRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)301 CastPipeRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)
302 {
303 RasterizerState *pRasterizerState = CastRasterizerState(hRasterizerState);
304 return pRasterizerState ? pRasterizerState->handle : NULL;
305 }
306
307
308 static inline Shader *
CastShader(D3D10DDI_HSHADER hShader)309 CastShader(D3D10DDI_HSHADER hShader)
310 {
311 return static_cast<Shader *>(hShader.pDrvPrivate);
312 }
313
314
315 static inline void *
CastPipeShader(D3D10DDI_HSHADER hShader)316 CastPipeShader(D3D10DDI_HSHADER hShader)
317 {
318 Shader *pShader = static_cast<Shader *>(hShader.pDrvPrivate);
319 return pShader ? pShader->handle : NULL;
320 }
321
322
323 struct ElementLayout
324 {
325 void *handle;
326 };
327
328
329 static inline ElementLayout *
CastElementLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)330 CastElementLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)
331 {
332 return static_cast<ElementLayout *>(hElementLayout.pDrvPrivate);
333 }
334
335 static inline void *
CastPipeInputLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)336 CastPipeInputLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)
337 {
338 ElementLayout *pElementLayout = CastElementLayout(hElementLayout);
339 return pElementLayout ? pElementLayout->handle : NULL;
340 }
341
342
343 struct SamplerState
344 {
345 void *handle;
346 };
347
348
349 static inline SamplerState *
CastSamplerState(D3D10DDI_HSAMPLER hSampler)350 CastSamplerState(D3D10DDI_HSAMPLER hSampler)
351 {
352 return static_cast<SamplerState *>(hSampler.pDrvPrivate);
353 }
354
355
356 static inline void *
CastPipeSamplerState(D3D10DDI_HSAMPLER hSampler)357 CastPipeSamplerState(D3D10DDI_HSAMPLER hSampler)
358 {
359 SamplerState *pSamplerState = CastSamplerState(hSampler);
360 return pSamplerState ? pSamplerState->handle : NULL;
361 }
362
363
364 struct ShaderResourceView
365 {
366 struct pipe_sampler_view *handle;
367 };
368
369
370 static inline ShaderResourceView *
CastShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)371 CastShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)
372 {
373 return static_cast<ShaderResourceView *>(hShaderResourceView.pDrvPrivate);
374 }
375
376
377 static inline struct pipe_sampler_view *
CastPipeShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)378 CastPipeShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView)
379 {
380 ShaderResourceView *pSRView = CastShaderResourceView(hShaderResourceView);
381 return pSRView ? pSRView->handle : NULL;
382 }
383
384
385 struct Query
386 {
387 D3D10DDI_QUERY Type;
388 UINT Flags;
389
390 unsigned pipe_type;
391 struct pipe_query *handle;
392 INT SeqNo;
393 UINT GetDataCount;
394
395 D3D10_DDI_QUERY_DATA_PIPELINE_STATISTICS Statistics;
396 };
397
398
399 static inline Query *
CastQuery(D3D10DDI_HQUERY hQuery)400 CastQuery(D3D10DDI_HQUERY hQuery)
401 {
402 return static_cast<Query *>(hQuery.pDrvPrivate);
403 }
404
405
406 static inline struct pipe_query *
CastPipeQuery(D3D10DDI_HQUERY hQuery)407 CastPipeQuery(D3D10DDI_HQUERY hQuery)
408 {
409 Query *pQuery = CastQuery(hQuery);
410 return pQuery ? pQuery->handle : NULL;
411 }
412
413