From 29d928ca293164bfdb9a839eb9daa122c68e6b9d Mon Sep 17 00:00:00 2001 From: kearwood Date: Fri, 5 Aug 2022 23:44:46 -0700 Subject: [PATCH] Eliminated static_cast from KRPipeline::hasUniform KRPipeline::setUniform now updates push constants for all stages --- kraken/KRPipeline.cpp | 69 ++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/kraken/KRPipeline.cpp b/kraken/KRPipeline.cpp index 67e223b..f1c9fe3 100644 --- a/kraken/KRPipeline.cpp +++ b/kraken/KRPipeline.cpp @@ -475,67 +475,82 @@ KRPipeline::~KRPipeline() { } } -void KRPipeline::setUniform(Uniform location, float value) -{ - if (m_pushConstants[0].size[static_cast(location)] == sizeof(value)) { - float* constant = (float*)(m_pushConstantBuffer + m_pushConstants[0].offset[static_cast(location)]); - *constant = value; - } -} - bool KRPipeline::hasUniform(Uniform location) const { - for (int i = 0; i < static_cast(ShaderStages::shaderStageCount); i++) { - if (m_pushConstants[i].size[static_cast(location)]) { + for (const PushConstantStageInfo& stageConstants : m_pushConstants) { + if (stageConstants.size[static_cast(location)]) { return true; } } return false; } +void KRPipeline::setUniform(Uniform location, float value) +{ + for (PushConstantStageInfo& stageConstants : m_pushConstants) { + if (stageConstants.size[static_cast(location)] == sizeof(value)) { + float* constant = (float*)(m_pushConstantBuffer + stageConstants.offset[static_cast(location)]); + *constant = value; + } + } +} + + void KRPipeline::setUniform(Uniform location, int value) { - if (m_pushConstants[0].size[static_cast(location)] == sizeof(value)) { - int* constant = (int*)(m_pushConstantBuffer + m_pushConstants[0].offset[static_cast(location)]); - *constant = value; + for (PushConstantStageInfo& stageConstants : m_pushConstants) { + if (stageConstants.size[static_cast(location)] == sizeof(value)) { + int* constant = (int*)(m_pushConstantBuffer + stageConstants.offset[static_cast(location)]); + *constant = value; + } } } void KRPipeline::setUniform(Uniform location, const Vector2 &value) { - if (m_pushConstants[0].size[static_cast(location)] == sizeof(value)) { - Vector2* constant = (Vector2*)(m_pushConstantBuffer + m_pushConstants[0].offset[static_cast(location)]); - *constant = value; + for (PushConstantStageInfo& stageConstants : m_pushConstants) { + if (stageConstants.size[static_cast(location)] == sizeof(value)) { + Vector2* constant = (Vector2*)(m_pushConstantBuffer + stageConstants.offset[static_cast(location)]); + *constant = value; + } } } void KRPipeline::setUniform(Uniform location, const Vector3 &value) { - if (m_pushConstants[0].size[static_cast(location)] == sizeof(value)) { - Vector3* constant = (Vector3*)(m_pushConstantBuffer + m_pushConstants[0].offset[static_cast(location)]); - *constant = value; + for (PushConstantStageInfo& stageConstants : m_pushConstants) { + if (stageConstants.size[static_cast(location)] == sizeof(value)) { + Vector3* constant = (Vector3*)(m_pushConstantBuffer + stageConstants.offset[static_cast(location)]); + *constant = value; + } } } void KRPipeline::setUniform(Uniform location, const Vector4 &value) { - if (m_pushConstants[0].size[static_cast(location)] == sizeof(value)) { - Vector4* constant = (Vector4*)(m_pushConstantBuffer + m_pushConstants[0].offset[static_cast(location)]); - *constant = value; + for (PushConstantStageInfo& stageConstants : m_pushConstants) { + if (stageConstants.size[static_cast(location)] == sizeof(value)) { + Vector4* constant = (Vector4*)(m_pushConstantBuffer + stageConstants.offset[static_cast(location)]); + *constant = value; + } } } void KRPipeline::setUniform(Uniform location, const Matrix4 &value) { - if (m_pushConstants[0].size[static_cast(location)] == sizeof(value)) { - Matrix4* constant = (Matrix4*)(m_pushConstantBuffer + m_pushConstants[0].offset[static_cast(location)]); - *constant = value; + for (PushConstantStageInfo& stageConstants : m_pushConstants) { + if (stageConstants.size[static_cast(location)] == sizeof(value)) { + Matrix4* constant = (Matrix4*)(m_pushConstantBuffer + m_pushConstants[0].offset[static_cast(location)]); + *constant = value; + } } } void KRPipeline::setUniform(Uniform location, const Matrix4* value, const size_t count) { - // TODO - Vulkan refactoring - // GLDEBUG(glUniformMatrix4fv(pShader->m_pushConstants[0].offset[KRPipeline::Uniform::bone_transforms], (GLsizei)bones.size(), GL_FALSE, bone_mats)); + for (PushConstantStageInfo& stageConstants : m_pushConstants) { + // TODO - Vulkan refactoring + // GLDEBUG(glUniformMatrix4fv(pShader->m_pushConstants[0].offset[KRPipeline::Uniform::bone_transforms], (GLsizei)bones.size(), GL_FALSE, bone_mats)); + } } bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector *point_lights, const std::vector *directional_lights, const std::vector *spot_lights, const KRNode::RenderPass &renderPass)