diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2025-01-26 22:14:47 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2025-01-26 22:14:47 +0100 |
| commit | 2b2d374eb642edf345f93fa559e8cd7d76a0c9d1 (patch) | |
| tree | fbc1440dc1514a55d14f72a773b0ea962eb93dd0 | |
| parent | f63be3ecc79499a9a362ce38d0f3be44033c37fc (diff) | |
Fix mesh loading for new API
| -rw-r--r-- | include/gltf.hpp | 5 | ||||
| -rw-r--r-- | include/material.hpp | 9 | ||||
| -rw-r--r-- | include/mesh.hpp | 10 | ||||
| -rw-r--r-- | include/scene.hpp | 22 | ||||
| -rw-r--r-- | include/vec3.hpp | 9 | ||||
| -rw-r--r-- | shaders/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | shaders/compute.comp | 17 | ||||
| -rw-r--r-- | shaders/test.comp | 10 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | src/gltf.cpp | 116 | ||||
| -rw-r--r-- | src/scene.cpp | 114 | ||||
| -rw-r--r-- | src/vec3.cpp | 4 |
12 files changed, 311 insertions, 23 deletions
diff --git a/include/gltf.hpp b/include/gltf.hpp index 6e89509..1ccaf56 100644 --- a/include/gltf.hpp +++ b/include/gltf.hpp @@ -49,7 +49,12 @@ private: json gltf_json;
std::vector<Mesh> meshes;
std::vector<material> materials;
+#ifdef API_TEST
+ std::vector<handle<device_texture>> textures;
+ // handle<device_sampler> samplers;
+#else
std::vector<Texture*> textures;
+#endif // API_TEST
std::vector<std::vector<uint8_t>> buffers;
};
diff --git a/include/material.hpp b/include/material.hpp index 71dd4ca..35710d2 100644 --- a/include/material.hpp +++ b/include/material.hpp @@ -4,12 +4,21 @@ #include "vec3.hpp" +#ifdef API_TEST +#include "vk-device-types.hpp" +#else class Texture; +#endif struct material { color base_color; +#ifdef API_TEST + handle<device_texture> base_color_texture; + handle<device_texture> metallic_roughness_texture; +#else Texture* base_color_texture; Texture* metallic_roughness_texture; +#endif // API_TEST float metalness = 1.f; float roughness = 1.f; }; diff --git a/include/mesh.hpp b/include/mesh.hpp index 9a30be6..b88896d 100644 --- a/include/mesh.hpp +++ b/include/mesh.hpp @@ -4,7 +4,11 @@ #include <vector> #include <array> +#ifdef API_TEST +#include "vk-device-types.hpp" +#else #include "vk-renderer.hpp" +#endif // API_TEST enum ATTRIBUTE_TYPE { POSITION, @@ -89,9 +93,15 @@ private: std::vector<submesh_info> submeshes; struct gpu_mesh { +#ifdef API_TEST + std::array<handle<device_buffer>, ATTRIBUTE_TYPE::MAX_ATTRIBUTE> attributes; + const device_buffer& indices; + const device_buffer& submeshes; +#else std::array<Buffer*, ATTRIBUTE_TYPE::MAX_ATTRIBUTE> attributes; Buffer* indices; Buffer* submeshes; +#endif // API_TEST }; // allocate gpu mesh upon instanciation diff --git a/include/scene.hpp b/include/scene.hpp index 78b90b7..ad298da 100644 --- a/include/scene.hpp +++ b/include/scene.hpp @@ -3,6 +3,10 @@ #include <cstdint>
+#ifdef API_TEST
+#include "vk-device-types.hpp"
+#include "vk-device.hpp"
+#endif // API_TEST
#include "camera.hpp"
class Buffer;
@@ -33,6 +37,23 @@ public: metadata meta;
+#ifdef API_TEST
+ handle<device_buffer> scene_buffer_handle;
+ handle<device_buffer> indices_buffer_handle;
+ handle<device_buffer> positions_buffer_handle;
+ handle<device_buffer> normals_buffer_handle;
+ handle<device_buffer> uvs_buffer_handle;
+ handle<device_buffer> bvh_buffer_handle;
+ handle<device_buffer> materials_buffer_handle;
+
+ uint64_t scene_buffer_address() { return vkdevice::get_render_device().get_buffer(scene_buffer_handle).device_address; };
+ uint64_t indices_buffer_address() { return vkdevice::get_render_device().get_buffer(indices_buffer_handle).device_address; };
+ uint64_t positions_buffer_address() { return vkdevice::get_render_device().get_buffer(positions_buffer_handle).device_address; };
+ uint64_t normals_buffer_address() { return vkdevice::get_render_device().get_buffer(normals_buffer_handle).device_address; };
+ uint64_t uvs_buffer_address() { return vkdevice::get_render_device().get_buffer(uvs_buffer_handle).device_address; };
+ uint64_t bvh_buffer_address() { return vkdevice::get_render_device().get_buffer(bvh_buffer_handle).device_address; };
+ uint64_t materials_buffer_address() { return vkdevice::get_render_device().get_buffer(materials_buffer_handle).device_address; };
+#else
Buffer* scene_buffer;
Buffer* indices_buffer;
Buffer* positions_buffer;
@@ -40,6 +61,7 @@ public: Buffer* uvs_buffer;
Buffer* bvh_buffer;
Buffer* materials_buffer;
+#endif // API_TEST
};
#endif // !__SCENE_HPP_
diff --git a/include/vec3.hpp b/include/vec3.hpp index 75b67d2..968f3ed 100644 --- a/include/vec3.hpp +++ b/include/vec3.hpp @@ -6,8 +6,10 @@ struct vec3u { union { - uint32_t vec[3]; - uint32_t x, y, z; + uint32_t arr[3]; + struct { + uint32_t x, y, z; + } vec; }; }; @@ -36,6 +38,9 @@ class vec3 { vec3 operator>(const vec3& vec) const; + [[nodiscard]]vec3 (min)(const vec3& vec) const; + [[nodiscard]]vec3 (max)(const vec3& vec) const; + float operator[](int axis); [[nodiscard]] float length() const; diff --git a/shaders/CMakeLists.txt b/shaders/CMakeLists.txt index f572ced..8f6985f 100644 --- a/shaders/CMakeLists.txt +++ b/shaders/CMakeLists.txt @@ -13,7 +13,7 @@ foreach(GLSL ${GLSL_SOURCE_FILES}) set(SPIRV "${PROJECT_BINARY_DIR}/shaders/${FILE_NAME}.spv") add_custom_command( OUTPUT ${SPIRV} - COMMAND glslc --target-env=vulkan1.2 -std=460 ${GLSL} -o ${SPIRV} -I "../../shaders/include" # relative to build directory + COMMAND glslc --target-env=vulkan1.2 -g -O -std=460 ${GLSL} -o ${SPIRV} -I "../../shaders/include" # relative to build directory DEPENDS ${GLSL}) list(APPEND SPIRV_BINARY_FILES ${SPIRV}) endforeach(GLSL) diff --git a/shaders/compute.comp b/shaders/compute.comp index 92fa9db..14f1238 100644 --- a/shaders/compute.comp +++ b/shaders/compute.comp @@ -142,13 +142,15 @@ vec3 ray_color(ray r, uint seed) { vec3 diffuse_color = srgb_to_linear(texture( sampler2D( textures[nonuniformEXT(tri.mat.base_color_texture.texture_id)], - samplers[nonuniformEXT(tri.mat.base_color_texture.sampler_id)] + // samplers[nonuniformEXT(tri.mat.base_color_texture.sampler_id)] + samplers[1] ), uv ).xyz) * tri.mat.base_color.xyz; vec2 metalness_roughness = texture( sampler2D( textures[nonuniformEXT(tri.mat.metallic_roughness_texture.texture_id)], - samplers[nonuniformEXT(tri.mat.metallic_roughness_texture.sampler_id)] + // samplers[nonuniformEXT(tri.mat.metallic_roughness_texture.sampler_id)] + samplers[1] ), uv ).xy * vec2(tri.mat.metalness, tri.mat.roughness); @@ -281,9 +283,10 @@ void main() { vec3 acc_color = srgb_to_linear(imageLoad(images[nonuniformEXT(bufs.accumulation_image_index)], coords).xyz); out_color = linear_to_srgb(mix(acc_color, out_color, spp_scale)); - for (uint i = 0; i < bufs.scene.downscale_factor; i++) { - for (uint j = 0; j < bufs.scene.downscale_factor; j++) { - imageStore(images[nonuniformEXT(bufs.output_image_index)], coords + ivec2(i, j), vec4(out_color, 1.0)); - } - } + // for (uint i = 0; i < bufs.scene.downscale_factor; i++) { + // for (uint j = 0; j < bufs.scene.downscale_factor; j++) { + // imageStore(images[nonuniformEXT(bufs.output_image_index)], coords + ivec2(i, j), vec4(out_color, 1.0)); + // } + // } + imageStore(images[nonuniformEXT(bufs.output_image_index)], coords, vec4(out_color, 1.0)); } diff --git a/shaders/test.comp b/shaders/test.comp index b3d2089..a17de69 100644 --- a/shaders/test.comp +++ b/shaders/test.comp @@ -6,10 +6,18 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; layout(set = 0, binding = 0) uniform sampler samplers[]; layout(set = 0, binding = 1) uniform texture2D textures[]; layout(set = 0, binding = 2, rgba32f) uniform image2D images[]; -layout(set = 2, binding = 0) uniform parameters { +// layout(set = 2, binding = 0) uniform parameters { +// uint input_id1; +// uint input_id2; +// uint output_id; +// } params; +layout(push_constant) uniform parameters { uint input_id1; + uint padding1; uint input_id2; + uint padding2; uint output_id; + uint padding3; } params; void main() { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f514f0..d482ddf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ set(LIBRARIES imgui::imgui) -set(DEFINES -DNOMINMAX -D_USE_MATH_DEFINES -DVK_NO_PROTOTYPES) +set(DEFINES -DNOMINMAX -D_USE_MATH_DEFINES -DVK_NO_PROTOTYPES TRACY_ENABLE) if(UNIX AND NOT APPLE) set(DEFINES ${DEFINES} -DLINUX -DVK_USE_PLATFORM_XCB_KHR) @@ -30,6 +30,8 @@ add_executable( bvh.cpp mesh.cpp resource-manager.cpp + + ${CMAKE_SOURCE_DIR}/tracy/public/TracyClient.cpp ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") @@ -57,11 +59,17 @@ target_link_directories(path-tracer PRIVATE "C:\\Program Files\\LLVM\\lib\\clang target_compile_definitions(path-tracer PUBLIC ${DEFINES}) -target_include_directories(path-tracer SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/thirdparty) +target_include_directories(path-tracer + SYSTEM PUBLIC + + ${CMAKE_SOURCE_DIR}/thirdparty + ${CMAKE_SOURCE_DIR}/tracy/public + ${Vulkan_INCLUDE_DIRS} -target_include_directories(path-tracer SYSTEM PUBLIC ${Vulkan_INCLUDE_DIRS}) + PUBLIC -target_include_directories(path-tracer PUBLIC ${CMAKE_SOURCE_DIR}/include) + ${CMAKE_SOURCE_DIR}/include +) if(UNIX AND NOT APPLE) target_include_directories(path-tracer PUBLIC ${X11_xcb_INCLUDE_PATH}) diff --git a/src/gltf.cpp b/src/gltf.cpp index 0e611da..1d3d935 100644 --- a/src/gltf.cpp +++ b/src/gltf.cpp @@ -5,16 +5,32 @@ #include <filesystem> #include <fstream> +#ifndef API_TEST #define STB_IMAGE_IMPLEMENTATION +#endif #include <stb_image.h> #include "utils.hpp" +#ifdef API_TEST +#include "vk-device-types.hpp" +#include "vk-device.hpp" +#include <vk_mem_alloc.h> +#else #include "vk-renderer.hpp" +#endif + +#ifdef TRACY_ENABLE +#include "tracy/Tracy.hpp" +#endif gltf::gltf(const std::filesystem::path& filepath) { auto parent_path = filepath.parent_path(); std::fstream f{ filepath }; + if (!f.is_open()) { + OutputDebugStringA("failed to open!"); + } + f >> gltf_json; auto& scene = gltf_json["scenes"][0]; @@ -119,6 +135,42 @@ void gltf::load_textures(const std::filesystem::path& path) { std::vector<size_t> v(images_count); std::iota(v.begin(), v.end(), 0); + const auto& gltf_textures = gltf_json["textures"]; + auto textures_count = gltf_textures.size(); + textures.resize(textures_count); + +#ifdef API_TEST + auto& device = vkdevice::get_render_device(); + + constexpr auto buffers_count = 2U; + auto total_size = images_count * 4096U * 4096 * sizeof(uint32_t); + auto buffer_size = total_size / 32U; + + handle<device_buffer> staging_buffers_handle[buffers_count] = { + device.create_buffer({ + .size = buffer_size, + .usages = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, + .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU, + }), + device.create_buffer({ + .size = buffer_size, + .usages = VK_BUFFER_USAGE_TRANSFER_SRC_BIT, + .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, + .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU, + }), + }; + + graphics_command_buffer command_buffers[buffers_count]; + device.allocate_command_buffers(command_buffers, buffers_count, QueueType::GRAPHICS); + auto buffer_index = 0U; + auto command_buffer = command_buffers[buffer_index]; + auto buffer_handle = staging_buffers_handle[buffer_index]; + auto buffer = device.get_buffer(buffer_handle); + + command_buffer.start(); +#endif // API_TEST + std::for_each(std::execution::par, v.begin(), v.end(), [&](const size_t image_index) { const auto& gltf_image = gltf_images[image_index]; auto filepath = (path / gltf_image["uri"].get<std::string>()).string(); @@ -130,14 +182,69 @@ void gltf::load_textures(const std::filesystem::path& path) { // auto samplers_count = gltf_samplers.size(); // std::vector<Sampler *> samplers{samplers_count}; - Sampler* sampler = vkrenderer::create_sampler(VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT); +#ifdef API_TEST + const auto &gltf_samplers = gltf_json["samplers"]; + auto samplers_count = gltf_samplers.size(); + std::vector<handle<device_sampler>> samplers{samplers_count}; + + // auto sampler = device.create_sampler(VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT); // for (size_t sampler_index = 0; sampler_index < samplers_count; sampler_index++) { // samplers[sampler_index] = vkrenderer::create_sampler(VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT); // } - const auto& gltf_textures = gltf_json["textures"]; - auto textures_count = gltf_textures.size(); - textures.resize(textures_count); + for (size_t texture_index = 0; texture_index < textures_count; texture_index++) { + auto gltf_texture = gltf_textures[texture_index]; + auto& image = images[gltf_texture["source"].get<uint32_t>()]; + // if (gltf_texture.contains("sampler")) { + // auto sampler_index = gltf_texture["sampler"].get<uint32_t>(); + // sampler = samplers[sampler_index]; + // } + + auto texture = device.create_texture({ + .width = static_cast<uint32_t>(image.width), + .height = static_cast<uint32_t>(image.height), + .usages = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + .format = VK_FORMAT_R8G8B8A8_UNORM, + .type = VK_IMAGE_TYPE_2D, + }); + + uint64_t size = image.width * image.height * sizeof(uint32_t); + auto offset = buffer.offset; + if (offset + size > buffer_size) { + command_buffer.stop(); + + device.submit(&command_buffer, 1 ); + + buffer_index = (++buffer_index) % buffers_count; + command_buffer = command_buffers[buffer_index]; + buffer_handle = staging_buffers_handle[buffer_index]; + buffer = device.get_buffer(buffer_handle); + buffer.reset(); + device.wait(); + command_buffer.start(); + offset = 0U; + } + + void* ptr = buffer.allocate(size); + memcpy(ptr, image.data, size); + + command_buffer.barrier(texture, VK_PIPELINE_STAGE_2_TRANSFER_BIT, VK_ACCESS_2_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + command_buffer.copy(buffer_handle, texture, static_cast<VkDeviceSize>(offset)); + command_buffer.barrier(texture, VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT, VK_ACCESS_2_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL); + + textures[texture_index] = texture; + } + + command_buffer.stop(); + device.submit(&command_buffer, 1); + device.wait(); + device.destroy_buffer(staging_buffers_handle[0]); + device.destroy_buffer(staging_buffers_handle[1]); +#else + Sampler* sampler = vkrenderer::create_sampler(VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT); + // for (size_t sampler_index = 0; sampler_index < samplers_count; sampler_index++) { + // samplers[sampler_index] = vkrenderer::create_sampler(VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT); + // } for (size_t texture_index = 0; texture_index < textures_count; texture_index++) { auto gltf_texture = gltf_textures[texture_index]; @@ -154,6 +261,7 @@ void gltf::load_textures(const std::filesystem::path& path) { textures[texture_index] = texture; } +#endif } void gltf::load_materials() { diff --git a/src/scene.cpp b/src/scene.cpp index 9980e75..b70026a 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -3,7 +3,12 @@ #include <filesystem>
#include <queue>
+#ifdef API_TEST
+#include <vk_mem_alloc.h>
+#else
#include "vk-renderer.hpp"
+#endif // API_TEST
+
#include "gltf.hpp"
#include "bvh.hpp"
#include "material.hpp"
@@ -64,6 +69,10 @@ scene::metadata::metadata(const camera &cam, uint32_t width, uint32_t height) scene::scene(const camera& cam, uint32_t width, uint32_t height)
:meta(cam, width, height){
+#ifdef API_TEST
+ auto& device = vkdevice::get_render_device();
+#endif
+
// Geometry & BVH
std::vector<uint32_t> indices;
std::vector<float> positions;
@@ -145,7 +154,7 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height) // const auto& albedo_image = vkrenderer::api.get_image(material.base_color_texture->device_image);
// const auto& albedo_sampler = vkrenderer::api.get_sampler(material.base_color_texture->sampler->device_sampler);
- materials.emplace_back(gpu_material {
+ auto& mat = materials.emplace_back(gpu_material {
.base_color = material.base_color,
// .albedo_texture_id = albedo_image.bindless_sampled_index,
// .albedo_texture_sampler_id = albedo_sampler.bindless_index,
@@ -153,14 +162,26 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height) .roughness = material.roughness
});
+#ifdef API_TEST
+ if (material.base_color_texture.id != handle<device_texture>::invalid_id) {
+ mat.albedo_texture_id = device.get_texture(material.base_color_texture).get_sampled_index();
+ // mat.albedo_texture_sampler_id = device.get_sampler(0);
+ }
+
+ if (material.metallic_roughness_texture.id != handle<device_texture>::invalid_id) {
+ mat.metallic_roughness_texture_id = device.get_texture(material.metallic_roughness_texture).get_sampled_index();
+ // mat.metallic_roughness_texture_sampler_id = device.get_sampler(0);
+ }
+#else
if (material.metallic_roughness_texture != nullptr) {
- auto& gpu_material = materials.back();
+ // auto& gpu_material = materials.back();
// const auto& metallic_roughness_image = vkrenderer::api.get_image(material.metallic_roughness_texture->device_image);
// const auto& metallic_roughness_sampler = vkrenderer::api.get_sampler(material.metallic_roughness_texture->sampler->device_sampler);
// gpu_material.metallic_roughness_texture_id = metallic_roughness_image.bindless_sampled_index;
// gpu_material.metallic_roughness_texture_sampler_id = metallic_roughness_sampler.bindless_index;
}
+#endif
}
@@ -180,6 +201,94 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height) bvh builder(triangles, packed_nodes);
// bvh builder(spheres, packed_nodes);
+#ifdef API_TEST
+ {
+ scene_buffer_handle = device.create_buffer({
+ .size = sizeof(meta) * 3U,
+ .usages = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
+ .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+ .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ });
+
+ const auto& scene_buffer = device.get_buffer(scene_buffer_handle);
+ uint8_t* ptr = static_cast<uint8_t*>(scene_buffer.mapped_ptr);
+ memcpy(static_cast<void*>(ptr), &meta, sizeof(meta));
+ memcpy(static_cast<void*>(ptr + sizeof(meta)), &meta, sizeof(meta));
+ memcpy(static_cast<void*>(ptr + sizeof(meta) * 2U), &meta, sizeof(meta));
+ }
+
+ {
+ indices_buffer_handle = device.create_buffer({
+ .size = indices.size() * sizeof(indices[0]),
+ .usages = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
+ .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+ .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ });
+ const auto& indices_buffer = device.get_buffer(indices_buffer_handle);
+ void* ptr = indices_buffer.mapped_ptr;
+ memcpy(ptr, indices.data(), indices.size() * sizeof(indices[0]));
+ }
+
+ {
+ positions_buffer_handle = device.create_buffer({
+ .size = positions.size() * sizeof(positions[0]),
+ .usages = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
+ .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+ .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ });
+ const auto& positions_buffer = device.get_buffer(positions_buffer_handle);
+ void* ptr = positions_buffer.mapped_ptr;
+ memcpy(ptr, positions.data(), positions.size() * sizeof(positions[0]));
+ }
+
+ {
+ normals_buffer_handle = device.create_buffer({
+ .size = normals.size() * sizeof(normals[0]),
+ .usages = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
+ .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+ .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ });
+ const auto& normals_buffer = device.get_buffer(normals_buffer_handle);
+ void* ptr = normals_buffer.mapped_ptr;
+ memcpy(ptr, normals.data(), normals.size() * sizeof(normals[0]));
+ }
+
+ {
+ uvs_buffer_handle = device.create_buffer({
+ .size = uvs.size() * sizeof(uvs[0]),
+ .usages = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
+ .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+ .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ });
+ const auto& uvs_buffer = device.get_buffer(uvs_buffer_handle);
+ void* ptr = uvs_buffer.mapped_ptr;
+ memcpy(ptr, uvs.data(), uvs.size() * sizeof(uvs[0]));
+ }
+
+ {
+ bvh_buffer_handle = device.create_buffer({
+ .size = packed_nodes.size() * sizeof(packed_nodes[0]),
+ .usages = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
+ .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+ .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ });
+ const auto& bvh_buffer = device.get_buffer(bvh_buffer_handle);
+ void* ptr = bvh_buffer.mapped_ptr;
+ memcpy(ptr, packed_nodes.data(), packed_nodes.size() * sizeof(packed_nodes[0]));
+ }
+
+ {
+ materials_buffer_handle = device.create_buffer({
+ .size = materials.size() * sizeof(materials[0]),
+ .usages = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
+ .memory_properties = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+ .memory_usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
+ });
+ const auto& materials_buffer = device.get_buffer(materials_buffer_handle);
+ void* ptr = materials_buffer.mapped_ptr;
+ memcpy(ptr, materials.data(), materials.size() * sizeof(materials[0]));
+ }
+#else
scene_buffer = vkrenderer::create_buffer(sizeof(meta) * vkrenderer::virtual_frames_count);
scene_buffer->write(&meta, 0, sizeof(meta));
scene_buffer->write(&meta, sizeof(meta), sizeof(meta));
@@ -202,4 +311,5 @@ scene::scene(const camera& cam, uint32_t width, uint32_t height) materials_buffer = vkrenderer::create_buffer(materials.size() * sizeof(materials[0]));
materials_buffer->write(materials.data(), 0, materials.size() * sizeof(materials[0]));
+#endif // API_TEST
}
diff --git a/src/vec3.cpp b/src/vec3.cpp index 0e08f16..73dec98 100644 --- a/src/vec3.cpp +++ b/src/vec3.cpp @@ -73,11 +73,11 @@ vec3 vec3::cross(const vec3& vec) const { return _mm_sub_ps(tmp3, tmp4); } -vec3 vec3::min(const vec3& vec) const { +vec3 (vec3::min)(const vec3& vec) const { return { _mm_min_ps(v, vec.v) }; } -vec3 vec3::max(const vec3& vec) const { +vec3 (vec3::max)(const vec3& vec) const { return { _mm_max_ps(v, vec.v) }; } |
