Skip to content

Commit

Permalink
rename descs (#25)
Browse files Browse the repository at this point in the history
* rename IFence::Desc -> FenceDesc

* metal fix

* rename IQueryPool::Desc -> QueryPoolDesc

* fix metal
  • Loading branch information
skallweitNV authored Sep 7, 2024
1 parent d2fb0a6 commit 8f463ca
Show file tree
Hide file tree
Showing 39 changed files with 113 additions and 86 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- rename IQueryPool::Desc -> QueryPoolDesc, add label to QueryPoolDesc
- rename IFence::Desc -> FenceDesc, add label to FenceDesc
- implement dynamic rendering in Vulkan
- remove IFramebuffer and IFramebufferLayout
- rename IFramebufferLayout::Desc -> FramebufferLayoutDesc
Expand Down
35 changes: 20 additions & 15 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 @@ -1380,17 +1384,18 @@ enum class QueryType
AccelerationStructureCurrentSize,
};

struct QueryPoolDesc
{
QueryType type;
GfxCount count;

const char* label = nullptr;
};

class IQueryPool : public ISlangUnknown
{
SLANG_COM_INTERFACE(0xe4b585e4, 0x9da9, 0x479b, {0x89, 0x5c, 0x48, 0x78, 0x8e, 0xf2, 0x33, 0x65});

public:
struct Desc
{
QueryType type;
GfxCount count;
};

public:
virtual SLANG_NO_THROW Result SLANG_MCALL getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) = 0;
virtual SLANG_NO_THROW Result SLANG_MCALL reset() = 0;
Expand Down Expand Up @@ -2379,7 +2384,7 @@ class IDevice : public ISlangUnknown
/// Get the type of this renderer
virtual SLANG_NO_THROW const DeviceInfo& SLANG_MCALL getDeviceInfo() const = 0;

virtual SLANG_NO_THROW Result SLANG_MCALL createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) = 0;
virtual SLANG_NO_THROW Result SLANG_MCALL createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool) = 0;

virtual SLANG_NO_THROW Result SLANG_MCALL getAccelerationStructurePrebuildInfo(
const IAccelerationStructure::BuildInputs& buildInputs,
Expand All @@ -2389,7 +2394,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/cpu/cpu-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ DeviceImpl::createComputePipeline(const ComputePipelineDesc& desc, IPipeline** o
return Result();
}

SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool)
SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool)
{
RefPtr<QueryPoolImpl> pool = new QueryPoolImpl();
pool->init(desc);
Expand Down
3 changes: 1 addition & 2 deletions src/cpu/cpu-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class DeviceImpl : public ImmediateComputeDeviceBase
virtual SLANG_NO_THROW Result SLANG_MCALL
createComputePipeline(const ComputePipelineDesc& desc, IPipeline** outPipeline) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool) override;

virtual void writeTimestamp(IQueryPool* pool, GfxIndex index) override;

Expand Down
2 changes: 1 addition & 1 deletion src/cpu/cpu-query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace rhi::cpu {

Result QueryPoolImpl::init(const IQueryPool::Desc& desc)
Result QueryPoolImpl::init(const QueryPoolDesc& desc)
{
m_queries.resize(desc.count);
return SLANG_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/cpu-query.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class QueryPoolImpl : public QueryPoolBase
{
public:
std::vector<uint64_t> m_queries;
Result init(const IQueryPool::Desc& desc);
Result init(const QueryPoolDesc& desc);
virtual SLANG_NO_THROW Result SLANG_MCALL getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
};

Expand Down
2 changes: 1 addition & 1 deletion src/cuda/cuda-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createBufferView(
return SLANG_OK;
}

SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool)
SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool)
{
RefPtr<QueryPoolImpl> pool = new QueryPoolImpl();
SLANG_RETURN_ON_FAIL(pool->init(desc));
Expand Down
3 changes: 1 addition & 2 deletions src/cuda/cuda-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ class DeviceImpl : public RendererBase
createBufferView(IBuffer* buffer, IBuffer* counterBuffer, IResourceView::Desc const& desc, IResourceView** outView)
override;

virtual SLANG_NO_THROW Result SLANG_MCALL
createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool) override;

