ogl_beamforming

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

beamformer.meta (12239B)


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