Skip to content
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

Port implementation to VK_KHR_ray_tracing #7

Merged
merged 36 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
37494f7
Bulk of the work to port from VK_NV_ray_tracing to VK_KHR_ray_tracing…
GPSnoopy Apr 9, 2020
1d1d447
Moving shaders to GL_EXT_ray_tracing.
GPSnoopy Apr 9, 2020
08ea761
Add DebugUtils.SetObjectName() and make good use of it.
GPSnoopy Apr 9, 2020
f41e191
Fixed incorrect buildOffsetInfo for bottom level triangle geometry.
GPSnoopy Apr 9, 2020
d579d2b
Fixed validation error.
GPSnoopy Apr 9, 2020
e45f4e9
Fix CI by updating Vulkan SDK to the correct version.
GPSnoopy Apr 9, 2020
e0973c3
Fix CI by updating Vulkan SDK to the correct version.
GPSnoopy Apr 9, 2020
09bb11b
Fix ShaderBindingTable offsets, strides and sizes.
GPSnoopy Apr 9, 2020
0536219
Comment: clarify shaderRecordEXT.
GPSnoopy Apr 9, 2020
0c868e0
Fix Linux build.
GPSnoopy Apr 9, 2020
98b5318
Expose to the derived Vulkan Apllications the responsibility of optin…
GPSnoopy Apr 10, 2020
9ca3769
Fix hyperlinks.
GPSnoopy Apr 10, 2020
f41d501
Reorganise references.
GPSnoopy Apr 10, 2020
86bb4d0
Cleanup.
GPSnoopy Apr 10, 2020
c114601
Merge branch 'VK_KHR_ray_tracing' of https://github.com/GPSnoopy/RayT…
GPSnoopy Apr 10, 2020
27a6323
Fix Release runtime error.
GPSnoopy Apr 10, 2020
7fb8776
Use environment variables to avoid repeating SDK version in YAML acti…
GPSnoopy Apr 22, 2020
0434bb5
Use environment variables to avoid repeating SDK version in YAML acti…
GPSnoopy Apr 22, 2020
1852d31
Use environment variables to avoid repeating SDK version in YAML acti…
GPSnoopy Apr 22, 2020
e9cf48c
Use environment variables to avoid repeating SDK version in YAML acti…
GPSnoopy Apr 22, 2020
afd889f
Merge branch 'master' into VK_KHR_ray_tracing
GPSnoopy May 4, 2020
5c50a25
Remove empty spaces.
GPSnoopy May 4, 2020
5f6e414
Merge branch 'master' into VK_KHR_ray_tracing
GPSnoopy May 10, 2020
3490119
Merge branch 'VK_KHR_ray_tracing' of https://github.com/GPSnoopy/RayT…
GPSnoopy May 10, 2020
86ae97f
Typo and other textual niceties.
GPSnoopy May 10, 2020
36853ff
Move Release build argument to build_linux.sh.
GPSnoopy May 10, 2020
352d75a
Cleanup the options help text.
GPSnoopy May 10, 2020
819a2e7
Cleanup the options help text.
GPSnoopy May 10, 2020
1d917d5
Fixed camera controls enabled in benchmark mode.
GPSnoopy May 24, 2020
1548bef
Merge branch 'master' into VK_KHR_ray_tracing
GPSnoopy Jun 6, 2020
0f5dd95
Merge branch 'master' into VK_KHR_ray_tracing
GPSnoopy Jun 29, 2020
4dfceba
Fix SDK version (older version got pulled from website).
GPSnoopy Jun 29, 2020
1473c46
Merge branch 'master' into VK_KHR_ray_tracing
GPSnoopy Aug 6, 2020
5ef8fe8
Target Vulkan 1.2 when compiling shaders.
GPSnoopy Aug 6, 2020
cfa0945
Update CMakeLists.txt
GPSnoopy Aug 6, 2020
d512551
Merge branch 'master' into VK_KHR_ray_tracing
GPSnoopy Aug 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ cmake_minimum_required(VERSION 3.10)

project(RayTracingInVulkan)

