Clay custom dispatch improvements & DPI scaling fixes (#26)
Co-authored-by: Zachary Levy <zachary@sunforge.is> Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
@@ -25,9 +25,9 @@ struct main0_in
|
||||
{
|
||||
float2 p_local [[user(locn0)]];
|
||||
float4 f_color [[user(locn1)]];
|
||||
float2 f_half_size [[user(locn2), flat]];
|
||||
float4 f_radii [[user(locn3), flat]];
|
||||
float f_half_feather [[user(locn4), flat]];
|
||||
float2 f_half_size_ppx [[user(locn2), flat]];
|
||||
float4 f_radii_ppx [[user(locn3), flat]];
|
||||
float f_half_feather_ppx [[user(locn4), flat]];
|
||||
};
|
||||
|
||||
static inline __attribute__((always_inline))
|
||||
@@ -96,16 +96,16 @@ fragment main0_out main0(main0_in in [[stage_in]], constant Uniforms& _108 [[buf
|
||||
return out;
|
||||
}
|
||||
float2 param_1 = in.p_local;
|
||||
float2 param_2 = in.f_half_size;
|
||||
float4 param_3 = in.f_radii;
|
||||
float2 param_2 = in.f_half_size_ppx;
|
||||
float4 param_3 = in.f_radii_ppx;
|
||||
float d = sdRoundedBox(param_1, param_2, param_3);
|
||||
if (d > in.f_half_feather)
|
||||
if (d > in.f_half_feather_ppx)
|
||||
{
|
||||
discard_fragment();
|
||||
}
|
||||
float grad_magnitude = fast::max(fwidth(d), 9.9999999747524270787835121154785e-07);
|
||||
float d_n = d / grad_magnitude;
|
||||
float h_n = in.f_half_feather / grad_magnitude;
|
||||
float h_n = in.f_half_feather_ppx / grad_magnitude;
|
||||
float2 uv_1 = (gl_FragCoord.xy * _108.inv_downsample_factor) * _108.inv_working_size;
|
||||
float3 color_1 = blur_input_tex.sample(blur_input_texSmplr, uv_1).xyz;
|
||||
float3 tinted = mix(color_1, color_1 * in.f_color.xyz, float3(in.f_color.w));
|
||||
|
||||
Binary file not shown.
@@ -55,18 +55,18 @@ struct Uniforms
|
||||
struct Gaussian_Blur_Primitive
|
||||
{
|
||||
float4 bounds;
|
||||
float4 radii;
|
||||
float2 half_size;
|
||||
float half_feather;
|
||||
float4 radii_ppx;
|
||||
float2 half_size_ppx;
|
||||
float half_feather_ppx;
|
||||
uint color;
|
||||
};
|
||||
|
||||
struct Gaussian_Blur_Primitive_1
|
||||
{
|
||||
float4 bounds;
|
||||
float4 radii;
|
||||
float2 half_size;
|
||||
float half_feather;
|
||||
float4 radii_ppx;
|
||||
float2 half_size_ppx;
|
||||
float half_feather_ppx;
|
||||
uint color;
|
||||
};
|
||||
|
||||
@@ -81,9 +81,9 @@ struct main0_out
|
||||
{
|
||||
float2 p_local [[user(locn0)]];
|
||||
float4 f_color [[user(locn1)]];
|
||||
float2 f_half_size [[user(locn2)]];
|
||||
float4 f_radii [[user(locn3)]];
|
||||
float f_half_feather [[user(locn4)]];
|
||||
float2 f_half_size_ppx [[user(locn2)]];
|
||||
float4 f_radii_ppx [[user(locn3)]];
|
||||
float f_half_feather_ppx [[user(locn4)]];
|
||||
float4 gl_Position [[position]];
|
||||
};
|
||||
|
||||
@@ -96,26 +96,26 @@ vertex main0_out main0(constant Uniforms& _13 [[buffer(0)]], const device Gaussi
|
||||
out.gl_Position = float4(ndc, 0.0, 1.0);
|
||||
out.p_local = float2(0.0);
|
||||
out.f_color = float4(0.0);
|
||||
out.f_half_size = float2(0.0);
|
||||
out.f_radii = float4(0.0);
|
||||
out.f_half_feather = 0.0;
|
||||
out.f_half_size_ppx = float2(0.0);
|
||||
out.f_radii_ppx = float4(0.0);
|
||||
out.f_half_feather_ppx = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Gaussian_Blur_Primitive p;
|
||||
p.bounds = _69.primitives[int(gl_InstanceIndex)].bounds;
|
||||
p.radii = _69.primitives[int(gl_InstanceIndex)].radii;
|
||||
p.half_size = _69.primitives[int(gl_InstanceIndex)].half_size;
|
||||
p.half_feather = _69.primitives[int(gl_InstanceIndex)].half_feather;
|
||||
p.radii_ppx = _69.primitives[int(gl_InstanceIndex)].radii_ppx;
|
||||
p.half_size_ppx = _69.primitives[int(gl_InstanceIndex)].half_size_ppx;
|
||||
p.half_feather_ppx = _69.primitives[int(gl_InstanceIndex)].half_feather_ppx;
|
||||
p.color = _69.primitives[int(gl_InstanceIndex)].color;
|
||||
float2 corner = _97[int(gl_VertexIndex)];
|
||||
float2 world_pos = mix(p.bounds.xy, p.bounds.zw, corner);
|
||||
float2 center = (p.bounds.xy + p.bounds.zw) * 0.5;
|
||||
out.p_local = (world_pos - center) * _13.dpi_scale;
|
||||
out.f_color = unpack_unorm4x8_to_float(p.color);
|
||||
out.f_half_size = p.half_size;
|
||||
out.f_radii = p.radii;
|
||||
out.f_half_feather = p.half_feather;
|
||||
out.f_half_size_ppx = p.half_size_ppx;
|
||||
out.f_radii_ppx = p.radii_ppx;
|
||||
out.f_half_feather_ppx = p.half_feather_ppx;
|
||||
out.gl_Position = _13.projection * float4(world_pos * _13.dpi_scale, 0.0, 1.0);
|
||||
}
|
||||
return out;
|
||||
|
||||
Binary file not shown.
@@ -107,57 +107,57 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
|
||||
}
|
||||
float d = 1000000015047466219876688855040.0;
|
||||
float h = 0.5;
|
||||
float2 half_size = in.f_params.xy;
|
||||
float2 p_local = in.f_local_or_uv;
|
||||
float2 half_size_ppx = in.f_params.xy;
|
||||
float2 p_local_ppx = in.f_local_or_uv;
|
||||
if (kind == 1u)
|
||||
{
|
||||
float4 corner_radii = float4(in.f_params.zw, in.f_params2.xy);
|
||||
float4 corner_radii_ppx = float4(in.f_params.zw, in.f_params2.xy);
|
||||
h = in.f_params2.z;
|
||||
float2 param = p_local;
|
||||
float2 param_1 = half_size;
|
||||
float4 param_2 = corner_radii;
|
||||
float2 param = p_local_ppx;
|
||||
float2 param_1 = half_size_ppx;
|
||||
float4 param_2 = corner_radii_ppx;
|
||||
d = sdRoundedBox(param, param_1, param_2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kind == 2u)
|
||||
{
|
||||
float radius = in.f_params.x;
|
||||
float radius_ppx = in.f_params.x;
|
||||
float sides = in.f_params.y;
|
||||
h = in.f_params.z;
|
||||
float2 param_3 = p_local;
|
||||
float param_4 = radius;
|
||||
float2 param_3 = p_local_ppx;
|
||||
float param_4 = radius_ppx;
|
||||
float param_5 = sides;
|
||||
d = sdRegularPolygon(param_3, param_4, param_5);
|
||||
half_size = float2(radius);
|
||||
half_size_ppx = float2(radius_ppx);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kind == 3u)
|
||||
{
|
||||
float2 ab = in.f_params.xy;
|
||||
float2 radii_ppx = in.f_params.xy;
|
||||
h = in.f_params.z;
|
||||
float2 param_6 = p_local;
|
||||
float2 param_7 = ab;
|
||||
float2 param_6 = p_local_ppx;
|
||||
float2 param_7 = radii_ppx;
|
||||
d = sdEllipseApprox(param_6, param_7);
|
||||
half_size = ab;
|
||||
half_size_ppx = radii_ppx;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kind == 4u)
|
||||
{
|
||||
float inner = in.f_params.x;
|
||||
float outer = in.f_params.y;
|
||||
float inner_radius_ppx = in.f_params.x;
|
||||
float outer_radius_ppx = in.f_params.y;
|
||||
float2 n_start = in.f_params.zw;
|
||||
float2 n_end = in.f_params2.xy;
|
||||
uint arc_bits = (flags >> 5u) & 3u;
|
||||
h = in.f_params2.z;
|
||||
float r = length(p_local);
|
||||
d = fast::max(inner - r, r - outer);
|
||||
float r = length(p_local_ppx);
|
||||
d = fast::max(inner_radius_ppx - r, r - outer_radius_ppx);
|
||||
if (arc_bits != 0u)
|
||||
{
|
||||
float d_start = dot(p_local, n_start);
|
||||
float d_end = dot(p_local, n_end);
|
||||
float d_start = dot(p_local_ppx, n_start);
|
||||
float d_end = dot(p_local_ppx, n_end);
|
||||
float _338;
|
||||
if (arc_bits == 1u)
|
||||
{
|
||||
@@ -170,7 +170,7 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
|
||||
float d_wedge = _338;
|
||||
d = fast::max(d, d_wedge);
|
||||
}
|
||||
half_size = float2(outer);
|
||||
half_size_ppx = float2(outer_radius_ppx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,7 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
|
||||
float4 gradient_end = unpack_unorm4x8_to_float(in.f_effects.x);
|
||||
if ((flags & 4u) != 0u)
|
||||
{
|
||||
float t_1 = length(p_local / half_size);
|
||||
float t_1 = length(p_local_ppx / half_size_ppx);
|
||||
float4 param_8 = gradient_start;
|
||||
float4 param_9 = gradient_end;
|
||||
float param_10 = t_1;
|
||||
@@ -194,7 +194,7 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
|
||||
else
|
||||
{
|
||||
float2 direction = float2(as_type<half2>(in.f_effects.z));
|
||||
float t_2 = (dot(p_local / half_size, direction) * 0.5) + 0.5;
|
||||
float t_2 = (dot(p_local_ppx / half_size_ppx, direction) * 0.5) + 0.5;
|
||||
float4 param_11 = gradient_start;
|
||||
float4 param_12 = gradient_end;
|
||||
float param_13 = t_2;
|
||||
@@ -206,7 +206,7 @@ fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> tex [[textur
|
||||
if ((flags & 1u) != 0u)
|
||||
{
|
||||
float4 uv_rect = in.f_uv_rect;
|
||||
float2 local_uv = ((p_local / half_size) * 0.5) + float2(0.5);
|
||||
float2 local_uv = ((p_local_ppx / half_size_ppx) * 0.5) + float2(0.5);
|
||||
float2 uv = mix(uv_rect.xy, uv_rect.zw, local_uv);
|
||||
shape_color = in.f_color * tex.sample(texSmplr, uv);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -60,32 +60,21 @@ struct main0_in
|
||||
float4 v_color [[attribute(2)]];
|
||||
};
|
||||
|
||||
vertex main0_out main0(main0_in in [[stage_in]], constant Uniforms& _12 [[buffer(0)]], const device Core_2D_Primitives& _75 [[buffer(1)]], uint gl_InstanceIndex [[instance_id]])
|
||||
vertex main0_out main0(main0_in in [[stage_in]], constant Uniforms& _12 [[buffer(0)]], const device Core_2D_Primitives& _31 [[buffer(1)]], uint gl_InstanceIndex [[instance_id]])
|
||||
{
|
||||
main0_out out = {};
|
||||
if (_12.mode == 0u)
|
||||
{
|
||||
out.f_color = in.v_color;
|
||||
out.f_local_or_uv = in.v_uv;
|
||||
out.f_params = float4(0.0);
|
||||
out.f_params2 = float4(0.0);
|
||||
out.f_flags = 0u;
|
||||
out.f_uv_rect = float4(0.0);
|
||||
out.f_effects = uint4(0u);
|
||||
out.gl_Position = _12.projection * float4(in.v_position * _12.dpi_scale, 0.0, 1.0);
|
||||
}
|
||||
else
|
||||
if (_12.mode == 1u)
|
||||
{
|
||||
Core_2D_Primitive p;
|
||||
p.bounds = _75.primitives[int(gl_InstanceIndex)].bounds;
|
||||
p.color = _75.primitives[int(gl_InstanceIndex)].color;
|
||||
p.flags = _75.primitives[int(gl_InstanceIndex)].flags;
|
||||
p.rotation_sc = _75.primitives[int(gl_InstanceIndex)].rotation_sc;
|
||||
p._pad = _75.primitives[int(gl_InstanceIndex)]._pad;
|
||||
p.params = _75.primitives[int(gl_InstanceIndex)].params;
|
||||
p.params2 = _75.primitives[int(gl_InstanceIndex)].params2;
|
||||
p.uv_rect = _75.primitives[int(gl_InstanceIndex)].uv_rect;
|
||||
p.effects = _75.primitives[int(gl_InstanceIndex)].effects;
|
||||
p.bounds = _31.primitives[int(gl_InstanceIndex)].bounds;
|
||||
p.color = _31.primitives[int(gl_InstanceIndex)].color;
|
||||
p.flags = _31.primitives[int(gl_InstanceIndex)].flags;
|
||||
p.rotation_sc = _31.primitives[int(gl_InstanceIndex)].rotation_sc;
|
||||
p._pad = _31.primitives[int(gl_InstanceIndex)]._pad;
|
||||
p.params = _31.primitives[int(gl_InstanceIndex)].params;
|
||||
p.params2 = _31.primitives[int(gl_InstanceIndex)].params2;
|
||||
p.uv_rect = _31.primitives[int(gl_InstanceIndex)].uv_rect;
|
||||
p.effects = _31.primitives[int(gl_InstanceIndex)].effects;
|
||||
float2 corner = in.v_position;
|
||||
float2 world_pos = mix(p.bounds.xy, p.bounds.zw, corner);
|
||||
float2 center = (p.bounds.xy + p.bounds.zw) * 0.5;
|
||||
@@ -105,6 +94,27 @@ vertex main0_out main0(main0_in in [[stage_in]], constant Uniforms& _12 [[buffer
|
||||
out.f_effects = p.effects;
|
||||
out.gl_Position = _12.projection * float4(world_pos * _12.dpi_scale, 0.0, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
out.f_color = in.v_color;
|
||||
out.f_local_or_uv = in.v_uv;
|
||||
out.f_params = float4(0.0);
|
||||
out.f_params2 = float4(0.0);
|
||||
out.f_flags = 0u;
|
||||
out.f_uv_rect = float4(0.0);
|
||||
out.f_effects = uint4(0u);
|
||||
float2 _199;
|
||||
if (_12.mode == 2u)
|
||||
{
|
||||
_199 = in.v_position;
|
||||
}
|
||||
else
|
||||
{
|
||||
_199 = in.v_position * _12.dpi_scale;
|
||||
}
|
||||
float2 pos = _199;
|
||||
out.gl_Position = _12.projection * float4(pos, 0.0, 1.0);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user