Skip to content

Commit c9f0417

Browse files
committed
Fix undersized AS scratch buffer on first allocation
1 parent 88dfa4c commit c9f0417

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

Quake/r_brush.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ static vulkan_memory_t bmodel_as_device_memory;
112112
static VkAccelerationStructureKHR tlas_garbage[TLAS_GARBAGE_FRAME_COUNT];
113113
static int tlas_garbage_index;
114114

115-
#define INITIAL_SCRATCH_BUFFER_SIZE_MB 8
115+
#define MIN_SCRATCH_BUFFER_SIZE_MB 8
116116

117117
// Shared scratch buffer for all AS operations (bmodel BLAS build, TLAS build, animated BLAS updates)
118118
dynbuffer_t as_scratch_buffer;
119119
static vulkan_memory_t as_scratch_memory;
120-
uint32_t as_scratch_buffer_size = INITIAL_SCRATCH_BUFFER_SIZE_MB * 1024 * 1024;
120+
uint32_t as_scratch_buffer_size;
121121

122122
/*
123123
===============
@@ -130,10 +130,8 @@ void R_EnsureASScratchBufferSize (uint32_t required_size)
130130
return;
131131

132132
if (as_scratch_buffer.buffer != VK_NULL_HANDLE)
133-
{
134133
R_AddDynamicBufferGarbage (as_scratch_memory, &as_scratch_buffer, 1, NULL);
135-
as_scratch_buffer_size = q_max (as_scratch_buffer_size * 2, Q_nextPow2 (required_size));
136-
}
134+
as_scratch_buffer_size = Q_nextPow2 (q_max (required_size, MIN_SCRATCH_BUFFER_SIZE_MB * 1024 * 1024));
137135

138136
Sys_Printf ("Reallocating dynamic AS scratch buffer (%u KB)\n", as_scratch_buffer_size / 1024);
139137

0 commit comments

Comments
 (0)