ogl_beamforming

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

beamformer.meta (13110B)


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