Skip to content

Commit

Permalink
Merge pull request #788 from Devsh-Graphics-Programming/ray_query_inl…
Browse files Browse the repository at this point in the history
…ine_spirv_example

Ray query inline spirv example
  • Loading branch information
devshgraphicsprogramming authored Nov 22, 2024
2 parents 38491b8 + 48d4440 commit e8f4dca
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/Vulkan-Headers
Submodule Vulkan-Headers updated 84 files
+0 −34 .cmake-format.py
+8 −0 .gitattributes
+26 −6 .github/ISSUE_TEMPLATE/bug_report.md
+12 −0 .github/dependabot.yml
+18 −0 .github/pull_request_template.md
+41 −0 .github/workflows/ci.yml
+8 −0 .gitignore
+15 −0 .reuse/dep5
+24 −16 BUILD.gn
+25 −253 BUILD.md
+59 −45 CMakeLists.txt
+10 −0 CODE_OF_CONDUCT.adoc
+0 −1 CODE_OF_CONDUCT.md
+40 −0 CONTRIBUTING.md
+18 −0 LICENSE.md
+0 −0 LICENSES/Apache-2.0.txt
+9 −0 LICENSES/MIT.txt
+43 −69 README.md
+11 −0 SECURITY.md
+0 −126 cmake/Copyright_cmake.txt
+0 −21 cmake/cmake_uninstall.cmake.in
+392 −0 include/vk_video/vulkan_video_codec_av1std.h
+109 −0 include/vk_video/vulkan_video_codec_av1std_decode.h
+44 −37 include/vk_video/vulkan_video_codec_h264std.h
+10 −36 include/vk_video/vulkan_video_codec_h264std_decode.h
+46 −31 include/vk_video/vulkan_video_codec_h264std_encode.h
+144 −55 include/vk_video/vulkan_video_codec_h265std.h
+9 −8 include/vk_video/vulkan_video_codec_h265std_decode.h
+55 −33 include/vk_video/vulkan_video_codec_h265std_encode.h
+6 −1 include/vk_video/vulkan_video_codecs_common.h
+23 −24 include/vulkan/vk_icd.h
+6 −27 include/vulkan/vk_layer.h
+1 −1 include/vulkan/vk_platform.h
+0 −69 include/vulkan/vk_sdk_platform.h
+4,829 −0 include/vulkan/vulkan.cppm
+9 −2 include/vulkan/vulkan.h
+8,290 −2,170 include/vulkan/vulkan.hpp
+29 −1 include/vulkan/vulkan_android.h
+149 −927 include/vulkan/vulkan_beta.h
+8,784 −3,963 include/vulkan/vulkan_core.h
+2 −1 include/vulkan/vulkan_directfb.h
+3,970 −12,349 include/vulkan/vulkan_enums.hpp
+2,988 −0 include/vulkan/vulkan_extension_inspection.hpp
+955 −619 include/vulkan/vulkan_format_traits.hpp
+5 −1 include/vulkan/vulkan_fuchsia.h
+12,401 −5,833 include/vulkan/vulkan_funcs.hpp
+3 −1 include/vulkan/vulkan_ggp.h
+6,285 −3,644 include/vulkan/vulkan_handles.hpp
+4,375 −836 include/vulkan/vulkan_hash.hpp
+297 −0 include/vulkan/vulkan_hpp_macros.hpp
+2 −1 include/vulkan/vulkan_ios.h
+2 −1 include/vulkan/vulkan_macos.h
+3 −1 include/vulkan/vulkan_metal.h
+14,024 −8,387 include/vulkan/vulkan_raii.hpp
+55 −1 include/vulkan/vulkan_screen.h
+1,087 −0 include/vulkan/vulkan_shared.hpp
+7,487 −0 include/vulkan/vulkan_static_assertions.hpp
+69,709 −45,738 include/vulkan/vulkan_structs.hpp
+9,075 −0 include/vulkan/vulkan_to_string.hpp
+2 −1 include/vulkan/vulkan_vi.h
+3,716 −0 include/vulkan/vulkan_video.hpp
+2 −1 include/vulkan/vulkan_wayland.h
+28 −1 include/vulkan/vulkan_win32.h
+2 −1 include/vulkan/vulkan_xcb.h
+2 −1 include/vulkan/vulkan_xlib.h
+2 −1 include/vulkan/vulkan_xlib_xrandr.h
+12 −2 registry/apiconventions.py
+110 −21 registry/cgenerator.py
+208 −45 registry/generator.py
+0 −818 registry/genvk.py
+403 −0 registry/parse_dependency.py
+390 −0 registry/profiles/VP_KHR_roadmap.json
+275 −179 registry/reg.py
+195 −17 registry/spec_tools/conventions.py
+2 −3 registry/spec_tools/util.py
+42 −0 registry/stripAPI.py
+81,089 −29,259 registry/validusage.json
+802 −210 registry/video.xml
+11,061 −5,452 registry/vk.xml
+58 −24 registry/vkconventions.py
+33 −0 tests/CMakeLists.txt
+73 −0 tests/integration/CMakeLists.txt
+14 −0 tests/vk_icd.c
+14 −0 tests/vk_layer.c
74 changes: 74 additions & 0 deletions include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (C) 2023 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_RAYTRACING_INCLUDED_
#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_RAYTRACING_INCLUDED_

