ogl_beamforming

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

beamformer.meta (13939B)


      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 		@Bake
    340 		{
    341 			[UseSharedMemory      use_shared_memory      B32]
    342 			[DecodeMode           decode_mode            U32]
    343 			[OutputChannelStride  output_channel_stride  U32]
    344 			[OutputSampleStride   output_sample_stride   U32]
    345 			[OutputTransmitStride output_transmit_stride U32]
    346 			[ToProcess            to_process             U32]
    347 			[TransmitCount        transmit_count         U32]
    348 			[ChunkChannelCount    chunk_channel_count    U32]
    349 			[CooperativeMatrix    cooperative_matrix     B32]
    350 			[CooperativeMatrixM   cooperative_matrix_m   U32]
    351 			[CooperativeMatrixN   cooperative_matrix_n   U32]
    352 			[CooperativeMatrixK   cooperative_matrix_k   U32]
    353 		}
    354 
    355 		@PushConstants
    356 		{
    357 			[hadamard_buffer  U64]
    358 			[rf_buffer        U64]
    359 			[output_buffer    U64]
    360 		}
    361 	}
    362 
    363 	@Shader(filter.glsl) Filter
    364 	{
    365 		@Enumeration ShaderBufferSlot
    366 		@Enumeration ShaderResourceKind
    367 
    368 		@ShaderAlias Demodulate
    369 
    370 		@Bake
    371 		{
    372 			[Demodulate            demodulate             U32]
    373 			[ComplexFilter         complex_filter         U32]
    374 			[DecimationRate        decimation_rate        U32]
    375 			[FilterLength          filter_length          U32]
    376 			[InputChannelStride    input_channel_stride   U32]
    377 			[InputSampleStride     input_sample_stride    U32]
    378 			[InputTransmitStride   input_transmit_stride  U32]
    379 			[OutputChannelStride   output_channel_stride  U32]
    380 			[OutputSampleStride    output_sample_stride   U32]
    381 			[OutputTransmitStride  output_transmit_stride U32]
    382 			[SampleCount           sample_count           U32]
    383 			[BatchSampleCount      batch_sample_count     U32]
    384 
    385 			[DemodulationFrequency demodulation_frequency F32]
    386 			[SamplingFrequency     sampling_frequency     F32]
    387 		}
    388 
    389 		@PushConstants
    390 		{
    391 			[input_data            U64]
    392 			[filter_coefficients   U64]
    393 			[output_element_offset U32]
    394 		}
    395 	}
    396 
    397 	@Shader(das.glsl) DAS
    398 	{
    399 		@Constant    MaxChannelCount
    400 
    401 		@Enumeration AcquisitionKind
    402 		@Enumeration InterpolationMode
    403 		@Enumeration RCAOrientation
    404 		@Enumeration ShaderBufferSlot
    405 		@Enumeration ShaderResourceKind
    406 
    407 		@Struct      DASArrayParameters
    408 
    409 		@Bake
    410 		{
    411 			[CoherencyWeighting         coherency_weighting          U32]
    412 			[SingleFocus                single_focus                 U32]
    413 			[SingleOrientation          single_orientation           U32]
    414 			[Sparse                     sparse                       U32]
    415 			[AcquisitionCount           acquisition_count            U32]
    416 			[AcquisitionKind            acquisition_kind             U32]
    417 			[ChannelCount               channel_count                U32]
    418 			[ChunkChannelCount          chunk_channel_count          U32]
    419 			[InterpolationMode          interpolation_mode           U32]
    420 			[SampleCount                sample_count                 U32]
    421 			[TransmitReceiveOrientation transmit_receive_orientation U32]
    422 
    423 			[DemodulationFrequency      demodulation_frequency       F32]
    424 			[FNumber                    f_number                     F32]
    425 			[FocusDepth                 focus_depth                  F32]
    426 			[SamplingFrequency          sampling_frequency           F32]
    427 			[SpeedOfSound               speed_of_sound               F32]
    428 			[TimeOffset                 time_offset                  F32]
    429 			[TransmitAngle              transmit_angle               F32]
    430 		}
    431 
    432 		@PushConstants
    433 		{
    434 			[xdc_transform      M4]
    435 			[voxel_transform    M4]
    436 			[xdc_element_pitch  V2]
    437 			[array_parameters  U64]
    438 			[output_frame      U64]
    439 			[incoherent_frame  U64]
    440 			[rf_element_offset U32]
    441 			[output_size_x     U32]
    442 			[output_size_y     U32]
    443 			[output_size_z     U32]
    444 			[cycle_t           U32]
    445 			[channel_offset    S32]
    446 		}
    447 	}
    448 
    449 	@Shader(sum.glsl) Sum
    450 	{
    451 		@PushConstants
    452 		{
    453 			[output_data    U64]
    454 			[input_data     U64]
    455 			[image_elements U32]
    456 			[scale          F32]
    457 		}
    458 	}
    459 
    460 	@Shader(min_max.glsl) MinMax
    461 
    462 	@Shader Hilbert
    463 }
    464 
    465 // NOTE: shaders which need to be baked into the beamforming pipeline
    466 // but should not be visible to the external interface
    467 @ShaderGroup ComputeHelpers
    468 {
    469 	@Shader(coherency_weighting.glsl) CoherencyWeighting
    470 	{
    471 		@PushConstants
    472 		{
    473 			[left_side_buffer  U64]
    474 			[right_side_buffer U64]
    475 			[scale             F32]
    476 			[output_size_x     U32]
    477 			[output_size_y     U32]
    478 			[output_size_z     U32]
    479 		}
    480 	}
    481 
    482 	@Shader(reshape.glsl) Reshape
    483 	{
    484 		@Bake
    485 		{
    486 			[SizeX          size_x           U32]
    487 			[SizeY          size_y           U32]
    488 			[SizeZ          size_z           U32]
    489 			[InputStrideX   input_stride_x   U32]
    490 			[InputStrideY   input_stride_y   U32]
    491 			[InputStrideZ   input_stride_z   U32]
    492 			[OutputStrideX  output_stride_x  U32]
    493 			[OutputStrideY  output_stride_y  U32]
    494 			[OutputStrideZ  output_stride_z  U32]
    495 			[Interleave     interleave       B32]
    496 			[Deinterleave   deinterleave     B32]
    497 		}
    498 
    499 		@PushConstants
    500 		{
    501 			[output_buffer      U64]
    502 			[left_input_buffer  U64]
    503 			[right_input_buffer U64]
    504 		}
    505 	}
    506 }
    507 
    508 @ShaderGroup Render
    509 {
    510 	@RenderShader RenderBeamformed
    511 	{
    512 		@VertexShader(render_3d.vert.glsl)
    513 		@FragmentShader(render_3d.frag.glsl)
    514 
    515 		@PushConstants
    516 		{
    517 			[mvp_matrix             M4]
    518 			[positions             U64]
    519 			[normals               U64]
    520 
    521 			[bounding_box_colour    V4]
    522 			[bounding_box_fraction F32]
    523 			[db_cutoff             F32]
    524 			[threshold             F32]
    525 			[gamma                 F32]
    526 			[input_data            U64]
    527 			[input_size_x          U32]
    528 			[input_size_y          U32]
    529 			[input_size_z          U32]
    530 			[data_kind             U32]
    531 		}
    532 	}
    533 }