demod.glsl (2787B)
1 /* See LICENSE for license details. */ 2 #version 460 core 3 layout(local_size_x = 32, local_size_y = 32, local_size_z = 1) in; 4 5 layout(std430, binding = 1) readonly restrict buffer buffer_1 { 6 vec2 in_data[]; 7 }; 8 9 layout(std430, binding = 2) writeonly restrict buffer buffer_2 { 10 vec2 out_data[]; 11 }; 12 13 layout(std140, binding = 0) uniform parameters { 14 uvec4 channel_mapping[64]; /* Transducer Channel to Verasonics Channel */ 15 uvec4 uforces_channels[32]; /* Channels used for virtual UFORCES elements */ 16 vec4 lpf_coefficients[16]; /* Low Pass Filter Cofficients */ 17 vec4 xdc_origin; /* [m] Corner of transducer being treated as origin */ 18 vec4 xdc_corner1; /* [m] Corner of transducer along first axis (arbitrary) */ 19 vec4 xdc_corner2; /* [m] Corner of transducer along second axis (arbitrary) */ 20 uvec4 dec_data_dim; /* Samples * Channels * Acquisitions; last element ignored */ 21 uvec4 output_points; /* Width * Height * Depth; last element ignored */ 22 vec4 output_min_coord; /* [m] Top left corner of output region */ 23 vec4 output_max_coord; /* [m] Bottom right corner of output region */ 24 uvec2 rf_raw_dim; /* Raw Data Dimensions */ 25 uint channel_offset; /* Offset into channel_mapping: 0 or 128 (rows or columns) */ 26 uint lpf_order; /* Order of Low Pass Filter */ 27 float speed_of_sound; /* [m/s] */ 28 float sampling_frequency; /* [Hz] */ 29 float center_frequency; /* [Hz] */ 30 float focal_depth; /* [m] */ 31 float time_offset; /* pulse length correction time [s] */ 32 uint uforces; /* mode is UFORCES (1) or FORCES (0) */ 33 float off_axis_pos; /* [m] Position on screen normal to beamform in 2D HERCULES */ 34 int beamform_plane; /* Plane to Beamform in 2D HERCULES */ 35 }; 36 37 void main() 38 { 39 uint time_sample = gl_GlobalInvocationID.x; 40 uint channel = gl_GlobalInvocationID.y; 41 uint acq = gl_GlobalInvocationID.z; 42 43 /* NOTE: offsets for storing the results in the output data */ 44 uint stride = dec_data_dim.x * dec_data_dim.y; 45 uint off = dec_data_dim.x * channel + stride * acq + time_sample; 46 47 /* NOTE: for calculating full-band I-Q data; needs to be stepped in loop */ 48 float arg = radians(360) * center_frequency * time_sample / sampling_frequency; 49 float arg_delta = radians(360) * center_frequency / sampling_frequency; 50 51 vec2 sum = vec2(0); 52 for (int i = 0; i <= lpf_order; i++) { 53 vec2 data; 54 /* NOTE: make sure data samples come from the same acquisition */ 55 if (time_sample >= i) data = in_data[off - i].xx * vec2(cos(arg), sin(arg)); 56 else data = vec2(0); 57 sum += lpf_coefficients[i / 4][i % 4] * data; 58 arg -= arg_delta; 59 } 60 out_data[off] = sum; 61 }