Skip to content

Commit

Permalink
Use staging buffer convenience method where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jherico committed Feb 26, 2024
1 parent 7fdca28 commit 52f81f8
Show file tree
Hide file tree
Showing 32 changed files with 156 additions and 538 deletions.
4 changes: 0 additions & 4 deletions framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ set(CORE_FILES
core/framebuffer.h
core/render_pass.h
core/query_pool.h
core/scratch_buffer.h
core/acceleration_structure.h
core/shader_binding_table.h
core/hpp_allocated.h
core/hpp_buffer.h
core/hpp_command_buffer.h
Expand Down Expand Up @@ -303,9 +301,7 @@ set(CORE_FILES
core/framebuffer.cpp
core/render_pass.cpp
core/query_pool.cpp
core/scratch_buffer.cpp
core/acceleration_structure.cpp
core/shader_binding_table.cpp
core/vulkan_resource.cpp
core/hpp_buffer.cpp
core/hpp_command_buffer.cpp
Expand Down
23 changes: 4 additions & 19 deletions framework/api_vulkan_sample.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019-2023, Sascha Willems
/* Copyright (c) 2019-2024, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -1000,12 +1000,7 @@ Texture ApiVulkanSample::load_texture(const std::string &file, vkb::sg::Image::C

VkCommandBuffer command_buffer = device->create_command_buffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);

vkb::core::Buffer stage_buffer{*device,
texture.image->get_data().size(),
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VMA_MEMORY_USAGE_CPU_ONLY};

stage_buffer.update(texture.image->get_data());
vkb::core::Buffer stage_buffer = vkb::core::Buffer::create_staging_buffer(*device, texture.image->get_data());

// Setup buffer copy regions for each mip level
std::vector<VkBufferImageCopy> bufferCopyRegions;
Expand Down Expand Up @@ -1096,12 +1091,7 @@ Texture ApiVulkanSample::load_texture_array(const std::string &file, vkb::sg::Im

VkCommandBuffer command_buffer = device->create_command_buffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);

vkb::core::Buffer stage_buffer{*device,
texture.image->get_data().size(),
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VMA_MEMORY_USAGE_CPU_ONLY};

stage_buffer.update(texture.image->get_data());
vkb::core::Buffer stage_buffer = vkb::core::Buffer::create_staging_buffer(*device, texture.image->get_data());

// Setup buffer copy regions for each mip level
std::vector<VkBufferImageCopy> buffer_copy_regions;
Expand Down Expand Up @@ -1195,12 +1185,7 @@ Texture ApiVulkanSample::load_texture_cubemap(const std::string &file, vkb::sg::

VkCommandBuffer command_buffer = device->create_command_buffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);

vkb::core::Buffer stage_buffer{*device,
texture.image->get_data().size(),
VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
VMA_MEMORY_USAGE_CPU_ONLY};

stage_buffer.update(texture.image->get_data());
vkb::core::Buffer stage_buffer = vkb::core::Buffer::create_staging_buffer(*device, texture.image->get_data());

// Setup buffer copy regions for each mip level
std::vector<VkBufferImageCopy> buffer_copy_regions;
Expand Down
10 changes: 7 additions & 3 deletions framework/core/acceleration_structure.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021, Sascha Willems
/* Copyright (c) 2021-2024, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -23,7 +23,7 @@ namespace vkb
{
namespace core
{
AccelerationStructure::AccelerationStructure(Device & device,
AccelerationStructure::AccelerationStructure(Device &device,
VkAccelerationStructureTypeKHR type) :
device{device},
type{type}
Expand Down Expand Up @@ -202,7 +202,11 @@ void AccelerationStructure::build(VkQueue queue, VkBuildAccelerationStructureFla
device_address = vkGetAccelerationStructureDeviceAddressKHR(device.get_handle(), &acceleration_device_address_info);

// Create a scratch buffer as a temporary storage for the acceleration structure build
scratch_buffer = std::make_unique<vkb::core::ScratchBuffer>(device, build_sizes_info.buildScratchSize);
scratch_buffer = std::make_unique<vkb::core::Buffer>(
device,
build_sizes_info.buildScratchSize,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
VMA_MEMORY_USAGE_GPU_ONLY);

build_geometry_info.scratchData.deviceAddress = scratch_buffer->get_device_address();
build_geometry_info.dstAccelerationStructure = handle;
Expand Down
9 changes: 4 additions & 5 deletions framework/core/acceleration_structure.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021, Sascha Willems
/* Copyright (c) 2021-2024, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -20,7 +20,6 @@
#include "common/helpers.h"
#include "common/vk_common.h"
#include "core/buffer.h"
#include "core/scratch_buffer.h"

namespace vkb
{
Expand All @@ -39,7 +38,7 @@ class AccelerationStructure
* @param device A valid Vulkan device
* @param type The type of the acceleration structure (top- or bottom-level)
*/
AccelerationStructure(Device & device,
AccelerationStructure(Device &device,
VkAccelerationStructureTypeKHR type);

~AccelerationStructure();
Expand All @@ -54,7 +53,7 @@ class AccelerationStructure
* @param max_vertex Index of the last vertex in the geometry
* @param vertex_stride Stride of the vertex structure
* @param transform_offset Offset of this geometry in the transform data buffer
* @param vertex_format Format of the vertex structure
* @param vertex_format Format of the vertex structure
* @param flags Ray tracing geometry flags
* @param vertex_buffer_data_address set this if don't want the vertex_buffer data_address
* @param index_buffer_data_address set this if don't want the index_buffer data_address
Expand Down Expand Up @@ -149,7 +148,7 @@ class AccelerationStructure
bool updated = false;
};

std::unique_ptr<vkb::core::ScratchBuffer> scratch_buffer;
std::unique_ptr<vkb::core::Buffer> scratch_buffer;

std::map<uint64_t, Geometry> geometries{};

Expand Down
74 changes: 0 additions & 74 deletions framework/core/scratch_buffer.cpp

This file was deleted.

71 changes: 0 additions & 71 deletions framework/core/scratch_buffer.h

This file was deleted.

80 changes: 0 additions & 80 deletions framework/core/shader_binding_table.cpp

This file was deleted.

Loading

0 comments on commit 52f81f8

Please sign in to comment.