ogl_beamforming

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

beamformer.meta (12887B)


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