Remove layout(marker) from runtime effect SkSL
This is another strange, experimental feature that clutters the
implementation and isn't used by anyone (to my knowledge).
Change-Id: I538b7eca0cd28aab32f4739b23459731ade9105e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/398226
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/include/effects/SkRuntimeEffect.h b/include/effects/SkRuntimeEffect.h
index 6e99faf..40b2c2b 100644
--- a/include/effects/SkRuntimeEffect.h
+++ b/include/effects/SkRuntimeEffect.h
@@ -59,9 +59,7 @@
enum Flags {
kArray_Flag = 0x1,
- kMarker_Flag = 0x2,
- kMarkerNormals_Flag = 0x4,
- kSRGBUnpremul_Flag = 0x8,
+ kSRGBUnpremul_Flag = 0x2,
};
SkString name;
@@ -69,7 +67,6 @@
Type type;
int count;
uint32_t flags;
- uint32_t marker;
bool isArray() const { return SkToBool(this->flags & kArray_Flag); }
size_t sizeInBytes() const;
diff --git a/include/private/SkSLLayout.h b/include/private/SkSLLayout.h
index 99f215f..6de5e6a 100644
--- a/include/private/SkSLLayout.h
+++ b/include/private/SkSLLayout.h
@@ -39,9 +39,8 @@
kPrimitive_Flag = 1 << 15,
kMaxVertices_Flag = 1 << 16,
kInvocations_Flag = 1 << 17,
- kMarker_Flag = 1 << 18,
- kWhen_Flag = 1 << 19,
- kCType_Flag = 1 << 20,
+ kWhen_Flag = 1 << 18,
+ kCType_Flag = 1 << 19,
};
enum Primitive {
@@ -114,7 +113,7 @@
Layout(int flags, int location, int offset, int binding, int index, int set, int builtin,
int inputAttachmentIndex, Primitive primitive, int maxVertices, int invocations,
- StringFragment marker, StringFragment when, CType ctype)
+ StringFragment when, CType ctype)
: fFlags(flags)
, fLocation(location)
, fOffset(offset)
@@ -126,7 +125,6 @@
, fPrimitive(primitive)
, fMaxVertices(maxVertices)
, fInvocations(invocations)
- , fMarker(marker)
, fWhen(when)
, fCType(ctype) {}
@@ -232,9 +230,6 @@
if (fInvocations >= 0) {
result += separator() + "invocations = " + to_string(fInvocations);
}
- if (fMarker.fLength) {
- result += separator() + "marker = " + fMarker;
- }
if (fWhen.fLength) {
result += separator() + "when = " + fWhen;
}
@@ -259,7 +254,6 @@
fPrimitive == other.fPrimitive &&
fMaxVertices == other.fMaxVertices &&
fInvocations == other.fInvocations &&
- fMarker == other.fMarker &&
fWhen == other.fWhen &&
fCType == other.fCType;
}
@@ -283,8 +277,6 @@
Primitive fPrimitive;
int fMaxVertices;
int fInvocations;
- // marker refers to matrices tagged on the SkCanvas with markCTM
- StringFragment fMarker;
StringFragment fWhen;
CType fCType;
};
diff --git a/modules/canvaskit/npm_build/extra.html b/modules/canvaskit/npm_build/extra.html
index b934f53..59f2fce 100644
--- a/modules/canvaskit/npm_build/extra.html
+++ b/modules/canvaskit/npm_build/extra.html
@@ -37,7 +37,6 @@
<canvas id=skp width=500 height=500></canvas>
<h2> 3D perspective transformations </h2>
-<canvas id=camera3d width=500 height=500></canvas>
<canvas id=glyphgame width=500 height=500></canvas>
<h2> Support for extended color spaces </h2>
@@ -145,7 +144,6 @@
GlyphGame(...results)
});
Promise.all([ckLoaded, loadSkp]).then((results) => {SkpExample(...results)});
- Promise.all([ckLoaded, loadBrickTex, loadBrickBump, loadFont]).then((results) => {Camera3D(...results)});
const rectLeft = 0;
const rectTop = 1;
@@ -480,314 +478,6 @@
surface.drawOnce(drawFrame);
}
- function Camera3D(canvas, textureImgData, normalImgData, robotoData) {
- const surface = CanvasKit.MakeCanvasSurface('camera3d');
- if (!surface) {
- console.error('Could not make surface');
- return;
- }
-
- const sizeX = document.getElementById('camera3d').width;
- const sizeY = document.getElementById('camera3d').height;
-
- let clickToWorld = CanvasKit.M44.identity();
- let worldToClick = CanvasKit.M44.identity();
- // rotation of the cube shown in the demo
- let rotation = CanvasKit.M44.identity();
- // temporary during a click and drag
- let clickRotation = CanvasKit.M44.identity();
-
- // A virtual sphere used for tumbling the object on screen.
- const vSphereCenter = [sizeX/2, sizeY/2];
- const vSphereRadius = Math.min(...vSphereCenter);
-
- // The rounded rect used for each face
- const margin = vSphereRadius / 20;
- const rr = CanvasKit.RRectXY(CanvasKit.LTRBRect(margin, margin,
- vSphereRadius - margin, vSphereRadius - margin), margin*2.5, margin*2.5);
-
- const camAngle = Math.PI / 12;
- const cam = {
- 'eye' : [0, 0, 1 / Math.tan(camAngle/2) - 1],
- 'coa' : [0, 0, 0],
- 'up' : [0, 1, 0],
- 'near' : 0.05,
- 'far' : 4,
- 'angle': camAngle,
- };
-
- let mouseDown = false;
- let clickDown = [0, 0]; // location of click down
- let lastMouse = [0, 0]; // last mouse location
-
- // keep spinning after mouse up. Also start spinning on load
- let axis = [0.4, 1, 1];
- let totalSpin = 0;
- let spinRate = 0.1;
- let lastRadians = 0;
- let spinning = setInterval(keepSpinning, 30);
-
- const textPaint = new CanvasKit.Paint();
- textPaint.setColor(CanvasKit.BLACK);
- textPaint.setAntiAlias(true);
- const roboto = CanvasKit.FontMgr.RefDefault().MakeTypefaceFromData(robotoData);
- const textFont = new CanvasKit.Font(roboto, 30);
-
- const imgscale = CanvasKit.Matrix.scaled(2, 2);
- const textureShader = CanvasKit.MakeImageFromEncoded(textureImgData).makeShaderCubic(
- CanvasKit.TileMode.Clamp, CanvasKit.TileMode.Clamp, 1/3, 1/3, imgscale);
- const normalShader = CanvasKit.MakeImageFromEncoded(normalImgData).makeShaderCubic(
- CanvasKit.TileMode.Clamp, CanvasKit.TileMode.Clamp, 1/3, 1/3, imgscale);
- const children = [textureShader, normalShader];
-
- const prog = `
- uniform shader color_map;
- uniform shader normal_map;
-
- uniform float3 lightPos;
- layout (marker=local_to_world) uniform float4x4 localToWorld;
- layout (marker=normals(local_to_world)) uniform float4x4 localToWorldAdjInv;
-
- float3 convert_normal_sample(half4 c) {
- float3 n = 2 * c.rgb - 1;
- n.y = -n.y;
- return n;
- }
-
- half4 main(float2 p) {
- float3 norm = convert_normal_sample(sample(normal_map, p));
- float3 plane_norm = normalize(localToWorldAdjInv * float4(norm, 0)).xyz;
-
- float3 plane_pos = (localToWorld * float4(p, 0, 1)).xyz;
- float3 light_dir = normalize(lightPos - plane_pos);
-
- float ambient = 0.2;
- float dp = dot(plane_norm, light_dir);
- float scale = min(ambient + max(dp, 0), 1);
-
- return sample(color_map, p) * half4(float4(scale, scale, scale, 1));
- }
-`;
-
- const fact = CanvasKit.RuntimeEffect.Make(prog);
-
- // properties of light
- let lightLocation = [...vSphereCenter];
- let lightDistance = vSphereRadius;
- let lightIconRadius = 12;
- let draggingLight = false;
-
- function computeLightWorldPos() {
- return CanvasKit.Vector.add(CanvasKit.Vector.mulScalar([...vSphereCenter, 0], 0.5),
- CanvasKit.Vector.mulScalar(vSphereUnitV3(lightLocation), lightDistance));
- }
-
- let lightWorldPos = computeLightWorldPos();
-
- function drawLight(canvas) {
- const paint = new CanvasKit.Paint();
- paint.setAntiAlias(true);
- paint.setColor(CanvasKit.WHITE);
- canvas.drawCircle(...lightLocation, lightIconRadius + 2, paint);
- paint.setColor(CanvasKit.BLACK);
- canvas.drawCircle(...lightLocation, lightIconRadius, paint);
- }
-
- // Takes an x and y rotation in radians and a scale and returns a 4x4 matrix used to draw a
- // face of the cube in that orientation.
- function faceM44(rx, ry, scale) {
- return CanvasKit.M44.multiply(
- CanvasKit.M44.rotated([0,1,0], ry),
- CanvasKit.M44.rotated([1,0,0], rx),
- CanvasKit.M44.translated([0, 0, scale]));
- }
-
- const faceScale = vSphereRadius/2
- const faces = [
- {matrix: faceM44( 0, 0, faceScale ), color:CanvasKit.RED}, // front
- {matrix: faceM44( 0, Math.PI, faceScale ), color:CanvasKit.GREEN}, // back
-
- {matrix: faceM44( Math.PI/2, 0, faceScale ), color:CanvasKit.BLUE}, // top
- {matrix: faceM44(-Math.PI/2, 0, faceScale ), color:CanvasKit.CYAN}, // bottom
-
- {matrix: faceM44( 0, Math.PI/2, faceScale ), color:CanvasKit.MAGENTA}, // left
- {matrix: faceM44( 0,-Math.PI/2, faceScale ), color:CanvasKit.YELLOW}, // right
- ];
-
- // Returns a component of the matrix m indicating whether it faces the camera.
- // If it's positive for one of the matrices representing the face of the cube,
- // that face is currently in front.
- function front(m) {
- // Is this invertible?
- var m2 = CanvasKit.M44.invert(m);
- if (m2 === null) {
- m2 = CanvasKit.M44.identity();
- }
- // look at the sign of the z-scale of the inverse of m.
- // that's the number in row 2, col 2.
- return m2[10]
- }
-
- function setClickToWorld(canvas, matrix) {
- const l2d = canvas.getLocalToDevice();
- worldToClick = CanvasKit.M44.multiply(CanvasKit.M44.mustInvert(matrix), l2d);
- clickToWorld = CanvasKit.M44.mustInvert(worldToClick);
- }
-
- function drawCubeFace(canvas, m, color) {
- const trans = new CanvasKit.M44.translated([vSphereRadius/2, vSphereRadius/2, 0]);
- canvas.concat(CanvasKit.M44.multiply(trans, m, CanvasKit.M44.mustInvert(trans)));
- const znormal = front(canvas.getLocalToDevice());
- if (znormal < 0) {
- return; // skip faces facing backwards
- }
- // Pad with space for two 4x4 matrices. Even though the shader uses a layout()
- // statement to populate them, we still have to reserve space for them.
- const uniforms = [...lightWorldPos, ...Array(32).fill(0)];
- const paint = new CanvasKit.Paint();
- paint.setAntiAlias(true);
- const shader = fact.makeShaderWithChildren(uniforms, true /*=opaque*/, children);
- paint.setShader(shader);
- canvas.drawRRect(rr, paint);
- canvas.drawText(znormal.toFixed(2), faceScale*0.25, faceScale*0.4, textPaint, textFont);
- }
-
- function drawFrame(canvas) {
- const clickM = canvas.getLocalToDevice();
- canvas.save();
- canvas.translate(vSphereCenter[0] - vSphereRadius/2, vSphereCenter[1] - vSphereRadius/2);
- // pass surface dimensions as viewport size.
- canvas.concat(CanvasKit.M44.setupCamera(
- CanvasKit.LTRBRect(0, 0, vSphereRadius, vSphereRadius), vSphereRadius/2, cam));
- // Mark the matrix to make it available to the shader by this name.
- canvas.markCTM('local_to_world');
- setClickToWorld(canvas, clickM);
- for (let f of faces) {
- const saveCount = canvas.getSaveCount();
- canvas.save();
- drawCubeFace(canvas, CanvasKit.M44.multiply(clickRotation, rotation, f.matrix), f.color);
- canvas.restoreToCount(saveCount);
- }
- canvas.restore(); // camera
- canvas.restore(); // center the following content in the window
-
- // draw virtual sphere outline.
- const paint = new CanvasKit.Paint();
- paint.setAntiAlias(true);
- paint.setStyle(CanvasKit.PaintStyle.Stroke);
- paint.setColor(CanvasKit.Color(64, 255, 0, 1.0));
- canvas.drawCircle(vSphereCenter[0], vSphereCenter[1], vSphereRadius, paint);
- canvas.drawLine(vSphereCenter[0], vSphereCenter[1] - vSphereRadius,
- vSphereCenter[0], vSphereCenter[1] + vSphereRadius, paint);
- canvas.drawLine(vSphereCenter[0] - vSphereRadius, vSphereCenter[1],
- vSphereCenter[0] + vSphereRadius, vSphereCenter[1], paint);
-
- drawLight(canvas);
- }
-
- // convert a 2D point in the circle displayed on screen to a 3D unit vector.
- // the virtual sphere is a technique selecting a 3D direction by clicking on a the projection
- // of a hemisphere.
- function vSphereUnitV3(p) {
- // v = (v - fCenter) * (1 / fRadius);
- let v = CanvasKit.Vector.mulScalar(CanvasKit.Vector.sub(p, vSphereCenter), 1/vSphereRadius);
-
- // constrain the clicked point within the circle.
- let len2 = CanvasKit.Vector.lengthSquared(v);
- if (len2 > 1) {
- v = CanvasKit.Vector.normalize(v);
- len2 = 1;
- }
- // the closer to the edge of the circle you are, the closer z is to zero.
- const z = Math.sqrt(1 - len2);
- v.push(z);
- return v;
- }
-
- function computeVSphereRotation(start, end) {
- const u = vSphereUnitV3(start);
- const v = vSphereUnitV3(end);
- // Axis is in the scope of the Camera3D function so it can be used in keepSpinning.
- axis = CanvasKit.Vector.cross(u, v);
- const sinValue = CanvasKit.Vector.length(axis);
- const cosValue = CanvasKit.Vector.dot(u, v);
-
- let m = new CanvasKit.M44.identity();
- if (Math.abs(sinValue) > 0.000000001) {
- m = CanvasKit.M44.rotatedUnitSinCos(
- CanvasKit.Vector.mulScalar(axis, 1/sinValue), sinValue, cosValue);
- const radians = Math.atan(cosValue / sinValue);
- spinRate = lastRadians - radians;
- lastRadians = radians;
- }
- return m;
- }
-
- function keepSpinning() {
- totalSpin += spinRate;
- clickRotation = CanvasKit.M44.rotated(axis, totalSpin);
- spinRate *= .998;
- if (spinRate < 0.01) {
- stopSpinning();
- }
- surface.requestAnimationFrame(drawFrame);
- }
-
- function stopSpinning() {
- clearInterval(spinning);
- rotation = CanvasKit.M44.multiply(clickRotation, rotation);
- clickRotation = CanvasKit.M44.identity();
- }
-
- function interact(e) {
- const type = e.type;
- let eventPos = [e.offsetX, e.offsetY];
- if (type === 'lostpointercapture' || type === 'pointerup' || type == 'pointerleave') {
- if (draggingLight) {
- draggingLight = false;
- } else if (mouseDown) {
- mouseDown = false;
- if (spinRate > 0.02) {
- stopSpinning();
- spinning = setInterval(keepSpinning, 30);
- }
- } else {
- return;
- }
- return;
- } else if (type === 'pointermove') {
- if (draggingLight) {
- lightLocation = eventPos;
- lightWorldPos = computeLightWorldPos();
- } else if (mouseDown) {
- lastMouse = eventPos;
- clickRotation = computeVSphereRotation(clickDown, lastMouse);
- } else {
- return;
- }
- } else if (type === 'pointerdown') {
- // Are we repositioning the light?
- if (CanvasKit.Vector.dist(eventPos, lightLocation) < lightIconRadius) {
- draggingLight = true;
- return;
- }
- stopSpinning();
- mouseDown = true;
- clickDown = eventPos;
- lastMouse = eventPos;
- }
- surface.requestAnimationFrame(drawFrame);
- };
-
- document.getElementById('camera3d').addEventListener('pointermove', interact);
- document.getElementById('camera3d').addEventListener('pointerdown', interact);
- document.getElementById('camera3d').addEventListener('lostpointercapture', interact);
- document.getElementById('camera3d').addEventListener('pointerleave', interact);
- document.getElementById('camera3d').addEventListener('pointerup', interact);
-
- surface.requestAnimationFrame(drawFrame);
- }
-
// Shows a hidden message by rotating all the characters in a kind of way that makes you
// search with your mouse.
function GlyphGame(canvas, robotoData) {
diff --git a/resources/sksl/errors/LayoutInFunctions.sksl b/resources/sksl/errors/LayoutInFunctions.sksl
index 3b4aa9f..be96aa4 100644
--- a/resources/sksl/errors/LayoutInFunctions.sksl
+++ b/resources/sksl/errors/LayoutInFunctions.sksl
@@ -15,7 +15,6 @@
input_attachment_index = 1,
max_vertices = 1,
invocations = 1,
- marker = one,
when = one,
ctype = int)
void on_return() {}
@@ -38,6 +37,5 @@
input_attachment_index = 1,
max_vertices = 1,
invocations = 1,
- marker = one,
when = one,
ctype = int) float x) {}
diff --git a/resources/sksl/errors/LayoutRepeatedQualifiers.sksl b/resources/sksl/errors/LayoutRepeatedQualifiers.sksl
index b7fea4c..d2454e4 100644
--- a/resources/sksl/errors/LayoutRepeatedQualifiers.sksl
+++ b/resources/sksl/errors/LayoutRepeatedQualifiers.sksl
@@ -16,7 +16,6 @@
input_attachment_index = 1,
max_vertices = 1,
invocations = 1,
- marker = one,
when = one,
ctype = int,
@@ -37,7 +36,6 @@
input_attachment_index = 2,
max_vertices = 2,
invocations = 2,
- marker = two,
when = two,
ctype = float
) float x;
diff --git a/resources/sksl/runtime_errors/InvalidColorFilterFeatures.rtcf b/resources/sksl/runtime_errors/InvalidColorFilterFeatures.rtcf
index 220da64..98f0aa2 100644
--- a/resources/sksl/runtime_errors/InvalidColorFilterFeatures.rtcf
+++ b/resources/sksl/runtime_errors/InvalidColorFilterFeatures.rtcf
@@ -1,8 +1,6 @@
-// Runtime color filters may not use layout(marker), or sk_FragCoord
+// Runtime color filters may not use sk_FragCoord
-// Expect 2 errors
-
-layout(marker=ctm) uniform float4x4 ctm;
+// Expect 1 error
half4 main(half4 color) {
return sk_FragCoord.xy01;
diff --git a/samplecode/Sample3D.cpp b/samplecode/Sample3D.cpp
index 89cd578..062bfbf 100644
--- a/samplecode/Sample3D.cpp
+++ b/samplecode/Sample3D.cpp
@@ -72,6 +72,14 @@
return inverse;
}
+// Compute the inverse transpose (of the upper-left 3x3) of a matrix, used to transform vectors
+static SkM44 normals(SkM44 m) {
+ m.setRow(3, {0, 0, 0, 1});
+ m.setCol(3, {0, 0, 0, 1});
+ SkAssertResult(m.invert(&m));
+ return m.transpose();
+}
+
class Sample3DView : public Sample {
protected:
float fNear = 0.05f;
@@ -82,8 +90,6 @@
SkV3 fCOA { 0, 0, 0 };
SkV3 fUp { 0, 1, 0 };
- const char* kLocalToWorld = "local_to_world";
-
public:
void concatCamera(SkCanvas* canvas, const SkRect& area, SkScalar zscale) {
SkM44 camera = SkM44::LookAt(fEye, fCOA, fUp),
@@ -258,7 +264,8 @@
return this->Sample3DView::onChar(uni);
}
- virtual void drawContent(SkCanvas* canvas, SkColor, int index, bool drawFront) = 0;
+ virtual void drawContent(
+ SkCanvas* canvas, SkColor, int index, bool drawFront, const SkM44& localToWorld) = 0;
void onDrawContent(SkCanvas* canvas) override {
if (!canvas->recordingContext() && !(fFlags & kCanRunOnCPU)) {
@@ -281,10 +288,10 @@
canvas->concat(trans);
// "World" space - content is centered at the origin, in device scale (+-200)
- canvas->markCTM(kLocalToWorld);
+ SkM44 localToWorld = m * inv(trans);
- canvas->concat(m * inv(trans));
- this->drawContent(canvas, f.fColor, index++, drawFront);
+ canvas->concat(localToWorld);
+ this->drawContent(canvas, f.fColor, index++, drawFront, localToWorld);
}
}
@@ -371,8 +378,8 @@
uniform shader color_map;
uniform shader normal_map;
- layout (marker=local_to_world) uniform float4x4 localToWorld;
- layout (marker=normals(local_to_world)) uniform float4x4 localToWorldAdjInv;
+ uniform float4x4 localToWorld;
+ uniform float4x4 localToWorldAdjInv;
uniform float3 lightPos;
float3 convert_normal_sample(half4 c) {
@@ -402,14 +409,19 @@
fEffect = effect;
}
- void drawContent(SkCanvas* canvas, SkColor color, int index, bool drawFront) override {
+ void drawContent(SkCanvas* canvas,
+ SkColor color,
+ int index,
+ bool drawFront,
+ const SkM44& localToWorld) override {
if (!drawFront || !front(canvas->getLocalToDevice())) {
return;
}
SkRuntimeShaderBuilder builder(fEffect);
builder.uniform("lightPos") = fLight.computeWorldPos(fSphere);
- // localToWorld matrices are automatically populated, via layout(marker)
+ builder.uniform("localToWorld") = localToWorld;
+ builder.uniform("localToWorldAdjInv") = normals(localToWorld);
builder.child("color_map") = fImgShader;
builder.child("normal_map") = fBmpShader;
@@ -450,7 +462,8 @@
}
}
- void drawContent(SkCanvas* canvas, SkColor color, int index, bool drawFront) override {
+ void drawContent(
+ SkCanvas* canvas, SkColor color, int index, bool drawFront, const SkM44&) override {
if (!drawFront || !front(canvas->getLocalToDevice())) {
return;
}
diff --git a/site/docs/user/modules/canvaskit.md b/site/docs/user/modules/canvaskit.md
index 5e0f148..1d6f3f9 100644
--- a/site/docs/user/modules/canvaskit.md
+++ b/site/docs/user/modules/canvaskit.md
@@ -29,7 +29,7 @@
margin: 2px;
}
- #patheffect, #ink, #shaping, #shader1, #camera3d {
+ #patheffect, #ink, #shaping, #shader1 {
width: 400px;
height: 400px;
}
@@ -68,14 +68,6 @@
Shader JSFiddle</a>
</figcaption>
</figure>
- <figure>
- <canvas id=camera3d width=400 height=400></canvas>
- <figcaption>
- <a href="https://jsfiddle.skia.org/canvaskit/786b7dd80aac6eda6ecbc7f035de62249ef0f61fd7aa6ab9a6829f70ba00fce2"
- target=_blank rel=noopener>
- 3D Cube JSFiddle</a>
- </figcaption>
- </figure>
<h3>Play back bodymovin lottie files with skottie (click for fiddles)</h3>
<a href="https://jsfiddle.skia.org/canvaskit/6f4540a485ecbb8f0663b5ab3e04d9f3626a45234595d65f1b87942b90678aff"
@@ -185,10 +177,6 @@
});
});
- const loadBrickTex = fetch('https://storage.googleapis.com/skia-cdn/misc/brickwork-texture.jpg').then((response) => response.arrayBuffer());
- const loadBrickBump = fetch('https://storage.googleapis.com/skia-cdn/misc/brickwork_normal-map.jpg').then((response) => response.arrayBuffer());
- Promise.all([ckLoaded, loadBrickTex, loadBrickBump]).then((results) => {Camera3D(...results)});
-
function preventScrolling(canvas) {
canvas.addEventListener('touchmove', (e) => {
// Prevents touch events in the canvas from scrolling the canvas.
@@ -524,307 +512,6 @@
requestAnimationFrame(drawFrame);
}
- function Camera3D(canvas, textureImgData, normalImgData) {
- const surface = CanvasKit.MakeCanvasSurface('camera3d');
- if (!surface) {
- console.error('Could not make surface');
- return;
- }
-
- const sizeX = document.getElementById('camera3d').width;
- const sizeY = document.getElementById('camera3d').height;
-
- let clickToWorld = CanvasKit.M44.identity();
- let worldToClick = CanvasKit.M44.identity();
- // rotation of the cube shown in the demo
- let rotation = CanvasKit.M44.identity();
- // temporary during a click and drag
- let clickRotation = CanvasKit.M44.identity();
-
- // A virtual sphere used for tumbling the object on screen.
- const vSphereCenter = [sizeX/2, sizeY/2];
- const vSphereRadius = Math.min(...vSphereCenter);
-
- // The rounded rect used for each face
- const margin = vSphereRadius / 20;
- const rr = CanvasKit.RRectXY(CanvasKit.LTRBRect(margin, margin,
- vSphereRadius - margin, vSphereRadius - margin), margin*2.5, margin*2.5);
-
- const camAngle = Math.PI / 12;
- const cam = {
- 'eye' : [0, 0, 1 / Math.tan(camAngle/2) - 1],
- 'coa' : [0, 0, 0],
- 'up' : [0, 1, 0],
- 'near' : 0.05,
- 'far' : 4,
- 'angle': camAngle,
- };
-
- let mouseDown = false;
- let clickDown = [0, 0]; // location of click down
- let lastMouse = [0, 0]; // last mouse location
-
- // keep spinning after mouse up. Also start spinning on load
- let axis = [0.4, 1, 1];
- let totalSpin = 0;
- let spinRate = 0.1;
- let lastRadians = 0;
- let spinning = setInterval(keepSpinning, 30);
-
- const imgscale = CanvasKit.Matrix.scaled(2, 2);
- const textureShader = CanvasKit.MakeImageFromEncoded(textureImgData).makeShaderCubic(
- CanvasKit.TileMode.Clamp, CanvasKit.TileMode.Clamp, 1/3, 1/3, imgscale);
- const normalShader = CanvasKit.MakeImageFromEncoded(normalImgData).makeShaderCubic(
- CanvasKit.TileMode.Clamp, CanvasKit.TileMode.Clamp, 1/3, 1/3, imgscale);
- const children = [textureShader, normalShader];
-
- const prog = `
- uniform shader color_map;
- uniform shader normal_map;
-
- uniform float3 lightPos;
- layout (marker=local_to_world) uniform float4x4 localToWorld;
- layout (marker=normals(local_to_world)) uniform float4x4 localToWorldAdjInv;
-
- float3 convert_normal_sample(half4 c) {
- float3 n = 2 * c.rgb - 1;
- n.y = -n.y;
- return n;
- }
-
- half4 main(float2 p) {
- float3 norm = convert_normal_sample(sample(normal_map, p));
- float3 plane_norm = normalize(localToWorldAdjInv * float4(norm, 0)).xyz;
-
- float3 plane_pos = (localToWorld * float4(p, 0, 1)).xyz;
- float3 light_dir = normalize(lightPos - plane_pos);
-
- float ambient = 0.2;
- float dp = dot(plane_norm, light_dir);
- float scale = min(ambient + max(dp, 0), 1);
-
- return sample(color_map, p) * half4(float4(scale, scale, scale, 1));
- }
-`;
-
- const fact = CanvasKit.RuntimeEffect.Make(prog);
-
- // properties of light
- let lightLocation = [...vSphereCenter];
- let lightDistance = vSphereRadius;
- let lightIconRadius = 12;
- let draggingLight = false;
-
- function computeLightWorldPos() {
- return CanvasKit.Vector.add(CanvasKit.Vector.mulScalar([...vSphereCenter, 0], 0.5),
- CanvasKit.Vector.mulScalar(vSphereUnitV3(lightLocation), lightDistance));
- }
-
- let lightWorldPos = computeLightWorldPos();
-
- function drawLight(canvas) {
- const paint = new CanvasKit.Paint();
- paint.setAntiAlias(true);
- paint.setColor(CanvasKit.WHITE);
- canvas.drawCircle(...lightLocation, lightIconRadius + 2, paint);
- paint.setColor(CanvasKit.BLACK);
- canvas.drawCircle(...lightLocation, lightIconRadius, paint);
- }
-
- // Takes an x and y rotation in radians and a scale and returns a 4x4 matrix used to draw a
- // face of the cube in that orientation.
- function faceM44(rx, ry, scale) {
- return CanvasKit.M44.multiply(
- CanvasKit.M44.rotated([0,1,0], ry),
- CanvasKit.M44.rotated([1,0,0], rx),
- CanvasKit.M44.translated([0, 0, scale]));
- }
-
- const faceScale = vSphereRadius/2
- const faces = [
- {matrix: faceM44( 0, 0, faceScale ), color:CanvasKit.RED}, // front
- {matrix: faceM44( 0, Math.PI, faceScale ), color:CanvasKit.GREEN}, // back
-
- {matrix: faceM44( Math.PI/2, 0, faceScale ), color:CanvasKit.BLUE}, // top
- {matrix: faceM44(-Math.PI/2, 0, faceScale ), color:CanvasKit.CYAN}, // bottom
-
- {matrix: faceM44( 0, Math.PI/2, faceScale ), color:CanvasKit.MAGENTA}, // left
- {matrix: faceM44( 0,-Math.PI/2, faceScale ), color:CanvasKit.YELLOW}, // right
- ];
-
- // Returns a component of the matrix m indicating whether it faces the camera.
- // If it's positive for one of the matrices representing the face of the cube,
- // that face is currently in front.
- function front(m) {
- // Is this invertible?
- var m2 = CanvasKit.M44.invert(m);
- if (m2 === null) {
- m2 = CanvasKit.M44.identity();
- }
- // look at the sign of the z-scale of the inverse of m.
- // that's the number in row 2, col 2.
- return m2[10]
- }
-
- function setClickToWorld(canvas, matrix) {
- const l2d = canvas.getLocalToDevice();
- worldToClick = CanvasKit.M44.multiply(CanvasKit.M44.mustInvert(matrix), l2d);
- clickToWorld = CanvasKit.M44.mustInvert(worldToClick);
- }
-
- function drawCubeFace(canvas, m, color) {
- const trans = new CanvasKit.M44.translated([vSphereRadius/2, vSphereRadius/2, 0]);
- canvas.concat(CanvasKit.M44.multiply(trans, m, CanvasKit.M44.mustInvert(trans)));
- const znormal = front(canvas.getLocalToDevice());
- if (znormal < 0) {
- return; // skip faces facing backwards
- }
- // Pad with space for two 4x4 matrices. Even though the shader uses a layout()
- // statement to populate them, we still have to reserve space for them.
- const uniforms = [...lightWorldPos, ...Array(32).fill(0)];
- const paint = new CanvasKit.Paint();
- paint.setAntiAlias(true);
- const shader = fact.makeShaderWithChildren(uniforms, true /*=opaque*/, children);
- paint.setShader(shader);
- canvas.drawRRect(rr, paint);
- }
-
- function drawFrame(canvas) {
- const clickM = canvas.getLocalToDevice();
- canvas.save();
- canvas.translate(vSphereCenter[0] - vSphereRadius/2, vSphereCenter[1] - vSphereRadius/2);
- // pass surface dimensions as viewport size.
- canvas.concat(CanvasKit.M44.setupCamera(
- CanvasKit.LTRBRect(0, 0, vSphereRadius, vSphereRadius), vSphereRadius/2, cam));
- // Mark the matrix to make it available to the shader by this name.
- canvas.markCTM('local_to_world');
- setClickToWorld(canvas, clickM);
- for (let f of faces) {
- const saveCount = canvas.getSaveCount();
- canvas.save();
- drawCubeFace(canvas, CanvasKit.M44.multiply(clickRotation, rotation, f.matrix), f.color);
- canvas.restoreToCount(saveCount);
- }
- canvas.restore(); // camera
- canvas.restore(); // center the following content in the window
-
- // draw virtual sphere outline.
- const paint = new CanvasKit.Paint();
- paint.setAntiAlias(true);
- paint.setStyle(CanvasKit.PaintStyle.Stroke);
- paint.setColor(CanvasKit.Color(64, 255, 0, 1.0));
- canvas.drawCircle(vSphereCenter[0], vSphereCenter[1], vSphereRadius, paint);
- canvas.drawLine(vSphereCenter[0], vSphereCenter[1] - vSphereRadius,
- vSphereCenter[0], vSphereCenter[1] + vSphereRadius, paint);
- canvas.drawLine(vSphereCenter[0] - vSphereRadius, vSphereCenter[1],
- vSphereCenter[0] + vSphereRadius, vSphereCenter[1], paint);
-
- drawLight(canvas);
- }
-
- // convert a 2D point in the circle displayed on screen to a 3D unit vector.
- // the virtual sphere is a technique selecting a 3D direction by clicking on a the projection
- // of a hemisphere.
- function vSphereUnitV3(p) {
- // v = (v - fCenter) * (1 / fRadius);
- let v = CanvasKit.Vector.mulScalar(CanvasKit.Vector.sub(p, vSphereCenter), 1/vSphereRadius);
-
- // constrain the clicked point within the circle.
- let len2 = CanvasKit.Vector.lengthSquared(v);
- if (len2 > 1) {
- v = CanvasKit.Vector.normalize(v);
- len2 = 1;
- }
- // the closer to the edge of the circle you are, the closer z is to zero.
- const z = Math.sqrt(1 - len2);
- v.push(z);
- return v;
- }
-
- function computeVSphereRotation(start, end) {
- const u = vSphereUnitV3(start);
- const v = vSphereUnitV3(end);
- // Axis is in the scope of the Camera3D function so it can be used in keepSpinning.
- axis = CanvasKit.Vector.cross(u, v);
- const sinValue = CanvasKit.Vector.length(axis);
- const cosValue = CanvasKit.Vector.dot(u, v);
-
- let m = new CanvasKit.M44.identity();
- if (Math.abs(sinValue) > 0.000000001) {
- m = CanvasKit.M44.rotatedUnitSinCos(
- CanvasKit.Vector.mulScalar(axis, 1/sinValue), sinValue, cosValue);
- const radians = Math.atan(cosValue / sinValue);
- spinRate = lastRadians - radians;
- lastRadians = radians;
- }
- return m;
- }
-
- function keepSpinning() {
- totalSpin += spinRate;
- clickRotation = CanvasKit.M44.rotated(axis, totalSpin);
- spinRate *= .998;
- if (spinRate < 0.01) {
- stopSpinning();
- }
- surface.requestAnimationFrame(drawFrame);
- }
-
- function stopSpinning() {
- clearInterval(spinning);
- rotation = CanvasKit.M44.multiply(clickRotation, rotation);
- clickRotation = CanvasKit.M44.identity();
- }
-
- function interact(e) {
- const type = e.type;
- let eventPos = [e.offsetX, e.offsetY];
- if (type === 'lostpointercapture' || type === 'pointerup' || type == 'pointerleave') {
- if (draggingLight) {
- draggingLight = false;
- } else if (mouseDown) {
- mouseDown = false;
- if (spinRate > 0.02) {
- stopSpinning();
- spinning = setInterval(keepSpinning, 30);
- }
- } else {
- return;
- }
- return;
- } else if (type === 'pointermove') {
- if (draggingLight) {
- lightLocation = eventPos;
- lightWorldPos = computeLightWorldPos();
- } else if (mouseDown) {
- lastMouse = eventPos;
- clickRotation = computeVSphereRotation(clickDown, lastMouse);
- } else {
- return;
- }
- } else if (type === 'pointerdown') {
- // Are we repositioning the light?
- if (CanvasKit.Vector.dist(eventPos, lightLocation) < lightIconRadius) {
- draggingLight = true;
- return;
- }
- stopSpinning();
- mouseDown = true;
- clickDown = eventPos;
- lastMouse = eventPos;
- }
- surface.requestAnimationFrame(drawFrame);
- };
-
- document.getElementById('camera3d').addEventListener('pointermove', interact);
- document.getElementById('camera3d').addEventListener('pointerdown', interact);
- document.getElementById('camera3d').addEventListener('lostpointercapture', interact);
- document.getElementById('camera3d').addEventListener('pointerleave', interact);
- document.getElementById('camera3d').addEventListener('pointerup', interact);
-
- surface.requestAnimationFrame(drawFrame);
- }
-
}
document.head.appendChild(s);
})();
diff --git a/src/core/SkRuntimeEffect.cpp b/src/core/SkRuntimeEffect.cpp
index b6055fc..fc00e10 100644
--- a/src/core/SkRuntimeEffect.cpp
+++ b/src/core/SkRuntimeEffect.cpp
@@ -91,20 +91,6 @@
} // namespace SkSL
-// Accepts a valid marker, or "normals(<marker>)"
-static bool parse_marker(const SkSL::StringFragment& marker, uint32_t* id, uint32_t* flags) {
- SkString s = marker;
- if (s.startsWith("normals(") && s.endsWith(')')) {
- *flags |= SkRuntimeEffect::Uniform::kMarkerNormals_Flag;
- s.set(marker.fChars + 8, marker.fLength - 9);
- }
- if (!SkCanvasPriv::ValidateMarker(s.c_str())) {
- return false;
- }
- *id = SkOpts::hash_fn(s.c_str(), s.size(), 0);
- return true;
-}
-
static bool init_uniform_type(const SkSL::Context& ctx,
const SkSL::Type* type,
SkRuntimeEffect::Uniform* v) {
@@ -209,8 +195,6 @@
// can sample children with matrices or explicit coords. Because the children are color filters,
// we know (by induction) that they don't use those coords, so we keep the overall invariant.
//
- // Further down, we also ensure that color filters can't use layout(marker), which
- // would allow them to change behavior based on the CTM.
// TODO(skbug.com/11813): When ProgramKind is always kRuntimeColorFilter or kRuntimeShader,
// this can be simpler. There is no way for color filters to refer to sk_FragCoord or sample
// coords in that mode.
@@ -259,16 +243,6 @@
RETURN_FAILURE("Invalid uniform type: '%s'", type->displayName().c_str());
}
- const SkSL::StringFragment& marker(var.modifiers().fLayout.fMarker);
- if (marker.fLength) {
- uni.flags |= Uniform::kMarker_Flag;
- flags &= ~kAllowColorFilter_Flag;
- if (!parse_marker(marker, &uni.marker, &uni.flags)) {
- RETURN_FAILURE("Invalid 'marker' string: '%.*s'", (int)marker.fLength,
- marker.fChars);
- }
- }
-
if (var.modifiers().fLayout.fFlags & SkSL::Layout::Flag::kSRGBUnpremul_Flag) {
uni.flags |= Uniform::kSRGBUnpremul_Flag;
}
@@ -498,7 +472,6 @@
static sk_sp<SkData> get_xformed_uniforms(const SkRuntimeEffect* effect,
sk_sp<SkData> baseUniforms,
- const SkMatrixProvider* matrixProvider,
const SkColorSpace* dstCS) {
using Flags = SkRuntimeEffect::Uniform::Flags;
using Type = SkRuntimeEffect::Uniform::Type;
@@ -514,26 +487,7 @@
};
for (const auto& v : effect->uniforms()) {
- if (v.flags & Flags::kMarker_Flag) {
- SkASSERT(v.type == Type::kFloat4x4);
- // Color filters don't provide a matrix provider, but shouldn't be allowed to get here
- SkASSERT(matrixProvider);
- SkM44* localToMarker = SkTAddOffset<SkM44>(writableData(), v.offset);
- if (!matrixProvider->getLocalToMarker(v.marker, localToMarker)) {
- // We couldn't provide a matrix that was requested by the SkSL
- return nullptr;
- }
- if (v.flags & Flags::kMarkerNormals_Flag) {
- // Normals need to be transformed by the inverse-transpose of the upper-left
- // 3x3 portion (scale + rotate) of the matrix.
- localToMarker->setRow(3, {0, 0, 0, 1});
- localToMarker->setCol(3, {0, 0, 0, 1});
- if (!localToMarker->invert(localToMarker)) {
- return nullptr;
- }
- *localToMarker = localToMarker->transpose();
- }
- } else if (v.flags & Flags::kSRGBUnpremul_Flag) {
+ if (v.flags & Flags::kSRGBUnpremul_Flag) {
SkASSERT(v.type == Type::kFloat3 || v.type == Type::kFloat4);
if (steps.flags.mask()) {
float* color = SkTAddOffset<float>(writableData(), v.offset);
@@ -577,10 +531,8 @@
GrRecordingContext* context,
const GrColorInfo& colorInfo) const override {
sk_sp<SkData> uniforms =
- get_xformed_uniforms(fEffect.get(), fUniforms, nullptr, colorInfo.colorSpace());
- if (!uniforms) {
- return GrFPFailure(nullptr);
- }
+ get_xformed_uniforms(fEffect.get(), fUniforms, colorInfo.colorSpace());
+ SkASSERT(uniforms);
auto fp = GrSkSLFP::Make(fEffect, "Runtime_Color_Filter", std::move(uniforms));
for (const auto& child : fChildren) {
@@ -611,10 +563,8 @@
skvm::Color onProgram(skvm::Builder* p, skvm::Color c,
SkColorSpace* dstCS,
skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override {
- sk_sp<SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms, nullptr, dstCS);
- if (!inputs) {
- return {};
- }
+ sk_sp<SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms, dstCS);
+ SkASSERT(inputs);
// The color filter code might use sample-with-matrix (even though the matrix/coords are
// ignored by the child). There should be no way for the color filter to use device coords.
@@ -648,9 +598,7 @@
const skvm::Program& program = fEffect->getFilterColorInfo().program;
// Get our specific uniform values
- sk_sp<SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms, nullptr, dstCS);
-
- // There should be no way for a color filter (which can't use "marker") to fail here
+ sk_sp<SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms, dstCS);
SkASSERT(inputs);
// 'program' defines sampling any child as returning a uniform color. Assemble a buffer
@@ -737,11 +685,9 @@
return nullptr;
}
- sk_sp<SkData> uniforms = get_xformed_uniforms(
- fEffect.get(), fUniforms, &args.fMatrixProvider, args.fDstColorInfo->colorSpace());
- if (!uniforms) {
- return nullptr;
- }
+ sk_sp<SkData> uniforms =
+ get_xformed_uniforms(fEffect.get(), fUniforms, args.fDstColorInfo->colorSpace());
+ SkASSERT(uniforms);
auto fp = GrSkSLFP::Make(fEffect, "runtime_shader", std::move(uniforms));
for (const auto& child : fChildren) {
@@ -779,11 +725,8 @@
const SkMatrixProvider& matrices, const SkMatrix* localM,
const SkColorInfo& dst,
skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override {
- sk_sp<SkData> inputs =
- get_xformed_uniforms(fEffect.get(), fUniforms, &matrices, dst.colorSpace());
- if (!inputs) {
- return {};
- }
+ sk_sp<SkData> inputs = get_xformed_uniforms(fEffect.get(), fUniforms, dst.colorSpace());
+ SkASSERT(inputs);
SkMatrix inv;
if (!this->computeTotalInverse(matrices.localToDevice(), localM, &inv)) {
@@ -944,18 +887,13 @@
if (!fillContext) {
return nullptr;
}
- SkSimpleMatrixProvider matrixProvider(SkMatrix::I());
- uniforms = get_xformed_uniforms(this,
- std::move(uniforms),
- &matrixProvider,
- resultInfo.colorSpace());
- if (!uniforms) {
- return nullptr;
- }
+ uniforms = get_xformed_uniforms(this, std::move(uniforms), resultInfo.colorSpace());
+ SkASSERT(uniforms);
auto fp = GrSkSLFP::Make(sk_ref_sp(this),
"runtime_image",
std::move(uniforms));
+ SkSimpleMatrixProvider matrixProvider(SkMatrix::I());
GrColorInfo colorInfo(resultInfo.colorInfo());
GrFPArgs args(recordingContext, matrixProvider, &colorInfo);
for (size_t i = 0; i < childCount; ++i) {
diff --git a/src/sksl/SkSLDehydrator.cpp b/src/sksl/SkSLDehydrator.cpp
index 2514254..cb4cf47 100644
--- a/src/sksl/SkSLDehydrator.cpp
+++ b/src/sksl/SkSLDehydrator.cpp
@@ -100,7 +100,6 @@
this->writeS8(l.fPrimitive);
this->writeS8(l.fMaxVertices);
this->writeS8(l.fInvocations);
- this->write(l.fMarker);
this->write(l.fWhen);
this->writeS8((int) l.fCType);
}
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 33f480d..e71b1d4 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -308,20 +308,6 @@
(modifiers.fFlags & Modifiers::kUniform_Flag)) {
this->errorReporter().error(offset, "'key' is not permitted on 'uniform' variables");
}
- if (modifiers.fLayout.fMarker.fLength) {
- if (this->programKind() != ProgramKind::kRuntimeEffect &&
- this->programKind() != ProgramKind::kRuntimeShader) {
- this->errorReporter().error(offset, "'marker' is only permitted in runtime shaders");
- }
- if (!(modifiers.fFlags & Modifiers::kUniform_Flag)) {
- this->errorReporter().error(offset,
- "'marker' is only permitted on 'uniform' variables");
- }
- if (*baseType != *fContext.fTypes.fFloat4x4) {
- this->errorReporter().error(offset,
- "'marker' is only permitted on float4x4 variables");
- }
- }
if (modifiers.fLayout.fFlags & Layout::kSRGBUnpremul_Flag) {
if (this->programKind() != ProgramKind::kRuntimeEffect &&
this->programKind() != ProgramKind::kRuntimeColorFilter &&
@@ -866,7 +852,6 @@
checkLayout(Layout::kPrimitive_Flag, "primitive-type");
checkLayout(Layout::kMaxVertices_Flag, "max_vertices");
checkLayout(Layout::kInvocations_Flag, "invocations");
- checkLayout(Layout::kMarker_Flag, "marker");
checkLayout(Layout::kWhen_Flag, "when");
checkLayout(Layout::kCType_Flag, "ctype");
SkASSERT(layoutFlags == 0);
diff --git a/src/sksl/SkSLParser.cpp b/src/sksl/SkSLParser.cpp
index 5b74a1d..121af09 100644
--- a/src/sksl/SkSLParser.cpp
+++ b/src/sksl/SkSLParser.cpp
@@ -107,7 +107,6 @@
TOKEN(TRIANGLES_ADJACENCY, "triangles_adjacency");
TOKEN(MAX_VERTICES, "max_vertices");
TOKEN(INVOCATIONS, "invocations");
- TOKEN(MARKER, "marker");
TOKEN(WHEN, "when");
TOKEN(KEY, "key");
TOKEN(TRACKED, "tracked");
@@ -881,14 +880,12 @@
Layout::Primitive primitive = Layout::kUnspecified_Primitive;
int maxVertices = -1;
int invocations = -1;
- StringFragment marker;
StringFragment when;
Layout::CType ctype = Layout::CType::kDefault;
if (this->checkNext(Token::Kind::TK_LAYOUT)) {
if (!this->expect(Token::Kind::TK_LPAREN, "'('")) {
return Layout(flags, location, offset, binding, index, set, builtin,
- inputAttachmentIndex, primitive, maxVertices, invocations, marker, when,
- ctype);
+ inputAttachmentIndex, primitive, maxVertices, invocations, when, ctype);
}
for (;;) {
Token t = this->nextToken();
@@ -991,10 +988,6 @@
setFlag(Layout::kInvocations_Flag);
invocations = this->layoutInt();
break;
- case LayoutToken::MARKER:
- setFlag(Layout::kMarker_Flag);
- marker = this->layoutCode();
- break;
case LayoutToken::WHEN:
setFlag(Layout::kWhen_Flag);
when = this->layoutCode();
@@ -1019,7 +1012,7 @@
}
}
return Layout(flags, location, offset, binding, index, set, builtin, inputAttachmentIndex,
- primitive, maxVertices, invocations, marker, when, ctype);
+ primitive, maxVertices, invocations, when, ctype);
}
/* layout? (UNIFORM | CONST | IN | OUT | INOUT | FLAT | NOPERSPECTIVE | INLINE)* */
diff --git a/src/sksl/SkSLParser.h b/src/sksl/SkSLParser.h
index 1b5617a..6131940 100644
--- a/src/sksl/SkSLParser.h
+++ b/src/sksl/SkSLParser.h
@@ -50,7 +50,6 @@
TRIANGLES_ADJACENCY,
MAX_VERTICES,
INVOCATIONS,
- MARKER,
WHEN,
KEY,
TRACKED,
diff --git a/src/sksl/SkSLRehydrator.cpp b/src/sksl/SkSLRehydrator.cpp
index cb6092c..c4dd94f 100644
--- a/src/sksl/SkSLRehydrator.cpp
+++ b/src/sksl/SkSLRehydrator.cpp
@@ -114,12 +114,11 @@
int primitive = this->readS8();
int maxVertices = this->readS8();
int invocations = this->readS8();
- StringFragment marker = this->readString();
StringFragment when = this->readString();
int ctype = this->readS8();
return Layout(flags, location, offset, binding, index, set, builtin,
inputAttachmentIndex, (Layout::Primitive)primitive, maxVertices,
- invocations, marker, when, (Layout::CType)ctype);
+ invocations, when, (Layout::CType)ctype);
}
default:
SkASSERT(false);
diff --git a/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp b/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
index c00ef53..46d1515 100644
--- a/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLSPIRVCodeGenerator.cpp
@@ -2053,8 +2053,7 @@
/*binding=*/-1, /*index=*/-1, /*set=*/-1, /*builtin=*/-1,
/*inputAttachmentIndex=*/-1,
Layout::kUnspecified_Primitive, /*maxVertices=*/1,
- /*invocations=*/-1, /*marker=*/"", /*when=*/"",
- Layout::CType::kDefault),
+ /*invocations=*/-1, /*when=*/"", Layout::CType::kDefault),
/*flags=*/0),
SKSL_RTHEIGHT_NAME, fContext.fTypes.fFloat.get());
StringFragment name("sksl_synthetic_uniforms");
@@ -2074,7 +2073,7 @@
Layout(flags, /*location=*/-1, /*offset=*/-1, binding, /*index=*/-1,
set, /*builtin=*/-1, /*inputAttachmentIndex=*/-1,
Layout::kUnspecified_Primitive,
- /*maxVertices=*/-1, /*invocations=*/-1, /*marker=*/"", /*when=*/"",
+ /*maxVertices=*/-1, /*invocations=*/-1, /*when=*/"",
Layout::CType::kDefault),
Modifiers::kUniform_Flag);
const Variable* intfVar = fSynthetics.takeOwnershipOfSymbol(
diff --git a/src/sksl/dsl/DSLVar.cpp b/src/sksl/dsl/DSLVar.cpp
index 9756672..cb71285 100644
--- a/src/sksl/dsl/DSLVar.cpp
+++ b/src/sksl/dsl/DSLVar.cpp
@@ -45,8 +45,7 @@
/*inputAttachmentIndex=*/-1,
Layout::kUnspecified_Primitive,
/*maxVertices=*/1, /*invocations=*/-1,
- /*marker=*/"", /*when=*/"",
- Layout::CType::kDefault),
+ /*when=*/"", Layout::CType::kDefault),
SkSL::Modifiers::kNo_Flag)),
fName,
DSLWriter::Context().fTypes.fFloat2.get(),
diff --git a/src/sksl/generated/sksl_fp.dehydrated.sksl b/src/sksl/generated/sksl_fp.dehydrated.sksl
index 1d1c252..ee76009 100644
--- a/src/sksl/generated/sksl_fp.dehydrated.sksl
+++ b/src/sksl/generated/sksl_fp.dehydrated.sksl
@@ -29,25 +29,25 @@
22,2,0,17,0,
53,3,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,0,255,255,255,255,30,0,30,0,0,2,31,0,
+36,0,32,0,0,255,255,255,255,255,15,0,255,255,255,255,30,0,0,2,31,0,
50,4,0,44,0,0,
0,5,0,
47,4,0,1,
53,6,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,30,0,0,0,51,0,
+36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,0,0,51,0,
47,5,0,0,
53,7,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,30,0,0,0,67,0,
+36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,0,0,67,0,
50,8,0,84,0,0,
53,9,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,30,0,0,0,90,0,
+36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,0,0,90,0,
47,8,0,0,
53,10,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,30,0,0,0,110,0,
+36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,0,0,110,0,
47,8,0,0,
53,11,0,
16,135,0,
diff --git a/src/sksl/generated/sksl_frag.dehydrated.sksl b/src/sksl/generated/sksl_frag.dehydrated.sksl
index 03bbcae..12bd60b 100644
--- a/src/sksl/generated/sksl_frag.dehydrated.sksl
+++ b/src/sksl/generated/sksl_frag.dehydrated.sksl
@@ -11,23 +11,23 @@
49,5,0,
53,1,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,0,255,255,255,255,2,0,2,0,0,2,3,0,
+36,0,32,0,0,255,255,255,255,255,15,0,255,255,255,255,2,0,0,2,3,0,
50,2,0,16,0,0,
53,3,0,
37,
-36,0,32,0,0,255,255,255,255,255,17,0,255,255,255,255,2,0,2,0,0,2,23,0,
+36,0,32,0,0,255,255,255,255,255,17,0,255,255,255,255,2,0,0,2,23,0,
50,4,0,36,0,0,
53,5,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,2,0,2,0,0,4,41,0,
+36,0,32,0,0,255,255,255,255,255,15,39,255,255,255,255,2,0,0,4,41,0,
50,6,0,66,0,0,
53,7,0,
37,
-36,0,41,0,0,0,255,255,0,255,17,39,255,255,255,255,2,0,2,0,0,4,72,0,
+36,0,41,0,0,0,255,255,0,255,17,39,255,255,255,255,2,0,0,4,72,0,
47,6,0,0,
53,8,0,
37,
-36,0,32,0,0,255,255,255,255,255,24,39,255,255,255,255,2,0,2,0,0,0,85,0,
+36,0,32,0,0,255,255,255,255,255,24,39,255,255,255,255,2,0,0,0,85,0,
47,6,0,0,5,0,
2,0,
1,0,
diff --git a/src/sksl/generated/sksl_geom.dehydrated.sksl b/src/sksl/generated/sksl_geom.dehydrated.sksl
index 83f41cc..100fbc2 100644
--- a/src/sksl/generated/sksl_geom.dehydrated.sksl
+++ b/src/sksl/generated/sksl_geom.dehydrated.sksl
@@ -16,26 +16,26 @@
49,12,0,
44,1,0,2,0,2,
37,
-36,0,32,0,0,255,255,255,255,255,0,0,255,255,255,255,15,0,15,0,0,0,16,0,
+36,0,32,0,0,255,255,255,255,255,0,0,255,255,255,255,15,0,0,0,16,0,
50,2,0,28,0,
37,
-36,0,32,0,0,255,255,255,255,255,1,0,255,255,255,255,15,0,15,0,0,0,35,0,
+36,0,32,0,0,255,255,255,255,255,1,0,255,255,255,255,15,0,0,0,35,0,
50,3,0,48,0,
53,4,0,
37,
-36,0,32,0,0,255,255,255,255,255,18,39,255,255,255,255,15,0,15,0,0,2,54,0,
+36,0,32,0,0,255,255,255,255,255,18,39,255,255,255,255,15,0,0,2,54,0,
0,5,0,
47,1,0,255,0,
44,6,0,2,0,2,
37,
-36,0,32,0,0,255,255,255,255,255,0,0,255,255,255,255,15,0,15,0,0,0,16,0,
+36,0,32,0,0,255,255,255,255,255,0,0,255,255,255,255,15,0,0,0,16,0,
47,2,0,
37,
-36,0,32,0,0,255,255,255,255,255,1,0,255,255,255,255,15,0,15,0,0,0,35,0,
+36,0,32,0,0,255,255,255,255,255,1,0,255,255,255,255,15,0,0,0,35,0,
47,3,0,
53,7,0,
37,
-36,0,32,0,0,255,255,255,255,255,23,39,255,255,255,255,15,0,15,0,0,4,2,0,
+36,0,32,0,0,255,255,255,255,255,23,39,255,255,255,255,15,0,0,4,2,0,
47,6,0,0,
24,7,0,0,
24,7,0,1,
diff --git a/src/sksl/generated/sksl_rt_shader.dehydrated.sksl b/src/sksl/generated/sksl_rt_shader.dehydrated.sksl
index c0cea05..ced2f98 100644
--- a/src/sksl/generated/sksl_rt_shader.dehydrated.sksl
+++ b/src/sksl/generated/sksl_rt_shader.dehydrated.sksl
@@ -11,7 +11,7 @@
49,4,0,
53,1,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,0,255,255,255,255,2,0,2,0,0,0,3,0,
+36,0,32,0,0,255,255,255,255,255,15,0,255,255,255,255,2,0,0,0,3,0,
50,2,0,16,0,0,
53,3,0,
16,23,0,
diff --git a/src/sksl/generated/sksl_runtime.dehydrated.sksl b/src/sksl/generated/sksl_runtime.dehydrated.sksl
index 1fb3e48..06ef180 100644
--- a/src/sksl/generated/sksl_runtime.dehydrated.sksl
+++ b/src/sksl/generated/sksl_runtime.dehydrated.sksl
@@ -15,7 +15,7 @@
49,14,0,
53,1,0,
37,
-36,0,32,0,0,255,255,255,255,255,15,0,255,255,255,255,2,0,2,0,0,0,3,0,
+36,0,32,0,0,255,255,255,255,255,15,0,255,255,255,255,2,0,0,0,3,0,
50,2,0,16,0,0,
53,3,0,
16,23,0,
diff --git a/src/sksl/generated/sksl_vert.dehydrated.sksl b/src/sksl/generated/sksl_vert.dehydrated.sksl
index 6145ac5..4d1d64c 100644
--- a/src/sksl/generated/sksl_vert.dehydrated.sksl
+++ b/src/sksl/generated/sksl_vert.dehydrated.sksl
@@ -11,10 +11,10 @@
49,6,0,
44,1,0,2,0,2,
37,
-36,0,32,0,0,255,255,255,255,255,0,0,255,255,255,255,15,0,15,0,0,0,16,0,
+36,0,32,0,0,255,255,255,255,255,0,0,255,255,255,255,15,0,0,0,16,0,
50,2,0,28,0,
37,
-36,0,32,0,0,255,255,255,255,255,1,0,255,255,255,255,15,0,15,0,0,0,35,0,
+36,0,32,0,0,255,255,255,255,255,1,0,255,255,255,255,15,0,0,0,35,0,
50,3,0,48,0,
53,4,0,
37,
@@ -24,11 +24,11 @@
24,4,0,1,
53,5,0,
37,
-36,0,32,0,0,255,255,255,255,255,42,0,255,255,255,255,15,0,15,0,0,2,54,0,
+36,0,32,0,0,255,255,255,255,255,42,0,255,255,255,255,15,0,0,2,54,0,
50,6,0,66,0,0,
53,7,0,
37,
-36,0,32,0,0,255,255,255,255,255,43,0,255,255,255,255,15,0,15,0,0,2,70,0,
+36,0,32,0,0,255,255,255,255,255,43,0,255,255,255,255,15,0,0,2,70,0,
47,6,0,0,4,0,
5,0,
3,0,
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index c32ec62..0013d3a 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -56,13 +56,6 @@
test_invalid_effect(r, "in half3x3 m;" EMPTY_MAIN, "'in'");
}
-DEF_TEST(SkRuntimeEffectInvalid_MarkerRequiresFloat4x4, r) {
- // 'marker' is only permitted on float4x4 uniforms
- test_invalid_effect(r,
- "layout(marker=local_to_world) uniform float3x3 localToWorld;" EMPTY_MAIN,
- "float4x4");
-}
-
DEF_TEST(SkRuntimeEffectInvalid_UndefinedFunction, r) {
test_invalid_effect(r, "half4 missing(); half4 main() { return missing(); }",
"undefined function");
@@ -94,10 +87,6 @@
// but not valid color filters
test("half4 main(float2 p) { return half2(p).xy01; }");
test("half4 main(float2 p) { return half2(sk_FragCoord.xy).xy01; }");
-
- // We also can't use layout(marker), which would give the runtime color filter CTM information
- test("layout(marker=ctm) uniform float4x4 ctm;"
- "half4 main(float2 p) { return half4(half(ctm[0][0]), 0, 0, 1); }");
}
class TestEffect {
diff --git a/tests/sksl/errors/LayoutInFunctions.glsl b/tests/sksl/errors/LayoutInFunctions.glsl
index 7a10dd3..7322121 100644
--- a/tests/sksl/errors/LayoutInFunctions.glsl
+++ b/tests/sksl/errors/LayoutInFunctions.glsl
@@ -1,41 +1,39 @@
### Compilation failed:
-error: 21: layout qualifier 'origin_upper_left' is not permitted here
-error: 21: layout qualifier 'override_coverage' is not permitted here
-error: 21: layout qualifier 'push_constant' is not permitted here
-error: 21: layout qualifier 'blend_support_all_equations' is not permitted here
-error: 21: layout qualifier 'tracked' is not permitted here
-error: 21: layout qualifier 'srgb_unpremul' is not permitted here
-error: 21: layout qualifier 'key' is not permitted here
-error: 21: layout qualifier 'location' is not permitted here
-error: 21: layout qualifier 'offset' is not permitted here
-error: 21: layout qualifier 'binding' is not permitted here
-error: 21: layout qualifier 'index' is not permitted here
-error: 21: layout qualifier 'set' is not permitted here
-error: 21: layout qualifier 'builtin' is not permitted here
-error: 21: layout qualifier 'input_attachment_index' is not permitted here
-error: 21: layout qualifier 'max_vertices' is not permitted here
-error: 21: layout qualifier 'invocations' is not permitted here
-error: 21: layout qualifier 'marker' is not permitted here
-error: 21: layout qualifier 'when' is not permitted here
-error: 21: layout qualifier 'ctype' is not permitted here
-error: 43: layout qualifier 'origin_upper_left' is not permitted here
-error: 43: layout qualifier 'override_coverage' is not permitted here
-error: 43: layout qualifier 'push_constant' is not permitted here
-error: 43: layout qualifier 'blend_support_all_equations' is not permitted here
-error: 43: layout qualifier 'tracked' is not permitted here
-error: 43: layout qualifier 'srgb_unpremul' is not permitted here
-error: 43: layout qualifier 'key' is not permitted here
-error: 43: layout qualifier 'location' is not permitted here
-error: 43: layout qualifier 'offset' is not permitted here
-error: 43: layout qualifier 'binding' is not permitted here
-error: 43: layout qualifier 'index' is not permitted here
-error: 43: layout qualifier 'set' is not permitted here
-error: 43: layout qualifier 'builtin' is not permitted here
-error: 43: layout qualifier 'input_attachment_index' is not permitted here
-error: 43: layout qualifier 'max_vertices' is not permitted here
-error: 43: layout qualifier 'invocations' is not permitted here
-error: 43: layout qualifier 'marker' is not permitted here
-error: 43: layout qualifier 'when' is not permitted here
-error: 43: layout qualifier 'ctype' is not permitted here
-38 errors
+error: 20: layout qualifier 'origin_upper_left' is not permitted here
+error: 20: layout qualifier 'override_coverage' is not permitted here
+error: 20: layout qualifier 'push_constant' is not permitted here
+error: 20: layout qualifier 'blend_support_all_equations' is not permitted here
+error: 20: layout qualifier 'tracked' is not permitted here
+error: 20: layout qualifier 'srgb_unpremul' is not permitted here
+error: 20: layout qualifier 'key' is not permitted here
+error: 20: layout qualifier 'location' is not permitted here
+error: 20: layout qualifier 'offset' is not permitted here
+error: 20: layout qualifier 'binding' is not permitted here
+error: 20: layout qualifier 'index' is not permitted here
+error: 20: layout qualifier 'set' is not permitted here
+error: 20: layout qualifier 'builtin' is not permitted here
+error: 20: layout qualifier 'input_attachment_index' is not permitted here
+error: 20: layout qualifier 'max_vertices' is not permitted here
+error: 20: layout qualifier 'invocations' is not permitted here
+error: 20: layout qualifier 'when' is not permitted here
+error: 20: layout qualifier 'ctype' is not permitted here
+error: 41: layout qualifier 'origin_upper_left' is not permitted here
+error: 41: layout qualifier 'override_coverage' is not permitted here
+error: 41: layout qualifier 'push_constant' is not permitted here
+error: 41: layout qualifier 'blend_support_all_equations' is not permitted here
+error: 41: layout qualifier 'tracked' is not permitted here
+error: 41: layout qualifier 'srgb_unpremul' is not permitted here
+error: 41: layout qualifier 'key' is not permitted here
+error: 41: layout qualifier 'location' is not permitted here
+error: 41: layout qualifier 'offset' is not permitted here
+error: 41: layout qualifier 'binding' is not permitted here
+error: 41: layout qualifier 'index' is not permitted here
+error: 41: layout qualifier 'set' is not permitted here
+error: 41: layout qualifier 'builtin' is not permitted here
+error: 41: layout qualifier 'input_attachment_index' is not permitted here
+error: 41: layout qualifier 'max_vertices' is not permitted here
+error: 41: layout qualifier 'invocations' is not permitted here
+error: 41: layout qualifier 'when' is not permitted here
+error: 41: layout qualifier 'ctype' is not permitted here
+36 errors
diff --git a/tests/sksl/errors/LayoutRepeatedQualifiers.glsl b/tests/sksl/errors/LayoutRepeatedQualifiers.glsl
index dec1d9e..917d921 100644
--- a/tests/sksl/errors/LayoutRepeatedQualifiers.glsl
+++ b/tests/sksl/errors/LayoutRepeatedQualifiers.glsl
@@ -1,23 +1,22 @@
### Compilation failed:
-error: 23: layout qualifier 'origin_upper_left' appears more than once
-error: 24: layout qualifier 'override_coverage' appears more than once
-error: 25: layout qualifier 'early_fragment_tests' appears more than once
-error: 26: layout qualifier 'push_constant' appears more than once
-error: 27: layout qualifier 'blend_support_all_equations' appears more than once
-error: 28: layout qualifier 'tracked' appears more than once
-error: 29: layout qualifier 'srgb_unpremul' appears more than once
-error: 30: layout qualifier 'key' appears more than once
-error: 31: layout qualifier 'location' appears more than once
-error: 32: layout qualifier 'offset' appears more than once
-error: 33: layout qualifier 'binding' appears more than once
-error: 34: layout qualifier 'index' appears more than once
-error: 35: layout qualifier 'set' appears more than once
-error: 36: layout qualifier 'builtin' appears more than once
-error: 37: layout qualifier 'input_attachment_index' appears more than once
-error: 38: layout qualifier 'max_vertices' appears more than once
-error: 39: layout qualifier 'invocations' appears more than once
-error: 40: layout qualifier 'marker' appears more than once
-error: 41: layout qualifier 'when' appears more than once
-error: 42: layout qualifier 'ctype' appears more than once
-20 errors
+error: 22: layout qualifier 'origin_upper_left' appears more than once
+error: 23: layout qualifier 'override_coverage' appears more than once
+error: 24: layout qualifier 'early_fragment_tests' appears more than once
+error: 25: layout qualifier 'push_constant' appears more than once
+error: 26: layout qualifier 'blend_support_all_equations' appears more than once
+error: 27: layout qualifier 'tracked' appears more than once
+error: 28: layout qualifier 'srgb_unpremul' appears more than once
+error: 29: layout qualifier 'key' appears more than once
+error: 30: layout qualifier 'location' appears more than once
+error: 31: layout qualifier 'offset' appears more than once
+error: 32: layout qualifier 'binding' appears more than once
+error: 33: layout qualifier 'index' appears more than once
+error: 34: layout qualifier 'set' appears more than once
+error: 35: layout qualifier 'builtin' appears more than once
+error: 36: layout qualifier 'input_attachment_index' appears more than once
+error: 37: layout qualifier 'max_vertices' appears more than once
+error: 38: layout qualifier 'invocations' appears more than once
+error: 39: layout qualifier 'when' appears more than once
+error: 40: layout qualifier 'ctype' appears more than once
+19 errors
diff --git a/tests/sksl/runtime_errors/InvalidColorFilterFeatures.skvm b/tests/sksl/runtime_errors/InvalidColorFilterFeatures.skvm
index 2c5d442..7d60309 100644
--- a/tests/sksl/runtime_errors/InvalidColorFilterFeatures.skvm
+++ b/tests/sksl/runtime_errors/InvalidColorFilterFeatures.skvm
@@ -1,5 +1,4 @@
### Compilation failed:
-error: 5: 'marker' is only permitted in runtime shaders
-error: 8: unknown identifier 'sk_FragCoord'
-2 errors
+error: 6: unknown identifier 'sk_FragCoord'
+1 error