Commit 2e4f6e84 by Alexis Hetu Committed by Alexis Hétu

Start untangling sw::Context from the rendering code

Remove sw::Context members from the processor classes and removed many related functions. Also, the Renderer::draw() function now takes a const sw::Context object in, so it is no longer legal to modify sw::Context object within the Renderer::draw() function. Bug b/132280877 Change-Id: I890b5ba7db2306c02a96ec3e10496aa35c51bbe2 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/30950Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 7a60e31e
...@@ -242,29 +242,29 @@ namespace sw ...@@ -242,29 +242,29 @@ namespace sw
return modified; return modified;
} }
bool Context::depthWriteActive() bool Context::depthWriteActive() const
{ {
if(!depthBufferActive()) return false; if(!depthBufferActive()) return false;
return depthWriteEnable; return depthWriteEnable;
} }
bool Context::alphaTestActive() bool Context::alphaTestActive() const
{ {
return transparencyAntialiasing != TRANSPARENCY_NONE; return transparencyAntialiasing != TRANSPARENCY_NONE;
} }
bool Context::depthBufferActive() bool Context::depthBufferActive() const
{ {
return depthBuffer && depthBufferEnable; return depthBuffer && depthBufferEnable;
} }
bool Context::stencilActive() bool Context::stencilActive() const
{ {
return stencilBuffer && stencilEnable; return stencilBuffer && stencilEnable;
} }
bool Context::alphaBlendActive() bool Context::alphaBlendActive() const
{ {
if(!alphaBlendEnable) if(!alphaBlendEnable)
{ {
...@@ -282,7 +282,7 @@ namespace sw ...@@ -282,7 +282,7 @@ namespace sw
return colorBlend || alphaBlend; return colorBlend || alphaBlend;
} }
VkBlendFactor Context::sourceBlendFactor() VkBlendFactor Context::sourceBlendFactor() const
{ {
if(!alphaBlendEnable) return VK_BLEND_FACTOR_ONE; if(!alphaBlendEnable) return VK_BLEND_FACTOR_ONE;
...@@ -303,7 +303,7 @@ namespace sw ...@@ -303,7 +303,7 @@ namespace sw
return sourceBlendFactorState; return sourceBlendFactorState;
} }
VkBlendFactor Context::destBlendFactor() VkBlendFactor Context::destBlendFactor() const
{ {
if(!alphaBlendEnable) return VK_BLEND_FACTOR_ONE; if(!alphaBlendEnable) return VK_BLEND_FACTOR_ONE;
...@@ -324,7 +324,7 @@ namespace sw ...@@ -324,7 +324,7 @@ namespace sw
return destBlendFactorState; return destBlendFactorState;
} }
VkBlendOp Context::blendOperation() VkBlendOp Context::blendOperation() const
{ {
if(!alphaBlendEnable) return VK_BLEND_OP_SRC_EXT; if(!alphaBlendEnable) return VK_BLEND_OP_SRC_EXT;
...@@ -436,7 +436,7 @@ namespace sw ...@@ -436,7 +436,7 @@ namespace sw
return blendOperationState; return blendOperationState;
} }
VkBlendFactor Context::sourceBlendFactorAlpha() VkBlendFactor Context::sourceBlendFactorAlpha() const
{ {
if(!separateAlphaBlendEnable) if(!separateAlphaBlendEnable)
{ {
...@@ -462,7 +462,7 @@ namespace sw ...@@ -462,7 +462,7 @@ namespace sw
} }
} }
VkBlendFactor Context::destBlendFactorAlpha() VkBlendFactor Context::destBlendFactorAlpha() const
{ {
if(!separateAlphaBlendEnable) if(!separateAlphaBlendEnable)
{ {
...@@ -488,7 +488,7 @@ namespace sw ...@@ -488,7 +488,7 @@ namespace sw
} }
} }
VkBlendOp Context::blendOperationAlpha() VkBlendOp Context::blendOperationAlpha() const
{ {
if(!separateAlphaBlendEnable) if(!separateAlphaBlendEnable)
{ {
...@@ -605,7 +605,7 @@ namespace sw ...@@ -605,7 +605,7 @@ namespace sw
} }
} }
bool Context::perspectiveActive() bool Context::perspectiveActive() const
{ {
if(!colorUsed()) if(!colorUsed())
{ {
...@@ -625,7 +625,7 @@ namespace sw ...@@ -625,7 +625,7 @@ namespace sw
return true; return true;
} }
VkFormat Context::renderTargetInternalFormat(int index) VkFormat Context::renderTargetInternalFormat(int index) const
{ {
if(renderTarget[index]) if(renderTarget[index])
{ {
...@@ -637,7 +637,7 @@ namespace sw ...@@ -637,7 +637,7 @@ namespace sw
} }
} }
bool Context::colorWriteActive() bool Context::colorWriteActive() const
{ {
for (int i = 0; i < RENDERTARGETS; i++) for (int i = 0; i < RENDERTARGETS; i++)
{ {
...@@ -650,7 +650,7 @@ namespace sw ...@@ -650,7 +650,7 @@ namespace sw
return false; return false;
} }
int Context::colorWriteActive(int index) int Context::colorWriteActive(int index) const
{ {
if(!renderTarget[index] || renderTarget[index]->getFormat() == VK_FORMAT_UNDEFINED) if(!renderTarget[index] || renderTarget[index]->getFormat() == VK_FORMAT_UNDEFINED)
{ {
...@@ -666,7 +666,7 @@ namespace sw ...@@ -666,7 +666,7 @@ namespace sw
return colorWriteMask[index]; return colorWriteMask[index];
} }
bool Context::colorUsed() bool Context::colorUsed() const
{ {
return colorWriteActive() || alphaTestActive() || (pixelShader && pixelShader->getModes().ContainsKill); return colorWriteActive() || alphaTestActive() || (pixelShader && pixelShader->getModes().ContainsKill);
} }
......
...@@ -116,21 +116,21 @@ namespace sw ...@@ -116,21 +116,21 @@ namespace sw
bool setColorWriteMask(int index, int colorWriteMask); bool setColorWriteMask(int index, int colorWriteMask);
bool setWriteSRGB(bool sRGB); bool setWriteSRGB(bool sRGB);
bool depthWriteActive(); bool depthWriteActive() const;
bool alphaTestActive(); bool alphaTestActive() const;
bool depthBufferActive(); bool depthBufferActive() const;
bool stencilActive(); bool stencilActive() const;
bool perspectiveActive(); bool perspectiveActive() const;
bool alphaBlendActive(); bool alphaBlendActive() const;
VkBlendFactor sourceBlendFactor(); VkBlendFactor sourceBlendFactor() const;
VkBlendFactor destBlendFactor(); VkBlendFactor destBlendFactor() const;
VkBlendOp blendOperation(); VkBlendOp blendOperation() const;
VkBlendFactor sourceBlendFactorAlpha(); VkBlendFactor sourceBlendFactorAlpha() const;
VkBlendFactor destBlendFactorAlpha(); VkBlendFactor destBlendFactorAlpha() const;
VkBlendOp blendOperationAlpha(); VkBlendOp blendOperationAlpha() const;
VkPrimitiveTopology topology; VkPrimitiveTopology topology;
...@@ -146,10 +146,10 @@ namespace sw ...@@ -146,10 +146,10 @@ namespace sw
float depthBias; float depthBias;
float slopeDepthBias; float slopeDepthBias;
VkFormat renderTargetInternalFormat(int index); VkFormat renderTargetInternalFormat(int index) const;
bool colorWriteActive(); bool colorWriteActive() const;
int colorWriteActive(int index); int colorWriteActive(int index) const;
bool colorUsed(); bool colorUsed() const;
vk::DescriptorSet::Bindings descriptorSets = {}; vk::DescriptorSet::Bindings descriptorSets = {};
vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets = {}; vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets = {};
......
...@@ -57,7 +57,7 @@ namespace sw ...@@ -57,7 +57,7 @@ namespace sw
return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0; return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
} }
PixelProcessor::PixelProcessor(Context *context) : context(context) PixelProcessor::PixelProcessor()
{ {
routineCache = nullptr; routineCache = nullptr;
setRoutineCacheSize(1024); setRoutineCacheSize(1024);
...@@ -69,47 +69,6 @@ namespace sw ...@@ -69,47 +69,6 @@ namespace sw
routineCache = nullptr; routineCache = nullptr;
} }
void PixelProcessor::setRenderTarget(int index, vk::ImageView* renderTarget)
{
context->renderTarget[index] = renderTarget;
}
void PixelProcessor::setDepthBuffer(vk::ImageView *depthBuffer)
{
context->depthBuffer = depthBuffer;
}
void PixelProcessor::setStencilBuffer(vk::ImageView *stencilBuffer)
{
context->stencilBuffer = stencilBuffer;
}
void PixelProcessor::setDepthBufferEnable(bool depthBufferEnable)
{
context->setDepthBufferEnable(depthBufferEnable);
}
void PixelProcessor::setDepthCompare(VkCompareOp depthCompareMode)
{
context->depthCompareMode = depthCompareMode;
}
void PixelProcessor::setDepthWriteEnable(bool depthWriteEnable)
{
context->depthWriteEnable = depthWriteEnable;
}
void PixelProcessor::setCullMode(CullMode cullMode, bool frontFacingCCW)
{
context->cullMode = cullMode;
context->frontFacingCCW = frontFacingCCW;
}
void PixelProcessor::setColorWriteMask(int index, int rgbaMask)
{
context->setColorWriteMask(index, rgbaMask);
}
void PixelProcessor::setBlendConstant(const Color<float> &blendConstant) void PixelProcessor::setBlendConstant(const Color<float> &blendConstant)
{ {
// FIXME: Compact into generic function // FIXME: Clamp // FIXME: Compact into generic function // FIXME: Clamp
...@@ -205,63 +164,18 @@ namespace sw ...@@ -205,63 +164,18 @@ namespace sw
factor.invBlendConstant4F[3][3] = 1 - blendConstant.a; factor.invBlendConstant4F[3][3] = 1 - blendConstant.a;
} }
void PixelProcessor::setAlphaBlendEnable(bool alphaBlendEnable)
{
context->setAlphaBlendEnable(alphaBlendEnable);
}
void PixelProcessor::setSourceBlendFactor(VkBlendFactor sourceBlendFactor)
{
context->setSourceBlendFactor(sourceBlendFactor);
}
void PixelProcessor::setDestBlendFactor(VkBlendFactor destBlendFactor)
{
context->setDestBlendFactor(destBlendFactor);
}
void PixelProcessor::setBlendOperation(VkBlendOp blendOperation)
{
context->setBlendOperation(blendOperation);
}
void PixelProcessor::setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable)
{
context->setSeparateAlphaBlendEnable(separateAlphaBlendEnable);
}
void PixelProcessor::setSourceBlendFactorAlpha(VkBlendFactor sourceBlendFactorAlpha)
{
context->setSourceBlendFactorAlpha(sourceBlendFactorAlpha);
}
void PixelProcessor::setDestBlendFactorAlpha(VkBlendFactor destBlendFactorAlpha)
{
context->setDestBlendFactorAlpha(destBlendFactorAlpha);
}
void PixelProcessor::setBlendOperationAlpha(VkBlendOp blendOperationAlpha)
{
context->setBlendOperationAlpha(blendOperationAlpha);
}
void PixelProcessor::setPerspectiveCorrection(bool perspectiveEnable) void PixelProcessor::setPerspectiveCorrection(bool perspectiveEnable)
{ {
perspectiveCorrection = perspectiveEnable; perspectiveCorrection = perspectiveEnable;
} }
void PixelProcessor::setOcclusionEnabled(bool enable)
{
context->occlusionEnabled = enable;
}
void PixelProcessor::setRoutineCacheSize(int cacheSize) void PixelProcessor::setRoutineCacheSize(int cacheSize)
{ {
delete routineCache; delete routineCache;
routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536)); routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536));
} }
const PixelProcessor::State PixelProcessor::update() const const PixelProcessor::State PixelProcessor::update(const Context* context) const
{ {
State state; State state;
...@@ -330,13 +244,16 @@ namespace sw ...@@ -330,13 +244,16 @@ namespace sw
return state; return state;
} }
Routine *PixelProcessor::routine(const State &state) Routine *PixelProcessor::routine(const State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *pixelShader,
const vk::DescriptorSet::Bindings &descriptorSets)
{ {
Routine *routine = routineCache->query(state); Routine *routine = routineCache->query(state);
if(!routine) if(!routine)
{ {
QuadRasterizer *generator = new PixelProgram(state, context->pipelineLayout, context->pixelShader, context->descriptorSets); QuadRasterizer *generator = new PixelProgram(state, pipelineLayout, pixelShader, descriptorSets);
generator->generate(); generator->generate();
routine = (*generator)("PixelRoutine_%0.8X", state.shaderID); routine = (*generator)("PixelRoutine_%0.8X", state.shaderID);
delete generator; delete generator;
......
...@@ -120,47 +120,24 @@ namespace sw ...@@ -120,47 +120,24 @@ namespace sw
public: public:
typedef void (*RoutinePointer)(const Primitive *primitive, int count, int thread, DrawData *draw); typedef void (*RoutinePointer)(const Primitive *primitive, int count, int thread, DrawData *draw);
PixelProcessor(Context *context); PixelProcessor();
virtual ~PixelProcessor(); virtual ~PixelProcessor();
void setRenderTarget(int index, vk::ImageView *renderTarget);
void setDepthBuffer(vk::ImageView *depthBuffer);
void setStencilBuffer(vk::ImageView *stencilBuffer);
void setDepthBufferEnable(bool depthBufferEnable);
void setDepthCompare(VkCompareOp depthCompareMode);
void setDepthWriteEnable(bool depthWriteEnable);
void setCullMode(CullMode cullMode, bool frontFacingCCW);
void setColorWriteMask(int index, int rgbaMask);
void setBlendConstant(const Color<float> &blendConstant); void setBlendConstant(const Color<float> &blendConstant);
void setAlphaBlendEnable(bool alphaBlendEnable);
void setSourceBlendFactor(VkBlendFactor sourceBlendFactor);
void setDestBlendFactor(VkBlendFactor destBlendFactor);
void setBlendOperation(VkBlendOp blendOperation);
void setSeparateAlphaBlendEnable(bool separateAlphaBlendEnable);
void setSourceBlendFactorAlpha(VkBlendFactor sourceBlendFactorAlpha);
void setDestBlendFactorAlpha(VkBlendFactor destBlendFactorAlpha);
void setBlendOperationAlpha(VkBlendOp blendOperationAlpha);
void setPerspectiveCorrection(bool perspectiveCorrection); void setPerspectiveCorrection(bool perspectiveCorrection);
void setOcclusionEnabled(bool enable);
protected: protected:
const State update() const; const State update(const Context* context) const;
Routine *routine(const State &state); Routine *routine(const State &state, vk::PipelineLayout const *pipelineLayout,
SpirvShader const *pixelShader, const vk::DescriptorSet::Bindings &descriptorSets);
void setRoutineCacheSize(int routineCacheSize); void setRoutineCacheSize(int routineCacheSize);
// Other semi-constants // Other semi-constants
Factor factor; Factor factor;
private: private:
Context *const context;
RoutineCache<State> *routineCache; RoutineCache<State> *routineCache;
}; };
} }
......
...@@ -199,13 +199,11 @@ namespace sw ...@@ -199,13 +199,11 @@ namespace sw
deallocate(data); deallocate(data);
} }
Renderer::Renderer(Context *context, Conventions conventions, bool exactColorRounding) : VertexProcessor(context), PixelProcessor(context), SetupProcessor(context), context(context), viewport() Renderer::Renderer(Conventions conventions, bool exactColorRounding)
{ {
setGlobalRenderingSettings(conventions, exactColorRounding); setGlobalRenderingSettings(conventions, exactColorRounding);
setRenderTarget(0, nullptr);
clipper = new Clipper; clipper = new Clipper;
blitter = new Blitter;
#if PERF_HUD #if PERF_HUD
resetTimers(); resetTimers();
...@@ -269,9 +267,6 @@ namespace sw ...@@ -269,9 +267,6 @@ namespace sw
delete clipper; delete clipper;
clipper = nullptr; clipper = nullptr;
delete blitter;
blitter = nullptr;
delete resumeApp; delete resumeApp;
resumeApp = nullptr; resumeApp = nullptr;
...@@ -297,7 +292,20 @@ namespace sw ...@@ -297,7 +292,20 @@ namespace sw
sw::deallocate(mem); sw::deallocate(mem);
} }
void Renderer::draw(VkPrimitiveTopology topology, VkIndexType indexType, unsigned int count, int baseVertex, vk::Fence* fence, bool update) bool Renderer::hasQueryOfType(VkQueryType type) const
{
for(auto query : queries)
{
if(query->type == type)
{
return true;
}
}
return false;
}
void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex, vk::Fence* fence, bool update)
{ {
#ifndef NDEBUG #ifndef NDEBUG
if(count < minPrimitives || count > maxPrimitives) if(count < minPrimitives || count > maxPrimitives)
...@@ -306,39 +314,26 @@ namespace sw ...@@ -306,39 +314,26 @@ namespace sw
} }
#endif #endif
context->topology = topology;
updateConfiguration(); updateConfiguration();
int ms = context->sampleCount; int ms = context->sampleCount;
context->multiSampleMask = context->sampleMask & ((unsigned)0xFFFFFFFF >> (32 - ms));
if(!context->multiSampleMask) if(!context->multiSampleMask)
{ {
return; return;
} }
context->occlusionEnabled = false;
for(auto query : queries)
{
if(query->type == VK_QUERY_TYPE_OCCLUSION)
{
context->occlusionEnabled = true;
break;
}
}
sync->lock(sw::PRIVATE); sync->lock(sw::PRIVATE);
if(update) if(update)
{ {
vertexState = VertexProcessor::update(topology); vertexState = VertexProcessor::update(context);
setupState = SetupProcessor::update(); setupState = SetupProcessor::update(context);
pixelState = PixelProcessor::update(); pixelState = PixelProcessor::update(context);
vertexRoutine = VertexProcessor::routine(vertexState); vertexRoutine = VertexProcessor::routine(vertexState, context->pipelineLayout, context->vertexShader, context->descriptorSets);
setupRoutine = SetupProcessor::routine(setupState); setupRoutine = SetupProcessor::routine(setupState);
pixelRoutine = PixelProcessor::routine(pixelState); pixelRoutine = PixelProcessor::routine(pixelState, context->pipelineLayout, context->pixelShader, context->descriptorSets);
} }
int batch = batchSize / ms; int batch = batchSize / ms;
...@@ -392,7 +387,7 @@ namespace sw ...@@ -392,7 +387,7 @@ namespace sw
} }
} }
draw->topology = topology; draw->topology = context->topology;
draw->indexType = indexType; draw->indexType = indexType;
draw->batchSize = batch; draw->batchSize = batch;
...@@ -1396,46 +1391,6 @@ namespace sw ...@@ -1396,46 +1391,6 @@ namespace sw
} }
} }
void Renderer::setMultiSampleMask(unsigned int mask)
{
context->sampleMask = mask;
}
void Renderer::setTransparencyAntialiasing(TransparencyAntialiasing transparencyAntialiasing)
{
sw::transparencyAntialiasing = transparencyAntialiasing;
}
void Renderer::setLineWidth(float width)
{
context->lineWidth = width;
}
void Renderer::setDepthBias(float bias)
{
context->depthBias = bias;
}
void Renderer::setSlopeDepthBias(float slopeBias)
{
context->slopeDepthBias = slopeBias;
}
void Renderer::setRasterizerDiscard(bool rasterizerDiscard)
{
context->rasterizerDiscard = rasterizerDiscard;
}
void Renderer::setPixelShader(const SpirvShader *shader)
{
context->pixelShader = shader;
}
void Renderer::setVertexShader(const SpirvShader *shader)
{
context->vertexShader = shader;
}
void Renderer::addQuery(vk::Query *query) void Renderer::addQuery(vk::Query *query)
{ {
queries.push_back(query); queries.push_back(query);
...@@ -1446,11 +1401,11 @@ namespace sw ...@@ -1446,11 +1401,11 @@ namespace sw
queries.remove(query); queries.remove(query);
} }
void Renderer::advanceInstanceAttributes() void Renderer::advanceInstanceAttributes(Stream* inputs)
{ {
for(uint32_t i = 0; i < vk::MAX_VERTEX_INPUT_BINDINGS; i++) for(uint32_t i = 0; i < vk::MAX_VERTEX_INPUT_BINDINGS; i++)
{ {
auto &attrib = context->input[i]; auto &attrib = inputs[i];
if (attrib.count && attrib.instanceStride) if (attrib.count && attrib.instanceStride)
{ {
// Under the casts: attrib.buffer += attrib.instanceStride // Under the casts: attrib.buffer += attrib.instanceStride
...@@ -1491,11 +1446,6 @@ namespace sw ...@@ -1491,11 +1446,6 @@ namespace sw
} }
#endif #endif
void Renderer::setContext(const sw::Context& context)
{
*(this->context) = context;
}
void Renderer::setViewport(const VkViewport &viewport) void Renderer::setViewport(const VkViewport &viewport)
{ {
this->viewport = viewport; this->viewport = viewport;
......
...@@ -193,30 +193,16 @@ namespace sw ...@@ -193,30 +193,16 @@ namespace sw
}; };
public: public:
Renderer(Context *context, Conventions conventions, bool exactColorRounding); Renderer(Conventions conventions, bool exactColorRounding);
virtual ~Renderer(); virtual ~Renderer();
void *operator new(size_t size); void *operator new(size_t size);
void operator delete(void * mem); void operator delete(void * mem);
void draw(VkPrimitiveTopology topology, VkIndexType indexType, unsigned int count, int baseVertex, vk::Fence* fence, bool update = true); bool hasQueryOfType(VkQueryType type) const;
void setContext(const sw::Context& context); void draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex, vk::Fence* fence, bool update = true);
void setMultiSampleMask(unsigned int mask);
void setTransparencyAntialiasing(TransparencyAntialiasing transparencyAntialiasing);
void setLineWidth(float width);
void setDepthBias(float bias);
void setSlopeDepthBias(float slopeBias);
void setRasterizerDiscard(bool rasterizerDiscard);
// Programmable pipelines
void setPixelShader(const SpirvShader *shader);
void setVertexShader(const SpirvShader *shader);
// Viewport & Clipper // Viewport & Clipper
void setViewport(const VkViewport &viewport); void setViewport(const VkViewport &viewport);
...@@ -225,7 +211,7 @@ namespace sw ...@@ -225,7 +211,7 @@ namespace sw
void addQuery(vk::Query *query); void addQuery(vk::Query *query);
void removeQuery(vk::Query *query); void removeQuery(vk::Query *query);
void advanceInstanceAttributes(); void advanceInstanceAttributes(Stream* inputs);
void synchronize(); void synchronize();
...@@ -262,9 +248,7 @@ namespace sw ...@@ -262,9 +248,7 @@ namespace sw
void initializeThreads(); void initializeThreads();
void terminateThreads(); void terminateThreads();
Context *context;
Clipper *clipper; Clipper *clipper;
Blitter *blitter;
VkViewport viewport; VkViewport viewport;
VkRect2D scissor; VkRect2D scissor;
int clipFlags; int clipFlags;
......
...@@ -57,7 +57,7 @@ namespace sw ...@@ -57,7 +57,7 @@ namespace sw
return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0; return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
} }
SetupProcessor::SetupProcessor(Context *context) : context(context) SetupProcessor::SetupProcessor()
{ {
routineCache = nullptr; routineCache = nullptr;
setRoutineCacheSize(1024); setRoutineCacheSize(1024);
...@@ -69,7 +69,7 @@ namespace sw ...@@ -69,7 +69,7 @@ namespace sw
routineCache = nullptr; routineCache = nullptr;
} }
SetupProcessor::State SetupProcessor::update() const SetupProcessor::State SetupProcessor::update(const sw::Context* context) const
{ {
State state; State state;
......
...@@ -64,19 +64,17 @@ namespace sw ...@@ -64,19 +64,17 @@ namespace sw
typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw); typedef bool (*RoutinePointer)(Primitive *primitive, const Triangle *triangle, const Polygon *polygon, const DrawData *draw);
SetupProcessor(Context *context); SetupProcessor();
~SetupProcessor(); ~SetupProcessor();
protected: protected:
State update() const; State update(const sw::Context* context) const;
Routine *routine(const State &state); Routine *routine(const State &state);
void setRoutineCacheSize(int cacheSize); void setRoutineCacheSize(int cacheSize);
private: private:
Context *const context;
RoutineCache<State> *routineCache; RoutineCache<State> *routineCache;
}; };
} }
......
...@@ -61,7 +61,7 @@ namespace sw ...@@ -61,7 +61,7 @@ namespace sw
return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0; return memcmp(static_cast<const States*>(this), static_cast<const States*>(&state), sizeof(States)) == 0;
} }
VertexProcessor::VertexProcessor(Context *context) : context(context) VertexProcessor::VertexProcessor()
{ {
routineCache = nullptr; routineCache = nullptr;
setRoutineCacheSize(1024); setRoutineCacheSize(1024);
...@@ -73,37 +73,19 @@ namespace sw ...@@ -73,37 +73,19 @@ namespace sw
routineCache = nullptr; routineCache = nullptr;
} }
void VertexProcessor::setInputStream(int index, const Stream &stream)
{
context->input[index] = stream;
}
void VertexProcessor::resetInputStreams()
{
for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
{
context->input[i].defaults();
}
}
void VertexProcessor::setInstanceID(int instanceID)
{
context->instanceID = instanceID;
}
void VertexProcessor::setRoutineCacheSize(int cacheSize) void VertexProcessor::setRoutineCacheSize(int cacheSize)
{ {
delete routineCache; delete routineCache;
routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536)); routineCache = new RoutineCache<State>(clamp(cacheSize, 1, 65536));
} }
const VertexProcessor::State VertexProcessor::update(VkPrimitiveTopology topology) const VertexProcessor::State VertexProcessor::update(const sw::Context* context)
{ {
State state; State state;
state.shaderID = context->vertexShader->getSerialID(); state.shaderID = context->vertexShader->getSerialID();
switch(topology) switch(context->topology)
{ {
case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
state.verticesPerPrimitive = 1; state.verticesPerPrimitive = 1;
...@@ -118,7 +100,7 @@ namespace sw ...@@ -118,7 +100,7 @@ namespace sw
state.verticesPerPrimitive = 3; state.verticesPerPrimitive = 3;
break; break;
default: default:
UNIMPLEMENTED("topology %d", int(topology)); UNIMPLEMENTED("topology %d", int(context->topology));
} }
for(int i = 0; i < MAX_VERTEX_INPUTS; i++) for(int i = 0; i < MAX_VERTEX_INPUTS; i++)
...@@ -136,13 +118,16 @@ namespace sw ...@@ -136,13 +118,16 @@ namespace sw
return state; return state;
} }
Routine *VertexProcessor::routine(const State &state) Routine *VertexProcessor::routine(const State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *vertexShader,
const vk::DescriptorSet::Bindings &descriptorSets)
{ {
Routine *routine = routineCache->query(state); Routine *routine = routineCache->query(state);
if(!routine) // Create one if(!routine) // Create one
{ {
VertexRoutine *generator = new VertexProgram(state, context->pipelineLayout, context->vertexShader, context->descriptorSets); VertexRoutine *generator = new VertexProgram(state, pipelineLayout, vertexShader, descriptorSets);
generator->generate(); generator->generate();
routine = (*generator)("VertexRoutine_%0.8X", state.shaderID); routine = (*generator)("VertexRoutine_%0.8X", state.shaderID);
delete generator; delete generator;
......
...@@ -80,24 +80,18 @@ namespace sw ...@@ -80,24 +80,18 @@ namespace sw
typedef void (*RoutinePointer)(Vertex *output, unsigned int *batch, VertexTask *vertexTask, DrawData *draw); typedef void (*RoutinePointer)(Vertex *output, unsigned int *batch, VertexTask *vertexTask, DrawData *draw);
VertexProcessor(Context *context); VertexProcessor();
virtual ~VertexProcessor(); virtual ~VertexProcessor();
void setInputStream(int index, const Stream &stream);
void resetInputStreams();
void setInstanceID(int instanceID);
protected: protected:
const State update(VkPrimitiveTopology topology); const State update(const sw::Context* context);
Routine *routine(const State &state); Routine *routine(const State &state, vk::PipelineLayout const *pipelineLayout,
SpirvShader const *vertexShader, const vk::DescriptorSet::Bindings &descriptorSets);
void setRoutineCacheSize(int cacheSize); void setRoutineCacheSize(int cacheSize);
private: private:
Context *const context;
RoutineCache<State> *routineCache; RoutineCache<State> *routineCache;
}; };
} }
......
...@@ -417,7 +417,7 @@ void CommandBuffer::ExecutionState::bindVertexInputs(sw::Context& context, int f ...@@ -417,7 +417,7 @@ void CommandBuffer::ExecutionState::bindVertexInputs(sw::Context& context, int f
} }
} }
void CommandBuffer::ExecutionState::bindAttachments() void CommandBuffer::ExecutionState::bindAttachments(sw::Context& context)
{ {
// Binds all the attachments for the current subpass // Binds all the attachments for the current subpass
// Ideally this would be performed by BeginRenderPass and NextSubpass, but // Ideally this would be performed by BeginRenderPass and NextSubpass, but
...@@ -429,8 +429,7 @@ void CommandBuffer::ExecutionState::bindAttachments() ...@@ -429,8 +429,7 @@ void CommandBuffer::ExecutionState::bindAttachments()
auto attachmentReference = renderPass->getCurrentSubpass().pColorAttachments[i]; auto attachmentReference = renderPass->getCurrentSubpass().pColorAttachments[i];
if (attachmentReference.attachment != VK_ATTACHMENT_UNUSED) if (attachmentReference.attachment != VK_ATTACHMENT_UNUSED)
{ {
auto attachment = renderPassFramebuffer->getAttachment(attachmentReference.attachment); context.renderTarget[i] = renderPassFramebuffer->getAttachment(attachmentReference.attachment);
renderer->setRenderTarget(i, attachment);
} }
} }
...@@ -440,11 +439,11 @@ void CommandBuffer::ExecutionState::bindAttachments() ...@@ -440,11 +439,11 @@ void CommandBuffer::ExecutionState::bindAttachments()
auto attachment = renderPassFramebuffer->getAttachment(attachmentReference->attachment); auto attachment = renderPassFramebuffer->getAttachment(attachmentReference->attachment);
if (attachment->hasDepthAspect()) if (attachment->hasDepthAspect())
{ {
renderer->setDepthBuffer(attachment); context.depthBuffer = attachment;
} }
if (attachment->hasStencilAspect()) if (attachment->hasStencilAspect())
{ {
renderer->setStencilBuffer(attachment); context.stencilBuffer = attachment;
} }
} }
} }
...@@ -516,17 +515,17 @@ struct DrawBase : public CommandBuffer::Command ...@@ -516,17 +515,17 @@ struct DrawBase : public CommandBuffer::Command
context.backStencil.reference = executionState.dynamicState.reference[1]; context.backStencil.reference = executionState.dynamicState.reference[1];
} }
executionState.renderer->setContext(context); executionState.bindAttachments(context);
executionState.bindAttachments(); context.multiSampleMask = context.sampleMask & ((unsigned)0xFFFFFFFF >> (32 - context.sampleCount));
context.occlusionEnabled = executionState.renderer->hasQueryOfType(VK_QUERY_TYPE_OCCLUSION);
const uint32_t primitiveCount = pipeline->computePrimitiveCount(count); const uint32_t primitiveCount = pipeline->computePrimitiveCount(count);
for(uint32_t instance = firstInstance; instance != firstInstance + instanceCount; instance++) for(uint32_t instance = firstInstance; instance != firstInstance + instanceCount; instance++)
{ {
executionState.renderer->setInstanceID(instance); context.instanceID = instance;
executionState.renderer->draw(context.topology, executionState.indexType, primitiveCount, vertexOffset, executionState.renderer->draw(&context, executionState.indexType, primitiveCount, vertexOffset, executionState.fence);
executionState.fence); executionState.renderer->advanceInstanceAttributes(context.input);
executionState.renderer->advanceInstanceAttributes();
} }
} }
}; };
......
...@@ -166,7 +166,7 @@ public: ...@@ -166,7 +166,7 @@ public:
VertexInputBinding indexBufferBinding; VertexInputBinding indexBufferBinding;
VkIndexType indexType; VkIndexType indexType;
void bindAttachments(); void bindAttachments(sw::Context& context);
void bindVertexInputs(sw::Context& context, int firstVertex, int firstInstance); void bindVertexInputs(sw::Context& context, int firstVertex, int firstInstance);
}; };
......
...@@ -75,8 +75,7 @@ namespace vk ...@@ -75,8 +75,7 @@ namespace vk
Queue::Queue() Queue::Queue()
{ {
context.reset(new sw::Context()); renderer.reset(new sw::Renderer(sw::OpenGL, true));
renderer.reset(new sw::Renderer(context.get(), sw::OpenGL, true));
queueThread = std::thread(TaskLoop, this); queueThread = std::thread(TaskLoop, this);
} }
...@@ -93,7 +92,6 @@ void Queue::destroy() ...@@ -93,7 +92,6 @@ void Queue::destroy()
garbageCollect(); garbageCollect();
renderer.reset(nullptr); renderer.reset(nullptr);
context.reset(nullptr);
} }
VkResult Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) VkResult Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence)
......
...@@ -151,7 +151,6 @@ private: ...@@ -151,7 +151,6 @@ private:
void garbageCollect(); void garbageCollect();
void submitQueue(const Task& task); void submitQueue(const Task& task);
std::unique_ptr<sw::Context> context;
std::unique_ptr<sw::Renderer> renderer; std::unique_ptr<sw::Renderer> renderer;
Chan<Task> pending; Chan<Task> pending;
Chan<VkSubmitInfo*> toDelete; Chan<VkSubmitInfo*> toDelete;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment