1 /* 2 * Copyright 2020 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrD3DTexture_DEFINED 9 #define GrD3DTexture_DEFINED 10 11 #include "src/core/SkLRUCache.h" 12 #include "src/gpu/ganesh/GrSamplerState.h" 13 #include "src/gpu/ganesh/GrTexture.h" 14 #include "src/gpu/ganesh/d3d/GrD3DDescriptorHeap.h" 15 #include "src/gpu/ganesh/d3d/GrD3DTextureResource.h" 16 17 class GrD3DTexture : public GrTexture, public virtual GrD3DTextureResource { 18 public: 19 static sk_sp<GrD3DTexture> MakeNewTexture(GrD3DGpu*, 20 skgpu::Budgeted, 21 SkISize dimensions, 22 const D3D12_RESOURCE_DESC&, 23 GrProtected, 24 GrMipmapStatus, 25 std::string_view label); 26 27 static sk_sp<GrD3DTexture> MakeWrappedTexture(GrD3DGpu*, 28 SkISize dimensions, 29 GrWrapCacheable, 30 GrIOType, 31 const GrD3DTextureResourceInfo&, 32 sk_sp<GrD3DResourceState>); 33 34 static sk_sp<GrD3DTexture> MakeAliasingTexture(GrD3DGpu*, 35 sk_sp<GrD3DTexture>, 36 const D3D12_RESOURCE_DESC& newDesc, 37 D3D12_RESOURCE_STATES); 38 ~GrD3DTexture()39 ~GrD3DTexture() override {} 40 41 GrBackendTexture getBackendTexture() const override; 42 backendFormat()43 GrBackendFormat backendFormat() const override { return this->getBackendFormat(); } shaderResourceView()44 D3D12_CPU_DESCRIPTOR_HANDLE shaderResourceView() { return fShaderResourceView.fHandle; } 45 textureParamsModified()46 void textureParamsModified() override {} 47 48 protected: 49 GrD3DTexture(GrD3DGpu*, 50 SkISize dimensions, 51 const GrD3DTextureResourceInfo&, 52 sk_sp<GrD3DResourceState>, 53 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 54 GrMipmapStatus, 55 std::string_view label); 56 57 GrD3DGpu* getD3DGpu() const; 58 59 void onAbandon() override; 60 void onRelease() override; 61 onStealBackendTexture(GrBackendTexture *,SkImage::BackendTextureReleaseProc *)62 bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override { 63 return false; 64 } 65 66 void onSetLabel() override; 67 68 private: 69 GrD3DTexture(GrD3DGpu*, 70 skgpu::Budgeted, 71 SkISize dimensions, 72 const GrD3DTextureResourceInfo&, 73 sk_sp<GrD3DResourceState>, 74 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 75 GrMipmapStatus, 76 std::string_view label); 77 GrD3DTexture(GrD3DGpu*, SkISize dimensions, const GrD3DTextureResourceInfo&, 78 sk_sp<GrD3DResourceState>, 79 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 80 GrMipmapStatus, 81 GrWrapCacheable, 82 GrIOType, 83 std::string_view label); 84 85 // In D3D we call the release proc after we are finished with the underlying 86 // GrSurfaceResource::Resource object (which occurs after the GPU has finished all work on it). onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper)87 void onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper) override { 88 // Forward the release proc on to GrSurfaceResource 89 this->setResourceRelease(std::move(releaseHelper)); 90 } 91 92 struct SamplerHash { operatorSamplerHash93 uint32_t operator()(GrSamplerState state) const { 94 // In D3D anisotropic filtering uses the same field (D3D12_SAMPLER_DESC::Filter) as 95 // min/mag/mip settings and so is not orthogonal to them. 96 return state.asKey(/*anisoIsOrthogonal=*/false); 97 } 98 }; 99 100 GrD3DDescriptorHeap::CPUHandle fShaderResourceView; 101 102 using INHERITED = GrTexture; 103 }; 104 105 #endif 106