Commit 76e9bc06 by Ben Clayton Committed by Ben Clayton

Plumb PipelineLayouts down to SpirvRoutine

This initializes arrays to hold the descriptor sets in the routine. Nothing uses this yet. Bug: b/126330097 Change-Id: If052d0b93e62e4f32e88ed02f9bc21f4203587f5 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/25553Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 2c25b14c
...@@ -218,6 +218,8 @@ namespace sw ...@@ -218,6 +218,8 @@ namespace sw
colorWriteMask[i] = 0x0000000F; colorWriteMask[i] = 0x0000000F;
} }
pipelineLayout = nullptr;
pixelShader = nullptr; pixelShader = nullptr;
vertexShader = nullptr; vertexShader = nullptr;
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
namespace vk namespace vk
{ {
class ImageView; class ImageView;
}; class PipelineLayout;
} // namespace vk
namespace sw namespace sw
{ {
...@@ -198,6 +199,8 @@ namespace sw ...@@ -198,6 +199,8 @@ namespace sw
vk::ImageView *stencilBuffer; vk::ImageView *stencilBuffer;
unsigned int stencilBufferLayer; unsigned int stencilBufferLayer;
vk::PipelineLayout const *pipelineLayout;
// Shaders // Shaders
const SpirvShader *pixelShader; const SpirvShader *pixelShader;
const SpirvShader *vertexShader; const SpirvShader *vertexShader;
......
...@@ -449,7 +449,7 @@ namespace sw ...@@ -449,7 +449,7 @@ namespace sw
if(!routine) if(!routine)
{ {
QuadRasterizer *generator = new PixelProgram(state, context->pixelShader); QuadRasterizer *generator = new PixelProgram(state, context->pipelineLayout, context->pixelShader);
generator->generate(); generator->generate();
routine = (*generator)("PixelRoutine_%0.8X", state.shaderID); routine = (*generator)("PixelRoutine_%0.8X", state.shaderID);
delete generator; delete generator;
......
...@@ -129,7 +129,7 @@ namespace sw ...@@ -129,7 +129,7 @@ namespace sw
if(!routine) // Create one if(!routine) // Create one
{ {
VertexRoutine *generator = new VertexProgram(state, context->vertexShader); VertexRoutine *generator = new VertexProgram(state, context->pipelineLayout, context->vertexShader);
generator->generate(); generator->generate();
routine = (*generator)("VertexRoutine_%0.8X", state.shaderID); routine = (*generator)("VertexRoutine_%0.8X", state.shaderID);
delete generator; delete generator;
......
...@@ -23,8 +23,11 @@ namespace sw ...@@ -23,8 +23,11 @@ namespace sw
class PixelProgram : public PixelRoutine class PixelProgram : public PixelRoutine
{ {
public: public:
PixelProgram(const PixelProcessor::State &state, SpirvShader const *spirvShader) : PixelProgram(
PixelRoutine(state, spirvShader) const PixelProcessor::State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *spirvShader) :
PixelRoutine(state, pipelineLayout, spirvShader)
{ {
} }
......
...@@ -29,8 +29,12 @@ namespace sw ...@@ -29,8 +29,12 @@ namespace sw
extern bool exactColorRounding; extern bool exactColorRounding;
extern bool forceClearRegisters; extern bool forceClearRegisters;
PixelRoutine::PixelRoutine(const PixelProcessor::State &state, SpirvShader const *spirvShader) PixelRoutine::PixelRoutine(
: QuadRasterizer(state, spirvShader) /* addressing */ const PixelProcessor::State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *spirvShader)
: QuadRasterizer(state, spirvShader),
routine(pipelineLayout)
{ {
spirvShader->emitProlog(&routine); spirvShader->emitProlog(&routine);
......
...@@ -25,7 +25,9 @@ namespace sw ...@@ -25,7 +25,9 @@ namespace sw
class PixelRoutine : public sw::QuadRasterizer, public ShaderCore class PixelRoutine : public sw::QuadRasterizer, public ShaderCore
{ {
public: public:
PixelRoutine(const PixelProcessor::State &state, SpirvShader const *spirvShader); PixelRoutine(const PixelProcessor::State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *spirvShader);
virtual ~PixelRoutine(); virtual ~PixelRoutine();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "SpirvShader.hpp" #include "SpirvShader.hpp"
#include "System/Math.hpp" #include "System/Math.hpp"
#include "Vulkan/VkDebug.hpp" #include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkPipelineLayout.hpp"
#include "Device/Config.hpp" #include "Device/Config.hpp"
namespace sw namespace sw
...@@ -1437,4 +1438,10 @@ namespace sw ...@@ -1437,4 +1438,10 @@ namespace sw
} }
} }
} }
SpirvRoutine::SpirvRoutine(vk::PipelineLayout const *pipelineLayout) :
pipelineLayout(pipelineLayout)
{
}
} }
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
#ifndef sw_SpirvShader_hpp #ifndef sw_SpirvShader_hpp
#define sw_SpirvShader_hpp #define sw_SpirvShader_hpp
#include "System/Types.hpp"
#include "Vulkan/VkDebug.hpp"
#include "ShaderCore.hpp" #include "ShaderCore.hpp"
#include "SpirvID.hpp" #include "SpirvID.hpp"
#include "System/Types.hpp"
#include "Vulkan/VkDebug.hpp"
#include "Vulkan/VkConfig.h"
#include <array>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -30,6 +32,11 @@ ...@@ -30,6 +32,11 @@
#include <spirv/unified1/spirv.hpp> #include <spirv/unified1/spirv.hpp>
#include <Device/Config.hpp> #include <Device/Config.hpp>
namespace vk
{
class PipelineLayout;
} // namespace vk
namespace sw namespace sw
{ {
// Forward declarations. // Forward declarations.
...@@ -412,8 +419,12 @@ namespace sw ...@@ -412,8 +419,12 @@ namespace sw
class SpirvRoutine class SpirvRoutine
{ {
public: public:
SpirvRoutine(vk::PipelineLayout const *pipelineLayout);
using Value = Array<SIMD::Float>; using Value = Array<SIMD::Float>;
vk::PipelineLayout const * const pipelineLayout;
std::unordered_map<SpirvShader::ObjectID, Value> lvalues; std::unordered_map<SpirvShader::ObjectID, Value> lvalues;
std::unordered_map<SpirvShader::ObjectID, Intermediate> intermediates; std::unordered_map<SpirvShader::ObjectID, Intermediate> intermediates;
...@@ -421,6 +432,8 @@ namespace sw ...@@ -421,6 +432,8 @@ namespace sw
Value inputs = Value{MAX_INTERFACE_COMPONENTS}; Value inputs = Value{MAX_INTERFACE_COMPONENTS};
Value outputs = Value{MAX_INTERFACE_COMPONENTS}; Value outputs = Value{MAX_INTERFACE_COMPONENTS};
std::array<Pointer<Byte>, vk::MAX_BOUND_DESCRIPTOR_SETS> descriptorSets;
void createLvalue(SpirvShader::ObjectID id, uint32_t size) void createLvalue(SpirvShader::ObjectID id, uint32_t size)
{ {
lvalues.emplace(id, Value(size)); lvalues.emplace(id, Value(size));
......
...@@ -22,8 +22,11 @@ ...@@ -22,8 +22,11 @@
namespace sw namespace sw
{ {
VertexProgram::VertexProgram(const VertexProcessor::State &state, SpirvShader const *spirvShader) VertexProgram::VertexProgram(
: VertexRoutine(state, spirvShader) const VertexProcessor::State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *spirvShader)
: VertexRoutine(state, pipelineLayout, spirvShader)
{ {
ifDepth = 0; ifDepth = 0;
loopRepDepth = 0; loopRepDepth = 0;
......
...@@ -29,7 +29,10 @@ namespace sw ...@@ -29,7 +29,10 @@ namespace sw
class VertexProgram : public VertexRoutine, public ShaderCore class VertexProgram : public VertexRoutine, public ShaderCore
{ {
public: public:
VertexProgram(const VertexProcessor::State &state, SpirvShader const *spirvShader); VertexProgram(
const VertexProcessor::State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *spirvShader);
virtual ~VertexProgram(); virtual ~VertexProgram();
......
...@@ -24,8 +24,12 @@ ...@@ -24,8 +24,12 @@
namespace sw namespace sw
{ {
VertexRoutine::VertexRoutine(const VertexProcessor::State &state, SpirvShader const *spirvShader) VertexRoutine::VertexRoutine(
: state(state), const VertexProcessor::State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *spirvShader)
: routine(pipelineLayout),
state(state),
spirvShader(spirvShader) spirvShader(spirvShader)
{ {
spirvShader->emitProlog(&routine); spirvShader->emitProlog(&routine);
......
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
#include "ShaderCore.hpp" #include "ShaderCore.hpp"
#include "SpirvShader.hpp" #include "SpirvShader.hpp"
namespace vk
{
class PipelineLayout;
} // namespace vk
namespace sw namespace sw
{ {
class VertexRoutinePrototype : public Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> class VertexRoutinePrototype : public Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)>
...@@ -38,7 +43,10 @@ namespace sw ...@@ -38,7 +43,10 @@ namespace sw
class VertexRoutine : public VertexRoutinePrototype class VertexRoutine : public VertexRoutinePrototype
{ {
public: public:
VertexRoutine(const VertexProcessor::State &state, SpirvShader const *spirvShader); VertexRoutine(
const VertexProcessor::State &state,
vk::PipelineLayout const *pipelineLayout,
SpirvShader const *spirvShader);
virtual ~VertexRoutine(); virtual ~VertexRoutine();
void generate(); void generate();
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
// limitations under the License. // limitations under the License.
#include "VkDescriptorSetLayout.hpp" #include "VkDescriptorSetLayout.hpp"
#include "System/Types.hpp"
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
...@@ -176,6 +178,12 @@ void DescriptorSetLayout::initialize(VkDescriptorSet vkDescriptorSet) ...@@ -176,6 +178,12 @@ void DescriptorSetLayout::initialize(VkDescriptorSet vkDescriptorSet)
} }
} }
size_t DescriptorSetLayout::getBindingOffset(uint32_t binding) const
{
uint32_t index = getBindingIndex(binding);
return bindingOffsets[index] + OFFSET(DescriptorSet, data[0]);
}
uint8_t* DescriptorSetLayout::getOffsetPointer(VkDescriptorSet descriptorSet, uint32_t binding, uint32_t arrayElement, uint32_t count, size_t* typeSize) const uint8_t* DescriptorSetLayout::getOffsetPointer(VkDescriptorSet descriptorSet, uint32_t binding, uint32_t arrayElement, uint32_t count, size_t* typeSize) const
{ {
uint32_t index = getBindingIndex(binding); uint32_t index = getBindingIndex(binding);
......
...@@ -35,6 +35,7 @@ public: ...@@ -35,6 +35,7 @@ public:
void initialize(VkDescriptorSet descriptorSet); void initialize(VkDescriptorSet descriptorSet);
size_t getSize() const; size_t getSize() const;
size_t getBindingOffset(uint32_t binding) const;
private: private:
uint32_t getBindingIndex(uint32_t binding) const; uint32_t getBindingIndex(uint32_t binding) const;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "VkPipeline.hpp" #include "VkPipeline.hpp"
#include "VkPipelineLayout.hpp"
#include "VkShaderModule.hpp" #include "VkShaderModule.hpp"
#include "Pipeline/SpirvShader.hpp" #include "Pipeline/SpirvShader.hpp"
...@@ -191,7 +192,10 @@ uint32_t getNumberOfChannels(VkFormat format) ...@@ -191,7 +192,10 @@ uint32_t getNumberOfChannels(VkFormat format)
namespace vk namespace vk
{ {
Pipeline::Pipeline(PipelineLayout const *layout) : layout(layout) {}
GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, void* mem) GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateInfo, void* mem)
: Pipeline(Cast(pCreateInfo->layout))
{ {
if((pCreateInfo->flags != 0) || if((pCreateInfo->flags != 0) ||
(pCreateInfo->stageCount != 2) || (pCreateInfo->stageCount != 2) ||
...@@ -230,6 +234,9 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn ...@@ -230,6 +234,9 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
// Context must always have a PipelineLayout set.
context.pipelineLayout = layout;
// Temporary in-binding-order representation of buffer strides, to be consumed below // Temporary in-binding-order representation of buffer strides, to be consumed below
// when considering attributes. TODO: unfuse buffers from attributes in backend, is old GL model. // when considering attributes. TODO: unfuse buffers from attributes in backend, is old GL model.
uint32_t bufferStrides[MAX_VERTEX_INPUT_BINDINGS]; uint32_t bufferStrides[MAX_VERTEX_INPUT_BINDINGS];
...@@ -499,6 +506,7 @@ const sw::Color<float>& GraphicsPipeline::getBlendConstants() const ...@@ -499,6 +506,7 @@ const sw::Color<float>& GraphicsPipeline::getBlendConstants() const
} }
ComputePipeline::ComputePipeline(const VkComputePipelineCreateInfo* pCreateInfo, void* mem) ComputePipeline::ComputePipeline(const VkComputePipelineCreateInfo* pCreateInfo, void* mem)
: Pipeline(Cast(pCreateInfo->layout))
{ {
} }
......
...@@ -23,9 +23,13 @@ namespace sw { class SpirvShader; } ...@@ -23,9 +23,13 @@ namespace sw { class SpirvShader; }
namespace vk namespace vk
{ {
class PipelineLayout;
class Pipeline class Pipeline
{ {
public: public:
Pipeline(PipelineLayout const *layout);
operator VkPipeline() operator VkPipeline()
{ {
return reinterpret_cast<VkPipeline>(this); return reinterpret_cast<VkPipeline>(this);
...@@ -40,6 +44,11 @@ public: ...@@ -40,6 +44,11 @@ public:
#ifndef NDEBUG #ifndef NDEBUG
virtual VkPipelineBindPoint bindPoint() const = 0; virtual VkPipelineBindPoint bindPoint() const = 0;
#endif #endif
PipelineLayout const * getLayout() const { return layout; }
protected:
PipelineLayout const *layout = nullptr;
}; };
class GraphicsPipeline : public Pipeline, public ObjectBase<GraphicsPipeline, VkPipeline> class GraphicsPipeline : public Pipeline, public ObjectBase<GraphicsPipeline, VkPipeline>
......
...@@ -44,4 +44,15 @@ size_t PipelineLayout::ComputeRequiredAllocationSize(const VkPipelineLayoutCreat ...@@ -44,4 +44,15 @@ size_t PipelineLayout::ComputeRequiredAllocationSize(const VkPipelineLayoutCreat
(pCreateInfo->pushConstantRangeCount * sizeof(VkPushConstantRange)); (pCreateInfo->pushConstantRangeCount * sizeof(VkPushConstantRange));
} }
size_t PipelineLayout::getNumDescriptorSets() const
{
return setLayoutCount;
}
size_t PipelineLayout::getBindingOffset(size_t descriptorSet, size_t binding) const
{
ASSERT(descriptorSet < setLayoutCount);
return setLayouts[descriptorSet]->getBindingOffset(binding);
}
} // namespace vk } // namespace vk
...@@ -29,6 +29,9 @@ public: ...@@ -29,6 +29,9 @@ public:
static size_t ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo* pCreateInfo); static size_t ComputeRequiredAllocationSize(const VkPipelineLayoutCreateInfo* pCreateInfo);
size_t getNumDescriptorSets() const;
size_t getBindingOffset(size_t descriptorSet, size_t binding) const;
private: private:
uint32_t setLayoutCount = 0; uint32_t setLayoutCount = 0;
DescriptorSetLayout** setLayouts = nullptr; DescriptorSetLayout** setLayouts = nullptr;
......
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