Greg Daniel | 02c4590 | 2020-03-09 10:58:09 -0400 | [diff] [blame] | 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 GrD3DResourceProvider_DEFINED |
| 9 | #define GrD3DResourceProvider_DEFINED |
| 10 | |
Jim Van Verth | 9aa9a68 | 2020-04-01 10:13:48 -0400 | [diff] [blame] | 11 | #include "include/gpu/d3d/GrD3DTypes.h" |
Greg Daniel | 7a5f1fa | 2020-03-24 14:50:19 -0400 | [diff] [blame] | 12 | #include "include/private/SkTArray.h" |
Greg Daniel | b698ad3 | 2020-05-04 10:17:22 -0400 | [diff] [blame] | 13 | #include "src/core/SkLRUCache.h" |
| 14 | #include "src/gpu/GrProgramDesc.h" |
Jim Van Verth | afd4113 | 2020-05-28 06:44:55 -0400 | [diff] [blame^] | 15 | #include "src/gpu/d3d/GrD3DCpuDescriptorManager.h" |
Greg Daniel | c31edc0 | 2020-04-23 11:03:02 -0400 | [diff] [blame] | 16 | #include "src/gpu/d3d/GrD3DRootSignature.h" |
Greg Daniel | 02c4590 | 2020-03-09 10:58:09 -0400 | [diff] [blame] | 17 | |
Greg Daniel | e52c978 | 2020-03-23 14:18:37 -0400 | [diff] [blame] | 18 | #include <memory> |
| 19 | |
| 20 | class GrD3DDirectCommandList; |
Greg Daniel | 02c4590 | 2020-03-09 10:58:09 -0400 | [diff] [blame] | 21 | class GrD3DGpu; |
Greg Daniel | b698ad3 | 2020-05-04 10:17:22 -0400 | [diff] [blame] | 22 | class GrD3DPipelineState; |
Greg Daniel | 02c4590 | 2020-03-09 10:58:09 -0400 | [diff] [blame] | 23 | |
| 24 | class GrD3DResourceProvider { |
| 25 | public: |
| 26 | GrD3DResourceProvider(GrD3DGpu*); |
| 27 | |
Greg Daniel | e52c978 | 2020-03-23 14:18:37 -0400 | [diff] [blame] | 28 | std::unique_ptr<GrD3DDirectCommandList> findOrCreateDirectCommandList(); |
Greg Daniel | 85da336 | 2020-03-09 15:18:35 -0400 | [diff] [blame] | 29 | |
Greg Daniel | 7a5f1fa | 2020-03-24 14:50:19 -0400 | [diff] [blame] | 30 | void recycleDirectCommandList(std::unique_ptr<GrD3DDirectCommandList>); |
| 31 | |
Greg Daniel | c31edc0 | 2020-04-23 11:03:02 -0400 | [diff] [blame] | 32 | sk_sp<GrD3DRootSignature> findOrCreateRootSignature(int numTextureSamplers); |
| 33 | |
Jim Van Verth | 5ce9440 | 2020-05-01 14:19:13 -0400 | [diff] [blame] | 34 | D3D12_CPU_DESCRIPTOR_HANDLE createRenderTargetView(ID3D12Resource* textureResource); |
| 35 | void recycleRenderTargetView(D3D12_CPU_DESCRIPTOR_HANDLE*); |
| 36 | |
Jim Van Verth | 7359165 | 2020-05-08 12:50:38 -0400 | [diff] [blame] | 37 | D3D12_CPU_DESCRIPTOR_HANDLE createDepthStencilView(ID3D12Resource* textureResource); |
| 38 | void recycleDepthStencilView(D3D12_CPU_DESCRIPTOR_HANDLE*); |
| 39 | |
Jim Van Verth | afd4113 | 2020-05-28 06:44:55 -0400 | [diff] [blame^] | 40 | D3D12_CPU_DESCRIPTOR_HANDLE createConstantBufferView(ID3D12Resource* bufferResource, |
| 41 | size_t offset, |
| 42 | size_t size); |
| 43 | D3D12_CPU_DESCRIPTOR_HANDLE createShaderResourceView(ID3D12Resource* resource); |
| 44 | void recycleConstantOrShaderView(D3D12_CPU_DESCRIPTOR_HANDLE*); |
| 45 | |
| 46 | D3D12_CPU_DESCRIPTOR_HANDLE createSampler(D3D12_FILTER filter, |
| 47 | D3D12_TEXTURE_ADDRESS_MODE addressModeU, |
| 48 | D3D12_TEXTURE_ADDRESS_MODE addressModeV); |
| 49 | void recycleSampler(D3D12_CPU_DESCRIPTOR_HANDLE*); |
| 50 | |
Greg Daniel | b698ad3 | 2020-05-04 10:17:22 -0400 | [diff] [blame] | 51 | sk_sp<GrD3DPipelineState> findOrCreateCompatiblePipelineState(GrRenderTarget*, |
| 52 | const GrProgramInfo&); |
| 53 | |
Greg Daniel | 02c4590 | 2020-03-09 10:58:09 -0400 | [diff] [blame] | 54 | private: |
Greg Daniel | b698ad3 | 2020-05-04 10:17:22 -0400 | [diff] [blame] | 55 | #ifdef SK_DEBUG |
| 56 | #define GR_PIPELINE_STATE_CACHE_STATS |
| 57 | #endif |
| 58 | |
| 59 | class PipelineStateCache : public ::SkNoncopyable { |
| 60 | public: |
| 61 | PipelineStateCache(GrD3DGpu* gpu); |
| 62 | ~PipelineStateCache(); |
| 63 | |
| 64 | sk_sp<GrD3DPipelineState> refPipelineState(GrRenderTarget*, const GrProgramInfo&); |
| 65 | |
| 66 | private: |
| 67 | struct Entry; |
| 68 | |
| 69 | struct DescHash { |
| 70 | uint32_t operator()(const GrProgramDesc& desc) const { |
| 71 | return SkOpts::hash_fn(desc.asKey(), desc.keyLength(), 0); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | SkLRUCache<const GrProgramDesc, std::unique_ptr<Entry>, DescHash> fMap; |
| 76 | |
| 77 | GrD3DGpu* fGpu; |
| 78 | |
| 79 | #ifdef GR_PIPELINE_STATE_CACHE_STATS |
| 80 | int fTotalRequests; |
| 81 | int fCacheMisses; |
| 82 | #endif |
| 83 | }; |
| 84 | |
Greg Daniel | 85da336 | 2020-03-09 15:18:35 -0400 | [diff] [blame] | 85 | GrD3DGpu* fGpu; |
Greg Daniel | 7a5f1fa | 2020-03-24 14:50:19 -0400 | [diff] [blame] | 86 | |
| 87 | SkSTArray<4, std::unique_ptr<GrD3DDirectCommandList>> fAvailableDirectCommandLists; |
Greg Daniel | c31edc0 | 2020-04-23 11:03:02 -0400 | [diff] [blame] | 88 | SkSTArray<4, sk_sp<GrD3DRootSignature>> fRootSignatures; |
Jim Van Verth | 5ce9440 | 2020-05-01 14:19:13 -0400 | [diff] [blame] | 89 | |
Jim Van Verth | afd4113 | 2020-05-28 06:44:55 -0400 | [diff] [blame^] | 90 | GrD3DCpuDescriptorManager fCpuDescriptorManager; |
Greg Daniel | b698ad3 | 2020-05-04 10:17:22 -0400 | [diff] [blame] | 91 | |
| 92 | std::unique_ptr<PipelineStateCache> fPipelineStateCache; |
Greg Daniel | 02c4590 | 2020-03-09 10:58:09 -0400 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | #endif |