#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"

namespace nbl
{
namespace hlsl
{
namespace spirv
{

//[[vk::ext_capability(spv::CapabilityRayQueryKHR)]] https://github.com/microsoft/DirectXShaderCompiler/issues/6958
using RayQueryKHR = vk::SpirvOpaqueType<spv::OpTypeRayQueryKHR>;

//[[vk::ext_capability(spv::CapabilityAccelerationStructureKHR)]]
using AccelerationStructureKHR = vk::SpirvOpaqueType<spv::OpTypeAccelerationStructureKHR>;

[[vk::ext_instruction(spv::OpConvertUToAccelerationStructureKHR)]]
AccelerationStructureKHR accelerationStructureKHR(uint64_t u);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_extension("SPV_KHR_ray_query")]]
[[vk::ext_instruction(spv::OpRayQueryInitializeKHR)]]
void rayQueryInitializeKHR([[vk::ext_reference]] RayQueryKHR query, AccelerationStructureKHR AS, uint32_t flags, uint32_t cullMask, float32_t3 origin, float32_t tmin, float32_t3 direction, float32_t tmax);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_extension("SPV_KHR_ray_query")]]
[[vk::ext_instruction(spv::OpRayQueryInitializeKHR)]]
void rayQueryInitializeKHR([[vk::ext_reference]] RayQueryKHR query, RaytracingAccelerationStructure AS, uint32_t flags, uint32_t cullMask, float32_t3 origin, float32_t tmin, float32_t3 direction, float32_t tmax);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_extension("SPV_KHR_ray_query")]]
[[vk::ext_instruction(spv::OpRayQueryProceedKHR)]]
bool rayQueryProceedKHR([[vk::ext_reference]] RayQueryKHR query);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_extension("SPV_KHR_ray_query")]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionTypeKHR)]]
int rayQueryGetIntersectionTypeKHR([[vk::ext_reference]] RayQueryKHR query, uint32_t committed);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_extension("SPV_KHR_ray_query")]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionInstanceIdKHR)]]
int rayQueryGetIntersectionInstanceIdKHR([[vk::ext_reference]] RayQueryKHR query, uint32_t committed);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_extension("SPV_KHR_ray_query")]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionPrimitiveIndexKHR)]]
int rayQueryGetIntersectionPrimitiveIndexKHR([[vk::ext_reference]] RayQueryKHR query, uint32_t committed);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_extension("SPV_KHR_ray_query")]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionBarycentricsKHR)]]
float2 rayQueryGetIntersectionBarycentricsKHR([[vk::ext_reference]] RayQueryKHR query, uint32_t committed);

// position fetch for ray tracing uses gl_HitTriangleVertexPositionsEXT -> HitTriangleVertexPositionsKHR decorated OpVariable
[[vk::ext_builtin_input(spv::BuiltInHitTriangleVertexPositionsKHR)]]
static const float32_t3 HitTriangleVertexPositionsKHR[3];

// ray query version
[[vk::ext_capability(spv::CapabilityRayQueryPositionFetchKHR)]]
[[vk::ext_extension("SPV_KHR_ray_tracing_position_fetch")]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionTriangleVertexPositionsKHR)]]
float3 rayQueryGetIntersectionTriangleVertexPositionsKHR([[vk::ext_reference]] RayQueryKHR query, uint32_t committed)[3];

}
}
}

