| File: | root/firefox-clang/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/build/swgl-250521f66641ef82/out/cs_border_solid.h |
| Warning: | line 433, column 31 Value stored to 'data' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | struct cs_border_solid_common { |
| 2 | struct Samplers { |
| 3 | sampler2D_impl sGpuBufferF_impl; |
| 4 | int sGpuBufferF_slot; |
| 5 | isampler2D_impl sGpuBufferI_impl; |
| 6 | int sGpuBufferI_slot; |
| 7 | bool set_slot(int index, int value) { |
| 8 | switch (index) { |
| 9 | case 1: |
| 10 | sGpuBufferF_slot = value; |
| 11 | return true; |
| 12 | case 2: |
| 13 | sGpuBufferI_slot = value; |
| 14 | return true; |
| 15 | } |
| 16 | return false; |
| 17 | } |
| 18 | } samplers; |
| 19 | struct AttribLocations { |
| 20 | int aPosition = NULL_ATTRIB16; |
| 21 | int aTaskOrigin = NULL_ATTRIB16; |
| 22 | int aFlags = NULL_ATTRIB16; |
| 23 | int aGpuDataAddress = NULL_ATTRIB16; |
| 24 | int aClipParams1 = NULL_ATTRIB16; |
| 25 | int aClipParams2 = NULL_ATTRIB16; |
| 26 | void bind_loc(const char* name, int index) { |
| 27 | if (strcmp("aPosition", name) == 0) { aPosition = index; return; } |
| 28 | if (strcmp("aTaskOrigin", name) == 0) { aTaskOrigin = index; return; } |
| 29 | if (strcmp("aFlags", name) == 0) { aFlags = index; return; } |
| 30 | if (strcmp("aGpuDataAddress", name) == 0) { aGpuDataAddress = index; return; } |
| 31 | if (strcmp("aClipParams1", name) == 0) { aClipParams1 = index; return; } |
| 32 | if (strcmp("aClipParams2", name) == 0) { aClipParams2 = index; return; } |
| 33 | } |
| 34 | int get_loc(const char* name) const { |
| 35 | if (strcmp("aPosition", name) == 0) { return aPosition != NULL_ATTRIB16 ? aPosition : -1; } |
| 36 | if (strcmp("aTaskOrigin", name) == 0) { return aTaskOrigin != NULL_ATTRIB16 ? aTaskOrigin : -1; } |
| 37 | if (strcmp("aFlags", name) == 0) { return aFlags != NULL_ATTRIB16 ? aFlags : -1; } |
| 38 | if (strcmp("aGpuDataAddress", name) == 0) { return aGpuDataAddress != NULL_ATTRIB16 ? aGpuDataAddress : -1; } |
| 39 | if (strcmp("aClipParams1", name) == 0) { return aClipParams1 != NULL_ATTRIB16 ? aClipParams1 : -1; } |
| 40 | if (strcmp("aClipParams2", name) == 0) { return aClipParams2 != NULL_ATTRIB16 ? aClipParams2 : -1; } |
| 41 | return -1; |
| 42 | } |
| 43 | } attrib_locations; |
| 44 | ivec2_scalar vGpuDataAddress; |
| 45 | vec4_scalar vColor0; |
| 46 | vec4_scalar vColor1; |
| 47 | vec4_scalar vColorLine; |
| 48 | ivec2_scalar vMixColors; |
| 49 | vec4_scalar vClipCenter_Sign; |
| 50 | vec4_scalar vClipRadii; |
| 51 | vec4_scalar vHorizontalClipCenter_Sign; |
| 52 | vec2_scalar vHorizontalClipRadii; |
| 53 | vec4_scalar vVerticalClipCenter_Sign; |
| 54 | vec2_scalar vVerticalClipRadii; |
| 55 | sampler2D sGpuBufferF; |
| 56 | isampler2D sGpuBufferI; |
| 57 | mat4_scalar uTransform; |
| 58 | void bind_textures() { |
| 59 | sGpuBufferF = lookup_sampler(&samplers.sGpuBufferF_impl, samplers.sGpuBufferF_slot); |
| 60 | sGpuBufferI = lookup_isampler(&samplers.sGpuBufferI_impl, samplers.sGpuBufferI_slot); |
| 61 | } |
| 62 | }; |
| 63 | struct cs_border_solid_vert : VertexShaderImpl, cs_border_solid_common { |
| 64 | private: |
| 65 | typedef cs_border_solid_vert Self; |
| 66 | // mat4_scalar uTransform; |
| 67 | vec2 aPosition; |
| 68 | struct RectWithSize_scalar { |
| 69 | vec2_scalar p0; |
| 70 | vec2_scalar size; |
| 71 | RectWithSize_scalar() = default; |
| 72 | RectWithSize_scalar(vec2_scalar p0, vec2_scalar size) : p0(p0), size(size){} |
| 73 | }; |
| 74 | struct RectWithSize { |
| 75 | vec2 p0; |
| 76 | vec2 size; |
| 77 | RectWithSize() = default; |
| 78 | RectWithSize(vec2 p0, vec2 size) : p0(p0), size(size){} |
| 79 | RectWithSize(vec2_scalar p0, vec2_scalar size):p0(p0),size(size){ |
| 80 | } |
| 81 | IMPLICIT RectWithSize(RectWithSize_scalar s):p0(s.p0),size(s.size){ |
| 82 | } |
| 83 | friend RectWithSize if_then_else(I32 c, RectWithSize t, RectWithSize e) { return RectWithSize( |
| 84 | if_then_else(c, t.p0, e.p0), if_then_else(c, t.size, e.size)); |
| 85 | }}; |
| 86 | struct RectWithEndpoint_scalar { |
| 87 | vec2_scalar p0; |
| 88 | vec2_scalar p1; |
| 89 | RectWithEndpoint_scalar() = default; |
| 90 | RectWithEndpoint_scalar(vec2_scalar p0, vec2_scalar p1) : p0(p0), p1(p1){} |
| 91 | }; |
| 92 | struct RectWithEndpoint { |
| 93 | vec2 p0; |
| 94 | vec2 p1; |
| 95 | RectWithEndpoint() = default; |
| 96 | RectWithEndpoint(vec2 p0, vec2 p1) : p0(p0), p1(p1){} |
| 97 | RectWithEndpoint(vec2_scalar p0, vec2_scalar p1):p0(p0),p1(p1){ |
| 98 | } |
| 99 | IMPLICIT RectWithEndpoint(RectWithEndpoint_scalar s):p0(s.p0),p1(s.p1){ |
| 100 | } |
| 101 | friend RectWithEndpoint if_then_else(I32 c, RectWithEndpoint t, RectWithEndpoint e) { return RectWithEndpoint( |
| 102 | if_then_else(c, t.p0, e.p0), if_then_else(c, t.p1, e.p1)); |
| 103 | }}; |
| 104 | // sampler2D sGpuBufferF; |
| 105 | // isampler2D sGpuBufferI; |
| 106 | vec2_scalar aTaskOrigin; |
| 107 | int32_t aFlags; |
| 108 | int32_t aGpuDataAddress; |
| 109 | vec4_scalar aClipParams1; |
| 110 | vec4_scalar aClipParams2; |
| 111 | struct BorderInstanceGpuData_scalar { |
| 112 | vec4_scalar rect; |
| 113 | vec4_scalar color0; |
| 114 | vec4_scalar color1; |
| 115 | vec2_scalar widths; |
| 116 | vec2_scalar radii; |
| 117 | BorderInstanceGpuData_scalar() = default; |
| 118 | BorderInstanceGpuData_scalar(vec4_scalar rect, vec4_scalar color0, vec4_scalar color1, vec2_scalar widths, vec2_scalar radii) : rect(rect), color0(color0), color1(color1), widths(widths), radii(radii){} |
| 119 | }; |
| 120 | struct BorderInstanceGpuData { |
| 121 | vec4 rect; |
| 122 | vec4 color0; |
| 123 | vec4 color1; |
| 124 | vec2 widths; |
| 125 | vec2 radii; |
| 126 | BorderInstanceGpuData() = default; |
| 127 | BorderInstanceGpuData(vec4 rect, vec4 color0, vec4 color1, vec2 widths, vec2 radii) : rect(rect), color0(color0), color1(color1), widths(widths), radii(radii){} |
| 128 | BorderInstanceGpuData(vec4_scalar rect, vec4_scalar color0, vec4_scalar color1, vec2_scalar widths, vec2_scalar radii):rect(rect),color0(color0),color1(color1),widths(widths),radii(radii){ |
| 129 | } |
| 130 | IMPLICIT BorderInstanceGpuData(BorderInstanceGpuData_scalar s):rect(s.rect),color0(s.color0),color1(s.color1),widths(s.widths),radii(s.radii){ |
| 131 | } |
| 132 | friend BorderInstanceGpuData if_then_else(I32 c, BorderInstanceGpuData t, BorderInstanceGpuData e) { return BorderInstanceGpuData( |
| 133 | if_then_else(c, t.rect, e.rect), if_then_else(c, t.color0, e.color0), if_then_else(c, t.color1, e.color1), if_then_else(c, t.widths, e.widths), if_then_else(c, t.radii, e.radii)); |
| 134 | }}; |
| 135 | // ivec2_scalar vGpuDataAddress; |
| 136 | // vec4_scalar vColor0; |
| 137 | // vec4_scalar vColor1; |
| 138 | // vec4_scalar vColorLine; |
| 139 | // ivec2_scalar vMixColors; |
| 140 | // vec4_scalar vClipCenter_Sign; |
| 141 | // vec4_scalar vClipRadii; |
| 142 | // vec4_scalar vHorizontalClipCenter_Sign; |
| 143 | // vec2_scalar vHorizontalClipRadii; |
| 144 | // vec4_scalar vVerticalClipCenter_Sign; |
| 145 | // vec2_scalar vVerticalClipRadii; |
| 146 | vec2 vPos; |
| 147 | ivec2_scalar get_gpu_buffer_uv(int32_t address) { |
| 148 | return make_ivec2((make_uint(address))%(1024u), (make_uint(address))/(1024u)); |
| 149 | } |
| 150 | Array<vec4_scalar,4> fetch_from_gpu_buffer_4f_direct(ivec2_scalar uv) { |
| 151 | auto sGpuBufferF_uv_fetch = texelFetchPtr(sGpuBufferF, uv, 0, 3, 0, 0); |
| 152 | return Array<vec4_scalar,4>{{texelFetchUnchecked(sGpuBufferF, sGpuBufferF_uv_fetch, 0, 0), texelFetchUnchecked(sGpuBufferF, sGpuBufferF_uv_fetch, 1, 0), texelFetchUnchecked(sGpuBufferF, sGpuBufferF_uv_fetch, 2, 0), texelFetchUnchecked(sGpuBufferF, sGpuBufferF_uv_fetch, 3, 0)}}; |
| 153 | } |
| 154 | Array<vec4_scalar,4> fetch_from_gpu_buffer_4f(int32_t address) { |
| 155 | ivec2_scalar uv = get_gpu_buffer_uv(address); |
| 156 | return fetch_from_gpu_buffer_4f_direct(uv); |
| 157 | } |
| 158 | BorderInstanceGpuData_scalar fetch_gpu_data(int32_t index) { |
| 159 | BorderInstanceGpuData_scalar data; |
| 160 | Array<vec4_scalar,4> texels = fetch_from_gpu_buffer_4f(index); |
| 161 | (data).rect = texels[0]; |
| 162 | (data).color0 = texels[1]; |
| 163 | (data).color1 = texels[2]; |
| 164 | (data).widths = (texels[3]).sel(X,Y); |
| 165 | (data).radii = (texels[3]).sel(Z,W); |
| 166 | return data; |
| 167 | } |
| 168 | vec2_scalar get_outer_corner_scale(int32_t segment) { |
| 169 | vec2_scalar p; |
| 170 | switch (segment) { |
| 171 | case 0: |
| 172 | p = make_vec2(0.f, 0.f); |
| 173 | break; |
| 174 | case 1: |
| 175 | p = make_vec2(1.f, 0.f); |
| 176 | break; |
| 177 | case 2: |
| 178 | p = make_vec2(1.f, 1.f); |
| 179 | break; |
| 180 | case 3: |
| 181 | p = make_vec2(0.f, 1.f); |
| 182 | break; |
| 183 | default: |
| 184 | p = make_vec2(0.f); |
| 185 | break; |
| 186 | } |
| 187 | return p; |
| 188 | } |
| 189 | ALWAYS_INLINE__attribute__((always_inline)) inline void main(void) { |
| 190 | BorderInstanceGpuData_scalar data = fetch_gpu_data(aGpuDataAddress); |
| 191 | (vGpuDataAddress).x = aGpuDataAddress; |
| 192 | int32_t segment = (aFlags)&(255); |
| 193 | bool do_aa = (((aFlags)>>(28))&(1))!=(0); |
| 194 | vec2_scalar outer_scale = get_outer_corner_scale(segment); |
| 195 | vec2_scalar size = (((data).rect).sel(Z,W))-(((data).rect).sel(X,Y)); |
| 196 | vec2_scalar outer = (outer_scale)*(size); |
| 197 | vec2_scalar clip_sign = (1.f)-((2.f)*(outer_scale)); |
| 198 | int32_t mix_colors; |
| 199 | switch (segment) { |
| 200 | case 0: |
| 201 | case 1: |
| 202 | case 2: |
| 203 | case 3: |
| 204 | { |
| 205 | mix_colors = do_aa ? 1 : 2; |
| 206 | break; |
| 207 | } |
| 208 | default: |
| 209 | mix_colors = 0; |
| 210 | break; |
| 211 | } |
| 212 | (vMixColors).x = mix_colors; |
| 213 | vPos = (size)*((aPosition).sel(X,Y)); |
| 214 | vColor0 = (data).color0; |
| 215 | vColor1 = (data).color1; |
| 216 | vClipCenter_Sign = make_vec4((outer)+((clip_sign)*((data).radii)), clip_sign); |
| 217 | vClipRadii = make_vec4((data).radii, max(((data).radii)-((data).widths), 0.f)); |
| 218 | vColorLine = make_vec4(outer, (((data).widths).y)*(-((clip_sign).y)), (((data).widths).x)*((clip_sign).x)); |
| 219 | vec2_scalar horizontal_clip_sign = make_vec2(-((clip_sign).x), (clip_sign).y); |
| 220 | vHorizontalClipCenter_Sign = make_vec4(((aClipParams1).sel(X,Y))+((horizontal_clip_sign)*((aClipParams1).sel(Z,W))), horizontal_clip_sign); |
| 221 | vHorizontalClipRadii = (aClipParams1).sel(Z,W); |
| 222 | vec2_scalar vertical_clip_sign = make_vec2((clip_sign).x, -((clip_sign).y)); |
| 223 | vVerticalClipCenter_Sign = make_vec4(((aClipParams2).sel(X,Y))+((vertical_clip_sign)*((aClipParams2).sel(Z,W))), vertical_clip_sign); |
| 224 | vVerticalClipRadii = (aClipParams2).sel(Z,W); |
| 225 | gl_Position = (uTransform)*(make_vec4(((aTaskOrigin)+(((data).rect).sel(X,Y)))+(vPos), 0.f, 1.f)); |
| 226 | } |
| 227 | static void set_uniform_1i(VertexShaderImpl* impl, int index, int value) { |
| 228 | Self* self = (Self*)impl; |
| 229 | if (self->samplers.set_slot(index, value)) return; |
| 230 | switch (index) { |
| 231 | case 1: |
| 232 | assert(0)(static_cast <bool> (0) ? void (0) : __assert_fail ("0" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); // sGpuBufferF |
| 233 | break; |
| 234 | case 2: |
| 235 | assert(0)(static_cast <bool> (0) ? void (0) : __assert_fail ("0" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); // sGpuBufferI |
| 236 | break; |
| 237 | case 3: |
| 238 | assert(0)(static_cast <bool> (0) ? void (0) : __assert_fail ("0" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); // uTransform |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | static void set_uniform_4fv(VertexShaderImpl* impl, int index, const float *value) { |
| 243 | Self* self = (Self*)impl; |
| 244 | switch (index) { |
| 245 | case 1: |
| 246 | assert(0)(static_cast <bool> (0) ? void (0) : __assert_fail ("0" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); // sGpuBufferF |
| 247 | break; |
| 248 | case 2: |
| 249 | assert(0)(static_cast <bool> (0) ? void (0) : __assert_fail ("0" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); // sGpuBufferI |
| 250 | break; |
| 251 | case 3: |
| 252 | assert(0)(static_cast <bool> (0) ? void (0) : __assert_fail ("0" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); // uTransform |
| 253 | break; |
| 254 | } |
| 255 | } |
| 256 | static void set_uniform_matrix4fv(VertexShaderImpl* impl, int index, const float *value) { |
| 257 | Self* self = (Self*)impl; |
| 258 | switch (index) { |
| 259 | case 1: |
| 260 | assert(0)(static_cast <bool> (0) ? void (0) : __assert_fail ("0" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); // sGpuBufferF |
| 261 | break; |
| 262 | case 2: |
| 263 | assert(0)(static_cast <bool> (0) ? void (0) : __assert_fail ("0" , __builtin_FILE (), __builtin_LINE (), __extension__ __PRETTY_FUNCTION__ )); // sGpuBufferI |
| 264 | break; |
| 265 | case 3: |
| 266 | self->uTransform = mat4_scalar::load_from_ptr(value); |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | static void load_attribs(VertexShaderImpl* impl, VertexAttrib *attribs, uint32_t start, int instance, int count) {Self* self = (Self*)impl; |
| 271 | load_attrib(self->aPosition, attribs[self->attrib_locations.aPosition], start, instance, count); |
| 272 | load_flat_attrib(self->aTaskOrigin, attribs[self->attrib_locations.aTaskOrigin], start, instance, count); |
| 273 | load_flat_attrib(self->aFlags, attribs[self->attrib_locations.aFlags], start, instance, count); |
| 274 | load_flat_attrib(self->aGpuDataAddress, attribs[self->attrib_locations.aGpuDataAddress], start, instance, count); |
| 275 | load_flat_attrib(self->aClipParams1, attribs[self->attrib_locations.aClipParams1], start, instance, count); |
| 276 | load_flat_attrib(self->aClipParams2, attribs[self->attrib_locations.aClipParams2], start, instance, count); |
| 277 | } |
| 278 | public: |
| 279 | struct InterpOutputs { |
| 280 | vec2_scalar vPos; |
| 281 | }; |
| 282 | private: |
| 283 | ALWAYS_INLINE__attribute__((always_inline)) inline void store_interp_outputs(char* dest_ptr, size_t stride) { |
| 284 | for(int n = 0; n < 4; n++) { |
| 285 | auto* dest = reinterpret_cast<InterpOutputs*>(dest_ptr); |
| 286 | dest->vPos = get_nth(vPos, n); |
| 287 | dest_ptr += stride; |
| 288 | } |
| 289 | } |
| 290 | static void run(VertexShaderImpl* impl, char* interps, size_t interp_stride) { |
| 291 | Self* self = (Self*)impl; |
| 292 | self->main(); |
| 293 | self->store_interp_outputs(interps, interp_stride); |
| 294 | } |
| 295 | static void init_batch(VertexShaderImpl* impl) { |
| 296 | Self* self = (Self*)impl; self->bind_textures(); } |
| 297 | public: |
| 298 | cs_border_solid_vert() { |
| 299 | set_uniform_1i_func = &set_uniform_1i; |
| 300 | set_uniform_4fv_func = &set_uniform_4fv; |
| 301 | set_uniform_matrix4fv_func = &set_uniform_matrix4fv; |
| 302 | init_batch_func = &init_batch; |
| 303 | load_attribs_func = &load_attribs; |
| 304 | run_primitive_func = &run; |
| 305 | } |
| 306 | }; |
| 307 | |
| 308 | |
| 309 | struct cs_border_solid_frag : FragmentShaderImpl, cs_border_solid_vert { |
| 310 | private: |
| 311 | typedef cs_border_solid_frag Self; |
| 312 | #define oFragColorgl_FragColor gl_FragColor |
| 313 | // vec4 oFragColor; |
| 314 | struct RectWithSize_scalar { |
| 315 | vec2_scalar p0; |
| 316 | vec2_scalar size; |
| 317 | RectWithSize_scalar() = default; |
| 318 | RectWithSize_scalar(vec2_scalar p0, vec2_scalar size) : p0(p0), size(size){} |
| 319 | }; |
| 320 | struct RectWithSize { |
| 321 | vec2 p0; |
| 322 | vec2 size; |
| 323 | RectWithSize() = default; |
| 324 | RectWithSize(vec2 p0, vec2 size) : p0(p0), size(size){} |
| 325 | RectWithSize(vec2_scalar p0, vec2_scalar size):p0(p0),size(size){ |
| 326 | } |
| 327 | IMPLICIT RectWithSize(RectWithSize_scalar s):p0(s.p0),size(s.size){ |
| 328 | } |
| 329 | friend RectWithSize if_then_else(I32 c, RectWithSize t, RectWithSize e) { return RectWithSize( |
| 330 | if_then_else(c, t.p0, e.p0), if_then_else(c, t.size, e.size)); |
| 331 | }}; |
| 332 | struct RectWithEndpoint_scalar { |
| 333 | vec2_scalar p0; |
| 334 | vec2_scalar p1; |
| 335 | RectWithEndpoint_scalar() = default; |
| 336 | RectWithEndpoint_scalar(vec2_scalar p0, vec2_scalar p1) : p0(p0), p1(p1){} |
| 337 | }; |
| 338 | struct RectWithEndpoint { |
| 339 | vec2 p0; |
| 340 | vec2 p1; |
| 341 | RectWithEndpoint() = default; |
| 342 | RectWithEndpoint(vec2 p0, vec2 p1) : p0(p0), p1(p1){} |
| 343 | RectWithEndpoint(vec2_scalar p0, vec2_scalar p1):p0(p0),p1(p1){ |
| 344 | } |
| 345 | IMPLICIT RectWithEndpoint(RectWithEndpoint_scalar s):p0(s.p0),p1(s.p1){ |
| 346 | } |
| 347 | friend RectWithEndpoint if_then_else(I32 c, RectWithEndpoint t, RectWithEndpoint e) { return RectWithEndpoint( |
| 348 | if_then_else(c, t.p0, e.p0), if_then_else(c, t.p1, e.p1)); |
| 349 | }}; |
| 350 | // sampler2D sGpuBufferF; |
| 351 | // isampler2D sGpuBufferI; |
| 352 | struct BorderInstanceGpuData_scalar { |
| 353 | vec4_scalar rect; |
| 354 | vec4_scalar color0; |
| 355 | vec4_scalar color1; |
| 356 | vec2_scalar widths; |
| 357 | vec2_scalar radii; |
| 358 | BorderInstanceGpuData_scalar() = default; |
| 359 | BorderInstanceGpuData_scalar(vec4_scalar rect, vec4_scalar color0, vec4_scalar color1, vec2_scalar widths, vec2_scalar radii) : rect(rect), color0(color0), color1(color1), widths(widths), radii(radii){} |
| 360 | }; |
| 361 | struct BorderInstanceGpuData { |
| 362 | vec4 rect; |
| 363 | vec4 color0; |
| 364 | vec4 color1; |
| 365 | vec2 widths; |
| 366 | vec2 radii; |
| 367 | BorderInstanceGpuData() = default; |
| 368 | BorderInstanceGpuData(vec4 rect, vec4 color0, vec4 color1, vec2 widths, vec2 radii) : rect(rect), color0(color0), color1(color1), widths(widths), radii(radii){} |
| 369 | BorderInstanceGpuData(vec4_scalar rect, vec4_scalar color0, vec4_scalar color1, vec2_scalar widths, vec2_scalar radii):rect(rect),color0(color0),color1(color1),widths(widths),radii(radii){ |
| 370 | } |
| 371 | IMPLICIT BorderInstanceGpuData(BorderInstanceGpuData_scalar s):rect(s.rect),color0(s.color0),color1(s.color1),widths(s.widths),radii(s.radii){ |
| 372 | } |
| 373 | friend BorderInstanceGpuData if_then_else(I32 c, BorderInstanceGpuData t, BorderInstanceGpuData e) { return BorderInstanceGpuData( |
| 374 | if_then_else(c, t.rect, e.rect), if_then_else(c, t.color0, e.color0), if_then_else(c, t.color1, e.color1), if_then_else(c, t.widths, e.widths), if_then_else(c, t.radii, e.radii)); |
| 375 | }}; |
| 376 | // ivec2_scalar vGpuDataAddress; |
| 377 | // vec4_scalar vColor0; |
| 378 | // vec4_scalar vColor1; |
| 379 | // vec4_scalar vColorLine; |
| 380 | // ivec2_scalar vMixColors; |
| 381 | // vec4_scalar vClipCenter_Sign; |
| 382 | // vec4_scalar vClipRadii; |
| 383 | // vec4_scalar vHorizontalClipCenter_Sign; |
| 384 | // vec2_scalar vHorizontalClipRadii; |
| 385 | // vec4_scalar vVerticalClipCenter_Sign; |
| 386 | // vec2_scalar vVerticalClipRadii; |
| 387 | vec2 vPos; |
| 388 | ivec2_scalar get_gpu_buffer_uv(int32_t address) { |
| 389 | return make_ivec2((make_uint(address))%(1024u), (make_uint(address))/(1024u)); |
| 390 | } |
| 391 | Array<vec4_scalar,4> fetch_from_gpu_buffer_4f_direct(ivec2_scalar uv) { |
| 392 | auto sGpuBufferF_uv_fetch = texelFetchPtr(sGpuBufferF, uv, 0, 3, 0, 0); |
| 393 | return Array<vec4_scalar,4>{{texelFetchUnchecked(sGpuBufferF, sGpuBufferF_uv_fetch, 0, 0), texelFetchUnchecked(sGpuBufferF, sGpuBufferF_uv_fetch, 1, 0), texelFetchUnchecked(sGpuBufferF, sGpuBufferF_uv_fetch, 2, 0), texelFetchUnchecked(sGpuBufferF, sGpuBufferF_uv_fetch, 3, 0)}}; |
| 394 | } |
| 395 | Array<vec4_scalar,4> fetch_from_gpu_buffer_4f(int32_t address) { |
| 396 | ivec2_scalar uv = get_gpu_buffer_uv(address); |
| 397 | return fetch_from_gpu_buffer_4f_direct(uv); |
| 398 | } |
| 399 | BorderInstanceGpuData_scalar fetch_gpu_data(int32_t index) { |
| 400 | BorderInstanceGpuData_scalar data; |
| 401 | Array<vec4_scalar,4> texels = fetch_from_gpu_buffer_4f(index); |
| 402 | (data).rect = texels[0]; |
| 403 | (data).color0 = texels[1]; |
| 404 | (data).color1 = texels[2]; |
| 405 | (data).widths = (texels[3]).sel(X,Y); |
| 406 | (data).radii = (texels[3]).sel(Z,W); |
| 407 | return data; |
| 408 | } |
| 409 | float compute_aa_range(vec2 position) { |
| 410 | return recip((fwidth(position)).x); |
| 411 | } |
| 412 | Float distance_to_line(vec2_scalar p0, vec2_scalar perp_dir, vec2 p) { |
| 413 | vec2 dir_to_p0 = (p0)-(p); |
| 414 | return dot(normalize(perp_dir), dir_to_p0); |
| 415 | } |
| 416 | Float distance_aa(float aa_range, Float signed_distance) { |
| 417 | Float dist = (signed_distance)*(aa_range); |
| 418 | return clamp((0.5f)-(dist), 0.f, 1.f); |
| 419 | } |
| 420 | Float distance_to_ellipse_approx(vec2 p, vec2_scalar inv_radii_sq, float scale) { |
| 421 | vec2 p_r = (p)*(inv_radii_sq); |
| 422 | Float g = (dot(p, p_r))-(scale); |
| 423 | vec2 dG = ((1.f)+(scale))*(p_r); |
| 424 | return (g)*(inversesqrt(dot(dG, dG))); |
| 425 | } |
| 426 | vec2_scalar inverse_radii_squared(vec2_scalar radii) { |
| 427 | return (1.f)/(max((radii)*(radii), 0.000001f)); |
| 428 | } |
| 429 | Float distance_to_ellipse(vec2 p, vec2_scalar radii) { |
| 430 | return distance_to_ellipse_approx(p, inverse_radii_squared(radii), make_float((make_int(all(greaterThan(radii, make_vec2(0.f)))))&(1))); |
| 431 | } |
| 432 | ALWAYS_INLINE__attribute__((always_inline)) inline void main(void) { |
| 433 | BorderInstanceGpuData_scalar data = fetch_gpu_data((vGpuDataAddress).x); |
Value stored to 'data' during its initialization is never read | |
| 434 | float aa_range = compute_aa_range(vPos); |
| 435 | bool do_aa = ((vMixColors).x)!=(2); |
| 436 | Float mix_factor = 0.f; |
| 437 | if (((vMixColors).x)!=(0)) { |
| 438 | { |
| 439 | Float d_line = distance_to_line((vColorLine).sel(X,Y), (vColorLine).sel(Z,W), vPos); |
| 440 | if (do_aa) { |
| 441 | { |
| 442 | mix_factor = distance_aa(aa_range, -(d_line)); |
| 443 | } |
| 444 | } else { |
| 445 | mix_factor = if_then_else(((d_line)+(0.0001f))>=(0.f), 1.f, 0.f); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | vec2 clip_relative_pos = (vPos)-((vClipCenter_Sign).sel(X,Y)); |
| 450 | Bool in_clip_region = all(lessThan(((vClipCenter_Sign).sel(Z,W))*(clip_relative_pos), make_vec2(0.f))); |
| 451 | Float d = -(1.f); |
| 452 | auto _c4_ = in_clip_region; |
| 453 | { |
| 454 | Float d_radii_a; |
| 455 | Float d_radii_b; |
| 456 | d_radii_a = if_then_else(_c4_,distance_to_ellipse(clip_relative_pos, (vClipRadii).sel(X,Y)),d_radii_a); |
| 457 | d_radii_b = if_then_else(_c4_,distance_to_ellipse(clip_relative_pos, (vClipRadii).sel(Z,W)),d_radii_b); |
| 458 | d = if_then_else(_c4_,max(d_radii_a, -(d_radii_b)),d); |
| 459 | } |
| 460 | clip_relative_pos = (vPos)-((vHorizontalClipCenter_Sign).sel(X,Y)); |
| 461 | in_clip_region = all(lessThan(((vHorizontalClipCenter_Sign).sel(Z,W))*(clip_relative_pos), make_vec2(0.f))); |
| 462 | auto _c5_ = in_clip_region; |
| 463 | { |
| 464 | Float d_radii = distance_to_ellipse(clip_relative_pos, (vHorizontalClipRadii).sel(X,Y)); |
| 465 | d = if_then_else(_c5_,max(d_radii, d),d); |
| 466 | } |
| 467 | clip_relative_pos = (vPos)-((vVerticalClipCenter_Sign).sel(X,Y)); |
| 468 | in_clip_region = all(lessThan(((vVerticalClipCenter_Sign).sel(Z,W))*(clip_relative_pos), make_vec2(0.f))); |
| 469 | auto _c6_ = in_clip_region; |
| 470 | { |
| 471 | Float d_radii = distance_to_ellipse(clip_relative_pos, (vVerticalClipRadii).sel(X,Y)); |
| 472 | d = if_then_else(_c6_,max(d_radii, d),d); |
| 473 | } |
| 474 | Float alpha = do_aa ? distance_aa(aa_range, d) : 1.f; |
| 475 | vec4 color = mix(vColor0, vColor1, mix_factor); |
| 476 | oFragColorgl_FragColor = (color)*(alpha); |
| 477 | } |
| 478 | typedef cs_border_solid_vert::InterpOutputs InterpInputs; |
| 479 | InterpInputs interp_step; |
| 480 | struct InterpPerspective { |
| 481 | vec2 vPos; |
| 482 | }; |
| 483 | InterpPerspective interp_perspective; |
| 484 | static void read_interp_inputs(FragmentShaderImpl* impl, const void* init_, const void* step_) {Self* self = (Self*)impl;const InterpInputs* init = (const InterpInputs*)init_;const InterpInputs* step = (const InterpInputs*)step_; |
| 485 | self->vPos = init_interp(init->vPos, step->vPos); |
| 486 | self->interp_step.vPos = step->vPos * 4.0f; |
| 487 | } |
| 488 | static void read_perspective_inputs(FragmentShaderImpl* impl, const void* init_, const void* step_) {Self* self = (Self*)impl;const InterpInputs* init = (const InterpInputs*)init_;const InterpInputs* step = (const InterpInputs*)step_; |
| 489 | Float w = 1.0f / self->gl_FragCoord.w; |
| 490 | self->interp_perspective.vPos = init_interp(init->vPos, step->vPos); |
| 491 | self->vPos = self->interp_perspective.vPos * w; |
| 492 | self->interp_step.vPos = step->vPos * 4.0f; |
| 493 | } |
| 494 | ALWAYS_INLINE__attribute__((always_inline)) inline void step_interp_inputs(int steps = 4) { |
| 495 | float chunks = steps * 0.25f; |
| 496 | vPos += interp_step.vPos * chunks; |
| 497 | } |
| 498 | ALWAYS_INLINE__attribute__((always_inline)) inline void step_perspective_inputs(int steps = 4) { |
| 499 | step_perspective(steps); |
| 500 | float chunks = steps * 0.25f; |
| 501 | Float w = 1.0f / gl_FragCoord.w; |
| 502 | interp_perspective.vPos += interp_step.vPos * chunks; |
| 503 | vPos = w * interp_perspective.vPos; |
| 504 | } |
| 505 | static void run(FragmentShaderImpl* impl) { |
| 506 | Self* self = (Self*)impl; |
| 507 | self->main(); |
| 508 | self->step_interp_inputs(); |
| 509 | } |
| 510 | static void skip(FragmentShaderImpl* impl, int steps) { |
| 511 | Self* self = (Self*)impl; |
| 512 | self->step_interp_inputs(steps); |
| 513 | } |
| 514 | static void run_perspective(FragmentShaderImpl* impl) { |
| 515 | Self* self = (Self*)impl; |
| 516 | self->main(); |
| 517 | self->step_perspective_inputs(); |
| 518 | } |
| 519 | static void skip_perspective(FragmentShaderImpl* impl, int steps) { |
| 520 | Self* self = (Self*)impl; |
| 521 | self->step_perspective_inputs(steps); |
| 522 | } |
| 523 | public: |
| 524 | cs_border_solid_frag() { |
| 525 | init_span_func = &read_interp_inputs; |
| 526 | run_func = &run; |
| 527 | skip_func = &skip; |
| 528 | enable_perspective(); |
| 529 | init_span_w_func = &read_perspective_inputs; |
| 530 | run_w_func = &run_perspective; |
| 531 | skip_w_func = &skip_perspective; |
| 532 | } |
| 533 | }; |
| 534 | |
| 535 | struct cs_border_solid_program : ProgramImpl, cs_border_solid_frag { |
| 536 | int get_uniform(const char *name) const override { |
| 537 | if (strcmp("sGpuBufferF", name) == 0) { return 1; } |
| 538 | if (strcmp("sGpuBufferI", name) == 0) { return 2; } |
| 539 | if (strcmp("uTransform", name) == 0) { return 3; } |
| 540 | return -1; |
| 541 | } |
| 542 | void bind_attrib(const char* name, int index) override { |
| 543 | attrib_locations.bind_loc(name, index); |
| 544 | } |
| 545 | int get_attrib(const char* name) const override { |
| 546 | return attrib_locations.get_loc(name); |
| 547 | } |
| 548 | size_t interpolants_size() const override { return sizeof(InterpOutputs); } |
| 549 | VertexShaderImpl* get_vertex_shader() override { |
| 550 | return this; |
| 551 | } |
| 552 | FragmentShaderImpl* get_fragment_shader() override { |
| 553 | return this; |
| 554 | } |
| 555 | const char* get_name() const override { return "cs_border_solid"; } |
| 556 | static ProgramImpl* loader() { return new cs_border_solid_program; } |
| 557 | }; |
| 558 |