Mercurial > games > semicongine
diff semiconginev2/rendering/renderer.nim @ 1253:c4f98eb4bb05
fix: a few things
author | sam <sam@basx.dev> |
---|---|
date | Fri, 26 Jul 2024 23:39:24 +0700 |
parents | 01e9f41d35b1 |
children | b0f4c8ccd49a |
line wrap: on
line diff
--- a/semiconginev2/rendering/renderer.nim Fri Jul 26 23:04:01 2024 +0700 +++ b/semiconginev2/rendering/renderer.nim Fri Jul 26 23:39:24 2024 +0700 @@ -670,6 +670,16 @@ ) = Render(commandBuffer, pipeline, mesh, EMPTY()) +proc assertValidPushConstantType(TShader, TPushConstant: typedesc) = + assert sizeof(TPushConstant) <= PUSH_CONSTANT_SIZE, "Push constant values must be <= 128 bytes" + var foundPushConstant = false + for fieldname, fieldvalue in default(TShader).fieldPairs(): + when hasCustomPragma(fieldvalue, PushConstantAttribute): + assert typeof(fieldvalue) is TPushConstant, "Provided push constant has not same type as declared in shader" + assert foundPushConstant == false, "More than on push constant found in shader" + foundPushConstant = true + assert foundPushConstant == true, "No push constant found in shader" + proc RenderWithPushConstant*[TShader, TMesh, TInstance, TPushConstant]( commandBuffer: VkCommandBuffer, pipeline: Pipeline[TShader], @@ -677,12 +687,13 @@ instances: TInstance, pushConstant: TPushConstant, ) = + static: assertValidPushConstantType(TShader, TPushConstant) vkCmdPushConstants( commandBuffer = commandBuffer, layout = pipeline.layout, stageFlags = VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS), offset = 0, - size = 128, + size = PUSH_CONSTANT_SIZE, pValues = addr(pushConstant) ); Render(commandBuffer, pipeline, mesh, instances) @@ -692,12 +703,13 @@ mesh: TMesh, pushConstant: TPushConstant, ) = + static: assertValidPushConstantType(TShader, TPushConstant) vkCmdPushConstants( commandBuffer = commandBuffer, layout = pipeline.layout, stageFlags = VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS), offset = 0, - size = 128, + size = PUSH_CONSTANT_SIZE, pValues = addr(pushConstant) ); Render(commandBuffer, pipeline, mesh, EMPTY())