Skip to content

Commit

Permalink
remove MemoryRange
Browse files Browse the repository at this point in the history
  • Loading branch information
skallweitNV committed Sep 23, 2024
1 parent feae06c commit 081920a
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 61 deletions.
31 changes: 12 additions & 19 deletions include/slang-rhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions src/core/deferred.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class Deferred
{
}

~Deferred() {
m_callback();
}
~Deferred() { m_callback(); }

private:
Callback m_callback;
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/cpu-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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)
*outPointer = m_data;
return SLANG_OK;
}

Result BufferImpl::unmap(MemoryRange* writtenRange)
Result BufferImpl::unmap(BufferRange* writtenRange)
{
SLANG_UNUSED(writtenRange);
return SLANG_OK;
Expand Down
4 changes: 2 additions & 2 deletions src/cpu/cpu-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/cuda/cuda-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/cuda/cuda-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/d3d11/d3d11-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/d3d11/d3d11-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class BufferImpl : public Buffer
std::unordered_map<ViewKey, ComPtr<ID3D11UnorderedAccessView>, 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);
Expand Down
4 changes: 2 additions & 2 deletions src/d3d12/d3d12-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/d3d12/d3d12-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/debug-layer/debug-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/debug-layer/debug-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class DebugBuffer : public DebugObject<IBuffer>
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
4 changes: 2 additions & 2 deletions src/metal/metal-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/metal/metal-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/metal/metal-shader-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions src/vulkan/vk-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ 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;
SLANG_VK_RETURN_ON_FAIL(api->vkMapMemory(api->m_device, m_buffer.m_memory, 0, VK_WHOLE_SIZE, 0, outPointer));
return SLANG_OK;
}

Result BufferImpl::unmap(MemoryRange* writtenRange)
Result BufferImpl::unmap(BufferRange* writtenRange)
{
SLANG_UNUSED(writtenRange);
auto api = m_buffer.m_api;
Expand Down
4 changes: 2 additions & 2 deletions src/vulkan/vk-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/wgpu/wgpu-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@
x(TextureViewSetLabel) \
x(TextureViewSetLabel2) \
x(TextureViewAddRef) \
x(TextureViewRelease) \
x(TextureViewRelease)

// clang-format on

Expand Down
4 changes: 2 additions & 2 deletions src/wgpu/wgpu-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/wgpu/wgpu-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/wgpu/wgpu-command-encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BufferImpl*>(stagingBuffer);
MemoryRange range = {stagingBufferOffset, size};
BufferRange range = {stagingBufferOffset, size};
void* mappedData;
if (stagingBufferImpl->map(&range, &mappedData) == SLANG_OK)
{
Expand Down
3 changes: 1 addition & 2 deletions src/wgpu/wgpu-shader-object-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/wgpu/wgpu-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 081920a

Please sign in to comment.