Changed to dynamic rendering since it's in vulkan 1.3

main
noah metz 2026-07-12 15:22:31 -06:00
parent 099b4cd13c
commit b9f6b69201
7 changed files with 174 additions and 227 deletions

2
.gitignore vendored

@ -37,3 +37,5 @@ editor
.DS_Store
client/test/test_*
*.d

@ -1,5 +1,5 @@
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
CFLAGS = -I $(ROOT_DIR)/include -I/usr/local/include -O0 -g -Wall -Wextra
CFLAGS = -I $(ROOT_DIR)/include -I/usr/local/include -O0 -g -Wall -Wextra -MMD -MP
LDFLAGS = -lfreetype -lz -lglfw -lvulkan -ldl -Xlinker -rpath -Xlinker /opt/homebrew/lib
ENGINE_SOURCES = src/engine.c src/draw.c src/ui.c src/gpu.c src/hex.c src/hsv.c lib/spng.c lib/vma.cpp
@ -11,6 +11,9 @@ APP_OBJECTS = $(addsuffix .o, $(basename $(APP_SOURCES)))
EDITOR_OBJECTS = $(addsuffix .o, $(basename $(EDITOR_SOURCES)))
TEST_OBJECTS = $(addsuffix .o, $(basename $(TEST_SOURCES)))
ALL_OBJECTS = $(sort $(APP_OBJECTS) $(EDITOR_OBJECTS) $(TEST_OBJECTS))
DEP_FILES = $(ALL_OBJECTS:.o=.d)
VERT_SPV = $(addsuffix .vert.spv, $(basename $(wildcard shader/*.vert)))
FRAG_SPV = $(addsuffix .frag.spv, $(basename $(wildcard shader/*.frag)))
COMP_SPV = $(addsuffix .comp.spv, $(basename $(wildcard shader/*.comp)))
@ -24,6 +27,7 @@ ifeq ($(UNAME_S),Linux)
endif
ifeq ($(UNAME_S),Darwin)
export MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1
export VK_ICD_FILENAMES=$(shell brew --prefix molten-vk)/etc/vulkan/icd.d/MoltenVK_icd.json
DSYM = dsymutil
GDB = lldb
EXTRA_DEBUG_REQUIREMENTS = roleplay.dSYM
@ -59,9 +63,8 @@ test: test/test_hsv
clean:
rm -f $(SPV_FILES)
rm -f $(APP_OBJECTS)
rm -f $(TEST_OBJECTS)
rm -f roleplay
rm -f $(ALL_OBJECTS) $(DEP_FILES)
rm -f roleplay editor test/test_hsv
rm -rf $(EXTRA_DEBUG_REQUIREMENTS)
clean_compdb:
@ -92,3 +95,5 @@ debug: roleplay $(EXTRA_DEBUG_REQUIREMENTS) $(SPV_FILES)
%.comp.spv: %.comp
glslc -o $@ $<
-include $(DEP_FILES)

@ -136,8 +136,6 @@ typedef struct RenderContextStruct {
uint32_t swapchain_image_count;
VkImage* swapchain_images;
VkImageView* swapchain_image_views;
VkFramebuffer* swapchain_framebuffers;
VkFormat depth_format;
VkImageView depth_image_view;
VkImage depth_image;
@ -147,11 +145,7 @@ typedef struct RenderContextStruct {
VkCommandPool graphics_pool;
VkCommandPool transfer_pool;
VkRenderPass render_pass;
VkCommandBuffer* swapchain_command_buffers;
uint64_t swapchain_command_buffer_record_id;
uint64_t* swapchain_command_buffer_record_ids;
VkCommandBuffer* frame_command_buffers;
FrameContext frame[MAX_FRAMES_IN_FLIGHT];

@ -175,7 +175,7 @@ VkResult draw_frame(
return result;
}
VkCommandBuffer command_buffer = context->swapchain_command_buffers[image_index];
VkCommandBuffer command_buffer = context->frame_command_buffers[context->current_frame];
VK_RESULT(vkResetCommandBuffer(command_buffer, 0));
VK_RESULT(vkBeginCommandBuffer(command_buffer, &begin_info));
@ -192,23 +192,105 @@ VkResult draw_frame(
};
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
VkClearValue clear_values[2] = {{.color={{0.0f, 0.0f, 0.0f, 0.0f}}}, {.depthStencil={1.0f, 0.0f}}};
VkRenderPassBeginInfo render_pass_begin = {
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
.renderPass = context->render_pass,
.framebuffer = context->swapchain_framebuffers[image_index],
.renderArea.offset = {0, 0},
.renderArea.extent = context->swapchain_extent,
.clearValueCount = 2,
.pClearValues = clear_values,
VkImageSubresourceRange color_range = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.levelCount = 1,
.layerCount = 1,
};
vkCmdBeginRenderPass(command_buffer, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE);
VkImageMemoryBarrier acquire_barrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = context->swapchain_images[image_index],
.subresourceRange = color_range,
};
vkCmdPipelineBarrier(command_buffer,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
0, 0, NULL, 0, NULL, 1, &acquire_barrier);
VkRenderingAttachmentInfo color_attachment = {
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
.imageView = context->swapchain_image_views[image_index],
.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.clearValue = {.color = {{0.0f, 0.0f, 0.0f, 0.0f}}},
};
VkRenderingAttachmentInfo depth_attachment = {
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
.imageView = context->depth_image_view,
.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
.clearValue = {.depthStencil = {1.0f, 0}},
};
VkRenderingInfo hex_rendering = {
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
.renderArea = {{0, 0}, context->swapchain_extent},
.layerCount = 1,
.colorAttachmentCount = 1,
.pColorAttachments = &color_attachment,
.pDepthAttachment = &depth_attachment,
};
vkCmdBeginRendering(command_buffer, &hex_rendering);
record_hex_draw(command_buffer, hex, time, context->current_frame);
vkCmdNextSubpass(command_buffer, VK_SUBPASS_CONTENTS_INLINE);
vkCmdEndRendering(command_buffer);
VkImageMemoryBarrier mid_barrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = context->swapchain_images[image_index],
.subresourceRange = color_range,
};
vkCmdPipelineBarrier(command_buffer,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
0, 0, NULL, 0, NULL, 1, &mid_barrier);
VkRenderingAttachmentInfo ui_color_attachment = {
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,
.imageView = context->swapchain_image_views[image_index],
.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
};
VkRenderingInfo ui_rendering = {
.sType = VK_STRUCTURE_TYPE_RENDERING_INFO,
.renderArea = {{0, 0}, context->swapchain_extent},
.layerCount = 1,
.colorAttachmentCount = 1,
.pColorAttachments = &ui_color_attachment,
};
vkCmdBeginRendering(command_buffer, &ui_rendering);
record_ui_draw(command_buffer, ui, time, context->current_frame);
vkCmdEndRenderPass(command_buffer);
vkCmdEndRendering(command_buffer);
VkImageMemoryBarrier present_barrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstAccessMask = 0,
.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = context->swapchain_images[image_index],
.subresourceRange = color_range,
};
vkCmdPipelineBarrier(command_buffer,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0, 0, NULL, 0, NULL, 1, &present_barrier);
VK_RESULT(vkEndCommandBuffer(command_buffer));
VkPipelineStageFlags wait_stages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT};
@ -229,7 +311,7 @@ VkResult draw_frame(
.pWaitSemaphores = wait_semaphores,
.pWaitDstStageMask = wait_stages,
.commandBufferCount = 1,
.pCommandBuffers = &context->swapchain_command_buffers[image_index],
.pCommandBuffers = &context->frame_command_buffers[context->current_frame],
.signalSemaphoreCount = sizeof(signal_semaphores)/sizeof(VkSemaphore),
.pSignalSemaphores = signal_semaphores,
.pNext = &timeline_info,

@ -29,6 +29,7 @@ const char * device_extensions[] = {
"VK_KHR_portability_subset",
#endif
VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME,
VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME,
@ -149,7 +150,7 @@ VkResult create_instance(VkInstance* instance) {
.applicationVersion = VK_MAKE_VERSION(0, 0, 1),
.pEngineName = "roleplay",
.engineVersion = VK_MAKE_VERSION(0, 0, 1),
.apiVersion = VK_API_VERSION_1_2,
.apiVersion = VK_API_VERSION_1_3,
};
uint32_t glfwExtensionCount = 0;
@ -391,9 +392,15 @@ VkResult create_logical_device(
queue_create_info[1].pQueuePriorities = &default_queue_priority;
}
VkPhysicalDeviceDynamicRenderingFeatures dynamic_rendering = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES,
.dynamicRendering = VK_TRUE,
};
VkPhysicalDeviceSynchronization2FeaturesKHR sync2 = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SYNCHRONIZATION_2_FEATURES_KHR,
.synchronization2 = VK_TRUE,
.pNext = &dynamic_rendering,
};
VkPhysicalDeviceVulkan12Features features_12 = {
@ -442,7 +449,7 @@ VkResult create_memory_allocator(
VkDevice device,
VmaAllocator* allocator) {
VmaAllocatorCreateInfo allocator_create_info = {
.vulkanApiVersion = VK_API_VERSION_1_2,
.vulkanApiVersion = VK_API_VERSION_1_3,
.instance = instance,
.physicalDevice = physical_device,
.device = device,
@ -652,153 +659,6 @@ VkResult find_depth_format(
return VK_ERROR_VALIDATION_FAILED_EXT;
}
VkResult create_render_pass(
VkDevice device,
VkSurfaceFormatKHR format,
VkFormat depth_format,
VkRenderPass* render_pass) {
VkAttachmentDescription attachments[] = {
{
.format = format.format,
.samples = VK_SAMPLE_COUNT_1_BIT,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
},
{
.format = depth_format,
.samples = VK_SAMPLE_COUNT_1_BIT,
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
},
};
VkAttachmentReference color_attachment_refs[] = {
{
.attachment = 0,
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
},
};
VkAttachmentReference depth_attachment_ref = {
.attachment = 1,
.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
};
// Create a subpass with the color and depth attachments
VkSubpassDescription subpasses[] = {
{
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
.colorAttachmentCount = sizeof(color_attachment_refs)/sizeof(VkAttachmentReference),
.pColorAttachments = color_attachment_refs,
.pDepthStencilAttachment = &depth_attachment_ref,
},
{
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
.colorAttachmentCount = sizeof(color_attachment_refs)/sizeof(VkAttachmentReference),
.pColorAttachments = color_attachment_refs,
},
};
// This basically says "make sure nothing else is writing to the depth_stencil or the color attachment during the pipeline
VkSubpassDependency dependencies[] = {
{
.srcSubpass = VK_SUBPASS_EXTERNAL,
.dstSubpass = 1,
.srcStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT,
.dstStageMask = VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT,
.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
.dstAccessMask = VK_ACCESS_INDIRECT_COMMAND_READ_BIT,
},
{
.srcSubpass = VK_SUBPASS_EXTERNAL,
.dstSubpass = 0,
.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
},
{
.srcSubpass = VK_SUBPASS_EXTERNAL,
.dstSubpass = 0,
.srcStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
.dstStageMask = VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
},
{
.srcSubpass = 0,
.dstSubpass = 1,
.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
},
};
VkRenderPassCreateInfo render_info = {
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
.attachmentCount = sizeof(attachments)/sizeof(VkAttachmentDescription),
.pAttachments = attachments,
.subpassCount = sizeof(subpasses)/sizeof(VkSubpassDescription),
.pSubpasses = subpasses,
.dependencyCount = sizeof(dependencies)/sizeof(VkSubpassDependency),
.pDependencies = dependencies,
};
VkResult result;
VK_RESULT(vkCreateRenderPass(device, &render_info, 0, render_pass));
return VK_SUCCESS;
}
VkResult create_swapchain_framebuffers(
VkDevice device,
uint32_t image_count,
VkImageView* image_views,
VkImageView depth_image_view,
VkRenderPass render_pass,
VkExtent2D extent,
VkFramebuffer** framebuffers) {
*framebuffers = malloc(sizeof(VkFramebuffer)*image_count);
if(*framebuffers == 0) {
return 0;
}
VkFramebuffer* framebuffer_ptr = *framebuffers;
for(uint32_t i = 0; i < image_count; i++) {
VkImageView attachments[] = {
image_views[i],
depth_image_view,
};
VkFramebufferCreateInfo framebuffer_info = {
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
.renderPass = render_pass,
.attachmentCount = 2,
.pAttachments = attachments,
.width = extent.width,
.height = extent.height,
.layers = 1,
};
VkResult result = vkCreateFramebuffer(device, &framebuffer_info, 0, &framebuffer_ptr[i]);
if(result != VK_SUCCESS) {
free(*framebuffers);
return result;
}
}
return VK_SUCCESS;
}
VkSemaphore create_timeline_semaphore(VkDevice device) {
VkSemaphoreTypeCreateInfo semaphore_type = {
@ -1059,15 +919,11 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) {
&context->swapchain_images,
&context->swapchain_image_count));
context->swapchain_command_buffers = create_command_buffers(context->device, context->graphics_pool, context->swapchain_image_count);
if(context->swapchain_command_buffers == NULL) {
context->frame_command_buffers = create_command_buffers(context->device, context->graphics_pool, MAX_FRAMES_IN_FLIGHT);
if(context->frame_command_buffers == NULL) {
return VK_ERROR_VALIDATION_FAILED_EXT;
}
context->swapchain_command_buffer_record_id = 1;
context->swapchain_command_buffer_record_ids = malloc(sizeof(uint64_t)*context->swapchain_image_count);
memset(context->swapchain_command_buffer_record_ids, 0, sizeof(uint64_t)*context->swapchain_image_count);
VK_RESULT(create_image_views(
context->device,
context->swapchain_image_count,
@ -1081,12 +937,6 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) {
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT,
&context->depth_format));
VK_RESULT(create_render_pass(
context->device,
context->swapchain_format,
context->depth_format,
&context->render_pass));
VK_RESULT(create_depth_image(
context->device,
context->depth_format,
@ -1098,15 +948,6 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) {
&context->depth_image_memory,
&context->depth_image_view));
VK_RESULT(create_swapchain_framebuffers(
context->device,
context->swapchain_image_count,
context->swapchain_image_views,
context->depth_image_view,
context->render_pass,
context->swapchain_extent,
&context->swapchain_framebuffers));
context->current_frame = 0;
return VK_SUCCESS;
}
@ -1360,7 +1201,6 @@ VkResult recreate_framebuffer(RenderContext* gpu) {
vkDeviceWaitIdle(gpu->device);
for(uint32_t i = 0; i < gpu->swapchain_image_count; i++) {
vkDestroyFramebuffer(gpu->device, gpu->swapchain_framebuffers[i], NULL);
vkDestroyImageView(gpu->device, gpu->swapchain_image_views[i], NULL);
}
@ -1369,7 +1209,6 @@ VkResult recreate_framebuffer(RenderContext* gpu) {
free(gpu->swapchain_images);
free(gpu->swapchain_image_views);
free(gpu->swapchain_framebuffers);
free(gpu->swapchain_details.formats);
free(gpu->swapchain_details.present_modes);
@ -1415,15 +1254,6 @@ VkResult recreate_framebuffer(RenderContext* gpu) {
&gpu->depth_image_memory,
&gpu->depth_image_view));
VK_RESULT(create_swapchain_framebuffers(
gpu->device,
gpu->swapchain_image_count,
gpu->swapchain_image_views,
gpu->depth_image_view,
gpu->render_pass,
gpu->swapchain_extent,
&gpu->swapchain_framebuffers));
gpu->framebuffer_recreated = true;
return VK_SUCCESS;

@ -191,6 +191,13 @@ VkResult create_point_pipeline(
.depthCompareOp = VK_COMPARE_OP_LESS,
};
VkPipelineRenderingCreateInfo rendering_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
.colorAttachmentCount = 1,
.pColorAttachmentFormats = &gpu->swapchain_format.format,
.depthAttachmentFormat = gpu->depth_format,
};
VkGraphicsPipelineCreateInfo graphics_pipeline_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.layout = pipeline->layout,
@ -204,8 +211,8 @@ VkResult create_point_pipeline(
.pDynamicState = &dynamic_info,
.pMultisampleState = &multisample_info,
.pDepthStencilState = &depth_info,
.renderPass = gpu->render_pass,
.subpass = 0,
.pNext = &rendering_info,
.renderPass = VK_NULL_HANDLE,
.basePipelineHandle = VK_NULL_HANDLE,
.basePipelineIndex = -1,
};
@ -351,6 +358,13 @@ VkResult create_ray_pipeline(
.depthCompareOp = VK_COMPARE_OP_LESS,
};
VkPipelineRenderingCreateInfo rendering_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
.colorAttachmentCount = 1,
.pColorAttachmentFormats = &gpu->swapchain_format.format,
.depthAttachmentFormat = gpu->depth_format,
};
VkGraphicsPipelineCreateInfo graphics_pipeline_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.layout = pipeline->layout,
@ -364,8 +378,8 @@ VkResult create_ray_pipeline(
.pDynamicState = &dynamic_info,
.pMultisampleState = &multisample_info,
.pDepthStencilState = &depth_info,
.renderPass = gpu->render_pass,
.subpass = 0,
.pNext = &rendering_info,
.renderPass = VK_NULL_HANDLE,
.basePipelineHandle = VK_NULL_HANDLE,
.basePipelineIndex = -1,
};
@ -511,6 +525,13 @@ VkResult create_hex_highlight_pipeline(
.depthCompareOp = VK_COMPARE_OP_LESS,
};
VkPipelineRenderingCreateInfo rendering_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
.colorAttachmentCount = 1,
.pColorAttachmentFormats = &gpu->swapchain_format.format,
.depthAttachmentFormat = gpu->depth_format,
};
VkGraphicsPipelineCreateInfo graphics_pipeline_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.layout = pipeline->layout,
@ -524,8 +545,8 @@ VkResult create_hex_highlight_pipeline(
.pDynamicState = &dynamic_info,
.pMultisampleState = &multisample_info,
.pDepthStencilState = &depth_info,
.renderPass = gpu->render_pass,
.subpass = 0,
.pNext = &rendering_info,
.renderPass = VK_NULL_HANDLE,
.basePipelineHandle = VK_NULL_HANDLE,
.basePipelineIndex = -1,
};
@ -671,6 +692,13 @@ VkResult create_hex_pipeline(
.depthCompareOp = VK_COMPARE_OP_LESS,
};
VkPipelineRenderingCreateInfo rendering_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
.colorAttachmentCount = 1,
.pColorAttachmentFormats = &gpu->swapchain_format.format,
.depthAttachmentFormat = gpu->depth_format,
};
VkGraphicsPipelineCreateInfo graphics_pipeline_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.layout = pipeline->layout,
@ -684,8 +712,8 @@ VkResult create_hex_pipeline(
.pDynamicState = &dynamic_info,
.pMultisampleState = &multisample_info,
.pDepthStencilState = &depth_info,
.renderPass = gpu->render_pass,
.subpass = 0,
.pNext = &rendering_info,
.renderPass = VK_NULL_HANDLE,
.basePipelineHandle = VK_NULL_HANDLE,
.basePipelineIndex = -1,
};

@ -13,7 +13,7 @@
VkResult create_ui_pipeline(
VkDevice device,
VkRenderPass render_pass,
VkFormat color_format,
VkDescriptorSetLayout samplers_layout,
VkDescriptorSetLayout textures_layout,
GraphicsPipeline* pipeline,
@ -201,6 +201,12 @@ VkResult create_ui_pipeline(
.pDynamicStates = dynamic_states,
};
VkPipelineRenderingCreateInfo rendering_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO,
.colorAttachmentCount = 1,
.pColorAttachmentFormats = &color_format,
};
VkGraphicsPipelineCreateInfo draw_pipeline_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.stageCount = sizeof(shader_stages)/sizeof(VkPipelineShaderStageCreateInfo),
@ -212,9 +218,9 @@ VkResult create_ui_pipeline(
.pColorBlendState = &color_blend_info,
.pDynamicState = &dynamic_info,
.pMultisampleState = &multisample_info,
.pNext = &rendering_info,
.layout = pipeline->layout,
.renderPass = render_pass,
.subpass = 1,
.renderPass = VK_NULL_HANDLE,
.basePipelineHandle = VK_NULL_HANDLE,
.basePipelineIndex = -1,
};
@ -304,6 +310,7 @@ VkResult load_container(
context->containers[index].callbacks,
container->callbacks,
sizeof(UICallbacks)*container->callback_count);
return VK_SUCCESS;
}
@ -1140,7 +1147,7 @@ VkResult create_ui_context(
VK_RESULT(create_ui_pipeline(
gpu->device,
gpu->render_pass,
gpu->swapchain_format.format,
context->samplers_layout,
context->textures_layout,
&context->pipeline,
@ -1203,15 +1210,13 @@ Container* context_container(uint32_t container_id, UIContext* ui) {
VkResult update_ui_string(
const char* string,
uint32_t container_id,
Container* container,
uint32_t layer_index,
uint32_t string_index,
UIContext* ui,
RenderContext* gpu) {
VkResult result;
Container* container = context_container(container_id, ui);
if(container == NULL) {
return VK_ERROR_UNKNOWN;
}
@ -1303,23 +1308,24 @@ bool ui_intersect(
void clear_active_element(UIContext* ui, RenderContext* gpu) {
if(ui->active_callbacks != NULL && ui->active_callbacks->deselect != NULL) {
ui->active_callbacks->deselect(ui->active_callbacks->data, ui, gpu);
ui->active_callbacks->deselect(ui->active_container, ui->active_callbacks->data, ui, gpu);
}
ui->active_callbacks = NULL;
ui->active_container = NULL;
ui->active_element = 0;
ui->active_container = 0;
}
void set_active_element(uint32_t container, uint32_t layer, uint32_t element, UIContext* ui) {
ui->active_container = container;
ui->active_element = element;
ui->active_layer = layer;
ui->active_callbacks = NULL;
Container* container_ptr = context_container(container, ui);
if(container_ptr == NULL) {
fprintf(stderr, "set_active_element passed invalid container id");
return;
}
ui->active_container = container_ptr;
for(uint32_t c = 0; c < container_ptr->callback_count; c++) {
if(container_ptr->callbacks[c].element == element && container_ptr->callbacks[c].layer == layer) {