Skip to content
Snippets Groups Projects
Verified Commit fe3c7d13 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Adjusted doxygen comments of shader program

parent 91be097e
No related branches found
No related tags found
1 merge request!97Resolve "Dokumentation vervollständigen"
......@@ -32,39 +32,69 @@ namespace vkcv {
~ShaderProgram() = default; // dtor
/**
* Adds a shader into the shader program.
* The shader is only added if the shader program does not contain the particular shader stage already.
* Contains: (1) reading of the code, (2) creation of a shader module, (3) creation of a shader stage, (4) adding to the shader stage list, (5) destroying of the shader module
* @param[in] flag that signals the respective shaderStage (e.g. VK_SHADER_STAGE_VERTEX_BIT)
* @param[in] relative path to the shader code (e.g. "../../../../../shaders/vert.spv")
*/
bool addShader(ShaderStage shaderStage, const std::filesystem::path &shaderPath);
* @brief Adds a shader into the shader program.
* The shader is only added if the shader program does not contain
* the particular shader stage already.
* Contains:
* (1) reading the SPIR-V file,
* (2) creating a shader module,
* (3) creating a shader stage,
* (4) adding to the shader stage list,
* (5) destroying of the shader module
*
* @param[in] stage The stage of the shader
* @param[in] path Path to the SPIR-V shader file
*/
bool addShader(ShaderStage stage, const std::filesystem::path &path);
/**
* Returns the shader program's shader of the specified shader.
* Needed for the transfer to the pipeline.
* @return Shader object consisting of buffer with shader code and shader stage enum
*/
const Shader &getShader(ShaderStage shaderStage) const;
* @brief Returns the shader of a specified stage from the program.
* Needed for the transfer to the pipeline.
*
* @param[in] stage The stage of the shader
* @return Shader object consisting of buffer with shader code and
* shader stage enum
*/
const Shader &getShader(ShaderStage stage) const;
bool existsShader(ShaderStage shaderStage) const;
/**
* @brief Returns whether a shader exists in the program for a
* specified shader stage.
*
* @param[in] stage The stage of the shader
* @return True, if a shader exists for the stage, else false
*/
bool existsShader(ShaderStage stage) const;
/**
* @brief Returns the vertex attachments for the program and its
* shader stages.
*
* @return Vertex attachments
*/
const std::vector<VertexAttachment> &getVertexAttachments() const;
size_t getPushConstantSize() const;
/**
* @brief Returns the size of the programs push constants.
*
* @return Size of push constants
*/
size_t getPushConstantsSize() const;
/**
* Returns the reflected descriptor sets/layouts/bindings in a map of maps.
* First uint32_t serves as descriptor SET id.
* Second uint32_t serves as the descriptor set's BINDING id.
* @return
* @brief Returns the reflected descriptor set bindings mapped via
* their descriptor set id.
*
* @return Reflected descriptor set bindings
*/
const std::unordered_map<uint32_t, std::unordered_map<uint32_t, DescriptorBinding>>& getReflectedDescriptors() const;
const std::unordered_map<uint32_t, DescriptorBindings>& getReflectedDescriptors() const;
private:
/**
* Called after successfully adding a shader to the program.
* @brief Called after successfully adding a shader to the program.
* Fills vertex input attachments and descriptor sets (if present).
* @param shaderStage the stage to reflect data from
*
* @param[in] shaderStage the stage to reflect data from
*/
void reflectShader(ShaderStage shaderStage);
......@@ -72,7 +102,7 @@ namespace vkcv {
// contains all vertex input attachments used in the vertex buffer
std::vector<VertexAttachment> m_VertexAttachments;
std::unordered_map<uint32_t, std::unordered_map<uint32_t, DescriptorBinding>> m_DescriptorSets;
size_t m_pushConstantSize = 0;
std::unordered_map<uint32_t, DescriptorBindings> m_DescriptorSets;
size_t m_pushConstantsSize = 0;
};
}
......@@ -59,9 +59,9 @@ namespace vkcv
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo({}, descriptorSetLayouts);
const size_t pushConstantSize = shaderProgram.getPushConstantSize();
vk::PushConstantRange pushConstantRange(vk::ShaderStageFlagBits::eCompute, 0, pushConstantSize);
if (pushConstantSize > 0) {
const size_t pushConstantsSize = shaderProgram.getPushConstantsSize();
vk::PushConstantRange pushConstantRange(vk::ShaderStageFlagBits::eCompute, 0, pushConstantsSize);
if (pushConstantsSize > 0) {
pipelineLayoutCreateInfo.setPushConstantRangeCount(1);
pipelineLayoutCreateInfo.setPPushConstantRanges(&pushConstantRange);
}
......
......@@ -365,9 +365,9 @@ namespace vkcv
const std::vector<vk::DescriptorSetLayout>& descriptorSetLayouts) {
static vk::PushConstantRange pushConstantRange;
const size_t pushConstantSize = config.m_ShaderProgram.getPushConstantSize();
const size_t pushConstantsSize = config.m_ShaderProgram.getPushConstantsSize();
pushConstantRange = vk::PushConstantRange(
vk::ShaderStageFlagBits::eAll, 0, pushConstantSize
vk::ShaderStageFlagBits::eAll, 0, pushConstantsSize
);
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo(
......@@ -376,7 +376,7 @@ namespace vkcv
(pushConstantRange)
);
if (pushConstantSize == 0) {
if (pushConstantsSize == 0) {
pipelineLayoutCreateInfo.pushConstantRangeCount = 0;
}
......
......@@ -76,32 +76,32 @@ namespace vkcv {
m_DescriptorSets{}
{}
bool ShaderProgram::addShader(ShaderStage shaderStage, const std::filesystem::path &shaderPath)
bool ShaderProgram::addShader(ShaderStage stage, const std::filesystem::path &path)
{
if(m_Shaders.find(shaderStage) != m_Shaders.end()) {
if(m_Shaders.find(stage) != m_Shaders.end()) {
vkcv_log(LogLevel::WARNING, "Overwriting existing shader stage");
}
const std::vector<char> shaderCode = readShaderCode(shaderPath);
const std::vector<char> shaderCode = readShaderCode(path);
if (shaderCode.empty()) {
return false;
} else {
Shader shader{shaderCode, shaderStage};
m_Shaders.insert(std::make_pair(shaderStage, shader));
reflectShader(shaderStage);
Shader shader{shaderCode, stage};
m_Shaders.insert(std::make_pair(stage, shader));
reflectShader(stage);
return true;
}
}
const Shader &ShaderProgram::getShader(ShaderStage shaderStage) const
const Shader &ShaderProgram::getShader(ShaderStage stage) const
{
return m_Shaders.at(shaderStage);
return m_Shaders.at(stage);
}
bool ShaderProgram::existsShader(ShaderStage shaderStage) const
bool ShaderProgram::existsShader(ShaderStage stage) const
{
if(m_Shaders.find(shaderStage) == m_Shaders.end())
if(m_Shaders.find(stage) == m_Shaders.end())
return false;
else
return true;
......@@ -346,7 +346,7 @@ namespace vkcv {
for (const auto &range : comp.get_active_buffer_ranges(pushConstantBuffer.id))
{
const size_t size = range.range + range.offset;
m_pushConstantSize = std::max(m_pushConstantSize, size);
m_pushConstantsSize = std::max(m_pushConstantsSize, size);
}
}
}
......@@ -361,8 +361,8 @@ namespace vkcv {
return m_DescriptorSets;
}
size_t ShaderProgram::getPushConstantSize() const
size_t ShaderProgram::getPushConstantsSize() const
{
return m_pushConstantSize;
return m_pushConstantsSize;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment