Nebula
Loading...
Searching...
No Matches
vkshaderpool.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
10#include "core/refcounted.h"
11#include "coregraphics/config.h"
12#include "resources/resourcestreamcache.h"
13#include "util/dictionary.h"
15#include "lowlevel/vk/vkprogram.h"
16#include "coregraphics/shader.h"
17#include "vkloader.h"
18#include "coregraphics/buffer.h"
21#include "vkshaderprogram.h"
22#include "vktexture.h"
23#include "vkshader.h"
24
25namespace CoreGraphics
26{
27 void SetShaderProgram(const CoreGraphics::ShaderProgramId pro, const CoreGraphics::QueueType queue, const bool bindSharedResources);
28}
29
30namespace Vulkan
31{
32
33class VkShaderCache : public Resources::ResourceStreamCache
34{
36
37public:
38
46
50 virtual ~VkShaderCache();
51
53 CoreGraphics::ShaderProgramId GetShaderProgram(const CoreGraphics::ShaderId shaderId, const CoreGraphics::ShaderFeature::Mask mask);
54
56 CoreGraphics::ResourceTableId CreateResourceTable(const CoreGraphics::ShaderId id, const IndexT group, const uint overallocationSize);
61
63 const IndexT GetConstantBinding(const CoreGraphics::ShaderId id, const Util::StringAtom& name) const;
65 const IndexT GetConstantBinding(const CoreGraphics::ShaderId id, const IndexT cIndex) const;
68
73
75 const SizeT GetConstantCount(const CoreGraphics::ShaderId id) const;
86
88 const IndexT GetConstantGroup(const CoreGraphics::ShaderId id, const Util::StringAtom& name) const;
90 const IndexT GetConstantSlot(const CoreGraphics::ShaderId id, const Util::StringAtom& name) const;
91
95 const SizeT GetConstantBufferSize(const CoreGraphics::ShaderId id, const IndexT i) const;
103 const IndexT GetResourceSlot(const CoreGraphics::ShaderId id, const Util::StringAtom& name) const;
104
105
109 Util::String GetProgramName(CoreGraphics::ShaderProgramId id);
110
111private:
113 friend class VkPipelineDatabase;
114 friend void ::CoreGraphics::SetShaderProgram(const CoreGraphics::ShaderProgramId pro, const CoreGraphics::QueueType queue, const bool bindSharedResources);
115
117 const VkProgramReflectionInfo& GetProgram(const CoreGraphics::ShaderProgramId shaderProgramId);
119 LoadStatus LoadFromStream(const Resources::ResourceId id, const Util::StringAtom& tag, const Ptr<IO::Stream>& stream, bool immediate = false) override;
121 LoadStatus ReloadFromStream(const Resources::ResourceId id, const Ptr<IO::Stream>& stream) override;
122
124 void Unload(const Resources::ResourceId id) override;
125
128
130 {
131 VkDescriptorSet set;
132 VkPipelineLayout layout;
134 };
135
137 {
138 uint32_t index;
139 uint32_t offset;
140 };
141
142
159
183
184 enum
185 {
190 };
191
195 VkShaderSetupInfo, //1 setup immutable values
196 VkShaderRuntimeInfo, //2 runtime values
197 VkShaderProgramAllocator //3 variations
199 __ImplementResourceAllocatorTyped(shaderAlloc, CoreGraphics::ShaderIdType);
200
201 //__ResourceAllocator(VkShader);
202 CoreGraphics::ShaderProgramId activeShaderProgram;
205};
206
207} // namespace Vulkan
uint Mask
a shader feature bit mask
Definition shaderfeature.h:31
IndexT Code
binary code for a ModelNodeType
Definition shaderidentifier.h:38
An ID allocator associates an id with a slice in an N number of arrays.
Definition idallocator.h:39
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:60
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
A StringAtom.
Definition stringatom.h:22
Definition vkpipelinedatabase.h:34
Definition vkshaderpool.h:34
CoreGraphics::ResourceTableId CreateResourceTable(const CoreGraphics::ShaderId id, const IndexT group, const uint overallocationSize)
create resource table
Definition vkshaderpool.cc:277
const SizeT GetConstantBindingsCount(const CoreGraphics::ShaderId id) const
get constant buffer bindings
Definition vkshaderpool.cc:365
CoreGraphics::ResourceTableLayoutId GetResourceTableLayout(const CoreGraphics::ShaderId id, const IndexT group)
get the resource table layout
Definition vkshaderpool.cc:375
const Util::StringAtom GetConstantBlockName(const CoreGraphics::ShaderId id, const Util::StringAtom &name)
get name of constant block wherein the variable resides
Definition vkshaderpool.cc:594
const SizeT GetConstantBufferSize(const CoreGraphics::ShaderId id, const IndexT i) const
get size of constant buffer
Definition vkshaderpool.cc:665
const SizeT GetConstantCount(const CoreGraphics::ShaderId id) const
get number of variables for shader
Definition vkshaderpool.cc:403
Util::Dictionary< Ids::Id24, Ids::Id32 > slicedStateMap
Definition vkshaderpool.h:204
Util::Dictionary< CoreGraphics::ShaderFeature::Mask, CoreGraphics::ShaderProgramId > ProgramMap
Definition vkshaderpool.h:39
LoadStatus LoadFromStream(const Resources::ResourceId id, const Util::StringAtom &tag, const Ptr< IO::Stream > &stream, bool immediate=false) override
load shader
Definition vkshaderpool.cc:45
Util::Dictionary< uint32_t, Util::Array< CoreGraphics::BufferId > > UniformBufferGroupMap
Definition vkshaderpool.h:127
__DeclareClass(VkShaderCache)
Util::String GetProgramName(CoreGraphics::ShaderProgramId id)
get name of program
Definition vkshaderpool.cc:726
CoreGraphics::ShaderProgramId activeShaderProgram
Definition vkshaderpool.h:202
friend class VkVertexSignatureCache
Definition vkshaderpool.h:112
const IndexT GetConstantBinding(const CoreGraphics::ShaderId id, const Util::StringAtom &name) const
get constant buffer binding from name
Definition vkshaderpool.cc:343
const SizeT GetConstantBufferCount(const CoreGraphics::ShaderId id) const
get number of constant blocks
Definition vkshaderpool.cc:656
const CoreGraphics::ShaderConstantType GetConstantType(const CoreGraphics::ShaderId id, const IndexT i) const
get type of constant by index
Definition vkshaderpool.cc:412
CoreGraphics::ShaderFeature::Mask activeMask
Definition vkshaderpool.h:203
const Util::StringAtom GetConstantName(const CoreGraphics::ShaderId id, const IndexT i) const
get name of constant by index
Definition vkshaderpool.cc:614
const VkProgramReflectionInfo & GetProgram(const CoreGraphics::ShaderProgramId shaderProgramId)
get shader program
Definition vkshaderpool.cc:394
virtual ~VkShaderCache()
destructor
Definition vkshaderpool.cc:36
const IndexT GetConstantSlot(const CoreGraphics::ShaderId id, const Util::StringAtom &name) const
get constant buffer slot index of constant
Definition vkshaderpool.cc:640
const IndexT GetConstantGroup(const CoreGraphics::ShaderId id, const Util::StringAtom &name) const
get constant buffer group index of constant
Definition vkshaderpool.cc:624
LoadStatus ReloadFromStream(const Resources::ResourceId id, const Ptr< IO::Stream > &stream) override
reload shader
Definition vkshaderpool.cc:161
@ Shader_ProgramAllocator
Definition vkshaderpool.h:189
@ Shader_RuntimeInfo
Definition vkshaderpool.h:188
@ Shader_SetupInfo
Definition vkshaderpool.h:187
@ Shader_ReflectionInfo
Definition vkshaderpool.h:186
Ids::IdAllocator< VkReflectionInfo, VkShaderSetupInfo, VkShaderRuntimeInfo, VkShaderProgramAllocator > shaderAlloc
this member allocates shaders
Definition vkshaderpool.h:198
__ImplementResourceAllocatorTyped(shaderAlloc, CoreGraphics::ShaderIdType)
void Unload(const Resources::ResourceId id) override
unload shader
Definition vkshaderpool.cc:243
VkShaderCache()
constructor
Definition vkshaderpool.cc:24
CoreGraphics::ShaderProgramId GetShaderProgram(const CoreGraphics::ShaderId shaderId, const CoreGraphics::ShaderFeature::Mask mask)
get shader-program id, which can be used to directly access a program in a shader
Definition vkshaderpool.cc:265
const IndexT GetConstantBufferResourceGroup(const CoreGraphics::ShaderId id, const IndexT i) const
get group of constant buffer based on index
Definition vkshaderpool.cc:695
CoreGraphics::BufferId CreateConstantBuffer(const CoreGraphics::ShaderId id, const Util::StringAtom &name, CoreGraphics::BufferAccessMode mode)
create constant buffer from name
Definition vkshaderpool.cc:297
const Util::Dictionary< CoreGraphics::ShaderFeature::Mask, CoreGraphics::ShaderProgramId > & GetPrograms(const CoreGraphics::ShaderId id)
get list all mask-program pairs
Definition vkshaderpool.cc:717
const Util::StringAtom GetConstantBufferName(const CoreGraphics::ShaderId id, const IndexT i) const
get name of constnat buffer
Definition vkshaderpool.cc:675
CoreGraphics::ResourcePipelineId GetResourcePipeline(const CoreGraphics::ShaderId id)
get the pipeline layout
Definition vkshaderpool.cc:384
Util::Dictionary< Util::StringAtom, CoreGraphics::BufferId > UniformBufferMap
Definition vkshaderpool.h:126
const IndexT GetResourceSlot(const CoreGraphics::ShaderId id, const Util::StringAtom &name) const
get slot of shader resource
Definition vkshaderpool.cc:705
const IndexT GetConstantBufferResourceSlot(const CoreGraphics::ShaderId id, const IndexT i) const
get slot of constant buffer based on index
Definition vkshaderpool.cc:685
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
BufferAccessMode
Definition buffer.h:27
QueueType
Definition config.h:40
void SetShaderProgram(const CoreGraphics::ShaderProgramId pro, const CoreGraphics::QueueType queue, const bool bindSharedResources)
ShaderConstantType
Definition shader.h:63
Vulkan implementation of GPU acceleration structure.
Definition vkaccelerationstructure.cc:15
Compile time configuration options for the CoreGraphics subsystem.
A resource table declares a list of resources (ResourceTable in DX12, DescriptorSet in Vulkan)
A shader represents an entire shader resource, containing several stages and programs.
Definition buffer.h:23
Definition resourcetable.h:402
Definition resourcetable.h:95
Definition resourcetable.h:25
Definition shader.h:51
Nebula's universal string class.
Definition string.h:50
Definition vkshaderprogram.h:53
Definition vkshader.h:98
Definition vkshaderpool.h:137
uint32_t index
Definition vkshaderpool.h:138
uint32_t offset
Definition vkshaderpool.h:139
Definition vkshaderpool.h:130
VkPipelineLayout layout
Definition vkshaderpool.h:132
VkDescriptorSet set
Definition vkshaderpool.h:131
IndexT slot
Definition vkshaderpool.h:133
uint32_t set
Definition vkshaderpool.h:164
uint32_t byteSize
Definition vkshaderpool.h:166
Util::StringAtom name
Definition vkshaderpool.h:167
uint32_t binding
Definition vkshaderpool.h:165
Util::StringAtom blockName
Definition vkshaderpool.h:176
uint32_t blockSet
Definition vkshaderpool.h:177
Util::StringAtom name
Definition vkshaderpool.h:175
uint32_t blockBinding
Definition vkshaderpool.h:178
AnyFX::VariableType type
Definition vkshaderpool.h:174
Definition vkshaderpool.h:161
Util::Array< Variable > variables
Definition vkshaderpool.h:181
Util::Dictionary< Util::StringAtom, UniformBuffer > uniformBuffersByName
Definition vkshaderpool.h:169
Util::Dictionary< Util::StringAtom, Variable > variablesByName
Definition vkshaderpool.h:180
Util::Array< UniformBuffer > uniformBuffers
Definition vkshaderpool.h:170
Definition vkshaderpool.h:41
ProgramMap programMap
Definition vkshaderpool.h:44
CoreGraphics::ShaderFeature::Mask activeMask
Definition vkshaderpool.h:42
CoreGraphics::ShaderProgramId activeShaderProgram
Definition vkshaderpool.h:43
Definition vkshaderpool.h:144
Util::Dictionary< Util::StringAtom, IndexT > constantBindings
Definition vkshaderpool.h:155
Util::Dictionary< Util::StringAtom, uint32_t > resourceIndexMap
Definition vkshaderpool.h:154
Util::Dictionary< uint32_t, uint32_t > descriptorSetLayoutMap
Definition vkshaderpool.h:157
Util::Array< CoreGraphics::SamplerId > immutableSamplers
Definition vkshaderpool.h:153
Util::FixedArray< CoreGraphics::ResourcePipelinePushConstantRange > constantRangeLayout
Definition vkshaderpool.h:152
VkDevice dev
Definition vkshaderpool.h:145
UniformBufferGroupMap uniformBufferGroupMap
Definition vkshaderpool.h:149
Util::FixedArray< Util::Pair< uint32_t, CoreGraphics::ResourceTableLayoutId > > descriptorSetLayouts
Definition vkshaderpool.h:156
Resources::ResourceName name
Definition vkshaderpool.h:146
CoreGraphics::ShaderIdentifier::Code id
Definition vkshaderpool.h:147
CoreGraphics::ResourcePipelineId pipelineLayout
Definition vkshaderpool.h:151
UniformBufferMap uniformBufferMap
Definition vkshaderpool.h:148
Definition vkshader.h:74
Definition vkshader.h:81
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48