ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

Commit: e3fdaace41c864d779e9c5ebc7405afe43bc4734
Parent: 6fabb5b95ffffb95026f62b9e907ca408f5e65af
Author: Randy Palamar
Date:   Thu, 12 Mar 2026 06:04:42 -0600

vulkan: workaround renderdoc bug with very large buffers

I think its the wrong attitude for a debugger to claim that a
completely valid usage of the API won't be handled and will just
result in the debugger crashing but its well within their right to
do so. I will just continue to complain about it. I'm sure this
bug will be reported again by someone else in the future.

Diffstat:
Mbeamformer.c | 6++++++
Mbeamformer_core.c | 22----------------------
Mbeamformer_internal.h | 15++++++++++++++-
Mvulkan.c | 9+++++++--
4 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/beamformer.c b/beamformer.c @@ -184,6 +184,12 @@ beamformer_init(BeamformerInput *input) ctx->compute_worker.arena = compute_arena; ctx->upload_worker.arena = upload_arena; + #if BEAMFORMER_RENDERDOC_HOOKS + start_frame_capture = input->renderdoc_start_frame_capture; + end_frame_capture = input->renderdoc_end_frame_capture; + set_capture_path_template = input->renderdoc_set_capture_file_path_template; + #endif + vk_load(input->vulkan_library_handle, &memory, &ctx->error_stream); BeamformerComputeContext *cs = &ctx->compute_context; diff --git a/beamformer_core.c b/beamformer_core.c @@ -27,22 +27,6 @@ global f32 dt_for_frame; -#if !BEAMFORMER_RENDERDOC_HOOKS -#define start_renderdoc_capture(...) -#define end_renderdoc_capture(...) -#define renderdoc_attached(...) (0) -#else -global renderdoc_start_frame_capture_fn *start_frame_capture; -global renderdoc_set_capture_path_template_fn *set_capture_path_template; -global renderdoc_end_frame_capture_fn *end_frame_capture; -#define start_renderdoc_capture() do { \ - if (set_capture_path_template) set_capture_path_template("captures/ogl.rdc"); \ - if (start_frame_capture) start_frame_capture(vk_renderdoc_instance_handle(), 0); \ -} while(0) -#define end_renderdoc_capture() if (end_frame_capture) end_frame_capture(vk_renderdoc_instance_handle(), 0) -#define renderdoc_attached(...) (start_frame_capture != 0) -#endif - read_only global u32 beamformer_compute_array_parameter_sizes[] = { #define X(k, type, elements) sizeof(type) * elements, BEAMFORMER_COMPUTE_ARRAY_PARAMETERS_LIST @@ -1429,12 +1413,6 @@ beamformer_process_input_events(BeamformerCtx *ctx, BeamformerInput *input, ctx->arena); } } - - #if BEAMFORMER_RENDERDOC_HOOKS - start_frame_capture = input->renderdoc_start_frame_capture; - end_frame_capture = input->renderdoc_end_frame_capture; - set_capture_path_template = input->renderdoc_set_capture_file_path_template; - #endif }break; case BeamformerInputEventKind_FileEvent:{ diff --git a/beamformer_internal.h b/beamformer_internal.h @@ -195,8 +195,21 @@ DEBUG_IMPORT u64 * vk_command_read_timestamps(VulkanTimeline timeline, Ar #if BEAMFORMER_RENDERDOC_HOOKS DEBUG_IMPORT void * vk_renderdoc_instance_handle(void); + +DEBUG_IMPORT renderdoc_start_frame_capture_fn *start_frame_capture; +DEBUG_IMPORT renderdoc_set_capture_path_template_fn *set_capture_path_template; +DEBUG_IMPORT renderdoc_end_frame_capture_fn *end_frame_capture; +#define start_renderdoc_capture() do { \ + if (set_capture_path_template) set_capture_path_template("captures/ogl.rdc"); \ + if (start_frame_capture) start_frame_capture(vk_renderdoc_instance_handle(), 0); \ +} while(0) +#define end_renderdoc_capture() if (end_frame_capture) end_frame_capture(vk_renderdoc_instance_handle(), 0) +#define renderdoc_attached(...) (start_frame_capture != 0) + #else -#define vk_renderdoc_instance_handle() ((void *)0) +#define start_renderdoc_capture(...) +#define end_renderdoc_capture(...) +#define renderdoc_attached(...) (0) #endif /////////////////////////////// diff --git a/vulkan.c b/vulkan.c @@ -340,7 +340,6 @@ global glslang_resource_t glslc_resource_constraints[1] = {{ }, }}; - #if BEAMFORMER_RENDERDOC_HOOKS DEBUG_IMPORT void * vk_renderdoc_instance_handle(void) @@ -897,7 +896,13 @@ vk_buffer_allocate_common(VulkanBuffer *vb, VulkanBufferAllocateInfo *ai) // TODO(rnp): this probably should be handled, its usually 4GB. likely // need to chain multiple allocations and handle it in shader code - u64 size = Min(ai->size, vk->memory_info.max_allocation_size & ~(vk->memory_info.non_coherent_atom_size - 1)); + u64 clamp_size = vk->memory_info.max_allocation_size & ~(vk->memory_info.non_coherent_atom_size - 1); + + // NOTE(rnp): renderdoc can't handle buffers that are too close to the allocation size limit + if (renderdoc_attached()) + clamp_size -= MB(8); + + u64 size = Min(ai->size, clamp_size); VkBufferCreateInfo buffer_create_info = { .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,