浏览代码

refine the logic on supportComputeBuffer check

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

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


static int _instanceNum;
public static bool enableComputeBuffer = true;
public static bool supportComputeBuffer {
get { return SystemInfo.supportsComputeShaders && CanvasShader.supportComputeBuffer && enableComputeBuffer; }
}
if (!supportComputeBuffer) {
if (!CanvasShader.supportComputeBuffer) {
return;
}

}
void resetComputeBuffer() {
if (!supportComputeBuffer) return;
if (!CanvasShader.supportComputeBuffer) return;
if (_computeBuffer == null) {
this.initComputeBuffer();

}
void bindComputeBuffer() {
if (!supportComputeBuffer) return;
if (!CanvasShader.supportComputeBuffer) return;
_computeBuffer.SetData(_vertices);
_indexBuffer.SetData(_indices);

if (!supportComputeBuffer) return;
if (!CanvasShader.supportComputeBuffer) return;
_startVertex = _vertices.Count;
_startIndex = _indices.Count;

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


this._saveLayer_Points[2],
this._saveLayer_Points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer, supportComputeBuffer);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer, supportComputeBuffer));
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
}
}
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, supportComputeBuffer);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
layer.draws.Add(renderDraw);
}
}

return;
}
var renderDraw = CanvasShader.texRT(currentLayer, layer.layerPaint.Value, mesh, layer, supportComputeBuffer);
var renderDraw = CanvasShader.texRT(currentLayer, layer.layerPaint.Value, mesh, layer);
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, supportComputeBuffer));
layer.draws.Add(CanvasShader.stencilClear(layer, boundsMesh));
layer.draws.Add(CanvasShader.stencil0(layer, maskElement.mesh.duplicate(), supportComputeBuffer));
layer.draws.Add(CanvasShader.stencil1(layer, boundsMesh.duplicate(), supportComputeBuffer));
layer.draws.Add(CanvasShader.stencil0(layer, maskElement.mesh.duplicate()));
layer.draws.Add(CanvasShader.stencil1(layer, boundsMesh.duplicate()));
}
}

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

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

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

