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 43struct Adapter 44{ 45 struct pipe_screen *screen; 46}; 47 48 49static inline Adapter * 50CastAdapter(D3D10DDI_HADAPTER hAdapter) 51{ 52 return static_cast<Adapter *>(hAdapter.pDrvPrivate); 53} 54 55struct 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 64struct Query; 65 66struct 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 108static inline Device * 109CastDevice(D3D10DDI_HDEVICE hDevice) 110{ 111 return static_cast<Device *>(hDevice.pDrvPrivate); 112} 113 114 115static inline struct pipe_context * 116CastPipeContext(D3D10DDI_HDEVICE hDevice) 117{ 118 Device *pDevice = CastDevice(hDevice); 119 return pDevice ? pDevice->pipe : NULL; 120} 121 122 123static inline Device * 124CastDevice(DXGI_DDI_HDEVICE hDevice) 125{ 126 return reinterpret_cast<Device *>(hDevice); 127} 128 129 130static inline struct pipe_context * 131CastPipeDevice(DXGI_DDI_HDEVICE hDevice) 132{ 133 Device *pDevice = CastDevice(hDevice); 134 return pDevice ? pDevice->pipe : NULL; 135} 136 137 138static inline void 139SetError(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 148struct 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 159static inline Resource * 160CastResource(D3D10DDI_HRESOURCE hResource) 161{ 162 return static_cast<Resource *>(hResource.pDrvPrivate); 163} 164 165 166static inline Resource * 167CastResource(DXGI_DDI_HRESOURCE hResource) 168{ 169 return reinterpret_cast<Resource *>(hResource); 170} 171 172 173static inline struct pipe_resource * 174CastPipeResource(D3D10DDI_HRESOURCE hResource) 175{ 176 Resource *pResource = CastResource(hResource); 177 return pResource ? pResource->resource : NULL; 178} 179 180 181static inline struct pipe_resource * 182CastPipeResource(DXGI_DDI_HRESOURCE hResource) 183{ 184 Resource *pResource = CastResource(hResource); 185 return pResource ? pResource->resource : NULL; 186} 187 188 189static inline struct pipe_resource * 190CastPipeBuffer(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 200struct RenderTargetView 201{ 202 struct pipe_surface *surface; 203 D3D10DDI_HRTRENDERTARGETVIEW hRTRenderTargetView; 204}; 205 206 207static inline RenderTargetView * 208CastRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView) 209{ 210 return static_cast<RenderTargetView *>(hRenderTargetView.pDrvPrivate); 211} 212 213 214static inline struct pipe_surface * 215CastPipeRenderTargetView(D3D10DDI_HRENDERTARGETVIEW hRenderTargetView) 216{ 217 RenderTargetView *pRenderTargetView = CastRenderTargetView(hRenderTargetView); 218 return pRenderTargetView ? pRenderTargetView->surface : NULL; 219} 220 221 222struct DepthStencilView 223{ 224 struct pipe_surface *surface; 225 D3D10DDI_HRTDEPTHSTENCILVIEW hRTDepthStencilView; 226}; 227 228 229static inline DepthStencilView * 230CastDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView) 231{ 232 return static_cast<DepthStencilView *>(hDepthStencilView.pDrvPrivate); 233} 234 235 236static inline struct pipe_surface * 237CastPipeDepthStencilView(D3D10DDI_HDEPTHSTENCILVIEW hDepthStencilView) 238{ 239 DepthStencilView *pDepthStencilView = CastDepthStencilView(hDepthStencilView); 240 return pDepthStencilView ? pDepthStencilView->surface : NULL; 241} 242 243 244struct BlendState 245{ 246 void *handle; 247}; 248 249 250static inline BlendState * 251CastBlendState(D3D10DDI_HBLENDSTATE hBlendState) 252{ 253 return static_cast<BlendState *>(hBlendState.pDrvPrivate); 254} 255 256 257static inline void * 258CastPipeBlendState(D3D10DDI_HBLENDSTATE hBlendState) 259{ 260 BlendState *pBlendState = CastBlendState(hBlendState); 261 return pBlendState ? pBlendState->handle : NULL; 262} 263 264 265struct DepthStencilState 266{ 267 void *handle; 268}; 269 270 271static inline DepthStencilState * 272CastDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState) 273{ 274 return static_cast<DepthStencilState *>(hDepthStencilState.pDrvPrivate); 275} 276 277 278static inline void * 279CastPipeDepthStencilState(D3D10DDI_HDEPTHSTENCILSTATE hDepthStencilState) 280{ 281 DepthStencilState *pDepthStencilState = CastDepthStencilState(hDepthStencilState); 282 return pDepthStencilState ? pDepthStencilState->handle : NULL; 283} 284 285 286struct RasterizerState 287{ 288 void *handle; 289}; 290 291 292static inline RasterizerState * 293CastRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState) 294{ 295 return static_cast<RasterizerState *>(hRasterizerState.pDrvPrivate); 296} 297 298 299static inline void * 300CastPipeRasterizerState(D3D10DDI_HRASTERIZERSTATE hRasterizerState) 301{ 302 RasterizerState *pRasterizerState = CastRasterizerState(hRasterizerState); 303 return pRasterizerState ? pRasterizerState->handle : NULL; 304} 305 306 307static inline Shader * 308CastShader(D3D10DDI_HSHADER hShader) 309{ 310 return static_cast<Shader *>(hShader.pDrvPrivate); 311} 312 313 314static inline void * 315CastPipeShader(D3D10DDI_HSHADER hShader) 316{ 317 Shader *pShader = static_cast<Shader *>(hShader.pDrvPrivate); 318 return pShader ? pShader->handle : NULL; 319} 320 321 322struct ElementLayout 323{ 324 void *handle; 325}; 326 327 328static inline ElementLayout * 329CastElementLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout) 330{ 331 return static_cast<ElementLayout *>(hElementLayout.pDrvPrivate); 332} 333 334static inline void * 335CastPipeInputLayout(D3D10DDI_HELEMENTLAYOUT hElementLayout) 336{ 337 ElementLayout *pElementLayout = CastElementLayout(hElementLayout); 338 return pElementLayout ? pElementLayout->handle : NULL; 339} 340 341 342struct SamplerState 343{ 344 void *handle; 345}; 346 347 348static inline SamplerState * 349CastSamplerState(D3D10DDI_HSAMPLER hSampler) 350{ 351 return static_cast<SamplerState *>(hSampler.pDrvPrivate); 352} 353 354 355static inline void * 356CastPipeSamplerState(D3D10DDI_HSAMPLER hSampler) 357{ 358 SamplerState *pSamplerState = CastSamplerState(hSampler); 359 return pSamplerState ? pSamplerState->handle : NULL; 360} 361 362 363struct ShaderResourceView 364{ 365 struct pipe_sampler_view *handle; 366}; 367 368 369static inline ShaderResourceView * 370CastShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView) 371{ 372 return static_cast<ShaderResourceView *>(hShaderResourceView.pDrvPrivate); 373} 374 375 376static inline struct pipe_sampler_view * 377CastPipeShaderResourceView(D3D10DDI_HSHADERRESOURCEVIEW hShaderResourceView) 378{ 379 ShaderResourceView *pSRView = CastShaderResourceView(hShaderResourceView); 380 return pSRView ? pSRView->handle : NULL; 381} 382 383 384struct 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 398static inline Query * 399CastQuery(D3D10DDI_HQUERY hQuery) 400{ 401 return static_cast<Query *>(hQuery.pDrvPrivate); 402} 403 404 405static inline struct pipe_query * 406CastPipeQuery(D3D10DDI_HQUERY hQuery) 407{ 408 Query *pQuery = CastQuery(hQuery); 409 return pQuery ? pQuery->handle : NULL; 410} 411 412