ogl_beamforming

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

beamformer.meta (12623B)


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