-
Notifications
You must be signed in to change notification settings - Fork 755
Add new sample for ray tracing position fetch #1070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marty-johnson59
merged 33 commits into
KhronosGroup:main
from
SaschaWillems:ray_tracing_position_fetch
Jul 29, 2024
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7504395
Clean up api sample base class interfaces
SaschaWillems 9214e1e
Revert "Clean up api sample base class interfaces"
SaschaWillems 6ee9bed
Merge branch 'main' of https://github.com/SaschaWillems/Vulkan-Samples
SaschaWillems fdc6969
Merge branch 'main' of https://github.com/SaschaWillems/Vulkan-Samples
SaschaWillems c93d360
Merge branch 'main' of https://github.com/SaschaWillems/Vulkan-Samples
SaschaWillems 2705658
Merge branch 'main' of https://github.com/SaschaWillems/Vulkan-Samples
SaschaWillems bbf46e5
Merge branch 'main' of https://github.com/SaschaWillems/Vulkan-Samples
SaschaWillems 434c9cd
Added sample for VK_KHR_ray_tracing_position_fetch
SaschaWillems b2b635b
Added argument for passing additional buffer usage flags to glTF loading
SaschaWillems 4299a27
Fix build flags
SaschaWillems 700f320
Added option to add additional buffer usage flags when loading glTF s…
SaschaWillems 50e7606
Load full glTF scene instead of just one sub mesh
SaschaWillems 9657ecf
Offset scene and adjust camera
SaschaWillems 1e396ee
Update HLSL shader
SaschaWillems f7e3cea
Code cleanup
SaschaWillems 6ace83a
Code cleanup and simplificaiton
SaschaWillems 8c7092a
Added new overload for adding triangle geometry to an acceleration st…
SaschaWillems 4b8bf85
Add display mode selection
SaschaWillems 0bd2c6a
Added sample to documentation
SaschaWillems d2d606e
Fix typo
SaschaWillems 4fce5b5
Add index type argument
SaschaWillems 9a551fd
Use index type from glTF mesh
SaschaWillems 6899a53
Added SPIR-V files for HLSL shaders
SaschaWillems 627c351
Add readme/tutorial
SaschaWillems 97a1de2
Trying to fix clang format
SaschaWillems 4089ed3
Reowkr additional buffer flags as per review, no longer use local var…
SaschaWillems 03b04f5
Fix typo, new line at end of file required to get past pre-commit
SaschaWillems 98817c8
Move strided device address regions for shader binding tables out of …
SaschaWillems 708ef3f
Make variables const
SaschaWillems b014de5
Port to HPPApiVulkanSample
asuessenbach b68a87a
Fixing clang-format
SaschaWillems 19d1297
Use vkb::core::Buffer const & in AccelerationStructure::add_triangle_…
asuessenbach 0059477
Point assets submodule to latest commit
SaschaWillems File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -406,7 +406,7 @@ GLTFLoader::GLTFLoader(Device &device) : | |
{ | ||
} | ||
|
||
std::unique_ptr<sg::Scene> GLTFLoader::read_scene_from_file(const std::string &file_name, int scene_index) | ||
std::unique_ptr<sg::Scene> GLTFLoader::read_scene_from_file(const std::string &file_name, int scene_index, VkBufferUsageFlags additional_buffer_usage_flags) | ||
{ | ||
std::string err; | ||
std::string warn; | ||
|
@@ -445,10 +445,10 @@ std::unique_ptr<sg::Scene> GLTFLoader::read_scene_from_file(const std::string &f | |
model_path.clear(); | ||
} | ||
|
||
return std::make_unique<sg::Scene>(load_scene(scene_index)); | ||
return std::make_unique<sg::Scene>(load_scene(scene_index, additional_buffer_usage_flags)); | ||
} | ||
|
||
std::unique_ptr<sg::SubMesh> GLTFLoader::read_model_from_file(const std::string &file_name, uint32_t index, bool storage_buffer) | ||
std::unique_ptr<sg::SubMesh> GLTFLoader::read_model_from_file(const std::string &file_name, uint32_t index, bool storage_buffer, VkBufferUsageFlags additional_buffer_usage_flags) | ||
{ | ||
std::string err; | ||
std::string warn; | ||
|
@@ -487,10 +487,10 @@ std::unique_ptr<sg::SubMesh> GLTFLoader::read_model_from_file(const std::string | |
model_path.clear(); | ||
} | ||
|
||
return std::move(load_model(index, storage_buffer)); | ||
return std::move(load_model(index, storage_buffer, additional_buffer_usage_flags)); | ||
} | ||
|
||
sg::Scene GLTFLoader::load_scene(int scene_index) | ||
sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_buffer_usage_flags) | ||
{ | ||
auto scene = sg::Scene(); | ||
|
||
|
@@ -751,7 +751,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index) | |
|
||
core::Buffer buffer{device, | ||
vertex_data.size(), | ||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, | ||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | additional_buffer_usage_flags, | ||
VMA_MEMORY_USAGE_CPU_TO_GPU}; | ||
buffer.update(vertex_data); | ||
buffer.set_debug_name(fmt::format("'{}' mesh, primitive #{}: '{}' vertex buffer", | ||
|
@@ -794,7 +794,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index) | |
|
||
submesh->index_buffer = std::make_unique<core::Buffer>(device, | ||
index_data.size(), | ||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT, | ||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | additional_buffer_usage_flags, | ||
VMA_MEMORY_USAGE_GPU_TO_CPU); | ||
submesh->index_buffer->set_debug_name(fmt::format("'{}' mesh, primitive #{}: index buffer", | ||
gltf_mesh.name, i_primitive)); | ||
|
@@ -1085,7 +1085,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index) | |
return scene; | ||
} | ||
|
||
std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage_buffer) | ||
std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage_buffer, VkBufferUsageFlags additional_buffer_usage_flags) | ||
{ | ||
auto submesh = std::make_unique<sg::SubMesh>(); | ||
|
||
|
@@ -1118,6 +1118,8 @@ std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage | |
auto &buffer_view = model.bufferViews[accessor.bufferView]; | ||
pos = reinterpret_cast<const float *>(&(model.buffers[buffer_view.buffer].data[accessor.byteOffset + buffer_view.byteOffset])); | ||
|
||
submesh->vertices_count = static_cast<uint32_t>(vertex_count); | ||
|
||
if (gltf_primitive.attributes.find("NORMAL") != gltf_primitive.attributes.end()) | ||
{ | ||
accessor = model.accessors[gltf_primitive.attributes.find("NORMAL")->second]; | ||
|
@@ -1190,9 +1192,15 @@ std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage | |
|
||
core::Buffer stage_buffer = vkb::core::Buffer::create_staging_buffer(device, vertex_data); | ||
|
||
VkBufferUsageFlags buffer_usage_flags = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; | ||
if (additional_buffer_usage_flags) | ||
{ | ||
buffer_usage_flags |= additional_buffer_usage_flags; | ||
} | ||
|
||
core::Buffer buffer{device, | ||
vertex_data.size() * sizeof(Vertex), | ||
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, | ||
buffer_usage_flags, | ||
SaschaWillems marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VMA_MEMORY_USAGE_GPU_ONLY}; | ||
|
||
command_buffer.copy_buffer(stage_buffer, buffer, vertex_data.size() * sizeof(Vertex)); | ||
|
@@ -1260,9 +1268,15 @@ std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage | |
{ | ||
core::Buffer stage_buffer = vkb::core::Buffer::create_staging_buffer(device, index_data); | ||
|
||
VkBufferUsageFlags buffer_usage_flags = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT; | ||
if (additional_buffer_usage_flags) | ||
{ | ||
buffer_usage_flags |= additional_buffer_usage_flags; | ||
} | ||
|
||
submesh->index_buffer = std::make_unique<core::Buffer>(device, | ||
index_data.size(), | ||
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, | ||
buffer_usage_flags, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. |
||
VMA_MEMORY_USAGE_GPU_ONLY); | ||
|
||
command_buffer.copy_buffer(stage_buffer, *submesh->index_buffer, index_data.size()); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
samples/extensions/ray_tracing_position_fetch/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) 2024, Sascha Willems | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 the "License"; | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) | ||
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH) | ||
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME) | ||
|
||
add_sample( | ||
ID ${FOLDER_NAME} | ||
CATEGORY ${CATEGORY_NAME} | ||
AUTHOR "Sascha Willems" | ||
NAME "Ray tracing position fetch" | ||
DESCRIPTION "Uses the VK_KHR_ray_tracing_position_fetch to fetch vertex positions from an acceleration structure" | ||
SHADER_FILES_GLSL | ||
"ray_tracing_position_fetch/glsl/closesthit.rchit" | ||
"ray_tracing_position_fetch/glsl/miss.rmiss" | ||
"ray_tracing_position_fetch/glsl/raygen.rgen" | ||
SHADER_FILES_HLSL | ||
"ray_tracing_position_fetch/hlsl/closesthit.rchit.hlsl" | ||
"ray_tracing_position_fetch/hlsl/miss.rmiss.hlsl" | ||
"ray_tracing_position_fetch/hlsl/raygen.rgen.hlsl") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.