Cogs.Core
IBindGroups.h
1#pragma once
2
3#include "Common.h"
4#include "TextureData.h"
5#include "DataFormat.h"
6
7namespace Cogs
8{
9 enum class BindingResourceType : uint8_t
10 {
11 UniformBuffer,
12 StorageBuffer,
13 Texture,
14 Sampler,
15 StorageTexture,
16 UAV,
17 SRV,
18 };
19
20 enum BindingVisibilityFlags : uint32_t
21 {
22 BindingVisibilityNone = 0,
23 BindingVisibilityVertex = 1u << 0,
24 BindingVisibilityFragment = 1u << 1,
25 BindingVisibilityCompute = 1u << 2,
26 };
27
28 enum class BindingTextureSampleType : uint8_t
29 {
30 Unknown,
31 Float,
32 UnfilterableFloat,
33 Depth,
34 Sint,
35 Uint,
36 };
37
38 enum class BindingSamplerBindingType : uint8_t
39 {
40 Unknown,
41 Filtering,
42 NonFiltering,
43 Comparison,
44 };
45
46 enum class BindingStorageTextureAccess : uint8_t
47 {
48 WriteOnly,
49 ReadOnly,
50 ReadWrite
51 };
52
53
55 {
56 uint32_t binding = 0;
57// std::string name;
58 size_t nameHash = 0;
59 BindingResourceType resourceType = BindingResourceType::UniformBuffer;
60 uint32_t visibility = BindingVisibilityNone;
61 uint32_t arrayCount = 1;
62 ResourceDimensions textureDimension = ResourceDimensions::Unknown;
63 BindingTextureSampleType textureSampleType = BindingTextureSampleType::Unknown;
64 BindingSamplerBindingType samplerBindingType = BindingSamplerBindingType::Unknown;
65 Format format = Format::Unknown;
66 BindingStorageTextureAccess storageTextureAccess = BindingStorageTextureAccess::WriteOnly;
67 bool isDepthTexture = false;
68 bool multisampled = false;
69 bool hasDynamicOffset = false;
70
71 size_t hash(size_t hashValue = Cogs::hash()) const {
72 hashValue = Cogs::hash(binding, hashValue);
73 hashValue = Cogs::hash(nameHash, hashValue);
74 hashValue = Cogs::hash(resourceType, hashValue);
75 hashValue = Cogs::hash(visibility, hashValue);
76 hashValue = Cogs::hash(arrayCount, hashValue);
77 hashValue = Cogs::hash(textureDimension, hashValue);
78 hashValue = Cogs::hash(textureSampleType, hashValue);
79 hashValue = Cogs::hash(samplerBindingType, hashValue);
80 hashValue = Cogs::hash(format, hashValue);
81 hashValue = Cogs::hash(storageTextureAccess, hashValue);
82 hashValue = Cogs::hash(isDepthTexture, hashValue);
83 hashValue = Cogs::hash(multisampled, hashValue);
84 hashValue = Cogs::hash(hasDynamicOffset, hashValue);
85
86 return hashValue;
87 }
88 };
89
90 const uint16_t MaxBindGroupEntries = 32;
92 {
93 BindGroupEntryDescription entries[MaxBindGroupEntries];
94 uint16_t numEntries = 0;
95
96 size_t hash(size_t hashValue = Cogs::hash()) const {
97 hashValue = Cogs::hash(numEntries, hashValue);
98 for (uint16_t i = 0; i < numEntries; ++i) {
99 hashValue = entries[i].hash(hashValue);
100 }
101
102 return hashValue;
103 }
104 };
105
106 const size_t MaxBindGroups = 4;
108 {
109 BindGroupDescription groups[MaxBindGroups];
110 uint16_t numGroups = 0;
111 };
112
117 {
121 virtual void annotate(BindGroupHandle handle, const StringView& name) { (void)handle; (void)name; }
122
123 virtual BindGroupHandle createBindGroup(const BindGroupDescription* desc) = 0;
124 virtual BindGroupConstantBufferBindingHandle getConstantBufferBinding(BindGroupHandle handle, const StringView& name) = 0;
125 virtual BindGroupTextureBindingHandle getTextureBinding(BindGroupHandle handle, const StringView& name) = 0;
126 virtual BindGroupSamplerStateBindingHandle getSamplerBinding(BindGroupHandle handle, const StringView& name) = 0;
127 virtual bool isCompatable(BindGroupHandle handle, const BindGroupDescription &desc) = 0;
128 virtual bool setTexture(BindGroupHandle handle, BindGroupTextureBindingHandle bindig, const TextureHandle textureHandle) = 0;
129 virtual bool setTexture(BindGroupHandle handle, BindGroupTextureBindingHandle bindig, const TextureViewHandle textureHandle) = 0;
130 virtual bool setSamplerState(BindGroupHandle handle, BindGroupSamplerStateBindingHandle bindig, SamplerStateHandle samplerStateHandle) = 0;
131 virtual bool setConstantBuffer(BindGroupHandle handle, BindGroupConstantBufferBindingHandle bindig, BufferHandle bufferHandle, const uint32_t offset = 0, const uint32_t size = ~0u) = 0;
132 virtual void releaseBindGroup(BindGroupHandle handle) = 0;
133 };
134
135
136}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:50
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62
Provides bind group management functionality.
Definition: IBindGroups.h:117
virtual void annotate(BindGroupHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
Definition: IBindGroups.h:121