Skip to content

Commit

Permalink
rename IFence::Desc -> FenceDesc
Browse files Browse the repository at this point in the history
  • Loading branch information
skallweitNV committed Sep 7, 2024
1 parent d2fb0a6 commit dc610f9
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- rename IFence::Desc -> FenceDesc, add label to FenceDesc
- implement dynamic rendering in Vulkan
- remove IFramebuffer and IFramebufferLayout
- rename IFramebufferLayout::Desc -> FramebufferLayoutDesc
Expand Down
18 changes: 11 additions & 7 deletions include/slang-rhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ struct SamplerDesc
float borderColor[4] = {1.0f, 1.0f, 1.0f, 1.0f};
float minLOD = -FLT_MAX;
float maxLOD = FLT_MAX;

const char* label = nullptr;
};

class ISampler : public ISlangUnknown
Expand Down Expand Up @@ -922,17 +924,19 @@ class IAccelerationStructure : public IResourceView
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() = 0;
};

struct FenceDesc
{
uint64_t initialValue = 0;
bool isShared = false;

const char* label = nullptr;
};

class IFence : public ISlangUnknown
{
SLANG_COM_INTERFACE(0x9daf743c, 0xbc69, 0x4887, {0x80, 0x8b, 0xe6, 0xcf, 0x1f, 0x9e, 0x48, 0xa0});

public:
struct Desc
{
uint64_t initialValue = 0;
bool isShared = false;
};

/// Returns the currently signaled value on the device.
virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentValue(uint64_t* outValue) = 0;

Expand Down Expand Up @@ -2389,7 +2393,7 @@ class IDevice : public ISlangUnknown
virtual SLANG_NO_THROW Result SLANG_MCALL
createAccelerationStructure(const IAccelerationStructure::CreateDesc& desc, IAccelerationStructure** outView) = 0;

virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const IFence::Desc& desc, IFence** outFence) = 0;
virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const FenceDesc& desc, IFence** outFence) = 0;

/// Wait on the host for the fences to signals.
/// `timeout` is in nanoseconds, can be set to `kTimeoutInfinite`.
Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/d3d12-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ Result DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** ou
}
}

Result DeviceImpl::createFence(const IFence::Desc& desc, IFence** outFence)
Result DeviceImpl::createFence(const FenceDesc& desc, IFence** outFence)
{
RefPtr<FenceImpl> fence = new FenceImpl();
SLANG_RETURN_ON_FAIL(fence->init(this, desc));
Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/d3d12-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class DeviceImpl : public RendererBase
virtual SLANG_NO_THROW Result SLANG_MCALL
createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outState) override;

virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const IFence::Desc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const FenceDesc& desc, IFence** outFence) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
waitForFences(GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
Expand Down
6 changes: 5 additions & 1 deletion src/d3d12/d3d12-fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ HANDLE FenceImpl::getWaitEvent()
return m_waitEvent;
}

Result FenceImpl::init(DeviceImpl* device, const IFence::Desc& desc)
Result FenceImpl::init(DeviceImpl* device, const FenceDesc& desc)
{
SLANG_RETURN_ON_FAIL(device->m_device->CreateFence(
desc.initialValue,
desc.isShared ? D3D12_FENCE_FLAG_SHARED : D3D12_FENCE_FLAG_NONE,
IID_PPV_ARGS(m_fence.writeRef())
));
if (desc.label)
{
m_fence->SetName(string::to_wstring(desc.label).c_str());
}
return SLANG_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/d3d12-fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FenceImpl : public FenceBase

HANDLE getWaitEvent();

Result init(DeviceImpl* device, const IFence::Desc& desc);
Result init(DeviceImpl* device, const FenceDesc& desc);

virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentValue(uint64_t* outValue) override;

Expand Down
2 changes: 1 addition & 1 deletion src/debug-layer/debug-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ Result DebugDevice::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** o
return SLANG_OK;
}

