diff options
| -rw-r--r-- | src/components.hpp | 2 | ||||
| -rw-r--r-- | src/ecs.cpp | 1 | ||||
| -rw-r--r-- | src/entities.cpp | 18 | ||||
| -rw-r--r-- | src/game.cpp | 1 | ||||
| -rw-r--r-- | src/window.cpp | 20 |
5 files changed, 28 insertions, 14 deletions
diff --git a/src/components.hpp b/src/components.hpp index 40c8aae..06477da 100644 --- a/src/components.hpp +++ b/src/components.hpp @@ -32,6 +32,7 @@ struct CompGrBinds { EntityHandle entHandle = EntityHandle_MAX; GrBindsHandle grBindsHandle = GrBindsHandle_MAX; VkPipelineLayout vkPipelineLayout = VK_NULL_HANDLE; + VkPipeline graphicsPipeline = VK_NULL_HANDLE; VkDescriptorSet *vkDescriptorSets = nullptr; VkBuffer vertexBuffer = VK_NULL_HANDLE; uint32_t vertexFirstBinding = 0; @@ -46,7 +47,6 @@ struct CompGrBinds { uint32_t uvBindingCount = 0; VkDeviceSize uvOffsets = 0; VkBuffer indexBuffer = VK_NULL_HANDLE; - uint32_t indexFirstBinding = 0; uint32_t indexBindingCount = 0; VkDeviceSize indexOffsets = 0; VkDeviceSize indexCount = 0; diff --git a/src/ecs.cpp b/src/ecs.cpp index bbb1a70..600eaa4 100644 --- a/src/ecs.cpp +++ b/src/ecs.cpp @@ -265,6 +265,7 @@ CompInstance &ECS_CreateInstance(EntityHandle entHandle, EntityHandle entityType auto i2 = Buckets_GetItemIndex(grBindsHandle_t); auto *grBinds = &Comp_GrBinds_BucketContainer.buckets[b2].compGrBinds[i2]; grBinds->isInstanceBufferNeedingUpdated = true; + grBinds->instanceBindingCount = 1; auto b = Buckets_GetBucketIndex(newHandle); auto i = Buckets_GetItemIndex(newHandle); auto *comp = &Comp_Instance_BucketContainer.buckets[b].instances[i]; diff --git a/src/entities.cpp b/src/entities.cpp index 1b85784..5afd985 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -75,26 +75,28 @@ void EntityType_Init() { const long vertexBindingCount = 4; long index = 0; VkVertexInputBindingDescription vertInputBD[vertexBindingCount]; - for (long i = 0; i < vertexBindingCount; ++i) { - vertInputBD[i].binding = i; - } // 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; + // vertInputBD[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; // index += 1; // instance + vertInputBD[index].binding = index; vertInputBD[index].stride = sizeof(glm::vec3) * 3; vertInputBD[index].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE; @@ -355,6 +357,7 @@ void EntityType_Load(EntityType &et) { * This should be moved to window.cpp. */ grBinds.vkPipelineLayout = vkPipelineLayout_Texture; + grBinds.graphicsPipeline = vkPipelines.Texture; cgltf_options options{}; // TODO allocator @@ -679,6 +682,7 @@ void EntityType_Load(EntityType &et) { long index = 0; if (et.Importer_GLTF.AccessorIndexVertex > -1) { const auto &acc = gltfData->accessors[et.Importer_GLTF.AccessorIndexVertex]; + grBinds.vertexFirstBinding = index; grBinds.vertexBindingCount = 1; bufferCI.size = acc.buffer_view->size; bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; @@ -688,6 +692,7 @@ void EntityType_Load(EntityType &et) { } if (et.Importer_GLTF.AccessorIndexNormal > -1) { const auto &acc = gltfData->accessors[et.Importer_GLTF.AccessorIndexNormal]; + grBinds.normalsFirstBinding = index; grBinds.normalsBindingCount = 1; bufferCI.size = acc.buffer_view->size; vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &grBinds.normalsBuffer); @@ -696,14 +701,19 @@ void EntityType_Load(EntityType &et) { } if (et.Importer_GLTF.AccessorIndexUV > -1) { const auto &acc = gltfData->accessors[et.Importer_GLTF.AccessorIndexUV]; + grBinds.uvFirstBinding = index; grBinds.uvBindingCount = 1; bufferCI.size = acc.buffer_view->size; vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &grBinds.uvBuffer); vkGetBufferMemoryRequirements(vkDevice, grBinds.uvBuffer, &vkMemoryRequirements[index++]); } + // 2023-09-27 - JCB + // I don't know where else to put this + grBinds.instanceFirstBinding = index; if (et.Importer_GLTF.AccessorIndexIndex > -1) { const auto &acc = gltfData->accessors[et.Importer_GLTF.AccessorIndexIndex]; + // grBinds.indexFirstBinding = index; grBinds.indexBindingCount = 1; grBinds.indexCount = acc.count; bufferCI.size = acc.buffer_view->size; diff --git a/src/game.cpp b/src/game.cpp index 21b460f..2c87818 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -400,7 +400,6 @@ void RecordImGui_CompGrBinds(bool readonly, CompGrBinds *component) { if (component->indexBuffer) ImGui::InputScalar("VkIndexBuffer", ImGuiDataType_U64, &component->indexBuffer, nullptr, nullptr, "0x%016lX", ImGuiInputTextFlags_ReadOnly); - ImGui::InputScalar("IndexFirstBinding", ImGuiDataType_U32, &component->indexFirstBinding, nullptr, nullptr, nullptr, inputTextFlags); ImGui::InputScalar("IndexBindingCount", ImGuiDataType_U32, &component->indexBindingCount, nullptr, nullptr, nullptr, inputTextFlags); ImGui::InputScalar("IndexOffsets", ImGuiDataType_U64, &component->indexOffsets, nullptr, nullptr, nullptr, inputTextFlags); ImGui::InputScalar("IndexCount", ImGuiDataType_U32, &component->indexCount, nullptr, nullptr, nullptr, inputTextFlags); diff --git a/src/window.cpp b/src/window.cpp index 66e2095..5598e56 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1351,6 +1351,8 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) { vkCmdSetViewport(commandBuffer, 0, 1, &viewport); vkCmdSetScissor(commandBuffer, 0, 1, &scissor); + VkDeviceSize offsets[1] = {0U}; + const uint64_t bindBucketCount = ECS_GetGrBinds_BucketCount(); for (long b = 0; b < bindBucketCount; ++b) { uint64_t itemCount; @@ -1359,16 +1361,18 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) { CompGrBinds *binder = &items[i]; if (!binder->vkPipelineLayout) continue; + if (binder->instanceBindingCount < 1) { + continue; + } + vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, binder->graphicsPipeline); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, binder->vkPipelineLayout, 0, 1, &binder->vkDescriptorSets[CURRENT_FRAME], 0, {}); + vkCmdBindVertexBuffers(commandBuffer, 0, 1, &UniformBuffers[CURRENT_FRAME], offsets); + vkCmdBindIndexBuffer(commandBuffer, binder->indexBuffer, binder->indexOffsets, VK_INDEX_TYPE_UINT16); + vkCmdBindVertexBuffers(commandBuffer, binder->vertexFirstBinding, binder->vertexBindingCount, &binder->vertexBuffer, &binder->vertexOffsets); - if (binder->normalsBindingCount > 0) - vkCmdBindVertexBuffers(commandBuffer, binder->normalsFirstBinding, binder->normalsBindingCount, &binder->normalsBuffer, &binder->normalsOffsets); - if (binder->uvBindingCount > 0) - vkCmdBindVertexBuffers(commandBuffer, binder->uvFirstBinding, binder->uvBindingCount, &binder->uvBuffer, &binder->uvOffsets); - if (binder->indexBindingCount > 0) - vkCmdBindIndexBuffer(commandBuffer, binder->indexBuffer, binder->vertexOffsets, VK_INDEX_TYPE_UINT16); - - vkCmdBindVertexBuffers(commandBuffer, binder->indexFirstBinding, binder->instanceBindingCount, &binder->instanceBuffer, &binder->instanceOffsets); + vkCmdBindVertexBuffers(commandBuffer, binder->normalsFirstBinding, binder->normalsBindingCount, &binder->normalsBuffer, &binder->normalsOffsets); + vkCmdBindVertexBuffers(commandBuffer, binder->uvFirstBinding, binder->uvBindingCount, &binder->uvBuffer, &binder->uvOffsets); + vkCmdBindVertexBuffers(commandBuffer, binder->instanceFirstBinding, binder->instanceBindingCount, &binder->instanceBuffer, &binder->instanceOffsets); vkCmdDrawIndexed(commandBuffer, binder->indexCount, binder->instances.Count(), 0, 0, 0); } |
