summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-01-10 13:30:41 -0800
committerGitHub <noreply@github.com>2022-01-10 13:30:41 -0800
commitad9abad220df96d2155f6825f158b7f6327b7ea8 (patch)
tree12b146961910c1b4aa6a68b3063ec3e68d2ce23d
parent0ac19741937e007ebb45791f53d413d21055feda (diff)
Various fixes to gfx. (#2074)
* Various gfx fixes. * Fixup. Co-authored-by: Yong He <yhe@nvidia.com>
-rw-r--r--build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj4
-rw-r--r--build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters18
-rw-r--r--examples/gpu-printing/main.cpp2
-rw-r--r--examples/shader-object/main.cpp2
-rw-r--r--slang-gfx.h38
-rw-r--r--tools/gfx-unit-test/buffer-barrier-test.cpp2
-rw-r--r--tools/gfx-unit-test/compute-smoke.cpp2
-rw-r--r--tools/gfx-unit-test/create-buffer-from-handle.cpp2
-rw-r--r--tools/gfx-unit-test/existing-device-handle-test.cpp2
-rw-r--r--tools/gfx-unit-test/format-unit-tests.cpp2
-rw-r--r--tools/gfx-unit-test/get-buffer-resource-handle-test.cpp2
-rw-r--r--tools/gfx-unit-test/mutable-shader-object.cpp2
-rw-r--r--tools/gfx-unit-test/root-mutable-shader-object.cpp2
-rw-r--r--tools/gfx-unit-test/shared-buffers-tests.cpp2
-rw-r--r--tools/gfx-unit-test/shared-textures-tests.cpp2
-rw-r--r--tools/gfx/cpu/render-cpu.cpp15
-rw-r--r--tools/gfx/cuda/render-cuda.cpp14
-rw-r--r--tools/gfx/d3d/d3d-util.cpp39
-rw-r--r--tools/gfx/d3d/d3d-util.h2
-rw-r--r--tools/gfx/d3d11/render-d3d11.cpp54
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp137
-rw-r--r--tools/gfx/debug-layer.cpp15
-rw-r--r--tools/gfx/debug-layer.h8
-rw-r--r--tools/gfx/open-gl/render-gl.cpp16
-rw-r--r--tools/gfx/render.cpp2
-rw-r--r--tools/gfx/simple-transient-resource-heap.h2
-rw-r--r--tools/gfx/transient-resource-heap-base.h8
-rw-r--r--tools/gfx/vulkan/render-vk.cpp44
-rw-r--r--tools/gfx/vulkan/vk-util.cpp2
-rw-r--r--tools/platform/gui.cpp6
-rw-r--r--tools/render-test/render-test-main.cpp6
31 files changed, 292 insertions, 162 deletions
diff --git a/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj b/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj
index 3adf5a226..4c66b32f2 100644
--- a/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj
+++ b/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj
@@ -275,7 +275,6 @@
<ClCompile Include="..\..\..\tools\gfx-unit-test\buffer-barrier-test.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\compute-smoke.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\create-buffer-from-handle.cpp" />
- <ClCompile Include="..\..\..\tools\gfx-unit-test\instanced-draw-tests.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\existing-device-handle-test.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\format-unit-tests.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\get-buffer-resource-handle-test.cpp" />
@@ -283,10 +282,11 @@
<ClCompile Include="..\..\..\tools\gfx-unit-test\get-cmd-queue-handle-test.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\get-texture-resource-handle-test.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\gfx-test-util.cpp" />
+ <ClCompile Include="..\..\..\tools\gfx-unit-test\instanced-draw-tests.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.cpp" />
+ <ClCompile Include="..\..\..\tools\gfx-unit-test\root-mutable-shader-object.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\shared-buffers-tests.cpp" />
<ClCompile Include="..\..\..\tools\gfx-unit-test\shared-textures-tests.cpp" />
- <ClCompile Include="..\..\..\tools\gfx-unit-test\root-mutable-shader-object.cpp" />
<ClCompile Include="..\..\..\tools\unit-test\slang-unit-test.cpp" />
</ItemGroup>
<ItemGroup>
diff --git a/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters b/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters
index b119da8bf..997487785 100644
--- a/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters
+++ b/build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters
@@ -47,22 +47,22 @@
<ClCompile Include="..\..\..\tools\gfx-unit-test\gfx-test-util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.cpp">
+ <ClCompile Include="..\..\..\tools\gfx-unit-test\instanced-draw-tests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\tools\gfx-unit-test\shared-buffers-tests.cpp">
+ <ClCompile Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\tools\gfx-unit-test\shared-textures-tests.cpp">
+ <ClCompile Include="..\..\..\tools\gfx-unit-test\root-mutable-shader-object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\tools\gfx-unit-test\root-mutable-shader-object.cpp">
+ <ClCompile Include="..\..\..\tools\gfx-unit-test\shared-buffers-tests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\tools\unit-test\slang-unit-test.cpp">
+ <ClCompile Include="..\..\..\tools\gfx-unit-test\shared-textures-tests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\tools\gfx-unit-test\instanced-draw-tests.cpp">
+ <ClCompile Include="..\..\..\tools\unit-test\slang-unit-test.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@@ -79,13 +79,13 @@
<None Include="..\..\..\tools\gfx-unit-test\format-test-shaders.slang">
<Filter>Source Files</Filter>
</None>
- <None Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.slang">
+ <None Include="..\..\..\tools\gfx-unit-test\graphics-smoke.slang">
<Filter>Source Files</Filter>
</None>
- <None Include="..\..\..\tools\gfx-unit-test\trivial-copy.slang">
+ <None Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.slang">
<Filter>Source Files</Filter>
</None>
- <None Include="..\..\..\tools\gfx-unit-test\graphics-smoke.slang">
+ <None Include="..\..\..\tools\gfx-unit-test\trivial-copy.slang">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
diff --git a/examples/gpu-printing/main.cpp b/examples/gpu-printing/main.cpp
index cf376236d..31313830f 100644
--- a/examples/gpu-printing/main.cpp
+++ b/examples/gpu-printing/main.cpp
@@ -108,7 +108,7 @@ Result execute()
printBufferDesc.defaultState = ResourceState::UnorderedAccess;
printBufferDesc.allowedStates = ResourceStateSet(
ResourceState::CopySource, ResourceState::CopyDestination, ResourceState::UnorderedAccess);
- printBufferDesc.cpuAccessFlags = MemoryType::CpuRead; // | Resource::AccessFlag::Write;
+ printBufferDesc.memoryType = MemoryType::ReadBack;
auto printBuffer = gDevice->createBufferResource(printBufferDesc);
IResourceView::Desc printBufferViewDesc;
diff --git a/examples/shader-object/main.cpp b/examples/shader-object/main.cpp
index 017aba3b7..58c6abbfd 100644
--- a/examples/shader-object/main.cpp
+++ b/examples/shader-object/main.cpp
@@ -170,7 +170,7 @@ int main()
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<gfx::IBufferResource> numbersBuffer;
SLANG_RETURN_ON_FAIL(device->createBufferResource(
diff --git a/slang-gfx.h b/slang-gfx.h
index c61dc31ea..6a4908e5f 100644
--- a/slang-gfx.h
+++ b/slang-gfx.h
@@ -98,6 +98,13 @@ enum class BindingStyle
CountOf,
};
+enum class AccessFlag
+{
+ None,
+ Read,
+ Write,
+};
+
class ITransientResourceHeap;
class IShaderProgram: public ISlangUnknown
@@ -176,6 +183,8 @@ public:
x(R8_UNORM, 1, 1) \
x(B8G8R8A8_UNORM, 4, 1) \
x(B8G8R8A8_UNORM_SRGB, 4, 1) \
+ x(B8G8R8X8_UNORM, 4, 1) \
+ x(B8G8R8X8_UNORM_SRGB, 4, 1) \
\
x(R16G16B16A16_SNORM, 8, 1) \
x(R16G16_SNORM, 4, 1) \
@@ -281,6 +290,8 @@ enum class Format
R8_UNORM,
B8G8R8A8_UNORM,
B8G8R8A8_UNORM_SRGB,
+ B8G8R8X8_UNORM,
+ B8G8R8X8_UNORM_SRGB,
R16G16B16A16_SNORM,
R16G16_SNORM,
@@ -414,14 +425,11 @@ private:
/// Describes how memory for the resource should be allocated for CPU access.
-struct MemoryType
+enum class MemoryType
{
- enum Enum
- {
- GpuOnly = 0x0,
- CpuRead = 0x1,
- CpuWrite = 0x2
- };
+ DeviceLocal,
+ Upload,
+ ReadBack,
};
enum class InteropHandleAPI
@@ -476,12 +484,10 @@ public:
/// Base class for Descs
struct DescBase
{
- bool hasCpuAccessFlag(MemoryType::Enum accessFlag) const { return (cpuAccessFlags & accessFlag) != 0; }
-
Type type = Type::Unknown;
ResourceState defaultState = ResourceState::Undefined;
ResourceStateSet allowedStates = ResourceStateSet();
- int cpuAccessFlags = 0; ///< Combination of Resource::AccessFlag
+ MemoryType memoryType = MemoryType::DeviceLocal;
InteropHandle existingHandle = {};
bool isShared = false;
};
@@ -499,6 +505,12 @@ public:
0xa0e39f34, 0x8398, 0x4522, { 0x95, 0xc2, 0xeb, 0xc0, 0xf9, 0x84, 0xef, 0x3f } \
}
+struct MemoryRange
+{
+ uint64_t offset;
+ uint64_t size;
+};
+
class IBufferResource: public IResource
{
public:
@@ -511,6 +523,8 @@ public:
virtual SLANG_NO_THROW Desc* SLANG_MCALL getDesc() = 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;
};
#define SLANG_UUID_IBufferResource \
{ \
@@ -1631,8 +1645,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL memoryBarrier(
int count,
IAccelerationStructure* const* structures,
- MemoryType::Enum sourceAccess,
- MemoryType::Enum destAccess) = 0;
+ AccessFlag sourceAccess,
+ AccessFlag destAccess) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL
bindPipeline(IPipelineState* state, IShaderObject** outRootObject) = 0;
diff --git a/tools/gfx-unit-test/buffer-barrier-test.cpp b/tools/gfx-unit-test/buffer-barrier-test.cpp
index 0103fda4d..48e23b2b3 100644
--- a/tools/gfx-unit-test/buffer-barrier-test.cpp
+++ b/tools/gfx-unit-test/buffer-barrier-test.cpp
@@ -32,7 +32,7 @@ namespace gfx_test
bufferDesc.format = gfx::Format::Unknown;
bufferDesc.elementSize = sizeof(float);
bufferDesc.defaultState = unorderedAccess ? ResourceState::UnorderedAccess : ResourceState::ShaderResource;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
bufferDesc.allowedStates = ResourceStateSet(
ResourceState::ShaderResource,
ResourceState::CopyDestination,
diff --git a/tools/gfx-unit-test/compute-smoke.cpp b/tools/gfx-unit-test/compute-smoke.cpp
index dbe22f08b..185e8aa99 100644
--- a/tools/gfx-unit-test/compute-smoke.cpp
+++ b/tools/gfx-unit-test/compute-smoke.cpp
@@ -39,7 +39,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<IBufferResource> numbersBuffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
diff --git a/tools/gfx-unit-test/create-buffer-from-handle.cpp b/tools/gfx-unit-test/create-buffer-from-handle.cpp
index f7e9356bc..22612dbf0 100644
--- a/tools/gfx-unit-test/create-buffer-from-handle.cpp
+++ b/tools/gfx-unit-test/create-buffer-from-handle.cpp
@@ -39,7 +39,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<IBufferResource> originalNumbersBuffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
diff --git a/tools/gfx-unit-test/existing-device-handle-test.cpp b/tools/gfx-unit-test/existing-device-handle-test.cpp
index efb21dd0b..cf13fe090 100644
--- a/tools/gfx-unit-test/existing-device-handle-test.cpp
+++ b/tools/gfx-unit-test/existing-device-handle-test.cpp
@@ -39,7 +39,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<IBufferResource> numbersBuffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
diff --git a/tools/gfx-unit-test/format-unit-tests.cpp b/tools/gfx-unit-test/format-unit-tests.cpp
index 2cba98178..55aa2768b 100644
--- a/tools/gfx-unit-test/format-unit-tests.cpp
+++ b/tools/gfx-unit-test/format-unit-tests.cpp
@@ -137,7 +137,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<IBufferResource> outBuffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
diff --git a/tools/gfx-unit-test/get-buffer-resource-handle-test.cpp b/tools/gfx-unit-test/get-buffer-resource-handle-test.cpp
index 047522688..dc0da830a 100644
--- a/tools/gfx-unit-test/get-buffer-resource-handle-test.cpp
+++ b/tools/gfx-unit-test/get-buffer-resource-handle-test.cpp
@@ -27,7 +27,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<IBufferResource> buffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
diff --git a/tools/gfx-unit-test/mutable-shader-object.cpp b/tools/gfx-unit-test/mutable-shader-object.cpp
index 0880bc2d2..28ec8fb45 100644
--- a/tools/gfx-unit-test/mutable-shader-object.cpp
+++ b/tools/gfx-unit-test/mutable-shader-object.cpp
@@ -39,7 +39,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<IBufferResource> numbersBuffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
diff --git a/tools/gfx-unit-test/root-mutable-shader-object.cpp b/tools/gfx-unit-test/root-mutable-shader-object.cpp
index 40b57e79d..43c5fbd1f 100644
--- a/tools/gfx-unit-test/root-mutable-shader-object.cpp
+++ b/tools/gfx-unit-test/root-mutable-shader-object.cpp
@@ -39,7 +39,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<IBufferResource> numbersBuffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
diff --git a/tools/gfx-unit-test/shared-buffers-tests.cpp b/tools/gfx-unit-test/shared-buffers-tests.cpp
index fc9f88173..915da798b 100644
--- a/tools/gfx-unit-test/shared-buffers-tests.cpp
+++ b/tools/gfx-unit-test/shared-buffers-tests.cpp
@@ -25,7 +25,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
bufferDesc.isShared = true;
ComPtr<IBufferResource> srcBuffer;
diff --git a/tools/gfx-unit-test/shared-textures-tests.cpp b/tools/gfx-unit-test/shared-textures-tests.cpp
index b2944b6e7..b83f58a78 100644
--- a/tools/gfx-unit-test/shared-textures-tests.cpp
+++ b/tools/gfx-unit-test/shared-textures-tests.cpp
@@ -114,7 +114,7 @@ namespace gfx_test
ResourceState::CopyDestination,
ResourceState::CopySource);
bufferDesc.defaultState = ResourceState::UnorderedAccess;
- bufferDesc.cpuAccessFlags = MemoryType::GpuOnly;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
ComPtr<IBufferResource> outBuffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
diff --git a/tools/gfx/cpu/render-cpu.cpp b/tools/gfx/cpu/render-cpu.cpp
index 15014f6e9..723dba10e 100644
--- a/tools/gfx/cpu/render-cpu.cpp
+++ b/tools/gfx/cpu/render-cpu.cpp
@@ -54,6 +54,21 @@ public:
{
return (DeviceAddress)m_data;
}
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ map(MemoryRange* rangeToRead, void** outPointer) override
+ {
+ SLANG_UNUSED(rangeToRead);
+ if (outPointer)
+ *outPointer = m_data;
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override
+ {
+ SLANG_UNUSED(writtenRange);
+ return SLANG_OK;
+ }
};
struct CPUTextureBaseShapeInfo
diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp
index efaaa8645..46f5be9cb 100644
--- a/tools/gfx/cuda/render-cuda.cpp
+++ b/tools/gfx/cuda/render-cuda.cpp
@@ -202,6 +202,20 @@ public:
outHandle->api = InteropHandleAPI::CUDA;
return SLANG_OK;
}
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ map(MemoryRange* rangeToRead, void** outPointer) override
+ {
+ SLANG_UNUSED(rangeToRead);
+ SLANG_UNUSED(outPointer);
+ return SLANG_FAIL;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override
+ {
+ SLANG_UNUSED(writtenRange);
+ return SLANG_FAIL;
+ }
};
class TextureCUDAResource : public TextureResource
diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp
index a9e49bfd9..860649be4 100644
--- a/tools/gfx/d3d/d3d-util.cpp
+++ b/tools/gfx/d3d/d3d-util.cpp
@@ -166,7 +166,9 @@ D3D12_DEPTH_STENCILOP_DESC D3DUtil::translateStencilOpDesc(DepthStencilOpDesc de
case Format::R8G8_UNORM: return DXGI_FORMAT_R8G8_UNORM;
case Format::R8_UNORM: return DXGI_FORMAT_R8_UNORM;
case Format::B8G8R8A8_UNORM: return DXGI_FORMAT_B8G8R8A8_UNORM;
+ case Format::B8G8R8X8_UNORM: return DXGI_FORMAT_B8G8R8X8_UNORM;
case Format::B8G8R8A8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
+ case Format::B8G8R8X8_UNORM_SRGB: return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
case Format::R16G16B16A16_SNORM: return DXGI_FORMAT_R16G16B16A16_SNORM;
case Format::R16G16_SNORM: return DXGI_FORMAT_R16G16_SNORM;
@@ -208,43 +210,6 @@ D3D12_DEPTH_STENCILOP_DESC D3DUtil::translateStencilOpDesc(DepthStencilOpDesc de
}
}
-D3D12_RESOURCE_STATES D3DUtil::translateResourceState(ResourceState state)
-{
- switch (state)
- {
- case ResourceState::Undefined:
- return D3D12_RESOURCE_STATE_COMMON;
- case ResourceState::ShaderResource:
- return D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE |
- D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- case ResourceState::UnorderedAccess:
- return D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
- case ResourceState::RenderTarget:
- return D3D12_RESOURCE_STATE_RENDER_TARGET;
- case ResourceState::DepthRead:
- return D3D12_RESOURCE_STATE_DEPTH_READ;
- case ResourceState::DepthWrite:
- return D3D12_RESOURCE_STATE_DEPTH_WRITE;
- case ResourceState::Present:
- return D3D12_RESOURCE_STATE_PRESENT;
- case ResourceState::CopySource:
- return D3D12_RESOURCE_STATE_COPY_SOURCE;
- case ResourceState::CopyDestination:
- return D3D12_RESOURCE_STATE_COPY_DEST;
- case ResourceState::ResolveSource:
- return D3D12_RESOURCE_STATE_RESOLVE_SOURCE;
- case ResourceState::ResolveDestination:
- return D3D12_RESOURCE_STATE_RESOLVE_DEST;
-#if SLANG_GFX_HAS_DXR_SUPPORT
- case ResourceState::AccelerationStructure:
- return D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE;
-#endif
- default:
- return D3D12_RESOURCE_STATE_COMMON;
- }
-}
-
-
/* static */DXGI_FORMAT D3DUtil::calcResourceFormat(UsageType usage, Int usageFlags, DXGI_FORMAT format)
{
SLANG_UNUSED(usage);
diff --git a/tools/gfx/d3d/d3d-util.h b/tools/gfx/d3d/d3d-util.h
index 41f4be613..dd22bfcdd 100644
--- a/tools/gfx/d3d/d3d-util.h
+++ b/tools/gfx/d3d/d3d-util.h
@@ -63,8 +63,6 @@ class D3DUtil
/// Given a slang pixel format returns the equivalent DXGI_ pixel format. If the format is not known, will return DXGI_FORMAT_UNKNOWN
static DXGI_FORMAT getMapFormat(Format format);
- static D3D12_RESOURCE_STATES translateResourceState(ResourceState state);
-
/// Given the usage, flags, and format will return the most suitable format. Will return DXGI_UNKNOWN if combination is not possible
static DXGI_FORMAT calcFormat(UsageType usage, DXGI_FORMAT format);
/// Calculate appropriate format for creating a buffer for usage and flags
diff --git a/tools/gfx/d3d11/render-d3d11.cpp b/tools/gfx/d3d11/render-d3d11.cpp
index f31cce931..530b67055 100644
--- a/tools/gfx/d3d11/render-d3d11.cpp
+++ b/tools/gfx/d3d11/render-d3d11.cpp
@@ -228,6 +228,20 @@ protected:
{
return 0;
}
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ map(MemoryRange* rangeToRead, void** outPointer) override
+ {
+ SLANG_UNUSED(rangeToRead);
+ SLANG_UNUSED(outPointer);
+ return SLANG_FAIL;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override
+ {
+ SLANG_UNUSED(writtenRange);
+ return SLANG_FAIL;
+ }
};
class TextureResourceImpl : public TextureResource
{
@@ -1524,7 +1538,7 @@ protected:
bufferDesc.defaultState = ResourceState::ConstantBuffer;
bufferDesc.allowedStates =
ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
- bufferDesc.cpuAccessFlags |= MemoryType::CpuWrite;
+ bufferDesc.memoryType = MemoryType::Upload;
SLANG_RETURN_ON_FAIL(
device->createBufferResource(bufferDesc, nullptr, bufferResourcePtr.writeRef()));
m_ordinaryDataBuffer = static_cast<BufferResourceImpl*>(bufferResourcePtr.get());
@@ -2561,16 +2575,19 @@ static int _calcResourceBindFlags(ResourceStateSet allowedStates)
return dstFlags;
}
-static int _calcResourceAccessFlags(int accessFlags)
+static int _calcResourceAccessFlags(MemoryType memType)
{
- switch (accessFlags)
- {
- case 0: return 0;
- case MemoryType::CpuRead: return D3D11_CPU_ACCESS_READ;
- case MemoryType::CpuWrite: return D3D11_CPU_ACCESS_WRITE;
- case MemoryType::CpuRead |
- MemoryType::CpuWrite: return D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
- default: assert(!"Invalid flags"); return 0;
+ switch (memType)
+ {
+ case MemoryType::DeviceLocal:
+ return 0;
+ case MemoryType::ReadBack:
+ return D3D11_CPU_ACCESS_READ;
+ case MemoryType::Upload:
+ return D3D11_CPU_ACCESS_WRITE;
+ default:
+ assert(!"Invalid flags");
+ return 0;
}
}
@@ -2616,7 +2633,7 @@ Result D3D11Device::createTextureResource(const ITextureResource::Desc& descIn,
subResourcesPtr = subRes.getBuffer();
}
- const int accessFlags = _calcResourceAccessFlags(srcDesc.cpuAccessFlags);
+ const int accessFlags = _calcResourceAccessFlags(srcDesc.memoryType);
RefPtr<TextureResourceImpl> texture(new TextureResourceImpl(srcDesc));
@@ -2722,17 +2739,22 @@ Result D3D11Device::createBufferResource(const IBufferResource::Desc& descIn, co
bufferDesc.ByteWidth = UINT(alignedSizeInBytes);
bufferDesc.BindFlags = d3dBindFlags;
// For read we'll need to do some staging
- bufferDesc.CPUAccessFlags =
- _calcResourceAccessFlags(descIn.cpuAccessFlags & MemoryType::CpuWrite);
+ bufferDesc.CPUAccessFlags = _calcResourceAccessFlags(descIn.memoryType);
bufferDesc.Usage = D3D11_USAGE_DEFAULT;
// If written by CPU, make it dynamic
- if ((descIn.cpuAccessFlags & MemoryType::CpuWrite) &&
+ if (descIn.memoryType == MemoryType::Upload &&
!descIn.allowedStates.contains(ResourceState::UnorderedAccess))
{
bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
}
+ if (srcDesc.memoryType == MemoryType::ReadBack)
+ {
+ bufferDesc.CPUAccessFlags |= D3D11_CPU_ACCESS_READ;
+ bufferDesc.Usage = D3D11_USAGE_STAGING;
+ }
+
switch (descIn.defaultState)
{
case ResourceState::ConstantBuffer:
@@ -2758,7 +2780,7 @@ Result D3D11Device::createBufferResource(const IBufferResource::Desc& descIn, co
}
}
- if (srcDesc.cpuAccessFlags & MemoryType::CpuWrite)
+ if (srcDesc.memoryType == MemoryType::Upload)
{
bufferDesc.CPUAccessFlags |= D3D11_CPU_ACCESS_WRITE;
}
@@ -2771,7 +2793,7 @@ Result D3D11Device::createBufferResource(const IBufferResource::Desc& descIn, co
SLANG_RETURN_ON_FAIL(m_device->CreateBuffer(&bufferDesc, initData ? &subResourceData : nullptr, buffer->m_buffer.writeRef()));
buffer->m_d3dUsage = bufferDesc.Usage;
- if (srcDesc.cpuAccessFlags & MemoryType::CpuRead || bufferDesc.Usage != D3D11_USAGE_DYNAMIC)
+ if (srcDesc.memoryType == MemoryType::ReadBack || bufferDesc.Usage != D3D11_USAGE_DYNAMIC)
{
D3D11_BUFFER_DESC bufDesc = {};
bufDesc.BindFlags = 0;
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index bbfc10f5a..494dfd0f0 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -233,7 +233,7 @@ public:
BufferResourceImpl(const Desc& desc)
: Parent(desc)
- , m_defaultState(D3DUtil::translateResourceState(desc.defaultState))
+ , m_defaultState(D3DUtil::getResourceState(desc.defaultState))
{
}
@@ -279,6 +279,31 @@ public:
sharedHandle = *outHandle;
return SLANG_OK;
}
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ map(MemoryRange* rangeToRead, void** outPointer) override
+ {
+ D3D12_RANGE range = {};
+ if (rangeToRead)
+ {
+ range.Begin = (SIZE_T)rangeToRead->offset;
+ range.End = (SIZE_T)(rangeToRead->offset + rangeToRead->size);
+ }
+ SLANG_RETURN_ON_FAIL(m_resource.getResource()->Map(0, rangeToRead ? &range : nullptr, outPointer));
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override
+ {
+ D3D12_RANGE range = {};
+ if (writtenRange)
+ {
+ range.Begin = (SIZE_T)writtenRange->offset;
+ range.End = (SIZE_T)(writtenRange->offset + writtenRange->size);
+ }
+ m_resource.getResource()->Unmap(0, writtenRange ? &range : nullptr);
+ return SLANG_OK;
+ }
};
class TextureResourceImpl: public TextureResource
@@ -288,7 +313,7 @@ public:
TextureResourceImpl(const Desc& desc)
: Parent(desc)
- , m_defaultState(D3DUtil::translateResourceState(desc.defaultState))
+ , m_defaultState(D3DUtil::getResourceState(desc.defaultState))
{
}
@@ -387,6 +412,7 @@ public:
{
SimpleRenderPassLayout::init(desc);
m_framebufferLayout = static_cast<FramebufferLayoutImpl*>(desc.framebufferLayout);
+ m_hasDepthStencil = m_framebufferLayout->m_hasDepthStencil;
}
};
@@ -705,7 +731,7 @@ public:
bufferDesc.allowedStates =
ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
bufferDesc.sizeInBytes = desc.constantBufferSize;
- bufferDesc.cpuAccessFlags |= MemoryType::CpuWrite;
+ bufferDesc.memoryType = MemoryType::Upload;
SLANG_RETURN_ON_FAIL(device->createBufferResource(
bufferDesc,
nullptr,
@@ -736,12 +762,15 @@ public:
IBufferResource* uploadResource;
- if (!buffer->getDesc()->hasCpuAccessFlag(MemoryType::CpuWrite))
+ if (buffer->getDesc()->memoryType != MemoryType::Upload)
{
transientHeap->allocateStagingBuffer(size, uploadResource, ResourceState::CopySource);
}
- D3D12Resource& uploadResourceRef = (buffer->getDesc()->hasCpuAccessFlag(MemoryType::CpuWrite)) ? buffer->m_resource : static_cast<BufferResourceImpl*>(uploadResource)->m_resource;
+ D3D12Resource& uploadResourceRef =
+ (buffer->getDesc()->memoryType == MemoryType::Upload)
+ ? buffer->m_resource
+ : static_cast<BufferResourceImpl*>(uploadResource)->m_resource;
void* uploadData;
SLANG_RETURN_ON_FAIL(uploadResourceRef.getResource()->Map(
@@ -749,7 +778,8 @@ public:
memcpy((uint8_t*)uploadData + offset, data, size);
uploadResourceRef.getResource()->Unmap(0, &readRange);
- if (!buffer->getDesc()->hasCpuAccessFlag(MemoryType::CpuWrite)) {
+ if (buffer->getDesc()->memoryType != MemoryType::Upload)
+ {
{
D3D12BarrierSubmitter submitter(cmdList);
submitter.transition(
@@ -3148,7 +3178,7 @@ public:
}
else
{
- initialState = D3DUtil::translateResourceState(access.initialState);
+ initialState = D3DUtil::getResourceState(access.initialState);
}
textureResource->m_resource.transition(
initialState,
@@ -3182,7 +3212,7 @@ public:
}
else
{
- initialState = D3DUtil::translateResourceState(
+ initialState = D3DUtil::getResourceState(
renderPass->m_depthStencilAccess.initialState);
}
textureResource->m_resource.transition(
@@ -3398,7 +3428,7 @@ public:
static_cast<TextureResourceImpl*>(resourceViewImpl->m_resource.Ptr());
textureResource->m_resource.transition(
D3D12_RESOURCE_STATE_RENDER_TARGET,
- D3DUtil::translateResourceState(access.finalState),
+ D3DUtil::getResourceState(access.finalState),
submitter);
}
}
@@ -3412,7 +3442,7 @@ public:
static_cast<TextureResourceImpl*>(resourceViewImpl->m_resource.Ptr());
textureResource->m_resource.transition(
D3D12_RESOURCE_STATE_DEPTH_WRITE,
- D3DUtil::translateResourceState(
+ D3DUtil::getResourceState(
m_renderPass->m_depthStencilAccess.finalState),
submitter);
}
@@ -3651,9 +3681,12 @@ public:
barrier.Transition.pResource = textureImpl->m_resource.getResource();
auto planeCount = D3DUtil::getPlaneSliceCount(
D3DUtil::getMapFormat(textureImpl->getDesc()->format));
+ auto arraySize = textureDesc->arraySize;
+ if (arraySize == 0)
+ arraySize = 1;
for (uint32_t planeIndex = 0; planeIndex < planeCount; planeIndex++)
{
- for (int layer = 0; layer < textureDesc->arraySize; layer++)
+ for (int layer = 0; layer < arraySize; layer++)
{
for (int mip = 0; mip < textureDesc->numMipLevels; mip++)
{
@@ -3662,7 +3695,7 @@ public:
layer,
planeIndex,
textureImpl->getDesc()->numMipLevels,
- textureImpl->getDesc()->arraySize);
+ arraySize);
barriers.add(barrier);
}
}
@@ -3697,8 +3730,8 @@ public:
}
else {
barrier.Transition.pResource = bufferImpl->m_resource;
- barrier.Transition.StateBefore = D3DUtil::translateResourceState(src);
- barrier.Transition.StateAfter = D3DUtil::translateResourceState(dst);
+ barrier.Transition.StateBefore = D3DUtil::getResourceState(src);
+ barrier.Transition.StateAfter = D3DUtil::getResourceState(dst);
barrier.Transition.Subresource = 0;
}
@@ -3884,11 +3917,9 @@ public:
bufferImpl->m_resource.getResource()->Unmap(0, nullptr);
srcRegion.pResource = bufferImpl->m_resource.getResource();
- D3D12_BOX srcBox = {};
- srcBox.right = (UINT)bufferSize;
- srcBox.bottom = srcBox.back = 1;
+
m_commandBuffer->m_cmdList->CopyTextureRegion(
- &dstRegion, offset.x, offset.y, offset.z, &srcRegion, &srcBox);
+ &dstRegion, offset.x, offset.y, offset.z, &srcRegion, nullptr);
}
}
@@ -4192,8 +4223,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL memoryBarrier(
int count,
IAccelerationStructure* const* structures,
- MemoryType::Enum sourceAccess,
- MemoryType::Enum destAccess) override;
+ AccessFlag sourceAccess,
+ AccessFlag destAccess) override;
virtual SLANG_NO_THROW void SLANG_MCALL
bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
virtual SLANG_NO_THROW void SLANG_MCALL dispatchRays(
@@ -4348,8 +4379,6 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL
executeCommandBuffers(uint32_t count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal) override
{
- // TODO: implement fence signal.
- assert(fence == nullptr);
ShortList<ID3D12CommandList*> commandLists;
for (uint32_t i = 0; i < count; i++)
{
@@ -4372,6 +4401,12 @@ public:
}
m_d3dQueue->Signal(m_fence, m_fenceValue);
ResetEvent(globalWaitHandle);
+
+ if (fence)
+ {
+ auto fenceImpl = static_cast<FenceImpl*>(fence);
+ m_d3dQueue->Signal(fenceImpl->m_fence.get(), valueToSignal);
+ }
}
virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost() override
@@ -4436,6 +4471,14 @@ public:
return SLANG_OK;
}
+ virtual SLANG_NO_THROW Result SLANG_MCALL resize(uint32_t width, uint32_t height) override
+ {
+ for (auto evt : m_frameEvents)
+ SetEvent(evt);
+ SLANG_RETURN_ON_FAIL(D3DSwapchainBase::resize(width, height));
+ return SLANG_OK;
+ }
+
virtual void createSwapchainBufferImages() override
{
m_images.clear();
@@ -4501,7 +4544,7 @@ public:
D3D12_RESOURCE_STATES finalState,
D3D12Resource& resourceOut,
bool isShared,
- MemoryType::Enum access = MemoryType::GpuOnly);
+ MemoryType access = MemoryType::DeviceLocal);
Result captureTextureToSurface(
TextureResourceImpl* resource,
@@ -4793,7 +4836,7 @@ static void _initSrvDesc(
}
}
-Result D3D12Device::createBuffer(const D3D12_RESOURCE_DESC& resourceDesc, const void* srcData, size_t srcDataSize, D3D12_RESOURCE_STATES finalState, D3D12Resource& resourceOut, bool isShared, MemoryType::Enum access)
+Result D3D12Device::createBuffer(const D3D12_RESOURCE_DESC& resourceDesc, const void* srcData, size_t srcDataSize, D3D12_RESOURCE_STATES finalState, D3D12Resource& resourceOut, bool isShared, MemoryType memoryType)
{
const size_t bufferSize = size_t(resourceDesc.Width);
@@ -4810,8 +4853,9 @@ Result D3D12Device::createBuffer(const D3D12_RESOURCE_DESC& resourceDesc, const
D3D12_RESOURCE_STATES initialState = finalState;
- switch (access) {
- case MemoryType::CpuRead:
+ switch (memoryType)
+ {
+ case MemoryType::ReadBack:
assert(!srcData);
heapProps.Type = D3D12_HEAP_TYPE_READBACK;
@@ -4819,14 +4863,14 @@ Result D3D12Device::createBuffer(const D3D12_RESOURCE_DESC& resourceDesc, const
initialState |= D3D12_RESOURCE_STATE_COPY_DEST;
break;
- case MemoryType::CpuWrite:
+ case MemoryType::Upload:
heapProps.Type = D3D12_HEAP_TYPE_UPLOAD;
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
initialState |= D3D12_RESOURCE_STATE_GENERIC_READ;
break;
- case MemoryType::GpuOnly:
+ case MemoryType::DeviceLocal:
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
initialState = (srcData ? D3D12_RESOURCE_STATE_COPY_DEST : finalState);
break;
@@ -4841,7 +4885,8 @@ Result D3D12Device::createBuffer(const D3D12_RESOURCE_DESC& resourceDesc, const
{
D3D12Resource uploadResource;
- if (access == MemoryType::GpuOnly) {
+ if (memoryType == MemoryType::DeviceLocal)
+ {
// If the buffer is on the default heap, create upload buffer.
D3D12_RESOURCE_DESC uploadDesc(resourceDesc);
uploadDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
@@ -4851,7 +4896,7 @@ Result D3D12Device::createBuffer(const D3D12_RESOURCE_DESC& resourceDesc, const
}
// Be careful not to actually copy a resource here.
- D3D12Resource& uploadResourceRef = (access == MemoryType::GpuOnly) ? uploadResource : resourceOut;
+ D3D12Resource& uploadResourceRef = (memoryType == MemoryType::DeviceLocal) ? uploadResource : resourceOut;
// Copy data to the intermediate upload heap and then schedule a copy
// from the upload heap to the vertex buffer.
@@ -4864,7 +4909,8 @@ Result D3D12Device::createBuffer(const D3D12_RESOURCE_DESC& resourceDesc, const
::memcpy(dstData, srcData, srcDataSize);
dxUploadResource->Unmap(0, nullptr);
- if (access == MemoryType::GpuOnly) {
+ if (memoryType == MemoryType::DeviceLocal)
+ {
auto encodeInfo = encodeResourceCommands();
encodeInfo.d3dCommandList->CopyBufferRegion(resourceOut, 0, uploadResourceRef, 0, bufferSize);
submitResourceCommandsAndWait(encodeInfo);
@@ -4883,7 +4929,7 @@ Result D3D12Device::captureTextureToSurface(
{
auto& resource = resourceImpl->m_resource;
- const D3D12_RESOURCE_STATES initialState = D3DUtil::translateResourceState(state);
+ const D3D12_RESOURCE_STATES initialState = D3DUtil::getResourceState(state);
const ITextureResource::Desc& gfxDesc = *resourceImpl->getDesc();
const D3D12_RESOURCE_DESC desc = resource.getResource()->GetDesc();
@@ -4923,7 +4969,7 @@ Result D3D12Device::captureTextureToSurface(
}
auto encodeInfo = encodeResourceCommands();
- auto currentState = D3DUtil::translateResourceState(state);
+ auto currentState = D3DUtil::getResourceState(state);
{
D3D12BarrierSubmitter submitter(encodeInfo.d3dCommandList);
@@ -5132,8 +5178,7 @@ Result D3D12Device::initialize(const Desc& desc)
}
#if ENABLE_DEBUG_LAYER
- m_D3D12GetDebugInterface =
- (PFN_D3D12_GET_DEBUG_INTERFACE)loadProc(d3dModule, "D3D12GetDebugInterface");
+ m_D3D12GetDebugInterface = (PFN_D3D12_GET_DEBUG_INTERFACE)loadProc(d3dModule, "D3D12GetDebugInterface");
if (m_D3D12GetDebugInterface)
{
if (SLANG_SUCCEEDED(m_D3D12GetDebugInterface(IID_PPV_ARGS(m_dxDebug.writeRef()))))
@@ -5789,8 +5834,14 @@ Result D3D12Device::createBufferResource(const IBufferResource::Desc& descIn, co
bufferDesc.Flags |= _calcResourceFlags(srcDesc.allowedStates);
const D3D12_RESOURCE_STATES initialState = buffer->m_defaultState;
- SLANG_RETURN_ON_FAIL(createBuffer(bufferDesc, initData, srcDesc.sizeInBytes, initialState, buffer->m_resource, descIn.isShared,
- (MemoryType::Enum)descIn.cpuAccessFlags));
+ SLANG_RETURN_ON_FAIL(createBuffer(
+ bufferDesc,
+ initData,
+ srcDesc.sizeInBytes,
+ initialState,
+ buffer->m_resource,
+ descIn.isShared,
+ descIn.memoryType));
returnComPtr(outResource, buffer);
return SLANG_OK;
@@ -6351,11 +6402,10 @@ Result D3D12Device::readBufferResource(
D3D12Resource& resource = buffer->m_resource;
D3D12Resource stageBuf;
- if (buffer->getDesc()->cpuAccessFlags != (int)MemoryType::CpuRead) {
-
+ if (buffer->getDesc()->memoryType != MemoryType::ReadBack)
+ {
auto encodeInfo = encodeResourceCommands();
-
// Readback heap
D3D12_HEAP_PROPERTIES heapProps;
heapProps.Type = D3D12_HEAP_TYPE_READBACK;
@@ -6377,7 +6427,8 @@ Result D3D12Device::readBufferResource(
submitResourceCommandsAndWait(encodeInfo);
}
- D3D12Resource& stageBufRef = (buffer->getDesc()->cpuAccessFlags != (int)MemoryType::CpuRead) ? stageBuf : resource;
+ D3D12Resource& stageBufRef =
+ buffer->getDesc()->memoryType != MemoryType::ReadBack ? stageBuf : resource;
// Map and copy
RefPtr<ListBlob> blob = new ListBlob();
@@ -7059,8 +7110,8 @@ void D3D12Device::CommandBufferImpl::RayTracingCommandEncoderImpl::deserializeAc
void D3D12Device::CommandBufferImpl::RayTracingCommandEncoderImpl::memoryBarrier(
int count,
IAccelerationStructure* const* structures,
- MemoryType::Enum sourceAccess,
- MemoryType::Enum destAccess)
+ AccessFlag sourceAccess,
+ AccessFlag destAccess)
{
ShortList<D3D12_RESOURCE_BARRIER> barriers;
barriers.setCount(count);
diff --git a/tools/gfx/debug-layer.cpp b/tools/gfx/debug-layer.cpp
index 2855ee2f4..b0b3ae30b 100644
--- a/tools/gfx/debug-layer.cpp
+++ b/tools/gfx/debug-layer.cpp
@@ -843,6 +843,17 @@ const char* DebugBufferResource::getDebugName()
return baseObject->getDebugName();
}
+Result DebugBufferResource::map(MemoryRange* rangeToRead, void** outPointer)
+{
+ SLANG_GFX_API_FUNC;
+ return baseObject->map(rangeToRead, outPointer);
+}
+
+Result DebugBufferResource::unmap(MemoryRange* writtenRange)
+{
+ return baseObject->unmap(writtenRange);
+}
+
IResource::Type DebugTextureResource::getType()
{
SLANG_GFX_API_FUNC;
@@ -1435,8 +1446,8 @@ void DebugRayTracingCommandEncoder::deserializeAccelerationStructure(
void DebugRayTracingCommandEncoder::memoryBarrier(
int count,
IAccelerationStructure* const* structures,
- MemoryType::Enum sourceAccess,
- MemoryType::Enum destAccess)
+ AccessFlag sourceAccess,
+ AccessFlag destAccess)
{
SLANG_GFX_API_FUNC;
List<IAccelerationStructure*> innerAS;
diff --git a/tools/gfx/debug-layer.h b/tools/gfx/debug-layer.h
index 5c8ba2115..83bcb736f 100644
--- a/tools/gfx/debug-layer.h
+++ b/tools/gfx/debug-layer.h
@@ -184,6 +184,10 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL setDebugName(const char* name) override;
virtual SLANG_NO_THROW const char* SLANG_MCALL getDebugName() 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;
};
class DebugTextureResource : public DebugObject<ITextureResource>
@@ -497,8 +501,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL memoryBarrier(
int count,
IAccelerationStructure* const* structures,
- MemoryType::Enum sourceAccess,
- MemoryType::Enum destAccess) override;
+ AccessFlag sourceAccess,
+ AccessFlag destAccess) override;
virtual SLANG_NO_THROW void SLANG_MCALL
bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
virtual SLANG_NO_THROW void SLANG_MCALL dispatchRays(
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index da62e7702..bcdaae8c0 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -271,6 +271,20 @@ public:
{
return 0;
}
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ map(MemoryRange* rangeToRead, void** outPointer) override
+ {
+ SLANG_UNUSED(rangeToRead);
+ SLANG_UNUSED(outPointer);
+ return SLANG_FAIL;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override
+ {
+ SLANG_UNUSED(writtenRange);
+ return SLANG_FAIL;
+ }
};
class TextureResourceImpl: public TextureResource
@@ -1272,7 +1286,7 @@ public:
bufferDesc.defaultState = ResourceState::ConstantBuffer;
bufferDesc.allowedStates =
ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
- bufferDesc.cpuAccessFlags |= MemoryType::CpuWrite;
+ bufferDesc.memoryType = MemoryType::Upload;
SLANG_RETURN_ON_FAIL(
device->createBufferResource(bufferDesc, nullptr, bufferResourcePtr.writeRef()));
m_ordinaryDataBuffer = static_cast<BufferResourceImpl*>(bufferResourcePtr.get());
diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp
index 293c5abcf..2125ed47f 100644
--- a/tools/gfx/render.cpp
+++ b/tools/gfx/render.cpp
@@ -113,6 +113,8 @@ struct FormatInfoMap
set(Format::R8_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 1);
set(Format::B8G8R8A8_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4);
set(Format::B8G8R8A8_UNORM_SRGB, SLANG_SCALAR_TYPE_FLOAT32, 4);
+ set(Format::B8G8R8X8_UNORM, SLANG_SCALAR_TYPE_FLOAT32, 4);
+ set(Format::B8G8R8X8_UNORM_SRGB, SLANG_SCALAR_TYPE_FLOAT32, 4);
set(Format::R16G16B16A16_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 4);
set(Format::R16G16_SNORM, SLANG_SCALAR_TYPE_FLOAT32, 2);
diff --git a/tools/gfx/simple-transient-resource-heap.h b/tools/gfx/simple-transient-resource-heap.h
index 23d9c3b59..5706c6b1d 100644
--- a/tools/gfx/simple-transient-resource-heap.h
+++ b/tools/gfx/simple-transient-resource-heap.h
@@ -24,7 +24,7 @@ public:
bufferDesc.allowedStates = ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
bufferDesc.defaultState = ResourceState::ConstantBuffer;
bufferDesc.sizeInBytes = desc.constantBufferSize;
- bufferDesc.cpuAccessFlags = MemoryType::CpuWrite;
+ bufferDesc.memoryType = MemoryType::Upload;
SLANG_RETURN_ON_FAIL(
device->createBufferResource(bufferDesc, nullptr, m_constantBuffer.writeRef()));
return SLANG_OK;
diff --git a/tools/gfx/transient-resource-heap-base.h b/tools/gfx/transient-resource-heap-base.h
index 8f346837a..f3df1c139 100644
--- a/tools/gfx/transient-resource-heap-base.h
+++ b/tools/gfx/transient-resource-heap-base.h
@@ -31,7 +31,7 @@ public:
bufferDesc.allowedStates =
ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
bufferDesc.sizeInBytes = desc.constantBufferSize;
- bufferDesc.cpuAccessFlags = MemoryType::CpuWrite;
+ bufferDesc.memoryType = MemoryType::Upload;
SLANG_RETURN_ON_FAIL(
m_device->createBufferResource(bufferDesc, nullptr, bufferPtr.writeRef()));
m_constantBuffers.add(static_cast<TBufferResource*>(bufferPtr.get()));
@@ -56,9 +56,9 @@ public:
bufferDesc.allowedStates =
ResourceStateSet(ResourceState::CopyDestination, ResourceState::CopySource);
if (state == ResourceState::CopySource)
- bufferDesc.cpuAccessFlags |= MemoryType::CpuWrite;
+ bufferDesc.memoryType = MemoryType::Upload;
else
- bufferDesc.cpuAccessFlags |= MemoryType::CpuRead;
+ bufferDesc.memoryType = MemoryType::ReadBack;
bufferDesc.sizeInBytes = size;
SLANG_RETURN_ON_FAIL(
m_device->createBufferResource(bufferDesc, nullptr, bufferPtr.writeRef()));
@@ -96,7 +96,7 @@ public:
bufferDesc.defaultState = ResourceState::ConstantBuffer;
bufferDesc.allowedStates =
ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
- bufferDesc.cpuAccessFlags |= MemoryType::CpuWrite;
+ bufferDesc.memoryType = MemoryType::Upload;
size_t lastConstantBufferSize = 0;
if (m_constantBuffers.getCount())
{
diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp
index 6534e9340..0952e7ea5 100644
--- a/tools/gfx/vulkan/render-vk.cpp
+++ b/tools/gfx/vulkan/render-vk.cpp
@@ -285,6 +285,24 @@ public:
outHandle->api = InteropHandleAPI::Vulkan;
return SLANG_OK;
}
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ map(MemoryRange* rangeToRead, void** outPointer) override
+ {
+ 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;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override
+ {
+ SLANG_UNUSED(writtenRange);
+ auto api = m_buffer.m_api;
+ api->vkUnmapMemory(api->m_device, m_buffer.m_memory);
+ return SLANG_OK;
+ }
};
class FenceImpl : public FenceBase
@@ -4796,13 +4814,13 @@ public:
public:
void init(CommandBufferImpl* commandBuffer) { m_commandBuffer = commandBuffer; }
- inline VkAccessFlags translateAccelerationStructureAccessFlag(MemoryType::Enum access)
+ inline VkAccessFlags translateAccelerationStructureAccessFlag(AccessFlag access)
{
VkAccessFlags result = 0;
- if (access & MemoryType::CpuRead)
+ if ((uint32_t)access & (uint32_t)AccessFlag::Read)
result |= VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR |
VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT;
- if (access & MemoryType::CpuWrite)
+ if ((uint32_t)access & (uint32_t)AccessFlag::Write)
result |= VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR;
return result;
}
@@ -4810,8 +4828,8 @@ public:
inline void _memoryBarrier(
int count,
IAccelerationStructure* const* structures,
- MemoryType::Enum srcAccess,
- MemoryType::Enum destAccess)
+ AccessFlag srcAccess,
+ AccessFlag destAccess)
{
ShortList<VkBufferMemoryBarrier> memBarriers;
memBarriers.setCount(count);
@@ -4938,7 +4956,7 @@ public:
if (propertyQueryCount)
{
- _memoryBarrier(1, &desc.dest, MemoryType::CpuWrite, MemoryType::CpuRead);
+ _memoryBarrier(1, &desc.dest, AccessFlag::Write, AccessFlag::Read);
_queryAccelerationStructureProperties(
1, &desc.dest, propertyQueryCount, queryDescs);
}
@@ -5011,8 +5029,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL memoryBarrier(
int count,
IAccelerationStructure* const* structures,
- MemoryType::Enum srcAccess,
- MemoryType::Enum destAccess) override
+ AccessFlag srcAccess,
+ AccessFlag destAccess) override
{
_memoryBarrier(count, structures, srcAccess, destAccess);
}
@@ -7020,12 +7038,12 @@ static VkImageUsageFlagBits _calcImageUsageFlags(ResourceStateSet states)
static VkImageUsageFlags _calcImageUsageFlags(
ResourceStateSet states,
- int cpuAccessFlags,
+ MemoryType memoryType,
const void* initData)
{
VkImageUsageFlags usage = _calcImageUsageFlags(states);
- if ((cpuAccessFlags & MemoryType::CpuWrite) || initData)
+ if (memoryType == MemoryType::Upload || initData)
{
usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
}
@@ -7223,7 +7241,7 @@ Result VKDevice::getTextureAllocationInfo(
imageInfo.format = format;
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
- imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.cpuAccessFlags, nullptr);
+ imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.memoryType, nullptr);
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
@@ -7302,7 +7320,7 @@ Result VKDevice::createTextureResource(const ITextureResource::Desc& descIn, con
imageInfo.format = format;
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
- imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.cpuAccessFlags, initData);
+ imageInfo.usage = _calcImageUsageFlags(desc.allowedStates, desc.memoryType, initData);
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
@@ -7542,7 +7560,7 @@ Result VKDevice::createBufferResource(const IBufferResource::Desc& descIn, const
SLANG_RETURN_ON_FAIL(buffer->m_buffer.init(m_api, desc.sizeInBytes, usage, reqMemoryProperties));
}
- if ((desc.cpuAccessFlags & MemoryType::CpuWrite) || initData)
+ if (desc.memoryType == MemoryType::Upload || initData)
{
SLANG_RETURN_ON_FAIL(buffer->m_uploadBuffer.init(m_api, bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
}
diff --git a/tools/gfx/vulkan/vk-util.cpp b/tools/gfx/vulkan/vk-util.cpp
index 0f6dfaf32..ea87e7c68 100644
--- a/tools/gfx/vulkan/vk-util.cpp
+++ b/tools/gfx/vulkan/vk-util.cpp
@@ -70,6 +70,8 @@ namespace gfx {
case Format::R8_UNORM: return VK_FORMAT_R8_UNORM;
case Format::B8G8R8A8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM;
case Format::B8G8R8A8_UNORM_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
+ case Format::B8G8R8X8_UNORM: return VK_FORMAT_B8G8R8A8_UNORM;
+ case Format::B8G8R8X8_UNORM_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
case Format::R16G16B16A16_SNORM: return VK_FORMAT_R16G16B16A16_SNORM;
case Format::R16G16_SNORM: return VK_FORMAT_R16G16_SNORM;
diff --git a/tools/platform/gui.cpp b/tools/platform/gui.cpp
index 5f7992abd..37e69114a 100644
--- a/tools/platform/gui.cpp
+++ b/tools/platform/gui.cpp
@@ -217,7 +217,7 @@ void GUI::endFrame(ITransientResourceHeap* transientHeap, IFramebuffer* framebuf
vertexBufferDesc.allowedStates =
ResourceStateSet(ResourceState::VertexBuffer, ResourceState::CopyDestination);
vertexBufferDesc.sizeInBytes = vertexCount * sizeof(ImDrawVert);
- vertexBufferDesc.cpuAccessFlags = MemoryType::CpuWrite;
+ vertexBufferDesc.memoryType = MemoryType::Upload;
auto vertexBuffer = device->createBufferResource(vertexBufferDesc);
gfx::IBufferResource::Desc indexBufferDesc;
@@ -226,7 +226,7 @@ void GUI::endFrame(ITransientResourceHeap* transientHeap, IFramebuffer* framebuf
indexBufferDesc.allowedStates =
ResourceStateSet(ResourceState::IndexBuffer, ResourceState::CopyDestination);
indexBufferDesc.defaultState = ResourceState::IndexBuffer;
- indexBufferDesc.cpuAccessFlags = MemoryType::CpuWrite;
+ indexBufferDesc.memoryType = MemoryType::Upload;
auto indexBuffer = device->createBufferResource(indexBufferDesc);
auto cmdBuf = transientHeap->createCommandBuffer();
auto encoder = cmdBuf->encodeResourceCommands();
@@ -254,7 +254,7 @@ void GUI::endFrame(ITransientResourceHeap* transientHeap, IFramebuffer* framebuf
ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
constantBufferDesc.defaultState = ResourceState::ConstantBuffer;
constantBufferDesc.sizeInBytes = sizeof(glm::mat4x4);
- constantBufferDesc.cpuAccessFlags = MemoryType::CpuWrite;
+ constantBufferDesc.memoryType = MemoryType::Upload;
auto constantBuffer = device->createBufferResource(constantBufferDesc);
{
diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp
index f3e3dbccf..3f5544ccd 100644
--- a/tools/render-test/render-test-main.cpp
+++ b/tools/render-test/render-test-main.cpp
@@ -558,7 +558,7 @@ SlangResult RenderTestApp::initialize(
IBufferResource::Desc vertexBufferDesc;
vertexBufferDesc.type = IResource::Type::Buffer;
vertexBufferDesc.sizeInBytes = kVertexCount * sizeof(Vertex);
- vertexBufferDesc.cpuAccessFlags = MemoryType::CpuWrite;
+ vertexBufferDesc.memoryType = MemoryType::Upload;
vertexBufferDesc.defaultState = ResourceState::VertexBuffer;
vertexBufferDesc.allowedStates = ResourceStateSet(ResourceState::VertexBuffer);
@@ -908,7 +908,7 @@ Result RenderTestApp::writeBindingOutput(const String& fileName)
const size_t bufferSize = bufferDesc.sizeInBytes;
ComPtr<ISlangBlob> blob;
- if(bufferDesc.cpuAccessFlags & MemoryType::CpuRead)
+ if(bufferDesc.memoryType == MemoryType::ReadBack)
{
// The buffer is already allocated for CPU access, so we can read it back directly.
//
@@ -919,7 +919,7 @@ Result RenderTestApp::writeBindingOutput(const String& fileName)
// The buffer is not CPU-readable, so we will copy it using a staging buffer.
auto stagingBufferDesc = bufferDesc;
- stagingBufferDesc.cpuAccessFlags = MemoryType::CpuRead;
+ stagingBufferDesc.memoryType = MemoryType::ReadBack;
stagingBufferDesc.allowedStates =
ResourceStateSet(ResourceState::CopyDestination, ResourceState::CopySource);
stagingBufferDesc.defaultState = ResourceState::CopyDestination;