ogl_beamforming

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

beamformer.meta (13088B)


      1 @Constant(16)   ChunkChannelCount
      2 @Constant(4)    FilterSlots
      3 @Constant(4096) MaxBacklogFrames
      4 @Constant(256)  MaxChannelCount
      5 @Constant(256)  MaxEmissionsCount
      6 @Constant(16)   MaxComputeShaderStages
      7 @Constant(16)   MaxParameterBlocks
      8 @Constant(3)    MaxRawDataFramesInFlight
      9 
     10 @Enumeration ShaderResourceKind
     11 {
     12 	Buffer
     13 }
     14 
     15 @Enumeration ShaderBufferSlot
     16 {
     17 	BeamformedData
     18 	PingPong
     19 }
     20 
     21 @Enumeration DecodeMode
     22 {
     23 	None
     24 	Hadamard
     25 }
     26 
     27 @Enumeration RCAOrientation
     28 {
     29 	None
     30 	Rows
     31 	Columns
     32 }
     33 
     34 @Enumeration SamplingMode
     35 {
     36 	2X
     37 	4X
     38 }
     39 
     40 @Table([name size elements complex glsl]) DataKindTable
     41 {
     42 	[Int16          2 1 0 int16_t  ]
     43 	[Int16Complex   2 2 1 i16vec2  ]
     44 	[Float32        4 1 0 float32_t]
     45 	[Float32Complex 4 2 1 f32vec2  ]
     46 	[Float16        2 1 0 float16_t]
     47 	[Float16Complex 2 2 1 f16vec2  ]
     48 }
     49 @Expand(DataKindTable) @Enumeration(`$(name)`) DataKind
     50 
     51 @Table([name samples]) ContrastModeTable
     52 {
     53 	[None 1]
     54 	[A1S2 3]
     55 }
     56 @Expand(ContrastModeTable) @Enumeration(`$(name)`) ContrastMode
     57 
     58 @Enumeration EmissionKind
     59 {
     60 	Sine
     61 	Chirp
     62 }
     63 
     64 @Enumeration InterpolationMode
     65 {
     66 	Nearest
     67 	Linear
     68 	Cubic
     69 }
     70 
     71 @Struct SineParameters
     72 {
     73 	[cycles    F32]
     74 	[frequency F32]
     75 }
     76 @Library @Struct SineParameters
     77 
     78 @Struct ChirpParameters
     79 {
     80 	[duration      F32]
     81 	[min_frequency F32]
     82 	[max_frequency F32]
     83 }
     84 @Library @Struct ChirpParameters
     85 
     86 @Table([type c_member m_member]) EmissionParametersTable
     87 {
     88 	[SineParameters  sine  Sine ]
     89 	[ChirpParameters chirp Chirp]
     90 }
     91 @Expand(EmissionParametersTable) @Union([`$(c_member)` `$(type)`]) EmissionParametersUnion
     92 @Expand(EmissionParametersTable) @Union([`$(m_member)` `$(type)`]) EmissionParametersUnionMATLAB
     93 @MATLAB(EmissionParameters)      @Union EmissionParametersUnionMATLAB
     94 
     95 @Struct EmissionParameters
     96 {
     97 	[kind EmissionKind           ]
     98 	[``   EmissionParametersUnion]
     99 }
    100 @Library          @Struct EmissionParameters
    101 @MATLAB(Emission) @Struct EmissionParameters
    102 
    103 @Table([name name_lower]) FilterKindTable
    104 {
    105 	[Kaiser       kaiser       ]
    106 	[MatchedChirp matched_chirp]
    107 }
    108 @Expand(FilterKindTable) @Enumeration(`$(name)`) FilterKind
    109 
    110 @Struct KaiserFilterParameters
    111 {
    112 	[cutoff_frequency F32]
    113 	[beta             F32]
    114 	[length           U32]
    115 }
    116 @Library @Struct KaiserFilterParameters
    117 
    118 @Struct MatchedChirpFilterParameters
    119 {
    120 	[duration      F32]
    121 	[min_frequency F32]
    122 	[max_frequency F32]
    123 }
    124 @Library @Struct MatchedChirpFilterParameters
    125 
    126 @Table([type c_member m_member]) FilterParametersTable
    127 {
    128 	[KaiserFilterParameters       kaiser        Kaiser      ]
    129 	[MatchedChirpFilterParameters matched_chirp MatchedChirp]
    130 }
    131 @Expand(FilterParametersTable) @Union([`$(c_member)` `$(type)`]) FilterParametersUnion
    132 @Expand(FilterParametersTable) @Union([`$(m_member)` `$(type)`]) FilterParametersUnionMATLAB
    133 @MATLAB(FilterParameters)      @Union FilterParametersUnionMATLAB
    134 
    135 @Struct FilterParameters
    136 {
    137 	[kind               FilterKind           ]
    138 	[sampling_frequency F32                  ]
    139 	[complex            B32                  ]
    140 	[``                 FilterParametersUnion]
    141 }
    142 @Library        @Struct FilterParameters
    143 @MATLAB(Filter) @Struct FilterParameters
    144 
    145 @Table([name pretty_name fixed_transmits]) AcquisitionKindTable
    146 {
    147 	[FORCES         FORCES         1]
    148 	[UFORCES        UFORCES        0]
    149 	[HERCULES       HERCULES       1]
    150 	[RCA_VLS        VLS            0]
    151 	[RCA_TPW        TPW            0]
    152 	[UHERCULES      UHERCULES      0]
    153 	[RACES          RACES          1]
    154 	[EPIC_FORCES    EPIC-FORCES    1]
    155 	[EPIC_UFORCES   EPIC-UFORCES   0]
    156 	[EPIC_UHERCULES EPIC-UHERCULES 0]
    157 	[Flash          Flash          0]
    158 	[HERO_PA        HERO-PA        0]
    159 }
    160 @Expand(AcquisitionKindTable) @Enumeration(`$(name)`) AcquisitionKind
    161 
    162 @Struct ParametersHead
    163 {
    164 	[das_voxel_transform          M4             ]
    165 	[xdc_transform                M4             ]
    166 	[xdc_element_pitch            V2             ]
    167 	[raw_data_dimensions          UV2            ]
    168 	[focal_vector                 V2             ]
    169 	[transmit_receive_orientation U32            ]
    170 	[sample_count                 U32            ]
    171 	[channel_count                U32            ]
    172 	[acquisition_count            U32            ]
    173 	[acquisition_kind             AcquisitionKind]
    174 	[decode_mode                  DecodeMode     ]
    175 	[sampling_mode                SamplingMode   ]
    176 	[time_offset                  F32            ]
    177 	[single_focus                 B32            ]
    178 	[single_orientation           B32            ]
    179 }
    180 
    181 @Struct UIParameters
    182 {
    183 	[output_points          SV4]
    184 	[sampling_frequency     F32]
    185 	[demodulation_frequency F32]
    186 	[speed_of_sound         F32]
    187 	[f_number               F32]
    188 	[interpolation_mode     InterpolationMode]
    189 	[coherency_weighting    B32]
    190 	[decimation_rate        U32]
    191 }
    192 
    193 @Struct ExtraParameters
    194 {
    195 	[contrast_mode       ContrastMode      ]
    196 	[emission_parameters EmissionParameters]
    197 }
    198 
    199 @Struct Parameters
    200 {
    201 	[`` ParametersHead ]
    202 	[`` UIParameters   ]
    203 	[`` ExtraParameters]
    204 }
    205 @Library @Struct Parameters
    206 @MATLAB  @Struct Parameters
    207 
    208 @Struct SimpleParameters
    209 {
    210 
    211 	[``                            Parameters 1                     ]
    212 	[channel_mapping               S16        MaxChannelCount       ]
    213 	[sparse_elements               S16        MaxEmissionsCount     ]
    214 	[transmit_receive_orientations U8         MaxEmissionsCount     ]
    215 	[steering_angles               F32        MaxEmissionsCount     ]
    216 	[focal_depths                  F32        MaxEmissionsCount     ]
    217 	[compute_stages                S32        MaxComputeShaderStages]
    218 	[compute_stage_parameters      S32        MaxComputeShaderStages]
    219 	[compute_stages_count          U32        1                     ]
    220 	[data_kind                     DataKind   1                     ]
    221 }
    222 @Library @Struct SimpleParameters
    223 @MATLAB  @Struct SimpleParameters
    224 
    225 @Struct DASArrayParameters
    226 {
    227 	[focal_vectors                 V2  MaxChannelCount]
    228 	[sparse_elements               S16 MaxChannelCount]
    229 	[transmit_receive_orientations U16 MaxChannelCount]
    230 }
    231 
    232 @Emit
    233 {
    234 	`read_only global u8 beamformer_data_kind_element_size[] = {`
    235 	@Expand(DataKindTable) `	$(size),`
    236 	`};`
    237 	``
    238 	`read_only global u8 beamformer_data_kind_element_count[] = {`
    239 	@Expand(DataKindTable) `	$(elements),`
    240 	`};`
    241 	``
    242 	`read_only global u8 beamformer_data_kind_byte_size[] = {`
    243 	@Expand(DataKindTable) `	$(size) * $(elements),`
    244 	`};`
    245 	``
    246 	`read_only global b8 beamformer_data_kind_complex[] = {`
    247 	@Expand(DataKindTable) `	$(complex),`
    248 	`};`
    249 	``
    250 	`read_only global s8 beamformer_data_kind_glsl_type[] = {`
    251 	@Expand(DataKindTable) `	s8_comp("$(glsl)"),`
    252 	`};`
    253 	``
    254 	`read_only global s8 beamformer_data_kind_s8[] = {`
    255 	@Expand(DataKindTable) `	s8_comp("$(name)"),`
    256 	`};`
    257 	``
    258 	`read_only global u8 beamformer_contrast_mode_samples[] = {`
    259 	@Expand(ContrastModeTable) `	$(samples),`
    260 	`};`
    261 	``
    262 	`read_only global u8 beamformer_acquisition_kind_has_fixed_transmits[] = {`
    263 	@Expand(AcquisitionKindTable) `	$(fixed_transmits),`
    264 	`};`
    265 	``
    266 	`read_only global s8 beamformer_acquisition_kind_strings[] = {`
    267 	@Expand(AcquisitionKindTable) `	s8_comp("$(pretty_name)"),`
    268 	`};`
    269 	``
    270 	`read_only global s8 beamformer_filter_kind_strings[] = {`
    271 	@Expand(FilterKindTable) `	s8_comp("$(name)"),`
    272 	`};`
    273 	``
    274 	`read_only global s8 beamformer_interpolation_mode_strings[] = {`
    275 	@Expand(InterpolationMode) `	s8_comp("$(name)"),`
    276 	`};`
    277 	``
    278 	`read_only global s8 beamformer_shader_resource_kind_strings[] = {`
    279 	@Expand(ShaderResourceKind) `	s8_comp("$(name)"),`
    280 	`};`
    281 	``
    282 	`read_only global s8 game_shader_buffer_slot_strings[] = {`
    283 	@Expand(ShaderBufferSlot) `	s8_comp("$(name)"),`
    284 	`};`
    285 }
    286 
    287 @ShaderGroup Compute
    288 {
    289 	@Shader(decode.glsl) Decode
    290 	{
    291 		@Enumeration DecodeMode
    292 
    293 		@Bake
    294 		{
    295 			[UseSharedMemory      use_shared_memory      B32]
    296 			[DecodeMode           decode_mode            U32]
    297 			[OutputChannelStride  output_channel_stride  U32]
    298 			[OutputSampleStride   output_sample_stride   U32]
    299 			[OutputTransmitStride output_transmit_stride U32]
    300 			[ToProcess            to_process             U32]
    301 			[TransmitCount        transmit_count         U32]
    302 			[ChunkChannelCount    chunk_channel_count    U32]
    303 			[CooperativeMatrix    cooperative_matrix     B32]
    304 			[CooperativeMatrixM   cooperative_matrix_m   U32]
    305 			[CooperativeMatrixN   cooperative_matrix_n   U32]
    306 			[CooperativeMatrixK   cooperative_matrix_k   U32]
    307 		}
    308 
    309 		@PushConstants
    310 		{
    311 			[hadamard_buffer  U64]
    312 			[rf_buffer        U64]
    313 			[output_buffer    U64]
    314 		}
    315 	}
    316 
    317 	@Shader(filter.glsl) Filter
    318 	{
    319 		@Enumeration ShaderBufferSlot
    320 		@Enumeration ShaderResourceKind
    321 
    322 		@ShaderAlias Demodulate
    323 
    324 		@Bake
    325 		{
    326 			[Demodulate            demodulate             U32]
    327 			[ComplexFilter         complex_filter         U32]
    328 			[DecimationRate        decimation_rate        U32]
    329 			[FilterLength          filter_length          U32]
    330 			[InputChannelStride    input_channel_stride   U32]
    331 			[InputSampleStride     input_sample_stride    U32]
    332 			[InputTransmitStride   input_transmit_stride  U32]
    333 			[OutputChannelStride   output_channel_stride  U32]
    334 			[OutputSampleStride    output_sample_stride   U32]
    335 			[OutputTransmitStride  output_transmit_stride U32]
    336 			[SampleCount           sample_count           U32]
    337 			[BatchSampleCount      batch_sample_count     U32]
    338 
    339 			[DemodulationFrequency demodulation_frequency F32]
    340 			[SamplingFrequency     sampling_frequency     F32]
    341 		}
    342 
    343 		@PushConstants
    344 		{
    345 			[input_data            U64]
    346 			[filter_coefficients   U64]
    347 			[output_element_offset U32]
    348 		}
    349 	}
    350 
    351 	@Shader(das.glsl) DAS
    352 	{
    353 		@Constant    MaxChannelCount
    354 
    355 		@Enumeration AcquisitionKind
    356 		@Enumeration InterpolationMode
    357 		@Enumeration RCAOrientation
    358 		@Enumeration ShaderBufferSlot
    359 		@Enumeration ShaderResourceKind
    360 
    361 		@Struct      DASArrayParameters
    362 
    363 		@Bake
    364 		{
    365 			[CoherencyWeighting         coherency_weighting          U32]
    366 			[SingleFocus                single_focus                 U32]
    367 			[SingleOrientation          single_orientation           U32]
    368 			[Sparse                     sparse                       U32]
    369 			[AcquisitionCount           acquisition_count            U32]
    370 			[AcquisitionKind            acquisition_kind             U32]
    371 			[ChannelCount               channel_count                U32]
    372 			[ChunkChannelCount          chunk_channel_count          U32]
    373 			[InterpolationMode          interpolation_mode           U32]
    374 			[SampleCount                sample_count                 U32]
    375 			[TransmitReceiveOrientation transmit_receive_orientation U32]
    376 
    377 			[DemodulationFrequency      demodulation_frequency       F32]
    378 			[FNumber                    f_number                     F32]
    379 			[FocusDepth                 focus_depth                  F32]
    380 			[SamplingFrequency          sampling_frequency           F32]
    381 			[SpeedOfSound               speed_of_sound               F32]
    382 			[TimeOffset                 time_offset                  F32]
    383 			[TransmitAngle              transmit_angle               F32]
    384 		}
    385 
    386 		@PushConstants
    387 		{
    388 			[xdc_transform      M4]
    389 			[voxel_transform    M4]
    390 			[xdc_element_pitch  V2]
    391 			[array_parameters  U64]
    392 			[output_frame      U64]
    393 			[incoherent_frame  U64]
    394 			[rf_element_offset U32]
    395 			[output_size_x     U32]
    396 			[output_size_y     U32]
    397 			[output_size_z     U32]
    398 			[cycle_t           U32]
    399 			[channel_offset    S32]
    400 		}
    401 	}
    402 
    403 	@Shader(sum.glsl) Sum
    404 	{
    405 		@PushConstants
    406 		{
    407 			[output_data    U64]
    408 			[input_data     U64]
    409 			[image_elements U32]
    410 			[scale          F32]
    411 		}
    412 	}
    413 
    414 	@Shader(min_max.glsl) MinMax
    415 
    416 	@Shader Hilbert
    417 }
    418 
    419 // NOTE: shaders which need to be baked into the beamforming pipeline
    420 // but should not be visible to the external interface
    421 @ShaderGroup ComputeHelpers
    422 {
    423 	@Shader(coherency_weighting.glsl) CoherencyWeighting
    424 	{
    425 		@PushConstants
    426 		{
    427 			[left_side_buffer  U64]
    428 			[right_side_buffer U64]
    429 			[scale             F32]
    430 			[output_size_x     U32]
    431 			[output_size_y     U32]
    432 			[output_size_z     U32]
    433 		}
    434 	}
    435 
    436 	@Shader(reshape.glsl) Reshape
    437 	{
    438 		@Bake
    439 		{
    440 			[SizeX          size_x           U32]
    441 			[SizeY          size_y           U32]
    442 			[SizeZ          size_z           U32]
    443 			[InputStrideX   input_stride_x   U32]
    444 			[InputStrideY   input_stride_y   U32]
    445 			[InputStrideZ   input_stride_z   U32]
    446 			[OutputStrideX  output_stride_x  U32]
    447 			[OutputStrideY  output_stride_y  U32]
    448 			[OutputStrideZ  output_stride_z  U32]
    449 			[Interleave     interleave       B32]
    450 			[Deinterleave   deinterleave     B32]
    451 		}
    452 
    453 		@PushConstants
    454 		{
    455 			[output_buffer      U64]
    456 			[left_input_buffer  U64]
    457 			[right_input_buffer U64]
    458 		}
    459 	}
    460 }
    461 
    462 // NOTE: general compute shaders which do not need baking
    463 @ShaderGroup ComputeInternal
    464 {
    465 	@Shader(buffer_clear.glsl) BufferClear
    466 	{
    467 		@PushConstants
    468 		{
    469 			[clear_v4 UV4]
    470 			[data     U64]
    471 			[bins     U32]
    472 		}
    473 	}
    474 }
    475 
    476 @ShaderGroup Render
    477 {
    478 	@RenderShader RenderBeamformed
    479 	{
    480 		@VertexShader(render_3d.vert.glsl)
    481 		@FragmentShader(render_3d.frag.glsl)
    482 
    483 		@PushConstants
    484 		{
    485 			[mvp_matrix             M4]
    486 			[positions             U64]
    487 			[normals               U64]
    488 
    489 			[bounding_box_colour    V4]
    490 			[bounding_box_fraction F32]
    491 			[db_cutoff             F32]
    492 			[threshold             F32]
    493 			[gamma                 F32]
    494 			[input_data            U64]
    495 			[input_size_x          U32]
    496 			[input_size_y          U32]
    497 			[input_size_z          U32]
    498 			[data_kind             U32]
    499 		}
    500 	}
    501 }