From 081920a53074839ccf09c728efa0643124a6e891 Mon Sep 17 00:00:00 2001 From: Simon Kallweit Date: Tue, 24 Sep 2024 01:06:06 +0200 Subject: [PATCH] remove MemoryRange --- include/slang-rhi.h | 31 ++++++++++---------------- src/core/deferred.h | 4 +--- src/cpu/cpu-buffer.cpp | 4 ++-- src/cpu/cpu-buffer.h | 4 ++-- src/cuda/cuda-buffer.cpp | 4 ++-- src/cuda/cuda-buffer.h | 4 ++-- src/d3d11/d3d11-buffer.cpp | 4 ++-- src/d3d11/d3d11-buffer.h | 4 ++-- src/d3d12/d3d12-buffer.cpp | 4 ++-- src/d3d12/d3d12-buffer.h | 4 ++-- src/debug-layer/debug-buffer.cpp | 4 ++-- src/debug-layer/debug-buffer.h | 4 ++-- src/metal/metal-buffer.cpp | 4 ++-- src/metal/metal-buffer.h | 4 ++-- src/metal/metal-shader-object.cpp | 4 ++-- src/vulkan/vk-buffer.cpp | 4 ++-- src/vulkan/vk-buffer.h | 4 ++-- src/wgpu/wgpu-api.h | 2 +- src/wgpu/wgpu-buffer.cpp | 4 ++-- src/wgpu/wgpu-buffer.h | 4 ++-- src/wgpu/wgpu-command-encoder.cpp | 2 +- src/wgpu/wgpu-shader-object-layout.cpp | 3 +-- src/wgpu/wgpu-util.cpp | 3 ++- 23 files changed, 52 insertions(+), 61 deletions(-) diff --git a/include/slang-rhi.h b/include/slang-rhi.h index 73a50cc1..6518100e 100644 --- a/include/slang-rhi.h +++ b/include/slang-rhi.h @@ -467,13 +467,19 @@ class IResource : public ISlangUnknown virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) = 0; }; -struct MemoryRange +struct BufferRange { - // TODO: Change to Offset/Size? - uint64_t offset; - uint64_t size; + /// Offset in bytes. + Offset offset = 0; + /// Size in bytes. + Size size = 0; + + bool operator==(const BufferRange& other) const { return offset == other.offset && size == other.size; } + bool operator!=(const BufferRange& other) const { return !(*this == other); } }; +static const BufferRange kEntireBuffer = BufferRange{0ull, ~0ull}; + enum class BufferUsage { None = 0, @@ -519,8 +525,8 @@ class IBuffer : public IResource virtual SLANG_NO_THROW const BufferDesc& SLANG_MCALL getDesc() = 0; virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(NativeHandle* outHandle) = 0; virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() = 0; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) = 0; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) = 0; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) = 0; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) = 0; }; struct DepthStencilClearValue @@ -542,19 +548,6 @@ struct ClearValue DepthStencilClearValue depthStencil; }; -struct BufferRange -{ - /// Offset in bytes. - Offset offset = 0; - /// Size in bytes. - Size size = 0; - - bool operator==(const BufferRange& other) const { return offset == other.offset && size == other.size; } - bool operator!=(const BufferRange& other) const { return !(*this == other); } -}; - -static const BufferRange kEntireBuffer = BufferRange{0ull, ~0ull}; - enum class TextureUsage { None = 0x0, diff --git a/src/core/deferred.h b/src/core/deferred.h index 2e3c9d82..55dba9b4 100644 --- a/src/core/deferred.h +++ b/src/core/deferred.h @@ -11,9 +11,7 @@ class Deferred { } - ~Deferred() { - m_callback(); - } + ~Deferred() { m_callback(); } private: Callback m_callback; diff --git a/src/cpu/cpu-buffer.cpp b/src/cpu/cpu-buffer.cpp index 48541bf8..0e3c4ddd 100644 --- a/src/cpu/cpu-buffer.cpp +++ b/src/cpu/cpu-buffer.cpp @@ -29,7 +29,7 @@ DeviceAddress BufferImpl::getDeviceAddress() return (DeviceAddress)m_data; } -Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) +Result BufferImpl::map(BufferRange* rangeToRead, void** outPointer) { SLANG_UNUSED(rangeToRead); if (outPointer) @@ -37,7 +37,7 @@ Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) return SLANG_OK; } -Result BufferImpl::unmap(MemoryRange* writtenRange) +Result BufferImpl::unmap(BufferRange* writtenRange) { SLANG_UNUSED(writtenRange); return SLANG_OK; diff --git a/src/cpu/cpu-buffer.h b/src/cpu/cpu-buffer.h index 43542b38..e19c2d24 100644 --- a/src/cpu/cpu-buffer.h +++ b/src/cpu/cpu-buffer.h @@ -22,9 +22,9 @@ class BufferImpl : public Buffer virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) override; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) override; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) override; }; } // namespace rhi::cpu diff --git a/src/cuda/cuda-buffer.cpp b/src/cuda/cuda-buffer.cpp index a0852f13..953b0133 100644 --- a/src/cuda/cuda-buffer.cpp +++ b/src/cuda/cuda-buffer.cpp @@ -28,14 +28,14 @@ Result BufferImpl::getNativeHandle(NativeHandle* outHandle) return SLANG_OK; } -Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) +Result BufferImpl::map(BufferRange* rangeToRead, void** outPointer) { SLANG_UNUSED(rangeToRead); SLANG_UNUSED(outPointer); return SLANG_FAIL; } -Result BufferImpl::unmap(MemoryRange* writtenRange) +Result BufferImpl::unmap(BufferRange* writtenRange) { SLANG_UNUSED(writtenRange); return SLANG_FAIL; diff --git a/src/cuda/cuda-buffer.h b/src/cuda/cuda-buffer.h index a309c382..0e5e0f38 100644 --- a/src/cuda/cuda-buffer.h +++ b/src/cuda/cuda-buffer.h @@ -25,8 +25,8 @@ class BufferImpl : public Buffer virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override; virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) override; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) override; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) override; }; } // namespace rhi::cuda diff --git a/src/d3d11/d3d11-buffer.cpp b/src/d3d11/d3d11-buffer.cpp index 5b1c5f70..80506a8c 100644 --- a/src/d3d11/d3d11-buffer.cpp +++ b/src/d3d11/d3d11-buffer.cpp @@ -8,14 +8,14 @@ DeviceAddress BufferImpl::getDeviceAddress() return 0; } -Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) +Result BufferImpl::map(BufferRange* rangeToRead, void** outPointer) { SLANG_UNUSED(rangeToRead); SLANG_UNUSED(outPointer); return SLANG_FAIL; } -Result BufferImpl::unmap(MemoryRange* writtenRange) +Result BufferImpl::unmap(BufferRange* writtenRange) { SLANG_UNUSED(writtenRange); return SLANG_FAIL; diff --git a/src/d3d11/d3d11-buffer.h b/src/d3d11/d3d11-buffer.h index a1d23ce9..d0772c97 100644 --- a/src/d3d11/d3d11-buffer.h +++ b/src/d3d11/d3d11-buffer.h @@ -43,8 +43,8 @@ class BufferImpl : public Buffer std::unordered_map, ViewKeyHasher> m_uavs; virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) override; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) override; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) override; ID3D11ShaderResourceView* getSRV(Format format, const BufferRange& range); ID3D11UnorderedAccessView* getUAV(Format format, const BufferRange& range); diff --git a/src/d3d12/d3d12-buffer.cpp b/src/d3d12/d3d12-buffer.cpp index fff2bc71..2894b1b7 100644 --- a/src/d3d12/d3d12-buffer.cpp +++ b/src/d3d12/d3d12-buffer.cpp @@ -70,7 +70,7 @@ Result BufferImpl::getSharedHandle(NativeHandle* outHandle) #endif } -Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) +Result BufferImpl::map(BufferRange* rangeToRead, void** outPointer) { D3D12_RANGE range = {}; if (rangeToRead) @@ -82,7 +82,7 @@ Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) return SLANG_OK; } -Result BufferImpl::unmap(MemoryRange* writtenRange) +Result BufferImpl::unmap(BufferRange* writtenRange) { D3D12_RANGE range = {}; if (writtenRange) diff --git a/src/d3d12/d3d12-buffer.h b/src/d3d12/d3d12-buffer.h index 21223327..0b95e4b2 100644 --- a/src/d3d12/d3d12-buffer.h +++ b/src/d3d12/d3d12-buffer.h @@ -22,9 +22,9 @@ class BufferImpl : public Buffer virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(NativeHandle* outHandle) override; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) override; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) override; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) override; public: struct ViewKey diff --git a/src/debug-layer/debug-buffer.cpp b/src/debug-layer/debug-buffer.cpp index ac180783..77850e84 100644 --- a/src/debug-layer/debug-buffer.cpp +++ b/src/debug-layer/debug-buffer.cpp @@ -27,13 +27,13 @@ Result DebugBuffer::getSharedHandle(NativeHandle* outHandle) return baseObject->getSharedHandle(outHandle); } -Result DebugBuffer::map(MemoryRange* rangeToRead, void** outPointer) +Result DebugBuffer::map(BufferRange* rangeToRead, void** outPointer) { SLANG_RHI_API_FUNC; return baseObject->map(rangeToRead, outPointer); } -Result DebugBuffer::unmap(MemoryRange* writtenRange) +Result DebugBuffer::unmap(BufferRange* writtenRange) { return baseObject->unmap(writtenRange); } diff --git a/src/debug-layer/debug-buffer.h b/src/debug-layer/debug-buffer.h index 505bff21..b8eb0162 100644 --- a/src/debug-layer/debug-buffer.h +++ b/src/debug-layer/debug-buffer.h @@ -16,8 +16,8 @@ class DebugBuffer : public DebugObject virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override; virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(NativeHandle* outHandle) override; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) override; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) override; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) override; }; } // namespace rhi::debug diff --git a/src/metal/metal-buffer.cpp b/src/metal/metal-buffer.cpp index b269c460..0746ae93 100644 --- a/src/metal/metal-buffer.cpp +++ b/src/metal/metal-buffer.cpp @@ -28,13 +28,13 @@ Result BufferImpl::getSharedHandle(NativeHandle* outHandle) return SLANG_E_NOT_AVAILABLE; } -Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) +Result BufferImpl::map(BufferRange* rangeToRead, void** outPointer) { *outPointer = m_buffer->contents(); return SLANG_OK; } -Result BufferImpl::unmap(MemoryRange* writtenRange) +Result BufferImpl::unmap(BufferRange* writtenRange) { return SLANG_OK; } diff --git a/src/metal/metal-buffer.h b/src/metal/metal-buffer.h index f8c36b76..c077cd2a 100644 --- a/src/metal/metal-buffer.h +++ b/src/metal/metal-buffer.h @@ -19,9 +19,9 @@ class BufferImpl : public Buffer virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(NativeHandle* outHandle) override; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) override; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) override; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) override; }; } // namespace rhi::metal diff --git a/src/metal/metal-shader-object.cpp b/src/metal/metal-shader-object.cpp index 82cecd25..f8263299 100644 --- a/src/metal/metal-shader-object.cpp +++ b/src/metal/metal-shader-object.cpp @@ -259,7 +259,7 @@ Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(DeviceImpl* de // don't need or want to inline it into this call site. // - MemoryRange range = {0, ordinaryDataSize}; + BufferRange range = {0, ordinaryDataSize}; void* ordinaryData; SLANG_RETURN_ON_FAIL(m_ordinaryDataBuffer->map(&range, &ordinaryData)); auto result = _writeOrdinaryData(ordinaryData, ordinaryDataSize, layout); @@ -352,7 +352,7 @@ BufferImpl* ShaderObjectImpl::_ensureArgumentBufferUpToDate(DeviceImpl* device, // the offsets for each field. // auto dataSize = typeLayout->getSize(); - MemoryRange range = {0, dataSize}; + BufferRange range = {0, dataSize}; void* argumentData; SLANG_RETURN_NULL_ON_FAIL(m_argumentBuffer->map(&range, &argumentData)); diff --git a/src/vulkan/vk-buffer.cpp b/src/vulkan/vk-buffer.cpp index b4785118..8632fde5 100644 --- a/src/vulkan/vk-buffer.cpp +++ b/src/vulkan/vk-buffer.cpp @@ -171,7 +171,7 @@ Result BufferImpl::getSharedHandle(NativeHandle* outHandle) return SLANG_OK; } -Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) +Result BufferImpl::map(BufferRange* rangeToRead, void** outPointer) { SLANG_UNUSED(rangeToRead); auto api = m_buffer.m_api; @@ -179,7 +179,7 @@ Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) return SLANG_OK; } -Result BufferImpl::unmap(MemoryRange* writtenRange) +Result BufferImpl::unmap(BufferRange* writtenRange) { SLANG_UNUSED(writtenRange); auto api = m_buffer.m_api; diff --git a/src/vulkan/vk-buffer.h b/src/vulkan/vk-buffer.h index 3eff3b9f..c194eedb 100644 --- a/src/vulkan/vk-buffer.h +++ b/src/vulkan/vk-buffer.h @@ -57,9 +57,9 @@ class BufferImpl : public Buffer virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(NativeHandle* outHandle) override; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) override; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) override; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) override; struct ViewKey { diff --git a/src/wgpu/wgpu-api.h b/src/wgpu/wgpu-api.h index 191f3a1b..c638dcf5 100644 --- a/src/wgpu/wgpu-api.h +++ b/src/wgpu/wgpu-api.h @@ -341,7 +341,7 @@ x(TextureViewSetLabel) \ x(TextureViewSetLabel2) \ x(TextureViewAddRef) \ - x(TextureViewRelease) \ + x(TextureViewRelease) // clang-format on diff --git a/src/wgpu/wgpu-buffer.cpp b/src/wgpu/wgpu-buffer.cpp index fcd3aa29..7d2564cb 100644 --- a/src/wgpu/wgpu-buffer.cpp +++ b/src/wgpu/wgpu-buffer.cpp @@ -38,7 +38,7 @@ Result BufferImpl::getSharedHandle(NativeHandle* outHandle) return SLANG_E_NOT_AVAILABLE; } -Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) +Result BufferImpl::map(BufferRange* rangeToRead, void** outPointer) { if (m_isMapped) { @@ -70,7 +70,7 @@ Result BufferImpl::map(MemoryRange* rangeToRead, void** outPointer) return SLANG_OK; } -Result BufferImpl::unmap(MemoryRange* writtenRange) +Result BufferImpl::unmap(BufferRange* writtenRange) { if (!m_isMapped) { diff --git a/src/wgpu/wgpu-buffer.h b/src/wgpu/wgpu-buffer.h index 86391157..677a781d 100644 --- a/src/wgpu/wgpu-buffer.h +++ b/src/wgpu/wgpu-buffer.h @@ -19,8 +19,8 @@ class BufferImpl : public Buffer virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override; virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(NativeHandle* outHandle) override; virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(NativeHandle* outHandle) override; - virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) override; - virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override; + virtual SLANG_NO_THROW Result SLANG_MCALL map(BufferRange* rangeToRead, void** outPointer) override; + virtual SLANG_NO_THROW Result SLANG_MCALL unmap(BufferRange* writtenRange) override; }; } // namespace rhi::wgpu diff --git a/src/wgpu/wgpu-command-encoder.cpp b/src/wgpu/wgpu-command-encoder.cpp index 489a15f2..aca549aa 100644 --- a/src/wgpu/wgpu-command-encoder.cpp +++ b/src/wgpu/wgpu-command-encoder.cpp @@ -95,7 +95,7 @@ void CommandEncoderImpl::uploadBufferDataImpl(IBuffer* buffer, Offset offset, Si m_commandBuffer->m_transientHeap ->allocateStagingBuffer(size, stagingBuffer, stagingBufferOffset, MemoryType::Upload); BufferImpl* stagingBufferImpl = static_cast(stagingBuffer); - MemoryRange range = {stagingBufferOffset, size}; + BufferRange range = {stagingBufferOffset, size}; void* mappedData; if (stagingBufferImpl->map(&range, &mappedData) == SLANG_OK) { diff --git a/src/wgpu/wgpu-shader-object-layout.cpp b/src/wgpu/wgpu-shader-object-layout.cpp index 82533686..3a4de491 100644 --- a/src/wgpu/wgpu-shader-object-layout.cpp +++ b/src/wgpu/wgpu-shader-object-layout.cpp @@ -173,8 +173,7 @@ void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue( case slang::BindingType::Texture: entry.texture.sampleType = getSampleType(leafType->getResourceResultType()); entry.texture.viewDimension = getViewDimension(leafType->getResourceShape()); - entry.texture.multisampled = - (leafType->getResourceShape() & SLANG_TEXTURE_MULTISAMPLE_FLAG) ? 1 : 0; + entry.texture.multisampled = (leafType->getResourceShape() & SLANG_TEXTURE_MULTISAMPLE_FLAG) ? 1 : 0; break; case slang::BindingType::MutableTexture: // WGPUStorageTextureAccess_Undefined = 0x00000000, diff --git a/src/wgpu/wgpu-util.cpp b/src/wgpu/wgpu-util.cpp index ba30227d..7ebc11d8 100644 --- a/src/wgpu/wgpu-util.cpp +++ b/src/wgpu/wgpu-util.cpp @@ -367,7 +367,8 @@ WGPUTextureViewDimension translateTextureViewDimension(TextureType type, bool ar WGPUTextureAspect translateTextureAspect(TextureAspect aspect) { - switch (aspect) { + switch (aspect) + { case TextureAspect::Color: return WGPUTextureAspect_All; case TextureAspect::Depth: