5#include "graphics/GPUTypes.hpp"
6#include "resources/Buffer.hpp"
7#include "resources/Texture.hpp"
9#include <unordered_map>
13VK_DEFINE_HANDLE(VkBuffer)
14VK_DEFINE_HANDLE(VkImageView)
15VK_DEFINE_HANDLE(VkSampler)
16VK_DEFINE_HANDLE(VkShaderModule)
17VK_DEFINE_HANDLE(VkPipelineLayout)
18VK_DEFINE_HANDLE(VkDescriptorSetLayout)
49 BOOL, BVEC2, BVEC3, BVEC4,
50 INT, IVEC2, IVEC3, IVEC4,
51 UINT, UVEC2, UVEC3, UVEC4,
52 FLOAT, VEC2, VEC3, VEC4,
93 using Uniforms = std::unordered_map<std::string, UniformDef>;
103 Program(
const std::string &
name,
const std::string & vertexContent,
const std::string & fragmentContent,
const std::string & tessControlContent =
"",
const std::string & tessEvalContent =
"");
110 Program(
const std::string &
name,
const std::string & computeContent);
119 void reload(
const std::string & vertexContent,
const std::string & fragmentContent,
const std::string & tessControlContent =
"",
const std::string & tessEvalContent =
"");
125 void reload(
const std::string & computeContent);
160 void bufferArray(
const std::vector<const Buffer *> & buffers, uint slot);
188 void textures(
const std::vector<const Texture *> &
textures,
size_t slot = 0);
232 void uniform(
const std::string &
name,
const glm::vec2 & t);
238 void uniform(
const std::string &
name,
const glm::vec3 & t);
244 void uniform(
const std::string &
name,
const glm::vec4 & t);
250 void uniform(
const std::string &
name,
const glm::ivec2 & t);
256 void uniform(
const std::string &
name,
const glm::ivec3 & t);
262 void uniform(
const std::string &
name,
const glm::ivec4 & t);
268 void uniform(
const std::string &
name,
const glm::mat3 & t);
274 void uniform(
const std::string &
name,
const glm::mat4 & t);
355 const std::string &
name()
const {
365 const glm::uvec3 &
size()
const;
386 VkPipelineLayout
layout = VK_NULL_HANDLE;
399 glm::uvec3
size = glm::uvec3(0);
436 buffState.
dirty =
true;
443 std::shared_ptr<UniformBuffer<char>>
buffer;
452 std::vector<const Texture*>
textures = {
nullptr };
453 std::vector<VkImageView>
views = { VK_NULL_HANDLE };
462 std::vector<VkBuffer>
buffers = { VK_NULL_HANDLE};
General purpose GPU buffer, with different use types determining its memory type, visibility and acce...
Definition: Buffer.hpp:10
Provide utility functions to communicate with the driver and GPU.
Definition: GPU.hpp:20
Represents a group of shaders used for rendering.
Definition: Program.hpp:31
void textureArray(const std::vector< const Texture * > &textures, uint slot, uint mip=Program::ALL_MIPS)
Definition: Program.cpp:642
std::vector< uint32_t > _currentOffsets
Offsets in the descriptor set for dynamic uniform buffers.
Definition: Program.hpp:483
static uint ALL_MIPS
Definition: Program.hpp:35
void update()
Definition: Program.cpp:387
std::unordered_map< std::string, UniformDef > Uniforms
List of named uniforms.
Definition: Program.hpp:93
Stage & stage(ShaderType type)
Definition: Program.hpp:408
void transitionResourcesTo(Program::Type type)
Definition: Program.cpp:327
void reload(const std::string &vertexContent, const std::string &fragmentContent, const std::string &tessControlContent="", const std::string &tessEvalContent="")
Definition: Program.cpp:21
char * retrieveUniformNonConst(const UniformDef::Location &location)
Definition: Program.hpp:434
const Type _type
Is this a compute shader.
Definition: Program.hpp:486
const std::string & name() const
Definition: Program.hpp:355
std::array< Stage, int(ShaderType::COUNT)> _stages
Per-stage reflection data.
Definition: Program.hpp:472
Program & operator=(Program &&)=delete
State _state
Program pipeline state.
Definition: Program.hpp:473
std::array< bool, 4 > _dirtySets
Marks which descriptor sets are dirty.
Definition: Program.hpp:481
const State & getState() const
Definition: Program.hpp:390
void uniform(const std::string &name, bool t)
Definition: Program.cpp:690
std::unordered_map< int, DynamicBufferState > _dynamicBuffers
Dynamic uniform buffer definitions (set 0).
Definition: Program.hpp:477
std::unordered_map< int, TextureState > _textures
Dynamic image-sampler definitions (set 2).
Definition: Program.hpp:478
void reflect()
Reflect all uniforms/textures/storage buffers and images based on the shader content.
Definition: Program.cpp:49
std::string _name
Debug name.
Definition: Program.hpp:471
Program(const Program &)=delete
Program(Program &&)=default
Program & operator=(const Program &)=delete
const char * retrieveUniform(const UniformDef::Location &location) const
Definition: Program.hpp:425
const glm::uvec3 & size() const
Definition: Program.cpp:921
void clean()
Definition: Program.cpp:552
void use() const
Definition: Program.cpp:548
std::unordered_map< std::string, UniformDef > _uniforms
All dynamic uniform definitions.
Definition: Program.hpp:475
std::array< DescriptorSet, 4 > _currentSets
Descriptor sets.
Definition: Program.hpp:482
void textures(const std::vector< const Texture * > &textures, size_t slot=0)
Definition: Program.cpp:682
void texture(const Texture *texture, uint slot, uint mip=Program::ALL_MIPS)
Definition: Program.cpp:664
bool _reloaded
Has the program been reloaded.
Definition: Program.hpp:485
void defaultTexture(uint slot)
Definition: Program.cpp:668
bool reloaded() const
Definition: Program.cpp:536
Program::Type type() const
Definition: Program.hpp:360
std::unordered_map< int, StaticBufferState > _staticBuffers
Static uniform buffer definitions (set 3).
Definition: Program.hpp:479
const Uniforms & uniforms() const
Definition: Program.hpp:350
void getUniform(const std::string &name, bool &t) const
Definition: Program.cpp:824
Type
Definition: Program.hpp:38
@ GRAPHICS
Graphics program for draw calls.
@ COMPUTE
Compute program for dispatch calls.
void updateUniformMetric() const
Update internal metrics.
Definition: Program.cpp:931
void bufferArray(const std::vector< const Buffer * > &buffers, uint slot)
Definition: Program.cpp:604
void buffer(const UniformBufferBase &buffer, uint slot)
Definition: Program.cpp:576
Represents a texture containing one or more images, stored on the CPU and/or GPU.
Definition: Texture.hpp:12
TextureShape
The shape of a texture: dimensions, layers organisation.
Definition: GPUTypes.hpp:153
ShaderType
The type of a shader.
Definition: GPUTypes.hpp:18
Buffer reflection information.
Definition: Program.hpp:83
bool storage
Is this a storage buffer.
Definition: Program.hpp:90
uint count
Number of similar buffers for this binding point.
Definition: Program.hpp:89
std::string name
Buffer name.
Definition: Program.hpp:85
std::vector< UniformDef > members
Uniforms in buffer.
Definition: Program.hpp:84
uint set
Buffer binding set.
Definition: Program.hpp:88
uint size
Buffer size.
Definition: Program.hpp:87
uint binding
Buffer binding location.
Definition: Program.hpp:86
Internal state for a dynamic uniform buffer.
Definition: Program.hpp:442
std::shared_ptr< UniformBuffer< char > > buffer
Owned Uniform buffer.
Definition: Program.hpp:443
uint descriptorIndex
Descriptor index in set.
Definition: Program.hpp:444
bool dirty
Is the buffer dirty since last draw.
Definition: Program.hpp:445
Image-sampler reflection information.
Definition: Program.hpp:72
uint set
Image binding set.
Definition: Program.hpp:76
std::string name
Image name.
Definition: Program.hpp:73
uint count
Number of similar images for this binding point.
Definition: Program.hpp:77
uint binding
Image binding location.
Definition: Program.hpp:75
bool storage
Is this a storage image.
Definition: Program.hpp:78
TextureShape shape
Image shape.
Definition: Program.hpp:74
Per-stage reflection information.
Definition: Program.hpp:395
std::vector< ImageDef > images
Image definitions.
Definition: Program.hpp:396
std::vector< BufferDef > buffers
Buffers definitions.
Definition: Program.hpp:397
glm::uvec3 size
Definition: Program.hpp:399
VkShaderModule module
Native shader data.
Definition: Program.hpp:398
void reset()
Reset the stage state.
Definition: Program.cpp:925
Program pipeline state.
Definition: Program.hpp:384
VkPipelineLayout layout
Layout handle (pre-created).
Definition: Program.hpp:386
std::vector< VkDescriptorSetLayout > setLayouts
Descriptor sets layouts.
Definition: Program.hpp:385
Internal state for a static (external) uniform buffer.
Definition: Program.hpp:460
std::vector< uint > offsets
Start offset in the buffer.
Definition: Program.hpp:463
uint size
Region size in the buffer.
Definition: Program.hpp:464
uint count
Number of buffers bound at this slot.
Definition: Program.hpp:465
std::string name
Name.
Definition: Program.hpp:461
bool storage
Is the buffer used as storage.
Definition: Program.hpp:467
std::vector< VkBuffer > buffers
Native buffer handle.
Definition: Program.hpp:462
uint lastSet
Keep track of one of the buffers that has been set (and is thus valid).
Definition: Program.hpp:466
Internal state for an image.
Definition: Program.hpp:449
bool storage
Is the image used as storage.
Definition: Program.hpp:456
std::string name
Name.
Definition: Program.hpp:450
std::vector< VkImageView > views
Texture view.
Definition: Program.hpp:453
std::vector< const Texture * > textures
The source texture.
Definition: Program.hpp:452
uint count
Number of images bound at this slot..
Definition: Program.hpp:454
TextureShape shape
Texture shape.
Definition: Program.hpp:451
uint mip
The corresponding mip.
Definition: Program.hpp:455