Drafting a better SHape plumber to render the items

This commit is contained in:
Sam Gateau 2017-07-06 16:35:40 +02:00
parent d91516c630
commit 53ffca796f
5 changed files with 39 additions and 17 deletions

View file

@ -345,7 +345,7 @@ public:
// Don't actually crash in debug builds, in case this apparent deadlock is simply from
// the developer actively debugging code
#ifdef NDEBUG
deadlockDetectionCrash();
// deadlockDetectionCrash();
#endif
}
}

View file

@ -459,7 +459,8 @@ _nextID(0) {
// Set the defaults needed for a simple program
batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO,
DependencyManager::get<TextureCache>()->getWhiteTexture());
}
},
nullptr
);
GeometryCache::_simpleTransparentPipeline =
std::make_shared<render::ShapePipeline>(getSimplePipeline(false, true, true, false), nullptr,
@ -467,11 +468,13 @@ _nextID(0) {
// Set the defaults needed for a simple program
batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO,
DependencyManager::get<TextureCache>()->getWhiteTexture());
}
},
nullptr
);
GeometryCache::_simpleWirePipeline =
std::make_shared<render::ShapePipeline>(getSimplePipeline(false, false, true, true), nullptr,
[](const render::ShapePipeline&, gpu::Batch& batch) {});
[](const render::ShapePipeline&, gpu::Batch& batch) {},
nullptr);
}
GeometryCache::~GeometryCache() {

View file

@ -45,6 +45,7 @@ void renderShape(RenderArgs* args, const ShapePlumberPointer& shapeContext, cons
if (key.isValid() && !key.hasOwnPipeline()) {
args->_pipeline = shapeContext->pickPipeline(args, key);
if (args->_pipeline) {
args->_pipeline->prepareShapeItem(args, key, item);
item.render(args);
}
args->_pipeline = nullptr;
@ -114,6 +115,7 @@ void render::renderStateSortShapes(const RenderContextPointer& renderContext,
continue;
}
for (auto& item : bucket) {
args->_pipeline->prepareShapeItem(args, pipelineKey, item);
item.render(args);
}
}

View file

@ -18,11 +18,18 @@
using namespace render;
void ShapePipeline::prepare(gpu::Batch& batch) {
if (batchSetter) {
batchSetter(*this, batch);
if (_batchSetter) {
_batchSetter(*this, batch);
}
}
void ShapePipeline::prepareShapeItem(RenderArgs* args, const ShapeKey& key, const Item& shape) {
if (_itemSetter) {
_itemSetter(*this, args, shape);
}
}
ShapeKey::Filter::Builder::Builder() {
_mask.set(OWN_PIPELINE);
_mask.set(INVALID);
@ -48,12 +55,12 @@ void ShapePlumber::addPipelineHelper(const Filter& filter, ShapeKey key, int bit
}
void ShapePlumber::addPipeline(const Key& key, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
BatchSetter batchSetter) {
addPipeline(Filter{key}, program, state, batchSetter);
BatchSetter batchSetter, ItemSetter itemSetter) {
addPipeline(Filter{key}, program, state, batchSetter, itemSetter);
}
void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
BatchSetter batchSetter) {
BatchSetter batchSetter, ItemSetter itemSetter) {
gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), Slot::BUFFER::LIGHTING_MODEL));
slotBindings.insert(gpu::Shader::Binding(std::string("skinClusterBuffer"), Slot::BUFFER::SKINNING));
@ -90,7 +97,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p
ShapeKey key{filter._flags};
auto gpuPipeline = gpu::Pipeline::create(program, state);
auto shapePipeline = std::make_shared<Pipeline>(gpuPipeline, locations, batchSetter);
auto shapePipeline = std::make_shared<Pipeline>(gpuPipeline, locations, batchSetter, itemSetter);
addPipelineHelper(filter, key, 0, shapePipeline);
}
@ -118,8 +125,8 @@ const ShapePipelinePointer ShapePlumber::pickPipeline(RenderArgs* args, const Ke
batch->setPipeline(shapePipeline->pipeline);
// Run the pipeline's BatchSetter on the passed in batch
if (shapePipeline->batchSetter) {
shapePipeline->batchSetter(*shapePipeline, *batch);
if (shapePipeline->_batchSetter) {
shapePipeline->_batchSetter(*shapePipeline, *batch);
}
return shapePipeline;

View file

@ -19,6 +19,7 @@
#include "Args.h"
namespace render {
class Item;
class ShapeKey {
public:
@ -242,8 +243,13 @@ public:
using BatchSetter = std::function<void(const ShapePipeline&, gpu::Batch&)>;
ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter) :
pipeline(pipeline), locations(locations), batchSetter(batchSetter) {}
using ItemSetter = std::function<void(const ShapePipeline&, render::Args*, const render::Item&)>;
ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter, ItemSetter itemSetter) :
pipeline(pipeline),
locations(locations),
_batchSetter(batchSetter),
_itemSetter(itemSetter) {}
// Normally, a pipeline is accessed thorugh pickPipeline. If it needs to be set manually,
// after calling setPipeline this method should be called to prepare the pipeline with default buffers.
@ -252,10 +258,13 @@ public:
gpu::PipelinePointer pipeline;
std::shared_ptr<Locations> locations;
void prepareShapeItem(Args* args, const ShapeKey& key, const Item& shape);
protected:
friend class ShapePlumber;
BatchSetter batchSetter;
BatchSetter _batchSetter;
ItemSetter _itemSetter;
};
using ShapePipelinePointer = std::shared_ptr<ShapePipeline>;
@ -270,11 +279,12 @@ public:
using Locations = Pipeline::Locations;
using LocationsPointer = Pipeline::LocationsPointer;
using BatchSetter = Pipeline::BatchSetter;
using ItemSetter = Pipeline::ItemSetter;
void addPipeline(const Key& key, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
BatchSetter batchSetter = nullptr);
BatchSetter batchSetter = nullptr, ItemSetter itemSetter = nullptr);
void addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
BatchSetter batchSetter = nullptr);
BatchSetter batchSetter = nullptr, ItemSetter itemSetter = nullptr);
const PipelinePointer pickPipeline(RenderArgs* args, const Key& key) const;