ogl_beamforming

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

beamformer.meta (12132B)


      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             U32]
    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    U32]
    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 		@Enumeration AcquisitionKind
    384 		@Enumeration InterpolationMode
    385 		@Enumeration RCAOrientation
    386 
    387 		@Flags
    388 		{
    389 			CoherencyWeighting
    390 			SingleFocus
    391 			SingleOrientation
    392 			Sparse
    393 		}
    394 
    395 		@Bake
    396 		{
    397 			[FocalVectors                U32]
    398 			[Hadamard                    U32]
    399 			[IncoherentFrame             U32]
    400 			[SparseElements              U32]
    401 			[TransmitReceiveOrientations U32]
    402 
    403 			[AcquisitionKind             U32]
    404 			[AcquisitionCount            S32]
    405 			[ReceiveChannelCount         S32]
    406 			[ChunkChannelCount           S32]
    407 			[SampleCount                 S32]
    408 
    409 			[SamplingFrequency           F32]
    410 			[DemodulationFrequency       F32]
    411 			[SpeedOfSound                F32]
    412 			[TimeOffset                  F32]
    413 			[InterpolationMode           U32]
    414 			[FNumber                     F32]
    415 
    416 			[TransmitReceiveOrientation  U32]
    417 			[FocusDepth                  F32]
    418 			[TransmitAngle               F32]
    419 
    420 			[OutputSizeX                 U32]
    421 			[OutputSizeY                 U32]
    422 			[OutputSizeZ                 U32]
    423 
    424 			[ReadiGroupCount             U32]
    425 		}
    426 
    427 		@PushConstants
    428 		{
    429 			[xdc_transform      M4]
    430 			[voxel_transform    M4]
    431 			[xdc_element_pitch  V2]
    432 			[rf_data           U64]
    433 			[output_frame      U64]
    434 			[channel_offset    S32]
    435 			[readi_group       U32]
    436 		}
    437 	}
    438 
    439 	@Shader Hilbert
    440 }
    441 
    442 // NOTE: shaders which need to be baked into the beamforming pipeline
    443 // but should not be visible to the external interface
    444 @ShaderGroup ComputeHelpers
    445 {
    446 	@Shader(coherency_weighting.glsl) CoherencyWeighting
    447 	{
    448 		@PushConstants
    449 		{
    450 			[coherent_sum  U64]
    451 		}
    452 
    453 		@Bake
    454 		{
    455 			[IncoherentSum U32]
    456 			[Scale         F32]
    457 			[OutputVoxels  U32]
    458 		}
    459 	}
    460 
    461 	@Shader(reshape.glsl) Reshape
    462 	{
    463 		@Flags
    464 		{
    465 			Deinterleave
    466 			Interleave
    467 		}
    468 
    469 		@Bake
    470 		{
    471 			[SizeX         U32]
    472 			[SizeY         U32]
    473 			[SizeZ         U32]
    474 			[InputStrideX  U32]
    475 			[InputStrideY  U32]
    476 			[InputStrideZ  U32]
    477 			[OutputStrideX U32]
    478 			[OutputStrideY U32]
    479 			[OutputStrideZ U32]
    480 		}
    481 
    482 		@PushConstants
    483 		{
    484 			[output_buffer      U64]
    485 			[left_input_buffer  U64]
    486 			[right_input_buffer U64]
    487 		}
    488 	}
    489 
    490 	@Shader(min_max.glsl) MinMax
    491 
    492 	@Shader(sum.glsl) Sum
    493 	{
    494 		@PushConstants
    495 		{
    496 			[output_data    U64]
    497 			[input_data     U64]
    498 			[image_elements U32]
    499 			[scale          F32]
    500 		}
    501 	}
    502 }
    503 
    504 @ShaderGroup Render
    505 {
    506 	@RenderShader RenderBeamformed
    507 	{
    508 		@VertexShader(render_3d.vert.glsl)
    509 		@FragmentShader(render_3d.frag.glsl)
    510 
    511 		@PushConstants
    512 		{
    513 			[mvp_matrix             M4]
    514 			[positions             U64]
    515 			[normals               U64]
    516 
    517 			[bounding_box_colour    V4]
    518 			[bounding_box_fraction F32]
    519 			[db_cutoff             F32]
    520 			[threshold             F32]
    521 			[gamma                 F32]
    522 			[input_data            U64]
    523 			[input_size_x          U32]
    524 			[input_size_y          U32]
    525 			[input_size_z          U32]
    526 			[data_kind             U32]
    527 		}
    528 	}
    529 }