diff --git a/CMakeLists.txt b/CMakeLists.txt index 02a3e047f..78dd44c85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.10) project(vsg - VERSION 1.1.15 + VERSION 1.1.16 DESCRIPTION "VulkanSceneGraph library" LANGUAGES CXX ) diff --git a/include/vsg/app/CompileManager.h b/include/vsg/app/CompileManager.h index fefdd3e25..e6f635280 100644 --- a/include/vsg/app/CompileManager.h +++ b/include/vsg/app/CompileManager.h @@ -82,7 +82,7 @@ namespace vsg CompileResult compile(ref_ptr object, ContextSelectionFunction contextSelection = {}); /// compile all the command graphs in a task - CompileResult compileTask(ref_ptr task, const ResourceRequirements& resourceRequirements = {}); + CompileResult compileTask(ref_ptr task, ResourceRequirements& resourceRequirements); /// mechanism for releasing and reusing used resources ref_ptr resourceScavenger; diff --git a/include/vsg/core/Array.h b/include/vsg/core/Array.h index ec70eb428..2c8fe6fc0 100644 --- a/include/vsg/core/Array.h +++ b/include/vsg/core/Array.h @@ -392,6 +392,8 @@ namespace vsg VSG_array(ushortArray, uint16_t); VSG_array(intArray, int32_t); VSG_array(uintArray, uint32_t); + VSG_array(int64Array, int64_t); + VSG_array(uint64Array, uint64_t); VSG_array(floatArray, float); VSG_array(doubleArray, double); diff --git a/include/vsg/core/Value.h b/include/vsg/core/Value.h index a5c02bd70..e5a5df9c5 100644 --- a/include/vsg/core/Value.h +++ b/include/vsg/core/Value.h @@ -208,8 +208,14 @@ namespace vsg VSG_value(pathValue, vsg::Path); VSG_value(boolValue, bool); - VSG_value(intValue, int); - VSG_value(uintValue, unsigned int); + VSG_value(byteValue, int8_t); + VSG_value(ubyteValue, uint8_t); + VSG_value(shortValue, int16_t); + VSG_value(ushortValue, uint16_t); + VSG_value(intValue, int32_t); + VSG_value(uintValue, uint32_t); + VSG_value(int64Value, int64_t); + VSG_value(uint64Value, uint64_t); VSG_value(floatValue, float); VSG_value(doubleValue, double); diff --git a/include/vsg/utils/GraphicsPipelineConfigurator.h b/include/vsg/utils/GraphicsPipelineConfigurator.h index cde9b24f5..f4d1e0b7c 100644 --- a/include/vsg/utils/GraphicsPipelineConfigurator.h +++ b/include/vsg/utils/GraphicsPipelineConfigurator.h @@ -37,6 +37,9 @@ namespace vsg { public: explicit DescriptorConfigurator(ref_ptr in_shaderSet = {}); + explicit DescriptorConfigurator(const DescriptorConfigurator& rhs, const CopyOp& copyop = {}); + + ref_ptr clone(const CopyOp& copyop = {}) const override { return DescriptorConfigurator::create(*this, copyop); } ref_ptr shaderSet; bool blending = false; @@ -76,6 +79,9 @@ namespace vsg { public: explicit ArrayConfigurator(ref_ptr in_shaderSet = {}); + explicit ArrayConfigurator(const ArrayConfigurator& rhs, const CopyOp& copyop = {}); + + ref_ptr clone(const CopyOp& copyop = {}) const override { return ArrayConfigurator::create(*this, copyop); } ref_ptr shaderSet; @@ -132,6 +138,7 @@ namespace vsg ref_ptr shaderHints; ref_ptr descriptorConfigurator; StateCommands inheritedState; + std::map vertexInputRates; int compare(const Object& rhs) const override; diff --git a/include/vsg/utils/ShaderSet.h b/include/vsg/utils/ShaderSet.h index fe4c74f0e..7bf1094ae 100644 --- a/include/vsg/utils/ShaderSet.h +++ b/include/vsg/utils/ShaderSet.h @@ -128,6 +128,19 @@ namespace vsg GraphicsPipelineStates defaultGraphicsPipelineStates; std::vector> customDescriptorSetBindings; + /// Hints mask for scene graph builders for what ShaderSet prefers/requires. + enum GeometryHints + { + NO_PREFERENCE = 0, + GEOMETRY = 1 << 0, + VERTEXDRAW = 1 << 1, + VERTEXINDEXDRAW = 1 << 2, + DRAWMESHTASKS = 1 << 3, + MESHLETS = 1 << 4 + }; + + int geometryHints = GeometryHints::NO_PREFERENCE; + ref_ptr defaultShaderHints; /// variants of the rootShaderModule compiled for different combinations of ShaderCompileSettings std::map, ShaderStages, DereferenceLess> variants; diff --git a/src/vsg/app/CompileManager.cpp b/src/vsg/app/CompileManager.cpp index 0db9a10a5..55a1c53c6 100644 --- a/src/vsg/app/CompileManager.cpp +++ b/src/vsg/app/CompileManager.cpp @@ -350,7 +350,7 @@ CompileResult CompileManager::compile(ref_ptr object, ContextSelectionFu return result; } -CompileResult CompileManager::compileTask(ref_ptr task, const ResourceRequirements& resourceRequirements) +CompileResult CompileManager::compileTask(ref_ptr task, ResourceRequirements& resourceRequirements) { CompileResult result; @@ -360,6 +360,7 @@ CompileResult CompileManager::compileTask(ref_ptr task, con try { auto compileTraversal = CompileTraversal::create(task->device, resourceRequirements); + auto deviceMemoryBufferPools = task->device->deviceMemoryBufferPools.ref_ptr(); for (const auto& context : compileTraversal->contexts) { @@ -369,6 +370,14 @@ CompileResult CompileManager::compileTask(ref_ptr task, con } } + if (deviceMemoryBufferPools && deviceMemoryBufferPools->compileTraversalUseReserve) + { + for (auto& context : compileTraversal->contexts) + { + context->reserve(resourceRequirements); + } + } + for (auto& cg : task->commandGraphs) { cg->accept(*compileTraversal); diff --git a/src/vsg/io/ObjectFactory.cpp b/src/vsg/io/ObjectFactory.cpp index 0f261bbf0..f8842b844 100644 --- a/src/vsg/io/ObjectFactory.cpp +++ b/src/vsg/io/ObjectFactory.cpp @@ -36,8 +36,14 @@ ObjectFactory::ObjectFactory() add(); add(); add(); + add(); + add(); + add(); + add(); add(); add(); + add(); + add(); add(); add(); add(); @@ -75,6 +81,8 @@ ObjectFactory::ObjectFactory() add(); add(); add(); + add(); + add(); add(); add(); add(); diff --git a/src/vsg/io/glsl.cpp b/src/vsg/io/glsl.cpp index c9fa89562..3b6398719 100644 --- a/src/vsg/io/glsl.cpp +++ b/src/vsg/io/glsl.cpp @@ -34,7 +34,8 @@ namespace {".rmiss", VK_SHADER_STAGE_MISS_BIT_KHR}, {".rcall", VK_SHADER_STAGE_CALLABLE_BIT_KHR}, {".glsl", VK_SHADER_STAGE_ALL}, - {".hlsl", VK_SHADER_STAGE_ALL}}; + {".hlsl", VK_SHADER_STAGE_ALL}, + {".h", VK_SHADER_STAGE_ALL}}; } // namespace glsl::glsl() diff --git a/src/vsg/utils/GraphicsPipelineConfigurator.cpp b/src/vsg/utils/GraphicsPipelineConfigurator.cpp index 0a5a69827..8094d056d 100644 --- a/src/vsg/utils/GraphicsPipelineConfigurator.cpp +++ b/src/vsg/utils/GraphicsPipelineConfigurator.cpp @@ -94,6 +94,17 @@ DescriptorConfigurator::DescriptorConfigurator(ref_ptr in_shaderSet) { } +DescriptorConfigurator::DescriptorConfigurator(const DescriptorConfigurator& rhs, const CopyOp& copyop) : + Inherit(rhs, copyop), + shaderSet(rhs.shaderSet), + blending(rhs.blending), + two_sided(rhs.two_sided), + assigned(rhs.assigned), + defines(rhs.defines), + descriptorSets(rhs.descriptorSets) +{ +} + int DescriptorConfigurator::compare(const Object& rhs_object) const { int result = Object::compare(rhs_object); @@ -263,6 +274,14 @@ bool DescriptorConfigurator::assignDescriptor(uint32_t set, uint32_t binding, Vk ds->setLayout = DescriptorSetLayout::create(); } + for(const auto& layout_binding : ds->setLayout->bindings) + { + if (layout_binding.binding == binding) + { + return false; + } + } + ds->descriptors.push_back(descriptor); auto& descriptorBindings = ds->setLayout->bindings; @@ -339,6 +358,18 @@ ArrayConfigurator::ArrayConfigurator(ref_ptr in_shaderSet) : { } +ArrayConfigurator::ArrayConfigurator(const ArrayConfigurator& rhs, const CopyOp& copyop) : + Inherit(rhs, copyop), + shaderSet(rhs.shaderSet), + baseAttributeBinding(rhs.baseAttributeBinding), + assigned(rhs.assigned), + defines(rhs.defines), + vertexBindingDescriptions(rhs.vertexBindingDescriptions), + vertexAttributeDescriptions(rhs.vertexAttributeDescriptions), + arrays(rhs.arrays) +{ +} + int ArrayConfigurator::compare(const Object& rhs_object) const { int result = Object::compare(rhs_object); @@ -427,6 +458,9 @@ void GraphicsPipelineConfigurator::reset() shaderHints->defines.clear(); if (descriptorConfigurator) descriptorConfigurator->reset(); + vertexInputRates.clear(); + + _assignShaderSetSettings(); } @@ -456,8 +490,7 @@ struct SetPipelineStates : public Visitor bool GraphicsPipelineConfigurator::enableArray(const std::string& name, VkVertexInputRate vertexInputRate, uint32_t stride, VkFormat format) { - auto& attributeBinding = shaderSet->getAttributeBinding(name); - if (attributeBinding) + if (auto& attributeBinding = shaderSet->getAttributeBinding(name)) { if (!attributeBinding.define.empty()) shaderHints->defines.insert(attributeBinding.define); @@ -465,6 +498,13 @@ bool GraphicsPipelineConfigurator::enableArray(const std::string& name, VkVertex accept(setVertexAttributeState); return true; } + + if (const auto& descriptorBinding = shaderSet->getDescriptorBinding(name)) + { + enableDescriptor(name); + vertexInputRates[descriptorBinding.binding] = vertexInputRate; + } + return false; } @@ -482,8 +522,7 @@ bool GraphicsPipelineConfigurator::enableDescriptor(const std::string& name) bool GraphicsPipelineConfigurator::assignArray(DataList& arrays, const std::string& name, VkVertexInputRate vertexInputRate, ref_ptr array) { - const auto& attributeBinding = shaderSet->getAttributeBinding(name); - if (attributeBinding) + if (const auto& attributeBinding = shaderSet->getAttributeBinding(name)) { if (!attributeBinding.define.empty()) shaderHints->defines.insert(attributeBinding.define); @@ -495,6 +534,13 @@ bool GraphicsPipelineConfigurator::assignArray(DataList& arrays, const std::stri arrays.push_back(array); return true; } + + if (const auto& descriptorBinding = shaderSet->getDescriptorBinding(name)) + { + assignDescriptor(name, array, 0); + vertexInputRates[descriptorBinding.binding] = vertexInputRate; + } + return false; } @@ -740,6 +786,25 @@ void GraphicsPipelineConfigurator::_assignInheritedSets() void GraphicsPipelineConfigurator::init() { + if (!vertexInputRates.empty()) + { + if (const auto& descriptorBinding = shaderSet->getDescriptorBinding("vertexInputRates")) + { + auto vir = vsg::uintArray::create(vertexInputRates.rbegin()->first+1, 0); + for(auto [binding, rate] : vertexInputRates) + { + vir->set(binding, rate); + } + + assignDescriptor(descriptorBinding.name, vir, 0); + } + else + { + vsg::warn("GraphicsPipelineConfigurator::init() - missing DescriptorBinding for vertexInputRates."); + + } + } + _assignInheritedSets(); if (descriptorConfigurator) @@ -785,45 +850,123 @@ bool GraphicsPipelineConfigurator::copyTo(StateCommands& stateCommands, ref_ptr< if (descriptorConfigurator) { - for (size_t set = 0; set < descriptorConfigurator->descriptorSets.size(); ++set) + struct DisableInheritedState : public Visitor { - if (auto ds = descriptorConfigurator->descriptorSets[set]) + DescriptorSets descritorSets; + + DisableInheritedState(DescriptorConfigurator& dc) : + descritorSets(dc.descriptorSets.size()) { - auto bindDescriptorSet = BindDescriptorSet::create(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, static_cast(set), ds); + for (size_t set = 0; set < dc.descriptorSets.size(); ++set) + { + descritorSets[set] = dc.descriptorSets[set]; + } + } - bool dsUnique = true; - for (const auto& sc : inheritedState) + void apply(BindViewDescriptorSets& bvds) override + { + if (bvds.firstSet < static_cast(descritorSets.size())) { - if (compare_pointer(sc, bindDescriptorSet) == 0) dsUnique = false; + descritorSets[bvds.firstSet].reset(); } + } - if (dsUnique) + void apply(BindDescriptorSet& bds) override + { + if (bds.firstSet < static_cast(descritorSets.size())) { - if (sharedObjects) + descritorSets[bds.firstSet].reset(); + } + } + + void apply(BindDescriptorSets& bds) override + { + if (bds.firstSet < static_cast(descritorSets.size())) + { + uint32_t end_set = bds.firstSet + static_cast(bds.descriptorSets.size()); + for(uint32_t set = bds.firstSet; set < end_set; ++set) + { + descritorSets[set].reset(); + } + } + } + } active(*descriptorConfigurator); + + for (const auto& sc : inheritedState) + { + sc->accept(active); + } + + if (sharedObjects) + { + for(auto& ds : active.descritorSets) + { + if (ds) + { + for (auto& descriptor : ds->descriptors) { - for (auto& descriptor : ds->descriptors) + if (auto descriptor_image = descriptor.cast()) { - if (auto descriptor_image = descriptor.cast()) + for (auto& image_info : descriptor_image->imageInfoList) { - for (auto& image_info : descriptor_image->imageInfoList) + if (image_info->imageView && image_info->imageView->image) { - if (image_info->imageView && image_info->imageView->image) - { - sharedObjects->share(image_info->imageView->image); - } + sharedObjects->share(image_info->imageView->image); } } - sharedObjects->share(descriptor); } - sharedObjects->share(ds->setLayout); - sharedObjects->share(ds); + sharedObjects->share(descriptor); + } + sharedObjects->share(ds->setLayout); + sharedObjects->share(ds); + } + } + } + + for(uint32_t set = 0; set < active.descritorSets.size();) + { + if (active.descritorSets[set]) + { + uint32_t last = set+1; + for(; (last < active.descritorSets.size()) && active.descritorSets[last]; ++last) {} + + if ((last-set) == 1) + { + auto bindDescriptorSet = BindDescriptorSet::create(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, static_cast(set), active.descritorSets[set]); + + if (sharedObjects) + { sharedObjects->share(bindDescriptorSet); } stateCommands.push_back(bindDescriptorSet); stateAssigned = true; } - } + else + { + DescriptorSets descriptorSets; + for(auto si = set; si(set), descriptorSets); + + if (sharedObjects) + { + sharedObjects->share(bindDescriptorSets); + } + + stateCommands.push_back(bindDescriptorSets); + stateAssigned = true; + } + + set = last; + } + else + { + ++set; + } } } diff --git a/src/vsg/utils/ShaderSet.cpp b/src/vsg/utils/ShaderSet.cpp index 1313b6d5b..340a5cb8e 100644 --- a/src/vsg/utils/ShaderSet.cpp +++ b/src/vsg/utils/ShaderSet.cpp @@ -294,7 +294,8 @@ int ShaderSet::compare(const Object& rhs_object) const 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; - return compare_pointer_container(defaultGraphicsPipelineStates, rhs.defaultGraphicsPipelineStates); + if ((result = compare_pointer_container(defaultGraphicsPipelineStates, rhs.defaultGraphicsPipelineStates))) return result; + return compare_value(geometryHints, rhs.geometryHints); } void ShaderSet::read(Input& input) @@ -377,6 +378,11 @@ void ShaderSet::read(Input& input) } } } + + if (input.version_greater_equal(1, 1, 16)) + { + input.readValue("geometryHints", geometryHints); + } } void ShaderSet::write(Output& output) const @@ -450,6 +456,11 @@ void ShaderSet::write(Output& output) const output.writeObject("customDescriptorSetBinding", custom); } } + + if (output.version_greater_equal(1, 1, 16)) + { + output.writeValue("geometryHints", geometryHints); + } } ref_ptr vsg::createFlatShadedShaderSet(ref_ptr options)