浏览代码

compute buffer setup - static Compute Buffer

/main
xingwei.zhu 6 年前
当前提交
ea0b2800
共有 4 个文件被更改,包括 53 次插入62 次删除
  1. 54
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_computebuffer_utils.cs
  2. 52
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  3. 7
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs
  4. 2
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs

54
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_computebuffer_utils.cs


public Vector2 uv;
}
ComputeBuffer computeBuffer;
List<uiVertex> vertexes;
static ComputeBuffer computeBuffer;
static List<uiVertex> vertexes;
ComputeBuffer indexBuffer;
List<int> indexes;
static ComputeBuffer indexBuffer;
static List<int> indexes;
int startVertex;
int startIndex;
static int startVertex;
static int startIndex;
bool supportComputeBuffer;
void setupComputeBuffer() {
this.supportComputeBuffer = this._isMainCanvas && CanvasShader.supportComputeBuffer;
static bool supportComputeBuffer {
get { return CanvasShader.supportComputeBuffer; }
this.computeBuffer = new ComputeBuffer(1024 * 1024, stride);
this.vertexes = new List<uiVertex>();
computeBuffer = new ComputeBuffer(1024 * 1024, stride);
vertexes = new List<uiVertex>();
this.indexBuffer = new ComputeBuffer(1024 * 1024, Marshal.SizeOf(typeof(int)));
this.indexes = new List<int>();
indexBuffer = new ComputeBuffer(1024 * 1024, Marshal.SizeOf(typeof(int)));
indexes = new List<int>();
if (!this.supportComputeBuffer) return;
if (!supportComputeBuffer) return;
if (this.computeBuffer == null) {
if (computeBuffer == null) {
this.vertexes.Clear();
this.indexes.Clear();
this.startVertex = 0;
this.startIndex = 0;
vertexes.Clear();
indexes.Clear();
startVertex = 0;
startIndex = 0;
if (!this.supportComputeBuffer) return;
if (!supportComputeBuffer) return;
this.computeBuffer.SetData(this.vertexes);
this.indexBuffer.SetData(this.indexes);
computeBuffer.SetData(vertexes);
indexBuffer.SetData(indexes);
if (!this.supportComputeBuffer) return;
if (!supportComputeBuffer) return;
this.startVertex = this.vertexes.Count;
this.startIndex = this.indexes.Count;
startVertex = vertexes.Count;
startIndex = indexes.Count;
this.vertexes.Add(new uiVertex {
vertexes.Add(new uiVertex {
position = new Vector2(vertex[i].x, vertex[i].y),
uv = hasUv ? uv[i] : Vector2.zero
});

this.indexes.Add(triangleId + this.startVertex);
indexes.Add(triangleId + startVertex);
}
}

52
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs


this.___drawTextDrawMeshCallback = this._drawTextDrawMeshCallback;
this.___drawPathDrawMeshCallback2 = this._drawPathDrawMeshCallback2;
this.___drawPathDrawMeshCallback = this._drawPathDrawMeshCallback;
this.setupComputeBuffer();
}
readonly _drawPathDrawMeshCallbackDelegate ___drawTextDrawMeshCallback;

this._saveLayer_Points[2],
this._saveLayer_Points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer, this.supportComputeBuffer);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer, supportComputeBuffer);
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer, supportComputeBuffer));
}
}
else if (paint.backdrop is _MatrixImageFilter) {

this._saveLayer_Points[2],
this._saveLayer_Points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer, this.supportComputeBuffer);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer, supportComputeBuffer);
layer.draws.Add(renderDraw);
}
}

return;
}
var renderDraw = CanvasShader.texRT(currentLayer, layer.layerPaint.Value, mesh, layer, this.supportComputeBuffer);
var renderDraw = CanvasShader.texRT(currentLayer, layer.layerPaint.Value, mesh, layer, supportComputeBuffer);
currentLayer.draws.Add(renderDraw);
}

// need to inflate a bit to make sure all area is cleared.
var inflatedScissor = uiRectHelper.inflate(reducedClip.scissor.Value, this._fringeWidth);
var boundsMesh = uiMeshMesh.create(inflatedScissor);
layer.draws.Add(CanvasShader.stencilClear(layer, boundsMesh, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.stencilClear(layer, boundsMesh, supportComputeBuffer));
layer.draws.Add(CanvasShader.stencil0(layer, maskElement.mesh.duplicate(), this.supportComputeBuffer));
layer.draws.Add(CanvasShader.stencil1(layer, boundsMesh.duplicate(), this.supportComputeBuffer));
layer.draws.Add(CanvasShader.stencil0(layer, maskElement.mesh.duplicate(), supportComputeBuffer));
layer.draws.Add(CanvasShader.stencil1(layer, boundsMesh.duplicate(), supportComputeBuffer));
}
}

