summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-02-04 19:17:59 -0500
committerJonathan Bradley <jcb@pikum.xyz>2025-02-04 19:17:59 -0500
commit61e179f9580c985cb5ca80ea732fc7572d31c489 (patch)
tree122ff15c6d94ce5aebff4ff6f1fc6d13317abe16 /src/window.cpp
parenta3fb454f9935960dc2d367455f891d8fedfb9016 (diff)
pke: chkpt: text rendering, no errors but blank
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp366
1 files changed, 249 insertions, 117 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 0cefba9..da4062c 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1,3 +1,5 @@
+#include "pk.h"
+#include <vulkan/vulkan_core.h>
#define GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_VULKAN
@@ -149,7 +151,7 @@ VkDeviceSize paddedUboBufferSize;
// public
VkBuffer *UniformBuffers;
DebugHitbox pkeDebugHitbox{};
-ImplementedPipelines pkePipelines{};
+ImplementedPKVK pkePipelines{};
/*
* ImGui
@@ -224,7 +226,7 @@ VkCommandBuffer GetCommandBuffer_Transfer() {
return pkvk_shared.command_buffer.transfer;
}
-void PKVK_BeginBuffer(unsigned int family_index, VkDeviceSize requestedMemorySize, PKVK_TmpBufferDetails &tmpBufferDetails) {
+void PKVK_BeginBuffer(unsigned int family_index, VkDeviceSize requestedMemorySize, PKVK_TmpBufferDetails &tmpBufferDetails, PKVK_TmpBufferFlags flags) {
if (family_index == graphicsFamilyIndex) {
tmpBufferDetails.queue = pkvk_shared.queue.graphics;
tmpBufferDetails.cmdBuffer = pkvk_shared.command_buffer.graphics;
@@ -262,12 +264,17 @@ void PKVK_BeginBuffer(unsigned int family_index, VkDeviceSize requestedMemorySiz
vkResult = vkBindBufferMemory(vkDevice, tmpBufferDetails.buffer, tmpBufferDetails.deviceMemory, 0);
assert(vkResult == VK_SUCCESS);
+
+ if (!PK_HAS_FLAG(flags, PKVK_TmpBufferFlags_MAP_MEMORY)) return;
+
vkResult = vkMapMemory(vkDevice, tmpBufferDetails.deviceMemory, 0, transferMemAllocInfo.allocationSize, 0, &tmpBufferDetails.deviceData);
assert(vkResult == VK_SUCCESS);
}
-void PKVK_EndBuffer(PKVK_TmpBufferDetails &tmpBufferDetails) {
- if (tmpBufferDetails.deviceMemory != VK_NULL_HANDLE) vkUnmapMemory(vkDevice, tmpBufferDetails.deviceMemory);
+void PKVK_EndBuffer(PKVK_TmpBufferDetails &tmpBufferDetails, PKVK_TmpBufferFlags flags) {
+ if (PK_HAS_FLAG(flags, PKVK_TmpBufferFlags_MAP_MEMORY)) {
+ if (tmpBufferDetails.deviceMemory != VK_NULL_HANDLE) vkUnmapMemory(vkDevice, tmpBufferDetails.deviceMemory);
+ }
if (tmpBufferDetails.buffer != VK_NULL_HANDLE) vkDestroyBuffer(vkDevice, tmpBufferDetails.buffer, vkAllocator);
if (tmpBufferDetails.deviceMemory != VK_NULL_HANDLE) vkFreeMemory(vkDevice, tmpBufferDetails.deviceMemory, vkAllocator);
tmpBufferDetails = {};
@@ -1063,7 +1070,7 @@ void CreateRenderPass() {
*/
VkAttachmentDescription attachment_descriptions[3];
memset(attachment_descriptions, 0, sizeof(VkAttachmentDescription) * 3);
- VkAttachmentReference attachment_refs[3];;
+ VkAttachmentReference attachment_refs[3];
memset(attachment_refs, 0, sizeof(VkAttachmentReference) * 3);
VkSubpassDependency subpass_dependencies[2];
memset(subpass_dependencies, 0, sizeof(VkSubpassDependency) * 2);
@@ -1157,7 +1164,7 @@ void CreateRenderPass() {
renderPassInfo.attachmentCount = 2;
if (vkCreateRenderPass(vkDevice, &renderPassInfo, vkAllocator, &pkvk_2d.render_pass) != VK_SUCCESS) {
- throw "failed to create render pass!";
+ throw "failed to create 2d render pass!";
}
// color
@@ -1191,7 +1198,7 @@ void CreateRenderPass() {
renderPassInfo.attachmentCount = 3;
if (vkCreateRenderPass(vkDevice, &renderPassInfo, vkAllocator, &pkvk_3d.render_pass) != VK_SUCCESS) {
- throw "failed to create render pass!";
+ throw "failed to create 3d render pass!";
}
}
@@ -1615,6 +1622,7 @@ void CreateSyncObjects() {
}
void CreateGraphicsPipelines() {
+ VkResult vkResult;
PKVK_TmpBufferDetails tmpBufferDetails{};
// layouts & sampler
{
@@ -1637,24 +1645,33 @@ void CreateGraphicsPipelines() {
.bindingCount = 2,
.pBindings = vkDescriptorSetLayoutBindings,
};
- vkCreateDescriptorSetLayout(vkDevice, &vkDescriptorSetLayoutCreateInfo, vkAllocator, &pkePipelines.descr_layouts.named.texture);
+ vkResult = vkCreateDescriptorSetLayout(vkDevice, &vkDescriptorSetLayoutCreateInfo, vkAllocator, &pkePipelines.descr_layouts.named.texture);
+ assert(vkResult == VK_SUCCESS);
+ assert(pkePipelines.descr_layouts.named.texture != VK_NULL_HANDLE);
// no UBO on glyph
vkDescriptorSetLayoutBindings[0] = vkDescriptorSetLayoutBindings[1];
vkDescriptorSetLayoutBindings[0].binding = 0;
vkDescriptorSetLayoutCreateInfo.bindingCount = 1;
- vkCreateDescriptorSetLayout(vkDevice, &vkDescriptorSetLayoutCreateInfo, vkAllocator, &pkePipelines.descr_layouts.named.glyph);
+ vkResult = vkCreateDescriptorSetLayout(vkDevice, &vkDescriptorSetLayoutCreateInfo, vkAllocator, &pkePipelines.descr_layouts.named.glyph);
+ assert(vkResult == VK_SUCCESS);
+ assert(pkePipelines.descr_layouts.named.glyph != VK_NULL_HANDLE);
VkPipelineLayoutCreateInfo vkPipelineLayoutCreateInfo {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
- .setLayoutCount = 2,
- .pSetLayouts = pkePipelines.descr_layouts.arr,
+ .setLayoutCount = 1,
+ .pSetLayouts = &pkePipelines.descr_layouts.named.texture,
.pushConstantRangeCount = 0,
.pPushConstantRanges = nullptr,
};
- vkCreatePipelineLayout(vkDevice, &vkPipelineLayoutCreateInfo, vkAllocator, pkePipelines.pipe_layouts.arr);
+ vkCreatePipelineLayout(vkDevice, &vkPipelineLayoutCreateInfo, vkAllocator, &pkePipelines.pipe_layouts.named.texture);
+ assert(pkePipelines.pipe_layouts.named.texture != VK_NULL_HANDLE);
+
+ vkPipelineLayoutCreateInfo.pSetLayouts = &pkePipelines.descr_layouts.named.glyph;
+ vkCreatePipelineLayout(vkDevice, &vkPipelineLayoutCreateInfo, vkAllocator, &pkePipelines.pipe_layouts.named.glyph);
+ assert(pkePipelines.pipe_layouts.named.glyph != VK_NULL_HANDLE);
}
// pipelines
@@ -1662,83 +1679,157 @@ void CreateGraphicsPipelines() {
// enqueue asset loading
AssetHandle vertShaderAssetHandle{AM_GetHandle(AssetKey{"pke_txtr_vrt\0\0\0"})};
AssetHandle textureFragShaderAssetHandle { AM_GetHandle(AssetKey{"pke_txtr_frg\0\0\0"})};
+ AssetHandle vertGlyphAssetHandle{AM_GetHandle(AssetKey{"pke_glyph_vrt\0\0"})};
+ AssetHandle fragGlyphAssetHandle { AM_GetHandle(AssetKey{"pke_glyph_frg\0\0"})};
const long vertexBindingCount = 4;
long index = 0;
- VkVertexInputBindingDescription vertInputBD[vertexBindingCount];
- // model vertex
- vertInputBD[index].binding = index;
- vertInputBD[index].stride = sizeof(glm::vec3);
- vertInputBD[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
- index += 1;
- // model normals
- vertInputBD[index].binding = index;
- vertInputBD[index].stride = sizeof(glm::vec3);
- vertInputBD[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
- index += 1;
- // model UV
- vertInputBD[index].binding = index;
- vertInputBD[index].stride = sizeof(glm::vec2);
- vertInputBD[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
- index += 1;
- // model index
- // vertInputBD[index].binding = index;
- // vertInputBD[index].stride = sizeof(uint16_t);
- // vertInputBD[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
- // index += 1;
- // instance
- vertInputBD[index].binding = index;
- vertInputBD[index].stride = sizeof(glm::mat4);
- vertInputBD[index].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
-
+ VkVertexInputBindingDescription vertInputBD_txtr[vertexBindingCount];
const long vertexAttrDescCount = 7;
- index = 0;
- VkVertexInputAttributeDescription vertAttrDesc[vertexAttrDescCount];
- for (long i = 0; i < vertexAttrDescCount; ++i) {
- vertAttrDesc[i].location = i;
- }
+ VkVertexInputAttributeDescription vertAttrDesc_txtr[vertexAttrDescCount];
+ VkPipelineVertexInputStateCreateInfo vkPipelineVertexInputStateCreateInfo_txtr;
+ {
+ // model vertex
+ vertInputBD_txtr[index].binding = index;
+ vertInputBD_txtr[index].stride = sizeof(glm::vec3);
+ vertInputBD_txtr[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
+ index += 1;
+ // model normals
+ vertInputBD_txtr[index].binding = index;
+ vertInputBD_txtr[index].stride = sizeof(glm::vec3);
+ vertInputBD_txtr[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
+ index += 1;
+ // model UV
+ vertInputBD_txtr[index].binding = index;
+ vertInputBD_txtr[index].stride = sizeof(glm::vec2);
+ vertInputBD_txtr[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
+ index += 1;
+ // instance
+ vertInputBD_txtr[index].binding = index;
+ vertInputBD_txtr[index].stride = sizeof(glm::mat4);
+ vertInputBD_txtr[index].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
+ // index += 1;
- // model vertex
- vertAttrDesc[index].binding = 0;
- vertAttrDesc[index].format = VK_FORMAT_R32G32B32_SFLOAT;
- vertAttrDesc[index].offset = 0;
- index += 1;
-
- // model normals
- vertAttrDesc[index].binding = 1;
- vertAttrDesc[index].format = VK_FORMAT_R32G32B32_SFLOAT;
- vertAttrDesc[index].offset = 0;
- index += 1;
-
- // model UV
- vertAttrDesc[index].binding = 2;
- vertAttrDesc[index].format = VK_FORMAT_R32G32_SFLOAT;
- vertAttrDesc[index].offset = 0;
- index += 1;
-
- // instPosRotScale
- for (long i = 0; i < 4; ++i) {
- vertAttrDesc[index].binding = 3;
- vertAttrDesc[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;
- vertAttrDesc[index].offset = sizeof(glm::vec4) * i;
+ index = 0;
+ for (long i = 0; i < vertexAttrDescCount; ++i) {
+ vertAttrDesc_txtr[i].location = i;
+ }
+
+ // model vertex
+ vertAttrDesc_txtr[index].binding = 0;
+ vertAttrDesc_txtr[index].format = VK_FORMAT_R32G32B32_SFLOAT;
+ vertAttrDesc_txtr[index].offset = 0;
+ index += 1;
+
+ // model normals
+ vertAttrDesc_txtr[index].binding = 1;
+ vertAttrDesc_txtr[index].format = VK_FORMAT_R32G32B32_SFLOAT;
+ vertAttrDesc_txtr[index].offset = 0;
+ index += 1;
+
+ // model UV
+ vertAttrDesc_txtr[index].binding = 2;
+ vertAttrDesc_txtr[index].format = VK_FORMAT_R32G32_SFLOAT;
+ vertAttrDesc_txtr[index].offset = 0;
index += 1;
+
+ // instPosRotScale
+ for (long i = 0; i < 4; ++i) {
+ vertAttrDesc_txtr[index].binding = 3;
+ vertAttrDesc_txtr[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;
+ vertAttrDesc_txtr[index].offset = sizeof(glm::vec4) * i;
+ index += 1;
+ }
+
+ vkPipelineVertexInputStateCreateInfo_txtr.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
+ vkPipelineVertexInputStateCreateInfo_txtr.pNext = nullptr;
+ vkPipelineVertexInputStateCreateInfo_txtr.flags = {};
+ vkPipelineVertexInputStateCreateInfo_txtr.vertexBindingDescriptionCount = vertexBindingCount;
+ vkPipelineVertexInputStateCreateInfo_txtr.pVertexBindingDescriptions = vertInputBD_txtr;
+ vkPipelineVertexInputStateCreateInfo_txtr.vertexAttributeDescriptionCount = vertexAttrDescCount;
+ vkPipelineVertexInputStateCreateInfo_txtr.pVertexAttributeDescriptions = vertAttrDesc_txtr;
}
- // instance texture index
- // vertAttrDesc[index].binding = 3;
- // vertAttrDesc[index].format = VK_FORMAT_R32_SFLOAT;
- // vertAttrDesc[index].offset = runningOffset;
- // runningOffset += sizeof(float);
- // index += 1;
-
- VkPipelineVertexInputStateCreateInfo vkPipelineVertexInputStateCreateInfo;
- vkPipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
- vkPipelineVertexInputStateCreateInfo.pNext = nullptr;
- vkPipelineVertexInputStateCreateInfo.flags = {};
- vkPipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = vertexBindingCount;
- vkPipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = vertInputBD;
- vkPipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = vertexAttrDescCount;
- vkPipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = vertAttrDesc;
+ index = 0;
+ long offset = 0;
+ const long vertexBindingCount_glyph = 3;
+ VkVertexInputBindingDescription vertInputBD_glyph[vertexBindingCount_glyph];
+ const long vertexAttrDescCount_glyph = 6;
+ VkVertexInputAttributeDescription vertAttrDesc_glyph[vertexAttrDescCount_glyph];
+ VkPipelineVertexInputStateCreateInfo vkPipelineVertexInputStateCreateInfo_glyph{vkPipelineVertexInputStateCreateInfo_txtr};
+ {
+ // model vertex
+ vertInputBD_glyph[index].binding = index;
+ vertInputBD_glyph[index].stride = sizeof(glm::vec2);
+ vertInputBD_glyph[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
+ index += 1;
+
+ // model UV
+ vertInputBD_glyph[index].binding = index;
+ vertInputBD_glyph[index].stride = sizeof(glm::vec2);
+ vertInputBD_glyph[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
+ index += 1;
+
+ // instance - total
+ vertInputBD_glyph[index].binding = index;
+ vertInputBD_glyph[index].stride = 0
+ + sizeof(glm::vec4)
+ + sizeof(glm::vec4)
+ + sizeof(glm::ivec4)
+ + sizeof(float);
+ vertInputBD_glyph[index].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
+ // index += 1;
+
+ index = 0;
+ for (long i = 0; i < vertexAttrDescCount_glyph; ++i) {
+ vertAttrDesc_glyph[i].location = i;
+ }
+
+ // model vertex
+ vertAttrDesc_glyph[index].binding = 0;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32_SFLOAT;
+ vertAttrDesc_glyph[index].offset = 0;
+ index += 1;
+
+ // model UV
+ vertAttrDesc_glyph[index].binding = 1;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32_SFLOAT;
+ vertAttrDesc_glyph[index].offset = 0;
+ index += 1;
+
+ // instance - in_fg_color
+ vertAttrDesc_glyph[index].binding = 2;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;
+ vertAttrDesc_glyph[index].offset = 0;
+ offset += sizeof(glm::vec4);
+ index += 1;
+
+ // instance - in_bg_color
+ vertAttrDesc_glyph[index].binding = 2;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;
+ vertAttrDesc_glyph[index].offset = offset;
+ offset += sizeof(glm::vec4);
+ index += 1;
+
+ // instance - in_sprite_region
+ vertAttrDesc_glyph[index].binding = 2;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32B32A32_SINT;
+ vertAttrDesc_glyph[index].offset = offset;
+ offset += sizeof(glm::ivec4);
+ index += 1;
+
+ // instance - in_sprite_region
+ vertAttrDesc_glyph[index].binding = 2;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32_SFLOAT;
+ vertAttrDesc_glyph[index].offset = offset;
+ // offset += sizeof(float);
+ // index += 1;
+
+ vkPipelineVertexInputStateCreateInfo_glyph.vertexBindingDescriptionCount = vertexBindingCount_glyph;
+ vkPipelineVertexInputStateCreateInfo_glyph.pVertexBindingDescriptions = vertInputBD_glyph;
+ vkPipelineVertexInputStateCreateInfo_glyph.vertexAttributeDescriptionCount = vertexAttrDescCount_glyph;
+ vkPipelineVertexInputStateCreateInfo_glyph.pVertexAttributeDescriptions = vertAttrDesc_glyph;
+ }
VkPipelineInputAssemblyStateCreateInfo vkPipelineInputAssemblyStateCreateInfo;
vkPipelineInputAssemblyStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
@@ -1841,31 +1932,40 @@ void CreateGraphicsPipelines() {
const Asset *textureVertShaderAsset = AM_Get(vertShaderAssetHandle);
const Asset *textureFragShaderAsset = AM_Get(textureFragShaderAssetHandle);
+ const Asset *glyphVertShaderAsset = AM_Get(vertGlyphAssetHandle);
+ const Asset *glyphFragShaderAsset = AM_Get(fragGlyphAssetHandle);
assert(textureVertShaderAsset != nullptr && textureVertShaderAsset->state == PKE_ASSET_LOADING_STATE_LOADED);
assert(textureFragShaderAsset != nullptr && textureFragShaderAsset->state == PKE_ASSET_LOADING_STATE_LOADED);
+ assert(glyphVertShaderAsset != nullptr && glyphVertShaderAsset->state == PKE_ASSET_LOADING_STATE_LOADED);
+ assert(glyphFragShaderAsset != nullptr && glyphFragShaderAsset->state == PKE_ASSET_LOADING_STATE_LOADED);
- VkPipelineShaderStageCreateInfo vkPipelineShaderStageCreateInfo[2];
+ VkPipelineShaderStageCreateInfo vkPipelineShaderStageCreateInfo_txtr[2];
for (long i = 0; i < 2; ++i) {
- vkPipelineShaderStageCreateInfo[i].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- vkPipelineShaderStageCreateInfo[i].pNext = nullptr;
- vkPipelineShaderStageCreateInfo[i].flags = {};
- vkPipelineShaderStageCreateInfo[i].pName = "main";
- vkPipelineShaderStageCreateInfo[i].pSpecializationInfo = nullptr;
+ vkPipelineShaderStageCreateInfo_txtr[i].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ vkPipelineShaderStageCreateInfo_txtr[i].pNext = nullptr;
+ vkPipelineShaderStageCreateInfo_txtr[i].flags = {};
+ vkPipelineShaderStageCreateInfo_txtr[i].pName = "main";
+ vkPipelineShaderStageCreateInfo_txtr[i].pSpecializationInfo = nullptr;
}
-
- vkPipelineShaderStageCreateInfo[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
- vkPipelineShaderStageCreateInfo[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
- // vkPipelineShaderStageCreateInfo[0].module = // deferred
- // vkPipelineShaderStageCreateInfo[1].module = // deferred
-
- VkGraphicsPipelineCreateInfo vkGraphicsPipelineCreateInfo[2];
+ vkPipelineShaderStageCreateInfo_txtr[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
+ vkPipelineShaderStageCreateInfo_txtr[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
+ VkPipelineShaderStageCreateInfo vkPipelineShaderStageCreateInfo_glyph[2];
for (long i = 0; i < 2; ++i) {
+ vkPipelineShaderStageCreateInfo_glyph[i].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ vkPipelineShaderStageCreateInfo_glyph[i].pNext = nullptr;
+ vkPipelineShaderStageCreateInfo_glyph[i].flags = {};
+ vkPipelineShaderStageCreateInfo_glyph[i].pName = "main";
+ vkPipelineShaderStageCreateInfo_glyph[i].pSpecializationInfo = nullptr;
+ }
+ vkPipelineShaderStageCreateInfo_glyph[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
+ vkPipelineShaderStageCreateInfo_glyph[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
+
+ VkGraphicsPipelineCreateInfo vkGraphicsPipelineCreateInfo[3];
+ for (long i = 0; i < 3; ++i) {
vkGraphicsPipelineCreateInfo[i].sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
vkGraphicsPipelineCreateInfo[i].pNext = nullptr;
vkGraphicsPipelineCreateInfo[i].flags = {};
vkGraphicsPipelineCreateInfo[i].stageCount = 2;
- vkGraphicsPipelineCreateInfo[i].pStages = vkPipelineShaderStageCreateInfo;
- vkGraphicsPipelineCreateInfo[i].pVertexInputState = &vkPipelineVertexInputStateCreateInfo;
vkGraphicsPipelineCreateInfo[i].pInputAssemblyState = &vkPipelineInputAssemblyStateCreateInfo;
vkGraphicsPipelineCreateInfo[i].pTessellationState = nullptr;
vkGraphicsPipelineCreateInfo[i].pViewportState = &vkPipelineViewportStateCreateInfo;
@@ -1873,28 +1973,57 @@ void CreateGraphicsPipelines() {
vkGraphicsPipelineCreateInfo[i].pDepthStencilState = &vkPipelineDepthStencilStateCreateInfo;
vkGraphicsPipelineCreateInfo[i].pColorBlendState = &vkPipelineColorBlendStateCreateInfo;
vkGraphicsPipelineCreateInfo[i].pDynamicState = &vkPipelineDynamicStateCreateInfo;
- vkGraphicsPipelineCreateInfo[i].layout = pkePipelines.pipe_layouts.named.texture;
- vkGraphicsPipelineCreateInfo[i].renderPass = pkvk_3d.render_pass;
vkGraphicsPipelineCreateInfo[i].subpass = 0;
vkGraphicsPipelineCreateInfo[i].basePipelineHandle = VK_NULL_HANDLE;
vkGraphicsPipelineCreateInfo[i].basePipelineIndex = {};
}
+ vkGraphicsPipelineCreateInfo[0].layout = pkePipelines.pipe_layouts.named.texture;
+ vkGraphicsPipelineCreateInfo[1].layout = pkePipelines.pipe_layouts.named.texture;
+ vkGraphicsPipelineCreateInfo[2].layout = pkePipelines.pipe_layouts.named.glyph;
+
+ vkGraphicsPipelineCreateInfo[0].renderPass = pkvk_3d.render_pass;
+ vkGraphicsPipelineCreateInfo[1].renderPass = pkvk_3d.render_pass;
+ vkGraphicsPipelineCreateInfo[2].renderPass = pkvk_2d.render_pass;
+
+ vkGraphicsPipelineCreateInfo[0].pVertexInputState = &vkPipelineVertexInputStateCreateInfo_txtr;
+ vkGraphicsPipelineCreateInfo[1].pVertexInputState = &vkPipelineVertexInputStateCreateInfo_txtr;
+ vkGraphicsPipelineCreateInfo[2].pVertexInputState = &vkPipelineVertexInputStateCreateInfo_glyph;
+
vkGraphicsPipelineCreateInfo[0].pRasterizationState = &vkPipelineRasterizationStateCreateInfoFill;
vkGraphicsPipelineCreateInfo[1].pRasterizationState = &vkPipelineRasterizationStateCreateInfoLine;
+ vkGraphicsPipelineCreateInfo[2].pRasterizationState = &vkPipelineRasterizationStateCreateInfoFill;
+
+ vkGraphicsPipelineCreateInfo[0].pStages = vkPipelineShaderStageCreateInfo_txtr;
+ vkGraphicsPipelineCreateInfo[1].pStages = vkPipelineShaderStageCreateInfo_txtr;
+ vkGraphicsPipelineCreateInfo[2].pStages = vkPipelineShaderStageCreateInfo_glyph;
// deffered shader creation
- vkPipelineShaderStageCreateInfo[0].module = UploadShader(vertShaderAssetHandle);
- vkPipelineShaderStageCreateInfo[1].module = UploadShader(textureFragShaderAssetHandle);
+ vkPipelineShaderStageCreateInfo_txtr[0].module = UploadShader(vertShaderAssetHandle);
+ vkPipelineShaderStageCreateInfo_txtr[1].module = UploadShader(textureFragShaderAssetHandle);
+ vkPipelineShaderStageCreateInfo_glyph[0].module = UploadShader(vertGlyphAssetHandle);
+ vkPipelineShaderStageCreateInfo_glyph[1].module = UploadShader(fragGlyphAssetHandle);
- vkCreateGraphicsPipelines(vkDevice, VK_NULL_HANDLE, 2, vkGraphicsPipelineCreateInfo, vkAllocator, pkePipelines.pipelines.arr);
+ vkResult = vkCreateGraphicsPipelines(vkDevice, VK_NULL_HANDLE, 1, &vkGraphicsPipelineCreateInfo[0], vkAllocator, &pkePipelines.pipelines.named.texture);
+ assert(vkResult == VK_SUCCESS);
+ vkResult = vkCreateGraphicsPipelines(vkDevice, VK_NULL_HANDLE, 1, &vkGraphicsPipelineCreateInfo[1], vkAllocator, &pkePipelines.pipelines.named.texture_wireframe);
+ assert(vkResult == VK_SUCCESS);
+ vkResult = vkCreateGraphicsPipelines(vkDevice, VK_NULL_HANDLE, 1, &vkGraphicsPipelineCreateInfo[2], vkAllocator, &pkePipelines.pipelines.named.glyph);
+ assert(vkResult == VK_SUCCESS);
+ assert(pkePipelines.pipelines.named.texture != VK_NULL_HANDLE);
+ assert(pkePipelines.pipelines.named.texture_wireframe != VK_NULL_HANDLE);
+ assert(pkePipelines.pipelines.named.glyph != VK_NULL_HANDLE);
for (long i = 0; i < 2; ++i) {
- vkDestroyShaderModule(vkDevice, vkPipelineShaderStageCreateInfo[i].module, vkAllocator);
+ vkDestroyShaderModule(vkDevice, vkPipelineShaderStageCreateInfo_txtr[i].module, vkAllocator);
+ vkDestroyShaderModule(vkDevice, vkPipelineShaderStageCreateInfo_glyph[i].module, vkAllocator);
}
- AM_Release(textureFragShaderAssetHandle);
+ // reverse order
+ AM_Release(fragGlyphAssetHandle);
+ AM_Release(vertGlyphAssetHandle);
AM_Release(vertShaderAssetHandle);
+ AM_Release(textureFragShaderAssetHandle);
}
// debug texture
@@ -2575,7 +2704,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
- // TODO 2d overlay grbinds
+ // 2d overlay grbinds
FontTypeIndex count;
FontType *fts = FontType_GetFonts(count);
for (FontTypeIndex i = FontTypeIndex{0}; i < count; ++i)
@@ -2584,7 +2713,6 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
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);
@@ -2836,18 +2964,22 @@ void DestroyWindow() {
vkDestroyImage(vkDevice, pkeDebugHitbox.vkImage, vkAllocator);
vkFreeMemory(vkDevice, pkeDebugHitbox.textureMemory, vkAllocator);
- for (long i = 0; i < 3; ++i) {
- if (pkePipelines.pipelines.arr[i] != VK_NULL_HANDLE)
- vkDestroyPipeline(vkDevice, pkePipelines.pipelines.arr[i], vkAllocator);
- }
- for (long i = 0; i < 2; ++i) {
- if (pkePipelines.pipelines.arr[i] != VK_NULL_HANDLE)
- vkDestroyPipelineLayout(vkDevice, pkePipelines.pipe_layouts.arr[i], vkAllocator);
- }
- for (long i = 0; i < 2; ++i) {
- if (pkePipelines.pipelines.arr[i] != VK_NULL_HANDLE)
- vkDestroyDescriptorSetLayout(vkDevice, pkePipelines.descr_layouts.arr[i], vkAllocator);
- }
+ if (pkePipelines.pipelines.named.texture != VK_NULL_HANDLE)
+ vkDestroyPipeline(vkDevice, pkePipelines.pipelines.named.texture, vkAllocator);
+ if (pkePipelines.pipelines.named.texture_wireframe != VK_NULL_HANDLE)
+ vkDestroyPipeline(vkDevice, pkePipelines.pipelines.named.texture_wireframe, vkAllocator);
+ if (pkePipelines.pipelines.named.glyph != VK_NULL_HANDLE)
+ vkDestroyPipeline(vkDevice, pkePipelines.pipelines.named.glyph, vkAllocator);
+
+ if (pkePipelines.pipe_layouts.named.texture != VK_NULL_HANDLE)
+ vkDestroyPipelineLayout(vkDevice, pkePipelines.pipe_layouts.named.texture, vkAllocator);
+ if (pkePipelines.pipe_layouts.named.glyph != VK_NULL_HANDLE)
+ vkDestroyPipelineLayout(vkDevice, pkePipelines.pipe_layouts.named.glyph, vkAllocator);
+
+ if (pkePipelines.descr_layouts.named.texture != VK_NULL_HANDLE)
+ vkDestroyDescriptorSetLayout(vkDevice, pkePipelines.descr_layouts.named.texture, vkAllocator);
+ if (pkePipelines.descr_layouts.named.glyph != VK_NULL_HANDLE)
+ vkDestroyDescriptorSetLayout(vkDevice, pkePipelines.descr_layouts.named.glyph, vkAllocator);
for (long i = 0; i < swapchainLength; ++i) {
vkDestroyBuffer(vkDevice, UniformBuffers[i], vkAllocator);