Set default size for pipelines since they dynamically set the size anyway, and created structs to transition to ObjectPipeline which will do the compute->offscreen->onscreen phase entirely in the GPU based on object buffers(compute generates draw call buffer and object id<->gl_InstanceId map based on object buffer, offscreen/onscreen use indirect draw call + object id<->gl_InstanceId map + object buffer to draw)

main
noah metz 2024-01-16 20:58:21 -07:00
parent 82ece9e038
commit 79657c5db0
1 changed files with 91 additions and 10 deletions

@ -83,6 +83,76 @@ typedef struct GraphicsPipelineInfoStruct {
VkPipelineShaderStageCreateInfo* shader_stages; VkPipelineShaderStageCreateInfo* shader_stages;
} GraphicsPipelineInfo; } GraphicsPipelineInfo;
typedef struct ComputePCStruct {
VkDeviceAddress object_buffer;
VkDeviceAddress draw_arg_buffer;
VkDeviceAddress object_id_buffer;
} ComputePC;
typedef struct OffscreenPCStruct {
VkDeviceAddress object_buffer;
VkDeviceAddress object_id_buffer;
} OffscreenPC;
typedef struct OnscreenPCStruct {
VkDeviceAddress object_buffer;
VkDeviceAddress object_id_buffer;
} OnscreenPC;
typedef struct InvalidChainStruct {
uint32_t index;
struct InvalidChainStruct* next;
} InvalidChain;
typedef struct ObjectPipelineStruct {
VkDescriptorPool descriptor_pool;
VkDescriptorSet compute_descriptors;
VkDescriptorSet offscreen_descriptors;
VkDescriptorSet onscreen_descriptors;
GPUBuffer mesh_buffer;
GPUBuffer vertex_buffer;
GPUBuffer index_buffer;
GPUBuffer object_buffer;
VkPipeline compute_pipeline;
VkPipeline offscreen_pipeline;
VkPipeline onscreen_pipeline;
// Per frame in flight objects
VkCommandBuffer* compute_command_buffers;
VkCommandBuffer* offscreen_command_buffers;
VkCommandBuffer* onscreen_command_buffers;
InvalidChain** invalid_objects;
GPUBuffer* object_buffers;
GPUBuffer* counter_buffers;
GPUBuffer* draw_arg_buffers;
GPUBuffer* object_id_buffers;
} ObjectPipeline;
typedef struct ObjectPipelineInfoStruct {
VkDescriptorSetLayout set_layout;
VkPipelineVertexInputStateCreateInfo input_info;
uint32_t shader_stages_count;
VkPipelineShaderStageCreateInfo* shader_stages;
} ObjectPipelineInfo;
typedef struct RenderInfoStruct {
uint32_t max_frames_in_flight;
VkRenderPass offscreen_render_pass;
VkDescriptorSetLayout offscreen_scene_layout;
VkRenderPass onscreen_render_pass;
VkDescriptorSetLayout onscreen_scene_layout;
} RenderInfo;
typedef struct GraphicsPipelineStruct { typedef struct GraphicsPipelineStruct {
uint32_t max_frames_in_flight; uint32_t max_frames_in_flight;
uint32_t max_objects; uint32_t max_objects;
@ -1687,9 +1757,17 @@ VkResult create_texture_set(VkDevice device, VkDescriptorSetLayout layout, uint3
return VK_SUCCESS; return VK_SUCCESS;
} }
VkResult create_object_pipeline(
VkDevice device,
RenderInfo render_info,
ObjectPipelineInfo pipeline_info,
ObjectPipeline* out
) {
return VK_SUCCESS;
}
VkResult create_graphics_pipeline( VkResult create_graphics_pipeline(
VkDevice device, VkDevice device,
VkExtent2D extent,
VkRenderPass draw_render_pass, VkRenderPass draw_render_pass,
VkRenderPass offscreen_render_pass, VkRenderPass offscreen_render_pass,
GraphicsPipelineInfo pipeline_info, GraphicsPipelineInfo pipeline_info,
@ -1760,8 +1838,8 @@ VkResult create_graphics_pipeline(
VkViewport viewport = { VkViewport viewport = {
.x = 0.0f, .x = 0.0f,
.y = 0.0f, .y = 0.0f,
.width = (float)(extent.width), .width = (float)(100),
.height = (float)(extent.height), .height = (float)(100),
.minDepth = 0.0f, .minDepth = 0.0f,
.maxDepth = 1.0f, .maxDepth = 1.0f,
}; };
@ -1771,7 +1849,10 @@ VkResult create_graphics_pipeline(
.x = 0, .x = 0,
.y = 0, .y = 0,
}, },
.extent = extent, .extent = {
.width = 100,
.height = 100,
},
}; };
VkPipelineViewportStateCreateInfo viewport_state = { VkPipelineViewportStateCreateInfo viewport_state = {
@ -1912,7 +1993,7 @@ VkResult create_graphics_pipeline(
return VK_SUCCESS; return VK_SUCCESS;
} }
VkResult create_simple_mesh_pipeline(VkDevice device, VkExtent2D extent, VkRenderPass render_pass, VkRenderPass offscreen_render_pass, VkDescriptorSetLayout scene_layout, uint32_t max_frames_in_flight, GraphicsPipeline* out) { VkResult create_simple_mesh_pipeline(VkDevice device, VkRenderPass render_pass, VkRenderPass offscreen_render_pass, VkDescriptorSetLayout scene_layout, uint32_t max_frames_in_flight, GraphicsPipeline* out) {
if(out == NULL) { if(out == NULL) {
return VK_ERROR_VALIDATION_FAILED_EXT; return VK_ERROR_VALIDATION_FAILED_EXT;
} }
@ -1973,10 +2054,10 @@ VkResult create_simple_mesh_pipeline(VkDevice device, VkExtent2D extent, VkRende
.input_info = input_info, .input_info = input_info,
}; };
return create_graphics_pipeline(device, extent, render_pass, offscreen_render_pass, pipeline_info, max_frames_in_flight, out); return create_graphics_pipeline(device, render_pass, offscreen_render_pass, pipeline_info, max_frames_in_flight, out);
} }
VkResult create_texture_mesh_pipeline(VkDevice device, VkExtent2D extent, VkRenderPass render_pass, VkRenderPass offscreen_render_pass, VkDescriptorSetLayout scene_layout, uint32_t max_frames_in_flight, TextureSet* texture_set, GraphicsPipeline* out) { VkResult create_texture_mesh_pipeline(VkDevice device, VkRenderPass render_pass, VkRenderPass offscreen_render_pass, VkDescriptorSetLayout scene_layout, uint32_t max_frames_in_flight, TextureSet* texture_set, GraphicsPipeline* out) {
if(out == NULL || texture_set == NULL) { if(out == NULL || texture_set == NULL) {
return VK_ERROR_VALIDATION_FAILED_EXT; return VK_ERROR_VALIDATION_FAILED_EXT;
} }
@ -2079,7 +2160,7 @@ VkResult create_texture_mesh_pipeline(VkDevice device, VkExtent2D extent, VkRend
.input_info = input_info, .input_info = input_info,
}; };
result = create_graphics_pipeline(device, extent, render_pass, offscreen_render_pass, pipeline_info, max_frames_in_flight, out); result = create_graphics_pipeline(device, render_pass, offscreen_render_pass, pipeline_info, max_frames_in_flight, out);
if(result != VK_SUCCESS) { if(result != VK_SUCCESS) {
return result; return result;
} }
@ -3191,7 +3272,7 @@ void main_loop(PlyMesh ply_mesh, GLFWwindow* window, VulkanContext* context) {
GraphicsPipeline simple_mesh_pipeline = {0}; GraphicsPipeline simple_mesh_pipeline = {0};
GraphicsPipeline texture_mesh_pipeline = {0}; GraphicsPipeline texture_mesh_pipeline = {0};
VkResult result = create_simple_mesh_pipeline(context->device, context->swapchain_extent, context->render_pass, context->g_renderpass, scene.descriptor_layout, context->max_frames_in_flight, &simple_mesh_pipeline); VkResult result = create_simple_mesh_pipeline(context->device, context->render_pass, context->g_renderpass, scene.descriptor_layout, context->max_frames_in_flight, &simple_mesh_pipeline);
if(result != VK_SUCCESS) { if(result != VK_SUCCESS) {
fprintf(stderr, "failed to create simple mesh material: %s\n", string_VkResult(result)); fprintf(stderr, "failed to create simple mesh material: %s\n", string_VkResult(result));
return; return;
@ -3204,7 +3285,7 @@ void main_loop(PlyMesh ply_mesh, GLFWwindow* window, VulkanContext* context) {
} }
TextureSet texture_set = {0}; TextureSet texture_set = {0};
result = create_texture_mesh_pipeline(context->device, context->swapchain_extent, context->render_pass, context->g_renderpass, scene.descriptor_layout, context->max_frames_in_flight, &texture_set, &texture_mesh_pipeline); result = create_texture_mesh_pipeline(context->device, context->render_pass, context->g_renderpass, scene.descriptor_layout, context->max_frames_in_flight, &texture_set, &texture_mesh_pipeline);
if(result != VK_SUCCESS) { if(result != VK_SUCCESS) {
fprintf(stderr, "failed to create texture mesh material\n"); fprintf(stderr, "failed to create texture mesh material\n");
return; return;