Skip to content

Add comments, rename things, remove unused code #3143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 2, 2018
Merged
2 changes: 1 addition & 1 deletion webrender/res/brush.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void main(void) {
VECS_PER_SPECIFIC_BRUSH +
segment_index * VECS_PER_SEGMENT;

vec4[2] segment_data = fetch_from_resource_cache_2(segment_address);
vec4[2] segment_data = fetch_from_gpu_cache_2(segment_address);
RectWithSize local_segment_rect = RectWithSize(segment_data[0].xy, segment_data[0].zw);

VertexInfo vi;
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/brush_blend.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ void brush_vs(
}
case 10: {
// Color Matrix
vec4 mat_data[3] = fetch_from_resource_cache_3(user_data.z);
vec4 offset_data = fetch_from_resource_cache_1(user_data.z + 4);
vec4 mat_data[3] = fetch_from_gpu_cache_3(user_data.z);
vec4 offset_data = fetch_from_gpu_cache_1(user_data.z + 4);
vColorMat = mat3(mat_data[0].xyz, mat_data[1].xyz, mat_data[2].xyz);
vColorOffset = offset_data.rgb;
break;
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/brush_image.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct ImageBrushData {
};

ImageBrushData fetch_image_data(int address) {
vec4[3] raw_data = fetch_from_resource_cache_3(address);
vec4[3] raw_data = fetch_from_gpu_cache_3(address);
ImageBrushData data = ImageBrushData(
raw_data[0],
raw_data[1],
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/brush_linear_gradient.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Gradient {
};

Gradient fetch_gradient(int address) {
vec4 data[2] = fetch_from_resource_cache_2(address);
vec4 data[2] = fetch_from_gpu_cache_2(address);
return Gradient(
data[0],
int(data[1].x),
Expand Down
6 changes: 3 additions & 3 deletions webrender/res/brush_mix_blend.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void brush_vs(
vec4 unused
) {
vec2 snapped_device_pos = snap_device_pos(vi);
vec2 texture_size = vec2(textureSize(sCacheRGBA8, 0));
vec2 texture_size = vec2(textureSize(sPrevPassColor, 0));
vOp = user_data.x;

PictureTask src_task = fetch_picture_task(user_data.z);
Expand Down Expand Up @@ -200,8 +200,8 @@ const int MixBlendMode_Color = 14;
const int MixBlendMode_Luminosity = 15;

Fragment brush_fs() {
vec4 Cb = textureLod(sCacheRGBA8, vBackdropUv, 0.0);
vec4 Cs = textureLod(sCacheRGBA8, vSrcUv, 0.0);
vec4 Cb = textureLod(sPrevPassColor, vBackdropUv, 0.0);
vec4 Cs = textureLod(sPrevPassColor, vSrcUv, 0.0);

if (Cb.a == 0.0) {
return Fragment(Cs);
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/brush_radial_gradient.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct RadialGradient {
};

RadialGradient fetch_radial_gradient(int address) {
vec4 data[2] = fetch_from_resource_cache_2(address);
vec4 data[2] = fetch_from_gpu_cache_2(address);
return RadialGradient(
data[0],
data[1].x,
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/brush_solid.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct SolidBrush {
};

SolidBrush fetch_solid_primitive(int address) {
vec4 data = fetch_from_resource_cache_1(address);
vec4 data = fetch_from_gpu_cache_1(address);
return SolidBrush(data);
}

Expand Down
2 changes: 1 addition & 1 deletion webrender/res/brush_yuv_image.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct YuvPrimitive {
};

YuvPrimitive fetch_yuv_primitive(int address) {
vec4 data = fetch_from_resource_cache_1(address);
vec4 data = fetch_from_gpu_cache_1(address);
return YuvPrimitive(data.x);
}

Expand Down
2 changes: 1 addition & 1 deletion webrender/res/clip_shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include rect,render_task,resource_cache,snap,transform
#include rect,render_task,gpu_cache,snap,transform

#ifdef WR_VERTEX_SHADER

Expand Down
8 changes: 4 additions & 4 deletions webrender/res/cs_blur.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ void main(void) {
RectWithSize target_rect = blur_task.common_data.task_rect;

#if defined WR_FEATURE_COLOR_TARGET
vec2 texture_size = vec2(textureSize(sCacheRGBA8, 0).xy);
vec2 texture_size = vec2(textureSize(sPrevPassColor, 0).xy);
#else
vec2 texture_size = vec2(textureSize(sCacheA8, 0).xy);
vec2 texture_size = vec2(textureSize(sPrevPassAlpha, 0).xy);
#endif
vUv.z = src_task.texture_layer_index;
vSigma = blur_task.blur_radius;
Expand Down Expand Up @@ -89,10 +89,10 @@ void main(void) {

#if defined WR_FEATURE_COLOR_TARGET
#define SAMPLE_TYPE vec4
#define SAMPLE_TEXTURE(uv) texture(sCacheRGBA8, uv)
#define SAMPLE_TEXTURE(uv) texture(sPrevPassColor, uv)
#else
#define SAMPLE_TYPE float
#define SAMPLE_TEXTURE(uv) texture(sCacheA8, uv).r
#define SAMPLE_TEXTURE(uv) texture(sPrevPassAlpha, uv).r
#endif

// TODO(gw): Write a fast path blur that handles smaller blur radii
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/cs_clip_box_shadow.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct BoxShadowData {
};

BoxShadowData fetch_data(ivec2 address) {
vec4 data[3] = fetch_from_resource_cache_3_direct(address);
vec4 data[3] = fetch_from_gpu_cache_3_direct(address);
RectWithSize dest_rect = RectWithSize(data[2].xy, data[2].zw);
BoxShadowData bs_data = BoxShadowData(
data[0].xy,
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/cs_clip_image.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ImageMaskData {
};

ImageMaskData fetch_mask_data(ivec2 address) {
vec4 data = fetch_from_resource_cache_1_direct(address);
vec4 data = fetch_from_gpu_cache_1_direct(address);
RectWithSize local_rect = RectWithSize(data.xy, data.zw);
ImageMaskData mask_data = ImageMaskData(local_rect);
return mask_data;
Expand Down
2 changes: 1 addition & 1 deletion webrender/res/cs_clip_line.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct LineDecorationData {
};

LineDecorationData fetch_data(ivec2 address) {
vec4 data[2] = fetch_from_resource_cache_2_direct(address);
vec4 data[2] = fetch_from_gpu_cache_2_direct(address);
RectWithSize local_rect = RectWithSize(data[0].xy, data[0].zw);
LineDecorationData line_data = LineDecorationData(
local_rect,
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/cs_clip_rectangle.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ClipRect {
};

ClipRect fetch_clip_rect(ivec2 address) {
vec4 data[2] = fetch_from_resource_cache_2_direct(address);
vec4 data[2] = fetch_from_gpu_cache_2_direct(address);
ClipRect rect = ClipRect(RectWithSize(data[0].xy, data[0].zw), data[1]);
return rect;
}
Expand All @@ -32,7 +32,7 @@ struct ClipCorner {
// miscompilations with a macOS 10.12 Intel driver.
ClipCorner fetch_clip_corner(ivec2 address, float index) {
address += ivec2(2 + 2 * int(index), 0);
vec4 data[2] = fetch_from_resource_cache_2_direct(address);
vec4 data[2] = fetch_from_gpu_cache_2_direct(address);
ClipCorner corner = ClipCorner(RectWithSize(data[0].xy, data[0].zw), data[1]);
return corner;
}
Expand Down
8 changes: 4 additions & 4 deletions webrender/res/cs_scale.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ void main(void) {
RectWithSize target_rect = scale_task.common_data.task_rect;

#if defined WR_FEATURE_COLOR_TARGET
vec2 texture_size = vec2(textureSize(sCacheRGBA8, 0).xy);
vec2 texture_size = vec2(textureSize(sPrevPassColor, 0).xy);
#else
vec2 texture_size = vec2(textureSize(sCacheA8, 0).xy);
vec2 texture_size = vec2(textureSize(sPrevPassAlpha, 0).xy);
#endif

vUv.z = src_task.texture_layer_index;
Expand All @@ -54,10 +54,10 @@ void main(void) {

#if defined WR_FEATURE_COLOR_TARGET
#define SAMPLE_TYPE vec4
#define SAMPLE_TEXTURE(uv) texture(sCacheRGBA8, uv)
#define SAMPLE_TEXTURE(uv) texture(sPrevPassColor, uv)
#else
#define SAMPLE_TYPE float
#define SAMPLE_TEXTURE(uv) texture(sCacheA8, uv).r
#define SAMPLE_TEXTURE(uv) texture(sPrevPassAlpha, uv).r
#endif

void main(void) {
Expand Down
137 changes: 137 additions & 0 deletions webrender/res/gpu_cache.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

uniform HIGHP_SAMPLER_FLOAT sampler2D sGpuCache;

#define VECS_PER_IMAGE_RESOURCE 2

// TODO(gw): This is here temporarily while we have
// both GPU store and cache. When the GPU
// store code is removed, we can change the
// PrimitiveInstance instance structure to
// use 2x unsigned shorts as vertex attributes
// instead of an int, and encode the UV directly
// in the vertices.
ivec2 get_gpu_cache_uv(int address) {
return ivec2(uint(address) % WR_MAX_VERTEX_TEXTURE_WIDTH,
uint(address) / WR_MAX_VERTEX_TEXTURE_WIDTH);
}

vec4[2] fetch_from_gpu_cache_2_direct(ivec2 address) {
return vec4[2](
TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0))
);
}

vec4[2] fetch_from_gpu_cache_2(int address) {
ivec2 uv = get_gpu_cache_uv(address);
return vec4[2](
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0))
);
}

#ifdef WR_VERTEX_SHADER

vec4[8] fetch_from_gpu_cache_8(int address) {
ivec2 uv = get_gpu_cache_uv(address);
return vec4[8](
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(3, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(4, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(5, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(6, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(7, 0))
);
}

vec4[3] fetch_from_gpu_cache_3(int address) {
ivec2 uv = get_gpu_cache_uv(address);
return vec4[3](
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0))
);
}

vec4[3] fetch_from_gpu_cache_3_direct(ivec2 address) {
return vec4[3](
TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(2, 0))
);
}

vec4[4] fetch_from_gpu_cache_4_direct(ivec2 address) {
return vec4[4](
TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(2, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(3, 0))
);
}

vec4[4] fetch_from_gpu_cache_4(int address) {
ivec2 uv = get_gpu_cache_uv(address);
return vec4[4](
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(3, 0))
);
}

vec4 fetch_from_gpu_cache_1_direct(ivec2 address) {
return texelFetch(sGpuCache, address, 0);
}

vec4 fetch_from_gpu_cache_1(int address) {
ivec2 uv = get_gpu_cache_uv(address);
return texelFetch(sGpuCache, uv, 0);
}

//TODO: image resource is too specific for this module

struct ImageResource {
RectWithEndpoint uv_rect;
float layer;
vec3 user_data;
};

ImageResource fetch_image_resource(int address) {
//Note: number of blocks has to match `renderer::BLOCKS_PER_UV_RECT`
vec4 data[2] = fetch_from_gpu_cache_2(address);
RectWithEndpoint uv_rect = RectWithEndpoint(data[0].xy, data[0].zw);
return ImageResource(uv_rect, data[1].x, data[1].yzw);
}

ImageResource fetch_image_resource_direct(ivec2 address) {
vec4 data[2] = fetch_from_gpu_cache_2_direct(address);
RectWithEndpoint uv_rect = RectWithEndpoint(data[0].xy, data[0].zw);
return ImageResource(uv_rect, data[1].x, data[1].yzw);
}

// Fetch optional extra data for a texture cache resource. This can contain
// a polygon defining a UV rect within the texture cache resource.
struct ImageResourceExtra {
vec2 st_tl;
vec2 st_tr;
vec2 st_bl;
vec2 st_br;
};

ImageResourceExtra fetch_image_resource_extra(int address) {
vec4 data[2] = fetch_from_gpu_cache_2(address + VECS_PER_IMAGE_RESOURCE);
return ImageResourceExtra(
data[0].xy,
data[0].zw,
data[1].xy,
data[1].zw
);
}

#endif //WR_VERTEX_SHADER
13 changes: 5 additions & 8 deletions webrender/res/prim_shared.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include rect,render_task,resource_cache,snap,transform
#include rect,render_task,gpu_cache,snap,transform

#define EXTEND_MODE_CLAMP 0
#define EXTEND_MODE_REPEAT 1
Expand All @@ -15,11 +15,8 @@
#define RASTER_LOCAL 0
#define RASTER_SCREEN 1

uniform sampler2DArray sCacheA8;
uniform sampler2DArray sCacheRGBA8;

// An A8 target for standalone tasks that is available to all passes.
uniform sampler2DArray sSharedCacheA8;
uniform sampler2DArray sPrevPassAlpha;
uniform sampler2DArray sPrevPassColor;

vec2 clamp_rect(vec2 pt, RectWithSize rect) {
return clamp(pt, rect.p0, rect.p0 + rect.size);
Expand Down Expand Up @@ -254,7 +251,7 @@ float do_clip() {
// is still interpolated and becomes a subject of precision-caused
// fluctuations, see https://bugzilla.mozilla.org/show_bug.cgi?id=1491911
ivec3 tc = ivec3(mask_uv, vClipMaskUv.z + 0.5);
return texelFetch(sCacheA8, tc, 0).r;
return texelFetch(sPrevPassAlpha, tc, 0).r;
}

#ifdef WR_FEATURE_DITHERING
Expand Down Expand Up @@ -297,7 +294,7 @@ vec4 sample_gradient(int address, float offset, float gradient_repeat) {
lut_offset = clamp(lut_offset, 0, 2 * (GRADIENT_ENTRIES + 1));

// Fetch the start and end color.
vec4 texels[2] = fetch_from_resource_cache_2(address + lut_offset);
vec4 texels[2] = fetch_from_gpu_cache_2(address + lut_offset);

// Finally interpolate and apply dithering
return dither(mix(texels[0], texels[1], fract(x)));
Expand Down
Loading