Skip to content

Commit

Permalink
Merge branch 'master' into Shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Sep 7, 2023
2 parents 4922344 + fa9f066 commit 6bd481e
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 75 deletions.
2 changes: 1 addition & 1 deletion include/vsg/state/DescriptorBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace vsg
{

/// DescriptorBuffer is a Descriptor class that encapsulates the bufferInfoList used to set VkWriteDescriptorSet::pBufferInfo settings
/// DescriptorBuffer is a means for passing uniforms to shaders.
/// DescriptorBuffer is a means for passing uniform and storage buffers to shaders.
class VSG_DECLSPEC DescriptorBuffer : public Inherit<Descriptor, DescriptorBuffer>
{
public:
Expand Down
3 changes: 2 additions & 1 deletion include/vsg/state/StateCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
namespace vsg
{

/// Base class for Vulkan commands associated with state, such as binding graphics pipelines and descriptor sets (textures and uniforms).
/// Base class for Vulkan commands associated with state, such as binding graphics
/// pipelines and descriptor sets for textures, uniform buffers and storage buffers.
/// StateCommands can be attached directly as nodes in the scene graph, or more typically assigned to StateGroup nodes to enable push/popping of state.
class VSG_DECLSPEC StateCommand : public Inherit<Command, StateCommand>
{
Expand Down
27 changes: 21 additions & 6 deletions include/vsg/utils/GraphicsPipelineConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ namespace vsg
bool two_sided = false;

bool enableTexture(const std::string& name);
bool enableUniform(const std::string& name);

bool assignTexture(const std::string& name, ref_ptr<Data> textureData = {}, ref_ptr<Sampler> sampler = {}, uint32_t dstArrayElement = 0);
bool assignTexture(const std::string& name, const ImageInfoList& imageInfoList, uint32_t dstArrayElement = 0);

bool assignUniform(const std::string& name, ref_ptr<Data> data = {}, uint32_t dstArrayElement = 0);
bool assignUniform(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0);
bool enableDescriptor(const std::string& name);
bool assignDescriptor(const std::string& name, ref_ptr<Data> data = {}, uint32_t dstArrayElement = 0);
bool assignDescriptor(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0);

[[deprecated("use enableDescriptor(..)")]]
bool enableUniform(const std::string& name) { return enableDescriptor(name); }

[[deprecated("use assignDescriptor(..)")]]
bool assignUniform(const std::string& name, ref_ptr<Data> data = {}, uint32_t dstArrayElement = 0) { return assignDescriptor(name, data, dstArrayElement); }

[[deprecated("use assignDescriptor(..)")]]
bool assignUniform(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0) { return assignDescriptor(name, bufferInfoList, dstArrayElement); }


bool assignDescriptor(uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr<Descriptor> descriptor);

Expand Down Expand Up @@ -104,12 +113,18 @@ namespace vsg
void reset();

bool enableArray(const std::string& name, VkVertexInputRate vertexInputRate, uint32_t stride, VkFormat format = VK_FORMAT_UNDEFINED);
bool enableDescriptor(const std::string& name);
bool enableTexture(const std::string& name);
bool enableUniform(const std::string& name);

bool assignArray(DataList& arrays, const std::string& name, VkVertexInputRate vertexInputRate, ref_ptr<Data> array);
bool assignDescriptor(const std::string& name, ref_ptr<Data> data = {});
bool assignTexture(const std::string& name, ref_ptr<Data> textureData = {}, ref_ptr<Sampler> sampler = {});
bool assignUniform(const std::string& name, ref_ptr<Data> data = {});

[[deprecated("use enableDescriptor(..)")]]
bool enableUniform(const std::string& name) { return enableDescriptor(name); }

[[deprecated("use assignDescriptor(..)")]]
bool assignUniform(const std::string& name, ref_ptr<Data> data = {}) { return assignDescriptor(name, data); }

// setup by assign calls
ref_ptr<ShaderCompileSettings> shaderHints;
Expand Down
34 changes: 22 additions & 12 deletions include/vsg/utils/ShaderSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace vsg
};
VSG_type_name(vsg::AttributeBinding);

struct VSG_DECLSPEC UniformBinding
struct VSG_DECLSPEC DescriptorBinding
{
std::string name;
std::string define;
Expand All @@ -46,11 +46,11 @@ namespace vsg
VkShaderStageFlags stageFlags = 0;
ref_ptr<Data> data;

int compare(const UniformBinding& rhs) const;
int compare(const DescriptorBinding& rhs) const;

explicit operator bool() const noexcept { return !name.empty(); }
};
VSG_type_name(vsg::UniformBinding);
VSG_type_name(vsg::DescriptorBinding);

struct VSG_DECLSPEC PushConstantRange
{
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace vsg
ShaderStages stages;

std::vector<AttributeBinding> attributeBindings;
std::vector<UniformBinding> uniformBindings;
std::vector<DescriptorBinding> descriptorBindings;
std::vector<PushConstantRange> pushConstantRanges;
std::vector<DefinesArrayState> definesArrayStates; // put more constrained ArrayState matches first so they are matched first.
std::set<std::string> optionalDefines;
Expand All @@ -134,30 +134,40 @@ namespace vsg
void addAttributeBinding(std::string name, std::string define, uint32_t location, VkFormat format, ref_ptr<Data> data);

/// add an uniform binding. Not thread safe, should only be called when initially setting up the ShaderSet
void addUniformBinding(std::string name, std::string define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr<Data> data);
void addDescriptorBinding(std::string name, std::string define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr<Data> data);

[[deprecated("use addDescriptorBinding(..)")]]
void addUniformBinding(std::string name, std::string define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr<Data> data) { addDescriptorBinding(name, define, set, binding, descriptorType, descriptorCount, stageFlags, data); }


/// add a push constant range. Not thread safe, should only be called when initially setting up the ShaderSet
void addPushConstantRange(std::string name, std::string define, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size);

/// get the AttributeBinding associated with name
AttributeBinding& getAttributeBinding(const std::string& name);

/// get the UniformBinding associated with name
UniformBinding& getUniformBinding(const std::string& name);

/// get the const AttributeBinding associated with name
const AttributeBinding& getAttributeBinding(const std::string& name) const;

/// get the const UniformBinding associated with name
const UniformBinding& getUniformBinding(const std::string& name) const;
/// get the DescriptorBinding associated with name
DescriptorBinding& getDescriptorBinding(const std::string& name);

/// get the const DescriptorBinding associated with name
const DescriptorBinding& getDescriptorBinding(const std::string& name) const;

[[deprecated("use getDescriptorBinding(..)")]]
DescriptorBinding& getUniformBinding(const std::string& name) { return getDescriptorBinding(name); }

[[deprecated("use getDescriptorBinding(..)")]]
const DescriptorBinding& getUnifomrBinding(const std::string& name) const { return getDescriptorBinding(name); }

/// get the first ArrayState that has matches with defines in the specified list of defines.
ref_ptr<ArrayState> getSuitableArrayState(const std::set<std::string>& defines) const;

/// get the ShaderStages variant that uses specified ShaderCompileSettings.
ShaderStages getShaderStages(ref_ptr<ShaderCompileSettings> scs = {});

/// return the <minimum_set, maximum_set+1> range of set numbers encompassing UniformBindings
/// return the <minimum_set, maximum_set+1> range of set numbers encompassing DescriptorBindings
std::pair<uint32_t, uint32_t> descriptorSetRange() const;

/// create the descriptor set layout.
Expand All @@ -182,7 +192,7 @@ namespace vsg
virtual ~ShaderSet();

AttributeBinding _nullAttributeBinding;
UniformBinding _nullUniformBinding;
DescriptorBinding _nullDescriptorBinding;
};
VSG_type_name(vsg::ShaderSet);

Expand Down
4 changes: 2 additions & 2 deletions src/vsg/io/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ void tile::init(vsg::ref_ptr<const vsg::Options> options)
_graphicsPipelineConfig->enableTexture("displacementMap");
}
#endif
_graphicsPipelineConfig->enableUniform("material");
_graphicsPipelineConfig->enableDescriptor("material");

_graphicsPipelineConfig->enableArray("vsg_Vertex", VK_VERTEX_INPUT_RATE_VERTEX, 12, VK_FORMAT_R32G32B32_SFLOAT);
_graphicsPipelineConfig->enableArray("vsg_Normal", VK_VERTEX_INPUT_RATE_VERTEX, 12, VK_FORMAT_R32G32B32_SFLOAT);
_graphicsPipelineConfig->enableArray("vsg_TexCoord0", VK_VERTEX_INPUT_RATE_VERTEX, 8, VK_FORMAT_R32G32_SFLOAT);
_graphicsPipelineConfig->enableArray("vsg_Color", VK_VERTEX_INPUT_RATE_INSTANCE, 16, VK_FORMAT_R32G32B32A32_SFLOAT);

if (auto& materialBinding = _shaderSet->getUniformBinding("material"))
if (auto& materialBinding = _shaderSet->getDescriptorBinding("material"))
{
ref_ptr<Data> mat = materialBinding.data;
if (!mat) mat = vsg::PhongMaterialValue::create();
Expand Down
2 changes: 2 additions & 0 deletions src/vsg/state/BufferInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ bool vsg::createBufferAndTransferData(Context& context, const BufferInfoList& bu

VkDeviceSize alignment = 4;
if (usage == VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) alignment = device->getPhysicalDevice()->getProperties().limits.minUniformBufferOffsetAlignment;
else if (usage == VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) alignment = device->getPhysicalDevice()->getProperties().limits.minStorageBufferOffsetAlignment;

VkDeviceSize totalSize = 0;
VkDeviceSize offset = 0;
Expand Down Expand Up @@ -303,6 +304,7 @@ BufferInfoList vsg::createHostVisibleBuffer(Device* device, const DataList& data

VkDeviceSize alignment = 4;
if (usage == VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) alignment = device->getPhysicalDevice()->getProperties().limits.minUniformBufferOffsetAlignment;
else if (usage == VK_BUFFER_USAGE_STORAGE_BUFFER_BIT) alignment = device->getPhysicalDevice()->getProperties().limits.minStorageBufferOffsetAlignment;

VkDeviceSize totalSize = 0;
VkDeviceSize offset = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/vsg/text/GpuLayoutTechnique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ void GpuLayoutTechnique::setup(Text* text, uint32_t minimumAllocation, ref_ptr<c
config->assignTexture("textureAtlas", text->font->atlas, sampler);
config->assignTexture("glyphMetrics", glyphMetricsProxy, glyphMetricSampler);

config->assignUniform("textLayout", layoutValue);
config->assignUniform("text", textArray);
config->assignDescriptor("textLayout", layoutValue);
config->assignDescriptor("text", textArray);

// Set the InputAssemblyState.topology
struct SetPipelineStates : public Visitor
Expand Down
4 changes: 2 additions & 2 deletions src/vsg/utils/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ ref_ptr<StateGroup> Builder::createStateGroup(const StateInfo& stateInfo)
graphicsPipelineConfig->assignTexture("displacementMap", stateInfo.displacementMap, sampler);
}

if (auto& materialBinding = activeShaderSet->getUniformBinding("material"))
if (auto& materialBinding = activeShaderSet->getDescriptorBinding("material"))
{
ref_ptr<Data> mat = materialBinding.data;
if (!mat) mat = vsg::PhongMaterialValue::create();
graphicsPipelineConfig->assignUniform("material", mat);
graphicsPipelineConfig->assignDescriptor("material", mat);
}

graphicsPipelineConfig->enableArray("vsg_Vertex", VK_VERTEX_INPUT_RATE_VERTEX, 12);
Expand Down
Loading

0 comments on commit 6bd481e

Please sign in to comment.