d3d11_objects.h revision 8224256946619fb25278718bbf4703e3b9d60c93
1/************************************************************************** 2 * 3 * Copyright 2010 Luca Barbieri 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial 15 * portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * 25 **************************************************************************/ 26 27template<typename Base = ID3D11DeviceChild> 28struct GalliumD3D11DeviceChild : public GalliumPrivateDataComObject<Base, dual_refcnt_t> 29{ 30 GalliumD3D11Screen* device; // must not be null 31 32 33 // if this is called, the subclass constructor must set device itself 34 GalliumD3D11DeviceChild() 35 : device(0) 36 {} 37 38 GalliumD3D11DeviceChild(GalliumD3D11Screen* p_device) 39 { 40 // we store the reference count minus one in refcnt 41 device = p_device; 42 device->AddRef(); 43 } 44 45 /* The purpose of this is to avoid cyclic garbage, since this won't hold 46 * a pointer to the device if it is only held by a pipeline binding in the immediate context 47 * 48 * TODO: we could only manipulate the device refcnt when atomic_refcnt == 0 changes, 49 * but this requires more complex atomic ops 50 */ 51 inline ULONG add_ref() 52 { 53 device->AddRef(); 54 return GalliumPrivateDataComObject<Base, dual_refcnt_t>::add_ref(); 55 } 56 57 inline ULONG release() 58 { 59 device->Release(); 60 return GalliumPrivateDataComObject<Base, dual_refcnt_t>::release(); 61 } 62 63 virtual ULONG STDMETHODCALLTYPE AddRef() 64 { 65 return add_ref(); 66 } 67 68 virtual ULONG STDMETHODCALLTYPE Release() 69 { 70 return release(); 71 } 72 73 virtual void STDMETHODCALLTYPE GetDevice( 74 ID3D11Device **ppDevice 75 ) 76 { 77 device->AddRef(); 78 *ppDevice = device; 79 } 80}; 81 82template<typename Base = ID3D11DeviceChild, typename Object = void> 83struct GalliumD3D11Object : public GalliumD3D11DeviceChild<Base> 84{ 85 Object* object; 86 GalliumD3D11Object(GalliumD3D11Screen* device, Object* object) 87 : GalliumD3D11DeviceChild<Base>(device), object(object) 88 {} 89 90 virtual ~GalliumD3D11Object(); 91}; 92 93#define IMPLEMENT_OBJECT_DTOR(name, gallium) \ 94template<> \ 95GalliumD3D11Object<ID3D11##name, void>::~GalliumD3D11Object() \ 96{ \ 97 DX10_ONLY(device->Unbind##name(this)); \ 98 device->immediate_pipe->delete_##gallium##_state(device->immediate_pipe, object); \ 99} 100 101#define IMPLEMENT_VIEW_DTOR(name, gallium) \ 102template<> \ 103GalliumD3D11Object<ID3D11##name, struct pipe_##gallium>::~GalliumD3D11Object() \ 104{ \ 105 DX10_ONLY(device->Unbind##name(this)); \ 106 pipe_##gallium##_reference(&object, 0); \ 107} 108 109IMPLEMENT_OBJECT_DTOR(InputLayout, vertex_elements) 110IMPLEMENT_OBJECT_DTOR(DepthStencilState, depth_stencil_alpha) 111IMPLEMENT_OBJECT_DTOR(RasterizerState, rasterizer) 112IMPLEMENT_OBJECT_DTOR(SamplerState, sampler) 113IMPLEMENT_OBJECT_DTOR(BlendState, blend) 114IMPLEMENT_OBJECT_DTOR(VertexShader, vs) 115IMPLEMENT_OBJECT_DTOR(PixelShader, fs) 116IMPLEMENT_OBJECT_DTOR(GeometryShader, gs) 117 118IMPLEMENT_VIEW_DTOR(ShaderResourceView, sampler_view) 119IMPLEMENT_VIEW_DTOR(RenderTargetView, surface) 120IMPLEMENT_VIEW_DTOR(DepthStencilView, surface) 121 122#if API >= 11 123// IMPLEMENT_VIEW_DTOR(UnorderedAccessView, surface); 124// IMPLEMENT_OBJECT_DTOR(HullShader, tcs); 125// IMPLEMENT_OBJECT_DTOR(DomainShader, tes); 126// IMPLEMENT_OBJECT_DTOR(ComputeShader, cs); 127#else 128IMPLEMENT_OBJECT_DTOR(BlendState1, blend) 129IMPLEMENT_VIEW_DTOR(ShaderResourceView1, sampler_view) 130#endif 131 132template<typename Base, typename Desc, typename Object = void> 133struct GalliumD3D11DescribedObject : public GalliumD3D11Object<Base, Object> 134{ 135 Desc desc; 136 GalliumD3D11DescribedObject(GalliumD3D11Screen* device, Object* object, const Desc& desc) 137 : GalliumD3D11Object<Base, Object>(device, object), desc(desc) 138 {} 139 140 virtual void STDMETHODCALLTYPE GetDesc(Desc *pDesc) 141 { 142 memcpy(pDesc, &desc, sizeof(desc)); 143 } 144}; 145 146typedef GalliumD3D11Object<ID3D11InputLayout> GalliumD3D11InputLayout; 147typedef GalliumD3D11DescribedObject<ID3D11DepthStencilState, D3D11_DEPTH_STENCIL_DESC> GalliumD3D11DepthStencilState; 148typedef GalliumD3D11DescribedObject<ID3D11RasterizerState, D3D11_RASTERIZER_DESC> GalliumD3D11RasterizerStateBase; 149typedef GalliumD3D11DescribedObject<ID3D11SamplerState, D3D11_SAMPLER_DESC> GalliumD3D11SamplerState; 150 151#if API >= 11 152typedef GalliumD3D11DescribedObject<ID3D11BlendState, D3D11_BLEND_DESC> GalliumD3D11BlendState; 153#else 154typedef GalliumD3D10DescribedObject<ID3D10BlendState1, D3D10_BLEND_DESC> GalliumD3D10BlendStateBase; 155 156struct GalliumD3D10BlendState : public GalliumD3D10BlendStateBase 157{ 158 static D3D10_BLEND_DESC convert_to_d3d10(const D3D10_BLEND_DESC1& desc1) 159 { 160 D3D10_BLEND_DESC desc; 161 desc.AlphaToCoverageEnable = desc1.AlphaToCoverageEnable; 162 desc.SrcBlend = desc1.RenderTarget[0].SrcBlend; 163 desc.DestBlend = desc1.RenderTarget[0].DestBlend; 164 desc.BlendOp = desc1.RenderTarget[0].BlendOp; 165 desc.SrcBlendAlpha = desc1.RenderTarget[0].SrcBlendAlpha; 166 desc.DestBlendAlpha = desc1.RenderTarget[0].DestBlendAlpha; 167 desc.BlendOpAlpha = desc1.RenderTarget[0].BlendOpAlpha; 168 for(unsigned i = 0; i < 8; ++i) 169 { 170 desc.BlendEnable[i] = desc1.RenderTarget[i].BlendEnable; 171 desc.RenderTargetWriteMask[i] = desc1.RenderTarget[i].RenderTargetWriteMask; 172 } 173 return desc; 174 } 175 176 D3D10_BLEND_DESC1 desc1; 177 178 GalliumD3D10BlendState(GalliumD3D10Screen* device, void* object, const D3D10_BLEND_DESC& desc) 179 : GalliumD3D10BlendStateBase(device, object, desc) 180 { 181 memset(&desc1, 0, sizeof(desc1)); 182 desc1.AlphaToCoverageEnable = desc.AlphaToCoverageEnable; 183 desc1.RenderTarget[0].SrcBlend = desc.SrcBlend; 184 desc1.RenderTarget[0].DestBlend = desc.DestBlend; 185 desc1.RenderTarget[0].BlendOp = desc.BlendOp; 186 desc1.RenderTarget[0].SrcBlendAlpha = desc.SrcBlendAlpha; 187 desc1.RenderTarget[0].DestBlendAlpha = desc.DestBlendAlpha; 188 desc1.RenderTarget[0].BlendOpAlpha = desc.BlendOpAlpha; 189 for(unsigned i = 0; i < 8; ++i) 190 { 191 desc1.RenderTarget[i].BlendEnable = desc.BlendEnable[i]; 192 desc1.RenderTarget[i].RenderTargetWriteMask = desc.RenderTargetWriteMask[i]; 193 } 194 } 195 196 GalliumD3D10BlendState(GalliumD3D10Screen* device, void* object, const D3D10_BLEND_DESC1& desc) 197 : GalliumD3D10BlendStateBase(device, object, convert_to_d3d10(desc)), desc1(desc1) 198 {} 199 200 virtual void STDMETHODCALLTYPE GetDesc1(D3D10_BLEND_DESC1 *pDesc) 201 { 202 memcpy(pDesc, &desc1, sizeof(desc1)); 203 } 204}; 205#endif 206 207struct GalliumD3D11RasterizerState : public GalliumD3D11RasterizerStateBase 208{ 209 bool depth_clamp; 210 211 GalliumD3D11RasterizerState(GalliumD3D11Screen* device, void* object, const D3D11_RASTERIZER_DESC& desc, bool depth_clamp) 212 : GalliumD3D11RasterizerStateBase(device, object, desc), depth_clamp(depth_clamp) 213 {} 214}; 215 216template<typename Base = ID3D11DeviceChild> 217struct GalliumD3D11Shader : public GalliumD3D11Object<Base> 218{ 219 std::vector<int> slot_to_resource; 220 std::vector<int> slot_to_sampler; 221 222 GalliumD3D11Shader(GalliumD3D11Screen* device, void* object) 223 : GalliumD3D11Object<Base>(device, object) 224 {} 225}; 226 227typedef GalliumD3D11Shader<ID3D11VertexShader> GalliumD3D11VertexShader; 228typedef GalliumD3D11Shader<ID3D11GeometryShader> GalliumD3D11GeometryShader; 229typedef GalliumD3D11Shader<ID3D11PixelShader> GalliumD3D11PixelShader; 230 231#if API >= 11 232/* 233typedef GalliumD3D11Shader<ID3D11HullShader> GalliumD3D11HullShader; 234typedef GalliumD3D11Shader<ID3D11DomainShader> GalliumD3D11DomainShader; 235typedef GalliumD3D11Shader<ID3D11ComputeShader> GalliumD3D11ComputeShader; 236*/ 237#endif 238 239template<typename Base = ID3D11Resource> 240struct GalliumD3D11ResourceBase : public GalliumD3D11DeviceChild<Base> 241{ 242 unsigned eviction_priority; 243 244 virtual void STDMETHODCALLTYPE SetEvictionPriority( 245 unsigned EvictionPriority) 246 { 247 eviction_priority = EvictionPriority; 248 } 249 250 virtual unsigned STDMETHODCALLTYPE GetEvictionPriority() 251 { 252 return eviction_priority; 253 } 254}; 255 256template<typename Real> 257struct GalliumDXGIResource : public IDXGIResource 258{ 259 virtual HRESULT STDMETHODCALLTYPE SetEvictionPriority( 260 unsigned EvictionPriority) 261 { 262 static_cast<Real*>(this)->eviction_priority = EvictionPriority; 263 return S_OK; 264 } 265 266 virtual HRESULT STDMETHODCALLTYPE GetEvictionPriority(unsigned* pEvictionPriority) 267 { 268 *pEvictionPriority = static_cast<Real*>(this)->eviction_priority; 269 return S_OK; 270 } 271 272 virtual HRESULT STDMETHODCALLTYPE GetDevice( 273 REFIID riid, 274 void **ppParent) 275 { 276 if(!static_cast<Real*>(this)->device) 277 return E_NOINTERFACE; 278 return static_cast<Real*>(this)->device->QueryInterface(riid, ppParent); 279 } 280 281 virtual HRESULT STDMETHODCALLTYPE GetParent( 282 REFIID riid, 283 void **ppParent) 284 { 285 if(!static_cast<Real*>(this)->device) 286 return E_NOINTERFACE; 287 return static_cast<Real*>(this)->device->QueryInterface(riid, ppParent); 288 } 289}; 290 291template<typename T> 292struct com_traits<GalliumDXGIResource<T> > : public com_traits<IDXGIResource> 293{}; 294 295template<typename Base = ID3D11Resource> 296struct GalliumD3D11Resource 297 : public GalliumMultiComObject< 298 GalliumMultiPrivateDataComObject< 299 GalliumD3D11ResourceBase<Base>, 300 GalliumDXGIResource<GalliumD3D11Resource<Base> > 301 >, 302 IGalliumResource 303 > 304{ 305 struct pipe_resource* resource; 306 std::unordered_map<unsigned, pipe_transfer*> transfers; 307 float min_lod; 308 DXGI_USAGE dxgi_usage; 309 310 GalliumD3D11Resource(GalliumD3D11Screen* device = 0, struct pipe_resource* resource = 0, unsigned dxgi_usage = 0) 311 : resource(resource), min_lod(0), dxgi_usage(dxgi_usage) 312 { 313 this->device = device; 314 if(device) 315 device->AddRef(); 316 this->eviction_priority = 0; 317 } 318 319 ~GalliumD3D11Resource() 320 { 321 pipe_resource_reference(&resource, 0); 322 } 323 324 virtual HRESULT STDMETHODCALLTYPE GetUsage( 325 DXGI_USAGE *pUsage 326 ) 327 { 328 *pUsage = this->dxgi_usage; 329 return S_OK; 330 } 331 332 virtual HRESULT STDMETHODCALLTYPE GetSharedHandle(HANDLE *pSharedHandle) 333 { 334 return E_NOTIMPL; 335 } 336 337 virtual struct pipe_resource* STDMETHODCALLTYPE GetGalliumResource() 338 { 339 return resource; 340 } 341}; 342 343template<typename Base, typename Desc, D3D11_RESOURCE_DIMENSION Dim> 344struct GalliumD3D11TypedResource : public GalliumD3D11Resource<Base> 345{ 346 Desc desc; 347 GalliumD3D11TypedResource() {} 348 GalliumD3D11TypedResource(GalliumD3D11Screen* device, struct pipe_resource* resource, const Desc& desc, unsigned dxgi_usage) 349 : GalliumD3D11Resource<Base>(device, resource, dxgi_usage), desc(desc) 350 {} 351 virtual void STDMETHODCALLTYPE GetType( 352 D3D11_RESOURCE_DIMENSION *pResourceDimension) 353 { 354 *pResourceDimension = Dim; 355 } 356 virtual void STDMETHODCALLTYPE GetDesc(Desc *pDesc) 357 { 358 memcpy(pDesc, &desc, sizeof(desc)); 359 } 360}; 361 362typedef GalliumD3D11TypedResource<ID3D11Texture1D, D3D11_TEXTURE1D_DESC, D3D11_RESOURCE_DIMENSION_TEXTURE1D> GalliumD3D11Texture1DBase; 363typedef GalliumD3D11TypedResource<ID3D11Texture2D, D3D11_TEXTURE2D_DESC, D3D11_RESOURCE_DIMENSION_TEXTURE2D> GalliumD3D11Texture2DBase; 364typedef GalliumD3D11TypedResource<ID3D11Texture3D, D3D11_TEXTURE3D_DESC, D3D11_RESOURCE_DIMENSION_TEXTURE3D> GalliumD3D11Texture3DBase; 365typedef GalliumD3D11TypedResource<ID3D11Buffer, D3D11_BUFFER_DESC, D3D11_RESOURCE_DIMENSION_BUFFER> GalliumD3D11BufferBase; 366 367#if API >= 11 368typedef GalliumD3D11BufferBase GalliumD3D11Buffer; 369typedef GalliumD3D11Texture1DBase GalliumD3D11Texture1D; 370typedef GalliumD3D11Texture2DBase GalliumD3D11Texture2D; 371typedef GalliumD3D11Texture3DBase GalliumD3D11Texture3D; 372#else 373struct GalliumD3D10Buffer : public GalliumD3D10BufferBase 374{ 375 GalliumD3D10Buffer(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_BUFFER_DESC& desc, unsigned dxgi_usage) 376 : GalliumD3D10BufferBase(device, resource, desc, dxgi_usage) 377 {} 378 379 ~GalliumD3D10Buffer() 380 { 381 device->UnbindBuffer(this); 382 } 383 384 virtual HRESULT STDMETHODCALLTYPE Map( 385 D3D10_MAP MapType, 386 unsigned MapFlags, 387 void **ppData) 388 { 389 D3D10_MAPPED_SUBRESOURCE msr; 390 HRESULT hr = device->Map(this, 0, MapType, MapFlags, &msr); 391 if(!SUCCEEDED(hr)) 392 return hr; 393 *ppData = msr.pData; 394 return S_OK; 395 } 396 397 virtual void STDMETHODCALLTYPE Unmap() 398 { 399 device->Unmap(this, 0); 400 } 401}; 402 403struct GalliumD3D10Texture1D : public GalliumD3D10Texture1DBase 404{ 405 GalliumD3D10Texture1D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE1D_DESC& desc, unsigned dxgi_usage) 406 : GalliumD3D10Texture1DBase(device, resource, desc, dxgi_usage) 407 {} 408 409 virtual HRESULT STDMETHODCALLTYPE Map( 410 unsigned Subresource, 411 D3D10_MAP MapType, 412 unsigned MapFlags, 413 void **ppData) 414 { 415 D3D10_MAPPED_SUBRESOURCE msr; 416 HRESULT hr = device->Map(this, Subresource, MapType, MapFlags, &msr); 417 if(!SUCCEEDED(hr)) 418 return hr; 419 *ppData = msr.pData; 420 return S_OK; 421 } 422 423 virtual void STDMETHODCALLTYPE Unmap( 424 unsigned Subresource 425 ) 426 { 427 device->Unmap(this, Subresource); 428 } 429}; 430 431struct GalliumD3D10Texture2D : public GalliumD3D10Texture2DBase 432{ 433 GalliumD3D10Texture2D() {} 434 GalliumD3D10Texture2D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE2D_DESC& desc, unsigned dxgi_usage) 435 : GalliumD3D10Texture2DBase(device, resource, desc, dxgi_usage) 436 {} 437 438 virtual HRESULT STDMETHODCALLTYPE Map( 439 unsigned Subresource, 440 D3D10_MAP MapType, 441 unsigned MapFlags, 442 D3D10_MAPPED_TEXTURE2D *pMappedTex2D) 443 { 444 D3D10_MAPPED_SUBRESOURCE msr; 445 HRESULT hr = device->Map(this, Subresource, MapType, MapFlags, &msr); 446 if(!SUCCEEDED(hr)) 447 return hr; 448 pMappedTex2D->pData = msr.pData; 449 pMappedTex2D->RowPitch = msr.RowPitch; 450 return S_OK; 451 } 452 453 virtual void STDMETHODCALLTYPE Unmap( 454 unsigned Subresource 455 ) 456 { 457 device->Unmap(this, Subresource); 458 } 459}; 460 461 462struct GalliumD3D10Texture3D : public GalliumD3D10Texture3DBase 463{ 464 GalliumD3D10Texture3D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE3D_DESC& desc, unsigned dxgi_usage) 465 : GalliumD3D10Texture3DBase(device, resource, desc, dxgi_usage) 466 {} 467 468 virtual HRESULT STDMETHODCALLTYPE Map( 469 unsigned Subresource, 470 D3D10_MAP MapType, 471 unsigned MapFlags, 472 D3D10_MAPPED_TEXTURE3D *pMappedTex3D) 473 { 474 D3D10_MAPPED_SUBRESOURCE msr; 475 HRESULT hr = device->Map(this, Subresource, MapType, MapFlags, &msr); 476 if(!SUCCEEDED(hr)) 477 return hr; 478 pMappedTex3D->pData = msr.pData; 479 pMappedTex3D->RowPitch = msr.RowPitch; 480 pMappedTex3D->DepthPitch = msr.DepthPitch; 481 return S_OK; 482 } 483 484 virtual void STDMETHODCALLTYPE Unmap( 485 unsigned Subresource 486 ) 487 { 488 device->Unmap(this, Subresource); 489 } 490}; 491#endif 492 493struct GalliumD3D11Surface : public GalliumMultiPrivateDataComObject<GalliumD3D11Texture2D, IDXGISurface1> 494{ 495 GalliumD3D11Surface(GalliumD3D11Screen* device, struct pipe_resource* resource, const D3D11_TEXTURE2D_DESC& desc, unsigned dxgi_usage) 496 { 497 this->device = device; 498 this->device->AddRef(); 499 this->resource = resource; 500 this->desc = desc; 501 this->dxgi_usage = dxgi_usage; 502 } 503 504 virtual HRESULT STDMETHODCALLTYPE GetDesc( 505 DXGI_SURFACE_DESC *pDesc) 506 { 507 pDesc->Format = this->desc.Format; 508 pDesc->Width = this->desc.Width; 509 pDesc->Height = this->desc.Height; 510 pDesc->SampleDesc = this->desc.SampleDesc; 511 return S_OK; 512 } 513 514 virtual HRESULT STDMETHODCALLTYPE GetParent( 515 REFIID riid, 516 void **ppParent) 517 { 518 if(!device) 519 return E_NOINTERFACE; 520 return device->QueryInterface(riid, ppParent); 521 } 522 523 /* TODO: somehow implement these */ 524 virtual HRESULT STDMETHODCALLTYPE GetDC( 525 BOOL Discard, 526 HDC *phdc) 527 { 528 *phdc = 0; 529 return E_NOTIMPL; 530 } 531 532 virtual HRESULT STDMETHODCALLTYPE ReleaseDC( 533 RECT *pDirtyRect) 534 { 535 return E_NOTIMPL; 536 } 537 538 virtual HRESULT STDMETHODCALLTYPE Map( 539 DXGI_MAPPED_RECT *pLockedRect, 540 unsigned MapFlags) 541 { 542 D3D11_MAP d3d_map; 543 if(MapFlags & DXGI_MAP_DISCARD) 544 d3d_map = D3D11_MAP_WRITE_DISCARD; 545 else 546 { 547 if(MapFlags & DXGI_MAP_READ) 548 { 549 if(MapFlags & DXGI_MAP_WRITE) 550 d3d_map = D3D11_MAP_READ_WRITE; 551 else 552 d3d_map = D3D11_MAP_READ; 553 } 554 else 555 d3d_map = D3D11_MAP_WRITE; 556 } 557 D3D11_MAPPED_SUBRESOURCE d3d_mapped; 558 HRESULT hres = this->device->get_immediate_context()->Map(this, 0, d3d_map, 0, &d3d_mapped); 559 pLockedRect->pBits = (uint8_t*)d3d_mapped.pData; 560 pLockedRect->Pitch = d3d_mapped.RowPitch; 561 return hres; 562 } 563 564 virtual HRESULT STDMETHODCALLTYPE Unmap(void) 565 { 566 this->device->get_immediate_context()->Unmap(this, 0); 567 return S_OK; 568 } 569 570 virtual HRESULT STDMETHODCALLTYPE GetDevice( 571 REFIID riid, 572 void **ppParent) 573 { 574 if(!device) 575 return E_NOINTERFACE; 576 return device->QueryInterface(riid, ppParent); 577 } 578}; 579 580template<typename Base, typename Desc, typename Object> 581struct GalliumD3D11View : public GalliumD3D11DescribedObject<Base, Desc, Object> 582{ 583 GalliumD3D11Resource<>* resource; 584 GalliumD3D11View(GalliumD3D11Screen* device, GalliumD3D11Resource<>* resource, Object* object, const Desc& desc) 585 : GalliumD3D11DescribedObject<Base, Desc, Object>(device, object, desc), resource(resource) 586 { 587 resource->AddRef(); 588 } 589 590 ~GalliumD3D11View() 591 { 592 resource->Release(); 593 } 594 595 virtual void STDMETHODCALLTYPE GetResource(ID3D11Resource** ppResource) 596 { 597 resource->AddRef(); 598 *ppResource = resource; 599 } 600}; 601 602typedef GalliumD3D11View<ID3D11DepthStencilView, D3D11_DEPTH_STENCIL_VIEW_DESC, struct pipe_surface> GalliumD3D11DepthStencilView; 603typedef GalliumD3D11View<ID3D11RenderTargetView, D3D11_RENDER_TARGET_VIEW_DESC, struct pipe_surface> GalliumD3D11RenderTargetView; 604 605#if API >= 11 606typedef GalliumD3D11View<ID3D11ShaderResourceView, D3D11_SHADER_RESOURCE_VIEW_DESC, struct pipe_sampler_view> GalliumD3D11ShaderResourceView; 607#else 608typedef GalliumD3D10View<ID3D10ShaderResourceView1, D3D10_SHADER_RESOURCE_VIEW_DESC1, struct pipe_sampler_view> GalliumD3D10ShaderResourceViewBase; 609 610struct GalliumD3D10ShaderResourceView : public GalliumD3D10ShaderResourceViewBase 611{ 612 GalliumD3D10ShaderResourceView(GalliumD3D10Screen* device, GalliumD3D10Resource<>* resource, struct pipe_sampler_view* view, const D3D10_SHADER_RESOURCE_VIEW_DESC1& desc) 613 : GalliumD3D10ShaderResourceViewBase(device, resource, view, desc) 614 {} 615 616 virtual void STDMETHODCALLTYPE GetDesc1(D3D10_SHADER_RESOURCE_VIEW_DESC1 *pDesc) 617 { 618 memcpy(pDesc, &desc, sizeof(*pDesc)); 619 } 620 621 virtual void STDMETHODCALLTYPE GetDesc(D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc) 622 { 623 memcpy(pDesc, &desc, sizeof(*pDesc)); 624 } 625}; 626#endif 627 628template<typename Base = ID3D11Asynchronous> 629struct GalliumD3D11Asynchronous : public GalliumD3D11DeviceChild<Base> 630{ 631 struct pipe_query* query; 632 unsigned data_size; 633 634 GalliumD3D11Asynchronous(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size) 635 : GalliumD3D11DeviceChild<Base>(device), query(query), data_size(data_size) 636 {} 637 638 ~GalliumD3D11Asynchronous() 639 { 640 this->device->immediate_pipe->destroy_query(this->device->immediate_pipe, query); 641 } 642 643 virtual unsigned STDMETHODCALLTYPE GetDataSize() 644 { 645 return data_size; 646 } 647 648#if API < 11 649 virtual void STDMETHODCALLTYPE Begin() 650 { 651 this->device->Begin(this); 652 } 653 654 virtual void STDMETHODCALLTYPE End() 655 { 656 this->device->End(this); 657 } 658 659 virtual HRESULT STDMETHODCALLTYPE GetData( 660 void *pData, 661 unsigned DataSize, 662 unsigned GetDataFlags) 663 { 664 return this->device->GetData(this, pData, DataSize, GetDataFlags); 665 } 666#endif 667}; 668 669template<typename Base = ID3D11Asynchronous> 670struct GalliumD3D11QueryOrPredicate : public GalliumD3D11Asynchronous<Base> 671{ 672 D3D11_QUERY_DESC desc; 673 GalliumD3D11QueryOrPredicate(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc) 674 : GalliumD3D11Asynchronous<Base>(device, query, data_size), desc(desc) 675 {} 676 677 virtual void STDMETHODCALLTYPE GetDesc( 678 D3D11_QUERY_DESC *pDesc) 679 { 680 *pDesc = desc; 681 } 682}; 683 684struct GalliumD3D11Query : public GalliumD3D11QueryOrPredicate<ID3D11Query> 685{ 686 GalliumD3D11Query(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc) 687 : GalliumD3D11QueryOrPredicate<ID3D11Query>(device, query, data_size, desc) 688 {} 689}; 690 691struct GalliumD3D11Predicate : public GalliumD3D11QueryOrPredicate<ID3D11Predicate> 692{ 693 GalliumD3D11Predicate(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc) 694 : GalliumD3D11QueryOrPredicate<ID3D11Predicate>(device, query, data_size, desc) 695 {} 696 697 ~GalliumD3D11Predicate() 698 { 699 DX10_ONLY(device->UnbindPredicate(this)); 700 } 701}; 702 703struct GalliumD3D11Counter : public GalliumD3D11Asynchronous<ID3D11Counter> 704{ 705 D3D11_COUNTER_DESC desc; 706 GalliumD3D11Counter(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_COUNTER_DESC& desc) 707 : GalliumD3D11Asynchronous<ID3D11Counter>(device, query, data_size), desc(desc) 708 {} 709 710 virtual void STDMETHODCALLTYPE GetDesc( 711 D3D11_COUNTER_DESC *pDesc) 712 { 713 *pDesc = desc; 714 } 715}; 716