ogl_beamforming

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

beamformer_parameters.h (9489B)


      1 /* See LICENSE for license details. */
      2 #include <stdint.h>
      3 
      4 /* TODO(rnp):
      5  * [ ]: shader kinds have ballooned; shader stats table needs to be compressed
      6  * [ ]: Upload previously exported data for display. maybe this is a UI thing but doing it
      7  *      programatically would be nice.
      8  * [ ]: Add interface for multi frame upload. RF upload already uses an offset into SM so
      9  *      that part works fine. We just need a way of specify a multi frame upload. (Data must
     10  *      be organized for simple offset access per frame).
     11  */
     12 
     13 /* X(enumarant, shader file name, pretty name) */
     14 #define COMPUTE_SHADERS \
     15 	X(CudaDecode,  "",        "CUDA Decode")      \
     16 	X(CudaHilbert, "",        "CUDA Hilbert")     \
     17 	X(DAS,         "das",     "DAS")              \
     18 	X(Decode,      "decode",  "Decode (I16)")     \
     19 	X(Filter,      "filter",  "Filter (F32C)")    \
     20 	X(Demodulate,  "",        "Demodulate (I16)") \
     21 	X(MinMax,      "min_max", "Min/Max")          \
     22 	X(Sum,         "sum",     "Sum")
     23 
     24 #define DECODE_SHADER_VARIATIONS \
     25 	X(DecodeInt16Complex, "", "Decode (I16C)",    " (I16)")     \
     26 	X(DecodeFloat,        "", "Decode (F32)",     " (F32)")     \
     27 	X(DecodeFloatComplex, "", "Decode (F32C)",    " (F32C)")    \
     28 	X(DecodeInt16ToFloat, "", "Decode (I16-F32)", " (I16-F32)")
     29 
     30 #define FILTER_SHADER_VARIATIONS \
     31 	X(FilterCF,          "", "Filter (F32C-CF)",    " (F32C-CF)") \
     32 	X(DemodulateCF,      "", "Demodulate (I16-CF)", " (I16-CF)")  \
     33 	X(DemodulateFloat,   "", "Demodulate (F32)",    " (F32)")     \
     34 	X(DemodulateFloatCF, "", "Demodulate (F32-CF)", " (F32-CF)")
     35 
     36 #define COMPUTE_SHADERS_INTERNAL \
     37 	COMPUTE_SHADERS              \
     38 	DECODE_SHADER_VARIATIONS     \
     39 	FILTER_SHADER_VARIATIONS     \
     40 	X(DASFast, "", "DAS (Fast)")
     41 
     42 typedef enum {
     43 	#define X(e, ...) BeamformerShaderKind_##e,
     44 	COMPUTE_SHADERS_INTERNAL
     45 	#undef X
     46 	BeamformerShaderKind_Render3D,
     47 	BeamformerShaderKind_Count,
     48 
     49 	BeamformerShaderKind_ComputeCount = BeamformerShaderKind_Render3D,
     50 } BeamformerShaderKind;
     51 
     52 typedef struct {
     53 	/* NOTE(rnp): this wants to be iterated on both dimensions. it depends entirely on which
     54 	 * visualization method you want to use. the coalescing function wants both directions */
     55 	float times[32][BeamformerShaderKind_Count];
     56 	float rf_time_deltas[32];
     57 } BeamformerComputeStatsTable;
     58 
     59 /* X(type, id, pretty name) */
     60 #define DECODE_TYPES \
     61 	X(NONE,     0, "None")     \
     62 	X(HADAMARD, 1, "Hadamard")
     63 
     64 #define SAMPLING_MODES_LIST \
     65 	X(NS200BW, 0) \
     66 	X(BS100BW, 1) \
     67 	X(BS50BW,  2)
     68 
     69 #define TRANSMIT_MODES_LIST \
     70 	X(Rows)    \
     71 	X(Columns)
     72 
     73 #define RECEIVE_MODES_LIST \
     74 	X(Rows)    \
     75 	X(Columns)
     76 
     77 #define X(k, ...) BeamformerTransmitMode_## k,
     78 typedef enum {TRANSMIT_MODES_LIST} BeamformerTransmitModes;
     79 #undef X
     80 
     81 #define X(k, ...) BeamformerReceiveMode_## k,
     82 typedef enum {RECEIVE_MODES_LIST} BeamformerReceiveModes;
     83 #undef X
     84 
     85 #define X(k, v, ...) BeamformerSamplingMode_## k = v,
     86 typedef enum {SAMPLING_MODES_LIST BeamformerSamplingMode_Count} BeamformerSamplingModes;
     87 #undef X
     88 
     89 #define BEAMFORMER_DATA_KIND_LIST \
     90 	X(Int16,          0) \
     91 	X(Int16Complex,   1) \
     92 	X(Float32,        2) \
     93 	X(Float32Complex, 3)
     94 
     95 #define X(k, id) BeamformerDataKind_##k = id,
     96 typedef enum {BEAMFORMER_DATA_KIND_LIST} BeamformerDataKind;
     97 #undef X
     98 
     99 /* TODO(rnp): this is an absolute abuse of the preprocessor, but now is
    100  * not a good time to write a full metaprogram */
    101 #define BEAMFORMER_FILTER_KIND_LIST(type, _) \
    102 	X(Kaiser,       type cutoff_frequency _ type beta          _ type length) \
    103 	X(MatchedChirp, type duration         _ type min_frequency _ type max_frequency)
    104 
    105 #define X(kind, ...) BeamformerFilterKind_##kind,
    106 typedef enum {BEAMFORMER_FILTER_KIND_LIST(,) BeamformerFilterKind_Count} BeamformerFilterKind;
    107 #undef X
    108 
    109 /* X(type, id, pretty name) */
    110 #define BEAMFORMER_VIEW_PLANE_TAG_LIST \
    111 	X(XZ,        0, "XZ")        \
    112 	X(YZ,        1, "YZ")        \
    113 	X(XY,        2, "XY")        \
    114 	X(Arbitrary, 3, "Arbitrary")
    115 
    116 typedef enum {
    117 	#define X(type, id, pretty) BeamformerViewPlaneTag_##type = id,
    118 	BEAMFORMER_VIEW_PLANE_TAG_LIST
    119 	#undef X
    120 	BeamformerViewPlaneTag_Count,
    121 } BeamformerViewPlaneTag;
    122 
    123 /* X(type, id, pretty name, fixed transmits) */
    124 #define DAS_SHADER_KIND_LIST \
    125 	X(FORCES,          0, "FORCES",         1) \
    126 	X(UFORCES,         1, "UFORCES",        0) \
    127 	X(HERCULES,        2, "HERCULES",       1) \
    128 	X(RCA_VLS,         3, "VLS",            0) \
    129 	X(RCA_TPW,         4, "TPW",            0) \
    130 	X(UHERCULES,       5, "UHERCULES",      0) \
    131 	X(RACES,           6, "RACES",          1) \
    132 	X(EPIC_FORCES,     7, "EPIC-FORCES",    1) \
    133 	X(EPIC_UFORCES,    8, "EPIC-UFORCES",   0) \
    134 	X(EPIC_UHERCULES,  9, "EPIC-UHERCULES", 0) \
    135 	X(Flash,          10, "Flash",          0)
    136 
    137 #define FILTER_LOCAL_SIZE_X 64
    138 #define FILTER_LOCAL_SIZE_Y  1
    139 #define FILTER_LOCAL_SIZE_Z  1
    140 
    141 #define DECODE_LOCAL_SIZE_X  4
    142 #define DECODE_LOCAL_SIZE_Y  1
    143 #define DECODE_LOCAL_SIZE_Z 16
    144 
    145 #define DECODE_FIRST_PASS_UNIFORM_LOC 1
    146 
    147 #define DAS_LOCAL_SIZE_X  16
    148 #define DAS_LOCAL_SIZE_Y   1
    149 #define DAS_LOCAL_SIZE_Z  16
    150 
    151 #define DAS_FAST_LOCAL_SIZE_X 16
    152 #define DAS_FAST_LOCAL_SIZE_Y  1
    153 #define DAS_FAST_LOCAL_SIZE_Z 16
    154 
    155 #define DAS_VOXEL_OFFSET_UNIFORM_LOC  2
    156 #define DAS_CYCLE_T_UNIFORM_LOC       3
    157 #define DAS_FAST_CHANNEL_UNIFORM_LOC  4
    158 
    159 #define MIN_MAX_MIPS_LEVEL_UNIFORM_LOC 1
    160 #define SUM_PRESCALE_UNIFORM_LOC       1
    161 
    162 #define BEAMFORMER_CONSTANTS_LIST \
    163 	X(FilterSlots,                4) \
    164 	X(MaxChannelCount,          256) \
    165 	X(MaxComputeShaderStages,    16) \
    166 	X(MaxParameterBlockSlots,    16) \
    167 	X(MaxRawDataFramesInFlight,   3) \
    168 	X(MaxSavedFrames,            16)
    169 #define X(k, v, ...) Beamformer##k = v,
    170 enum {BEAMFORMER_CONSTANTS_LIST};
    171 #undef X
    172 
    173 /* X(name, type, size, elements, comment) */
    174 #define BEAMFORMER_PARAMS_HEAD \
    175 	X(xdc_transform,          float,    [16], 16, "IMPORTANT: column major order")           \
    176 	X(xdc_element_pitch,      float,     [2],  2, "[m] Transducer Element Pitch {row, col}") \
    177 	X(raw_data_dimensions,    uint32_t,  [2],  2, "Raw Data Dimensions")                     \
    178 	X(sample_count,           uint32_t,     ,  1, "")                                        \
    179 	X(channel_count,          uint32_t,     ,  1, "")                                        \
    180 	X(acquisition_count,      uint32_t,     ,  1, "")                                        \
    181 	X(das_shader_id,          uint32_t,     ,  1, "")                                        \
    182 	X(time_offset,            float,        ,  1, "pulse length correction time [s]")        \
    183 	X(decode,                 uint8_t,      ,  1, "Decode or just reshape data")             \
    184 	X(transmit_mode,          uint8_t,      ,  1, "Method/Orientation of Transmit")          \
    185 	X(receive_mode,           uint8_t,      ,  1, "Method/Orientation of Receive")           \
    186 	X(sampling_mode,          uint8_t,      ,  1, "")
    187 
    188 #define BEAMFORMER_UI_PARAMS \
    189 	X(output_min_coordinate,  float,     [3], 3, "[m] Back-Top-Left corner of output region")                     \
    190 	X(output_max_coordinate,  float,     [3], 3, "[m] Front-Bottom-Right corner of output region")                \
    191 	X(output_points,          int32_t,   [4], 4, "Width * Height * Depth * (Frame Average Count)")                \
    192 	X(sampling_frequency,     float,        , 1, "[Hz]")                                                          \
    193 	X(demodulation_frequency, float,        , 1, "[Hz]")                                                          \
    194 	X(speed_of_sound,         float,        , 1, "[m/s]")                                                         \
    195 	X(f_number,               float,        , 1, "F# (set to 0 to disable)")                                      \
    196 	X(off_axis_pos,           float,        , 1, "[m] Position on screen normal to beamform in TPW/VLS/HERCULES") \
    197 	X(interpolate,            uint32_t,     , 1, "Perform Cubic Interpolation of RF Samples")                     \
    198 	X(coherency_weighting,    uint32_t,     , 1, "Apply coherency weighting to output data")                      \
    199 	X(beamform_plane,         uint32_t,     , 1, "Plane to Beamform in TPW/VLS/HERCULES")                         \
    200 	X(decimation_rate,        uint32_t,     , 1, "Number of times to decimate")
    201 
    202 #define X(name, type, size, ...) type name size;
    203 typedef struct {BEAMFORMER_PARAMS_HEAD} BeamformerParametersHead;
    204 typedef struct {BEAMFORMER_UI_PARAMS}   BeamformerUIParameters;
    205 
    206 typedef struct {
    207 	BEAMFORMER_PARAMS_HEAD
    208 	BEAMFORMER_UI_PARAMS
    209 } BeamformerParameters;
    210 #undef X
    211 
    212 #define BEAMFORMER_LIVE_IMAGING_DIRTY_FLAG_LIST \
    213 	X(ImagePlaneOffsets, 0) \
    214 	X(TransmitPower,     1) \
    215 	X(TGCControlPoints,  2) \
    216 	X(SaveData,          3) \
    217 	X(SaveNameTag,       4) \
    218 	X(StopImaging,       5)
    219 /* NOTE(rnp): if this exceeds 32 you need to fix the flag handling code */
    220 
    221 #define BEAMFORMER_LIVE_IMAGING_PARAMETERS_LIST \
    222 	X(active,               uint32_t, ,                               1)   \
    223 	X(save_enabled,         uint32_t, ,                               1)   \
    224 	X(save_active,          uint32_t, ,                               1)   \
    225 	X(transmit_power,       float,    ,                               1)   \
    226 	X(image_plane_offsets,  float,    [BeamformerViewPlaneTag_Count], BeamformerViewPlaneTag_Count) \
    227 	X(tgc_control_points,   float,    [8],                            8)   \
    228 	X(save_name_tag_length, int32_t,  ,                               1)   \
    229 	X(save_name_tag,        char,     [128],                          128)
    230 
    231 #define X(name, type, size, ...) type name size;
    232 typedef struct {BEAMFORMER_LIVE_IMAGING_PARAMETERS_LIST} BeamformerLiveImagingParameters;
    233 #undef X