Skip to content
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

Make all render task data structs contain a common base field. #2052

Merged
merged 2 commits into from Nov 20, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Remove AlphaBatchTask, and introduce start of raster mode.

Most of the difficult work related to this was done in the
large picture PR that landed previously.

This removes the remnants of AlphaBatch tasks, and makes them
all run through Picture render tasks.

This also introduces the first part of the picture and shader
side support for selecting whether primitives on a given picture
are to be rasterized in screen space or a local space.
  • Loading branch information
gw3583 committed Nov 19, 2017
commit 99b487dee7fccaee2b0e23296f7184b52f8c8a8c
@@ -11,10 +11,8 @@ void brush_vs(
ivec2 user_data
);

// Whether this brush is being drawn on a Picture
// task (new) or an alpha batch task (legacy).
// Can be removed once everything uses pictures.
#define BRUSH_FLAG_USES_PICTURE (1 << 0)
#define RASTERIZATION_MODE_LOCAL_SPACE 0.0
#define RASTERIZATION_MODE_SCREEN_SPACE 1.0

struct BrushInstance {
int picture_address;
@@ -54,9 +52,10 @@ void main(void) {
vec2 device_pos, local_pos;
RectWithSize local_rect = geom.local_rect;

if ((brush.flags & BRUSH_FLAG_USES_PICTURE) != 0) {
// Fetch the dynamic picture that we are drawing on.
PictureTask pic_task = fetch_picture_task(brush.picture_address);
// Fetch the dynamic picture that we are drawing on.
PictureTask pic_task = fetch_picture_task(brush.picture_address);

if (pic_task.rasterization_mode == RASTERIZATION_MODE_LOCAL_SPACE) {

local_pos = local_rect.p0 + aPosition.xy * local_rect.size;

@@ -68,7 +67,6 @@ void main(void) {
// Write the final position transformed by the orthographic device-pixel projection.
gl_Position = uTransform * vec4(device_pos, 0.0, 1.0);
} else {
AlphaBatchTask alpha_task = fetch_alpha_batch_task(brush.picture_address);
Layer layer = fetch_layer(brush.clip_node_id, brush.scroll_node_id);
ClipArea clip_area = fetch_clip_area(brush.clip_address);

@@ -82,7 +80,7 @@ void main(void) {
geom.local_clip_rect,
float(brush.z),
layer,
alpha_task,
pic_task,
geom.local_rect
);

@@ -32,7 +32,7 @@ void brush_vs(
// the normal texture cache and unify this
// with the normal image shader.
BlurTask blur_task = fetch_blur_task(user_data.x);
vUv.z = blur_task.common_data.render_target_layer_index;
vUv.z = blur_task.common_data.texture_layer_index;
vImageKind = user_data.y;

#if defined WR_FEATURE_COLOR_TARGET
@@ -34,7 +34,7 @@ void main(void) {
#else
vec2 texture_size = vec2(textureSize(sCacheA8, 0).xy);
#endif
vUv.z = src_task.render_target_layer_index;
vUv.z = src_task.texture_layer_index;
vBlurRadius = int(3.0 * blur_task.blur_radius);
vSigma = blur_task.blur_radius;

@@ -2,8 +2,6 @@
* 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/. */

#define PRIMITIVE_HAS_PICTURE_TASK

#include shared,prim_shared

varying vec3 vUv;
@@ -208,24 +208,39 @@ Layer fetch_layer(int clip_node_id, int scroll_node_id) {

struct RenderTaskCommonData {
RectWithSize task_rect;
float render_target_layer_index;
float texture_layer_index;
};

RenderTaskCommonData fetch_render_task_data(
int index,
out vec3 data1,
out vec4 data2
) {
struct RenderTaskData {
RenderTaskCommonData common_data;
vec3 data1;
vec4 data2;
};

RenderTaskData fetch_render_task_data(int index) {
ivec2 uv = get_fetch_uv(index, VECS_PER_RENDER_TASK);

vec4 texel0 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(0, 0));
vec4 texel1 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(1, 0));
vec4 texel2 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(2, 0));

data1 = texel1.yzw;
data2 = texel2;
RectWithSize task_rect = RectWithSize(
texel0.xy,
texel0.zw
);

RenderTaskCommonData common_data = RenderTaskCommonData(
task_rect,
texel1.x
);

return RenderTaskCommonData(RectWithSize(texel0.xy, texel0.zw), texel1.x);
RenderTaskData data = RenderTaskData(
common_data,
texel1.yzw,
texel2
);

return data;
}

RenderTaskCommonData fetch_render_task_common_data(int index) {
@@ -234,7 +249,17 @@ RenderTaskCommonData fetch_render_task_common_data(int index) {
vec4 texel0 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(0, 0));
vec4 texel1 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(1, 0));

return RenderTaskCommonData(RectWithSize(texel0.xy, texel0.zw), texel1.x);
RectWithSize task_rect = RectWithSize(
texel0.xy,
texel0.zw
);

RenderTaskCommonData data = RenderTaskCommonData(
task_rect,
texel1.x
);

return data;
}

/*
@@ -245,18 +270,18 @@ RenderTaskCommonData fetch_render_task_common_data(int index) {
struct PictureTask {
RenderTaskCommonData common_data;
vec2 content_origin;
float rasterization_mode;
vec4 color;
};

PictureTask fetch_picture_task(int address) {
vec3 data1;
vec4 data2;
RenderTaskCommonData common_data = fetch_render_task_data(address, data1, data2);
RenderTaskData task_data = fetch_render_task_data(address);

PictureTask task = PictureTask(
common_data,
data1.xy,
data2
task_data.common_data,
task_data.data1.xy,
task_data.data1.z,
task_data.data2
);

return task;
@@ -270,36 +295,13 @@ struct BlurTask {
};

BlurTask fetch_blur_task(int address) {
vec3 data1;
vec4 data2;
RenderTaskData task_data = fetch_render_task_data(address);

RenderTaskCommonData common_data = fetch_render_task_data(
address,
data1,
data2
);

return BlurTask(
common_data,
data1.x,
data1.y,
data2
);
}

struct AlphaBatchTask {
RenderTaskCommonData common_data;
vec2 screen_space_origin;
};

AlphaBatchTask fetch_alpha_batch_task(int index) {
vec3 data1;
vec4 data2;
RenderTaskCommonData common_data = fetch_render_task_data(index, data1, data2);

AlphaBatchTask task = AlphaBatchTask(
common_data,
data1.xy
BlurTask task = BlurTask(
task_data.common_data,
task_data.data1.x,
task_data.data1.y,
task_data.data2
);

return task;
@@ -322,11 +324,11 @@ ClipArea fetch_clip_area(int index) {
area.screen_origin = vec2(0.0);
area.inner_rect = vec4(0.0);
} else {
vec3 data1;
vec4 data2;
area.common_data = fetch_render_task_data(index, data1, data2);
area.screen_origin = data1.xy;
area.inner_rect = data2;
RenderTaskData task_data = fetch_render_task_data(index);

area.common_data = task_data.common_data;
area.screen_origin = task_data.data1.xy;
area.inner_rect = task_data.data2;
}

return area;
@@ -461,11 +463,7 @@ CompositeInstance fetch_composite_instance() {
struct Primitive {
Layer layer;
ClipArea clip_area;
#ifdef PRIMITIVE_HAS_PICTURE_TASK
PictureTask task;
#else
AlphaBatchTask task;
#endif
RectWithSize local_rect;
RectWithSize local_clip_rect;
int specific_prim_address;
@@ -493,11 +491,7 @@ Primitive load_primitive() {

prim.layer = fetch_layer(pi.clip_node_id, pi.scroll_node_id);
prim.clip_area = fetch_clip_area(pi.clip_task_index);
#ifdef PRIMITIVE_HAS_PICTURE_TASK
prim.task = fetch_picture_task(pi.render_task_index);
#else
prim.task = fetch_alpha_batch_task(pi.render_task_index);
#endif

PrimitiveGeometry geom = fetch_primitive_geometry(pi.prim_address);
prim.local_rect = geom.local_rect;
@@ -593,7 +587,7 @@ VertexInfo write_vertex(RectWithSize instance_rect,
RectWithSize local_clip_rect,
float z,
Layer layer,
AlphaBatchTask task,
PictureTask task,
RectWithSize snap_rect) {

// Select the corner of the local rect that we are processing.
@@ -613,7 +607,7 @@ VertexInfo write_vertex(RectWithSize instance_rect,

// Apply offsets for the render task to get correct screen location.
vec2 final_pos = device_pos + snap_offset -
task.screen_space_origin +
task.content_origin +
task.common_data.task_rect.p0;

gl_Position = uTransform * vec4(final_pos, z, 1.0);
@@ -653,7 +647,7 @@ TransformVertexInfo write_transform_vertex(RectWithSize instance_rect,
vec4 clip_edge_mask,
float z,
Layer layer,
AlphaBatchTask task) {
PictureTask task) {
RectWithEndpoint local_rect = to_rect_with_endpoint(instance_rect);
RectWithSize clip_rect;
clip_rect.p0 = clamp_rect(local_clip_rect.p0, layer.local_clip_rect);
@@ -723,7 +717,7 @@ TransformVertexInfo write_transform_vertex(RectWithSize instance_rect,

// Apply offsets for the render task to get correct screen location.
vec2 final_pos = device_pos - //Note: `snap_rect` is not used
task.screen_space_origin +
task.content_origin +
task.common_data.task_rect.p0;


@@ -820,7 +814,7 @@ void write_clip(vec2 global_pos, ClipArea area) {
area.common_data.task_rect.p0,
area.common_data.task_rect.p0 + area.common_data.task_rect.size
);
vClipMaskUv = vec3(uv, area.common_data.render_target_layer_index);
vClipMaskUv = vec3(uv, area.common_data.texture_layer_index);
}
#endif //WR_VERTEX_SHADER

@@ -13,12 +13,12 @@ flat varying mat4 vColorMat;
#ifdef WR_VERTEX_SHADER
void main(void) {
CompositeInstance ci = fetch_composite_instance();
AlphaBatchTask dest_task = fetch_alpha_batch_task(ci.render_task_index);
AlphaBatchTask src_task = fetch_alpha_batch_task(ci.src_task_index);
PictureTask dest_task = fetch_picture_task(ci.render_task_index);
PictureTask src_task = fetch_picture_task(ci.src_task_index);

vec2 dest_origin = dest_task.common_data.task_rect.p0 -
dest_task.screen_space_origin +
src_task.screen_space_origin;
dest_task.content_origin +
src_task.content_origin;

vec2 local_pos = mix(dest_origin,
dest_origin + src_task.common_data.task_rect.size,
@@ -29,7 +29,7 @@ void main(void) {
vec2 st1 = src_task.common_data.task_rect.p0 + src_task.common_data.task_rect.size;

vec2 uv = src_task.common_data.task_rect.p0 + aPosition.xy * src_task.common_data.task_rect.size;
vUv = vec3(uv / texture_size, src_task.common_data.render_target_layer_index);
vUv = vec3(uv / texture_size, src_task.common_data.texture_layer_index);
vUvBounds = vec4(st0 + 0.5, st1 - 0.5) / texture_size.xyxy;

vOp = ci.user_data0;
@@ -11,13 +11,13 @@ flat varying int vOp;
#ifdef WR_VERTEX_SHADER
void main(void) {
CompositeInstance ci = fetch_composite_instance();
AlphaBatchTask dest_task = fetch_alpha_batch_task(ci.render_task_index);
PictureTask dest_task = fetch_picture_task(ci.render_task_index);
RenderTaskCommonData backdrop_task = fetch_render_task_common_data(ci.backdrop_task_index);
AlphaBatchTask src_task = fetch_alpha_batch_task(ci.src_task_index);
PictureTask src_task = fetch_picture_task(ci.src_task_index);

vec2 dest_origin = dest_task.common_data.task_rect.p0 -
dest_task.screen_space_origin +
src_task.screen_space_origin;
dest_task.content_origin +
src_task.content_origin;

vec2 local_pos = mix(dest_origin,
dest_origin + src_task.common_data.task_rect.size,
@@ -27,11 +27,11 @@ void main(void) {

vec2 st0 = backdrop_task.task_rect.p0 / texture_size;
vec2 st1 = (backdrop_task.task_rect.p0 + backdrop_task.task_rect.size) / texture_size;
vUv0 = vec3(mix(st0, st1, aPosition.xy), backdrop_task.render_target_layer_index);
vUv0 = vec3(mix(st0, st1, aPosition.xy), backdrop_task.texture_layer_index);

st0 = src_task.common_data.task_rect.p0 / texture_size;
st1 = (src_task.common_data.task_rect.p0 + src_task.common_data.task_rect.size) / texture_size;
vUv1 = vec3(mix(st0, st1, aPosition.xy), src_task.common_data.render_target_layer_index);
vUv1 = vec3(mix(st0, st1, aPosition.xy), src_task.common_data.texture_layer_index);

vOp = ci.user_data0;

@@ -10,11 +10,11 @@ flat varying vec4 vUvBounds;
#ifdef WR_VERTEX_SHADER
void main(void) {
CompositeInstance ci = fetch_composite_instance();
AlphaBatchTask dest_task = fetch_alpha_batch_task(ci.render_task_index);
AlphaBatchTask src_task = fetch_alpha_batch_task(ci.src_task_index);
PictureTask dest_task = fetch_picture_task(ci.render_task_index);
PictureTask src_task = fetch_picture_task(ci.src_task_index);

vec2 dest_origin = dest_task.common_data.task_rect.p0 -
dest_task.screen_space_origin +
dest_task.content_origin +
vec2(ci.user_data0, ci.user_data1);

vec2 local_pos = mix(dest_origin,
@@ -24,7 +24,7 @@ void main(void) {
vec2 texture_size = vec2(textureSize(sCacheRGBA8, 0));
vec2 st0 = src_task.common_data.task_rect.p0;
vec2 st1 = src_task.common_data.task_rect.p0 + src_task.common_data.task_rect.size;
vUv = vec3(mix(st0, st1, aPosition.xy) / texture_size, src_task.common_data.render_target_layer_index);
vUv = vec3(mix(st0, st1, aPosition.xy) / texture_size, src_task.common_data.texture_layer_index);
vUvBounds = vec4(st0 + 0.5, st1 - 0.5) / texture_size.xyxy;

gl_Position = uTransform * vec4(local_pos, ci.z, 1.0);
@@ -2,10 +2,6 @@
* 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/. */

#ifdef WR_FEATURE_CACHE
#define PRIMITIVE_HAS_PICTURE_TASK
#endif

#include shared,prim_shared

varying vec4 vColor;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.