Result DebugDevice::createFence(const IFence::Desc& desc, IFence** outFence)
Result DebugDevice::createFence(const FenceDesc& desc, IFence** outFence)
{
SLANG_RHI_API_FUNC;
RefPtr<DebugFence> result = new DebugFence();
Expand Down
2 changes: 1 addition & 1 deletion src/debug-layer/debug-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class DebugDevice : public DebugObject<IDevice>
virtual SLANG_NO_THROW const DeviceInfo& SLANG_MCALL getDeviceInfo() const override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const IFence::Desc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const FenceDesc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
waitForFences(GfxCount fenceCount, IFence** fences, uint64_t* values, bool waitForAll, uint64_t timeout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
Expand Down
2 changes: 1 addition & 1 deletion src/metal/metal-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ Result DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** ou
return SLANG_OK;
}

Result DeviceImpl::createFence(const IFence::Desc& desc, IFence** outFence)
Result DeviceImpl::createFence(const FenceDesc& desc, IFence** outFence)
{
AUTORELEASEPOOL

Expand Down
2 changes: 1 addition & 1 deletion src/metal/metal-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DeviceImpl : public RendererBase

virtual SLANG_NO_THROW Result SLANG_MCALL getTextureRowAlignment(Size* outAlignment) override;

virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const IFence::Desc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const FenceDesc& desc, IFence** outFence) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
waitForFences(GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
Expand Down
2 changes: 1 addition & 1 deletion src/metal/metal-fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace rhi::metal {

FenceImpl::~FenceImpl() {}

Result FenceImpl::init(DeviceImpl* device, const IFence::Desc& desc)
Result FenceImpl::init(DeviceImpl* device, const FenceDesc& desc)
{
m_device = device;
m_event = NS::TransferPtr(m_device->m_device->newSharedEvent());
Expand Down
2 changes: 1 addition & 1 deletion src/metal/metal-fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FenceImpl : public FenceBase

~FenceImpl();

Result init(DeviceImpl* device, const IFence::Desc& desc);
Result init(DeviceImpl* device, const FenceDesc& desc);

virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentValue(uint64_t* outValue) override;

Expand Down
1 change: 1 addition & 0 deletions src/metal/metal-sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Result SamplerImpl::init(DeviceImpl* device, const SamplerDesc& desc)
samplerDesc->setLodMaxClamp(std::clamp(desc.maxLOD, samplerDesc->lodMinClamp(), 1000.f));

samplerDesc->setSupportArgumentBuffers(true);
samplerDesc->setLabel(MetalUtil::createString(desc.label));

// TODO: no support for reduction op

Expand Down
2 changes: 1 addition & 1 deletion src/renderer-shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ Result RendererBase::createMutableRootShaderObject(IShaderProgram* program, ISha
return SLANG_E_NOT_AVAILABLE;
}

Result RendererBase::createFence(const IFence::Desc& desc, IFence** outFence)
Result RendererBase::createFence(const FenceDesc& desc, IFence** outFence)
{
SLANG_UNUSED(desc);
*outFence = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer-shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ class RendererBase : public IDevice, public ComObject
createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;

// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE.
virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const IFence::Desc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const FenceDesc& desc, IFence** outFence) override;

// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE.
virtual SLANG_NO_THROW Result SLANG_MCALL
Expand Down
36 changes: 17 additions & 19 deletions src/vulkan/vk-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,18 @@ void DeviceImpl::_transitionImageLayout(
_transitionImageLayout(commandBuffer, image, format, desc, oldLayout, newLayout);
}

void DeviceImpl::_labelObject(uint64_t object, VkDebugReportObjectTypeEXT objectType, const char* label)
{
if (label && m_api.vkDebugMarkerSetObjectNameEXT)
{
VkDebugMarkerObjectNameInfoEXT nameDesc = {VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT};
nameDesc.object = object;
nameDesc.objectType = objectType;
nameDesc.pObjectName = label;
m_api.vkDebugMarkerSetObjectNameEXT(m_api.m_device, &nameDesc);
}
}

Result DeviceImpl::getTextureAllocationInfo(const TextureDesc& descIn, Size* outSize, Size* outAlignment)
{
TextureDesc desc = fixupTextureDesc(descIn);
Expand Down Expand Up @@ -1589,15 +1601,7 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
// Bind the memory to the image
m_api.vkBindImageMemory(m_device, texture->m_image, texture->m_imageMemory, 0);

if (desc.label && m_api.vkDebugMarkerSetObjectNameEXT)
{
VkDebugMarkerObjectNameInfoEXT nameDesc = {};
nameDesc.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT;
nameDesc.object = (uint64_t)texture->m_image;
nameDesc.objectType = VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT;
nameDesc.pObjectName = desc.label;
m_api.vkDebugMarkerSetObjectNameEXT(m_api.m_device, &nameDesc);
}
_labelObject((uint64_t)texture->m_image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, desc.label);

VKBufferHandleRAII uploadBuffer;
if (initData)
Expand Down Expand Up @@ -1924,15 +1928,7 @@ Result DeviceImpl::createBufferImpl(
SLANG_RETURN_ON_FAIL(buffer->m_buffer.init(m_api, desc.size, usage, reqMemoryProperties));
}

if (desc.label && m_api.vkDebugMarkerSetObjectNameEXT)
{
VkDebugMarkerObjectNameInfoEXT nameDesc = {};
nameDesc.sType = VK_STRUCTURE_TYPE_DEBUG_MARKER_OBJECT_NAME_INFO_EXT;
nameDesc.object = (uint64_t)buffer->m_buffer.m_buffer;
nameDesc.objectType = VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT;
nameDesc.pObjectName = desc.label;
m_api.vkDebugMarkerSetObjectNameEXT(m_api.m_device, &nameDesc);
}
_labelObject((uint64_t)buffer->m_buffer.m_buffer, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, desc.label);

if (initData)
{
Expand Down Expand Up @@ -2026,6 +2022,8 @@ Result DeviceImpl::createSampler(SamplerDesc const& desc, ISampler** outSampler)
VkSampler sampler;
SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateSampler(m_device, &samplerInfo, nullptr, &sampler));

_labelObject((uint64_t)sampler, VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, desc.label);

RefPtr<SamplerImpl> samplerImpl = new SamplerImpl(this);
samplerImpl->m_sampler = sampler;
returnComPtr(outSampler, samplerImpl);
Expand Down Expand Up @@ -2491,7 +2489,7 @@ Result DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** ou
return SLANG_OK;
}

Result DeviceImpl::createFence(const IFence::Desc& desc, IFence** outFence)
Result DeviceImpl::createFence(const FenceDesc& desc, IFence** outFence)
{
RefPtr<FenceImpl> fence = new FenceImpl(this);
SLANG_RETURN_ON_FAIL(fence->init(desc));
Expand Down
5 changes: 4 additions & 1 deletion src/vulkan/vk-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DeviceImpl : public RendererBase

virtual SLANG_NO_THROW Result SLANG_MCALL getTextureRowAlignment(Size* outAlignment) override;

virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const IFence::Desc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFence(const FenceDesc& desc, IFence** outFence) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
waitForFences(GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
Expand Down Expand Up @@ -129,13 +129,16 @@ class DeviceImpl : public RendererBase
void* pUserData
);

void _labelObject(uint64_t object, VkDebugReportObjectTypeEXT objectType, const char* label);

void _transitionImageLayout(
VkImage image,
VkFormat format,
const TextureDesc& desc,
VkImageLayout oldLayout,
VkImageLayout newLayout
);

void _transitionImageLayout(
VkCommandBuffer commandBuffer,
VkImage image,
Expand Down
4 changes: 3 additions & 1 deletion src/vulkan/vk-fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ FenceImpl::~FenceImpl()
}
}

Result FenceImpl::init(const IFence::Desc& desc)
Result FenceImpl::init(const FenceDesc& desc)
{
if (!m_device->m_api.m_extendedFeatures.vulkan12Features.timelineSemaphore)
return SLANG_E_NOT_AVAILABLE;
Expand Down Expand Up @@ -61,6 +61,8 @@ Result FenceImpl::init(const IFence::Desc& desc)
m_device->m_api.vkCreateSemaphore(m_device->m_api.m_device, &createInfo, nullptr, &m_semaphore)
);

m_device->_labelObject((uint64_t)m_semaphore, VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, desc.label);

return SLANG_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/vk-fence.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FenceImpl : public FenceBase

~FenceImpl();

Result init(const IFence::Desc& desc);
Result init(const FenceDesc& desc);

virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentValue(uint64_t* outValue) override;

Expand Down

0 comments on commit dc610f9

Please sign in to comment.