[graphite] Add ExtractRenderStepData
This doesn't reuse memory w/in the gatherer but sets us up to do so. Bug: skia:12701 Change-Id: If5ed962e73609b113581ed2bd681e872fe3214c0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/526029 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
ee9ecfa478
commit
0ec0c38e2e
@ -122,7 +122,9 @@ generated_cc_atom(
|
||||
":ContextUtils_hdr",
|
||||
":PaintParams_hdr",
|
||||
":RecorderPriv_hdr",
|
||||
":Renderer_hdr",
|
||||
":ResourceProvider_hdr",
|
||||
":UniformManager_hdr",
|
||||
"//include/private:SkUniquePaintParamsID_hdr",
|
||||
"//src/core:SkBlenderBase_hdr",
|
||||
"//src/core:SkKeyContext_hdr",
|
||||
|
@ -10,7 +10,9 @@
|
||||
#include <string>
|
||||
#include "experimental/graphite/src/PaintParams.h"
|
||||
#include "experimental/graphite/src/RecorderPriv.h"
|
||||
#include "experimental/graphite/src/Renderer.h"
|
||||
#include "experimental/graphite/src/ResourceProvider.h"
|
||||
#include "experimental/graphite/src/UniformManager.h"
|
||||
#include "include/private/SkUniquePaintParamsID.h"
|
||||
#include "src/core/SkBlenderBase.h"
|
||||
#include "src/core/SkKeyContext.h"
|
||||
@ -47,4 +49,20 @@ ExtractPaintData(Recorder* recorder,
|
||||
return { entry->uniqueID(), uniformIndex, textureIndex };
|
||||
}
|
||||
|
||||
UniformDataCache::Index ExtractRenderStepData(UniformDataCache* geometryUniformDataCache,
|
||||
SkPipelineDataGatherer* gatherer,
|
||||
const RenderStep* step,
|
||||
const DrawGeometry& geometry) {
|
||||
SkDEBUGCODE(gatherer->checkReset());
|
||||
|
||||
// TODO: Get layout from the GPU
|
||||
step->writeUniforms(Layout::kMetal, geometry, gatherer);
|
||||
|
||||
UniformDataCache::Index uIndex = geometryUniformDataCache->insert(gatherer->uniformDataBlock());
|
||||
|
||||
gatherer->reset();
|
||||
|
||||
return uIndex;
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -16,8 +16,10 @@ class SkUniquePaintParamsID;
|
||||
|
||||
namespace skgpu {
|
||||
|
||||
class DrawGeometry;
|
||||
class PaintParams;
|
||||
class Recorder;
|
||||
class RenderStep;
|
||||
|
||||
std::tuple<SkUniquePaintParamsID, UniformDataCache::Index, TextureDataCache::Index>
|
||||
ExtractPaintData(Recorder*,
|
||||
@ -25,6 +27,11 @@ ExtractPaintData(Recorder*,
|
||||
SkPaintParamsKeyBuilder* builder,
|
||||
const PaintParams&);
|
||||
|
||||
UniformDataCache::Index ExtractRenderStepData(UniformDataCache* geometryUniformDataCache,
|
||||
SkPipelineDataGatherer* gatherer,
|
||||
const RenderStep* step,
|
||||
const DrawGeometry& geometry);
|
||||
|
||||
} // namespace skgpu
|
||||
|
||||
#endif // skgpu_ContextUtils_DEFINED
|
||||
|
@ -195,15 +195,6 @@ public:
|
||||
, fUniformDataCache(uniformDataCache) {
|
||||
}
|
||||
|
||||
UniformDataCache::Index addUniforms(const SkUniformDataBlock& uniformDataBlock) {
|
||||
if (uniformDataBlock.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
UniformDataCache::Index uIndex = fUniformDataCache->insert(uniformDataBlock);
|
||||
return this->addUniforms(uIndex);
|
||||
}
|
||||
|
||||
UniformDataCache::Index addUniforms(UniformDataCache::Index uIndex) {
|
||||
if (!uIndex.isValid()) {
|
||||
return {};
|
||||
@ -354,11 +345,12 @@ std::unique_ptr<DrawPass> DrawPass::Make(Recorder* recorder,
|
||||
|
||||
UniformDataCache::Index geometryUniformIndex;
|
||||
if (step->numUniforms() > 0) {
|
||||
// TODO: Get layout from the GPU
|
||||
auto uniforms = step->writeUniforms(Layout::kMetal, draw.fGeometry);
|
||||
|
||||
geometryUniformIndex = geometryUniformBindings.addUniforms(
|
||||
SkUniformDataBlock(std::move(uniforms)));
|
||||
UniformDataCache::Index uniformDataIndex;
|
||||
uniformDataIndex = ExtractRenderStepData(&geometryUniformDataCache,
|
||||
&gatherer,
|
||||
step,
|
||||
draw.fGeometry);
|
||||
geometryUniformIndex = geometryUniformBindings.addUniforms(uniformDataIndex);
|
||||
}
|
||||
|
||||
GraphicsPipelineDesc desc;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <vector>
|
||||
|
||||
enum class SkPathFillType;
|
||||
class SkPipelineDataGatherer;
|
||||
class SkUniformData;
|
||||
|
||||
namespace skgpu {
|
||||
@ -53,7 +54,9 @@ public:
|
||||
// nice if we could remember the offsets for the layout/gpu and reuse them across draws.
|
||||
// Similarly, it would be nice if this could write into reusable storage and then DrawPass or
|
||||
// UniformCache handles making an sk_sp if we need to assign a new unique ID to the uniform data
|
||||
virtual sk_sp<SkUniformData> writeUniforms(Layout layout, const DrawGeometry&) const = 0;
|
||||
virtual void writeUniforms(Layout layout,
|
||||
const DrawGeometry&,
|
||||
SkPipelineDataGatherer*) const = 0;
|
||||
|
||||
// Returns a name formatted as "Subclass[variant]", where "Subclass" matches the C++ class name
|
||||
// and variant is a unique term describing instance's specific configuration.
|
||||
|
@ -56,9 +56,10 @@ void CoverBoundsRenderStep::writeVertices(DrawWriter* writer, const DrawGeometry
|
||||
<< devPoints[2].x << devPoints[2].y << depth << devPoints[2].w;// BR
|
||||
}
|
||||
|
||||
sk_sp<SkUniformData> CoverBoundsRenderStep::writeUniforms(Layout, const DrawGeometry&) const {
|
||||
void CoverBoundsRenderStep::writeUniforms(Layout,
|
||||
const DrawGeometry&,
|
||||
SkPipelineDataGatherer*) const {
|
||||
// Control points are pre-transformed to device space on the CPU, so no uniforms needed.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
|
||||
const char* vertexSkSL() const override;
|
||||
void writeVertices(DrawWriter*, const DrawGeometry&) const override;
|
||||
sk_sp<SkUniformData> writeUniforms(Layout, const DrawGeometry&) const override;
|
||||
void writeUniforms(Layout, const DrawGeometry&, SkPipelineDataGatherer*) const override;
|
||||
|
||||
private:
|
||||
const bool fInverseFill;
|
||||
|
@ -60,9 +60,10 @@ void MiddleOutFanRenderStep::writeVertices(DrawWriter* writer, const DrawGeometr
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<SkUniformData> MiddleOutFanRenderStep::writeUniforms(Layout, const DrawGeometry&) const {
|
||||
void MiddleOutFanRenderStep::writeUniforms(Layout,
|
||||
const DrawGeometry&,
|
||||
SkPipelineDataGatherer*) const {
|
||||
// Control points are pre-transformed to device space on the CPU, so no uniforms needed.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
|
||||
const char* vertexSkSL() const override;
|
||||
void writeVertices(DrawWriter*, const DrawGeometry&) const override;
|
||||
sk_sp<SkUniformData> writeUniforms(Layout, const DrawGeometry&) const override;
|
||||
void writeUniforms(Layout, const DrawGeometry&, SkPipelineDataGatherer*) const override;
|
||||
};
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -206,9 +206,10 @@ void TessellateCurvesRenderStep::writeVertices(DrawWriter* dw, const DrawGeometr
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<SkUniformData> TessellateCurvesRenderStep::writeUniforms(Layout, const DrawGeometry&) const {
|
||||
void TessellateCurvesRenderStep::writeUniforms(Layout,
|
||||
const DrawGeometry&,
|
||||
SkPipelineDataGatherer*) const {
|
||||
// Control points are pre-transformed to device space on the CPU, so no uniforms needed.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
|
||||
const char* vertexSkSL() const override;
|
||||
void writeVertices(DrawWriter*, const DrawGeometry&) const override;
|
||||
sk_sp<SkUniformData> writeUniforms(Layout, const DrawGeometry&) const override;
|
||||
void writeUniforms(Layout, const DrawGeometry&, SkPipelineDataGatherer*) const override;
|
||||
};
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -241,9 +241,10 @@ void TessellateWedgesRenderStep::writeVertices(DrawWriter* dw, const DrawGeometr
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<SkUniformData> TessellateWedgesRenderStep::writeUniforms(Layout, const DrawGeometry&) const {
|
||||
void TessellateWedgesRenderStep::writeUniforms(Layout,
|
||||
const DrawGeometry&,
|
||||
SkPipelineDataGatherer*) const {
|
||||
// Control points are pre-transformed to device space on the CPU, so no uniforms needed.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace skgpu
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
|
||||
const char* vertexSkSL() const override;
|
||||
void writeVertices(DrawWriter*, const DrawGeometry&) const override;
|
||||
sk_sp<SkUniformData> writeUniforms(Layout, const DrawGeometry&) const override;
|
||||
void writeUniforms(Layout, const DrawGeometry&, SkPipelineDataGatherer*) const override;
|
||||
|
||||
};
|
||||
|
||||
|
@ -74,16 +74,18 @@ public:
|
||||
writer->draw({}, 4);
|
||||
}
|
||||
|
||||
sk_sp<SkUniformData> writeUniforms(Layout layout, const DrawGeometry& geom) const override {
|
||||
void writeUniforms(Layout layout,
|
||||
const DrawGeometry& geom,
|
||||
SkPipelineDataGatherer* gatherer) const override {
|
||||
SkASSERT(geom.shape().isRect());
|
||||
// TODO: A << API for uniforms would be nice, particularly if it could take pre-computed
|
||||
// offsets for each uniform.
|
||||
auto uniforms = SkUniformData::Make(this->uniforms(), sizeof(float) * 4);
|
||||
sk_sp<SkUniformData> uniforms = SkUniformData::Make(this->uniforms(), sizeof(float) * 4);
|
||||
float2 scale = geom.shape().rect().size();
|
||||
float2 translate = geom.shape().rect().topLeft();
|
||||
memcpy(uniforms->data(), &scale, sizeof(float2));
|
||||
memcpy(uniforms->data() + sizeof(float2), &translate, sizeof(float2));
|
||||
return uniforms;
|
||||
gatherer->add(std::move(uniforms));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -133,11 +135,13 @@ public:
|
||||
writer->drawIndexed(vertices, indices, 6);
|
||||
}
|
||||
|
||||
sk_sp<SkUniformData> writeUniforms(Layout layout, const DrawGeometry&) const override {
|
||||
auto uniforms = SkUniformData::Make(this->uniforms(), sizeof(float) * 4);
|
||||
void writeUniforms(Layout layout,
|
||||
const DrawGeometry&,
|
||||
SkPipelineDataGatherer* gatherer) const override {
|
||||
sk_sp<SkUniformData> uniforms = SkUniformData::Make(this->uniforms(), sizeof(float) * 4);
|
||||
float data[4] = {2.f, 2.f, -1.f, -1.f};
|
||||
memcpy(uniforms->data(), data, 4 * sizeof(float));
|
||||
return uniforms;
|
||||
gatherer->add(std::move(uniforms));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -183,9 +187,7 @@ public:
|
||||
instances.append(1) << geom.shape().rect().topLeft() << geom.shape().rect().size();
|
||||
}
|
||||
|
||||
sk_sp<SkUniformData> writeUniforms(Layout, const DrawGeometry&) const override {
|
||||
return nullptr;
|
||||
}
|
||||
void writeUniforms(Layout, const DrawGeometry&, SkPipelineDataGatherer*) const override { }
|
||||
|
||||
private:
|
||||
InstanceRectDraw()
|
||||
@ -288,6 +290,8 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) {
|
||||
SkColor4f fColor;
|
||||
};
|
||||
|
||||
SkPipelineDataGatherer gatherer;
|
||||
|
||||
auto draw = [&](const RenderStep* step, std::vector<RectAndColor> draws) {
|
||||
GraphicsPipelineDesc pipelineDesc;
|
||||
pipelineDesc.setProgram(step, uniqueID);
|
||||
@ -312,15 +316,20 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) {
|
||||
DrawOrder order(depth);
|
||||
DrawGeometry geom{kIdentity, shape, {shape.bounds(), kBounds}, order, nullptr};
|
||||
|
||||
auto renderStepUniforms = step->writeUniforms(Layout::kMetal, geom);
|
||||
if (renderStepUniforms) {
|
||||
SkDEBUGCODE(gatherer.checkReset());
|
||||
step->writeUniforms(Layout::kMetal, geom, &gatherer);
|
||||
if (gatherer.hasUniforms()) {
|
||||
SkUniformDataBlock* renderStepUniforms = &gatherer.uniformDataBlock();
|
||||
auto [writer, bindInfo] =
|
||||
bufferMgr.getUniformWriter(renderStepUniforms->dataSize());
|
||||
writer.write(renderStepUniforms->data(), renderStepUniforms->dataSize());
|
||||
bufferMgr.getUniformWriter(renderStepUniforms->totalUniformSize());
|
||||
for (const auto &u : *renderStepUniforms) {
|
||||
writer.write(u->data(), u->dataSize());
|
||||
}
|
||||
commandBuffer->bindUniformBuffer(UniformSlot::kRenderStep,
|
||||
sk_ref_sp(bindInfo.fBuffer),
|
||||
bindInfo.fOffset);
|
||||
}
|
||||
gatherer.reset();
|
||||
|
||||
// TODO: Rely on uniform writer and GetUniforms(kSolidColor).
|
||||
auto [writer, bindInfo] = bufferMgr.getUniformWriter(sizeof(SkColor4f));
|
||||
|
Loading…
Reference in New Issue
Block a user