blob: 0d327552d0a7910ca19e48ebd7417df468abad1f [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Austin Eng036f76f2017-06-29 14:11:43 -04002//
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
Corentin Wallez30965a72018-07-24 16:42:33 +020015#ifndef DAWNNATIVE_D3D12_BINDGROUPD3D12_H_
16#define DAWNNATIVE_D3D12_BINDGROUPD3D12_H_
Austin Eng036f76f2017-06-29 14:11:43 -040017
Austin Engae96f042020-03-13 23:34:40 +000018#include "common/PlacementAllocated.h"
Austin Enge5b361d2021-11-29 23:02:49 +000019#include "common/ityp_span.h"
20#include "common/ityp_stack_vec.h"
Corentin Wallezd37523f2018-07-24 13:53:51 +020021#include "dawn_native/BindGroup.h"
Bryan Bernhartcb859a22020-04-06 22:07:42 +000022#include "dawn_native/d3d12/CPUDescriptorHeapAllocationD3D12.h"
Bryan Bernhart303a3da2020-04-30 23:19:16 +000023#include "dawn_native/d3d12/GPUDescriptorHeapAllocationD3D12.h"
Austin Eng036f76f2017-06-29 14:11:43 -040024
Corentin Wallezec9cf2a2022-01-12 09:17:35 +000025namespace dawn::native::d3d12 {
Austin Eng036f76f2017-06-29 14:11:43 -040026
27 class Device;
Bryan Bernharte25ee252020-05-18 23:25:31 +000028 class SamplerHeapCacheEntry;
Bryan Bernhart0363c3e2020-02-27 01:14:22 +000029 class ShaderVisibleDescriptorAllocator;
Austin Eng036f76f2017-06-29 14:11:43 -040030
Rafael Cintronc64242d2020-04-06 18:20:02 +000031 class BindGroup final : public BindGroupBase, public PlacementAllocated {
Corentin Wallez2d62a372017-11-24 14:04:22 -050032 public:
Corentin Wallez50f99582021-03-31 18:36:32 +000033 static ResultOrError<Ref<BindGroup>> Create(Device* device,
34 const BindGroupDescriptor* descriptor);
Austin Engae96f042020-03-13 23:34:40 +000035
Bryan Bernhartcb859a22020-04-06 22:07:42 +000036 BindGroup(Device* device,
37 const BindGroupDescriptor* descriptor,
38 uint32_t viewSizeIncrement,
Bryan Bernharte25ee252020-05-18 23:25:31 +000039 const CPUDescriptorHeapAllocation& viewAllocation);
Austin Eng036f76f2017-06-29 14:11:43 -040040
Bryan Bernhart0363c3e2020-02-27 01:14:22 +000041 // Returns true if the BindGroup was successfully populated.
Bryan Bernhart303a3da2020-04-30 23:19:16 +000042 bool PopulateViews(ShaderVisibleDescriptorAllocator* viewAllocator);
Bryan Bernharte25ee252020-05-18 23:25:31 +000043 bool PopulateSamplers(Device* device, ShaderVisibleDescriptorAllocator* samplerAllocator);
Jiawei Shaoe4c0a822019-05-16 05:56:49 +000044
Bryan Bernhart303a3da2020-04-30 23:19:16 +000045 D3D12_GPU_DESCRIPTOR_HANDLE GetBaseViewDescriptor() const;
Bryan Bernhart0363c3e2020-02-27 01:14:22 +000046 D3D12_GPU_DESCRIPTOR_HANDLE GetBaseSamplerDescriptor() const;
Austin Eng036f76f2017-06-29 14:11:43 -040047
Bryan Bernharte25ee252020-05-18 23:25:31 +000048 void SetSamplerAllocationEntry(Ref<SamplerHeapCacheEntry> entry);
Bryan Bernhart303a3da2020-04-30 23:19:16 +000049
Austin Enge5b361d2021-11-29 23:02:49 +000050 using DynamicStorageBufferLengths =
51 ityp::stack_vec<uint32_t, uint32_t, kMaxDynamicStorageBuffersPerPipelineLayout>;
52 const DynamicStorageBufferLengths& GetDynamicStorageBufferLengths() const;
53
Bryan Bernharte25ee252020-05-18 23:25:31 +000054 private:
Rafael Cintronc64242d2020-04-06 18:20:02 +000055 ~BindGroup() override;
56
Loko Kunge9c84c02021-11-11 01:39:52 +000057 void DestroyImpl() override;
Loko Kung2c67af92021-11-11 00:39:22 +000058
Bryan Bernharte25ee252020-05-18 23:25:31 +000059 Ref<SamplerHeapCacheEntry> mSamplerAllocationEntry;
Bryan Bernhartcb859a22020-04-06 22:07:42 +000060
Bryan Bernharte25ee252020-05-18 23:25:31 +000061 GPUDescriptorHeapAllocation mGPUViewAllocation;
Bryan Bernhartcb859a22020-04-06 22:07:42 +000062 CPUDescriptorHeapAllocation mCPUViewAllocation;
Austin Enge5b361d2021-11-29 23:02:49 +000063
64 DynamicStorageBufferLengths mDynamicStorageBufferLengths;
Austin Eng036f76f2017-06-29 14:11:43 -040065 };
Corentin Wallezec9cf2a2022-01-12 09:17:35 +000066} // namespace dawn::native::d3d12
Austin Eng036f76f2017-06-29 14:11:43 -040067
Corentin Wallez30965a72018-07-24 16:42:33 +020068#endif // DAWNNATIVE_D3D12_BINDGROUPD3D12_H_