ogl_beamforming

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

beamformer.meta (13272B)


      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 DecodeMode
     11 {
     12 	None
     13 	Hadamard
     14 }
     15 
     16 @Enumeration RCAOrientation
     17 {
     18 	None
     19 	Rows
     20 	Columns
     21 }
     22 
     23 @Table([name samples]) SamplingModeTable
     24 {
     25 	[2X 2]
     26 	[4X 4]
     27 }
     28 @Expand(SamplingModeTable) @Enumeration(`$(name)`) SamplingMode
     29 
     30 @Table([name size elements complex glsl]) DataKindTable
     31 {
     32 	[Int16          2 1 0 int16_t  ]
     33 	[Int16Complex   2 2 1 i16vec2  ]
     34 	[Float32        4 1 0 float32_t]
     35 	[Float32Complex 4 2 1 f32vec2  ]
     36 	[Float16        2 1 0 float16_t]
     37 	[Float16Complex 2 2 1 f16vec2  ]
     38 }
     39 @Expand(DataKindTable) @Enumeration(`$(name)`) DataKind
     40 
     41 @Enumeration RFDimension
     42 {
     43 	Channels
     44 	Events
     45 	Samples
     46 	Frames
     47 }
     48 
     49 @Table([name dim1 dim2 dim3])  DataLayoutTable
     50 {
     51 	[ChannelEventSample Channels Events   Samples]
     52 	[ChannelSampleEvent Channels Samples  Events ]
     53 	[EventChannelSample Events   Channels Samples]
     54 	[SampleChannelEvent Samples  Channels Events ]
     55 }
     56 
     57 @Enumeration DataLayout
     58 {
     59 	@Expand(DataLayoutTable) `$(name)`
     60 	Image
     61 }
     62 
     63 @Table([name samples]) ContrastModeTable
     64 {
     65 	[None 1]
     66 	[A1S2 3]
     67 }
     68 @Expand(ContrastModeTable) @Enumeration(`$(name)`) ContrastMode
     69 
     70 @Enumeration EmissionKind
     71 {
     72 	Sine
     73 	Chirp
     74 }
     75 
     76 @Enumeration InterpolationMode
     77 {
     78 	Nearest
     79 	Linear
     80 	Cubic
     81 }
     82 
     83 @Enumeration ViewPlaneTag
     84 {
     85 	XZ
     86 	YZ
     87 	XY
     88 	Arbitrary
     89 }
     90 
     91 @Flags AcquisitionKindFlags
     92 {
     93 	FixedTransmits
     94 	Sparse
     95 }
     96 
     97 @Table([name pretty_name fixed_transmits sparse]) AcquisitionKindTable
     98 {
     99 	[FORCES         FORCES         1 0]
    100 	[UFORCES        UFORCES        0 1]
    101 	[HERCULES       HERCULES       1 0]
    102 	[RCA_VLS        VLS            0 0]
    103 	[RCA_TPW        TPW            0 0]
    104 	[UHERCULES      UHERCULES      0 1]
    105 	[RACES          RACES          1 0]
    106 	[EPIC_FORCES    EPIC-FORCES    1 0]
    107 	[EPIC_UFORCES   EPIC-UFORCES   0 1]
    108 	[EPIC_UHERCULES EPIC-UHERCULES 0 1]
    109 	[Flash          Flash          0 0]
    110 	[HERO_PA        HERO-PA        0 0]
    111 	[ULM            ULM            0 0]
    112 }
    113 @Expand(AcquisitionKindTable) @Enumeration(`$(name)`) AcquisitionKind
    114 
    115 @Struct SineParameters
    116 {
    117 	[cycles    F32]
    118 	[frequency F32]
    119 }
    120 @Library @Struct SineParameters
    121 
    122 @Struct ChirpParameters
    123 {
    124 	[duration      F32]
    125 	[min_frequency F32]
    126 	[max_frequency F32]
    127 }
    128 @Library @Struct ChirpParameters
    129 
    130 @Table([type c_member m_member]) EmissionParametersTable
    131 {
    132 	[SineParameters  sine  Sine ]
    133 	[ChirpParameters chirp Chirp]
    134 }
    135 @Expand(EmissionParametersTable) @Union([`$(c_member)` `$(type)`]) EmissionParametersUnion
    136 @Expand(EmissionParametersTable) @Union([`$(m_member)` `$(type)`]) EmissionParametersUnionMATLAB
    137 @MATLAB(EmissionParameters)      @Union EmissionParametersUnionMATLAB
    138 
    139 @Struct EmissionParameters
    140 {
    141 	[kind EmissionKind]
    142 	@Union EmissionParametersUnion
    143 }
    144 @Library          @Struct EmissionParameters
    145 @MATLAB(Emission) @Struct EmissionParameters
    146 
    147 @Table([name name_lower]) FilterKindTable
    148 {
    149 	[Kaiser       kaiser       ]
    150 	[MatchedChirp matched_chirp]
    151 }
    152 @Expand(FilterKindTable) @Enumeration(`$(name)`) FilterKind
    153 
    154 @Struct KaiserFilterParameters
    155 {
    156 	[cutoff_frequency F32]
    157 	[beta             F32]
    158 	[length           U32]
    159 }
    160 @Library @Struct KaiserFilterParameters
    161 
    162 @Struct MatchedChirpFilterParameters
    163 {
    164 	[duration      F32]
    165 	[min_frequency F32]
    166 	[max_frequency F32]
    167 }
    168 @Library @Struct MatchedChirpFilterParameters
    169 
    170 @Table([type c_member m_member]) FilterParametersTable
    171 {
    172 	[KaiserFilterParameters       kaiser        Kaiser      ]
    173 	[MatchedChirpFilterParameters matched_chirp MatchedChirp]
    174 }
    175 @Expand(FilterParametersTable) @Union([`$(c_member)` `$(type)`]) FilterParametersUnion
    176 @Expand(FilterParametersTable) @Union([`$(m_member)` `$(type)`]) FilterParametersUnionMATLAB
    177 @MATLAB(FilterParameters)      @Union FilterParametersUnionMATLAB
    178 
    179 @Struct FilterParameters
    180 {
    181 	[kind               FilterKind           ]
    182 	[sampling_frequency F32                  ]
    183 	[complex            B32                  ]
    184 
    185 	@Union FilterParametersUnion
    186 }
    187 @Library        @Struct FilterParameters
    188 @MATLAB(Filter) @Struct FilterParameters
    189 
    190 @Struct Parameters
    191 {
    192 	[das_voxel_transform          M4                ]
    193 	[xdc_transform                M4                ]
    194 	[xdc_element_pitch            V2                ]
    195 	[raw_data_dimensions          UV2               ]
    196 	[focal_vector                 V2                ]
    197 	[transmit_receive_orientation U32               ]
    198 	[sample_count                 U32               ]
    199 	[channel_count                U32               ]
    200 	[acquisition_count            U32               ]
    201 	[acquisition_kind             AcquisitionKind   ]
    202 	[decode_mode                  DecodeMode        ]
    203 	[sampling_mode                SamplingMode      ]
    204 	[time_offset                  F32               ]
    205 	[single_focus                 B32               ]
    206 	[single_orientation           B32               ]
    207 	[output_points                SV4               ]
    208 	[sampling_frequency           F32               ]
    209 	[demodulation_frequency       F32               ]
    210 	[speed_of_sound               F32               ]
    211 	[f_number                     F32               ]
    212 	[interpolation_mode           InterpolationMode ]
    213 	[coherency_weighting          B32               ]
    214 	[decimation_rate              U32               ]
    215 	[contrast_mode                ContrastMode      ]
    216 	[emission_parameters          EmissionParameters]
    217 	[readi_group_count            U32               ]
    218 	[readi_group                  U32               ]
    219 }
    220 @Library @Struct Parameters
    221 @MATLAB  @Struct Parameters
    222 
    223 @Struct SimpleParameters
    224 {
    225 	@Expand(Parameters) [`$(name)` `$(type)` `$(elements)`]
    226 	[channel_mapping               S16        MaxChannelCount       ]
    227 	[sparse_elements               S16        MaxEmissionsCount     ]
    228 	[transmit_receive_orientations U8         MaxEmissionsCount     ]
    229 	[steering_angles               F32        MaxEmissionsCount     ]
    230 	[focal_depths                  F32        MaxEmissionsCount     ]
    231 	[compute_stages                S32        MaxComputeShaderStages]
    232 	[compute_stage_parameters      S32        MaxComputeShaderStages]
    233 	[compute_stages_count          U32        1                     ]
    234 	[data_kind                     DataKind   1                     ]
    235 }
    236 @Library @Struct SimpleParameters
    237 @MATLAB  @Struct SimpleParameters
    238 
    239 @Flags LiveImagingDirtyFlags
    240 {
    241 	ImagePlaneOffsets
    242 	TransmitPower
    243 	TGCControlPoints
    244 	SaveData
    245 	SaveNameTag
    246 	StopImaging
    247 	AcquisitionKind
    248 }
    249 
    250 // NOTE(rnp): we have this other name in MATLAB for some reason
    251 @Enumeration LiveFeedbackFlags
    252 {
    253 	@Expand(LiveImagingDirtyFlags) `$(name)`
    254 }
    255 
    256 @Struct LiveImagingParameters
    257 {
    258 	[active                         U32   1]
    259 	[save_enabled                   U32   1]
    260 	[save_active                    U32   1]
    261 	[acquisition_kind               U32   1]
    262 	[acquisition_kind_enabled_flags U64   1]
    263 	[transmit_power                 F32   1]
    264 	[image_plane_offsets            F32 #ViewPlaneTag]
    265 	[tgc_control_points             F32   8]
    266 	[save_name_tag_length           S32   1]
    267 	[save_name_tag                  U8  128]
    268 }
    269 @Library @Struct LiveImagingParameters
    270 @MATLAB  @Struct LiveImagingParameters
    271 
    272 @Emit
    273 {
    274 	`read_only u8 beamformer_data_kind_element_size[] = {`
    275 	@Expand(DataKindTable) `	$(size),`
    276 	`};`
    277 	``
    278 	`read_only u8 beamformer_data_kind_element_count[] = {`
    279 	@Expand(DataKindTable) `	$(elements),`
    280 	`};`
    281 	``
    282 	`read_only u8 beamformer_data_kind_byte_size[] = {`
    283 	@Expand(DataKindTable) `	$(size) * $(elements),`
    284 	`};`
    285 	``
    286 	`read_only b8 beamformer_data_kind_complex[] = {`
    287 	@Expand(DataKindTable) `	$(complex),`
    288 	`};`
    289 	``
    290 	`read_only str8 beamformer_data_kind_glsl_type[] = {`
    291 	@Expand(DataKindTable) `	str8_comp("$(glsl)"),`
    292 	`};`
    293 	``
    294 	`read_only str8 beamformer_data_kind_str8[] = {`
    295 	@Expand(DataKindTable) `	str8_comp("$(name)"),`
    296 	`};`
    297 	``
    298 	`read_only f32 beamformer_sampling_mode_samples_per_wave[] = {`
    299 	@Expand(SamplingModeTable) `	$(samples),`
    300 	`};`
    301 	``
    302 	`read_only u32 beamformer_acquisition_kind_flags[] = {`
    303 	@Expand(AcquisitionKindTable) `	($(fixed_transmits)*BeamformerAcquisitionKindFlags_FixedTransmits)|($(sparse)*BeamformerAcquisitionKindFlags_Sparse),`
    304 	`};`
    305 	``
    306 	`read_only str8 beamformer_acquisition_kind_strings[] = {`
    307 	@Expand(AcquisitionKindTable) `	str8_comp("$(pretty_name)"),`
    308 	`};`
    309 	``
    310 	`read_only u8 beamformer_contrast_mode_samples[] = {`
    311 	@Expand(ContrastModeTable) `	$(samples),`
    312 	`};`
    313 	``
    314 	`read_only str8 beamformer_contrast_mode_strings[] = {`
    315 	@Expand(ContrastModeTable) `	str8_comp("$(name)"),`
    316 	`};`
    317 	``
    318 	`read_only str8 beamformer_view_plane_tag_strings[] = {`
    319 	@Expand(ViewPlaneTag) `	str8_comp("$(name)"),`
    320 	`};`
    321 	``
    322 	`read_only str8 beamformer_emission_kind_strings[] = {`
    323 	@Expand(EmissionKind) `	str8_comp("$(name)"),`
    324 	`};`
    325 	``
    326 	`read_only str8 beamformer_interpolation_mode_strings[] = {`
    327 	@Expand(InterpolationMode) `	str8_comp("$(name)"),`
    328 	`};`
    329 	``
    330 	`read_only u8 beamformer_data_stride_indices[BeamformerDataLayout_Count][3] = {`
    331 	@Expand(DataLayoutTable) `	[BeamformerDataLayout_$(name)]$(|)= {BeamformerRFDimension_$(dim1),$(|)BeamformerRFDimension_$(dim2),$(|)BeamformerRFDimension_$(dim3)},`
    332 	`};`
    333 }
    334 
    335 @ShaderGroup Compute
    336 {
    337 	@Shader(decode.glsl) Decode
    338 	{
    339 		@Enumeration DecodeMode
    340 
    341 		@Flags
    342 		{
    343 			CooperativeMatrix
    344 			UseSharedMemory
    345 		}
    346 
    347 		@Bake
    348 		{
    349 			[Hadamard             U32]
    350 			[DecodeMode           U32]
    351 			[OutputChannelStride  U32]
    352 			[OutputSampleStride   U32]
    353 			[OutputTransmitStride U32]
    354 			[ToProcess            U32]
    355 			[TransmitCount        U32]
    356 			[ChunkChannelCount    U32]
    357 			[CooperativeMatrixM   U32]
    358 			[CooperativeMatrixN   U32]
    359 			[CooperativeMatrixK   U32]
    360 		}
    361 
    362 		@PushConstants
    363 		{
    364 			[rf_buffer     U64]
    365 			[output_buffer U64]
    366 		}
    367 	}
    368 
    369 	@Shader(filter.glsl) Filter
    370 	{
    371 		@ShaderAlias Demodulate
    372 
    373 		@Flags
    374 		{
    375 			ComplexFilter
    376 			Demodulate
    377 		}
    378 
    379 		@Bake
    380 		{
    381 			[FilterCoefficients   U32]
    382 			[FilterLength         U32]
    383 			[SamplesPerWave       F32]
    384 			[DecimationRate       U32]
    385 			[SampleCount          U32]
    386 			[BatchSampleCount     U32]
    387 			[InputChannelStride   U32]
    388 			[InputSampleStride    U32]
    389 			[InputTransmitStride  U32]
    390 			[OutputChannelStride  U32]
    391 			[OutputSampleStride   U32]
    392 			[OutputTransmitStride U32]
    393 		}
    394 
    395 		@PushConstants
    396 		{
    397 			[input_buffer  U64]
    398 			[output_buffer U64]
    399 		}
    400 	}
    401 
    402 	@Shader(das.glsl) DAS
    403 	{
    404 		@Enumeration AcquisitionKind
    405 		@Enumeration InterpolationMode
    406 		@Enumeration RCAOrientation
    407 
    408 		@Flags
    409 		{
    410 			CoherencyWeighting
    411 			Sparse
    412 		}
    413 
    414 		@Bake
    415 		{
    416 			[FocalVectors                U32]
    417 			[Hadamard                    U32]
    418 			[IncoherentFrame             U32]
    419 			[SparseElements              U32]
    420 			[TransducerTransforms        U32]
    421 			[TransmitReceiveOrientations U32]
    422 
    423 			[AcquisitionKind             U32]
    424 			[AcquisitionCount            S32]
    425 			[SampleCount                 S32]
    426 			[AcquisitionByteStride       U32]
    427 			[ChannelByteStride           U32]
    428 			[ReceiveChannelCount         U16]
    429 			[TransmitChannelCount        U16]
    430 			[ReceiveTileCount            U16]
    431 			[TransmitTileCount           U16]
    432 			[ChunkChannelCount           U16]
    433 			[TransmitReceiveOrientation  U16]
    434 
    435 			[InterpolationMode           U16]
    436 
    437 			[ReadiGroupCount             U16]
    438 
    439 			[SamplingFrequency           F32]
    440 			[SamplesPerWave              F32]
    441 			[SpeedOfSound                F32]
    442 			[TimeOffset                  F32]
    443 			[FNumber                     F32]
    444 
    445 			[OutputSizeX                 U32]
    446 			[OutputSizeY                 U32]
    447 			[OutputSizeZ                 U32]
    448 		}
    449 
    450 		@PushConstants
    451 		{
    452 			[voxel_transform     M4]
    453 			[xdc_element_pitch   V2]
    454 			[rf_data            U64]
    455 			[output_frame       U64]
    456 			[channel_offset     U32]
    457 			[focus_depth        F32]
    458 			[steering_angle     F32]
    459 			[tx_rx_orientation  U16]
    460 			[readi_group        U16]
    461 		}
    462 	}
    463 
    464 	@Shader Hilbert
    465 }
    466 
    467 // NOTE: shaders which need to be baked into the beamforming pipeline
    468 // but should not be visible to the external interface
    469 @ShaderGroup ComputeHelpers
    470 {
    471 	@Shader(coherency_weighting.glsl) CoherencyWeighting
    472 	{
    473 		@PushConstants
    474 		{
    475 			[coherent_sum  U64]
    476 		}
    477 
    478 		@Bake
    479 		{
    480 			[IncoherentSum U32]
    481 			[Scale         F32]
    482 			[OutputVoxels  U32]
    483 		}
    484 	}
    485 
    486 	@Shader(reshape.glsl) Reshape
    487 	{
    488 		@Flags
    489 		{
    490 			Deinterleave
    491 			Interleave
    492 		}
    493 
    494 		@Bake
    495 		{
    496 			[SizeX         U32]
    497 			[SizeY         U32]
    498 			[SizeZ         U32]
    499 			[InputStrideX  U32]
    500 			[InputStrideY  U32]
    501 			[InputStrideZ  U32]
    502 			[OutputStrideX U32]
    503 			[OutputStrideY U32]
    504 			[OutputStrideZ U32]
    505 		}
    506 
    507 		@PushConstants
    508 		{
    509 			[output_buffer      U64]
    510 			[left_input_buffer  U64]
    511 			[right_input_buffer U64]
    512 		}
    513 	}
    514 
    515 	@Shader(min_max.glsl) MinMax
    516 
    517 	@Shader(sum.glsl) Sum
    518 	{
    519 		@PushConstants
    520 		{
    521 			[output_data    U64]
    522 			[input_data     U64]
    523 			[image_elements U32]
    524 			[scale          F32]
    525 		}
    526 	}
    527 }
    528 
    529 @ShaderGroup Render
    530 {
    531 	@RenderShader RenderBeamformed
    532 	{
    533 		@VertexShader(render_3d.vert.glsl)
    534 		@FragmentShader(render_3d.frag.glsl)
    535 
    536 		@PushConstants
    537 		{
    538 			[mvp_matrix             M4]
    539 			[positions             U64]
    540 			[normals               U64]
    541 
    542 			[bounding_box_colour    V4]
    543 			[bounding_box_fraction F32]
    544 			[db_cutoff             F32]
    545 			[threshold             F32]
    546 			[gamma                 F32]
    547 			[input_data            U64]
    548 			[input_size_x          U32]
    549 			[input_size_y          U32]
    550 			[input_size_z          U32]
    551 			[data_kind             U32]
    552 		}
    553 	}
    554 }