summaryrefslogtreecommitdiff
path: root/src/entities.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-09-15 08:17:57 -0400
committerJonathan Bradley <jcb@pikum.xyz>2023-09-15 08:20:56 -0400
commit766271e601a614a0692366f4caa053b172c2210b (patch)
treeafa832438a5e3caaa2e9b90927ea37e95b0a0ccc /src/entities.cpp
parentde0814665281ab14db1ad4ee1ad1832b7143c131 (diff)
cleanup commit - use transfer buffer & release our memory
Diffstat (limited to 'src/entities.cpp')
-rw-r--r--src/entities.cpp34
1 files changed, 6 insertions, 28 deletions
diff --git a/src/entities.cpp b/src/entities.cpp
index 200c28e..15b2b76 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -128,8 +128,6 @@ void EntityType_Init() {
void EntityType_Load(EntityType &et) {
assert(et.startingInstanceCount > 0);
if (et.modelFile != nullptr && et.modelFile != CAFE_BABE(char)) {
- // assert(et.vkDescriptorSetLayoutCreateInfo != nullptr && et.vkDescriptorSetLayoutCreateInfo != CAFE_BABE(VkDescriptorSetLayoutCreateInfo) && "EntityType with a defined model must also contain appropriate Vulkan CreateInfos");
- // assert(et.vkPipelineLayoutCreateInfo != nullptr && et.vkPipelineLayoutCreateInfo != CAFE_BABE(VkPipelineLayoutCreateInfo) && "EntityType with a defined model must also contain appropriate Vulkan CreateInfos");
char modelPath[128];
memset(modelPath, '\0', 128);
@@ -144,25 +142,18 @@ void EntityType_Load(EntityType &et) {
* This should be moved to window.cpp.
*/
grBinds.vkPipelineLayout = vkPipelineLayout_Texture;
- // et.textureSampler = vkPipelineLayout_Texture;
- // VkResult vkResult = vkCreateDescriptorSetLayout(vkDevice, et.vkDescriptorSetLayoutCreateInfo, vkAllocator, &grBinds.vkDescriptorSetLayout);
- // assert(vkResult == VK_SUCCESS);
- // vkResult = vkCreatePipelineLayout(vkDevice, et.vkPipelineLayoutCreateInfo, vkAllocator, &grBinds.vkPipelineLayout);
- // assert(vkResult == VK_SUCCESS);
cgltf_options options{};
// TODO allocator
cgltf_data *gltfData = nullptr;
cgltf_result result = cgltf_parse(&options, asset->ptr, asset->size, &gltfData);
assert(result == cgltf_result_success);
- // TODO consider using AssetHandler OR loading this directly to the GPU
result = cgltf_load_buffers(&options, gltfData, modelPath);
assert(result == cgltf_result_success);
result = cgltf_validate(gltfData);
assert(result == cgltf_result_success);
assert(gltfData->images_count < 2);
- // AssetHandle textureAssetHandle = AssetHandle_MAX;
if (gltfData->images_count == 1) {
char imagePath[128];
memset(imagePath, '\0', 128);
@@ -174,7 +165,6 @@ void EntityType_Load(EntityType &et) {
uint32_t imageSizeBytes = pixelWidth * pixelHeight * pixelChannels;
AssetHandle textureAssetHandle{AM_Register(pixels, imageSizeBytes, imagePath)};
- const Asset *textureAsset = AM_Get(textureAssetHandle);
VkFormat imageFormat = VK_FORMAT_R8G8B8A8_SRGB;
if (pixelChannels == 3) {
@@ -248,6 +238,7 @@ void EntityType_Load(EntityType &et) {
};
vkCreateImageView(vkDevice, &vkImageViewCreateInfo, vkAllocator, &et.textureImageView);
+ AM_Destroy(textureAssetHandle);
// transition image layout and copy to buffer
VkBuffer transferImageBuffer;
@@ -499,23 +490,11 @@ void EntityType_Load(EntityType &et) {
// create transfer items && transfer
{
- // reminder that we don't need to do instance here, because we're just
- // setting up the type. No instances have been created yet.
VkDeviceMemory transferDeviceMemory;
VkBuffer transferBuffer;
- VkMemoryRequirements vkMemoryRequirementsTransfer;
-
- bufferCI.size = combinedMemReqs.size;
- bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
- vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &transferBuffer);
- vkGetBufferMemoryRequirements(vkDevice, transferBuffer, &vkMemoryRequirementsTransfer);
- vkMemoryAllocateInfo.memoryTypeIndex = FindMemoryTypeIndex(vkMemoryRequirementsTransfer.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
- // note, this should be identical (other than memory type) to the dst buffer
- vkAllocateMemory(vkDevice, &vkMemoryAllocateInfo, vkAllocator, &transferDeviceMemory);
- vkBindBufferMemory(vkDevice, transferBuffer, transferDeviceMemory, 0);
void *data;
- vkMapMemory(vkDevice, transferDeviceMemory, 0, combinedMemReqs.size, 0, &data);
- // memcpy(data, gltfData->buffers[0].data, vkMemoryRequirements.size);
+ BeginTransferBuffer(combinedMemReqs.size, transferBuffer, transferDeviceMemory, data);
+
uint32_t runningOffset2 = 0;
if (et.Importer_GLTF.AccessorIndexVertex > -1) {
const auto &acc = gltfData->accessors[et.Importer_GLTF.AccessorIndexVertex];
@@ -544,7 +523,6 @@ void EntityType_Load(EntityType &et) {
char *srcPtr = static_cast<char *>(gltfData->buffers[0].data) + acc.buffer_view->offset;
memcpy(dstPtr, srcPtr, acc.buffer_view->size);
}
- vkUnmapMemory(vkDevice, transferDeviceMemory);
VkCommandBufferBeginInfo vkCommandBufferBeginInfo;
vkCommandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -557,7 +535,7 @@ void EntityType_Load(EntityType &et) {
for (long i = 0; i < 4; ++i) {
bufferCopys[i].dstOffset = 0;
}
- long index = 0;
+ index = 0;
if (et.Importer_GLTF.AccessorIndexVertex > -1) {
const auto &acc = gltfData->accessors[et.Importer_GLTF.AccessorIndexVertex];
bufferCopys[index].srcOffset = acc.buffer_view->offset;
@@ -601,8 +579,7 @@ void EntityType_Load(EntityType &et) {
vkQueueSubmit(transferQueue, 1, &submitInfo, nullptr);
vkQueueWaitIdle(transferQueue);
- vkDestroyBuffer(vkDevice, transferBuffer, vkAllocator);
- vkFreeMemory(vkDevice, transferDeviceMemory, vkAllocator);
+ EndTransferBuffer(transferBuffer, transferDeviceMemory);
}
// set up instance buffer
@@ -618,6 +595,7 @@ void EntityType_Load(EntityType &et) {
// cleanup
cgltf_free(gltfData);
+ AM_Destroy(assetHandle);
}
}