Fix mixed up image counts

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-02 03:59:16 +01:00
1 parent 3806fa97a3
commit 16c4fe3704
1 file changed
+15 -15
+15 -15
View File
@@ -285,17 +285,17 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
}
// Select image count
uint32_t swapchain_img_count = surface_caps.minImageCount + 1;
assert(swapchain_img_count <= MAX_FRAMES_IN_FLIGHT);
uint32_t min_swapchain_img_count = surface_caps.minImageCount + 1;
assert(min_swapchain_img_count <= MAX_FRAMES_IN_FLIGHT);
assert(
surface_caps.maxImageCount == 0
|| swapchain_img_count <= surface_caps.maxImageCount);
|| min_swapchain_img_count <= surface_caps.maxImageCount);
// Create the swap chain
const VkSwapchainCreateInfoKHR swapchain_create_info = {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
.surface = ctx->surface,
.minImageCount = swapchain_img_count,
.minImageCount = min_swapchain_img_count,
.imageFormat = surface_fmt.format,
.imageColorSpace = surface_fmt.colorSpace,
.imageExtent = ctx->swapchain_extent,
@@ -316,7 +316,7 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
VkImage swapchain_imgs[MAX_FRAMES_IN_FLIGHT];
ctx->swapchain_img_count = MAX_FRAMES_IN_FLIGHT;
result = vkGetSwapchainImagesKHR(
ctx->dev, ctx->swapchain, &swapchain_img_count, swapchain_imgs);
ctx->dev, ctx->swapchain, &ctx->swapchain_img_count, swapchain_imgs);
assert(result == VK_SUCCESS);
// Create swapchain image views
@@ -338,7 +338,7 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
.layerCount = 1,
},
};
for (unsigned i = 0; i < swapchain_img_count; ++i) {
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
img_view_create_info.image = swapchain_imgs[i];
result = vkCreateImageView(
ctx->dev, &img_view_create_info, nullptr,
@@ -441,22 +441,22 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
.poolSizeCount = 1,
.pPoolSizes = &(VkDescriptorPoolSize) {
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 2 * swapchain_img_count,
.descriptorCount = 2 * ctx->swapchain_img_count,
},
.maxSets = 2 * swapchain_img_count,
.maxSets = 2 * ctx->swapchain_img_count,
};
result = vkCreateDescriptorPool(
ctx->dev, &desc_pool_config, nullptr, &ctx->desc_pool);
assert(result == VK_SUCCESS);
// Create and configure descriptor sets
VkDescriptorSetLayout desc_set_layouts[swapchain_img_count];
for (unsigned i = 0; i < swapchain_img_count; ++i)
VkDescriptorSetLayout desc_set_layouts[ctx->swapchain_img_count];
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i)
desc_set_layouts[i] = ctx->desc_set_layout;
const VkDescriptorSetAllocateInfo desc_sets_alloc_config = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.descriptorPool = ctx->desc_pool,
.descriptorSetCount = swapchain_img_count,
.descriptorSetCount = ctx->swapchain_img_count,
.pSetLayouts = desc_set_layouts,
};
result = vkAllocateDescriptorSets(
@@ -464,7 +464,7 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
assert(result == VK_SUCCESS);
// Create and map MVP buffer
const size_t mvp_buffer_size = swapchain_img_count * sizeof(mvp_t);
const size_t mvp_buffer_size = ctx->swapchain_img_count * sizeof(mvp_t);
create_buffer(
ctx, mvp_buffer_size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
@@ -476,7 +476,7 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
// Create and map bone matrix buffer
const size_t bone_matrix_buffer_size
= swapchain_img_count * model.bone_count * sizeof(mat4_t);
= ctx->swapchain_img_count * model.bone_count * sizeof(mat4_t);
create_buffer(
ctx, bone_matrix_buffer_size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
@@ -487,7 +487,7 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
(void **)&ctx->bone_matrices);
// Configure descriptor sets to use MVP and bone matrix buffers
for (unsigned i = 0; i < swapchain_img_count; ++i) {
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
const VkWriteDescriptorSet desc_writes[] = {
{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
@@ -718,7 +718,7 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
assert(result == VK_SUCCESS);
// Create framebuffers
for (unsigned i = 0; i < swapchain_img_count; ++i) {
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
VkImageView attachments[] = {
ctx->swapchain_img_views[i],
ctx->depth_img_view,