diff --git a/include/vsg/state/DescriptorBuffer.h b/include/vsg/state/DescriptorBuffer.h index 4a0c85c12..b4632ba23 100644 --- a/include/vsg/state/DescriptorBuffer.h +++ b/include/vsg/state/DescriptorBuffer.h @@ -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 { public: diff --git a/include/vsg/state/StateCommand.h b/include/vsg/state/StateCommand.h index 59da9ebb9..9146f3c27 100644 --- a/include/vsg/state/StateCommand.h +++ b/include/vsg/state/StateCommand.h @@ -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 { diff --git a/include/vsg/utils/GraphicsPipelineConfigurator.h b/include/vsg/utils/GraphicsPipelineConfigurator.h index bd2d20847..9a2c1e1c3 100644 --- a/include/vsg/utils/GraphicsPipelineConfigurator.h +++ b/include/vsg/utils/GraphicsPipelineConfigurator.h @@ -45,19 +45,31 @@ namespace vsg bool two_sided = false; bool enableTexture(const std::string& name); - bool enableUniform(const std::string& name); + bool enableDescriptorBuffer(const std::string& name); bool assignTexture(const std::string& name, ref_ptr textureData = {}, ref_ptr 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 = {}, uint32_t dstArrayElement = 0); - bool assignUniform(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0); + bool assignDescriptorBuffer(const std::string& name, ref_ptr data = {}, uint32_t dstArrayElement = 0); + bool assignDescriptorBuffer(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0); bool assignDescriptor(uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr descriptor); - /// call after all the textures/uniforms have been explictly assigned to add in textures/uniforms descriptors that are enabled by default (define == ""). + /// call after all the textures and buffers have been explictly assigned to add in texture/buffer descriptors that are enabled by default (define == ""). bool assignDefaults(); + /// deprecated: use enableDescriptorBuffer() + [[deprecated("use enableDescriptorBuffer()")]] + bool enableUniform(const std::string& name); + + /// deprecated: use assignDescriptorBuffer() + [[deprecated("use assignDescriptorBuffer()")]] + bool assignUniform(const std::string& name, ref_ptr data = {}, uint32_t dstArrayElement = 0); + + /// deprecated: use assignDescriptorBuffer() + [[deprecated("use assignDescriptorBuffer()")]] + bool assignUniform(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement = 0); + std::set assigned; std::set defines; std::vector> descriptorSets; @@ -105,11 +117,11 @@ namespace vsg bool enableArray(const std::string& name, VkVertexInputRate vertexInputRate, uint32_t stride, VkFormat format = VK_FORMAT_UNDEFINED); bool enableTexture(const std::string& name); - bool enableUniform(const std::string& name); + bool enableDescriptorBuffer(const std::string& name); bool assignArray(DataList& arrays, const std::string& name, VkVertexInputRate vertexInputRate, ref_ptr array); bool assignTexture(const std::string& name, ref_ptr textureData = {}, ref_ptr sampler = {}); - bool assignUniform(const std::string& name, ref_ptr data = {}); + bool assignDescriptorBuffer(const std::string& name, ref_ptr data = {}); // setup by assign calls ref_ptr shaderHints; @@ -128,6 +140,14 @@ namespace vsg ref_ptr graphicsPipeline; ref_ptr bindGraphicsPipeline; + /// deprecated: use enableDescriptorBuffer() + [[deprecated("use enableDescriptorBuffer()")]] + bool enableUniform(const std::string& name); + + /// deprecated: use assignDescriptorBuffer() + [[deprecated("use assignDescriptorBuffer()")]] + bool assignUniform(const std::string& name, ref_ptr data = {}); + protected: void _assignShaderSetSettings(); }; diff --git a/include/vsg/utils/ShaderSet.h b/include/vsg/utils/ShaderSet.h index 725a427f6..416ea0070 100644 --- a/include/vsg/utils/ShaderSet.h +++ b/include/vsg/utils/ShaderSet.h @@ -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; @@ -46,11 +46,11 @@ namespace vsg VkShaderStageFlags stageFlags = 0; ref_ptr 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 { @@ -116,7 +116,7 @@ namespace vsg ShaderStages stages; std::vector attributeBindings; - std::vector uniformBindings; + std::vector descriptorBindings; std::vector pushConstantRanges; std::vector definesArrayStates; // put more constrained ArrayState matches first so they are matched first. std::set optionalDefines; @@ -133,8 +133,8 @@ namespace vsg /// add an attribute binding, Not thread safe, should only be called when initially setting up the ShaderSet void addAttributeBinding(std::string name, std::string define, uint32_t location, VkFormat format, ref_ptr 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); + /// add a uniform, storage or texture binding. Not thread safe, should only be called when initially setting up the ShaderSet + void addDescriptorBinding(std::string name, std::string define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr 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); @@ -142,14 +142,14 @@ namespace vsg /// 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 DescriptorBinding (uniform, storage or texture) associated with name + DescriptorBinding& getDescriptorBinding(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 const DescriptorBinding (uniform, storage or texture) associated with name + const DescriptorBinding& getDescriptorBinding(const std::string& name) const; /// get the first ArrayState that has matches with defines in the specified list of defines. ref_ptr getSuitableArrayState(const std::set& defines) const; @@ -157,7 +157,7 @@ namespace vsg /// get the ShaderStages variant that uses specified ShaderCompileSettings. ShaderStages getShaderStages(ref_ptr scs = {}); - /// return the range of set numbers encompassing UniformBindings + /// return the range of set numbers encompassing DescriptorBindings std::pair descriptorSetRange() const; /// create the descriptor set layout. @@ -178,11 +178,26 @@ namespace vsg void read(Input& input) override; void write(Output& output) const override; + /// deprecated: use descriptorBindings + std::vector& uniformBindings = descriptorBindings; + + /// deprecated: use addDescriptorBinding() + [[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); + + /// deprecated: use getDescriptorBinding() + [[deprecated("use getDescriptorBinding()")]] + DescriptorBinding& getUniformBinding(const std::string& name); + + /// deprecated: use getDescriptorBinding() + [[deprecated("use getDescriptorBinding()")]] + const DescriptorBinding& getUniformBinding(const std::string& name) const; + protected: virtual ~ShaderSet(); AttributeBinding _nullAttributeBinding; - UniformBinding _nullUniformBinding; + DescriptorBinding _nullDescriptorBinding; }; VSG_type_name(vsg::ShaderSet); @@ -195,4 +210,7 @@ namespace vsg /// create a ShaderSet for Physics Based Rendering extern VSG_DECLSPEC ref_ptr createPhysicsBasedRenderingShaderSet(ref_ptr options = {}); + /// deprecated: use vsg::DescriptorBinding + using UniformBinding = DescriptorBinding; + } // namespace vsg diff --git a/src/vsg/io/tile.cpp b/src/vsg/io/tile.cpp index 426c93950..df97c9cc0 100644 --- a/src/vsg/io/tile.cpp +++ b/src/vsg/io/tile.cpp @@ -327,14 +327,14 @@ void tile::init(vsg::ref_ptr options) _graphicsPipelineConfig->enableTexture("displacementMap"); } #endif - _graphicsPipelineConfig->enableUniform("material"); + _graphicsPipelineConfig->enableDescriptorBuffer("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 mat = materialBinding.data; if (!mat) mat = vsg::PhongMaterialValue::create(); diff --git a/src/vsg/state/BufferInfo.cpp b/src/vsg/state/BufferInfo.cpp index 5431b722b..4573ac2e9 100644 --- a/src/vsg/state/BufferInfo.cpp +++ b/src/vsg/state/BufferInfo.cpp @@ -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; @@ -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; diff --git a/src/vsg/text/GpuLayoutTechnique.cpp b/src/vsg/text/GpuLayoutTechnique.cpp index a18959212..1cb426737 100644 --- a/src/vsg/text/GpuLayoutTechnique.cpp +++ b/src/vsg/text/GpuLayoutTechnique.cpp @@ -249,8 +249,8 @@ void GpuLayoutTechnique::setup(Text* text, uint32_t minimumAllocation, ref_ptrassignTexture("textureAtlas", text->font->atlas, sampler); config->assignTexture("glyphMetrics", glyphMetricsProxy, glyphMetricSampler); - config->assignUniform("textLayout", layoutValue); - config->assignUniform("text", textArray); + config->assignDescriptorBuffer("textLayout", layoutValue); + config->assignDescriptorBuffer("text", textArray); // Set the InputAssemblyState.topology struct SetPipelineStates : public Visitor diff --git a/src/vsg/utils/Builder.cpp b/src/vsg/utils/Builder.cpp index 2b2bce05d..5bcb95bde 100644 --- a/src/vsg/utils/Builder.cpp +++ b/src/vsg/utils/Builder.cpp @@ -81,11 +81,11 @@ ref_ptr 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 mat = materialBinding.data; if (!mat) mat = vsg::PhongMaterialValue::create(); - graphicsPipelineConfig->assignUniform("material", mat); + graphicsPipelineConfig->assignDescriptorBuffer("material", mat); } graphicsPipelineConfig->enableArray("vsg_Vertex", VK_VERTEX_INPUT_RATE_VERTEX, 12); diff --git a/src/vsg/utils/GraphicsPipelineConfigurator.cpp b/src/vsg/utils/GraphicsPipelineConfigurator.cpp index 87e1ca54a..726371d4f 100644 --- a/src/vsg/utils/GraphicsPipelineConfigurator.cpp +++ b/src/vsg/utils/GraphicsPipelineConfigurator.cpp @@ -101,7 +101,7 @@ void DescriptorConfigurator::reset() bool DescriptorConfigurator::enableTexture(const std::string& name) { - if (auto& textureBinding = shaderSet->getUniformBinding(name)) + if (auto& textureBinding = shaderSet->getDescriptorBinding(name)) { assigned.insert(name); @@ -118,7 +118,7 @@ bool DescriptorConfigurator::enableTexture(const std::string& name) bool DescriptorConfigurator::assignTexture(const std::string& name, ref_ptr textureData, ref_ptr sampler, uint32_t dstArrayElement) { - if (auto& textureBinding = shaderSet->getUniformBinding(name)) + if (auto& textureBinding = shaderSet->getDescriptorBinding(name)) { assigned.insert(name); @@ -135,7 +135,7 @@ bool DescriptorConfigurator::assignTexture(const std::string& name, ref_ptrgetUniformBinding(name)) + if (auto& textureBinding = shaderSet->getDescriptorBinding(name)) { assigned.insert(name); @@ -149,54 +149,79 @@ bool DescriptorConfigurator::assignTexture(const std::string& name, const ImageI return false; } -bool DescriptorConfigurator::enableUniform(const std::string& name) +bool DescriptorConfigurator::enableDescriptorBuffer(const std::string& name) { - if (auto& uniformBinding = shaderSet->getUniformBinding(name)) + if (auto& bufferBinding = shaderSet->getDescriptorBinding(name)) { assigned.insert(name); // set up bindings - if (!uniformBinding.define.empty()) defines.insert(uniformBinding.define); + if (!bufferBinding.define.empty()) defines.insert(bufferBinding.define); - // create uniform and associated DescriptorSets and binding - return assignDescriptor(uniformBinding.set, uniformBinding.binding, uniformBinding.descriptorType, uniformBinding.descriptorCount, uniformBinding.stageFlags, - DescriptorBuffer::create(uniformBinding.data, uniformBinding.binding)); + // create uniform or storage buffer, associated DescriptorSets and binding + const uint32_t dstArrayElement{0}; + return assignDescriptor(bufferBinding.set, bufferBinding.binding, bufferBinding.descriptorType, bufferBinding.descriptorCount, bufferBinding.stageFlags, + DescriptorBuffer::create(bufferBinding.data, bufferBinding.binding, dstArrayElement, bufferBinding.descriptorType)); } return false; } -bool DescriptorConfigurator::assignUniform(const std::string& name, ref_ptr data, uint32_t dstArrayElement) +/// deprecated: use DescriptorConfigurator::enableDescriptorBuffer() instead +bool DescriptorConfigurator::enableUniform(const std::string& name) { - if (auto& uniformBinding = shaderSet->getUniformBinding(name)) + warn("DescriptorConfigurator::enableUniform() has been deprecated." + " Use DescriptorConfigurator::enableDescriptorBuffer() instead."); + return enableDescriptorBuffer(name); +} + +bool DescriptorConfigurator::assignDescriptorBuffer(const std::string& name, ref_ptr data, uint32_t dstArrayElement) +{ + if (auto& bufferBinding = shaderSet->getDescriptorBinding(name)) { assigned.insert(name); // set up bindings - if (!uniformBinding.define.empty()) defines.insert(uniformBinding.define); + if (!bufferBinding.define.empty()) defines.insert(bufferBinding.define); - // create uniform and associated DescriptorSets and binding - return assignDescriptor(uniformBinding.set, uniformBinding.binding, uniformBinding.descriptorType, uniformBinding.descriptorCount, uniformBinding.stageFlags, - DescriptorBuffer::create(data ? data : uniformBinding.data, uniformBinding.binding, dstArrayElement, uniformBinding.descriptorType)); + // create uniform or storage buffer, associated DescriptorSets and binding + return assignDescriptor(bufferBinding.set, bufferBinding.binding, bufferBinding.descriptorType, bufferBinding.descriptorCount, bufferBinding.stageFlags, + DescriptorBuffer::create(data ? data : bufferBinding.data, bufferBinding.binding, dstArrayElement, bufferBinding.descriptorType)); } return false; } -bool DescriptorConfigurator::assignUniform(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement) +/// deprecated: use DescriptorConfigurator::assignDescriptorBuffer() instead. +bool DescriptorConfigurator::assignUniform(const std::string& name, ref_ptr data, uint32_t dstArrayElement) +{ + warn("DescriptorConfigurator::assignUniform() has been deprecated." + " Use DescriptorConfigurator::assignDescriptorBuffer() instead."); + return assignDescriptorBuffer(name, data, dstArrayElement); +} + +bool DescriptorConfigurator::assignDescriptorBuffer(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement) { - if (auto& uniformBinding = shaderSet->getUniformBinding(name)) + if (auto& bufferBinding = shaderSet->getDescriptorBinding(name)) { assigned.insert(name); // set up bindings - if (!uniformBinding.define.empty()) defines.insert(uniformBinding.define); + if (!bufferBinding.define.empty()) defines.insert(bufferBinding.define); - // create uniform and associated DescriptorSets and binding - return assignDescriptor(uniformBinding.set, uniformBinding.binding, uniformBinding.descriptorType, uniformBinding.descriptorCount, uniformBinding.stageFlags, - DescriptorBuffer::create(bufferInfoList, uniformBinding.binding, dstArrayElement, uniformBinding.descriptorType)); + // create uniform or storage buffer, associated DescriptorSets and binding + return assignDescriptor(bufferBinding.set, bufferBinding.binding, bufferBinding.descriptorType, bufferBinding.descriptorCount, bufferBinding.stageFlags, + DescriptorBuffer::create(bufferInfoList, bufferBinding.binding, dstArrayElement, bufferBinding.descriptorType)); } return false; } +/// deprecated: use DescriptorConfigurator::assignDescriptorBuffer() instead. +bool DescriptorConfigurator::assignUniform(const std::string& name, const BufferInfoList& bufferInfoList, uint32_t dstArrayElement) +{ + warn("DescriptorConfigurator::assignUniform() has been deprecated." + " Use DescriptorConfigurator::assignDescriptorBuffer() instead."); + return assignDescriptorBuffer(name, bufferInfoList, dstArrayElement); +} + bool DescriptorConfigurator::assignDescriptor(uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr descriptor) { if (auto currentSize = descriptorSets.size(); set >= currentSize) @@ -223,14 +248,14 @@ bool DescriptorConfigurator::assignDefaults() bool assignedDefault = false; if (shaderSet) { - for (auto& uniformBinding : shaderSet->uniformBindings) + for (auto& descriptorBinding : shaderSet->descriptorBindings) { - if (uniformBinding.define.empty() && assigned.count(uniformBinding.name) == 0) + if (descriptorBinding.define.empty() && assigned.count(descriptorBinding.name) == 0) { bool set_matched = false; for (auto& cds : shaderSet->customDescriptorSetBindings) { - if (cds->set == uniformBinding.set) + if (cds->set == descriptorBinding.set) { set_matched = true; break; @@ -239,7 +264,7 @@ bool DescriptorConfigurator::assignDefaults() if (!set_matched) { bool isTexture = false; - switch (uniformBinding.descriptorType) + switch (descriptorBinding.descriptorType) { case (VK_DESCRIPTOR_TYPE_SAMPLER): case (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER): @@ -253,16 +278,16 @@ bool DescriptorConfigurator::assignDefaults() if (isTexture) { - assignDescriptor(uniformBinding.set, uniformBinding.binding, uniformBinding.descriptorType, uniformBinding.descriptorCount, uniformBinding.stageFlags, - DescriptorImage::create(Sampler::create(), uniformBinding.data, uniformBinding.binding, 0, uniformBinding.descriptorType)); + assignDescriptor(descriptorBinding.set, descriptorBinding.binding, descriptorBinding.descriptorType, descriptorBinding.descriptorCount, descriptorBinding.stageFlags, + DescriptorImage::create(Sampler::create(), descriptorBinding.data, descriptorBinding.binding, 0, descriptorBinding.descriptorType)); } else { - assignDescriptor(uniformBinding.set, uniformBinding.binding, uniformBinding.descriptorType, uniformBinding.descriptorCount, uniformBinding.stageFlags, - DescriptorBuffer::create(uniformBinding.data, uniformBinding.binding)); + assignDescriptor(descriptorBinding.set, descriptorBinding.binding, descriptorBinding.descriptorType, descriptorBinding.descriptorCount, descriptorBinding.stageFlags, + DescriptorBuffer::create(descriptorBinding.data, descriptorBinding.binding, 0, descriptorBinding.descriptorType)); } - assigned.insert(uniformBinding.name); + assigned.insert(descriptorBinding.name); assignedDefault = true; } } @@ -401,10 +426,18 @@ bool GraphicsPipelineConfigurator::enableTexture(const std::string& name) return descriptorConfigurator->enableTexture(name); } -bool GraphicsPipelineConfigurator::enableUniform(const std::string& name) +bool GraphicsPipelineConfigurator::enableDescriptorBuffer(const std::string& name) { if (!descriptorConfigurator) descriptorConfigurator = DescriptorConfigurator::create(shaderSet); - return descriptorConfigurator->enableUniform(name); + return descriptorConfigurator->enableDescriptorBuffer(name); +} + +/// deprecated: use GraphicsPipelineConfigurator::enableDescriptorBuffer() instead +bool GraphicsPipelineConfigurator::enableUniform(const std::string& name) +{ + warn("GraphicsPipelineConfigurator::enableUniform() has been deprecated." + " use GraphicsPipelineConfigurator::enableDescriptorBuffer() instead."); + return enableDescriptorBuffer(name); } bool GraphicsPipelineConfigurator::assignArray(DataList& arrays, const std::string& name, VkVertexInputRate vertexInputRate, ref_ptr array) @@ -429,10 +462,18 @@ bool GraphicsPipelineConfigurator::assignTexture(const std::string& name, ref_pt return descriptorConfigurator->assignTexture(name, textureData, sampler); } -bool GraphicsPipelineConfigurator::assignUniform(const std::string& name, ref_ptr data) +bool GraphicsPipelineConfigurator::assignDescriptorBuffer(const std::string& name, ref_ptr data) { if (!descriptorConfigurator) descriptorConfigurator = DescriptorConfigurator::create(shaderSet); - return descriptorConfigurator->assignUniform(name, data); + return descriptorConfigurator->assignDescriptorBuffer(name, data); +} + +/// deprecated: use GraphicsPipelineConfigurator::assignDescriptorBuffer() instead +bool GraphicsPipelineConfigurator::assignUniform(const std::string& name, ref_ptr data) +{ + warn("GraphicsPipelineConfigurator::assignUniform() has been deprecated." + " use GraphicsPipelineConfigurator::assignDescriptorBuffer() instead."); + return assignDescriptorBuffer(name, data); } int GraphicsPipelineConfigurator::compare(const Object& rhs_object) const diff --git a/src/vsg/utils/ShaderSet.cpp b/src/vsg/utils/ShaderSet.cpp index 1fe134644..699a1c71a 100644 --- a/src/vsg/utils/ShaderSet.cpp +++ b/src/vsg/utils/ShaderSet.cpp @@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include #include #include #include @@ -47,7 +48,7 @@ int AttributeBinding::compare(const AttributeBinding& rhs) const return compare_pointer(data, rhs.data); } -int UniformBinding::compare(const UniformBinding& rhs) const +int DescriptorBinding::compare(const DescriptorBinding& rhs) const { if (name < rhs.name) return -1; if (name > rhs.name) return 1; @@ -174,9 +175,17 @@ void ShaderSet::addAttributeBinding(std::string name, std::string define, uint32 attributeBindings.push_back(AttributeBinding{name, define, location, format, data}); } +void ShaderSet::addDescriptorBinding(std::string name, std::string define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr data) +{ + descriptorBindings.push_back(DescriptorBinding{name, define, set, binding, descriptorType, descriptorCount, stageFlags, data}); +} + +/// deprecated: use ShaderSet::addDescriptorBinding() instead void ShaderSet::addUniformBinding(std::string name, std::string define, uint32_t set, uint32_t binding, VkDescriptorType descriptorType, uint32_t descriptorCount, VkShaderStageFlags stageFlags, ref_ptr data) { - uniformBindings.push_back(UniformBinding{name, define, set, binding, descriptorType, descriptorCount, stageFlags, data}); + warn("ShaderSet::addUniformBinding() has been deprecated." + " use ShaderSet::addDescriptorBinding() instead."); + return addDescriptorBinding(name, define, set, binding, descriptorType, descriptorCount, stageFlags, data); } void ShaderSet::addPushConstantRange(std::string name, std::string define, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size) @@ -193,13 +202,21 @@ const AttributeBinding& ShaderSet::getAttributeBinding(const std::string& name) return _nullAttributeBinding; } -UniformBinding& ShaderSet::getUniformBinding(const std::string& name) +DescriptorBinding& ShaderSet::getDescriptorBinding(const std::string& name) { - for (auto& binding : uniformBindings) + for (auto& binding : descriptorBindings) { if (binding.name == name) return binding; } - return _nullUniformBinding; + return _nullDescriptorBinding; +} + +/// deprecated: use ShaderSet::getDescriptorBinding() instead +DescriptorBinding& ShaderSet::getUniformBinding(const std::string& name) +{ + warn("ShaderSet::getUniformBinding() has been deprecated." + " use ShaderSet::getDescriptorBinding() instead."); + return getDescriptorBinding(name); } AttributeBinding& ShaderSet::getAttributeBinding(const std::string& name) @@ -211,13 +228,21 @@ AttributeBinding& ShaderSet::getAttributeBinding(const std::string& name) return _nullAttributeBinding; } -const UniformBinding& ShaderSet::getUniformBinding(const std::string& name) const +const DescriptorBinding& ShaderSet::getDescriptorBinding(const std::string& name) const { - for (auto& binding : uniformBindings) + for (auto& binding : descriptorBindings) { if (binding.name == name) return binding; } - return _nullUniformBinding; + return _nullDescriptorBinding; +} + +/// deprecated: use ShaderSet::getDescriptorBinding() instead. +const DescriptorBinding& ShaderSet::getUniformBinding(const std::string& name) const +{ + warn("ShaderSet::getUniformBinding() has been deprecated." + " use ShaderSet::getDescriptorBinding() instead."); + return getDescriptorBinding(name); } ref_ptr ShaderSet::getSuitableArrayState(const std::set& defines) const @@ -289,7 +314,7 @@ int ShaderSet::compare(const Object& rhs_object) const auto& rhs = static_cast(rhs_object); if ((result = compare_pointer_container(stages, rhs.stages))) return result; if ((result = compare_container(attributeBindings, rhs.attributeBindings))) return result; - if ((result = compare_container(uniformBindings, rhs.uniformBindings))) return result; + if ((result = compare_container(descriptorBindings, rhs.descriptorBindings))) return result; if ((result = compare_container(pushConstantRanges, rhs.pushConstantRanges))) return result; if ((result = compare_container(definesArrayStates, rhs.definesArrayStates))) return result; if ((result = compare_container(optionalDefines, rhs.optionalDefines))) return result; @@ -318,9 +343,14 @@ void ShaderSet::read(Input& input) input.readObject("data", binding.data); } - auto num_uniformBindings = input.readValue("uniformBindings"); - uniformBindings.resize(num_uniformBindings); - for (auto& binding : uniformBindings) + std::string descriptorBindingsName{"descriptorBindings"}; + if (input.version_less(1, 0, 10)) + { + descriptorBindingsName = "uniformBindings"; + } + auto num_descriptorBindings = input.readValue(descriptorBindingsName.c_str()); + descriptorBindings.resize(num_descriptorBindings); + for (auto& binding : descriptorBindings) { input.read("name", binding.name); input.read("define", binding.define); @@ -397,8 +427,13 @@ void ShaderSet::write(Output& output) const output.writeObject("data", binding.data); } - output.writeValue("uniformBindings", uniformBindings.size()); - for (auto& binding : uniformBindings) + std::string descriptorBindingsName{"descriptorBindings"}; + if (output.version_less(1, 0, 10)) + { + descriptorBindingsName = "uniformBindings"; + } + output.writeValue(descriptorBindingsName.c_str(), descriptorBindings.size()); + for (auto& binding : descriptorBindings) { output.write("name", binding.name); output.write("define", binding.define); @@ -481,12 +516,12 @@ ref_ptr vsg::createPhysicsBasedRenderingShaderSet(ref_ptr ShaderSet::descriptorSetRange() const { - if (uniformBindings.empty()) return {0, 0}; + if (descriptorBindings.empty()) return {0, 0}; uint32_t minimum = std::numeric_limits::max(); uint32_t maximum = std::numeric_limits::min(); - for (auto& binding : uniformBindings) + for (auto& binding : descriptorBindings) { if (binding.set < minimum) minimum = binding.set; if (binding.set > maximum) maximum = binding.set; @@ -498,7 +533,7 @@ std::pair ShaderSet::descriptorSetRange() const ref_ptr ShaderSet::createDescriptorSetLayout(const std::set& defines, uint32_t set) const { DescriptorSetLayoutBindings bindings; - for (auto& binding : uniformBindings) + for (auto& binding : descriptorBindings) { if (binding.set == set) {