diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-01-16 14:57:16 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-01-16 14:57:16 -0500 |
| commit | 15524958f409b1f13a1deffc4dd8c1fbddefaf28 (patch) | |
| tree | 803313d44006be0f35e393e43a04b02dbed82989 | |
| parent | 727c5e90798455703b88834aa864df94837e8956 (diff) | |
pke: CompGrBinds sub-structs
| -rw-r--r-- | editor/editor.cpp | 44 | ||||
| -rw-r--r-- | src/components.hpp | 22 | ||||
| -rw-r--r-- | src/entities.cpp | 90 | ||||
| -rw-r--r-- | src/window.cpp | 8 |
4 files changed, 76 insertions, 88 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index dfa766c..e67ee12 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -1014,28 +1014,28 @@ void RecordImGui_CompGrBinds(bool readonly, CompGrBinds *component) { ImGui::InputScalarN("VkPipelineDescriptorSets", ImGuiDataType_U64, &component->vkDescriptorSets, MAX_FRAMES_IN_FLIGHT, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); } - if (component->vertexBuffer) - ImGui::InputScalar("VkVertexBuffer", ImGuiDataType_U64, &component->vertexBuffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); - ImGui::InputScalar("VertexFirstBinding", ImGuiDataType_U32, &component->vertexFirstBinding, nullptr, nullptr, nullptr, inputTextFlags); - ImGui::InputScalar("VertexBindingCount", ImGuiDataType_U32, &component->vertexBindingCount, nullptr, nullptr, nullptr, inputTextFlags); - ImGui::InputScalar("VertexOffsets", ImGuiDataType_U64, &component->vertexOffsets, nullptr, nullptr, nullptr, inputTextFlags); - - if (component->normalsBuffer) - ImGui::InputScalar("VkNormalBuffer", ImGuiDataType_U64, &component->normalsBuffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); - ImGui::InputScalar("NormalFirstBinding", ImGuiDataType_U32, &component->normalsFirstBinding, nullptr, nullptr, nullptr, inputTextFlags); - ImGui::InputScalar("NormalBindingCount", ImGuiDataType_U32, &component->normalsBindingCount, nullptr, nullptr, nullptr, inputTextFlags); - ImGui::InputScalar("NormalOffsets", ImGuiDataType_U64, &component->normalsOffsets, nullptr, nullptr, nullptr, inputTextFlags); - - if (component->uvBuffer) - ImGui::InputScalar("VkUVBuffer", ImGuiDataType_U64, &component->uvBuffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); - ImGui::InputScalar("UVFirstBinding", ImGuiDataType_U32, &component->uvFirstBinding, nullptr, nullptr, nullptr, inputTextFlags); - ImGui::InputScalar("UVBindingCount", ImGuiDataType_U32, &component->uvBindingCount, nullptr, nullptr, nullptr, inputTextFlags); - ImGui::InputScalar("UVOffsets", ImGuiDataType_U64, &component->uvOffsets, nullptr, nullptr, nullptr, inputTextFlags); - - if (component->indexBuffer) - ImGui::InputScalar("VkIndexBuffer", ImGuiDataType_U64, &component->indexBuffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); - ImGui::InputScalar("IndexBindingCount", ImGuiDataType_U32, &component->indexBindingCount, nullptr, nullptr, nullptr, inputTextFlags); - ImGui::InputScalar("IndexOffsets", ImGuiDataType_U64, &component->indexOffsets, nullptr, nullptr, nullptr, inputTextFlags); + if (component->vertexBD.buffer) + ImGui::InputScalar("VkVertexBuffer", ImGuiDataType_U64, &component->vertexBD.buffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); + ImGui::InputScalar("VertexFirstBinding", ImGuiDataType_U32, &component->vertexBD.firstBinding, nullptr, nullptr, nullptr, inputTextFlags); + ImGui::InputScalar("VertexBindingCount", ImGuiDataType_U32, &component->vertexBD.bindingCount, nullptr, nullptr, nullptr, inputTextFlags); + ImGui::InputScalar("VertexOffsets", ImGuiDataType_U64, &component->vertexBD.offsets[0], nullptr, nullptr, nullptr, inputTextFlags); + + if (component->normalsBD.buffer) + ImGui::InputScalar("VkNormalBuffer", ImGuiDataType_U64, &component->normalsBD.buffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); + ImGui::InputScalar("NormalFirstBinding", ImGuiDataType_U32, &component->normalsBD.firstBinding, nullptr, nullptr, nullptr, inputTextFlags); + ImGui::InputScalar("NormalBindingCount", ImGuiDataType_U32, &component->normalsBD.bindingCount, nullptr, nullptr, nullptr, inputTextFlags); + ImGui::InputScalar("NormalOffsets", ImGuiDataType_U64, &component->normalsBD.offsets[0], nullptr, nullptr, nullptr, inputTextFlags); + + if (component->uvBD.buffer) + ImGui::InputScalar("VkUVBuffer", ImGuiDataType_U64, &component->uvBD.buffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); + ImGui::InputScalar("UVFirstBinding", ImGuiDataType_U32, &component->uvBD.firstBinding, nullptr, nullptr, nullptr, inputTextFlags); + ImGui::InputScalar("UVBindingCount", ImGuiDataType_U32, &component->uvBD.bindingCount, nullptr, nullptr, nullptr, inputTextFlags); + ImGui::InputScalar("UVOffsets", ImGuiDataType_U64, &component->uvBD.offsets[0], nullptr, nullptr, nullptr, inputTextFlags); + + if (component->indexBD.buffer) + ImGui::InputScalar("VkIndexBuffer", ImGuiDataType_U64, &component->indexBD.buffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); + ImGui::InputScalar("IndexBindingCount", ImGuiDataType_U32, &component->indexBD.firstBinding, nullptr, nullptr, nullptr, inputTextFlags); + ImGui::InputScalar("IndexOffsets", ImGuiDataType_U64, &component->indexBD.offsets[0], nullptr, nullptr, nullptr, inputTextFlags); ImGui::InputScalar("IndexCount", ImGuiDataType_U32, &component->indexCount, nullptr, nullptr, nullptr, inputTextFlags); if (component->instanceBuffer) diff --git a/src/components.hpp b/src/components.hpp index 6b99a8b..eb891a4 100644 --- a/src/components.hpp +++ b/src/components.hpp @@ -1,7 +1,6 @@ #ifndef PKE_COMPONENTS_HPP #define PKE_COMPONENTS_HPP -#include "dynamic-array.hpp" #include "pk.h" #include "physics.hpp" #include "plugin-types.hpp" @@ -39,27 +38,16 @@ struct CompGrBinds { VkPipelineLayout vkPipelineLayout = VK_NULL_HANDLE; VkPipeline graphicsPipeline = VK_NULL_HANDLE; VkDescriptorSet *vkDescriptorSets = nullptr; - VkBuffer vertexBuffer = VK_NULL_HANDLE; - uint32_t vertexFirstBinding = 0; - uint32_t vertexBindingCount = 0; - VkDeviceSize vertexOffsets = 0; - VkBuffer normalsBuffer = VK_NULL_HANDLE; - uint32_t normalsFirstBinding = 0; - uint32_t normalsBindingCount = 0; - VkDeviceSize normalsOffsets = 0; - VkBuffer uvBuffer = VK_NULL_HANDLE; - uint32_t uvFirstBinding = 0; - uint32_t uvBindingCount = 0; - VkDeviceSize uvOffsets = 0; - VkBuffer indexBuffer = VK_NULL_HANDLE; - uint32_t indexBindingCount = 0; - VkDeviceSize indexOffsets = 0; - VkDeviceSize indexCount = 0; + BufferBindingDetails vertexBD; + BufferBindingDetails normalsBD; + BufferBindingDetails uvBD; + BufferBindingDetails indexBD; BufferBindingDetails physVertBD; BufferBindingDetails physNormBD; BufferBindingDetails physUvBD; BufferBindingDetails physIndxBD; VkBuffer instanceBuffer = VK_NULL_HANDLE; + uint32_t indexCount; uint32_t instanceFirstBinding = 0; uint32_t instanceBindingCount = 0; uint32_t instanceCounter = 0; diff --git a/src/entities.cpp b/src/entities.cpp index a81c5be..179ce4b 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -729,15 +729,15 @@ void EntityType_LoadMesh(EntityType_LoadHelperStruct &helper, const int64_t mesh const auto &accVert = helper.gltfData->accessors[accessorIndexVertex]; uint32_t offsetVert = runningOffset; uint32_t sizeVert = accVert.buffer_view->size; - etdHelper.etd->grBinds->vertexFirstBinding = index; - etdHelper.etd->grBinds->vertexBindingCount = 1; + etdHelper.etd->grBinds->vertexBD.firstBinding = index; + etdHelper.etd->grBinds->vertexBD.bindingCount = 1; alignmentPadding = sizeVert % helper.vertMemoryRequirementsCombined.alignment; alignmentPadding = alignmentPadding == 0 ? 0 : helper.vertMemoryRequirementsCombined.alignment - alignmentPadding; sizeVert += alignmentPadding; bufferCI.size = sizeVert; bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; - vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &etdHelper.etd->grBinds->vertexBuffer); - vkBindBufferMemory(vkDevice, etdHelper.etd->grBinds->vertexBuffer, helper.et.deviceMemoryVert, offsetVert); + vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &etdHelper.etd->grBinds->vertexBD.buffer); + vkBindBufferMemory(vkDevice, etdHelper.etd->grBinds->vertexBD.buffer, helper.et.deviceMemoryVert, offsetVert); runningOffset += sizeVert; index += 1; @@ -745,14 +745,14 @@ void EntityType_LoadMesh(EntityType_LoadHelperStruct &helper, const int64_t mesh const auto &accNorm = helper.gltfData->accessors[accessorIndexNormal]; uint32_t offsetNorm = runningOffset; uint32_t sizeNorm = accNorm.buffer_view->size; - etdHelper.etd->grBinds->normalsFirstBinding = index; - etdHelper.etd->grBinds->normalsBindingCount = 1; + etdHelper.etd->grBinds->normalsBD.firstBinding = index; + etdHelper.etd->grBinds->normalsBD.bindingCount = 1; alignmentPadding = sizeNorm % helper.vertMemoryRequirementsCombined.alignment; alignmentPadding = alignmentPadding == 0 ? 0 : helper.vertMemoryRequirementsCombined.alignment - alignmentPadding; sizeNorm += alignmentPadding; bufferCI.size = sizeNorm; - vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &etdHelper.etd->grBinds->normalsBuffer); - vkBindBufferMemory(vkDevice, etdHelper.etd->grBinds->normalsBuffer, helper.et.deviceMemoryVert, offsetNorm); + vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &etdHelper.etd->grBinds->normalsBD.buffer); + vkBindBufferMemory(vkDevice, etdHelper.etd->grBinds->normalsBD.buffer, helper.et.deviceMemoryVert, offsetNorm); runningOffset += sizeNorm; index += 1; @@ -760,14 +760,14 @@ void EntityType_LoadMesh(EntityType_LoadHelperStruct &helper, const int64_t mesh const auto &accUV = helper.gltfData->accessors[accessorIndexUV]; uint32_t offsetUV = runningOffset; uint32_t sizeUV = accUV.buffer_view->size; - etdHelper.etd->grBinds->uvFirstBinding = index; - etdHelper.etd->grBinds->uvBindingCount = 1; + etdHelper.etd->grBinds->uvBD.firstBinding = index; + etdHelper.etd->grBinds->uvBD.bindingCount = 1; alignmentPadding = sizeUV % helper.vertMemoryRequirementsCombined.alignment; alignmentPadding = alignmentPadding == 0 ? 0 : helper.vertMemoryRequirementsCombined.alignment - alignmentPadding; sizeUV += alignmentPadding; bufferCI.size = sizeUV; - vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &etdHelper.etd->grBinds->uvBuffer); - vkBindBufferMemory(vkDevice, etdHelper.etd->grBinds->uvBuffer , helper.et.deviceMemoryVert, offsetUV); + vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &etdHelper.etd->grBinds->uvBD.buffer); + vkBindBufferMemory(vkDevice, etdHelper.etd->grBinds->uvBD.buffer, helper.et.deviceMemoryVert, offsetUV); runningOffset += sizeUV; index += 1; @@ -782,15 +782,15 @@ void EntityType_LoadMesh(EntityType_LoadHelperStruct &helper, const int64_t mesh const auto &accIndex = helper.gltfData->accessors[accessorIndexIndex]; uint32_t offsetIndex = runningOffset; uint32_t sizeIndex = accIndex.buffer_view->size; - etdHelper.etd->grBinds->indexBindingCount = 1; + etdHelper.etd->grBinds->indexBD.bindingCount = 1; etdHelper.etd->grBinds->indexCount = accIndex.count; alignmentPadding = sizeIndex % helper.vertMemoryRequirementsCombined.alignment; alignmentPadding = alignmentPadding == 0 ? 0 : helper.vertMemoryRequirementsCombined.alignment - alignmentPadding; sizeIndex += alignmentPadding; bufferCI.size = sizeIndex; bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT; - vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &etdHelper.etd->grBinds->indexBuffer); - vkBindBufferMemory(vkDevice, etdHelper.etd->grBinds->indexBuffer, helper.et.deviceMemoryVert, offsetIndex); + vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &etdHelper.etd->grBinds->indexBD.buffer); + vkBindBufferMemory(vkDevice, etdHelper.etd->grBinds->indexBD.buffer, helper.et.deviceMemoryVert, offsetIndex); runningOffset += sizeIndex; // index += 1; @@ -837,22 +837,22 @@ void EntityType_LoadMesh(EntityType_LoadHelperStruct &helper, const int64_t mesh index = 0; bufferCopys[index].srcOffset = offsetVert; bufferCopys[index].size = sizeVert; - vkCmdCopyBuffer(transferCommandBuffer, transferBuffer, etdHelper.etd->grBinds->vertexBuffer, 1, &bufferCopys[index]); + vkCmdCopyBuffer(transferCommandBuffer, transferBuffer, etdHelper.etd->grBinds->vertexBD.buffer, 1, &bufferCopys[index]); index+=1; bufferCopys[index].srcOffset = offsetNorm; bufferCopys[index].size = sizeNorm; - vkCmdCopyBuffer(transferCommandBuffer, transferBuffer, etdHelper.etd->grBinds->normalsBuffer, 1, &bufferCopys[index]); + vkCmdCopyBuffer(transferCommandBuffer, transferBuffer, etdHelper.etd->grBinds->normalsBD.buffer, 1, &bufferCopys[index]); index+=1; bufferCopys[index].srcOffset = offsetUV; bufferCopys[index].size = sizeUV; - vkCmdCopyBuffer(transferCommandBuffer, transferBuffer, etdHelper.etd->grBinds->uvBuffer, 1, &bufferCopys[index]); + vkCmdCopyBuffer(transferCommandBuffer, transferBuffer, etdHelper.etd->grBinds->uvBD.buffer, 1, &bufferCopys[index]); index+=1; bufferCopys[index].srcOffset = offsetIndex; bufferCopys[index].size = sizeIndex; - vkCmdCopyBuffer(transferCommandBuffer, transferBuffer, etdHelper.etd->grBinds->indexBuffer, 1, &bufferCopys[index]); + vkCmdCopyBuffer(transferCommandBuffer, transferBuffer, etdHelper.etd->grBinds->indexBD.buffer, 1, &bufferCopys[index]); // index+=1; vkEndCommandBuffer(transferCommandBuffer); @@ -1129,32 +1129,32 @@ void EntityType_Unload(EntityType &et, CompGrBinds *grBindsArr[1]) { vkDestroyDescriptorPool(vkDevice, etd.vkDescriptorPool, vkAllocator); grBinds->vkDescriptorSets = CAFE_BABE(VkDescriptorSet); } - if (grBinds->vertexBuffer != VK_NULL_HANDLE) - vkDestroyBuffer(vkDevice, grBinds->vertexBuffer, vkAllocator); - grBinds->vertexBuffer = VK_NULL_HANDLE; - grBinds->vertexFirstBinding = 0; - grBinds->vertexBindingCount = 0; - grBinds->vertexOffsets = 0; - - if (grBinds->normalsBuffer != VK_NULL_HANDLE) - vkDestroyBuffer(vkDevice, grBinds->normalsBuffer, vkAllocator); - grBinds->normalsBuffer = VK_NULL_HANDLE; - grBinds->normalsFirstBinding = 0; - grBinds->normalsBindingCount = 0; - grBinds->normalsOffsets = 0; - - if (grBinds->uvBuffer != VK_NULL_HANDLE) - vkDestroyBuffer(vkDevice, grBinds->uvBuffer, vkAllocator); - grBinds->uvBuffer = VK_NULL_HANDLE; - grBinds->uvFirstBinding = 0; - grBinds->uvBindingCount = 0; - grBinds->uvOffsets = 0; - - if (grBinds->indexBuffer != VK_NULL_HANDLE) - vkDestroyBuffer(vkDevice, grBinds->indexBuffer, vkAllocator); - grBinds->indexBuffer = VK_NULL_HANDLE; - grBinds->indexBindingCount = 0; - grBinds->indexOffsets = 0; + if (grBinds->vertexBD.buffer != VK_NULL_HANDLE) + vkDestroyBuffer(vkDevice, grBinds->vertexBD.buffer, vkAllocator); + grBinds->vertexBD.buffer = VK_NULL_HANDLE; + grBinds->vertexBD.firstBinding = 0; + grBinds->vertexBD.bindingCount = 0; + grBinds->vertexBD.offsets[0] = 0; + + if (grBinds->normalsBD.buffer != VK_NULL_HANDLE) + vkDestroyBuffer(vkDevice, grBinds->normalsBD.buffer, vkAllocator); + grBinds->normalsBD.buffer = VK_NULL_HANDLE; + grBinds->normalsBD.firstBinding = 0; + grBinds->normalsBD.bindingCount = 0; + grBinds->normalsBD.offsets[0] = 0; + + if (grBinds->uvBD.buffer != VK_NULL_HANDLE) + vkDestroyBuffer(vkDevice, grBinds->uvBD.buffer, vkAllocator); + grBinds->uvBD.buffer = VK_NULL_HANDLE; + grBinds->uvBD.firstBinding = 0; + grBinds->uvBD.bindingCount = 0; + grBinds->uvBD.offsets[0] = 0; + + if (grBinds->indexBD.buffer != VK_NULL_HANDLE) + vkDestroyBuffer(vkDevice, grBinds->indexBD.buffer, vkAllocator); + grBinds->indexBD.buffer = VK_NULL_HANDLE; + grBinds->indexBD.bindingCount = 0; + grBinds->indexBD.offsets[0] = 0; grBinds->indexCount = 0; if (grBinds->physVertBD.buffer != VK_NULL_HANDLE) diff --git a/src/window.cpp b/src/window.cpp index 215fd0d..b83ef9a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2469,11 +2469,11 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) { vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, binder->graphicsPipeline); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, binder->vkPipelineLayout, 0, 1, &binder->vkDescriptorSets[imageIndex], 0, {}); vkCmdBindVertexBuffers(commandBuffer, 0, 1, &UniformBuffers[imageIndex], offsets); - vkCmdBindIndexBuffer(commandBuffer, binder->indexBuffer, binder->indexOffsets, VK_INDEX_TYPE_UINT16); + vkCmdBindIndexBuffer(commandBuffer, binder->indexBD.buffer, binder->indexBD.offsets[0], VK_INDEX_TYPE_UINT16); - vkCmdBindVertexBuffers(commandBuffer, binder->vertexFirstBinding, binder->vertexBindingCount, &binder->vertexBuffer, &binder->vertexOffsets); - vkCmdBindVertexBuffers(commandBuffer, binder->normalsFirstBinding, binder->normalsBindingCount, &binder->normalsBuffer, &binder->normalsOffsets); - vkCmdBindVertexBuffers(commandBuffer, binder->uvFirstBinding, binder->uvBindingCount, &binder->uvBuffer, &binder->uvOffsets); + 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); vkCmdDrawIndexed(commandBuffer, binder->indexCount, binder->instanceCounter, 0, 0, 0); |