#endif
1 change: 1 addition & 0 deletions src/nbl/builtin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/macros.h")
#spirv intrinsics
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/core.hlsl")
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/fragment_shader_pixel_interlock.hlsl")
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/raytracing.hlsl")
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/subgroup_arithmetic.hlsl")
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/subgroup_ballot.hlsl")
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/subgroup_basic.hlsl")
Expand Down
11 changes: 11 additions & 0 deletions src/nbl/video/CVulkanPhysicalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR workgroupMemoryExplicitLayout = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_FEATURES_KHR };
VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR raytracingMaintenance1Features = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_MAINTENANCE_1_FEATURES_KHR };
VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesARM rasterizationOrderAttachmentAccessFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_ARM };
VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR rayTracingPositionFetchFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR };
VkPhysicalDeviceColorWriteEnableFeaturesEXT colorWriteEnableFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT };
#if 0
VkPhysicalDeviceCooperativeMatrixFeaturesKHR cooperativeMatrixFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR };
Expand Down Expand Up @@ -768,6 +769,8 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
addToPNextChain(&workgroupMemoryExplicitLayout);
if (isExtensionSupported(VK_ARM_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXTENSION_NAME))
addToPNextChain(&rasterizationOrderAttachmentAccessFeatures);
if (isExtensionSupported(VK_KHR_RAY_TRACING_POSITION_FETCH_EXTENSION_NAME))
addToPNextChain(&rayTracingPositionFetchFeatures);
if (isExtensionSupported(VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME))
addToPNextChain(&colorWriteEnableFeatures);
// call
Expand Down Expand Up @@ -1196,6 +1199,9 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
properties.limits.workgroupMemoryExplicitLayout16BitAccess = workgroupMemoryExplicitLayout.workgroupMemoryExplicitLayout16BitAccess;
}

if (isExtensionSupported(VK_KHR_RAY_TRACING_POSITION_FETCH_EXTENSION_NAME) && isExtensionSupported(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME))
properties.limits.rayTracingPositionFetch = rayTracingPositionFetchFeatures.rayTracingPositionFetch;

if (isExtensionSupported(VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME))
properties.limits.colorWriteEnable = colorWriteEnableFeatures.colorWriteEnable;
#if 0 //TODO
Expand Down Expand Up @@ -1566,6 +1572,9 @@ core::smart_refctd_ptr<ILogicalDevice> CVulkanPhysicalDevice::createLogicalDevic
&rasterizationOrderAttachmentAccessFeatures
);

VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR rayTracingPositionFetchFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR, nullptr };
REQUIRE_EXTENSION_IF(enabledFeatures.accelerationStructure && m_initData.properties.limits.rayTracingPositionFetch, VK_KHR_RAY_TRACING_POSITION_FETCH_EXTENSION_NAME, &rayTracingPositionFetchFeatures);

VkPhysicalDeviceColorWriteEnableFeaturesEXT colorWriteEnableFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT,nullptr };
enableExtensionIfAvailable(VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME,&colorWriteEnableFeatures);
#if 0
Expand Down Expand Up @@ -1751,6 +1760,8 @@ core::smart_refctd_ptr<ILogicalDevice> CVulkanPhysicalDevice::createLogicalDevic

rayQueryFeatures.rayQuery = enabledFeatures.rayQuery;

rayTracingPositionFetchFeatures.rayTracingPositionFetch = limits.rayTracingPositionFetch;

//shaderSMBuiltinsFeaturesNV [LIMIT SO ENABLE EVERYTHING BY DEFAULT]

representativeFragmentTestFeatures.representativeFragmentTest = enabledFeatures.representativeFragmentTest;
Expand Down
12 changes: 10 additions & 2 deletions src/nbl/video/device_capabilities/device_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -4023,8 +4023,16 @@
"VK_AMD_extension_478",
"VK_AMD_extension_479",
"VK_EXT_extension_480",
"VK_EXT_extension_481",
"TODO: implement",
"VK_EXT_extension_481"
]
},
{
"type": "bool",
"name": "rayTracingPositionFetch",
"value": false,
"expose": "MOVE_TO_LIMIT",
"comment": [
"RayTracingPositionFetchFeaturesKHR",
"VK_KHR_ray_tracing_position_fetch"
]
},
Expand Down

0 comments on commit e8f4dca

Please sign in to comment.