From 7f0809de93af9cbf40492edc57b61913446ac7c9 Mon Sep 17 00:00:00 2001 From: Harrand Date: Wed, 30 Oct 2024 16:41:28 +0000 Subject: [PATCH] [gpu.resource] resource_write now can have an offset --- include/tz/gpu/resource.hpp | 2 +- src/tz/gpu/rhi_vulkan.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/tz/gpu/resource.hpp b/include/tz/gpu/resource.hpp index b369e20772..9e1f62b235 100644 --- a/include/tz/gpu/resource.hpp +++ b/include/tz/gpu/resource.hpp @@ -202,7 +202,7 @@ namespace tz::gpu * - If the image was created with @ref image_type::rgba, then each pixel should be 4 bytes - one for each component (0-255). * - If the image was created with @ref image_type::depth or @ref image_type::floats, then each pixel should be 4 bytes - a single signed 32-bit float. */ - void resource_write(resource_handle res, std::span new_data); + void resource_write(resource_handle res, std::span new_data, std::size_t offset = 0); /** * @ingroup tz_gpu_resource * @brief Retrieves the current data within a resource. diff --git a/src/tz/gpu/rhi_vulkan.cpp b/src/tz/gpu/rhi_vulkan.cpp index d7d72e777d..57c91ec4ee 100644 --- a/src/tz/gpu/rhi_vulkan.cpp +++ b/src/tz/gpu/rhi_vulkan.cpp @@ -898,12 +898,12 @@ namespace tz::gpu return tz::error_code::success; } - void resource_write(resource_handle resh, std::span new_data) + void resource_write(resource_handle resh, std::span new_data, std::size_t offset) { auto& res = resources[resh.peek()]; // update the resource data cpu-side. - tz_assert(new_data.size_bytes() == res.data.size(), "resource write data span is of wrong size."); - std::copy(new_data.begin(), new_data.end(), res.data.begin()); + tz_assert(offset + new_data.size_bytes() <= res.data.size(), "resource write data span is of wrong size."); + std::copy(new_data.begin(), new_data.end(), res.data.begin() + offset); // make sure the change is resident GPU-side. // definitely could cause gpu sync issues if commands are currently in-flight that are reading from it. impl_write_single_resource(resh);