summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-01-23 21:57:31 -0500
committerJonathan Bradley <jcb@pikum.xyz>2025-01-23 21:57:31 -0500
commite93eb289ca44e98967482ab80fd5329f85ccd03e (patch)
tree4164b6d5b9ac2e40d18ec3eea52730c9f9606ccb /src/window.cpp
parent846a6e1185417ee3e187edc06ef327d180bf0d9b (diff)
pke: first-pass 2d overlay render pass scaffolding
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp97
1 files changed, 75 insertions, 22 deletions
diff --git a/src/window.cpp b/src/window.cpp
index b83ef9a..a06895c 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1,3 +1,4 @@
+#include "font.hpp"
#define GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_VULKAN
@@ -1562,18 +1563,23 @@ void CreateGraphicsPipelines() {
.bindingCount = 2,
.pBindings = vkDescriptorSetLayoutBindings,
};
- vkCreateDescriptorSetLayout(vkDevice, &vkDescriptorSetLayoutCreateInfo, vkAllocator, &pkePipelines.vkDescriptorSetLayout_Texture);
+ vkCreateDescriptorSetLayout(vkDevice, &vkDescriptorSetLayoutCreateInfo, vkAllocator, &pkePipelines.descr_layouts.named.texture);
+
+ // no UBO on glyph
+ vkDescriptorSetLayoutBindings[0] = vkDescriptorSetLayoutBindings[1];
+ vkDescriptorSetLayoutCreateInfo.bindingCount = 1;
+ vkCreateDescriptorSetLayout(vkDevice, &vkDescriptorSetLayoutCreateInfo, vkAllocator, &pkePipelines.descr_layouts.named.glyph);
VkPipelineLayoutCreateInfo vkPipelineLayoutCreateInfo {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
- .setLayoutCount = 1,
- .pSetLayouts = &pkePipelines.vkDescriptorSetLayout_Texture,
+ .setLayoutCount = 2,
+ .pSetLayouts = pkePipelines.descr_layouts.arr,
.pushConstantRangeCount = 0,
.pPushConstantRanges = nullptr,
};
- vkCreatePipelineLayout(vkDevice, &vkPipelineLayoutCreateInfo, vkAllocator, &pkePipelines.vkPipelineLayout_Texture);
+ vkCreatePipelineLayout(vkDevice, &vkPipelineLayoutCreateInfo, vkAllocator, pkePipelines.pipe_layouts.arr);
VkSamplerCreateInfo vkSamplerCreateInfo;
vkSamplerCreateInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
@@ -1814,7 +1820,7 @@ void CreateGraphicsPipelines() {
vkGraphicsPipelineCreateInfo[i].pDepthStencilState = &vkPipelineDepthStencilStateCreateInfo;
vkGraphicsPipelineCreateInfo[i].pColorBlendState = &vkPipelineColorBlendStateCreateInfo;
vkGraphicsPipelineCreateInfo[i].pDynamicState = &vkPipelineDynamicStateCreateInfo;
- vkGraphicsPipelineCreateInfo[i].layout = pkePipelines.vkPipelineLayout_Texture;
+ vkGraphicsPipelineCreateInfo[i].layout = pkePipelines.pipe_layouts.named.texture;
vkGraphicsPipelineCreateInfo[i].renderPass = renderRenderPass;
vkGraphicsPipelineCreateInfo[i].subpass = 0;
vkGraphicsPipelineCreateInfo[i].basePipelineHandle = VK_NULL_HANDLE;
@@ -2259,7 +2265,7 @@ void UpdateDebugGraphicsPipeline() {
VkDescriptorSetLayout descriptorSets[MAX_FRAMES_IN_FLIGHT];
for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) {
- descriptorSets[i] = pkePipelines.vkDescriptorSetLayout_Texture;
+ descriptorSets[i] = pkePipelines.descr_layouts.named.texture;
}
VkDescriptorSetAllocateInfo vkDescriptorSetAllocateInfo;
vkDescriptorSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
@@ -2414,7 +2420,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
throw "failed to begin recording command buffer";
}
- // VkClearColorValue clearColorTransparent = {{0.0f, 0.0f, 0.0f, 0.0f}};
+ VkClearColorValue clearColorTransparent = {{0.0f, 0.0f, 0.0f, 0.0f}};
VkClearColorValue clearColorBlack = {{0.0f, 0.0f, 0.0f, 1.0f}};
VkClearDepthStencilValue clearDepth;
clearDepth.depth = 1.0;
@@ -2463,7 +2469,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
continue;
if (!binder->vkPipelineLayout)
continue;
- if (binder->instanceBindingCount < 1) {
+ if (binder->instanceBD.bindingCount < 1) {
continue;
}
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, binder->graphicsPipeline);
@@ -2474,13 +2480,13 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
vkCmdBindVertexBuffers(commandBuffer, binder->vertexBD.firstBinding, binder->vertexBD.bindingCount, &binder->vertexBD.buffer, binder->vertexBD.offsets);
vkCmdBindVertexBuffers(commandBuffer, binder->normalsBD.firstBinding, binder->normalsBD.bindingCount, &binder->normalsBD.buffer, binder->normalsBD.offsets);
vkCmdBindVertexBuffers(commandBuffer, binder->uvBD.firstBinding, binder->uvBD.bindingCount, &binder->uvBD.buffer, binder->uvBD.offsets);
- vkCmdBindVertexBuffers(commandBuffer, binder->instanceFirstBinding, binder->instanceBindingCount, &binder->instanceBuffer, &binder->instanceOffsets);
+ vkCmdBindVertexBuffers(commandBuffer, binder->instanceBD.firstBinding, binder->instanceBD.bindingCount, &binder->instanceBD.buffer, binder->instanceBD.offsets);
vkCmdDrawIndexed(commandBuffer, binder->indexCount, binder->instanceCounter, 0, 0, 0);
if (pkeSettings.isRenderingDebug) {
- vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipelines.named.TextureWireframe);
- vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.vkPipelineLayout_Texture, 0, 1, &pkeDebugHitbox.vkDescriptorSets[imageIndex], 0, {});
+ vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipelines.named.texture_wireframe);
+ vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipe_layouts.named.texture, 0, 1, &pkeDebugHitbox.vkDescriptorSets[imageIndex], 0, {});
vkCmdBindVertexBuffers(commandBuffer, binder->physVertBD.firstBinding, 1, &binder->physVertBD.buffer, binder->physVertBD.offsets);
vkCmdBindVertexBuffers(commandBuffer, binder->physNormBD.firstBinding, 1, &binder->physNormBD.buffer, binder->physVertBD.offsets);
@@ -2493,8 +2499,8 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
}
if (pkeDebugHitbox.instanceBuffer != VK_NULL_HANDLE) {
- vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipelines.named.TextureWireframe);
- vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.vkPipelineLayout_Texture, 0, 1, &pkeDebugHitbox.vkDescriptorSets[imageIndex], 0, {});
+ vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipelines.named.texture_wireframe);
+ vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipe_layouts.named.texture, 0, 1, &pkeDebugHitbox.vkDescriptorSets[imageIndex], 0, {});
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &UniformBuffers[imageIndex], offsets);
// TODO don't hardcode firstBinding
@@ -2509,8 +2515,8 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
vkCmdEndRenderPass(commandBuffer);
- /*
// 2d overlay pass
+ /*
renderPassInfo.renderPass = d2OverlayRenderPass;
renderPassInfo.framebuffer = d2OverlayImageFramebuffers[imageIndex];
renderPassInfo.clearValueCount = 1;
@@ -2521,10 +2527,23 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
// TODO 2d overlay grbinds
+ FontTypeIndex count;
+ FontType *fts = FontType_GetFonts(count);
+ for (FontTypeIndex i = FontTypeIndex{0}; i < count; ++i)
{
+ FontType *ft = &fts[(FontTypeIndex_T)i];
+ vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipelines.named.glyph);
- }
+ vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipe_layouts.named.glyph, 0, 1, &ft->vkDescriptorSets[imageIndex], 0, {});
+ vkCmdBindVertexBuffers(commandBuffer, 0, 1, &UniformBuffers[imageIndex], offsets);
+ vkCmdBindIndexBuffer(commandBuffer, ft->bindings.indexBD.buffer, ft->bindings.indexBD.offsets[0], VK_INDEX_TYPE_UINT16);
+ vkCmdBindVertexBuffers(commandBuffer, ft->bindings.vertexBD.firstBinding, ft->bindings.vertexBD.bindingCount, &ft->bindings.vertexBD.buffer, ft->bindings.vertexBD.offsets);
+ vkCmdBindVertexBuffers(commandBuffer, ft->bindings.uvBD.firstBinding, ft->bindings.uvBD.bindingCount, &ft->bindings.uvBD.buffer, ft->bindings.uvBD.offsets);
+ vkCmdBindVertexBuffers(commandBuffer, ft->bindings.instanceBD.firstBinding, ft->bindings.instanceBD.bindingCount, &ft->bindings.instanceBD.buffer, ft->bindings.instanceBD.offsets);
+
+ vkCmdDrawIndexed(commandBuffer, ft->bindings.indexCount, ft->bindings.instanceCounter, 0, 0, 0);
+ }
vkCmdEndRenderPass(commandBuffer);
*/
@@ -2544,9 +2563,9 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
// ImGui
- const auto count = LoadedPkePlugins.Count();
+ const auto plugin_count = LoadedPkePlugins.Count();
bool any = false;
- for (long i = 0; i < count; ++i) {
+ for (long i = 0; i < plugin_count; ++i) {
if (LoadedPkePlugins[i].OnImGuiRender != nullptr) {
any = true;
break;
@@ -2556,7 +2575,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
ImGui_ImplVulkan_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
- for (long i = 0; i < count; ++i) {
+ for (long i = 0; i < plugin_count; ++i) {
if (LoadedPkePlugins[i].OnImGuiRender != nullptr) {
LoadedPkePlugins[i].OnImGuiRender();
}
@@ -2746,10 +2765,10 @@ void DestroyWindow() {
if (pkePipelines.pipelines.arr[i] != VK_NULL_HANDLE)
vkDestroyPipeline(vkDevice, pkePipelines.pipelines.arr[i], vkAllocator);
}
- if (pkePipelines.vkPipelineLayout_Texture != VK_NULL_HANDLE)
- vkDestroyPipelineLayout(vkDevice, pkePipelines.vkPipelineLayout_Texture, vkAllocator);
- if (pkePipelines.vkDescriptorSetLayout_Texture != VK_NULL_HANDLE)
- vkDestroyDescriptorSetLayout(vkDevice, pkePipelines.vkDescriptorSetLayout_Texture, vkAllocator);
+ if (pkePipelines.pipe_layouts.named.texture != VK_NULL_HANDLE)
+ vkDestroyPipelineLayout(vkDevice, pkePipelines.pipe_layouts.named.texture, vkAllocator);
+ if (pkePipelines.descr_layouts.named.texture != VK_NULL_HANDLE)
+ vkDestroyDescriptorSetLayout(vkDevice, pkePipelines.descr_layouts.named.texture, vkAllocator);
for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) {
vkDestroyBuffer(vkDevice, UniformBuffers[i], vkAllocator);
@@ -2805,6 +2824,40 @@ VkShaderModule UploadShader(AssetHandle handle) {
return vkShaderModule;
}
+void CalculateCombinedMemReqs(uint64_t memReqsCount, VkMemoryRequirements *memReqs, VkMemoryRequirements &combinedMemReqs) {
+ combinedMemReqs.size = 0;
+ combinedMemReqs.alignment = memReqs[0].alignment;
+ combinedMemReqs.memoryTypeBits = memReqs[0].memoryTypeBits;
+ for (uint64_t i = 1; i < memReqsCount; ++i) {
+ combinedMemReqs.memoryTypeBits |= memReqs[i].memoryTypeBits;
+ if (combinedMemReqs.alignment == memReqs[i].alignment) {
+ continue;
+ }
+ VkDeviceSize larger, smaller;
+ if (combinedMemReqs.alignment > memReqs[i].alignment) {
+ larger = combinedMemReqs.alignment;
+ smaller = memReqs[i].alignment;
+ } else {
+ larger = memReqs[i].alignment;
+ smaller = combinedMemReqs.alignment;
+ }
+ if (larger % smaller == 0) {
+ combinedMemReqs.alignment = larger;
+ continue;
+ }
+ int combined = larger * smaller;
+ while ((combined / 2) % 2 == 0 && (combined / 2) % larger == 0) {
+ combined /= 2;
+ }
+ combinedMemReqs.alignment = combined;
+ }
+ for (uint64_t i = 0; i < memReqsCount; ++i) {
+ uint32_t alignmentPadding = memReqs[i].size % combinedMemReqs.alignment;
+ memReqs[i].size += (alignmentPadding == 0 ? 0 : combinedMemReqs.alignment - alignmentPadding);
+ combinedMemReqs.size += memReqs[i].size;
+ }
+}
+
void Render() {
vkWaitForFences(vkDevice, 1, &presentInFlightFences[CURRENT_FRAME], VK_TRUE, UINT64_MAX);