# On Linux, default to Release if not specified.
if (UNIX AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Specifies the build type on single-configuration generators" FORCE)
endif ()

set(CMAKE_DEBUG_POSTFIX d)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img align="center" src="https://github.com/GPSnoopy/RayTracingInVulkan/blob/master/gallery/LucySettings.jpg">

My implementation of [Peter Shirley's Ray Tracing in One Weekend](https://github.com/RayTracing/raytracing.github.io) books using Vulkan and NVIDIA's RTX extension (VK_NV_ray_tracing). This allows most scenes to be rendered at interactive speed on appropriate hardware.
My implementation of [Peter Shirley's Ray Tracing in One Weekend](https://github.com/RayTracing/raytracing.github.io) books using Vulkan and NVIDIA's RTX extension (VK_NV_ray_tracing, now ported to VK_KHR_ray_tracing). This allows most scenes to be rendered at interactive speed on appropriate hardware.

The real-time ray tracer can also load full geometry from OBJ files as well as render the procedural spheres from the book. An accumulation buffer is used to increase the sample count when the camera is not moving while keeping the frame rate interactive. I have added a UI built using [Dear ImGui](https://github.com/ocornut/imgui) to allow changing the renderer parameters on the fly. Unlike projects such as [Q2VKPT](http://brechpunkt.de/q2vkpt/), there is no denoising filter. So the image will get noisy when moving the camera.

Expand Down Expand Up @@ -67,12 +67,20 @@ If in doubt, please check the GitHub Actions [continuous integration configurati

## References

### Initial Implementation

* [Vulkan Tutorial](https://vulkan-tutorial.com/)
* [Introduction to Real-Time Ray Tracing with Vulkan](https://devblogs.nvidia.com/vulkan-raytracing/)
* [Introduction to Real-Time Ray Tracing with Vulkan](https://devblogs.nvidia.com/vulkan-raytracing)
* [NVIDIA Vulkan Ray Tracing Tutorial](https://developer.nvidia.com/rtx/raytracing/vkray)
* [NVIDIA Vulkan Ray Tracing Helpers: Introduction](https://developer.nvidia.com/rtx/raytracing/vkray_helpers)
* [Fast and Fun: My First Real-Time Ray Tracing Demo](https://devblogs.nvidia.com/my-first-ray-tracing-demo/)
* [Getting Started with RTX Ray Tracing](https://github.com/NVIDIAGameWorks/GettingStartedWithRTXRayTracing)
* [D3D12 Raytracing Samples](https://github.com/Microsoft/DirectX-Graphics-Samples/tree/master/Samples/Desktop/D3D12Raytracing)
* [George Ouzounoudis's vk_exp](https://github.com/georgeouzou/vk_exp)
* [NVIDIA Vulkan Forums](https://devtalk.nvidia.com/default/board/166/vulkan/)
* [NVIDIA Vulkan Forums](https://devtalk.nvidia.com/default/board/166/vulkan)

### VK_KHR_ray_tracing Port

* [Khronos Vulkan Registry](https://www.khronos.org/registry/vulkan/)
* [NVIDIA Vulkan Ray Tracing Tutorial (VK_KHR_ray_tracing)](https://nvpro-samples.github.io/vk_raytracing_tutorial_KHR)
* [NVIDIA Converting VK_NV_ray_tracing to VK_KHR_ray_tracing](https://nvpro-samples.github.io/vk_raytracing_tutorial_KHR/NV_to_KHR.md.htm)
2 changes: 1 addition & 1 deletion assets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ foreach(shader ${shader_files})
add_custom_command(
OUTPUT ${output_file}
COMMAND ${CMAKE_COMMAND} -E make_directory ${output_dir}
COMMAND ${Vulkan_GLSLANG_VALIDATOR} -V ${full_path} -o ${output_file}
COMMAND ${Vulkan_GLSLANG_VALIDATOR} --target-env vulkan1.2 -V ${full_path} -o ${output_file}
DEPENDS ${full_path}
)
endforeach()
Expand Down
14 changes: 7 additions & 7 deletions assets/shaders/RayTracing.Procedural.rchit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 460
#extension GL_EXT_nonuniform_qualifier : require
#extension GL_GOOGLE_include_directive : require
#extension GL_NV_ray_tracing : require
#extension GL_EXT_ray_tracing : require
#include "Material.glsl"

layout(binding = 4) readonly buffer VertexArray { float Vertices[]; };
Expand All @@ -14,8 +14,8 @@ layout(binding = 9) readonly buffer SphereArray { vec4[] Spheres; };
#include "Scatter.glsl"
#include "Vertex.glsl"

hitAttributeNV vec4 Sphere;
rayPayloadInNV RayPayload Ray;
hitAttributeEXT vec4 Sphere;
rayPayloadInEXT RayPayload Ray;

vec2 GetSphereTexCoord(const vec3 point)
{
Expand All @@ -33,19 +33,19 @@ vec2 GetSphereTexCoord(const vec3 point)
void main()
{
// Get the material.
const uvec2 offsets = Offsets[gl_InstanceCustomIndexNV];
const uvec2 offsets = Offsets[gl_InstanceCustomIndexEXT];
const uint indexOffset = offsets.x;
const uint vertexOffset = offsets.y;
const Vertex v0 = UnpackVertex(vertexOffset + Indices[indexOffset]);
const Material material = Materials[v0.MaterialIndex];

// Compute the ray hit point properties.
const vec4 sphere = Spheres[gl_InstanceCustomIndexNV];
const vec4 sphere = Spheres[gl_InstanceCustomIndexEXT];
const vec3 center = sphere.xyz;
const float radius = sphere.w;
const vec3 point = gl_WorldRayOriginNV + gl_HitTNV * gl_WorldRayDirectionNV;
const vec3 point = gl_WorldRayOriginEXT + gl_HitTEXT * gl_WorldRayDirectionEXT;
const vec3 normal = (point - center) / radius;
const vec2 texCoord = GetSphereTexCoord(normal);

Ray = Scatter(material, gl_WorldRayDirectionNV, normal, texCoord, gl_HitTNV, Ray.RandomSeed);
Ray = Scatter(material, gl_WorldRayDirectionEXT, normal, texCoord, gl_HitTEXT, Ray.RandomSeed);
}
16 changes: 8 additions & 8 deletions assets/shaders/RayTracing.Procedural.rint
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#version 460
#extension GL_GOOGLE_include_directive : require
#extension GL_NV_ray_tracing : require
#extension GL_EXT_ray_tracing : require

layout(binding = 9) readonly buffer SphereArray { vec4[] Spheres; };

hitAttributeNV vec4 Sphere;
hitAttributeEXT vec4 Sphere;

void main()
{
const vec4 sphere = Spheres[gl_InstanceCustomIndexNV];
const vec4 sphere = Spheres[gl_InstanceCustomIndexEXT];
const vec3 center = sphere.xyz;
const float radius = sphere.w;

const vec3 origin = gl_WorldRayOriginNV;
const vec3 direction = gl_WorldRayDirectionNV;
const float tMin = gl_RayTminNV;
const float tMax = gl_RayTmaxNV;
const vec3 origin = gl_WorldRayOriginEXT;
const vec3 direction = gl_WorldRayDirectionEXT;
const float tMin = gl_RayTminEXT;
const float tMax = gl_RayTmaxEXT;

// https://en.wikipedia.org/wiki/Quadratic_formula

Expand All @@ -33,7 +33,7 @@ void main()
if ((tMin <= t1 && t1 < tMax) || (tMin <= t2 && t2 < tMax))
{
Sphere = sphere;
reportIntersectionNV((tMin <= t1 && t1 < tMax) ? t1 : t2, 0);
reportIntersectionEXT((tMin <= t1 && t1 < tMax) ? t1 : t2, 0);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions assets/shaders/RayTracing.rchit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#version 460
#extension GL_EXT_nonuniform_qualifier : require
#extension GL_GOOGLE_include_directive : require
#extension GL_NV_ray_tracing : require
#extension GL_EXT_ray_tracing : require
#include "Material.glsl"

layout(binding = 4) readonly buffer VertexArray { float Vertices[]; };
Expand All @@ -13,8 +13,8 @@ layout(binding = 8) uniform sampler2D[] TextureSamplers;
#include "Scatter.glsl"
#include "Vertex.glsl"

hitAttributeNV vec2 HitAttributes;
rayPayloadInNV RayPayload Ray;
hitAttributeEXT vec2 HitAttributes;
rayPayloadInEXT RayPayload Ray;

vec2 Mix(vec2 a, vec2 b, vec2 c, vec3 barycentrics)
{
Expand All @@ -29,7 +29,7 @@ vec3 Mix(vec3 a, vec3 b, vec3 c, vec3 barycentrics)
void main()
{
// Get the material.
const uvec2 offsets = Offsets[gl_InstanceCustomIndexNV];
const uvec2 offsets = Offsets[gl_InstanceCustomIndexEXT];
const uint indexOffset = offsets.x;
const uint vertexOffset = offsets.y;
const Vertex v0 = UnpackVertex(vertexOffset + Indices[indexOffset + gl_PrimitiveID * 3 + 0]);
Expand All @@ -42,5 +42,5 @@ void main()
const vec3 normal = normalize(Mix(v0.Normal, v1.Normal, v2.Normal, barycentrics));
const vec2 texCoord = Mix(v0.TexCoord, v1.TexCoord, v2.TexCoord, barycentrics);

Ray = Scatter(material, gl_WorldRayDirectionNV, normal, texCoord, gl_HitTNV, Ray.RandomSeed);
Ray = Scatter(material, gl_WorldRayDirectionEXT, normal, texCoord, gl_HitTEXT, Ray.RandomSeed);
}
24 changes: 12 additions & 12 deletions assets/shaders/RayTracing.rgen
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
#version 460
#extension GL_GOOGLE_include_directive : require
#extension GL_NV_ray_tracing : require
#extension GL_EXT_ray_tracing : require
#include "Random.glsl"
#include "RayPayload.glsl"
#include "UniformBufferObject.glsl"

layout(binding = 0, set = 0) uniform accelerationStructureNV Scene;
layout(binding = 0, set = 0) uniform accelerationStructureEXT Scene;
layout(binding = 1, rgba32f) uniform image2D AccumulationImage;
layout(binding = 2, rgba8) uniform image2D OutputImage;
layout(binding = 3) readonly uniform UniformBufferObjectStruct { UniformBufferObject Camera; };

layout(location = 0) rayPayloadNV RayPayload Ray;
layout(location = 0) rayPayloadEXT RayPayload Ray;

void main()
{
// Initialise separate random seeds for the pixel and the rays.
// - pixel: we want the same random seed for each pixel to get a homogeneous anti-aliasing.
// - ray: we want a noisy random seed, different for each pixel.
uint pixelRandomSeed = Camera.RandomSeed;
Ray.RandomSeed = InitRandomSeed(InitRandomSeed(gl_LaunchIDNV.x, gl_LaunchIDNV.y), Camera.TotalNumberOfSamples);
Ray.RandomSeed = InitRandomSeed(InitRandomSeed(gl_LaunchIDEXT.x, gl_LaunchIDEXT.y), Camera.TotalNumberOfSamples);

vec3 pixelColor = vec3(0);

// Accumulate all the rays for this pixels.
for (uint s = 0; s < Camera.NumberOfSamples; ++s)
{
//if (Camera.NumberOfSamples != Camera.TotalNumberOfSamples) break;
const vec2 pixel = vec2(gl_LaunchIDNV.x + RandomFloat(pixelRandomSeed), gl_LaunchIDNV.y + RandomFloat(pixelRandomSeed));
const vec2 uv = (pixel / gl_LaunchSizeNV.xy) * 2.0 - 1.0;
const vec2 pixel = vec2(gl_LaunchIDEXT.x + RandomFloat(pixelRandomSeed), gl_LaunchIDEXT.y + RandomFloat(pixelRandomSeed));
const vec2 uv = (pixel / gl_LaunchSizeEXT.xy) * 2.0 - 1.0;

vec2 offset = Camera.Aperture/2 * RandomInUnitDisk(Ray.RandomSeed);
vec4 origin = Camera.ModelViewInverse * vec4(offset, 0, 1);
vec4 target = Camera.ProjectionInverse * (vec4(uv.x, uv.y, 1, 1));
vec4 direction = Camera.ModelViewInverse * vec4(normalize(target.xyz * Camera.FocusDistance - vec3(offset, 0)), 0);
vec3 rayColor = vec3(1);

// Ray scatters are handled in this loop. There are no recursive traceNV() calls in other shaders.
// Ray scatters are handled in this loop. There are no recursive traceRayEXT() calls in other shaders.
for (uint b = 0; b <= Camera.NumberOfBounces; ++b)
{
const float tMin = 0.001;
Expand All @@ -49,8 +49,8 @@ void main()
break;
}

traceNV(
Scene, gl_RayFlagsOpaqueNV, 0xff,
traceRayEXT(
Scene, gl_RayFlagsOpaqueEXT, 0xff,
0 /*sbtRecordOffset*/, 0 /*sbtRecordStride*/, 0 /*missIndex*/,
origin.xyz, tMin, direction.xyz, tMax, 0 /*payload*/);

Expand All @@ -75,7 +75,7 @@ void main()
}

const bool accumulate = Camera.NumberOfSamples != Camera.TotalNumberOfSamples;
const vec3 accumulatedColor = (accumulate ? imageLoad(AccumulationImage, ivec2(gl_LaunchIDNV.xy)) : vec4(0)).rgb + pixelColor;
const vec3 accumulatedColor = (accumulate ? imageLoad(AccumulationImage, ivec2(gl_LaunchIDEXT.xy)) : vec4(0)).rgb + pixelColor;

pixelColor = accumulatedColor / Camera.TotalNumberOfSamples;

Expand All @@ -85,6 +85,6 @@ void main()
pixelColor = sqrt(pixelColor);
}

imageStore(AccumulationImage, ivec2(gl_LaunchIDNV.xy), vec4(accumulatedColor, 0));
imageStore(OutputImage, ivec2(gl_LaunchIDNV.xy), vec4(pixelColor, 0));
imageStore(AccumulationImage, ivec2(gl_LaunchIDEXT.xy), vec4(accumulatedColor, 0));
imageStore(OutputImage, ivec2(gl_LaunchIDEXT.xy), vec4(pixelColor, 0));
}
6 changes: 3 additions & 3 deletions assets/shaders/RayTracing.rmiss
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#version 460
#extension GL_GOOGLE_include_directive : require
#extension GL_NV_ray_tracing : require
#extension GL_EXT_ray_tracing : require
#include "RayPayload.glsl"
#include "UniformBufferObject.glsl"

layout(binding = 3) readonly uniform UniformBufferObjectStruct { UniformBufferObject Camera; };

layout(location = 0) rayPayloadInNV RayPayload Ray;
layout(location = 0) rayPayloadInEXT RayPayload Ray;

void main()
{
if (Camera.HasSky)
{
// Sky color
const float t = 0.5*(normalize(gl_WorldRayDirectionNV).y + 1);
const float t = 0.5*(normalize(gl_WorldRayDirectionEXT).y + 1);
const vec3 skyColor = mix(vec3(1.0), vec3(0.5, 0.7, 1.0), t);

Ray.ColorAndDistance = vec4(skyColor, -1);
Expand Down
2 changes: 1 addition & 1 deletion build_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ set -e

mkdir --parents build/linux
cd build/linux
cmake -D VCPKG_TARGET_TRIPLET=x64-linux -D CMAKE_TOOLCHAIN_FILE=../vcpkg.linux/scripts/buildsystems/vcpkg.cmake ../..
cmake -D CMAKE_BUILD_TYPE=Release -D VCPKG_TARGET_TRIPLET=x64-linux -D CMAKE_TOOLCHAIN_FILE=../vcpkg.linux/scripts/buildsystems/vcpkg.cmake ../..
make -j
2 changes: 1 addition & 1 deletion src/Assets/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Assets {

Model Model::LoadModel(const std::string& filename)
{
std::cout << "Loading '" << filename << "'... " << std::flush;
std::cout << "- loading '" << filename << "'... " << std::flush;

const auto timer = std::chrono::high_resolution_clock::now();
const std::string materialPath = std::filesystem::path(filename).parent_path().string();
Expand Down
28 changes: 18 additions & 10 deletions src/Assets/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Texture.hpp"
#include "TextureImage.hpp"
#include "Vulkan/Buffer.hpp"
#include "Vulkan/Device.hpp"
#include "Vulkan/CommandPool.hpp"
#include "Vulkan/ImageView.hpp"
#include "Vulkan/Sampler.hpp"
Expand Down Expand Up @@ -40,17 +41,23 @@ namespace
template <class T>
void CreateDeviceBuffer(
Vulkan::CommandPool& commandPool,
const char* const name,
const VkBufferUsageFlags usage,
const std::vector<T>& content,
std::unique_ptr<Vulkan::Buffer>& buffer,
std::unique_ptr<Vulkan::DeviceMemory>& memory)
{
const auto& device = commandPool.Device();
const auto& debugUtils = device.DebugUtils();
const auto contentSize = sizeof(content[0]) * content.size();
const VkMemoryAllocateFlags allocateFlags = usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT ? VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT : 0;

buffer.reset(new Vulkan::Buffer(device, contentSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT | usage));
memory.reset(new Vulkan::DeviceMemory(buffer->AllocateMemory(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)));
memory.reset(new Vulkan::DeviceMemory(buffer->AllocateMemory(allocateFlags, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)));

debugUtils.SetObjectName(buffer->Handle(), (name + std::string(" Buffer")).c_str());
debugUtils.SetObjectName(memory->Handle(), (name + std::string(" Memory")).c_str());

CopyFromStagingBuffer(commandPool, *buffer, content);
}

Expand All @@ -65,7 +72,7 @@ Scene::Scene(Vulkan::CommandPool& commandPool, std::vector<Model>&& models, std:
std::vector<uint32_t> indices;
std::vector<Material> materials;
std::vector<glm::vec4> procedurals;
std::vector<std::pair<glm::vec3, glm::vec3>> aabbs;
std::vector<VkAabbPositionsKHR> aabbs;
std::vector<glm::uvec2> offsets;

for (const auto& model : models_)
Expand All @@ -92,7 +99,8 @@ Scene::Scene(Vulkan::CommandPool& commandPool, std::vector<Model>&& models, std:
const auto sphere = dynamic_cast<const Sphere*>(model.Procedural());
if (sphere != nullptr)
{
aabbs.push_back(sphere->BoundingBox());
const auto aabb = sphere->BoundingBox();
aabbs.push_back({aabb.first.x, aabb.first.y, aabb.first.z, aabb.second.x, aabb.second.y, aabb.second.z});
procedurals.emplace_back(sphere->Center, sphere->Radius);
}
else
Expand All @@ -102,15 +110,15 @@ Scene::Scene(Vulkan::CommandPool& commandPool, std::vector<Model>&& models, std:
}
}

const auto flag = usedForRayTracing ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : 0;
const auto flag = usedForRayTracing ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0;

CreateDeviceBuffer(commandPool, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | flag, vertices, vertexBuffer_, vertexBufferMemory_);
CreateDeviceBuffer(commandPool, VK_BUFFER_USAGE_INDEX_BUFFER_BIT | flag, indices, indexBuffer_, indexBufferMemory_);
CreateDeviceBuffer(commandPool, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, materials, materialBuffer_, materialBufferMemory_);
CreateDeviceBuffer(commandPool, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, offsets, offsetBuffer_, offsetBufferMemory_);
CreateDeviceBuffer(commandPool, "Vertices", VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | flag, vertices, vertexBuffer_, vertexBufferMemory_);
CreateDeviceBuffer(commandPool, "Indices", VK_BUFFER_USAGE_INDEX_BUFFER_BIT | flag, indices, indexBuffer_, indexBufferMemory_);
CreateDeviceBuffer(commandPool, "Materials", flag, materials, materialBuffer_, materialBufferMemory_);
CreateDeviceBuffer(commandPool, "Offsets", flag, offsets, offsetBuffer_, offsetBufferMemory_);

CreateDeviceBuffer(commandPool, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, aabbs, aabbBuffer_, aabbBufferMemory_);
CreateDeviceBuffer(commandPool, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, procedurals, proceduralBuffer_, proceduralBufferMemory_);
CreateDeviceBuffer(commandPool, "AABBs", flag, aabbs, aabbBuffer_, aabbBufferMemory_);
CreateDeviceBuffer(commandPool, "Procedurals", flag, procedurals, proceduralBuffer_, proceduralBufferMemory_);

// Upload all textures
textureImages_.reserve(textures_.size());
Expand Down
2 changes: 1 addition & 1 deletion src/Assets/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Assets {

Texture Texture::LoadTexture(const std::string& filename, const Vulkan::SamplerConfig& samplerConfig)
{
std::cout << "Loading '" << filename << "'... " << std::flush;
std::cout << "- loading '" << filename << "'... " << std::flush;
const auto timer = std::chrono::high_resolution_clock::now();

// Load the texture in normal host memory.
Expand Down
Loading