virtual Result createShaderObjectLayout(
slang::ISession* session,
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/cuda-query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace rhi::cuda {

Result QueryPoolImpl::init(const IQueryPool::Desc& desc)
Result QueryPoolImpl::init(const QueryPoolDesc& desc)
{
cuEventCreate(&m_startEvent, 0);
cuEventRecord(m_startEvent, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/cuda-query.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class QueryPoolImpl : public QueryPoolBase
/// The event that marks the starting point.
CUevent m_startEvent;

Result init(const IQueryPool::Desc& desc);
Result init(const QueryPoolDesc& desc);

~QueryPoolImpl();

Expand Down
2 changes: 1 addition & 1 deletion src/d3d11/d3d11-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ Result DeviceImpl::createInputLayout(InputLayoutDesc const& desc, IInputLayout**
return SLANG_OK;
}

Result DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool)
Result DeviceImpl::createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool)
{
RefPtr<QueryPoolImpl> result = new QueryPoolImpl();
SLANG_RETURN_ON_FAIL(result->init(desc, this));
Expand Down
3 changes: 1 addition & 2 deletions src/d3d11/d3d11-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class DeviceImpl : public ImmediateRendererBase
virtual SLANG_NO_THROW Result SLANG_MCALL
createInputLayout(InputLayoutDesc const& desc, IInputLayout** outLayout) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool) override;

virtual Result createShaderObjectLayout(
slang::ISession* session,
Expand Down
2 changes: 1 addition & 1 deletion src/d3d11/d3d11-query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace rhi::d3d11 {

Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
Result QueryPoolImpl::init(const QueryPoolDesc& desc, DeviceImpl* device)
{
m_device = device;
m_queryDesc.MiscFlags = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/d3d11/d3d11-query.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class QueryPoolImpl : public QueryPoolBase
RefPtr<DeviceImpl> m_device;
D3D11_QUERY_DESC m_queryDesc;

Result init(const IQueryPool::Desc& desc, DeviceImpl* device);
Result init(const QueryPoolDesc& desc, DeviceImpl* device);
ID3D11Query* getQuery(SlangInt index);
virtual SLANG_NO_THROW Result SLANG_MCALL getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
};
Expand Down
4 changes: 2 additions & 2 deletions src/d3d12/d3d12-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ void DeviceImpl::processExperimentalFeaturesDesc(SharedLibraryHandle d3dModule,
}
}

Result DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outState)
Result DeviceImpl::createQueryPool(const QueryPoolDesc& desc, IQueryPool** outState)
{
switch (desc.type)
{
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/d3d12/d3d12-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ class DeviceImpl : public RendererBase
createComputePipeline(const ComputePipelineDesc& desc, IPipeline** outPipeline) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outState) override;
createQueryPool(const QueryPoolDesc& 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
9 changes: 7 additions & 2 deletions src/d3d12/d3d12-query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace rhi::d3d12 {

Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
Result QueryPoolImpl::init(const QueryPoolDesc& desc, DeviceImpl* device)
{
m_desc = desc;

Expand All @@ -26,6 +26,11 @@ Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
auto d3dDevice = device->m_device;
SLANG_RETURN_ON_FAIL(d3dDevice->CreateQueryHeap(&heapDesc, IID_PPV_ARGS(m_queryHeap.writeRef())));

if (desc.label)
{
m_queryHeap->SetName(string::to_wstring(desc.label).c_str());
}

// Create readback buffer.
D3D12_HEAP_PROPERTIES heapProps;
heapProps.Type = D3D12_HEAP_TYPE_READBACK;
Expand Down Expand Up @@ -111,7 +116,7 @@ IQueryPool* PlainBufferProxyQueryPoolImpl::getInterface(const Guid& guid)
return nullptr;
}

Result PlainBufferProxyQueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device, uint32_t stride)
Result PlainBufferProxyQueryPoolImpl::init(const QueryPoolDesc& desc, DeviceImpl* device, uint32_t stride)
{
ComPtr<IBuffer> buffer;
BufferDesc bufferDesc = {};
Expand Down
4 changes: 2 additions & 2 deletions src/d3d12/d3d12-query.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace rhi::d3d12 {
class QueryPoolImpl : public QueryPoolBase
{
public:
Result init(const IQueryPool::Desc& desc, DeviceImpl* device);
Result init(const QueryPoolDesc& desc, DeviceImpl* device);

virtual SLANG_NO_THROW Result SLANG_MCALL getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;

Expand Down Expand Up @@ -37,7 +37,7 @@ class PlainBufferProxyQueryPoolImpl : public QueryPoolBase
IQueryPool* getInterface(const Guid& guid);

public:
Result init(const IQueryPool::Desc& desc, DeviceImpl* device, uint32_t stride);
Result init(const QueryPoolDesc& desc, DeviceImpl* device, uint32_t stride);

virtual SLANG_NO_THROW Result SLANG_MCALL reset() override;
virtual SLANG_NO_THROW Result SLANG_MCALL getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
Expand Down
4 changes: 2 additions & 2 deletions src/debug-layer/debug-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ const DeviceInfo& DebugDevice::getDeviceInfo() const
return baseObject->getDeviceInfo();
}

Result DebugDevice::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool)
Result DebugDevice::createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool)
{
SLANG_RHI_API_FUNC;
RefPtr<DebugQueryPool> result = new DebugQueryPool();
Expand All @@ -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
5 changes: 2 additions & 3 deletions src/debug-layer/debug-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ class DebugDevice : public DebugObject<IDevice>
virtual SLANG_NO_THROW Result SLANG_MCALL
readBuffer(IBuffer* buffer, Offset offset, Size size, ISlangBlob** outBlob) override;
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 createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool) 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/debug-layer/debug-query.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DebugQueryPool : public DebugObject<IQueryPool>
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL;

IQueryPool::Desc desc;
QueryPoolDesc desc;

public:
IQueryPool* getInterface(const Guid& guid);
Expand Down
6 changes: 4 additions & 2 deletions src/metal/metal-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ Result DeviceImpl::createTexture(const TextureDesc& descIn, const SubresourceDat
textureImpl->m_pixelFormat = textureDesc->pixelFormat();

if (desc.label)
{
textureImpl->m_texture->setLabel(MetalUtil::createString(desc.label).get());
}

// TODO: handle initData
if (initData)
Expand Down Expand Up @@ -758,7 +760,7 @@ Result DeviceImpl::createRayTracingPipeline(const RayTracingPipelineDesc& desc,
return SLANG_E_NOT_IMPLEMENTED;
}

Result DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool)
Result DeviceImpl::createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool)
{
AUTORELEASEPOOL

Expand All @@ -768,7 +770,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
5 changes: 2 additions & 3 deletions src/metal/metal-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class DeviceImpl : public RendererBase
createComputePipeline(const ComputePipelineDesc& desc, IPipeline** outPipeline) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createRayTracingPipeline(const RayTracingPipelineDesc& desc, IPipeline** outPipeline) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createQueryPool(const QueryPoolDesc& desc, IQueryPool** outPool) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
readTexture(ITexture* texture, ResourceState state, ISlangBlob** outBlob, Size* outRowPitch, Size* outPixelSize)
Expand All @@ -88,7 +87,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
Loading

0 comments on commit 8f463ca

Please sign in to comment.