Fix static analysis warnings
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled

This commit is contained in:
2026-05-31 15:37:45 -07:00
parent 1c6f3f6690
commit 244b43e993
10 changed files with 47 additions and 26 deletions

View File

@@ -150,7 +150,7 @@ KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, const KR
VkVertexInputBindingDescription bindingDescription{}; VkVertexInputBindingDescription bindingDescription{};
bindingDescription.binding = 0; bindingDescription.binding = 0;
bindingDescription.stride = KRMesh::VertexSizeForAttributes(vertexAttributes); bindingDescription.stride = (uint32_t)KRMesh::VertexSizeForAttributes(vertexAttributes);
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
uint32_t vertexAttributeCount = 0; uint32_t vertexAttributeCount = 0;
@@ -164,7 +164,7 @@ KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, const KR
desc.binding = 0; desc.binding = 0;
desc.location = attribute_locations[location_attrib] - 1; desc.location = attribute_locations[location_attrib] - 1;
desc.format = KRMesh::AttributeVulkanFormat(mesh_attrib); desc.format = KRMesh::AttributeVulkanFormat(mesh_attrib);
desc.offset = KRMesh::AttributeOffset(mesh_attrib, vertexAttributes); desc.offset = (uint32_t)KRMesh::AttributeOffset(mesh_attrib, vertexAttributes);
} }
} }
@@ -533,8 +533,9 @@ bool KRPipeline::hasPushConstant(ShaderValue location) const
} }
void KRPipeline::setPushConstants(const std::vector<const KRReflectedObject*> objects) bool KRPipeline::setPushConstants(const std::vector<const KRReflectedObject*> objects)
{ {
bool success = true;
for (StageInfo& stageInfo : m_stages) { for (StageInfo& stageInfo : m_stages) {
PushConstantInfo& pushConstants = stageInfo.pushConstants; PushConstantInfo& pushConstants = stageInfo.pushConstants;
for (int i = 0; i < kPushConstantCount; i++) { for (int i = 0; i < kPushConstantCount; i++) {
@@ -549,11 +550,13 @@ void KRPipeline::setPushConstants(const std::vector<const KRReflectedObject*> ob
} }
} }
if(!found) { if(!found) {
success = false;
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Push constant not found: %s", getShaderValueName(i)); KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Push constant not found: %s", getShaderValueName(i));
} }
} }
} }
} }
return success;
} }
void KRPipeline::setPushConstant(ShaderValue location, float value) void KRPipeline::setPushConstant(ShaderValue location, float value)
@@ -637,7 +640,7 @@ void KRPipeline::updateDescriptorBinding()
// Vulkan Refactoring // Vulkan Refactoring
} }
void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matModel) bool KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matModel)
{ {
KRDirectionalLight* directionalLight = nullptr; KRDirectionalLight* directionalLight = nullptr;
if (ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_LIGHTS && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_GBUFFER && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_OPAQUE && ri.renderPass->getType() != RenderPassType::RENDER_PASS_SHADOWMAP) { if (ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_LIGHTS && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_GBUFFER && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_OPAQUE && ri.renderPass->getType() != RenderPassType::RENDER_PASS_SHADOWMAP) {
@@ -653,7 +656,7 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
ri.reflectedObjects.push_back(ri.viewport); ri.reflectedObjects.push_back(ri.viewport);
ri.reflectedObjects.push_back(&ri.camera->settings); ri.reflectedObjects.push_back(&ri.camera->settings);
setPushConstants(ri.reflectedObjects); bool success = setPushConstants(ri.reflectedObjects);
ri.reflectedObjects.pop_back(); ri.reflectedObjects.pop_back();
ri.reflectedObjects.pop_back(); ri.reflectedObjects.pop_back();
@@ -661,12 +664,18 @@ void KRPipeline::updatePushConstants(KRNode::RenderInfo& ri, const Matrix4& matM
setPushConstant(ShaderValue::absolute_time, getContext().getAbsoluteTime()); setPushConstant(ShaderValue::absolute_time, getContext().getAbsoluteTime());
if (!success) {
return false;
}
for (StageInfo& stageInfo : m_stages) { for (StageInfo& stageInfo : m_stages) {
PushConstantInfo& pushConstants = stageInfo.pushConstants; PushConstantInfo& pushConstants = stageInfo.pushConstants;
if (pushConstants.buffer) { if (pushConstants.buffer) {
vkCmdPushConstants(ri.commandBuffer, pushConstants.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, pushConstants.bufferSize, pushConstants.buffer); vkCmdPushConstants(ri.commandBuffer, pushConstants.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, pushConstants.bufferSize, pushConstants.buffer);
} }
} }
return true;
} }
bool KRPipeline::bind(KRNode::RenderInfo& ri, const Matrix4& matModel) bool KRPipeline::bind(KRNode::RenderInfo& ri, const Matrix4& matModel)
@@ -674,7 +683,9 @@ bool KRPipeline::bind(KRNode::RenderInfo& ri, const Matrix4& matModel)
updateDescriptorBinding(); updateDescriptorBinding();
updateDescriptorSets(); updateDescriptorSets();
bindDescriptorSets(ri.commandBuffer); bindDescriptorSets(ri.commandBuffer);
updatePushConstants(ri, matModel); if (!updatePushConstants(ri, matModel)) {
return false;
}
if (ri.pipeline != this) { if (ri.pipeline != this) {
vkCmdBindPipeline(ri.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline); vkCmdBindPipeline(ri.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline);

View File

@@ -221,7 +221,7 @@ public:
static const size_t kPushConstantCount = static_cast<size_t>(ShaderValue::NUM_SHADER_VALUES); static const size_t kPushConstantCount = static_cast<size_t>(ShaderValue::NUM_SHADER_VALUES);
void setPushConstants(const std::vector<const KRReflectedObject*> objects); bool setPushConstants(const std::vector<const KRReflectedObject*> objects);
bool hasPushConstant(ShaderValue location) const; bool hasPushConstant(ShaderValue location) const;
void setPushConstant(ShaderValue location, float value); void setPushConstant(ShaderValue location, float value);
void setPushConstant(ShaderValue location, int value); void setPushConstant(ShaderValue location, int value);
@@ -239,7 +239,7 @@ public:
private: private:
void updateDescriptorBinding(); void updateDescriptorBinding();
void updateDescriptorSets(); void updateDescriptorSets();
void updatePushConstants(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel); bool updatePushConstants(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel);
struct PushConstantInfo struct PushConstantInfo
{ {

View File

@@ -166,7 +166,9 @@ void KRNode::makeOrphan()
KRNode::~KRNode() KRNode::~KRNode()
{ {
while (m_firstChildNode != nullptr) { while (m_firstChildNode != nullptr) {
KRNode* nextChild = m_firstChildNode->m_nextNode;
delete m_firstChildNode; delete m_firstChildNode;
m_firstChildNode = nextChild;
} }
makeOrphan(); makeOrphan();

View File

@@ -743,14 +743,13 @@ kraken_stream_level KRMaterial::getStreamLevel()
return stream_level; return stream_level;
} }
void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, float lod_coverage) bool KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, float lod_coverage)
{ {
bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap; bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap;
Vector2 default_scale = Vector2::One(); Vector2 default_scale = Vector2::One();
Vector2 default_offset = Vector2::Zero(); Vector2 default_offset = Vector2::Zero();
bool bHasReflection = m_roughnessFactor > 0.f;
bool bDiffuseMap = m_baseColorMap.texture.isBound() && ri.camera->settings.bEnableDiffuseMap; bool bDiffuseMap = m_baseColorMap.texture.isBound() && ri.camera->settings.bEnableDiffuseMap;
bool bNormalMap = m_normalMap.texture.isBound() && ri.camera->settings.bEnableNormalMap; bool bNormalMap = m_normalMap.texture.isBound() && ri.camera->settings.bEnableNormalMap;
bool bSpecMap = false; bool bSpecMap = false;
@@ -845,9 +844,13 @@ void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_
// pShader->setImageBinding("reflectionTexture", m_reflection.texture.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); // pShader->setImageBinding("reflectionTexture", m_reflection.texture.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
} }
bool success = true;
ri.reflectedObjects.push_back(this); ri.reflectedObjects.push_back(this);
pShader->bind(ri, matModel); if (!pShader->bind(ri, matModel)) {
success = false;
}
ri.reflectedObjects.pop_back(); ri.reflectedObjects.pop_back();
return success;
} }
bool KRMaterial::getShaderValue(ShaderValue value, float* output) const bool KRMaterial::getShaderValue(ShaderValue value, float* output) const

View File

@@ -130,7 +130,7 @@ public:
bool isTransparent(); bool isTransparent();
void bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<hydra::Matrix4>& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, float lod_coverage = 0.0f); bool bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<hydra::Matrix4>& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, float lod_coverage = 0.0f);
bool needsVertexTangents(); bool needsVertexTangents();

View File

@@ -266,21 +266,27 @@ void KRMesh::render(KRNode::RenderInfo& ri, const std::string& object_name, cons
switch (pMaterial->getAlphaMode()) { switch (pMaterial->getAlphaMode()) {
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5 case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage); if (pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
{
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage); renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
}
break; break;
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLEND: // Blended Alpha case KRMaterial::KRMATERIAL_ALPHA_MODE_BLEND: // Blended Alpha
if (pMaterial->m_doubleSided) { if (pMaterial->m_doubleSided) {
// Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces. // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
// //
// Render back faces before front faces // Render back faces before front faces
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullFront, bones, bone_bind_poses, matModel, pLightMap, lod_coverage); if (pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullFront, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
{
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage); renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
} }
}
// Render front faces // Render front faces
pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage); if (pMaterial->bind(ri, getModelFormat(), getVertexAttributes(), CullMode::kCullBack, bones, bone_bind_poses, matModel, pLightMap, lod_coverage))
{
renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage); renderSubmesh(ri.commandBuffer, iSubmesh, ri.renderPass, object_name, pMaterial->getName(), lod_coverage);
}
break; break;
} }
} }

