push constants

This commit is contained in:
Gregory Wells
2025-06-17 15:40:47 -04:00
parent e4e182610a
commit 309ce8cd74
8 changed files with 39 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
#include "pipelines/graphics_pipeline/vulkan_graphics_pipeline.h"
#include "buffers/vulkan_buffer.h"
#include "uniforms/vulkan_uniform.h"
#include "shader_module/vulkan_shader_module.h"
void gnCommandBeginRenderPassFn(gnCommandBuffer buffer, struct gnRenderPassInfo_t passInfo) {
VkClearValue* values = malloc(sizeof(VkClearValue) * passInfo.clearValueCount);
@@ -83,3 +84,14 @@ void gnCommandBindUniformFn(gnCommandBufferHandle buffer, gnUniform uniform, uin
&uniform->uniform->set, 0, NULL
);
}
void gnCommandPushConstantFn(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data) {
vkCmdPushConstants(
buffer->commandBuffer->buffer,
buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->pipelineLayout,
vkGryphnShaderModuleStage(layout.stage),
layout.offset,
layout.size,
data
);
}

View File

@@ -241,12 +241,21 @@ gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline graphicsPipeline, gnD
graphicsPipeline->graphicsPipeline->sets = malloc(sizeof(VkDescriptorSetLayout) * info.uniformLayout.setCount);
for (int i = 0; i < info.uniformLayout.setCount; i++) graphicsPipeline->graphicsPipeline->sets[i] = vkGryphnCreateSetLayouts(&info.uniformLayout.sets[i], device->outputDevice->device);
graphicsPipeline->graphicsPipeline->ranges = malloc(sizeof(VkPushConstantRange) * info.uniformLayout.pushConstantCount);
for (int i = 0; i < info.uniformLayout.pushConstantCount; i++) {
graphicsPipeline->graphicsPipeline->ranges[i] = (VkPushConstantRange) {
.offset = info.uniformLayout.pushConstants[i].offset,
.size = info.uniformLayout.pushConstants[i].size,
.stageFlags = vkGryphnShaderModuleStage(info.uniformLayout.pushConstants[i].stage)
};
}
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.setLayoutCount = graphicsPipeline->graphicsPipeline->setCount,
pipelineLayoutInfo.pSetLayouts = graphicsPipeline->graphicsPipeline->sets,
pipelineLayoutInfo.pushConstantRangeCount = 0,
pipelineLayoutInfo.pPushConstantRanges = NULL
pipelineLayoutInfo.pushConstantRangeCount = info.uniformLayout.pushConstantCount,
pipelineLayoutInfo.pPushConstantRanges = graphicsPipeline->graphicsPipeline->ranges
};
if (vkCreatePipelineLayout(device->outputDevice->device, &pipelineLayoutInfo, NULL, &graphicsPipeline->graphicsPipeline->pipelineLayout) != VK_SUCCESS)
@@ -286,6 +295,7 @@ void gnDestroyGraphicsPipelineFn(struct gnGraphicsPipeline_t *graphicsPipeline)
free(graphicsPipeline->graphicsPipeline->dynamicStates);
free(graphicsPipeline->graphicsPipeline->bindingDescriptions);
free(graphicsPipeline->graphicsPipeline->attributeDescriptions);
free(graphicsPipeline->graphicsPipeline->ranges);
for (int i = 0; i < graphicsPipeline->graphicsPipeline->setCount; i++)
vkDestroyDescriptorSetLayout(graphicsPipeline->device->outputDevice->device, graphicsPipeline->graphicsPipeline->sets[i], NULL);
free(graphicsPipeline->graphicsPipeline->modules);

View File

@@ -31,4 +31,5 @@ typedef struct gnPlatformGraphicsPipeline_t {
VkVertexInputBindingDescription* bindingDescriptions;
VkVertexInputAttributeDescription* attributeDescriptions;
VkPipelineShaderStageCreateInfo* modules;
VkPushConstantRange* ranges;
} gnPlatformGraphicsPipeline;