blurXLayer.draws.Add(CanvasShader.maskFilter(
blurXLayer, blurMesh, maskLayer,
radiusX, new Vector2(1f / textureWidth, 0), kernelX, this.supportComputeBuffer));
radiusX, new Vector2(1f / textureWidth, 0), kernelX, supportComputeBuffer));
radiusY, new Vector2(0, -1f / textureHeight), kernelY, this.supportComputeBuffer));
radiusY, new Vector2(0, -1f / textureHeight), kernelY, supportComputeBuffer));
return blurYLayer;
}

return;
}
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer, supportComputeBuffer));
}
delegate void _drawPathDrawMeshCallbackDelegate(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh,

var layer = this._currentLayer;
if (convex) {
layer.draws.Add(CanvasShader.convexFill(layer, p, fillMesh, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.convexFill(layer, p, fillMesh, supportComputeBuffer));
layer.draws.Add(CanvasShader.fill0(layer, fillMesh, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.fill1(layer, p, fillMesh.boundsMesh, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.fill0(layer, fillMesh, supportComputeBuffer));
layer.draws.Add(CanvasShader.fill1(layer, p, fillMesh.boundsMesh, supportComputeBuffer));
layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate(), this.supportComputeBuffer));
layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh, supportComputeBuffer));
layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate(), supportComputeBuffer));
}
}

var layer = this._currentLayer;
layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate(), this.supportComputeBuffer));
layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh, supportComputeBuffer));
layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate(), supportComputeBuffer));
}
void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha,

var layer = this._currentLayer;
if (notEmoji) {
layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex, supportComputeBuffer));
}
else {
uiPaint paintWithWhite = new uiPaint(p);

var raw_mesh = textMesh.resolveMesh();
var meshmesh = raw_mesh.duplicate();
ObjectPool<TextBlobMesh>.release(textMesh);
layer.draws.Add(CanvasShader.tex(layer, paintWithWhite, meshmesh, EmojiUtils.image, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.tex(layer, paintWithWhite, meshmesh, EmojiUtils.image, supportComputeBuffer));
}
}

return;
}
layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image, supportComputeBuffer));
}
void _drawImageNine(Image image, uiRect? src, uiRect center, uiRect dst, uiPaint paint) {

return;
}
layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image, supportComputeBuffer));
}

}
D.assert(mesh.vertices.Count > 0);
if (this.supportComputeBuffer) {
if (supportComputeBuffer) {
cmd.properties.SetBuffer(CmdDraw.vertexBufferId, this.computeBuffer);
cmd.properties.SetBuffer(CmdDraw.indexBufferId, this.indexBuffer);
cmd.properties.SetInt(CmdDraw.startIndexId, this.startIndex);
cmd.properties.SetBuffer(CmdDraw.vertexBufferId, computeBuffer);
cmd.properties.SetBuffer(CmdDraw.indexBufferId, indexBuffer);
cmd.properties.SetInt(CmdDraw.startIndexId, startIndex);
cmdBuf.DrawProcedural(Matrix4x4.identity, cmd.material, cmd.pass, MeshTopology.Triangles, mesh.triangles.Count, 1, cmd.properties.mpb);
}
else {

7
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs


public static readonly bool supportComputeBuffer;
public static Shader rshadowShader;
public static Shader rrshadowShader;
static CanvasShader() {
var convexFillShader = GetShader("UIWidgets/canvas_convexFill");
var fill0Shader = GetShader("UIWidgets/canvas_fill0");

var shadowRBoxShaderCompute = GetShader("UIWidgets/ShadowRBox_cb");
var strokeAlphaShaderCompute = GetShader("UIWidgets/canvas_strokeAlpha_cb");
rshadowShader = shadowBoxShader;
rrshadowShader = shadowRBoxShader;
_convexFillMat = new MaterialByBlendModeStencilComp(convexFillShader);
_fill0Mat = new MaterialByStencilComp(fill0Shader);
_fill1Mat = new MaterialByBlendMode(fill1Shader);

_shadowBox_cb = new Material(shadowBoxShaderCompute) {hideFlags = HideFlags.HideAndDontSave};
_shadowRBox_cb = new Material(shadowRBoxShaderCompute) {hideFlags = HideFlags.HideAndDontSave};
//check compute buffer support
supportComputeBuffer = convexFillShaderCompute.isSupported;
}

2
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs


ObjectPool<uiMeshMesh>.release(meshBounds);
ObjectPool<uiMeshMesh>.release(blurMesh);
var mesh = uiMeshMesh.create(state.matrix, vertices, _triangles);
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, sigma, path.isRect, path.isCircle, path.rRectCorner, new Vector4(bound.left, bound.top, bound.right, bound.bottom), paint.color, this.supportComputeBuffer));
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, sigma, path.isRect, path.isCircle, path.rRectCorner, new Vector4(bound.left, bound.top, bound.right, bound.bottom), paint.color, supportComputeBuffer));
}
}
正在加载...
取消
保存