Skip to content

Commit

Permalink
Adding some debug logging for beginning to hunt down sync errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Honeybunch committed Nov 25, 2024
1 parent b83d98e commit ab619dc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/tb_render_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ typedef struct TbBufferImageCopy {
VkImage dst;
VkBufferImageCopy region;
VkImageSubresourceRange range;
const char *src_name;
const char *dst_name;
} TbBufferImageCopy;

typedef TB_QUEUE_OF(VkWriteDescriptorSet) TbSetWriteQueue;
Expand Down
17 changes: 14 additions & 3 deletions source/tb_render_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,10 @@ VkResult alloc_host_buffer(TbRenderSystem *self,

VmaAllocationCreateInfo alloc_create_info = {
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
.pUserData = (void *)name,
};
VkResult err =
vmaCreateBuffer(vma_alloc, create_info, &alloc_create_info,
Expand All @@ -406,7 +408,9 @@ VkResult tb_rnd_sys_alloc_gpu_buffer(TbRenderSystem *self,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT |
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT,
VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT |
VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT,
.pUserData = (void *)name,
};

VkResult err =
Expand Down Expand Up @@ -434,7 +438,8 @@ VkResult tb_rnd_sys_alloc_gpu_image(TbRenderSystem *self,
VmaAllocator vma_alloc = self->vma_alloc;
VmaAllocationCreateInfo alloc_create_info = {
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
.flags = vma_flags,
.flags = vma_flags | VMA_ALLOCATION_CREATE_USER_DATA_COPY_STRING_BIT,
.pUserData = (void *)name,
};
VkResult err = vmaCreateImage(vma_alloc, create_info, &alloc_create_info,
&image->image, &image->alloc, &image->info);
Expand Down Expand Up @@ -645,6 +650,8 @@ VkResult tb_rnd_sys_create_gpu_image_tmp(TbRenderSystem *self, const void *data,
TbBufferImageCopy copy = {
.src = buffer,
.dst = image->image,
.src_name = "GpuTMP",
.dst_name = (const char *)image->info.pName,
.region =
{
.bufferOffset = offset,
Expand Down Expand Up @@ -864,8 +871,12 @@ void tb_rnd_upload_buffers(TbRenderSystem *self, TbBufferCopy *uploads,
void tb_rnd_upload_buffer_to_image(TbRenderSystem *self,
TbBufferImageCopy *uploads,
uint32_t upload_count) {

TbRenderSystemFrameState *state = &self->frame_states[self->frame_idx];
for (uint32_t i = 0; i < upload_count; ++i) {
TB_LOG_DEBUG(TB_LOG_CATEGORY_RENDER_THREAD,
"Scheduling buffer [%s] to image [%s] upload for frame %d",
uploads[i].src_name, uploads[i].dst_name, self->frame_idx);
TB_QUEUE_PUSH(state->buf_img_copy_queue, uploads[i])
}
}
Expand Down
7 changes: 7 additions & 0 deletions source/tb_render_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,13 @@ bool init_swapchain(SDL_Window *window, VkDevice device, VkPhysicalDevice gpu,
}
}

if (swapchain_extent.width > surf_caps.maxImageExtent.width) {
swapchain_extent.width = surf_caps.maxImageExtent.width;
}
if (swapchain_extent.height > surf_caps.maxImageExtent.height) {
swapchain_extent.height = surf_caps.maxImageExtent.height;
}

VkSwapchainCreateInfoKHR create_info = {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
.surface = surface,
Expand Down
8 changes: 8 additions & 0 deletions source/tb_texture_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ ECS_TAG_DECLARE(TbTextureLoaded);
typedef struct KTX2IterData {
VkBuffer buffer;
VkImage image;
const char *buffer_name;
const char *image_name;
TbBufferImageCopy *uploads;
uint64_t offset;
} KTX2IterData;
Expand All @@ -82,6 +84,8 @@ ktx_error_code_e iterate_ktx2_levels(int32_t mip_level, int32_t face,
user_data->uploads[mip_level] = (TbBufferImageCopy){
.src = user_data->buffer,
.dst = user_data->image,
.src_name = user_data->buffer_name,
.dst_name = user_data->image_name,
.region =
{
.bufferOffset = user_data->offset,
Expand Down Expand Up @@ -233,6 +237,8 @@ TbTextureImage tb_load_ktx_image(TbRenderSystem *rnd_sys, const char *name,
KTX2IterData iter_data = {
.buffer = texture.host_buffer.buffer,
.image = texture.gpu_image.image,
.buffer_name = texture.host_buffer.info.pName,
.image_name = texture.gpu_image.info.pName,
.offset = texture.host_buffer.offset,
.uploads = uploads,
};
Expand Down Expand Up @@ -364,6 +370,8 @@ TbTextureImage tb_load_raw_image(TbRenderSystem *rnd_sys, const char *name,
uploads[0] = (TbBufferImageCopy){
.src = texture.host_buffer.buffer,
.dst = texture.gpu_image.image,
.src_name = texture.host_buffer.info.pName,
.dst_name = texture.gpu_image.info.pName,
.region =
{
.bufferOffset = texture.host_buffer.offset,
Expand Down

0 comments on commit ab619dc

Please sign in to comment.