From f076fa089c996898fff1e1063d010d3cfc671152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mercan=20Yazici?= Date: Tue, 11 Feb 2025 12:17:33 +0100 Subject: [PATCH] rename --- .../{UnifiedArray.cpp => DeviceArray.cpp} | 18 ++++---- src/device/{UnifiedArray.h => DeviceArray.h} | 46 +++++++++---------- src/device/DeviceInterface.cpp | 44 +++++++++--------- src/device/DeviceInterface.h | 22 ++++----- 4 files changed, 65 insertions(+), 65 deletions(-) rename src/device/{UnifiedArray.cpp => DeviceArray.cpp} (55%) rename src/device/{UnifiedArray.h => DeviceArray.h} (85%) diff --git a/src/device/UnifiedArray.cpp b/src/device/DeviceArray.cpp similarity index 55% rename from src/device/UnifiedArray.cpp rename to src/device/DeviceArray.cpp index 8b872b05..25a84f70 100644 --- a/src/device/UnifiedArray.cpp +++ b/src/device/DeviceArray.cpp @@ -1,31 +1,31 @@ -#include "UnifiedArray.h" +#include "DeviceArray.h" #include namespace IG { -void* UnifiedArrayBase::allocateUnified(int dev, size_t sizeInBytes) +void* DeviceArrayBase::allocateUnified(int dev, size_t sizeInBytes) { return anydsl_alloc_unified(dev, (int64_t)sizeInBytes); } -void* UnifiedArrayBase::allocateDevice(int dev, size_t sizeInBytes) +void* DeviceArrayBase::allocateDevice(int dev, size_t sizeInBytes) { return anydsl_alloc(dev, (int64_t)sizeInBytes); } -void UnifiedArrayBase::deallocateUnified(int dev, void* ptr) +void DeviceArrayBase::deallocateUnified(int dev, void* ptr) { if (ptr) anydsl_release(dev, ptr); } -void UnifiedArrayBase::deallocateDevice(int dev, void* ptr) +void DeviceArrayBase::deallocateDevice(int dev, void* ptr) { if (ptr) anydsl_release(dev, ptr); } -void* UnifiedArrayBase::getDevicePtr(int dev, void* hostPtr) +void* DeviceArrayBase::getDevicePtr(int dev, void* hostPtr) { if (dev == 0) return hostPtr; @@ -35,13 +35,13 @@ void* UnifiedArrayBase::getDevicePtr(int dev, void* hostPtr) return nullptr; } -void UnifiedArrayBase::fillHostWithZero(int dev, void* ptr, size_t sizeInBytes) +void DeviceArrayBase::fillHostWithZero(int dev, void* ptr, size_t sizeInBytes) { IG_UNUSED(dev); std::memset(ptr, 0, sizeInBytes); } -void UnifiedArrayBase::copyToHost(int dev, const void* devPtr, void* hostPtr, size_t sizeInBytes) +void DeviceArrayBase::copyToHost(int dev, const void* devPtr, void* hostPtr, size_t sizeInBytes) { if (dev == 0 /*Host*/ && devPtr == hostPtr) return; @@ -49,7 +49,7 @@ void UnifiedArrayBase::copyToHost(int dev, const void* devPtr, void* hostPtr, si anydsl_copy(dev, devPtr, 0, 0 /*Host*/, hostPtr, 0, (int64)sizeInBytes); } -void UnifiedArrayBase::copyFromHost(int dev, void* devPtr, const void* hostPtr, size_t sizeInBytes) +void DeviceArrayBase::copyFromHost(int dev, void* devPtr, const void* hostPtr, size_t sizeInBytes) { if (dev == 0 /*Host*/ && devPtr == hostPtr) return; diff --git a/src/device/UnifiedArray.h b/src/device/DeviceArray.h similarity index 85% rename from src/device/UnifiedArray.h rename to src/device/DeviceArray.h index 130d0dde..1860ba67 100644 --- a/src/device/UnifiedArray.h +++ b/src/device/DeviceArray.h @@ -3,7 +3,7 @@ #include "IG_Config.h" namespace IG { -class UnifiedArrayBase { +class DeviceArrayBase { protected: [[nodiscard]] static void* allocateUnified(int dev, size_t sizeInBytes); [[nodiscard]] static void* allocateDevice(int dev, size_t sizeInBytes); @@ -16,8 +16,8 @@ class UnifiedArrayBase { }; template -class UnifiedArray : public UnifiedArrayBase { - IG_CLASS_NON_COPYABLE(UnifiedArray); +class DeviceArray : public DeviceArrayBase { + IG_CLASS_NON_COPYABLE(DeviceArray); public: enum class MemoryType { @@ -39,7 +39,7 @@ class UnifiedArray : public UnifiedArrayBase { MemoryType Type; int32 StatusFlags; - inline UnifiedArray() + inline DeviceArray() : DevicePtr(nullptr) , HostPtr(nullptr) , SizeInBytes(0) @@ -49,7 +49,7 @@ class UnifiedArray : public UnifiedArrayBase { { } - inline UnifiedArray(UnifiedArray&& arr) + inline DeviceArray(DeviceArray&& arr) : DevicePtr(arr.DevicePtr) , HostPtr(arr.HostPtr) , SizeInBytes(arr.SizeInBytes) @@ -65,10 +65,10 @@ class UnifiedArray : public UnifiedArrayBase { arr.StatusFlags = 0; } - static inline UnifiedArray AllocateUnified(int dev, size_t size) + static inline DeviceArray AllocateUnified(int dev, size_t size) { void* ptr = allocateUnified(dev, size * sizeof(T)); - return UnifiedArray( + return DeviceArray( (T*)ptr, (T*)ptr, size * sizeof(T), @@ -76,9 +76,9 @@ class UnifiedArray : public UnifiedArrayBase { MemoryType::Unified); } - static inline UnifiedArray AllocateDevice(int dev, size_t size) + static inline DeviceArray AllocateDevice(int dev, size_t size) { - return UnifiedArray( + return DeviceArray( nullptr, (T*)allocateDevice(dev, size * sizeof(T)), size * sizeof(T), @@ -86,10 +86,10 @@ class UnifiedArray : public UnifiedArrayBase { MemoryType::Device); } - static inline UnifiedArray AllocateBuffered(int dev, size_t size) + static inline DeviceArray AllocateBuffered(int dev, size_t size) { void* devPtr = allocateDevice(dev, size * sizeof(T)); - return UnifiedArray( + return DeviceArray( dev != 0 ? (T*)allocateDevice(0 /*Host*/, size * sizeof(T)) : (T*)devPtr, // Only allocate buffer if the device != host (T*)devPtr, size * sizeof(T), @@ -97,9 +97,9 @@ class UnifiedArray : public UnifiedArrayBase { MemoryType::Buffered); } - static inline UnifiedArray CreateExternal(int dev, T* ptr, size_t size) + static inline DeviceArray CreateExternal(int dev, T* ptr, size_t size) { - return UnifiedArray( + return DeviceArray( ptr, ptr, size * sizeof(T), @@ -107,7 +107,7 @@ class UnifiedArray : public UnifiedArrayBase { MemoryType::External); } - static inline UnifiedArray CreateExternalOrAllocateUnified(int dev, T* ptr, size_t size, bool externalFlag) + static inline DeviceArray CreateExternalOrAllocateUnified(int dev, T* ptr, size_t size, bool externalFlag) { if (externalFlag) { return CreateExternal(dev, ptr, size); @@ -118,7 +118,7 @@ class UnifiedArray : public UnifiedArrayBase { } } - static inline UnifiedArray CreateExternalOrAllocateDevice(int dev, T* ptr, size_t size, bool externalFlag) + static inline DeviceArray CreateExternalOrAllocateDevice(int dev, T* ptr, size_t size, bool externalFlag) { if (externalFlag) { return CreateExternal(dev, ptr, size); @@ -129,12 +129,12 @@ class UnifiedArray : public UnifiedArrayBase { } } - inline ~UnifiedArray() + inline ~DeviceArray() { release(); } - inline UnifiedArray& operator=(UnifiedArray&& arr) + inline DeviceArray& operator=(DeviceArray&& arr) { release(); @@ -161,14 +161,14 @@ class UnifiedArray : public UnifiedArrayBase { inline void fillHostWithZero() { - UnifiedArrayBase::fillHostWithZero(Device, (void*)HostPtr, SizeInBytes); + DeviceArrayBase::fillHostWithZero(Device, (void*)HostPtr, SizeInBytes); StatusFlags &= ~(int)Flags::DirtyDevice; // We do not care if the device is "dirty". Cleanup has priority StatusFlags |= (int)Flags::DirtyHost; } inline void copyFromExternalHostToDevice(const T* hostPtr, size_t sizeInBytes) { - UnifiedArrayBase::copyFromHost(Device, DevicePtr, hostPtr, sizeInBytes); + DeviceArrayBase::copyFromHost(Device, DevicePtr, hostPtr, sizeInBytes); StatusFlags |= (int)Flags::DirtyDevice; } @@ -176,7 +176,7 @@ class UnifiedArray : public UnifiedArrayBase { inline void copyFromDeviceToExternalHost(T* hostPtr, size_t sizeInBytes) { - UnifiedArrayBase::copyToHost(Device, DevicePtr, hostPtr, sizeInBytes); + DeviceArrayBase::copyToHost(Device, DevicePtr, hostPtr, sizeInBytes); } inline void copyFromDeviceToExternalHost(T* hostPtr) { copyFromDeviceToExternalHost(hostPtr, SizeInBytes); } @@ -211,7 +211,7 @@ class UnifiedArray : public UnifiedArrayBase { IG_ASSERT((StatusFlags & ((int)Flags::DirtyDevice | (int)Flags::DirtyHost)) != ((int)Flags::DirtyDevice | (int)Flags::DirtyHost), "Unified array can not deal with device and host buffer being out of sync at the same time!"); - UnifiedArrayBase::copyFromHost(Device, DevicePtr, HostPtr, SizeInBytes); + DeviceArrayBase::copyFromHost(Device, DevicePtr, HostPtr, SizeInBytes); } } @@ -226,7 +226,7 @@ class UnifiedArray : public UnifiedArrayBase { IG_ASSERT((StatusFlags & ((int)Flags::DirtyDevice | (int)Flags::DirtyHost)) != ((int)Flags::DirtyDevice | (int)Flags::DirtyHost), "Unified array can not deal with device and host buffer being out of sync at the same time!"); - UnifiedArrayBase::copyToHost(Device, DevicePtr, HostPtr, SizeInBytes); + DeviceArrayBase::copyToHost(Device, DevicePtr, HostPtr, SizeInBytes); } } @@ -261,7 +261,7 @@ class UnifiedArray : public UnifiedArrayBase { } private: - inline UnifiedArray(T* hostPtr, T* devicePtr, size_t sizeInBytes, int device, MemoryType type) + inline DeviceArray(T* hostPtr, T* devicePtr, size_t sizeInBytes, int device, MemoryType type) : DevicePtr(devicePtr) , HostPtr(hostPtr) , SizeInBytes(sizeInBytes) diff --git a/src/device/DeviceInterface.cpp b/src/device/DeviceInterface.cpp index cccfa273..761723aa 100644 --- a/src/device/DeviceInterface.cpp +++ b/src/device/DeviceInterface.cpp @@ -45,12 +45,12 @@ static inline size_t roundUp(size_t num, size_t multiple) } template -static inline void resizeDeviceArray(int32_t dev, UnifiedArray& array, size_t size, size_t multiplier) +static inline void resizeDeviceArray(int32_t dev, DeviceArray& array, size_t size, size_t multiplier) { const auto capacity = roundUp(std::max(1, size), 32); const size_t n = capacity * multiplier; if (array.SizeInBytes < n * sizeof(T)) { - array = UnifiedArray::AllocateDevice(dev, n); + array = DeviceArray::AllocateDevice(dev, n); if (array.DevicePtr == nullptr) IG_LOG(L_FATAL) << "Stream allocation resulted in out of memory!" << std::endl; } @@ -204,13 +204,13 @@ void DeviceInterface::resizeFramebuffer(size_t width, size_t height) ensureFramebuffer(); } -static inline UnifiedArray createAOVArray(int device, size_t size) +static inline DeviceArray createAOVArray(int device, size_t size) { // Unified memory on Windows (Nvidia RTX 4070 Ti Super) has quite a penalty for our AOV access pattern. AOVs in general are easy to sync in access so it is not worth it. #if 1 - return UnifiedArray::AllocateBuffered(device, size); + return DeviceArray::AllocateBuffered(device, size); #else - return UnifiedArray::AllocateUnified(device, size); + return DeviceArray::AllocateUnified(device, size); #endif } @@ -474,7 +474,7 @@ void* DeviceInterface::loadRayList() IG_ASSERT(mCurrentRenderSettings.rays != nullptr, "Expected list of rays to be available"); - device.ray_list = UnifiedArray::AllocateDevice(mDeviceID, count); + device.ray_list = DeviceArray::AllocateDevice(mDeviceID, count); std::vector host_data(isGPU() ? count : 0); StreamRay* ptr = isGPU() ? host_data.data() : device.ray_list.DevicePtr; @@ -527,8 +527,8 @@ IDeviceInterface::DynTableProxy DeviceInterface::loadDynTable(const std::string& DeviceDynTable entry = DeviceDynTable{ .EntryCount = tbl.entryCount(), - .LookupEntries = UnifiedArray<::LookupEntry>::AllocateDevice(mDeviceID, tbl.lookups().size()), - .Data = UnifiedArray::AllocateDevice(mDeviceID, tbl.data().size()) + .LookupEntries = DeviceArray<::LookupEntry>::AllocateDevice(mDeviceID, tbl.lookups().size()), + .Data = DeviceArray::AllocateDevice(mDeviceID, tbl.data().size()) }; entry.LookupEntries.copyFromExternalHostToDevice((const ::LookupEntry*)tbl.lookups().data()); @@ -564,7 +564,7 @@ IDeviceInterface::FixTableProxy DeviceInterface::loadFixTable(const std::string& // Special case: No entities in the scene return FixTableProxy::Invalid(); } else { - DeviceBuffer buffer = DeviceBuffer{ .Data = UnifiedArray::AllocateDevice(mDeviceID, fixtable.data().size()) }; + DeviceBuffer buffer = DeviceBuffer{ .Data = DeviceArray::AllocateDevice(mDeviceID, fixtable.data().size()) }; buffer.Data.copyFromExternalHostToDevice(fixtable.data().data()); return mapToProxyDevice(tables.try_emplace(name, std::move(buffer)).first->second); } @@ -599,22 +599,22 @@ void DeviceInterface::loadEntityBVH(BVHType type, const char* prim_type, void** case BVHType::BVH2: { const size_t node_count = bvh.Nodes.size() / sizeof(Node2); device.bvh_ents[str] = IG::Bvh2Ent{ - std::move(UnifiedArray::CreateExternalOrAllocateDevice(mDeviceID, (Node2*)bvh.Nodes.data(), node_count, !isGPU())), - std::move(UnifiedArray::CreateExternalOrAllocateDevice(mDeviceID, (EntityLeaf1*)bvh.Leaves.data(), leaf_count, !isGPU())) + std::move(DeviceArray::CreateExternalOrAllocateDevice(mDeviceID, (Node2*)bvh.Nodes.data(), node_count, !isGPU())), + std::move(DeviceArray::CreateExternalOrAllocateDevice(mDeviceID, (EntityLeaf1*)bvh.Leaves.data(), leaf_count, !isGPU())) }; } break; case BVHType::BVH4: { const size_t node_count = bvh.Nodes.size() / sizeof(Node4); device.bvh_ents[str] = IG::Bvh4Ent{ - std::move(UnifiedArray::CreateExternalOrAllocateDevice(mDeviceID, (Node4*)bvh.Nodes.data(), node_count, !isGPU())), - std::move(UnifiedArray::CreateExternalOrAllocateDevice(mDeviceID, (EntityLeaf1*)bvh.Leaves.data(), leaf_count, !isGPU())) + std::move(DeviceArray::CreateExternalOrAllocateDevice(mDeviceID, (Node4*)bvh.Nodes.data(), node_count, !isGPU())), + std::move(DeviceArray::CreateExternalOrAllocateDevice(mDeviceID, (EntityLeaf1*)bvh.Leaves.data(), leaf_count, !isGPU())) }; } break; case BVHType::BVH8: { const size_t node_count = bvh.Nodes.size() / sizeof(Node8); device.bvh_ents[str] = IG::Bvh8Ent{ - std::move(UnifiedArray::CreateExternalOrAllocateDevice(mDeviceID, (Node8*)bvh.Nodes.data(), node_count, !isGPU())), - std::move(UnifiedArray::CreateExternalOrAllocateDevice(mDeviceID, (EntityLeaf1*)bvh.Leaves.data(), leaf_count, !isGPU())) + std::move(DeviceArray::CreateExternalOrAllocateDevice(mDeviceID, (Node8*)bvh.Nodes.data(), node_count, !isGPU())), + std::move(DeviceArray::CreateExternalOrAllocateDevice(mDeviceID, (EntityLeaf1*)bvh.Leaves.data(), leaf_count, !isGPU())) }; } break; } @@ -655,14 +655,14 @@ IDeviceInterface::DeviceImageProxy DeviceInterface::loadImageFromFile(con _SECTION(SectionType::ImageLoading); IG_LOG(L_DEBUG) << "Loading image '" << filename << "' (C=" << expected_channels << ")" << std::endl; - UnifiedArray arr; + DeviceArray arr; size_t width, height; try { Image image = Image::load(filename); if (image.channels != (size_t)expected_channels) image = image.castTo((size_t)expected_channels); - arr = UnifiedArray::AllocateDevice(mDeviceID, image.width * image.height * image.channels); + arr = DeviceArray::AllocateDevice(mDeviceID, image.width * image.height * image.channels); width = image.width; height = image.height; arr.copyFromExternalHostToDevice(image.pixels.get()); @@ -675,12 +675,12 @@ IDeviceInterface::DeviceImageProxy DeviceInterface::loadImageFromFile(con if (MissingImage.channels != (size_t)expected_channels) { Image image = MissingImage.castTo((size_t)expected_channels); - arr = UnifiedArray::AllocateDevice(mDeviceID, image.width * image.height * image.channels); + arr = DeviceArray::AllocateDevice(mDeviceID, image.width * image.height * image.channels); width = image.width; height = image.height; arr.copyFromExternalHostToDevice(image.pixels.get()); } else { - arr = UnifiedArray::AllocateDevice(mDeviceID, MissingImage.width * MissingImage.height * MissingImage.channels); + arr = DeviceArray::AllocateDevice(mDeviceID, MissingImage.width * MissingImage.height * MissingImage.channels); width = MissingImage.width; height = MissingImage.height; arr.copyFromExternalHostToDevice(MissingImage.pixels.get()); @@ -730,7 +730,7 @@ IDeviceInterface::DeviceImageProxy DeviceInterface::loadPackedImageFrom channels = MissingImage.channels; } - auto arr = UnifiedArray::AllocateDevice(mDeviceID, hostData.size()); + auto arr = DeviceArray::AllocateDevice(mDeviceID, hostData.size()); arr.copyFromExternalHostToDevice(hostData.data()); return mapToProxyDevice(images.try_emplace(filename, @@ -774,7 +774,7 @@ IDeviceInterface::DeviceBufferProxy DeviceInterface::loadBufferFromFile if ((vec.size() % sizeof(int32_t)) != 0) IG_LOG(L_WARNING) << "Buffer '" << filename << "' is not properly sized!" << std::endl; - auto arr = UnifiedArray::AllocateDevice(mDeviceID, vec.size()); + auto arr = DeviceArray::AllocateDevice(mDeviceID, vec.size()); arr.copyFromExternalHostToDevice(vec.data()); return mapToProxyDevice(buffers.try_emplace(filename, DeviceBuffer{ .Data = std::move(arr) }).first->second); @@ -809,7 +809,7 @@ IDeviceInterface::DeviceBufferProxy DeviceInterface::requestBuffer(cons IG_LOG(L_DEBUG) << "Requested buffer '" << name << "' with " << FormatMemory(size) << std::endl; - auto arr = UnifiedArray::AllocateDevice(mDeviceID, size); + auto arr = DeviceArray::AllocateDevice(mDeviceID, size); return mapToProxyDevice(buffers.insert_or_assign(name, DeviceBuffer{ .Data = std::move(arr) }).first->second); } diff --git a/src/device/DeviceInterface.h b/src/device/DeviceInterface.h index 123d8276..ae822471 100644 --- a/src/device/DeviceInterface.h +++ b/src/device/DeviceInterface.h @@ -1,7 +1,7 @@ #pragma once +#include "DeviceArray.h" #include "Statistics.h" -#include "UnifiedArray.h" #include "device/IDeviceInterface.h" #include "device/ShaderKey.h" @@ -13,8 +13,8 @@ namespace IG { template struct BvhProxy { - UnifiedArray Nodes; - UnifiedArray Objs; + DeviceArray Nodes; + DeviceArray Objs; }; using Bvh2Ent = BvhProxy; @@ -25,13 +25,13 @@ using BvhVariant = std::variant; struct DeviceDynTable { size_t EntryCount = 0; - UnifiedArray<::LookupEntry> LookupEntries; - UnifiedArray Data; + DeviceArray<::LookupEntry> LookupEntries; + DeviceArray Data; }; struct TemporaryStorageHost { - UnifiedArray ray_begins; - UnifiedArray ray_ends; + DeviceArray ray_begins; + DeviceArray ray_ends; }; struct Resource { @@ -51,7 +51,7 @@ struct ShaderStats { template struct DeviceImageBase { - UnifiedArray Data; + DeviceArray Data; size_t Width = 0; size_t Height = 0; }; @@ -60,13 +60,13 @@ using DevicePackedImage = DeviceImageBase; // Packed RGBA template struct DeviceBufferBase { - UnifiedArray Data; + DeviceArray Data; }; using DeviceBuffer = DeviceBufferBase; template struct DeviceStreamBase { - UnifiedArray Data; + DeviceArray Data; size_t BlockSize = 0; }; using DeviceStream = DeviceStreamBase; @@ -96,7 +96,7 @@ class DeviceInterface : public IDeviceInterface { TemporaryStorageHost temporary_storage_host; std::array streams; std::array current_streams; - UnifiedArray ray_list; + DeviceArray ray_list; std::unordered_map aovs; std::unordered_map images; std::unordered_map packed_images;