diff --git a/build/build_all_h.cmake b/build/build_all_h.cmake index d1289e2835..0f71ec31a8 100644 --- a/build/build_all_h.cmake +++ b/build/build_all_h.cmake @@ -25,7 +25,7 @@ macro(BUILD_ALL_H) file(GLOB COMMANDS_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/include include/vsg/commands/*.h ) file(GLOB STATE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/include include/vsg/state/*.h ) file(GLOB TEXT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/include include/vsg/text/*.h ) - file(GLOB RAYTRACING_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/include include/vsg/raytracing/*.h ) + file(GLOB RTX_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/include include/vsg/rtx/*.h ) file(READ ${CMAKE_CURRENT_SOURCE_DIR}/build/header_license_preamble.txt ALL_H_CONTENTS) APPEND_INCLUDES(ALL_H_CONTENTS CORE_HEADERS "// Core header files\n") @@ -42,7 +42,7 @@ macro(BUILD_ALL_H) APPEND_INCLUDES(ALL_H_CONTENTS UTILS_HEADERS "// Utility header files\n") APPEND_INCLUDES(ALL_H_CONTENTS INTROSPECTION_HEADERS "// Introspection header files\n") APPEND_INCLUDES(ALL_H_CONTENTS TEXT_HEADERS "// Text header files\n") - APPEND_INCLUDES(ALL_H_CONTENTS RAYTRACING_HEADERS "// Raytracing header files\n") + APPEND_INCLUDES(ALL_H_CONTENTS RTX_HEADERS "// RTX mesh and ray tracing header files\n") file(WRITE include/vsg/all.h ${ALL_H_CONTENTS}) diff --git a/include/vsg/README.md b/include/vsg/README.md index 5ba1750444..c222769adc 100644 --- a/include/vsg/README.md +++ b/include/vsg/README.md @@ -22,7 +22,7 @@ The headers that provide the library classes and definitions are organized in su ## Scene graphs nodes * [include/vsg/nodes](nodes/) - Scene graph node classes * [include/vsg/text](text/) - Scene graph node classes that provide high quality Text support -* [include/vsg/raytracing](raytracing/) - Raytracing related scene graph classes +* [include/vsg/rtx](rtx/) - RTX Raytracing and mesh shader related scene graph classes ## Application level * [include/vsg/traversals](traversals/) - Graph traversals diff --git a/include/vsg/all.h b/include/vsg/all.h index 183f85d29c..0966c16b03 100644 --- a/include/vsg/all.h +++ b/include/vsg/all.h @@ -216,13 +216,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include -// Raytracing header files -#include -#include -#include -#include -#include -#include -#include -#include -#include +// RTX mesh and ray tracing header files +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/vsg/core/ConstVisitor.h b/include/vsg/core/ConstVisitor.h index 1c874b4961..b1b06840f4 100644 --- a/include/vsg/core/ConstVisitor.h +++ b/include/vsg/core/ConstVisitor.h @@ -70,6 +70,11 @@ namespace vsg class ResourceHints; class ClearAttachments; + // forward declare rtx classes + class DrawMeshTasks; + class DrawMeshTasksIndirect; + class DrawMeshTasksIndirectCount; + // forward declare ui events classes class UIEvent; class WindowEvent; @@ -255,6 +260,11 @@ namespace vsg virtual void apply(const DrawIndexed&); virtual void apply(const ClearAttachments&); + // rtx classes + virtual void apply(const DrawMeshTasks&); + virtual void apply(const DrawMeshTasksIndirect&); + virtual void apply(const DrawMeshTasksIndirectCount&); + // ui events virtual void apply(const UIEvent&); virtual void apply(const WindowEvent&); diff --git a/include/vsg/core/Visitor.h b/include/vsg/core/Visitor.h index fb5477b955..6ab1c65665 100644 --- a/include/vsg/core/Visitor.h +++ b/include/vsg/core/Visitor.h @@ -70,6 +70,11 @@ namespace vsg class ResourceHints; class ClearAttachments; + // forward declare rtx classes + class DrawMeshTasks; + class DrawMeshTasksIndirect; + class DrawMeshTasksIndirectCount; + // forward declare ui events classes class UIEvent; class WindowEvent; @@ -255,6 +260,11 @@ namespace vsg virtual void apply(DrawIndexed&); virtual void apply(ClearAttachments&); + // rtx classes + virtual void apply(DrawMeshTasks&); + virtual void apply(DrawMeshTasksIndirect&); + virtual void apply(DrawMeshTasksIndirectCount&); + // ui events virtual void apply(UIEvent&); virtual void apply(WindowEvent&); diff --git a/include/vsg/raytracing/AccelerationGeometry.h b/include/vsg/rtx/AccelerationGeometry.h similarity index 100% rename from include/vsg/raytracing/AccelerationGeometry.h rename to include/vsg/rtx/AccelerationGeometry.h diff --git a/include/vsg/raytracing/AccelerationStructure.h b/include/vsg/rtx/AccelerationStructure.h similarity index 100% rename from include/vsg/raytracing/AccelerationStructure.h rename to include/vsg/rtx/AccelerationStructure.h diff --git a/include/vsg/raytracing/BottomLevelAccelerationStructure.h b/include/vsg/rtx/BottomLevelAccelerationStructure.h similarity index 94% rename from include/vsg/raytracing/BottomLevelAccelerationStructure.h rename to include/vsg/rtx/BottomLevelAccelerationStructure.h index eec13c93b1..33b8d43f4a 100644 --- a/include/vsg/raytracing/BottomLevelAccelerationStructure.h +++ b/include/vsg/rtx/BottomLevelAccelerationStructure.h @@ -12,8 +12,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include -#include +#include +#include namespace vsg { diff --git a/include/vsg/raytracing/BuildAccelerationStructureTraversal.h b/include/vsg/rtx/BuildAccelerationStructureTraversal.h similarity index 93% rename from include/vsg/raytracing/BuildAccelerationStructureTraversal.h rename to include/vsg/rtx/BuildAccelerationStructureTraversal.h index e01fee8c79..1b197c7a21 100644 --- a/include/vsg/raytracing/BuildAccelerationStructureTraversal.h +++ b/include/vsg/rtx/BuildAccelerationStructureTraversal.h @@ -21,9 +21,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include -#include -#include -#include +#include +#include +#include namespace vsg { diff --git a/include/vsg/raytracing/DescriptorAccelerationStructure.h b/include/vsg/rtx/DescriptorAccelerationStructure.h similarity index 97% rename from include/vsg/raytracing/DescriptorAccelerationStructure.h rename to include/vsg/rtx/DescriptorAccelerationStructure.h index 5438db53e9..26aa7637b6 100644 --- a/include/vsg/raytracing/DescriptorAccelerationStructure.h +++ b/include/vsg/rtx/DescriptorAccelerationStructure.h @@ -12,7 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include +#include #include namespace vsg diff --git a/include/vsg/rtx/DrawMeshTasks.h b/include/vsg/rtx/DrawMeshTasks.h new file mode 100644 index 0000000000..2d8a4e3f5a --- /dev/null +++ b/include/vsg/rtx/DrawMeshTasks.h @@ -0,0 +1,37 @@ +#pragma once + +/* + +Copyright(c) 2019 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include + +namespace vsg +{ + + class VSG_DECLSPEC DrawMeshTasks : public Inherit + { + public: + DrawMeshTasks(); + + DrawMeshTasks(uint32_t in_taskCount, uint32_t in_firstTask); + + void read(Input& input) override; + void write(Output& output) const override; + + void record(CommandBuffer& commandBuffer) const override; + + uint32_t taskCount = 0; + uint32_t firstTask = 0; + }; + VSG_type_name(vsg::DrawMeshTasks); + +} // namespace vsg diff --git a/include/vsg/rtx/DrawMeshTasksIndirect.h b/include/vsg/rtx/DrawMeshTasksIndirect.h new file mode 100644 index 0000000000..71b7431138 --- /dev/null +++ b/include/vsg/rtx/DrawMeshTasksIndirect.h @@ -0,0 +1,48 @@ +#pragma once + +/* + +Copyright(c) 2019 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include + +namespace vsg +{ + + class VSG_DECLSPEC DrawMeshTasksIndirect : public Inherit + { + public: + DrawMeshTasksIndirect(); + + DrawMeshTasksIndirect(ref_ptr data, uint32_t in_drawCount, uint32_t in_stride) : + buffer(data), + drawCount(in_drawCount), + stride(in_stride) {} + + DrawMeshTasksIndirect(ref_ptr in_buffer, VkDeviceSize in_offset, uint32_t in_drawCount, uint32_t in_stride) : + buffer(in_buffer, in_offset, in_drawCount * in_stride), + drawCount(in_drawCount), + stride(in_stride) {} + + void read(Input& input) override; + void write(Output& output) const override; + + void compile(Context& context) override; + void record(CommandBuffer& commandBuffer) const override; + + BufferInfo buffer; + uint32_t drawCount = 0; + uint32_t stride = 0; + }; + VSG_type_name(vsg::DrawMeshTasksIndirect); + +} // namespace vsg diff --git a/include/vsg/rtx/DrawMeshTasksIndirectCommand.h b/include/vsg/rtx/DrawMeshTasksIndirectCommand.h new file mode 100644 index 0000000000..a38806cd9f --- /dev/null +++ b/include/vsg/rtx/DrawMeshTasksIndirectCommand.h @@ -0,0 +1,45 @@ +#pragma once + +/* + +Copyright(c) 2018 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include +#include + +namespace vsg +{ + /// Equivalent to VkDrawMeshTasksIndirectCommandNV that adds read/write support + struct DrawMeshTasksIndirectCommand + { + uint32_t taskCount; + uint32_t firstTask; + + void read(vsg::Input& input) + { + input.read("taskCount", taskCount); + input.read("firstTask", firstTask); + } + + void write(vsg::Output& output) const + { + output.write("taskCount", taskCount); + output.write("firstTask", firstTask); + } + }; + + template<> + constexpr bool has_read_write() { return true; } + + VSG_array(DrawMeshTasksIndirectCommandArray, DrawMeshTasksIndirectCommand); + +} // namespace vsg diff --git a/include/vsg/rtx/DrawMeshTasksIndirectCount.h b/include/vsg/rtx/DrawMeshTasksIndirectCount.h new file mode 100644 index 0000000000..58f652f376 --- /dev/null +++ b/include/vsg/rtx/DrawMeshTasksIndirectCount.h @@ -0,0 +1,45 @@ +#pragma once + +/* + +Copyright(c) 2019 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include + +namespace vsg +{ + + class VSG_DECLSPEC DrawMeshTasksIndirectCount : public Inherit + { + public: + DrawMeshTasksIndirectCount(); + + DrawMeshTasksIndirectCount(ref_ptr in_bufferData, ref_ptr in_countBufferData, uint32_t in_maxDrawCount, uint32_t in_stride) : + buffer(in_bufferData), + countBuffer(in_countBufferData), + maxDrawCount(in_maxDrawCount), + stride(in_stride) {} + + void read(Input& input) override; + void write(Output& output) const override; + + void compile(Context& context) override; + void record(CommandBuffer& commandBuffer) const override; + + BufferInfo buffer; + BufferInfo countBuffer; + uint32_t maxDrawCount = 0; + uint32_t stride = 0; + }; + VSG_type_name(vsg::DrawMeshTasksIndirectCount); + +} // namespace vsg diff --git a/include/vsg/raytracing/README.md b/include/vsg/rtx/README.md similarity index 60% rename from include/vsg/raytracing/README.md rename to include/vsg/rtx/README.md index 68f48b7d34..e72798f6d4 100644 --- a/include/vsg/raytracing/README.md +++ b/include/vsg/rtx/README.md @@ -8,4 +8,8 @@ * [RayTracingPipeline.h](RayTracingPipeline.h) - * [RayTracingShaderGroup.h](RayTracingShaderGroup.h) - * [TopLevelAccelerationStructure.h](TopLevelAccelerationStructure.h) - -* [TraceRays.h](TraceRays.h) - +* [TraceRays.h](TraceRays.h) - encapsulation of vkCmdTraceRaysNV + +* [DrawMeshTasks.h](DrawMeshTasks.h) - encapsulation of vkCmdDrawMeshTasksNV +* [DrawMeshTasksIndirect.h](DrawMeshTasksIndirect.h) -encapsulation of vkCmdDrawMeshTasksIndirectNV +* [DrawMeshTasksIndirectCount.h](DrawMeshTasksIndirectCount.h) - encapsulation of vkCmdDrawMeshTasksIndirectCountNV diff --git a/include/vsg/raytracing/RayTracingPipeline.h b/include/vsg/rtx/RayTracingPipeline.h similarity index 98% rename from include/vsg/raytracing/RayTracingPipeline.h rename to include/vsg/rtx/RayTracingPipeline.h index 821726a0bb..290af8ac19 100644 --- a/include/vsg/raytracing/RayTracingPipeline.h +++ b/include/vsg/rtx/RayTracingPipeline.h @@ -12,7 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include +#include #include #include #include diff --git a/include/vsg/raytracing/RayTracingShaderGroup.h b/include/vsg/rtx/RayTracingShaderGroup.h similarity index 100% rename from include/vsg/raytracing/RayTracingShaderGroup.h rename to include/vsg/rtx/RayTracingShaderGroup.h diff --git a/include/vsg/raytracing/TopLevelAccelerationStructure.h b/include/vsg/rtx/TopLevelAccelerationStructure.h similarity index 97% rename from include/vsg/raytracing/TopLevelAccelerationStructure.h rename to include/vsg/rtx/TopLevelAccelerationStructure.h index c23286da2e..2b574aee8d 100644 --- a/include/vsg/raytracing/TopLevelAccelerationStructure.h +++ b/include/vsg/rtx/TopLevelAccelerationStructure.h @@ -14,8 +14,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include -#include -#include +#include +#include namespace vsg { diff --git a/include/vsg/raytracing/TraceRays.h b/include/vsg/rtx/TraceRays.h similarity index 97% rename from include/vsg/raytracing/TraceRays.h rename to include/vsg/rtx/TraceRays.h index b8435d10c2..c351d36a31 100644 --- a/include/vsg/raytracing/TraceRays.h +++ b/include/vsg/rtx/TraceRays.h @@ -13,7 +13,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include -#include +#include namespace vsg { diff --git a/include/vsg/vk/Context.h b/include/vsg/vk/Context.h index 3bbf50f36b..8a7f548390 100644 --- a/include/vsg/vk/Context.h +++ b/include/vsg/vk/Context.h @@ -114,7 +114,7 @@ namespace vsg ref_ptr deviceMemoryBufferPools; ref_ptr stagingMemoryBufferPools; - // raytracing + // RTX ray tracing VkDeviceSize scratchBufferSize; std::vector> buildAccelerationStructureCommands; }; diff --git a/include/vsg/vk/Extensions.h b/include/vsg/vk/Extensions.h index 58d20bc2a4..b57aef3d81 100644 --- a/include/vsg/vk/Extensions.h +++ b/include/vsg/vk/Extensions.h @@ -34,15 +34,20 @@ namespace vsg Extensions(Device* device); // VK_NV_ray_tracing - PFN_vkCreateAccelerationStructureNV vkCreateAccelerationStructureNV; - PFN_vkDestroyAccelerationStructureNV vkDestroyAccelerationStructureNV; - PFN_vkBindAccelerationStructureMemoryNV vkBindAccelerationStructureMemoryNV; - PFN_vkGetAccelerationStructureHandleNV vkGetAccelerationStructureHandleNV; - PFN_vkGetAccelerationStructureMemoryRequirementsNV vkGetAccelerationStructureMemoryRequirementsNV; - PFN_vkCmdBuildAccelerationStructureNV vkCmdBuildAccelerationStructureNV; - PFN_vkCreateRayTracingPipelinesNV vkCreateRayTracingPipelinesNV; - PFN_vkGetRayTracingShaderGroupHandlesNV vkGetRayTracingShaderGroupHandlesNV; - PFN_vkCmdTraceRaysNV vkCmdTraceRaysNV; + PFN_vkCreateAccelerationStructureNV vkCreateAccelerationStructureNV = nullptr; + PFN_vkDestroyAccelerationStructureNV vkDestroyAccelerationStructureNV = nullptr; + PFN_vkBindAccelerationStructureMemoryNV vkBindAccelerationStructureMemoryNV = nullptr; + PFN_vkGetAccelerationStructureHandleNV vkGetAccelerationStructureHandleNV = nullptr; + PFN_vkGetAccelerationStructureMemoryRequirementsNV vkGetAccelerationStructureMemoryRequirementsNV = nullptr; + PFN_vkCmdBuildAccelerationStructureNV vkCmdBuildAccelerationStructureNV = nullptr; + PFN_vkCreateRayTracingPipelinesNV vkCreateRayTracingPipelinesNV = nullptr; + PFN_vkGetRayTracingShaderGroupHandlesNV vkGetRayTracingShaderGroupHandlesNV = nullptr; + PFN_vkCmdTraceRaysNV vkCmdTraceRaysNV = nullptr; + + // VK_NV_mesh_shader + PFN_vkCmdDrawMeshTasksNV vkCmdDrawMeshTasksNV = nullptr; + PFN_vkCmdDrawMeshTasksIndirectNV vkCmdDrawMeshTasksIndirectNV = nullptr; + PFN_vkCmdDrawMeshTasksIndirectCountNV vkCmdDrawMeshTasksIndirectCountNV = nullptr; }; } // namespace vsg diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index ab3e237f3f..32045eed58 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -125,15 +125,18 @@ set(SOURCES viewer/WindowResizeHandler.cpp viewer/View.cpp - raytracing/AccelerationGeometry.cpp - raytracing/AccelerationStructure.cpp - raytracing/BottomLevelAccelerationStructure.cpp - raytracing/BuildAccelerationStructureTraversal.cpp - raytracing/DescriptorAccelerationStructure.cpp - raytracing/RayTracingPipeline.cpp - raytracing/RayTracingShaderGroup.cpp - raytracing/TopLevelAccelerationStructure.cpp - raytracing/TraceRays.cpp + rtx/AccelerationGeometry.cpp + rtx/AccelerationStructure.cpp + rtx/BottomLevelAccelerationStructure.cpp + rtx/BuildAccelerationStructureTraversal.cpp + rtx/DescriptorAccelerationStructure.cpp + rtx/RayTracingPipeline.cpp + rtx/RayTracingShaderGroup.cpp + rtx/TopLevelAccelerationStructure.cpp + rtx/TraceRays.cpp + rtx/DrawMeshTasks.cpp + rtx/DrawMeshTasksIndirect.cpp + rtx/DrawMeshTasksIndirectCount.cpp ui/UIEvent.cpp ui/ApplicationEvent.cpp diff --git a/src/vsg/README.md b/src/vsg/README.md index f53c461797..b5414a18cc 100644 --- a/src/vsg/README.md +++ b/src/vsg/README.md @@ -13,7 +13,7 @@ The implementations provided by the src/vsg directories mirror the structure of * [src/vsg/vk](vk) - classes that provide wrappers to high level Vulkan objects, providing robust resource management and convinient C++ style setup. * [src/vsg/state](state) - scene graph level classes that provude wrappers Vulkan object with setting Vulkan state such as Pipelines, Unfirorms and Textures. * [src/vsg/commands](commands) - scene graph level classes that proviide wrappers to vkCmd* Vulkan API calls. -* [src/vsg/raytracing](raytracing) - scene graph level classes that provide wrappes to Vulkan ray tracing extensions. +* [src/vsg/rtx](rtx) - scene graph level classes that provide wrappes to Vulkan RTX ray tracing and mesh shader extensions. ## Scene graphs nodes * [src/vsg/nodes](nodes) - scene graph node classes that provide the internal structure to the scene graph. diff --git a/src/vsg/core/ConstVisitor.cpp b/src/vsg/core/ConstVisitor.cpp index 5e2a2aad85..13222dec4e 100644 --- a/src/vsg/core/ConstVisitor.cpp +++ b/src/vsg/core/ConstVisitor.cpp @@ -595,6 +595,23 @@ void ConstVisitor::apply(const ClearAttachments& value) apply(static_cast(value)); } +//////////////////////////////////////////////////////////////////////////////// +// +// RTX +// +void ConstVisitor::apply(const DrawMeshTasks& dmt) +{ + apply(static_cast(dmt)); +} +void ConstVisitor::apply(const DrawMeshTasksIndirect& dmti) +{ + apply(static_cast(dmti)); +} +void ConstVisitor::apply(const DrawMeshTasksIndirectCount& dmtic) +{ + apply(static_cast(dmtic)); +} + //////////////////////////////////////////////////////////////////////////////// // // UI Events diff --git a/src/vsg/core/Visitor.cpp b/src/vsg/core/Visitor.cpp index 3e08db8243..8905ddc018 100644 --- a/src/vsg/core/Visitor.cpp +++ b/src/vsg/core/Visitor.cpp @@ -595,6 +595,23 @@ void Visitor::apply(ClearAttachments& value) apply(static_cast(value)); } +//////////////////////////////////////////////////////////////////////////////// +// +// RTX +// +void Visitor::apply(DrawMeshTasks& dmt) +{ + apply(static_cast(dmt)); +} +void Visitor::apply(DrawMeshTasksIndirect& dmti) +{ + apply(static_cast(dmti)); +} +void Visitor::apply(DrawMeshTasksIndirectCount& dmtic) +{ + apply(static_cast(dmtic)); +} + //////////////////////////////////////////////////////////////////////////////// // // UI Events diff --git a/src/vsg/io/ObjectFactory.cpp b/src/vsg/io/ObjectFactory.cpp index 4fee64e221..3e06c54ec5 100644 --- a/src/vsg/io/ObjectFactory.cpp +++ b/src/vsg/io/ObjectFactory.cpp @@ -239,6 +239,11 @@ ObjectFactory::ObjectFactory() VSG_REGISTER_create(vsg::KeyPressEvent); VSG_REGISTER_create(vsg::KeyReleaseEvent); + // rtx + VSG_REGISTER_create(vsg::DrawMeshTasks); + VSG_REGISTER_create(vsg::DrawMeshTasksIndirect); + VSG_REGISTER_create(vsg::DrawMeshTasksIndirectCommandArray); + // application VSG_REGISTER_create(vsg::EllipsoidModel); } diff --git a/src/vsg/raytracing/AccelerationGeometry.cpp b/src/vsg/rtx/AccelerationGeometry.cpp similarity index 98% rename from src/vsg/raytracing/AccelerationGeometry.cpp rename to src/vsg/rtx/AccelerationGeometry.cpp index 98fdbcd401..2c7c1e798f 100644 --- a/src/vsg/raytracing/AccelerationGeometry.cpp +++ b/src/vsg/rtx/AccelerationGeometry.cpp @@ -14,7 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include -#include +#include #include #include #include diff --git a/src/vsg/raytracing/AccelerationStructure.cpp b/src/vsg/rtx/AccelerationStructure.cpp similarity index 98% rename from src/vsg/raytracing/AccelerationStructure.cpp rename to src/vsg/rtx/AccelerationStructure.cpp index 191fea6366..f10c91ae49 100644 --- a/src/vsg/raytracing/AccelerationStructure.cpp +++ b/src/vsg/rtx/AccelerationStructure.cpp @@ -12,7 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include -#include +#include #include #include diff --git a/src/vsg/raytracing/BottomLevelAccelerationStructure.cpp b/src/vsg/rtx/BottomLevelAccelerationStructure.cpp similarity index 97% rename from src/vsg/raytracing/BottomLevelAccelerationStructure.cpp rename to src/vsg/rtx/BottomLevelAccelerationStructure.cpp index 0d5892d37c..3019ee9f5b 100644 --- a/src/vsg/raytracing/BottomLevelAccelerationStructure.cpp +++ b/src/vsg/rtx/BottomLevelAccelerationStructure.cpp @@ -12,7 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include -#include +#include #include #include diff --git a/src/vsg/raytracing/BuildAccelerationStructureTraversal.cpp b/src/vsg/rtx/BuildAccelerationStructureTraversal.cpp similarity index 98% rename from src/vsg/raytracing/BuildAccelerationStructureTraversal.cpp rename to src/vsg/rtx/BuildAccelerationStructureTraversal.cpp index b226ecbe1c..bde3d0125f 100644 --- a/src/vsg/raytracing/BuildAccelerationStructureTraversal.cpp +++ b/src/vsg/rtx/BuildAccelerationStructureTraversal.cpp @@ -11,7 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include -#include +#include using namespace vsg; diff --git a/src/vsg/raytracing/DescriptorAccelerationStructure.cpp b/src/vsg/rtx/DescriptorAccelerationStructure.cpp similarity index 98% rename from src/vsg/raytracing/DescriptorAccelerationStructure.cpp rename to src/vsg/rtx/DescriptorAccelerationStructure.cpp index edf0608822..5bf77dcda3 100644 --- a/src/vsg/raytracing/DescriptorAccelerationStructure.cpp +++ b/src/vsg/rtx/DescriptorAccelerationStructure.cpp @@ -10,7 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include +#include #include #include diff --git a/src/vsg/rtx/DrawMeshTasks.cpp b/src/vsg/rtx/DrawMeshTasks.cpp new file mode 100644 index 0000000000..b68fbccf1c --- /dev/null +++ b/src/vsg/rtx/DrawMeshTasks.cpp @@ -0,0 +1,50 @@ +/* + +Copyright(c) 2018 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include +#include +#include +#include + +#include + +using namespace vsg; + +DrawMeshTasks::DrawMeshTasks() +{ +} + +DrawMeshTasks::DrawMeshTasks(uint32_t in_taskCount, uint32_t in_firstTask) : + taskCount(in_taskCount), + firstTask(in_firstTask) +{ +} + +void DrawMeshTasks::read(Input& input) +{ + input.read("taskCount", taskCount); + input.read("firstTask", firstTask); +} + +void DrawMeshTasks::write(Output& output) const +{ + output.write("taskCount", taskCount); + output.write("firstTask", firstTask); +} + +void DrawMeshTasks::record(vsg::CommandBuffer& commandBuffer) const +{ + Device* device = commandBuffer.getDevice(); + Extensions* extensions = Extensions::Get(device, true); + extensions->vkCmdDrawMeshTasksNV(commandBuffer, taskCount, firstTask); +} diff --git a/src/vsg/rtx/DrawMeshTasksIndirect.cpp b/src/vsg/rtx/DrawMeshTasksIndirect.cpp new file mode 100644 index 0000000000..7e40e29492 --- /dev/null +++ b/src/vsg/rtx/DrawMeshTasksIndirect.cpp @@ -0,0 +1,71 @@ +/* + +Copyright(c) 2018 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include +#include +#include + +#include + +using namespace vsg; + +DrawMeshTasksIndirect::DrawMeshTasksIndirect() +{ +} + +void DrawMeshTasksIndirect::read(Input& input) +{ + input.readObject("buffer.data", buffer.data); + if (!buffer.data) + { + input.read("buffer.buffer", buffer.buffer); + input.readValue("buffer.offset", buffer.offset); + input.readValue("buffer.range", buffer.range); + } + + input.read("drawCount", drawCount); + input.read("stride", stride); +} + +void DrawMeshTasksIndirect::write(Output& output) const +{ + output.writeObject("buffer.data", buffer.data); + if (!buffer.data) + { + output.write("buffer.buffer", buffer.buffer); + output.writeValue("buffer.offset", buffer.offset); + output.writeValue("buffer.range", buffer.range); + } + + output.write("drawCount", drawCount); + output.write("stride", stride); +} + +void DrawMeshTasksIndirect::compile(Context& context) +{ + if (!buffer.buffer && buffer.data) + { + auto bufferList = vsg::createBufferAndTransferData(context, {buffer.data}, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE); + if (!bufferList.empty()) + { + buffer = bufferList.back(); + } + } +} + +void DrawMeshTasksIndirect::record(vsg::CommandBuffer& commandBuffer) const +{ + Device* device = commandBuffer.getDevice(); + Extensions* extensions = Extensions::Get(device, true); + extensions->vkCmdDrawMeshTasksIndirectNV(commandBuffer, buffer.buffer->vk(commandBuffer.deviceID), buffer.offset, drawCount, stride); +} diff --git a/src/vsg/rtx/DrawMeshTasksIndirectCount.cpp b/src/vsg/rtx/DrawMeshTasksIndirectCount.cpp new file mode 100644 index 0000000000..723fc3df57 --- /dev/null +++ b/src/vsg/rtx/DrawMeshTasksIndirectCount.cpp @@ -0,0 +1,80 @@ +/* + +Copyright(c) 2018 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include +#include +#include + +#include + +using namespace vsg; + +DrawMeshTasksIndirectCount::DrawMeshTasksIndirectCount() +{ +} + +void DrawMeshTasksIndirectCount::read(Input& input) +{ + input.readObject("buffer.data", buffer.data); + if (!buffer.data) + { + input.read("buffer.buffer", buffer.buffer); + input.readValue("buffer.offset", buffer.offset); + input.readValue("buffer.range", buffer.range); + } + + input.read("maxDrawCount", maxDrawCount); + input.read("stride", stride); +} + +void DrawMeshTasksIndirectCount::write(Output& output) const +{ + output.writeObject("buffer.data", buffer.data); + if (!buffer.data) + { + output.write("buffer,buffer", buffer.buffer); + output.writeValue("buffer.offset", buffer.offset); + output.writeValue("buffer.range", buffer.range); + } + + output.writeObject("countBuffer.data", countBuffer.data); + if (!countBuffer.data) + { + output.write("countBuffer.buffer", countBuffer.buffer); + output.writeValue("countBuffer.offset", countBuffer.offset); + output.writeValue("countBuffer.range", countBuffer.range); + } + + output.write("maxDrawCount", maxDrawCount); + output.write("stride", stride); +} + +void DrawMeshTasksIndirectCount::compile(Context& context) +{ + if ((!buffer.buffer && buffer.data) || (!countBuffer.buffer && countBuffer.data)) + { + auto bufferInfoList = vsg::createBufferAndTransferData(context, {buffer.data, countBuffer.data}, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE); + if (bufferInfoList.size() == 2) + { + buffer = bufferInfoList[0]; + countBuffer = bufferInfoList[1]; + } + } +} + +void DrawMeshTasksIndirectCount::record(vsg::CommandBuffer& commandBuffer) const +{ + Device* device = commandBuffer.getDevice(); + Extensions* extensions = Extensions::Get(device, true); + extensions->vkCmdDrawMeshTasksIndirectCountNV(commandBuffer, buffer.buffer->vk(commandBuffer.deviceID), buffer.offset, countBuffer.buffer->vk(commandBuffer.deviceID), countBuffer.offset, maxDrawCount, stride); +} diff --git a/src/vsg/raytracing/README.md b/src/vsg/rtx/README.md similarity index 100% rename from src/vsg/raytracing/README.md rename to src/vsg/rtx/README.md diff --git a/src/vsg/raytracing/RayTracingPipeline.cpp b/src/vsg/rtx/RayTracingPipeline.cpp similarity index 99% rename from src/vsg/raytracing/RayTracingPipeline.cpp rename to src/vsg/rtx/RayTracingPipeline.cpp index fadd1d3747..d5e4f0ab33 100644 --- a/src/vsg/raytracing/RayTracingPipeline.cpp +++ b/src/vsg/rtx/RayTracingPipeline.cpp @@ -10,7 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include +#include #include #include diff --git a/src/vsg/raytracing/RayTracingShaderGroup.cpp b/src/vsg/rtx/RayTracingShaderGroup.cpp similarity index 97% rename from src/vsg/raytracing/RayTracingShaderGroup.cpp rename to src/vsg/rtx/RayTracingShaderGroup.cpp index 518b6a977a..79a48bff7e 100644 --- a/src/vsg/raytracing/RayTracingShaderGroup.cpp +++ b/src/vsg/rtx/RayTracingShaderGroup.cpp @@ -11,7 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include -#include +#include using namespace vsg; diff --git a/src/vsg/raytracing/TopLevelAccelerationStructure.cpp b/src/vsg/rtx/TopLevelAccelerationStructure.cpp similarity index 98% rename from src/vsg/raytracing/TopLevelAccelerationStructure.cpp rename to src/vsg/rtx/TopLevelAccelerationStructure.cpp index 58d5379921..45af50a888 100644 --- a/src/vsg/raytracing/TopLevelAccelerationStructure.cpp +++ b/src/vsg/rtx/TopLevelAccelerationStructure.cpp @@ -12,7 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include -#include +#include #include #include diff --git a/src/vsg/raytracing/TraceRays.cpp b/src/vsg/rtx/TraceRays.cpp similarity index 98% rename from src/vsg/raytracing/TraceRays.cpp rename to src/vsg/rtx/TraceRays.cpp index c5972f635d..c1b17f3dbe 100644 --- a/src/vsg/raytracing/TraceRays.cpp +++ b/src/vsg/rtx/TraceRays.cpp @@ -11,7 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include -#include +#include #include #include diff --git a/src/vsg/vk/Extensions.cpp b/src/vsg/vk/Extensions.cpp index 082ba31a0b..e8b31ba77e 100644 --- a/src/vsg/vk/Extensions.cpp +++ b/src/vsg/vk/Extensions.cpp @@ -84,4 +84,9 @@ Extensions::Extensions(Device* device) vkCreateRayTracingPipelinesNV = reinterpret_cast(vkGetDeviceProcAddr(*device, "vkCreateRayTracingPipelinesNV")); vkGetRayTracingShaderGroupHandlesNV = reinterpret_cast(vkGetDeviceProcAddr(*device, "vkGetRayTracingShaderGroupHandlesNV")); vkCmdTraceRaysNV = reinterpret_cast(vkGetDeviceProcAddr(*device, "vkCmdTraceRaysNV")); + + // VK_NV_mesh_shader + vkCmdDrawMeshTasksNV = reinterpret_cast(vkGetDeviceProcAddr(*device, "vkCmdDrawMeshTasksNV")); + vkCmdDrawMeshTasksIndirectNV = reinterpret_cast(vkGetDeviceProcAddr(*device, "vkCmdDrawMeshTasksIndirectNV")); + vkCmdDrawMeshTasksIndirectCountNV = reinterpret_cast(vkGetDeviceProcAddr(*device, "vkCmdDrawMeshTasksIndirectCountNV")); } diff --git a/src/vsg/vk/ShaderCompiler.cpp b/src/vsg/vk/ShaderCompiler.cpp index 00781acece..a9030d3f20 100644 --- a/src/vsg/vk/ShaderCompiler.cpp +++ b/src/vsg/vk/ShaderCompiler.cpp @@ -11,7 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include -#include +#include #include #include #include