var layer = this._currentLayer;
layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh, supportComputeBuffer));
layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate(), supportComputeBuffer));
layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh));
layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate()));
}
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, supportComputeBuffer));
layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex));
}
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, supportComputeBuffer));
layer.draws.Add(CanvasShader.tex(layer, paintWithWhite, meshmesh, EmojiUtils.image));
}
}

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

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

}
D.assert(mesh.vertices.Count > 0);
if (supportComputeBuffer) {
if (CanvasShader.supportComputeBuffer) {
this.addMeshToComputeBuffer(mesh.vertices?.data, mesh.uv?.data, mesh.triangles?.data);
cmd.properties.SetBuffer(CmdDraw.vertexBufferId, _computeBuffer);
cmd.properties.SetBuffer(CmdDraw.indexBufferId, _indexBuffer);

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


return shader;
}
public static bool enableComputeBuffer = true;
supportComputeBuffer = convexFillShaderCompute.isSupported;
supportComputeBuffer = enableComputeBuffer && SystemInfo.supportsComputeShaders && convexFillShaderCompute.isSupported;
//if compute buffer is not supported, load normal shaders
if (!PictureFlusher.supportComputeBuffer) {
//if compute buffer is not supported, load normal shader
if (!supportComputeBuffer) {
var convexFillShader = GetShader("UIWidgets/canvas_convexFill");
var fill0Shader = GetShader("UIWidgets/canvas_fill0");
var fill1Shader = GetShader("UIWidgets/canvas_fill1");

}
public static PictureFlusher.CmdDraw convexFill(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh, bool supportComputeBuffer) {
uiMeshMesh mesh) {
var mat = supportComputeBuffer ? _convexFillMat_cb.getMaterial(paint.blendMode, layer.ignoreClip) : _convexFillMat.getMaterial(paint.blendMode, layer.ignoreClip);
_getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, 0.0f, out var pass, out var props);

);
}
public static PictureFlusher.CmdDraw fill0(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, bool supportComputeBuffer) {
public static PictureFlusher.CmdDraw fill0(PictureFlusher.RenderLayer layer, uiMeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = supportComputeBuffer ? _fill0Mat_cb.getMaterial(layer.ignoreClip) : _fill0Mat.getMaterial(layer.ignoreClip);

}
public static PictureFlusher.CmdDraw fill1(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh, bool supportComputeBuffer) {
uiMeshMesh mesh) {
var mat = supportComputeBuffer
? _fill1Mat_cb.getMaterial(paint.blendMode)
: _fill1Mat.getMaterial(paint.blendMode);

}
public static PictureFlusher.CmdDraw stroke0(PictureFlusher.RenderLayer layer, uiPaint paint,
float alpha, uiMeshMesh mesh, bool supportComputeBuffer) {
float alpha, uiMeshMesh mesh) {
var mat = supportComputeBuffer
? _stroke0Mat_cb.getMaterial(paint.blendMode, layer.ignoreClip)
: _stroke0Mat.getMaterial(paint.blendMode, layer.ignoreClip);

);
}
public static PictureFlusher.CmdDraw stroke1(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, bool supportComputeBuffer) {
public static PictureFlusher.CmdDraw stroke1(PictureFlusher.RenderLayer layer, uiMeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = supportComputeBuffer ? _stroke1Mat_cb : _stroke1Mat;

);
}
public static PictureFlusher.CmdDraw strokeAlpha(PictureFlusher.RenderLayer layer, uiPaint paint, float alpha, float strokeMult, uiMeshMesh mesh, bool supportComputeBuffer) {
public static PictureFlusher.CmdDraw strokeAlpha(PictureFlusher.RenderLayer layer, uiPaint paint, float alpha, float strokeMult, uiMeshMesh mesh) {
var mat = supportComputeBuffer
? _strokeAlphaMat_cb.getMaterial(paint.blendMode, layer.ignoreClip)
: _strokeAlphaMat.getMaterial(paint.blendMode, layer.ignoreClip);

}
public static PictureFlusher.CmdDraw stencilClear(
PictureFlusher.RenderLayer layer, uiMeshMesh mesh, bool supportComputeBuffer) {
PictureFlusher.RenderLayer layer, uiMeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = supportComputeBuffer ? _stencilMat_cb : _stencilMat;

);
}
public static PictureFlusher.CmdDraw stencil0(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, bool supportComputeBuffer) {
public static PictureFlusher.CmdDraw stencil0(PictureFlusher.RenderLayer layer, uiMeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = supportComputeBuffer ? _stencilMat_cb : _stencilMat;

);
}
public static PictureFlusher.CmdDraw stencil1(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, bool supportComputeBuffer) {
public static PictureFlusher.CmdDraw stencil1(PictureFlusher.RenderLayer layer, uiMeshMesh mesh) {
Vector4 viewport = layer.viewport;
var mat = supportComputeBuffer ? _stencilMat_cb : _stencilMat;

}
public static PictureFlusher.CmdDraw tex(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh, Image image, bool supportComputeBuffer) {
uiMeshMesh mesh, Image image) {
var mat = supportComputeBuffer
? _texMat_cb.getMaterial(paint.blendMode, layer.ignoreClip)
: _texMat.getMaterial(paint.blendMode, layer.ignoreClip);

}
public static PictureFlusher.CmdDraw texRT(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh, PictureFlusher.RenderLayer renderLayer, bool supportComputeBuffer) {
uiMeshMesh mesh, PictureFlusher.RenderLayer renderLayer) {
var mat = supportComputeBuffer
? _texMat_cb.getMaterial(paint.blendMode, layer.ignoreClip)
: _texMat.getMaterial(paint.blendMode, layer.ignoreClip);

}
public static PictureFlusher.CmdDraw texAlpha(PictureFlusher.RenderLayer layer, uiPaint paint,
uiMeshMesh mesh, Texture tex, bool supportComputeBuffer) {
return texAlpha(layer, paint, mesh, null, tex, supportComputeBuffer);
uiMeshMesh mesh, Texture tex) {
return texAlpha(layer, paint, mesh, null, tex);
TextBlobMesh textMesh, Texture tex, bool supportComputeBuffer) {
return texAlpha(layer, paint, null, textMesh, tex, supportComputeBuffer);
TextBlobMesh textMesh, Texture tex) {
return texAlpha(layer, paint, null, textMesh, tex);
uiMeshMesh mesh, TextBlobMesh textMesh, Texture tex, bool supportComputeBuffer) {
uiMeshMesh mesh, TextBlobMesh textMesh, Texture tex) {
var mat = supportComputeBuffer
?_texMat_cb.getMaterial(paint.blendMode, layer.ignoreClip)
:_texMat.getMaterial(paint.blendMode, layer.ignoreClip);

}
public static PictureFlusher.CmdDraw maskFilter(PictureFlusher.RenderLayer layer, uiMeshMesh mesh,
PictureFlusher.RenderLayer renderLayer, float radius, Vector2 imgInc, float[] kernel, bool supportComputeBuffer) {
PictureFlusher.RenderLayer renderLayer, float radius, Vector2 imgInc, float[] kernel) {
Vector4 viewport = layer.viewport;
var mat = supportComputeBuffer ? _filterMat_cb : _filterMat;

}
public static PictureFlusher.CmdDraw fastShadow(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, float sigma,
bool isRect, bool isCircle, float corner, Vector4 bound, uiColor color, bool supportComputeBuffer) {
bool isRect, bool isCircle, float corner, Vector4 bound, uiColor color) {
Vector4 viewport = layer.viewport;
var mat = supportComputeBuffer ? _shadowBox_cb : _shadowBox;
if (!isRect) {

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, 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));
}
}
正在加载...
取消
保存