Skip to content

Commit

Permalink
Backed out 4 changesets (bug 1700434) for causing bustages in src/gls…
Browse files Browse the repository at this point in the history
…l.h. CLOSED TREE

Backed out changeset 215ea9dc277b (bug 1700434)
Backed out changeset 64f8b849e94e (bug 1700434)
Backed out changeset 6643c36ec306 (bug 1700434)
Backed out changeset a998658f3364 (bug 1700434)

[ghsync] From https://hg.mozilla.org/mozilla-central/rev/b107b6129cbfd5da8b7107d892dcd1153e8b4952
  • Loading branch information
Iulian Moraru committed May 21, 2021
1 parent d443b3b commit 90135a8
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 276 deletions.
49 changes: 0 additions & 49 deletions glsl-to-cxx/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,14 +788,6 @@ impl Type {
array_sizes: None,
}
}

pub fn new_array(kind: TypeKind, size: i32) -> Self {
Type {
kind,
precision: None,
array_sizes: Some(Box::new(ArraySizes { sizes: vec![make_const(TypeKind::Int, size)] })),
}
}
}

impl LiftFrom<&syntax::FullySpecifiedType> for Type {
Expand Down Expand Up @@ -969,8 +961,6 @@ pub struct State {
modified_globals: RefCell<Vec<SymRef>>,
pub used_globals: RefCell<Vec<SymRef>>,
pub texel_fetches: HashMap<(SymRef, SymRef), TexelFetchOffsets>,
clip_dist_sym: SymRef,
pub used_clip_dist: u32,
}

impl State {
Expand All @@ -986,8 +976,6 @@ impl State {
modified_globals: RefCell::new(Vec::new()),
used_globals: RefCell::new(Vec::new()),
texel_fetches: HashMap::new(),
clip_dist_sym: SymRef(0),
used_clip_dist: 0,
}
}

Expand Down Expand Up @@ -2230,18 +2218,6 @@ fn translate_expression(state: &mut State, e: &syntax::Expr) -> Expr {
if !globals.contains(&global) {
globals.push(global);
}
if global == state.clip_dist_sym {
if let ExprKind::Bracket(_, idx) = &lhs.kind {
// Get the constant array index used for gl_ClipDistance and add it to the used mask.
let idx = match idx.kind {
ExprKind::IntConst(idx) => idx,
ExprKind::UIntConst(idx) => idx as i32,
_ => panic!("bad index for gl_ClipDistance"),
};
assert!(idx >= 0 && idx < 4);
state.used_clip_dist |= 1 << idx;
}
}
}
Expr {
kind: ExprKind::Assignment(lhs, op.clone(), rhs),
Expand Down Expand Up @@ -3765,10 +3741,6 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
"gl_Position",
SymDecl::Global(StorageClass::Out, None, Type::new(Vec4), RunClass::Vector),
);
state.clip_dist_sym = state.declare(
"gl_ClipDistance",
SymDecl::Global(StorageClass::Out, None, Type::new_array(Float, 4), RunClass::Vector),
);

state.declare(
"swgl_SpanLength",
Expand Down Expand Up @@ -3872,13 +3844,6 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
Type::new(Void),
vec![Type::new(Vec4)],
);
declare_function(
state,
"swgl_blendSubpixelText",
None,
Type::new(Void),
vec![Type::new(Vec4)],
);
declare_function(
state,
"swgl_clipMask",
Expand Down Expand Up @@ -3976,13 +3941,6 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
Type::new(Void),
vec![Type::new(*s), Type::new(Vec2), Type::new(Vec4)],
);
declare_function(
state,
"swgl_commitTextureLinearR8ToRGBA8",
None,
Type::new(Void),
vec![Type::new(*s), Type::new(Vec2), Type::new(Vec4)],
);
declare_function(
state,
"swgl_commitPartialTextureLinearR8",
Expand Down Expand Up @@ -4018,13 +3976,6 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
Type::new(Void),
vec![Type::new(*s), Type::new(Vec2), Type::new(Vec4), Type::new(Float)],
);
declare_function(
state,
"swgl_commitTextureLinearColorR8ToRGBA8",
None,
Type::new(Void),
vec![Type::new(*s), Type::new(Vec2), Type::new(Vec4), Type::new(Vec4)],
);

declare_function(
state,
Expand Down
15 changes: 0 additions & 15 deletions glsl-to-cxx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,6 @@ fn write_load_attribs(state: &mut OutputState, attribs: &[hir::SymRef]) {
fn write_store_outputs(state: &mut OutputState, outputs: &[hir::SymRef]) {
let is_scalar = state.is_scalar.replace(true);
write!(state, "public:\nstruct InterpOutputs {{\n");
if state.hir.used_clip_dist != 0 {
state.write(" Float swgl_ClipDistance;\n");
}
for i in outputs {
let sym = state.hir.sym(*i);
match &sym.decl {
Expand All @@ -563,15 +560,6 @@ fn write_store_outputs(state: &mut OutputState, outputs: &[hir::SymRef]) {
state,
" auto* dest = reinterpret_cast<InterpOutputs*>(dest_ptr);\n"
);
if state.hir.used_clip_dist != 0 {
for (i, comp) in "xyzw".chars().enumerate() {
if (state.hir.used_clip_dist & (1 << i)) != 0 {
write!(state, " dest->swgl_ClipDistance.{} = get_nth(gl_ClipDistance[{}], n);\n", comp, i);
} else {
write!(state, " dest->swgl_ClipDistance.{} = 0.0f;\n", comp);
}
}
}
for i in outputs {
let sym = state.hir.sym(*i);
match &sym.decl {
Expand Down Expand Up @@ -3643,9 +3631,6 @@ fn write_abi(state: &mut OutputState) {
state.write(" init_batch_func = (InitBatchFunc)&init_batch;\n");
state.write(" load_attribs_func = (LoadAttribsFunc)&load_attribs;\n");
state.write(" run_primitive_func = (RunPrimitiveFunc)&run;\n");
if state.hir.used_clip_dist != 0 {
state.write(" enable_clip_distance();\n");
}
}
}
state.write("}\n");
Expand Down
8 changes: 1 addition & 7 deletions swgl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ those span boundary pixels to estimate the coverage based on edge slope.
```
void swgl_commitTextureLinearRGBA8(sampler, vec2 uv, vec4 uv_bounds);
void swgl_commitTextureLinearR8(sampler, vec2 uv, vec4 uv_bounds);
void swgl_commitTextureLinearR8ToRGBA8(sampler, vec2 uv, vec4 uv_bounds);
void swgl_commitTextureLinearColorRGBA8(sampler, vec2 uv, vec4 uv_bounds, vec4|float color);
void swgl_commitTextureLinearColorR8(sampler, vec2 uv, vec4 uv_bounds, vec4|float color);
void swgl_commitTextureLinearColorR8ToRGBA8(sampler, vec2 uv, vec4 uv_bounds, vec4|float color);
void swgl_commitTextureLinearRepeatRGBA8(sampler, vec2 uv, vec2 tile_repeat, vec4 uv_repeat, vec4 uv_bounds);
void swgl_commitTextureLinearRepeatColorRGBA8(sampler, vec2 uv, vec2 tile_repeat, vec4 uv_repeat, vec4 uv_bounds, vec4|float color);
Expand All @@ -183,9 +181,7 @@ within the supplied uv bounds. The color variations also accept a supplied color
that modulates the result.

The RGBA8 versions may only be used to commit within `swgl_drawSpanRGBA8`, and
the R8 versions may only be used to commit within `swgl_drawSpanR8`. The R8ToRGBA8
versions may be used to sample from an R8 source while committing to an RGBA8
framebuffer.
the R8 versions may only be used to commit within `swgl_drawSpanR8`.

The Linear variations use a linear filter that bilinearly interpolates between
the four samples near the pixel. The Nearest variations use a nearest filter
Expand All @@ -208,8 +204,6 @@ useful for implementing clip-out modes by inverting the source texture value.
```
// Premultiplied alpha over blend, but with source color set to source alpha modulated with a constant color.
void swgl_blendDropShadow(vec4 color);
// Premultiplied alpha over blend, but treats the source as a subpixel mask modulated with a constant color.
void swgl_blendSubpixelText(vec4 color);
```

SWGL allows overriding the blend mode per-primitive by calling `swgl_blend`
Expand Down
29 changes: 14 additions & 15 deletions swgl/src/blend.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,21 @@ static ALWAYS_INLINE P applyColor(P src, InvertColor) {

template <typename P>
static ALWAYS_INLINE P applyColor(P src, P color) {
return muldiv255(color, src);
return muldiv256(src, color);
}

static ALWAYS_INLINE WideRGBA8 applyColor(PackedRGBA8 src, WideRGBA8 color) {
return applyColor(unpack(src), color);
return muldiv256(unpack(src), color);
}

// Packs a color on a scale of 0..256 rather than 0..255 to allow faster scale
// math with muldiv256. Note that this can cause a slight rounding difference in
// the result versus the 255 scale. To alleviate this we scale by 256.49, so
// that the color rounds slightly up and in turn causes the the value it scales
// to round slightly up as well.
template <typename P, typename C>
static ALWAYS_INLINE auto packColor(P* buf, C color) {
return pack_span(buf, color, 255.0f);
return pack_span(buf, color, 256.49f);
}

template <typename P>
Expand Down Expand Up @@ -335,17 +340,17 @@ enum SWGLClipFlag {
static int swgl_ClipFlags = 0;
static BlendKey swgl_BlendOverride = BLEND_KEY_NONE;
static WideRGBA8 swgl_BlendColorRGBA8 = {0};
static WideRGBA8 swgl_BlendAlphaRGBA8 = {0};

// A pointer into the color buffer for the start of the span.
static void* swgl_SpanBuf = nullptr;
// A pointer into the clip mask for the start of the span.
static uint8_t* swgl_ClipMaskBuf = nullptr;

static ALWAYS_INLINE WideR8 expand_mask(UNUSED uint8_t* buf, WideR8 mask) {
static ALWAYS_INLINE WideR8 expand_clip_mask(UNUSED uint8_t* buf, WideR8 mask) {
return mask;
}
static ALWAYS_INLINE WideRGBA8 expand_mask(UNUSED uint32_t* buf, WideR8 mask) {
static ALWAYS_INLINE WideRGBA8 expand_clip_mask(UNUSED uint32_t* buf,
WideR8 mask) {
WideRG8 maskRG = zip(mask, mask);
return zip(maskRG, maskRG);
}
Expand All @@ -361,9 +366,9 @@ static ALWAYS_INLINE uint8_t* get_clip_mask(P* buf) {

template <typename P>
static ALWAYS_INLINE auto load_clip_mask(P* buf, int span)
-> decltype(expand_mask(buf, 0)) {
return expand_mask(buf,
unpack(load_span<PackedR8>(get_clip_mask(buf), span)));
-> decltype(expand_clip_mask(buf, 0)) {
return expand_clip_mask(
buf, unpack(load_span<PackedR8>(get_clip_mask(buf), span)));
}

// Temporarily removes masking from the blend stage, assuming the caller will
Expand Down Expand Up @@ -684,12 +689,6 @@ static PREFER_INLINE WideRGBA8 blend_pixels(uint32_t* buf, PackedRGBA8 pdst,
return color + dst - muldiv255(dst, alphas(color));
}

BLEND_CASE(SWGL_BLEND_SUBPIXEL_TEXT):
// Premultiplied alpha over blend, but treats the source as a subpixel mask
// modulated with a constant color.
return applyColor(src, swgl_BlendColorRGBA8) + dst -
muldiv255(dst, applyColor(src, swgl_BlendAlphaRGBA8));

default:
UNREACHABLE;
// return src;
Expand Down
7 changes: 1 addition & 6 deletions swgl/src/gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ struct IntRange {
int end;

int len() const { return end - start; }

IntRange intersect(IntRange r) const {
return {max(start, r.start), min(end, r.end)};
}
};

struct FloatRange {
Expand Down Expand Up @@ -623,8 +619,7 @@ struct Program {
macro(GL_HSL_SATURATION_KHR, 0, 0, 0) \
macro(GL_HSL_COLOR_KHR, 0, 0, 0) \
macro(GL_HSL_LUMINOSITY_KHR, 0, 0, 0) \
macro(SWGL_BLEND_DROP_SHADOW, 0, 0, 0) \
macro(SWGL_BLEND_SUBPIXEL_TEXT, 0, 0, 0)
macro(SWGL_BLEND_DROP_SHADOW, 0, 0, 0)

#define DEFINE_BLEND_KEY(...) BLEND_KEY(__VA_ARGS__),
#define DEFINE_MASK_BLEND_KEY(...) MASK_BLEND_KEY(__VA_ARGS__),
Expand Down
1 change: 0 additions & 1 deletion swgl/src/gl_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,3 @@ typedef intptr_t GLintptr;
#define GL_HSL_LUMINOSITY_KHR 0x92B0

#define SWGL_BLEND_DROP_SHADOW 0xB001
#define SWGL_BLEND_SUBPIXEL_TEXT 0xB002
2 changes: 0 additions & 2 deletions swgl/src/glsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,6 @@ SI I32 roundzero(Float v, Float scale) { return cast(v * scale); }
SI I32 roundfast(Float v, Float scale) {
#if USE_SSE2
return _mm_cvtps_epi32(v * scale);
#elif USE_NEON
return vcvtq_s32_f32(vmlaq_f32(v, scale, 0.5f));
#else
return cast(v * scale + 0.5f);
#endif
Expand Down
19 changes: 0 additions & 19 deletions swgl/src/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ namespace glsl {
// to operate in Float-sized chunks.
typedef vec3 Interpolants;

// Clip distances, if enabled, are always stored in the first SIMD chunk of the
// interpolants.
static ALWAYS_INLINE Float get_clip_distances(const Interpolants& interp) {
return interp.x;
}

struct VertexShaderImpl;
struct FragmentShaderImpl;

Expand All @@ -34,9 +28,6 @@ struct ProgramImpl {

typedef ProgramImpl* (*ProgramLoader)();

// The maximum size of the gl_ClipDistance array.
constexpr int32_t gl_MaxClipDistances = 4;

struct VertexShaderImpl {
typedef void (*SetUniform1iFunc)(VertexShaderImpl*, int index, int value);
typedef void (*SetUniform4fvFunc)(VertexShaderImpl*, int index,
Expand All @@ -56,17 +47,7 @@ struct VertexShaderImpl {
LoadAttribsFunc load_attribs_func = nullptr;
RunPrimitiveFunc run_primitive_func = nullptr;

enum FLAGS {
CLIP_DISTANCE = 1 << 0,
};
int flags = 0;
void enable_clip_distance() { flags |= CLIP_DISTANCE; }
ALWAYS_INLINE bool use_clip_distance() const {
return (flags & CLIP_DISTANCE) != 0;
}

vec4 gl_Position;
Float gl_ClipDistance[gl_MaxClipDistances];

void set_uniform_1i(int index, int value) {
(*set_uniform_1i_func)(this, index, value);
Expand Down
41 changes: 0 additions & 41 deletions swgl/src/rasterize.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,36 +561,6 @@ static ALWAYS_INLINE IntRange aa_span(P* buf, const E& left, const E& right,
return {leftAA.start, rightAA.end};
}

// Calculate the span the user clip distances occupy from the left and right
// edges at the current row.
template <typename E>
static ALWAYS_INLINE IntRange clip_distance_range(const E& left,
const E& right) {
Float leftClip = get_clip_distances(left.interp);
Float rightClip = get_clip_distances(right.interp);
// Get the change in clip dist per X step.
Float clipStep = (rightClip - leftClip) / (right.cur_x() - left.cur_x());
// Find the zero intercepts starting from the left edge.
Float clipDist = left.cur_x() - leftClip * recip(clipStep);
// Find the distance to the start of the span for any clip distances that
// are increasing in value. If the clip distance is constant or decreasing
// in value, then check if it starts outside the clip volume.
Float start = if_then_else(clipStep > 0.0f, clipDist,
if_then_else(leftClip < 0.0f, 1.0e6f, 0.0f));
// Find the distance to the end of the span for any clip distances that are
// decreasing in value. If the clip distance is constant or increasing in
// value, then check if it ends inside the clip volume.
Float end = if_then_else(clipStep < 0.0f, clipDist,
if_then_else(rightClip >= 0.0f, 1.0e6f, 0.0f));
// Find the furthest start offset.
start = max(start, start.zwxy);
// Find the closest end offset.
end = min(end, end.zwxy);
// Finally, round the offsets to an integer span that can be used to bound
// the current span.
return FloatRange{max(start.x, start.y), min(end.x, end.y)}.round();
}

// Converts a run array into a flattened array of depth samples. This just
// walks through every run and fills the samples with the depth value from
// the run.
Expand Down Expand Up @@ -946,11 +916,6 @@ static inline void draw_quad_spans(int nump, Point2D p[4], uint32_t z,
// Calculate a potentially AA'd span and check if it is non-empty.
IntRange span = aa_span(fbuf, left, right, clipSpan);
if (span.len() > 0) {
// If user clip planes are enabled, use them to bound the current span.
if (vertex_shader->use_clip_distance()) {
span = span.intersect(clip_distance_range(left, right));
if (span.len() <= 0) goto next_span;
}
ctx->shaded_rows++;
ctx->shaded_pixels += span.len();
// Advance color/depth buffer pointers to the start of the span.
Expand Down Expand Up @@ -1196,11 +1161,6 @@ static inline void draw_perspective_spans(int nump, Point3D* p,
// Calculate a potentially AA'd span and check if it is non-empty.
IntRange span = aa_span(fbuf, left, right, clipSpan);
if (span.len() > 0) {
// If user clip planes are enabled, use them to bound the current span.
if (vertex_shader->use_clip_distance()) {
span = span.intersect(clip_distance_range(left, right));
if (span.len() <= 0) goto next_span;
}
ctx->shaded_rows++;
ctx->shaded_pixels += span.len();
// Advance color/depth buffer pointers to the start of the span.
Expand Down Expand Up @@ -1257,7 +1217,6 @@ static inline void draw_perspective_spans(int nump, Point3D* p,
draw_span<true, true>(buf, depth, span.len(), packDepth);
}
}
next_span:
// Advance Y and edge interpolants to next row.
y++;
left.nextRow();
Expand Down
Loading

0 comments on commit 90135a8

Please sign in to comment.