Make the hints a uniform instead of a buffer texture.

Saves a good bit of memory traffic during vertex shading.
This commit is contained in:
Patrick Walton 2017-10-05 19:14:52 -07:00
parent 28837f72a6
commit 6a7c013e61
11 changed files with 39 additions and 50 deletions

View File

@ -25,6 +25,7 @@ import {BUILTIN_FONT_URI, ExpandedMeshData} from "./text";
import {GlyphStore, Hint, PathfinderFont, TextFrame, TextRun} from "./text";
import {assert, panic, PathfinderError, unwrapNull} from "./utils";
import {DemoView, Timings} from "./view";
import { UniformMap } from './gl-utils';
const TEXT_AVAILABLE_WIDTH: number = 150000;
const TEXT_PADDING: number = 2000;
@ -304,6 +305,10 @@ class ThreeDView extends DemoView {
this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, CUBE_INDICES, this.gl.STATIC_DRAW);
}
setHintsUniform(uniforms: UniformMap): void {
this.gl.uniform4f(uniforms.uHints, 0, 0, 0, 0);
}
protected pathColorsForObject(objectIndex: number): Uint8Array {
return TEXT_COLOR;
}

View File

@ -25,6 +25,7 @@ import {BUILTIN_FONT_URI, ExpandedMeshData, GlyphStore, PathfinderFont, TextFram
import {TextRun} from "./text";
import {assert, PathfinderError, unwrapNull, unwrapUndef} from "./utils";
import {DemoView, MonochromeDemoView, Timings } from "./view";
import { UniformMap } from './gl-utils';
const STRING: string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@ -125,7 +126,6 @@ class BenchmarkAppController extends DemoAppController<BenchmarkTestView> {
this.view.then(view => {
view.uploadPathColors(1);
view.uploadPathTransforms(1);
view.uploadHints();
view.attachMeshes([expandedMeshes.meshes]);
});
});
@ -246,13 +246,8 @@ class BenchmarkTestView extends MonochromeDemoView {
this.camera.onZoom = () => this.setDirty();
}
uploadHints(): void {
const glyphCount = unwrapNull(this.appController.textRun).glyphIDs.length;
const pathHints = new Float32Array((glyphCount + 1) * 4);
const pathHintsBufferTexture = new PathfinderBufferTexture(this.gl, 'uPathHints');
pathHintsBufferTexture.upload(this.gl, pathHints);
this.pathHintsBufferTexture = pathHintsBufferTexture;
setHintsUniform(uniforms: UniformMap): void {
this.gl.uniform4f(uniforms.uHints, 0, 0, 0, 0);
}
protected createAAStrategy(aaType: AntialiasingStrategyName,

View File

@ -379,8 +379,7 @@ export abstract class ECAAStrategy extends AntialiasingStrategy {
this.bVertexPositionBufferTexture.bind(view.gl, uniforms, 0);
this.bVertexPathIDBufferTexture.bind(view.gl, uniforms, 1);
view.pathTransformBufferTextures[0].bind(view.gl, uniforms, 2);
if (view.pathHintsBufferTexture !== null)
view.pathHintsBufferTexture.bind(view.gl, uniforms, 3);
view.setHintsUniform(uniforms);
}
private antialiasLines(view: MonochromeDemoView) {

View File

@ -23,6 +23,7 @@ import SSAAStrategy from "./ssaa-strategy";
import {BUILTIN_SVG_URI, SVGLoader} from './svg-loader';
import {panic, unwrapNull} from './utils';
import {DemoView, Timings} from './view';
import { UniformMap } from './gl-utils';
const parseColor = require('parse-color');
@ -120,6 +121,10 @@ class SVGDemoView extends DemoView {
return this.destAllocatedSize;
}
setHintsUniform(uniforms: UniformMap): void {
this.gl.uniform4f(uniforms.uHints, 0, 0, 0, 0);
}
protected pathColorsForObject(objectIndex: number): Uint8Array {
const instances = this.appController.loader.pathInstances;
const pathColors = new Uint8Array(4 * (instances.length + 1));

View File

@ -342,6 +342,15 @@ class TextDemoView extends MonochromeDemoView {
this.setDirty();
}
setHintsUniform(uniforms: UniformMap): void {
const hint = this.createHint();
this.gl.uniform4f(uniforms.uHints,
hint.xHeight,
hint.hintedXHeight,
hint.stemHeight,
hint.hintedStemHeight);
}
protected initContext() {
super.initContext();
}
@ -568,19 +577,6 @@ class TextDemoView extends MonochromeDemoView {
this.uploadPathTransforms(1);
// TODO(pcwalton): Regenerate the IBOs to include only the glyphs we care about.
const pathCount = this.appController.pathCount;
const pathHints = new Float32Array((pathCount + 1) * 4);
for (let pathID = 0; pathID < pathCount; pathID++) {
pathHints[pathID * 4 + 0] = hint.xHeight;
pathHints[pathID * 4 + 1] = hint.hintedXHeight;
pathHints[pathID * 4 + 2] = hint.stemHeight;
pathHints[pathID * 4 + 3] = hint.hintedStemHeight;
}
const pathHintsBufferTexture = new PathfinderBufferTexture(this.gl, 'uPathHints');
pathHintsBufferTexture.upload(this.gl, pathHints);
this.pathHintsBufferTexture = pathHintsBufferTexture;
this.setGlyphTexCoords();
}

View File

@ -139,7 +139,6 @@ export abstract class DemoView extends PathfinderView {
meshData: PathfinderMeshData[];
pathTransformBufferTextures: PathfinderBufferTexture[];
pathHintsBufferTexture: PathfinderBufferTexture | null;
protected timerQueryExt: any;
@ -280,6 +279,8 @@ export abstract class DemoView extends PathfinderView {
}
}
abstract setHintsUniform(uniforms: UniformMap): void;
protected resized(): void {
super.resized();
@ -500,14 +501,13 @@ export abstract class DemoView extends PathfinderView {
// Draw direct interior parts.
this.setTransformUniform(directInteriorProgram.uniforms, objectIndex);
this.setFramebufferSizeUniform(directInteriorProgram.uniforms);
this.setHintsUniform(directInteriorProgram.uniforms);
this.pathColorsBufferTextures[objectIndex].bind(this.gl,
directInteriorProgram.uniforms,
0);
this.pathTransformBufferTextures[objectIndex].bind(this.gl,
directInteriorProgram.uniforms,
1);
if (this.pathHintsBufferTexture != null)
this.pathHintsBufferTexture.bind(this.gl, directInteriorProgram.uniforms, 2);
let indexCount = this.gl.getBufferParameter(this.gl.ELEMENT_ARRAY_BUFFER,
this.gl.BUFFER_SIZE) / UINT32_SIZE;
if (instanceCount == null) {
@ -538,14 +538,13 @@ export abstract class DemoView extends PathfinderView {
// Draw direct curve parts.
this.setTransformUniform(directCurveProgram.uniforms, objectIndex);
this.setFramebufferSizeUniform(directCurveProgram.uniforms);
this.setHintsUniform(directInteriorProgram.uniforms);
this.pathColorsBufferTextures[objectIndex].bind(this.gl,
directCurveProgram.uniforms,
0);
this.pathTransformBufferTextures[objectIndex].bind(this.gl,
directCurveProgram.uniforms,
1);
if (this.pathHintsBufferTexture != null)
this.pathHintsBufferTexture.bind(this.gl, directCurveProgram.uniforms, 2);
indexCount = this.gl.getBufferParameter(this.gl.ELEMENT_ARRAY_BUFFER,
this.gl.BUFFER_SIZE) / UINT32_SIZE;
if (instanceCount == null) {

View File

@ -11,12 +11,11 @@
precision highp float;
uniform mat4 uTransform;
uniform vec4 uHints;
uniform ivec2 uPathColorsDimensions;
uniform ivec2 uPathTransformDimensions;
uniform ivec2 uPathHintsDimensions;
uniform sampler2D uPathColors;
uniform sampler2D uPathTransform;
uniform sampler2D uPathHints;
attribute vec2 aPosition;
attribute vec2 aTexCoord;
@ -31,10 +30,9 @@ varying float vSign;
void main() {
int pathID = int(aPathID);
vec4 pathHints = fetchFloat4Data(uPathHints, pathID, uPathHintsDimensions);
vec4 pathTransform = fetchFloat4Data(uPathTransform, pathID, uPathTransformDimensions);
vec2 position = hintPosition(aPosition, pathHints);
vec2 position = hintPosition(aPosition, uHints);
position = transformVertexPositionST(position, pathTransform);
position = transformVertexPosition(position, uTransform);

View File

@ -11,12 +11,11 @@
precision highp float;
uniform mat4 uTransform;
uniform vec4 uHints;
uniform ivec2 uPathColorsDimensions;
uniform ivec2 uPathTransformDimensions;
uniform ivec2 uPathHintsDimensions;
uniform sampler2D uPathColors;
uniform sampler2D uPathTransform;
uniform sampler2D uPathHints;
attribute vec2 aPosition;
attribute float aPathID;
@ -27,10 +26,9 @@ varying vec2 vPathID;
void main() {
int pathID = int(aPathID);
vec4 pathHints = fetchFloat4Data(uPathHints, pathID, uPathHintsDimensions);
vec4 pathTransform = fetchFloat4Data(uPathTransform, pathID, uPathTransformDimensions);
vec2 position = hintPosition(aPosition, pathHints);
vec2 position = hintPosition(aPosition, uHints);
position = transformVertexPositionST(position, pathTransform);
position = transformVertexPosition(position, uTransform);

View File

@ -11,15 +11,14 @@
precision highp float;
uniform vec4 uTransformST;
uniform vec4 uHints;
uniform ivec2 uFramebufferSize;
uniform ivec2 uBVertexPositionDimensions;
uniform ivec2 uBVertexPathIDDimensions;
uniform ivec2 uPathTransformDimensions;
uniform ivec2 uPathHintsDimensions;
uniform sampler2D uBVertexPosition;
uniform sampler2D uBVertexPathID;
uniform sampler2D uPathTransform;
uniform sampler2D uPathHints;
attribute vec2 aQuadPosition;
attribute vec4 aUpperPointIndices;
@ -51,11 +50,10 @@ void main() {
int pathID = fetchUInt16Data(uBVertexPathID, pointIndices.x, uBVertexPathIDDimensions);
vec4 hints = fetchFloat4Data(uPathHints, pathID, uPathHintsDimensions);
vec4 transform = fetchFloat4Data(uPathTransform, pathID, uPathTransformDimensions);
upperLeftPosition = hintPosition(upperLeftPosition, hints);
lowerRightPosition = hintPosition(lowerRightPosition, hints);
upperLeftPosition = hintPosition(upperLeftPosition, uHints);
lowerRightPosition = hintPosition(lowerRightPosition, uHints);
upperLeftPosition = transformVertexPositionST(upperLeftPosition, transform);
lowerRightPosition = transformVertexPositionST(lowerRightPosition, transform);

View File

@ -11,15 +11,14 @@
precision highp float;
uniform vec4 uTransformST;
uniform vec4 uHints;
uniform ivec2 uFramebufferSize;
uniform ivec2 uBVertexPositionDimensions;
uniform ivec2 uBVertexPathIDDimensions;
uniform ivec2 uPathTransformDimensions;
uniform ivec2 uPathHintsDimensions;
uniform sampler2D uBVertexPosition;
uniform sampler2D uBVertexPathID;
uniform sampler2D uPathTransform;
uniform sampler2D uPathHints;
uniform bool uLowerPart;
attribute vec2 aQuadPosition;
@ -46,7 +45,6 @@ void main() {
int pathID = fetchUInt16Data(uBVertexPathID, pointIndices.x, uBVertexPathIDDimensions);
vec4 hints = fetchFloat4Data(uPathHints, pathID, uPathHintsDimensions);
vec4 transform = fetchFloat4Data(uPathTransform, pathID, uPathTransformDimensions);
// Transform the points, and compute the position of this vertex.
@ -58,8 +56,8 @@ void main() {
uFramebufferSize,
transform,
uTransformST,
hints)) {
controlPointPosition = hintPosition(controlPointPosition, hints);
uHints)) {
controlPointPosition = hintPosition(controlPointPosition, uHints);
controlPointPosition = transformVertexPositionST(controlPointPosition, transform);
controlPointPosition = transformVertexPositionST(controlPointPosition, uTransformST);
controlPointPosition = convertClipToScreenSpace(controlPointPosition, uFramebufferSize);

View File

@ -11,15 +11,14 @@
precision highp float;
uniform vec4 uTransformST;
uniform vec4 uHints;
uniform ivec2 uFramebufferSize;
uniform ivec2 uBVertexPositionDimensions;
uniform ivec2 uBVertexPathIDDimensions;
uniform ivec2 uPathTransformDimensions;
uniform ivec2 uPathHintsDimensions;
uniform sampler2D uBVertexPosition;
uniform sampler2D uBVertexPathID;
uniform sampler2D uPathTransform;
uniform sampler2D uPathHints;
uniform bool uLowerPart;
attribute vec2 aQuadPosition;
@ -40,7 +39,6 @@ void main() {
int pathID = fetchUInt16Data(uBVertexPathID, pointIndices.x, uBVertexPathIDDimensions);
vec4 hints = fetchFloat4Data(uPathHints, pathID, uPathHintsDimensions);
vec4 transform = fetchFloat4Data(uPathTransform, pathID, uPathTransformDimensions);
// Transform the points, and compute the position of this vertex.
@ -52,7 +50,7 @@ void main() {
uFramebufferSize,
transform,
uTransformST,
hints);
uHints);
float depth = convertPathIndexToViewportDepthValue(pathID);