xref: /aosp_15_r20/external/mesa3d/src/gallium/frontends/d3d10umd/State.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 #include "cso_cache/cso_context.h"
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    bool output_resolved;
62 };
63 
64 struct Query;
65 struct ElementLayout;
66 
67 struct Device
68 {
69    struct pipe_context *pipe;
70 
71    struct cso_context *cso;
72    struct pipe_framebuffer_state fb;
73    struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
74    unsigned vertex_strides[PIPE_MAX_ATTRIBS];
75    struct pipe_resource *index_buffer;
76    unsigned restart_index;
77    unsigned index_size;
78    unsigned ib_offset;
79    void *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
80    struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
81 
82    void *empty_fs;
83    void *empty_vs;
84 
85    enum mesa_prim primitive;
86 
87    struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_BUFFERS];
88    struct pipe_stream_output_target *draw_so_target;
89    Shader *bound_empty_gs;
90    Shader *bound_vs;
91 
92    unsigned max_dual_source_render_targets;
93 
94    D3D10DDI_HRTCORELAYER  hRTCoreLayer;
95 
96    HANDLE hDevice;
97    HANDLE hContext;
98 
99    D3DDDI_DEVICECALLBACKS KTCallbacks;
100    D3D10DDI_CORELAYER_DEVICECALLBACKS UMCallbacks;
101    DXGI_DDI_BASE_CALLBACKS *pDXGIBaseCallbacks;
102 
103    INT LastEmittedQuerySeqNo;
104    INT LastFinishedQuerySeqNo;
105 
106    Query *pPredicate;
107    BOOL PredicateValue;
108 
109    ElementLayout *element_layout;
110    BOOL velems_changed;
111    BOOL vbuffers_changed;
112 };
113 
114 
115 static inline Device *
CastDevice(D3D10DDI_HDEVICE hDevice)116 CastDevice(D3D10DDI_HDEVICE hDevice)
117 {
118    return static_cast<Device *>(hDevice.pDrvPrivate);
119 }
120 
121 
122 static inline struct pipe_context *
CastPipeContext(D3D10DDI_HDEVICE hDevice)123 CastPipeContext(D3D10DDI_HDEVICE hDevice)
124 {
125    Device *pDevice = CastDevice(hDevice);
126    return pDevice ? pDevice->pipe : NULL;
127 }
128 
129 
130 static inline Device *
CastDevice(DXGI_DDI_HDEVICE hDevice)131 CastDevice(DXGI_DDI_HDEVICE hDevice)
132 {
133    return reinterpret_cast<Device *>(hDevice);
134 }
135 
136 
137 static inline struct pipe_context *
CastPipeDevice(DXGI_DDI_HDEVICE hDevice)138 CastPipeDevice(DXGI_DDI_HDEVICE hDevice)
139 {
140    Device *pDevice = CastDevice(hDevice);
141    return pDevice ? pDevice->pipe : NULL;
142 }
143 
144 
145 static inline void
SetError(D3D10DDI_HDEVICE hDevice,HRESULT hr)146 SetError(D3D10DDI_HDEVICE hDevice, HRESULT hr)
147 {
148    if (FAILED(hr)) {
149       Device *pDevice = CastDevice(hDevice);
150       pDevice->UMCallbacks.pfnSetErrorCb(pDevice->hRTCoreLayer, hr);
151    }
152 }
153 
154 
155 struct Resource
156 {
157    DXGI_FORMAT Format;
158    UINT MipLevels;
159    UINT NumSubResources;
160    bool buffer;
161    struct pipe_resource *resource;
162    struct pipe_transfer **transfers;
163    struct pipe_stream_output_target *so_target;
164 };
165 
166 
167 static inline Resource *
CastResource(D3D10DDI_HRESOURCE hResource)168 CastResource(D3D10DDI_HRESOURCE hResource)
169 {
170    return static_cast<Resource *>(hResource.pDrvPrivate);
171 }
172 
173 
174 static inline Resource *
CastResource(DXGI_DDI_HRESOURCE hResource)175 CastResource(DXGI_DDI_HRESOURCE hResource)
176 {
177    return reinterpret_cast<Resource *>(hResource);
178 }
179 
180 
181 static inline struct pipe_resource *
CastPipeResource(D3D10DDI_HRESOURCE hResource)182 CastPipeResource(D3D10DDI_HRESOURCE hResource)
183 {
184    Resource *pResource = CastResource(hResource);
185    return pResource ? pResource->resource : NULL;
186 }
187 
188 
189 static inline struct pipe_resource *
CastPipeResource(DXGI_DDI_HRESOURCE hResource)190 CastPipeResource(DXGI_DDI_HRESOURCE hResource)
191 {
192    Resource *pResource = CastResource(hResource);
193    return pResource ? pResource->resource : NULL;
194 }
195 
196 
197 static inline struct pipe_resource *
CastPipeBuffer(D3D10DDI_HRESOURCE hResource)198 CastPipeBuffer(D3D10DDI_HRESOURCE hResource)
199 {
200    Resource *pResource = CastResource(hResource);
201    if (!pResource) {
202       return NULL;
203    }
204    return static_cast<struct pipe_resource *>(pResource->resource);
205 }
206 
207 
208 struct RenderTargetView
209 {
210    struct pipe_surface *surface;
211    D3D10DDI_HRTRENDERTARGETVIEW hRTRenderTargetView;
212 };
213 
214 
215 static inline RenderTargetView *
CastRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)216 CastRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)
217 {
218    return static_cast<RenderTargetView *>(hRenderTargetView.pDrvPrivate);
219 }
220 
221 
222 static inline struct pipe_surface *
CastPipeRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)223 CastPipeRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView)
224 {
225    RenderTargetView *pRenderTargetView = CastRenderTargetView(hRenderTargetView);
226    return pRenderTargetView ? pRenderTargetView->surface : NULL;
227 }
228 
229 
230 struct DepthStencilView
231 {
232    struct pipe_surface *surface;
233    D3D10DDI_HRTDEPTHSTENCILVIEW hRTDepthStencilView;
234 };
235 
236 
237 static inline DepthStencilView *
CastDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)238 CastDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)
239 {
240    return static_cast<DepthStencilView *>(hDepthStencilView.pDrvPrivate);
241 }
242 
243 
244 static inline struct pipe_surface *
CastPipeDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)245 CastPipeDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView)
246 {
247    DepthStencilView *pDepthStencilView = CastDepthStencilView(hDepthStencilView);
248    return pDepthStencilView ? pDepthStencilView->surface : NULL;
249 }
250 
251 
252 struct BlendState
253 {
254    void *handle;
255 };
256 
257 
258 static inline BlendState *
CastBlendState(D3D10DDI_HBLENDSTATE hBlendState)259 CastBlendState(D3D10DDI_HBLENDSTATE hBlendState)
260 {
261    return static_cast<BlendState *>(hBlendState.pDrvPrivate);
262 }
263 
264 
265 static inline void *
CastPipeBlendState(D3D10DDI_HBLENDSTATE hBlendState)266 CastPipeBlendState(D3D10DDI_HBLENDSTATE hBlendState)
267 {
268    BlendState *pBlendState = CastBlendState(hBlendState);
269    return pBlendState ? pBlendState->handle : NULL;
270 }
271 
272 
273 struct DepthStencilState
274 {
275    void *handle;
276 };
277 
278 
279 static inline DepthStencilState *
CastDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)280 CastDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)
281 {
282    return static_cast<DepthStencilState *>(hDepthStencilState.pDrvPrivate);
283 }
284 
285 
286 static inline void *
CastPipeDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)287 CastPipeDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState)
288 {
289    DepthStencilState *pDepthStencilState = CastDepthStencilState(hDepthStencilState);
290    return pDepthStencilState ? pDepthStencilState->handle : NULL;
291 }
292 
293 
294 struct RasterizerState
295 {
296    void *handle;
297 };
298 
299 
300 static inline RasterizerState *
CastRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)301 CastRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)
302 {
303    return static_cast<RasterizerState *>(hRasterizerState.pDrvPrivate);
304 }
305 
306 
307 static inline void *
CastPipeRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)308 CastPipeRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState)
309 {
310    RasterizerState *pRasterizerState = CastRasterizerState(hRasterizerState);
311    return pRasterizerState ? pRasterizerState->handle : NULL;
312 }
313 
314 
315 static inline Shader *
CastShader(D3D10DDI_HSHADER hShader)316 CastShader(D3D10DDI_HSHADER hShader)
317 {
318    return static_cast<Shader *>(hShader.pDrvPrivate);
319 }
320 
321 
322 static inline void *
CastPipeShader(D3D10DDI_HSHADER hShader)323 CastPipeShader(D3D10DDI_HSHADER hShader)
324 {
325    Shader *pShader = static_cast<Shader *>(hShader.pDrvPrivate);
326    return pShader ? pShader->handle : NULL;
327 }
328 
329 
330 struct ElementLayout
331 {
332    struct cso_velems_state state;
333 };
334 
335 
336 static inline ElementLayout *
CastElementLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)337 CastElementLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout)
338 {
339    return static_cast<ElementLayout *>(hElementLayout.pDrvPrivate);
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