ogl_beamforming

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

beamformer.meta (13123B)


      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 	[ULM            ULM            0]
    160 }
    161 @Expand(AcquisitionKindTable) @Enumeration(`$(name)`) AcquisitionKind
    162 
    163 @Struct ParametersHead
    164 {
    165 	[das_voxel_transform          M4             ]
    166 	[xdc_transform                M4             ]
    167 	[xdc_element_pitch            V2             ]
    168 	[raw_data_dimensions          UV2            ]
    169 	[focal_vector                 V2             ]
    170 	[transmit_receive_orientation U32            ]
    171 	[sample_count                 U32            ]
    172 	[channel_count                U32            ]
    173 	[acquisition_count            U32            ]
    174 	[acquisition_kind             AcquisitionKind]
    175 	[decode_mode                  DecodeMode     ]
    176 	[sampling_mode                SamplingMode   ]
    177 	[time_offset                  F32            ]
    178 	[single_focus                 B32            ]
    179 	[single_orientation           B32            ]
    180 }
    181 
    182 @Struct UIParameters
    183 {
    184 	[output_points          SV4]
    185 	[sampling_frequency     F32]
    186 	[demodulation_frequency F32]
    187 	[speed_of_sound         F32]
    188 	[f_number               F32]
    189 	[interpolation_mode     InterpolationMode]
    190 	[coherency_weighting    B32]
    191 	[decimation_rate        U32]
    192 }
    193 
    194 @Struct ExtraParameters
    195 {
    196 	[contrast_mode       ContrastMode      ]
    197 	[emission_parameters EmissionParameters]
    198 }
    199 
    200 @Struct Parameters
    201 {
    202 	[`` ParametersHead ]
    203 	[`` UIParameters   ]
    204 	[`` ExtraParameters]
    205 }
    206 @Library @Struct Parameters
    207 @MATLAB  @Struct Parameters
    208 
    209 @Struct SimpleParameters
    210 {
    211 
    212 	[``                            Parameters 1                     ]
    213 	[channel_mapping               S16        MaxChannelCount       ]
    214 	[sparse_elements               S16        MaxEmissionsCount     ]
    215 	[transmit_receive_orientations U8         MaxEmissionsCount     ]
    216 	[steering_angles               F32        MaxEmissionsCount     ]
    217 	[focal_depths                  F32        MaxEmissionsCount     ]
    218 	[compute_stages                S32        MaxComputeShaderStages]
    219 	[compute_stage_parameters      S32        MaxComputeShaderStages]
    220 	[compute_stages_count          U32        1                     ]
    221 	[data_kind                     DataKind   1                     ]
    222 }
    223 @Library @Struct SimpleParameters
    224 @MATLAB  @Struct SimpleParameters
    225 
    226 @Struct DASArrayParameters
    227 {
    228 	[focal_vectors                 V2  MaxChannelCount]
    229 	[sparse_elements               S16 MaxChannelCount]
    230 	[transmit_receive_orientations U16 MaxChannelCount]
    231 }
    232 
    233 @Emit
    234 {
    235 	`read_only global u8 beamformer_data_kind_element_size[] = {`
    236 	@Expand(DataKindTable) `	$(size),`
    237 	`};`
    238 	``
    239 	`read_only global u8 beamformer_data_kind_element_count[] = {`
    240 	@Expand(DataKindTable) `	$(elements),`
    241 	`};`
    242 	``
    243 	`read_only global u8 beamformer_data_kind_byte_size[] = {`
    244 	@Expand(DataKindTable) `	$(size) * $(elements),`
    245 	`};`
    246 	``
    247 	`read_only global b8 beamformer_data_kind_complex[] = {`
    248 	@Expand(DataKindTable) `	$(complex),`
    249 	`};`
    250 	``
    251 	`read_only global s8 beamformer_data_kind_glsl_type[] = {`
    252 	@Expand(DataKindTable) `	s8_comp("$(glsl)"),`
    253 	`};`
    254 	``
    255 	`read_only global s8 beamformer_data_kind_s8[] = {`
    256 	@Expand(DataKindTable) `	s8_comp("$(name)"),`
    257 	`};`
    258 	``
    259 	`read_only global u8 beamformer_contrast_mode_samples[] = {`
    260 	@Expand(ContrastModeTable) `	$(samples),`
    261 	`};`
    262 	``
    263 	`read_only global u8 beamformer_acquisition_kind_has_fixed_transmits[] = {`
    264 	@Expand(AcquisitionKindTable) `	$(fixed_transmits),`
    265 	`};`
    266 	``
    267 	`read_only global s8 beamformer_acquisition_kind_strings[] = {`
    268 	@Expand(AcquisitionKindTable) `	s8_comp("$(pretty_name)"),`
    269 	`};`
    270 	``
    271 	`read_only global s8 beamformer_filter_kind_strings[] = {`
    272 	@Expand(FilterKindTable) `	s8_comp("$(name)"),`
    273 	`};`
    274 	``
    275 	`read_only global s8 beamformer_interpolation_mode_strings[] = {`
    276 	@Expand(InterpolationMode) `	s8_comp("$(name)"),`
    277 	`};`
    278 	``
    279 	`read_only global s8 beamformer_shader_resource_kind_strings[] = {`
    280 	@Expand(ShaderResourceKind) `	s8_comp("$(name)"),`
    281 	`};`
    282 	``
    283 	`read_only global s8 game_shader_buffer_slot_strings[] = {`
    284 	@Expand(ShaderBufferSlot) `	s8_comp("$(name)"),`
    285 	`};`
    286 }
    287 
    288 @ShaderGroup Compute
    289 {
    290 	@Shader(decode.glsl) Decode
    291 	{
    292 		@Enumeration DecodeMode
    293 
    294 		@Bake
    295 		{
    296 			[UseSharedMemory      use_shared_memory      B32]
    297 			[DecodeMode           decode_mode            U32]
    298 			[OutputChannelStride  output_channel_stride  U32]
    299 			[OutputSampleStride   output_sample_stride   U32]
    300 			[OutputTransmitStride output_transmit_stride U32]
    301 			[ToProcess            to_process             U32]
    302 			[TransmitCount        transmit_count         U32]
    303 			[ChunkChannelCount    chunk_channel_count    U32]
    304 			[CooperativeMatrix    cooperative_matrix     B32]
    305 			[CooperativeMatrixM   cooperative_matrix_m   U32]
    306 			[CooperativeMatrixN   cooperative_matrix_n   U32]
    307 			[CooperativeMatrixK   cooperative_matrix_k   U32]
    308 		}
    309 
    310 		@PushConstants
    311 		{
    312 			[hadamard_buffer  U64]
    313 			[rf_buffer        U64]
    314 			[output_buffer    U64]
    315 		}
    316 	}
    317 
    318 	@Shader(filter.glsl) Filter
    319 	{
    320 		@Enumeration ShaderBufferSlot
    321 		@Enumeration ShaderResourceKind
    322 
    323 		@ShaderAlias Demodulate
    324 
    325 		@Bake
    326 		{
    327 			[Demodulate            demodulate             U32]
    328 			[ComplexFilter         complex_filter         U32]
    329 			[DecimationRate        decimation_rate        U32]
    330 			[FilterLength          filter_length          U32]
    331 			[InputChannelStride    input_channel_stride   U32]
    332 			[InputSampleStride     input_sample_stride    U32]
    333 			[InputTransmitStride   input_transmit_stride  U32]
    334 			[OutputChannelStride   output_channel_stride  U32]
    335 			[OutputSampleStride    output_sample_stride   U32]
    336 			[OutputTransmitStride  output_transmit_stride U32]
    337 			[SampleCount           sample_count           U32]
    338 			[BatchSampleCount      batch_sample_count     U32]
    339 
    340 			[DemodulationFrequency demodulation_frequency F32]
    341 			[SamplingFrequency     sampling_frequency     F32]
    342 		}
    343 
    344 		@PushConstants
    345 		{
    346 			[input_data            U64]
    347 			[filter_coefficients   U64]
    348 			[output_element_offset U32]
    349 		}
    350 	}
    351 
    352 	@Shader(das.glsl) DAS
    353 	{
    354 		@Constant    MaxChannelCount
    355 
    356 		@Enumeration AcquisitionKind
    357 		@Enumeration InterpolationMode
    358 		@Enumeration RCAOrientation
    359 		@Enumeration ShaderBufferSlot
    360 		@Enumeration ShaderResourceKind
    361 
    362 		@Struct      DASArrayParameters
    363 
    364 		@Bake
    365 		{
    366 			[CoherencyWeighting         coherency_weighting          U32]
    367 			[SingleFocus                single_focus                 U32]
    368 			[SingleOrientation          single_orientation           U32]
    369 			[Sparse                     sparse                       U32]
    370 			[AcquisitionCount           acquisition_count            U32]
    371 			[AcquisitionKind            acquisition_kind             U32]
    372 			[ChannelCount               channel_count                U32]
    373 			[ChunkChannelCount          chunk_channel_count          U32]
    374 			[InterpolationMode          interpolation_mode           U32]
    375 			[SampleCount                sample_count                 U32]
    376 			[TransmitReceiveOrientation transmit_receive_orientation U32]
    377 
    378 			[DemodulationFrequency      demodulation_frequency       F32]
    379 			[FNumber                    f_number                     F32]
    380 			[FocusDepth                 focus_depth                  F32]
    381 			[SamplingFrequency          sampling_frequency           F32]
    382 			[SpeedOfSound               speed_of_sound               F32]
    383 			[TimeOffset                 time_offset                  F32]
    384 			[TransmitAngle              transmit_angle               F32]
    385 		}
    386 
    387 		@PushConstants
    388 		{
    389 			[xdc_transform      M4]
    390 			[voxel_transform    M4]
    391 			[xdc_element_pitch  V2]
    392 			[array_parameters  U64]
    393 			[output_frame      U64]
    394 			[incoherent_frame  U64]
    395 			[rf_element_offset U32]
    396 			[output_size_x     U32]
    397 			[output_size_y     U32]
    398 			[output_size_z     U32]
    399 			[cycle_t           U32]
    400 			[channel_offset    S32]
    401 		}
    402 	}
    403 
    404 	@Shader(sum.glsl) Sum
    405 	{
    406 		@PushConstants
    407 		{
    408 			[output_data    U64]
    409 			[input_data     U64]
    410 			[image_elements U32]
    411 			[scale          F32]
    412 		}
    413 	}
    414 
    415 	@Shader(min_max.glsl) MinMax
    416 
    417 	@Shader Hilbert
    418 }
    419 
    420 // NOTE: shaders which need to be baked into the beamforming pipeline
    421 // but should not be visible to the external interface
    422 @ShaderGroup ComputeHelpers
    423 {
    424 	@Shader(coherency_weighting.glsl) CoherencyWeighting
    425 	{
    426 		@PushConstants
    427 		{
    428 			[left_side_buffer  U64]
    429 			[right_side_buffer U64]
    430 			[scale             F32]
    431 			[output_size_x     U32]
    432 			[output_size_y     U32]
    433 			[output_size_z     U32]
    434 		}
    435 	}
    436 
    437 	@Shader(reshape.glsl) Reshape
    438 	{
    439 		@Bake
    440 		{
    441 			[SizeX          size_x           U32]
    442 			[SizeY          size_y           U32]
    443 			[SizeZ          size_z           U32]
    444 			[InputStrideX   input_stride_x   U32]
    445 			[InputStrideY   input_stride_y   U32]
    446 			[InputStrideZ   input_stride_z   U32]
    447 			[OutputStrideX  output_stride_x  U32]
    448 			[OutputStrideY  output_stride_y  U32]
    449 			[OutputStrideZ  output_stride_z  U32]
    450 			[Interleave     interleave       B32]
    451 			[Deinterleave   deinterleave     B32]
    452 		}
    453 
    454 		@PushConstants
    455 		{
    456 			[output_buffer      U64]
    457 			[left_input_buffer  U64]
    458 			[right_input_buffer U64]
    459 		}
    460 	}
    461 }
    462 
    463 // NOTE: general compute shaders which do not need baking
    464 @ShaderGroup ComputeInternal
    465 {
    466 	@Shader(buffer_clear.glsl) BufferClear
    467 	{
    468 		@PushConstants
    469 		{
    470 			[clear_v4 UV4]
    471 			[data     U64]
    472 			[bins     U32]
    473 		}
    474 	}
    475 }
    476 
    477 @ShaderGroup Render
    478 {
    479 	@RenderShader RenderBeamformed
    480 	{
    481 		@VertexShader(render_3d.vert.glsl)
    482 		@FragmentShader(render_3d.frag.glsl)
    483 
    484 		@PushConstants
    485 		{
    486 			[mvp_matrix             M4]
    487 			[positions             U64]
    488 			[normals               U64]
    489 
    490 			[bounding_box_colour    V4]
    491 			[bounding_box_fraction F32]
    492 			[db_cutoff             F32]
    493 			[threshold             F32]
    494 			[gamma                 F32]
    495 			[input_data            U64]
    496 			[input_size_x          U32]
    497 			[input_size_y          U32]
    498 			[input_size_z          U32]
    499 			[data_kind             U32]
    500 		}
    501 	}
    502 }