View File

@@ -298,7 +298,7 @@ bool KRShaderManager::compileAll(KRBundle* outputBundle, KRUnknown* logResource)
} }
sourceName = source->getName() + "." + source->getExtension(); sourceName = source->getName() + "." + source->getExtension();
sourceText[0] = (char*)source->getData()->getStart(); sourceText[0] = (char*)source->getData()->getStart();
sourceLen[0] = source->getData()->getSize(); sourceLen[0] = (int)source->getData()->getSize();
sourceNameStr[0] = sourceName.c_str(); sourceNameStr[0] = sourceName.c_str();
shader.setStringsWithLengthsAndNames(sourceText, sourceLen, sourceNameStr, 1); shader.setStringsWithLengthsAndNames(sourceText, sourceLen, sourceNameStr, 1);
//shader.setStrings(&sourceStr, 1); //shader.setStrings(&sourceStr, 1);

View File

@@ -57,7 +57,7 @@ bool KRTexture2D::createGPUTexture(int targetLod)
void* buffer = malloc(bufferSize); void* buffer = malloc(bufferSize);
if (!getLodData(buffer, targetLod)) { if (!getLodData(buffer, targetLod)) {
delete buffer; free(buffer);
return false; return false;
} }
@@ -130,7 +130,7 @@ bool KRTexture2D::createGPUTexture(int targetLod)
device.streamUpload((void*)buffer, bufferSize, texture.image, regions.data(), regions.size()); device.streamUpload((void*)buffer, bufferSize, texture.image, regions.data(), regions.size());
} }
delete buffer; free(buffer);
if (success) { if (success) {
m_new_lod = targetLod; m_new_lod = targetLod;

View File

@@ -152,7 +152,8 @@ bool KRTextureCube::createGPUTexture(int lod)
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
if (buffers[i]) { if (buffers[i]) {
delete buffers[i]; free(buffers[i]);
buffers[i] = nullptr;
} }
} }

View File

@@ -130,8 +130,6 @@ bool KRTextureTGA::getLodData(void* buffer, int lod)
return false; // Mapped colors not supported return false; // Mapped colors not supported
} }
Vector3i dimensions = { pHeader->width, pHeader->height, 1 };
switch (pHeader->imagetype) { switch (pHeader->imagetype) {
case 2: // rgb case 2: // rgb
switch (pHeader->bitsperpixel) { switch (pHeader->bitsperpixel) {