1 // Copyright 2017 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_D3D12_BINDGROUPD3D12_H_ 16 #define DAWNNATIVE_D3D12_BINDGROUPD3D12_H_ 17 18 #include "common/PlacementAllocated.h" 19 #include "common/ityp_span.h" 20 #include "common/ityp_stack_vec.h" 21 #include "dawn_native/BindGroup.h" 22 #include "dawn_native/d3d12/CPUDescriptorHeapAllocationD3D12.h" 23 #include "dawn_native/d3d12/GPUDescriptorHeapAllocationD3D12.h" 24 25 namespace dawn_native { namespace d3d12 { 26 27 class Device; 28 class SamplerHeapCacheEntry; 29 class ShaderVisibleDescriptorAllocator; 30 31 class BindGroup final : public BindGroupBase, public PlacementAllocated { 32 public: 33 static ResultOrError<Ref<BindGroup>> Create(Device* device, 34 const BindGroupDescriptor* descriptor); 35 36 BindGroup(Device* device, 37 const BindGroupDescriptor* descriptor, 38 uint32_t viewSizeIncrement, 39 const CPUDescriptorHeapAllocation& viewAllocation); 40 41 // Returns true if the BindGroup was successfully populated. 42 bool PopulateViews(ShaderVisibleDescriptorAllocator* viewAllocator); 43 bool PopulateSamplers(Device* device, ShaderVisibleDescriptorAllocator* samplerAllocator); 44 45 D3D12_GPU_DESCRIPTOR_HANDLE GetBaseViewDescriptor() const; 46 D3D12_GPU_DESCRIPTOR_HANDLE GetBaseSamplerDescriptor() const; 47 48 void SetSamplerAllocationEntry(Ref<SamplerHeapCacheEntry> entry); 49 50 using DynamicStorageBufferLengths = 51 ityp::stack_vec<uint32_t, uint32_t, kMaxDynamicStorageBuffersPerPipelineLayout>; 52 const DynamicStorageBufferLengths& GetDynamicStorageBufferLengths() const; 53 54 private: 55 ~BindGroup() override; 56 57 void DestroyImpl() override; 58 59 Ref<SamplerHeapCacheEntry> mSamplerAllocationEntry; 60 61 GPUDescriptorHeapAllocation mGPUViewAllocation; 62 CPUDescriptorHeapAllocation mCPUViewAllocation; 63 64 DynamicStorageBufferLengths mDynamicStorageBufferLengths; 65 }; 66 }} // namespace dawn_native::d3d12 67 68 #endif // DAWNNATIVE_D3D12_BINDGROUPD3D12_H_ 69