summaryrefslogtreecommitdiff
path: root/tools/gfx
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-08-20 01:03:06 -0700
committerGitHub <noreply@github.com>2022-08-20 01:03:06 -0700
commitaf70651a4843b16dd24e14b5cedffe399ebeb862 (patch)
treea6aefd5db94a048114b9a8d7ed3f826533105fab /tools/gfx
parent6412c4913b6a063438bb11863f2c154d3ae42dfe (diff)
Call `gfx` in slang program. (#2370)
Diffstat (limited to 'tools/gfx')
-rw-r--r--tools/gfx/cuda/cuda-command-encoder.h4
-rw-r--r--tools/gfx/d3d12/d3d12-command-encoder.cpp2
-rw-r--r--tools/gfx/d3d12/d3d12-command-encoder.h6
-rw-r--r--tools/gfx/d3d12/d3d12-shader-table.cpp7
-rw-r--r--tools/gfx/gfx.slang60
-rw-r--r--tools/gfx/immediate-renderer-base.cpp4
-rw-r--r--tools/gfx/render.cpp6
-rw-r--r--tools/gfx/renderer-shared.h2
-rw-r--r--tools/gfx/slang.slang2
-rw-r--r--tools/gfx/vulkan/vk-command-encoder.h6
10 files changed, 49 insertions, 50 deletions
diff --git a/tools/gfx/cuda/cuda-command-encoder.h b/tools/gfx/cuda/cuda-command-encoder.h
index 9b7e94c8c..b73dd48c0 100644
--- a/tools/gfx/cuda/cuda-command-encoder.h
+++ b/tools/gfx/cuda/cuda-command-encoder.h
@@ -31,8 +31,8 @@ public:
}
return SLANG_E_NO_INTERFACE;
}
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() { return 1; }
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
void init(CommandBufferImpl* cmdBuffer);
diff --git a/tools/gfx/d3d12/d3d12-command-encoder.cpp b/tools/gfx/d3d12/d3d12-command-encoder.cpp
index 516053d39..59498856c 100644
--- a/tools/gfx/d3d12/d3d12-command-encoder.cpp
+++ b/tools/gfx/d3d12/d3d12-command-encoder.cpp
@@ -1379,7 +1379,7 @@ void RayTracingCommandEncoderImpl::dispatchRays(
dispatchDesc.RayGenerationShaderRecord.StartAddress =
shaderTableAddr + shaderTableImpl->m_rayGenTableOffset +
- rayGenShaderIndex * D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES;
+ rayGenShaderIndex * kRayGenRecordSize;
dispatchDesc.RayGenerationShaderRecord.SizeInBytes = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES;
dispatchDesc.MissShaderTable.StartAddress =
diff --git a/tools/gfx/d3d12/d3d12-command-encoder.h b/tools/gfx/d3d12/d3d12-command-encoder.h
index 5dd9909f8..d54411e1a 100644
--- a/tools/gfx/d3d12/d3d12-command-encoder.h
+++ b/tools/gfx/d3d12/d3d12-command-encoder.h
@@ -59,7 +59,7 @@ public:
return nullptr;
}
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject)
+ queryInterface(SlangUUID const& uuid, void** outObject) override
{
if (auto ptr = getInterface(uuid))
{
@@ -68,8 +68,8 @@ public:
}
return SLANG_E_NO_INTERFACE;
}
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() { return 1; }
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer(
IBufferResource* dst,
diff --git a/tools/gfx/d3d12/d3d12-shader-table.cpp b/tools/gfx/d3d12/d3d12-shader-table.cpp
index ef4feecc7..2773578b8 100644
--- a/tools/gfx/d3d12/d3d12-shader-table.cpp
+++ b/tools/gfx/d3d12/d3d12-shader-table.cpp
@@ -17,12 +17,11 @@ RefPtr<BufferResource> ShaderTableImpl::createDeviceBuffer(
TransientResourceHeapBase* transientHeap,
IResourceCommandEncoder* encoder)
{
- uint32_t raygenTableSize = m_rayGenShaderCount * D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES;
+ uint32_t raygenTableSize = m_rayGenShaderCount * kRayGenRecordSize;
uint32_t missTableSize = m_missShaderCount * D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES;
uint32_t hitgroupTableSize = m_hitGroupCount * D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES;
m_rayGenTableOffset = 0;
- m_missTableOffset = (uint32_t)D3DUtil::calcAligned(
- raygenTableSize, D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT);
+ m_missTableOffset = raygenTableSize;
m_hitGroupTableOffset = (uint32_t)D3DUtil::calcAligned(
m_missTableOffset + missTableSize, D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT);
uint32_t tableSize = m_hitGroupTableOffset + hitgroupTableSize;
@@ -72,7 +71,7 @@ RefPtr<BufferResource> ShaderTableImpl::createDeviceBuffer(
for (uint32_t i = 0; i < m_rayGenShaderCount; i++)
{
copyShaderIdInto(
- stagingBufferPtr + m_rayGenTableOffset + D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES * i,
+ stagingBufferPtr + m_rayGenTableOffset + kRayGenRecordSize * i,
m_shaderGroupNames[i],
m_recordOverwrites[i]);
}
diff --git a/tools/gfx/gfx.slang b/tools/gfx/gfx.slang
index 1561ac2a8..7c6aefe79 100644
--- a/tools/gfx/gfx.slang
+++ b/tools/gfx/gfx.slang
@@ -1300,7 +1300,7 @@ interface IQueryPool
interface ICommandEncoder
{
void endEncoding();
- void writeTimestamp(IQueryPool *queryPool, GfxIndex queryIndex);
+ void writeTimestamp(IQueryPool queryPool, GfxIndex queryIndex);
};
struct IndirectDispatchArguments
@@ -1541,36 +1541,12 @@ interface ICommandBuffer
IRenderPassLayout renderPass,
IFramebuffer framebuffer,
out IRenderCommandEncoder outEncoder);
- IRenderCommandEncoder encodeRenderCommands(IRenderPassLayout renderPass, IFramebuffer framebuffer)
- {
- IRenderCommandEncoder result;
- encodeRenderCommands(renderPass, framebuffer, result);
- return result;
- }
void encodeComputeCommands(out IComputeCommandEncoder encoder);
- IComputeCommandEncoder encodeComputeCommands()
- {
- IComputeCommandEncoder result;
- encodeComputeCommands(result);
- return result;
- }
void encodeResourceCommands(out IResourceCommandEncoder outEncoder);
- IResourceCommandEncoder encodeResourceCommands()
- {
- IResourceCommandEncoder result;
- encodeResourceCommands(result);
- return result;
- }
void encodeRayTracingCommands(out IRayTracingCommandEncoder outEncoder);
- IRayTracingCommandEncoder encodeRayTracingCommands()
- {
- IRayTracingCommandEncoder result;
- encodeRayTracingCommands(result);
- return result;
- }
void close();
@@ -1599,12 +1575,6 @@ interface ICommandQueue
NativeRef<ICommandBuffer> *commandBuffers,
Optional<IFence> fenceToSignal,
uint64_t newFenceValue);
- void executeCommandBuffer(
- ICommandBuffer commandBuffer, Optional<IFence> fenceToSignal = none, uint64_t newFenceValue = 0)
- {
- NativeRef<ICommandBuffer> nativeCmdBuffer = NativeRef<ICommandBuffer>(commandBuffer);
- executeCommandBuffers(1, &nativeCmdBuffer, fenceToSignal, newFenceValue);
- }
Result getNativeHandle(out InteropHandle outHandle);
@@ -1955,4 +1925,32 @@ interface IDevice
Result getTextureRowAlignment(out Size outAlignment);
};
+#define SLANG_GFX_IMPORT [DllImport("gfx")]
+/// Checks if format is compressed
+SLANG_GFX_IMPORT bool gfxIsCompressedFormat(Format format);
+
+/// Checks if format is typeless
+SLANG_GFX_IMPORT bool gfxIsTypelessFormat(Format format);
+
+/// Gets information about the format
+SLANG_GFX_IMPORT Result gfxGetFormatInfo(Format format, FormatInfo *outInfo);
+
+/// Given a type returns a function that can construct it, or nullptr if there isn't one
+SLANG_GFX_IMPORT Result gfxCreateDevice(const DeviceDesc* desc, out IDevice outDevice);
+
+/// Sets a callback for receiving debug messages.
+/// The layer does not hold a strong reference to the callback object.
+/// The user is responsible for holding the callback object alive.
+SLANG_GFX_IMPORT Result gfxSetDebugCallback(IDebugCallback callback);
+
+/// Enables debug layer. The debug layer will check all `gfx` calls and verify that uses are valid.
+SLANG_GFX_IMPORT void gfxEnableDebugLayer();
+
+SLANG_GFX_IMPORT NativeString gfxGetDeviceTypeName(DeviceType type);
+
+public bool succeeded(Result code)
+{
+ return code >= 0;
+}
+
}
diff --git a/tools/gfx/immediate-renderer-base.cpp b/tools/gfx/immediate-renderer-base.cpp
index 57cb7f934..7a800d49b 100644
--- a/tools/gfx/immediate-renderer-base.cpp
+++ b/tools/gfx/immediate-renderer-base.cpp
@@ -78,8 +78,8 @@ public:
}
return SLANG_E_NO_INTERFACE;
}
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() { return 1; }
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override {}
virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer(
diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp
index b508e0fe8..e32ed8f6c 100644
--- a/tools/gfx/render.cpp
+++ b/tools/gfx/render.cpp
@@ -180,7 +180,7 @@ static void _compileTimeAsserts()
extern "C"
{
- SLANG_GFX_API bool gfxIsCompressedFormat(Format format)
+ SLANG_GFX_API bool SLANG_MCALL gfxIsCompressedFormat(Format format)
{
switch (format)
{
@@ -204,7 +204,7 @@ extern "C"
}
}
- SLANG_GFX_API bool gfxIsTypelessFormat(Format format)
+ SLANG_GFX_API bool SLANG_MCALL gfxIsTypelessFormat(Format format)
{
switch (format)
{
@@ -226,7 +226,7 @@ extern "C"
}
}
- SLANG_GFX_API SlangResult gfxGetFormatInfo(Format format, FormatInfo* outInfo)
+ SLANG_GFX_API SlangResult SLANG_MCALL gfxGetFormatInfo(Format format, FormatInfo* outInfo)
{
*outInfo = s_formatInfoMap.get(format);
return SLANG_OK;
diff --git a/tools/gfx/renderer-shared.h b/tools/gfx/renderer-shared.h
index eb3c7cad1..0d71059fc 100644
--- a/tools/gfx/renderer-shared.h
+++ b/tools/gfx/renderer-shared.h
@@ -1161,6 +1161,8 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL finish() override { return SLANG_OK; }
};
+static const int kRayGenRecordSize = 64; // D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT;
+
class ShaderTableBase
: public IShaderTable
, public Slang::ComObject
diff --git a/tools/gfx/slang.slang b/tools/gfx/slang.slang
index 56b304efd..4250cb62e 100644
--- a/tools/gfx/slang.slang
+++ b/tools/gfx/slang.slang
@@ -1,7 +1,7 @@
namespace slang
{
-typedef int64_t Result;
+typedef int32_t Result;
typedef uint64_t Size;
typedef int64_t Int;
typedef uint64_t UInt;
diff --git a/tools/gfx/vulkan/vk-command-encoder.h b/tools/gfx/vulkan/vk-command-encoder.h
index 0e834a5fb..1cd05e6eb 100644
--- a/tools/gfx/vulkan/vk-command-encoder.h
+++ b/tools/gfx/vulkan/vk-command-encoder.h
@@ -61,7 +61,7 @@ public:
return nullptr;
}
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject)
+ queryInterface(SlangUUID const& uuid, void** outObject) override
{
if (auto ptr = getInterface(uuid))
{
@@ -70,8 +70,8 @@ public:
}
return SLANG_E_NO_INTERFACE;
}
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() { return 1; }
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer(
IBufferResource* dst,