ogl_beamforming

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

beamformer_internal.h (19960B)


      1 /* See LICENSE for license details. */
      2 #ifndef BEAMFORMER_INTERNAL_H
      3 #define BEAMFORMER_INTERNAL_H
      4 
      5 #include "beamformer.h"
      6 
      7 #include "util.h"
      8 #include "opengl.h"
      9 
     10 #include "generated/beamformer.c"
     11 #include "generated/beamformer_core.c"
     12 #include "generated/beamformer_shader_data.c"
     13 
     14 #include "external/raylib/src/raylib.h"
     15 #include "external/raylib/src/rlgl.h"
     16 
     17 #define beamformer_info(s) str8("[info] " s "\n")
     18 
     19 #define os_path_separator() (str8){.data = &os_system_info()->path_separator_byte, .length = 1}
     20 
     21 typedef struct { u64 value; } GPUHandle;
     22 typedef struct { u64 value; } GPUCommandList;
     23 typedef struct { u64 value; } GPUSplitBarrier;
     24 
     25 typedef struct { u64 value[1]; } VulkanHandle;
     26 
     27 typedef enum {
     28 	GPUTimeline_Graphics,
     29 	GPUTimeline_Compute,
     30 	GPUTimeline_Transfer,
     31 	GPUTimeline_Count,
     32 } GPUTimeline;
     33 
     34 typedef enum {
     35 	VulkanShaderKind_Vertex,
     36 	VulkanShaderKind_Mesh,
     37 	VulkanShaderKind_Fragment,
     38 	VulkanShaderKind_Compute,
     39 	VulkanShaderKind_Count,
     40 } VulkanShaderKind;
     41 
     42 typedef enum {
     43 	VulkanImageUsage_None,
     44 	VulkanImageUsage_Colour,
     45 	VulkanImageUsage_DepthStencil,
     46 	VulkanImageUsage_Count,
     47 } VulkanImageUsage;
     48 
     49 typedef enum {
     50 	GPUUsageFlag_ImageSampling       = 1 << 0,
     51 	GPUUsageFlag_HostRead            = 1 << 1, // NOTE: not valid on images
     52 	GPUUsageFlag_HostWrite           = 1 << 2, // NOTE: not valid on images
     53 	/* NOTE: uses:
     54 	 * - image-image copy operations
     55 	 * - buffer-buffer copy operations
     56 	 */
     57 	GPUUsageFlag_TransferSource      = 1 << 3,
     58 	GPUUsageFlag_TransferDestination = 1 << 4,
     59 
     60 	GPUUsageFlag_HostReadWrite       = (GPUUsageFlag_HostRead|GPUUsageFlag_HostWrite),
     61 } GPUUsageFlags;
     62 
     63 typedef struct {
     64 	VulkanShaderKind kind;
     65 	i32              specialization_struct_id;
     66 	void            *specialization_data;
     67 	str8             text;
     68 	str8             name;
     69 } VulkanPipelineCreateInfo;
     70 
     71 typedef struct {
     72 	GPUHandle handle;
     73 	u64       gpu_pointer;
     74 	i64       size;
     75 
     76 	// NOTE: only used for render models
     77 	u64       index_count;
     78 } GPUBuffer;
     79 
     80 typedef struct {
     81 	VulkanHandle image;
     82 	u32          width;
     83 	u32          height;
     84 	u32          samples;
     85 	u32          mip_map_levels;
     86 	// TODO(rnp): this is only here for importing from OpenGL, move it back into handle later
     87 	u64          memory_size;
     88 } GPUImage;
     89 
     90 typedef enum {
     91 	GPUVendor_AMD      = 0x1002,
     92 	GPUVendor_NVIDIA   = 0x10DE,
     93 	GPUVendor_Qualcomm = 0x5143,
     94 	GPUVendor_Intel    = 0x8086,
     95 } GPUVendor;
     96 
     97 typedef struct {
     98 	str8      name;
     99 	GPUVendor vendor;
    100 
    101 	f32 timestamp_period_ns;
    102 
    103 	u32 max_compute_shared_memory_size;
    104 	u16 max_msaa_samples;
    105 	u16 subgroup_size;
    106 
    107 	b32 cooperative_matrix;
    108 
    109 	u32 max_image_dimension_2D;
    110 	// NOTE(rnp): vulkan compute will output to a buffer so this won't be relevant
    111 	u32 max_image_dimension_3D;
    112 
    113 	u64 gpu_heap_size;
    114 	u64 gpu_heap_used;
    115 } GPUInfo;
    116 
    117 typedef struct {
    118 	GPUUsageFlags     flags;
    119 	i64               size;
    120 
    121 	// NOTE(rnp): only required if buffer will be used on multiple timelines
    122 	u32               timeline_count;
    123 	GPUTimeline      *timelines_used;
    124 
    125 	OSHandle         *export;
    126 
    127 	str8              label;
    128 } GPUBufferAllocateInfo;
    129 
    130 typedef struct {
    131 	GPUBuffer model;
    132 	u32       vertex_count;
    133 	u32       normals_offset;
    134 } RenderModel;
    135 
    136 #include "threads.c"
    137 
    138 ///////////////////////////
    139 // NOTE: vulkan layer API
    140 DEBUG_IMPORT void vk_load(OSLibrary vulkan, Stream *error);
    141 
    142 DEBUG_IMPORT GPUInfo *gpu_info(void);
    143 
    144 DEBUG_IMPORT void gpu_buffer_allocate(GPUBuffer *, GPUBufferAllocateInfo info);
    145 DEBUG_IMPORT void gpu_buffer_release(GPUBuffer *);
    146 DEBUG_IMPORT u64  gpu_buffer_range_upload(GPUBuffer *, void *data, u64 offset, u64 size, b32 non_temporal);
    147 DEBUG_IMPORT void gpu_buffer_range_download(void *output, GPUBuffer *, u64 source_offset, u64 size, b32 non_temporal);
    148 DEBUG_IMPORT u64  gpu_round_up_to_sync_size(u64, u64 min);
    149 
    150 // NOTE: images are 2D only, any other use case should just use a buffer and index in the shader
    151 DEBUG_IMPORT void vk_image_allocate(GPUImage *, u32 width, u32 height, u32 mips, u32 samples, VulkanImageUsage usage, GPUUsageFlags flags, OSHandle *export, str8 label);
    152 DEBUG_IMPORT void vk_image_release(GPUImage *);
    153 
    154 DEBUG_IMPORT void vk_render_model_allocate(GPUBuffer *, void *indices, u64 index_count, u64 model_size, str8 label);
    155 DEBUG_IMPORT void vk_render_model_range_upload(GPUBuffer *, void *data, u64 offset, u64 size, b32 non_temporal);
    156 DEBUG_IMPORT void vk_render_model_release(GPUBuffer *);
    157 
    158 /* NOTE: Pipelines do not have bindings. Data should be passed using push constants.
    159  * In particular the push constants should contain pointers to gpu memory using the
    160  * BufferDeviceAddress extension. */
    161 // TODO(rnp): change this to accept SPIR-V directly and accept BakeParameters as specialization data
    162 DEBUG_IMPORT VulkanHandle vk_pipeline(VulkanPipelineCreateInfo *infos, u32 count, u32 push_constants_size);
    163 DEBUG_IMPORT b32          vk_pipeline_valid(VulkanHandle);
    164 DEBUG_IMPORT void         vk_pipeline_release(VulkanHandle);
    165 
    166 DEBUG_IMPORT b32 vk_buffer_needs_sync(GPUBuffer *);
    167 
    168 DEBUG_IMPORT VulkanHandle vk_create_semaphore(OSHandle *export);
    169 
    170 DEBUG_IMPORT b32             gpu_host_wait_timeline(GPUTimeline timeline, u64 value, u64 timeout_ns);
    171 DEBUG_IMPORT u64             gpu_host_signal_timeline(GPUTimeline timeline);
    172 
    173 DEBUG_IMPORT GPUCommandList  gpu_command_list_begin(GPUTimeline timeline);
    174 // NOTE: extra semaphores only exist for synchronization with OpenGL and will be removed in the future
    175 DEBUG_IMPORT u64             gpu_command_list_end(GPUCommandList command, VulkanHandle wait_semaphore, VulkanHandle finished_semaphore);
    176 
    177 DEBUG_IMPORT void            gpu_command_bind_pipeline(GPUCommandList command, VulkanHandle pipeline);
    178 DEBUG_IMPORT void            gpu_command_pipeline_barrier(GPUCommandList command, b32 memory);
    179 DEBUG_IMPORT void            gpu_command_clear_buffer(GPUCommandList command, GPUBuffer *buffer, u64 offset, u64 size, u32 clear_word);
    180 DEBUG_IMPORT void            gpu_command_dispatch_compute(GPUCommandList command, uv3 dispatch);
    181 DEBUG_IMPORT void            gpu_command_push_constants(GPUCommandList command, u32 offset, u32 size, void *values);
    182 DEBUG_IMPORT void            gpu_command_timestamp(GPUCommandList command);
    183 DEBUG_IMPORT void            gpu_command_wait_timeline(GPUCommandList command, GPUTimeline timeline, u64 value);
    184 
    185 DEBUG_IMPORT void            gpu_command_begin_rendering(GPUCommandList command, GPUImage *restrict colour, GPUImage *restrict depth, GPUImage *restrict resolve);
    186 DEBUG_IMPORT void            gpu_command_draw(GPUCommandList command, GPUBuffer *model);
    187 DEBUG_IMPORT void            gpu_command_scissor(GPUCommandList command, u32 width, u32 height, u32 x_offset, u32 y_offset);
    188 DEBUG_IMPORT void            gpu_command_viewport(GPUCommandList command, f32 width, f32 height, f32 x_offset, f32 y_offset, f32 min_depth, f32 max_depth);
    189 DEBUG_IMPORT void            gpu_command_end_rendering(GPUCommandList command);
    190 
    191 DEBUG_IMPORT void            gpu_command_copy_buffer(GPUCommandList command,
    192                                                      GPUBuffer *restrict destination, u64 destination_offset,
    193                                                      GPUBuffer *restrict source,      u64 source_offset,
    194                                                      u64 size);
    195 
    196 // NOTE: returns array of valid timestamps. Calling thread may stall until results available.
    197 DEBUG_IMPORT u64 *           gpu_read_timestamps(GPUTimeline timeline, u64 *count, Arena *arena);
    198 
    199 #if BEAMFORMER_RENDERDOC_HOOKS
    200 DEBUG_IMPORT void *       vk_renderdoc_instance_handle(void);
    201 
    202 #define RENDERDOC_GET_API_FN(name) b32 name(u32 version, void **out_api)
    203 typedef RENDERDOC_GET_API_FN(renderdoc_get_api_fn);
    204 
    205 #define RENDERDOC_START_FRAME_CAPTURE_FN(name) void name(void *instance_handle, i64 window_handle)
    206 typedef RENDERDOC_START_FRAME_CAPTURE_FN(renderdoc_start_frame_capture_fn);
    207 
    208 #define RENDERDOC_END_FRAME_CAPTURE_FN(name) b32 name(void *instance_handle, i64 window_handle)
    209 typedef RENDERDOC_END_FRAME_CAPTURE_FN(renderdoc_end_frame_capture_fn);
    210 
    211 typedef alignas(16) u8 RenderDocAPI[216];
    212 #define RENDERDOC_API_FN_ADDR(a, offset) (*(i64 *)((*a) + offset))
    213 #define RENDERDOC_START_FRAME_CAPTURE(a) (renderdoc_start_frame_capture_fn *)RENDERDOC_API_FN_ADDR(a, 152)
    214 #define RENDERDOC_END_FRAME_CAPTURE(a)   (renderdoc_end_frame_capture_fn *)  RENDERDOC_API_FN_ADDR(a, 168)
    215 
    216 DEBUG_IMPORT renderdoc_start_frame_capture_fn *start_frame_capture;
    217 DEBUG_IMPORT renderdoc_end_frame_capture_fn   *end_frame_capture;
    218 #define start_renderdoc_capture() if (start_frame_capture) start_frame_capture(vk_renderdoc_instance_handle(), 0)
    219 #define end_renderdoc_capture()   if (end_frame_capture)   end_frame_capture(vk_renderdoc_instance_handle(), 0)
    220 #define renderdoc_attached(...)   (start_frame_capture != 0)
    221 
    222 #else
    223 #define start_renderdoc_capture(...)
    224 #define end_renderdoc_capture(...)
    225 #define renderdoc_attached(...) (0)
    226 #endif
    227 
    228 #include "util_os_ui.c"
    229 
    230 ///////////////////////////////
    231 // NOTE: CUDA Library Bindings
    232 
    233 #define cuda_supported() (cuda_init != cuda_init_stub)
    234 #define CUDA_INIT_FN(name) void name(u32 *input_dims, u32 *decoded_dims)
    235 typedef CUDA_INIT_FN(cuda_init_fn);
    236 CUDA_INIT_FN(cuda_init_stub) {}
    237 
    238 #define CUDA_REGISTER_BUFFERS_FN(name) void name(u32 *rf_data_ssbos, u32 rf_buffer_count, u32 raw_data_ssbo)
    239 typedef CUDA_REGISTER_BUFFERS_FN(cuda_register_buffers_fn);
    240 CUDA_REGISTER_BUFFERS_FN(cuda_register_buffers_stub) {}
    241 
    242 #define CUDA_HILBERT_FN(name) void name(u32 input_buffer_idx, u32 output_buffer_idx)
    243 typedef CUDA_HILBERT_FN(cuda_hilbert_fn);
    244 CUDA_HILBERT_FN(cuda_hilbert_stub) {}
    245 
    246 #define CUDA_SET_CHANNEL_MAPPING_FN(name) void name(i16 *channel_mapping)
    247 typedef CUDA_SET_CHANNEL_MAPPING_FN(cuda_set_channel_mapping_fn);
    248 CUDA_SET_CHANNEL_MAPPING_FN(cuda_set_channel_mapping_stub) {}
    249 
    250 #define CUDALibraryProcedureList \
    251 	X(hilbert,             "cuda_hilbert")             \
    252 	X(init,                "init_cuda_configuration")  \
    253 	X(register_buffers,    "register_cuda_buffers")    \
    254 	X(set_channel_mapping, "cuda_set_channel_mapping")
    255 
    256 #define X(name, ...) DEBUG_IMPORT cuda_## name ##_fn *cuda_## name;
    257 CUDALibraryProcedureList
    258 #undef X
    259 
    260 /////////////////////////////////////
    261 // NOTE: Core Beamformer Definitions
    262 
    263 #include "beamformer_compute_stats.c"
    264 #include "beamformer_shared_memory.c"
    265 
    266 typedef struct {
    267 	BeamformerFilterParameters parameters;
    268 	f32                        time_delay;
    269 	i32                        length;
    270 	void                      *data;
    271 } BeamformerFilter;
    272 
    273 typedef struct {
    274 	uv3 layout;
    275 	uv3 dispatch;
    276 	u32 compile_flags;
    277 	b32 uses_heap;
    278 	BeamformerDataKind input_data_kind;
    279 	BeamformerDataKind output_data_kind;
    280 	BeamformerShaderBakeParameters bake;
    281 } BeamformerShaderDescriptor;
    282 
    283 typedef struct BeamformerComputePlan BeamformerComputePlan;
    284 struct BeamformerComputePlan {
    285 	BeamformerComputePipeline pipeline;
    286 
    287 	VulkanHandle vulkan_pipelines[BeamformerMaxComputeShaderStages];
    288 
    289 	u32 first_image_shader_index;
    290 	u32 channel_count;
    291 	u32 raw_channel_byte_stride;
    292 
    293 	u32 dirty_programs;
    294 
    295 	BeamformerAcquisitionKind acquisition_kind;
    296 	u32                       acquisition_count;
    297 	BeamformerContrastMode    contrast_mode;
    298 
    299 	u32 rf_size;
    300 	b32 iq_pipeline;
    301 
    302 	m4  ui_voxel_transform;
    303 	// NOTE(rnp): final voxel transform determining frame dimensions
    304 	m4  voxel_transform;
    305 	// NOTE(rnp): final voxel transform used for beamforming
    306 	m4  das_voxel_transform;
    307 
    308 	iv3 output_points;
    309 	i32 average_frames;
    310 
    311 	// TODO(rnp): specialization constants
    312 	v2  xdc_element_pitch;
    313 	m4  xdc_transform;
    314 
    315 	u32  readi_group;
    316 
    317 	u64 last_gpu_heap_pointer;
    318 	GPUBuffer gpu_temp_arena;
    319 
    320 	BeamformerFilterParameters filter_parameters[BeamformerFilterSlots];
    321 
    322 	u128 shader_hashes[BeamformerMaxComputeShaderStages];
    323 	BeamformerShaderDescriptor shader_descriptors[BeamformerMaxComputeShaderStages];
    324 
    325 	BeamformerComputePlan *next;
    326 };
    327 
    328 typedef struct {
    329 	u64 upload_complete_values[BeamformerMaxRawDataFramesInFlight];
    330 	u64 compute_complete_values[BeamformerMaxRawDataFramesInFlight];
    331 
    332 	GPUBuffer buffer;
    333 
    334 	u32 active_rf_size;
    335 
    336 	u64 timestamp;
    337 
    338 	u64 insertion_index;
    339 	u64 compute_index;
    340 } BeamformerRFBuffer;
    341 
    342 typedef struct {
    343 	BeamformerComputeStatsTable table;
    344 	f32 average_times[BeamformerShaderKind_Count];
    345 
    346 	u64 last_rf_timer_count;
    347 	f32 rf_time_delta_average;
    348 
    349 	u32 latest_frame_index;
    350 	u32 latest_rf_index;
    351 } ComputeShaderStats;
    352 
    353 /* TODO(rnp): maybe this also gets used for CPU timing info as well */
    354 typedef enum {
    355 	ComputeTimingInfoKind_ComputeFrameBegin,
    356 	ComputeTimingInfoKind_ComputeFrameEnd,
    357 	ComputeTimingInfoKind_Shader,
    358 	ComputeTimingInfoKind_RF_Data,
    359 } ComputeTimingInfoKind;
    360 
    361 typedef struct {
    362 	u64 timer_count;
    363 	ComputeTimingInfoKind kind;
    364 	union {
    365 		struct {
    366 			static_assert(BeamformerShaderKind_Count <= U16_MAX, "");
    367 			u16 shader;
    368 			u16 shader_slot;
    369 		};
    370 	};
    371 } ComputeTimingInfo;
    372 
    373 typedef struct {
    374 	u32 write_index;
    375 	u32 read_index;
    376 	b32 compute_frame_active;
    377 
    378 	u32                  in_flight_shader_count;
    379 	BeamformerShaderKind in_flight_shader_ids[BeamformerMaxComputeShaderStages];
    380 
    381 	ComputeTimingInfo buffer[4096];
    382 } ComputeTimingTable;
    383 
    384 typedef struct {
    385 	BeamformerRFBuffer      *rf_buffer;
    386 	BeamformerSharedMemory  *shared_memory;
    387 	i64                      shared_memory_size;
    388 	ComputeTimingTable      *compute_timing_table;
    389 	i32                     *compute_worker_sync;
    390 } BeamformerUploadThreadContext;
    391 
    392 typedef struct {
    393 	u64 gpu_pointer;
    394 	u64 timeline_valid_value;
    395 
    396 	/* NOTE: for use when displaying either prebeamformed frames or on the current frame
    397 	 * when we intend to recompute on the next frame */
    398 	m4  voxel_transform;
    399 
    400 	iv3 points;
    401 
    402 	u32                       id;
    403 	u32                       compound_count;
    404 	u32                       parameter_block;
    405 	BeamformerDataKind        data_kind;
    406 	BeamformerAcquisitionKind acquisition_kind;
    407 	BeamformerContrastMode    contrast_mode;
    408 	BeamformerViewPlaneTag    view_plane_tag;
    409 } BeamformerFrame;
    410 
    411 /* NOTE(rnp): backing storage for beamformed frames. The amount of backlog frames
    412  * is dependant on the currently requested output size. */
    413 typedef struct {
    414 	GPUBuffer   buffer[1];
    415 
    416 	u64         next_offset;
    417 	u64         counter;
    418 
    419 	BeamformerFrame frames[BeamformerMaxBacklogFrames];
    420 } BeamformerFrameBacklog;
    421 
    422 typedef struct {
    423 	BeamformerRFBuffer rf_buffer;
    424 
    425 	BeamformerComputePlan *compute_plans[BeamformerMaxParameterBlocks];
    426 	BeamformerComputePlan *compute_plan_freelist;
    427 
    428 	// NOTE(rnp): used to ping pong data between compute stages.
    429 	#define PING_PONG_BUFFER_SLOTS 2
    430 	GPUBuffer ping_pong_buffer;
    431 	OSHandle  ping_pong_export_handle;
    432 	u32       ping_pong_input_index;
    433 
    434 	f32 processing_progress;
    435 	b32 processing_compute;
    436 
    437 	BeamformerFrameBacklog backlog;
    438 } BeamformerComputeContext;
    439 
    440 typedef struct {
    441 	Arena    *arena;
    442 	iptr      user_context;
    443 	i32       sync_variable;
    444 	b32       awake;
    445 	OSThread  handle;
    446 } GLWorkerThreadContext;
    447 
    448 typedef struct {
    449 	str8                 name;
    450 	BeamformerRegisters *registers;
    451 } BeamformerCommand;
    452 
    453 typedef struct BeamformerRegistersNode BeamformerRegistersNode;
    454 struct BeamformerRegistersNode {
    455 	BeamformerRegistersNode *next;
    456 	BeamformerRegisters      v;
    457 };
    458 
    459 typedef struct BeamformerCommandNode BeamformerCommandNode;
    460 struct BeamformerCommandNode {
    461 	BeamformerCommandNode *next;
    462 	BeamformerCommandNode *prev;
    463 	BeamformerCommand      command;
    464 };
    465 
    466 typedef struct {
    467 	BeamformerCommandNode *first;
    468 	BeamformerCommandNode *last;
    469 	u64                    count;
    470 } BeamformerCommandList;
    471 
    472 typedef enum {
    473 	BeamformerState_Uninitialized = 0,
    474 	BeamformerState_Running,
    475 	BeamformerState_ShouldClose,
    476 	BeamformerState_Terminated,
    477 } BeamformerState;
    478 
    479 typedef enum {
    480 	RulerState_None,
    481 	RulerState_Start,
    482 	RulerState_Hold,
    483 	RulerState_Count,
    484 } RulerState;
    485 
    486 typedef struct {
    487 	v3 start;
    488 	v3 end;
    489 	RulerState state;
    490 } Ruler;
    491 
    492 typedef struct {
    493 	f32 t;
    494 	f32 scale;
    495 } BeamformerUIBlinker;
    496 
    497 #define BEAMFORMER_FRAME_VIEW_KIND_LIST \
    498 	X(Latest,   "Latest")     \
    499 	X(3DXPlane, "3D X-Plane") \
    500 	X(Copy,     "Copy")       \
    501 
    502 typedef enum {
    503 	#define X(kind, ...) BeamformerFrameViewKind_##kind,
    504 	BEAMFORMER_FRAME_VIEW_KIND_LIST
    505 	#undef X
    506 	BeamformerFrameViewKind_Count,
    507 } BeamformerFrameViewKind;
    508 
    509 typedef struct BeamformerFrameView BeamformerFrameView;
    510 struct BeamformerFrameView {
    511 	BeamformerFrameViewKind kind;
    512 	b32 dirty;
    513 
    514 	// NOTE(rnp): for FrameViewKindCopy
    515 	GPUBuffer copy_buffer;
    516 
    517 	GPUImage colour_image;
    518 	// NOTE(rnp): temporary, on w32 we must hold onto this when importing vulkan data to OpenGL
    519 	OSHandle export_handle;
    520 	u32      memory_object;
    521 	u32      texture;
    522 
    523 	b32 log_scale;
    524 	f32 threshold;
    525 	f32 dynamic_range;
    526 	f32 gamma;
    527 
    528 	union {
    529 		/* BeamformerFrameViewKind_Latest/BeamformerFrameViewKind_Copy */
    530 		struct {
    531 			b32   scale_bar_active[2];
    532 			Ruler ruler;
    533 			BeamformerViewPlaneTag view_plane;
    534 			BeamformerFrame frame;
    535 		};
    536 
    537 		/* BeamformerFrameViewKind_3DXPlane */
    538 		struct {
    539 			f32 hot_t[BeamformerViewPlaneTag_Count];
    540 			//b32 plane_active[BeamformerViewPlaneTag_Count];
    541 			b32 plane_active[BeamformerViewPlaneTag_Count - 2];
    542 			i32 plane_drag_index;
    543 			f32 rotation;
    544 			b32 demo;
    545 			v3  hit_start_point;
    546 			v3  hit_test_point;
    547 		};
    548 	};
    549 
    550 	BeamformerFrameView *prev, *next;
    551 };
    552 
    553 typedef struct BeamformerUIPanel BeamformerUIPanel;
    554 struct BeamformerUIPanel {
    555 	BeamformerUIPanel *parent;
    556 	BeamformerUIPanel *last_child;
    557 	BeamformerUIPanel *first_child;
    558 	BeamformerUIPanel *previous_sibling;
    559 	BeamformerUIPanel *next_sibling;
    560 
    561 	u64 child_count;
    562 
    563 	BeamformerPanelKind kind;
    564 	union {
    565 		BeamformerFrameView *frame_view;
    566 
    567 		BeamformerUIPanel *tab_focus;
    568 
    569 		BeamformerUIBlinker compute_stats_broken_shader_blinker;
    570 		BeamformerUIBlinker live_imaging_save_button_blinker;
    571 
    572 		struct {
    573 			u32 parameter_block;
    574 			b16 expand_coordinate[2];
    575 		} parameter_listing;
    576 
    577 		struct {
    578 			Axis2 axis;
    579 			f32   fraction;
    580 		} split;
    581 	} u;
    582 };
    583 
    584 typedef struct {
    585 	BeamformerState state;
    586 
    587 	iv2 window_size;
    588 
    589 	Arena *arena;
    590 	Arena *ui_arena;
    591 	void  *ui;
    592 	u32    ui_dirty_parameter_blocks;
    593 
    594 	u64    frame_timestamp;
    595 	u64    frame_index;
    596 	Arena *frame_arenas[2];
    597 
    598 	BeamformerUIPanel *auto_live_control_panel;
    599 	u64                live_imaging_active_frame;
    600 	b32                live_imaging_active;
    601 
    602 	BeamformerRegistersNode  base_registers;
    603 	BeamformerRegistersNode *registers;
    604 
    605 	BeamformerCommandList command_queues[2];
    606 
    607 	Stream error_stream;
    608 
    609 	BeamformerSharedMemory *shared_memory;
    610 	i64                     shared_memory_size;
    611 
    612 	BeamformerFrame *latest_frame;
    613 
    614 	// TODO(rnp): track elsewhere
    615 	b32 render_shader_updated;
    616 
    617 	/* NOTE: this will only be used when we are averaging */
    618 	u32             averaged_frame_index;
    619 	BeamformerFrame averaged_frames[2];
    620 
    621 	GLWorkerThreadContext  upload_worker;
    622 	GLWorkerThreadContext  compute_worker;
    623 
    624 	BeamformerComputeContext compute_context;
    625 
    626 	ComputeShaderStats compute_shader_stats[1];
    627 	ComputeTimingTable compute_timing_table[1];
    628 
    629 	BeamformWorkQueue  beamform_work_queue[1];
    630 
    631 	// TODO(rnp): this should go to the UI eventually
    632 	OSWindow main_window;
    633 } BeamformerCtx;
    634 
    635 typedef enum {
    636 	BeamformerFileReloadKind_ComputeShader,
    637 	BeamformerFileReloadKind_RenderShader,
    638 } BeamformerFileReloadKind;
    639 
    640 typedef struct {
    641 	BeamformerShaderKind shader;
    642 	VulkanHandle *       pipeline;
    643 } BeamformerShaderReloadData;
    644 
    645 typedef struct {
    646 	BeamformerShaderKind  shader;
    647 	VulkanShaderKind      shader_kind;
    648 
    649 	// NOTE(rnp): based on BakeShaders compile time value
    650 	str8                  filename_or_data;
    651 
    652 	BeamformerShaderDescriptor *shader_descriptor;
    653 
    654 	u64 gpu_heap_pointer;
    655 	uv3 layout;
    656 } BeamformerShaderReloadInfo;
    657 
    658 typedef struct {
    659 	BeamformerFileReloadKind kind;
    660 	union {
    661 		BeamformerShaderReloadData shader_reload;
    662 	};
    663 } BeamformerFileReloadContext;
    664 
    665 #define BEAMFORMER_COMPLETE_COMPUTE_FN(name) void name(BeamformerCtx *ctx, Arena *arena)
    666 typedef BEAMFORMER_COMPLETE_COMPUTE_FN(beamformer_complete_compute_fn);
    667 
    668 #define BEAMFORMER_RF_UPLOAD_FN(name) void name(BeamformerUploadThreadContext *ctx)
    669 typedef BEAMFORMER_RF_UPLOAD_FN(beamformer_rf_upload_fn);
    670 
    671 #define BEAMFORMER_DEBUG_UI_DEINIT_FN(name) void name(BeamformerCtx *ctx)
    672 typedef BEAMFORMER_DEBUG_UI_DEINIT_FN(beamformer_debug_ui_deinit_fn);
    673 
    674 #endif /* BEAMFORMER_INTERNAL_H */