summaryrefslogtreecommitdiff
path: root/tools/gfx
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /tools/gfx
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'tools/gfx')
-rw-r--r--tools/gfx/apple/cocoa-util.h10
-rw-r--r--tools/gfx/command-encoder-com-forward.h301
-rw-r--r--tools/gfx/command-writer.h25
-rw-r--r--tools/gfx/cpu/cpu-base.h45
-rw-r--r--tools/gfx/cpu/cpu-buffer.cpp2
-rw-r--r--tools/gfx/cpu/cpu-buffer.h5
-rw-r--r--tools/gfx/cpu/cpu-device.cpp493
-rw-r--r--tools/gfx/cpu/cpu-device.h22
-rw-r--r--tools/gfx/cpu/cpu-helper-functions.cpp1
-rw-r--r--tools/gfx/cpu/cpu-helper-functions.h1
-rw-r--r--tools/gfx/cpu/cpu-pipeline-state.cpp22
-rw-r--r--tools/gfx/cpu/cpu-query.cpp4
-rw-r--r--tools/gfx/cpu/cpu-query.h4
-rw-r--r--tools/gfx/cpu/cpu-resource-views.cpp36
-rw-r--r--tools/gfx/cpu/cpu-resource-views.h28
-rw-r--r--tools/gfx/cpu/cpu-shader-object-layout.cpp64
-rw-r--r--tools/gfx/cpu/cpu-shader-object-layout.h20
-rw-r--r--tools/gfx/cpu/cpu-shader-object.cpp72
-rw-r--r--tools/gfx/cpu/cpu-shader-object.h28
-rw-r--r--tools/gfx/cpu/cpu-shader-program.h5
-rw-r--r--tools/gfx/cpu/cpu-texture.cpp48
-rw-r--r--tools/gfx/cpu/cpu-texture.h35
-rw-r--r--tools/gfx/cuda/cuda-base.h76
-rw-r--r--tools/gfx/cuda/cuda-buffer.cpp5
-rw-r--r--tools/gfx/cuda/cuda-buffer.h8
-rw-r--r--tools/gfx/cuda/cuda-command-buffer.cpp6
-rw-r--r--tools/gfx/cuda/cuda-command-buffer.h13
-rw-r--r--tools/gfx/cuda/cuda-command-encoder.cpp26
-rw-r--r--tools/gfx/cuda/cuda-command-encoder.h30
-rw-r--r--tools/gfx/cuda/cuda-command-queue.cpp29
-rw-r--r--tools/gfx/cuda/cuda-command-queue.h18
-rw-r--r--tools/gfx/cuda/cuda-device.cpp257
-rw-r--r--tools/gfx/cuda/cuda-device.h44
-rw-r--r--tools/gfx/cuda/cuda-helper-functions.cpp12
-rw-r--r--tools/gfx/cuda/cuda-helper-functions.h100
-rw-r--r--tools/gfx/cuda/cuda-query.cpp4
-rw-r--r--tools/gfx/cuda/cuda-query.h4
-rw-r--r--tools/gfx/cuda/cuda-resource-views.h1
-rw-r--r--tools/gfx/cuda/cuda-shader-object-layout.cpp51
-rw-r--r--tools/gfx/cuda/cuda-shader-object-layout.h5
-rw-r--r--tools/gfx/cuda/cuda-shader-object.cpp37
-rw-r--r--tools/gfx/cuda/cuda-shader-object.h31
-rw-r--r--tools/gfx/cuda/cuda-shader-program.h1
-rw-r--r--tools/gfx/cuda/cuda-texture.h7
-rw-r--r--tools/gfx/d3d/d3d-swapchain.h38
-rw-r--r--tools/gfx/d3d/d3d-util.cpp789
-rw-r--r--tools/gfx/d3d/d3d-util.h101
-rw-r--r--tools/gfx/d3d11/d3d11-base.h61
-rw-r--r--tools/gfx/d3d11/d3d11-buffer.cpp2
-rw-r--r--tools/gfx/d3d11/d3d11-buffer.h6
-rw-r--r--tools/gfx/d3d11/d3d11-device.cpp979
-rw-r--r--tools/gfx/d3d11/d3d11-device.h52
-rw-r--r--tools/gfx/d3d11/d3d11-helper-functions.cpp494
-rw-r--r--tools/gfx/d3d11/d3d11-helper-functions.h467
-rw-r--r--tools/gfx/d3d11/d3d11-pipeline-state.h12
-rw-r--r--tools/gfx/d3d11/d3d11-query.cpp21
-rw-r--r--tools/gfx/d3d11/d3d11-query.h23
-rw-r--r--tools/gfx/d3d11/d3d11-resource-views.h8
-rw-r--r--tools/gfx/d3d11/d3d11-scopeNVAPI.h5
-rw-r--r--tools/gfx/d3d11/d3d11-shader-object-layout.cpp60
-rw-r--r--tools/gfx/d3d11/d3d11-shader-object-layout.h107
-rw-r--r--tools/gfx/d3d11/d3d11-shader-object.cpp80
-rw-r--r--tools/gfx/d3d11/d3d11-shader-object.h115
-rw-r--r--tools/gfx/d3d11/d3d11-shader-program.cpp1
-rw-r--r--tools/gfx/d3d11/d3d11-swap-chain.cpp5
-rw-r--r--tools/gfx/d3d11/d3d11-texture.h1
-rw-r--r--tools/gfx/d3d11/d3d11-vertex-layout.h4
-rw-r--r--tools/gfx/d3d12/d3d12-base.h73
-rw-r--r--tools/gfx/d3d12/d3d12-buffer.cpp12
-rw-r--r--tools/gfx/d3d12/d3d12-buffer.h7
-rw-r--r--tools/gfx/d3d12/d3d12-command-buffer.cpp13
-rw-r--r--tools/gfx/d3d12/d3d12-command-buffer.h27
-rw-r--r--tools/gfx/d3d12/d3d12-command-encoder.cpp418
-rw-r--r--tools/gfx/d3d12/d3d12-command-encoder.h73
-rw-r--r--tools/gfx/d3d12/d3d12-command-queue.cpp19
-rw-r--r--tools/gfx/d3d12/d3d12-command-queue.h10
-rw-r--r--tools/gfx/d3d12/d3d12-descriptor-heap.cpp26
-rw-r--r--tools/gfx/d3d12/d3d12-descriptor-heap.h182
-rw-r--r--tools/gfx/d3d12/d3d12-device.cpp772
-rw-r--r--tools/gfx/d3d12/d3d12-device.h74
-rw-r--r--tools/gfx/d3d12/d3d12-fence.cpp6
-rw-r--r--tools/gfx/d3d12/d3d12-fence.h2
-rw-r--r--tools/gfx/d3d12/d3d12-helper-functions.cpp390
-rw-r--r--tools/gfx/d3d12/d3d12-helper-functions.h14
-rw-r--r--tools/gfx/d3d12/d3d12-pipeline-state-stream.h432
-rw-r--r--tools/gfx/d3d12/d3d12-pipeline-state.cpp129
-rw-r--r--tools/gfx/d3d12/d3d12-pipeline-state.h3
-rw-r--r--tools/gfx/d3d12/d3d12-posix-synchapi.cpp136
-rw-r--r--tools/gfx/d3d12/d3d12-posix-synchapi.h24
-rw-r--r--tools/gfx/d3d12/d3d12-query.cpp18
-rw-r--r--tools/gfx/d3d12/d3d12-query.h8
-rw-r--r--tools/gfx/d3d12/d3d12-resource-views.cpp177
-rw-r--r--tools/gfx/d3d12/d3d12-resource-views.h10
-rw-r--r--tools/gfx/d3d12/d3d12-resource.cpp123
-rw-r--r--tools/gfx/d3d12/d3d12-resource.h176
-rw-r--r--tools/gfx/d3d12/d3d12-sal-defs.h128
-rw-r--r--tools/gfx/d3d12/d3d12-sampler.cpp5
-rw-r--r--tools/gfx/d3d12/d3d12-shader-object-layout.cpp288
-rw-r--r--tools/gfx/d3d12/d3d12-shader-object-layout.h30
-rw-r--r--tools/gfx/d3d12/d3d12-shader-object.cpp226
-rw-r--r--tools/gfx/d3d12/d3d12-shader-object.h29
-rw-r--r--tools/gfx/d3d12/d3d12-shader-program.cpp3
-rw-r--r--tools/gfx/d3d12/d3d12-shader-program.h3
-rw-r--r--tools/gfx/d3d12/d3d12-shader-table.cpp10
-rw-r--r--tools/gfx/d3d12/d3d12-submitter.cpp22
-rw-r--r--tools/gfx/d3d12/d3d12-submitter.h25
-rw-r--r--tools/gfx/d3d12/d3d12-swap-chain.cpp16
-rw-r--r--tools/gfx/d3d12/d3d12-texture.cpp12
-rw-r--r--tools/gfx/d3d12/d3d12-texture.h2
-rw-r--r--tools/gfx/d3d12/d3d12-transient-heap.cpp10
-rw-r--r--tools/gfx/d3d12/d3d12-transient-heap.h10
-rw-r--r--tools/gfx/debug-layer/debug-base.h104
-rw-r--r--tools/gfx/debug-layer/debug-buffer.h5
-rw-r--r--tools/gfx/debug-layer/debug-command-buffer.cpp33
-rw-r--r--tools/gfx/debug-layer/debug-command-buffer.h9
-rw-r--r--tools/gfx/debug-layer/debug-command-encoder.cpp114
-rw-r--r--tools/gfx/debug-layer/debug-command-encoder.h82
-rw-r--r--tools/gfx/debug-layer/debug-command-queue.cpp22
-rw-r--r--tools/gfx/debug-layer/debug-command-queue.h11
-rw-r--r--tools/gfx/debug-layer/debug-device.cpp111
-rw-r--r--tools/gfx/debug-layer/debug-device.h56
-rw-r--r--tools/gfx/debug-layer/debug-fence.cpp5
-rw-r--r--tools/gfx/debug-layer/debug-fence.h4
-rw-r--r--tools/gfx/debug-layer/debug-framebuffer.h3
-rw-r--r--tools/gfx/debug-layer/debug-helper-functions.cpp39
-rw-r--r--tools/gfx/debug-layer/debug-helper-functions.h33
-rw-r--r--tools/gfx/debug-layer/debug-query.h3
-rw-r--r--tools/gfx/debug-layer/debug-resource-views.h5
-rw-r--r--tools/gfx/debug-layer/debug-sampler-state.h2
-rw-r--r--tools/gfx/debug-layer/debug-shader-object.cpp13
-rw-r--r--tools/gfx/debug-layer/debug-shader-object.h22
-rw-r--r--tools/gfx/debug-layer/debug-shader-program.h4
-rw-r--r--tools/gfx/debug-layer/debug-swap-chain.cpp3
-rw-r--r--tools/gfx/debug-layer/debug-swap-chain.h2
-rw-r--r--tools/gfx/debug-layer/debug-texture.cpp5
-rw-r--r--tools/gfx/debug-layer/debug-texture.h3
-rw-r--r--tools/gfx/debug-layer/debug-transient-heap.cpp6
-rw-r--r--tools/gfx/debug-layer/debug-transient-heap.h9
-rw-r--r--tools/gfx/flag-combiner.cpp3
-rw-r--r--tools/gfx/flag-combiner.h38
-rw-r--r--tools/gfx/immediate-renderer-base.cpp187
-rw-r--r--tools/gfx/immediate-renderer-base.h34
-rw-r--r--tools/gfx/metal/metal-api.cpp2
-rw-r--r--tools/gfx/metal/metal-base.h70
-rw-r--r--tools/gfx/metal/metal-buffer.cpp8
-rw-r--r--tools/gfx/metal/metal-buffer.h6
-rw-r--r--tools/gfx/metal/metal-command-buffer.cpp16
-rw-r--r--tools/gfx/metal/metal-command-buffer.h17
-rw-r--r--tools/gfx/metal/metal-command-encoder.cpp163
-rw-r--r--tools/gfx/metal/metal-command-encoder.h83
-rw-r--r--tools/gfx/metal/metal-command-queue.cpp33
-rw-r--r--tools/gfx/metal/metal-command-queue.h10
-rw-r--r--tools/gfx/metal/metal-device.cpp231
-rw-r--r--tools/gfx/metal/metal-device.h67
-rw-r--r--tools/gfx/metal/metal-fence.cpp5
-rw-r--r--tools/gfx/metal/metal-fence.h7
-rw-r--r--tools/gfx/metal/metal-framebuffer.cpp12
-rw-r--r--tools/gfx/metal/metal-helper-functions.cpp1
-rw-r--r--tools/gfx/metal/metal-pipeline-state.cpp134
-rw-r--r--tools/gfx/metal/metal-query.cpp15
-rw-r--r--tools/gfx/metal/metal-query.h3
-rw-r--r--tools/gfx/metal/metal-render-pass.cpp44
-rw-r--r--tools/gfx/metal/metal-render-pass.h4
-rw-r--r--tools/gfx/metal/metal-resource-views.cpp17
-rw-r--r--tools/gfx/metal/metal-resource-views.h12
-rw-r--r--tools/gfx/metal/metal-sampler.cpp10
-rw-r--r--tools/gfx/metal/metal-sampler.h2
-rw-r--r--tools/gfx/metal/metal-shader-object-layout.cpp58
-rw-r--r--tools/gfx/metal/metal-shader-object-layout.h30
-rw-r--r--tools/gfx/metal/metal-shader-object.cpp196
-rw-r--r--tools/gfx/metal/metal-shader-object.h55
-rw-r--r--tools/gfx/metal/metal-shader-program.cpp17
-rw-r--r--tools/gfx/metal/metal-shader-program.h4
-rw-r--r--tools/gfx/metal/metal-swap-chain.cpp18
-rw-r--r--tools/gfx/metal/metal-swap-chain.h6
-rw-r--r--tools/gfx/metal/metal-texture.cpp9
-rw-r--r--tools/gfx/metal/metal-texture.h3
-rw-r--r--tools/gfx/metal/metal-transient-heap.cpp4
-rw-r--r--tools/gfx/metal/metal-transient-heap.h2
-rw-r--r--tools/gfx/metal/metal-util.cpp541
-rw-r--r--tools/gfx/metal/metal-util.h23
-rw-r--r--tools/gfx/metal/metal-vertex-layout.cpp18
-rw-r--r--tools/gfx/metal/metal-vertex-layout.h3
-rw-r--r--tools/gfx/mutable-shader-object.h668
-rw-r--r--tools/gfx/nvapi/nvapi-include.h27
-rw-r--r--tools/gfx/nvapi/nvapi-util.cpp9
-rw-r--r--tools/gfx/nvapi/nvapi-util.h11
-rw-r--r--tools/gfx/open-gl/render-gl.cpp868
-rw-r--r--tools/gfx/open-gl/render-gl.h5
-rw-r--r--tools/gfx/render.cpp172
-rw-r--r--tools/gfx/renderer-shared.cpp372
-rw-r--r--tools/gfx/renderer-shared.h402
-rw-r--r--tools/gfx/resource-desc-utils.cpp26
-rw-r--r--tools/gfx/resource-desc-utils.h22
-rw-r--r--tools/gfx/simple-render-pass-layout.h10
-rw-r--r--tools/gfx/simple-transient-resource-heap.h7
-rw-r--r--tools/gfx/slang-context.h108
-rw-r--r--tools/gfx/transient-resource-heap-base.h21
-rw-r--r--tools/gfx/vulkan/vk-api.cpp30
-rw-r--r--tools/gfx/vulkan/vk-api.h95
-rw-r--r--tools/gfx/vulkan/vk-base.h70
-rw-r--r--tools/gfx/vulkan/vk-buffer.cpp24
-rw-r--r--tools/gfx/vulkan/vk-buffer.h7
-rw-r--r--tools/gfx/vulkan/vk-command-buffer.cpp13
-rw-r--r--tools/gfx/vulkan/vk-command-buffer.h10
-rw-r--r--tools/gfx/vulkan/vk-command-encoder.cpp242
-rw-r--r--tools/gfx/vulkan/vk-command-encoder.h89
-rw-r--r--tools/gfx/vulkan/vk-command-queue.cpp26
-rw-r--r--tools/gfx/vulkan/vk-command-queue.h8
-rw-r--r--tools/gfx/vulkan/vk-descriptor-allocator.cpp11
-rw-r--r--tools/gfx/vulkan/vk-descriptor-allocator.h2
-rw-r--r--tools/gfx/vulkan/vk-device-queue.cpp19
-rw-r--r--tools/gfx/vulkan/vk-device-queue.h50
-rw-r--r--tools/gfx/vulkan/vk-device.cpp698
-rw-r--r--tools/gfx/vulkan/vk-device.h64
-rw-r--r--tools/gfx/vulkan/vk-fence.cpp32
-rw-r--r--tools/gfx/vulkan/vk-fence.h2
-rw-r--r--tools/gfx/vulkan/vk-framebuffer.cpp17
-rw-r--r--tools/gfx/vulkan/vk-helper-functions.cpp264
-rw-r--r--tools/gfx/vulkan/vk-helper-functions.h37
-rw-r--r--tools/gfx/vulkan/vk-module.cpp13
-rw-r--r--tools/gfx/vulkan/vk-module.h40
-rw-r--r--tools/gfx/vulkan/vk-pipeline-dump-layer.cpp280
-rw-r--r--tools/gfx/vulkan/vk-pipeline-dump-layer.h8
-rw-r--r--tools/gfx/vulkan/vk-pipeline-state.cpp89
-rw-r--r--tools/gfx/vulkan/vk-pipeline-state.h3
-rw-r--r--tools/gfx/vulkan/vk-query.cpp17
-rw-r--r--tools/gfx/vulkan/vk-query.h7
-rw-r--r--tools/gfx/vulkan/vk-render-pass.cpp10
-rw-r--r--tools/gfx/vulkan/vk-render-pass.h4
-rw-r--r--tools/gfx/vulkan/vk-resource-views.cpp10
-rw-r--r--tools/gfx/vulkan/vk-resource-views.h9
-rw-r--r--tools/gfx/vulkan/vk-sampler.cpp3
-rw-r--r--tools/gfx/vulkan/vk-shader-object-layout.cpp104
-rw-r--r--tools/gfx/vulkan/vk-shader-object-layout.h12
-rw-r--r--tools/gfx/vulkan/vk-shader-object.cpp72
-rw-r--r--tools/gfx/vulkan/vk-shader-object.h30
-rw-r--r--tools/gfx/vulkan/vk-shader-program.cpp13
-rw-r--r--tools/gfx/vulkan/vk-shader-program.h3
-rw-r--r--tools/gfx/vulkan/vk-shader-table.cpp16
-rw-r--r--tools/gfx/vulkan/vk-swap-chain.cpp61
-rw-r--r--tools/gfx/vulkan/vk-swap-chain.h6
-rw-r--r--tools/gfx/vulkan/vk-texture.cpp6
-rw-r--r--tools/gfx/vulkan/vk-texture.h2
-rw-r--r--tools/gfx/vulkan/vk-transient-heap.cpp16
-rw-r--r--tools/gfx/vulkan/vk-transient-heap.h2
-rw-r--r--tools/gfx/vulkan/vk-util.cpp624
-rw-r--r--tools/gfx/vulkan/vk-util.h76
248 files changed, 10057 insertions, 8586 deletions
diff --git a/tools/gfx/apple/cocoa-util.h b/tools/gfx/apple/cocoa-util.h
index e9d29b87c..427cf1570 100644
--- a/tools/gfx/apple/cocoa-util.h
+++ b/tools/gfx/apple/cocoa-util.h
@@ -1,15 +1,17 @@
#pragma once
-namespace gfx {
+namespace gfx
+{
// Utility functions for Cocoa
-struct CocoaUtil {
+struct CocoaUtil
+{
static void getNSWindowContentSize(void* nswindow, int* widthOut, int* heightOut);
static void* createMetalLayer(void* nswindow);
static void destroyMetalLayer(void* metalLayer);
- static void* nextDrawable(void* metalLayer) ;
+ static void* nextDrawable(void* metalLayer);
};
-}
+} // namespace gfx
diff --git a/tools/gfx/command-encoder-com-forward.h b/tools/gfx/command-encoder-com-forward.h
index 9a26b0590..43f87c931 100644
--- a/tools/gfx/command-encoder-com-forward.h
+++ b/tools/gfx/command-encoder-com-forward.h
@@ -1,142 +1,165 @@
#pragma once
-#define SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderBase) \
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface( \
- SlangUUID const& uuid, void** outObject) override \
- { \
- return ResourceCommandEncoderBase::queryInterface(uuid, outObject); \
- } \
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override \
- { \
- return ResourceCommandEncoderBase::addRef(); \
- } \
- virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override \
- { \
- return ResourceCommandEncoderBase::release(); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer( \
- IBufferResource* dst, Offset dstOffset, IBufferResource* src, Offset srcOffset, Size size) \
- override \
- { \
- ResourceCommandEncoderBase::copyBuffer(dst, dstOffset, src, srcOffset, size); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL copyTexture( \
- ITextureResource* dst, \
- ResourceState dstState, \
- SubresourceRange dstSubresource, \
- ITextureResource::Offset3D dstOffset, \
- ITextureResource* src, \
- ResourceState srcState, \
- SubresourceRange srcSubresource, \
- ITextureResource::Offset3D srcOffset, \
- ITextureResource::Extents extent) override \
- { \
- ResourceCommandEncoderBase::copyTexture( \
- dst, \
- dstState, \
- dstSubresource, \
- dstOffset, \
- src, \
- srcState, \
- srcSubresource, \
- srcOffset, \
- extent); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL copyTextureToBuffer( \
- IBufferResource* dst, \
- Offset dstOffset, \
- Size dstSize, \
- Size dstRowStride, \
- ITextureResource* src, \
- ResourceState srcState, \
- SubresourceRange srcSubresource, \
- ITextureResource::Offset3D srcOffset, \
- ITextureResource::Extents extent) override \
- { \
- ResourceCommandEncoderBase::copyTextureToBuffer( \
- dst, \
- dstOffset, \
- dstSize, \
- dstRowStride, \
- src, \
- srcState, \
- srcSubresource, \
- srcOffset, \
- extent); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL uploadTextureData( \
- ITextureResource* dst, \
- SubresourceRange subResourceRange, \
- ITextureResource::Offset3D offset, \
- ITextureResource::Extents extent, \
- ITextureResource::SubresourceData* subResourceData, \
- GfxCount subResourceDataCount) override \
- { \
- ResourceCommandEncoderBase::uploadTextureData( \
- dst, subResourceRange, offset, extent, subResourceData, subResourceDataCount); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL uploadBufferData( \
- IBufferResource* dst, Offset offset, Size size, void* data) override \
- { \
- ResourceCommandEncoderBase::uploadBufferData(dst, offset, size, data); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL textureBarrier( \
- GfxCount count, ITextureResource* const* textures, ResourceState src, ResourceState dst) \
- override \
- { \
- ResourceCommandEncoderBase::textureBarrier(count, textures, src, dst); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL textureSubresourceBarrier( \
- ITextureResource* texture, \
- SubresourceRange subresourceRange, \
- ResourceState src, \
- ResourceState dst) override \
- { \
- ResourceCommandEncoderBase::textureSubresourceBarrier( \
- texture, subresourceRange, src, dst); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL bufferBarrier( \
- GfxCount count, IBufferResource* const* buffers, ResourceState src, ResourceState dst) \
- override \
- { \
- ResourceCommandEncoderBase::bufferBarrier(count, buffers, src, dst); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL clearResourceView( \
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags) override \
- { \
- ResourceCommandEncoderBase::clearResourceView(view, clearValue, flags); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL resolveResource( \
- ITextureResource* source, \
- ResourceState sourceState, \
- SubresourceRange sourceRange, \
- ITextureResource* dest, \
- ResourceState destState, \
- SubresourceRange destRange) override \
- { \
- ResourceCommandEncoderBase::resolveResource( \
- source, sourceState, sourceRange, dest, destState, destRange); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL resolveQuery( \
- IQueryPool* queryPool, \
- GfxIndex index, \
- GfxCount count, \
- IBufferResource* buffer, \
- Offset offset) override \
- { \
- ResourceCommandEncoderBase::resolveQuery(queryPool, index, count, buffer, offset); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL writeTimestamp(IQueryPool* pool, GfxIndex index) \
- override \
- { \
- ResourceCommandEncoderBase::writeTimestamp(pool, index); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL beginDebugEvent(const char* name, float rgbColor[3]) \
- override \
- { \
- ResourceCommandEncoderBase::beginDebugEvent(name, rgbColor); \
- } \
- virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override \
- { \
- ResourceCommandEncoderBase::endDebugEvent(); \
+#define SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderBase) \
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface( \
+ SlangUUID const& uuid, \
+ void** outObject) override \
+ { \
+ return ResourceCommandEncoderBase::queryInterface(uuid, outObject); \
+ } \
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override \
+ { \
+ return ResourceCommandEncoderBase::addRef(); \
+ } \
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override \
+ { \
+ return ResourceCommandEncoderBase::release(); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer( \
+ IBufferResource* dst, \
+ Offset dstOffset, \
+ IBufferResource* src, \
+ Offset srcOffset, \
+ Size size) override \
+ { \
+ ResourceCommandEncoderBase::copyBuffer(dst, dstOffset, src, srcOffset, size); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL copyTexture( \
+ ITextureResource* dst, \
+ ResourceState dstState, \
+ SubresourceRange dstSubresource, \
+ ITextureResource::Offset3D dstOffset, \
+ ITextureResource* src, \
+ ResourceState srcState, \
+ SubresourceRange srcSubresource, \
+ ITextureResource::Offset3D srcOffset, \
+ ITextureResource::Extents extent) override \
+ { \
+ ResourceCommandEncoderBase::copyTexture( \
+ dst, \
+ dstState, \
+ dstSubresource, \
+ dstOffset, \
+ src, \
+ srcState, \
+ srcSubresource, \
+ srcOffset, \
+ extent); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL copyTextureToBuffer( \
+ IBufferResource* dst, \
+ Offset dstOffset, \
+ Size dstSize, \
+ Size dstRowStride, \
+ ITextureResource* src, \
+ ResourceState srcState, \
+ SubresourceRange srcSubresource, \
+ ITextureResource::Offset3D srcOffset, \
+ ITextureResource::Extents extent) override \
+ { \
+ ResourceCommandEncoderBase::copyTextureToBuffer( \
+ dst, \
+ dstOffset, \
+ dstSize, \
+ dstRowStride, \
+ src, \
+ srcState, \
+ srcSubresource, \
+ srcOffset, \
+ extent); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL uploadTextureData( \
+ ITextureResource* dst, \
+ SubresourceRange subResourceRange, \
+ ITextureResource::Offset3D offset, \
+ ITextureResource::Extents extent, \
+ ITextureResource::SubresourceData* subResourceData, \
+ GfxCount subResourceDataCount) override \
+ { \
+ ResourceCommandEncoderBase::uploadTextureData( \
+ dst, \
+ subResourceRange, \
+ offset, \
+ extent, \
+ subResourceData, \
+ subResourceDataCount); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL \
+ uploadBufferData(IBufferResource* dst, Offset offset, Size size, void* data) override \
+ { \
+ ResourceCommandEncoderBase::uploadBufferData(dst, offset, size, data); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL textureBarrier( \
+ GfxCount count, \
+ ITextureResource* const* textures, \
+ ResourceState src, \
+ ResourceState dst) override \
+ { \
+ ResourceCommandEncoderBase::textureBarrier(count, textures, src, dst); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL textureSubresourceBarrier( \
+ ITextureResource* texture, \
+ SubresourceRange subresourceRange, \
+ ResourceState src, \
+ ResourceState dst) override \
+ { \
+ ResourceCommandEncoderBase::textureSubresourceBarrier( \
+ texture, \
+ subresourceRange, \
+ src, \
+ dst); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL bufferBarrier( \
+ GfxCount count, \
+ IBufferResource* const* buffers, \
+ ResourceState src, \
+ ResourceState dst) override \
+ { \
+ ResourceCommandEncoderBase::bufferBarrier(count, buffers, src, dst); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL clearResourceView( \
+ IResourceView* view, \
+ ClearValue* clearValue, \
+ ClearResourceViewFlags::Enum flags) override \
+ { \
+ ResourceCommandEncoderBase::clearResourceView(view, clearValue, flags); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL resolveResource( \
+ ITextureResource* source, \
+ ResourceState sourceState, \
+ SubresourceRange sourceRange, \
+ ITextureResource* dest, \
+ ResourceState destState, \
+ SubresourceRange destRange) override \
+ { \
+ ResourceCommandEncoderBase::resolveResource( \
+ source, \
+ sourceState, \
+ sourceRange, \
+ dest, \
+ destState, \
+ destRange); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL resolveQuery( \
+ IQueryPool* queryPool, \
+ GfxIndex index, \
+ GfxCount count, \
+ IBufferResource* buffer, \
+ Offset offset) override \
+ { \
+ ResourceCommandEncoderBase::resolveQuery(queryPool, index, count, buffer, offset); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL writeTimestamp(IQueryPool* pool, GfxIndex index) \
+ override \
+ { \
+ ResourceCommandEncoderBase::writeTimestamp(pool, index); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL beginDebugEvent(const char* name, float rgbColor[3]) \
+ override \
+ { \
+ ResourceCommandEncoderBase::beginDebugEvent(name, rgbColor); \
+ } \
+ virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override \
+ { \
+ ResourceCommandEncoderBase::endDebugEvent(); \
}
diff --git a/tools/gfx/command-writer.h b/tools/gfx/command-writer.h
index 03ac3ac6d..febdcfef3 100644
--- a/tools/gfx/command-writer.h
+++ b/tools/gfx/command-writer.h
@@ -1,9 +1,9 @@
#pragma once
-#include "slang-gfx.h"
-#include "slang-com-ptr.h"
#include "core/slang-basic.h"
#include "renderer-shared.h"
+#include "slang-com-ptr.h"
+#include "slang-gfx.h"
namespace gfx
{
@@ -115,12 +115,14 @@ public:
return offset;
}
- template <typename T> T* getObject(uint32_t offset)
+ template<typename T>
+ T* getObject(uint32_t offset)
{
return static_cast<T*>(m_objects[offset].Ptr());
}
- template <typename T> T* getData(Offset offset)
+ template<typename T>
+ T* getData(Offset offset)
{
return reinterpret_cast<T*>(m_data.getBuffer() + offset);
}
@@ -176,7 +178,10 @@ public:
void clearFrame(uint32_t colorBufferMask, bool clearDepth, bool clearStencil)
{
m_commands.add(Command(
- CommandName::ClearFrame, colorBufferMask, clearDepth ? 1 : 0, clearStencil ? 1 : 0));
+ CommandName::ClearFrame,
+ colorBufferMask,
+ clearDepth ? 1 : 0,
+ clearStencil ? 1 : 0));
}
void setViewports(GfxCount count, const Viewport* viewports)
@@ -222,7 +227,10 @@ public:
{
auto bufferOffset = encodeObject(static_cast<BufferResource*>(buffer));
m_commands.add(Command(
- CommandName::SetIndexBuffer, (uint32_t)bufferOffset, (uint32_t)indexFormat, (uint32_t)offset));
+ CommandName::SetIndexBuffer,
+ (uint32_t)bufferOffset,
+ (uint32_t)indexFormat,
+ (uint32_t)offset));
}
void draw(GfxCount vertexCount, GfxIndex startVertex)
@@ -283,9 +291,8 @@ public:
void writeTimestamp(IQueryPool* pool, GfxIndex index)
{
auto poolOffset = encodeObject(static_cast<QueryPoolBase*>(pool));
- m_commands.add(
- Command(CommandName::WriteTimestamp, (uint32_t)poolOffset, (uint32_t)index));
+ m_commands.add(Command(CommandName::WriteTimestamp, (uint32_t)poolOffset, (uint32_t)index));
m_hasWriteTimestamps = true;
}
};
-}
+} // namespace gfx
diff --git a/tools/gfx/cpu/cpu-base.h b/tools/gfx/cpu/cpu-base.h
index 6f30662ec..5c9cca5d9 100644
--- a/tools/gfx/cpu/cpu-base.h
+++ b/tools/gfx/cpu/cpu-base.h
@@ -2,15 +2,14 @@
// Shared header file for CPU implementation
#pragma once
-#include "slang.h"
-#include "slang-com-ptr.h"
-#include "slang-com-helper.h"
-#include "core/slang-basic.h"
-#include "core/slang-blob.h"
-
#include "../immediate-renderer-base.h"
-#include "../slang-context.h"
#include "../mutable-shader-object.h"
+#include "../slang-context.h"
+#include "core/slang-basic.h"
+#include "core/slang-blob.h"
+#include "slang-com-helper.h"
+#include "slang-com-ptr.h"
+#include "slang.h"
#define SLANG_PRELUDE_NAMESPACE slang_prelude
#include "prelude/slang-cpp-types.h"
@@ -20,21 +19,21 @@ using namespace Slang;
namespace cpu
{
- class BufferResourceImpl;
- class TextureResourceImpl;
- class ResourceViewImpl;
- class BufferResourceViewImpl;
- class TextureResourceViewImpl;
- class ShaderObjectLayoutImpl;
- class EntryPointLayoutImpl;
- class RootShaderObjectLayoutImpl;
- class ShaderObjectImpl;
- class MutableShaderObjectImpl;
- class EntryPointShaderObjectImpl;
- class RootShaderObjectImpl;
- class ShaderProgramImpl;
- class PipelineStateImpl;
- class QueryPoolImpl;
- class DeviceImpl;
+class BufferResourceImpl;
+class TextureResourceImpl;
+class ResourceViewImpl;
+class BufferResourceViewImpl;
+class TextureResourceViewImpl;
+class ShaderObjectLayoutImpl;
+class EntryPointLayoutImpl;
+class RootShaderObjectLayoutImpl;
+class ShaderObjectImpl;
+class MutableShaderObjectImpl;
+class EntryPointShaderObjectImpl;
+class RootShaderObjectImpl;
+class ShaderProgramImpl;
+class PipelineStateImpl;
+class QueryPoolImpl;
+class DeviceImpl;
} // namespace cpu
} // namespace gfx
diff --git a/tools/gfx/cpu/cpu-buffer.cpp b/tools/gfx/cpu/cpu-buffer.cpp
index 2c9c3077d..a1184fd95 100644
--- a/tools/gfx/cpu/cpu-buffer.cpp
+++ b/tools/gfx/cpu/cpu-buffer.cpp
@@ -36,7 +36,7 @@ SLANG_NO_THROW DeviceAddress SLANG_MCALL BufferResourceImpl::getDeviceAddress()
}
SLANG_NO_THROW Result SLANG_MCALL
- BufferResourceImpl::map(MemoryRange* rangeToRead, void** outPointer)
+BufferResourceImpl::map(MemoryRange* rangeToRead, void** outPointer)
{
SLANG_UNUSED(rangeToRead);
if (outPointer)
diff --git a/tools/gfx/cpu/cpu-buffer.h b/tools/gfx/cpu/cpu-buffer.h
index 6273b18b9..9b1866c74 100644
--- a/tools/gfx/cpu/cpu-buffer.h
+++ b/tools/gfx/cpu/cpu-buffer.h
@@ -14,7 +14,8 @@ class BufferResourceImpl : public BufferResource
public:
BufferResourceImpl(const Desc& _desc)
: BufferResource(_desc)
- {}
+ {
+ }
~BufferResourceImpl();
@@ -27,7 +28,7 @@ public:
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- map(MemoryRange* rangeToRead, void** outPointer) override;
+ map(MemoryRange* rangeToRead, void** outPointer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override;
};
diff --git a/tools/gfx/cpu/cpu-device.cpp b/tools/gfx/cpu/cpu-device.cpp
index bd747d998..6f7ff0f16 100644
--- a/tools/gfx/cpu/cpu-device.cpp
+++ b/tools/gfx/cpu/cpu-device.cpp
@@ -1,8 +1,6 @@
// cpu-device.cpp
#include "cpu-device.h"
-#include <chrono>
-
#include "cpu-buffer.h"
#include "cpu-pipeline-state.h"
#include "cpu-query.h"
@@ -11,293 +9,300 @@
#include "cpu-shader-program.h"
#include "cpu-texture.h"
+#include <chrono>
+
namespace gfx
{
using namespace Slang;
namespace cpu
{
- DeviceImpl::~DeviceImpl()
+DeviceImpl::~DeviceImpl()
+{
+ m_currentPipeline = nullptr;
+ m_currentRootObject = nullptr;
+}
+
+SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::initialize(const Desc& desc)
+{
+ SLANG_RETURN_ON_FAIL(slangContext.initialize(
+ desc.slang,
+ desc.extendedDescCount,
+ desc.extendedDescs,
+ SLANG_SHADER_HOST_CALLABLE,
+ "sm_5_1",
+ makeArray(slang::PreprocessorMacroDesc{"__CPU__", "1"}).getView()));
+
+ SLANG_RETURN_ON_FAIL(RendererBase::initialize(desc));
+
+ // Initialize DeviceInfo
{
- m_currentPipeline = nullptr;
- m_currentRootObject = nullptr;
+ m_info.deviceType = DeviceType::CPU;
+ m_info.bindingStyle = BindingStyle::CUDA;
+ m_info.projectionStyle = ProjectionStyle::DirectX;
+ m_info.apiName = "CPU";
+ static const float kIdentity[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
+ ::memcpy(m_info.identityProjectionMatrix, kIdentity, sizeof(kIdentity));
+ m_info.adapterName = "CPU";
+ m_info.timestampFrequency = 1000000000;
}
- SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::initialize(const Desc& desc)
+ // Can support pointers (or something akin to that)
{
- SLANG_RETURN_ON_FAIL(slangContext.initialize(
- desc.slang,
- desc.extendedDescCount,
- desc.extendedDescs,
- SLANG_SHADER_HOST_CALLABLE,
- "sm_5_1",
- makeArray(slang::PreprocessorMacroDesc{ "__CPU__", "1" }).getView()));
-
- SLANG_RETURN_ON_FAIL(RendererBase::initialize(desc));
-
- // Initialize DeviceInfo
- {
- m_info.deviceType = DeviceType::CPU;
- m_info.bindingStyle = BindingStyle::CUDA;
- m_info.projectionStyle = ProjectionStyle::DirectX;
- m_info.apiName = "CPU";
- static const float kIdentity[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
- ::memcpy(m_info.identityProjectionMatrix, kIdentity, sizeof(kIdentity));
- m_info.adapterName = "CPU";
- m_info.timestampFrequency = 1000000000;
- }
-
- // Can support pointers (or something akin to that)
- {
- m_features.add("has-ptr");
- }
-
- return SLANG_OK;
+ m_features.add("has-ptr");
}
- SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureResource(
- const ITextureResource::Desc& desc,
- const ITextureResource::SubresourceData* initData,
- ITextureResource** outResource)
- {
- TextureResource::Desc srcDesc = fixupTextureDesc(desc);
+ return SLANG_OK;
+}
- RefPtr<TextureResourceImpl> texture = new TextureResourceImpl(srcDesc);
+SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureResource(
+ const ITextureResource::Desc& desc,
+ const ITextureResource::SubresourceData* initData,
+ ITextureResource** outResource)
+{
+ TextureResource::Desc srcDesc = fixupTextureDesc(desc);
- SLANG_RETURN_ON_FAIL(texture->init(initData));
+ RefPtr<TextureResourceImpl> texture = new TextureResourceImpl(srcDesc);
- returnComPtr(outResource, texture);
- return SLANG_OK;
- }
+ SLANG_RETURN_ON_FAIL(texture->init(initData));
- SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createBufferResource(
- const IBufferResource::Desc& descIn,
- const void* initData,
- IBufferResource** outResource)
- {
- auto desc = fixupBufferDesc(descIn);
- RefPtr<BufferResourceImpl> resource = new BufferResourceImpl(desc);
- SLANG_RETURN_ON_FAIL(resource->init());
- if (initData)
- {
- SLANG_RETURN_ON_FAIL(resource->setData(0, desc.sizeInBytes, initData));
- }
- returnComPtr(outResource, resource);
- return SLANG_OK;
- }
+ returnComPtr(outResource, texture);
+ return SLANG_OK;
+}
- SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureView(
- ITextureResource* inTexture, IResourceView::Desc const& desc, IResourceView** outView)
+SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createBufferResource(
+ const IBufferResource::Desc& descIn,
+ const void* initData,
+ IBufferResource** outResource)
+{
+ auto desc = fixupBufferDesc(descIn);
+ RefPtr<BufferResourceImpl> resource = new BufferResourceImpl(desc);
+ SLANG_RETURN_ON_FAIL(resource->init());
+ if (initData)
{
- auto texture = static_cast<TextureResourceImpl*>(inTexture);
- RefPtr<TextureResourceViewImpl> view = new TextureResourceViewImpl(desc, texture);
- returnComPtr(outView, view);
- return SLANG_OK;
+ SLANG_RETURN_ON_FAIL(resource->setData(0, desc.sizeInBytes, initData));
}
+ returnComPtr(outResource, resource);
+ return SLANG_OK;
+}
- SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createBufferView(
- IBufferResource* inBuffer,
- IBufferResource* counterBuffer,
- IResourceView::Desc const& desc,
- IResourceView** outView)
- {
- auto buffer = static_cast<BufferResourceImpl*>(inBuffer);
- RefPtr<BufferResourceViewImpl> view = new BufferResourceViewImpl(desc, buffer);
- returnComPtr(outView, view);
- return SLANG_OK;
- }
+SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureView(
+ ITextureResource* inTexture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView)
+{
+ auto texture = static_cast<TextureResourceImpl*>(inTexture);
+ RefPtr<TextureResourceViewImpl> view = new TextureResourceViewImpl(desc, texture);
+ returnComPtr(outView, view);
+ return SLANG_OK;
+}
- Result DeviceImpl::createShaderObjectLayout(
- slang::ISession* session,
- slang::TypeLayoutReflection* typeLayout,
- ShaderObjectLayoutBase** outLayout)
- {
- RefPtr<ShaderObjectLayoutImpl> cpuLayout = new ShaderObjectLayoutImpl(this, session, typeLayout);
- returnRefPtrMove(outLayout, cpuLayout);
+SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createBufferView(
+ IBufferResource* inBuffer,
+ IBufferResource* counterBuffer,
+ IResourceView::Desc const& desc,
+ IResourceView** outView)
+{
+ auto buffer = static_cast<BufferResourceImpl*>(inBuffer);
+ RefPtr<BufferResourceViewImpl> view = new BufferResourceViewImpl(desc, buffer);
+ returnComPtr(outView, view);
+ return SLANG_OK;
+}
- return SLANG_OK;
- }
+Result DeviceImpl::createShaderObjectLayout(
+ slang::ISession* session,
+ slang::TypeLayoutReflection* typeLayout,
+ ShaderObjectLayoutBase** outLayout)
+{
+ RefPtr<ShaderObjectLayoutImpl> cpuLayout =
+ new ShaderObjectLayoutImpl(this, session, typeLayout);
+ returnRefPtrMove(outLayout, cpuLayout);
- Result DeviceImpl::createShaderObject(
- ShaderObjectLayoutBase* layout,
- IShaderObject** outObject)
- {
- auto cpuLayout = static_cast<ShaderObjectLayoutImpl*>(layout);
+ return SLANG_OK;
+}
- RefPtr<ShaderObjectImpl> result = new ShaderObjectImpl();
- SLANG_RETURN_ON_FAIL(result->init(this, cpuLayout));
- returnComPtr(outObject, result);
+Result DeviceImpl::createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+{
+ auto cpuLayout = static_cast<ShaderObjectLayoutImpl*>(layout);
- return SLANG_OK;
- }
+ RefPtr<ShaderObjectImpl> result = new ShaderObjectImpl();
+ SLANG_RETURN_ON_FAIL(result->init(this, cpuLayout));
+ returnComPtr(outObject, result);
- Result DeviceImpl::createMutableShaderObject(
- ShaderObjectLayoutBase* layout,
- IShaderObject** outObject)
- {
- auto cpuLayout = static_cast<ShaderObjectLayoutImpl*>(layout);
+ return SLANG_OK;
+}
- RefPtr<MutableShaderObjectImpl> result = new MutableShaderObjectImpl();
- SLANG_RETURN_ON_FAIL(result->init(this, cpuLayout));
- returnComPtr(outObject, result);
+Result DeviceImpl::createMutableShaderObject(
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject)
+{
+ auto cpuLayout = static_cast<ShaderObjectLayoutImpl*>(layout);
- return SLANG_OK;
- }
+ RefPtr<MutableShaderObjectImpl> result = new MutableShaderObjectImpl();
+ SLANG_RETURN_ON_FAIL(result->init(this, cpuLayout));
+ returnComPtr(outObject, result);
- Result DeviceImpl::createRootShaderObject(IShaderProgram* program, ShaderObjectBase** outObject)
- {
- auto cpuProgram = static_cast<ShaderProgramImpl*>(program);
- auto cpuProgramLayout = cpuProgram->layout;
+ return SLANG_OK;
+}
- RefPtr<RootShaderObjectImpl> result = new RootShaderObjectImpl();
- SLANG_RETURN_ON_FAIL(result->init(this, cpuProgramLayout));
- returnRefPtrMove(outObject, result);
- return SLANG_OK;
- }
+Result DeviceImpl::createRootShaderObject(IShaderProgram* program, ShaderObjectBase** outObject)
+{
+ auto cpuProgram = static_cast<ShaderProgramImpl*>(program);
+ auto cpuProgramLayout = cpuProgram->layout;
- SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createProgram(
- const IShaderProgram::Desc& desc,
- IShaderProgram** outProgram,
- ISlangBlob** outDiagnosticBlob)
- {
- RefPtr<ShaderProgramImpl> cpuProgram = new ShaderProgramImpl();
- cpuProgram->init(desc);
- auto slangGlobalScope = cpuProgram->linkedProgram;
- if (slangGlobalScope)
- {
- auto slangProgramLayout = slangGlobalScope->getLayout();
- if (!slangProgramLayout)
- return SLANG_FAIL;
-
- RefPtr<RootShaderObjectLayoutImpl> cpuProgramLayout = new RootShaderObjectLayoutImpl(this, slangGlobalScope->getSession(), slangProgramLayout);
- cpuProgramLayout->m_programLayout = slangProgramLayout;
-
- cpuProgram->layout = cpuProgramLayout;
- }
-
- returnComPtr(outProgram, cpuProgram);
- return SLANG_OK;
- }
+ RefPtr<RootShaderObjectImpl> result = new RootShaderObjectImpl();
+ SLANG_RETURN_ON_FAIL(result->init(this, cpuProgramLayout));
+ returnRefPtrMove(outObject, result);
+ return SLANG_OK;
+}
- SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState)
+SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createProgram(
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnosticBlob)
+{
+ RefPtr<ShaderProgramImpl> cpuProgram = new ShaderProgramImpl();
+ cpuProgram->init(desc);
+ auto slangGlobalScope = cpuProgram->linkedProgram;
+ if (slangGlobalScope)
{
- RefPtr<PipelineStateImpl> state = new PipelineStateImpl();
- state->init(desc);
- returnComPtr(outState, state);
- return Result();
- }
+ auto slangProgramLayout = slangGlobalScope->getLayout();
+ if (!slangProgramLayout)
+ return SLANG_FAIL;
- SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createQueryPool(
- const IQueryPool::Desc& desc, IQueryPool** outPool)
- {
- RefPtr<QueryPoolImpl> pool = new QueryPoolImpl();
- pool->init(desc);
- returnComPtr(outPool, pool);
- return SLANG_OK;
- }
+ RefPtr<RootShaderObjectLayoutImpl> cpuProgramLayout = new RootShaderObjectLayoutImpl(
+ this,
+ slangGlobalScope->getSession(),
+ slangProgramLayout);
+ cpuProgramLayout->m_programLayout = slangProgramLayout;
- void DeviceImpl::writeTimestamp(IQueryPool* pool, GfxIndex index)
- {
- static_cast<QueryPoolImpl*>(pool)->m_queries[index] =
- std::chrono::high_resolution_clock::now().time_since_epoch().count();
+ cpuProgram->layout = cpuProgramLayout;
}
- SLANG_NO_THROW const DeviceInfo& SLANG_MCALL DeviceImpl::getDeviceInfo() const
- {
- return m_info;
- }
+ returnComPtr(outProgram, cpuProgram);
+ return SLANG_OK;
+}
- SLANG_NO_THROW Result SLANG_MCALL
- DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler)
- {
- SLANG_UNUSED(desc);
- *outSampler = nullptr;
- return SLANG_OK;
- }
+SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createComputePipelineState(
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState)
+{
+ RefPtr<PipelineStateImpl> state = new PipelineStateImpl();
+ state->init(desc);
+ returnComPtr(outState, state);
+ return Result();
+}
- void* DeviceImpl::map(IBufferResource* buffer, MapFlavor flavor)
- {
- SLANG_UNUSED(flavor);
- auto bufferImpl = static_cast<BufferResourceImpl*>(buffer);
- return bufferImpl->m_data;
- }
- void DeviceImpl::unmap(IBufferResource* buffer, size_t offsetWritten, size_t sizeWritten)
- {
- SLANG_UNUSED(buffer);
- SLANG_UNUSED(offsetWritten);
- SLANG_UNUSED(sizeWritten);
- }
+SLANG_NO_THROW Result SLANG_MCALL
+DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool)
+{
+ RefPtr<QueryPoolImpl> pool = new QueryPoolImpl();
+ pool->init(desc);
+ returnComPtr(outPool, pool);
+ return SLANG_OK;
+}
- void DeviceImpl::setPipelineState(IPipelineState* state)
- {
- m_currentPipeline = static_cast<PipelineStateImpl*>(state);
- }
+void DeviceImpl::writeTimestamp(IQueryPool* pool, GfxIndex index)
+{
+ static_cast<QueryPoolImpl*>(pool)->m_queries[index] =
+ std::chrono::high_resolution_clock::now().time_since_epoch().count();
+}
- void DeviceImpl::bindRootShaderObject(IShaderObject* object)
- {
- m_currentRootObject = static_cast<RootShaderObjectImpl*>(object);
- }
+SLANG_NO_THROW const DeviceInfo& SLANG_MCALL DeviceImpl::getDeviceInfo() const
+{
+ return m_info;
+}
- void DeviceImpl::dispatchCompute(int x, int y, int z)
- {
- int entryPointIndex = 0;
- int targetIndex = 0;
-
- // Specialize the compute kernel based on the shader object bindings.
- RefPtr<PipelineStateBase> newPipeline;
- maybeSpecializePipeline(m_currentPipeline, m_currentRootObject, newPipeline);
- m_currentPipeline = static_cast<PipelineStateImpl*>(newPipeline.Ptr());
-
- auto program = m_currentPipeline->getProgram();
- auto entryPointLayout =
- m_currentRootObject->getLayout()->getEntryPoint(entryPointIndex);
- auto entryPointName = entryPointLayout->getEntryPointName();
-
- auto entryPointObject = m_currentRootObject->getEntryPoint(entryPointIndex);
-
- ComPtr<ISlangSharedLibrary> sharedLibrary;
- ComPtr<ISlangBlob> diagnostics;
- auto compileResult = program->slangGlobalScope->getEntryPointHostCallable(
- entryPointIndex, targetIndex, sharedLibrary.writeRef(), diagnostics.writeRef());
- if (diagnostics)
- {
- getDebugCallback()->handleMessage(
- compileResult == SLANG_OK ? DebugMessageType::Warning : DebugMessageType::Error,
- DebugMessageSource::Slang,
- (char*)diagnostics->getBufferPointer());
- }
- if (SLANG_FAILED(compileResult)) return;
-
- auto func = (slang_prelude::ComputeFunc)sharedLibrary->findSymbolAddressByName(entryPointName);
-
- slang_prelude::ComputeVaryingInput varyingInput;
- varyingInput.startGroupID.x = 0;
- varyingInput.startGroupID.y = 0;
- varyingInput.startGroupID.z = 0;
- varyingInput.endGroupID.x = x;
- varyingInput.endGroupID.y = y;
- varyingInput.endGroupID.z = z;
-
- auto globalParamsData = m_currentRootObject->getDataBuffer();
- auto entryPointParamsData = entryPointObject->getDataBuffer();
- func(&varyingInput, entryPointParamsData, globalParamsData);
- }
+SLANG_NO_THROW Result SLANG_MCALL
+DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler)
+{
+ SLANG_UNUSED(desc);
+ *outSampler = nullptr;
+ return SLANG_OK;
+}
- void DeviceImpl::copyBuffer(
- IBufferResource* dst,
- size_t dstOffset,
- IBufferResource* src,
- size_t srcOffset,
- size_t size)
+void* DeviceImpl::map(IBufferResource* buffer, MapFlavor flavor)
+{
+ SLANG_UNUSED(flavor);
+ auto bufferImpl = static_cast<BufferResourceImpl*>(buffer);
+ return bufferImpl->m_data;
+}
+void DeviceImpl::unmap(IBufferResource* buffer, size_t offsetWritten, size_t sizeWritten)
+{
+ SLANG_UNUSED(buffer);
+ SLANG_UNUSED(offsetWritten);
+ SLANG_UNUSED(sizeWritten);
+}
+
+void DeviceImpl::setPipelineState(IPipelineState* state)
+{
+ m_currentPipeline = static_cast<PipelineStateImpl*>(state);
+}
+
+void DeviceImpl::bindRootShaderObject(IShaderObject* object)
+{
+ m_currentRootObject = static_cast<RootShaderObjectImpl*>(object);
+}
+
+void DeviceImpl::dispatchCompute(int x, int y, int z)
+{
+ int entryPointIndex = 0;
+ int targetIndex = 0;
+
+ // Specialize the compute kernel based on the shader object bindings.
+ RefPtr<PipelineStateBase> newPipeline;
+ maybeSpecializePipeline(m_currentPipeline, m_currentRootObject, newPipeline);
+ m_currentPipeline = static_cast<PipelineStateImpl*>(newPipeline.Ptr());
+
+ auto program = m_currentPipeline->getProgram();
+ auto entryPointLayout = m_currentRootObject->getLayout()->getEntryPoint(entryPointIndex);
+ auto entryPointName = entryPointLayout->getEntryPointName();
+
+ auto entryPointObject = m_currentRootObject->getEntryPoint(entryPointIndex);
+
+ ComPtr<ISlangSharedLibrary> sharedLibrary;
+ ComPtr<ISlangBlob> diagnostics;
+ auto compileResult = program->slangGlobalScope->getEntryPointHostCallable(
+ entryPointIndex,
+ targetIndex,
+ sharedLibrary.writeRef(),
+ diagnostics.writeRef());
+ if (diagnostics)
{
- auto dstImpl = static_cast<BufferResourceImpl*>(dst);
- auto srcImpl = static_cast<BufferResourceImpl*>(src);
- memcpy(
- (uint8_t*)dstImpl->m_data + dstOffset,
- (uint8_t*)srcImpl->m_data + srcOffset,
- size);
+ getDebugCallback()->handleMessage(
+ compileResult == SLANG_OK ? DebugMessageType::Warning : DebugMessageType::Error,
+ DebugMessageSource::Slang,
+ (char*)diagnostics->getBufferPointer());
}
+ if (SLANG_FAILED(compileResult))
+ return;
+
+ auto func = (slang_prelude::ComputeFunc)sharedLibrary->findSymbolAddressByName(entryPointName);
+
+ slang_prelude::ComputeVaryingInput varyingInput;
+ varyingInput.startGroupID.x = 0;
+ varyingInput.startGroupID.y = 0;
+ varyingInput.startGroupID.z = 0;
+ varyingInput.endGroupID.x = x;
+ varyingInput.endGroupID.y = y;
+ varyingInput.endGroupID.z = z;
+
+ auto globalParamsData = m_currentRootObject->getDataBuffer();
+ auto entryPointParamsData = entryPointObject->getDataBuffer();
+ func(&varyingInput, entryPointParamsData, globalParamsData);
+}
+
+void DeviceImpl::copyBuffer(
+ IBufferResource* dst,
+ size_t dstOffset,
+ IBufferResource* src,
+ size_t srcOffset,
+ size_t size)
+{
+ auto dstImpl = static_cast<BufferResourceImpl*>(dst);
+ auto srcImpl = static_cast<BufferResourceImpl*>(src);
+ memcpy((uint8_t*)dstImpl->m_data + dstOffset, (uint8_t*)srcImpl->m_data + srcOffset, size);
+}
} // namespace cpu
diff --git a/tools/gfx/cpu/cpu-device.h b/tools/gfx/cpu/cpu-device.h
index c7b80e26d..1bfafb1a1 100644
--- a/tools/gfx/cpu/cpu-device.h
+++ b/tools/gfx/cpu/cpu-device.h
@@ -1,7 +1,6 @@
// cpu-device.h
#pragma once
#include "cpu-base.h"
-
#include "cpu-pipeline-state.h"
#include "cpu-shader-object.h"
@@ -30,7 +29,9 @@ public:
IBufferResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView(
- ITextureResource* inTexture, IResourceView::Desc const& desc, IResourceView** outView) override;
+ ITextureResource* inTexture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createBufferView(
IBufferResource* inBuffer,
@@ -43,15 +44,15 @@ public:
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) override;
- virtual Result createShaderObject(
- ShaderObjectLayoutBase* layout,
- IShaderObject** outObject) override;
+ virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ override;
virtual Result createMutableShaderObject(
ShaderObjectLayoutBase* layout,
IShaderObject** outObject) override;
- virtual Result createRootShaderObject(IShaderProgram* program, ShaderObjectBase** outObject) override;
+ virtual Result createRootShaderObject(IShaderProgram* program, ShaderObjectBase** outObject)
+ override;
virtual SLANG_NO_THROW Result SLANG_MCALL createProgram(
const IShaderProgram::Desc& desc,
@@ -59,17 +60,18 @@ public:
ISlangBlob** outDiagnosticBlob) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState) 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 IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual void writeTimestamp(IQueryPool* pool, GfxIndex index) override;
virtual SLANG_NO_THROW const DeviceInfo& SLANG_MCALL getDeviceInfo() const override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
+ createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
virtual void submitGpuWork() override {}
virtual void waitForGpu() override {}
diff --git a/tools/gfx/cpu/cpu-helper-functions.cpp b/tools/gfx/cpu/cpu-helper-functions.cpp
index f21be8d66..ea9308b35 100644
--- a/tools/gfx/cpu/cpu-helper-functions.cpp
+++ b/tools/gfx/cpu/cpu-helper-functions.cpp
@@ -8,5 +8,4 @@ namespace gfx
using namespace Slang;
-
} // namespace gfx
diff --git a/tools/gfx/cpu/cpu-helper-functions.h b/tools/gfx/cpu/cpu-helper-functions.h
index ba8d4c88e..2c6de19d8 100644
--- a/tools/gfx/cpu/cpu-helper-functions.h
+++ b/tools/gfx/cpu/cpu-helper-functions.h
@@ -7,5 +7,4 @@ namespace gfx
using namespace Slang;
-
} // namespace gfx
diff --git a/tools/gfx/cpu/cpu-pipeline-state.cpp b/tools/gfx/cpu/cpu-pipeline-state.cpp
index 7d2b6a636..d0de98532 100644
--- a/tools/gfx/cpu/cpu-pipeline-state.cpp
+++ b/tools/gfx/cpu/cpu-pipeline-state.cpp
@@ -10,18 +10,18 @@ using namespace Slang;
namespace cpu
{
- ShaderProgramImpl* PipelineStateImpl::getProgram()
- {
- return static_cast<ShaderProgramImpl*>(m_program.Ptr());
- }
+ShaderProgramImpl* PipelineStateImpl::getProgram()
+{
+ return static_cast<ShaderProgramImpl*>(m_program.Ptr());
+}
- void PipelineStateImpl::init(const ComputePipelineStateDesc& inDesc)
- {
- PipelineStateDesc pipelineDesc;
- pipelineDesc.type = PipelineType::Compute;
- pipelineDesc.compute = inDesc;
- initializeBase(pipelineDesc);
- }
+void PipelineStateImpl::init(const ComputePipelineStateDesc& inDesc)
+{
+ PipelineStateDesc pipelineDesc;
+ pipelineDesc.type = PipelineType::Compute;
+ pipelineDesc.compute = inDesc;
+ initializeBase(pipelineDesc);
+}
} // namespace cpu
} // namespace gfx
diff --git a/tools/gfx/cpu/cpu-query.cpp b/tools/gfx/cpu/cpu-query.cpp
index 3f87d7a65..9ed416c42 100644
--- a/tools/gfx/cpu/cpu-query.cpp
+++ b/tools/gfx/cpu/cpu-query.cpp
@@ -14,8 +14,8 @@ Result QueryPoolImpl::init(const IQueryPool::Desc& desc)
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL QueryPoolImpl::getResult(
- GfxIndex queryIndex, GfxCount count, uint64_t* data)
+SLANG_NO_THROW Result SLANG_MCALL
+QueryPoolImpl::getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data)
{
for (GfxCount i = 0; i < count; i++)
{
diff --git a/tools/gfx/cpu/cpu-query.h b/tools/gfx/cpu/cpu-query.h
index 172dcea41..fd4ac4754 100644
--- a/tools/gfx/cpu/cpu-query.h
+++ b/tools/gfx/cpu/cpu-query.h
@@ -14,8 +14,8 @@ class QueryPoolImpl : public QueryPoolBase
public:
List<uint64_t> m_queries;
Result init(const IQueryPool::Desc& desc);
- virtual SLANG_NO_THROW Result SLANG_MCALL getResult(
- GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
};
} // namespace cpu
diff --git a/tools/gfx/cpu/cpu-resource-views.cpp b/tools/gfx/cpu/cpu-resource-views.cpp
index ccf253cab..b9d04beff 100644
--- a/tools/gfx/cpu/cpu-resource-views.cpp
+++ b/tools/gfx/cpu/cpu-resource-views.cpp
@@ -77,8 +77,10 @@ void TextureResourceViewImpl::SampleLevel(
int32_t baseCoordCount = baseShape->baseCoordCount;
int32_t integerMipLevel = int32_t(level + 0.5f);
- if (integerMipLevel >= desc.numMipLevels) integerMipLevel = desc.numMipLevels - 1;
- if (integerMipLevel < 0) integerMipLevel = 0;
+ if (integerMipLevel >= desc.numMipLevels)
+ integerMipLevel = desc.numMipLevels - 1;
+ if (integerMipLevel < 0)
+ integerMipLevel = 0;
auto& mipLevelInfo = texture->m_mipLevels[integerMipLevel];
@@ -90,8 +92,10 @@ void TextureResourceViewImpl::SampleLevel(
{
elementIndex = int32_t(coords[coordIndex++] + 0.5f);
}
- if (elementIndex >= effectiveArrayElementCount) elementIndex = effectiveArrayElementCount - 1;
- if (elementIndex < 0) elementIndex = 0;
+ if (elementIndex >= effectiveArrayElementCount)
+ elementIndex = effectiveArrayElementCount - 1;
+ if (elementIndex < 0)
+ elementIndex = 0;
// Note: for now we are just going to do nearest-neighbor sampling
//
@@ -107,8 +111,10 @@ void TextureResourceViewImpl::SampleLevel(
int32_t integerCoord = int32_t(coord * (extent - 1) + 0.5f);
- if (integerCoord >= extent) integerCoord = extent - 1;
- if (integerCoord < 0) integerCoord = 0;
+ if (integerCoord >= extent)
+ integerCoord = extent - 1;
+ if (integerCoord < 0)
+ integerCoord = 0;
texelOffset += integerCoord * mipLevelInfo.strides[axis];
}
@@ -145,16 +151,20 @@ void* TextureResourceViewImpl::_getTexelPtr(int32_t const* texelCoords)
{
elementIndex = texelCoords[coordIndex++];
}
- if (elementIndex >= effectiveArrayElementCount) elementIndex = effectiveArrayElementCount - 1;
- if (elementIndex < 0) elementIndex = 0;
+ if (elementIndex >= effectiveArrayElementCount)
+ elementIndex = effectiveArrayElementCount - 1;
+ if (elementIndex < 0)
+ elementIndex = 0;
int32_t mipLevel = 0;
if (!hasMipLevels)
{
mipLevel = texelCoords[coordIndex++];
}
- if (mipLevel >= desc.numMipLevels) mipLevel = desc.numMipLevels - 1;
- if (mipLevel < 0) mipLevel = 0;
+ if (mipLevel >= desc.numMipLevels)
+ mipLevel = desc.numMipLevels - 1;
+ if (mipLevel < 0)
+ mipLevel = 0;
auto& mipLevelInfo = texture->m_mipLevels[mipLevel];
@@ -163,8 +173,10 @@ void* TextureResourceViewImpl::_getTexelPtr(int32_t const* texelCoords)
for (int32_t axis = 0; axis < rank; ++axis)
{
int32_t coord = texelCoords[axis];
- if (coord >= mipLevelInfo.extents[axis]) coord = mipLevelInfo.extents[axis] - 1;
- if (coord < 0) coord = 0;
+ if (coord >= mipLevelInfo.extents[axis])
+ coord = mipLevelInfo.extents[axis] - 1;
+ if (coord < 0)
+ coord = 0;
texelOffset += texelCoords[axis] * mipLevelInfo.strides[axis];
}
diff --git a/tools/gfx/cpu/cpu-resource-views.h b/tools/gfx/cpu/cpu-resource-views.h
index bec1339a3..c08946811 100644
--- a/tools/gfx/cpu/cpu-resource-views.h
+++ b/tools/gfx/cpu/cpu-resource-views.h
@@ -1,7 +1,6 @@
// cpu-resource-views.h
#pragma once
#include "cpu-base.h"
-
#include "cpu-buffer.h"
#include "cpu-texture.h"
@@ -34,9 +33,9 @@ class BufferResourceViewImpl : public ResourceViewImpl
{
public:
BufferResourceViewImpl(Desc const& desc, BufferResourceImpl* buffer)
- : ResourceViewImpl(Kind::Buffer, desc)
- , m_buffer(buffer)
- {}
+ : ResourceViewImpl(Kind::Buffer, desc), m_buffer(buffer)
+ {
+ }
BufferResourceImpl* getBuffer() const;
@@ -48,9 +47,9 @@ class TextureResourceViewImpl : public ResourceViewImpl, public slang_prelude::I
{
public:
TextureResourceViewImpl(Desc const& desc, TextureResourceImpl* texture)
- : ResourceViewImpl(Kind::Texture, desc)
- , m_texture(texture)
- {}
+ : ResourceViewImpl(Kind::Texture, desc), m_texture(texture)
+ {
+ }
TextureResourceImpl* getTexture() const;
@@ -62,9 +61,18 @@ public:
void Load(const int32_t* texelCoords, void* outData, size_t dataSize) SLANG_OVERRIDE;
- void Sample(slang_prelude::SamplerState samplerState, const float* coords, void* outData, size_t dataSize) SLANG_OVERRIDE;
-
- void SampleLevel(slang_prelude::SamplerState samplerState, const float* coords, float level, void* outData, size_t dataSize) SLANG_OVERRIDE;
+ void Sample(
+ slang_prelude::SamplerState samplerState,
+ const float* coords,
+ void* outData,
+ size_t dataSize) SLANG_OVERRIDE;
+
+ void SampleLevel(
+ slang_prelude::SamplerState samplerState,
+ const float* coords,
+ float level,
+ void* outData,
+ size_t dataSize) SLANG_OVERRIDE;
//
// IRWTexture interface
diff --git a/tools/gfx/cpu/cpu-shader-object-layout.cpp b/tools/gfx/cpu/cpu-shader-object-layout.cpp
index 4f4c33a6a..aeeadfc23 100644
--- a/tools/gfx/cpu/cpu-shader-object-layout.cpp
+++ b/tools/gfx/cpu/cpu-shader-object-layout.cpp
@@ -8,13 +8,16 @@ using namespace Slang;
namespace cpu
{
-ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* layout)
+ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::TypeLayoutReflection* layout)
{
initBase(renderer, session, layout);
m_subObjectCount = 0;
m_resourceCount = 0;
-
+
m_elementTypeLayout = _unwrapParameterGroups(layout, m_containerType);
m_size = m_elementTypeLayout->getSize();
@@ -44,7 +47,8 @@ ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::IS
// linear search over the descriptor ranges for a specific binding range.
//
auto uniformOffset = m_elementTypeLayout->getDescriptorSetDescriptorRangeIndexOffset(
- descriptorSetIndex, rangeIndexInDescriptorSet);
+ descriptorSetIndex,
+ rangeIndexInDescriptorSet);
Index baseIndex = 0;
Index subObjectIndex = 0;
@@ -103,8 +107,10 @@ ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::IS
RefPtr<ShaderObjectLayoutImpl> subObjectLayout;
if (slangBindingType != slang::BindingType::ExistentialValue)
{
- subObjectLayout =
- new ShaderObjectLayoutImpl(renderer, m_slangSession, slangLeafTypeLayout->getElementTypeLayout());
+ subObjectLayout = new ShaderObjectLayoutImpl(
+ renderer,
+ m_slangSession,
+ slangLeafTypeLayout->getElementTypeLayout());
}
SubObjectRangeInfo subObjectRange;
@@ -119,35 +125,50 @@ size_t ShaderObjectLayoutImpl::getSize()
return m_size;
}
-Index ShaderObjectLayoutImpl::getResourceCount() const { return m_resourceCount; }
-Index ShaderObjectLayoutImpl::getSubObjectCount() const { return m_subObjectCount; }
-List<SubObjectRangeInfo>& ShaderObjectLayoutImpl::getSubObjectRanges() { return subObjectRanges; }
-BindingRangeInfo ShaderObjectLayoutImpl::getBindingRange(Index index) { return m_bindingRanges[index]; }
-Index ShaderObjectLayoutImpl::getBindingRangeCount() const { return m_bindingRanges.getCount(); }
+Index ShaderObjectLayoutImpl::getResourceCount() const
+{
+ return m_resourceCount;
+}
+Index ShaderObjectLayoutImpl::getSubObjectCount() const
+{
+ return m_subObjectCount;
+}
+List<SubObjectRangeInfo>& ShaderObjectLayoutImpl::getSubObjectRanges()
+{
+ return subObjectRanges;
+}
+BindingRangeInfo ShaderObjectLayoutImpl::getBindingRange(Index index)
+{
+ return m_bindingRanges[index];
+}
+Index ShaderObjectLayoutImpl::getBindingRangeCount() const
+{
+ return m_bindingRanges.getCount();
+}
const char* EntryPointLayoutImpl::getEntryPointName()
{
return m_entryPointLayout->getName();
}
-RootShaderObjectLayoutImpl::RootShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::ProgramLayout* programLayout)
+RootShaderObjectLayoutImpl::RootShaderObjectLayoutImpl(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::ProgramLayout* programLayout)
: ShaderObjectLayoutImpl(renderer, session, programLayout->getGlobalParamsTypeLayout())
, m_programLayout(programLayout)
{
- for (UInt i =0; i< programLayout->getEntryPointCount(); i++)
+ for (UInt i = 0; i < programLayout->getEntryPointCount(); i++)
{
- m_entryPointLayouts.add(new EntryPointLayoutImpl(
- renderer,
- session,
- programLayout->getEntryPointByIndex(i)));
+ m_entryPointLayouts.add(
+ new EntryPointLayoutImpl(renderer, session, programLayout->getEntryPointByIndex(i)));
}
-
}
int RootShaderObjectLayoutImpl::getKernelIndex(UnownedStringSlice kernelName)
{
- auto entryPointCount = (int) m_programLayout->getEntryPointCount();
- for(int i = 0; i < entryPointCount; i++)
+ auto entryPointCount = (int)m_programLayout->getEntryPointCount();
+ for (int i = 0; i < entryPointCount; i++)
{
auto entryPoint = m_programLayout->getEntryPointByIndex(i);
if (kernelName == entryPoint->getName())
@@ -164,7 +185,10 @@ void RootShaderObjectLayoutImpl::getKernelThreadGroupSize(int kernelIndex, UInt*
entryPoint->getComputeThreadGroupSize(3, threadGroupSizes);
}
-EntryPointLayoutImpl* RootShaderObjectLayoutImpl::getEntryPoint(Index index) { return m_entryPointLayouts[index]; }
+EntryPointLayoutImpl* RootShaderObjectLayoutImpl::getEntryPoint(Index index)
+{
+ return m_entryPointLayouts[index];
+}
} // namespace cpu
} // namespace gfx
diff --git a/tools/gfx/cpu/cpu-shader-object-layout.h b/tools/gfx/cpu/cpu-shader-object-layout.h
index 3bf2e2aa7..b5439f370 100644
--- a/tools/gfx/cpu/cpu-shader-object-layout.h
+++ b/tools/gfx/cpu/cpu-shader-object-layout.h
@@ -43,7 +43,6 @@ struct SubObjectRangeInfo
class ShaderObjectLayoutImpl : public ShaderObjectLayoutBase
{
public:
-
// TODO: Once memory lifetime stuff is handled, there is
// no specific need to even track binding or sub-object
// ranges for CPU.
@@ -55,7 +54,10 @@ public:
Index m_subObjectCount = 0;
Index m_resourceCount = 0;
- ShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* layout);
+ ShaderObjectLayoutImpl(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::TypeLayoutReflection* layout);
size_t getSize();
Index getResourceCount() const;
@@ -72,12 +74,13 @@ private:
public:
EntryPointLayoutImpl(
- RendererBase* renderer,
- slang::ISession* session,
- slang::EntryPointLayout* entryPointLayout)
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::EntryPointLayout* entryPointLayout)
: ShaderObjectLayoutImpl(renderer, session, entryPointLayout->getTypeLayout())
, m_entryPointLayout(entryPointLayout)
- {}
+ {
+ }
const char* getEntryPointName();
};
@@ -88,7 +91,10 @@ public:
slang::ProgramLayout* m_programLayout = nullptr;
List<RefPtr<EntryPointLayoutImpl>> m_entryPointLayouts;
- RootShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::ProgramLayout* programLayout);
+ RootShaderObjectLayoutImpl(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::ProgramLayout* programLayout);
int getKernelIndex(UnownedStringSlice kernelName);
void getKernelThreadGroupSize(int kernelIndex, UInt* threadGroupSizes);
diff --git a/tools/gfx/cpu/cpu-shader-object.cpp b/tools/gfx/cpu/cpu-shader-object.cpp
index 67ffd6af5..3c9dd3cb2 100644
--- a/tools/gfx/cpu/cpu-shader-object.cpp
+++ b/tools/gfx/cpu/cpu-shader-object.cpp
@@ -54,7 +54,6 @@ ResourceViewBase* CPUShaderObjectData::getResourceView(
viewDesc.type = IResourceView::Type::UnorderedAccess;
viewDesc.format = Format::Unknown;
m_bufferView = new BufferResourceViewImpl(viewDesc, m_bufferResource);
-
}
m_bufferResource->getDesc()->sizeInBytes = m_ordinaryData.getCount();
m_bufferResource->m_data = m_ordinaryData.getBuffer();
@@ -129,7 +128,7 @@ SLANG_NO_THROW GfxCount SLANG_MCALL ShaderObjectImpl::getEntryPointCount()
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
+ShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
{
*outEntryPoint = nullptr;
return SLANG_OK;
@@ -146,7 +145,7 @@ SLANG_NO_THROW size_t SLANG_MCALL ShaderObjectImpl::getSize()
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setData(ShaderOffset const& offset, void const* data, size_t size)
+ShaderObjectImpl::setData(ShaderOffset const& offset, void const* data, size_t size)
{
size = Math::Min(size, size_t(m_data.getCount() - offset.uniformOffset));
memcpy((char*)m_data.getBuffer() + offset.uniformOffset, data, size);
@@ -154,7 +153,7 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* inView)
+ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* inView)
{
auto layout = getLayout();
@@ -172,40 +171,40 @@ SLANG_NO_THROW Result SLANG_MCALL
switch (view->getViewKind())
{
case ResourceViewImpl::Kind::Texture:
- {
- auto textureView = static_cast<TextureResourceViewImpl*>(view);
+ {
+ auto textureView = static_cast<TextureResourceViewImpl*>(view);
- slang_prelude::IRWTexture* textureObj = textureView;
- SLANG_RETURN_ON_FAIL(setData(offset, &textureObj, sizeof(textureObj)));
- }
- break;
+ slang_prelude::IRWTexture* textureObj = textureView;
+ SLANG_RETURN_ON_FAIL(setData(offset, &textureObj, sizeof(textureObj)));
+ }
+ break;
case ResourceViewImpl::Kind::Buffer:
- {
- auto bufferView = static_cast<BufferResourceViewImpl*>(view);
- auto buffer = bufferView->getBuffer();
- auto desc = *buffer->getDesc();
+ {
+ auto bufferView = static_cast<BufferResourceViewImpl*>(view);
+ auto buffer = bufferView->getBuffer();
+ auto desc = *buffer->getDesc();
- void* dataPtr = buffer->m_data;
- size_t size = desc.sizeInBytes;
- if (desc.elementSize > 1)
- size /= desc.elementSize;
+ void* dataPtr = buffer->m_data;
+ size_t size = desc.sizeInBytes;
+ if (desc.elementSize > 1)
+ size /= desc.elementSize;
- auto ptrOffset = offset;
- SLANG_RETURN_ON_FAIL(setData(ptrOffset, &dataPtr, sizeof(dataPtr)));
+ auto ptrOffset = offset;
+ SLANG_RETURN_ON_FAIL(setData(ptrOffset, &dataPtr, sizeof(dataPtr)));
- auto sizeOffset = offset;
- sizeOffset.uniformOffset += sizeof(dataPtr);
- SLANG_RETURN_ON_FAIL(setData(sizeOffset, &size, sizeof(size)));
- }
- break;
+ auto sizeOffset = offset;
+ sizeOffset.uniformOffset += sizeof(dataPtr);
+ SLANG_RETURN_ON_FAIL(setData(sizeOffset, &size, sizeof(size)));
+ }
+ break;
}
return SLANG_OK;
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setObject(ShaderOffset const& offset, IShaderObject* object)
+ShaderObjectImpl::setObject(ShaderOffset const& offset, IShaderObject* object)
{
SLANG_RETURN_ON_FAIL(Super::setObject(offset, object));
@@ -217,21 +216,20 @@ SLANG_NO_THROW Result SLANG_MCALL
switch (bindingRange.bindingType)
{
default:
- {
- void* bufferPtr = subObject->m_data.getBuffer();
- SLANG_RETURN_ON_FAIL(setData(offset, &bufferPtr, sizeof(void*)));
- }
- break;
+ {
+ void* bufferPtr = subObject->m_data.getBuffer();
+ SLANG_RETURN_ON_FAIL(setData(offset, &bufferPtr, sizeof(void*)));
+ }
+ break;
case slang::BindingType::ExistentialValue:
case slang::BindingType::RawBuffer:
- case slang::BindingType::MutableRawBuffer:
- break;
+ case slang::BindingType::MutableRawBuffer: break;
}
return SLANG_OK;
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* sampler)
+ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* sampler)
{
SLANG_UNUSED(sampler);
SLANG_UNUSED(offset);
@@ -239,7 +237,9 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL ShaderObjectImpl::setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler)
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler)
{
SLANG_UNUSED(sampler);
setResource(offset, textureView);
@@ -294,7 +294,7 @@ SLANG_NO_THROW GfxCount SLANG_MCALL RootShaderObjectImpl::getEntryPointCount()
}
SLANG_NO_THROW Result SLANG_MCALL
- RootShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
+RootShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
{
returnComPtr(outEntryPoint, m_entryPoints[index]);
return SLANG_OK;
diff --git a/tools/gfx/cpu/cpu-shader-object.h b/tools/gfx/cpu/cpu-shader-object.h
index 2be703dc5..dc7199509 100644
--- a/tools/gfx/cpu/cpu-shader-object.h
+++ b/tools/gfx/cpu/cpu-shader-object.h
@@ -1,7 +1,6 @@
// cpu-shader-object.h
#pragma once
#include "cpu-base.h"
-
#include "cpu-shader-object-layout.h"
namespace gfx
@@ -36,38 +35,43 @@ public:
class ShaderObjectImpl
: public ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, CPUShaderObjectData>
{
- typedef ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, CPUShaderObjectData> Super;
+ typedef ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, CPUShaderObjectData>
+ Super;
public:
List<RefPtr<ResourceViewImpl>> m_resources;
virtual SLANG_NO_THROW Result SLANG_MCALL
- init(IDevice* device, ShaderObjectLayoutImpl* typeLayout);
+ init(IDevice* device, ShaderObjectLayoutImpl* typeLayout);
virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override;
virtual SLANG_NO_THROW size_t SLANG_MCALL getSize() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& offset, void const* data, size_t size) override;
+ setData(ShaderOffset const& offset, void const* data, size_t size) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* inView) override;
+ setResource(ShaderOffset const& offset, IResourceView* inView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setObject(ShaderOffset const& offset, IShaderObject* object) override;
+ setObject(ShaderOffset const& offset, IShaderObject* object) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) override;
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) override;
char* getDataBuffer();
};
-class MutableShaderObjectImpl : public MutableShaderObject<MutableShaderObjectImpl, ShaderObjectLayoutImpl>
-{};
+class MutableShaderObjectImpl
+ : public MutableShaderObject<MutableShaderObjectImpl, ShaderObjectLayoutImpl>
+{
+};
class EntryPointShaderObjectImpl : public ShaderObjectImpl
{
@@ -92,7 +96,7 @@ public:
virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) override;
};
diff --git a/tools/gfx/cpu/cpu-shader-program.h b/tools/gfx/cpu/cpu-shader-program.h
index f2f159538..6c92151fa 100644
--- a/tools/gfx/cpu/cpu-shader-program.h
+++ b/tools/gfx/cpu/cpu-shader-program.h
@@ -1,7 +1,6 @@
// cpu-shader-program.h
#pragma once
#include "cpu-base.h"
-
#include "cpu-shader-object-layout.h"
namespace gfx
@@ -16,9 +15,7 @@ class ShaderProgramImpl : public ShaderProgramBase
public:
RefPtr<RootShaderObjectLayoutImpl> layout;
- ~ShaderProgramImpl()
- {
- }
+ ~ShaderProgramImpl() {}
};
} // namespace cpu
diff --git a/tools/gfx/cpu/cpu-texture.cpp b/tools/gfx/cpu/cpu-texture.cpp
index d5367bd96..9077084f2 100644
--- a/tools/gfx/cpu/cpu-texture.cpp
+++ b/tools/gfx/cpu/cpu-texture.cpp
@@ -18,7 +18,7 @@ void _unpackFloatTexel(void const* texelData, void* outData, size_t outSize)
{
auto input = (float const*)texelData;
- float temp[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ float temp[4] = {0.0f, 0.0f, 0.0f, 1.0f};
for (int i = 0; i < N; ++i)
temp[i] = input[i];
@@ -30,7 +30,7 @@ void _unpackFloat16Texel(void const* texelData, void* outData, size_t outSize)
{
auto input = (int16_t const*)texelData;
- float temp[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ float temp[4] = {0.0f, 0.0f, 0.0f, 1.0f};
for (int i = 0; i < N; ++i)
temp[i] = HalfToFloat(input[i]);
@@ -47,7 +47,7 @@ void _unpackUnorm8Texel(void const* texelData, void* outData, size_t outSize)
{
auto input = (uint8_t const*)texelData;
- float temp[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ float temp[4] = {0.0f, 0.0f, 0.0f, 1.0f};
for (int i = 0; i < N; ++i)
temp[i] = _unpackUnorm8Value(input[i]);
@@ -72,7 +72,7 @@ void _unpackUInt16Texel(void const* texelData, void* outData, size_t outSize)
{
auto input = (uint16_t const*)texelData;
- uint32_t temp[4] = { 0, 0, 0, 0 };
+ uint32_t temp[4] = {0, 0, 0, 0};
for (int i = 0; i < N; ++i)
temp[i] = input[i];
@@ -84,7 +84,7 @@ void _unpackUInt32Texel(void const* texelData, void* outData, size_t outSize)
{
auto input = (uint32_t const*)texelData;
- uint32_t temp[4] = { 0, 0, 0, 0 };
+ uint32_t temp[4] = {0, 0, 0, 0};
for (int i = 0; i < N; ++i)
temp[i] = input[i];
@@ -117,16 +117,16 @@ Result TextureResourceImpl::init(ITextureResource::SubresourceData const* initDa
uint32_t texelSize = uint32_t(texelInfo.blockSizeInBytes / texelInfo.pixelsPerBlock);
m_texelSize = texelSize;
- int32_t formatBlockSize[kMaxRank] = { 1, 1, 1 };
+ int32_t formatBlockSize[kMaxRank] = {1, 1, 1};
auto baseShapeInfo = _getBaseShapeInfo(desc.type);
m_baseShape = baseShapeInfo;
- if(!baseShapeInfo)
+ if (!baseShapeInfo)
return SLANG_FAIL;
auto formatInfo = _getFormatInfo(desc.format);
m_formatInfo = formatInfo;
- if(!formatInfo)
+ if (!formatInfo)
return SLANG_FAIL;
int32_t rank = baseShapeInfo->rank;
@@ -139,7 +139,7 @@ Result TextureResourceImpl::init(ITextureResource::SubresourceData const* initDa
extents[1] = desc.size.height;
extents[2] = desc.size.depth;
- for(int32_t axis = rank; axis < kMaxRank; ++axis)
+ for (int32_t axis = rank; axis < kMaxRank; ++axis)
extents[axis] = 1;
int32_t levelCount = desc.numMipLevels;
@@ -147,26 +147,27 @@ Result TextureResourceImpl::init(ITextureResource::SubresourceData const* initDa
m_mipLevels.setCount(levelCount);
int64_t totalDataSize = 0;
- for( int32_t levelIndex = 0; levelIndex < levelCount; ++levelIndex )
+ for (int32_t levelIndex = 0; levelIndex < levelCount; ++levelIndex)
{
auto& level = m_mipLevels[levelIndex];
- for( int32_t axis = 0; axis < kMaxRank; ++axis )
+ for (int32_t axis = 0; axis < kMaxRank; ++axis)
{
int32_t extent = extents[axis] >> levelIndex;
- if(extent < 1) extent = 1;
+ if (extent < 1)
+ extent = 1;
level.extents[axis] = extent;
}
level.strides[0] = texelSize;
- for( int32_t axis = 1; axis < kMaxRank+1; ++axis)
+ for (int32_t axis = 1; axis < kMaxRank + 1; ++axis)
{
- level.strides[axis] = level.strides[axis-1]*level.extents[axis-1];
+ level.strides[axis] = level.strides[axis - 1] * level.extents[axis - 1];
}
int64_t levelDataSize = texelSize;
levelDataSize *= effectiveArrayElementCount;
- for( int32_t axis = 0; axis < rank; ++axis)
+ for (int32_t axis = 0; axis < rank; ++axis)
levelDataSize *= int64_t(level.extents[axis]);
level.offset = totalDataSize;
@@ -176,12 +177,13 @@ Result TextureResourceImpl::init(ITextureResource::SubresourceData const* initDa
void* textureData = malloc((size_t)totalDataSize);
m_data = textureData;
- if( initData )
+ if (initData)
{
int32_t subResourceCounter = 0;
- for(int32_t arrayElementIndex = 0; arrayElementIndex < effectiveArrayElementCount; ++arrayElementIndex)
+ for (int32_t arrayElementIndex = 0; arrayElementIndex < effectiveArrayElementCount;
+ ++arrayElementIndex)
{
- for(int32_t mipLevel = 0; mipLevel < m_desc.numMipLevels; ++mipLevel)
+ for (int32_t mipLevel = 0; mipLevel < m_desc.numMipLevels; ++mipLevel)
{
int32_t subResourceIndex = subResourceCounter++;
@@ -189,7 +191,7 @@ Result TextureResourceImpl::init(ITextureResource::SubresourceData const* initDa
auto dstLayerStride = m_mipLevels[mipLevel].strides[2];
auto dstArrayStride = m_mipLevels[mipLevel].strides[3];
- auto textureRowSize = m_mipLevels[mipLevel].extents[0]*texelSize;
+ auto textureRowSize = m_mipLevels[mipLevel].extents[0] * texelSize;
auto rowCount = m_mipLevels[mipLevel].extents[1];
auto depthLayerCount = m_mipLevels[mipLevel].extents[2];
@@ -199,17 +201,17 @@ Result TextureResourceImpl::init(ITextureResource::SubresourceData const* initDa
ptrdiff_t srcLayerStride = ptrdiff_t(srcImage.strideZ);
char* dstLevel = (char*)textureData + m_mipLevels[mipLevel].offset;
- char* dstImage = dstLevel + dstArrayStride*arrayElementIndex;
+ char* dstImage = dstLevel + dstArrayStride * arrayElementIndex;
- const char* srcLayer = (const char*) srcImage.data;
+ const char* srcLayer = (const char*)srcImage.data;
char* dstLayer = dstImage;
- for(int32_t depthLayer = 0; depthLayer < depthLayerCount; ++depthLayer)
+ for (int32_t depthLayer = 0; depthLayer < depthLayerCount; ++depthLayer)
{
const char* srcRow = srcLayer;
char* dstRow = dstLayer;
- for(int32_t row = 0; row < rowCount; ++row)
+ for (int32_t row = 0; row < rowCount; ++row)
{
memcpy(dstRow, srcRow, textureRowSize);
diff --git a/tools/gfx/cpu/cpu-texture.h b/tools/gfx/cpu/cpu-texture.h
index 5ae896d0f..e65f8f4be 100644
--- a/tools/gfx/cpu/cpu-texture.h
+++ b/tools/gfx/cpu/cpu-texture.h
@@ -16,14 +16,14 @@ struct CPUTextureBaseShapeInfo
int32_t implicitArrayElementCount;
};
-static const CPUTextureBaseShapeInfo kCPUTextureBaseShapeInfos[(int)ITextureResource::Type::_Count] =
-{
- /* Unknown */ { 0, 0, 0 },
- /* Buffer */ { 1, 1, 1 },
- /* Texture1D */ { 1, 1, 1 },
- /* Texture2D */ { 2, 2, 1 },
- /* Texture3D */ { 3, 3, 1 },
- /* TextureCube */ { 2, 3, 6 },
+static const CPUTextureBaseShapeInfo
+ kCPUTextureBaseShapeInfos[(int)ITextureResource::Type::_Count] = {
+ /* Unknown */ {0, 0, 0},
+ /* Buffer */ {1, 1, 1},
+ /* Texture1D */ {1, 1, 1},
+ /* Texture2D */ {2, 2, 1},
+ /* Texture3D */ {3, 3, 1},
+ /* TextureCube */ {2, 3, 6},
};
static CPUTextureBaseShapeInfo const* _getBaseShapeInfo(ITextureResource::Type baseShape);
@@ -82,7 +82,10 @@ struct CPUFormatInfoMap
auto& info = m_infos[Index(format)];
info.unpackFunc = func;
}
- SLANG_FORCE_INLINE const CPUTextureFormatInfo& get(Format format) const { return m_infos[Index(format)]; }
+ SLANG_FORCE_INLINE const CPUTextureFormatInfo& get(Format format) const
+ {
+ return m_infos[Index(format)];
+ }
CPUTextureFormatInfo m_infos[Index(Format::_Count)];
};
@@ -97,12 +100,16 @@ static CPUTextureFormatInfo const* _getFormatInfo(Format format)
class TextureResourceImpl : public TextureResource
{
- enum { kMaxRank = 3 };
+ enum
+ {
+ kMaxRank = 3
+ };
public:
TextureResourceImpl(const TextureResource::Desc& desc)
: TextureResource(desc)
- {}
+ {
+ }
~TextureResourceImpl();
Result init(ITextureResource::SubresourceData const* initData);
@@ -119,11 +126,11 @@ public:
struct MipLevel
{
int32_t extents[kMaxRank];
- int64_t strides[kMaxRank+1];
+ int64_t strides[kMaxRank + 1];
int64_t offset;
};
- List<MipLevel> m_mipLevels;
- void* m_data = nullptr;
+ List<MipLevel> m_mipLevels;
+ void* m_data = nullptr;
};
} // namespace cpu
diff --git a/tools/gfx/cuda/cuda-base.h b/tools/gfx/cuda/cuda-base.h
index 63c280cde..11a798636 100644
--- a/tools/gfx/cuda/cuda-base.h
+++ b/tools/gfx/cuda/cuda-base.h
@@ -3,32 +3,32 @@
#pragma once
#ifdef GFX_ENABLE_CUDA
-#include <cuda.h>
-#include "core/slang-basic.h"
-#include "core/slang-blob.h"
-#include "core/slang-std-writers.h"
-
-#include "slang.h"
-#include "slang-com-ptr.h"
-#include "slang-com-helper.h"
+#include "../command-encoder-com-forward.h"
#include "../command-writer.h"
-#include "../renderer-shared.h"
#include "../mutable-shader-object.h"
+#include "../renderer-shared.h"
#include "../simple-transient-resource-heap.h"
#include "../slang-context.h"
-#include "../command-encoder-com-forward.h"
+#include "core/slang-basic.h"
+#include "core/slang-blob.h"
+#include "core/slang-std-writers.h"
+#include "slang-com-helper.h"
+#include "slang-com-ptr.h"
+#include "slang.h"
+
+#include <cuda.h>
-# ifdef RENDER_TEST_OPTIX
+#ifdef RENDER_TEST_OPTIX
// The `optix_stubs.h` header produces warnings when compiled with MSVC
-# ifdef _MSC_VER
-# pragma warning(disable: 4996)
-# endif
+#ifdef _MSC_VER
+#pragma warning(disable : 4996)
+#endif
-# include <optix.h>
-# include <optix_function_table_definition.h>
-# include <optix_stubs.h>
-# endif
+#include <optix.h>
+#include <optix_function_table_definition.h>
+#include <optix_stubs.h>
+#endif
#endif
@@ -36,23 +36,23 @@ namespace gfx
{
namespace cuda
{
- class CUDAContext;
- class BufferResourceImpl;
- class TextureResourceImpl;
- class ResourceViewImpl;
- class ShaderObjectLayoutImpl;
- class RootShaderObjectLayoutImpl;
- class ShaderObjectImpl;
- class MutableShaderObjectImpl;
- class EntryPointShaderObjectImpl;
- class RootShaderObjectImpl;
- class ShaderProgramImpl;
- class PipelineStateImpl;
- class QueryPoolImpl;
- class DeviceImpl;
- class CommandBufferImpl;
- class ResourceCommandEncoderImpl;
- class ComputeCommandEncoderImpl;
- class CommandQueueImpl;
-}
-}
+class CUDAContext;
+class BufferResourceImpl;
+class TextureResourceImpl;
+class ResourceViewImpl;
+class ShaderObjectLayoutImpl;
+class RootShaderObjectLayoutImpl;
+class ShaderObjectImpl;
+class MutableShaderObjectImpl;
+class EntryPointShaderObjectImpl;
+class RootShaderObjectImpl;
+class ShaderProgramImpl;
+class PipelineStateImpl;
+class QueryPoolImpl;
+class DeviceImpl;
+class CommandBufferImpl;
+class ResourceCommandEncoderImpl;
+class ComputeCommandEncoderImpl;
+class CommandQueueImpl;
+} // namespace cuda
+} // namespace gfx
diff --git a/tools/gfx/cuda/cuda-buffer.cpp b/tools/gfx/cuda/cuda-buffer.cpp
index bc4ef32ef..63c94b459 100644
--- a/tools/gfx/cuda/cuda-buffer.cpp
+++ b/tools/gfx/cuda/cuda-buffer.cpp
@@ -19,7 +19,10 @@ BufferResourceImpl::~BufferResourceImpl()
}
}
-uint64_t BufferResourceImpl::getBindlessHandle() { return (uint64_t)m_cudaMemory; }
+uint64_t BufferResourceImpl::getBindlessHandle()
+{
+ return (uint64_t)m_cudaMemory;
+}
DeviceAddress BufferResourceImpl::getDeviceAddress()
{
diff --git a/tools/gfx/cuda/cuda-buffer.h b/tools/gfx/cuda/cuda-buffer.h
index 838a06555..c83ab755d 100644
--- a/tools/gfx/cuda/cuda-buffer.h
+++ b/tools/gfx/cuda/cuda-buffer.h
@@ -16,7 +16,8 @@ class BufferResourceImpl : public BufferResource
public:
BufferResourceImpl(const Desc& _desc)
: BufferResource(_desc)
- {}
+ {
+ }
~BufferResourceImpl();
@@ -28,9 +29,10 @@ public:
RefPtr<CUDAContext> m_cudaContext;
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- map(MemoryRange* rangeToRead, void** outPointer) override;
+ getNativeResourceHandle(InteropHandle* outHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ map(MemoryRange* rangeToRead, void** outPointer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override;
};
diff --git a/tools/gfx/cuda/cuda-command-buffer.cpp b/tools/gfx/cuda/cuda-command-buffer.cpp
index efb2486f4..ce95a2196 100644
--- a/tools/gfx/cuda/cuda-command-buffer.cpp
+++ b/tools/gfx/cuda/cuda-command-buffer.cpp
@@ -33,21 +33,21 @@ SLANG_NO_THROW void SLANG_MCALL CommandBufferImpl::encodeRenderCommands(
}
SLANG_NO_THROW void SLANG_MCALL
- CommandBufferImpl::encodeResourceCommands(IResourceCommandEncoder** outEncoder)
+CommandBufferImpl::encodeResourceCommands(IResourceCommandEncoder** outEncoder)
{
m_resourceCommandEncoder.init(this);
*outEncoder = &m_resourceCommandEncoder;
}
SLANG_NO_THROW void SLANG_MCALL
- CommandBufferImpl::encodeComputeCommands(IComputeCommandEncoder** outEncoder)
+CommandBufferImpl::encodeComputeCommands(IComputeCommandEncoder** outEncoder)
{
m_computeCommandEncoder.init(this);
*outEncoder = &m_computeCommandEncoder;
}
SLANG_NO_THROW void SLANG_MCALL
- CommandBufferImpl::encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder)
+CommandBufferImpl::encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder)
{
*outEncoder = nullptr;
}
diff --git a/tools/gfx/cuda/cuda-command-buffer.h b/tools/gfx/cuda/cuda-command-buffer.h
index 76d9aa01f..05329d67c 100644
--- a/tools/gfx/cuda/cuda-command-buffer.h
+++ b/tools/gfx/cuda/cuda-command-buffer.h
@@ -11,14 +11,11 @@ using namespace Slang;
namespace cuda
{
-class CommandBufferImpl
- : public ICommandBuffer
- , public CommandWriter
- , public ComObject
+class CommandBufferImpl : public ICommandBuffer, public CommandWriter, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
- ICommandBuffer* getInterface(const Guid& guid);
+ ICommandBuffer* getInterface(const Guid& guid);
public:
DeviceImpl* m_device;
@@ -33,11 +30,11 @@ public:
IRenderCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
+ encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
+ encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
+ encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL close() override {}
diff --git a/tools/gfx/cuda/cuda-command-encoder.cpp b/tools/gfx/cuda/cuda-command-encoder.cpp
index d94b40e21..1f4afcc5c 100644
--- a/tools/gfx/cuda/cuda-command-encoder.cpp
+++ b/tools/gfx/cuda/cuda-command-encoder.cpp
@@ -13,7 +13,7 @@ namespace cuda
{
void ResourceCommandEncoderImpl::init(CommandBufferImpl* cmdBuffer)
-{
+{
m_writer = cmdBuffer;
}
@@ -28,13 +28,16 @@ SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::copyBuffer(
}
SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::uploadBufferData(
- IBufferResource* dst, Offset offset, Size size, void* data)
+ IBufferResource* dst,
+ Offset offset,
+ Size size,
+ void* data)
{
m_writer->uploadBufferData(dst, offset, size, data);
}
SLANG_NO_THROW void SLANG_MCALL
- ResourceCommandEncoderImpl::writeTimestamp(IQueryPool* pool, GfxIndex index)
+ResourceCommandEncoderImpl::writeTimestamp(IQueryPool* pool, GfxIndex index)
{
m_writer->writeTimestamp(pool, index);
}
@@ -159,7 +162,7 @@ SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::textureSubresourceBa
}
SLANG_NO_THROW void SLANG_MCALL
- ResourceCommandEncoderImpl::beginDebugEvent(const char* name, float rgbColor[3])
+ResourceCommandEncoderImpl::beginDebugEvent(const char* name, float rgbColor[3])
{
SLANG_UNUSED(name);
SLANG_UNUSED(rgbColor);
@@ -172,23 +175,26 @@ void ComputeCommandEncoderImpl::init(CommandBufferImpl* cmdBuffer)
}
SLANG_NO_THROW Result SLANG_MCALL
- ComputeCommandEncoderImpl::bindPipeline(IPipelineState* state, IShaderObject** outRootObject)
+ComputeCommandEncoderImpl::bindPipeline(IPipelineState* state, IShaderObject** outRootObject)
{
m_writer->setPipelineState(state);
PipelineStateBase* pipelineImpl = static_cast<PipelineStateBase*>(state);
SLANG_RETURN_ON_FAIL(m_commandBuffer->m_device->createRootShaderObject(
- pipelineImpl->m_program, m_rootObject.writeRef()));
+ pipelineImpl->m_program,
+ m_rootObject.writeRef()));
returnComPtr(outRootObject, m_rootObject);
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL
- ComputeCommandEncoderImpl::bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject)
+SLANG_NO_THROW Result SLANG_MCALL ComputeCommandEncoderImpl::bindPipelineWithRootObject(
+ IPipelineState* state,
+ IShaderObject* rootObject)
{
m_writer->setPipelineState(state);
PipelineStateBase* pipelineImpl = static_cast<PipelineStateBase*>(state);
SLANG_RETURN_ON_FAIL(m_commandBuffer->m_device->createRootShaderObject(
- pipelineImpl->m_program, m_rootObject.writeRef()));
+ pipelineImpl->m_program,
+ m_rootObject.writeRef()));
m_rootObject->copyFrom(rootObject, m_commandBuffer->m_transientHeap);
return SLANG_OK;
}
@@ -201,7 +207,7 @@ SLANG_NO_THROW Result SLANG_MCALL ComputeCommandEncoderImpl::dispatchCompute(int
}
SLANG_NO_THROW Result SLANG_MCALL
- ComputeCommandEncoderImpl::dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset)
+ComputeCommandEncoderImpl::dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset)
{
SLANG_UNIMPLEMENTED_X("dispatchComputeIndirect");
}
diff --git a/tools/gfx/cuda/cuda-command-encoder.h b/tools/gfx/cuda/cuda-command-encoder.h
index ab8aa8f8f..e845e1962 100644
--- a/tools/gfx/cuda/cuda-command-encoder.h
+++ b/tools/gfx/cuda/cuda-command-encoder.h
@@ -22,7 +22,7 @@ public:
return nullptr;
}
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject) override
+ queryInterface(SlangUUID const& uuid, void** outObject) override
{
if (auto ptr = getInterface(uuid))
{
@@ -49,20 +49,22 @@ public:
ITextureResource* const* textures,
ResourceState src,
ResourceState dst) override
- {}
+ {
+ }
virtual SLANG_NO_THROW void SLANG_MCALL bufferBarrier(
GfxCount count,
IBufferResource* const* buffers,
ResourceState src,
ResourceState dst) override
- {}
+ {
+ }
- virtual SLANG_NO_THROW void SLANG_MCALL uploadBufferData(
- IBufferResource* dst, Offset offset, Size size, void* data) override;
+ virtual SLANG_NO_THROW void SLANG_MCALL
+ uploadBufferData(IBufferResource* dst, Offset offset, Size size, void* data) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- writeTimestamp(IQueryPool* pool, GfxIndex index) override;
+ writeTimestamp(IQueryPool* pool, GfxIndex index) override;
virtual SLANG_NO_THROW void SLANG_MCALL copyTexture(
ITextureResource* dst,
@@ -120,22 +122,22 @@ public:
ResourceState src,
ResourceState dst) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- beginDebugEvent(const char* name, float rgbColor[3]) override;
+ beginDebugEvent(const char* name, float rgbColor[3]) override;
virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override {}
};
-class ComputeCommandEncoderImpl
- : public IComputeCommandEncoder
- , public ResourceCommandEncoderImpl
+class ComputeCommandEncoderImpl : public IComputeCommandEncoder, public ResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderImpl)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
return this;
return nullptr;
}
+
public:
CommandWriter* m_writer;
CommandBufferImpl* m_commandBuffer;
@@ -144,15 +146,15 @@ public:
void init(CommandBufferImpl* cmdBuffer);
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL dispatchCompute(int x, int y, int z) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
+ dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
};
} // namespace cuda
diff --git a/tools/gfx/cuda/cuda-command-queue.cpp b/tools/gfx/cuda/cuda-command-queue.cpp
index 5c6f2db26..4cc3e111d 100644
--- a/tools/gfx/cuda/cuda-command-queue.cpp
+++ b/tools/gfx/cuda/cuda-command-queue.cpp
@@ -36,7 +36,10 @@ CommandQueueImpl::~CommandQueueImpl()
}
SLANG_NO_THROW void SLANG_MCALL CommandQueueImpl::executeCommandBuffers(
- GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
+ GfxCount count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal)
{
SLANG_UNUSED(valueToSignal);
// TODO: implement fence.
@@ -55,7 +58,9 @@ SLANG_NO_THROW void SLANG_MCALL CommandQueueImpl::waitOnHost()
}
SLANG_NO_THROW Result SLANG_MCALL CommandQueueImpl::waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* waitValues)
{
return SLANG_FAIL;
}
@@ -115,8 +120,7 @@ void CommandQueueImpl::dispatchCompute(int x, int y, int z)
// stored in host memory in a CUDAEntryPointShaderObject, as expected by cuLaunchKernel.
//
auto entryPointBuffer = currentRootObject->entryPointObjects[kernelId]->getBuffer();
- auto entryPointDataSize =
- currentRootObject->entryPointObjects[kernelId]->getBufferSize();
+ auto entryPointDataSize = currentRootObject->entryPointObjects[kernelId]->getBufferSize();
void* extraOptions[] = {
CU_LAUNCH_PARAM_BUFFER_POINTER,
@@ -160,13 +164,14 @@ void CommandQueueImpl::copyBuffer(
size);
}
-void CommandQueueImpl::uploadBufferData(IBufferResource* dst, size_t offset, size_t size, void* data)
+void CommandQueueImpl::uploadBufferData(
+ IBufferResource* dst,
+ size_t offset,
+ size_t size,
+ void* data)
{
auto dstImpl = static_cast<BufferResourceImpl*>(dst);
- cuMemcpy(
- (CUdeviceptr)((uint8_t*)dstImpl->m_cudaMemory + offset),
- (CUdeviceptr)data,
- size);
+ cuMemcpy((CUdeviceptr)((uint8_t*)dstImpl->m_cudaMemory + offset), (CUdeviceptr)data, size);
}
void CommandQueueImpl::writeTimestamp(IQueryPool* pool, SlangInt index)
@@ -185,12 +190,10 @@ void CommandQueueImpl::execute(CommandBufferImpl* commandBuffer)
setPipelineState(commandBuffer->getObject<PipelineStateBase>(cmd.operands[0]));
break;
case CommandName::BindRootShaderObject:
- bindRootShaderObject(
- commandBuffer->getObject<ShaderObjectBase>(cmd.operands[0]));
+ bindRootShaderObject(commandBuffer->getObject<ShaderObjectBase>(cmd.operands[0]));
break;
case CommandName::DispatchCompute:
- dispatchCompute(
- int(cmd.operands[0]), int(cmd.operands[1]), int(cmd.operands[2]));
+ dispatchCompute(int(cmd.operands[0]), int(cmd.operands[1]), int(cmd.operands[2]));
break;
case CommandName::CopyBuffer:
copyBuffer(
diff --git a/tools/gfx/cuda/cuda-command-queue.h b/tools/gfx/cuda/cuda-command-queue.h
index 10601890e..91d73b184 100644
--- a/tools/gfx/cuda/cuda-command-queue.h
+++ b/tools/gfx/cuda/cuda-command-queue.h
@@ -1,11 +1,10 @@
// cuda-command-queue.h
#pragma once
#include "cuda-base.h"
-
#include "cuda-device.h"
+#include "cuda-helper-functions.h"
#include "cuda-pipeline-state.h"
#include "cuda-shader-object.h"
-#include "cuda-helper-functions.h"
namespace gfx
{
@@ -15,13 +14,11 @@ using namespace Slang;
namespace cuda
{
-class CommandQueueImpl
- : public ICommandQueue
- , public ComObject
+class CommandQueueImpl : public ICommandQueue, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
- ICommandQueue* getInterface(const Guid& guid);
+ ICommandQueue* getInterface(const Guid& guid);
RefPtr<ComputePipelineStateImpl> currentPipeline;
RefPtr<RootShaderObjectImpl> currentRootObject;
@@ -35,12 +32,15 @@ public:
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override { return m_desc; }
virtual SLANG_NO_THROW void SLANG_MCALL executeCommandBuffers(
- GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal) override;
+ GfxCount count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal) override;
virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ waitForFenceValuesOnDevice(GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
diff --git a/tools/gfx/cuda/cuda-device.cpp b/tools/gfx/cuda/cuda-device.cpp
index b1b582d00..8162a20b8 100644
--- a/tools/gfx/cuda/cuda-device.cpp
+++ b/tools/gfx/cuda/cuda-device.cpp
@@ -5,10 +5,10 @@
#include "cuda-command-queue.h"
#include "cuda-pipeline-state.h"
#include "cuda-query.h"
-#include "cuda-shader-object.h"
+#include "cuda-resource-views.h"
#include "cuda-shader-object-layout.h"
+#include "cuda-shader-object.h"
#include "cuda-shader-program.h"
-#include "cuda-resource-views.h"
#include "cuda-texture.h"
namespace gfx
@@ -42,7 +42,7 @@ int DeviceImpl::_calcSMCountPerMultiProcessor(int major, int minor)
{0x62, 128},
{0x70, 64},
{0x72, 64},
- {0x75, 64} };
+ {0x75, 64}};
const int sm = ((major << 4) + minor);
for (Index i = 0; i < SLANG_COUNT_OF(infos); ++i)
@@ -78,9 +78,12 @@ SlangResult DeviceImpl::_findMaxFlopsDeviceIndex(int* outDeviceIndex)
CUdevice device;
SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGet(&device, currentDevice));
int computeMode = -1, major = 0, minor = 0;
- SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGetAttribute(&computeMode, CU_DEVICE_ATTRIBUTE_COMPUTE_MODE, device));
- SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, device));
- SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, device));
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuDeviceGetAttribute(&computeMode, CU_DEVICE_ATTRIBUTE_COMPUTE_MODE, device));
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuDeviceGetAttribute(&major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, device));
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuDeviceGetAttribute(&minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, device));
// If this GPU is not running on Compute Mode prohibited,
// then we can add it to the list
@@ -96,8 +99,12 @@ SlangResult DeviceImpl::_findMaxFlopsDeviceIndex(int* outDeviceIndex)
}
int multiProcessorCount = 0, clockRate = 0;
- SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGetAttribute(&multiProcessorCount, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, device));
- SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGetAttribute(&clockRate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, device));
+ SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGetAttribute(
+ &multiProcessorCount,
+ CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT,
+ device));
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuDeviceGetAttribute(&clockRate, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, device));
uint64_t compute_perf = uint64_t(multiProcessorCount) * smPerMultiproc * clockRate;
if (compute_perf > maxComputePerf)
@@ -143,7 +150,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::initialize(const Desc& desc)
desc.extendedDescs,
SLANG_PTX,
"sm_5_1",
- makeArray(slang::PreprocessorMacroDesc{ "__CUDA_COMPUTE__", "1" }).getView()));
+ makeArray(slang::PreprocessorMacroDesc{"__CUDA_COMPUTE__", "1"}).getView()));
SLANG_RETURN_ON_FAIL(RendererBase::initialize(desc));
@@ -174,12 +181,13 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::initialize(const Desc& desc)
SLANG_CUDA_RETURN_ON_FAIL(cuDeviceGet(&m_device, m_deviceIndex));
SLANG_CUDA_RETURN_WITH_REPORT_ON_FAIL(
- cuCtxCreate(&m_context->m_context, 0, m_device), reportType);
+ cuCtxCreate(&m_context->m_context, 0, m_device),
+ reportType);
{
// Not clear how to detect half support on CUDA. For now we'll assume we have it
m_features.add("half");
-
+
// CUDA has support for realtime clock
m_features.add("realtime-clock");
@@ -193,7 +201,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::initialize(const Desc& desc)
m_info.bindingStyle = BindingStyle::CUDA;
m_info.projectionStyle = ProjectionStyle::DirectX;
m_info.apiName = "CUDA";
- static const float kIdentity[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
+ static const float kIdentity[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
::memcpy(m_info.identityProjectionMatrix, kIdentity, sizeof(kIdentity));
char deviceName[256];
cuDeviceGetName(deviceName, sizeof(deviceName), m_device);
@@ -225,7 +233,8 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::initialize(const Desc& desc)
Math::Min(
getAttribute(CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT),
getAttribute(CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH)));
- limits.maxTextureDimensionCube = getAttribute(CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_WIDTH);
+ limits.maxTextureDimensionCube =
+ getAttribute(CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACECUBEMAP_WIDTH);
limits.maxTextureArrayLayers = Math::Min(
getAttribute(CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_LAYERED_LAYERS),
getAttribute(CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_LAYERED_LAYERS));
@@ -266,47 +275,31 @@ Result DeviceImpl::getCUDAFormat(Format format, CUarray_format* outFormat)
case Format::R32G32B32_FLOAT:
case Format::R32G32_FLOAT:
case Format::R32_FLOAT:
- case Format::D32_FLOAT:
- *outFormat = CU_AD_FORMAT_FLOAT;
- return SLANG_OK;
+ case Format::D32_FLOAT: *outFormat = CU_AD_FORMAT_FLOAT; return SLANG_OK;
case Format::R16G16B16A16_FLOAT:
case Format::R16G16_FLOAT:
- case Format::R16_FLOAT:
- *outFormat = CU_AD_FORMAT_HALF;
- return SLANG_OK;
+ case Format::R16_FLOAT: *outFormat = CU_AD_FORMAT_HALF; return SLANG_OK;
case Format::R32G32B32A32_UINT:
case Format::R32G32B32_UINT:
case Format::R32G32_UINT:
- case Format::R32_UINT:
- *outFormat = CU_AD_FORMAT_UNSIGNED_INT32;
- return SLANG_OK;
+ case Format::R32_UINT: *outFormat = CU_AD_FORMAT_UNSIGNED_INT32; return SLANG_OK;
case Format::R16G16B16A16_UINT:
case Format::R16G16_UINT:
- case Format::R16_UINT:
- *outFormat = CU_AD_FORMAT_UNSIGNED_INT16;
- return SLANG_OK;
+ case Format::R16_UINT: *outFormat = CU_AD_FORMAT_UNSIGNED_INT16; return SLANG_OK;
case Format::R8G8B8A8_UINT:
case Format::R8G8_UINT:
case Format::R8_UINT:
- case Format::R8G8B8A8_UNORM:
- *outFormat = CU_AD_FORMAT_UNSIGNED_INT8;
- return SLANG_OK;
+ case Format::R8G8B8A8_UNORM: *outFormat = CU_AD_FORMAT_UNSIGNED_INT8; return SLANG_OK;
case Format::R32G32B32A32_SINT:
case Format::R32G32B32_SINT:
case Format::R32G32_SINT:
- case Format::R32_SINT:
- *outFormat = CU_AD_FORMAT_SIGNED_INT32;
- return SLANG_OK;
+ case Format::R32_SINT: *outFormat = CU_AD_FORMAT_SIGNED_INT32; return SLANG_OK;
case Format::R16G16B16A16_SINT:
case Format::R16G16_SINT:
- case Format::R16_SINT:
- *outFormat = CU_AD_FORMAT_SIGNED_INT16;
- return SLANG_OK;
+ case Format::R16_SINT: *outFormat = CU_AD_FORMAT_SIGNED_INT16; return SLANG_OK;
case Format::R8G8B8A8_SINT:
case Format::R8G8_SINT:
- case Format::R8_SINT:
- *outFormat = CU_AD_FORMAT_SIGNED_INT8;
- return SLANG_OK;
+ case Format::R8_SINT: *outFormat = CU_AD_FORMAT_SIGNED_INT8; return SLANG_OK;
default:
SLANG_ASSERT(!"Only support R32_FLOAT/R8G8B8A8_UNORM formats for now");
return SLANG_FAIL;
@@ -348,16 +341,11 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureResource(
depth = 0;
break;
- case IResource::Type::Texture2D:
- depth = 0;
- break;
+ case IResource::Type::Texture2D: depth = 0; break;
- case IResource::Type::Texture3D:
- break;
+ case IResource::Type::Texture3D: break;
- case IResource::Type::TextureCube:
- depth = 1;
- break;
+ case IResource::Type::TextureCube: depth = 1; break;
}
{
@@ -372,25 +360,25 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureResource(
switch (format)
{
case CU_AD_FORMAT_FLOAT:
- {
- elementSize = sizeof(float) * numChannels;
- break;
- }
+ {
+ elementSize = sizeof(float) * numChannels;
+ break;
+ }
case CU_AD_FORMAT_HALF:
- {
- elementSize = sizeof(uint16_t) * numChannels;
- break;
- }
+ {
+ elementSize = sizeof(uint16_t) * numChannels;
+ break;
+ }
case CU_AD_FORMAT_UNSIGNED_INT8:
- {
- elementSize = sizeof(uint8_t) * numChannels;
- break;
- }
+ {
+ elementSize = sizeof(uint8_t) * numChannels;
+ break;
+ }
default:
- {
- SLANG_ASSERT(!"Only support R32_FLOAT/R8G8B8A8_UNORM formats for now");
- return SLANG_FAIL;
- }
+ {
+ SLANG_ASSERT(!"Only support R32_FLOAT/R8G8B8A8_UNORM formats for now");
+ return SLANG_FAIL;
+ }
}
if (desc.numMipLevels > 1)
@@ -468,7 +456,8 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureResource(
SLANG_CUDA_RETURN_ON_FAIL(cuArray3DCreate(&tex->m_cudaArray, &arrayDesc));
}
- else if (desc.type == IResource::Type::Texture3D ||
+ else if (
+ desc.type == IResource::Type::Texture3D ||
desc.type == IResource::Type::TextureCube)
{
CUDA_ARRAY3D_DESCRIPTOR arrayDesc;
@@ -574,8 +563,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureResource(
{
const auto srcData = initData[mipLevel + j * desc.numMipLevels].data;
// Copy over to the workspace to make contiguous
- ::memcpy(
- workspace.begin() + faceSizeInBytes * j, srcData, faceSizeInBytes);
+ ::memcpy(workspace.begin() + faceSizeInBytes * j, srcData, faceSizeInBytes);
}
srcDataPtr = workspace.getBuffer();
@@ -590,8 +578,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureResource(
// Copy the data over to make contiguous
for (Index j = 0; j < 6; j++)
{
- const auto srcData =
- initData[mipLevel + j * desc.numMipLevels].data;
+ const auto srcData = initData[mipLevel + j * desc.numMipLevels].data;
::memcpy(
workspace.getBuffer() + faceSizeInBytes * j,
srcData,
@@ -640,44 +627,44 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureResource(
{
case IResource::Type::Texture1D:
case IResource::Type::Texture2D:
- {
- CUDA_MEMCPY2D copyParam;
- memset(&copyParam, 0, sizeof(copyParam));
- copyParam.dstMemoryType = CU_MEMORYTYPE_ARRAY;
- copyParam.dstArray = dstArray;
- copyParam.srcMemoryType = CU_MEMORYTYPE_HOST;
- copyParam.srcHost = srcDataPtr;
- copyParam.srcPitch = mipWidth * elementSize;
- copyParam.WidthInBytes = copyParam.srcPitch;
- copyParam.Height = mipHeight;
- SLANG_CUDA_RETURN_ON_FAIL(cuMemcpy2D(&copyParam));
- break;
- }
+ {
+ CUDA_MEMCPY2D copyParam;
+ memset(&copyParam, 0, sizeof(copyParam));
+ copyParam.dstMemoryType = CU_MEMORYTYPE_ARRAY;
+ copyParam.dstArray = dstArray;
+ copyParam.srcMemoryType = CU_MEMORYTYPE_HOST;
+ copyParam.srcHost = srcDataPtr;
+ copyParam.srcPitch = mipWidth * elementSize;
+ copyParam.WidthInBytes = copyParam.srcPitch;
+ copyParam.Height = mipHeight;
+ SLANG_CUDA_RETURN_ON_FAIL(cuMemcpy2D(&copyParam));
+ break;
+ }
case IResource::Type::Texture3D:
case IResource::Type::TextureCube:
- {
- CUDA_MEMCPY3D copyParam;
- memset(&copyParam, 0, sizeof(copyParam));
+ {
+ CUDA_MEMCPY3D copyParam;
+ memset(&copyParam, 0, sizeof(copyParam));
- copyParam.dstMemoryType = CU_MEMORYTYPE_ARRAY;
- copyParam.dstArray = dstArray;
+ copyParam.dstMemoryType = CU_MEMORYTYPE_ARRAY;
+ copyParam.dstArray = dstArray;
- copyParam.srcMemoryType = CU_MEMORYTYPE_HOST;
- copyParam.srcHost = srcDataPtr;
- copyParam.srcPitch = mipWidth * elementSize;
- copyParam.WidthInBytes = copyParam.srcPitch;
- copyParam.Height = mipHeight;
- copyParam.Depth = mipDepth;
+ copyParam.srcMemoryType = CU_MEMORYTYPE_HOST;
+ copyParam.srcHost = srcDataPtr;
+ copyParam.srcPitch = mipWidth * elementSize;
+ copyParam.WidthInBytes = copyParam.srcPitch;
+ copyParam.Height = mipHeight;
+ copyParam.Depth = mipDepth;
- SLANG_CUDA_RETURN_ON_FAIL(cuMemcpy3D(&copyParam));
- break;
- }
+ SLANG_CUDA_RETURN_ON_FAIL(cuMemcpy3D(&copyParam));
+ break;
+ }
default:
- {
- SLANG_ASSERT(!"Not implemented");
- break;
- }
+ {
+ SLANG_ASSERT(!"Not implemented");
+ break;
+ }
}
}
}
@@ -749,10 +736,8 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createBufferResource(
CU_MEM_ATTACH_GLOBAL));
if (initData)
{
- SLANG_CUDA_RETURN_ON_FAIL(cuMemcpy(
- (CUdeviceptr)resource->m_cudaMemory,
- (CUdeviceptr)initData,
- desc.sizeInBytes));
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuMemcpy((CUdeviceptr)resource->m_cudaMemory, (CUdeviceptr)initData, desc.sizeInBytes));
}
returnComPtr(outResource, resource);
return SLANG_OK;
@@ -786,8 +771,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createBufferFromSharedHandle(
case InteropHandleAPI::Vulkan:
externalMemoryHandleDesc.type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32;
break;
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
}
externalMemoryHandleDesc.handle.win32.handle = (void*)handle.handleValue;
externalMemoryHandleDesc.size = desc.sizeInBytes;
@@ -813,7 +797,8 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createBufferFromSharedHandle(
// Finally, we can "map" the buffer to get a device address.
void* deviceAddress;
- SLANG_CUDA_RETURN_ON_FAIL(cuExternalMemoryGetMappedBuffer((CUdeviceptr*)&deviceAddress, externalMemory, &bufferDesc));
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuExternalMemoryGetMappedBuffer((CUdeviceptr*)&deviceAddress, externalMemory, &bufferDesc));
resource->m_cudaMemory = deviceAddress;
returnComPtr(outResource, resource);
@@ -849,8 +834,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureFromSharedHandle(
case InteropHandleAPI::Vulkan:
externalMemoryHandleDesc.type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32;
break;
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
}
externalMemoryHandleDesc.handle.win32.handle = (void*)handle.handleValue;
externalMemoryHandleDesc.size = size;
@@ -877,7 +861,8 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureFromSharedHandle(
externalMemoryMipDesc.numLevels = desc.numMipLevels;
CUmipmappedArray mipArray;
- SLANG_CUDA_RETURN_ON_FAIL(cuExternalMemoryGetMappedMipmappedArray(&mipArray, externalMemory, &externalMemoryMipDesc));
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuExternalMemoryGetMappedMipmappedArray(&mipArray, externalMemory, &externalMemoryMipDesc));
resource->m_cudaMipMappedArray = mipArray;
CUarray cuArray;
@@ -898,7 +883,9 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureFromSharedHandle(
}
SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTextureView(
- ITextureResource* texture, IResourceView::Desc const& desc, IResourceView** outView)
+ ITextureResource* texture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView)
{
RefPtr<ResourceViewImpl> view = new ResourceViewImpl();
view->m_desc = desc;
@@ -920,9 +907,8 @@ 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 IQueryPool::Desc& desc, IQueryPool** outPool)
{
RefPtr<QueryPoolImpl> pool = new QueryPoolImpl();
SLANG_RETURN_ON_FAIL(pool->init(desc));
@@ -941,9 +927,7 @@ Result DeviceImpl::createShaderObjectLayout(
return SLANG_OK;
}
-Result DeviceImpl::createShaderObject(
- ShaderObjectLayoutBase* layout,
- IShaderObject** outObject)
+Result DeviceImpl::createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
{
RefPtr<ShaderObjectImpl> result = new ShaderObjectImpl();
SLANG_RETURN_ON_FAIL(result->init(this, dynamic_cast<ShaderObjectLayoutImpl*>(layout)));
@@ -985,15 +969,20 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createProgram(
cudaProgram->cudaContext = m_context;
if (desc.slangGlobalScope->getSpecializationParamCount() != 0)
{
- cudaProgram->layout = new RootShaderObjectLayoutImpl(this, desc.slangGlobalScope->getLayout());
+ cudaProgram->layout =
+ new RootShaderObjectLayoutImpl(this, desc.slangGlobalScope->getLayout());
returnComPtr(outProgram, cudaProgram);
return SLANG_OK;
}
ComPtr<ISlangBlob> kernelCode;
ComPtr<ISlangBlob> diagnostics;
- auto compileResult = getEntryPointCodeFromShaderCache(desc.slangGlobalScope,
- (SlangInt)0, 0, kernelCode.writeRef(), diagnostics.writeRef());
+ auto compileResult = getEntryPointCodeFromShaderCache(
+ desc.slangGlobalScope,
+ (SlangInt)0,
+ 0,
+ kernelCode.writeRef(),
+ diagnostics.writeRef());
if (diagnostics)
{
getDebugCallback()->handleMessage(
@@ -1005,10 +994,14 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createProgram(
}
SLANG_RETURN_ON_FAIL(compileResult);
- SLANG_CUDA_RETURN_ON_FAIL(cuModuleLoadData(&cudaProgram->cudaModule, kernelCode->getBufferPointer()));
- cudaProgram->kernelName = desc.slangGlobalScope->getLayout()->getEntryPointByIndex(0)->getName();
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuModuleLoadData(&cudaProgram->cudaModule, kernelCode->getBufferPointer()));
+ cudaProgram->kernelName =
+ desc.slangGlobalScope->getLayout()->getEntryPointByIndex(0)->getName();
SLANG_CUDA_RETURN_ON_FAIL(cuModuleGetFunction(
- &cudaProgram->cudaKernel, cudaProgram->cudaModule, cudaProgram->kernelName.getBuffer()));
+ &cudaProgram->cudaKernel,
+ cudaProgram->cudaModule,
+ cudaProgram->kernelName.getBuffer()));
auto slangGlobalScope = desc.slangGlobalScope;
if (slangGlobalScope)
@@ -1030,7 +1023,8 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createProgram(
}
SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState)
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState)
{
RefPtr<ComputePipelineStateImpl> state = new ComputePipelineStateImpl();
state->shaderProgram = static_cast<ShaderProgramImpl*>(desc.program);
@@ -1065,7 +1059,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createTransientResourceHeap(
}
SLANG_NO_THROW Result SLANG_MCALL
- DeviceImpl::createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue)
+DeviceImpl::createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue)
{
RefPtr<CommandQueueImpl> queue = new CommandQueueImpl();
queue->init(this);
@@ -1074,7 +1068,9 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain)
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain)
{
SLANG_UNUSED(desc);
SLANG_UNUSED(window);
@@ -1083,7 +1079,8 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createSwapchain(
}
SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout)
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout)
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outLayout);
@@ -1091,7 +1088,7 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createFramebufferLayout(
}
SLANG_NO_THROW Result SLANG_MCALL
- DeviceImpl::createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer)
+DeviceImpl::createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer)
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outFramebuffer);
@@ -1108,16 +1105,15 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createRenderPassLayout(
}
SLANG_NO_THROW Result SLANG_MCALL
- DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler)
+DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler)
{
SLANG_UNUSED(desc);
*outSampler = nullptr;
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createInputLayout(
- IInputLayout::Desc const& desc,
- IInputLayout** outLayout)
+SLANG_NO_THROW Result SLANG_MCALL
+DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout)
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outLayout);
@@ -1125,7 +1121,8 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createInputLayout(
}
SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& desc, IPipelineState** outState)
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState)
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outState);
diff --git a/tools/gfx/cuda/cuda-device.h b/tools/gfx/cuda/cuda-device.h
index e711dc261..a21333ab6 100644
--- a/tools/gfx/cuda/cuda-device.h
+++ b/tools/gfx/cuda/cuda-device.h
@@ -1,7 +1,6 @@
// cuda-device.h
#pragma once
#include "cuda-base.h"
-
#include "cuda-command-buffer.h"
#include "cuda-context.h"
#include "cuda-helper-functions.h"
@@ -32,7 +31,8 @@ private:
String m_adapterName;
public:
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeDeviceHandles(InteropHandles* outHandles) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeDeviceHandles(InteropHandles* outHandles) override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL initialize(const Desc& desc) override;
@@ -60,7 +60,9 @@ public:
ITextureResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView(
- ITextureResource* texture, IResourceView::Desc const& desc, IResourceView** outView) override;
+ ITextureResource* texture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createBufferView(
IBufferResource* buffer,
@@ -68,18 +70,16 @@ public:
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 IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual Result createShaderObjectLayout(
slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) override;
- virtual Result createShaderObject(
- ShaderObjectLayoutBase* layout,
- IShaderObject** outObject) override;
+ virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ override;
virtual Result createMutableShaderObject(
ShaderObjectLayoutBase* layout,
@@ -93,7 +93,8 @@ public:
ISlangBlob** outDiagnosticBlob) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState) override;
void* map(IBufferResource* buffer);
@@ -109,30 +110,33 @@ public:
ITransientResourceHeap** outHeap) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
+ createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override;
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
+ createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createRenderPassLayout(
const IRenderPassLayout::Desc& desc,
IRenderPassLayout** outRenderPassLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
-
- virtual SLANG_NO_THROW Result SLANG_MCALL createInputLayout(
- IInputLayout::Desc const& desc,
- IInputLayout** outLayout) override;
+ createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& desc, IPipelineState** outState) override;
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL readTextureResource(
ITextureResource* texture,
diff --git a/tools/gfx/cuda/cuda-helper-functions.cpp b/tools/gfx/cuda/cuda-helper-functions.cpp
index d478e8815..9fb69d620 100644
--- a/tools/gfx/cuda/cuda-helper-functions.cpp
+++ b/tools/gfx/cuda/cuda-helper-functions.cpp
@@ -24,7 +24,9 @@ SlangResult CUDAErrorInfo::handle() const
builder << m_errorString;
}
- getDebugCallback()->handleMessage(DebugMessageType::Error, DebugMessageSource::Driver,
+ getDebugCallback()->handleMessage(
+ DebugMessageType::Error,
+ DebugMessageSource::Driver,
builder.getUnownedSlice().begin());
// Slang::signalUnexpectedError(builder.getBuffer());
@@ -39,14 +41,14 @@ SlangResult _handleCUDAError(CUresult cuResult, const char* file, int line)
return info.handle();
}
-# ifdef RENDER_TEST_OPTIX
+#ifdef RENDER_TEST_OPTIX
static bool _isError(OptixResult result)
{
return result != OPTIX_SUCCESS;
}
-# if 1
+#if 1
static SlangResult _handleOptixError(OptixResult result, char const* file, int line)
{
fprintf(
@@ -63,8 +65,8 @@ void _optixLogCallback(unsigned int level, const char* tag, const char* message,
{
fprintf(stderr, "optix: %s (%s)\n", message, tag);
}
-# endif
-# endif
+#endif
+#endif
AdapterLUID getAdapterLUID(int deviceIndex)
{
diff --git a/tools/gfx/cuda/cuda-helper-functions.h b/tools/gfx/cuda/cuda-helper-functions.h
index 2217c727c..8474e830d 100644
--- a/tools/gfx/cuda/cuda-helper-functions.h
+++ b/tools/gfx/cuda/cuda-helper-functions.h
@@ -1,9 +1,9 @@
// cuda-helper-functions.h
#pragma once
-#include "slang-gfx.h"
-#include "cuda-base.h"
#include "../../../source/core/slang-list.h"
+#include "cuda-base.h"
+#include "slang-gfx.h"
namespace gfx
{
@@ -12,7 +12,10 @@ using namespace Slang;
#ifdef GFX_ENABLE_CUDA
namespace cuda
{
-SLANG_FORCE_INLINE bool _isError(CUresult result) { return result != 0; }
+SLANG_FORCE_INLINE bool _isError(CUresult result)
+{
+ return result != 0;
+}
// A enum used to control if errors are reported on failure of CUDA call.
enum class CUDAReportStyle
@@ -28,11 +31,9 @@ struct CUDAErrorInfo
int lineNo,
const char* errorName = nullptr,
const char* errorString = nullptr)
- : m_filePath(filePath)
- , m_lineNo(lineNo)
- , m_errorName(errorName)
- , m_errorString(errorString)
- {}
+ : m_filePath(filePath), m_lineNo(lineNo), m_errorName(errorName), m_errorString(errorString)
+ {
+ }
SlangResult handle() const;
const char* m_filePath;
@@ -45,57 +46,56 @@ struct CUDAErrorInfo
SlangResult _handleCUDAError(CUresult cuResult, const char* file, int line);
-# define SLANG_CUDA_HANDLE_ERROR(x) _handleCUDAError(x, __FILE__, __LINE__)
-
-# define SLANG_CUDA_RETURN_ON_FAIL(x) \
- { \
- auto _res = x; \
- if (_isError(_res)) \
- return SLANG_CUDA_HANDLE_ERROR(_res); \
- }
-
-# define SLANG_CUDA_RETURN_WITH_REPORT_ON_FAIL(x, r) \
- { \
- auto _res = x; \
- if (_isError(_res)) \
- { \
- return (r == CUDAReportStyle::Normal) ? SLANG_CUDA_HANDLE_ERROR(_res) \
- : SLANG_FAIL; \
- } \
- }
-
-# define SLANG_CUDA_ASSERT_ON_FAIL(x) \
- { \
- auto _res = x; \
- if (_isError(_res)) \
- { \
- SLANG_ASSERT(!"Failed CUDA call"); \
- }; \
- }
-
-# ifdef RENDER_TEST_OPTIX
+#define SLANG_CUDA_HANDLE_ERROR(x) _handleCUDAError(x, __FILE__, __LINE__)
+
+#define SLANG_CUDA_RETURN_ON_FAIL(x) \
+ { \
+ auto _res = x; \
+ if (_isError(_res)) \
+ return SLANG_CUDA_HANDLE_ERROR(_res); \
+ }
+
+#define SLANG_CUDA_RETURN_WITH_REPORT_ON_FAIL(x, r) \
+ { \
+ auto _res = x; \
+ if (_isError(_res)) \
+ { \
+ return (r == CUDAReportStyle::Normal) ? SLANG_CUDA_HANDLE_ERROR(_res) : SLANG_FAIL; \
+ } \
+ }
+
+#define SLANG_CUDA_ASSERT_ON_FAIL(x) \
+ { \
+ auto _res = x; \
+ if (_isError(_res)) \
+ { \
+ SLANG_ASSERT(!"Failed CUDA call"); \
+ }; \
+ }
+
+#ifdef RENDER_TEST_OPTIX
bool _isError(OptixResult result);
-# if 1
+#if 1
SlangResult _handleOptixError(OptixResult result, char const* file, int line);
-# define SLANG_OPTIX_HANDLE_ERROR(RESULT) _handleOptixError(RESULT, __FILE__, __LINE__)
-# else
-# define SLANG_OPTIX_HANDLE_ERROR(RESULT) SLANG_FAIL
-# endif
+#define SLANG_OPTIX_HANDLE_ERROR(RESULT) _handleOptixError(RESULT, __FILE__, __LINE__)
+#else
+#define SLANG_OPTIX_HANDLE_ERROR(RESULT) SLANG_FAIL
+#endif
-# define SLANG_OPTIX_RETURN_ON_FAIL(EXPR) \
- do \
- { \
- auto _res = EXPR; \
- if (_isError(_res)) \
- return SLANG_OPTIX_HANDLE_ERROR(_res); \
- } while (0)
+#define SLANG_OPTIX_RETURN_ON_FAIL(EXPR) \
+ do \
+ { \
+ auto _res = EXPR; \
+ if (_isError(_res)) \
+ return SLANG_OPTIX_HANDLE_ERROR(_res); \
+ } while (0)
void _optixLogCallback(unsigned int level, const char* tag, const char* message, void* userData);
-# endif
+#endif
AdapterLUID getAdapterLUID(int deviceIndex);
diff --git a/tools/gfx/cuda/cuda-query.cpp b/tools/gfx/cuda/cuda-query.cpp
index 7e97699f8..a671d43fb 100644
--- a/tools/gfx/cuda/cuda-query.cpp
+++ b/tools/gfx/cuda/cuda-query.cpp
@@ -30,8 +30,8 @@ QueryPoolImpl::~QueryPoolImpl()
cuEventDestroy(m_startEvent);
}
-SLANG_NO_THROW Result SLANG_MCALL QueryPoolImpl::getResult(
- GfxIndex queryIndex, GfxCount count, uint64_t* data)
+SLANG_NO_THROW Result SLANG_MCALL
+QueryPoolImpl::getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data)
{
for (GfxIndex i = 0; i < count; i++)
{
diff --git a/tools/gfx/cuda/cuda-query.h b/tools/gfx/cuda/cuda-query.h
index db29f488d..04d7edc43 100644
--- a/tools/gfx/cuda/cuda-query.h
+++ b/tools/gfx/cuda/cuda-query.h
@@ -23,8 +23,8 @@ public:
~QueryPoolImpl();
- virtual SLANG_NO_THROW Result SLANG_MCALL getResult(
- GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
};
} // namespace cuda
diff --git a/tools/gfx/cuda/cuda-resource-views.h b/tools/gfx/cuda/cuda-resource-views.h
index 33bf557d7..b2f0441fe 100644
--- a/tools/gfx/cuda/cuda-resource-views.h
+++ b/tools/gfx/cuda/cuda-resource-views.h
@@ -1,7 +1,6 @@
// cuda-resource-views.h
#pragma once
#include "cuda-base.h"
-
#include "cuda-buffer.h"
#include "cuda-texture.h"
diff --git a/tools/gfx/cuda/cuda-shader-object-layout.cpp b/tools/gfx/cuda/cuda-shader-object-layout.cpp
index f527d78de..d00855972 100644
--- a/tools/gfx/cuda/cuda-shader-object-layout.cpp
+++ b/tools/gfx/cuda/cuda-shader-object-layout.cpp
@@ -9,7 +9,10 @@ using namespace Slang;
namespace cuda
{
-ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* layout)
+ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::TypeLayoutReflection* layout)
{
m_elementTypeLayout = _unwrapParameterGroups(layout, m_containerType);
@@ -41,7 +44,8 @@ ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::IS
// linear search over the descriptor ranges for a specific binding range.
//
auto uniformOffset = m_elementTypeLayout->getDescriptorSetDescriptorRangeIndexOffset(
- descriptorSetIndex, rangeIndexInDescriptorSet);
+ descriptorSetIndex,
+ rangeIndexInDescriptorSet);
Index baseIndex = 0;
Index subObjectIndex = 0;
@@ -79,7 +83,7 @@ ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::IS
bindingRangeInfo.uniformOffset = uniformOffset;
bindingRangeInfo.subObjectIndex = subObjectIndex;
bindingRangeInfo.isSpecializable = m_elementTypeLayout->isBindingRangeSpecializable(r);
- m_bindingRanges.add(bindingRangeInfo);
+ m_bindingRanges.add(bindingRangeInfo);
}
SlangInt subObjectRangeCount = m_elementTypeLayout->getSubObjectRangeCount();
@@ -100,8 +104,10 @@ ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::IS
RefPtr<ShaderObjectLayoutImpl> subObjectLayout;
if (slangBindingType != slang::BindingType::ExistentialValue)
{
- subObjectLayout =
- new ShaderObjectLayoutImpl(renderer, session, slangLeafTypeLayout->getElementTypeLayout());
+ subObjectLayout = new ShaderObjectLayoutImpl(
+ renderer,
+ session,
+ slangLeafTypeLayout->getElementTypeLayout());
}
SubObjectRangeInfo subObjectRange;
@@ -111,14 +117,34 @@ ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::IS
}
}
-Index ShaderObjectLayoutImpl::getResourceCount() const { return m_resourceCount; }
-Index ShaderObjectLayoutImpl::getSubObjectCount() const { return m_subObjectCount; }
-List<SubObjectRangeInfo>& ShaderObjectLayoutImpl::getSubObjectRanges() { return subObjectRanges; }
-BindingRangeInfo ShaderObjectLayoutImpl::getBindingRange(Index index) { return m_bindingRanges[index]; }
-Index ShaderObjectLayoutImpl::getBindingRangeCount() const { return m_bindingRanges.getCount(); }
+Index ShaderObjectLayoutImpl::getResourceCount() const
+{
+ return m_resourceCount;
+}
+Index ShaderObjectLayoutImpl::getSubObjectCount() const
+{
+ return m_subObjectCount;
+}
+List<SubObjectRangeInfo>& ShaderObjectLayoutImpl::getSubObjectRanges()
+{
+ return subObjectRanges;
+}
+BindingRangeInfo ShaderObjectLayoutImpl::getBindingRange(Index index)
+{
+ return m_bindingRanges[index];
+}
+Index ShaderObjectLayoutImpl::getBindingRangeCount() const
+{
+ return m_bindingRanges.getCount();
+}
-RootShaderObjectLayoutImpl::RootShaderObjectLayoutImpl(RendererBase* renderer, slang::ProgramLayout* inProgramLayout)
- : ShaderObjectLayoutImpl(renderer, inProgramLayout->getSession(), inProgramLayout->getGlobalParamsTypeLayout())
+RootShaderObjectLayoutImpl::RootShaderObjectLayoutImpl(
+ RendererBase* renderer,
+ slang::ProgramLayout* inProgramLayout)
+ : ShaderObjectLayoutImpl(
+ renderer,
+ inProgramLayout->getSession(),
+ inProgramLayout->getGlobalParamsTypeLayout())
, programLayout(inProgramLayout)
{
for (UInt i = 0; i < programLayout->getEntryPointCount(); i++)
@@ -128,7 +154,6 @@ RootShaderObjectLayoutImpl::RootShaderObjectLayoutImpl(RendererBase* renderer, s
programLayout->getSession(),
programLayout->getEntryPointByIndex(i)->getTypeLayout()));
}
-
}
int RootShaderObjectLayoutImpl::getKernelIndex(UnownedStringSlice kernelName)
diff --git a/tools/gfx/cuda/cuda-shader-object-layout.h b/tools/gfx/cuda/cuda-shader-object-layout.h
index edec0c352..4830fe975 100644
--- a/tools/gfx/cuda/cuda-shader-object-layout.h
+++ b/tools/gfx/cuda/cuda-shader-object-layout.h
@@ -50,7 +50,10 @@ public:
Index m_subObjectCount = 0;
Index m_resourceCount = 0;
- ShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* layout);
+ ShaderObjectLayoutImpl(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::TypeLayoutReflection* layout);
Index getResourceCount() const;
Index getSubObjectCount() const;
diff --git a/tools/gfx/cuda/cuda-shader-object.cpp b/tools/gfx/cuda/cuda-shader-object.cpp
index 02b4cf695..e7033e403 100644
--- a/tools/gfx/cuda/cuda-shader-object.cpp
+++ b/tools/gfx/cuda/cuda-shader-object.cpp
@@ -1,10 +1,9 @@
// cuda-shader-object.cpp
#include "cuda-shader-object.h"
-#include "cuda-shader-object-layout.h"
-#include "cuda-resource-views.h"
-
#include "cuda-helper-functions.h"
+#include "cuda-resource-views.h"
+#include "cuda-shader-object-layout.h"
namespace gfx
{
@@ -37,7 +36,8 @@ Result ShaderObjectData::setCount(Index count)
m_bufferResource = new BufferResourceImpl(desc);
if (count)
{
- SLANG_CUDA_RETURN_ON_FAIL(cuMemAlloc((CUdeviceptr*)&m_bufferResource->m_cudaMemory, (size_t)count));
+ SLANG_CUDA_RETURN_ON_FAIL(
+ cuMemAlloc((CUdeviceptr*)&m_bufferResource->m_cudaMemory, (size_t)count));
}
IResourceView::Desc viewDesc = {};
viewDesc.type = IResourceView::Type::UnorderedAccess;
@@ -167,7 +167,7 @@ SLANG_NO_THROW GfxCount SLANG_MCALL ShaderObjectImpl::getEntryPointCount()
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
+ShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
{
*outEntryPoint = nullptr;
return SLANG_OK;
@@ -184,7 +184,7 @@ SLANG_NO_THROW Size SLANG_MCALL ShaderObjectImpl::getSize()
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setData(ShaderOffset const& offset, void const* data, Size size)
+ShaderObjectImpl::setData(ShaderOffset const& offset, void const* data, Size size)
{
Size temp = m_data.getCount() - (Size)offset.uniformOffset;
size = Math::Min(size, temp);
@@ -196,7 +196,7 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* resourceView)
+ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* resourceView)
{
if (!resourceView)
return SLANG_OK;
@@ -255,7 +255,7 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setObject(ShaderOffset const& offset, IShaderObject* object)
+ShaderObjectImpl::setObject(ShaderOffset const& offset, IShaderObject* object)
{
SLANG_RETURN_ON_FAIL(Super::setObject(offset, object));
@@ -266,21 +266,20 @@ SLANG_NO_THROW Result SLANG_MCALL
switch (bindingRange.bindingType)
{
default:
- {
- void* subObjectDataBuffer = subObject->getBuffer();
- SLANG_RETURN_ON_FAIL(setData(offset, &subObjectDataBuffer, sizeof(void*)));
- }
- break;
+ {
+ void* subObjectDataBuffer = subObject->getBuffer();
+ SLANG_RETURN_ON_FAIL(setData(offset, &subObjectDataBuffer, sizeof(void*)));
+ }
+ break;
case slang::BindingType::ExistentialValue:
case slang::BindingType::RawBuffer:
- case slang::BindingType::MutableRawBuffer:
- break;
+ case slang::BindingType::MutableRawBuffer: break;
}
return SLANG_OK;
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* sampler)
+ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* sampler)
{
SLANG_UNUSED(sampler);
SLANG_UNUSED(offset);
@@ -288,7 +287,9 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL ShaderObjectImpl::setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler)
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler)
{
SLANG_UNUSED(sampler);
setResource(offset, textureView);
@@ -329,7 +330,7 @@ SLANG_NO_THROW GfxCount SLANG_MCALL RootShaderObjectImpl::getEntryPointCount()
}
SLANG_NO_THROW Result SLANG_MCALL
- RootShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
+RootShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
{
returnComPtr(outEntryPoint, entryPointObjects[index]);
return SLANG_OK;
diff --git a/tools/gfx/cuda/cuda-shader-object.h b/tools/gfx/cuda/cuda-shader-object.h
index f564f5eb5..c1c00a821 100644
--- a/tools/gfx/cuda/cuda-shader-object.h
+++ b/tools/gfx/cuda/cuda-shader-object.h
@@ -1,7 +1,6 @@
// cuda-shader-object.h
#pragma once
#include "cuda-base.h"
-
#include "cuda-buffer.h"
#include "cuda-resource-views.h"
@@ -35,37 +34,40 @@ public:
class ShaderObjectImpl
: public ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, ShaderObjectData>
{
- typedef ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, ShaderObjectData>
- Super;
+ typedef ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, ShaderObjectData> Super;
public:
List<RefPtr<ResourceViewImpl>> resources;
virtual SLANG_NO_THROW Result SLANG_MCALL
- init(IDevice* device, ShaderObjectLayoutImpl* typeLayout);
+ init(IDevice* device, ShaderObjectLayoutImpl* typeLayout);
virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override;
virtual SLANG_NO_THROW Size SLANG_MCALL getSize() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& offset, void const* data, Size size) override;
+ setData(ShaderOffset const& offset, void const* data, Size size) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setObject(ShaderOffset const& offset, IShaderObject* object) override;
+ setObject(ShaderOffset const& offset, IShaderObject* object) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) override;
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) override;
};
-class MutableShaderObjectImpl : public MutableShaderObject< MutableShaderObjectImpl, ShaderObjectLayoutImpl>
-{};
+class MutableShaderObjectImpl
+ : public MutableShaderObject<MutableShaderObjectImpl, ShaderObjectLayoutImpl>
+{
+};
class EntryPointShaderObjectImpl : public ShaderObjectImpl
{
@@ -78,13 +80,14 @@ class RootShaderObjectImpl : public ShaderObjectImpl
public:
virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override;
virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override;
+
public:
List<RefPtr<EntryPointShaderObjectImpl>> entryPointObjects;
virtual SLANG_NO_THROW Result SLANG_MCALL
- init(IDevice* device, ShaderObjectLayoutImpl* typeLayout) override;
+ init(IDevice* device, ShaderObjectLayoutImpl* typeLayout) override;
virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) override;
};
diff --git a/tools/gfx/cuda/cuda-shader-program.h b/tools/gfx/cuda/cuda-shader-program.h
index b0961bfc3..3f6117254 100644
--- a/tools/gfx/cuda/cuda-shader-program.h
+++ b/tools/gfx/cuda/cuda-shader-program.h
@@ -1,7 +1,6 @@
// cuda-shader-program.h
#pragma once
#include "cuda-base.h"
-
#include "cuda-context.h"
#include "cuda-shader-object-layout.h"
diff --git a/tools/gfx/cuda/cuda-texture.h b/tools/gfx/cuda/cuda-texture.h
index c9cc8569a..4af2b323b 100644
--- a/tools/gfx/cuda/cuda-texture.h
+++ b/tools/gfx/cuda/cuda-texture.h
@@ -1,7 +1,6 @@
// cuda-texture.h
#pragma once
#include "cuda-base.h"
-
#include "cuda-context.h"
namespace gfx
@@ -17,7 +16,8 @@ class TextureResourceImpl : public TextureResource
public:
TextureResourceImpl(const TextureResource::Desc& desc)
: TextureResource(desc)
- {}
+ {
+ }
~TextureResourceImpl();
uint64_t getBindlessHandle();
@@ -36,7 +36,8 @@ public:
RefPtr<CUDAContext> m_cudaContext;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeResourceHandle(InteropHandle* outHandle) override;
};
} // namespace cuda
diff --git a/tools/gfx/d3d/d3d-swapchain.h b/tools/gfx/d3d/d3d-swapchain.h
index c9e0de82a..49a4f1c99 100644
--- a/tools/gfx/d3d/d3d-swapchain.h
+++ b/tools/gfx/d3d/d3d-swapchain.h
@@ -1,16 +1,15 @@
#pragma once
-#include "slang-gfx.h"
-#include "core/slang-basic.h"
-#include <dxgi1_4.h>
#include "../renderer-shared.h"
+#include "core/slang-basic.h"
#include "d3d-util.h"
+#include "slang-gfx.h"
+
+#include <dxgi1_4.h>
namespace gfx
{
-class D3DSwapchainBase
- : public ISwapchain
- , public Slang::ComObject
+class D3DSwapchainBase : public ISwapchain, public Slang::ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -27,10 +26,8 @@ public:
// Return fail on non-supported platforms.
switch (window.type)
{
- case WindowHandle::Type::Win32Handle:
- break;
- default:
- return SLANG_FAIL;
+ case WindowHandle::Type::Win32Handle: break;
+ default: return SLANG_FAIL;
}
m_desc = desc;
@@ -60,9 +57,12 @@ public:
{
ComPtr<IDXGISwapChain> swapChain;
SLANG_RETURN_ON_FAIL(getDXGIFactory()->CreateSwapChain(
- getOwningDevice(), &swapChainDesc, swapChain.writeRef()));
+ getOwningDevice(),
+ &swapChainDesc,
+ swapChain.writeRef()));
SLANG_RETURN_ON_FAIL(getDXGIFactory()->MakeWindowAssociation(
- (HWND)window.handleValues[0], DXGI_MWA_NO_ALT_ENTER));
+ (HWND)window.handleValues[0],
+ DXGI_MWA_NO_ALT_ENTER));
SLANG_RETURN_ON_FAIL(swapChain->QueryInterface(m_swapChain.writeRef()));
}
else
@@ -92,7 +92,7 @@ public:
}
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override { return m_desc; }
virtual SLANG_NO_THROW Result SLANG_MCALL
- getImage(GfxIndex index, ITextureResource** outResource) override
+ getImage(GfxIndex index, ITextureResource** outResource) override
{
returnComPtr(outResource, m_images[index]);
return SLANG_OK;
@@ -126,17 +126,17 @@ public:
{
if (width == m_desc.width && height == m_desc.height)
return SLANG_OK;
-
+
m_desc.width = width;
m_desc.height = height;
for (auto& image : m_images)
image = nullptr;
m_images.clear();
auto result = m_swapChain->ResizeBuffers(
- m_desc.imageCount,
- width,
- height,
- D3DUtil::getMapFormat(m_desc.format),
+ m_desc.imageCount,
+ width,
+ height,
+ D3DUtil::getMapFormat(m_desc.format),
m_desc.enableVSync ? 0 : DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT);
if (result != 0)
return SLANG_FAIL;
@@ -153,4 +153,4 @@ public:
Slang::ShortList<Slang::RefPtr<TextureResource>> m_images;
};
-}
+} // namespace gfx
diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp
index 8d76c74b3..9d32f8532 100644
--- a/tools/gfx/d3d/d3d-util.cpp
+++ b/tools/gfx/d3d/d3d-util.cpp
@@ -9,37 +9,32 @@
#endif
// We will use the C standard library just for printing error messages.
-#include <stdio.h>
-
#include "core/slang-basic.h"
#include "core/slang-platform.h"
-#ifdef GFX_NV_AFTERMATH
-# include "GFSDK_Aftermath.h"
-# include "GFSDK_Aftermath_Defines.h"
-# include "GFSDK_Aftermath_GpuCrashDump.h"
+#include <stdio.h>
-# include "core/slang-process.h"
+#ifdef GFX_NV_AFTERMATH
+#include "GFSDK_Aftermath.h"
+#include "GFSDK_Aftermath_Defines.h"
+#include "GFSDK_Aftermath_GpuCrashDump.h"
+#include "core/slang-process.h"
#endif
-namespace gfx {
+namespace gfx
+{
using namespace Slang;
-/* static */D3D_PRIMITIVE_TOPOLOGY D3DUtil::getPrimitiveTopology(PrimitiveTopology topology)
+/* static */ D3D_PRIMITIVE_TOPOLOGY D3DUtil::getPrimitiveTopology(PrimitiveTopology topology)
{
switch (topology)
{
- case PrimitiveTopology::TriangleList:
- return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
- case PrimitiveTopology::TriangleStrip:
- return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
- case PrimitiveTopology::LineList:
- return D3D_PRIMITIVE_TOPOLOGY_LINELIST;
- case PrimitiveTopology::LineStrip:
- return D3D_PRIMITIVE_TOPOLOGY_LINESTRIP;
- case PrimitiveTopology::PointList:
- return D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
- default: break;
+ case PrimitiveTopology::TriangleList: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
+ case PrimitiveTopology::TriangleStrip: return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
+ case PrimitiveTopology::LineList: return D3D_PRIMITIVE_TOPOLOGY_LINELIST;
+ case PrimitiveTopology::LineStrip: return D3D_PRIMITIVE_TOPOLOGY_LINESTRIP;
+ case PrimitiveTopology::PointList: return D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
+ default: break;
}
return D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
}
@@ -49,15 +44,11 @@ D3D12_PRIMITIVE_TOPOLOGY_TYPE D3DUtil::getPrimitiveType(PrimitiveTopology topolo
switch (topology)
{
case PrimitiveTopology::TriangleList:
- case PrimitiveTopology::TriangleStrip:
- return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
+ case PrimitiveTopology::TriangleStrip: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
case PrimitiveTopology::LineList:
- case PrimitiveTopology::LineStrip:
- return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
- case PrimitiveTopology::PointList:
- return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
- default:
- break;
+ case PrimitiveTopology::LineStrip: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
+ case PrimitiveTopology::PointList: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
+ default: break;
}
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_UNDEFINED;
}
@@ -66,16 +57,11 @@ D3D12_PRIMITIVE_TOPOLOGY_TYPE D3DUtil::getPrimitiveType(PrimitiveType type)
{
switch (type)
{
- case PrimitiveType::Point:
- return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
- case PrimitiveType::Line:
- return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
- case PrimitiveType::Triangle:
- return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
- case PrimitiveType::Patch:
- return D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH;
- default:
- break;
+ case PrimitiveType::Point: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
+ case PrimitiveType::Line: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
+ case PrimitiveType::Triangle: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
+ case PrimitiveType::Patch: return D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH;
+ default: break;
}
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_UNDEFINED;
}
@@ -84,24 +70,15 @@ D3D12_COMPARISON_FUNC D3DUtil::getComparisonFunc(ComparisonFunc func)
{
switch (func)
{
- case gfx::ComparisonFunc::Never:
- return D3D12_COMPARISON_FUNC_NEVER;
- case gfx::ComparisonFunc::Less:
- return D3D12_COMPARISON_FUNC_LESS;
- case gfx::ComparisonFunc::Equal:
- return D3D12_COMPARISON_FUNC_EQUAL;
- case gfx::ComparisonFunc::LessEqual:
- return D3D12_COMPARISON_FUNC_LESS_EQUAL;
- case gfx::ComparisonFunc::Greater:
- return D3D12_COMPARISON_FUNC_GREATER;
- case gfx::ComparisonFunc::NotEqual:
- return D3D12_COMPARISON_FUNC_NOT_EQUAL;
- case gfx::ComparisonFunc::GreaterEqual:
- return D3D12_COMPARISON_FUNC_GREATER_EQUAL;
- case gfx::ComparisonFunc::Always:
- return D3D12_COMPARISON_FUNC_ALWAYS;
- default:
- return D3D12_COMPARISON_FUNC_NEVER;
+ case gfx::ComparisonFunc::Never: return D3D12_COMPARISON_FUNC_NEVER;
+ case gfx::ComparisonFunc::Less: return D3D12_COMPARISON_FUNC_LESS;
+ case gfx::ComparisonFunc::Equal: return D3D12_COMPARISON_FUNC_EQUAL;
+ case gfx::ComparisonFunc::LessEqual: return D3D12_COMPARISON_FUNC_LESS_EQUAL;
+ case gfx::ComparisonFunc::Greater: return D3D12_COMPARISON_FUNC_GREATER;
+ case gfx::ComparisonFunc::NotEqual: return D3D12_COMPARISON_FUNC_NOT_EQUAL;
+ case gfx::ComparisonFunc::GreaterEqual: return D3D12_COMPARISON_FUNC_GREATER_EQUAL;
+ case gfx::ComparisonFunc::Always: return D3D12_COMPARISON_FUNC_ALWAYS;
+ default: return D3D12_COMPARISON_FUNC_NEVER;
}
}
@@ -109,24 +86,15 @@ static D3D12_STENCIL_OP translateStencilOp(StencilOp op)
{
switch (op)
{
- case gfx::StencilOp::Keep:
- return D3D12_STENCIL_OP_KEEP;
- case gfx::StencilOp::Zero:
- return D3D12_STENCIL_OP_ZERO;
- case gfx::StencilOp::Replace:
- return D3D12_STENCIL_OP_REPLACE;
- case gfx::StencilOp::IncrementSaturate:
- return D3D12_STENCIL_OP_INCR_SAT;
- case gfx::StencilOp::DecrementSaturate:
- return D3D12_STENCIL_OP_DECR_SAT;
- case gfx::StencilOp::Invert:
- return D3D12_STENCIL_OP_INVERT;
- case gfx::StencilOp::IncrementWrap:
- return D3D12_STENCIL_OP_INCR;
- case gfx::StencilOp::DecrementWrap:
- return D3D12_STENCIL_OP_DECR;
- default:
- return D3D12_STENCIL_OP_KEEP;
+ case gfx::StencilOp::Keep: return D3D12_STENCIL_OP_KEEP;
+ case gfx::StencilOp::Zero: return D3D12_STENCIL_OP_ZERO;
+ case gfx::StencilOp::Replace: return D3D12_STENCIL_OP_REPLACE;
+ case gfx::StencilOp::IncrementSaturate: return D3D12_STENCIL_OP_INCR_SAT;
+ case gfx::StencilOp::DecrementSaturate: return D3D12_STENCIL_OP_DECR_SAT;
+ case gfx::StencilOp::Invert: return D3D12_STENCIL_OP_INVERT;
+ case gfx::StencilOp::IncrementWrap: return D3D12_STENCIL_OP_INCR;
+ case gfx::StencilOp::DecrementWrap: return D3D12_STENCIL_OP_DECR;
+ default: return D3D12_STENCIL_OP_KEEP;
}
}
@@ -140,188 +108,189 @@ D3D12_DEPTH_STENCILOP_DESC D3DUtil::translateStencilOpDesc(DepthStencilOpDesc de
return rs;
}
-/* static */DXGI_FORMAT D3DUtil::getMapFormat(Format format)
+/* static */ DXGI_FORMAT D3DUtil::getMapFormat(Format format)
{
switch (format)
{
- case Format::R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS;
- case Format::R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS;
- case Format::R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS;
- case Format::R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS;
-
- case Format::R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS;
- case Format::R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS;
- case Format::R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS;
-
- case Format::R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS;
- case Format::R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS;
- case Format::R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS;
- case Format::B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_TYPELESS;
-
- case Format::R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT;
- case Format::R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT;
- case Format::R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT;
- case Format::R32_FLOAT: return DXGI_FORMAT_R32_FLOAT;
-
- case Format::R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
- case Format::R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT;
- case Format::R16_FLOAT: return DXGI_FORMAT_R16_FLOAT;
-
- case Format::R64_UINT: return DXGI_FORMAT_R32G32_UINT;
-
- case Format::R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT;
- case Format::R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT;
- case Format::R32G32_UINT: return DXGI_FORMAT_R32G32_UINT;
- case Format::R32_UINT: return DXGI_FORMAT_R32_UINT;
-
- case Format::R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
- case Format::R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
- case Format::R16_UINT: return DXGI_FORMAT_R16_UINT;
-
- case Format::R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
- case Format::R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
- case Format::R8_UINT: return DXGI_FORMAT_R8_UINT;
-
- case Format::R64_SINT: return DXGI_FORMAT_R32G32_SINT;
-
- case Format::R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT;
- case Format::R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT;
- case Format::R32G32_SINT: return DXGI_FORMAT_R32G32_SINT;
- case Format::R32_SINT: return DXGI_FORMAT_R32_SINT;
-
- case Format::R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT;
- case Format::R16G16_SINT: return DXGI_FORMAT_R16G16_SINT;
- case Format::R16_SINT: return DXGI_FORMAT_R16_SINT;
-
- case Format::R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT;
- case Format::R8G8_SINT: return DXGI_FORMAT_R8G8_SINT;
- case Format::R8_SINT: return DXGI_FORMAT_R8_SINT;
-
- case Format::R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
- case Format::R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM;
- case Format::R16_UNORM: return DXGI_FORMAT_R16_UNORM;
-
- case Format::R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
- case Format::R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
- 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;
- case Format::R16_SNORM: return DXGI_FORMAT_R16_SNORM;
-
- case Format::R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM;
- case Format::R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM;
- case Format::R8_SNORM: return DXGI_FORMAT_R8_SNORM;
-
- case Format::D32_FLOAT: return DXGI_FORMAT_D32_FLOAT;
- case Format::D16_UNORM: return DXGI_FORMAT_D16_UNORM;
- case Format::D32_FLOAT_S8_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
- case Format::R32_FLOAT_X32_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
-
- case Format::B4G4R4A4_UNORM: return DXGI_FORMAT_B4G4R4A4_UNORM;
- case Format::B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM;
- case Format::B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM;
-
- case Format::R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
- case Format::R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS;
- case Format::R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT;
- case Format::R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM;
- case Format::R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT;
-
- case Format::BC1_UNORM: return DXGI_FORMAT_BC1_UNORM;
- case Format::BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB;
- case Format::BC2_UNORM: return DXGI_FORMAT_BC2_UNORM;
- case Format::BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB;
- case Format::BC3_UNORM: return DXGI_FORMAT_BC3_UNORM;
- case Format::BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB;
- case Format::BC4_UNORM: return DXGI_FORMAT_BC4_UNORM;
- case Format::BC4_SNORM: return DXGI_FORMAT_BC4_SNORM;
- case Format::BC5_UNORM: return DXGI_FORMAT_BC5_UNORM;
- case Format::BC5_SNORM: return DXGI_FORMAT_BC5_SNORM;
- case Format::BC6H_UF16: return DXGI_FORMAT_BC6H_UF16;
- case Format::BC6H_SF16: return DXGI_FORMAT_BC6H_SF16;
- case Format::BC7_UNORM: return DXGI_FORMAT_BC7_UNORM;
- case Format::BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB;
-
- default: return DXGI_FORMAT_UNKNOWN;
- }
-}
-
-/* static */DXGI_FORMAT D3DUtil::calcResourceFormat(UsageType usage, Int usageFlags, DXGI_FORMAT format)
+ case Format::R32G32B32A32_TYPELESS: return DXGI_FORMAT_R32G32B32A32_TYPELESS;
+ case Format::R32G32B32_TYPELESS: return DXGI_FORMAT_R32G32B32_TYPELESS;
+ case Format::R32G32_TYPELESS: return DXGI_FORMAT_R32G32_TYPELESS;
+ case Format::R32_TYPELESS: return DXGI_FORMAT_R32_TYPELESS;
+
+ case Format::R16G16B16A16_TYPELESS: return DXGI_FORMAT_R16G16B16A16_TYPELESS;
+ case Format::R16G16_TYPELESS: return DXGI_FORMAT_R16G16_TYPELESS;
+ case Format::R16_TYPELESS: return DXGI_FORMAT_R16_TYPELESS;
+
+ case Format::R8G8B8A8_TYPELESS: return DXGI_FORMAT_R8G8B8A8_TYPELESS;
+ case Format::R8G8_TYPELESS: return DXGI_FORMAT_R8G8_TYPELESS;
+ case Format::R8_TYPELESS: return DXGI_FORMAT_R8_TYPELESS;
+ case Format::B8G8R8A8_TYPELESS: return DXGI_FORMAT_B8G8R8A8_TYPELESS;
+
+ case Format::R32G32B32A32_FLOAT: return DXGI_FORMAT_R32G32B32A32_FLOAT;
+ case Format::R32G32B32_FLOAT: return DXGI_FORMAT_R32G32B32_FLOAT;
+ case Format::R32G32_FLOAT: return DXGI_FORMAT_R32G32_FLOAT;
+ case Format::R32_FLOAT: return DXGI_FORMAT_R32_FLOAT;
+
+ case Format::R16G16B16A16_FLOAT: return DXGI_FORMAT_R16G16B16A16_FLOAT;
+ case Format::R16G16_FLOAT: return DXGI_FORMAT_R16G16_FLOAT;
+ case Format::R16_FLOAT: return DXGI_FORMAT_R16_FLOAT;
+
+ case Format::R64_UINT: return DXGI_FORMAT_R32G32_UINT;
+
+ case Format::R32G32B32A32_UINT: return DXGI_FORMAT_R32G32B32A32_UINT;
+ case Format::R32G32B32_UINT: return DXGI_FORMAT_R32G32B32_UINT;
+ case Format::R32G32_UINT: return DXGI_FORMAT_R32G32_UINT;
+ case Format::R32_UINT: return DXGI_FORMAT_R32_UINT;
+
+ case Format::R16G16B16A16_UINT: return DXGI_FORMAT_R16G16B16A16_UINT;
+ case Format::R16G16_UINT: return DXGI_FORMAT_R16G16_UINT;
+ case Format::R16_UINT: return DXGI_FORMAT_R16_UINT;
+
+ case Format::R8G8B8A8_UINT: return DXGI_FORMAT_R8G8B8A8_UINT;
+ case Format::R8G8_UINT: return DXGI_FORMAT_R8G8_UINT;
+ case Format::R8_UINT: return DXGI_FORMAT_R8_UINT;
+
+ case Format::R64_SINT: return DXGI_FORMAT_R32G32_SINT;
+
+ case Format::R32G32B32A32_SINT: return DXGI_FORMAT_R32G32B32A32_SINT;
+ case Format::R32G32B32_SINT: return DXGI_FORMAT_R32G32B32_SINT;
+ case Format::R32G32_SINT: return DXGI_FORMAT_R32G32_SINT;
+ case Format::R32_SINT: return DXGI_FORMAT_R32_SINT;
+
+ case Format::R16G16B16A16_SINT: return DXGI_FORMAT_R16G16B16A16_SINT;
+ case Format::R16G16_SINT: return DXGI_FORMAT_R16G16_SINT;
+ case Format::R16_SINT: return DXGI_FORMAT_R16_SINT;
+
+ case Format::R8G8B8A8_SINT: return DXGI_FORMAT_R8G8B8A8_SINT;
+ case Format::R8G8_SINT: return DXGI_FORMAT_R8G8_SINT;
+ case Format::R8_SINT: return DXGI_FORMAT_R8_SINT;
+
+ case Format::R16G16B16A16_UNORM: return DXGI_FORMAT_R16G16B16A16_UNORM;
+ case Format::R16G16_UNORM: return DXGI_FORMAT_R16G16_UNORM;
+ case Format::R16_UNORM: return DXGI_FORMAT_R16_UNORM;
+
+ case Format::R8G8B8A8_UNORM: return DXGI_FORMAT_R8G8B8A8_UNORM;
+ case Format::R8G8B8A8_UNORM_SRGB: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
+ 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;
+ case Format::R16_SNORM: return DXGI_FORMAT_R16_SNORM;
+
+ case Format::R8G8B8A8_SNORM: return DXGI_FORMAT_R8G8B8A8_SNORM;
+ case Format::R8G8_SNORM: return DXGI_FORMAT_R8G8_SNORM;
+ case Format::R8_SNORM: return DXGI_FORMAT_R8_SNORM;
+
+ case Format::D32_FLOAT: return DXGI_FORMAT_D32_FLOAT;
+ case Format::D16_UNORM: return DXGI_FORMAT_D16_UNORM;
+ case Format::D32_FLOAT_S8_UINT: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
+ case Format::R32_FLOAT_X32_TYPELESS: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
+
+ case Format::B4G4R4A4_UNORM: return DXGI_FORMAT_B4G4R4A4_UNORM;
+ case Format::B5G6R5_UNORM: return DXGI_FORMAT_B5G6R5_UNORM;
+ case Format::B5G5R5A1_UNORM: return DXGI_FORMAT_B5G5R5A1_UNORM;
+
+ case Format::R9G9B9E5_SHAREDEXP: return DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
+ case Format::R10G10B10A2_TYPELESS: return DXGI_FORMAT_R10G10B10A2_TYPELESS;
+ case Format::R10G10B10A2_UINT: return DXGI_FORMAT_R10G10B10A2_UINT;
+ case Format::R10G10B10A2_UNORM: return DXGI_FORMAT_R10G10B10A2_UNORM;
+ case Format::R11G11B10_FLOAT: return DXGI_FORMAT_R11G11B10_FLOAT;
+
+ case Format::BC1_UNORM: return DXGI_FORMAT_BC1_UNORM;
+ case Format::BC1_UNORM_SRGB: return DXGI_FORMAT_BC1_UNORM_SRGB;
+ case Format::BC2_UNORM: return DXGI_FORMAT_BC2_UNORM;
+ case Format::BC2_UNORM_SRGB: return DXGI_FORMAT_BC2_UNORM_SRGB;
+ case Format::BC3_UNORM: return DXGI_FORMAT_BC3_UNORM;
+ case Format::BC3_UNORM_SRGB: return DXGI_FORMAT_BC3_UNORM_SRGB;
+ case Format::BC4_UNORM: return DXGI_FORMAT_BC4_UNORM;
+ case Format::BC4_SNORM: return DXGI_FORMAT_BC4_SNORM;
+ case Format::BC5_UNORM: return DXGI_FORMAT_BC5_UNORM;
+ case Format::BC5_SNORM: return DXGI_FORMAT_BC5_SNORM;
+ case Format::BC6H_UF16: return DXGI_FORMAT_BC6H_UF16;
+ case Format::BC6H_SF16: return DXGI_FORMAT_BC6H_SF16;
+ case Format::BC7_UNORM: return DXGI_FORMAT_BC7_UNORM;
+ case Format::BC7_UNORM_SRGB: return DXGI_FORMAT_BC7_UNORM_SRGB;
+
+ default: return DXGI_FORMAT_UNKNOWN;
+ }
+}
+
+/* static */ DXGI_FORMAT
+D3DUtil::calcResourceFormat(UsageType usage, Int usageFlags, DXGI_FORMAT format)
{
SLANG_UNUSED(usage);
if (usageFlags)
{
switch (format)
{
- case DXGI_FORMAT_R32_FLOAT: /* fallthru */
- case DXGI_FORMAT_R32_UINT:
- case DXGI_FORMAT_D32_FLOAT:
+ case DXGI_FORMAT_R32_FLOAT: /* fallthru */
+ case DXGI_FORMAT_R32_UINT:
+ case DXGI_FORMAT_D32_FLOAT:
{
return DXGI_FORMAT_R32_TYPELESS;
}
- case DXGI_FORMAT_D24_UNORM_S8_UINT: return DXGI_FORMAT_R24G8_TYPELESS;
- default: break;
+ case DXGI_FORMAT_D24_UNORM_S8_UINT: return DXGI_FORMAT_R24G8_TYPELESS;
+ default: break;
}
return format;
}
return format;
}
-/* static */DXGI_FORMAT D3DUtil::calcFormat(UsageType usage, DXGI_FORMAT format)
+/* static */ DXGI_FORMAT D3DUtil::calcFormat(UsageType usage, DXGI_FORMAT format)
{
switch (usage)
{
- case USAGE_COUNT_OF:
- case USAGE_UNKNOWN:
+ case USAGE_COUNT_OF:
+ case USAGE_UNKNOWN:
{
return DXGI_FORMAT_UNKNOWN;
}
- case USAGE_DEPTH_STENCIL:
+ case USAGE_DEPTH_STENCIL:
{
switch (format)
{
- case DXGI_FORMAT_D32_FLOAT: /* fallthru */
- case DXGI_FORMAT_R32_TYPELESS:
+ case DXGI_FORMAT_D32_FLOAT: /* fallthru */
+ case DXGI_FORMAT_R32_TYPELESS:
{
return DXGI_FORMAT_D32_FLOAT;
}
- case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_D24_UNORM_S8_UINT;
- case DXGI_FORMAT_R24G8_TYPELESS: return DXGI_FORMAT_D24_UNORM_S8_UINT;
- default: break;
+ case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_D24_UNORM_S8_UINT;
+ case DXGI_FORMAT_R24G8_TYPELESS: return DXGI_FORMAT_D24_UNORM_S8_UINT;
+ default: break;
}
return format;
}
- case USAGE_TARGET:
+ case USAGE_TARGET:
{
switch (format)
{
- case DXGI_FORMAT_D32_FLOAT: /* fallthru */
- case DXGI_FORMAT_D24_UNORM_S8_UINT:
+ case DXGI_FORMAT_D32_FLOAT: /* fallthru */
+ case DXGI_FORMAT_D24_UNORM_S8_UINT:
{
return DXGI_FORMAT_UNKNOWN;
}
- case DXGI_FORMAT_R32_TYPELESS: return DXGI_FORMAT_R32_FLOAT;
- default: break;
+ case DXGI_FORMAT_R32_TYPELESS: return DXGI_FORMAT_R32_FLOAT;
+ default: break;
}
return format;
}
- case USAGE_SRV:
+ case USAGE_SRV:
{
switch (format)
{
- case DXGI_FORMAT_D32_FLOAT: /* fallthru */
- case DXGI_FORMAT_R32_TYPELESS:
+ case DXGI_FORMAT_D32_FLOAT: /* fallthru */
+ case DXGI_FORMAT_R32_TYPELESS:
{
return DXGI_FORMAT_R32_FLOAT;
}
- case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
- default: break;
+ case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
+ default: break;
}
return format;
@@ -336,101 +305,105 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
{
switch (format)
{
- case DXGI_FORMAT_R32G32B32A32_TYPELESS:
- case DXGI_FORMAT_R32G32B32_TYPELESS:
- case DXGI_FORMAT_R16G16B16A16_TYPELESS:
- case DXGI_FORMAT_R32G32_TYPELESS:
- case DXGI_FORMAT_R32G8X24_TYPELESS:
- case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
- case DXGI_FORMAT_R10G10B10A2_TYPELESS:
- case DXGI_FORMAT_R8G8B8A8_TYPELESS:
- case DXGI_FORMAT_R16G16_TYPELESS:
- case DXGI_FORMAT_R32_TYPELESS:
- case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
- case DXGI_FORMAT_R24G8_TYPELESS:
- case DXGI_FORMAT_R8G8_TYPELESS:
- case DXGI_FORMAT_R16_TYPELESS:
- case DXGI_FORMAT_R8_TYPELESS:
- case DXGI_FORMAT_BC1_TYPELESS:
- case DXGI_FORMAT_BC2_TYPELESS:
- case DXGI_FORMAT_BC3_TYPELESS:
- case DXGI_FORMAT_BC4_TYPELESS:
- case DXGI_FORMAT_BC5_TYPELESS:
- case DXGI_FORMAT_B8G8R8A8_TYPELESS:
- case DXGI_FORMAT_BC6H_TYPELESS:
- case DXGI_FORMAT_BC7_TYPELESS:
+ case DXGI_FORMAT_R32G32B32A32_TYPELESS:
+ case DXGI_FORMAT_R32G32B32_TYPELESS:
+ case DXGI_FORMAT_R16G16B16A16_TYPELESS:
+ case DXGI_FORMAT_R32G32_TYPELESS:
+ case DXGI_FORMAT_R32G8X24_TYPELESS:
+ case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS:
+ case DXGI_FORMAT_R10G10B10A2_TYPELESS:
+ case DXGI_FORMAT_R8G8B8A8_TYPELESS:
+ case DXGI_FORMAT_R16G16_TYPELESS:
+ case DXGI_FORMAT_R32_TYPELESS:
+ case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
+ case DXGI_FORMAT_R24G8_TYPELESS:
+ case DXGI_FORMAT_R8G8_TYPELESS:
+ case DXGI_FORMAT_R16_TYPELESS:
+ case DXGI_FORMAT_R8_TYPELESS:
+ case DXGI_FORMAT_BC1_TYPELESS:
+ case DXGI_FORMAT_BC2_TYPELESS:
+ case DXGI_FORMAT_BC3_TYPELESS:
+ case DXGI_FORMAT_BC4_TYPELESS:
+ case DXGI_FORMAT_BC5_TYPELESS:
+ case DXGI_FORMAT_B8G8R8A8_TYPELESS:
+ case DXGI_FORMAT_BC6H_TYPELESS:
+ case DXGI_FORMAT_BC7_TYPELESS:
{
return true;
}
- default: break;
+ default: break;
}
return false;
}
-/* static */Int D3DUtil::getNumColorChannelBits(DXGI_FORMAT fmt)
+/* static */ Int D3DUtil::getNumColorChannelBits(DXGI_FORMAT fmt)
{
switch (fmt)
{
- case DXGI_FORMAT_R32G32B32A32_TYPELESS:
- case DXGI_FORMAT_R32G32B32A32_FLOAT:
- case DXGI_FORMAT_R32G32B32A32_UINT:
- case DXGI_FORMAT_R32G32B32A32_SINT:
- case DXGI_FORMAT_R32G32B32_TYPELESS:
- case DXGI_FORMAT_R32G32B32_FLOAT:
- case DXGI_FORMAT_R32G32B32_UINT:
- case DXGI_FORMAT_R32G32B32_SINT:
+ case DXGI_FORMAT_R32G32B32A32_TYPELESS:
+ case DXGI_FORMAT_R32G32B32A32_FLOAT:
+ case DXGI_FORMAT_R32G32B32A32_UINT:
+ case DXGI_FORMAT_R32G32B32A32_SINT:
+ case DXGI_FORMAT_R32G32B32_TYPELESS:
+ case DXGI_FORMAT_R32G32B32_FLOAT:
+ case DXGI_FORMAT_R32G32B32_UINT:
+ case DXGI_FORMAT_R32G32B32_SINT:
{
return 32;
}
- case DXGI_FORMAT_R16G16B16A16_TYPELESS:
- case DXGI_FORMAT_R16G16B16A16_FLOAT:
- case DXGI_FORMAT_R16G16B16A16_UNORM:
- case DXGI_FORMAT_R16G16B16A16_UINT:
- case DXGI_FORMAT_R16G16B16A16_SNORM:
- case DXGI_FORMAT_R16G16B16A16_SINT:
+ case DXGI_FORMAT_R16G16B16A16_TYPELESS:
+ case DXGI_FORMAT_R16G16B16A16_FLOAT:
+ case DXGI_FORMAT_R16G16B16A16_UNORM:
+ case DXGI_FORMAT_R16G16B16A16_UINT:
+ case DXGI_FORMAT_R16G16B16A16_SNORM:
+ case DXGI_FORMAT_R16G16B16A16_SINT:
{
return 16;
}
- case DXGI_FORMAT_R10G10B10A2_TYPELESS:
- case DXGI_FORMAT_R10G10B10A2_UNORM:
- case DXGI_FORMAT_R10G10B10A2_UINT:
- case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
+ case DXGI_FORMAT_R10G10B10A2_TYPELESS:
+ case DXGI_FORMAT_R10G10B10A2_UNORM:
+ case DXGI_FORMAT_R10G10B10A2_UINT:
+ case DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM:
{
return 10;
}
- case DXGI_FORMAT_R8G8B8A8_TYPELESS:
- case DXGI_FORMAT_R8G8B8A8_UNORM:
- case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
- case DXGI_FORMAT_R8G8B8A8_UINT:
- case DXGI_FORMAT_R8G8B8A8_SNORM:
- case DXGI_FORMAT_R8G8B8A8_SINT:
- case DXGI_FORMAT_B8G8R8A8_UNORM:
- case DXGI_FORMAT_B8G8R8X8_UNORM:
- case DXGI_FORMAT_B8G8R8A8_TYPELESS:
- case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
- case DXGI_FORMAT_B8G8R8X8_TYPELESS:
- case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
+ case DXGI_FORMAT_R8G8B8A8_TYPELESS:
+ case DXGI_FORMAT_R8G8B8A8_UNORM:
+ case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
+ case DXGI_FORMAT_R8G8B8A8_UINT:
+ case DXGI_FORMAT_R8G8B8A8_SNORM:
+ case DXGI_FORMAT_R8G8B8A8_SINT:
+ case DXGI_FORMAT_B8G8R8A8_UNORM:
+ case DXGI_FORMAT_B8G8R8X8_UNORM:
+ case DXGI_FORMAT_B8G8R8A8_TYPELESS:
+ case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
+ case DXGI_FORMAT_B8G8R8X8_TYPELESS:
+ case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
{
return 8;
}
- case DXGI_FORMAT_B5G6R5_UNORM:
- case DXGI_FORMAT_B5G5R5A1_UNORM:
+ case DXGI_FORMAT_B5G6R5_UNORM:
+ case DXGI_FORMAT_B5G5R5A1_UNORM:
{
return 5;
}
- case DXGI_FORMAT_B4G4R4A4_UNORM:
- return 4;
+ case DXGI_FORMAT_B4G4R4A4_UNORM: return 4;
- default:
- return 0;
+ default: return 0;
}
}
// Note: this subroutine is now only used by D3D11 for generating bytecode to go into input layouts.
//
-// TODO: we can probably remove that code completely by switching to a PSO-like model across all APIs.
+// TODO: we can probably remove that code completely by switching to a PSO-like model across all
+// APIs.
//
-/* static */Result D3DUtil::compileHLSLShader(char const* sourcePath, char const* source, char const* entryPointName, char const* dxProfileName, ComPtr<ID3DBlob>& shaderBlobOut)
+/* static */ Result D3DUtil::compileHLSLShader(
+ char const* sourcePath,
+ char const* source,
+ char const* entryPointName,
+ char const* dxProfileName,
+ ComPtr<ID3DBlob>& shaderBlobOut)
{
#if !SLANG_ENABLE_DXBC_SUPPORT
return SLANG_E_NOT_IMPLEMENTED;
@@ -458,7 +431,8 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
return SLANG_FAIL;
}
- compileFunc = (pD3DCompile)SharedLibrary::findSymbolAddressByName(compilerModule, "D3DCompile");
+ compileFunc =
+ (pD3DCompile)SharedLibrary::findSymbolAddressByName(compilerModule, "D3DCompile");
if (!compileFunc)
{
fprintf(stderr, "error: failed load symbol 'D3DCompile'\n");
@@ -476,8 +450,8 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
// We will always define `__HLSL__` when compiling here, so that
// input code can react differently to being compiled as pure HLSL.
D3D_SHADER_MACRO defines[] = {
- { "__HLSL__", "1" },
- { nullptr, nullptr },
+ {"__HLSL__", "1"},
+ {nullptr, nullptr},
};
// The `D3DCompile` entry point takes a bunch of parameters, but we
@@ -485,8 +459,18 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
ComPtr<ID3DBlob> shaderBlob;
ComPtr<ID3DBlob> errorBlob;
- HRESULT hr = compileFunc(source, strlen(source), sourcePath, &defines[0], nullptr, entryPointName, dxProfileName, flags, 0,
- shaderBlob.writeRef(), errorBlob.writeRef());
+ HRESULT hr = compileFunc(
+ source,
+ strlen(source),
+ sourcePath,
+ &defines[0],
+ nullptr,
+ entryPointName,
+ dxProfileName,
+ flags,
+ 0,
+ shaderBlob.writeRef(),
+ errorBlob.writeRef());
// If the HLSL-to-bytecode compilation produced any diagnostic messages
// then we will print them out (whether or not the compilation failed).
@@ -505,11 +489,12 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
#endif // SLANG_ENABLE_DXBC_SUPPORT
}
-/* static */SharedLibrary::Handle D3DUtil::getDxgiModule()
+/* static */ SharedLibrary::Handle D3DUtil::getDxgiModule()
{
const char* const libName = SLANG_ENABLE_DXVK ? "dxvk_dxgi" : "dxgi";
- static SharedLibrary::Handle s_dxgiModule = [&](){
+ static SharedLibrary::Handle s_dxgiModule = [&]()
+ {
SharedLibrary::Handle h = nullptr;
SharedLibrary::load(libName, h);
if (!h)
@@ -521,19 +506,23 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
return s_dxgiModule;
}
-/* static */SlangResult D3DUtil::createFactory(DeviceCheckFlags flags, ComPtr<IDXGIFactory>& outFactory)
+/* static */ SlangResult D3DUtil::createFactory(
+ DeviceCheckFlags flags,
+ ComPtr<IDXGIFactory>& outFactory)
{
- auto dxgiModule = getDxgiModule();
+ auto dxgiModule = getDxgiModule();
if (!dxgiModule)
{
return SLANG_FAIL;
}
- typedef HRESULT(WINAPI *PFN_DXGI_CREATE_FACTORY)(REFIID riid, void **ppFactory);
- typedef HRESULT(WINAPI *PFN_DXGI_CREATE_FACTORY_2)(UINT Flags, REFIID riid, void **ppFactory);
+ typedef HRESULT(WINAPI * PFN_DXGI_CREATE_FACTORY)(REFIID riid, void** ppFactory);
+ typedef HRESULT(WINAPI * PFN_DXGI_CREATE_FACTORY_2)(UINT Flags, REFIID riid, void** ppFactory);
{
- auto createFactory2 = (PFN_DXGI_CREATE_FACTORY_2)SharedLibrary::findSymbolAddressByName(dxgiModule, "CreateDXGIFactory2");
+ auto createFactory2 = (PFN_DXGI_CREATE_FACTORY_2)SharedLibrary::findSymbolAddressByName(
+ dxgiModule,
+ "CreateDXGIFactory2");
if (createFactory2)
{
UINT dxgiFlags = 0;
@@ -552,7 +541,9 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
}
{
- auto createFactory = (PFN_DXGI_CREATE_FACTORY)SharedLibrary::findSymbolAddressByName(dxgiModule, "CreateDXGIFactory");
+ auto createFactory = (PFN_DXGI_CREATE_FACTORY)SharedLibrary::findSymbolAddressByName(
+ dxgiModule,
+ "CreateDXGIFactory");
if (!createFactory)
{
fprintf(stderr, "error: failed load symbol '%s'\n", "CreateDXGIFactory");
@@ -562,7 +553,10 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
}
}
-/* static */SlangResult D3DUtil::findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, List<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
+/* static */ SlangResult D3DUtil::findAdapters(
+ DeviceCheckFlags flags,
+ const AdapterLUID* adapterLUID,
+ List<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
{
ComPtr<IDXGIFactory> factory;
SLANG_RETURN_ON_FAIL(createFactory(flags, factory));
@@ -579,7 +573,7 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
return luid;
}
-/* static */bool D3DUtil::isWarp(IDXGIFactory* dxgiFactory, IDXGIAdapter* adapterIn)
+/* static */ bool D3DUtil::isWarp(IDXGIFactory* dxgiFactory, IDXGIAdapter* adapterIn)
{
ComPtr<IDXGIFactory4> dxgiFactory4;
if (SLANG_SUCCEEDED(dxgiFactory->QueryInterface(IID_PPV_ARGS(dxgiFactory4.writeRef()))))
@@ -599,10 +593,8 @@ bool D3DUtil::isUAVBinding(slang::BindingType bindingType)
{
case slang::BindingType::MutableRawBuffer:
case slang::BindingType::MutableTexture:
- case slang::BindingType::MutableTypedBuffer:
- return true;
- default:
- return false;
+ case slang::BindingType::MutableTypedBuffer: return true;
+ default: return false;
}
}
@@ -636,10 +628,8 @@ uint32_t D3DUtil::getPlaneSliceCount(DXGI_FORMAT format)
switch (format)
{
case DXGI_FORMAT_D24_UNORM_S8_UINT:
- case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
- return 2;
- default:
- return 1;
+ case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return 2;
+ default: return 1;
}
}
@@ -648,28 +638,19 @@ uint32_t D3DUtil::getPlaneSlice(DXGI_FORMAT format, TextureAspect aspect)
switch (aspect)
{
case TextureAspect::Default:
- case TextureAspect::Color:
- return 0;
- case TextureAspect::Depth:
- return 0;
+ case TextureAspect::Color: return 0;
+ case TextureAspect::Depth: return 0;
case TextureAspect::Stencil:
switch (format)
{
case DXGI_FORMAT_D24_UNORM_S8_UINT:
- case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
- return 1;
- default:
- return 0;
+ case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: return 1;
+ default: return 0;
}
- case TextureAspect::Plane0:
- return 0;
- case TextureAspect::Plane1:
- return 1;
- case TextureAspect::Plane2:
- return 2;
- default:
- SLANG_ASSERT_FAILURE("Unknown texture aspect.");
- return 0;
+ case TextureAspect::Plane0: return 0;
+ case TextureAspect::Plane1: return 1;
+ case TextureAspect::Plane2: return 2;
+ default: SLANG_ASSERT_FAILURE("Unknown texture aspect."); return 0;
}
}
@@ -677,10 +658,8 @@ D3D12_INPUT_CLASSIFICATION D3DUtil::getInputSlotClass(InputSlotClass slotClass)
{
switch (slotClass)
{
- case InputSlotClass::PerVertex:
- return D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
- case InputSlotClass::PerInstance:
- return D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA;
+ case InputSlotClass::PerVertex: return D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
+ case InputSlotClass::PerInstance: return D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA;
default:
SLANG_ASSERT_FAILURE("Unknown input slot class.");
return D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
@@ -691,13 +670,9 @@ D3D12_FILL_MODE D3DUtil::getFillMode(FillMode mode)
{
switch (mode)
{
- case FillMode::Solid:
- return D3D12_FILL_MODE_SOLID;
- case FillMode::Wireframe:
- return D3D12_FILL_MODE_WIREFRAME;
- default:
- SLANG_ASSERT_FAILURE("Unknown fill mode.");
- return D3D12_FILL_MODE_SOLID;
+ case FillMode::Solid: return D3D12_FILL_MODE_SOLID;
+ case FillMode::Wireframe: return D3D12_FILL_MODE_WIREFRAME;
+ default: SLANG_ASSERT_FAILURE("Unknown fill mode."); return D3D12_FILL_MODE_SOLID;
}
}
@@ -705,15 +680,10 @@ D3D12_CULL_MODE D3DUtil::getCullMode(CullMode mode)
{
switch (mode)
{
- case CullMode::None:
- return D3D12_CULL_MODE_NONE;
- case CullMode::Front:
- return D3D12_CULL_MODE_FRONT;
- case CullMode::Back:
- return D3D12_CULL_MODE_BACK;
- default:
- SLANG_ASSERT_FAILURE("Unknown cull mode.");
- return D3D12_CULL_MODE_NONE;
+ case CullMode::None: return D3D12_CULL_MODE_NONE;
+ case CullMode::Front: return D3D12_CULL_MODE_FRONT;
+ case CullMode::Back: return D3D12_CULL_MODE_BACK;
+ default: SLANG_ASSERT_FAILURE("Unknown cull mode."); return D3D12_CULL_MODE_NONE;
}
}
@@ -721,19 +691,12 @@ D3D12_BLEND_OP D3DUtil::getBlendOp(BlendOp op)
{
switch (op)
{
- case BlendOp::Add:
- return D3D12_BLEND_OP_ADD;
- case BlendOp::Subtract:
- return D3D12_BLEND_OP_SUBTRACT;
- case BlendOp::ReverseSubtract:
- return D3D12_BLEND_OP_REV_SUBTRACT;
- case BlendOp::Min:
- return D3D12_BLEND_OP_MIN;
- case BlendOp::Max:
- return D3D12_BLEND_OP_MAX;
- default:
- SLANG_ASSERT_FAILURE("Unknown blend op.");
- return D3D12_BLEND_OP_ADD;
+ case BlendOp::Add: return D3D12_BLEND_OP_ADD;
+ case BlendOp::Subtract: return D3D12_BLEND_OP_SUBTRACT;
+ case BlendOp::ReverseSubtract: return D3D12_BLEND_OP_REV_SUBTRACT;
+ case BlendOp::Min: return D3D12_BLEND_OP_MIN;
+ case BlendOp::Max: return D3D12_BLEND_OP_MAX;
+ default: SLANG_ASSERT_FAILURE("Unknown blend op."); return D3D12_BLEND_OP_ADD;
}
}
@@ -741,43 +704,24 @@ D3D12_BLEND D3DUtil::getBlendFactor(BlendFactor factor)
{
switch (factor)
{
- case BlendFactor::Zero:
- return D3D12_BLEND_ZERO;
- case BlendFactor::One:
- return D3D12_BLEND_ONE;
- case BlendFactor::SrcColor:
- return D3D12_BLEND_SRC_COLOR;
- case BlendFactor::InvSrcColor:
- return D3D12_BLEND_INV_SRC_COLOR;
- case BlendFactor::SrcAlpha:
- return D3D12_BLEND_SRC_ALPHA;
- case BlendFactor::InvSrcAlpha:
- return D3D12_BLEND_INV_SRC_ALPHA;
- case BlendFactor::DestAlpha:
- return D3D12_BLEND_DEST_ALPHA;
- case BlendFactor::InvDestAlpha:
- return D3D12_BLEND_INV_DEST_ALPHA;
- case BlendFactor::DestColor:
- return D3D12_BLEND_DEST_COLOR;
- case BlendFactor::InvDestColor:
- return D3D12_BLEND_INV_DEST_COLOR;
- case BlendFactor::SrcAlphaSaturate:
- return D3D12_BLEND_SRC_ALPHA_SAT;
- case BlendFactor::BlendColor:
- return D3D12_BLEND_BLEND_FACTOR;
- case BlendFactor::InvBlendColor:
- return D3D12_BLEND_INV_BLEND_FACTOR;
- case BlendFactor::SecondarySrcColor:
- return D3D12_BLEND_SRC1_COLOR;
- case BlendFactor::InvSecondarySrcColor:
- return D3D12_BLEND_INV_SRC1_COLOR;
- case BlendFactor::SecondarySrcAlpha:
- return D3D12_BLEND_SRC1_ALPHA;
- case BlendFactor::InvSecondarySrcAlpha:
- return D3D12_BLEND_INV_SRC1_ALPHA;
- default:
- SLANG_ASSERT_FAILURE("Unknown blend factor.");
- return D3D12_BLEND_ZERO;
+ case BlendFactor::Zero: return D3D12_BLEND_ZERO;
+ case BlendFactor::One: return D3D12_BLEND_ONE;
+ case BlendFactor::SrcColor: return D3D12_BLEND_SRC_COLOR;
+ case BlendFactor::InvSrcColor: return D3D12_BLEND_INV_SRC_COLOR;
+ case BlendFactor::SrcAlpha: return D3D12_BLEND_SRC_ALPHA;
+ case BlendFactor::InvSrcAlpha: return D3D12_BLEND_INV_SRC_ALPHA;
+ case BlendFactor::DestAlpha: return D3D12_BLEND_DEST_ALPHA;
+ case BlendFactor::InvDestAlpha: return D3D12_BLEND_INV_DEST_ALPHA;
+ case BlendFactor::DestColor: return D3D12_BLEND_DEST_COLOR;
+ case BlendFactor::InvDestColor: return D3D12_BLEND_INV_DEST_COLOR;
+ case BlendFactor::SrcAlphaSaturate: return D3D12_BLEND_SRC_ALPHA_SAT;
+ case BlendFactor::BlendColor: return D3D12_BLEND_BLEND_FACTOR;
+ case BlendFactor::InvBlendColor: return D3D12_BLEND_INV_BLEND_FACTOR;
+ case BlendFactor::SecondarySrcColor: return D3D12_BLEND_SRC1_COLOR;
+ case BlendFactor::InvSecondarySrcColor: return D3D12_BLEND_INV_SRC1_COLOR;
+ case BlendFactor::SecondarySrcAlpha: return D3D12_BLEND_SRC1_ALPHA;
+ case BlendFactor::InvSecondarySrcAlpha: return D3D12_BLEND_INV_SRC1_ALPHA;
+ default: SLANG_ASSERT_FAILURE("Unknown blend factor."); return D3D12_BLEND_ZERO;
}
}
@@ -800,55 +744,37 @@ D3D12_RESOURCE_STATES D3DUtil::getResourceState(ResourceState state)
{
switch (state)
{
- case ResourceState::Undefined:
- return D3D12_RESOURCE_STATE_COMMON;
- case ResourceState::General:
- return D3D12_RESOURCE_STATE_COMMON;
- case ResourceState::PreInitialized:
- return D3D12_RESOURCE_STATE_COMMON;
- case ResourceState::VertexBuffer:
- return D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER;
- case ResourceState::IndexBuffer:
- return D3D12_RESOURCE_STATE_INDEX_BUFFER;
- case ResourceState::ConstantBuffer:
- return D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER;
- case ResourceState::StreamOutput:
- return D3D12_RESOURCE_STATE_STREAM_OUT;
+ case ResourceState::Undefined: return D3D12_RESOURCE_STATE_COMMON;
+ case ResourceState::General: return D3D12_RESOURCE_STATE_COMMON;
+ case ResourceState::PreInitialized: return D3D12_RESOURCE_STATE_COMMON;
+ case ResourceState::VertexBuffer: return D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER;
+ case ResourceState::IndexBuffer: return D3D12_RESOURCE_STATE_INDEX_BUFFER;
+ case ResourceState::ConstantBuffer: return D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER;
+ case ResourceState::StreamOutput: return D3D12_RESOURCE_STATE_STREAM_OUT;
case ResourceState::ShaderResource:
case ResourceState::AccelerationStructureBuildInput:
- return D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
- case ResourceState::PixelShaderResource:
- return D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
+ return D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE |
+ D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE;
+ case ResourceState::PixelShaderResource: return D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
case ResourceState::NonPixelShaderResource:
return 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::IndirectArgument:
- return D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT;
- 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;
+ 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::IndirectArgument: return D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT;
+ 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;
case ResourceState::AccelerationStructure:
return D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE;
- default:
- return D3D12_RESOURCE_STATE_COMMON;
+ default: return D3D12_RESOURCE_STATE_COMMON;
}
}
-/* static */SlangResult D3DUtil::reportLiveObjects()
+/* static */ SlangResult D3DUtil::reportLiveObjects()
{
static IDXGIDebug* dxgiDebug = nullptr;
@@ -858,7 +784,8 @@ D3D12_RESOURCE_STATES D3DUtil::getResourceState(ResourceState state)
HMODULE debugModule = LoadLibraryA("dxgidebug.dll");
if (debugModule != INVALID_HANDLE_VALUE)
{
- auto fun = reinterpret_cast<decltype(&DXGIGetDebugInterface)>(GetProcAddress(debugModule, "DXGIGetDebugInterface"));
+ auto fun = reinterpret_cast<decltype(&DXGIGetDebugInterface)>(
+ GetProcAddress(debugModule, "DXGIGetDebugInterface"));
if (fun)
{
fun(__uuidof(IDXGIDebug), (void**)&dxgiDebug);
@@ -869,7 +796,8 @@ D3D12_RESOURCE_STATES D3DUtil::getResourceState(ResourceState state)
if (dxgiDebug)
{
- const GUID DXGI_DEBUG_ALL_ = { 0xe48ae283, 0xda80, 0x490b, { 0x87, 0xe6, 0x43, 0xe9, 0xa9, 0xcf, 0xda, 0x8 } };
+ const GUID DXGI_DEBUG_ALL_ =
+ {0xe48ae283, 0xda80, 0x490b, {0x87, 0xe6, 0x43, 0xe9, 0xa9, 0xcf, 0xda, 0x8}};
dxgiDebug->ReportLiveObjects(DXGI_DEBUG_ALL_, DXGI_DEBUG_RLO_ALL);
return SLANG_OK;
}
@@ -883,7 +811,7 @@ Result SLANG_MCALL reportD3DLiveObjects()
}
-/* static */SlangResult D3DUtil::waitForCrashDumpCompletion(HRESULT res)
+/* static */ SlangResult D3DUtil::waitForCrashDumpCompletion(HRESULT res)
{
// If it's not a device remove/reset then theres nothing to wait for
if (!(res == DXGI_ERROR_DEVICE_REMOVED || res == DXGI_ERROR_DEVICE_RESET))
@@ -909,8 +837,8 @@ Result SLANG_MCALL reportD3DLiveObjects()
// Loop while Aftermath crash dump data collection has not finished or
// the application is still processing the crash dump data.
while (status != GFSDK_Aftermath_CrashDump_Status_CollectingDataFailed &&
- status != GFSDK_Aftermath_CrashDump_Status_Finished &&
- Process::getClockTick() - startTick < timeOutTicks)
+ status != GFSDK_Aftermath_CrashDump_Status_Finished &&
+ Process::getClockTick() - startTick < timeOutTicks)
{
// Sleep a couple of milliseconds and poll the status again.
Process::sleepCurrentThread(50);
@@ -934,7 +862,11 @@ Result SLANG_MCALL reportD3DLiveObjects()
return SLANG_OK;
}
-/* static */SlangResult D3DUtil::findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, IDXGIFactory* dxgiFactory, List<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
+/* static */ SlangResult D3DUtil::findAdapters(
+ DeviceCheckFlags flags,
+ const AdapterLUID* adapterLUID,
+ IDXGIFactory* dxgiFactory,
+ List<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
{
outDxgiAdapters.clear();
@@ -979,7 +911,8 @@ Result SLANG_MCALL reportD3DLiveObjects()
}
// If the right type then add it
- if ((deviceFlags & DXGI_ADAPTER_FLAG_SOFTWARE) == 0 && (flags & DeviceCheckFlag::UseHardwareDevice) != 0)
+ if ((deviceFlags & DXGI_ADAPTER_FLAG_SOFTWARE) == 0 &&
+ (flags & DeviceCheckFlag::UseHardwareDevice) != 0)
{
outDxgiAdapters.add(dxgiAdapter);
}
diff --git a/tools/gfx/d3d/d3d-util.h b/tools/gfx/d3d/d3d-util.h
index ce40ec722..af186a336 100644
--- a/tools/gfx/d3d/d3d-util.h
+++ b/tools/gfx/d3d/d3d-util.h
@@ -1,52 +1,49 @@
// d3d-util.h
#pragma once
-#include <stdint.h>
-
-#include "slang-com-helper.h"
-
-#include "slang-com-ptr.h"
+#include "../flag-combiner.h"
#include "core/slang-basic.h"
#include "core/slang-platform.h"
-
-#include "../flag-combiner.h"
-
+#include "slang-com-helper.h"
+#include "slang-com-ptr.h"
#include "slang-gfx.h"
+#include <d3d12.h>
#include <d3dcommon.h>
-#include <dxgiformat.h>
#include <dxgi.h>
-#include <d3d12.h>
+#include <dxgiformat.h>
+#include <stdint.h>
#if defined(__ID3D12Device5_FWD_DEFINED__) && defined(__ID3D12GraphicsCommandList4_FWD_DEFINED__)
-# define SLANG_GFX_HAS_DXR_SUPPORT 1
+#define SLANG_GFX_HAS_DXR_SUPPORT 1
#else
-# define SLANG_GFX_HAS_DXR_SUPPORT 0
+#define SLANG_GFX_HAS_DXR_SUPPORT 0
typedef ISlangUnknown ID3D12Device5;
typedef ISlangUnknown ID3D12GraphicsCommandList4;
#endif
-namespace gfx {
+namespace gfx
+{
class D3DUtil
{
- public:
+public:
enum UsageType
{
- USAGE_UNKNOWN, ///< Generally used to mark an error
- USAGE_TARGET, ///< Format should be used when written as target
- USAGE_DEPTH_STENCIL, ///< Format should be used when written as depth stencil
- USAGE_SRV, ///< Format if being read as srv
+ USAGE_UNKNOWN, ///< Generally used to mark an error
+ USAGE_TARGET, ///< Format should be used when written as target
+ USAGE_DEPTH_STENCIL, ///< Format should be used when written as depth stencil
+ USAGE_SRV, ///< Format if being read as srv
USAGE_COUNT_OF,
};
enum UsageFlag
{
- USAGE_FLAG_MULTI_SAMPLE = 0x1, ///< If set will be used form multi sampling (such as MSAA)
- USAGE_FLAG_SRV = 0x2, ///< If set means will be used as a shader resource view (SRV)
+ USAGE_FLAG_MULTI_SAMPLE = 0x1, ///< If set will be used form multi sampling (such as MSAA)
+ USAGE_FLAG_SRV = 0x2, ///< If set means will be used as a shader resource view (SRV)
};
- /// Get primitive topology as D3D primitive topology
+ /// Get primitive topology as D3D primitive topology
static D3D_PRIMITIVE_TOPOLOGY getPrimitiveTopology(PrimitiveTopology prim);
static D3D12_PRIMITIVE_TOPOLOGY_TYPE getPrimitiveType(PrimitiveType type);
@@ -57,38 +54,58 @@ class D3DUtil
static D3D12_DEPTH_STENCILOP_DESC translateStencilOpDesc(DepthStencilOpDesc desc);
- /// Calculate size taking into account alignment. Alignment must be a power of 2
- static UInt calcAligned(UInt size, UInt alignment) { return (size + alignment - 1) & ~(alignment - 1); }
+ /// Calculate size taking into account alignment. Alignment must be a power of 2
+ static UInt calcAligned(UInt size, UInt alignment)
+ {
+ return (size + alignment - 1) & ~(alignment - 1);
+ }
- /// Compile HLSL code to DXBC
- static Slang::Result compileHLSLShader(char const* sourcePath, char const* source, char const* entryPointName, char const* dxProfileName, Slang::ComPtr<ID3DBlob>& shaderBlobOut);
+ /// Compile HLSL code to DXBC
+ static Slang::Result compileHLSLShader(
+ char const* sourcePath,
+ char const* source,
+ char const* entryPointName,
+ char const* dxProfileName,
+ Slang::ComPtr<ID3DBlob>& shaderBlobOut);
- /// Given a slang pixel format returns the equivalent DXGI_ pixel format. If the format is not known, will return DXGI_FORMAT_UNKNOWN
+ /// 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);
- /// Given the usage, flags, and format will return the most suitable format. Will return DXGI_UNKNOWN if combination is not possible
+ /// 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
+ /// Calculate appropriate format for creating a buffer for usage and flags
static DXGI_FORMAT calcResourceFormat(UsageType usage, Int usageFlags, DXGI_FORMAT format);
- /// True if the type is 'typeless'
+ /// True if the type is 'typeless'
static bool isTypeless(DXGI_FORMAT format);
- /// Returns number of bits used for color channel for format (for channels with multiple sizes, returns smallest ie RGB565 -> 5)
+ /// Returns number of bits used for color channel for format (for channels with multiple sizes,
+ /// returns smallest ie RGB565 -> 5)
static Int getNumColorChannelBits(DXGI_FORMAT fmt);
- static SlangResult createFactory(DeviceCheckFlags flags, Slang::ComPtr<IDXGIFactory>& outFactory);
+ static SlangResult createFactory(
+ DeviceCheckFlags flags,
+ Slang::ComPtr<IDXGIFactory>& outFactory);
- /// Get the dxgiModule
+ /// Get the dxgiModule
static Slang::SharedLibrary::Handle getDxgiModule();
- /// Find adapters
- static SlangResult findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, IDXGIFactory* dxgiFactory, Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
- /// Find adapters
- static SlangResult findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
+ /// Find adapters
+ static SlangResult findAdapters(
+ DeviceCheckFlags flags,
+ const AdapterLUID* adapterLUID,
+ IDXGIFactory* dxgiFactory,
+ Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
+ /// Find adapters
+ static SlangResult findAdapters(
+ DeviceCheckFlags flags,
+ const AdapterLUID* adapterLUID,
+ Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
static AdapterLUID getAdapterLUID(IDXGIAdapter* dxgiAdapter);
- /// True if the adapter is warp
+ /// True if the adapter is warp
static bool isWarp(IDXGIFactory* dxgiFactory, IDXGIAdapter* adapter);
static bool isUAVBinding(slang::BindingType bindingType);
@@ -122,8 +139,8 @@ class D3DUtil
static SlangResult reportLiveObjects();
- /// Call after a DXGI_ERROR_DEVICE_REMOVED/DXGI_ERROR_DEVICE_RESET on present, to wait for
- /// dumping to complete. Will return SLANG_OK if wait happened successfully
+ /// Call after a DXGI_ERROR_DEVICE_REMOVED/DXGI_ERROR_DEVICE_RESET on present, to wait for
+ /// dumping to complete. Will return SLANG_OK if wait happened successfully
static SlangResult waitForCrashDumpCompletion(HRESULT res);
};
@@ -138,11 +155,11 @@ struct D3DAccelerationStructureInputsBuilder
IDebugCallback* callback);
private:
- D3D12_RAYTRACING_GEOMETRY_FLAGS translateGeometryFlags(
- IAccelerationStructure::GeometryFlags::Enum flags)
+ D3D12_RAYTRACING_GEOMETRY_FLAGS
+ translateGeometryFlags(IAccelerationStructure::GeometryFlags::Enum flags)
{
return (D3D12_RAYTRACING_GEOMETRY_FLAGS)flags;
}
};
#endif
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/d3d11/d3d11-base.h b/tools/gfx/d3d11/d3d11-base.h
index ce38bb174..084654991 100644
--- a/tools/gfx/d3d11/d3d11-base.h
+++ b/tools/gfx/d3d11/d3d11-base.h
@@ -2,16 +2,15 @@
// Shared header file for D3D11 implementation
#pragma once
-#include "../immediate-renderer-base.h"
-#include "../d3d/d3d-util.h"
#include "../d3d/d3d-swapchain.h"
-#include "../nvapi/nvapi-util.h"
+#include "../d3d/d3d-util.h"
+#include "../flag-combiner.h"
+#include "../immediate-renderer-base.h"
#include "../mutable-shader-object.h"
+#include "../nvapi/nvapi-util.h"
#include "core/slang-basic.h"
#include "core/slang-blob.h"
-
#include "slang-com-ptr.h"
-#include "../flag-combiner.h"
#pragma push_macro("WIN32_LEAN_AND_MEAN")
#pragma push_macro("NOMINMAX")
@@ -30,7 +29,7 @@
// NVAPI integration is described here
// https://developer.nvidia.com/unlocking-gpu-intrinsics-hlsl
-# include "../nvapi/nvapi-include.h"
+#include "../nvapi/nvapi-include.h"
#endif
// We will use the C standard library just for printing error messages.
@@ -47,28 +46,28 @@ namespace gfx
{
namespace d3d11
{
- class DeviceImpl;
- class ShaderProgramImpl;
- class BufferResourceImpl;
- class TextureResourceImpl;
- class SamplerStateImpl;
- class ResourceViewImpl;
- class ShaderResourceViewImpl;
- class UnorderedAccessViewImpl;
- class DepthStencilViewImpl;
- class RenderTargetViewImpl;
- class FramebufferLayoutImpl;
- class FramebufferImpl;
- class SwapchainImpl;
- class InputLayoutImpl;
- class QueryPoolImpl;
- class PipelineStateImpl;
- class GraphicsPipelineStateImpl;
- class ComputePipelineStateImpl;
- class ShaderObjectLayoutImpl;
- class RootShaderObjectLayoutImpl;
- class ShaderObjectImpl;
- class MutableShaderObjectImpl;
- class RootShaderObjectImpl;
-}
-}
+class DeviceImpl;
+class ShaderProgramImpl;
+class BufferResourceImpl;
+class TextureResourceImpl;
+class SamplerStateImpl;
+class ResourceViewImpl;
+class ShaderResourceViewImpl;
+class UnorderedAccessViewImpl;
+class DepthStencilViewImpl;
+class RenderTargetViewImpl;
+class FramebufferLayoutImpl;
+class FramebufferImpl;
+class SwapchainImpl;
+class InputLayoutImpl;
+class QueryPoolImpl;
+class PipelineStateImpl;
+class GraphicsPipelineStateImpl;
+class ComputePipelineStateImpl;
+class ShaderObjectLayoutImpl;
+class RootShaderObjectLayoutImpl;
+class ShaderObjectImpl;
+class MutableShaderObjectImpl;
+class RootShaderObjectImpl;
+} // namespace d3d11
+} // namespace gfx
diff --git a/tools/gfx/d3d11/d3d11-buffer.cpp b/tools/gfx/d3d11/d3d11-buffer.cpp
index aa51b999f..42c4c698c 100644
--- a/tools/gfx/d3d11/d3d11-buffer.cpp
+++ b/tools/gfx/d3d11/d3d11-buffer.cpp
@@ -15,7 +15,7 @@ SLANG_NO_THROW DeviceAddress SLANG_MCALL BufferResourceImpl::getDeviceAddress()
}
SLANG_NO_THROW Result SLANG_MCALL
- BufferResourceImpl::map(MemoryRange* rangeToRead, void** outPointer)
+BufferResourceImpl::map(MemoryRange* rangeToRead, void** outPointer)
{
SLANG_UNUSED(rangeToRead);
SLANG_UNUSED(outPointer);
diff --git a/tools/gfx/d3d11/d3d11-buffer.h b/tools/gfx/d3d11/d3d11-buffer.h
index f5462b029..237e33fd6 100644
--- a/tools/gfx/d3d11/d3d11-buffer.h
+++ b/tools/gfx/d3d11/d3d11-buffer.h
@@ -16,8 +16,8 @@ class BufferResourceImpl : public BufferResource
public:
typedef BufferResource Parent;
- BufferResourceImpl(const IBufferResource::Desc& desc) :
- Parent(desc)
+ BufferResourceImpl(const IBufferResource::Desc& desc)
+ : Parent(desc)
{
}
@@ -29,7 +29,7 @@ public:
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- map(MemoryRange* rangeToRead, void** outPointer) override;
+ map(MemoryRange* rangeToRead, void** outPointer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override;
};
diff --git a/tools/gfx/d3d11/d3d11-device.cpp b/tools/gfx/d3d11/d3d11-device.cpp
index 148590831..8fe3bf589 100644
--- a/tools/gfx/d3d11/d3d11-device.cpp
+++ b/tools/gfx/d3d11/d3d11-device.cpp
@@ -3,23 +3,22 @@
#include "d3d11-device.h"
#include "d3d11-buffer.h"
+#include "d3d11-helper-functions.h"
#include "d3d11-query.h"
#include "d3d11-resource-views.h"
#include "d3d11-sampler.h"
#include "d3d11-scopeNVAPI.h"
-#include "d3d11-shader-object.h"
#include "d3d11-shader-object-layout.h"
+#include "d3d11-shader-object.h"
#include "d3d11-shader-program.h"
#include "d3d11-swap-chain.h"
#include "d3d11-texture.h"
#include "d3d11-vertex-layout.h"
-#include "d3d11-helper-functions.h"
-
#ifdef GFX_NV_AFTERMATH
-# include "GFSDK_Aftermath.h"
-# include "GFSDK_Aftermath_Defines.h"
-# include "GFSDK_Aftermath_GpuCrashDump.h"
+#include "GFSDK_Aftermath.h"
+#include "GFSDK_Aftermath_Defines.h"
+#include "GFSDK_Aftermath_GpuCrashDump.h"
#endif
namespace gfx
@@ -38,7 +37,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
desc.extendedDescs,
SLANG_DXBC,
"sm_5_0",
- makeArray(slang::PreprocessorMacroDesc{ "__D3D11__", "1" }).getView()));
+ makeArray(slang::PreprocessorMacroDesc{"__D3D11__", "1"}).getView()));
SLANG_RETURN_ON_FAIL(RendererBase::initialize(desc));
@@ -48,7 +47,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
m_info.bindingStyle = BindingStyle::DirectX;
m_info.projectionStyle = ProjectionStyle::DirectX;
m_info.apiName = "Direct3D 11";
- static const float kIdentity[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
+ static const float kIdentity[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
::memcpy(m_info.identityProjectionMatrix, kIdentity, sizeof(kIdentity));
}
@@ -64,20 +63,20 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
}
PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN D3D11CreateDeviceAndSwapChain_ =
- (PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN)SharedLibrary::findSymbolAddressByName(d3dModule, "D3D11CreateDeviceAndSwapChain");
+ (PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN)SharedLibrary::findSymbolAddressByName(
+ d3dModule,
+ "D3D11CreateDeviceAndSwapChain");
if (!D3D11CreateDeviceAndSwapChain_)
{
- fprintf(stderr,
- "error: failed load symbol 'D3D11CreateDeviceAndSwapChain'\n");
+ fprintf(stderr, "error: failed load symbol 'D3D11CreateDeviceAndSwapChain'\n");
return SLANG_FAIL;
}
- PFN_D3D11_CREATE_DEVICE D3D11CreateDevice_ =
- (PFN_D3D11_CREATE_DEVICE)SharedLibrary::findSymbolAddressByName(d3dModule, "D3D11CreateDevice");
+ PFN_D3D11_CREATE_DEVICE D3D11CreateDevice_ = (PFN_D3D11_CREATE_DEVICE)
+ SharedLibrary::findSymbolAddressByName(d3dModule, "D3D11CreateDevice");
if (!D3D11CreateDevice_)
{
- fprintf(stderr,
- "error: failed load symbol 'D3D11CreateDevice'\n");
+ fprintf(stderr, "error: failed load symbol 'D3D11CreateDevice'\n");
return SLANG_FAIL;
}
@@ -107,12 +106,18 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
// up to each back-end to specify.
#if _DEBUG
- combiner.add(DeviceCheckFlag::UseDebug, ChangeType::OnOff); ///< First try debug then non debug
+ combiner.add(
+ DeviceCheckFlag::UseDebug,
+ ChangeType::OnOff); ///< First try debug then non debug
#else
- combiner.add(DeviceCheckFlag::UseDebug, ChangeType::Off); ///< Don't bother with debug
+ combiner.add(DeviceCheckFlag::UseDebug, ChangeType::Off); ///< Don't bother with debug
#endif
- combiner.add(DeviceCheckFlag::UseHardwareDevice, ChangeType::OnOff); ///< First try hardware, then reference
- combiner.add(DeviceCheckFlag::UseFullFeatureLevel, ChangeType::OnOff); ///< First try fully featured, then degrade features
+ combiner.add(
+ DeviceCheckFlag::UseHardwareDevice,
+ ChangeType::OnOff); ///< First try hardware, then reference
+ combiner.add(
+ DeviceCheckFlag::UseFullFeatureLevel,
+ ChangeType::OnOff); ///< First try fully featured, then degrade features
const int numCombinations = combiner.getNumCombinations();
@@ -127,7 +132,11 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
if (desc.adapterLUID)
{
List<ComPtr<IDXGIAdapter>> dxgiAdapters;
- D3DUtil::findAdapters(deviceCheckFlags, desc.adapterLUID, m_dxgiFactory, dxgiAdapters);
+ D3DUtil::findAdapters(
+ deviceCheckFlags,
+ desc.adapterLUID,
+ m_dxgiFactory,
+ dxgiAdapters);
if (dxgiAdapters.getCount() == 0)
{
continue;
@@ -135,16 +144,21 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
adapter = dxgiAdapters[0];
}
- // The adapter can be nullptr - that just means 'default', but when so we need to select the driver type
+ // The adapter can be nullptr - that just means 'default', but when so we need to select
+ // the driver type
D3D_DRIVER_TYPE driverType = D3D_DRIVER_TYPE_UNKNOWN;
if (adapter == nullptr)
{
// If we don't have an adapter, select directly
- driverType = (deviceCheckFlags & DeviceCheckFlag::UseHardwareDevice) ? D3D_DRIVER_TYPE_HARDWARE : D3D_DRIVER_TYPE_REFERENCE;
+ driverType = (deviceCheckFlags & DeviceCheckFlag::UseHardwareDevice)
+ ? D3D_DRIVER_TYPE_HARDWARE
+ : D3D_DRIVER_TYPE_REFERENCE;
}
- const int startFeatureIndex = (deviceCheckFlags & DeviceCheckFlag::UseFullFeatureLevel) ? 0 : 1;
- const UINT deviceFlags = (deviceCheckFlags & DeviceCheckFlag::UseDebug) ? D3D11_CREATE_DEVICE_DEBUG : 0;
+ const int startFeatureIndex =
+ (deviceCheckFlags & DeviceCheckFlag::UseFullFeatureLevel) ? 0 : 1;
+ const UINT deviceFlags =
+ (deviceCheckFlags & DeviceCheckFlag::UseDebug) ? D3D11_CREATE_DEVICE_DEBUG : 0;
res = D3D11CreateDevice_(
adapter,
@@ -161,16 +175,24 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
#ifdef GFX_NV_AFTERMATH
if (SLANG_SUCCEEDED(res))
{
- if (deviceCheckFlags & DeviceCheckFlag::UseDebug)
+ if (deviceCheckFlags & DeviceCheckFlag::UseDebug)
{
// Initialize Nsight Aftermath for this device.
- // This combination of flags is not necessarily appropriate for real world usage
+ // This combination of flags is not necessarily appropriate for real world usage
const uint32_t aftermathFlags =
- GFSDK_Aftermath_FeatureFlags_EnableMarkers | // Enable event marker tracking.
- GFSDK_Aftermath_FeatureFlags_CallStackCapturing | // Enable automatic call stack event markers.
- GFSDK_Aftermath_FeatureFlags_EnableResourceTracking | // Enable tracking of resources.
- GFSDK_Aftermath_FeatureFlags_GenerateShaderDebugInfo | // Generate debug information for shaders.
- GFSDK_Aftermath_FeatureFlags_EnableShaderErrorReporting; // Enable additional runtime shader error reporting.
+ GFSDK_Aftermath_FeatureFlags_EnableMarkers | // Enable event marker
+ // tracking.
+ GFSDK_Aftermath_FeatureFlags_CallStackCapturing | // Enable automatic call
+ // stack event markers.
+ GFSDK_Aftermath_FeatureFlags_EnableResourceTracking | // Enable tracking of
+ // resources.
+ GFSDK_Aftermath_FeatureFlags_GenerateShaderDebugInfo | // Generate debug
+ // information for
+ // shaders.
+ GFSDK_Aftermath_FeatureFlags_EnableShaderErrorReporting; // Enable
+ // additional
+ // runtime shader
+ // error reporting.
auto initResult = GFSDK_Aftermath_DX11_Initialize(
GFSDK_Aftermath_Version_API,
@@ -192,7 +214,6 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
{
break;
}
-
}
// If res is failure, means all styles have have failed, and so initialization fails.
if (SLANG_FAILED(res))
@@ -250,8 +271,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
// Create a TIMESTAMP_DISJOINT query object to query/update frequency info.
D3D11_QUERY_DESC disjointQueryDesc = {};
disjointQueryDesc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
- SLANG_RETURN_ON_FAIL(m_device->CreateQuery(
- &disjointQueryDesc, m_disjointQuery.writeRef()));
+ SLANG_RETURN_ON_FAIL(m_device->CreateQuery(&disjointQueryDesc, m_disjointQuery.writeRef()));
m_immediateContext->Begin(m_disjointQuery);
m_immediateContext->End(m_disjointQuery);
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjointData = {};
@@ -310,15 +330,17 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
limits.maxVertexInputElements = maxInputElements;
limits.maxVertexInputElementOffset = 256; // TODO
- limits.maxVertexStreams = D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT ;
+ limits.maxVertexStreams = D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT;
limits.maxVertexStreamStride = D3D11_REQ_MULTI_ELEMENT_STRUCTURE_SIZE_IN_BYTES;
limits.maxComputeThreadsPerGroup = D3D11_CS_THREAD_GROUP_MAX_THREADS_PER_GROUP;
limits.maxComputeThreadGroupSize[0] = maxComputeThreadGroupSizeXY;
limits.maxComputeThreadGroupSize[1] = maxComputeThreadGroupSizeXY;
limits.maxComputeThreadGroupSize[2] = maxComputeThreadGroupSizeZ;
- limits.maxComputeDispatchThreadGroups[0] = D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
- limits.maxComputeDispatchThreadGroups[1] = D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
+ limits.maxComputeDispatchThreadGroups[0] =
+ D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
+ limits.maxComputeDispatchThreadGroups[1] =
+ D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
limits.maxComputeDispatchThreadGroups[2] = maxComputeDispatchThreadGroupsZ;
limits.maxViewports = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
@@ -365,7 +387,9 @@ void DeviceImpl::clearFrame(uint32_t colorBufferMask, bool clearDepth, bool clea
}
Result DeviceImpl::createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain)
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain)
{
RefPtr<SwapchainImpl> swapchain = new SwapchainImpl();
SLANG_RETURN_ON_FAIL(swapchain->init(this, desc, window));
@@ -374,7 +398,8 @@ Result DeviceImpl::createSwapchain(
}
Result DeviceImpl::createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout)
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout)
{
RefPtr<FramebufferLayoutImpl> layout = new FramebufferLayoutImpl();
layout->m_renderTargets.setCount(desc.renderTargetCount);
@@ -396,19 +421,20 @@ Result DeviceImpl::createFramebufferLayout(
return SLANG_OK;
}
-Result DeviceImpl::createFramebuffer(
- const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer)
+Result DeviceImpl::createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer)
{
RefPtr<FramebufferImpl> framebuffer = new FramebufferImpl();
framebuffer->renderTargetViews.setCount(desc.renderTargetCount);
framebuffer->d3dRenderTargetViews.setCount(desc.renderTargetCount);
for (GfxIndex i = 0; i < desc.renderTargetCount; i++)
{
- framebuffer->renderTargetViews[i] = static_cast<RenderTargetViewImpl*>(desc.renderTargetViews[i]);
+ framebuffer->renderTargetViews[i] =
+ static_cast<RenderTargetViewImpl*>(desc.renderTargetViews[i]);
framebuffer->d3dRenderTargetViews[i] = framebuffer->renderTargetViews[i]->m_rtv;
}
framebuffer->depthStencilView = static_cast<DepthStencilViewImpl*>(desc.depthStencilView);
- framebuffer->d3dDepthStencilView = framebuffer->depthStencilView ? framebuffer->depthStencilView->m_dsv : nullptr;
+ framebuffer->d3dDepthStencilView =
+ framebuffer->depthStencilView ? framebuffer->depthStencilView->m_dsv : nullptr;
returnComPtr(outFramebuffer, framebuffer);
return SLANG_OK;
}
@@ -491,7 +517,8 @@ SlangResult DeviceImpl::readTextureResource(
// Now just read back texels from the staging textures
{
D3D11_MAPPED_SUBRESOURCE mappedResource;
- SLANG_RETURN_ON_FAIL(m_immediateContext->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mappedResource));
+ SLANG_RETURN_ON_FAIL(
+ m_immediateContext->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mappedResource));
List<uint8_t> data;
@@ -514,7 +541,10 @@ SlangResult DeviceImpl::readTextureResource(
}
}
-Result DeviceImpl::createTextureResource(const ITextureResource::Desc& descIn, const ITextureResource::SubresourceData* initData, ITextureResource** outResource)
+Result DeviceImpl::createTextureResource(
+ const ITextureResource::Desc& descIn,
+ const ITextureResource::SubresourceData* initData,
+ ITextureResource** outResource)
{
TextureResource::Desc srcDesc = fixupTextureDesc(descIn);
@@ -563,79 +593,84 @@ Result DeviceImpl::createTextureResource(const ITextureResource::Desc& descIn, c
switch (srcDesc.type)
{
case IResource::Type::Texture1D:
- {
- D3D11_TEXTURE1D_DESC desc = { 0 };
- desc.BindFlags = bindFlags;
- desc.CPUAccessFlags = accessFlags;
- desc.Format = format;
- desc.MiscFlags = 0;
- desc.MipLevels = srcDesc.numMipLevels;
- desc.ArraySize = effectiveArraySize;
- desc.Width = srcDesc.size.width;
- desc.Usage = D3D11_USAGE_DEFAULT;
-
- ComPtr<ID3D11Texture1D> texture1D;
- SLANG_RETURN_ON_FAIL(m_device->CreateTexture1D(&desc, subResourcesPtr, texture1D.writeRef()));
-
- texture->m_resource = texture1D;
- break;
- }
+ {
+ D3D11_TEXTURE1D_DESC desc = {0};
+ desc.BindFlags = bindFlags;
+ desc.CPUAccessFlags = accessFlags;
+ desc.Format = format;
+ desc.MiscFlags = 0;
+ desc.MipLevels = srcDesc.numMipLevels;
+ desc.ArraySize = effectiveArraySize;
+ desc.Width = srcDesc.size.width;
+ desc.Usage = D3D11_USAGE_DEFAULT;
+
+ ComPtr<ID3D11Texture1D> texture1D;
+ SLANG_RETURN_ON_FAIL(
+ m_device->CreateTexture1D(&desc, subResourcesPtr, texture1D.writeRef()));
+
+ texture->m_resource = texture1D;
+ break;
+ }
case IResource::Type::TextureCube:
case IResource::Type::Texture2D:
- {
- D3D11_TEXTURE2D_DESC desc = { 0 };
- desc.BindFlags = bindFlags;
- desc.CPUAccessFlags = accessFlags;
- desc.Format = format;
- desc.MiscFlags = 0;
- desc.MipLevels = srcDesc.numMipLevels;
- desc.ArraySize = effectiveArraySize;
-
- desc.Width = srcDesc.size.width;
- desc.Height = srcDesc.size.height;
- desc.Usage = D3D11_USAGE_DEFAULT;
- desc.SampleDesc.Count = srcDesc.sampleDesc.numSamples;
- desc.SampleDesc.Quality = srcDesc.sampleDesc.quality;
-
- if (srcDesc.type == IResource::Type::TextureCube)
{
- desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
- }
+ D3D11_TEXTURE2D_DESC desc = {0};
+ desc.BindFlags = bindFlags;
+ desc.CPUAccessFlags = accessFlags;
+ desc.Format = format;
+ desc.MiscFlags = 0;
+ desc.MipLevels = srcDesc.numMipLevels;
+ desc.ArraySize = effectiveArraySize;
+
+ desc.Width = srcDesc.size.width;
+ desc.Height = srcDesc.size.height;
+ desc.Usage = D3D11_USAGE_DEFAULT;
+ desc.SampleDesc.Count = srcDesc.sampleDesc.numSamples;
+ desc.SampleDesc.Quality = srcDesc.sampleDesc.quality;
+
+ if (srcDesc.type == IResource::Type::TextureCube)
+ {
+ desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
+ }
- ComPtr<ID3D11Texture2D> texture2D;
- SLANG_RETURN_ON_FAIL(m_device->CreateTexture2D(&desc, subResourcesPtr, texture2D.writeRef()));
+ ComPtr<ID3D11Texture2D> texture2D;
+ SLANG_RETURN_ON_FAIL(
+ m_device->CreateTexture2D(&desc, subResourcesPtr, texture2D.writeRef()));
- texture->m_resource = texture2D;
- break;
- }
+ texture->m_resource = texture2D;
+ break;
+ }
case IResource::Type::Texture3D:
- {
- D3D11_TEXTURE3D_DESC desc = { 0 };
- desc.BindFlags = bindFlags;
- desc.CPUAccessFlags = accessFlags;
- desc.Format = format;
- desc.MiscFlags = 0;
- desc.MipLevels = srcDesc.numMipLevels;
- desc.Width = srcDesc.size.width;
- desc.Height = srcDesc.size.height;
- desc.Depth = srcDesc.size.depth;
- desc.Usage = D3D11_USAGE_DEFAULT;
-
- ComPtr<ID3D11Texture3D> texture3D;
- SLANG_RETURN_ON_FAIL(m_device->CreateTexture3D(&desc, subResourcesPtr, texture3D.writeRef()));
-
- texture->m_resource = texture3D;
- break;
- }
- default:
- return SLANG_FAIL;
+ {
+ D3D11_TEXTURE3D_DESC desc = {0};
+ desc.BindFlags = bindFlags;
+ desc.CPUAccessFlags = accessFlags;
+ desc.Format = format;
+ desc.MiscFlags = 0;
+ desc.MipLevels = srcDesc.numMipLevels;
+ desc.Width = srcDesc.size.width;
+ desc.Height = srcDesc.size.height;
+ desc.Depth = srcDesc.size.depth;
+ desc.Usage = D3D11_USAGE_DEFAULT;
+
+ ComPtr<ID3D11Texture3D> texture3D;
+ SLANG_RETURN_ON_FAIL(
+ m_device->CreateTexture3D(&desc, subResourcesPtr, texture3D.writeRef()));
+
+ texture->m_resource = texture3D;
+ break;
+ }
+ default: return SLANG_FAIL;
}
returnComPtr(outResource, texture);
return SLANG_OK;
}
-Result DeviceImpl::createBufferResource(const IBufferResource::Desc& descIn, const void* initData, IBufferResource** outResource)
+Result DeviceImpl::createBufferResource(
+ const IBufferResource::Desc& descIn,
+ const void* initData,
+ IBufferResource** outResource)
{
IBufferResource::Desc srcDesc = fixupBufferDesc(descIn);
@@ -649,7 +684,8 @@ Result DeviceImpl::createBufferResource(const IBufferResource::Desc& descIn, con
alignedSizeInBytes = D3DUtil::calcAligned(alignedSizeInBytes, 256);
}
- // Hack to make the initialization never read from out of bounds memory, by copying into a buffer
+ // Hack to make the initialization never read from out of bounds memory, by copying into a
+ // buffer
List<uint8_t> initDataBuffer;
if (initData && alignedSizeInBytes > srcDesc.sizeInBytes)
{
@@ -658,7 +694,7 @@ Result DeviceImpl::createBufferResource(const IBufferResource::Desc& descIn, con
initData = initDataBuffer.getBuffer();
}
- D3D11_BUFFER_DESC bufferDesc = { 0 };
+ D3D11_BUFFER_DESC bufferDesc = {0};
bufferDesc.ByteWidth = UINT(alignedSizeInBytes);
bufferDesc.BindFlags = d3dBindFlags;
// For read we'll need to do some staging
@@ -681,17 +717,17 @@ Result DeviceImpl::createBufferResource(const IBufferResource::Desc& descIn, con
switch (descIn.defaultState)
{
case ResourceState::ConstantBuffer:
- {
- // We'll just assume ConstantBuffers are dynamic for now
- bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
- break;
- }
+ {
+ // We'll just assume ConstantBuffers are dynamic for now
+ bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
+ break;
+ }
default: break;
}
if (bufferDesc.BindFlags & (D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE))
{
- //desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
+ // desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS | D3D11_BIND_SHADER_RESOURCE;
if (srcDesc.elementSize != 0)
{
bufferDesc.StructureByteStride = (UINT)srcDesc.elementSize;
@@ -708,12 +744,15 @@ Result DeviceImpl::createBufferResource(const IBufferResource::Desc& descIn, con
bufferDesc.CPUAccessFlags |= D3D11_CPU_ACCESS_WRITE;
}
- D3D11_SUBRESOURCE_DATA subResourceData = { 0 };
+ D3D11_SUBRESOURCE_DATA subResourceData = {0};
subResourceData.pSysMem = initData;
RefPtr<BufferResourceImpl> buffer(new BufferResourceImpl(srcDesc));
- SLANG_RETURN_ON_FAIL(m_device->CreateBuffer(&bufferDesc, initData ? &subResourceData : nullptr, buffer->m_buffer.writeRef()));
+ SLANG_RETURN_ON_FAIL(m_device->CreateBuffer(
+ &bufferDesc,
+ initData ? &subResourceData : nullptr,
+ buffer->m_buffer.writeRef()));
buffer->m_d3dUsage = bufferDesc.Usage;
if (srcDesc.memoryType == MemoryType::ReadBack || bufferDesc.Usage != D3D11_USAGE_DYNAMIC)
@@ -724,7 +763,8 @@ Result DeviceImpl::createBufferResource(const IBufferResource::Desc& descIn, con
bufDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
bufDesc.Usage = D3D11_USAGE_STAGING;
- SLANG_RETURN_ON_FAIL(m_device->CreateBuffer(&bufDesc, nullptr, buffer->m_staging.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ m_device->CreateBuffer(&bufDesc, nullptr, buffer->m_staging.writeRef()));
}
returnComPtr(outResource, buffer);
return SLANG_OK;
@@ -761,9 +801,7 @@ Result DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerS
dxDesc.MaxLOD = desc.maxLOD;
ComPtr<ID3D11SamplerState> sampler;
- SLANG_RETURN_ON_FAIL(m_device->CreateSamplerState(
- &dxDesc,
- sampler.writeRef()));
+ SLANG_RETURN_ON_FAIL(m_device->CreateSamplerState(&dxDesc, sampler.writeRef()));
RefPtr<SamplerStateImpl> samplerImpl = new SamplerStateImpl();
samplerImpl->m_sampler = sampler;
@@ -771,85 +809,103 @@ Result DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerS
return SLANG_OK;
}
-Result DeviceImpl::createTextureView(ITextureResource* texture, IResourceView::Desc const& desc, IResourceView** outView)
+Result DeviceImpl::createTextureView(
+ ITextureResource* texture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView)
{
auto resourceImpl = (TextureResourceImpl*)texture;
switch (desc.type)
{
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
case IResourceView::Type::RenderTarget:
- {
- ComPtr<ID3D11RenderTargetView> rtv;
- SLANG_RETURN_ON_FAIL(m_device->CreateRenderTargetView(resourceImpl->m_resource, nullptr, rtv.writeRef()));
-
- RefPtr<RenderTargetViewImpl> viewImpl = new RenderTargetViewImpl();
- viewImpl->m_type = ResourceViewImpl::Type::RTV;
- viewImpl->m_rtv = rtv;
- viewImpl->m_desc = desc;
- if (resourceImpl->getDesc()->optimalClearValue)
{
- memcpy(
- viewImpl->m_clearValue,
- &resourceImpl->getDesc()->optimalClearValue->color,
- sizeof(float) * 4);
+ ComPtr<ID3D11RenderTargetView> rtv;
+ SLANG_RETURN_ON_FAIL(m_device->CreateRenderTargetView(
+ resourceImpl->m_resource,
+ nullptr,
+ rtv.writeRef()));
+
+ RefPtr<RenderTargetViewImpl> viewImpl = new RenderTargetViewImpl();
+ viewImpl->m_type = ResourceViewImpl::Type::RTV;
+ viewImpl->m_rtv = rtv;
+ viewImpl->m_desc = desc;
+ if (resourceImpl->getDesc()->optimalClearValue)
+ {
+ memcpy(
+ viewImpl->m_clearValue,
+ &resourceImpl->getDesc()->optimalClearValue->color,
+ sizeof(float) * 4);
+ }
+ returnComPtr(outView, viewImpl);
+ return SLANG_OK;
}
- returnComPtr(outView, viewImpl);
- return SLANG_OK;
- }
- break;
+ break;
case IResourceView::Type::DepthStencil:
- {
- ComPtr<ID3D11DepthStencilView> dsv;
- SLANG_RETURN_ON_FAIL(m_device->CreateDepthStencilView(resourceImpl->m_resource, nullptr, dsv.writeRef()));
+ {
+ ComPtr<ID3D11DepthStencilView> dsv;
+ SLANG_RETURN_ON_FAIL(m_device->CreateDepthStencilView(
+ resourceImpl->m_resource,
+ nullptr,
+ dsv.writeRef()));
- RefPtr<DepthStencilViewImpl> viewImpl = new DepthStencilViewImpl();
- viewImpl->m_type = ResourceViewImpl::Type::DSV;
- viewImpl->m_dsv = dsv;
- if (resourceImpl->getDesc()->optimalClearValue)
- viewImpl->m_clearValue = resourceImpl->getDesc()->optimalClearValue->depthStencil;
- viewImpl->m_desc = desc;
+ RefPtr<DepthStencilViewImpl> viewImpl = new DepthStencilViewImpl();
+ viewImpl->m_type = ResourceViewImpl::Type::DSV;
+ viewImpl->m_dsv = dsv;
+ if (resourceImpl->getDesc()->optimalClearValue)
+ viewImpl->m_clearValue = resourceImpl->getDesc()->optimalClearValue->depthStencil;
+ viewImpl->m_desc = desc;
- returnComPtr(outView, viewImpl);
- return SLANG_OK;
- }
- break;
+ returnComPtr(outView, viewImpl);
+ return SLANG_OK;
+ }
+ break;
case IResourceView::Type::UnorderedAccess:
- {
- ComPtr<ID3D11UnorderedAccessView> uav;
- SLANG_RETURN_ON_FAIL(m_device->CreateUnorderedAccessView(resourceImpl->m_resource, nullptr, uav.writeRef()));
+ {
+ ComPtr<ID3D11UnorderedAccessView> uav;
+ SLANG_RETURN_ON_FAIL(m_device->CreateUnorderedAccessView(
+ resourceImpl->m_resource,
+ nullptr,
+ uav.writeRef()));
- RefPtr<UnorderedAccessViewImpl> viewImpl = new UnorderedAccessViewImpl();
- viewImpl->m_type = ResourceViewImpl::Type::UAV;
- viewImpl->m_uav = uav;
- viewImpl->m_desc = desc;
+ RefPtr<UnorderedAccessViewImpl> viewImpl = new UnorderedAccessViewImpl();
+ viewImpl->m_type = ResourceViewImpl::Type::UAV;
+ viewImpl->m_uav = uav;
+ viewImpl->m_desc = desc;
- returnComPtr(outView, viewImpl);
- return SLANG_OK;
- }
- break;
+ returnComPtr(outView, viewImpl);
+ return SLANG_OK;
+ }
+ break;
case IResourceView::Type::ShaderResource:
- {
- D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
- initSrvDesc(resourceImpl->getType(), *resourceImpl->getDesc(), D3DUtil::getMapFormat(desc.format), srvDesc);
-
- ComPtr<ID3D11ShaderResourceView> srv;
- SLANG_RETURN_ON_FAIL(m_device->CreateShaderResourceView(resourceImpl->m_resource, &srvDesc, srv.writeRef()));
-
- RefPtr<ShaderResourceViewImpl> viewImpl = new ShaderResourceViewImpl();
- viewImpl->m_type = ResourceViewImpl::Type::SRV;
- viewImpl->m_srv = srv;
- viewImpl->m_desc = desc;
-
- returnComPtr(outView, viewImpl);
- return SLANG_OK;
- }
- break;
+ {
+ D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
+ initSrvDesc(
+ resourceImpl->getType(),
+ *resourceImpl->getDesc(),
+ D3DUtil::getMapFormat(desc.format),
+ srvDesc);
+
+ ComPtr<ID3D11ShaderResourceView> srv;
+ SLANG_RETURN_ON_FAIL(m_device->CreateShaderResourceView(
+ resourceImpl->m_resource,
+ &srvDesc,
+ srv.writeRef()));
+
+ RefPtr<ShaderResourceViewImpl> viewImpl = new ShaderResourceViewImpl();
+ viewImpl->m_type = ResourceViewImpl::Type::SRV;
+ viewImpl->m_srv = srv;
+ viewImpl->m_desc = desc;
+
+ returnComPtr(outView, viewImpl);
+ return SLANG_OK;
+ }
+ break;
}
}
@@ -864,93 +920,104 @@ Result DeviceImpl::createBufferView(
switch (desc.type)
{
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
case IResourceView::Type::UnorderedAccess:
- {
- D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
- uavDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
- uavDesc.Format = D3DUtil::getMapFormat(desc.format);
- uavDesc.Buffer.FirstElement = 0;
-
- if (resourceDesc.elementSize)
{
- uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / resourceDesc.elementSize);
- }
- else if (desc.format == Format::Unknown)
- {
- uavDesc.Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
- uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
- uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / 4);
- }
- else
- {
- FormatInfo sizeInfo;
- gfxGetFormatInfo(desc.format, &sizeInfo);
- uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock));
- }
-
- ComPtr<ID3D11UnorderedAccessView> uav;
- SLANG_RETURN_ON_FAIL(m_device->CreateUnorderedAccessView(resourceImpl->m_buffer, &uavDesc, uav.writeRef()));
+ D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
+ uavDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
+ uavDesc.Format = D3DUtil::getMapFormat(desc.format);
+ uavDesc.Buffer.FirstElement = 0;
- RefPtr<UnorderedAccessViewImpl> viewImpl = new UnorderedAccessViewImpl();
- viewImpl->m_type = ResourceViewImpl::Type::UAV;
- viewImpl->m_uav = uav;
- viewImpl->m_desc = desc;
+ if (resourceDesc.elementSize)
+ {
+ uavDesc.Buffer.NumElements =
+ UINT(resourceDesc.sizeInBytes / resourceDesc.elementSize);
+ }
+ else if (desc.format == Format::Unknown)
+ {
+ uavDesc.Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
+ uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
+ uavDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / 4);
+ }
+ else
+ {
+ FormatInfo sizeInfo;
+ gfxGetFormatInfo(desc.format, &sizeInfo);
+ uavDesc.Buffer.NumElements = UINT(
+ resourceDesc.sizeInBytes /
+ (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock));
+ }
- returnComPtr(outView, viewImpl);
- return SLANG_OK;
- }
- break;
+ ComPtr<ID3D11UnorderedAccessView> uav;
+ SLANG_RETURN_ON_FAIL(m_device->CreateUnorderedAccessView(
+ resourceImpl->m_buffer,
+ &uavDesc,
+ uav.writeRef()));
- case IResourceView::Type::ShaderResource:
- {
- D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
- srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
- srvDesc.Format = D3DUtil::getMapFormat(desc.format);
- srvDesc.Buffer.FirstElement = 0;
+ RefPtr<UnorderedAccessViewImpl> viewImpl = new UnorderedAccessViewImpl();
+ viewImpl->m_type = ResourceViewImpl::Type::UAV;
+ viewImpl->m_uav = uav;
+ viewImpl->m_desc = desc;
- if (resourceDesc.elementSize)
- {
- srvDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / resourceDesc.elementSize);
+ returnComPtr(outView, viewImpl);
+ return SLANG_OK;
}
- else if (desc.format == Format::Unknown)
- {
- // We need to switch to a different member of the `union`,
- // so that we can set the `BufferEx.Flags` member.
- //
- srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
-
- // Because we've switched, we need to re-set the `FirstElement`
- // field to be valid, since we can't count on all compilers
- // to respect that `Buffer.FirstElement` and `BufferEx.FirstElement`
- // alias in memory.
- //
- srvDesc.BufferEx.FirstElement = 0;
+ break;
- srvDesc.BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
- srvDesc.Format = DXGI_FORMAT_R32_TYPELESS;
- srvDesc.BufferEx.NumElements = UINT(resourceDesc.sizeInBytes / 4);
- }
- else
+ case IResourceView::Type::ShaderResource:
{
- FormatInfo sizeInfo;
- gfxGetFormatInfo(desc.format, &sizeInfo);
- srvDesc.Buffer.NumElements = UINT(resourceDesc.sizeInBytes / (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock));
- }
+ D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
+ srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
+ srvDesc.Format = D3DUtil::getMapFormat(desc.format);
+ srvDesc.Buffer.FirstElement = 0;
- ComPtr<ID3D11ShaderResourceView> srv;
- SLANG_RETURN_ON_FAIL(m_device->CreateShaderResourceView(resourceImpl->m_buffer, &srvDesc, srv.writeRef()));
+ if (resourceDesc.elementSize)
+ {
+ srvDesc.Buffer.NumElements =
+ UINT(resourceDesc.sizeInBytes / resourceDesc.elementSize);
+ }
+ else if (desc.format == Format::Unknown)
+ {
+ // We need to switch to a different member of the `union`,
+ // so that we can set the `BufferEx.Flags` member.
+ //
+ srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
+
+ // Because we've switched, we need to re-set the `FirstElement`
+ // field to be valid, since we can't count on all compilers
+ // to respect that `Buffer.FirstElement` and `BufferEx.FirstElement`
+ // alias in memory.
+ //
+ srvDesc.BufferEx.FirstElement = 0;
+
+ srvDesc.BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
+ srvDesc.Format = DXGI_FORMAT_R32_TYPELESS;
+ srvDesc.BufferEx.NumElements = UINT(resourceDesc.sizeInBytes / 4);
+ }
+ else
+ {
+ FormatInfo sizeInfo;
+ gfxGetFormatInfo(desc.format, &sizeInfo);
+ srvDesc.Buffer.NumElements = UINT(
+ resourceDesc.sizeInBytes /
+ (sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock));
+ }
- RefPtr<ShaderResourceViewImpl> viewImpl = new ShaderResourceViewImpl();
- viewImpl->m_type = ResourceViewImpl::Type::SRV;
- viewImpl->m_srv = srv;
- viewImpl->m_desc = desc;
- returnComPtr(outView, viewImpl);
- return SLANG_OK;
- }
- break;
+ ComPtr<ID3D11ShaderResourceView> srv;
+ SLANG_RETURN_ON_FAIL(m_device->CreateShaderResourceView(
+ resourceImpl->m_buffer,
+ &srvDesc,
+ srv.writeRef()));
+
+ RefPtr<ShaderResourceViewImpl> viewImpl = new ShaderResourceViewImpl();
+ viewImpl->m_type = ResourceViewImpl::Type::SRV;
+ viewImpl->m_srv = srv;
+ viewImpl->m_desc = desc;
+ returnComPtr(outView, viewImpl);
+ return SLANG_OK;
+ }
+ break;
}
}
@@ -975,8 +1042,9 @@ Result DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayou
inputElements[ii].Format = D3DUtil::getMapFormat(inputElementsIn[ii].format);
inputElements[ii].InputSlot = (UINT)vertexStreamIndex;
inputElements[ii].AlignedByteOffset = (UINT)inputElementsIn[ii].offset;
- inputElements[ii].InputSlotClass =
- (vertexStream.slotClass == InputSlotClass::PerInstance) ? D3D11_INPUT_PER_INSTANCE_DATA : D3D11_INPUT_PER_VERTEX_DATA;
+ inputElements[ii].InputSlotClass = (vertexStream.slotClass == InputSlotClass::PerInstance)
+ ? D3D11_INPUT_PER_INSTANCE_DATA
+ : D3D11_INPUT_PER_VERTEX_DATA;
inputElements[ii].InstanceDataStepRate = (UINT)vertexStream.instanceDataStepRate;
if (ii != 0)
@@ -988,23 +1056,16 @@ Result DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayou
switch (inputElementsIn[ii].format)
{
case Format::R32G32B32A32_FLOAT:
- case Format::R8G8B8A8_UNORM:
- typeName = "float4";
- break;
- case Format::R32G32B32_FLOAT:
- typeName = "float3";
- break;
- case Format::R32G32_FLOAT:
- typeName = "float2";
- break;
- case Format::R32_FLOAT:
- typeName = "float";
- break;
- default:
- return SLANG_FAIL;
+ case Format::R8G8B8A8_UNORM: typeName = "float4"; break;
+ case Format::R32G32B32_FLOAT: typeName = "float3"; break;
+ case Format::R32G32_FLOAT: typeName = "float2"; break;
+ case Format::R32_FLOAT: typeName = "float"; break;
+ default: return SLANG_FAIL;
}
- hlslCursor += sprintf(hlslCursor, "%s a%d : %s%d",
+ hlslCursor += sprintf(
+ hlslCursor,
+ "%s a%d : %s%d",
typeName,
(int)ii,
inputElementsIn[ii].semanticName,
@@ -1014,10 +1075,15 @@ Result DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayou
hlslCursor += sprintf(hlslCursor, "\n) : SV_Position { return 0; }");
ComPtr<ID3DBlob> vertexShaderBlob;
- SLANG_RETURN_ON_FAIL(D3DUtil::compileHLSLShader("inputLayout", hlslBuffer, "main", "vs_5_0", vertexShaderBlob));
+ SLANG_RETURN_ON_FAIL(
+ D3DUtil::compileHLSLShader("inputLayout", hlslBuffer, "main", "vs_5_0", vertexShaderBlob));
ComPtr<ID3D11InputLayout> inputLayout;
- SLANG_RETURN_ON_FAIL(m_device->CreateInputLayout(&inputElements[0], (UINT)inputElementCount, vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize(),
+ SLANG_RETURN_ON_FAIL(m_device->CreateInputLayout(
+ &inputElements[0],
+ (UINT)inputElementCount,
+ vertexShaderBlob->GetBufferPointer(),
+ vertexShaderBlob->GetBufferSize(),
inputLayout.writeRef()));
RefPtr<InputLayoutImpl> impl = new InputLayoutImpl;
@@ -1051,17 +1117,10 @@ void* DeviceImpl::map(IBufferResource* bufferIn, MapFlavor flavor)
switch (flavor)
{
- case MapFlavor::WriteDiscard:
- mapType = D3D11_MAP_WRITE_DISCARD;
- break;
- case MapFlavor::HostWrite:
- mapType = D3D11_MAP_WRITE_NO_OVERWRITE;
- break;
- case MapFlavor::HostRead:
- mapType = D3D11_MAP_READ;
- break;
- default:
- return nullptr;
+ case MapFlavor::WriteDiscard: mapType = D3D11_MAP_WRITE_DISCARD; break;
+ case MapFlavor::HostWrite: mapType = D3D11_MAP_WRITE_NO_OVERWRITE; break;
+ case MapFlavor::HostRead: mapType = D3D11_MAP_READ; break;
+ default: return nullptr;
}
bufferResource->m_mapFlavor = flavor;
@@ -1086,7 +1145,6 @@ void* DeviceImpl::map(IBufferResource* bufferIn, MapFlavor flavor)
// Okay copy the data over
m_immediateContext->CopyResource(buffer, bufferResource->m_buffer);
-
}
// We update our constant buffer per-frame, just for the purposes
@@ -1124,7 +1182,10 @@ void DeviceImpl::unmap(IBufferResource* bufferIn, size_t offsetWritten, size_t s
return;
}
}
- m_immediateContext->Unmap(bufferResource->m_mapFlavor == MapFlavor::HostRead ? bufferResource->m_staging : bufferResource->m_buffer, 0);
+ m_immediateContext->Unmap(
+ bufferResource->m_mapFlavor == MapFlavor::HostRead ? bufferResource->m_staging
+ : bufferResource->m_buffer,
+ 0);
}
#if 0
@@ -1148,7 +1209,8 @@ void DeviceImpl::setVertexBuffers(
{
static const int kMaxVertexBuffers = 16;
assert(slotCount <= kMaxVertexBuffers);
- assert(m_currentPipelineState); // The pipeline state should be created before setting vertex buffers.
+ assert(m_currentPipelineState); // The pipeline state should be created before setting vertex
+ // buffers.
UINT vertexStrides[kMaxVertexBuffers];
UINT vertexOffsets[kMaxVertexBuffers];
@@ -1164,13 +1226,21 @@ void DeviceImpl::setVertexBuffers(
dxBuffers[ii] = buffers[ii]->m_buffer;
}
- m_immediateContext->IASetVertexBuffers((UINT)startSlot, (UINT)slotCount, dxBuffers, &vertexStrides[0], &vertexOffsets[0]);
+ m_immediateContext->IASetVertexBuffers(
+ (UINT)startSlot,
+ (UINT)slotCount,
+ dxBuffers,
+ &vertexStrides[0],
+ &vertexOffsets[0]);
}
void DeviceImpl::setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset)
{
DXGI_FORMAT dxFormat = D3DUtil::getMapFormat(indexFormat);
- m_immediateContext->IASetIndexBuffer(((BufferResourceImpl*)buffer)->m_buffer, dxFormat, UINT(offset));
+ m_immediateContext->IASetIndexBuffer(
+ ((BufferResourceImpl*)buffer)->m_buffer,
+ dxFormat,
+ UINT(offset));
}
void DeviceImpl::setViewports(GfxCount count, Viewport const* viewports)
@@ -1222,66 +1292,69 @@ void DeviceImpl::setPipelineState(IPipelineState* state)
switch (pipelineType)
{
- default:
- break;
+ default: break;
case PipelineType::Graphics:
- {
- auto stateImpl = (GraphicsPipelineStateImpl*)state;
- auto programImpl = static_cast<ShaderProgramImpl*>(stateImpl->m_program.Ptr());
+ {
+ auto stateImpl = (GraphicsPipelineStateImpl*)state;
+ auto programImpl = static_cast<ShaderProgramImpl*>(stateImpl->m_program.Ptr());
- // TODO: We could conceivably do some lightweight state
- // differencing here (e.g., check if `programImpl` is the
- // same as the program that is currently bound).
- //
- // It isn't clear how much that would pay off given that
- // the D3D11 runtime seems to do its own state diffing.
+ // TODO: We could conceivably do some lightweight state
+ // differencing here (e.g., check if `programImpl` is the
+ // same as the program that is currently bound).
+ //
+ // It isn't clear how much that would pay off given that
+ // the D3D11 runtime seems to do its own state diffing.
- // IA
+ // IA
- m_immediateContext->IASetInputLayout(stateImpl->m_inputLayout->m_layout);
+ m_immediateContext->IASetInputLayout(stateImpl->m_inputLayout->m_layout);
- // VS
+ // VS
- // TODO(tfoley): Why the conditional here? If somebody is trying to disable the VS or PS, shouldn't we respect that?
- if (programImpl->m_vertexShader)
- m_immediateContext->VSSetShader(programImpl->m_vertexShader, nullptr, 0);
+ // TODO(tfoley): Why the conditional here? If somebody is trying to disable the VS or
+ // PS, shouldn't we respect that?
+ if (programImpl->m_vertexShader)
+ m_immediateContext->VSSetShader(programImpl->m_vertexShader, nullptr, 0);
- // HS
+ // HS
- // DS
+ // DS
- // GS
+ // GS
- // RS
+ // RS
- m_immediateContext->RSSetState(stateImpl->m_rasterizerState);
+ m_immediateContext->RSSetState(stateImpl->m_rasterizerState);
- // PS
- if (programImpl->m_pixelShader)
- m_immediateContext->PSSetShader(programImpl->m_pixelShader, nullptr, 0);
+ // PS
+ if (programImpl->m_pixelShader)
+ m_immediateContext->PSSetShader(programImpl->m_pixelShader, nullptr, 0);
- // OM
+ // OM
- m_immediateContext->OMSetBlendState(stateImpl->m_blendState, stateImpl->m_blendColor, stateImpl->m_sampleMask);
+ m_immediateContext->OMSetBlendState(
+ stateImpl->m_blendState,
+ stateImpl->m_blendColor,
+ stateImpl->m_sampleMask);
- m_currentPipelineState = stateImpl;
+ m_currentPipelineState = stateImpl;
- m_depthStencilStateDirty = true;
- }
- break;
+ m_depthStencilStateDirty = true;
+ }
+ break;
case PipelineType::Compute:
- {
- auto stateImpl = (ComputePipelineStateImpl*)state;
- auto programImpl = static_cast<ShaderProgramImpl*>(stateImpl->m_program.Ptr());
+ {
+ auto stateImpl = (ComputePipelineStateImpl*)state;
+ auto programImpl = static_cast<ShaderProgramImpl*>(stateImpl->m_program.Ptr());
- // CS
+ // CS
- m_immediateContext->CSSetShader(programImpl->m_computeShader, nullptr, 0);
- m_currentPipelineState = stateImpl;
- }
- break;
+ m_immediateContext->CSSetShader(programImpl->m_computeShader, nullptr, 0);
+ m_currentPipelineState = stateImpl;
+ }
+ break;
}
/// ...
@@ -1306,11 +1379,8 @@ void DeviceImpl::drawInstanced(
GfxIndex startInstanceLocation)
{
_flushGraphicsState();
- m_immediateContext->DrawInstanced(
- vertexCount,
- instanceCount,
- startVertex,
- startInstanceLocation);
+ m_immediateContext
+ ->DrawInstanced(vertexCount, instanceCount, startVertex, startInstanceLocation);
}
void DeviceImpl::drawIndexedInstanced(
@@ -1330,7 +1400,9 @@ void DeviceImpl::drawIndexedInstanced(
}
Result DeviceImpl::createProgram(
- const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnosticBlob)
{
SLANG_ASSERT(desc.slangGlobalScope);
@@ -1363,8 +1435,12 @@ Result DeviceImpl::createProgram(
ComPtr<ISlangBlob> kernelCode;
ComPtr<ISlangBlob> diagnostics;
- auto compileResult = getEntryPointCodeFromShaderCache(slangGlobalScope,
- (SlangInt)i, 0, kernelCode.writeRef(), diagnostics.writeRef());
+ auto compileResult = getEntryPointCodeFromShaderCache(
+ slangGlobalScope,
+ (SlangInt)i,
+ 0,
+ kernelCode.writeRef(),
+ diagnostics.writeRef());
if (diagnostics)
{
@@ -1406,8 +1482,7 @@ Result DeviceImpl::createProgram(
nullptr,
shaderProgram->m_pixelShader.writeRef()));
break;
- default:
- SLANG_ASSERT(!"pipeline stage not implemented");
+ default: SLANG_ASSERT(!"pipeline stage not implemented");
}
}
returnComPtr(outProgram, shaderProgram);
@@ -1420,8 +1495,8 @@ Result DeviceImpl::createShaderObjectLayout(
ShaderObjectLayoutBase** outLayout)
{
RefPtr<ShaderObjectLayoutImpl> layout;
- SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- this, session, typeLayout, layout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ ShaderObjectLayoutImpl::createForElementType(this, session, typeLayout, layout.writeRef()));
returnRefPtrMove(outLayout, layout);
return SLANG_OK;
}
@@ -1429,8 +1504,10 @@ Result DeviceImpl::createShaderObjectLayout(
Result DeviceImpl::createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
{
RefPtr<ShaderObjectImpl> shaderObject;
- SLANG_RETURN_ON_FAIL(ShaderObjectImpl::create(this,
- static_cast<ShaderObjectLayoutImpl*>(layout), shaderObject.writeRef()));
+ SLANG_RETURN_ON_FAIL(ShaderObjectImpl::create(
+ this,
+ static_cast<ShaderObjectLayoutImpl*>(layout),
+ shaderObject.writeRef()));
returnComPtr(outObject, shaderObject);
return SLANG_OK;
}
@@ -1454,9 +1531,12 @@ Result DeviceImpl::createRootShaderObject(IShaderProgram* program, ShaderObjectB
RefPtr<RootShaderObjectImpl> shaderObject;
RefPtr<RootShaderObjectLayoutImpl> rootLayout;
SLANG_RETURN_ON_FAIL(RootShaderObjectLayoutImpl::create(
- this, programImpl->slangGlobalScope, programImpl->slangGlobalScope->getLayout(), rootLayout.writeRef()));
- SLANG_RETURN_ON_FAIL(RootShaderObjectImpl::create(
- this, rootLayout.Ptr(), shaderObject.writeRef()));
+ this,
+ programImpl->slangGlobalScope,
+ programImpl->slangGlobalScope->getLayout(),
+ rootLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ RootShaderObjectImpl::create(this, rootLayout.Ptr(), shaderObject.writeRef()));
returnRefPtrMove(outObject, shaderObject);
return SLANG_OK;
}
@@ -1466,9 +1546,11 @@ void DeviceImpl::bindRootShaderObject(IShaderObject* shaderObject)
RootShaderObjectImpl* rootShaderObjectImpl = static_cast<RootShaderObjectImpl*>(shaderObject);
RefPtr<PipelineStateBase> specializedPipeline;
// TODO: Do something less crappy than just asserting on failure here
- SLANG_ASSERT_VOID_ON_FAIL(maybeSpecializePipeline(m_currentPipelineState, rootShaderObjectImpl, specializedPipeline));
+ SLANG_ASSERT_VOID_ON_FAIL(
+ maybeSpecializePipeline(m_currentPipelineState, rootShaderObjectImpl, specializedPipeline));
maybeSpecializePipeline(m_currentPipelineState, rootShaderObjectImpl, specializedPipeline);
- PipelineStateImpl* specializedPipelineImpl = static_cast<PipelineStateImpl*>(specializedPipeline.Ptr());
+ PipelineStateImpl* specializedPipelineImpl =
+ static_cast<PipelineStateImpl*>(specializedPipeline.Ptr());
setPipelineState(specializedPipelineImpl);
// In order to bind the root object we must compute its specialized layout.
@@ -1478,7 +1560,8 @@ void DeviceImpl::bindRootShaderObject(IShaderObject* shaderObject)
//
RefPtr<ShaderObjectLayoutImpl> specializedRootLayout;
rootShaderObjectImpl->_getSpecializedLayout(specializedRootLayout.writeRef());
- RootShaderObjectLayoutImpl* specializedRootLayoutImpl = static_cast<RootShaderObjectLayoutImpl*>(specializedRootLayout.Ptr());
+ RootShaderObjectLayoutImpl* specializedRootLayoutImpl =
+ static_cast<RootShaderObjectLayoutImpl*>(specializedRootLayout.Ptr());
// Depending on whether we are binding a compute or a graphics/rasterization
// pipeline, we will need to bind any SRVs/UAVs/CBs/samplers using different
@@ -1488,76 +1571,79 @@ void DeviceImpl::bindRootShaderObject(IShaderObject* shaderObject)
switch (m_currentPipelineState->desc.type)
{
case PipelineType::Compute:
- {
- ComputeBindingContext context(this, m_immediateContext);
- rootShaderObjectImpl->bindAsRoot(&context, specializedRootLayoutImpl);
-
- // Because D3D11 requires all UAVs to be set at once, we did *not* issue
- // actual binding calls during the `bindAsRoot` step, and instead we
- // batch them up and set them here.
- //
- m_immediateContext->CSSetUnorderedAccessViews(0, context.uavCount, context.uavs, nullptr);
- }
- break;
+ {
+ ComputeBindingContext context(this, m_immediateContext);
+ rootShaderObjectImpl->bindAsRoot(&context, specializedRootLayoutImpl);
+
+ // Because D3D11 requires all UAVs to be set at once, we did *not* issue
+ // actual binding calls during the `bindAsRoot` step, and instead we
+ // batch them up and set them here.
+ //
+ m_immediateContext
+ ->CSSetUnorderedAccessViews(0, context.uavCount, context.uavs, nullptr);
+ }
+ break;
default:
- {
- GraphicsBindingContext context(this, m_immediateContext);
- rootShaderObjectImpl->bindAsRoot(&context, specializedRootLayoutImpl);
-
- // Similar to the compute case above, the rasteirzation case needs to
- // set the UAVs after the call to `bindAsRoot()` completes, but we
- // also have a few extra wrinkles here that are specific to the D3D 11.0
- // rasterization pipeline.
- //
- // In D3D 11.0, the RTV and UAV binding slots alias, so that a shader
- // that binds an RTV for `SV_Target0` cannot also bind a UAV for `u0`.
- // The Slang layout algorithm already accounts for this rule, and assigns
- // all UAVs to slots taht won't alias the RTVs it knows about.
- //
- // In order to account for the aliasing, we need to consider how many
- // RTVs are bound as part of the active framebuffer, and then adjust
- // the UAVs that we bind accordingly.
- //
- auto rtvCount = (UINT)m_currentFramebuffer->renderTargetViews.getCount();
- //
- // The `context` we are using will have computed the number of UAV registers
- // that might need to be bound, as a range from 0 to `context.uavCount`.
- // However we need to skip over the first `rtvCount` of those, so the
- // actual number of UAVs we wnat to bind is smaller:
- //
- // Note: As a result we expect that either there were no UAVs bound,
- // *or* the number of UAV slots bound is higher than the number of
- // RTVs so that there is something left to actually bind.
- //
- SLANG_ASSERT((context.uavCount == 0) || (context.uavCount >= rtvCount));
- auto bindableUAVCount = context.uavCount - rtvCount;
- //
- // Similarly, the actual UAVs we intend to bind will come after the first
- // `rtvCount` in the array.
- //
- auto bindableUAVs = context.uavs + rtvCount;
-
- // Once the offsetting is accounted for, we set all of the RTVs, DSV,
- // and UAVs with one call.
- //
- // TODO: We may want to use the capability for `OMSetRenderTargetsAnd...`
- // to only set the UAVs and leave the RTVs/UAVs alone, so that we don't
- // needlessly re-bind RTVs during a pass.
- //
- m_immediateContext->OMSetRenderTargetsAndUnorderedAccessViews(
- rtvCount,
- m_currentFramebuffer->d3dRenderTargetViews.getArrayView().getBuffer(),
- m_currentFramebuffer->d3dDepthStencilView,
- rtvCount,
- bindableUAVCount,
- bindableUAVs,
- nullptr);
- }
- break;
+ {
+ GraphicsBindingContext context(this, m_immediateContext);
+ rootShaderObjectImpl->bindAsRoot(&context, specializedRootLayoutImpl);
+
+ // Similar to the compute case above, the rasteirzation case needs to
+ // set the UAVs after the call to `bindAsRoot()` completes, but we
+ // also have a few extra wrinkles here that are specific to the D3D 11.0
+ // rasterization pipeline.
+ //
+ // In D3D 11.0, the RTV and UAV binding slots alias, so that a shader
+ // that binds an RTV for `SV_Target0` cannot also bind a UAV for `u0`.
+ // The Slang layout algorithm already accounts for this rule, and assigns
+ // all UAVs to slots taht won't alias the RTVs it knows about.
+ //
+ // In order to account for the aliasing, we need to consider how many
+ // RTVs are bound as part of the active framebuffer, and then adjust
+ // the UAVs that we bind accordingly.
+ //
+ auto rtvCount = (UINT)m_currentFramebuffer->renderTargetViews.getCount();
+ //
+ // The `context` we are using will have computed the number of UAV registers
+ // that might need to be bound, as a range from 0 to `context.uavCount`.
+ // However we need to skip over the first `rtvCount` of those, so the
+ // actual number of UAVs we wnat to bind is smaller:
+ //
+ // Note: As a result we expect that either there were no UAVs bound,
+ // *or* the number of UAV slots bound is higher than the number of
+ // RTVs so that there is something left to actually bind.
+ //
+ SLANG_ASSERT((context.uavCount == 0) || (context.uavCount >= rtvCount));
+ auto bindableUAVCount = context.uavCount - rtvCount;
+ //
+ // Similarly, the actual UAVs we intend to bind will come after the first
+ // `rtvCount` in the array.
+ //
+ auto bindableUAVs = context.uavs + rtvCount;
+
+ // Once the offsetting is accounted for, we set all of the RTVs, DSV,
+ // and UAVs with one call.
+ //
+ // TODO: We may want to use the capability for `OMSetRenderTargetsAnd...`
+ // to only set the UAVs and leave the RTVs/UAVs alone, so that we don't
+ // needlessly re-bind RTVs during a pass.
+ //
+ m_immediateContext->OMSetRenderTargetsAndUnorderedAccessViews(
+ rtvCount,
+ m_currentFramebuffer->d3dRenderTargetViews.getArrayView().getBuffer(),
+ m_currentFramebuffer->d3dDepthStencilView,
+ rtvCount,
+ bindableUAVCount,
+ bindableUAVs,
+ nullptr);
+ }
+ break;
}
}
-Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc& inDesc, IPipelineState** outState)
+Result DeviceImpl::createGraphicsPipelineState(
+ const GraphicsPipelineStateDesc& inDesc,
+ IPipelineState** outState)
{
GraphicsPipelineStateDesc desc = inDesc;
@@ -1567,25 +1653,25 @@ Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc&
{
D3D11_DEPTH_STENCIL_DESC dsDesc;
dsDesc.DepthEnable = desc.depthStencil.depthTestEnable;
- dsDesc.DepthWriteMask = desc.depthStencil.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
+ dsDesc.DepthWriteMask = desc.depthStencil.depthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL
+ : D3D11_DEPTH_WRITE_MASK_ZERO;
dsDesc.DepthFunc = translateComparisonFunc(desc.depthStencil.depthFunc);
dsDesc.StencilEnable = desc.depthStencil.stencilEnable;
dsDesc.StencilReadMask = desc.depthStencil.stencilReadMask;
dsDesc.StencilWriteMask = desc.depthStencil.stencilWriteMask;
-#define FACE(DST, SRC) \
- dsDesc.DST.StencilFailOp = translateStencilOp( desc.depthStencil.SRC.stencilFailOp); \
- dsDesc.DST.StencilDepthFailOp = translateStencilOp( desc.depthStencil.SRC.stencilDepthFailOp); \
- dsDesc.DST.StencilPassOp = translateStencilOp( desc.depthStencil.SRC.stencilPassOp); \
- dsDesc.DST.StencilFunc = translateComparisonFunc(desc.depthStencil.SRC.stencilFunc); \
+#define FACE(DST, SRC) \
+ dsDesc.DST.StencilFailOp = translateStencilOp(desc.depthStencil.SRC.stencilFailOp); \
+ dsDesc.DST.StencilDepthFailOp = translateStencilOp(desc.depthStencil.SRC.stencilDepthFailOp); \
+ dsDesc.DST.StencilPassOp = translateStencilOp(desc.depthStencil.SRC.stencilPassOp); \
+ dsDesc.DST.StencilFunc = translateComparisonFunc(desc.depthStencil.SRC.stencilFunc); \
/* end */
FACE(FrontFace, frontFace);
FACE(BackFace, backFace);
- SLANG_RETURN_ON_FAIL(m_device->CreateDepthStencilState(
- &dsDesc,
- depthStencilState.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ m_device->CreateDepthStencilState(&dsDesc, depthStencilState.writeRef()));
}
ComPtr<ID3D11RasterizerState> rasterizerState;
@@ -1602,10 +1688,7 @@ Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc&
rsDesc.MultisampleEnable = desc.rasterizer.multisampleEnable;
rsDesc.AntialiasedLineEnable = desc.rasterizer.antialiasedLineEnable;
- SLANG_RETURN_ON_FAIL(m_device->CreateRasterizerState(
- &rsDesc,
- rasterizerState.writeRef()));
-
+ SLANG_RETURN_ON_FAIL(m_device->CreateRasterizerState(&rsDesc, rasterizerState.writeRef()));
}
ComPtr<ID3D11BlendState> blendState;
@@ -1616,7 +1699,8 @@ Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc&
TargetBlendDesc defaultTargetBlendDesc;
static const UInt kMaxTargets = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT;
- if (srcDesc.targetCount > kMaxTargets) return SLANG_FAIL;
+ if (srcDesc.targetCount > kMaxTargets)
+ return SLANG_FAIL;
for (GfxIndex ii = 0; ii < kMaxTargets; ++ii)
{
@@ -1652,21 +1736,24 @@ Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc&
dstTargetBlendDesc.BlendEnable = true;
dstTargetBlendDesc.BlendOp = translateBlendOp(srcTargetBlendDesc.color.op);
dstTargetBlendDesc.BlendOpAlpha = translateBlendOp(srcTargetBlendDesc.alpha.op);
- dstTargetBlendDesc.SrcBlend = translateBlendFactor(srcTargetBlendDesc.color.srcFactor);
- dstTargetBlendDesc.SrcBlendAlpha = translateBlendFactor(srcTargetBlendDesc.alpha.srcFactor);
- dstTargetBlendDesc.DestBlend = translateBlendFactor(srcTargetBlendDesc.color.dstFactor);
- dstTargetBlendDesc.DestBlendAlpha = translateBlendFactor(srcTargetBlendDesc.alpha.dstFactor);
+ dstTargetBlendDesc.SrcBlend =
+ translateBlendFactor(srcTargetBlendDesc.color.srcFactor);
+ dstTargetBlendDesc.SrcBlendAlpha =
+ translateBlendFactor(srcTargetBlendDesc.alpha.srcFactor);
+ dstTargetBlendDesc.DestBlend =
+ translateBlendFactor(srcTargetBlendDesc.color.dstFactor);
+ dstTargetBlendDesc.DestBlendAlpha =
+ translateBlendFactor(srcTargetBlendDesc.alpha.dstFactor);
}
- dstTargetBlendDesc.RenderTargetWriteMask = translateRenderTargetWriteMask(srcTargetBlendDesc.writeMask);
+ dstTargetBlendDesc.RenderTargetWriteMask =
+ translateRenderTargetWriteMask(srcTargetBlendDesc.writeMask);
}
dstDesc.IndependentBlendEnable = srcDesc.targetCount > 1;
dstDesc.AlphaToCoverageEnable = srcDesc.alphaToCoverageEnable;
- SLANG_RETURN_ON_FAIL(m_device->CreateBlendState(
- &dstDesc,
- blendState.writeRef()));
+ SLANG_RETURN_ON_FAIL(m_device->CreateBlendState(&dstDesc, blendState.writeRef()));
}
RefPtr<GraphicsPipelineStateImpl> state = new GraphicsPipelineStateImpl();
@@ -1675,7 +1762,7 @@ Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc&
state->m_blendState = blendState;
state->m_inputLayout = static_cast<InputLayoutImpl*>(desc.inputLayout);
state->m_rtvCount = (UINT) static_cast<FramebufferLayoutImpl*>(desc.framebufferLayout)
- ->m_renderTargets.getCount();
+ ->m_renderTargets.getCount();
state->m_blendColor[0] = 0;
state->m_blendColor[1] = 0;
state->m_blendColor[2] = 0;
@@ -1686,7 +1773,9 @@ Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc&
return SLANG_OK;
}
-Result DeviceImpl::createComputePipelineState(const ComputePipelineStateDesc& inDesc, IPipelineState** outState)
+Result DeviceImpl::createComputePipelineState(
+ const ComputePipelineStateDesc& inDesc,
+ IPipelineState** outState)
{
ComputePipelineStateDesc desc = inDesc;
@@ -1710,7 +1799,14 @@ void DeviceImpl::copyBuffer(
srcBox.right = (UINT)(srcOffset + size);
srcBox.bottom = srcBox.back = 1;
m_immediateContext->CopySubresourceRegion(
- dstImpl->m_buffer, 0, (UINT)dstOffset, 0, 0, srcImpl->m_buffer, 0, &srcBox);
+ dstImpl->m_buffer,
+ 0,
+ (UINT)dstOffset,
+ 0,
+ 0,
+ srcImpl->m_buffer,
+ 0,
+ &srcBox);
}
void DeviceImpl::dispatchCompute(int x, int y, int z)
@@ -1725,7 +1821,8 @@ void DeviceImpl::_flushGraphicsState()
m_depthStencilStateDirty = false;
auto pipelineState = static_cast<GraphicsPipelineStateImpl*>(m_currentPipelineState.Ptr());
m_immediateContext->OMSetDepthStencilState(
- pipelineState->m_depthStencilState, m_stencilRef);
+ pipelineState->m_depthStencilState,
+ m_stencilRef);
}
}
diff --git a/tools/gfx/d3d11/d3d11-device.h b/tools/gfx/d3d11/d3d11-device.h
index 42fffa3c9..0f79e82a5 100644
--- a/tools/gfx/d3d11/d3d11-device.h
+++ b/tools/gfx/d3d11/d3d11-device.h
@@ -14,18 +14,20 @@ namespace d3d11
class DeviceImpl : public ImmediateRendererBase
{
public:
-
~DeviceImpl() {}
// Renderer implementation
virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const Desc& desc) override;
virtual void clearFrame(uint32_t colorBufferMask, bool clearDepth, bool clearStencil) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override;
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
+ createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
virtual void setFramebuffer(IFramebuffer* frameBuffer) override;
virtual void setStencilReference(uint32_t referenceValue) override;
@@ -38,7 +40,7 @@ public:
const void* initData,
IBufferResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
+ createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView(
ITextureResource* texture,
@@ -51,12 +53,11 @@ public:
IResourceView::Desc const& desc,
IResourceView** outView) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL createInputLayout(
- IInputLayout::Desc const& desc,
- IInputLayout** outLayout) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ createInputLayout(IInputLayout::Desc 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 IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual Result createShaderObjectLayout(
slang::ISession* session,
@@ -64,7 +65,9 @@ public:
ShaderObjectLayoutBase** outLayout) override;
virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
override;
- virtual Result createMutableShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
+ virtual Result createMutableShaderObject(
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject) override;
virtual Result createRootShaderObject(IShaderProgram* program, ShaderObjectBase** outObject)
override;
virtual void bindRootShaderObject(IShaderObject* shaderObject) override;
@@ -74,9 +77,11 @@ public:
IShaderProgram** outProgram,
ISlangBlob** outDiagnosticBlob) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& desc, IPipelineState** outState) override;
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual void* map(IBufferResource* buffer, MapFlavor flavor) override;
virtual void unmap(IBufferResource* buffer, size_t offsetWritten, size_t sizeWritten) override;
@@ -87,7 +92,11 @@ public:
size_t srcOffset,
size_t size) override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL readTextureResource(
- ITextureResource* texture, ResourceState state, ISlangBlob** outBlob, size_t* outRowPitch, size_t* outPixelSize) override;
+ ITextureResource* texture,
+ ResourceState state,
+ ISlangBlob** outBlob,
+ size_t* outRowPitch,
+ size_t* outPixelSize) override;
virtual void setPrimitiveTopology(PrimitiveTopology topology) override;
@@ -96,14 +105,14 @@ public:
GfxCount slotCount,
IBufferResource* const* buffers,
const Offset* offsets) override;
- virtual void setIndexBuffer(
- IBufferResource* buffer, Format indexFormat, Offset offset) override;
+ virtual void setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset)
+ override;
virtual void setViewports(GfxCount count, Viewport const* viewports) override;
virtual void setScissorRects(GfxCount count, ScissorRect const* rects) override;
virtual void setPipelineState(IPipelineState* state) override;
virtual void draw(GfxCount vertexCount, GfxIndex startVertex) override;
- virtual void drawIndexed(
- GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex) override;
+ virtual void drawIndexed(GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex)
+ override;
virtual void drawInstanced(
GfxCount vertexCount,
GfxCount instanceCount,
@@ -117,10 +126,7 @@ public:
GfxIndex startInstanceLocation) override;
virtual void dispatchCompute(int x, int y, int z) override;
virtual void submitGpuWork() override {}
- virtual void waitForGpu() override
- {
-
- }
+ virtual void waitForGpu() override {}
virtual SLANG_NO_THROW const DeviceInfo& SLANG_MCALL getDeviceInfo() const override
{
return m_info;
@@ -153,7 +159,7 @@ public:
Desc m_desc;
- float m_clearColor[4] = { 0, 0, 0, 0 };
+ float m_clearColor[4] = {0, 0, 0, 0};
bool m_nvapi = false;
};
diff --git a/tools/gfx/d3d11/d3d11-helper-functions.cpp b/tools/gfx/d3d11/d3d11-helper-functions.cpp
index 6774b7d93..76b339880 100644
--- a/tools/gfx/d3d11/d3d11-helper-functions.cpp
+++ b/tools/gfx/d3d11/d3d11-helper-functions.cpp
@@ -10,345 +10,346 @@ using namespace Slang;
namespace d3d11
{
- bool isSupportedNVAPIOp(IUnknown* dev, uint32_t op)
- {
+bool isSupportedNVAPIOp(IUnknown* dev, uint32_t op)
+{
#ifdef GFX_NVAPI
- {
- bool isSupported;
- NvAPI_Status status = NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(dev, NvU32(op), &isSupported);
- return status == NVAPI_OK && isSupported;
- }
+ {
+ bool isSupported;
+ NvAPI_Status status =
+ NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(dev, NvU32(op), &isSupported);
+ return status == NVAPI_OK && isSupported;
+ }
#else
- return false;
+ return false;
#endif
- }
+}
- D3D11_BIND_FLAG calcResourceFlag(ResourceState state)
+D3D11_BIND_FLAG calcResourceFlag(ResourceState state)
+{
+ switch (state)
{
- switch (state)
- {
- case ResourceState::VertexBuffer:
- return D3D11_BIND_VERTEX_BUFFER;
- case ResourceState::IndexBuffer:
- return D3D11_BIND_INDEX_BUFFER;
- case ResourceState::ConstantBuffer:
- return D3D11_BIND_CONSTANT_BUFFER;
- case ResourceState::StreamOutput:
- return D3D11_BIND_STREAM_OUTPUT;
- case ResourceState::RenderTarget:
- return D3D11_BIND_RENDER_TARGET;
- case ResourceState::DepthRead:
- case ResourceState::DepthWrite:
- return D3D11_BIND_DEPTH_STENCIL;
- case ResourceState::UnorderedAccess:
- return D3D11_BIND_UNORDERED_ACCESS;
- case ResourceState::ShaderResource:
- case ResourceState::PixelShaderResource:
- case ResourceState::NonPixelShaderResource:
- return D3D11_BIND_SHADER_RESOURCE;
- default:
- return D3D11_BIND_FLAG(0);
- }
+ case ResourceState::VertexBuffer: return D3D11_BIND_VERTEX_BUFFER;
+ case ResourceState::IndexBuffer: return D3D11_BIND_INDEX_BUFFER;
+ case ResourceState::ConstantBuffer: return D3D11_BIND_CONSTANT_BUFFER;
+ case ResourceState::StreamOutput: return D3D11_BIND_STREAM_OUTPUT;
+ case ResourceState::RenderTarget: return D3D11_BIND_RENDER_TARGET;
+ case ResourceState::DepthRead:
+ case ResourceState::DepthWrite: return D3D11_BIND_DEPTH_STENCIL;
+ case ResourceState::UnorderedAccess: return D3D11_BIND_UNORDERED_ACCESS;
+ case ResourceState::ShaderResource:
+ case ResourceState::PixelShaderResource:
+ case ResourceState::NonPixelShaderResource: return D3D11_BIND_SHADER_RESOURCE;
+ default: return D3D11_BIND_FLAG(0);
}
+}
- int _calcResourceBindFlags(ResourceStateSet allowedStates)
+int _calcResourceBindFlags(ResourceStateSet allowedStates)
+{
+ int dstFlags = 0;
+ for (uint32_t i = 0; i < (uint32_t)ResourceState::_Count; i++)
{
- int dstFlags = 0;
- for (uint32_t i = 0; i < (uint32_t)ResourceState::_Count; i++)
- {
- auto state = (ResourceState)i;
- if (allowedStates.contains(state))
- dstFlags |= calcResourceFlag(state);
- }
- return dstFlags;
+ auto state = (ResourceState)i;
+ if (allowedStates.contains(state))
+ dstFlags |= calcResourceFlag(state);
}
+ return dstFlags;
+}
- int _calcResourceAccessFlags(MemoryType memType)
+int _calcResourceAccessFlags(MemoryType memType)
+{
+ switch (memType)
{
- 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;
- }
+ 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;
}
+}
- D3D11_FILTER_TYPE translateFilterMode(TextureFilteringMode mode)
+D3D11_FILTER_TYPE translateFilterMode(TextureFilteringMode mode)
+{
+ switch (mode)
{
- switch (mode)
- {
- default:
- return D3D11_FILTER_TYPE(0);
+ default: return D3D11_FILTER_TYPE(0);
#define CASE(SRC, DST) \
case TextureFilteringMode::SRC: return D3D11_FILTER_TYPE_##DST
- CASE(Point, POINT);
- CASE(Linear, LINEAR);
+ CASE(Point, POINT);
+ CASE(Linear, LINEAR);
#undef CASE
- }
}
+}
- D3D11_FILTER_REDUCTION_TYPE translateFilterReduction(TextureReductionOp op)
+D3D11_FILTER_REDUCTION_TYPE translateFilterReduction(TextureReductionOp op)
+{
+ switch (op)
{
- switch (op)
- {
- default:
- return D3D11_FILTER_REDUCTION_TYPE(0);
+ default: return D3D11_FILTER_REDUCTION_TYPE(0);
#define CASE(SRC, DST) \
case TextureReductionOp::SRC: return D3D11_FILTER_REDUCTION_TYPE_##DST
- CASE(Average, STANDARD);
- CASE(Comparison, COMPARISON);
- CASE(Minimum, MINIMUM);
- CASE(Maximum, MAXIMUM);
+ CASE(Average, STANDARD);
+ CASE(Comparison, COMPARISON);
+ CASE(Minimum, MINIMUM);
+ CASE(Maximum, MAXIMUM);
#undef CASE
- }
}
+}
- D3D11_TEXTURE_ADDRESS_MODE translateAddressingMode(TextureAddressingMode mode)
+D3D11_TEXTURE_ADDRESS_MODE translateAddressingMode(TextureAddressingMode mode)
+{
+ switch (mode)
{
- switch (mode)
- {
- default:
- return D3D11_TEXTURE_ADDRESS_MODE(0);
+ default: return D3D11_TEXTURE_ADDRESS_MODE(0);
#define CASE(SRC, DST) \
case TextureAddressingMode::SRC: return D3D11_TEXTURE_ADDRESS_##DST
- CASE(Wrap, WRAP);
- CASE(ClampToEdge, CLAMP);
- CASE(ClampToBorder, BORDER);
- CASE(MirrorRepeat, MIRROR);
- CASE(MirrorOnce, MIRROR_ONCE);
+ CASE(Wrap, WRAP);
+ CASE(ClampToEdge, CLAMP);
+ CASE(ClampToBorder, BORDER);
+ CASE(MirrorRepeat, MIRROR);
+ CASE(MirrorOnce, MIRROR_ONCE);
#undef CASE
- }
}
+}
- D3D11_COMPARISON_FUNC translateComparisonFunc(ComparisonFunc func)
+D3D11_COMPARISON_FUNC translateComparisonFunc(ComparisonFunc func)
+{
+ switch (func)
{
- switch (func)
- {
- default:
- // TODO: need to report failures
- return D3D11_COMPARISON_ALWAYS;
+ default:
+ // TODO: need to report failures
+ return D3D11_COMPARISON_ALWAYS;
#define CASE(FROM, TO) \
case ComparisonFunc::FROM: return D3D11_COMPARISON_##TO
- CASE(Never, NEVER);
- CASE(Less, LESS);
- CASE(Equal, EQUAL);
- CASE(LessEqual, LESS_EQUAL);
- CASE(Greater, GREATER);
- CASE(NotEqual, NOT_EQUAL);
- CASE(GreaterEqual, GREATER_EQUAL);
- CASE(Always, ALWAYS);
+ CASE(Never, NEVER);
+ CASE(Less, LESS);
+ CASE(Equal, EQUAL);
+ CASE(LessEqual, LESS_EQUAL);
+ CASE(Greater, GREATER);
+ CASE(NotEqual, NOT_EQUAL);
+ CASE(GreaterEqual, GREATER_EQUAL);
+ CASE(Always, ALWAYS);
#undef CASE
- }
}
+}
- D3D11_STENCIL_OP translateStencilOp(StencilOp op)
+D3D11_STENCIL_OP translateStencilOp(StencilOp op)
+{
+ switch (op)
{
- switch (op)
- {
- default:
- // TODO: need to report failures
- return D3D11_STENCIL_OP_KEEP;
+ default:
+ // TODO: need to report failures
+ return D3D11_STENCIL_OP_KEEP;
#define CASE(FROM, TO) \
case StencilOp::FROM: return D3D11_STENCIL_OP_##TO
- CASE(Keep, KEEP);
- CASE(Zero, ZERO);
- CASE(Replace, REPLACE);
- CASE(IncrementSaturate, INCR_SAT);
- CASE(DecrementSaturate, DECR_SAT);
- CASE(Invert, INVERT);
- CASE(IncrementWrap, INCR);
- CASE(DecrementWrap, DECR);
+ CASE(Keep, KEEP);
+ CASE(Zero, ZERO);
+ CASE(Replace, REPLACE);
+ CASE(IncrementSaturate, INCR_SAT);
+ CASE(DecrementSaturate, DECR_SAT);
+ CASE(Invert, INVERT);
+ CASE(IncrementWrap, INCR);
+ CASE(DecrementWrap, DECR);
#undef CASE
-
- }
}
+}
- D3D11_FILL_MODE translateFillMode(FillMode mode)
+D3D11_FILL_MODE translateFillMode(FillMode mode)
+{
+ switch (mode)
{
- switch (mode)
- {
- default:
- // TODO: need to report failures
- return D3D11_FILL_SOLID;
+ default:
+ // TODO: need to report failures
+ return D3D11_FILL_SOLID;
- case FillMode::Solid: return D3D11_FILL_SOLID;
- case FillMode::Wireframe: return D3D11_FILL_WIREFRAME;
- }
+ case FillMode::Solid: return D3D11_FILL_SOLID;
+ case FillMode::Wireframe: return D3D11_FILL_WIREFRAME;
}
+}
- D3D11_CULL_MODE translateCullMode(CullMode mode)
+D3D11_CULL_MODE translateCullMode(CullMode mode)
+{
+ switch (mode)
{
- switch (mode)
- {
- default:
- // TODO: need to report failures
- return D3D11_CULL_NONE;
+ default:
+ // TODO: need to report failures
+ return D3D11_CULL_NONE;
- case CullMode::None: return D3D11_CULL_NONE;
- case CullMode::Back: return D3D11_CULL_BACK;
- case CullMode::Front: return D3D11_CULL_FRONT;
- }
+ case CullMode::None: return D3D11_CULL_NONE;
+ case CullMode::Back: return D3D11_CULL_BACK;
+ case CullMode::Front: return D3D11_CULL_FRONT;
}
+}
- bool isBlendDisabled(AspectBlendDesc const& desc)
- {
- return desc.op == BlendOp::Add
- && desc.srcFactor == BlendFactor::One
- && desc.dstFactor == BlendFactor::Zero;
- }
+bool isBlendDisabled(AspectBlendDesc const& desc)
+{
+ return desc.op == BlendOp::Add && desc.srcFactor == BlendFactor::One &&
+ desc.dstFactor == BlendFactor::Zero;
+}
- bool isBlendDisabled(TargetBlendDesc const& desc)
- {
- return isBlendDisabled(desc.color)
- && isBlendDisabled(desc.alpha);
- }
+bool isBlendDisabled(TargetBlendDesc const& desc)
+{
+ return isBlendDisabled(desc.color) && isBlendDisabled(desc.alpha);
+}
- D3D11_BLEND_OP translateBlendOp(BlendOp op)
+D3D11_BLEND_OP translateBlendOp(BlendOp op)
+{
+ switch (op)
{
- switch (op)
- {
- default:
- assert(!"unimplemented");
- return (D3D11_BLEND_OP)-1;
-
-#define CASE(FROM, TO) case BlendOp::FROM: return D3D11_BLEND_OP_##TO
- CASE(Add, ADD);
- CASE(Subtract, SUBTRACT);
- CASE(ReverseSubtract, REV_SUBTRACT);
- CASE(Min, MIN);
- CASE(Max, MAX);
+ default: assert(!"unimplemented"); return (D3D11_BLEND_OP)-1;
+
+#define CASE(FROM, TO) \
+ case BlendOp::FROM: return D3D11_BLEND_OP_##TO
+ CASE(Add, ADD);
+ CASE(Subtract, SUBTRACT);
+ CASE(ReverseSubtract, REV_SUBTRACT);
+ CASE(Min, MIN);
+ CASE(Max, MAX);
#undef CASE
- }
}
+}
- D3D11_BLEND translateBlendFactor(BlendFactor factor)
+D3D11_BLEND translateBlendFactor(BlendFactor factor)
+{
+ switch (factor)
{
- switch (factor)
- {
- default:
- assert(!"unimplemented");
- return (D3D11_BLEND)-1;
-
-#define CASE(FROM, TO) case BlendFactor::FROM: return D3D11_BLEND_##TO
- CASE(Zero, ZERO);
- CASE(One, ONE);
- CASE(SrcColor, SRC_COLOR);
- CASE(InvSrcColor, INV_SRC_COLOR);
- CASE(SrcAlpha, SRC_ALPHA);
- CASE(InvSrcAlpha, INV_SRC_ALPHA);
- CASE(DestAlpha, DEST_ALPHA);
- CASE(InvDestAlpha, INV_DEST_ALPHA);
- CASE(DestColor, DEST_COLOR);
- CASE(InvDestColor, INV_DEST_ALPHA);
- CASE(SrcAlphaSaturate, SRC_ALPHA_SAT);
- CASE(BlendColor, BLEND_FACTOR);
- CASE(InvBlendColor, INV_BLEND_FACTOR);
- CASE(SecondarySrcColor, SRC1_COLOR);
- CASE(InvSecondarySrcColor, INV_SRC1_COLOR);
- CASE(SecondarySrcAlpha, SRC1_ALPHA);
- CASE(InvSecondarySrcAlpha, INV_SRC1_ALPHA);
+ default: assert(!"unimplemented"); return (D3D11_BLEND)-1;
+
+#define CASE(FROM, TO) \
+ case BlendFactor::FROM: return D3D11_BLEND_##TO
+ CASE(Zero, ZERO);
+ CASE(One, ONE);
+ CASE(SrcColor, SRC_COLOR);
+ CASE(InvSrcColor, INV_SRC_COLOR);
+ CASE(SrcAlpha, SRC_ALPHA);
+ CASE(InvSrcAlpha, INV_SRC_ALPHA);
+ CASE(DestAlpha, DEST_ALPHA);
+ CASE(InvDestAlpha, INV_DEST_ALPHA);
+ CASE(DestColor, DEST_COLOR);
+ CASE(InvDestColor, INV_DEST_ALPHA);
+ CASE(SrcAlphaSaturate, SRC_ALPHA_SAT);
+ CASE(BlendColor, BLEND_FACTOR);
+ CASE(InvBlendColor, INV_BLEND_FACTOR);
+ CASE(SecondarySrcColor, SRC1_COLOR);
+ CASE(InvSecondarySrcColor, INV_SRC1_COLOR);
+ CASE(SecondarySrcAlpha, SRC1_ALPHA);
+ CASE(InvSecondarySrcAlpha, INV_SRC1_ALPHA);
#undef CASE
- }
}
+}
- D3D11_COLOR_WRITE_ENABLE translateRenderTargetWriteMask(RenderTargetWriteMaskT mask)
- {
- UINT result = 0;
-#define CASE(FROM, TO) if(mask & RenderTargetWriteMask::Enable##FROM) result |= D3D11_COLOR_WRITE_ENABLE_##TO
+D3D11_COLOR_WRITE_ENABLE translateRenderTargetWriteMask(RenderTargetWriteMaskT mask)
+{
+ UINT result = 0;
+#define CASE(FROM, TO) \
+ if (mask & RenderTargetWriteMask::Enable##FROM) \
+ result |= D3D11_COLOR_WRITE_ENABLE_##TO
- CASE(Red, RED);
- CASE(Green, GREEN);
- CASE(Blue, BLUE);
- CASE(Alpha, ALPHA);
+ CASE(Red, RED);
+ CASE(Green, GREEN);
+ CASE(Blue, BLUE);
+ CASE(Alpha, ALPHA);
#undef CASE
- return D3D11_COLOR_WRITE_ENABLE(result);
- }
+ return D3D11_COLOR_WRITE_ENABLE(result);
+}
- void initSrvDesc(IResource::Type resourceType, const ITextureResource::Desc& textureDesc, DXGI_FORMAT pixelFormat, D3D11_SHADER_RESOURCE_VIEW_DESC& descOut)
+void initSrvDesc(
+ IResource::Type resourceType,
+ const ITextureResource::Desc& textureDesc,
+ DXGI_FORMAT pixelFormat,
+ D3D11_SHADER_RESOURCE_VIEW_DESC& descOut)
+{
+ // create SRV
+ descOut = D3D11_SHADER_RESOURCE_VIEW_DESC();
+
+ descOut.Format =
+ (pixelFormat == DXGI_FORMAT_UNKNOWN)
+ ? D3DUtil::calcFormat(D3DUtil::USAGE_SRV, D3DUtil::getMapFormat(textureDesc.format))
+ : pixelFormat;
+ const int arraySize = calcEffectiveArraySize(textureDesc);
+ if (arraySize <= 1)
{
- // create SRV
- descOut = D3D11_SHADER_RESOURCE_VIEW_DESC();
-
- descOut.Format = (pixelFormat == DXGI_FORMAT_UNKNOWN) ? D3DUtil::calcFormat(D3DUtil::USAGE_SRV, D3DUtil::getMapFormat(textureDesc.format)) : pixelFormat;
- const int arraySize = calcEffectiveArraySize(textureDesc);
- if (arraySize <= 1)
+ switch (textureDesc.type)
{
- switch (textureDesc.type)
- {
- case IResource::Type::Texture1D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D; break;
- case IResource::Type::Texture2D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; break;
- case IResource::Type::Texture3D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; break;
- default: assert(!"Unknown dimension");
- }
-
- descOut.Texture2D.MipLevels = textureDesc.numMipLevels;
- descOut.Texture2D.MostDetailedMip = 0;
+ case IResource::Type::Texture1D:
+ descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
+ break;
+ case IResource::Type::Texture2D:
+ descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+ break;
+ case IResource::Type::Texture3D:
+ descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
+ break;
+ default: assert(!"Unknown dimension");
}
- else if (resourceType == IResource::Type::TextureCube)
+
+ descOut.Texture2D.MipLevels = textureDesc.numMipLevels;
+ descOut.Texture2D.MostDetailedMip = 0;
+ }
+ else if (resourceType == IResource::Type::TextureCube)
+ {
+ if (textureDesc.arraySize > 1)
{
- if (textureDesc.arraySize > 1)
- {
- descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY;
-
- descOut.TextureCubeArray.NumCubes = textureDesc.arraySize;
- descOut.TextureCubeArray.First2DArrayFace = 0;
- descOut.TextureCubeArray.MipLevels = textureDesc.numMipLevels;
- descOut.TextureCubeArray.MostDetailedMip = 0;
- }
- else
- {
- descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
-
- descOut.TextureCube.MipLevels = textureDesc.numMipLevels;
- descOut.TextureCube.MostDetailedMip = 0;
- }
+ descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY;
+
+ descOut.TextureCubeArray.NumCubes = textureDesc.arraySize;
+ descOut.TextureCubeArray.First2DArrayFace = 0;
+ descOut.TextureCubeArray.MipLevels = textureDesc.numMipLevels;
+ descOut.TextureCubeArray.MostDetailedMip = 0;
}
else
{
- assert(textureDesc.size.depth > 1 || arraySize > 1);
+ descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
- switch (textureDesc.type)
- {
- case IResource::Type::Texture1D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY; break;
- case IResource::Type::Texture2D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; break;
- case IResource::Type::Texture3D: descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; break;
-
- default: assert(!"Unknown dimension");
- }
+ descOut.TextureCube.MipLevels = textureDesc.numMipLevels;
+ descOut.TextureCube.MostDetailedMip = 0;
+ }
+ }
+ else
+ {
+ assert(textureDesc.size.depth > 1 || arraySize > 1);
- descOut.Texture2DArray.ArraySize = std::max(textureDesc.size.depth, arraySize);
- descOut.Texture2DArray.MostDetailedMip = 0;
- descOut.Texture2DArray.MipLevels = textureDesc.numMipLevels;
- descOut.Texture2DArray.FirstArraySlice = 0;
+ switch (textureDesc.type)
+ {
+ case IResource::Type::Texture1D:
+ descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
+ break;
+ case IResource::Type::Texture2D:
+ descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
+ break;
+ case IResource::Type::Texture3D:
+ descOut.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
+ break;
+
+ default: assert(!"Unknown dimension");
}
+
+ descOut.Texture2DArray.ArraySize = std::max(textureDesc.size.depth, arraySize);
+ descOut.Texture2DArray.MostDetailedMip = 0;
+ descOut.Texture2DArray.MipLevels = textureDesc.numMipLevels;
+ descOut.Texture2DArray.FirstArraySlice = 0;
}
+}
} // namespace d3d11
Result SLANG_MCALL getD3D11Adapters(List<AdapterInfo>& outAdapters)
{
List<ComPtr<IDXGIAdapter>> dxgiAdapters;
- SLANG_RETURN_ON_FAIL(D3DUtil::findAdapters(DeviceCheckFlag::UseHardwareDevice, nullptr, dxgiAdapters));
+ SLANG_RETURN_ON_FAIL(
+ D3DUtil::findAdapters(DeviceCheckFlag::UseHardwareDevice, nullptr, dxgiAdapters));
outAdapters.clear();
for (const auto& dxgiAdapter : dxgiAdapters)
@@ -357,7 +358,10 @@ Result SLANG_MCALL getD3D11Adapters(List<AdapterInfo>& outAdapters)
dxgiAdapter->GetDesc(&desc);
AdapterInfo info = {};
auto name = String::fromWString(desc.Description);
- memcpy(info.name, name.getBuffer(), Math::Min(name.getLength(), (Index)sizeof(AdapterInfo::name) - 1));
+ memcpy(
+ info.name,
+ name.getBuffer(),
+ Math::Min(name.getLength(), (Index)sizeof(AdapterInfo::name) - 1));
info.vendorID = desc.VendorId;
info.deviceID = desc.DeviceId;
info.luid = D3DUtil::getAdapterLUID(dxgiAdapter);
diff --git a/tools/gfx/d3d11/d3d11-helper-functions.h b/tools/gfx/d3d11/d3d11-helper-functions.h
index 9f115d88d..cca49de14 100644
--- a/tools/gfx/d3d11/d3d11-helper-functions.h
+++ b/tools/gfx/d3d11/d3d11-helper-functions.h
@@ -1,9 +1,9 @@
// d3d11-helper-functions.h
#pragma once
-#include "slang-gfx.h"
-#include "d3d11-base.h"
#include "../../../source/core/slang-list.h"
+#include "d3d11-base.h"
+#include "slang-gfx.h"
namespace gfx
{
@@ -12,274 +12,265 @@ using namespace Slang;
namespace d3d11
{
- /// Contextual data and operations required when binding shader objects to the pipeline state
- struct BindingContext
+/// Contextual data and operations required when binding shader objects to the pipeline state
+struct BindingContext
+{
+ // One key service that the `BindingContext` provides is abstracting over
+ // the difference between the D3D11 compute and graphics/rasteriation pipelines.
+ // D3D11 has distinct operations for, e.g., `CSSetShaderResources`
+ // for compute vs. `VSSetShaderResources` and `PSSetShaderResources`
+ // for rasterization.
+ //
+ // The context type provides simple operations for setting each class
+ // of resource/sampler, which will be overridden in derived types.
+ //
+ // TODO: These operations should really support binding multiple resources/samplers
+ // in one call, so that we can eventually make more efficient use of the API.
+ //
+ // TODO: We could reasonably also just store the bound resources into
+ // lcoal arrays like we are doing for UAVs, and remove the pipeline-specific
+ // virtual functions. However, doing so would seemingly eliminate any
+ // chance of avoiding redundant binding work when binding changes are
+ // made for a root shader object.
+ //
+ virtual void setCBV(UINT index, ID3D11Buffer* buffer) = 0;
+ virtual void setSRV(UINT index, ID3D11ShaderResourceView* srv) = 0;
+ virtual void setSampler(UINT index, ID3D11SamplerState* sampler) = 0;
+
+ // Unordered Access Views (UAVs) are a somewhat special case in that
+ // the D3D11 API requires them to all be set at once, rather than one
+ // at a time. To support this, we will keep a local array of the UAVs
+ // that have been bound (up to the maximum supported by D3D 11.0)
+ //
+ void setUAV(UINT index, ID3D11UnorderedAccessView* uav)
{
- // One key service that the `BindingContext` provides is abstracting over
- // the difference between the D3D11 compute and graphics/rasteriation pipelines.
- // D3D11 has distinct operations for, e.g., `CSSetShaderResources`
- // for compute vs. `VSSetShaderResources` and `PSSetShaderResources`
- // for rasterization.
- //
- // The context type provides simple operations for setting each class
- // of resource/sampler, which will be overridden in derived types.
- //
- // TODO: These operations should really support binding multiple resources/samplers
- // in one call, so that we can eventually make more efficient use of the API.
- //
- // TODO: We could reasonably also just store the bound resources into
- // lcoal arrays like we are doing for UAVs, and remove the pipeline-specific
- // virtual functions. However, doing so would seemingly eliminate any
- // chance of avoiding redundant binding work when binding changes are
- // made for a root shader object.
- //
- virtual void setCBV(UINT index, ID3D11Buffer* buffer) = 0;
- virtual void setSRV(UINT index, ID3D11ShaderResourceView* srv) = 0;
- virtual void setSampler(UINT index, ID3D11SamplerState* sampler) = 0;
-
- // Unordered Access Views (UAVs) are a somewhat special case in that
- // the D3D11 API requires them to all be set at once, rather than one
- // at a time. To support this, we will keep a local array of the UAVs
- // that have been bound (up to the maximum supported by D3D 11.0)
+ uavs[index] = uav;
+
+ // We will also track the total number of UAV slots that will
+ // need to be bound (including any gaps that might occur due
+ // to either explicit bindings or RTV bindings that conflict
+ // with the `u` registers for fragment shaders).
//
- void setUAV(UINT index, ID3D11UnorderedAccessView* uav)
+ if (uavCount <= index)
{
- uavs[index] = uav;
-
- // We will also track the total number of UAV slots that will
- // need to be bound (including any gaps that might occur due
- // to either explicit bindings or RTV bindings that conflict
- // with the `u` registers for fragment shaders).
- //
- if (uavCount <= index)
- {
- uavCount = index + 1;
- }
+ uavCount = index + 1;
}
+ }
- /// The values bound for any UAVs
- ID3D11UnorderedAccessView* uavs[D3D11_PS_CS_UAV_REGISTER_COUNT];
+ /// The values bound for any UAVs
+ ID3D11UnorderedAccessView* uavs[D3D11_PS_CS_UAV_REGISTER_COUNT];
- /// The number of entries in `uavs` that need to be considered when binding to the pipeline
- UINT uavCount = 0;
+ /// The number of entries in `uavs` that need to be considered when binding to the pipeline
+ UINT uavCount = 0;
- /// The D3D11 device that we are using for binding
- DeviceImpl* device = nullptr;
+ /// The D3D11 device that we are using for binding
+ DeviceImpl* device = nullptr;
- /// The D3D11 device context that we are using for binding
- ID3D11DeviceContext* context = nullptr;
+ /// The D3D11 device context that we are using for binding
+ ID3D11DeviceContext* context = nullptr;
- /// Initialize a binding context for binding to the given `device` and `context`
- BindingContext(
- DeviceImpl* device,
- ID3D11DeviceContext* context)
- : device(device)
- , context(context)
- {
- memset(uavs, 0, sizeof(uavs));
- }
- };
-
- /// A `BindingContext` for binding to the compute pipeline
- struct ComputeBindingContext : BindingContext
+ /// Initialize a binding context for binding to the given `device` and `context`
+ BindingContext(DeviceImpl* device, ID3D11DeviceContext* context)
+ : device(device), context(context)
{
- /// Initialize a binding context for binding to the given `device` and `context`
- ComputeBindingContext(
- DeviceImpl* device,
- ID3D11DeviceContext* context)
- : BindingContext(device, context)
- {}
-
- void setCBV(UINT index, ID3D11Buffer* buffer) SLANG_OVERRIDE
- {
- context->CSSetConstantBuffers(index, 1, &buffer);
- }
+ memset(uavs, 0, sizeof(uavs));
+ }
+};
- void setSRV(UINT index, ID3D11ShaderResourceView* srv) SLANG_OVERRIDE
- {
- context->CSSetShaderResources(index, 1, &srv);
- }
+/// A `BindingContext` for binding to the compute pipeline
+struct ComputeBindingContext : BindingContext
+{
+ /// Initialize a binding context for binding to the given `device` and `context`
+ ComputeBindingContext(DeviceImpl* device, ID3D11DeviceContext* context)
+ : BindingContext(device, context)
+ {
+ }
- void setSampler(UINT index, ID3D11SamplerState* sampler) SLANG_OVERRIDE
- {
- context->CSSetSamplers(index, 1, &sampler);
- }
- };
+ void setCBV(UINT index, ID3D11Buffer* buffer) SLANG_OVERRIDE
+ {
+ context->CSSetConstantBuffers(index, 1, &buffer);
+ }
- /// A `BindingContext` for binding to the graphics/rasterization pipeline
- struct GraphicsBindingContext : BindingContext
+ void setSRV(UINT index, ID3D11ShaderResourceView* srv) SLANG_OVERRIDE
{
- /// Initialize a binding context for binding to the given `device` and `context`
- GraphicsBindingContext(
- DeviceImpl* device,
- ID3D11DeviceContext* context)
- : BindingContext(device, context)
- {}
-
- // TODO: The operations here are only dealing with vertex and fragment
- // shaders for now. We should eventually extend them to handle HS/DS/GS
- // bindings. (We might want to skip those stages depending on whether
- // the associated program uses them at all).
- //
- // TODO: If we support cases where different stages might use distinct
- // entry-point parameters, we might need to support some modes where
- // a "stage mask" is passed in that applies to the bindings.
- //
- void setCBV(UINT index, ID3D11Buffer* buffer) SLANG_OVERRIDE
- {
- context->VSSetConstantBuffers(index, 1, &buffer);
- context->PSSetConstantBuffers(index, 1, &buffer);
- }
+ context->CSSetShaderResources(index, 1, &srv);
+ }
- void setSRV(UINT index, ID3D11ShaderResourceView* srv) SLANG_OVERRIDE
- {
- context->VSSetShaderResources(index, 1, &srv);
- context->PSSetShaderResources(index, 1, &srv);
- }
+ void setSampler(UINT index, ID3D11SamplerState* sampler) SLANG_OVERRIDE
+ {
+ context->CSSetSamplers(index, 1, &sampler);
+ }
+};
- void setSampler(UINT index, ID3D11SamplerState* sampler) SLANG_OVERRIDE
- {
- context->VSSetSamplers(index, 1, &sampler);
- context->PSSetSamplers(index, 1, &sampler);
- }
- };
+/// A `BindingContext` for binding to the graphics/rasterization pipeline
+struct GraphicsBindingContext : BindingContext
+{
+ /// Initialize a binding context for binding to the given `device` and `context`
+ GraphicsBindingContext(DeviceImpl* device, ID3D11DeviceContext* context)
+ : BindingContext(device, context)
+ {
+ }
- // In order to bind shader parameters to the correct locations, we need to
- // be able to describe those locations. Most shader parameters will
- // only consume a single type of D3D11-visible regsiter (e.g., a `t`
- // register for a txture, or an `s` register for a sampler), and scalar
- // integers suffice for these cases.
+ // TODO: The operations here are only dealing with vertex and fragment
+ // shaders for now. We should eventually extend them to handle HS/DS/GS
+ // bindings. (We might want to skip those stages depending on whether
+ // the associated program uses them at all).
+ //
+ // TODO: If we support cases where different stages might use distinct
+ // entry-point parameters, we might need to support some modes where
+ // a "stage mask" is passed in that applies to the bindings.
//
- // In more complex cases we might be binding an entire "sub-object" like
- // a parameter block, an entry point, etc. For the general case, we need
- // to be able to represent a composite offset that includes offsets for
- // each of the register classes known to D3D11.
+ void setCBV(UINT index, ID3D11Buffer* buffer) SLANG_OVERRIDE
+ {
+ context->VSSetConstantBuffers(index, 1, &buffer);
+ context->PSSetConstantBuffers(index, 1, &buffer);
+ }
- /// A "simple" binding offset that records an offset in CBV/SRV/UAV/Sampler slots
- struct SimpleBindingOffset
+ void setSRV(UINT index, ID3D11ShaderResourceView* srv) SLANG_OVERRIDE
{
- uint32_t cbv = 0;
- uint32_t srv = 0;
- uint32_t uav = 0;
- uint32_t sampler = 0;
+ context->VSSetShaderResources(index, 1, &srv);
+ context->PSSetShaderResources(index, 1, &srv);
+ }
- /// Create a default (zero) offset
- SimpleBindingOffset()
- {}
+ void setSampler(UINT index, ID3D11SamplerState* sampler) SLANG_OVERRIDE
+ {
+ context->VSSetSamplers(index, 1, &sampler);
+ context->PSSetSamplers(index, 1, &sampler);
+ }
+};
+
+// In order to bind shader parameters to the correct locations, we need to
+// be able to describe those locations. Most shader parameters will
+// only consume a single type of D3D11-visible regsiter (e.g., a `t`
+// register for a txture, or an `s` register for a sampler), and scalar
+// integers suffice for these cases.
+//
+// In more complex cases we might be binding an entire "sub-object" like
+// a parameter block, an entry point, etc. For the general case, we need
+// to be able to represent a composite offset that includes offsets for
+// each of the register classes known to D3D11.
+
+/// A "simple" binding offset that records an offset in CBV/SRV/UAV/Sampler slots
+struct SimpleBindingOffset
+{
+ uint32_t cbv = 0;
+ uint32_t srv = 0;
+ uint32_t uav = 0;
+ uint32_t sampler = 0;
- /// Create an offset based on offset information in the given Slang `varLayout`
- SimpleBindingOffset(slang::VariableLayoutReflection* varLayout)
- {
- if (varLayout)
- {
- cbv = (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER);
- srv = (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE);
- uav = (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS);
- sampler = (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_SAMPLER_STATE);
- }
- }
+ /// Create a default (zero) offset
+ SimpleBindingOffset() {}
- /// Create an offset based on size/stride information in the given Slang `typeLayout`
- SimpleBindingOffset(slang::TypeLayoutReflection* typeLayout)
+ /// Create an offset based on offset information in the given Slang `varLayout`
+ SimpleBindingOffset(slang::VariableLayoutReflection* varLayout)
+ {
+ if (varLayout)
{
- if (typeLayout)
- {
- cbv = (uint32_t)typeLayout->getSize(SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER);
- srv = (uint32_t)typeLayout->getSize(SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE);
- uav = (uint32_t)typeLayout->getSize(SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS);
- sampler = (uint32_t)typeLayout->getSize(SLANG_PARAMETER_CATEGORY_SAMPLER_STATE);
- }
+ cbv = (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER);
+ srv = (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE);
+ uav = (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS);
+ sampler = (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_SAMPLER_STATE);
}
+ }
- /// Add any values in the given `offset`
- void operator+=(SimpleBindingOffset const& offset)
+ /// Create an offset based on size/stride information in the given Slang `typeLayout`
+ SimpleBindingOffset(slang::TypeLayoutReflection* typeLayout)
+ {
+ if (typeLayout)
{
- cbv += offset.cbv;
- srv += offset.srv;
- uav += offset.uav;
- sampler += offset.sampler;
+ cbv = (uint32_t)typeLayout->getSize(SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER);
+ srv = (uint32_t)typeLayout->getSize(SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE);
+ uav = (uint32_t)typeLayout->getSize(SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS);
+ sampler = (uint32_t)typeLayout->getSize(SLANG_PARAMETER_CATEGORY_SAMPLER_STATE);
}
- };
+ }
- // While a "simple" binding offset representation will work in many cases,
- // once we need to deal with layout for programs with interface-type parameters
- // that have been statically specialized, we also need to track the offset
- // for where to bind any "pending" data that arises from the process of static
- // specialization.
- //
- // In order to conveniently track both the "primary" and "pending" offset information,
- // we will define a more complete `BindingOffset` type that combines simple
- // binding offsets for the primary and pending parts.
+ /// Add any values in the given `offset`
+ void operator+=(SimpleBindingOffset const& offset)
+ {
+ cbv += offset.cbv;
+ srv += offset.srv;
+ uav += offset.uav;
+ sampler += offset.sampler;
+ }
+};
+
+// While a "simple" binding offset representation will work in many cases,
+// once we need to deal with layout for programs with interface-type parameters
+// that have been statically specialized, we also need to track the offset
+// for where to bind any "pending" data that arises from the process of static
+// specialization.
+//
+// In order to conveniently track both the "primary" and "pending" offset information,
+// we will define a more complete `BindingOffset` type that combines simple
+// binding offsets for the primary and pending parts.
+
+/// A representation of the offset at which to bind a shader parameter or sub-object
+struct BindingOffset : SimpleBindingOffset
+{
+ // Offsets for "primary" data are stored directly in the `BindingOffset`
+ // via the inheritance from `SimpleBindingOffset`.
+
+ /// Offset for any "pending" data
+ SimpleBindingOffset pending;
- /// A representation of the offset at which to bind a shader parameter or sub-object
- struct BindingOffset : SimpleBindingOffset
+ /// Create a default (zero) offset
+ BindingOffset() {}
+
+ /// Create an offset from a simple offset
+ explicit BindingOffset(SimpleBindingOffset const& offset)
+ : SimpleBindingOffset(offset)
{
- // Offsets for "primary" data are stored directly in the `BindingOffset`
- // via the inheritance from `SimpleBindingOffset`.
-
- /// Offset for any "pending" data
- SimpleBindingOffset pending;
-
- /// Create a default (zero) offset
- BindingOffset()
- {}
-
- /// Create an offset from a simple offset
- explicit BindingOffset(SimpleBindingOffset const& offset)
- : SimpleBindingOffset(offset)
- {}
-
- /// Create an offset based on offset information in the given Slang `varLayout`
- BindingOffset(slang::VariableLayoutReflection* varLayout)
- : SimpleBindingOffset(varLayout)
- , pending(varLayout->getPendingDataLayout())
- {}
-
- /// Create an offset based on size/stride information in the given Slang `typeLayout`
- BindingOffset(slang::TypeLayoutReflection* typeLayout)
- : SimpleBindingOffset(typeLayout)
- , pending(typeLayout->getPendingDataTypeLayout())
- {}
-
- /// Add any values in the given `offset`
- void operator+=(SimpleBindingOffset const& offset)
- {
- SimpleBindingOffset::operator+=(offset);
- }
+ }
- /// Add any values in the given `offset`
- void operator+=(BindingOffset const& offset)
- {
- SimpleBindingOffset::operator+=(offset);
- pending += offset.pending;
- }
- };
-
- bool isSupportedNVAPIOp(IUnknown* dev, uint32_t op);
-
- D3D11_BIND_FLAG calcResourceFlag(ResourceState state);
- int _calcResourceBindFlags(ResourceStateSet allowedStates);
- int _calcResourceAccessFlags(MemoryType memType);
-
- D3D11_FILTER_TYPE translateFilterMode(TextureFilteringMode mode);
- D3D11_FILTER_REDUCTION_TYPE translateFilterReduction(TextureReductionOp op);
- D3D11_TEXTURE_ADDRESS_MODE translateAddressingMode(TextureAddressingMode mode);
- D3D11_COMPARISON_FUNC translateComparisonFunc(ComparisonFunc func);
-
- D3D11_STENCIL_OP translateStencilOp(StencilOp op);
- D3D11_FILL_MODE translateFillMode(FillMode mode);
- D3D11_CULL_MODE translateCullMode(CullMode mode);
- bool isBlendDisabled(AspectBlendDesc const& desc);
- bool isBlendDisabled(TargetBlendDesc const& desc);
- D3D11_BLEND_OP translateBlendOp(BlendOp op);
- D3D11_BLEND translateBlendFactor(BlendFactor factor);
- D3D11_COLOR_WRITE_ENABLE translateRenderTargetWriteMask(RenderTargetWriteMaskT mask);
-
- void initSrvDesc(
- IResource::Type resourceType,
- const ITextureResource::Desc& textureDesc,
- DXGI_FORMAT pixelFormat,
- D3D11_SHADER_RESOURCE_VIEW_DESC& descOut);
+ /// Create an offset based on offset information in the given Slang `varLayout`
+ BindingOffset(slang::VariableLayoutReflection* varLayout)
+ : SimpleBindingOffset(varLayout), pending(varLayout->getPendingDataLayout())
+ {
+ }
+
+ /// Create an offset based on size/stride information in the given Slang `typeLayout`
+ BindingOffset(slang::TypeLayoutReflection* typeLayout)
+ : SimpleBindingOffset(typeLayout), pending(typeLayout->getPendingDataTypeLayout())
+ {
+ }
+
+ /// Add any values in the given `offset`
+ void operator+=(SimpleBindingOffset const& offset) { SimpleBindingOffset::operator+=(offset); }
+
+ /// Add any values in the given `offset`
+ void operator+=(BindingOffset const& offset)
+ {
+ SimpleBindingOffset::operator+=(offset);
+ pending += offset.pending;
+ }
+};
+
+bool isSupportedNVAPIOp(IUnknown* dev, uint32_t op);
+
+D3D11_BIND_FLAG calcResourceFlag(ResourceState state);
+int _calcResourceBindFlags(ResourceStateSet allowedStates);
+int _calcResourceAccessFlags(MemoryType memType);
+
+D3D11_FILTER_TYPE translateFilterMode(TextureFilteringMode mode);
+D3D11_FILTER_REDUCTION_TYPE translateFilterReduction(TextureReductionOp op);
+D3D11_TEXTURE_ADDRESS_MODE translateAddressingMode(TextureAddressingMode mode);
+D3D11_COMPARISON_FUNC translateComparisonFunc(ComparisonFunc func);
+
+D3D11_STENCIL_OP translateStencilOp(StencilOp op);
+D3D11_FILL_MODE translateFillMode(FillMode mode);
+D3D11_CULL_MODE translateCullMode(CullMode mode);
+bool isBlendDisabled(AspectBlendDesc const& desc);
+bool isBlendDisabled(TargetBlendDesc const& desc);
+D3D11_BLEND_OP translateBlendOp(BlendOp op);
+D3D11_BLEND translateBlendFactor(BlendFactor factor);
+D3D11_COLOR_WRITE_ENABLE translateRenderTargetWriteMask(RenderTargetWriteMaskT mask);
+
+void initSrvDesc(
+ IResource::Type resourceType,
+ const ITextureResource::Desc& textureDesc,
+ DXGI_FORMAT pixelFormat,
+ D3D11_SHADER_RESOURCE_VIEW_DESC& descOut);
} // namespace d3d11
Result SLANG_MCALL getD3D11Adapters(List<AdapterInfo>& outAdapters);
diff --git a/tools/gfx/d3d11/d3d11-pipeline-state.h b/tools/gfx/d3d11/d3d11-pipeline-state.h
index 7ca812d1d..dec4ef285 100644
--- a/tools/gfx/d3d11/d3d11-pipeline-state.h
+++ b/tools/gfx/d3d11/d3d11-pipeline-state.h
@@ -19,15 +19,15 @@ public:
class GraphicsPipelineStateImpl : public PipelineStateImpl
{
public:
- UINT m_rtvCount;
+ UINT m_rtvCount;
- RefPtr<InputLayoutImpl> m_inputLayout;
+ RefPtr<InputLayoutImpl> m_inputLayout;
ComPtr<ID3D11DepthStencilState> m_depthStencilState;
- ComPtr<ID3D11RasterizerState> m_rasterizerState;
- ComPtr<ID3D11BlendState> m_blendState;
+ ComPtr<ID3D11RasterizerState> m_rasterizerState;
+ ComPtr<ID3D11BlendState> m_blendState;
- float m_blendColor[4];
- UINT m_sampleMask;
+ float m_blendColor[4];
+ UINT m_sampleMask;
void init(const GraphicsPipelineStateDesc& inDesc);
};
diff --git a/tools/gfx/d3d11/d3d11-query.cpp b/tools/gfx/d3d11/d3d11-query.cpp
index c917ccbca..1a1c27466 100644
--- a/tools/gfx/d3d11/d3d11-query.cpp
+++ b/tools/gfx/d3d11/d3d11-query.cpp
@@ -17,11 +17,8 @@ Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
m_queryDesc.MiscFlags = 0;
switch (desc.type)
{
- case QueryType::Timestamp:
- m_queryDesc.Query = D3D11_QUERY_TIMESTAMP;
- break;
- default:
- return SLANG_E_INVALID_ARG;
+ case QueryType::Timestamp: m_queryDesc.Query = D3D11_QUERY_TIMESTAMP; break;
+ default: return SLANG_E_INVALID_ARG;
}
m_queries.setCount(desc.count);
return SLANG_OK;
@@ -34,12 +31,15 @@ ID3D11Query* QueryPoolImpl::getQuery(SlangInt index)
return m_queries[index].get();
}
-SLANG_NO_THROW Result SLANG_MCALL QueryPoolImpl::getResult(
- GfxIndex queryIndex, GfxCount count, uint64_t* data)
+SLANG_NO_THROW Result SLANG_MCALL
+QueryPoolImpl::getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data)
{
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjointData;
while (S_OK != m_device->m_immediateContext->GetData(
- m_device->m_disjointQuery, &disjointData, sizeof(D3D11_QUERY_DATA_TIMESTAMP_DISJOINT), 0))
+ m_device->m_disjointQuery,
+ &disjointData,
+ sizeof(D3D11_QUERY_DATA_TIMESTAMP_DISJOINT),
+ 0))
{
Process::sleepCurrentThread(1);
}
@@ -48,7 +48,10 @@ SLANG_NO_THROW Result SLANG_MCALL QueryPoolImpl::getResult(
for (SlangInt i = 0; i < count; i++)
{
SLANG_RETURN_ON_FAIL(m_device->m_immediateContext->GetData(
- m_queries[queryIndex + i], data + i, sizeof(uint64_t), 0));
+ m_queries[queryIndex + i],
+ data + i,
+ sizeof(uint64_t),
+ 0));
}
return SLANG_OK;
}
diff --git a/tools/gfx/d3d11/d3d11-query.h b/tools/gfx/d3d11/d3d11-query.h
index 393294c0a..63866d848 100644
--- a/tools/gfx/d3d11/d3d11-query.h
+++ b/tools/gfx/d3d11/d3d11-query.h
@@ -1,7 +1,6 @@
// d3d11-query.h
#pragma once
#include "d3d11-base.h"
-
#include "d3d11-device.h"
namespace gfx
@@ -12,18 +11,18 @@ using namespace Slang;
namespace d3d11
{
- class QueryPoolImpl : public QueryPoolBase
- {
- public:
- List<ComPtr<ID3D11Query>> m_queries;
- RefPtr<DeviceImpl> m_device;
- D3D11_QUERY_DESC m_queryDesc;
+class QueryPoolImpl : public QueryPoolBase
+{
+public:
+ List<ComPtr<ID3D11Query>> m_queries;
+ RefPtr<DeviceImpl> m_device;
+ D3D11_QUERY_DESC m_queryDesc;
- Result init(const IQueryPool::Desc& desc, DeviceImpl* device);
- ID3D11Query* getQuery(SlangInt index);
- virtual SLANG_NO_THROW Result SLANG_MCALL getResult(
- GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
- };
+ Result init(const IQueryPool::Desc& desc, DeviceImpl* device);
+ ID3D11Query* getQuery(SlangInt index);
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
+};
} // namespace d3d11
} // namespace gfx
diff --git a/tools/gfx/d3d11/d3d11-resource-views.h b/tools/gfx/d3d11/d3d11-resource-views.h
index f76acd98b..1ce385f20 100644
--- a/tools/gfx/d3d11/d3d11-resource-views.h
+++ b/tools/gfx/d3d11/d3d11-resource-views.h
@@ -27,26 +27,26 @@ public:
class ShaderResourceViewImpl : public ResourceViewImpl
{
public:
- ComPtr<ID3D11ShaderResourceView> m_srv;
+ ComPtr<ID3D11ShaderResourceView> m_srv;
};
class UnorderedAccessViewImpl : public ResourceViewImpl
{
public:
- ComPtr<ID3D11UnorderedAccessView> m_uav;
+ ComPtr<ID3D11UnorderedAccessView> m_uav;
};
class DepthStencilViewImpl : public ResourceViewImpl
{
public:
- ComPtr<ID3D11DepthStencilView> m_dsv;
+ ComPtr<ID3D11DepthStencilView> m_dsv;
DepthStencilClearValue m_clearValue;
};
class RenderTargetViewImpl : public ResourceViewImpl
{
public:
- ComPtr<ID3D11RenderTargetView> m_rtv;
+ ComPtr<ID3D11RenderTargetView> m_rtv;
float m_clearValue[4];
};
diff --git a/tools/gfx/d3d11/d3d11-scopeNVAPI.h b/tools/gfx/d3d11/d3d11-scopeNVAPI.h
index 0de611ee0..1e49f2db8 100644
--- a/tools/gfx/d3d11/d3d11-scopeNVAPI.h
+++ b/tools/gfx/d3d11/d3d11-scopeNVAPI.h
@@ -14,7 +14,10 @@ namespace d3d11
class ScopeNVAPI
{
public:
- ScopeNVAPI() : m_renderer(nullptr) {}
+ ScopeNVAPI()
+ : m_renderer(nullptr)
+ {
+ }
SlangResult init(DeviceImpl* renderer, Index regIndex);
~ScopeNVAPI();
diff --git a/tools/gfx/d3d11/d3d11-shader-object-layout.cpp b/tools/gfx/d3d11/d3d11-shader-object-layout.cpp
index 70204e4c0..b2b851760 100644
--- a/tools/gfx/d3d11/d3d11-shader-object-layout.cpp
+++ b/tools/gfx/d3d11/d3d11-shader-object-layout.cpp
@@ -29,7 +29,8 @@ ShaderObjectLayoutImpl::SubObjectRangeStride::SubObjectRangeStride(
}
}
-Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutReflection* typeLayout)
+Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(
+ slang::TypeLayoutReflection* typeLayout)
{
typeLayout = _unwrapParameterGroups(typeLayout, m_containerType);
@@ -89,8 +90,7 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
m_samplerRanges.add(r);
break;
- case slang::BindingType::CombinedTextureSampler:
- break;
+ case slang::BindingType::CombinedTextureSampler: break;
case slang::BindingType::MutableTexture:
case slang::BindingType::MutableTypedBuffer:
bindingRangeInfo.baseIndex = m_uavCount;
@@ -98,11 +98,9 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
m_uavRanges.add(r);
break;
- case slang::BindingType::VaryingInput:
- break;
+ case slang::BindingType::VaryingInput: break;
- case slang::BindingType::VaryingOutput:
- break;
+ case slang::BindingType::VaryingOutput: break;
default:
bindingRangeInfo.baseIndex = m_srvCount;
@@ -138,7 +136,9 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
SLANG_ASSERT(descriptorSetIndex == 0);
SlangInt descriptorRangeIndex = typeLayout->getBindingRangeFirstDescriptorRangeIndex(r);
- auto registerOffset = typeLayout->getDescriptorSetDescriptorRangeIndexOffset(descriptorSetIndex, descriptorRangeIndex);
+ auto registerOffset = typeLayout->getDescriptorSetDescriptorRangeIndexOffset(
+ descriptorSetIndex,
+ descriptorRangeIndex);
bindingRangeInfo.registerOffset = (uint32_t)registerOffset;
}
@@ -173,18 +173,18 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
switch (slangBindingType)
{
default:
- {
- // In the case of `ConstantBuffer<X>` or `ParameterBlock<X>`
- // we can construct a layout from the element type directly.
- //
- auto elementTypeLayout = slangLeafTypeLayout->getElementTypeLayout();
- createForElementType(
- m_renderer,
- m_session,
- elementTypeLayout,
- subObjectLayout.writeRef());
- }
- break;
+ {
+ // In the case of `ConstantBuffer<X>` or `ParameterBlock<X>`
+ // we can construct a layout from the element type directly.
+ //
+ auto elementTypeLayout = slangLeafTypeLayout->getElementTypeLayout();
+ createForElementType(
+ m_renderer,
+ m_session,
+ elementTypeLayout,
+ subObjectLayout.writeRef());
+ }
+ break;
case slang::BindingType::ExistentialValue:
// In the case of an interface-type sub-object range, we can only
@@ -207,8 +207,9 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
// increase the size of the ordinary data buffer we need to
// allocate for the parent object.
//
- uint32_t ordinaryDataEnd = subObjectRange.offset.pendingOrdinaryData
- + (uint32_t)bindingRange.count * subObjectRange.stride.pendingOrdinaryData;
+ uint32_t ordinaryDataEnd =
+ subObjectRange.offset.pendingOrdinaryData +
+ (uint32_t)bindingRange.count * subObjectRange.stride.pendingOrdinaryData;
if (ordinaryDataEnd > m_totalOrdinaryDataSize)
{
@@ -225,8 +226,7 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
SlangResult ShaderObjectLayoutImpl::Builder::build(ShaderObjectLayoutImpl** outLayout)
{
- auto layout =
- RefPtr<ShaderObjectLayoutImpl>(new ShaderObjectLayoutImpl());
+ auto layout = RefPtr<ShaderObjectLayoutImpl>(new ShaderObjectLayoutImpl());
SLANG_RETURN_ON_FAIL(layout->_init(this));
returnRefPtrMove(outLayout, layout);
@@ -276,14 +276,17 @@ Result RootShaderObjectLayoutImpl::Builder::build(RootShaderObjectLayoutImpl** o
return SLANG_OK;
}
-void RootShaderObjectLayoutImpl::Builder::addGlobalParams(slang::VariableLayoutReflection* globalsLayout)
+void RootShaderObjectLayoutImpl::Builder::addGlobalParams(
+ slang::VariableLayoutReflection* globalsLayout)
{
setElementTypeLayout(globalsLayout->getTypeLayout());
m_pendingDataOffset = BindingOffset(globalsLayout).pending;
}
void RootShaderObjectLayoutImpl::Builder::addEntryPoint(
- SlangStage stage, ShaderObjectLayoutImpl* entryPointLayout, slang::EntryPointLayout* slangEntryPoint)
+ SlangStage stage,
+ ShaderObjectLayoutImpl* entryPointLayout,
+ slang::EntryPointLayout* slangEntryPoint)
{
EntryPointInfo info;
info.layout = entryPointLayout;
@@ -306,7 +309,10 @@ Result RootShaderObjectLayoutImpl::create(
auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
RefPtr<ShaderObjectLayoutImpl> entryPointLayout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- renderer, program->getSession(), slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
+ renderer,
+ program->getSession(),
+ slangEntryPoint->getTypeLayout(),
+ entryPointLayout.writeRef()));
builder.addEntryPoint(slangEntryPoint->getStage(), entryPointLayout, slangEntryPoint);
}
diff --git a/tools/gfx/d3d11/d3d11-shader-object-layout.h b/tools/gfx/d3d11/d3d11-shader-object-layout.h
index e18c91c2e..16cd6c714 100644
--- a/tools/gfx/d3d11/d3d11-shader-object-layout.h
+++ b/tools/gfx/d3d11/d3d11-shader-object-layout.h
@@ -29,31 +29,31 @@ public:
// API, and a shader object layout will store information about those
// ranges in a form that is usable for the D3D11 API:
- /// Information about a logical binding range as reported by Slang reflection
+ /// Information about a logical binding range as reported by Slang reflection
struct BindingRangeInfo
{
- /// The type of bindings in this range
+ /// The type of bindings in this range
slang::BindingType bindingType;
- /// The number of bindings in this range
+ /// The number of bindings in this range
Index count;
- /// The starting index for this range in the appropriate "flat" array in a shader object.
- /// E.g., for a shader resource view range, this would be an index into the `m_srvs` array.
+ /// The starting index for this range in the appropriate "flat" array in a shader object.
+ /// E.g., for a shader resource view range, this would be an index into the `m_srvs` array.
Index baseIndex;
- /// The offset of this binding range from the start of the sub-object
- /// in terms of whatever D3D11 register class it consumes. E.g., for
- /// a `Texture2D` binding range this will represent an offset in
- /// `t` registers.
- ///
+ /// The offset of this binding range from the start of the sub-object
+ /// in terms of whatever D3D11 register class it consumes. E.g., for
+ /// a `Texture2D` binding range this will represent an offset in
+ /// `t` registers.
+ ///
uint32_t registerOffset;
- /// An index into the sub-object array if this binding range is treated
- /// as a sub-object.
+ /// An index into the sub-object array if this binding range is treated
+ /// as a sub-object.
Index subObjectIndex;
- /// Is this binding range specializable, e.g. an existential value or ParameterBlock<IFoo>.
+ /// Is this binding range specializable, e.g. an existential value or ParameterBlock<IFoo>.
bool isSpecializable;
};
@@ -64,43 +64,41 @@ public:
// For that reason we also store pre-computed information about each
// sub-object range.
- /// Offset information for a sub-object range
+ /// Offset information for a sub-object range
struct SubObjectRangeOffset : BindingOffset
{
- SubObjectRangeOffset()
- {}
+ SubObjectRangeOffset() {}
SubObjectRangeOffset(slang::VariableLayoutReflection* varLayout);
- /// The offset for "pending" ordinary data related to this range
+ /// The offset for "pending" ordinary data related to this range
uint32_t pendingOrdinaryData = 0;
};
- /// Stride information for a sub-object range
+ /// Stride information for a sub-object range
struct SubObjectRangeStride : BindingOffset
{
- SubObjectRangeStride()
- {}
+ SubObjectRangeStride() {}
SubObjectRangeStride(slang::TypeLayoutReflection* typeLayout);
- /// The strid for "pending" ordinary data related to this range
+ /// The strid for "pending" ordinary data related to this range
uint32_t pendingOrdinaryData = 0;
};
- /// Information about a logical binding range as reported by Slang reflection
+ /// Information about a logical binding range as reported by Slang reflection
struct SubObjectRangeInfo
{
- /// The index of the binding range that corresponds to this sub-object range
+ /// The index of the binding range that corresponds to this sub-object range
Index bindingRangeIndex;
- /// The layout expected for objects bound to this range (if known)
+ /// The layout expected for objects bound to this range (if known)
RefPtr<ShaderObjectLayoutImpl> layout;
- /// The offset to use when binding the first object in this range
+ /// The offset to use when binding the first object in this range
SubObjectRangeOffset offset;
- /// Stride between consecutive objects in this range
+ /// Stride between consecutive objects in this range
SubObjectRangeStride stride;
};
@@ -109,7 +107,8 @@ public:
public:
Builder(RendererBase* renderer, slang::ISession* session)
: m_renderer(renderer), m_session(session)
- {}
+ {
+ }
RendererBase* m_renderer;
slang::ISession* m_session;
@@ -118,13 +117,13 @@ public:
List<BindingRangeInfo> m_bindingRanges;
List<SubObjectRangeInfo> m_subObjectRanges;
- /// The indices of the binding ranges that represent SRVs
+ /// The indices of the binding ranges that represent SRVs
List<Index> m_srvRanges;
- /// The indices of the binding ranges that represent UAVs
+ /// The indices of the binding ranges that represent UAVs
List<Index> m_uavRanges;
- /// The indices of the binding ranges that represent samplers
+ /// The indices of the binding ranges that represent samplers
List<Index> m_samplerRanges;
Index m_srvCount = 0;
@@ -133,10 +132,10 @@ public:
Index m_subObjectCount = 0;
uint32_t m_totalOrdinaryDataSize = 0;
-
- /// The container type of this shader object. When `m_containerType` is
- /// `StructuredBuffer` or `UnsizedArray`, this shader object represents a collection
- /// instead of a single object.
+
+ /// The container type of this shader object. When `m_containerType` is
+ /// `StructuredBuffer` or `UnsizedArray`, this shader object represents a collection
+ /// instead of a single object.
ShaderObjectContainerType m_containerType = ShaderObjectContainerType::None;
Result setElementTypeLayout(slang::TypeLayoutReflection* typeLayout);
@@ -166,18 +165,15 @@ public:
RendererBase* getRenderer() { return m_renderer; }
- slang::TypeReflection* getType()
- {
- return m_elementTypeLayout->getType();
- }
+ slang::TypeReflection* getType() { return m_elementTypeLayout->getType(); }
- /// Get the indices that represent all the SRV ranges in this type
+ /// Get the indices that represent all the SRV ranges in this type
List<Index> const& getSRVRanges() const { return m_srvRanges; }
- /// Get the indices that reprsent all the UAV ranges in this type
+ /// Get the indices that reprsent all the UAV ranges in this type
List<Index> const& getUAVRanges() const { return m_uavRanges; }
- /// Get the indices that represnet all the sampler ranges in this type
+ /// Get the indices that represnet all the sampler ranges in this type
List<Index> const& getSamplerRanges() const { return m_samplerRanges; }
uint32_t getTotalOrdinaryDataSize() const { return m_totalOrdinaryDataSize; }
@@ -206,10 +202,11 @@ class RootShaderObjectLayoutImpl : public ShaderObjectLayoutImpl
public:
struct EntryPointInfo
{
- RefPtr<ShaderObjectLayoutImpl> layout;
+ RefPtr<ShaderObjectLayoutImpl> layout;
- /// The offset for this entry point's parameters, relative to the starting offset for the program
- BindingOffset offset;
+ /// The offset for this entry point's parameters, relative to the starting offset for the
+ /// program
+ BindingOffset offset;
};
struct Builder : Super::Builder
@@ -221,16 +218,20 @@ public:
: Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
- {}
+ {
+ }
Result build(RootShaderObjectLayoutImpl** outLayout);
void addGlobalParams(slang::VariableLayoutReflection* globalsLayout);
- void addEntryPoint(SlangStage stage, ShaderObjectLayoutImpl* entryPointLayout, slang::EntryPointLayout* slangEntryPoint);
-
- slang::IComponentType* m_program;
- slang::ProgramLayout* m_programLayout;
- List<EntryPointInfo> m_entryPoints;
- SimpleBindingOffset m_pendingDataOffset;
+ void addEntryPoint(
+ SlangStage stage,
+ ShaderObjectLayoutImpl* entryPointLayout,
+ slang::EntryPointLayout* slangEntryPoint);
+
+ slang::IComponentType* m_program;
+ slang::ProgramLayout* m_programLayout;
+ List<EntryPointInfo> m_entryPoints;
+ SimpleBindingOffset m_pendingDataOffset;
};
EntryPointInfo& getEntryPoint(Index index) { return m_entryPoints[index]; }
@@ -246,13 +247,13 @@ public:
slang::IComponentType* getSlangProgram() const { return m_program; }
slang::ProgramLayout* getSlangProgramLayout() const { return m_programLayout; }
- /// Get the offset at which "pending" shader parameters for this program start
+ /// Get the offset at which "pending" shader parameters for this program start
SimpleBindingOffset const& getPendingDataOffset() const { return m_pendingDataOffset; }
protected:
Result _init(Builder const* builder);
- ComPtr<slang::IComponentType> m_program;
+ ComPtr<slang::IComponentType> m_program;
slang::ProgramLayout* m_programLayout = nullptr;
List<EntryPointInfo> m_entryPoints;
diff --git a/tools/gfx/d3d11/d3d11-shader-object.cpp b/tools/gfx/d3d11/d3d11-shader-object.cpp
index a83b115fa..697d463fb 100644
--- a/tools/gfx/d3d11/d3d11-shader-object.cpp
+++ b/tools/gfx/d3d11/d3d11-shader-object.cpp
@@ -24,7 +24,7 @@ Result ShaderObjectImpl::create(
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setData(ShaderOffset const& inOffset, void const* data, size_t inSize)
+ShaderObjectImpl::setData(ShaderOffset const& inOffset, void const* data, size_t inSize)
{
Index offset = inOffset.uniformOffset;
Index size = inSize;
@@ -54,7 +54,7 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* resourceView)
+ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* resourceView)
{
if (offset.bindingRangeIndex < 0)
return SLANG_E_INVALID_ARG;
@@ -67,17 +67,20 @@ SLANG_NO_THROW Result SLANG_MCALL
if (D3DUtil::isUAVBinding(bindingRange.bindingType))
{
SLANG_ASSERT(resourceViewImpl->m_type == ResourceViewImpl::Type::UAV);
- m_uavs[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<UnorderedAccessViewImpl*>(resourceView);
+ m_uavs[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<UnorderedAccessViewImpl*>(resourceView);
}
else
{
SLANG_ASSERT(resourceViewImpl->m_type == ResourceViewImpl::Type::SRV);
- m_srvs[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<ShaderResourceViewImpl*>(resourceView);
+ m_srvs[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<ShaderResourceViewImpl*>(resourceView);
}
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* sampler)
+SLANG_NO_THROW Result SLANG_MCALL
+ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* sampler)
{
if (offset.bindingRangeIndex < 0)
return SLANG_E_INVALID_ARG;
@@ -86,7 +89,8 @@ SLANG_NO_THROW Result SLANG_MCALL ShaderObjectImpl::setSampler(ShaderOffset cons
return SLANG_E_INVALID_ARG;
auto& bindingRange = layout->getBindingRange(offset.bindingRangeIndex);
- m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<SamplerStateImpl*>(sampler);
+ m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<SamplerStateImpl*>(sampler);
return SLANG_OK;
}
@@ -152,7 +156,7 @@ Result ShaderObjectImpl::init(IDevice* device, ShaderObjectLayoutImpl* layout)
Result ShaderObjectImpl::_writeOrdinaryData(
void* dest,
- size_t destSize,
+ size_t destSize,
ShaderObjectLayoutImpl* specializedLayout)
{
// We start by simply writing in the ordinary data contained directly in this object.
@@ -180,7 +184,8 @@ Result ShaderObjectImpl::_writeOrdinaryData(
for (auto const& subObjectRangeInfo : specializedLayout->getSubObjectRanges())
{
Index subObjectRangeIndex = subObjectRangeCounter++;
- auto const& bindingRangeInfo = specializedLayout->getBindingRange(subObjectRangeInfo.bindingRangeIndex);
+ auto const& bindingRangeInfo =
+ specializedLayout->getBindingRange(subObjectRangeInfo.bindingRangeIndex);
// We only need to handle sub-object ranges for interface/existential-type fields,
// because fields of constant-buffer or parameter-block type are responsible for
@@ -234,11 +239,15 @@ Result ShaderObjectImpl::_writeOrdinaryData(
RefPtr<ShaderObjectLayoutImpl> subObjectLayout;
SLANG_RETURN_ON_FAIL(subObject->_getSpecializedLayout(subObjectLayout.writeRef()));
- auto subObjectOffset = subObjectRangePendingDataOffset + i * subObjectRangePendingDataStride;
+ auto subObjectOffset =
+ subObjectRangePendingDataOffset + i * subObjectRangePendingDataStride;
auto subObjectDest = (char*)dest + subObjectOffset;
- subObject->_writeOrdinaryData(subObjectDest, destSize - subObjectOffset, subObjectLayout);
+ subObject->_writeOrdinaryData(
+ subObjectDest,
+ destSize - subObjectOffset,
+ subObjectLayout);
}
}
@@ -280,7 +289,8 @@ Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(
//
auto ordinaryData = device->map(m_ordinaryDataBuffer, gfx::MapFlavor::WriteDiscard);
- auto result = _writeOrdinaryData(ordinaryData, specializedOrdinaryDataSize, specializedLayout);
+ auto result =
+ _writeOrdinaryData(ordinaryData, specializedOrdinaryDataSize, specializedLayout);
device->unmap(m_ordinaryDataBuffer, 0, specializedOrdinaryDataSize);
m_isConstantBufferDirty = false;
return result;
@@ -295,7 +305,8 @@ Result ShaderObjectImpl::_bindOrdinaryDataBufferIfNeeded(
{
// We start by ensuring that the buffer is created, if it is needed.
//
- SLANG_RETURN_ON_FAIL(_ensureOrdinaryDataBufferCreatedIfNeeded(context->device, specializedLayout));
+ SLANG_RETURN_ON_FAIL(
+ _ensureOrdinaryDataBufferCreatedIfNeeded(context->device, specializedLayout));
// If we did indeed need/create a buffer, then we must bind it
// into root binding state.
@@ -319,7 +330,8 @@ Result ShaderObjectImpl::bindAsConstantBuffer(
// resources and sub-objects.
//
BindingOffset offset = inOffset;
- SLANG_RETURN_ON_FAIL(_bindOrdinaryDataBufferIfNeeded(context, /*inout*/ offset, specializedLayout));
+ SLANG_RETURN_ON_FAIL(
+ _bindOrdinaryDataBufferIfNeeded(context, /*inout*/ offset, specializedLayout));
// Once the ordinary data buffer is bound, we can move on to binding
// the rest of the state, which can use logic shared with the case
@@ -403,7 +415,8 @@ Result ShaderObjectImpl::bindAsValue(
for (auto const& subObjectRange : specializedLayout->getSubObjectRanges())
{
auto subObjectLayout = subObjectRange.layout;
- auto const& bindingRange = specializedLayout->getBindingRange(subObjectRange.bindingRangeIndex);
+ auto const& bindingRange =
+ specializedLayout->getBindingRange(subObjectRange.bindingRangeIndex);
Index count = bindingRange.count;
Index subObjectIndex = bindingRange.subObjectIndex;
@@ -425,21 +438,21 @@ Result ShaderObjectImpl::bindAsValue(
//
case slang::BindingType::ConstantBuffer:
case slang::BindingType::ParameterBlock:
- {
- BindingOffset objOffset = rangeOffset;
- for (Index i = 0; i < count; ++i)
{
- auto subObject = m_objects[subObjectIndex + i];
+ BindingOffset objOffset = rangeOffset;
+ for (Index i = 0; i < count; ++i)
+ {
+ auto subObject = m_objects[subObjectIndex + i];
- // Unsurprisingly, we bind each object in the range as
- // a constant buffer.
- //
- subObject->bindAsConstantBuffer(context, objOffset, subObjectLayout);
+ // Unsurprisingly, we bind each object in the range as
+ // a constant buffer.
+ //
+ subObject->bindAsConstantBuffer(context, objOffset, subObjectLayout);
- objOffset += rangeStride;
+ objOffset += rangeStride;
+ }
}
- }
- break;
+ break;
case slang::BindingType::ExistentialValue:
// We can only bind information for existential-typed sub-object
@@ -465,8 +478,7 @@ Result ShaderObjectImpl::bindAsValue(
}
break;
- default:
- break;
+ default: break;
}
}
@@ -552,7 +564,10 @@ Result RootShaderObjectImpl::bindAsRoot(
// really be querying an appropriate absolute offset from `specializedLayout`.
//
BindingOffset ordinaryDataBufferOffset = offset;
- SLANG_RETURN_ON_FAIL(_bindOrdinaryDataBufferIfNeeded(context, /*inout*/ ordinaryDataBufferOffset, specializedLayout));
+ SLANG_RETURN_ON_FAIL(_bindOrdinaryDataBufferIfNeeded(
+ context,
+ /*inout*/ ordinaryDataBufferOffset,
+ specializedLayout));
SLANG_RETURN_ON_FAIL(bindAsValue(context, offset, specializedLayout));
// Once the state stored in the root shader object itself has been bound,
@@ -574,7 +589,8 @@ Result RootShaderObjectImpl::bindAsRoot(
// the absolute offsets as are used for the global scope do not apply
// (because entry points don't need to deal with explicit bindings).
//
- SLANG_RETURN_ON_FAIL(entryPoint->bindAsConstantBuffer(context, entryPointOffset, entryPointInfo.layout));
+ SLANG_RETURN_ON_FAIL(
+ entryPoint->bindAsConstantBuffer(context, entryPointOffset, entryPointInfo.layout));
}
return SLANG_OK;
@@ -652,7 +668,11 @@ Result RootShaderObjectImpl::_createSpecializedLayout(ShaderObjectLayoutImpl** o
auto slangSpecializedLayout = specializedComponentType->getLayout();
RefPtr<RootShaderObjectLayoutImpl> specializedLayout;
- RootShaderObjectLayoutImpl::create(getRenderer(), specializedComponentType, slangSpecializedLayout, specializedLayout.writeRef());
+ RootShaderObjectLayoutImpl::create(
+ getRenderer(),
+ specializedComponentType,
+ slangSpecializedLayout,
+ specializedLayout.writeRef());
// Note: Computing the layout for the specialized program will have also computed
// the layouts for the entry points, and we really need to attach that information
diff --git a/tools/gfx/d3d11/d3d11-shader-object.h b/tools/gfx/d3d11/d3d11-shader-object.h
index b4e43c3ee..62fb4cf62 100644
--- a/tools/gfx/d3d11/d3d11-shader-object.h
+++ b/tools/gfx/d3d11/d3d11-shader-object.h
@@ -1,14 +1,12 @@
// d3d11-shader-object.h
#pragma once
#include "d3d11-base.h"
-
#include "d3d11-buffer.h"
+#include "d3d11-helper-functions.h"
#include "d3d11-resource-views.h"
#include "d3d11-sampler.h"
#include "d3d11-shader-object-layout.h"
-#include "d3d11-helper-functions.h"
-
namespace gfx
{
@@ -18,10 +16,7 @@ namespace d3d11
{
class ShaderObjectImpl
- : public ShaderObjectBaseImpl<
- ShaderObjectImpl,
- ShaderObjectLayoutImpl,
- SimpleShaderObjectData>
+ : public ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, SimpleShaderObjectData>
{
public:
static Result create(
@@ -51,67 +46,68 @@ public:
}
SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& inOffset, void const* data, size_t inSize) SLANG_OVERRIDE;
+ setData(ShaderOffset const& inOffset, void const* data, size_t inSize) SLANG_OVERRIDE;
SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView) SLANG_OVERRIDE;
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) SLANG_OVERRIDE;
SLANG_NO_THROW Result SLANG_MCALL setSampler(ShaderOffset const& offset, ISamplerState* sampler)
SLANG_OVERRIDE;
SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) SLANG_OVERRIDE
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) SLANG_OVERRIDE
{
return SLANG_E_NOT_IMPLEMENTED;
}
public:
-
-
protected:
friend class ProgramVars;
Result init(IDevice* device, ShaderObjectLayoutImpl* layout);
- /// Write the uniform/ordinary data of this object into the given `dest` buffer at the given `offset`
+ /// Write the uniform/ordinary data of this object into the given `dest` buffer at the given
+ /// `offset`
Result _writeOrdinaryData(
void* dest,
- size_t destSize,
+ size_t destSize,
ShaderObjectLayoutImpl* specializedLayout);
- /// Ensure that the `m_ordinaryDataBuffer` has been created, if it is needed
- ///
- /// The `specializedLayout` type must represent a specialized layout for this
- /// type that includes any "pending" data.
- ///
+ /// Ensure that the `m_ordinaryDataBuffer` has been created, if it is needed
+ ///
+ /// The `specializedLayout` type must represent a specialized layout for this
+ /// type that includes any "pending" data.
+ ///
Result _ensureOrdinaryDataBufferCreatedIfNeeded(
DeviceImpl* device,
ShaderObjectLayoutImpl* specializedLayout);
- /// Bind the buffer for ordinary/uniform data, if needed
- ///
- /// The `ioOffset` parameter will be updated to reflect the constant buffer
- /// register consumed by the ordinary data buffer, if one was bound.
- ///
+ /// Bind the buffer for ordinary/uniform data, if needed
+ ///
+ /// The `ioOffset` parameter will be updated to reflect the constant buffer
+ /// register consumed by the ordinary data buffer, if one was bound.
+ ///
Result _bindOrdinaryDataBufferIfNeeded(
BindingContext* context,
BindingOffset& ioOffset,
ShaderObjectLayoutImpl* specializedLayout);
public:
- /// Bind this object as if it was declared as a `ConstantBuffer<T>` in Slang
+ /// Bind this object as if it was declared as a `ConstantBuffer<T>` in Slang
Result bindAsConstantBuffer(
BindingContext* context,
BindingOffset const& inOffset,
ShaderObjectLayoutImpl* specializedLayout);
- /// Bind this object as a value that appears in the body of another object.
- ///
- /// This case is directly used when binding an object for an interface-type
- /// sub-object range when static specialization is used. It is also used
- /// indirectly when binding sub-objects to constant buffer or parameter
- /// block ranges.
- ///
+ /// Bind this object as a value that appears in the body of another object.
+ ///
+ /// This case is directly used when binding an object for an interface-type
+ /// sub-object range when static specialization is used. It is also used
+ /// indirectly when binding sub-objects to constant buffer or parameter
+ /// block ranges.
+ ///
Result bindAsValue(
BindingContext* context,
BindingOffset const& offset,
@@ -121,28 +117,28 @@ public:
// and organized as part of each shader object layout,
// the object itself can store its data in a small number
// of simple arrays.
- /// The shader resource views (SRVs) that are part of the state of this object
+ /// The shader resource views (SRVs) that are part of the state of this object
List<RefPtr<ShaderResourceViewImpl>> m_srvs;
- /// The unordered access views (UAVs) that are part of the state of this object
+ /// The unordered access views (UAVs) that are part of the state of this object
List<RefPtr<UnorderedAccessViewImpl>> m_uavs;
- /// The samplers that are part of the state of this object
+ /// The samplers that are part of the state of this object
List<RefPtr<SamplerStateImpl>> m_samplers;
- /// A constant buffer used to stored ordinary data for this object
- /// and existential-type sub-objects.
- ///
- /// Created on demand with `_createOrdinaryDataBufferIfNeeded()`
+ /// A constant buffer used to stored ordinary data for this object
+ /// and existential-type sub-objects.
+ ///
+ /// Created on demand with `_createOrdinaryDataBufferIfNeeded()`
RefPtr<BufferResourceImpl> m_ordinaryDataBuffer;
bool m_isConstantBufferDirty = true;
- /// Get the layout of this shader object with specialization arguments considered
- ///
- /// This operation should only be called after the shader object has been
- /// fully filled in and finalized.
- ///
+ /// Get the layout of this shader object with specialization arguments considered
+ ///
+ /// This operation should only be called after the shader object has been
+ /// fully filled in and finalized.
+ ///
Result _getSpecializedLayout(ShaderObjectLayoutImpl** outLayout);
/// Create the layout for this shader object with specialization arguments considered
@@ -155,10 +151,9 @@ public:
};
class MutableShaderObjectImpl
- : public MutableShaderObject<
- MutableShaderObjectImpl,
- ShaderObjectLayoutImpl>
-{};
+ : public MutableShaderObject<MutableShaderObjectImpl, ShaderObjectLayoutImpl>
+{
+};
class RootShaderObjectImpl : public ShaderObjectImpl
{
@@ -168,12 +163,22 @@ public:
virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
- static Result create(IDevice* device, RootShaderObjectLayoutImpl* layout, RootShaderObjectImpl** outShaderObject);
+ static Result create(
+ IDevice* device,
+ RootShaderObjectLayoutImpl* layout,
+ RootShaderObjectImpl** outShaderObject);
- RootShaderObjectLayoutImpl* getLayout() { return static_cast<RootShaderObjectLayoutImpl*>(m_layout.Ptr()); }
+ RootShaderObjectLayoutImpl* getLayout()
+ {
+ return static_cast<RootShaderObjectLayoutImpl*>(m_layout.Ptr());
+ }
- GfxCount SLANG_MCALL getEntryPointCount() SLANG_OVERRIDE { return (GfxCount)m_entryPoints.getCount(); }
- SlangResult SLANG_MCALL getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) SLANG_OVERRIDE
+ GfxCount SLANG_MCALL getEntryPointCount() SLANG_OVERRIDE
+ {
+ return (GfxCount)m_entryPoints.getCount();
+ }
+ SlangResult SLANG_MCALL getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
+ SLANG_OVERRIDE
{
returnComPtr(outEntryPoint, m_entryPoints[index]);
return SLANG_OK;
@@ -181,10 +186,8 @@ public:
virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) override;
- /// Bind this object as a root shader object
- Result bindAsRoot(
- BindingContext* context,
- RootShaderObjectLayoutImpl* specializedLayout);
+ /// Bind this object as a root shader object
+ Result bindAsRoot(BindingContext* context, RootShaderObjectLayoutImpl* specializedLayout);
protected:
diff --git a/tools/gfx/d3d11/d3d11-shader-program.cpp b/tools/gfx/d3d11/d3d11-shader-program.cpp
index f957f6353..16f73c984 100644
--- a/tools/gfx/d3d11/d3d11-shader-program.cpp
+++ b/tools/gfx/d3d11/d3d11-shader-program.cpp
@@ -12,6 +12,5 @@ namespace d3d11
{
-
} // namespace d3d11
} // namespace gfx
diff --git a/tools/gfx/d3d11/d3d11-swap-chain.cpp b/tools/gfx/d3d11/d3d11-swap-chain.cpp
index 177fb89dd..8eb8d66d6 100644
--- a/tools/gfx/d3d11/d3d11-swap-chain.cpp
+++ b/tools/gfx/d3d11/d3d11-swap-chain.cpp
@@ -12,7 +12,10 @@ using namespace Slang;
namespace d3d11
{
-Result SwapchainImpl::init(DeviceImpl* renderer, const ISwapchain::Desc& swapchainDesc, WindowHandle window)
+Result SwapchainImpl::init(
+ DeviceImpl* renderer,
+ const ISwapchain::Desc& swapchainDesc,
+ WindowHandle window)
{
m_renderer = renderer;
m_device = renderer->m_device;
diff --git a/tools/gfx/d3d11/d3d11-texture.h b/tools/gfx/d3d11/d3d11-texture.h
index fb88d2b76..81e3b2a82 100644
--- a/tools/gfx/d3d11/d3d11-texture.h
+++ b/tools/gfx/d3d11/d3d11-texture.h
@@ -21,7 +21,6 @@ public:
{
}
ComPtr<ID3D11Resource> m_resource;
-
};
} // namespace d3d11
diff --git a/tools/gfx/d3d11/d3d11-vertex-layout.h b/tools/gfx/d3d11/d3d11-vertex-layout.h
index 9c3f1cd46..1908e8cce 100644
--- a/tools/gfx/d3d11/d3d11-vertex-layout.h
+++ b/tools/gfx/d3d11/d3d11-vertex-layout.h
@@ -11,10 +11,10 @@ using namespace Slang;
namespace d3d11
{
-class InputLayoutImpl: public InputLayoutBase
+class InputLayoutImpl : public InputLayoutBase
{
public:
- ComPtr<ID3D11InputLayout> m_layout;
+ ComPtr<ID3D11InputLayout> m_layout;
List<UINT> m_vertexStreamStrides;
};
diff --git a/tools/gfx/d3d12/d3d12-base.h b/tools/gfx/d3d12/d3d12-base.h
index 0e648f9c4..e67a7226c 100644
--- a/tools/gfx/d3d12/d3d12-base.h
+++ b/tools/gfx/d3d12/d3d12-base.h
@@ -12,8 +12,8 @@
#include "core/slang-blob.h"
#include "core/slang-chunked-list.h"
#include "d3d12-descriptor-heap.h"
-#include "d3d12-resource.h"
#include "d3d12-posix-synchapi.h"
+#include "d3d12-resource.h"
#pragma push_macro("WIN32_LEAN_AND_MEAN")
#pragma push_macro("NOMINMAX")
@@ -35,47 +35,48 @@
#ifndef __ID3D12GraphicsCommandList1_FWD_DEFINED__
// If can't find a definition of CommandList1, just use an empty definition
struct ID3D12GraphicsCommandList1
-{};
+{
+};
#endif
namespace gfx
{
namespace d3d12
{
- class DeviceImpl;
- class BufferResourceImpl;
- class TextureResourceImpl;
- class CommandBufferImpl;
- class PipelineCommandEncoder;
- class ResourceCommandEncoderImpl;
- class ComputeCommandEncoderImpl;
- class RenderCommandEncoderImpl;
- class CommandQueueImpl;
- class FenceImpl;
- class FramebufferLayoutImpl;
- class FramebufferImpl;
- class QueryPoolImpl;
- class PlainBufferProxyQueryPoolImpl;
- class PipelineStateImpl;
- class RenderPassLayoutImpl;
- class ResourceViewInternalImpl;
- class ResourceViewImpl;
- class AccelerationStructureImpl;
- class SamplerStateImpl;
- class ShaderObjectImpl;
- class RootShaderObjectImpl;
- class MutableRootShaderObjectImpl;
- class ShaderObjectLayoutImpl;
- class RootShaderObjectLayoutImpl;
- class ShaderProgramImpl;
- class ShaderTableImpl;
- class SwapChainImpl;
- class TransientResourceHeapImpl;
- class InputLayoutImpl;
+class DeviceImpl;
+class BufferResourceImpl;
+class TextureResourceImpl;
+class CommandBufferImpl;
+class PipelineCommandEncoder;
+class ResourceCommandEncoderImpl;
+class ComputeCommandEncoderImpl;
+class RenderCommandEncoderImpl;
+class CommandQueueImpl;
+class FenceImpl;
+class FramebufferLayoutImpl;
+class FramebufferImpl;
+class QueryPoolImpl;
+class PlainBufferProxyQueryPoolImpl;
+class PipelineStateImpl;
+class RenderPassLayoutImpl;
+class ResourceViewInternalImpl;
+class ResourceViewImpl;
+class AccelerationStructureImpl;
+class SamplerStateImpl;
+class ShaderObjectImpl;
+class RootShaderObjectImpl;
+class MutableRootShaderObjectImpl;
+class ShaderObjectLayoutImpl;
+class RootShaderObjectLayoutImpl;
+class ShaderProgramImpl;
+class ShaderTableImpl;
+class SwapChainImpl;
+class TransientResourceHeapImpl;
+class InputLayoutImpl;
#if SLANG_GFX_HAS_DXR_SUPPORT
- class RayTracingCommandEncoderImpl;
- class RayTracingPipelineStateImpl;
+class RayTracingCommandEncoderImpl;
+class RayTracingPipelineStateImpl;
#endif
-}
-}
+} // namespace d3d12
+} // namespace gfx
diff --git a/tools/gfx/d3d12/d3d12-buffer.cpp b/tools/gfx/d3d12/d3d12-buffer.cpp
index 7d3376607..ee078bb3d 100644
--- a/tools/gfx/d3d12/d3d12-buffer.cpp
+++ b/tools/gfx/d3d12/d3d12-buffer.cpp
@@ -9,9 +9,9 @@ namespace d3d12
using namespace Slang;
BufferResourceImpl::BufferResourceImpl(const Desc& desc)
- : Parent(desc)
- , m_defaultState(D3DUtil::getResourceState(desc.defaultState))
-{}
+ : Parent(desc), m_defaultState(D3DUtil::getResourceState(desc.defaultState))
+{
+}
BufferResourceImpl::~BufferResourceImpl()
{
@@ -50,7 +50,11 @@ Result BufferResourceImpl::getSharedHandle(InteropHandle* outHandle)
auto pResource = m_resource.getResource();
pResource->GetDevice(IID_PPV_ARGS(pDevice.writeRef()));
SLANG_RETURN_ON_FAIL(pDevice->CreateSharedHandle(
- pResource, NULL, GENERIC_ALL, nullptr, (HANDLE*)&outHandle->handleValue));
+ pResource,
+ NULL,
+ GENERIC_ALL,
+ nullptr,
+ (HANDLE*)&outHandle->handleValue));
outHandle->api = InteropHandleAPI::D3D12;
sharedHandle = *outHandle;
return SLANG_OK;
diff --git a/tools/gfx/d3d12/d3d12-buffer.h b/tools/gfx/d3d12/d3d12-buffer.h
index 272969b07..b58426af6 100644
--- a/tools/gfx/d3d12/d3d12-buffer.h
+++ b/tools/gfx/d3d12/d3d12-buffer.h
@@ -20,19 +20,19 @@ public:
~BufferResourceImpl();
D3D12Resource m_resource; ///< The resource in gpu memory, allocated on the correct heap
- ///< relative to the cpu access flag
+ ///< relative to the cpu access flag
D3D12_RESOURCE_STATES m_defaultState;
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeResourceHandle(InteropHandle* outHandle) override;
+ getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- map(MemoryRange* rangeToRead, void** outPointer) override;
+ map(MemoryRange* rangeToRead, void** outPointer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override;
@@ -41,4 +41,3 @@ public:
} // namespace d3d12
} // namespace gfx
-
diff --git a/tools/gfx/d3d12/d3d12-command-buffer.cpp b/tools/gfx/d3d12/d3d12-command-buffer.cpp
index fb979d3b9..641234a63 100644
--- a/tools/gfx/d3d12/d3d12-command-buffer.cpp
+++ b/tools/gfx/d3d12/d3d12-command-buffer.cpp
@@ -60,7 +60,7 @@ void CommandBufferImpl::init(
reinit();
m_cmdList->QueryInterface<ID3D12GraphicsCommandList6>(m_cmdList6.writeRef());
-if (m_cmdList6)
+ if (m_cmdList6)
{
m_cmdList4 = m_cmdList6;
m_cmdList1 = m_cmdList6;
@@ -84,7 +84,9 @@ void CommandBufferImpl::encodeResourceCommands(IResourceCommandEncoder** outEnco
}
void CommandBufferImpl::encodeRenderCommands(
- IRenderPassLayout* renderPass, IFramebuffer* framebuffer, IRenderCommandEncoder** outEncoder)
+ IRenderPassLayout* renderPass,
+ IFramebuffer* framebuffer,
+ IRenderCommandEncoder** outEncoder)
{
m_renderCommandEncoder.init(
m_renderer,
@@ -107,11 +109,14 @@ void CommandBufferImpl::encodeRayTracingCommands(IRayTracingCommandEncoder** out
m_rayTracingCommandEncoder.init(this);
*outEncoder = &m_rayTracingCommandEncoder;
#else
- * outEncoder = nullptr;
+ *outEncoder = nullptr;
#endif
}
-void CommandBufferImpl::close() { m_cmdList->Close(); }
+void CommandBufferImpl::close()
+{
+ m_cmdList->Close();
+}
} // namespace d3d12
} // namespace gfx
diff --git a/tools/gfx/d3d12/d3d12-command-buffer.h b/tools/gfx/d3d12/d3d12-command-buffer.h
index 1cc6e8850..192be9e2b 100644
--- a/tools/gfx/d3d12/d3d12-command-buffer.h
+++ b/tools/gfx/d3d12/d3d12-command-buffer.h
@@ -2,13 +2,14 @@
#pragma once
#include "d3d12-base.h"
-#include "d3d12-shader-object.h"
#include "d3d12-command-encoder.h"
+#include "d3d12-shader-object.h"
#ifndef __ID3D12GraphicsCommandList1_FWD_DEFINED__
// If can't find a definition of CommandList1, just use an empty definition
struct ID3D12GraphicsCommandList1
-{};
+{
+};
#endif
namespace gfx
@@ -18,9 +19,7 @@ namespace d3d12
using namespace Slang;
-class CommandBufferImpl
- : public ICommandBufferD3D12
- , public ComObject
+class CommandBufferImpl : public ICommandBufferD3D12, public ComObject
{
public:
// There are a pair of cyclic references between a `TransientResourceHeap` and
@@ -28,7 +27,7 @@ public:
// the public reference count of a command buffer dropping to 0.
SLANG_COM_OBJECT_IUNKNOWN_ALL
- ICommandBufferD3D12* getInterface(const Guid& guid);
+ ICommandBufferD3D12* getInterface(const Guid& guid);
virtual void comFree() override { m_transientHeap.breakStrongReference(); }
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* handle) override;
@@ -49,8 +48,14 @@ public:
void bindDescriptorHeaps();
- virtual SLANG_NO_THROW void SLANG_MCALL invalidateDescriptorHeapBinding() override { m_descriptorHeapsBound = false; }
- virtual SLANG_NO_THROW void SLANG_MCALL ensureInternalDescriptorHeapsBound() override { bindDescriptorHeaps(); }
+ virtual SLANG_NO_THROW void SLANG_MCALL invalidateDescriptorHeapBinding() override
+ {
+ m_descriptorHeapsBound = false;
+ }
+ virtual SLANG_NO_THROW void SLANG_MCALL ensureInternalDescriptorHeapsBound() override
+ {
+ bindDescriptorHeaps();
+ }
void reinit();
@@ -62,7 +67,7 @@ public:
ResourceCommandEncoderImpl m_resourceCommandEncoder;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
+ encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
RenderCommandEncoderImpl m_renderCommandEncoder;
virtual SLANG_NO_THROW void SLANG_MCALL encodeRenderCommands(
@@ -72,13 +77,13 @@ public:
ComputeCommandEncoderImpl m_computeCommandEncoder;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
+ encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
#if SLANG_GFX_HAS_DXR_SUPPORT
RayTracingCommandEncoderImpl m_rayTracingCommandEncoder;
#endif
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
+ encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL close() override;
};
diff --git a/tools/gfx/d3d12/d3d12-command-encoder.cpp b/tools/gfx/d3d12/d3d12-command-encoder.cpp
index 892c792fb..f0b4b0dfc 100644
--- a/tools/gfx/d3d12/d3d12-command-encoder.cpp
+++ b/tools/gfx/d3d12/d3d12-command-encoder.cpp
@@ -3,17 +3,16 @@
#include "d3d12-command-buffer.h"
#include "d3d12-device.h"
+#include "d3d12-helper-functions.h"
#include "d3d12-pipeline-state.h"
#include "d3d12-query.h"
#include "d3d12-shader-object.h"
#include "d3d12-shader-program.h"
#include "d3d12-shader-table.h"
-#include "d3d12-transient-heap.h"
#include "d3d12-texture.h"
+#include "d3d12-transient-heap.h"
#include "d3d12-vertex-layout.h"
-#include "d3d12-helper-functions.h"
-
namespace gfx
{
namespace d3d12
@@ -25,15 +24,10 @@ int PipelineCommandEncoder::getBindPointIndex(PipelineType type)
{
switch (type)
{
- case PipelineType::Graphics:
- return 0;
- case PipelineType::Compute:
- return 1;
- case PipelineType::RayTracing:
- return 2;
- default:
- assert(!"unknown pipeline type.");
- return -1;
+ case PipelineType::Graphics: return 0;
+ case PipelineType::Compute: return 1;
+ case PipelineType::RayTracing: return 2;
+ default: assert(!"unknown pipeline type."); return -1;
}
}
@@ -48,7 +42,8 @@ void PipelineCommandEncoder::init(CommandBufferImpl* commandBuffer)
}
Result PipelineCommandEncoder::bindPipelineImpl(
- IPipelineState* pipelineState, IShaderObject** outRootObject)
+ IPipelineState* pipelineState,
+ IShaderObject** outRootObject)
{
m_currentPipeline = static_cast<PipelineStateBase*>(pipelineState);
auto rootObject = &m_commandBuffer->m_rootShaderObject;
@@ -63,7 +58,8 @@ Result PipelineCommandEncoder::bindPipelineImpl(
}
Result PipelineCommandEncoder::bindPipelineWithRootObjectImpl(
- IPipelineState* pipelineState, IShaderObject* rootObject)
+ IPipelineState* pipelineState,
+ IShaderObject* rootObject)
{
m_currentPipeline = static_cast<PipelineStateBase*>(pipelineState);
m_commandBuffer->m_mutableRootShaderObject =
@@ -73,11 +69,12 @@ Result PipelineCommandEncoder::bindPipelineWithRootObjectImpl(
}
Result PipelineCommandEncoder::_bindRenderState(
- Submitter* submitter, RefPtr<PipelineStateBase>& newPipeline)
+ Submitter* submitter,
+ RefPtr<PipelineStateBase>& newPipeline)
{
RootShaderObjectImpl* rootObjectImpl = m_commandBuffer->m_mutableRootShaderObject
- ? m_commandBuffer->m_mutableRootShaderObject.Ptr()
- : &m_commandBuffer->m_rootShaderObject;
+ ? m_commandBuffer->m_mutableRootShaderObject.Ptr()
+ : &m_commandBuffer->m_rootShaderObject;
SLANG_RETURN_ON_FAIL(
m_renderer->maybeSpecializePipeline(m_currentPipeline, rootObjectImpl, newPipeline));
PipelineStateBase* newPipelineImpl = static_cast<PipelineStateBase*>(newPipeline.Ptr());
@@ -127,9 +124,7 @@ Result PipelineCommandEncoder::_bindRenderState(
d3dheap = m_transientHeap->getCurrentSamplerHeap().getHeap();
m_commandBuffer->bindDescriptorHeaps();
break;
- default:
- assert(!"shouldn't be here");
- return SLANG_FAIL;
+ default: assert(!"shouldn't be here"); return SLANG_FAIL;
}
// Try again.
@@ -140,7 +135,10 @@ Result PipelineCommandEncoder::_bindRenderState(
}
void ResourceCommandEncoderImpl::bufferBarrier(
- GfxCount count, IBufferResource* const* buffers, ResourceState src, ResourceState dst)
+ GfxCount count,
+ IBufferResource* const* buffers,
+ ResourceState src,
+ ResourceState dst)
{
ShortList<D3D12_RESOURCE_BARRIER, 16> barriers;
for (GfxIndex i = 0; i < count; i++)
@@ -150,8 +148,8 @@ void ResourceCommandEncoderImpl::bufferBarrier(
D3D12_RESOURCE_BARRIER barrier = {};
// If the src == dst, it must be a UAV barrier.
barrier.Type = (src == dst && dst == ResourceState::UnorderedAccess)
- ? D3D12_RESOURCE_BARRIER_TYPE_UAV
- : D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ ? D3D12_RESOURCE_BARRIER_TYPE_UAV
+ : D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
if (barrier.Type == D3D12_RESOURCE_BARRIER_TYPE_UAV)
@@ -172,7 +170,8 @@ void ResourceCommandEncoderImpl::bufferBarrier(
if (barriers.getCount())
{
m_commandBuffer->m_cmdList4->ResourceBarrier(
- (UINT)barriers.getCount(), barriers.getArrayView().getBuffer());
+ (UINT)barriers.getCount(),
+ barriers.getArrayView().getBuffer());
}
}
@@ -199,7 +198,8 @@ void ResourceCommandEncoderImpl::copyTexture(
srcSubresource.layerCount == 0 && srcSubresource.mipLevelCount == 0)
{
m_commandBuffer->m_cmdList->CopyResource(
- dstTexture->m_resource.getResource(), srcTexture->m_resource.getResource());
+ dstTexture->m_resource.getResource(),
+ srcTexture->m_resource.getResource());
return;
}
@@ -246,7 +246,12 @@ void ResourceCommandEncoderImpl::copyTexture(
srcBox.back = srcBox.front + extent.depth;
m_commandBuffer->m_cmdList->CopyTextureRegion(
- &dstRegion, dstOffset.x, dstOffset.y, dstOffset.z, &srcRegion, &srcBox);
+ &dstRegion,
+ dstOffset.x,
+ dstOffset.y,
+ dstOffset.z,
+ &srcRegion,
+ &srcBox);
}
}
}
@@ -314,7 +319,7 @@ void ResourceCommandEncoderImpl::uploadTextureData(
footprint.Footprint.Depth = Math::Max(1, (textureSize.depth >> mipLevel)) - offset.z;
}
auto rowSize = (footprint.Footprint.Width + formatInfo.blockWidth - 1) /
- formatInfo.blockWidth * formatInfo.blockSizeInBytes;
+ formatInfo.blockWidth * formatInfo.blockSizeInBytes;
auto rowCount =
(footprint.Footprint.Height + formatInfo.blockHeight - 1) / formatInfo.blockHeight;
footprint.Footprint.RowPitch =
@@ -325,11 +330,15 @@ void ResourceCommandEncoderImpl::uploadTextureData(
IBufferResource* stagingBuffer;
Offset stagingBufferOffset = 0;
m_commandBuffer->m_transientHeap->allocateStagingBuffer(
- bufferSize, stagingBuffer, stagingBufferOffset, MemoryType::Upload, true);
+ bufferSize,
+ stagingBuffer,
+ stagingBufferOffset,
+ MemoryType::Upload,
+ true);
assert(stagingBufferOffset == 0);
BufferResourceImpl* bufferImpl = static_cast<BufferResourceImpl*>(stagingBuffer);
uint8_t* bufferData = nullptr;
- D3D12_RANGE mapRange = { 0, 0 };
+ D3D12_RANGE mapRange = {0, 0};
bufferImpl->m_resource.getResource()->Map(0, &mapRange, (void**)&bufferData);
for (uint32_t z = 0; z < footprint.Footprint.Depth; z++)
{
@@ -345,13 +354,15 @@ void ResourceCommandEncoderImpl::uploadTextureData(
}
bufferImpl->m_resource.getResource()->Unmap(0, nullptr);
srcRegion.pResource = bufferImpl->m_resource.getResource();
- m_commandBuffer->m_cmdList->CopyTextureRegion(
- &dstRegion, offset.x, offset.y, offset.z, &srcRegion, nullptr);
+ m_commandBuffer->m_cmdList
+ ->CopyTextureRegion(&dstRegion, offset.x, offset.y, offset.z, &srcRegion, nullptr);
}
}
void ResourceCommandEncoderImpl::clearResourceView(
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags)
+ IResourceView* view,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags)
{
auto viewImpl = static_cast<ResourceViewImpl*>(view);
m_commandBuffer->bindDescriptorHeaps();
@@ -359,86 +370,93 @@ void ResourceCommandEncoderImpl::clearResourceView(
{
case IResourceView::Type::RenderTarget:
m_commandBuffer->m_cmdList->ClearRenderTargetView(
- viewImpl->m_descriptor.cpuHandle, clearValue->color.floatValues, 0, nullptr);
- break;
- case IResourceView::Type::DepthStencil:
- {
- D3D12_CLEAR_FLAGS clearFlags = (D3D12_CLEAR_FLAGS)0;
- if (flags & ClearResourceViewFlags::ClearDepth)
- {
- clearFlags |= D3D12_CLEAR_FLAG_DEPTH;
- }
- if (flags & ClearResourceViewFlags::ClearStencil)
- {
- clearFlags |= D3D12_CLEAR_FLAG_STENCIL;
- }
- m_commandBuffer->m_cmdList->ClearDepthStencilView(
viewImpl->m_descriptor.cpuHandle,
- clearFlags,
- clearValue->depthStencil.depth,
- (UINT8)clearValue->depthStencil.stencil,
+ clearValue->color.floatValues,
0,
nullptr);
break;
- }
- case IResourceView::Type::UnorderedAccess:
- {
- ID3D12Resource* d3dResource = nullptr;
- D3D12Descriptor descriptor = viewImpl->m_descriptor;
- switch (viewImpl->m_resource->getType())
- {
- case IResource::Type::Buffer:
- d3dResource = static_cast<BufferResourceImpl*>(viewImpl->m_resource.Ptr())
- ->m_resource.getResource();
- // D3D12 requires a UAV descriptor with zero buffer stride for calling ClearUnorderedAccessViewUint/Float.
- viewImpl->getBufferDescriptorForBinding(m_commandBuffer->m_renderer, viewImpl, 0, descriptor);
- break;
- default:
- d3dResource = static_cast<TextureResourceImpl*>(viewImpl->m_resource.Ptr())
- ->m_resource.getResource();
- break;
- }
- auto gpuHandleIndex =
- m_commandBuffer->m_transientHeap->getCurrentViewHeap().allocate(1);
- if (gpuHandleIndex == -1)
- {
- m_commandBuffer->m_transientHeap->allocateNewViewDescriptorHeap(
- m_commandBuffer->m_renderer);
- gpuHandleIndex = m_commandBuffer->m_transientHeap->getCurrentViewHeap().allocate(1);
- m_commandBuffer->bindDescriptorHeaps();
- }
- this->m_commandBuffer->m_renderer->m_device->CopyDescriptorsSimple(
- 1,
- m_commandBuffer->m_transientHeap->getCurrentViewHeap().getCpuHandle(gpuHandleIndex),
- descriptor.cpuHandle,
- D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
-
- if (flags & ClearResourceViewFlags::FloatClearValues)
+ case IResourceView::Type::DepthStencil:
{
- m_commandBuffer->m_cmdList->ClearUnorderedAccessViewFloat(
- m_commandBuffer->m_transientHeap->getCurrentViewHeap().getGpuHandle(
- gpuHandleIndex),
- descriptor.cpuHandle,
- d3dResource,
- clearValue->color.floatValues,
+ D3D12_CLEAR_FLAGS clearFlags = (D3D12_CLEAR_FLAGS)0;
+ if (flags & ClearResourceViewFlags::ClearDepth)
+ {
+ clearFlags |= D3D12_CLEAR_FLAG_DEPTH;
+ }
+ if (flags & ClearResourceViewFlags::ClearStencil)
+ {
+ clearFlags |= D3D12_CLEAR_FLAG_STENCIL;
+ }
+ m_commandBuffer->m_cmdList->ClearDepthStencilView(
+ viewImpl->m_descriptor.cpuHandle,
+ clearFlags,
+ clearValue->depthStencil.depth,
+ (UINT8)clearValue->depthStencil.stencil,
0,
nullptr);
+ break;
}
- else
+ case IResourceView::Type::UnorderedAccess:
{
- m_commandBuffer->m_cmdList->ClearUnorderedAccessViewUint(
- m_commandBuffer->m_transientHeap->getCurrentViewHeap().getGpuHandle(
- gpuHandleIndex),
+ ID3D12Resource* d3dResource = nullptr;
+ D3D12Descriptor descriptor = viewImpl->m_descriptor;
+ switch (viewImpl->m_resource->getType())
+ {
+ case IResource::Type::Buffer:
+ d3dResource = static_cast<BufferResourceImpl*>(viewImpl->m_resource.Ptr())
+ ->m_resource.getResource();
+ // D3D12 requires a UAV descriptor with zero buffer stride for calling
+ // ClearUnorderedAccessViewUint/Float.
+ viewImpl->getBufferDescriptorForBinding(
+ m_commandBuffer->m_renderer,
+ viewImpl,
+ 0,
+ descriptor);
+ break;
+ default:
+ d3dResource = static_cast<TextureResourceImpl*>(viewImpl->m_resource.Ptr())
+ ->m_resource.getResource();
+ break;
+ }
+ auto gpuHandleIndex =
+ m_commandBuffer->m_transientHeap->getCurrentViewHeap().allocate(1);
+ if (gpuHandleIndex == -1)
+ {
+ m_commandBuffer->m_transientHeap->allocateNewViewDescriptorHeap(
+ m_commandBuffer->m_renderer);
+ gpuHandleIndex = m_commandBuffer->m_transientHeap->getCurrentViewHeap().allocate(1);
+ m_commandBuffer->bindDescriptorHeaps();
+ }
+ this->m_commandBuffer->m_renderer->m_device->CopyDescriptorsSimple(
+ 1,
+ m_commandBuffer->m_transientHeap->getCurrentViewHeap().getCpuHandle(gpuHandleIndex),
descriptor.cpuHandle,
- d3dResource,
- clearValue->color.uintValues,
- 0,
- nullptr);
+ D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
+
+ if (flags & ClearResourceViewFlags::FloatClearValues)
+ {
+ m_commandBuffer->m_cmdList->ClearUnorderedAccessViewFloat(
+ m_commandBuffer->m_transientHeap->getCurrentViewHeap().getGpuHandle(
+ gpuHandleIndex),
+ descriptor.cpuHandle,
+ d3dResource,
+ clearValue->color.floatValues,
+ 0,
+ nullptr);
+ }
+ else
+ {
+ m_commandBuffer->m_cmdList->ClearUnorderedAccessViewUint(
+ m_commandBuffer->m_transientHeap->getCurrentViewHeap().getGpuHandle(
+ gpuHandleIndex),
+ descriptor.cpuHandle,
+ d3dResource,
+ clearValue->color.uintValues,
+ 0,
+ nullptr);
+ }
+ break;
}
- break;
- }
- default:
- break;
+ default: break;
}
}
@@ -485,7 +503,11 @@ void ResourceCommandEncoderImpl::resolveResource(
}
void ResourceCommandEncoderImpl::resolveQuery(
- IQueryPool* queryPool, GfxIndex index, GfxCount count, IBufferResource* buffer, Offset offset)
+ IQueryPool* queryPool,
+ GfxIndex index,
+ GfxCount count,
+ IBufferResource* buffer,
+ Offset offset)
{
auto queryBase = static_cast<QueryPoolBase*>(queryPool);
switch (queryBase->m_desc.type)
@@ -493,45 +515,45 @@ void ResourceCommandEncoderImpl::resolveQuery(
case QueryType::AccelerationStructureCompactedSize:
case QueryType::AccelerationStructureCurrentSize:
case QueryType::AccelerationStructureSerializedSize:
- {
- auto queryPoolImpl = static_cast<PlainBufferProxyQueryPoolImpl*>(queryPool);
- auto bufferImpl = static_cast<BufferResourceImpl*>(buffer);
- auto srcQueryBuffer = queryPoolImpl->m_bufferResource->m_resource.getResource();
+ {
+ auto queryPoolImpl = static_cast<PlainBufferProxyQueryPoolImpl*>(queryPool);
+ auto bufferImpl = static_cast<BufferResourceImpl*>(buffer);
+ auto srcQueryBuffer = queryPoolImpl->m_bufferResource->m_resource.getResource();
- D3D12_RESOURCE_BARRIER barrier = {};
- barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
- barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
- barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
- barrier.Transition.pResource = srcQueryBuffer;
- m_commandBuffer->m_cmdList->ResourceBarrier(1, &barrier);
-
- m_commandBuffer->m_cmdList->CopyBufferRegion(
- bufferImpl->m_resource.getResource(),
- (uint64_t)offset,
- srcQueryBuffer,
- index * sizeof(uint64_t),
- count * sizeof(uint64_t));
+ D3D12_RESOURCE_BARRIER barrier = {};
+ barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
+ barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
+ barrier.Transition.pResource = srcQueryBuffer;
+ m_commandBuffer->m_cmdList->ResourceBarrier(1, &barrier);
+
+ m_commandBuffer->m_cmdList->CopyBufferRegion(
+ bufferImpl->m_resource.getResource(),
+ (uint64_t)offset,
+ srcQueryBuffer,
+ index * sizeof(uint64_t),
+ count * sizeof(uint64_t));
- barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
- barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_SOURCE;
- barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
- barrier.Transition.pResource = srcQueryBuffer;
- m_commandBuffer->m_cmdList->ResourceBarrier(1, &barrier);
- }
- break;
+ barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
+ barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_SOURCE;
+ barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
+ barrier.Transition.pResource = srcQueryBuffer;
+ m_commandBuffer->m_cmdList->ResourceBarrier(1, &barrier);
+ }
+ break;
default:
- {
- auto queryPoolImpl = static_cast<QueryPoolImpl*>(queryPool);
- auto bufferImpl = static_cast<BufferResourceImpl*>(buffer);
- m_commandBuffer->m_cmdList->ResolveQueryData(
- queryPoolImpl->m_queryHeap.get(),
- queryPoolImpl->m_queryType,
- index,
- count,
- bufferImpl->m_resource.getResource(),
- offset);
- }
- break;
+ {
+ auto queryPoolImpl = static_cast<QueryPoolImpl*>(queryPool);
+ auto bufferImpl = static_cast<BufferResourceImpl*>(buffer);
+ m_commandBuffer->m_cmdList->ResolveQueryData(
+ queryPoolImpl->m_queryHeap.get(),
+ queryPoolImpl->m_queryType,
+ index,
+ count,
+ bufferImpl->m_resource.getResource(),
+ offset);
+ }
+ break;
}
}
@@ -680,7 +702,8 @@ void ResourceCommandEncoderImpl::textureSubresourceBarrier(
}
}
m_commandBuffer->m_cmdList->ResourceBarrier(
- (UINT)barriers.getCount(), barriers.getArrayView().getBuffer());
+ (UINT)barriers.getCount(),
+ barriers.getArrayView().getBuffer());
}
void ResourceCommandEncoderImpl::beginDebugEvent(const char* name, float rgbColor[3])
@@ -691,7 +714,7 @@ void ResourceCommandEncoderImpl::beginDebugEvent(const char* name, float rgbColo
beginEvent(
m_commandBuffer->m_cmdList,
0xff000000 | (uint8_t(rgbColor[0] * 255.0f) << 16) |
- (uint8_t(rgbColor[1] * 255.0f) << 8) | uint8_t(rgbColor[2] * 255.0f),
+ (uint8_t(rgbColor[1] * 255.0f) << 8) | uint8_t(rgbColor[2] * 255.0f),
name);
}
}
@@ -706,7 +729,11 @@ void ResourceCommandEncoderImpl::endDebugEvent()
}
void ResourceCommandEncoderImpl::copyBuffer(
- IBufferResource* dst, Offset dstOffset, IBufferResource* src, Offset srcOffset, Size size)
+ IBufferResource* dst,
+ Offset dstOffset,
+ IBufferResource* src,
+ Offset srcOffset,
+ Size size)
{
auto dstBuffer = static_cast<BufferResourceImpl*>(dst);
auto srcBuffer = static_cast<BufferResourceImpl*>(src);
@@ -720,7 +747,10 @@ void ResourceCommandEncoderImpl::copyBuffer(
}
void ResourceCommandEncoderImpl::uploadBufferData(
- IBufferResource* dst, Offset offset, Size size, void* data)
+ IBufferResource* dst,
+ Offset offset,
+ Size size,
+ void* data)
{
uploadBufferDataImpl(
m_commandBuffer->m_renderer->m_device,
@@ -733,7 +763,10 @@ void ResourceCommandEncoderImpl::uploadBufferData(
}
void ResourceCommandEncoderImpl::textureBarrier(
- GfxCount count, ITextureResource* const* textures, ResourceState src, ResourceState dst)
+ GfxCount count,
+ ITextureResource* const* textures,
+ ResourceState src,
+ ResourceState dst)
{
ShortList<D3D12_RESOURCE_BARRIER> barriers;
@@ -769,7 +802,8 @@ void ResourceCommandEncoderImpl::textureBarrier(
if (barriers.getCount())
{
m_commandBuffer->m_cmdList->ResourceBarrier(
- (UINT)barriers.getCount(), barriers.getArrayView().getBuffer());
+ (UINT)barriers.getCount(),
+ barriers.getArrayView().getBuffer());
}
}
@@ -832,7 +866,9 @@ void RenderCommandEncoderImpl::init(
initialState = D3DUtil::getResourceState(access.initialState);
}
textureResource->m_resource.transition(
- initialState, D3D12_RESOURCE_STATE_RENDER_TARGET, submitter);
+ initialState,
+ D3D12_RESOURCE_STATE_RENDER_TARGET,
+ submitter);
}
}
}
@@ -866,7 +902,9 @@ void RenderCommandEncoderImpl::init(
D3DUtil::getResourceState(renderPass->m_depthStencilAccess.initialState);
}
textureResource->m_resource.transition(
- initialState, D3D12_RESOURCE_STATE_DEPTH_WRITE, submitter);
+ initialState,
+ D3D12_RESOURCE_STATE_DEPTH_WRITE,
+ submitter);
}
// Clear.
uint32_t clearFlags = 0;
@@ -898,7 +936,8 @@ Result RenderCommandEncoderImpl::bindPipeline(IPipelineState* state, IShaderObje
}
Result RenderCommandEncoderImpl::bindPipelineWithRootObject(
- IPipelineState* state, IShaderObject* rootObject)
+ IPipelineState* state,
+ IShaderObject* rootObject)
{
return bindPipelineWithRootObjectImpl(state, rootObject);
}
@@ -972,7 +1011,9 @@ void RenderCommandEncoderImpl::setVertexBuffers(
}
void RenderCommandEncoderImpl::setIndexBuffer(
- IBufferResource* buffer, Format indexFormat, Offset offset)
+ IBufferResource* buffer,
+ Format indexFormat,
+ Offset offset)
{
m_boundIndexBuffer = (BufferResourceImpl*)buffer;
m_boundIndexFormat = D3DUtil::getMapFormat(indexFormat);
@@ -1045,10 +1086,17 @@ Result RenderCommandEncoderImpl::draw(GfxCount vertexCount, GfxIndex startVertex
}
Result RenderCommandEncoderImpl::drawIndexed(
- GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex)
+ GfxCount indexCount,
+ GfxIndex startIndex,
+ GfxIndex baseVertex)
{
SLANG_RETURN_ON_FAIL(prepareDraw());
- m_d3dCmdList->DrawIndexedInstanced((uint32_t)indexCount, 1, (uint32_t)startIndex, (uint32_t)baseVertex, 0);
+ m_d3dCmdList->DrawIndexedInstanced(
+ (uint32_t)indexCount,
+ 1,
+ (uint32_t)startIndex,
+ (uint32_t)baseVertex,
+ 0);
return SLANG_OK;
}
@@ -1146,12 +1194,16 @@ Result RenderCommandEncoderImpl::drawIndexedIndirect(
}
Result RenderCommandEncoderImpl::setSamplePositions(
- GfxCount samplesPerPixel, GfxCount pixelCount, const SamplePosition* samplePositions)
+ GfxCount samplesPerPixel,
+ GfxCount pixelCount,
+ const SamplePosition* samplePositions)
{
if (m_commandBuffer->m_cmdList1)
{
m_commandBuffer->m_cmdList1->SetSamplePositions(
- (uint32_t)samplesPerPixel, (uint32_t)pixelCount, (D3D12_SAMPLE_POSITION*)samplePositions);
+ (uint32_t)samplesPerPixel,
+ (uint32_t)pixelCount,
+ (D3D12_SAMPLE_POSITION*)samplePositions);
return SLANG_OK;
}
return SLANG_E_NOT_AVAILABLE;
@@ -1196,10 +1248,15 @@ Result RenderCommandEncoderImpl::drawMeshTasks(int x, int y, int z)
return SLANG_OK;
}
-void ComputeCommandEncoderImpl::endEncoding() { PipelineCommandEncoder::endEncodingImpl(); }
+void ComputeCommandEncoderImpl::endEncoding()
+{
+ PipelineCommandEncoder::endEncodingImpl();
+}
void ComputeCommandEncoderImpl::init(
- DeviceImpl* renderer, TransientResourceHeapImpl* transientHeap, CommandBufferImpl* cmdBuffer)
+ DeviceImpl* renderer,
+ TransientResourceHeapImpl* transientHeap,
+ CommandBufferImpl* cmdBuffer)
{
PipelineCommandEncoder::init(cmdBuffer);
m_preCmdList = nullptr;
@@ -1213,7 +1270,8 @@ Result ComputeCommandEncoderImpl::bindPipeline(IPipelineState* state, IShaderObj
}
Result ComputeCommandEncoderImpl::bindPipelineWithRootObject(
- IPipelineState* state, IShaderObject* rootObject)
+ IPipelineState* state,
+ IShaderObject* rootObject)
{
return bindPipelineWithRootObjectImpl(state, rootObject);
}
@@ -1241,7 +1299,12 @@ Result ComputeCommandEncoderImpl::dispatchComputeIndirect(IBufferResource* argBu
auto argBufferImpl = static_cast<BufferResourceImpl*>(argBuffer);
m_d3dCmdList->ExecuteIndirect(
- m_renderer->dispatchIndirectCmdSignature, 1, argBufferImpl->m_resource, (uint64_t)offset, nullptr, 0);
+ m_renderer->dispatchIndirectCmdSignature,
+ 1,
+ argBufferImpl->m_resource,
+ (uint64_t)offset,
+ nullptr,
+ 0);
return SLANG_OK;
}
@@ -1278,11 +1341,15 @@ void RayTracingCommandEncoderImpl::buildAccelerationStructure(
List<D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_DESC> postBuildInfoDescs;
translatePostBuildInfoDescs(propertyQueryCount, queryDescs, postBuildInfoDescs);
m_commandBuffer->m_cmdList4->BuildRaytracingAccelerationStructure(
- &buildDesc, (UINT)propertyQueryCount, postBuildInfoDescs.getBuffer());
+ &buildDesc,
+ (UINT)propertyQueryCount,
+ postBuildInfoDescs.getBuffer());
}
void RayTracingCommandEncoderImpl::copyAccelerationStructure(
- IAccelerationStructure* dest, IAccelerationStructure* src, AccelerationStructureCopyMode mode)
+ IAccelerationStructure* dest,
+ IAccelerationStructure* src,
+ AccelerationStructureCopyMode mode)
{
auto destASImpl = static_cast<AccelerationStructureImpl*>(dest);
auto srcASImpl = static_cast<AccelerationStructureImpl*>(src);
@@ -1303,7 +1370,9 @@ void RayTracingCommandEncoderImpl::copyAccelerationStructure(
return;
}
m_commandBuffer->m_cmdList4->CopyRaytracingAccelerationStructure(
- destASImpl->getDeviceAddress(), srcASImpl->getDeviceAddress(), copyMode);
+ destASImpl->getDeviceAddress(),
+ srcASImpl->getDeviceAddress(),
+ copyMode);
}
void RayTracingCommandEncoderImpl::queryAccelerationStructureProperties(
@@ -1319,11 +1388,14 @@ void RayTracingCommandEncoderImpl::queryAccelerationStructureProperties(
asAddresses[i] = accelerationStructures[i]->getDeviceAddress();
translatePostBuildInfoDescs(queryCount, queryDescs, postBuildInfoDescs);
m_commandBuffer->m_cmdList4->EmitRaytracingAccelerationStructurePostbuildInfo(
- postBuildInfoDescs.getBuffer(), (UINT)accelerationStructureCount, asAddresses.getBuffer());
+ postBuildInfoDescs.getBuffer(),
+ (UINT)accelerationStructureCount,
+ asAddresses.getBuffer());
}
void RayTracingCommandEncoderImpl::serializeAccelerationStructure(
- DeviceAddress dest, IAccelerationStructure* src)
+ DeviceAddress dest,
+ IAccelerationStructure* src)
{
auto srcASImpl = static_cast<AccelerationStructureImpl*>(src);
m_commandBuffer->m_cmdList4->CopyRaytracingAccelerationStructure(
@@ -1333,7 +1405,8 @@ void RayTracingCommandEncoderImpl::serializeAccelerationStructure(
}
void RayTracingCommandEncoderImpl::deserializeAccelerationStructure(
- IAccelerationStructure* dest, DeviceAddress source)
+ IAccelerationStructure* dest,
+ DeviceAddress source)
{
auto destASImpl = static_cast<AccelerationStructureImpl*>(dest);
m_commandBuffer->m_cmdList4->CopyRaytracingAccelerationStructure(
@@ -1343,7 +1416,8 @@ void RayTracingCommandEncoderImpl::deserializeAccelerationStructure(
}
Result RayTracingCommandEncoderImpl::bindPipeline(
- IPipelineState* state, IShaderObject** outRootObject)
+ IPipelineState* state,
+ IShaderObject** outRootObject)
{
return bindPipelineImpl(state, outRootObject);
}
@@ -1362,9 +1436,9 @@ Result RayTracingCommandEncoderImpl::dispatchRays(
{
ID3D12GraphicsCommandList4* m_cmdList4;
RayTracingSubmitter(ID3D12GraphicsCommandList4* cmdList4)
- : ComputeSubmitter(cmdList4)
- , m_cmdList4(cmdList4)
- {}
+ : ComputeSubmitter(cmdList4), m_cmdList4(cmdList4)
+ {
+ }
virtual void setPipelineState(PipelineStateBase* pipeline) override
{
auto pipelineImpl = static_cast<RayTracingPipelineStateImpl*>(pipeline);
@@ -1380,15 +1454,17 @@ Result RayTracingCommandEncoderImpl::dispatchRays(
auto shaderTableImpl = static_cast<ShaderTableImpl*>(shaderTable);
- auto shaderTableBuffer =
- shaderTableImpl->getOrCreateBuffer(pipelineImpl, m_transientHeap, static_cast<ResourceCommandEncoderImpl*>(this));
+ auto shaderTableBuffer = shaderTableImpl->getOrCreateBuffer(
+ pipelineImpl,
+ m_transientHeap,
+ static_cast<ResourceCommandEncoderImpl*>(this));
auto shaderTableAddr = shaderTableBuffer->getDeviceAddress();
D3D12_DISPATCH_RAYS_DESC dispatchDesc = {};
- dispatchDesc.RayGenerationShaderRecord.StartAddress =
- shaderTableAddr + shaderTableImpl->m_rayGenTableOffset +
- rayGenShaderIndex * kRayGenRecordSize;
+ dispatchDesc.RayGenerationShaderRecord.StartAddress = shaderTableAddr +
+ shaderTableImpl->m_rayGenTableOffset +
+ rayGenShaderIndex * kRayGenRecordSize;
dispatchDesc.RayGenerationShaderRecord.SizeInBytes = D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES;
if (shaderTableImpl->m_missShaderCount > 0)
diff --git a/tools/gfx/d3d12/d3d12-command-encoder.h b/tools/gfx/d3d12/d3d12-command-encoder.h
index 034749946..513c7c994 100644
--- a/tools/gfx/d3d12/d3d12-command-encoder.h
+++ b/tools/gfx/d3d12/d3d12-command-encoder.h
@@ -48,9 +48,7 @@ public:
Result _bindRenderState(Submitter* submitter, RefPtr<PipelineStateBase>& newPipeline);
};
-class ResourceCommandEncoderImpl
- : public IResourceCommandEncoder
- , public PipelineCommandEncoder
+class ResourceCommandEncoderImpl : public IResourceCommandEncoder, public PipelineCommandEncoder
{
public:
virtual void* getInterface(SlangUUID const& uuid)
@@ -60,7 +58,7 @@ public:
return nullptr;
}
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject) override
+ queryInterface(SlangUUID const& uuid, void** outObject) override
{
if (auto ptr = getInterface(uuid))
{
@@ -79,7 +77,7 @@ public:
Offset srcOffset,
Size size) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- uploadBufferData(IBufferResource* dst, Offset offset, Size size, void* data) override;
+ uploadBufferData(IBufferResource* dst, Offset offset, Size size, void* data) override;
virtual SLANG_NO_THROW void SLANG_MCALL textureBarrier(
GfxCount count,
ITextureResource* const* textures,
@@ -92,7 +90,7 @@ public:
ResourceState dst) override;
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override {}
virtual SLANG_NO_THROW void SLANG_MCALL
- writeTimestamp(IQueryPool* pool, GfxIndex index) override;
+ writeTimestamp(IQueryPool* pool, GfxIndex index) override;
virtual SLANG_NO_THROW void SLANG_MCALL copyTexture(
ITextureResource* dst,
ResourceState dstState,
@@ -113,7 +111,9 @@ public:
GfxCount subResourceDataCount) override;
virtual SLANG_NO_THROW void SLANG_MCALL clearResourceView(
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags) override;
+ IResourceView* view,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags) override;
virtual SLANG_NO_THROW void SLANG_MCALL resolveResource(
ITextureResource* source,
@@ -148,19 +148,18 @@ public:
ResourceState dst) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- beginDebugEvent(const char* name, float rgbColor[3]) override;
+ beginDebugEvent(const char* name, float rgbColor[3]) override;
virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override;
};
-class ComputeCommandEncoderImpl
- : public IComputeCommandEncoder
- , public ResourceCommandEncoderImpl
+class ComputeCommandEncoderImpl : public IComputeCommandEncoder, public ResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderImpl)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IComputeCommandEncoder ||
+ uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
return this;
return nullptr;
}
@@ -173,15 +172,15 @@ public:
CommandBufferImpl* cmdBuffer);
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL dispatchCompute(int x, int y, int z) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
+ dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
};
struct BoundVertexBuffer
@@ -190,15 +189,14 @@ struct BoundVertexBuffer
int m_offset;
};
-class RenderCommandEncoderImpl
- : public IRenderCommandEncoder
- , public ResourceCommandEncoderImpl
+class RenderCommandEncoderImpl : public IRenderCommandEncoder, public ResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderImpl)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IRenderCommandEncoder ||
+ uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
return this;
return nullptr;
}
@@ -228,19 +226,19 @@ public:
FramebufferImpl* framebuffer);
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setViewports(GfxCount count, const Viewport* viewports) override;
+ setViewports(GfxCount count, const Viewport* viewports) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setScissorRects(GfxCount count, const ScissorRect* rects) override;
+ setScissorRects(GfxCount count, const ScissorRect* rects) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setPrimitiveTopology(PrimitiveTopology topology) override;
+ setPrimitiveTopology(PrimitiveTopology topology) override;
virtual SLANG_NO_THROW void SLANG_MCALL setVertexBuffers(
GfxIndex startSlot,
@@ -249,13 +247,13 @@ public:
const Offset* offsets) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) override;
+ setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) override;
Result prepareDraw();
virtual SLANG_NO_THROW Result SLANG_MCALL
- draw(GfxCount vertexCount, GfxIndex startVertex = 0) override;
+ draw(GfxCount vertexCount, GfxIndex startVertex = 0) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override;
+ drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override;
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW void SLANG_MCALL setStencilReference(uint32_t referenceValue) override;
@@ -292,20 +290,19 @@ public:
GfxIndex baseVertexLocation,
GfxIndex startInstanceLocation) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- drawMeshTasks(int x, int y, int z) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL drawMeshTasks(int x, int y, int z) override;
};
#if SLANG_GFX_HAS_DXR_SUPPORT
-class RayTracingCommandEncoderImpl
- : public IRayTracingCommandEncoder
- , public ResourceCommandEncoderImpl
+class RayTracingCommandEncoderImpl : public IRayTracingCommandEncoder,
+ public ResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderImpl)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IRayTracingCommandEncoder || uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IRayTracingCommandEncoder ||
+ uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
return this;
return nullptr;
}
@@ -325,13 +322,13 @@ public:
GfxCount queryCount,
AccelerationStructureQueryDesc* queryDescs) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- serializeAccelerationStructure(DeviceAddress dest, IAccelerationStructure* source) override;
- virtual SLANG_NO_THROW void SLANG_MCALL deserializeAccelerationStructure(
- IAccelerationStructure* dest, DeviceAddress source) override;
+ serializeAccelerationStructure(DeviceAddress dest, IAccelerationStructure* source) override;
+ virtual SLANG_NO_THROW void SLANG_MCALL
+ deserializeAccelerationStructure(IAccelerationStructure* dest, DeviceAddress source) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override
{
return bindPipelineWithRootObjectImpl(state, rootObject);
}
diff --git a/tools/gfx/d3d12/d3d12-command-queue.cpp b/tools/gfx/d3d12/d3d12-command-queue.cpp
index d0c567b13..a856c0633 100644
--- a/tools/gfx/d3d12/d3d12-command-queue.cpp
+++ b/tools/gfx/d3d12/d3d12-command-queue.cpp
@@ -24,7 +24,10 @@ Result CommandQueueImpl::init(DeviceImpl* device, uint32_t queueIndex)
SLANG_RETURN_ON_FAIL(
m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(m_fence.writeRef())));
globalWaitHandle = CreateEventEx(
- nullptr, nullptr, CREATE_EVENT_INITIAL_SET | CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
+ nullptr,
+ nullptr,
+ CREATE_EVENT_INITIAL_SET | CREATE_EVENT_MANUAL_RESET,
+ EVENT_ALL_ACCESS);
return SLANG_OK;
}
@@ -36,7 +39,10 @@ CommandQueueImpl::~CommandQueueImpl()
}
void CommandQueueImpl::executeCommandBuffers(
- GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
+ GfxCount count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal)
{
ShortList<ID3D12CommandList*> commandLists;
for (GfxCount i = 0; i < count; i++)
@@ -80,7 +86,9 @@ void CommandQueueImpl::waitOnHost()
}
Result CommandQueueImpl::waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* waitValues)
{
for (GfxCount i = 0; i < fenceCount; ++i)
{
@@ -90,7 +98,10 @@ Result CommandQueueImpl::waitForFenceValuesOnDevice(
return SLANG_OK;
}
-const CommandQueueImpl::Desc& CommandQueueImpl::getDesc() { return m_desc; }
+const CommandQueueImpl::Desc& CommandQueueImpl::getDesc()
+{
+ return m_desc;
+}
ICommandQueue* CommandQueueImpl::getInterface(const Guid& guid)
{
diff --git a/tools/gfx/d3d12/d3d12-command-queue.h b/tools/gfx/d3d12/d3d12-command-queue.h
index f11df5894..dadb85d17 100644
--- a/tools/gfx/d3d12/d3d12-command-queue.h
+++ b/tools/gfx/d3d12/d3d12-command-queue.h
@@ -10,13 +10,11 @@ namespace d3d12
using namespace Slang;
-class CommandQueueImpl
- : public ICommandQueue
- , public ComObject
+class CommandQueueImpl : public ICommandQueue, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
- ICommandQueue* getInterface(const Guid& guid);
+ ICommandQueue* getInterface(const Guid& guid);
void breakStrongReferenceToDevice() { m_renderer.breakStrongReference(); }
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* handle) override;
@@ -43,8 +41,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ waitForFenceValuesOnDevice(GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
};
} // namespace d3d12
diff --git a/tools/gfx/d3d12/d3d12-descriptor-heap.cpp b/tools/gfx/d3d12/d3d12-descriptor-heap.cpp
index b9c0d28ba..d975727f9 100644
--- a/tools/gfx/d3d12/d3d12-descriptor-heap.cpp
+++ b/tools/gfx/d3d12/d3d12-descriptor-heap.cpp
@@ -1,17 +1,20 @@
#include "d3d12-descriptor-heap.h"
-namespace gfx {
+namespace gfx
+{
using namespace Slang;
-D3D12DescriptorHeap::D3D12DescriptorHeap():
- m_totalSize(0),
- m_currentIndex(0),
- m_descriptorSize(0)
+D3D12DescriptorHeap::D3D12DescriptorHeap()
+ : m_totalSize(0), m_currentIndex(0), m_descriptorSize(0)
{
}
-Result D3D12DescriptorHeap::init(ID3D12Device* device, int size, D3D12_DESCRIPTOR_HEAP_TYPE type, D3D12_DESCRIPTOR_HEAP_FLAGS flags)
+Result D3D12DescriptorHeap::init(
+ ID3D12Device* device,
+ int size,
+ D3D12_DESCRIPTOR_HEAP_TYPE type,
+ D3D12_DESCRIPTOR_HEAP_FLAGS flags)
{
m_device = device;
@@ -19,7 +22,8 @@ Result D3D12DescriptorHeap::init(ID3D12Device* device, int size, D3D12_DESCRIPTO
srvHeapDesc.NumDescriptors = size;
srvHeapDesc.Flags = flags;
srvHeapDesc.Type = type;
- SLANG_RETURN_ON_FAIL(device->CreateDescriptorHeap(&srvHeapDesc, IID_PPV_ARGS(m_heap.writeRef())));
+ SLANG_RETURN_ON_FAIL(
+ device->CreateDescriptorHeap(&srvHeapDesc, IID_PPV_ARGS(m_heap.writeRef())));
m_descriptorSize = device->GetDescriptorHandleIncrementSize(type);
m_totalSize = size;
@@ -28,7 +32,12 @@ Result D3D12DescriptorHeap::init(ID3D12Device* device, int size, D3D12_DESCRIPTO
return SLANG_OK;
}
-Result D3D12DescriptorHeap::init(ID3D12Device* device, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, int numHandles, D3D12_DESCRIPTOR_HEAP_TYPE type, D3D12_DESCRIPTOR_HEAP_FLAGS flags)
+Result D3D12DescriptorHeap::init(
+ ID3D12Device* device,
+ const D3D12_CPU_DESCRIPTOR_HANDLE* handles,
+ int numHandles,
+ D3D12_DESCRIPTOR_HEAP_TYPE type,
+ D3D12_DESCRIPTOR_HEAP_FLAGS flags)
{
SLANG_RETURN_ON_FAIL(init(device, numHandles, type, flags));
D3D12_CPU_DESCRIPTOR_HANDLE dst = m_heap->GetCPUDescriptorHandleForHeapStart();
@@ -47,4 +56,3 @@ Result D3D12DescriptorHeap::init(ID3D12Device* device, const D3D12_CPU_DESCRIPTO
}
} // namespace gfx
-
diff --git a/tools/gfx/d3d12/d3d12-descriptor-heap.h b/tools/gfx/d3d12/d3d12-descriptor-heap.h
index 6f82a3f42..44d03b5b0 100644
--- a/tools/gfx/d3d12/d3d12-descriptor-heap.h
+++ b/tools/gfx/d3d12/d3d12-descriptor-heap.h
@@ -1,68 +1,86 @@
#pragma once
-#include <dxgi.h>
-#include <d3d12.h>
-
-#include "slang-com-ptr.h"
-#include "core/slang-virtual-object-pool.h"
-#include "core/slang-short-list.h"
#include "core/slang-basic.h"
+#include "core/slang-short-list.h"
+#include "core/slang-virtual-object-pool.h"
+#include "slang-com-ptr.h"
-namespace gfx {
+#include <d3d12.h>
+#include <dxgi.h>
-/*! \brief A simple class to manage an underlying Dx12 Descriptor Heap. Allocations are made linearly in order. It is not possible to free
-individual allocations, but all allocations can be deallocated with 'deallocateAll'. */
+namespace gfx
+{
+
+/*! \brief A simple class to manage an underlying Dx12 Descriptor Heap. Allocations are made
+linearly in order. It is not possible to free individual allocations, but all allocations can be
+deallocated with 'deallocateAll'. */
class D3D12DescriptorHeap
{
public:
typedef D3D12DescriptorHeap ThisType;
- /// Initialize
- Slang::Result init(ID3D12Device* device, int size, D3D12_DESCRIPTOR_HEAP_TYPE type, D3D12_DESCRIPTOR_HEAP_FLAGS flags);
- /// Initialize with an array of handles copying over the representation
- Slang::Result init(ID3D12Device* device, const D3D12_CPU_DESCRIPTOR_HANDLE* handles, int numHandles, D3D12_DESCRIPTOR_HEAP_TYPE type, D3D12_DESCRIPTOR_HEAP_FLAGS flags);
+ /// Initialize
+ Slang::Result init(
+ ID3D12Device* device,
+ int size,
+ D3D12_DESCRIPTOR_HEAP_TYPE type,
+ D3D12_DESCRIPTOR_HEAP_FLAGS flags);
+ /// Initialize with an array of handles copying over the representation
+ Slang::Result init(
+ ID3D12Device* device,
+ const D3D12_CPU_DESCRIPTOR_HANDLE* handles,
+ int numHandles,
+ D3D12_DESCRIPTOR_HEAP_TYPE type,
+ D3D12_DESCRIPTOR_HEAP_FLAGS flags);
- /// Returns the number of slots that have been used
+ /// Returns the number of slots that have been used
SLANG_FORCE_INLINE int getUsedSize() const { return m_currentIndex; }
- /// Get the total amount of descriptors possible on the heap
+ /// Get the total amount of descriptors possible on the heap
SLANG_FORCE_INLINE int getTotalSize() const { return m_totalSize; }
- /// Allocate a descriptor. Returns the index, or -1 if none left.
+ /// Allocate a descriptor. Returns the index, or -1 if none left.
SLANG_FORCE_INLINE int allocate();
- /// Allocate a number of descriptors. Returns the start index (or -1 if not possible)
+ /// Allocate a number of descriptors. Returns the start index (or -1 if not possible)
SLANG_FORCE_INLINE int allocate(int numDescriptors);
- ///
+ ///
SLANG_FORCE_INLINE int placeAt(int index);
- /// Deallocates all allocations, and starts allocation from the start of the underlying heap again
+ /// Deallocates all allocations, and starts allocation from the start of the underlying heap
+ /// again
SLANG_FORCE_INLINE void deallocateAll() { m_currentIndex = 0; }
- /// Get the size of each
+ /// Get the size of each
SLANG_FORCE_INLINE int getDescriptorSize() const { return m_descriptorSize; }
- /// Get the GPU heap start
- SLANG_FORCE_INLINE D3D12_GPU_DESCRIPTOR_HANDLE getGpuStart() const { return m_heap->GetGPUDescriptorHandleForHeapStart(); }
- /// Get the CPU heap start
- SLANG_FORCE_INLINE D3D12_CPU_DESCRIPTOR_HANDLE getCpuStart() const { return m_heap->GetCPUDescriptorHandleForHeapStart(); }
+ /// Get the GPU heap start
+ SLANG_FORCE_INLINE D3D12_GPU_DESCRIPTOR_HANDLE getGpuStart() const
+ {
+ return m_heap->GetGPUDescriptorHandleForHeapStart();
+ }
+ /// Get the CPU heap start
+ SLANG_FORCE_INLINE D3D12_CPU_DESCRIPTOR_HANDLE getCpuStart() const
+ {
+ return m_heap->GetCPUDescriptorHandleForHeapStart();
+ }
- /// Get the GPU handle at the specified index
+ /// Get the GPU handle at the specified index
SLANG_FORCE_INLINE D3D12_GPU_DESCRIPTOR_HANDLE getGpuHandle(int index) const;
- /// Get the CPU handle at the specified index
+ /// Get the CPU handle at the specified index
SLANG_FORCE_INLINE D3D12_CPU_DESCRIPTOR_HANDLE getCpuHandle(int index) const;
- /// Get the underlying heap
+ /// Get the underlying heap
SLANG_FORCE_INLINE ID3D12DescriptorHeap* getHeap() const { return m_heap; }
- /// Ctor
+ /// Ctor
D3D12DescriptorHeap();
protected:
Slang::ComPtr<ID3D12Device> m_device;
- Slang::ComPtr<ID3D12DescriptorHeap> m_heap; ///< The underlying heap being allocated from
- int m_totalSize; ///< Total amount of allocations available on the heap
- int m_currentIndex; ///< The current descriptor
+ Slang::ComPtr<ID3D12DescriptorHeap> m_heap; ///< The underlying heap being allocated from
+ int m_totalSize; ///< Total amount of allocations available on the heap
+ int m_currentIndex; ///< The current descriptor
int m_descriptorSize; ///< The size of each descriptor
D3D12_DESCRIPTOR_HEAP_FLAGS m_heapFlags; ///< The flags of the heap
};
@@ -83,17 +101,21 @@ struct D3D12Descriptor
///
class D3D12GeneralDescriptorHeap : public Slang::RefObject
{
- ID3D12Device* m_device;
- int m_chunkSize;
- D3D12_DESCRIPTOR_HEAP_TYPE m_type;
+ ID3D12Device* m_device;
+ int m_chunkSize;
+ D3D12_DESCRIPTOR_HEAP_TYPE m_type;
- D3D12DescriptorHeap m_heap;
+ D3D12DescriptorHeap m_heap;
Slang::VirtualObjectPool m_allocator;
public:
int getSize() { return m_chunkSize; }
- Slang::Result init(ID3D12Device* device, int chunkSize, D3D12_DESCRIPTOR_HEAP_TYPE type, D3D12_DESCRIPTOR_HEAP_FLAGS flag)
+ Slang::Result init(
+ ID3D12Device* device,
+ int chunkSize,
+ D3D12_DESCRIPTOR_HEAP_TYPE type,
+ D3D12_DESCRIPTOR_HEAP_FLAGS flag)
{
m_device = device;
m_chunkSize = chunkSize;
@@ -114,17 +136,14 @@ public:
return m_heap.getGpuHandle(index);
}
- int allocate(int count)
- {
- return m_allocator.alloc(count);
- }
+ int allocate(int count) { return m_allocator.alloc(count); }
Slang::Result allocate(D3D12Descriptor* outDescriptor)
{
// TODO: this allocator would take some work to make thread-safe
int index = m_allocator.alloc(1);
- if(index < 0)
+ if (index < 0)
{
assert(!"descriptor allocation failed");
return SLANG_FAIL;
@@ -137,10 +156,7 @@ public:
return SLANG_OK;
}
- void free(int index, int count)
- {
- m_allocator.free(index, count);
- }
+ void free(int index, int count) { m_allocator.free(index, count); }
void free(D3D12Descriptor descriptor)
{
@@ -167,7 +183,8 @@ public:
m_subHeaps.add(subHeap);
if (m_subHeapStartingIndex.getCount())
{
- m_subHeapStartingIndex.add(m_subHeapStartingIndex.getLast() + m_subHeaps.getLast()->getSize());
+ m_subHeapStartingIndex.add(
+ m_subHeapStartingIndex.getLast() + m_subHeaps.getLast()->getSize());
}
else
{
@@ -268,7 +285,6 @@ public:
break;
}
}
-
}
}
};
@@ -344,7 +360,10 @@ struct DescriptorHeapReference
{
enum class Type
{
- Linear, General, ExpandingGeneral, ExpandingLinear
+ Linear,
+ General,
+ ExpandingGeneral,
+ ExpandingLinear
};
union Ptr
{
@@ -380,44 +399,31 @@ struct DescriptorHeapReference
{
switch (type)
{
- case Type::Linear:
- return ptr.linearHeap->getCpuHandle(index);
- case Type::General:
- return ptr.generalHeap->getCpuHandle(index);
- case Type::ExpandingGeneral:
- return ptr.generalExpandingHeap->getCpuHandle(index);
- case Type::ExpandingLinear:
- return ptr.linearExpandingHeap->getCpuHandle(index);
- default:
- return D3D12_CPU_DESCRIPTOR_HANDLE();
+ case Type::Linear: return ptr.linearHeap->getCpuHandle(index);
+ case Type::General: return ptr.generalHeap->getCpuHandle(index);
+ case Type::ExpandingGeneral: return ptr.generalExpandingHeap->getCpuHandle(index);
+ case Type::ExpandingLinear: return ptr.linearExpandingHeap->getCpuHandle(index);
+ default: return D3D12_CPU_DESCRIPTOR_HANDLE();
}
}
D3D12_GPU_DESCRIPTOR_HANDLE getGpuHandle(int index) const
{
switch (type)
{
- case Type::Linear:
- return ptr.linearHeap->getGpuHandle(index);
- case Type::General:
- return ptr.generalHeap->getGpuHandle(index);
- case Type::ExpandingGeneral:
- return ptr.generalExpandingHeap->getGpuHandle(index);
- default:
- return D3D12_GPU_DESCRIPTOR_HANDLE();
+ case Type::Linear: return ptr.linearHeap->getGpuHandle(index);
+ case Type::General: return ptr.generalHeap->getGpuHandle(index);
+ case Type::ExpandingGeneral: return ptr.generalExpandingHeap->getGpuHandle(index);
+ default: return D3D12_GPU_DESCRIPTOR_HANDLE();
}
}
int allocate(int numDescriptors)
{
switch (type)
{
- case Type::Linear:
- return ptr.linearHeap->allocate(numDescriptors);
- case Type::General:
- return ptr.generalHeap->allocate(numDescriptors);
- case Type::ExpandingGeneral:
- return ptr.generalExpandingHeap->allocate(numDescriptors);
- default:
- return ptr.linearExpandingHeap->allocate(numDescriptors);
+ case Type::Linear: return ptr.linearHeap->allocate(numDescriptors);
+ case Type::General: return ptr.generalHeap->allocate(numDescriptors);
+ case Type::ExpandingGeneral: return ptr.generalExpandingHeap->allocate(numDescriptors);
+ default: return ptr.linearExpandingHeap->allocate(numDescriptors);
}
}
void free(int index, int count)
@@ -425,33 +431,28 @@ struct DescriptorHeapReference
switch (type)
{
default:
- case Type::Linear:
- SLANG_ASSERT(!"Linear heap does not support free().");
- break;
- case Type::General:
- return ptr.generalHeap->free(index, count);
- case Type::ExpandingGeneral:
- return ptr.generalExpandingHeap->free(index, count);
+ case Type::Linear: SLANG_ASSERT(!"Linear heap does not support free()."); break;
+ case Type::General: return ptr.generalHeap->free(index, count);
+ case Type::ExpandingGeneral: return ptr.generalExpandingHeap->free(index, count);
}
}
void freeIfSupported(int index, int count)
{
switch (type)
{
- case Type::Linear:
- return;
- case Type::General:
- return ptr.generalHeap->free(index, count);
- case Type::ExpandingGeneral:
- return ptr.generalExpandingHeap->free(index, count);
- default:
- break;
+ case Type::Linear: return;
+ case Type::General: return ptr.generalHeap->free(index, count);
+ case Type::ExpandingGeneral: return ptr.generalExpandingHeap->free(index, count);
+ default: break;
}
}
};
// ---------------------------------------------------------------------------
-int D3D12DescriptorHeap::allocate() { return allocate(1); }
+int D3D12DescriptorHeap::allocate()
+{
+ return allocate(1);
+}
// ---------------------------------------------------------------------------
int D3D12DescriptorHeap::allocate(int numDescriptors)
{
@@ -511,4 +512,3 @@ SLANG_FORCE_INLINE D3D12_GPU_DESCRIPTOR_HANDLE D3D12DescriptorHeap::getGpuHandle
}
} // namespace gfx
-
diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp
index 09a789ff0..f2b24ab5f 100644
--- a/tools/gfx/d3d12/d3d12-device.cpp
+++ b/tools/gfx/d3d12/d3d12-device.cpp
@@ -5,6 +5,7 @@
#include "d3d12-buffer.h"
#include "d3d12-fence.h"
#include "d3d12-framebuffer.h"
+#include "d3d12-helper-functions.h"
#include "d3d12-pipeline-state.h"
#include "d3d12-query.h"
#include "d3d12-render-pass.h"
@@ -16,22 +17,20 @@
#include "d3d12-swap-chain.h"
#include "d3d12-vertex-layout.h"
-#include "d3d12-helper-functions.h"
-
#ifdef _DEBUG
-# define ENABLE_DEBUG_LAYER 1
+#define ENABLE_DEBUG_LAYER 1
#else
-# define ENABLE_DEBUG_LAYER 0
+#define ENABLE_DEBUG_LAYER 0
#endif
#ifdef GFX_NVAPI
-# include "../nvapi/nvapi-include.h"
+#include "../nvapi/nvapi-include.h"
#endif
#ifdef GFX_NV_AFTERMATH
-# include "GFSDK_Aftermath.h"
-# include "GFSDK_Aftermath_Defines.h"
-# include "GFSDK_Aftermath_GpuCrashDump.h"
+#include "GFSDK_Aftermath.h"
+#include "GFSDK_Aftermath_Defines.h"
+#include "GFSDK_Aftermath_GpuCrashDump.h"
#endif
namespace gfx
@@ -45,9 +44,9 @@ static const uint32_t D3D_FEATURE_LEVEL_12_2 = 0xc200;
#if GFX_NV_AFTERMATH
-/* static */const bool DeviceImpl::g_isAftermathEnabled = true;
+/* static */ const bool DeviceImpl::g_isAftermathEnabled = true;
#else
-/* static */const bool DeviceImpl::g_isAftermathEnabled = false;
+/* static */ const bool DeviceImpl::g_isAftermathEnabled = false;
#endif
struct ShaderModelInfo
@@ -58,10 +57,16 @@ struct ShaderModelInfo
};
// List of shader models. Do not change oldest to newest order.
static ShaderModelInfo kKnownShaderModels[] = {
-#define SHADER_MODEL_INFO_DXBC(major, minor) {D3D_SHADER_MODEL_##major##_##minor, SLANG_DXBC, "sm_" #major "_" #minor }
+#define SHADER_MODEL_INFO_DXBC(major, minor) \
+ { \
+ D3D_SHADER_MODEL_##major##_##minor, SLANG_DXBC, "sm_" #major "_" #minor \
+ }
SHADER_MODEL_INFO_DXBC(5, 1),
#undef SHADER_MODEL_INFO_DXBC
-#define SHADER_MODEL_INFO_DXIL(major, minor) {(D3D_SHADER_MODEL)0x##major##minor, SLANG_DXIL, "sm_" #major "_" #minor }
+#define SHADER_MODEL_INFO_DXIL(major, minor) \
+ { \
+ (D3D_SHADER_MODEL)0x##major##minor, SLANG_DXIL, "sm_" #major "_" #minor \
+ }
SHADER_MODEL_INFO_DXIL(6, 0),
SHADER_MODEL_INFO_DXIL(6, 1),
SHADER_MODEL_INFO_DXIL(6, 2),
@@ -119,8 +124,7 @@ Result DeviceImpl::createBuffer(
if (initialState != D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE)
initialState = D3D12_RESOURCE_STATE_COMMON;
break;
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
}
// Create the resource.
@@ -166,8 +170,8 @@ Result DeviceImpl::createBuffer(
if (memoryType == MemoryType::DeviceLocal)
{
auto encodeInfo = encodeResourceCommands();
- encodeInfo.d3dCommandList->CopyBufferRegion(
- resourceOut, 0, uploadResourceRef, 0, bufferSize);
+ encodeInfo.d3dCommandList
+ ->CopyBufferRegion(resourceOut, 0, uploadResourceRef, 0, bufferSize);
submitResourceCommandsAndWait(encodeInfo);
}
}
@@ -269,7 +273,7 @@ Result DeviceImpl::captureTextureToSurface(
ID3D12Resource* dxResource = stagingResource;
UINT8* data;
- D3D12_RANGE readRange = { 0, bufferSize };
+ D3D12_RANGE readRange = {0, bufferSize};
SLANG_RETURN_ON_FAIL(dxResource->Map(0, &readRange, reinterpret_cast<void**>(&data)));
@@ -320,7 +324,7 @@ Result DeviceImpl::_createDevice(
{
IDXGIAdapter* dxgiAdapter = dxgiAdapters[i];
if (SLANG_SUCCEEDED(
- m_D3D12CreateDevice(dxgiAdapter, featureLevel, IID_PPV_ARGS(device.writeRef()))))
+ m_D3D12CreateDevice(dxgiAdapter, featureLevel, IID_PPV_ARGS(device.writeRef()))))
{
adapter = dxgiAdapter;
break;
@@ -357,7 +361,9 @@ Result DeviceImpl::_createDevice(
D3D12_FEATURE_DATA_SHADER_MODEL featureShaderModel;
featureShaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_3;
SLANG_SUCCEEDED(device->CheckFeatureSupport(
- D3D12_FEATURE_SHADER_MODEL, &featureShaderModel, sizeof(featureShaderModel)));
+ D3D12_FEATURE_SHADER_MODEL,
+ &featureShaderModel,
+ sizeof(featureShaderModel)));
if (featureShaderModel.HighestShaderModel >= D3D_SHADER_MODEL_6_3)
{
@@ -373,7 +379,7 @@ Result DeviceImpl::_createDevice(
};
// We filter INFO messages because they are way too many
- D3D12_MESSAGE_SEVERITY severities[] = { D3D12_MESSAGE_SEVERITY_INFO };
+ D3D12_MESSAGE_SEVERITY severities[] = {D3D12_MESSAGE_SEVERITY_INFO};
D3D12_INFO_QUEUE_FILTER infoQueueFilter = {};
infoQueueFilter.DenyList.NumSeverities = SLANG_COUNT_OF(severities);
@@ -392,23 +398,28 @@ Result DeviceImpl::_createDevice(
if ((deviceCheckFlags & DeviceCheckFlag::UseDebug) && g_isAftermathEnabled)
{
// Initialize Nsight Aftermath for this device.
- // This combination of flags is not necessarily appropraite for real world usage
- const uint32_t aftermathFlags =
- GFSDK_Aftermath_FeatureFlags_EnableMarkers | // Enable event marker tracking.
- GFSDK_Aftermath_FeatureFlags_CallStackCapturing | // Enable automatic call stack event markers.
- GFSDK_Aftermath_FeatureFlags_EnableResourceTracking | // Enable tracking of resources.
- GFSDK_Aftermath_FeatureFlags_GenerateShaderDebugInfo | // Generate debug information for shaders.
- GFSDK_Aftermath_FeatureFlags_EnableShaderErrorReporting; // Enable additional runtime shader error reporting.
-
+ // This combination of flags is not necessarily appropraite for real world usage
+ const uint32_t aftermathFlags =
+ GFSDK_Aftermath_FeatureFlags_EnableMarkers | // Enable event marker tracking.
+ GFSDK_Aftermath_FeatureFlags_CallStackCapturing | // Enable automatic call stack
+ // event markers.
+ GFSDK_Aftermath_FeatureFlags_EnableResourceTracking | // Enable tracking of
+ // resources.
+ GFSDK_Aftermath_FeatureFlags_GenerateShaderDebugInfo | // Generate debug information
+ // for shaders.
+ GFSDK_Aftermath_FeatureFlags_EnableShaderErrorReporting; // Enable additional
+ // runtime shader error
+ // reporting.
+
auto initResult = GFSDK_Aftermath_DX12_Initialize(
GFSDK_Aftermath_Version_API,
aftermathFlags,
device);
-
- if ( initResult != GFSDK_Aftermath_Result_Success)
+
+ if (initResult != GFSDK_Aftermath_Result_Success)
{
SLANG_ASSERT_FAILURE("Unable to initialize aftermath");
- // Unable to initialize
+ // Unable to initialize
return SLANG_FAIL;
}
}
@@ -456,7 +467,9 @@ Result DeviceImpl::initialize(const Desc& desc)
if (SLANG_FAILED(SharedLibrary::load(libName, d3dModule)))
{
getDebugCallback()->handleMessage(
- DebugMessageType::Error, DebugMessageSource::Layer, "error: failed load 'd3d12.dll'\n");
+ DebugMessageType::Error,
+ DebugMessageSource::Layer,
+ "error: failed load 'd3d12.dll'\n");
return SLANG_FAIL;
}
@@ -465,7 +478,7 @@ Result DeviceImpl::initialize(const Desc& desc)
{
StructType stype;
memcpy(&stype, desc.extendedDescs[i], sizeof(stype));
- switch (stype )
+ switch (stype)
{
case StructType::D3D12DeviceExtendedDesc:
memcpy(&m_extendedDesc, desc.extendedDescs[i], sizeof(m_extendedDesc));
@@ -486,7 +499,7 @@ Result DeviceImpl::initialize(const Desc& desc)
m_info.bindingStyle = BindingStyle::DirectX;
m_info.projectionStyle = ProjectionStyle::DirectX;
m_info.apiName = "Direct3D 12";
- static const float kIdentity[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
+ static const float kIdentity[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
::memcpy(m_info.identityProjectionMatrix, kIdentity, sizeof(kIdentity));
}
@@ -498,8 +511,9 @@ Result DeviceImpl::initialize(const Desc& desc)
return SLANG_FAIL;
}
- m_D3D12SerializeVersionedRootSignature =
- (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)loadProc(d3dModule, "D3D12SerializeVersionedRootSignature");
+ m_D3D12SerializeVersionedRootSignature = (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)loadProc(
+ d3dModule,
+ "D3D12SerializeVersionedRootSignature");
if (!m_D3D12SerializeVersionedRootSignature)
{
return SLANG_FAIL;
@@ -526,7 +540,7 @@ Result DeviceImpl::initialize(const Desc& desc)
{
if (SLANG_SUCCEEDED(m_D3D12GetDebugInterface(IID_PPV_ARGS(m_dxDebug.writeRef()))))
{
-# if 0
+#if 0
// Can enable for extra validation. NOTE! That d3d12 warns if you do....
// D3D12 MESSAGE : Device Debug Layer Startup Options : GPU - Based Validation is enabled(disabled by default).
// This results in new validation not possible during API calls on the CPU, by creating patched shaders that have validation
@@ -539,7 +553,7 @@ Result DeviceImpl::initialize(const Desc& desc)
{
debug1->SetEnableGPUBasedValidation(true);
}
-# endif
+#endif
}
}
}
@@ -559,7 +573,8 @@ Result DeviceImpl::initialize(const Desc& desc)
if (ENABLE_DEBUG_LAYER || isGfxDebugLayerEnabled())
{
combiner.add(
- DeviceCheckFlag::UseDebug, ChangeType::OnOff); ///< First try debug then non debug
+ DeviceCheckFlag::UseDebug,
+ ChangeType::OnOff); ///< First try debug then non debug
}
else
{
@@ -570,8 +585,7 @@ Result DeviceImpl::initialize(const Desc& desc)
ChangeType::OnOff); ///< First try hardware, then reference
- const D3D_FEATURE_LEVEL featureLevels[] =
- {
+ const D3D_FEATURE_LEVEL featureLevels[] = {
(D3D_FEATURE_LEVEL)D3D_FEATURE_LEVEL_12_2,
D3D_FEATURE_LEVEL_12_1,
D3D_FEATURE_LEVEL_12_0,
@@ -581,24 +595,23 @@ Result DeviceImpl::initialize(const Desc& desc)
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
- D3D_FEATURE_LEVEL_9_1
- };
+ D3D_FEATURE_LEVEL_9_1};
for (auto featureLevel : featureLevels)
{
const int numCombinations = combiner.getNumCombinations();
for (int i = 0; i < numCombinations; ++i)
{
if (SLANG_SUCCEEDED(_createDevice(
- combiner.getCombination(i),
- desc.adapterLUID,
- featureLevel,
- m_deviceInfo)))
+ combiner.getCombination(i),
+ desc.adapterLUID,
+ featureLevel,
+ m_deviceInfo)))
{
goto succ;
}
}
}
- succ:
+ succ:
if (!m_deviceInfo.m_adapter)
{
// Couldn't find an adapter
@@ -669,9 +682,10 @@ Result DeviceImpl::initialize(const Desc& desc)
SLANG_COMPILE_TIME_ASSERT(D3D_SHADER_MODEL_6_0 == 0x60);
{
- // CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL) can fail if the runtime/driver does not yet know the
- // specified highest shader model. Therefore we assemble a list of shader models to check and
- // walk it from highest to lowest to find the supported shader model.
+ // CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL) can fail if the runtime/driver does
+ // not yet know the specified highest shader model. Therefore we assemble a list of
+ // shader models to check and walk it from highest to lowest to find the supported
+ // shader model.
Slang::ShortList<D3D_SHADER_MODEL> shaderModels;
if (m_extendedDesc.highestShaderModel != 0)
shaderModels.add((D3D_SHADER_MODEL)m_extendedDesc.highestShaderModel);
@@ -680,12 +694,16 @@ Result DeviceImpl::initialize(const Desc& desc)
for (D3D_SHADER_MODEL shaderModel : shaderModels)
{
shaderModelData.HighestShaderModel = shaderModel;
- if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shaderModelData, sizeof(shaderModelData))))
+ if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(
+ D3D12_FEATURE_SHADER_MODEL,
+ &shaderModelData,
+ sizeof(shaderModelData))))
break;
}
// TODO: Currently warp causes a crash when using half, so disable for now
- if (m_deviceInfo.m_isWarp == false && shaderModelData.HighestShaderModel >= D3D_SHADER_MODEL_6_2)
+ if (m_deviceInfo.m_isWarp == false &&
+ shaderModelData.HighestShaderModel >= D3D_SHADER_MODEL_6_2)
{
// With sm_6_2 we have half
m_features.add("half");
@@ -694,7 +712,9 @@ Result DeviceImpl::initialize(const Desc& desc)
{
D3D12_FEATURE_DATA_D3D12_OPTIONS options;
if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(
- D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options))))
+ D3D12_FEATURE_D3D12_OPTIONS,
+ &options,
+ sizeof(options))))
{
// Check double precision support
if (options.DoublePrecisionFloatShaderOps)
@@ -728,7 +748,9 @@ Result DeviceImpl::initialize(const Desc& desc)
{
D3D12_FEATURE_DATA_D3D12_OPTIONS1 options;
if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(
- D3D12_FEATURE_D3D12_OPTIONS1, &options, sizeof(options))))
+ D3D12_FEATURE_D3D12_OPTIONS1,
+ &options,
+ sizeof(options))))
{
// Check wave operations support
if (options.WaveOps)
@@ -738,7 +760,9 @@ Result DeviceImpl::initialize(const Desc& desc)
{
D3D12_FEATURE_DATA_D3D12_OPTIONS2 options;
if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(
- D3D12_FEATURE_D3D12_OPTIONS2, &options, sizeof(options))))
+ D3D12_FEATURE_D3D12_OPTIONS2,
+ &options,
+ sizeof(options))))
{
// Check programmable sample positions support
switch (options.ProgrammableSamplePositionsTier)
@@ -750,15 +774,16 @@ Result DeviceImpl::initialize(const Desc& desc)
case D3D12_PROGRAMMABLE_SAMPLE_POSITIONS_TIER_1:
m_features.add("programmable-sample-positions-1");
break;
- default:
- break;
+ default: break;
}
}
}
{
D3D12_FEATURE_DATA_D3D12_OPTIONS3 options;
if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(
- D3D12_FEATURE_D3D12_OPTIONS3, &options, sizeof(options))))
+ D3D12_FEATURE_D3D12_OPTIONS3,
+ &options,
+ sizeof(options))))
{
// Check barycentrics support
if (options.BarycentricsSupported)
@@ -771,7 +796,9 @@ Result DeviceImpl::initialize(const Desc& desc)
{
D3D12_FEATURE_DATA_D3D12_OPTIONS5 options;
if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(
- D3D12_FEATURE_D3D12_OPTIONS5, &options, sizeof(options))))
+ D3D12_FEATURE_D3D12_OPTIONS5,
+ &options,
+ sizeof(options))))
{
if (options.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED)
{
@@ -787,7 +814,9 @@ Result DeviceImpl::initialize(const Desc& desc)
{
D3D12_FEATURE_DATA_D3D12_OPTIONS7 options;
if (SLANG_SUCCEEDED(m_device->CheckFeatureSupport(
- D3D12_FEATURE_D3D12_OPTIONS7, &options, sizeof(options))))
+ D3D12_FEATURE_D3D12_OPTIONS7,
+ &options,
+ sizeof(options))))
{
if (options.MeshShaderTier >= D3D12_MESH_SHADER_TIER_1)
{
@@ -825,9 +854,12 @@ Result DeviceImpl::initialize(const Desc& desc)
limits.maxComputeThreadGroupSize[0] = D3D12_CS_THREAD_GROUP_MAX_X;
limits.maxComputeThreadGroupSize[1] = D3D12_CS_THREAD_GROUP_MAX_Y;
limits.maxComputeThreadGroupSize[2] = D3D12_CS_THREAD_GROUP_MAX_Z;
- limits.maxComputeDispatchThreadGroups[0] = D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
- limits.maxComputeDispatchThreadGroups[1] = D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
- limits.maxComputeDispatchThreadGroups[2] = D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
+ limits.maxComputeDispatchThreadGroups[0] =
+ D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
+ limits.maxComputeDispatchThreadGroups[1] =
+ D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
+ limits.maxComputeDispatchThreadGroups[2] =
+ D3D12_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION;
limits.maxViewports = D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
limits.maxViewportDimensions[0] = D3D12_VIEWPORT_BOUNDS_MAX;
@@ -859,14 +891,23 @@ Result DeviceImpl::initialize(const Desc& desc)
D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
m_cpuSamplerHeap = new D3D12GeneralExpandingDescriptorHeap();
SLANG_RETURN_ON_FAIL(m_cpuSamplerHeap->init(
- m_device, 2048, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
+ m_device,
+ 2048,
+ D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
+ D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
m_rtvAllocator = new D3D12GeneralExpandingDescriptorHeap();
SLANG_RETURN_ON_FAIL(m_rtvAllocator->init(
- m_device, 16 * 1024, D3D12_DESCRIPTOR_HEAP_TYPE_RTV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
+ m_device,
+ 16 * 1024,
+ D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
+ D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
m_dsvAllocator = new D3D12GeneralExpandingDescriptorHeap();
SLANG_RETURN_ON_FAIL(m_dsvAllocator->init(
- m_device, 1024, D3D12_DESCRIPTOR_HEAP_TYPE_DSV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
+ m_device,
+ 1024,
+ D3D12_DESCRIPTOR_HEAP_TYPE_DSV,
+ D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
ComPtr<IDXGIDevice> dxgiDevice;
if (m_deviceInfo.m_adapter)
@@ -914,7 +955,7 @@ Result DeviceImpl::initialize(const Desc& desc)
desc.extendedDescs,
compileTarget,
profileName,
- makeArray(slang::PreprocessorMacroDesc{ "__D3D12__", "1" }).getView()));
+ makeArray(slang::PreprocessorMacroDesc{"__D3D12__", "1"}).getView()));
// Allocate a D3D12 "command signature" object that matches the behavior
// of a D3D11-style `DrawInstancedIndirect` operation.
@@ -929,7 +970,9 @@ Result DeviceImpl::initialize(const Desc& desc)
desc.NodeMask = 0;
SLANG_RETURN_ON_FAIL(m_device->CreateCommandSignature(
- &desc, nullptr, IID_PPV_ARGS(drawIndirectCmdSignature.writeRef())));
+ &desc,
+ nullptr,
+ IID_PPV_ARGS(drawIndirectCmdSignature.writeRef())));
}
// Allocate a D3D12 "command signature" object that matches the behavior
@@ -945,7 +988,9 @@ Result DeviceImpl::initialize(const Desc& desc)
desc.NodeMask = 0;
SLANG_RETURN_ON_FAIL(m_device->CreateCommandSignature(
- &desc, nullptr, IID_PPV_ARGS(drawIndexedIndirectCmdSignature.writeRef())));
+ &desc,
+ nullptr,
+ IID_PPV_ARGS(drawIndexedIndirectCmdSignature.writeRef())));
}
// Allocate a D3D12 "command signature" object that matches the behavior
@@ -961,14 +1006,17 @@ Result DeviceImpl::initialize(const Desc& desc)
desc.NodeMask = 0;
SLANG_RETURN_ON_FAIL(m_device->CreateCommandSignature(
- &desc, nullptr, IID_PPV_ARGS(dispatchIndirectCmdSignature.writeRef())));
+ &desc,
+ nullptr,
+ IID_PPV_ARGS(dispatchIndirectCmdSignature.writeRef())));
}
m_isInitialized = true;
return SLANG_OK;
}
Result DeviceImpl::createTransientResourceHeap(
- const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap)
+ const ITransientResourceHeap::Desc& desc,
+ ITransientResourceHeap** outHeap)
{
RefPtr<TransientResourceHeapImpl> heap;
SLANG_RETURN_ON_FAIL(createTransientResourceHeapImpl(
@@ -990,7 +1038,9 @@ Result DeviceImpl::createCommandQueue(const ICommandQueue::Desc& desc, ICommandQ
}
Result DeviceImpl::createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain)
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain)
{
RefPtr<SwapchainImpl> swapchain = new SwapchainImpl();
SLANG_RETURN_ON_FAIL(swapchain->init(this, desc, window));
@@ -1006,11 +1056,17 @@ SlangResult DeviceImpl::readTextureResource(
Size* outPixelSize)
{
return captureTextureToSurface(
- static_cast<TextureResourceImpl*>(resource), state, outBlob, outRowPitch, outPixelSize);
+ static_cast<TextureResourceImpl*>(resource),
+ state,
+ outBlob,
+ outRowPitch,
+ outPixelSize);
}
Result DeviceImpl::getTextureAllocationInfo(
- const ITextureResource::Desc& desc, Size* outSize, Size* outAlignment)
+ const ITextureResource::Desc& desc,
+ Size* outSize,
+ Size* outAlignment)
{
TextureResource::Desc srcDesc = fixupTextureDesc(desc);
D3D12_RESOURCE_DESC resourceDesc = {};
@@ -1069,7 +1125,7 @@ Result DeviceImpl::createTextureResource(
clearValuePtr = &clearValue;
}
if ((resourceDesc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET |
- D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) == 0)
+ D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) == 0)
{
clearValuePtr = nullptr;
}
@@ -1194,8 +1250,8 @@ Result DeviceImpl::createTextureResource(
const uint8_t* srcRow = srcLayer;
uint8_t* dstRow = dstLayer;
int j = gfxIsCompressedFormat(descIn.format)
- ? 4
- : 1; // BC compressed formats are organized into 4x4 blocks
+ ? 4
+ : 1; // BC compressed formats are organized into 4x4 blocks
for (int k = 0; k < mipSize.height; k += j)
{
::memcpy(dstRow, srcRow, (Size)mipRowSize);
@@ -1240,7 +1296,9 @@ Result DeviceImpl::createTextureResource(
{
D3D12BarrierSubmitter submitter(encodeInfo.d3dCommandList);
texture->m_resource.transition(
- D3D12_RESOURCE_STATE_COPY_DEST, texture->m_defaultState, submitter);
+ D3D12_RESOURCE_STATE_COPY_DEST,
+ texture->m_defaultState,
+ submitter);
}
submitResourceCommandsAndWait(encodeInfo);
}
@@ -1250,7 +1308,9 @@ Result DeviceImpl::createTextureResource(
}
Result DeviceImpl::createTextureFromNativeHandle(
- InteropHandle handle, const ITextureResource::Desc& srcDesc, ITextureResource** outResource)
+ InteropHandle handle,
+ const ITextureResource::Desc& srcDesc,
+ ITextureResource** outResource)
{
RefPtr<TextureResourceImpl> texture(new TextureResourceImpl(srcDesc));
@@ -1268,7 +1328,9 @@ Result DeviceImpl::createTextureFromNativeHandle(
}
Result DeviceImpl::createBufferResource(
- const IBufferResource::Desc& descIn, const void* initData, IBufferResource** outResource)
+ const IBufferResource::Desc& descIn,
+ const void* initData,
+ IBufferResource** outResource)
{
BufferResource::Desc srcDesc = fixupBufferDesc(descIn);
@@ -1294,7 +1356,9 @@ Result DeviceImpl::createBufferResource(
}
Result DeviceImpl::createBufferFromNativeHandle(
- InteropHandle handle, const IBufferResource::Desc& srcDesc, IBufferResource** outResource)
+ InteropHandle handle,
+ const IBufferResource::Desc& srcDesc,
+ IBufferResource** outResource)
{
RefPtr<BufferResourceImpl> buffer(new BufferResourceImpl(srcDesc));
@@ -1359,7 +1423,9 @@ Result DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerS
}
Result DeviceImpl::createTextureView(
- ITextureResource* texture, IResourceView::Desc const& desc, IResourceView** outView)
+ ITextureResource* texture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView)
{
auto resourceImpl = (TextureResourceImpl*)texture;
@@ -1370,242 +1436,246 @@ Result DeviceImpl::createTextureView(
bool isMultiSample = resourceImpl ? resourceImpl->getDesc()->sampleDesc.numSamples > 1 : false;
switch (desc.type)
{
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
case IResourceView::Type::RenderTarget:
- {
- SLANG_RETURN_ON_FAIL(m_rtvAllocator->allocate(&viewImpl->m_descriptor));
- viewImpl->m_allocator = m_rtvAllocator;
- D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = {};
- rtvDesc.Format = D3DUtil::getMapFormat(desc.format);
- switch (desc.renderTarget.shape)
{
- case IResource::Type::Texture1D:
- rtvDesc.ViewDimension = isArray ? D3D12_RTV_DIMENSION_TEXTURE1DARRAY : D3D12_RTV_DIMENSION_TEXTURE1D;
- if(isArray)
- {
- rtvDesc.Texture1DArray.MipSlice = desc.subresourceRange.mipLevel;
- rtvDesc.Texture1DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
- rtvDesc.Texture1DArray.ArraySize = desc.subresourceRange.layerCount;
- }
- else
- {
- rtvDesc.Texture1D.MipSlice = desc.subresourceRange.mipLevel;
- }
-
- break;
- case IResource::Type::Texture2D:
- if (isMultiSample)
+ SLANG_RETURN_ON_FAIL(m_rtvAllocator->allocate(&viewImpl->m_descriptor));
+ viewImpl->m_allocator = m_rtvAllocator;
+ D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = {};
+ rtvDesc.Format = D3DUtil::getMapFormat(desc.format);
+ switch (desc.renderTarget.shape)
{
- rtvDesc.ViewDimension = isArray ? D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY
- : D3D12_RTV_DIMENSION_TEXTURE2DMS;
- rtvDesc.Texture2DMSArray.ArraySize = desc.subresourceRange.layerCount;
- rtvDesc.Texture2DMSArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
- }
- else
- {
- rtvDesc.ViewDimension = isArray ? D3D12_RTV_DIMENSION_TEXTURE2DARRAY
- : D3D12_RTV_DIMENSION_TEXTURE2D;
- if(isArray)
+ case IResource::Type::Texture1D:
+ rtvDesc.ViewDimension =
+ isArray ? D3D12_RTV_DIMENSION_TEXTURE1DARRAY : D3D12_RTV_DIMENSION_TEXTURE1D;
+ if (isArray)
{
- rtvDesc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
- rtvDesc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount;
- rtvDesc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
- rtvDesc.Texture2DArray.PlaneSlice =
- resourceImpl ? D3DUtil::getPlaneSlice(
- D3DUtil::getMapFormat(resourceImpl->getDesc()->format),
- desc.subresourceRange.aspectMask)
- : 0;
+ rtvDesc.Texture1DArray.MipSlice = desc.subresourceRange.mipLevel;
+ rtvDesc.Texture1DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
+ rtvDesc.Texture1DArray.ArraySize = desc.subresourceRange.layerCount;
}
else
{
- rtvDesc.Texture2D.MipSlice = desc.subresourceRange.mipLevel;
- rtvDesc.Texture2D.PlaneSlice =
- resourceImpl ? D3DUtil::getPlaneSlice(
- D3DUtil::getMapFormat(resourceImpl->getDesc()->format),
- desc.subresourceRange.aspectMask)
- : 0;
+ rtvDesc.Texture1D.MipSlice = desc.subresourceRange.mipLevel;
+ }
+
+ break;
+ case IResource::Type::Texture2D:
+ if (isMultiSample)
+ {
+ rtvDesc.ViewDimension = isArray ? D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY
+ : D3D12_RTV_DIMENSION_TEXTURE2DMS;
+ rtvDesc.Texture2DMSArray.ArraySize = desc.subresourceRange.layerCount;
+ rtvDesc.Texture2DMSArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
}
+ else
+ {
+ rtvDesc.ViewDimension = isArray ? D3D12_RTV_DIMENSION_TEXTURE2DARRAY
+ : D3D12_RTV_DIMENSION_TEXTURE2D;
+ if (isArray)
+ {
+ rtvDesc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
+ rtvDesc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount;
+ rtvDesc.Texture2DArray.FirstArraySlice =
+ desc.subresourceRange.baseArrayLayer;
+ rtvDesc.Texture2DArray.PlaneSlice =
+ resourceImpl
+ ? D3DUtil::getPlaneSlice(
+ D3DUtil::getMapFormat(resourceImpl->getDesc()->format),
+ desc.subresourceRange.aspectMask)
+ : 0;
+ }
+ else
+ {
+ rtvDesc.Texture2D.MipSlice = desc.subresourceRange.mipLevel;
+ rtvDesc.Texture2D.PlaneSlice =
+ resourceImpl
+ ? D3DUtil::getPlaneSlice(
+ D3DUtil::getMapFormat(resourceImpl->getDesc()->format),
+ desc.subresourceRange.aspectMask)
+ : 0;
+ }
+ }
+ break;
+ case IResource::Type::TextureCube:
+ rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY;
+ rtvDesc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
+ rtvDesc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount;
+ rtvDesc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
+ rtvDesc.Texture2DArray.PlaneSlice =
+ resourceImpl ? D3DUtil::getPlaneSlice(
+ D3DUtil::getMapFormat(resourceImpl->getDesc()->format),
+ desc.subresourceRange.aspectMask)
+ : 0;
+ break;
+ case IResource::Type::Texture3D:
+ rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE3D;
+ rtvDesc.Texture3D.MipSlice = desc.subresourceRange.mipLevel;
+ rtvDesc.Texture3D.FirstWSlice = desc.subresourceRange.baseArrayLayer;
+ rtvDesc.Texture3D.WSize =
+ (desc.subresourceRange.layerCount == 0) ? -1 : desc.subresourceRange.layerCount;
+ break;
+ case IResource::Type::Buffer: rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_BUFFER; break;
+ default: return SLANG_FAIL;
}
- break;
- case IResource::Type::TextureCube:
- rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY;
- rtvDesc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
- rtvDesc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount;
- rtvDesc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
- rtvDesc.Texture2DArray.PlaneSlice =
- resourceImpl
- ? D3DUtil::getPlaneSlice(D3DUtil::getMapFormat(resourceImpl->getDesc()->format), desc.subresourceRange.aspectMask)
- : 0;
- break;
- case IResource::Type::Texture3D:
- rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE3D;
- rtvDesc.Texture3D.MipSlice = desc.subresourceRange.mipLevel;
- rtvDesc.Texture3D.FirstWSlice = desc.subresourceRange.baseArrayLayer;
- rtvDesc.Texture3D.WSize = (desc.subresourceRange.layerCount == 0) ? -1 : desc.subresourceRange.layerCount;
- break;
- case IResource::Type::Buffer:
- rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_BUFFER;
- break;
- default:
- return SLANG_FAIL;
+ m_device->CreateRenderTargetView(
+ resourceImpl ? resourceImpl->m_resource.getResource() : nullptr,
+ &rtvDesc,
+ viewImpl->m_descriptor.cpuHandle);
}
- m_device->CreateRenderTargetView(
- resourceImpl ? resourceImpl->m_resource.getResource() : nullptr,
- &rtvDesc,
- viewImpl->m_descriptor.cpuHandle);
- }
- break;
+ break;
case IResourceView::Type::DepthStencil:
- {
- SLANG_RETURN_ON_FAIL(m_dsvAllocator->allocate(&viewImpl->m_descriptor));
- viewImpl->m_allocator = m_dsvAllocator;
- D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
- dsvDesc.Format = D3DUtil::getMapFormat(desc.format);
- switch (desc.renderTarget.shape)
{
- case IResource::Type::Texture1D:
- dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE1D;
- dsvDesc.Texture1D.MipSlice = desc.subresourceRange.mipLevel;
- break;
- case IResource::Type::Texture2D:
- if (isMultiSample)
- {
- dsvDesc.ViewDimension = isArray ? D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY
- : D3D12_DSV_DIMENSION_TEXTURE2DMS;
- dsvDesc.Texture2DMSArray.ArraySize = desc.subresourceRange.layerCount;
- dsvDesc.Texture2DMSArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
- }
- else
+ SLANG_RETURN_ON_FAIL(m_dsvAllocator->allocate(&viewImpl->m_descriptor));
+ viewImpl->m_allocator = m_dsvAllocator;
+ D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
+ dsvDesc.Format = D3DUtil::getMapFormat(desc.format);
+ switch (desc.renderTarget.shape)
{
- dsvDesc.ViewDimension = isArray ? D3D12_DSV_DIMENSION_TEXTURE2DARRAY
- : D3D12_DSV_DIMENSION_TEXTURE2D;
+ case IResource::Type::Texture1D:
+ dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE1D;
+ dsvDesc.Texture1D.MipSlice = desc.subresourceRange.mipLevel;
+ break;
+ case IResource::Type::Texture2D:
+ if (isMultiSample)
+ {
+ dsvDesc.ViewDimension = isArray ? D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY
+ : D3D12_DSV_DIMENSION_TEXTURE2DMS;
+ dsvDesc.Texture2DMSArray.ArraySize = desc.subresourceRange.layerCount;
+ dsvDesc.Texture2DMSArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
+ }
+ else
+ {
+ dsvDesc.ViewDimension = isArray ? D3D12_DSV_DIMENSION_TEXTURE2DARRAY
+ : D3D12_DSV_DIMENSION_TEXTURE2D;
+ dsvDesc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
+ dsvDesc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount;
+ dsvDesc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
+ }
+ break;
+ case IResource::Type::TextureCube:
+ dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DARRAY;
dsvDesc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
dsvDesc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount;
dsvDesc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
+ break;
+ default: return SLANG_FAIL;
}
- break;
- case IResource::Type::TextureCube:
- dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DARRAY;
- dsvDesc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
- dsvDesc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount;
- dsvDesc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
- break;
- default:
- return SLANG_FAIL;
+ m_device->CreateDepthStencilView(
+ resourceImpl ? resourceImpl->m_resource.getResource() : nullptr,
+ &dsvDesc,
+ viewImpl->m_descriptor.cpuHandle);
}
- m_device->CreateDepthStencilView(
- resourceImpl ? resourceImpl->m_resource.getResource() : nullptr,
- &dsvDesc,
- viewImpl->m_descriptor.cpuHandle);
- }
- break;
+ break;
case IResourceView::Type::UnorderedAccess:
- {
- // TODO: need to support the separate "counter resource" for the case
- // of append/consume buffers with attached counters.
-
- SLANG_RETURN_ON_FAIL(m_cpuViewHeap->allocate(&viewImpl->m_descriptor));
- viewImpl->m_allocator = m_cpuViewHeap;
- D3D12_UNORDERED_ACCESS_VIEW_DESC d3d12desc = {};
- auto& resourceDesc = *resourceImpl->getDesc();
- d3d12desc.Format = gfxIsTypelessFormat(texture->getDesc()->format)
- ? D3DUtil::getMapFormat(desc.format)
- : D3DUtil::getMapFormat(texture->getDesc()->format);
- switch (resourceImpl->getDesc()->type)
{
- case IResource::Type::Texture1D:
- d3d12desc.ViewDimension = isArray
- ? D3D12_UAV_DIMENSION_TEXTURE1DARRAY
- : D3D12_UAV_DIMENSION_TEXTURE1D;
- if(isArray)
- {
- d3d12desc.Texture1DArray.MipSlice = desc.subresourceRange.mipLevel;
- d3d12desc.Texture1DArray.ArraySize = desc.subresourceRange.layerCount == 0
- ? resourceDesc.arraySize
- : desc.subresourceRange.layerCount;
- d3d12desc.Texture1DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
- }
- else
- {
- d3d12desc.Texture1D.MipSlice = desc.subresourceRange.mipLevel;
- }
- break;
- case IResource::Type::Texture2D:
- d3d12desc.ViewDimension = isArray
- ? D3D12_UAV_DIMENSION_TEXTURE2DARRAY
- : D3D12_UAV_DIMENSION_TEXTURE2D;
- if(isArray)
+ // TODO: need to support the separate "counter resource" for the case
+ // of append/consume buffers with attached counters.
+
+ SLANG_RETURN_ON_FAIL(m_cpuViewHeap->allocate(&viewImpl->m_descriptor));
+ viewImpl->m_allocator = m_cpuViewHeap;
+ D3D12_UNORDERED_ACCESS_VIEW_DESC d3d12desc = {};
+ auto& resourceDesc = *resourceImpl->getDesc();
+ d3d12desc.Format = gfxIsTypelessFormat(texture->getDesc()->format)
+ ? D3DUtil::getMapFormat(desc.format)
+ : D3DUtil::getMapFormat(texture->getDesc()->format);
+ switch (resourceImpl->getDesc()->type)
{
+ case IResource::Type::Texture1D:
+ d3d12desc.ViewDimension =
+ isArray ? D3D12_UAV_DIMENSION_TEXTURE1DARRAY : D3D12_UAV_DIMENSION_TEXTURE1D;
+ if (isArray)
+ {
+ d3d12desc.Texture1DArray.MipSlice = desc.subresourceRange.mipLevel;
+ d3d12desc.Texture1DArray.ArraySize = desc.subresourceRange.layerCount == 0
+ ? resourceDesc.arraySize
+ : desc.subresourceRange.layerCount;
+ d3d12desc.Texture1DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
+ }
+ else
+ {
+ d3d12desc.Texture1D.MipSlice = desc.subresourceRange.mipLevel;
+ }
+ break;
+ case IResource::Type::Texture2D:
+ d3d12desc.ViewDimension =
+ isArray ? D3D12_UAV_DIMENSION_TEXTURE2DARRAY : D3D12_UAV_DIMENSION_TEXTURE2D;
+ if (isArray)
+ {
+ d3d12desc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
+ d3d12desc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount == 0
+ ? resourceDesc.arraySize
+ : desc.subresourceRange.layerCount;
+ d3d12desc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
+ d3d12desc.Texture2DArray.PlaneSlice =
+ D3DUtil::getPlaneSlice(d3d12desc.Format, desc.subresourceRange.aspectMask);
+ }
+ else
+ {
+ d3d12desc.Texture2D.MipSlice = desc.subresourceRange.mipLevel;
+ d3d12desc.Texture2D.PlaneSlice =
+ D3DUtil::getPlaneSlice(d3d12desc.Format, desc.subresourceRange.aspectMask);
+ }
+ break;
+ case IResource::Type::TextureCube:
+ d3d12desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY;
d3d12desc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
d3d12desc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount == 0
- ? resourceDesc.arraySize
- : desc.subresourceRange.layerCount;
+ ? resourceDesc.arraySize
+ : desc.subresourceRange.layerCount;
d3d12desc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
d3d12desc.Texture2DArray.PlaneSlice =
D3DUtil::getPlaneSlice(d3d12desc.Format, desc.subresourceRange.aspectMask);
+ break;
+ case IResource::Type::Texture3D:
+ d3d12desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D;
+ d3d12desc.Texture3D.MipSlice = desc.subresourceRange.mipLevel;
+ d3d12desc.Texture3D.FirstWSlice = desc.subresourceRange.baseArrayLayer;
+ d3d12desc.Texture3D.WSize =
+ resourceDesc.size.depth >> desc.subresourceRange.mipLevel;
+ break;
+ default: return SLANG_FAIL;
}
- else
- {
- d3d12desc.Texture2D.MipSlice = desc.subresourceRange.mipLevel;
- d3d12desc.Texture2D.PlaneSlice =
- D3DUtil::getPlaneSlice(d3d12desc.Format, desc.subresourceRange.aspectMask);
- }
- break;
- case IResource::Type::TextureCube:
- d3d12desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY;
- d3d12desc.Texture2DArray.MipSlice = desc.subresourceRange.mipLevel;
- d3d12desc.Texture2DArray.ArraySize = desc.subresourceRange.layerCount == 0
- ? resourceDesc.arraySize
- : desc.subresourceRange.layerCount;
- d3d12desc.Texture2DArray.FirstArraySlice = desc.subresourceRange.baseArrayLayer;
- d3d12desc.Texture2DArray.PlaneSlice =
- D3DUtil::getPlaneSlice(d3d12desc.Format, desc.subresourceRange.aspectMask);
- break;
- case IResource::Type::Texture3D:
- d3d12desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D;
- d3d12desc.Texture3D.MipSlice = desc.subresourceRange.mipLevel;
- d3d12desc.Texture3D.FirstWSlice = desc.subresourceRange.baseArrayLayer;
- d3d12desc.Texture3D.WSize = resourceDesc.size.depth >> desc.subresourceRange.mipLevel;
- break;
- default:
- return SLANG_FAIL;
+ m_device->CreateUnorderedAccessView(
+ resourceImpl->m_resource,
+ nullptr,
+ &d3d12desc,
+ viewImpl->m_descriptor.cpuHandle);
}
- m_device->CreateUnorderedAccessView(
- resourceImpl->m_resource, nullptr, &d3d12desc, viewImpl->m_descriptor.cpuHandle);
- }
- break;
+ break;
case IResourceView::Type::ShaderResource:
- {
- SLANG_RETURN_ON_FAIL(m_cpuViewHeap->allocate(&viewImpl->m_descriptor));
- viewImpl->m_allocator = m_cpuViewHeap;
-
- // Need to construct the D3D12_SHADER_RESOURCE_VIEW_DESC because otherwise TextureCube
- // is not accessed appropriately (rather than just passing nullptr to
- // CreateShaderResourceView)
- const D3D12_RESOURCE_DESC resourceDesc =
- resourceImpl->m_resource.getResource()->GetDesc();
- const DXGI_FORMAT pixelFormat = desc.format == Format::Unknown
- ? resourceDesc.Format
- : D3DUtil::getMapFormat(desc.format);
-
- D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
- initSrvDesc(
- resourceImpl->getType(),
- *resourceImpl->getDesc(),
- resourceDesc,
- pixelFormat,
- desc.subresourceRange,
- srvDesc);
-
- m_device->CreateShaderResourceView(
- resourceImpl->m_resource, &srvDesc, viewImpl->m_descriptor.cpuHandle);
- }
- break;
+ {
+ SLANG_RETURN_ON_FAIL(m_cpuViewHeap->allocate(&viewImpl->m_descriptor));
+ viewImpl->m_allocator = m_cpuViewHeap;
+
+ // Need to construct the D3D12_SHADER_RESOURCE_VIEW_DESC because otherwise TextureCube
+ // is not accessed appropriately (rather than just passing nullptr to
+ // CreateShaderResourceView)
+ const D3D12_RESOURCE_DESC resourceDesc =
+ resourceImpl->m_resource.getResource()->GetDesc();
+ const DXGI_FORMAT pixelFormat = desc.format == Format::Unknown
+ ? resourceDesc.Format
+ : D3DUtil::getMapFormat(desc.format);
+
+ D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
+ initSrvDesc(
+ resourceImpl->getType(),
+ *resourceImpl->getDesc(),
+ resourceDesc,
+ pixelFormat,
+ desc.subresourceRange,
+ srvDesc);
+
+ m_device->CreateShaderResourceView(
+ resourceImpl->m_resource,
+ &srvDesc,
+ viewImpl->m_descriptor.cpuHandle);
+ }
+ break;
}
returnComPtr(outView, viewImpl);
@@ -1677,7 +1747,7 @@ Result DeviceImpl::createBufferView(
// Buffer view descriptors are created on demand.
viewImpl->m_descriptor = {0};
viewImpl->m_allocator = m_cpuViewHeap.get();
-
+
returnComPtr(outView, viewImpl);
return SLANG_OK;
}
@@ -1699,11 +1769,14 @@ Result DeviceImpl::createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffe
auto clearValue =
static_cast<TextureResourceImpl*>(
static_cast<ResourceViewImpl*>(desc.renderTargetViews[i])->m_resource.Ptr())
- ->getDesc()
- ->optimalClearValue;
+ ->getDesc()
+ ->optimalClearValue;
if (clearValue)
{
- memcpy(&framebuffer->renderTargetClearValues[i], &clearValue->color, sizeof(ColorClearValue));
+ memcpy(
+ &framebuffer->renderTargetClearValues[i],
+ &clearValue->color,
+ sizeof(ColorClearValue));
}
}
else
@@ -1714,10 +1787,11 @@ Result DeviceImpl::createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffe
framebuffer->depthStencilView = static_cast<ResourceViewImpl*>(desc.depthStencilView);
if (desc.depthStencilView)
{
- auto clearValue = static_cast<TextureResourceImpl*>(
- static_cast<ResourceViewImpl*>(desc.depthStencilView)->m_resource.Ptr())
- ->getDesc()
- ->optimalClearValue;
+ auto clearValue =
+ static_cast<TextureResourceImpl*>(
+ static_cast<ResourceViewImpl*>(desc.depthStencilView)->m_resource.Ptr())
+ ->getDesc()
+ ->optimalClearValue;
if (clearValue)
{
@@ -1735,7 +1809,8 @@ Result DeviceImpl::createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffe
}
Result DeviceImpl::createFramebufferLayout(
- IFramebufferLayout::Desc const& desc, IFramebufferLayout** outLayout)
+ IFramebufferLayout::Desc const& desc,
+ IFramebufferLayout** outLayout)
{
RefPtr<FramebufferLayoutImpl> layout = new FramebufferLayoutImpl();
layout->m_renderTargets.setCount(desc.renderTargetCount);
@@ -1758,7 +1833,8 @@ Result DeviceImpl::createFramebufferLayout(
}
Result DeviceImpl::createRenderPassLayout(
- const IRenderPassLayout::Desc& desc, IRenderPassLayout** outRenderPassLayout)
+ const IRenderPassLayout::Desc& desc,
+ IRenderPassLayout** outRenderPassLayout)
{
RefPtr<RenderPassLayoutImpl> result = new RenderPassLayoutImpl();
result->init(desc);
@@ -1824,10 +1900,16 @@ Result DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayou
return SLANG_OK;
}
-const gfx::DeviceInfo& DeviceImpl::getDeviceInfo() const { return m_info; }
+const gfx::DeviceInfo& DeviceImpl::getDeviceInfo() const
+{
+ return m_info;
+}
Result DeviceImpl::readBufferResource(
- IBufferResource* bufferIn, Offset offset, Size size, ISlangBlob** outBlob)
+ IBufferResource* bufferIn,
+ Offset offset,
+ Size size,
+ ISlangBlob** outBlob)
{
BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(bufferIn);
@@ -1876,7 +1958,7 @@ Result DeviceImpl::readBufferResource(
List<uint8_t> blobData;
{
UINT8* data;
- D3D12_RANGE readRange = { 0, size };
+ D3D12_RANGE readRange = {0, size};
SLANG_RETURN_ON_FAIL(
stageBufRef.getResource()->Map(0, &readRange, reinterpret_cast<void**>(&data)));
@@ -1893,7 +1975,9 @@ Result DeviceImpl::readBufferResource(
}
Result DeviceImpl::createProgram(
- const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnosticBlob)
{
RefPtr<ShaderProgramImpl> shaderProgram = new ShaderProgramImpl();
shaderProgram->init(desc);
@@ -1941,13 +2025,16 @@ Result DeviceImpl::createShaderObject(ShaderObjectLayoutBase* layout, IShaderObj
{
RefPtr<ShaderObjectImpl> shaderObject;
SLANG_RETURN_ON_FAIL(ShaderObjectImpl::create(
- this, reinterpret_cast<ShaderObjectLayoutImpl*>(layout), shaderObject.writeRef()));
+ this,
+ reinterpret_cast<ShaderObjectLayoutImpl*>(layout),
+ shaderObject.writeRef()));
returnComPtr(outObject, shaderObject);
return SLANG_OK;
}
Result DeviceImpl::createMutableShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject)
{
auto result = createShaderObject(layout, outObject);
SLANG_RETURN_ON_FAIL(result);
@@ -1961,7 +2048,11 @@ Result DeviceImpl::createMutableRootShaderObject(IShaderProgram* program, IShade
result->init(this);
auto programImpl = static_cast<ShaderProgramImpl*>(program);
result->resetImpl(
- this, programImpl->m_rootObjectLayout, m_cpuViewHeap.Ptr(), m_cpuSamplerHeap.Ptr(), true);
+ this,
+ programImpl->m_rootObjectLayout,
+ m_cpuViewHeap.Ptr(),
+ m_cpuSamplerHeap.Ptr(),
+ true);
returnComPtr(outObject, result);
return SLANG_OK;
}
@@ -1976,7 +2067,8 @@ Result DeviceImpl::createShaderTable(const IShaderTable::Desc& desc, IShaderTabl
}
Result DeviceImpl::createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& desc, IPipelineState** outState)
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState)
{
RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl(this);
pipelineStateImpl->init(desc);
@@ -1985,7 +2077,8 @@ Result DeviceImpl::createGraphicsPipelineState(
}
Result DeviceImpl::createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState)
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState)
{
RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl(this);
pipelineStateImpl->init(desc);
@@ -2011,17 +2104,17 @@ void DeviceImpl::submitResourceCommandsAndWait(const DeviceImpl::ResourceCommand
void DeviceImpl::processExperimentalFeaturesDesc(SharedLibrary::Handle d3dModule, void* inDesc)
{
- typedef HRESULT(WINAPI* PFN_D3D12_ENABLE_EXPERIMENTAL_FEATURES)(
- UINT NumFeatures,
+ typedef HRESULT(WINAPI * PFN_D3D12_ENABLE_EXPERIMENTAL_FEATURES)(
+ UINT NumFeatures,
const IID* pIIDs,
void* pConfigurationStructs,
- UINT* pConfigurationStructSizes
- );
+ UINT* pConfigurationStructSizes);
D3D12ExperimentalFeaturesDesc desc = {};
memcpy(&desc, inDesc, sizeof(desc));
- auto enableExperimentalFeaturesFunc =
- (PFN_D3D12_ENABLE_EXPERIMENTAL_FEATURES)loadProc(d3dModule, "D3D12EnableExperimentalFeatures");
+ auto enableExperimentalFeaturesFunc = (PFN_D3D12_ENABLE_EXPERIMENTAL_FEATURES)loadProc(
+ d3dModule,
+ "D3D12EnableExperimentalFeatures");
if (!enableExperimentalFeaturesFunc)
{
getDebugCallback()->handleMessage(
@@ -2031,7 +2124,11 @@ void DeviceImpl::processExperimentalFeaturesDesc(SharedLibrary::Handle d3dModule
"not found.");
return;
}
- if (!SLANG_SUCCEEDED(enableExperimentalFeaturesFunc(desc.numFeatures, (IID*)desc.featureIIDs, desc.configurationStructs, desc.configurationStructSizes)))
+ if (!SLANG_SUCCEEDED(enableExperimentalFeaturesFunc(
+ desc.numFeatures,
+ (IID*)desc.featureIIDs,
+ desc.configurationStructs,
+ desc.configurationStructSizes)))
{
getDebugCallback()->handleMessage(
gfx::DebugMessageType::Warning,
@@ -2049,23 +2146,23 @@ Result DeviceImpl::createQueryPool(const IQueryPool::Desc& desc, IQueryPool** ou
case QueryType::AccelerationStructureCompactedSize:
case QueryType::AccelerationStructureSerializedSize:
case QueryType::AccelerationStructureCurrentSize:
- {
- RefPtr<PlainBufferProxyQueryPoolImpl> queryPoolImpl =
- new PlainBufferProxyQueryPoolImpl();
- uint32_t stride = 8;
- if (desc.type == QueryType::AccelerationStructureSerializedSize)
- stride = 16;
- SLANG_RETURN_ON_FAIL(queryPoolImpl->init(desc, this, stride));
- returnComPtr(outState, queryPoolImpl);
- return SLANG_OK;
- }
+ {
+ RefPtr<PlainBufferProxyQueryPoolImpl> queryPoolImpl =
+ new PlainBufferProxyQueryPoolImpl();
+ uint32_t stride = 8;
+ if (desc.type == QueryType::AccelerationStructureSerializedSize)
+ stride = 16;
+ SLANG_RETURN_ON_FAIL(queryPoolImpl->init(desc, this, stride));
+ returnComPtr(outState, queryPoolImpl);
+ return SLANG_OK;
+ }
default:
- {
- RefPtr<QueryPoolImpl> queryPoolImpl = new QueryPoolImpl();
- SLANG_RETURN_ON_FAIL(queryPoolImpl->init(desc, this));
- returnComPtr(outState, queryPoolImpl);
- return SLANG_OK;
- }
+ {
+ RefPtr<QueryPoolImpl> queryPoolImpl = new QueryPoolImpl();
+ SLANG_RETURN_ON_FAIL(queryPoolImpl->init(desc, this));
+ returnComPtr(outState, queryPoolImpl);
+ return SLANG_OK;
+ }
}
}
@@ -2078,7 +2175,11 @@ Result DeviceImpl::createFence(const IFence::Desc& desc, IFence** outFence)
}
Result DeviceImpl::waitForFences(
- GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* fenceValues,
+ bool waitForAll,
+ uint64_t timeout)
{
ShortList<HANDLE> waitHandles;
for (GfxCount i = 0; i < fenceCount; ++i)
@@ -2118,7 +2219,8 @@ Result DeviceImpl::getAccelerationStructurePrebuildInfo(
}
Result DeviceImpl::createAccelerationStructure(
- const IAccelerationStructure::CreateDesc& desc, IAccelerationStructure** outAS)
+ const IAccelerationStructure::CreateDesc& desc,
+ IAccelerationStructure** outAS)
{
#if SLANG_GFX_HAS_DXR_SUPPORT
RefPtr<AccelerationStructureImpl> result = new AccelerationStructureImpl();
@@ -2139,13 +2241,14 @@ Result DeviceImpl::createAccelerationStructure(
returnComPtr(outAS, result);
return SLANG_OK;
#else
- * outAS = nullptr;
+ *outAS = nullptr;
return SLANG_FAIL;
#endif
}
Result DeviceImpl::createRayTracingPipelineState(
- const RayTracingPipelineStateDesc& inDesc, IPipelineState** outState)
+ const RayTracingPipelineStateDesc& inDesc,
+ IPipelineState** outState)
{
if (!m_device5)
{
@@ -2203,7 +2306,10 @@ void* DeviceImpl::loadProc(SharedLibrary::Handle module, char const* name)
return proc;
}
-DeviceImpl::~DeviceImpl() { m_shaderObjectLayoutCache = decltype(m_shaderObjectLayoutCache)(); }
+DeviceImpl::~DeviceImpl()
+{
+ m_shaderObjectLayoutCache = decltype(m_shaderObjectLayoutCache)();
+}
} // namespace d3d12
diff --git a/tools/gfx/d3d12/d3d12-device.h b/tools/gfx/d3d12/d3d12-device.h
index a38e3c68e..31756d3e9 100644
--- a/tools/gfx/d3d12/d3d12-device.h
+++ b/tools/gfx/d3d12/d3d12-device.h
@@ -2,8 +2,8 @@
#pragma once
#include "d3d12-command-buffer.h"
#include "d3d12-command-queue.h"
-#include "d3d12-transient-heap.h"
#include "d3d12-texture.h"
+#include "d3d12-transient-heap.h"
#include <d3d12.h>
#include <d3d12sdklayers.h>
@@ -17,7 +17,9 @@ using namespace Slang;
// Define function pointer types for PIX library.
typedef HRESULT(WINAPI* PFN_BeginEventOnCommandList)(
- ID3D12GraphicsCommandList* commandList, UINT64 color, PCSTR formatString);
+ ID3D12GraphicsCommandList* commandList,
+ UINT64 color,
+ PCSTR formatString);
typedef HRESULT(WINAPI* PFN_EndEventOnCommandList)(ID3D12GraphicsCommandList* commandList);
struct D3D12DeviceInfo
@@ -74,7 +76,7 @@ public:
// around CPU-visible heaps for storing shader-objects' descriptors in a format
// that is ready for copying into the GPU-visible heaps as needed.
//
- RefPtr<D3D12GeneralExpandingDescriptorHeap> m_cpuViewHeap; ///< Cbv, Srv, Uav
+ RefPtr<D3D12GeneralExpandingDescriptorHeap> m_cpuViewHeap; ///< Cbv, Srv, Uav
RefPtr<D3D12GeneralExpandingDescriptorHeap> m_cpuSamplerHeap; ///< Heap for samplers
// Dll entry points
@@ -97,17 +99,22 @@ public:
public:
virtual SLANG_NO_THROW SlangResult SLANG_MCALL initialize(const Desc& desc) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
+ getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
+ createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap(
- const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap) override;
+ const ITransientResourceHeap::Desc& desc,
+ ITransientResourceHeap** outHeap) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureAllocationInfo(
- const ITextureResource::Desc& desc, Size* outSize, Size* outAlignment) override;
+ const ITextureResource::Desc& desc,
+ Size* outSize,
+ Size* outAlignment) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureRowAlignment(Size* outAlignment) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureResource(
const ITextureResource::Desc& desc,
@@ -127,7 +134,7 @@ public:
IBufferResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
+ createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView(
ITextureResource* texture,
@@ -140,42 +147,49 @@ public:
IResourceView** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffer** outFrameBuffer) override;
+ createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffer** outFrameBuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFramebufferLayout(
- IFramebufferLayout::Desc const& desc, IFramebufferLayout** outLayout) override;
+ IFramebufferLayout::Desc const& desc,
+ IFramebufferLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createRenderPassLayout(
- const IRenderPassLayout::Desc& desc, IRenderPassLayout** outRenderPassLayout) override;
+ const IRenderPassLayout::Desc& desc,
+ IRenderPassLayout** outRenderPassLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
+ createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
virtual Result createShaderObjectLayout(
- slang::ISession* session, slang::TypeLayoutReflection* typeLayout, ShaderObjectLayoutBase** outLayout) override;
- virtual Result createShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
+ slang::ISession* session,
+ slang::TypeLayoutReflection* typeLayout,
+ ShaderObjectLayoutBase** outLayout) override;
+ virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ override;
virtual Result createMutableShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
+ createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outShaderTable) override;
+ createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outShaderTable) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createProgram(
const IShaderProgram::Desc& desc,
IShaderProgram** outProgram,
ISlangBlob** outDiagnostics) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& desc, IPipelineState** outState) override;
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outState) override;
+ createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createFence(const IFence::Desc& desc, IFence** outFence) override;
+ createFence(const IFence::Desc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL waitForFences(
GfxCount fenceCount,
@@ -192,12 +206,15 @@ public:
Size* outPixelSize) override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL readBufferResource(
- IBufferResource* resource, Offset offset, Size size, ISlangBlob** outBlob) override;
+ IBufferResource* resource,
+ Offset offset,
+ Size size,
+ ISlangBlob** outBlob) override;
virtual SLANG_NO_THROW const gfx::DeviceInfo& SLANG_MCALL getDeviceInfo() const override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeDeviceHandles(InteropHandles* outHandles) override;
+ getNativeDeviceHandles(InteropHandles* outHandles) override;
~DeviceImpl();
@@ -205,9 +222,11 @@ public:
const IAccelerationStructure::BuildInputs& buildInputs,
IAccelerationStructure::PrebuildInfo* outPrebuildInfo) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createAccelerationStructure(
- const IAccelerationStructure::CreateDesc& desc, IAccelerationStructure** outView) override;
+ const IAccelerationStructure::CreateDesc& desc,
+ IAccelerationStructure** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createRayTracingPipelineState(
- const RayTracingPipelineStateDesc& desc, IPipelineState** outState) override;
+ const RayTracingPipelineStateDesc& desc,
+ IPipelineState** outState) override;
public:
static void* loadProc(SharedLibrary::Handle module, char const* name);
@@ -250,6 +269,7 @@ public:
};
ResourceCommandRecordInfo encodeResourceCommands();
void submitResourceCommandsAndWait(const ResourceCommandRecordInfo& info);
+
private:
void processExperimentalFeaturesDesc(SharedLibrary::Handle d3dModule, void* desc);
};
diff --git a/tools/gfx/d3d12/d3d12-fence.cpp b/tools/gfx/d3d12/d3d12-fence.cpp
index 124d9354c..8b7d47440 100644
--- a/tools/gfx/d3d12/d3d12-fence.cpp
+++ b/tools/gfx/d3d12/d3d12-fence.cpp
@@ -60,7 +60,11 @@ Result FenceImpl::getSharedHandle(InteropHandle* outHandle)
ComPtr<ID3D12Device> devicePtr;
m_fence->GetDevice(IID_PPV_ARGS(devicePtr.writeRef()));
SLANG_RETURN_ON_FAIL(devicePtr->CreateSharedHandle(
- m_fence, NULL, GENERIC_ALL, nullptr, (HANDLE*)&outHandle->handleValue));
+ m_fence,
+ NULL,
+ GENERIC_ALL,
+ nullptr,
+ (HANDLE*)&outHandle->handleValue));
outHandle->api = InteropHandleAPI::D3D12;
sharedHandle = *outHandle;
return SLANG_OK;
diff --git a/tools/gfx/d3d12/d3d12-fence.h b/tools/gfx/d3d12/d3d12-fence.h
index 9a109ae65..3e735ef78 100644
--- a/tools/gfx/d3d12/d3d12-fence.h
+++ b/tools/gfx/d3d12/d3d12-fence.h
@@ -30,7 +30,7 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeHandle(InteropHandle* outNativeHandle) override;
+ getNativeHandle(InteropHandle* outNativeHandle) override;
};
} // namespace d3d12
diff --git a/tools/gfx/d3d12/d3d12-helper-functions.cpp b/tools/gfx/d3d12/d3d12-helper-functions.cpp
index 077645b95..3ce9b872e 100644
--- a/tools/gfx/d3d12/d3d12-helper-functions.cpp
+++ b/tools/gfx/d3d12/d3d12-helper-functions.cpp
@@ -2,18 +2,18 @@
#include "d3d12-helper-functions.h"
#ifdef GFX_NVAPI
-# include "../nvapi/nvapi-include.h"
+#include "../nvapi/nvapi-include.h"
#endif
#include "../nvapi/nvapi-util.h"
#include "d3d12-buffer.h"
-#include "d3d12-transient-heap.h"
#include "d3d12-query.h"
+#include "d3d12-transient-heap.h"
#ifdef _DEBUG
-# define ENABLE_DEBUG_LAYER 1
+#define ENABLE_DEBUG_LAYER 1
#else
-# define ENABLE_DEBUG_LAYER 0
+#define ENABLE_DEBUG_LAYER 0
#endif
namespace gfx
@@ -42,16 +42,12 @@ D3D12_RESOURCE_FLAGS calcResourceFlag(ResourceState state)
{
switch (state)
{
- case ResourceState::RenderTarget:
- return D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
+ case ResourceState::RenderTarget: return D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
case ResourceState::DepthRead:
- case ResourceState::DepthWrite:
- return D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
+ case ResourceState::DepthWrite: return D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
case ResourceState::UnorderedAccess:
- case ResourceState::AccelerationStructure:
- return D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
- default:
- return D3D12_RESOURCE_FLAG_NONE;
+ case ResourceState::AccelerationStructure: return D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
+ default: return D3D12_RESOURCE_FLAG_NONE;
}
}
@@ -71,19 +67,15 @@ D3D12_RESOURCE_DIMENSION calcResourceDimension(IResource::Type type)
{
switch (type)
{
- case IResource::Type::Buffer:
- return D3D12_RESOURCE_DIMENSION_BUFFER;
- case IResource::Type::Texture1D:
- return D3D12_RESOURCE_DIMENSION_TEXTURE1D;
+ case IResource::Type::Buffer: return D3D12_RESOURCE_DIMENSION_BUFFER;
+ case IResource::Type::Texture1D: return D3D12_RESOURCE_DIMENSION_TEXTURE1D;
case IResource::Type::TextureCube:
case IResource::Type::Texture2D:
- {
- return D3D12_RESOURCE_DIMENSION_TEXTURE2D;
- }
- case IResource::Type::Texture3D:
- return D3D12_RESOURCE_DIMENSION_TEXTURE3D;
- default:
- return D3D12_RESOURCE_DIMENSION_UNKNOWN;
+ {
+ return D3D12_RESOURCE_DIMENSION_TEXTURE2D;
+ }
+ case IResource::Type::Texture3D: return D3D12_RESOURCE_DIMENSION_TEXTURE3D;
+ default: return D3D12_RESOURCE_DIMENSION_UNKNOWN;
}
}
@@ -91,16 +83,12 @@ DXGI_FORMAT getTypelessFormatFromDepthFormat(Format format)
{
switch (format)
{
- case Format::D16_UNORM:
- return DXGI_FORMAT_R16_TYPELESS;
- case Format::D32_FLOAT:
- return DXGI_FORMAT_R32_TYPELESS;
- case Format::D32_FLOAT_S8_UINT:
- return DXGI_FORMAT_R32G8X24_TYPELESS;
- //case Format::D24_UNORM_S8_UINT:
- // return DXGI_FORMAT_R24G8_TYPELESS;
- default:
- return D3DUtil::getMapFormat(format);
+ case Format::D16_UNORM: return DXGI_FORMAT_R16_TYPELESS;
+ case Format::D32_FLOAT: return DXGI_FORMAT_R32_TYPELESS;
+ case Format::D32_FLOAT_S8_UINT: return DXGI_FORMAT_R32G8X24_TYPELESS;
+ // case Format::D24_UNORM_S8_UINT:
+ // return DXGI_FORMAT_R24G8_TYPELESS;
+ default: return D3DUtil::getMapFormat(format);
}
}
@@ -111,10 +99,8 @@ bool isTypelessDepthFormat(DXGI_FORMAT format)
case DXGI_FORMAT_R16_TYPELESS:
case DXGI_FORMAT_R32_TYPELESS:
case DXGI_FORMAT_R32G8X24_TYPELESS:
- case DXGI_FORMAT_R24G8_TYPELESS:
- return true;
- default:
- return false;
+ case DXGI_FORMAT_R24G8_TYPELESS: return true;
+ default: return false;
}
}
@@ -122,12 +108,10 @@ D3D12_FILTER_TYPE translateFilterMode(TextureFilteringMode mode)
{
switch (mode)
{
- default:
- return D3D12_FILTER_TYPE(0);
+ default: return D3D12_FILTER_TYPE(0);
-#define CASE(SRC, DST) \
- case TextureFilteringMode::SRC: \
- return D3D12_FILTER_TYPE_##DST
+#define CASE(SRC, DST) \
+ case TextureFilteringMode::SRC: return D3D12_FILTER_TYPE_##DST
CASE(Point, POINT);
CASE(Linear, LINEAR);
@@ -140,12 +124,10 @@ D3D12_FILTER_REDUCTION_TYPE translateFilterReduction(TextureReductionOp op)
{
switch (op)
{
- default:
- return D3D12_FILTER_REDUCTION_TYPE(0);
+ default: return D3D12_FILTER_REDUCTION_TYPE(0);
-#define CASE(SRC, DST) \
- case TextureReductionOp::SRC: \
- return D3D12_FILTER_REDUCTION_TYPE_##DST
+#define CASE(SRC, DST) \
+ case TextureReductionOp::SRC: return D3D12_FILTER_REDUCTION_TYPE_##DST
CASE(Average, STANDARD);
CASE(Comparison, COMPARISON);
@@ -160,12 +142,10 @@ D3D12_TEXTURE_ADDRESS_MODE translateAddressingMode(TextureAddressingMode mode)
{
switch (mode)
{
- default:
- return D3D12_TEXTURE_ADDRESS_MODE(0);
+ default: return D3D12_TEXTURE_ADDRESS_MODE(0);
-#define CASE(SRC, DST) \
- case TextureAddressingMode::SRC: \
- return D3D12_TEXTURE_ADDRESS_MODE_##DST
+#define CASE(SRC, DST) \
+ case TextureAddressingMode::SRC: return D3D12_TEXTURE_ADDRESS_MODE_##DST
CASE(Wrap, WRAP);
CASE(ClampToEdge, CLAMP);
@@ -185,9 +165,8 @@ D3D12_COMPARISON_FUNC translateComparisonFunc(ComparisonFunc func)
// TODO: need to report failures
return D3D12_COMPARISON_FUNC_ALWAYS;
-#define CASE(FROM, TO) \
- case ComparisonFunc::FROM: \
- return D3D12_COMPARISON_FUNC_##TO
+#define CASE(FROM, TO) \
+ case ComparisonFunc::FROM: return D3D12_COMPARISON_FUNC_##TO
CASE(Never, NEVER);
CASE(Less, LESS);
@@ -224,8 +203,8 @@ void initSrvDesc(
descOut = D3D12_SHADER_RESOURCE_VIEW_DESC();
descOut.Format = (pixelFormat == DXGI_FORMAT_UNKNOWN)
- ? D3DUtil::calcFormat(D3DUtil::USAGE_SRV, desc.Format)
- : pixelFormat;
+ ? D3DUtil::calcFormat(D3DUtil::USAGE_SRV, desc.Format)
+ : pixelFormat;
descOut.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
if (desc.DepthOrArraySize == 1)
{
@@ -234,29 +213,30 @@ void initSrvDesc(
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
descOut.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D;
descOut.Texture1D.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels - subresourceRange.mipLevel
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels - subresourceRange.mipLevel
+ : subresourceRange.mipLevelCount;
descOut.Texture1D.MostDetailedMip = subresourceRange.mipLevel;
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
- descOut.ViewDimension = textureDesc.sampleDesc.numSamples > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMS : D3D12_SRV_DIMENSION_TEXTURE2D;
+ descOut.ViewDimension = textureDesc.sampleDesc.numSamples > 1
+ ? D3D12_SRV_DIMENSION_TEXTURE2DMS
+ : D3D12_SRV_DIMENSION_TEXTURE2D;
descOut.Texture2D.PlaneSlice =
D3DUtil::getPlaneSlice(descOut.Format, subresourceRange.aspectMask);
descOut.Texture2D.ResourceMinLODClamp = 0.0f;
descOut.Texture2D.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels - subresourceRange.mipLevel
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels - subresourceRange.mipLevel
+ : subresourceRange.mipLevelCount;
descOut.Texture2D.MostDetailedMip = subresourceRange.mipLevel;
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE3D:
descOut.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D;
descOut.Texture3D.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels - subresourceRange.mipLevel
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels - subresourceRange.mipLevel
+ : subresourceRange.mipLevelCount;
descOut.Texture3D.MostDetailedMip = subresourceRange.mipLevel;
break;
- default:
- assert(!"Unknown dimension");
+ default: assert(!"Unknown dimension");
}
}
else if (resourceType == IResource::Type::TextureCube)
@@ -266,12 +246,12 @@ void initSrvDesc(
descOut.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY;
descOut.TextureCubeArray.NumCubes = subresourceRange.layerCount == 0
- ? textureDesc.arraySize
- : subresourceRange.layerCount / 6;
+ ? textureDesc.arraySize
+ : subresourceRange.layerCount / 6;
descOut.TextureCubeArray.First2DArrayFace = subresourceRange.baseArrayLayer;
descOut.TextureCubeArray.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels - subresourceRange.mipLevel
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels - subresourceRange.mipLevel
+ : subresourceRange.mipLevelCount;
descOut.TextureCubeArray.MostDetailedMip = subresourceRange.mipLevel;
descOut.TextureCubeArray.ResourceMinLODClamp = 0;
}
@@ -280,8 +260,8 @@ void initSrvDesc(
descOut.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE;
descOut.TextureCube.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels - subresourceRange.mipLevel
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels - subresourceRange.mipLevel
+ : subresourceRange.mipLevelCount;
descOut.TextureCube.MostDetailedMip = subresourceRange.mipLevel;
descOut.TextureCube.ResourceMinLODClamp = 0;
}
@@ -296,60 +276,62 @@ void initSrvDesc(
descOut.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1DARRAY;
descOut.Texture1D.MostDetailedMip = subresourceRange.mipLevel;
descOut.Texture1D.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels
+ : subresourceRange.mipLevelCount;
descOut.Texture1DArray.ArraySize = subresourceRange.layerCount == 0
- ? desc.DepthOrArraySize
- : subresourceRange.layerCount;
+ ? desc.DepthOrArraySize
+ : subresourceRange.layerCount;
descOut.Texture1DArray.FirstArraySlice = subresourceRange.baseArrayLayer;
descOut.Texture1DArray.ResourceMinLODClamp = 0;
descOut.Texture1DArray.MostDetailedMip = subresourceRange.mipLevel;
descOut.Texture1DArray.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels - subresourceRange.mipLevel
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels - subresourceRange.mipLevel
+ : subresourceRange.mipLevelCount;
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
- descOut.ViewDimension = textureDesc.sampleDesc.numSamples > 1 ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY : D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
- if(descOut.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DARRAY)
+ descOut.ViewDimension = textureDesc.sampleDesc.numSamples > 1
+ ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY
+ : D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
+ if (descOut.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DARRAY)
{
descOut.Texture2DArray.ArraySize = subresourceRange.layerCount == 0
- ? desc.DepthOrArraySize
- : subresourceRange.layerCount;
+ ? desc.DepthOrArraySize
+ : subresourceRange.layerCount;
descOut.Texture2DArray.FirstArraySlice = subresourceRange.baseArrayLayer;
descOut.Texture2DArray.PlaneSlice =
D3DUtil::getPlaneSlice(descOut.Format, subresourceRange.aspectMask);
descOut.Texture2DArray.ResourceMinLODClamp = 0;
descOut.Texture2DArray.MostDetailedMip = subresourceRange.mipLevel;
descOut.Texture2DArray.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels - subresourceRange.mipLevel
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels - subresourceRange.mipLevel
+ : subresourceRange.mipLevelCount;
}
else
{
assert(descOut.ViewDimension == D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY);
descOut.Texture2DMSArray.FirstArraySlice = subresourceRange.baseArrayLayer;
descOut.Texture2DMSArray.ArraySize = subresourceRange.layerCount == 0
- ? desc.DepthOrArraySize
- : subresourceRange.layerCount;
+ ? desc.DepthOrArraySize
+ : subresourceRange.layerCount;
}
-
+
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE3D:
descOut.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D;
descOut.Texture3D.MostDetailedMip = subresourceRange.mipLevel;
descOut.Texture3D.MipLevels = subresourceRange.mipLevelCount == 0
- ? desc.MipLevels
- : subresourceRange.mipLevelCount;
+ ? desc.MipLevels
+ : subresourceRange.mipLevelCount;
break;
- default:
- assert(!"Unknown dimension");
+ default: assert(!"Unknown dimension");
}
}
}
Result initTextureResourceDesc(
- D3D12_RESOURCE_DESC& resourceDesc, const ITextureResource::Desc& srcDesc)
+ D3D12_RESOURCE_DESC& resourceDesc,
+ const ITextureResource::Desc& srcDesc)
{
const DXGI_FORMAT pixelFormat = D3DUtil::getMapFormat(srcDesc.format);
if (pixelFormat == DXGI_FORMAT_UNKNOWN)
@@ -385,7 +367,7 @@ Result initTextureResourceDesc(
if (isDepthFormat(srcDesc.format) &&
(srcDesc.allowedStates.contains(ResourceState::ShaderResource) ||
- srcDesc.allowedStates.contains(ResourceState::UnorderedAccess)))
+ srcDesc.allowedStates.contains(ResourceState::UnorderedAccess)))
{
resourceDesc.Format = getTypelessFormatFromDepthFormat(srcDesc.format);
}
@@ -424,7 +406,10 @@ Result uploadBufferDataImpl(
if (buffer->getDesc()->memoryType != MemoryType::Upload)
{
SLANG_RETURN_ON_FAIL(transientHeap->allocateStagingBuffer(
- size, uploadResource, uploadResourceOffset, MemoryType::Upload));
+ size,
+ uploadResource,
+ uploadResourceOffset,
+ MemoryType::Upload));
}
else
{
@@ -432,8 +417,8 @@ Result uploadBufferDataImpl(
}
D3D12Resource& uploadResourceRef =
(buffer->getDesc()->memoryType == MemoryType::Upload)
- ? buffer->m_resource
- : static_cast<BufferResourceImpl*>(uploadResource)->m_resource;
+ ? buffer->m_resource
+ : static_cast<BufferResourceImpl*>(uploadResource)->m_resource;
D3D12_RANGE readRange = {};
readRange.Begin = 0;
@@ -468,122 +453,105 @@ Result createNullDescriptor(
switch (bindingRange.bindingType)
{
case slang::BindingType::ConstantBuffer:
- {
- D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {};
- cbvDesc.BufferLocation = 0;
- cbvDesc.SizeInBytes = 0;
- d3dDevice->CreateConstantBufferView(&cbvDesc, destDescriptor);
- }
- break;
+ {
+ D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {};
+ cbvDesc.BufferLocation = 0;
+ cbvDesc.SizeInBytes = 0;
+ d3dDevice->CreateConstantBufferView(&cbvDesc, destDescriptor);
+ }
+ break;
case slang::BindingType::MutableRawBuffer:
- {
- D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
- uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
- uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
- d3dDevice->CreateUnorderedAccessView(nullptr, nullptr, &uavDesc, destDescriptor);
- }
- break;
+ {
+ D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
+ uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
+ uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
+ uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
+ d3dDevice->CreateUnorderedAccessView(nullptr, nullptr, &uavDesc, destDescriptor);
+ }
+ break;
case slang::BindingType::MutableTypedBuffer:
- {
- D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
- uavDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- d3dDevice->CreateUnorderedAccessView(nullptr, nullptr, &uavDesc, destDescriptor);
- }
- break;
+ {
+ D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
+ uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
+ uavDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ d3dDevice->CreateUnorderedAccessView(nullptr, nullptr, &uavDesc, destDescriptor);
+ }
+ break;
case slang::BindingType::RawBuffer:
- {
- D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
- srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
- srvDesc.Format = DXGI_FORMAT_R32_TYPELESS;
- srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- d3dDevice->CreateShaderResourceView(nullptr, &srvDesc, destDescriptor);
- }
- break;
+ {
+ D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
+ srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
+ srvDesc.Format = DXGI_FORMAT_R32_TYPELESS;
+ srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ d3dDevice->CreateShaderResourceView(nullptr, &srvDesc, destDescriptor);
+ }
+ break;
case slang::BindingType::TypedBuffer:
- {
- D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
- srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- d3dDevice->CreateShaderResourceView(nullptr, &srvDesc, destDescriptor);
- }
- break;
+ {
+ D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
+ srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ d3dDevice->CreateShaderResourceView(nullptr, &srvDesc, destDescriptor);
+ }
+ break;
case slang::BindingType::Texture:
- {
- D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
- srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- switch (bindingRange.resourceShape)
{
- case SLANG_TEXTURE_1D:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D;
- break;
- case SLANG_TEXTURE_1D_ARRAY:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1DARRAY;
- break;
- case SLANG_TEXTURE_2D:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- break;
- case SLANG_TEXTURE_2D_ARRAY:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
- break;
- case SLANG_TEXTURE_3D:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D;
- break;
- case SLANG_TEXTURE_CUBE:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE;
- break;
- case SLANG_TEXTURE_CUBE_ARRAY:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY;
- break;
- case SLANG_TEXTURE_2D_MULTISAMPLE:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMS;
- break;
- case SLANG_TEXTURE_2D_MULTISAMPLE_ARRAY:
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY;
- break;
- default:
- return SLANG_OK;
+ D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
+ srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ switch (bindingRange.resourceShape)
+ {
+ case SLANG_TEXTURE_1D: srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D; break;
+ case SLANG_TEXTURE_1D_ARRAY:
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1DARRAY;
+ break;
+ case SLANG_TEXTURE_2D: srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; break;
+ case SLANG_TEXTURE_2D_ARRAY:
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY;
+ break;
+ case SLANG_TEXTURE_3D: srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; break;
+ case SLANG_TEXTURE_CUBE: srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; break;
+ case SLANG_TEXTURE_CUBE_ARRAY:
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY;
+ break;
+ case SLANG_TEXTURE_2D_MULTISAMPLE:
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMS;
+ break;
+ case SLANG_TEXTURE_2D_MULTISAMPLE_ARRAY:
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY;
+ break;
+ default: return SLANG_OK;
+ }
+ d3dDevice->CreateShaderResourceView(nullptr, &srvDesc, destDescriptor);
}
- d3dDevice->CreateShaderResourceView(nullptr, &srvDesc, destDescriptor);
- }
- break;
+ break;
case slang::BindingType::MutableTexture:
- {
- D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
- uavDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- switch (bindingRange.resourceShape)
{
- case SLANG_TEXTURE_1D:
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1D;
- break;
- case SLANG_TEXTURE_1D_ARRAY:
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1DARRAY;
- break;
- case SLANG_TEXTURE_2D:
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
- break;
- case SLANG_TEXTURE_2D_ARRAY:
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY;
- break;
- case SLANG_TEXTURE_3D:
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D;
- break;
- case SLANG_TEXTURE_CUBE:
- case SLANG_TEXTURE_CUBE_ARRAY:
- case SLANG_TEXTURE_2D_MULTISAMPLE:
- case SLANG_TEXTURE_2D_MULTISAMPLE_ARRAY:
- default:
- return SLANG_OK;
+ D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
+ uavDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ switch (bindingRange.resourceShape)
+ {
+ case SLANG_TEXTURE_1D: uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1D; break;
+ case SLANG_TEXTURE_1D_ARRAY:
+ uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1DARRAY;
+ break;
+ case SLANG_TEXTURE_2D: uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D; break;
+ case SLANG_TEXTURE_2D_ARRAY:
+ uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY;
+ break;
+ case SLANG_TEXTURE_3D: uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; break;
+ case SLANG_TEXTURE_CUBE:
+ case SLANG_TEXTURE_CUBE_ARRAY:
+ case SLANG_TEXTURE_2D_MULTISAMPLE:
+ case SLANG_TEXTURE_2D_MULTISAMPLE_ARRAY:
+ default: return SLANG_OK;
+ }
+ d3dDevice->CreateUnorderedAccessView(nullptr, nullptr, &uavDesc, destDescriptor);
}
- d3dDevice->CreateUnorderedAccessView(nullptr, nullptr, &uavDesc, destDescriptor);
- }
- break;
- default:
break;
+ default: break;
}
return SLANG_OK;
}
@@ -603,27 +571,27 @@ void translatePostBuildInfoDescs(
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_COMPACTED_SIZE;
postBuildInfoDescs[i].DestBuffer =
static_cast<PlainBufferProxyQueryPoolImpl*>(queryDescs[i].queryPool)
- ->m_bufferResource->getDeviceAddress() +
+ ->m_bufferResource->getDeviceAddress() +
sizeof(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_COMPACTED_SIZE_DESC) *
- queryDescs[i].firstQueryIndex;
+ queryDescs[i].firstQueryIndex;
break;
case QueryType::AccelerationStructureCurrentSize:
postBuildInfoDescs[i].InfoType =
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_CURRENT_SIZE;
postBuildInfoDescs[i].DestBuffer =
static_cast<PlainBufferProxyQueryPoolImpl*>(queryDescs[i].queryPool)
- ->m_bufferResource->getDeviceAddress() +
+ ->m_bufferResource->getDeviceAddress() +
sizeof(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_COMPACTED_SIZE_DESC) *
- queryDescs[i].firstQueryIndex;
+ queryDescs[i].firstQueryIndex;
break;
case QueryType::AccelerationStructureSerializedSize:
postBuildInfoDescs[i].InfoType =
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_SERIALIZATION;
postBuildInfoDescs[i].DestBuffer =
static_cast<PlainBufferProxyQueryPoolImpl*>(queryDescs[i].queryPool)
- ->m_bufferResource->getDeviceAddress() +
+ ->m_bufferResource->getDeviceAddress() +
sizeof(D3D12_RAYTRACING_ACCELERATION_STRUCTURE_POSTBUILD_INFO_SERIALIZATION_DESC) *
- queryDescs[i].firstQueryIndex;
+ queryDescs[i].firstQueryIndex;
break;
}
}
@@ -634,7 +602,8 @@ void translatePostBuildInfoDescs(
Result SLANG_MCALL getD3D12Adapters(List<AdapterInfo>& outAdapters)
{
List<ComPtr<IDXGIAdapter>> dxgiAdapters;
- SLANG_RETURN_ON_FAIL(D3DUtil::findAdapters(DeviceCheckFlag::UseHardwareDevice, nullptr, dxgiAdapters));
+ SLANG_RETURN_ON_FAIL(
+ D3DUtil::findAdapters(DeviceCheckFlag::UseHardwareDevice, nullptr, dxgiAdapters));
outAdapters.clear();
for (const auto& dxgiAdapter : dxgiAdapters)
@@ -643,7 +612,10 @@ Result SLANG_MCALL getD3D12Adapters(List<AdapterInfo>& outAdapters)
dxgiAdapter->GetDesc(&desc);
AdapterInfo info = {};
auto name = String::fromWString(desc.Description);
- memcpy(info.name, name.getBuffer(), Math::Min(name.getLength(), (Index)sizeof(AdapterInfo::name) - 1));
+ memcpy(
+ info.name,
+ name.getBuffer(),
+ Math::Min(name.getLength(), (Index)sizeof(AdapterInfo::name) - 1));
info.vendorID = desc.VendorId;
info.deviceID = desc.DeviceId;
info.luid = D3DUtil::getAdapterLUID(dxgiAdapter);
diff --git a/tools/gfx/d3d12/d3d12-helper-functions.h b/tools/gfx/d3d12/d3d12-helper-functions.h
index 52b587529..e9eeb4c8f 100644
--- a/tools/gfx/d3d12/d3d12-helper-functions.h
+++ b/tools/gfx/d3d12/d3d12-helper-functions.h
@@ -1,17 +1,18 @@
// d3d12-helper-functions.h
#pragma once
-#include "slang-gfx.h"
+#include "../../../source/core/slang-list.h"
+#include "../../../source/core/slang-short-list.h"
#include "d3d12-base.h"
#include "d3d12-shader-object-layout.h"
#include "d3d12-submitter.h"
-#include "../../../source/core/slang-short-list.h"
-#include "../../../source/core/slang-list.h"
+#include "slang-gfx.h"
#ifndef __ID3D12GraphicsCommandList1_FWD_DEFINED__
// If can't find a definition of CommandList1, just use an empty definition
struct ID3D12GraphicsCommandList1
-{};
+{
+};
#endif
namespace gfx
@@ -35,7 +36,7 @@ struct BindingContext
TransientResourceHeapImpl* transientHeap;
DeviceImpl* device;
D3D12_DESCRIPTOR_HEAP_TYPE
- outOfMemoryHeap; // The type of descriptor heap that is OOM during binding.
+ outOfMemoryHeap; // The type of descriptor heap that is OOM during binding.
ShortList<PendingDescriptorTableBinding>* pendingTableBindings;
};
@@ -62,7 +63,8 @@ void initSrvDesc(
SubresourceRange subresourceRange,
D3D12_SHADER_RESOURCE_VIEW_DESC& descOut);
Result initTextureResourceDesc(
- D3D12_RESOURCE_DESC& resourceDesc, const ITextureResource::Desc& srcDesc);
+ D3D12_RESOURCE_DESC& resourceDesc,
+ const ITextureResource::Desc& srcDesc);
void initBufferResourceDesc(Size bufferSize, D3D12_RESOURCE_DESC& out);
Result uploadBufferDataImpl(
ID3D12Device* device,
diff --git a/tools/gfx/d3d12/d3d12-pipeline-state-stream.h b/tools/gfx/d3d12/d3d12-pipeline-state-stream.h
index 9848e96f9..db1f85d28 100644
--- a/tools/gfx/d3d12/d3d12-pipeline-state-stream.h
+++ b/tools/gfx/d3d12/d3d12-pipeline-state-stream.h
@@ -5,22 +5,25 @@
// `d3dx12_pipeline_state_stream.h`. Attribution Microsoft.
//
+#include "d3d12-sal-defs.h"
+
#include <climits>
#include <d3d12.h>
#include <dxgi1_4.h>
-#include "d3d12-sal-defs.h"
-
-struct CD3DX12_DEFAULT {};
+struct CD3DX12_DEFAULT
+{
+};
//------------------------------------------------------------------------------------------------
struct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC
{
CD3DX12_DEPTH_STENCIL_DESC() = default;
- explicit CD3DX12_DEPTH_STENCIL_DESC( const D3D12_DEPTH_STENCIL_DESC& o ) noexcept :
- D3D12_DEPTH_STENCIL_DESC( o )
- {}
- explicit CD3DX12_DEPTH_STENCIL_DESC( CD3DX12_DEFAULT ) noexcept
+ explicit CD3DX12_DEPTH_STENCIL_DESC(const D3D12_DEPTH_STENCIL_DESC& o) noexcept
+ : D3D12_DEPTH_STENCIL_DESC(o)
+ {
+ }
+ explicit CD3DX12_DEPTH_STENCIL_DESC(CD3DX12_DEFAULT) noexcept
{
DepthEnable = TRUE;
DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
@@ -28,8 +31,11 @@ struct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC
StencilEnable = FALSE;
StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
- const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp =
- { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_ALWAYS };
+ const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp = {
+ D3D12_STENCIL_OP_KEEP,
+ D3D12_STENCIL_OP_KEEP,
+ D3D12_STENCIL_OP_KEEP,
+ D3D12_COMPARISON_FUNC_ALWAYS};
FrontFace = defaultStencilOp;
BackFace = defaultStencilOp;
}
@@ -47,7 +53,7 @@ struct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC
D3D12_STENCIL_OP backStencilFailOp,
D3D12_STENCIL_OP backStencilDepthFailOp,
D3D12_STENCIL_OP backStencilPassOp,
- D3D12_COMPARISON_FUNC backStencilFunc ) noexcept
+ D3D12_COMPARISON_FUNC backStencilFunc) noexcept
{
DepthEnable = depthEnable;
DepthWriteMask = depthWriteMask;
@@ -70,28 +76,29 @@ struct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC
struct CD3DX12_DEPTH_STENCIL_DESC1 : public D3D12_DEPTH_STENCIL_DESC1
{
CD3DX12_DEPTH_STENCIL_DESC1() = default;
- explicit CD3DX12_DEPTH_STENCIL_DESC1( const D3D12_DEPTH_STENCIL_DESC1& o ) noexcept :
- D3D12_DEPTH_STENCIL_DESC1( o )
- {}
- explicit CD3DX12_DEPTH_STENCIL_DESC1( const D3D12_DEPTH_STENCIL_DESC& o ) noexcept
+ explicit CD3DX12_DEPTH_STENCIL_DESC1(const D3D12_DEPTH_STENCIL_DESC1& o) noexcept
+ : D3D12_DEPTH_STENCIL_DESC1(o)
+ {
+ }
+ explicit CD3DX12_DEPTH_STENCIL_DESC1(const D3D12_DEPTH_STENCIL_DESC& o) noexcept
{
- DepthEnable = o.DepthEnable;
- DepthWriteMask = o.DepthWriteMask;
- DepthFunc = o.DepthFunc;
- StencilEnable = o.StencilEnable;
- StencilReadMask = o.StencilReadMask;
- StencilWriteMask = o.StencilWriteMask;
- FrontFace.StencilFailOp = o.FrontFace.StencilFailOp;
+ DepthEnable = o.DepthEnable;
+ DepthWriteMask = o.DepthWriteMask;
+ DepthFunc = o.DepthFunc;
+ StencilEnable = o.StencilEnable;
+ StencilReadMask = o.StencilReadMask;
+ StencilWriteMask = o.StencilWriteMask;
+ FrontFace.StencilFailOp = o.FrontFace.StencilFailOp;
FrontFace.StencilDepthFailOp = o.FrontFace.StencilDepthFailOp;
- FrontFace.StencilPassOp = o.FrontFace.StencilPassOp;
- FrontFace.StencilFunc = o.FrontFace.StencilFunc;
- BackFace.StencilFailOp = o.BackFace.StencilFailOp;
- BackFace.StencilDepthFailOp = o.BackFace.StencilDepthFailOp;
- BackFace.StencilPassOp = o.BackFace.StencilPassOp;
- BackFace.StencilFunc = o.BackFace.StencilFunc;
- DepthBoundsTestEnable = FALSE;
+ FrontFace.StencilPassOp = o.FrontFace.StencilPassOp;
+ FrontFace.StencilFunc = o.FrontFace.StencilFunc;
+ BackFace.StencilFailOp = o.BackFace.StencilFailOp;
+ BackFace.StencilDepthFailOp = o.BackFace.StencilDepthFailOp;
+ BackFace.StencilPassOp = o.BackFace.StencilPassOp;
+ BackFace.StencilFunc = o.BackFace.StencilFunc;
+ DepthBoundsTestEnable = FALSE;
}
- explicit CD3DX12_DEPTH_STENCIL_DESC1( CD3DX12_DEFAULT ) noexcept
+ explicit CD3DX12_DEPTH_STENCIL_DESC1(CD3DX12_DEFAULT) noexcept
{
DepthEnable = TRUE;
DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
@@ -99,8 +106,11 @@ struct CD3DX12_DEPTH_STENCIL_DESC1 : public D3D12_DEPTH_STENCIL_DESC1
StencilEnable = FALSE;
StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
- const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp =
- { D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_COMPARISON_FUNC_ALWAYS };
+ const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp = {
+ D3D12_STENCIL_OP_KEEP,
+ D3D12_STENCIL_OP_KEEP,
+ D3D12_STENCIL_OP_KEEP,
+ D3D12_COMPARISON_FUNC_ALWAYS};
FrontFace = defaultStencilOp;
BackFace = defaultStencilOp;
DepthBoundsTestEnable = FALSE;
@@ -120,7 +130,7 @@ struct CD3DX12_DEPTH_STENCIL_DESC1 : public D3D12_DEPTH_STENCIL_DESC1
D3D12_STENCIL_OP backStencilDepthFailOp,
D3D12_STENCIL_OP backStencilPassOp,
D3D12_COMPARISON_FUNC backStencilFunc,
- BOOL depthBoundsTestEnable ) noexcept
+ BOOL depthBoundsTestEnable) noexcept
{
DepthEnable = depthEnable;
DepthWriteMask = depthWriteMask;
@@ -141,20 +151,20 @@ struct CD3DX12_DEPTH_STENCIL_DESC1 : public D3D12_DEPTH_STENCIL_DESC1
operator D3D12_DEPTH_STENCIL_DESC() const noexcept
{
D3D12_DEPTH_STENCIL_DESC D;
- D.DepthEnable = DepthEnable;
- D.DepthWriteMask = DepthWriteMask;
- D.DepthFunc = DepthFunc;
- D.StencilEnable = StencilEnable;
- D.StencilReadMask = StencilReadMask;
- D.StencilWriteMask = StencilWriteMask;
- D.FrontFace.StencilFailOp = FrontFace.StencilFailOp;
+ D.DepthEnable = DepthEnable;
+ D.DepthWriteMask = DepthWriteMask;
+ D.DepthFunc = DepthFunc;
+ D.StencilEnable = StencilEnable;
+ D.StencilReadMask = StencilReadMask;
+ D.StencilWriteMask = StencilWriteMask;
+ D.FrontFace.StencilFailOp = FrontFace.StencilFailOp;
D.FrontFace.StencilDepthFailOp = FrontFace.StencilDepthFailOp;
- D.FrontFace.StencilPassOp = FrontFace.StencilPassOp;
- D.FrontFace.StencilFunc = FrontFace.StencilFunc;
- D.BackFace.StencilFailOp = BackFace.StencilFailOp;
- D.BackFace.StencilDepthFailOp = BackFace.StencilDepthFailOp;
- D.BackFace.StencilPassOp = BackFace.StencilPassOp;
- D.BackFace.StencilFunc = BackFace.StencilFunc;
+ D.FrontFace.StencilPassOp = FrontFace.StencilPassOp;
+ D.FrontFace.StencilFunc = FrontFace.StencilFunc;
+ D.BackFace.StencilFailOp = BackFace.StencilFailOp;
+ D.BackFace.StencilDepthFailOp = BackFace.StencilDepthFailOp;
+ D.BackFace.StencilPassOp = BackFace.StencilPassOp;
+ D.BackFace.StencilFunc = BackFace.StencilFunc;
return D;
}
};
@@ -163,23 +173,28 @@ struct CD3DX12_DEPTH_STENCIL_DESC1 : public D3D12_DEPTH_STENCIL_DESC1
struct CD3DX12_BLEND_DESC : public D3D12_BLEND_DESC
{
CD3DX12_BLEND_DESC() = default;
- explicit CD3DX12_BLEND_DESC( const D3D12_BLEND_DESC& o ) noexcept :
- D3D12_BLEND_DESC( o )
- {}
- explicit CD3DX12_BLEND_DESC( CD3DX12_DEFAULT ) noexcept
+ explicit CD3DX12_BLEND_DESC(const D3D12_BLEND_DESC& o) noexcept
+ : D3D12_BLEND_DESC(o)
+ {
+ }
+ explicit CD3DX12_BLEND_DESC(CD3DX12_DEFAULT) noexcept
{
AlphaToCoverageEnable = FALSE;
IndependentBlendEnable = FALSE;
- const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc =
- {
- FALSE,FALSE,
- D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
- D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
+ const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc = {
+ FALSE,
+ FALSE,
+ D3D12_BLEND_ONE,
+ D3D12_BLEND_ZERO,
+ D3D12_BLEND_OP_ADD,
+ D3D12_BLEND_ONE,
+ D3D12_BLEND_ZERO,
+ D3D12_BLEND_OP_ADD,
D3D12_LOGIC_OP_NOOP,
D3D12_COLOR_WRITE_ENABLE_ALL,
};
for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
- RenderTarget[ i ] = defaultRenderTargetBlendDesc;
+ RenderTarget[i] = defaultRenderTargetBlendDesc;
}
};
@@ -187,10 +202,11 @@ struct CD3DX12_BLEND_DESC : public D3D12_BLEND_DESC
struct CD3DX12_RASTERIZER_DESC : public D3D12_RASTERIZER_DESC
{
CD3DX12_RASTERIZER_DESC() = default;
- explicit CD3DX12_RASTERIZER_DESC( const D3D12_RASTERIZER_DESC& o ) noexcept :
- D3D12_RASTERIZER_DESC( o )
- {}
- explicit CD3DX12_RASTERIZER_DESC( CD3DX12_DEFAULT ) noexcept
+ explicit CD3DX12_RASTERIZER_DESC(const D3D12_RASTERIZER_DESC& o) noexcept
+ : D3D12_RASTERIZER_DESC(o)
+ {
+ }
+ explicit CD3DX12_RASTERIZER_DESC(CD3DX12_DEFAULT) noexcept
{
FillMode = D3D12_FILL_MODE_SOLID;
CullMode = D3D12_CULL_MODE_BACK;
@@ -235,10 +251,11 @@ struct CD3DX12_RASTERIZER_DESC : public D3D12_RASTERIZER_DESC
struct CD3DX12_VIEW_INSTANCING_DESC : public D3D12_VIEW_INSTANCING_DESC
{
CD3DX12_VIEW_INSTANCING_DESC() = default;
- explicit CD3DX12_VIEW_INSTANCING_DESC( const D3D12_VIEW_INSTANCING_DESC& o ) noexcept :
- D3D12_VIEW_INSTANCING_DESC( o )
- {}
- explicit CD3DX12_VIEW_INSTANCING_DESC( CD3DX12_DEFAULT ) noexcept
+ explicit CD3DX12_VIEW_INSTANCING_DESC(const D3D12_VIEW_INSTANCING_DESC& o) noexcept
+ : D3D12_VIEW_INSTANCING_DESC(o)
+ {
+ }
+ explicit CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT) noexcept
{
ViewInstanceCount = 0;
pViewInstanceLocations = nullptr;
@@ -261,8 +278,11 @@ struct CD3DX12_RT_FORMAT_ARRAY : public D3D12_RT_FORMAT_ARRAY
CD3DX12_RT_FORMAT_ARRAY() = default;
explicit CD3DX12_RT_FORMAT_ARRAY(const D3D12_RT_FORMAT_ARRAY& o) noexcept
: D3D12_RT_FORMAT_ARRAY(o)
- {}
- explicit CD3DX12_RT_FORMAT_ARRAY(_In_reads_(NumFormats) const DXGI_FORMAT* pFormats, UINT NumFormats) noexcept
+ {
+ }
+ explicit CD3DX12_RT_FORMAT_ARRAY(
+ _In_reads_(NumFormats) const DXGI_FORMAT* pFormats,
+ UINT NumFormats) noexcept
{
NumRenderTargets = NumFormats;
memcpy(RTFormats, pFormats, sizeof(RTFormats));
@@ -274,103 +294,203 @@ struct CD3DX12_RT_FORMAT_ARRAY : public D3D12_RT_FORMAT_ARRAY
struct CD3DX12_SHADER_BYTECODE : public D3D12_SHADER_BYTECODE
{
CD3DX12_SHADER_BYTECODE() = default;
- explicit CD3DX12_SHADER_BYTECODE(const D3D12_SHADER_BYTECODE &o) noexcept :
- D3D12_SHADER_BYTECODE(o)
- {}
- CD3DX12_SHADER_BYTECODE(
- _In_ ID3DBlob* pShaderBlob ) noexcept
+ explicit CD3DX12_SHADER_BYTECODE(const D3D12_SHADER_BYTECODE& o) noexcept
+ : D3D12_SHADER_BYTECODE(o)
+ {
+ }
+ CD3DX12_SHADER_BYTECODE(_In_ ID3DBlob* pShaderBlob) noexcept
{
pShaderBytecode = pShaderBlob->GetBufferPointer();
BytecodeLength = pShaderBlob->GetBufferSize();
}
- CD3DX12_SHADER_BYTECODE(
- const void* _pShaderBytecode,
- SIZE_T bytecodeLength ) noexcept
+ CD3DX12_SHADER_BYTECODE(const void* _pShaderBytecode, SIZE_T bytecodeLength) noexcept
{
pShaderBytecode = _pShaderBytecode;
BytecodeLength = bytecodeLength;
}
};
-struct DefaultSampleMask { operator UINT() noexcept { return UINT_MAX; } };
-struct DefaultSampleDesc { operator DXGI_SAMPLE_DESC() noexcept { return DXGI_SAMPLE_DESC{1, 0}; } };
+struct DefaultSampleMask
+{
+ operator UINT() noexcept { return UINT_MAX; }
+};
+struct DefaultSampleDesc
+{
+ operator DXGI_SAMPLE_DESC() noexcept { return DXGI_SAMPLE_DESC{1, 0}; }
+};
#ifdef _MSC_VER
-# pragma warning(push)
-# pragma warning(disable : 4324)
+#pragma warning(push)
+#pragma warning(disable : 4324)
#endif
-template <typename InnerStructType, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type, typename DefaultArg = InnerStructType>
+template<
+ typename InnerStructType,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type,
+ typename DefaultArg = InnerStructType>
class alignas(void*) CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT
{
private:
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE pssType;
InnerStructType pssInner;
+
public:
- CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT() noexcept : pssType(Type), pssInner(DefaultArg()) {}
- CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT(InnerStructType const& i) noexcept : pssType(Type), pssInner(i) {}
- CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT& operator=(InnerStructType const& i) noexcept { pssType = Type; pssInner = i; return *this; }
+ CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT() noexcept
+ : pssType(Type), pssInner(DefaultArg())
+ {
+ }
+ CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT(InnerStructType const& i) noexcept
+ : pssType(Type), pssInner(i)
+ {
+ }
+ CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT& operator=(InnerStructType const& i) noexcept
+ {
+ pssType = Type;
+ pssInner = i;
+ return *this;
+ }
operator InnerStructType const&() const noexcept { return pssInner; }
operator InnerStructType&() noexcept { return pssInner; }
InnerStructType* operator&() noexcept { return &pssInner; }
InnerStructType const* operator&() const noexcept { return &pssInner; }
};
#ifdef _MSC_VER
-# pragma warning(pop)
+#pragma warning(pop)
#endif
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_PIPELINE_STATE_FLAGS, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS> CD3DX12_PIPELINE_STATE_STREAM_FLAGS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< UINT, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK> CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< ID3D12RootSignature*, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE> CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_INPUT_LAYOUT_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT> CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_INDEX_BUFFER_STRIP_CUT_VALUE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE> CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_PRIMITIVE_TOPOLOGY_TYPE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY> CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS> CD3DX12_PIPELINE_STATE_STREAM_VS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS> CD3DX12_PIPELINE_STATE_STREAM_GS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_STREAM_OUTPUT_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT> CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS> CD3DX12_PIPELINE_STATE_STREAM_HS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS> CD3DX12_PIPELINE_STATE_STREAM_DS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS> CD3DX12_PIPELINE_STATE_STREAM_PS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS> CD3DX12_PIPELINE_STATE_STREAM_AS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS> CD3DX12_PIPELINE_STATE_STREAM_MS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS> CD3DX12_PIPELINE_STATE_STREAM_CS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< CD3DX12_BLEND_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND, CD3DX12_DEFAULT> CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< CD3DX12_DEPTH_STENCIL_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, CD3DX12_DEFAULT> CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< CD3DX12_DEPTH_STENCIL_DESC1, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1, CD3DX12_DEFAULT> CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< DXGI_FORMAT, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT> CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< CD3DX12_RASTERIZER_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER, CD3DX12_DEFAULT> CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_RT_FORMAT_ARRAY, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS> CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< DXGI_SAMPLE_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC, DefaultSampleDesc> CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< UINT, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK, DefaultSampleMask> CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< D3D12_CACHED_PIPELINE_STATE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO> CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO;
-typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT< CD3DX12_VIEW_INSTANCING_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING, CD3DX12_DEFAULT> CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_PIPELINE_STATE_FLAGS,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS>
+ CD3DX12_PIPELINE_STATE_STREAM_FLAGS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<UINT, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK>
+ CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ ID3D12RootSignature*,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE>
+ CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_INPUT_LAYOUT_DESC,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT>
+ CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_INDEX_BUFFER_STRIP_CUT_VALUE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE>
+ CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_PRIMITIVE_TOPOLOGY_TYPE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY>
+ CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_SHADER_BYTECODE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS>
+ CD3DX12_PIPELINE_STATE_STREAM_VS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_SHADER_BYTECODE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS>
+ CD3DX12_PIPELINE_STATE_STREAM_GS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_STREAM_OUTPUT_DESC,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT>
+ CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_SHADER_BYTECODE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS>
+ CD3DX12_PIPELINE_STATE_STREAM_HS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_SHADER_BYTECODE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS>
+ CD3DX12_PIPELINE_STATE_STREAM_DS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_SHADER_BYTECODE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS>
+ CD3DX12_PIPELINE_STATE_STREAM_PS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_SHADER_BYTECODE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS>
+ CD3DX12_PIPELINE_STATE_STREAM_AS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_SHADER_BYTECODE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MS>
+ CD3DX12_PIPELINE_STATE_STREAM_MS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_SHADER_BYTECODE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS>
+ CD3DX12_PIPELINE_STATE_STREAM_CS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ CD3DX12_BLEND_DESC,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND,
+ CD3DX12_DEFAULT>
+ CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ CD3DX12_DEPTH_STENCIL_DESC,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL,
+ CD3DX12_DEFAULT>
+ CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ CD3DX12_DEPTH_STENCIL_DESC1,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1,
+ CD3DX12_DEFAULT>
+ CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ DXGI_FORMAT,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT>
+ CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ CD3DX12_RASTERIZER_DESC,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER,
+ CD3DX12_DEFAULT>
+ CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_RT_FORMAT_ARRAY,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS>
+ CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ DXGI_SAMPLE_DESC,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC,
+ DefaultSampleDesc>
+ CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ UINT,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK,
+ DefaultSampleMask>
+ CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ D3D12_CACHED_PIPELINE_STATE,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO>
+ CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO;
+typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
+ CD3DX12_VIEW_INSTANCING_DESC,
+ D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING,
+ CD3DX12_DEFAULT>
+ CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING;
struct D3DX12_MESH_SHADER_PIPELINE_STATE_DESC
{
- ID3D12RootSignature* pRootSignature;
- D3D12_SHADER_BYTECODE AS;
- D3D12_SHADER_BYTECODE MS;
- D3D12_SHADER_BYTECODE PS;
- D3D12_BLEND_DESC BlendState;
- UINT SampleMask;
- D3D12_RASTERIZER_DESC RasterizerState;
- D3D12_DEPTH_STENCIL_DESC DepthStencilState;
+ ID3D12RootSignature* pRootSignature;
+ D3D12_SHADER_BYTECODE AS;
+ D3D12_SHADER_BYTECODE MS;
+ D3D12_SHADER_BYTECODE PS;
+ D3D12_BLEND_DESC BlendState;
+ UINT SampleMask;
+ D3D12_RASTERIZER_DESC RasterizerState;
+ D3D12_DEPTH_STENCIL_DESC DepthStencilState;
D3D12_PRIMITIVE_TOPOLOGY_TYPE PrimitiveTopologyType;
- UINT NumRenderTargets;
- DXGI_FORMAT RTVFormats[ D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT ];
- DXGI_FORMAT DSVFormat;
- DXGI_SAMPLE_DESC SampleDesc;
- UINT NodeMask;
- D3D12_CACHED_PIPELINE_STATE CachedPSO;
- D3D12_PIPELINE_STATE_FLAGS Flags;
+ UINT NumRenderTargets;
+ DXGI_FORMAT RTVFormats[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT];
+ DXGI_FORMAT DSVFormat;
+ DXGI_SAMPLE_DESC SampleDesc;
+ UINT NodeMask;
+ D3D12_CACHED_PIPELINE_STATE CachedPSO;
+ D3D12_PIPELINE_STATE_FLAGS Flags;
};
-// CD3DX12_PIPELINE_STATE_STREAM2 Works on OS Build 19041+ (where there is a new mesh shader pipeline).
-// Use CD3DX12_PIPELINE_STATE_STREAM1 for OS Build 16299+ (where there is a new view instancing subobject).
-// Use CD3DX12_PIPELINE_STATE_STREAM for OS Build 15063+ support.
+// CD3DX12_PIPELINE_STATE_STREAM2 Works on OS Build 19041+ (where there is a new mesh shader
+// pipeline). Use CD3DX12_PIPELINE_STATE_STREAM1 for OS Build 16299+ (where there is a new view
+// instancing subobject). Use CD3DX12_PIPELINE_STATE_STREAM for OS Build 15063+ support.
struct CD3DX12_PIPELINE_STATE_STREAM2
{
CD3DX12_PIPELINE_STATE_STREAM2() = default;
- // Mesh and amplification shaders must be set manually, since they do not have representation in D3D12_GRAPHICS_PIPELINE_STATE_DESC
+ // Mesh and amplification shaders must be set manually, since they do not have representation in
+ // D3D12_GRAPHICS_PIPELINE_STATE_DESC
CD3DX12_PIPELINE_STATE_STREAM2(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& Desc) noexcept
: Flags(Desc.Flags)
, NodeMask(Desc.NodeMask)
@@ -393,7 +513,8 @@ struct CD3DX12_PIPELINE_STATE_STREAM2
, SampleMask(Desc.SampleMask)
, CachedPSO(Desc.CachedPSO)
, ViewInstancingDesc(CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT()))
- {}
+ {
+ }
CD3DX12_PIPELINE_STATE_STREAM2(const D3DX12_MESH_SHADER_PIPELINE_STATE_DESC& Desc) noexcept
: Flags(Desc.Flags)
, NodeMask(Desc.NodeMask)
@@ -411,7 +532,8 @@ struct CD3DX12_PIPELINE_STATE_STREAM2
, SampleMask(Desc.SampleMask)
, CachedPSO(Desc.CachedPSO)
, ViewInstancingDesc(CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT()))
- {}
+ {
+ }
CD3DX12_PIPELINE_STATE_STREAM2(const D3D12_COMPUTE_PIPELINE_STATE_DESC& Desc) noexcept
: Flags(Desc.Flags)
, NodeMask(Desc.NodeMask)
@@ -448,37 +570,41 @@ struct CD3DX12_PIPELINE_STATE_STREAM2
D3D12_GRAPHICS_PIPELINE_STATE_DESC GraphicsDescV0() const noexcept
{
D3D12_GRAPHICS_PIPELINE_STATE_DESC D;
- D.Flags = this->Flags;
- D.NodeMask = this->NodeMask;
- D.pRootSignature = this->pRootSignature;
- D.InputLayout = this->InputLayout;
- D.IBStripCutValue = this->IBStripCutValue;
+ D.Flags = this->Flags;
+ D.NodeMask = this->NodeMask;
+ D.pRootSignature = this->pRootSignature;
+ D.InputLayout = this->InputLayout;
+ D.IBStripCutValue = this->IBStripCutValue;
D.PrimitiveTopologyType = this->PrimitiveTopologyType;
- D.VS = this->VS;
- D.GS = this->GS;
- D.StreamOutput = this->StreamOutput;
- D.HS = this->HS;
- D.DS = this->DS;
- D.PS = this->PS;
- D.BlendState = this->BlendState;
- D.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC1(D3D12_DEPTH_STENCIL_DESC1(this->DepthStencilState));
- D.DSVFormat = this->DSVFormat;
- D.RasterizerState = this->RasterizerState;
- D.NumRenderTargets = D3D12_RT_FORMAT_ARRAY(this->RTVFormats).NumRenderTargets;
- memcpy(D.RTVFormats, D3D12_RT_FORMAT_ARRAY(this->RTVFormats).RTFormats, sizeof(D.RTVFormats));
- D.SampleDesc = this->SampleDesc;
- D.SampleMask = this->SampleMask;
- D.CachedPSO = this->CachedPSO;
+ D.VS = this->VS;
+ D.GS = this->GS;
+ D.StreamOutput = this->StreamOutput;
+ D.HS = this->HS;
+ D.DS = this->DS;
+ D.PS = this->PS;
+ D.BlendState = this->BlendState;
+ D.DepthStencilState =
+ CD3DX12_DEPTH_STENCIL_DESC1(D3D12_DEPTH_STENCIL_DESC1(this->DepthStencilState));
+ D.DSVFormat = this->DSVFormat;
+ D.RasterizerState = this->RasterizerState;
+ D.NumRenderTargets = D3D12_RT_FORMAT_ARRAY(this->RTVFormats).NumRenderTargets;
+ memcpy(
+ D.RTVFormats,
+ D3D12_RT_FORMAT_ARRAY(this->RTVFormats).RTFormats,
+ sizeof(D.RTVFormats));
+ D.SampleDesc = this->SampleDesc;
+ D.SampleMask = this->SampleMask;
+ D.CachedPSO = this->CachedPSO;
return D;
}
D3D12_COMPUTE_PIPELINE_STATE_DESC ComputeDescV0() const noexcept
{
D3D12_COMPUTE_PIPELINE_STATE_DESC D;
- D.Flags = this->Flags;
- D.NodeMask = this->NodeMask;
- D.pRootSignature = this->pRootSignature;
- D.CS = this->CS;
- D.CachedPSO = this->CachedPSO;
+ D.Flags = this->Flags;
+ D.NodeMask = this->NodeMask;
+ D.pRootSignature = this->pRootSignature;
+ D.CS = this->CS;
+ D.CachedPSO = this->CachedPSO;
return D;
}
};
diff --git a/tools/gfx/d3d12/d3d12-pipeline-state.cpp b/tools/gfx/d3d12/d3d12-pipeline-state.cpp
index fc54b3884..df830960f 100644
--- a/tools/gfx/d3d12/d3d12-pipeline-state.cpp
+++ b/tools/gfx/d3d12/d3d12-pipeline-state.cpp
@@ -2,15 +2,15 @@
#include "d3d12-pipeline-state.h"
#ifdef GFX_NVAPI
-# include "../nvapi/nvapi-include.h"
+#include "../nvapi/nvapi-include.h"
#endif
#include "../nvapi/nvapi-util.h"
#include "d3d12-device.h"
#include "d3d12-framebuffer.h"
+#include "d3d12-pipeline-state-stream.h"
#include "d3d12-shader-program.h"
#include "d3d12-vertex-layout.h"
-#include "d3d12-pipeline-state-stream.h"
#include <climits>
@@ -61,7 +61,8 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
auto inputLayoutImpl = (InputLayoutImpl*)desc.graphics.inputLayout;
// A helper to fill common fields between graphics and mesh pipeline descs
- const auto fillCommonGraphicsState = [&](auto& psoDesc){
+ const auto fillCommonGraphicsState = [&](auto& psoDesc)
+ {
psoDesc.pRootSignature = programImpl->m_rootObjectLayout->m_rootSignature;
psoDesc.PrimitiveTopologyType = D3DUtil::getPrimitiveType(desc.graphics.primitiveType);
@@ -73,7 +74,8 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
if (framebufferLayout->m_hasDepthStencil)
{
- psoDesc.DSVFormat = D3DUtil::getMapFormat(framebufferLayout->m_depthStencil.format);
+ psoDesc.DSVFormat =
+ D3DUtil::getMapFormat(framebufferLayout->m_depthStencil.format);
psoDesc.SampleDesc.Count = framebufferLayout->m_depthStencil.sampleCount;
}
else
@@ -81,7 +83,8 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
psoDesc.DSVFormat = DXGI_FORMAT_UNKNOWN;
if (framebufferLayout->m_renderTargets.getCount())
{
- psoDesc.SampleDesc.Count = framebufferLayout->m_renderTargets[0].sampleCount;
+ psoDesc.SampleDesc.Count =
+ framebufferLayout->m_renderTargets[0].sampleCount;
}
}
psoDesc.NumRenderTargets = numRenderTargets;
@@ -100,8 +103,9 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
rs.FillMode = D3DUtil::getFillMode(desc.graphics.rasterizer.fillMode);
rs.CullMode = D3DUtil::getCullMode(desc.graphics.rasterizer.cullMode);
rs.FrontCounterClockwise =
- desc.graphics.rasterizer.frontFace == gfx::FrontFaceMode::CounterClockwise ? TRUE
- : FALSE;
+ desc.graphics.rasterizer.frontFace == gfx::FrontFaceMode::CounterClockwise
+ ? TRUE
+ : FALSE;
rs.DepthBias = desc.graphics.rasterizer.depthBias;
rs.DepthBiasClamp = desc.graphics.rasterizer.depthBiasClamp;
rs.SlopeScaledDepthBias = desc.graphics.rasterizer.slopeScaledDepthBias;
@@ -111,21 +115,24 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
desc.graphics.rasterizer.antialiasedLineEnable ? TRUE : FALSE;
rs.ForcedSampleCount = desc.graphics.rasterizer.forcedSampleCount;
rs.ConservativeRaster = desc.graphics.rasterizer.enableConservativeRasterization
- ? D3D12_CONSERVATIVE_RASTERIZATION_MODE_ON
- : D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
+ ? D3D12_CONSERVATIVE_RASTERIZATION_MODE_ON
+ : D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
}
{
D3D12_BLEND_DESC& blend = psoDesc.BlendState;
blend.IndependentBlendEnable = FALSE;
- blend.AlphaToCoverageEnable = desc.graphics.blend.alphaToCoverageEnable ? TRUE : FALSE;
- blend.RenderTarget[0].RenderTargetWriteMask = (uint8_t)RenderTargetWriteMask::EnableAll;
+ blend.AlphaToCoverageEnable =
+ desc.graphics.blend.alphaToCoverageEnable ? TRUE : FALSE;
+ blend.RenderTarget[0].RenderTargetWriteMask =
+ (uint8_t)RenderTargetWriteMask::EnableAll;
for (GfxIndex i = 0; i < desc.graphics.blend.targetCount; i++)
{
auto& d3dDesc = blend.RenderTarget[i];
d3dDesc.BlendEnable = desc.graphics.blend.targets[i].enableBlend ? TRUE : FALSE;
d3dDesc.BlendOp = D3DUtil::getBlendOp(desc.graphics.blend.targets[i].color.op);
- d3dDesc.BlendOpAlpha = D3DUtil::getBlendOp(desc.graphics.blend.targets[i].alpha.op);
+ d3dDesc.BlendOpAlpha =
+ D3DUtil::getBlendOp(desc.graphics.blend.targets[i].alpha.op);
d3dDesc.DestBlend =
D3DUtil::getBlendFactor(desc.graphics.blend.targets[i].color.dstFactor);
d3dDesc.DestBlendAlpha =
@@ -141,17 +148,17 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
for (GfxIndex i = 1; i < desc.graphics.blend.targetCount; i++)
{
if (memcmp(
- &desc.graphics.blend.targets[i],
- &desc.graphics.blend.targets[0],
- sizeof(desc.graphics.blend.targets[0])) != 0)
+ &desc.graphics.blend.targets[i],
+ &desc.graphics.blend.targets[0],
+ sizeof(desc.graphics.blend.targets[0])) != 0)
{
blend.IndependentBlendEnable = TRUE;
break;
}
}
for (uint32_t i = (uint32_t)desc.graphics.blend.targetCount;
- i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT;
- ++i)
+ i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT;
+ ++i)
{
blend.RenderTarget[i] = blend.RenderTarget[0];
}
@@ -162,21 +169,21 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
ds.DepthEnable = desc.graphics.depthStencil.depthTestEnable;
ds.DepthWriteMask = desc.graphics.depthStencil.depthWriteEnable
- ? D3D12_DEPTH_WRITE_MASK_ALL
- : D3D12_DEPTH_WRITE_MASK_ZERO;
+ ? D3D12_DEPTH_WRITE_MASK_ALL
+ : D3D12_DEPTH_WRITE_MASK_ZERO;
ds.DepthFunc = D3DUtil::getComparisonFunc(desc.graphics.depthStencil.depthFunc);
ds.StencilEnable = desc.graphics.depthStencil.stencilEnable;
ds.StencilReadMask = (UINT8)desc.graphics.depthStencil.stencilReadMask;
ds.StencilWriteMask = (UINT8)desc.graphics.depthStencil.stencilWriteMask;
- ds.FrontFace = D3DUtil::translateStencilOpDesc(desc.graphics.depthStencil.frontFace);
+ ds.FrontFace =
+ D3DUtil::translateStencilOpDesc(desc.graphics.depthStencil.frontFace);
ds.BackFace = D3DUtil::translateStencilOpDesc(desc.graphics.depthStencil.backFace);
}
psoDesc.PrimitiveTopologyType = D3DUtil::getPrimitiveType(desc.graphics.primitiveType);
-
};
- if(m_program->isMeshShaderProgram())
+ if (m_program->isMeshShaderProgram())
{
D3DX12_MESH_SHADER_PIPELINE_STATE_DESC meshDesc = {};
for (auto& shaderBin : programImpl->m_shaders)
@@ -184,13 +191,13 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
switch (shaderBin.stage)
{
case SLANG_STAGE_FRAGMENT:
- meshDesc.PS = { shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount()) };
+ meshDesc.PS = {shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount())};
break;
case SLANG_STAGE_AMPLIFICATION:
- meshDesc.AS = { shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount()) };
+ meshDesc.AS = {shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount())};
break;
case SLANG_STAGE_MESH:
- meshDesc.MS = { shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount()) };
+ meshDesc.MS = {shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount())};
break;
default:
getDebugCallback()->handleMessage(
@@ -213,10 +220,13 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
else
{
CD3DX12_PIPELINE_STATE_STREAM2 meshStateStream{meshDesc};
- D3D12_PIPELINE_STATE_STREAM_DESC streamDesc{sizeof(meshStateStream), &meshStateStream};
+ D3D12_PIPELINE_STATE_STREAM_DESC streamDesc{
+ sizeof(meshStateStream),
+ &meshStateStream};
SLANG_RETURN_ON_FAIL(m_device->m_device5->CreatePipelineState(
- &streamDesc, IID_PPV_ARGS(m_pipelineState.writeRef())));
+ &streamDesc,
+ IID_PPV_ARGS(m_pipelineState.writeRef())));
}
}
else
@@ -227,19 +237,29 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
switch (shaderBin.stage)
{
case SLANG_STAGE_VERTEX:
- graphicsDesc.VS = { shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount()) };
+ graphicsDesc.VS = {
+ shaderBin.code.getBuffer(),
+ SIZE_T(shaderBin.code.getCount())};
break;
case SLANG_STAGE_FRAGMENT:
- graphicsDesc.PS = { shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount()) };
+ graphicsDesc.PS = {
+ shaderBin.code.getBuffer(),
+ SIZE_T(shaderBin.code.getCount())};
break;
case SLANG_STAGE_DOMAIN:
- graphicsDesc.DS = { shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount()) };
+ graphicsDesc.DS = {
+ shaderBin.code.getBuffer(),
+ SIZE_T(shaderBin.code.getCount())};
break;
case SLANG_STAGE_HULL:
- graphicsDesc.HS = { shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount()) };
+ graphicsDesc.HS = {
+ shaderBin.code.getBuffer(),
+ SIZE_T(shaderBin.code.getCount())};
break;
case SLANG_STAGE_GEOMETRY:
- graphicsDesc.GS = { shaderBin.code.getBuffer(), SIZE_T(shaderBin.code.getCount()) };
+ graphicsDesc.GS = {
+ shaderBin.code.getBuffer(),
+ SIZE_T(shaderBin.code.getCount())};
break;
default:
getDebugCallback()->handleMessage(
@@ -254,7 +274,7 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
{
graphicsDesc.InputLayout = {
inputLayoutImpl->m_elements.getBuffer(),
- UINT(inputLayoutImpl->m_elements.getCount()) };
+ UINT(inputLayoutImpl->m_elements.getCount())};
}
fillCommonGraphicsState(graphicsDesc);
@@ -271,7 +291,8 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
else
{
SLANG_RETURN_ON_FAIL(m_device->m_device->CreateGraphicsPipelineState(
- &graphicsDesc, IID_PPV_ARGS(m_pipelineState.writeRef())));
+ &graphicsDesc,
+ IID_PPV_ARGS(m_pipelineState.writeRef())));
}
}
}
@@ -286,11 +307,11 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
D3D12_COMPUTE_PIPELINE_STATE_DESC computeDesc = {};
computeDesc.pRootSignature =
desc.compute.d3d12RootSignatureOverride
- ? static_cast<ID3D12RootSignature*>(desc.compute.d3d12RootSignatureOverride)
- : programImpl->m_rootObjectLayout->m_rootSignature;
+ ? static_cast<ID3D12RootSignature*>(desc.compute.d3d12RootSignatureOverride)
+ : programImpl->m_rootObjectLayout->m_rootSignature;
computeDesc.CS = {
programImpl->m_shaders[0].code.getBuffer(),
- SIZE_T(programImpl->m_shaders[0].code.getCount()) };
+ SIZE_T(programImpl->m_shaders[0].code.getCount())};
#ifdef GFX_NVAPI
if (m_device->m_nvapi)
@@ -307,7 +328,7 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
// Put the pointer to the extension into an array - there can be multiple extensions
// enabled at once.
- const NVAPI_D3D12_PSO_EXTENSION_DESC* extensions[] = { &extensionDesc };
+ const NVAPI_D3D12_PSO_EXTENSION_DESC* extensions[] = {&extensionDesc};
// Now create the PSO.
const NvAPI_Status nvapiStatus = NvAPI_D3D12_CreateComputePipelineState(
@@ -337,7 +358,8 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
else
{
SLANG_RETURN_ON_FAIL(m_device->m_device->CreateComputePipelineState(
- &computeDesc, IID_PPV_ARGS(m_pipelineState.writeRef())));
+ &computeDesc,
+ IID_PPV_ARGS(m_pipelineState.writeRef())));
}
}
}
@@ -350,7 +372,8 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
RayTracingPipelineStateImpl::RayTracingPipelineStateImpl(DeviceImpl* device)
: m_device(device)
-{}
+{
+}
void RayTracingPipelineStateImpl::init(const RayTracingPipelineStateDesc& inDesc)
{
@@ -405,12 +428,16 @@ Result RayTracingPipelineStateImpl::ensureAPIPipelineStateCreated()
subObjects.add(pipelineConfigSubobject);
auto compileShader = [&](slang::EntryPointLayout* entryPointInfo,
- slang::IComponentType* component,
- SlangInt entryPointIndex)
+ slang::IComponentType* component,
+ SlangInt entryPointIndex)
{
ComPtr<ISlangBlob> codeBlob;
- auto compileResult = m_device->getEntryPointCodeFromShaderCache(component,
- entryPointIndex, 0, codeBlob.writeRef(), diagnostics.writeRef());
+ auto compileResult = m_device->getEntryPointCodeFromShaderCache(
+ component,
+ entryPointIndex,
+ 0,
+ codeBlob.writeRef(),
+ diagnostics.writeRef());
if (diagnostics.get())
{
getDebugCallback()->handleMessage(
@@ -441,7 +468,9 @@ Result RayTracingPipelineStateImpl::ensureAPIPipelineStateCreated()
for (SlangUInt i = 0; i < programLayout->getEntryPointCount(); i++)
{
SLANG_RETURN_ON_FAIL(compileShader(
- programLayout->getEntryPointByIndex(i), program->linkedProgram, (SlangInt)i));
+ programLayout->getEntryPointByIndex(i),
+ program->linkedProgram,
+ (SlangInt)i));
}
}
else
@@ -458,8 +487,8 @@ Result RayTracingPipelineStateImpl::ensureAPIPipelineStateCreated()
auto& hitGroup = desc.rayTracing.hitGroups[i];
D3D12_HIT_GROUP_DESC hitGroupDesc = {};
hitGroupDesc.Type = hitGroup.intersectionEntryPoint.getLength() == 0
- ? D3D12_HIT_GROUP_TYPE_TRIANGLES
- : D3D12_HIT_GROUP_TYPE_PROCEDURAL_PRIMITIVE;
+ ? D3D12_HIT_GROUP_TYPE_TRIANGLES
+ : D3D12_HIT_GROUP_TYPE_PROCEDURAL_PRIMITIVE;
if (hitGroup.anyHitEntryPoint.getLength())
{
@@ -503,7 +532,8 @@ Result RayTracingPipelineStateImpl::ensureAPIPipelineStateCreated()
if (m_device->m_pipelineCreationAPIDispatcher)
{
m_device->m_pipelineCreationAPIDispatcher->beforeCreateRayTracingState(
- m_device, slangGlobalScope);
+ m_device,
+ slangGlobalScope);
}
D3D12_STATE_OBJECT_DESC rtpsoDesc = {};
@@ -516,7 +546,8 @@ Result RayTracingPipelineStateImpl::ensureAPIPipelineStateCreated()
if (m_device->m_pipelineCreationAPIDispatcher)
{
m_device->m_pipelineCreationAPIDispatcher->afterCreateRayTracingState(
- m_device, slangGlobalScope);
+ m_device,
+ slangGlobalScope);
}
return SLANG_OK;
}
diff --git a/tools/gfx/d3d12/d3d12-pipeline-state.h b/tools/gfx/d3d12/d3d12-pipeline-state.h
index a22e04a05..21645642a 100644
--- a/tools/gfx/d3d12/d3d12-pipeline-state.h
+++ b/tools/gfx/d3d12/d3d12-pipeline-state.h
@@ -15,7 +15,8 @@ class PipelineStateImpl : public PipelineStateBase
public:
PipelineStateImpl(DeviceImpl* device)
: m_device(device)
- {}
+ {
+ }
DeviceImpl* m_device;
ComPtr<ID3D12PipelineState> m_pipelineState;
void init(const GraphicsPipelineStateDesc& inDesc);
diff --git a/tools/gfx/d3d12/d3d12-posix-synchapi.cpp b/tools/gfx/d3d12/d3d12-posix-synchapi.cpp
index b979bb3cc..292f692d6 100644
--- a/tools/gfx/d3d12/d3d12-posix-synchapi.cpp
+++ b/tools/gfx/d3d12/d3d12-posix-synchapi.cpp
@@ -6,6 +6,7 @@
#include "core/slang-common.h"
+#include <cerrno>
#include <fcntl.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
@@ -13,8 +14,6 @@
#include <sys/timerfd.h>
#include <unistd.h>
-#include <cerrno>
-
// To keep aligned with the d3d12 API, we store file descriptors in the low 32
// bits of HANDLEs.
static int _handleToFD(HANDLE h)
@@ -41,16 +40,16 @@ static HANDLE _fdToHandle(int fd, int flags)
HANDLE CreateEventEx(
LPSECURITY_ATTRIBUTES lpEventAttributes,
- LPCSTR lpName,
- DWORD dwFlags,
- DWORD dwDesiredAccess)
+ LPCSTR lpName,
+ DWORD dwFlags,
+ DWORD dwDesiredAccess)
{
int fd = ::eventfd(dwFlags & CREATE_EVENT_INITIAL_SET ? 1 : 0, EFD_CLOEXEC | EFD_NONBLOCK);
// Make sure not to return a zero handle, duplicate the fd if necessary
- if(fd == 0)
+ if (fd == 0)
{
int nextFd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
- if(fcntl(nextFd, F_SETFL, O_NONBLOCK) == -1)
+ if (fcntl(nextFd, F_SETFL, O_NONBLOCK) == -1)
{
close(nextFd);
nextFd = -1;
@@ -63,7 +62,7 @@ HANDLE CreateEventEx(
BOOL CloseHandle(HANDLE h)
{
- if(h == 0)
+ if (h == 0)
{
return 1;
}
@@ -79,22 +78,22 @@ BOOL ResetEvent(HANDLE h)
uint64_t x;
int r = 0;
int nEvents = poll(&pfd, 1, 0);
- if(pfd.revents != POLLIN)
+ if (pfd.revents != POLLIN)
{
// Nothing to read, already reset
return 1;
}
- if(nEvents != 1)
+ if (nEvents != 1)
{
return 0;
}
r = read(fd, &x, sizeof(x));
- if(r == sizeof(x))
+ if (r == sizeof(x))
{
// We reset it
return 1;
}
- if(r == -1 && errno == EAGAIN)
+ if (r == -1 && errno == EAGAIN)
{
// Something else reset it
return 1;
@@ -106,18 +105,18 @@ BOOL SetEvent(HANDLE h)
{
int fd = _handleToFD(h);
pollfd pfd{fd, POLLOUT, 0};
- for(;;)
+ for (;;)
{
int nEvents = poll(&pfd, 1, -1);
SLANG_ASSERT(nEvents != -1);
SLANG_ASSERT(nEvents != 0); // shouldn't have timed out
const uint64_t one = 1;
int w = ::write(fd, &one, sizeof(one));
- if(w == sizeof(one))
+ if (w == sizeof(one))
{
return 1;
}
- if(errno != EAGAIN)
+ if (errno != EAGAIN)
{
return 0;
}
@@ -137,11 +136,11 @@ DWORD WaitForSingleObject(const HANDLE h, const DWORD ms)
const bool isInfinite = ms == INFINITE;
const DWORD fiveSeconds = 5000;
int nEvents = poll(&pfd, 1, isInfinite ? fiveSeconds : ms);
- if(pfd.revents != POLLIN)
+ if (pfd.revents != POLLIN)
{
return WAIT_FAILED;
}
- if(nEvents == -1)
+ if (nEvents == -1)
{
return WAIT_FAILED;
}
@@ -149,29 +148,25 @@ DWORD WaitForSingleObject(const HANDLE h, const DWORD ms)
{
return isInfinite ? WAIT_FAILED : WAIT_TIMEOUT;
}
- if(manualReset)
+ if (manualReset)
{
return WAIT_OBJECT_0;
}
r = read(fd, &x, sizeof(x));
- if(r == sizeof(x))
+ if (r == sizeof(x))
{
return WAIT_OBJECT_0;
}
- if(r == -1 && errno == EAGAIN)
+ if (r == -1 && errno == EAGAIN)
{
return isInfinite ? WAIT_FAILED : WAIT_TIMEOUT;
}
return WAIT_FAILED;
}
-DWORD WaitForMultipleObjects(
- DWORD n,
- const HANDLE *hs,
- BOOL bWaitAll,
- DWORD requestedMs)
+DWORD WaitForMultipleObjects(DWORD n, const HANDLE* hs, BOOL bWaitAll, DWORD requestedMs)
{
- if(n == 0)
+ if (n == 0)
{
return bWaitAll ? WAIT_OBJECT_0 : WAIT_FAILED;
}
@@ -185,22 +180,22 @@ DWORD WaitForMultipleObjects(
DWORD res;
int fds[n];
int flagss[n];
- epoll_event evs[n+1]; // +1 for our timer
+ epoll_event evs[n + 1]; // +1 for our timer
int ufd = -1;
int epfd = epoll_create1(EPOLL_CLOEXEC);
- if(epfd == -1)
+ if (epfd == -1)
{
goto fail;
}
- for(int i = 0; i < n; ++i)
+ for (int i = 0; i < n; ++i)
{
fds[i] = _handleToFD(hs[i]);
flagss[i] = _handleToFlags(hs[i]);
epoll_event ev;
ev.data.fd = fds[i];
ev.events = EPOLLIN | EPOLLONESHOT;
- if(epoll_ctl(epfd, EPOLL_CTL_ADD, fds[i], &ev) == -1)
+ if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[i], &ev) == -1)
{
goto fail;
}
@@ -214,13 +209,13 @@ DWORD WaitForMultipleObjects(
// after the other, and put the values back if we can't claim them all, it
// sucks.
//
- if(bWaitAll)
+ if (bWaitAll)
{
// Use a timer to easily know for sure when we've timed out
- if(dwMilliseconds != INFINITE)
+ if (dwMilliseconds != INFINITE)
{
ufd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
- if(ufd == -1)
+ if (ufd == -1)
{
goto fail;
}
@@ -229,13 +224,13 @@ DWORD WaitForMultipleObjects(
spec.it_interval.tv_nsec = 0;
spec.it_value.tv_sec = 0;
spec.it_value.tv_nsec = 1000000 * dwMilliseconds;
- if(timerfd_settime(ufd, 0, &spec, nullptr) == -1)
+ if (timerfd_settime(ufd, 0, &spec, nullptr) == -1)
{
goto fail;
}
evs[n].data.fd = ufd;
evs[n].events = EPOLLIN | EPOLLONESHOT;
- if(epoll_ctl(epfd, EPOLL_CTL_ADD, ufd, &evs[n]) == -1)
+ if (epoll_ctl(epfd, EPOLL_CTL_ADD, ufd, &evs[n]) == -1)
{
goto fail;
}
@@ -250,29 +245,29 @@ DWORD WaitForMultipleObjects(
do
{
// Wait until epoll tells us they're all available, or the timer is
- const int nEvents = epoll_wait(epfd, evs, n+1, -1);
+ const int nEvents = epoll_wait(epfd, evs, n + 1, -1);
// We didn't specify a timeout, so 0 results is abnormal
- if(nEvents < 1)
+ if (nEvents < 1)
{
goto fail;
}
// Process all the returned fds
- for(int i = 0; i < nEvents; ++i)
+ for (int i = 0; i < nEvents; ++i)
{
- if(!(evs[i].events & EPOLLIN))
+ if (!(evs[i].events & EPOLLIN))
{
// Something exceptional happened on the fd
// Possibly we could just continue and hope it doesn't
// happen again?
goto fail;
}
- if(evs[i].data.fd == ufd)
+ if (evs[i].data.fd == ufd)
{
// We're out of time, make this the last loop
uint64_t x;
int r = read(ufd, &x, sizeof(x));
- if(r == sizeof(x))
+ if (r == sizeof(x))
{
timesUp = true;
}
@@ -287,11 +282,10 @@ DWORD WaitForMultipleObjects(
++nSeenEvents;
}
}
- }
- while(!(timesUp || nSeenEvents == n));
+ } while (!(timesUp || nSeenEvents == n));
// If we got here without seeing enough events, we must have timed out
- if(nSeenEvents < n)
+ if (nSeenEvents < n)
{
res = isInfinite ? WAIT_FAILED : WAIT_TIMEOUT;
goto end;
@@ -303,51 +297,52 @@ DWORD WaitForMultipleObjects(
// makes the code a bit cleaner.
// Put all the events back in our epoll instance and see if they're
// all readable.
- for(int i = 0; i < n; ++i)
+ for (int i = 0; i < n; ++i)
{
epoll_event modEv;
modEv.data.fd = fds[i];
modEv.events = EPOLLIN | EPOLLONESHOT;
- if(epoll_ctl(epfd, EPOLL_CTL_MOD, fds[i], &modEv) == -1)
+ if (epoll_ctl(epfd, EPOLL_CTL_MOD, fds[i], &modEv) == -1)
{
goto fail;
}
}
// Remove the timer if we're using it
- if(dwMilliseconds != INFINITE && epoll_ctl(epfd, EPOLL_CTL_DEL, ufd, nullptr) == -1)
+ if (dwMilliseconds != INFINITE && epoll_ctl(epfd, EPOLL_CTL_DEL, ufd, nullptr) == -1)
{
goto fail;
}
int nEvents = epoll_wait(epfd, evs, n, 0);
- if(nEvents < 0)
+ if (nEvents < 0)
{
goto fail;
}
- else if(nEvents < n)
+ else if (nEvents < n)
{
// They're not all still available :(
// Put our timer back in and try again from the top
- if(dwMilliseconds != INFINITE && epoll_ctl(epfd, EPOLL_CTL_ADD, ufd, &evs[n]) == -1)
+ if (dwMilliseconds != INFINITE &&
+ epoll_ctl(epfd, EPOLL_CTL_ADD, ufd, &evs[n]) == -1)
{
goto fail;
}
// Put back the any fds which did trigger
- for(int i = 0; i < nEvents; ++i)
+ for (int i = 0; i < nEvents; ++i)
{
epoll_event modEv = evs[i];
modEv.events = EPOLLIN | EPOLLONESHOT;
- if(epoll_ctl(epfd, EPOLL_CTL_MOD, modEv.data.fd, &modEv) == -1)
+ if (epoll_ctl(epfd, EPOLL_CTL_MOD, modEv.data.fd, &modEv) == -1)
{
goto fail;
}
}
continue;
}
- else if(nEvents == n)
+ else if (nEvents == n)
{
- for(int i = 0; i < nEvents; ++i)
+ for (int i = 0; i < nEvents; ++i)
{
- if(!(evs->events & EPOLLIN))
+ if (!(evs->events & EPOLLIN))
{
goto fail;
}
@@ -358,19 +353,19 @@ DWORD WaitForMultipleObjects(
uint64_t vs[n];
int i;
bool failure = false;
- for(i = 0; i < n; ++i)
+ for (i = 0; i < n; ++i)
{
- if(flagss[i] & CREATE_EVENT_MANUAL_RESET)
+ if (flagss[i] & CREATE_EVENT_MANUAL_RESET)
{
// We don't need to read this to unset it
continue;
}
int r = read(fds[i], &vs[i], sizeof(vs[i]));
- if(r == sizeof(vs[i]))
+ if (r == sizeof(vs[i]))
{
continue;
}
- else if(r == -1 && errno == EAGAIN)
+ else if (r == -1 && errno == EAGAIN)
{
// contention, put things back and try again
break;
@@ -385,9 +380,9 @@ DWORD WaitForMultipleObjects(
if (i < n)
{
// contention or failure
- for(int j = 0; j < i; ++j)
+ for (int j = 0; j < i; ++j)
{
- if(flagss[i] & CREATE_EVENT_MANUAL_RESET)
+ if (flagss[i] & CREATE_EVENT_MANUAL_RESET)
{
// We didn't read, so we shouldn't write
continue;
@@ -401,7 +396,7 @@ DWORD WaitForMultipleObjects(
int w = write(fds[j], &vs[j], sizeof(vs[j]));
SLANG_ASSERT(w == sizeof(vs[j]));
}
- if(failure)
+ if (failure)
{
goto fail;
}
@@ -413,28 +408,29 @@ DWORD WaitForMultipleObjects(
goto end;
}
- // If we get here then we've got some contention, go back to the top and try again (or timeout)
- }
- while(!timesUp);
+ // If we get here then we've got some contention, go back to the top and try again (or
+ // timeout)
+ } while (!timesUp);
}
else
{
// Wait any
- const int nEvents = epoll_wait(epfd, evs, n, dwMilliseconds == INFINITE ? -1 : dwMilliseconds);
- if(nEvents == -1)
+ const int nEvents =
+ epoll_wait(epfd, evs, n, dwMilliseconds == INFINITE ? -1 : dwMilliseconds);
+ if (nEvents == -1)
{
goto fail;
}
- if(nEvents == 0)
+ if (nEvents == 0)
{
res = isInfinite ? WAIT_FAILED : WAIT_TIMEOUT;
goto end;
}
// Try reads until we get one
- for(int i = 0; i < nEvents; ++i)
+ for (int i = 0; i < nEvents; ++i)
{
uint64_t x;
- if(!evs[i].events & EPOLLIN)
+ if (!evs[i].events & EPOLLIN)
{
continue;
}
diff --git a/tools/gfx/d3d12/d3d12-posix-synchapi.h b/tools/gfx/d3d12/d3d12-posix-synchapi.h
index ba5a15b0a..15aef9418 100644
--- a/tools/gfx/d3d12/d3d12-posix-synchapi.h
+++ b/tools/gfx/d3d12/d3d12-posix-synchapi.h
@@ -33,20 +33,20 @@
#define WAIT_FAILED 0xffffffff
#define WAIT_OBJECT_0 0
-typedef struct _SECURITY_ATTRIBUTES *LPSECURITY_ATTRIBUTES;
+typedef struct _SECURITY_ATTRIBUTES* LPSECURITY_ATTRIBUTES;
#define CREATE_EVENT_MANUAL_RESET 1
-#define CREATE_EVENT_INITIAL_SET 2
+#define CREATE_EVENT_INITIAL_SET 2
-#define SYNCHRONIZE 0x00100000
-#define STANDARD_RIGHTS_REQUIRED 0x000f0000
-#define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
+#define SYNCHRONIZE 0x00100000
+#define STANDARD_RIGHTS_REQUIRED 0x000f0000
+#define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3)
HANDLE CreateEventEx(
LPSECURITY_ATTRIBUTES lpEventAttributes,
- LPCSTR lpName,
- DWORD dwFlags,
- DWORD dwDesiredAccess);
+ LPCSTR lpName,
+ DWORD dwFlags,
+ DWORD dwDesiredAccess);
BOOL CloseHandle(HANDLE h);
@@ -57,9 +57,9 @@ BOOL SetEvent(HANDLE h);
DWORD WaitForSingleObject(HANDLE h, DWORD ms);
DWORD WaitForMultipleObjects(
- DWORD nHandles,
- const HANDLE *handles,
- BOOL bWaitAll,
- DWORD dwMilliseconds);
+ DWORD nHandles,
+ const HANDLE* handles,
+ BOOL bWaitAll,
+ DWORD dwMilliseconds);
#endif // SLANG_LINUX_FAMILY
diff --git a/tools/gfx/d3d12/d3d12-query.cpp b/tools/gfx/d3d12/d3d12-query.cpp
index 6b2e92980..d0191e349 100644
--- a/tools/gfx/d3d12/d3d12-query.cpp
+++ b/tools/gfx/d3d12/d3d12-query.cpp
@@ -2,7 +2,6 @@
#include "d3d12-query.h"
#include "d3d12-command-queue.h"
-
#include "d3d12-helper-functions.h"
namespace gfx
@@ -26,8 +25,7 @@ Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
heapDesc.Type = D3D12_QUERY_HEAP_TYPE_TIMESTAMP;
m_queryType = D3D12_QUERY_TYPE_TIMESTAMP;
break;
- default:
- return SLANG_E_INVALID_ARG;
+ default: return SLANG_E_INVALID_ARG;
}
// Create query heap.
@@ -54,7 +52,8 @@ Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
// Create command allocator.
SLANG_RETURN_ON_FAIL(d3dDevice->CreateCommandAllocator(
- D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(m_commandAllocator.writeRef())));
+ D3D12_COMMAND_LIST_TYPE_DIRECT,
+ IID_PPV_ARGS(m_commandAllocator.writeRef())));
// Create command list.
SLANG_RETURN_ON_FAIL(d3dDevice->CreateCommandList(
@@ -99,7 +98,8 @@ Result QueryPoolImpl::getResult(GfxIndex queryIndex, GfxCount count, uint64_t* d
int8_t* mappedData = nullptr;
D3D12_RANGE readRange = {
- sizeof(uint64_t) * queryIndex, sizeof(uint64_t) * (queryIndex + count) };
+ sizeof(uint64_t) * queryIndex,
+ sizeof(uint64_t) * (queryIndex + count)};
m_readBackBuffer.getResource()->Map(0, &readRange, (void**)&mappedData);
memcpy(data, mappedData + sizeof(uint64_t) * queryIndex, sizeof(uint64_t) * count);
m_readBackBuffer.getResource()->Unmap(0, nullptr);
@@ -119,7 +119,9 @@ IQueryPool* PlainBufferProxyQueryPoolImpl::getInterface(const Guid& guid)
}
Result PlainBufferProxyQueryPoolImpl::init(
- const IQueryPool::Desc& desc, DeviceImpl* device, uint32_t stride)
+ const IQueryPool::Desc& desc,
+ DeviceImpl* device,
+ uint32_t stride)
{
ComPtr<IBufferResource> bufferResource;
IBufferResource::Desc bufferDesc = {};
@@ -187,8 +189,8 @@ Result PlainBufferProxyQueryPoolImpl::getResult(GfxIndex queryIndex, GfxCount co
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr));
- encodeInfo.d3dCommandList->CopyBufferRegion(
- stageBuf, 0, m_bufferResource->m_resource.getResource(), 0, size);
+ encodeInfo.d3dCommandList
+ ->CopyBufferRegion(stageBuf, 0, m_bufferResource->m_resource.getResource(), 0, size);
m_device->submitResourceCommandsAndWait(encodeInfo);
void* ptr = nullptr;
stageBuf.getResource()->Map(0, nullptr, &ptr);
diff --git a/tools/gfx/d3d12/d3d12-query.h b/tools/gfx/d3d12/d3d12-query.h
index 770990e81..dff3fbd21 100644
--- a/tools/gfx/d3d12/d3d12-query.h
+++ b/tools/gfx/d3d12/d3d12-query.h
@@ -2,8 +2,8 @@
#pragma once
#include "d3d12-base.h"
-#include "d3d12-device.h"
#include "d3d12-buffer.h"
+#include "d3d12-device.h"
namespace gfx
{
@@ -18,7 +18,7 @@ public:
Result init(const IQueryPool::Desc& desc, DeviceImpl* device);
virtual SLANG_NO_THROW Result SLANG_MCALL
- getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
+ getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
void writeTimestamp(ID3D12GraphicsCommandList* cmdList, GfxIndex index);
@@ -41,14 +41,14 @@ class PlainBufferProxyQueryPoolImpl : public QueryPoolBase
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
- IQueryPool* getInterface(const Guid& guid);
+ IQueryPool* getInterface(const Guid& guid);
public:
Result init(const IQueryPool::Desc& 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;
+ getResult(GfxIndex queryIndex, GfxCount count, uint64_t* data) override;
public:
QueryType m_queryType;
diff --git a/tools/gfx/d3d12/d3d12-resource-views.cpp b/tools/gfx/d3d12/d3d12-resource-views.cpp
index b156f6ab6..a760caef8 100644
--- a/tools/gfx/d3d12/d3d12-resource-views.cpp
+++ b/tools/gfx/d3d12/d3d12-resource-views.cpp
@@ -1,5 +1,6 @@
// d3d12-resource-views.cpp
#include "d3d12-resource-views.h"
+
#include "d3d12-device.h"
namespace gfx
@@ -34,104 +35,106 @@ SlangResult createD3D12BufferDescriptor(
const auto counterResourceImpl = static_cast<BufferResourceImpl*>(counterBuffer);
uint64_t offset = desc.bufferRange.offset;
- uint64_t size = desc.bufferRange.size == 0 ? buffer->getDesc()->sizeInBytes - offset : desc.bufferRange.size;
+ uint64_t size = desc.bufferRange.size == 0 ? buffer->getDesc()->sizeInBytes - offset
+ : desc.bufferRange.size;
switch (desc.type)
{
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
case IResourceView::Type::UnorderedAccess:
- {
- D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
- uavDesc.Format = D3DUtil::getMapFormat(desc.format);
- if (bufferStride)
- {
- uavDesc.Buffer.FirstElement = offset / bufferStride;
- uavDesc.Buffer.NumElements = UINT(size / bufferStride);
- uavDesc.Buffer.StructureByteStride = bufferStride;
- }
- else if (desc.format == Format::Unknown)
- {
- uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
- uavDesc.Buffer.FirstElement = offset / 4;
- uavDesc.Buffer.NumElements = UINT(size / 4);
- uavDesc.Buffer.Flags |= D3D12_BUFFER_UAV_FLAG_RAW;
- }
- else
{
- FormatInfo sizeInfo;
- gfxGetFormatInfo(desc.format, &sizeInfo);
- assert(sizeInfo.pixelsPerBlock == 1);
- uavDesc.Buffer.FirstElement = offset / sizeInfo.blockSizeInBytes;
- uavDesc.Buffer.NumElements = UINT(size / sizeInfo.blockSizeInBytes);
+ D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
+ uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
+ uavDesc.Format = D3DUtil::getMapFormat(desc.format);
+ if (bufferStride)
+ {
+ uavDesc.Buffer.FirstElement = offset / bufferStride;
+ uavDesc.Buffer.NumElements = UINT(size / bufferStride);
+ uavDesc.Buffer.StructureByteStride = bufferStride;
+ }
+ else if (desc.format == Format::Unknown)
+ {
+ uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
+ uavDesc.Buffer.FirstElement = offset / 4;
+ uavDesc.Buffer.NumElements = UINT(size / 4);
+ uavDesc.Buffer.Flags |= D3D12_BUFFER_UAV_FLAG_RAW;
+ }
+ else
+ {
+ FormatInfo sizeInfo;
+ gfxGetFormatInfo(desc.format, &sizeInfo);
+ assert(sizeInfo.pixelsPerBlock == 1);
+ uavDesc.Buffer.FirstElement = offset / sizeInfo.blockSizeInBytes;
+ uavDesc.Buffer.NumElements = UINT(size / sizeInfo.blockSizeInBytes);
+ }
+
+ if (size >= (1ull << 32) - 8)
+ {
+ // D3D12 does not support view descriptors that has size near 4GB.
+ // We will not create actual SRV/UAVs for such large buffers.
+ // However, a buffer this large can still be bound as root parameter.
+ // So instead of failing, we quietly ignore descriptor creation.
+ outDescriptor->cpuHandle.ptr = 0;
+ }
+ else
+ {
+ SLANG_RETURN_ON_FAIL(descriptorHeap->allocate(outDescriptor));
+ device->m_device->CreateUnorderedAccessView(
+ resourceImpl->m_resource,
+ counterResourceImpl ? counterResourceImpl->m_resource.getResource() : nullptr,
+ &uavDesc,
+ outDescriptor->cpuHandle);
+ }
}
-
- if (size >= (1ull << 32) - 8)
- {
- // D3D12 does not support view descriptors that has size near 4GB.
- // We will not create actual SRV/UAVs for such large buffers.
- // However, a buffer this large can still be bound as root parameter.
- // So instead of failing, we quietly ignore descriptor creation.
- outDescriptor->cpuHandle.ptr = 0;
- }
- else
- {
- SLANG_RETURN_ON_FAIL(descriptorHeap->allocate(outDescriptor));
- device->m_device->CreateUnorderedAccessView(
- resourceImpl->m_resource,
- counterResourceImpl ? counterResourceImpl->m_resource.getResource() : nullptr,
- &uavDesc,
- outDescriptor->cpuHandle);
- }
- }
- break;
+ break;
case IResourceView::Type::ShaderResource:
- {
- D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
- srvDesc.Format = D3DUtil::getMapFormat(desc.format);
- srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- if (bufferStride)
- {
- srvDesc.Buffer.FirstElement = offset / bufferStride;
- srvDesc.Buffer.NumElements = UINT(size / bufferStride);
- srvDesc.Buffer.StructureByteStride = bufferStride;
- }
- else if (desc.format == Format::Unknown)
{
- srvDesc.Format = DXGI_FORMAT_R32_TYPELESS;
- srvDesc.Buffer.FirstElement = offset / 4;
- srvDesc.Buffer.NumElements = UINT(size / 4);
- srvDesc.Buffer.Flags |= D3D12_BUFFER_SRV_FLAG_RAW;
+ D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
+ srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
+ srvDesc.Format = D3DUtil::getMapFormat(desc.format);
+ srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
+ if (bufferStride)
+ {
+ srvDesc.Buffer.FirstElement = offset / bufferStride;
+ srvDesc.Buffer.NumElements = UINT(size / bufferStride);
+ srvDesc.Buffer.StructureByteStride = bufferStride;
+ }
+ else if (desc.format == Format::Unknown)
+ {
+ srvDesc.Format = DXGI_FORMAT_R32_TYPELESS;
+ srvDesc.Buffer.FirstElement = offset / 4;
+ srvDesc.Buffer.NumElements = UINT(size / 4);
+ srvDesc.Buffer.Flags |= D3D12_BUFFER_SRV_FLAG_RAW;
+ }
+ else
+ {
+ FormatInfo sizeInfo;
+ gfxGetFormatInfo(desc.format, &sizeInfo);
+ assert(sizeInfo.pixelsPerBlock == 1);
+ srvDesc.Buffer.FirstElement = offset / sizeInfo.blockSizeInBytes;
+ srvDesc.Buffer.NumElements = UINT(size / sizeInfo.blockSizeInBytes);
+ }
+
+ if (size >= (1ull << 32) - 8)
+ {
+ // D3D12 does not support view descriptors that has size near 4GB.
+ // We will not create actual SRV/UAVs for such large buffers.
+ // However, a buffer this large can still be bound as root parameter.
+ // So instead of failing, we quietly ignore descriptor creation.
+ outDescriptor->cpuHandle.ptr = 0;
+ }
+ else
+ {
+ SLANG_RETURN_ON_FAIL(descriptorHeap->allocate(outDescriptor));
+ device->m_device->CreateShaderResourceView(
+ resourceImpl->m_resource,
+ &srvDesc,
+ outDescriptor->cpuHandle);
+ }
}
- else
- {
- FormatInfo sizeInfo;
- gfxGetFormatInfo(desc.format, &sizeInfo);
- assert(sizeInfo.pixelsPerBlock == 1);
- srvDesc.Buffer.FirstElement = offset / sizeInfo.blockSizeInBytes;
- srvDesc.Buffer.NumElements = UINT(size / sizeInfo.blockSizeInBytes);
- }
-
- if (size >= (1ull << 32) - 8)
- {
- // D3D12 does not support view descriptors that has size near 4GB.
- // We will not create actual SRV/UAVs for such large buffers.
- // However, a buffer this large can still be bound as root parameter.
- // So instead of failing, we quietly ignore descriptor creation.
- outDescriptor->cpuHandle.ptr = 0;
- }
- else
- {
- SLANG_RETURN_ON_FAIL(descriptorHeap->allocate(outDescriptor));
- device->m_device->CreateShaderResourceView(
- resourceImpl->m_resource, &srvDesc, outDescriptor->cpuHandle);
- }
- }
- break;
+ break;
}
return SLANG_OK;
}
diff --git a/tools/gfx/d3d12/d3d12-resource-views.h b/tools/gfx/d3d12/d3d12-resource-views.h
index ac80a9368..379aaa7aa 100644
--- a/tools/gfx/d3d12/d3d12-resource-views.h
+++ b/tools/gfx/d3d12/d3d12-resource-views.h
@@ -1,8 +1,8 @@
// d3d12-resource-views.h
#pragma once
-#include "d3d12-base.h"
#include "../d3d/d3d-util.h"
+#include "d3d12-base.h"
#include "d3d12-buffer.h"
namespace gfx
@@ -44,9 +44,7 @@ SlangResult createD3D12BufferDescriptor(
D3D12GeneralExpandingDescriptorHeap* descriptorHeap,
D3D12Descriptor* outDescriptor);
-class ResourceViewImpl
- : public ResourceViewBase
- , public ResourceViewInternalImpl
+class ResourceViewImpl : public ResourceViewBase, public ResourceViewInternalImpl
{
public:
Slang::RefPtr<Resource> m_resource;
@@ -57,9 +55,7 @@ public:
#if SLANG_GFX_HAS_DXR_SUPPORT
-class AccelerationStructureImpl
- : public AccelerationStructureBase
- , public ResourceViewInternalImpl
+class AccelerationStructureImpl : public AccelerationStructureBase, public ResourceViewInternalImpl
{
public:
RefPtr<BufferResourceImpl> m_buffer;
diff --git a/tools/gfx/d3d12/d3d12-resource.cpp b/tools/gfx/d3d12/d3d12-resource.cpp
index 8975f5825..273e14f29 100644
--- a/tools/gfx/d3d12/d3d12-resource.cpp
+++ b/tools/gfx/d3d12/d3d12-resource.cpp
@@ -1,29 +1,34 @@
// d3d12-resource.cpp
#include "d3d12-resource.h"
-namespace gfx {
+namespace gfx
+{
using namespace Slang;
-/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! D3D12BarrierSubmitter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! D3D12BarrierSubmitter
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
void D3D12BarrierSubmitter::_flush()
{
- assert(m_numBarriers > 0);
+ assert(m_numBarriers > 0);
- if (m_commandList)
- {
- m_commandList->ResourceBarrier(UINT(m_numBarriers), m_barriers);
- }
- m_numBarriers = 0;
+ if (m_commandList)
+ {
+ m_commandList->ResourceBarrier(UINT(m_numBarriers), m_barriers);
+ }
+ m_numBarriers = 0;
}
D3D12_RESOURCE_BARRIER& D3D12BarrierSubmitter::_expandOne()
{
- _flush();
- return m_barriers[m_numBarriers++];
+ _flush();
+ return m_barriers[m_numBarriers++];
}
-void D3D12BarrierSubmitter::transition(ID3D12Resource* resource, D3D12_RESOURCE_STATES prevState, D3D12_RESOURCE_STATES nextState)
+void D3D12BarrierSubmitter::transition(
+ ID3D12Resource* resource,
+ D3D12_RESOURCE_STATES prevState,
+ D3D12_RESOURCE_STATES nextState)
{
if (nextState != prevState)
{
@@ -53,11 +58,13 @@ void D3D12BarrierSubmitter::transition(ID3D12Resource* resource, D3D12_RESOURCE_
}
}
-/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! D3D12ResourceBase !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! D3D12ResourceBase
+ * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
-/* static */DXGI_FORMAT D3D12ResourceBase::calcFormat(D3DUtil::UsageType usage, ID3D12Resource* resource)
+/* static */ DXGI_FORMAT
+D3D12ResourceBase::calcFormat(D3DUtil::UsageType usage, ID3D12Resource* resource)
{
- return resource ? D3DUtil::calcFormat(usage, resource->GetDesc().Format) : DXGI_FORMAT_UNKNOWN;
+ return resource ? D3DUtil::calcFormat(usage, resource->GetDesc().Format) : DXGI_FORMAT_UNKNOWN;
}
void D3D12ResourceBase::transition(
@@ -65,16 +72,16 @@ void D3D12ResourceBase::transition(
D3D12_RESOURCE_STATES nextState,
D3D12BarrierSubmitter& submitter)
{
- // Transition only if there is a resource
+ // Transition only if there is a resource
if (m_resource && oldState != nextState)
- {
+ {
submitter.transition(m_resource, oldState, nextState);
}
}
/* !!!!!!!!!!!!!!!!!!!!!!!!! D3D12Resource !!!!!!!!!!!!!!!!!!!!!!!! */
-/* static */void D3D12Resource::setDebugName(ID3D12Resource* resource, const char* name)
+/* static */ void D3D12Resource::setDebugName(ID3D12Resource* resource, const char* name)
{
if (resource)
{
@@ -84,63 +91,75 @@ void D3D12ResourceBase::transition(
void D3D12Resource::setDebugName(const char* name)
{
- setDebugName(m_resource, name);
+ setDebugName(m_resource, name);
}
void D3D12Resource::setDebugName(const wchar_t* name)
{
- if (m_resource)
- {
- m_resource->SetName(name);
- }
+ if (m_resource)
+ {
+ m_resource->SetName(name);
+ }
}
void D3D12Resource::setResource(ID3D12Resource* resource)
{
- if (resource != m_resource)
- {
- if (resource)
- {
- resource->AddRef();
- }
- if (m_resource)
- {
- m_resource->Release();
- }
- m_resource = resource;
- }
+ if (resource != m_resource)
+ {
+ if (resource)
+ {
+ resource->AddRef();
+ }
+ if (m_resource)
+ {
+ m_resource->Release();
+ }
+ m_resource = resource;
+ }
}
void D3D12Resource::setResourceNull()
{
- if (m_resource)
- {
- m_resource->Release();
- m_resource = nullptr;
- }
+ if (m_resource)
+ {
+ m_resource->Release();
+ m_resource = nullptr;
+ }
}
-Result D3D12Resource::initCommitted(ID3D12Device* device, const D3D12_HEAP_PROPERTIES& heapProps, D3D12_HEAP_FLAGS heapFlags, const D3D12_RESOURCE_DESC& resourceDesc, D3D12_RESOURCE_STATES initState, const D3D12_CLEAR_VALUE * clearValue)
+Result D3D12Resource::initCommitted(
+ ID3D12Device* device,
+ const D3D12_HEAP_PROPERTIES& heapProps,
+ D3D12_HEAP_FLAGS heapFlags,
+ const D3D12_RESOURCE_DESC& resourceDesc,
+ D3D12_RESOURCE_STATES initState,
+ const D3D12_CLEAR_VALUE* clearValue)
{
- setResourceNull();
- ComPtr<ID3D12Resource> resource;
- SLANG_RETURN_ON_FAIL(device->CreateCommittedResource(&heapProps, heapFlags, &resourceDesc, initState, clearValue, IID_PPV_ARGS(resource.writeRef())));
- setResource(resource);
- return SLANG_OK;
+ setResourceNull();
+ ComPtr<ID3D12Resource> resource;
+ SLANG_RETURN_ON_FAIL(device->CreateCommittedResource(
+ &heapProps,
+ heapFlags,
+ &resourceDesc,
+ initState,
+ clearValue,
+ IID_PPV_ARGS(resource.writeRef())));
+ setResource(resource);
+ return SLANG_OK;
}
ID3D12Resource* D3D12Resource::detach()
{
- ID3D12Resource* resource = m_resource;
- m_resource = nullptr;
- return resource;
+ ID3D12Resource* resource = m_resource;
+ m_resource = nullptr;
+ return resource;
}
void D3D12Resource::swap(ComPtr<ID3D12Resource>& resourceInOut)
{
- ID3D12Resource* tmp = m_resource;
- m_resource = resourceInOut.detach();
- resourceInOut.attach(tmp);
+ ID3D12Resource* tmp = m_resource;
+ m_resource = resourceInOut.detach();
+ resourceInOut.attach(tmp);
}
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/d3d12/d3d12-resource.h b/tools/gfx/d3d12/d3d12-resource.h
index cd56793cc..cbf47ed66 100644
--- a/tools/gfx/d3d12/d3d12-resource.h
+++ b/tools/gfx/d3d12/d3d12-resource.h
@@ -11,13 +11,14 @@
#pragma pop_macro("NOMINMAX")
#pragma pop_macro("WIN32_LEAN_AND_MEAN")
-#include <dxgi1_4.h>
-#include <d3d12.h>
-
-#include "slang-com-ptr.h"
#include "../d3d/d3d-util.h"
+#include "slang-com-ptr.h"
-namespace gfx {
+#include <d3d12.h>
+#include <dxgi1_4.h>
+
+namespace gfx
+{
// Enables more conservative barriers - restoring the state of resources after they are used.
// Should not need to be enabled in normal builds, as the barriers should correctly sync resources
@@ -26,95 +27,120 @@ namespace gfx {
struct D3D12BarrierSubmitter
{
- enum { MAX_BARRIERS = 8 };
-
- /// Expand one space to hold a barrier
- SLANG_FORCE_INLINE D3D12_RESOURCE_BARRIER& expandOne() { return (m_numBarriers < MAX_BARRIERS) ? m_barriers[m_numBarriers++] : _expandOne(); }
- /// Flush barriers to command list
- SLANG_FORCE_INLINE void flush() { if (m_numBarriers > 0) _flush(); }
-
- /// Transition resource from prevState to nextState
- void transition(ID3D12Resource* resource, D3D12_RESOURCE_STATES prevState, D3D12_RESOURCE_STATES nextState);
-
- /// Ctor
- SLANG_FORCE_INLINE D3D12BarrierSubmitter(ID3D12GraphicsCommandList* commandList) : m_numBarriers(0), m_commandList(commandList) { }
- /// Dtor
- SLANG_FORCE_INLINE ~D3D12BarrierSubmitter() { flush(); }
+ enum
+ {
+ MAX_BARRIERS = 8
+ };
+
+ /// Expand one space to hold a barrier
+ SLANG_FORCE_INLINE D3D12_RESOURCE_BARRIER& expandOne()
+ {
+ return (m_numBarriers < MAX_BARRIERS) ? m_barriers[m_numBarriers++] : _expandOne();
+ }
+ /// Flush barriers to command list
+ SLANG_FORCE_INLINE void flush()
+ {
+ if (m_numBarriers > 0)
+ _flush();
+ }
+
+ /// Transition resource from prevState to nextState
+ void transition(
+ ID3D12Resource* resource,
+ D3D12_RESOURCE_STATES prevState,
+ D3D12_RESOURCE_STATES nextState);
+
+ /// Ctor
+ SLANG_FORCE_INLINE D3D12BarrierSubmitter(ID3D12GraphicsCommandList* commandList)
+ : m_numBarriers(0), m_commandList(commandList)
+ {
+ }
+ /// Dtor
+ SLANG_FORCE_INLINE ~D3D12BarrierSubmitter() { flush(); }
protected:
- D3D12_RESOURCE_BARRIER& _expandOne();
- void _flush();
+ D3D12_RESOURCE_BARRIER& _expandOne();
+ void _flush();
- ID3D12GraphicsCommandList* m_commandList;
- int m_numBarriers;
- D3D12_RESOURCE_BARRIER m_barriers[MAX_BARRIERS];
+ ID3D12GraphicsCommandList* m_commandList;
+ int m_numBarriers;
+ D3D12_RESOURCE_BARRIER m_barriers[MAX_BARRIERS];
};
-/** The base class for resource types allows for tracking of state. It does not allow for setting of the resource though, such that
-an interface can return a D3D12ResourceBase, and a client cant manipulate it's state, but it cannot replace/change the actual resource */
+/** The base class for resource types allows for tracking of state. It does not allow for setting of
+the resource though, such that an interface can return a D3D12ResourceBase, and a client cant
+manipulate it's state, but it cannot replace/change the actual resource */
struct D3D12ResourceBase
{
- /// Add a transition if necessary to the list
+ /// Add a transition if necessary to the list
void transition(
- D3D12_RESOURCE_STATES currentState,
- D3D12_RESOURCE_STATES nextState,
- D3D12BarrierSubmitter& submitter);
- /// Get the associated resource
- SLANG_FORCE_INLINE ID3D12Resource* getResource() const { return m_resource; }
+ D3D12_RESOURCE_STATES currentState,
+ D3D12_RESOURCE_STATES nextState,
+ D3D12BarrierSubmitter& submitter);
+ /// Get the associated resource
+ SLANG_FORCE_INLINE ID3D12Resource* getResource() const { return m_resource; }
- /// True if a resource is set
- SLANG_FORCE_INLINE bool isSet() const { return m_resource != nullptr; }
+ /// True if a resource is set
+ SLANG_FORCE_INLINE bool isSet() const { return m_resource != nullptr; }
- /// Coercible into ID3D12Resource
- SLANG_FORCE_INLINE operator ID3D12Resource*() const { return m_resource; }
+ /// Coercible into ID3D12Resource
+ SLANG_FORCE_INLINE operator ID3D12Resource*() const { return m_resource; }
- /// 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(D3DUtil::UsageType usage, ID3D12Resource* resource);
+ /// 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(D3DUtil::UsageType usage, ID3D12Resource* resource);
- /// Ctor
- SLANG_FORCE_INLINE D3D12ResourceBase() :
- m_resource(nullptr)
- {}
+ /// Ctor
+ SLANG_FORCE_INLINE D3D12ResourceBase()
+ : m_resource(nullptr)
+ {
+ }
protected:
- /// This is protected so as clients cannot slice the class, and so state tracking is lost
- ~D3D12ResourceBase() {}
+ /// This is protected so as clients cannot slice the class, and so state tracking is lost
+ ~D3D12ResourceBase() {}
- ID3D12Resource* m_resource; ///< The resource (ref counted)
+ ID3D12Resource* m_resource; ///< The resource (ref counted)
};
struct D3D12Resource : public D3D12ResourceBase
{
- /// Dtor
- ~D3D12Resource()
- {
- if (m_resource)
- {
- m_resource->Release();
- }
- }
-
- /// Initialize as committed resource
- Slang::Result initCommitted(ID3D12Device* device, const D3D12_HEAP_PROPERTIES& heapProps, D3D12_HEAP_FLAGS heapFlags, const D3D12_RESOURCE_DESC& resourceDesc, D3D12_RESOURCE_STATES initState, const D3D12_CLEAR_VALUE * clearValue);
-
- /// Set a resource.
- void setResource(ID3D12Resource* resource);
- /// Make the resource null
- void setResourceNull();
- /// Returns the attached resource (with any ref counts) and sets to nullptr on this.
- ID3D12Resource* detach();
-
- /// Swaps the resource contents with the contents of the smart pointer
- void swap(Slang::ComPtr<ID3D12Resource>& resourceInOut);
-
- /// Set the debug name on a resource
- static void setDebugName(ID3D12Resource* resource, const char* name);
-
- /// Set the the debug name on the resource
- void setDebugName(const wchar_t* name);
- /// Set the debug name
- void setDebugName(const char* name);
+ /// Dtor
+ ~D3D12Resource()
+ {
+ if (m_resource)
+ {
+ m_resource->Release();
+ }
+ }
+
+ /// Initialize as committed resource
+ Slang::Result initCommitted(
+ ID3D12Device* device,
+ const D3D12_HEAP_PROPERTIES& heapProps,
+ D3D12_HEAP_FLAGS heapFlags,
+ const D3D12_RESOURCE_DESC& resourceDesc,
+ D3D12_RESOURCE_STATES initState,
+ const D3D12_CLEAR_VALUE* clearValue);
+
+ /// Set a resource.
+ void setResource(ID3D12Resource* resource);
+ /// Make the resource null
+ void setResourceNull();
+ /// Returns the attached resource (with any ref counts) and sets to nullptr on this.
+ ID3D12Resource* detach();
+
+ /// Swaps the resource contents with the contents of the smart pointer
+ void swap(Slang::ComPtr<ID3D12Resource>& resourceInOut);
+
+ /// Set the debug name on a resource
+ static void setDebugName(ID3D12Resource* resource, const char* name);
+
+ /// Set the the debug name on the resource
+ void setDebugName(const wchar_t* name);
+ /// Set the debug name
+ void setDebugName(const char* name);
};
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/d3d12/d3d12-sal-defs.h b/tools/gfx/d3d12/d3d12-sal-defs.h
index 058fbb14c..26df704d9 100644
--- a/tools/gfx/d3d12/d3d12-sal-defs.h
+++ b/tools/gfx/d3d12/d3d12-sal-defs.h
@@ -6,194 +6,194 @@
//
#if !defined(_In_)
-# define _In_
+#define _In_
#endif
#if !defined(_Out_)
-# define _Out_
+#define _Out_
#endif
#if !defined(_Inout_)
-# define _Inout_
+#define _Inout_
#endif
#if !defined(_In_z_)
-# define _In_z_
+#define _In_z_
#endif
#if !defined(_Inout_z_)
-# define _Inout_z_
+#define _Inout_z_
#endif
#if !defined(_In_reads_)
-# define _In_reads_(s)
+#define _In_reads_(s)
#endif
#if !defined(_In_reads_z_)
-# define _In_reads_z_(s)
+#define _In_reads_z_(s)
#endif
#if !defined(_In_reads_or_z_)
-# define _In_reads_or_z_(s)
+#define _In_reads_or_z_(s)
#endif
#if !defined(_Out_writes_)
-# define _Out_writes_(s)
+#define _Out_writes_(s)
#endif
#if !defined(_Out_writes_z_)
-# define _Out_writes_z_(s)
+#define _Out_writes_z_(s)
#endif
#if !defined(_Inout_updates_)
-# define _Inout_updates_(s)
+#define _Inout_updates_(s)
#endif
#if !defined(_Inout_updates_z_)
-# define _Inout_updates_z_(s)
+#define _Inout_updates_z_(s)
#endif
#if !defined(_Out_writes_to_)
-# define _Out_writes_to_(s,c)
+#define _Out_writes_to_(s, c)
#endif
#if !defined(_Inout_updates_to_)
-# define _Inout_updates_to_(s,c)
+#define _Inout_updates_to_(s, c)
#endif
#if !defined(_Inout_updates_all_)
-# define _Inout_updates_all_(s)
+#define _Inout_updates_all_(s)
#endif
#if !defined(_In_reads_to_ptr_)
-# define _In_reads_to_ptr_(p)
+#define _In_reads_to_ptr_(p)
#endif
#if !defined(_In_reads_to_ptr_z_)
-# define _In_reads_to_ptr_z_(p)
+#define _In_reads_to_ptr_z_(p)
#endif
#if !defined(_Out_writes_to_ptr_)
-# define _Out_writes_to_ptr_(p)
+#define _Out_writes_to_ptr_(p)
#endif
#if !defined(_Out_writes_to_ptr_z_)
-# define _Out_writes_to_ptr_z_(p)
+#define _Out_writes_to_ptr_z_(p)
#endif
#if !defined(_Outptr_)
-# define _Outptr_
+#define _Outptr_
#endif
#if !defined(_Outptr_opt_)
-# define _Outptr_opt_
+#define _Outptr_opt_
#endif
#if !defined(_Outptr_result_maybenull_)
-# define _Outptr_result_maybenull_
+#define _Outptr_result_maybenull_
#endif
#if !defined(_Outptr_opt_result_maybenull_)
-# define _Outptr_opt_result_maybenull_
+#define _Outptr_opt_result_maybenull_
#endif
#if !defined(_Outptr_result_z_)
-# define _Outptr_result_z_
+#define _Outptr_result_z_
#endif
#if !defined(_COM_Outptr_)
-# define _COM_Outptr_
+#define _COM_Outptr_
#endif
#if !defined(_Outptr_result_buffer_)
-# define _Outptr_result_buffer_(s)
+#define _Outptr_result_buffer_(s)
#endif
#if !defined(_Outptr_result_buffer_to_)
-# define _Outptr_result_buffer_to_(s, c)
+#define _Outptr_result_buffer_to_(s, c)
#endif
#if !defined(_Result_nullonfailure_)
-# define _Result_nullonfailure_
+#define _Result_nullonfailure_
#endif
#if !defined(_Result_zeroonfailure_)
-# define _Result_zeroonfailure_
+#define _Result_zeroonfailure_
#endif
#if !defined(_Outptr_result_nullonfailure_)
-# define _Outptr_result_nullonfailure_
+#define _Outptr_result_nullonfailure_
#endif
#if !defined(_Outptr_opt_result_nullonfailure_)
-# define _Outptr_opt_result_nullonfailure_
+#define _Outptr_opt_result_nullonfailure_
#endif
#if !defined(_Outref_result_nullonfailure_)
-# define _Outref_result_nullonfailure_
+#define _Outref_result_nullonfailure_
#endif
#if !defined(_Outref_)
-# define _Outref_
+#define _Outref_
#endif
#if !defined(_Outref_result_maybenull_)
-# define _Outref_result_maybenull_
+#define _Outref_result_maybenull_
#endif
#if !defined(_Outref_result_buffer_)
-# define _Outref_result_buffer_(s)
+#define _Outref_result_buffer_(s)
#endif
#if !defined(_Outref_result_bytebuffer_)
-# define _Outref_result_bytebuffer_(s)
+#define _Outref_result_bytebuffer_(s)
#endif
#if !defined(_Outref_result_buffer_to_)
-# define _Outref_result_buffer_to_(s, c)
+#define _Outref_result_buffer_to_(s, c)
#endif
#if !defined(_Outref_result_bytebuffer_to_)
-# define _Outref_result_bytebuffer_to_(s, c)
+#define _Outref_result_bytebuffer_to_(s, c)
#endif
#if !defined(_Outref_result_buffer_all_)
-# define _Outref_result_buffer_all_(s)
+#define _Outref_result_buffer_all_(s)
#endif
#if !defined(_Outref_result_bytebuffer_all_)
-# define _Outref_result_bytebuffer_all_(s)
+#define _Outref_result_bytebuffer_all_(s)
#endif
#if !defined(_Outref_result_buffer_maybenull_)
-# define _Outref_result_buffer_maybenull_(s)
+#define _Outref_result_buffer_maybenull_(s)
#endif
#if !defined(_Outref_result_bytebuffer_maybenull_)
-# define _Outref_result_bytebuffer_maybenull_(s)
+#define _Outref_result_bytebuffer_maybenull_(s)
#endif
#if !defined(_Outref_result_buffer_to_maybenull_)
-# define _Outref_result_buffer_to_maybenull_(s, c)
+#define _Outref_result_buffer_to_maybenull_(s, c)
#endif
#if !defined(_Outref_result_bytebuffer_to_maybenull_)
-# define _Outref_result_bytebuffer_to_maybenull_(s,c)
+#define _Outref_result_bytebuffer_to_maybenull_(s, c)
#endif
#if !defined(_Outref_result_buffer_all_maybenull_)
-# define _Outref_result_buffer_all_maybenull_(s)
+#define _Outref_result_buffer_all_maybenull_(s)
#endif
#if !defined(_Outref_result_bytebuffer_all_maybenull_)
-# define _Outref_result_bytebuffer_all_maybenull_(s)
+#define _Outref_result_bytebuffer_all_maybenull_(s)
#endif
#if !defined(_Printf_format_string_)
-# define _Printf_format_string_
+#define _Printf_format_string_
#endif
#if !defined(_Scanf_format_string_)
-# define _Scanf_format_string_
+#define _Scanf_format_string_
#endif
#if !defined(_Scanf_s_format_string_)
-# define _Scanf_s_format_string_
+#define _Scanf_s_format_string_
#endif
#if !defined(_In_range_)
-# define _In_range_(low, hi)
+#define _In_range_(low, hi)
#endif
#if !defined(_Pre_equal_to_)
-# define _Pre_equal_to_(expr)
+#define _Pre_equal_to_(expr)
#endif
#if !defined(_Struct_size_bytes_)
-# define _Struct_size_bytes_(size)
+#define _Struct_size_bytes_(size)
#endif
#if !defined(_Called_from_function_class_)
-# define _Called_from_function_class_(name)
+#define _Called_from_function_class_(name)
#endif
#if !defined(_Check_return_)
-# define _Check_return_
+#define _Check_return_
#endif
#if !defined(_Function_class_)
-# define _Function_class_(name)
+#define _Function_class_(name)
#endif
#if !defined(_Raises_SEH_exception_)
-# define _Raises_SEH_exception_
+#define _Raises_SEH_exception_
#endif
#if !defined(_Maybe_raises_SEH_exception_)
-# define _Maybe_raises_SEH_exception_
+#define _Maybe_raises_SEH_exception_
#endif
#if !defined(_Must_inspect_result_)
-# define _Must_inspect_result_
+#define _Must_inspect_result_
#endif
#if !defined(_Use_decl_annotations_)
-# define _Use_decl_annotations_
+#define _Use_decl_annotations_
#endif
#if !defined(_Always_)
-# define _Always_(anno_list)
+#define _Always_(anno_list)
#endif
#if !defined(_On_failure_)
-# define _On_failure_(anno_list)
+#define _On_failure_(anno_list)
#endif
#if !defined(_Return_type_success_)
-# define _Return_type_success_(expr)
+#define _Return_type_success_(expr)
#endif
#if !defined(_Success_)
-# define _Success_(expr)
+#define _Success_(expr)
#endif
#if !defined(__analysis_assume)
-# define __analysis_assume(expr)
+#define __analysis_assume(expr)
#endif
diff --git a/tools/gfx/d3d12/d3d12-sampler.cpp b/tools/gfx/d3d12/d3d12-sampler.cpp
index b96fb4c90..9f739a268 100644
--- a/tools/gfx/d3d12/d3d12-sampler.cpp
+++ b/tools/gfx/d3d12/d3d12-sampler.cpp
@@ -8,7 +8,10 @@ namespace d3d12
using namespace Slang;
-SamplerStateImpl::~SamplerStateImpl() { m_allocator->free(m_descriptor); }
+SamplerStateImpl::~SamplerStateImpl()
+{
+ m_allocator->free(m_descriptor);
+}
Result SamplerStateImpl::getNativeHandle(InteropHandle* outHandle)
{
diff --git a/tools/gfx/d3d12/d3d12-shader-object-layout.cpp b/tools/gfx/d3d12/d3d12-shader-object-layout.cpp
index c93ddf2cd..ad60fb12d 100644
--- a/tools/gfx/d3d12/d3d12-shader-object-layout.cpp
+++ b/tools/gfx/d3d12/d3d12-shader-object-layout.cpp
@@ -63,7 +63,7 @@ Result ShaderObjectLayoutImpl::init(Builder* builder)
{
auto renderer = builder->m_renderer;
- initBase(renderer, builder->m_session, builder->m_elementTypeLayout);
+ initBase(renderer, builder->m_session, builder->m_elementTypeLayout);
m_containerType = builder->m_containerType;
@@ -116,7 +116,7 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(
uint32_t count = (uint32_t)typeLayout->getBindingRangeBindingCount(r);
slang::TypeLayoutReflection* slangLeafTypeLayout =
typeLayout->getBindingRangeLeafTypeLayout(r);
-
+
BindingRangeInfo bindingRangeInfo = {};
bindingRangeInfo.bindingType = slangBindingType;
bindingRangeInfo.resourceShape = slangLeafTypeLayout->getResourceShape();
@@ -198,8 +198,7 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(
break;
case slang::BindingType::VaryingInput:
- case slang::BindingType::VaryingOutput:
- break;
+ case slang::BindingType::VaryingOutput: break;
default:
bindingRangeInfo.baseIndex = m_ownCounts.resource;
@@ -240,7 +239,11 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(
{
if (auto pendingTypeLayout = slangLeafTypeLayout->getPendingDataTypeLayout())
{
- createForElementType(m_renderer, m_session, pendingTypeLayout, subObjectLayout.writeRef());
+ createForElementType(
+ m_renderer,
+ m_session,
+ pendingTypeLayout,
+ subObjectLayout.writeRef());
}
}
else
@@ -294,53 +297,53 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(
switch (slangBindingType)
{
default:
- {
- // We only treat buffers of interface types as actual sub-object binding
- // range.
- auto bindingRangeTypeLayout =
- typeLayout->getBindingRangeLeafTypeLayout(bindingRangeIndex);
- if (!bindingRangeTypeLayout)
- continue;
- auto elementType = typeLayout->getBindingRangeLeafTypeLayout(bindingRangeIndex)
- ->getElementTypeLayout();
- if (!elementType)
- continue;
- if (elementType->getKind() != slang::TypeReflection::Kind::Interface)
{
- continue;
+ // We only treat buffers of interface types as actual sub-object binding
+ // range.
+ auto bindingRangeTypeLayout =
+ typeLayout->getBindingRangeLeafTypeLayout(bindingRangeIndex);
+ if (!bindingRangeTypeLayout)
+ continue;
+ auto elementType = typeLayout->getBindingRangeLeafTypeLayout(bindingRangeIndex)
+ ->getElementTypeLayout();
+ if (!elementType)
+ continue;
+ if (elementType->getKind() != slang::TypeReflection::Kind::Interface)
+ {
+ continue;
+ }
}
- }
- break;
+ break;
case slang::BindingType::ConstantBuffer:
- {
- SLANG_ASSERT(subObjectLayout);
+ {
+ SLANG_ASSERT(subObjectLayout);
- // The resource and sampler descriptors of a nested
- // constant buffer will "leak" into those of the
- // parent type, and we need to account for them
- // whenever we allocate storage.
- //
- objectCounts.resource = subObjectLayout->getTotalResourceDescriptorCount();
- objectCounts.sampler = subObjectLayout->getTotalSamplerDescriptorCount();
- objectCounts.rootParam = subObjectRange.layout->getChildRootParameterCount();
- }
- break;
+ // The resource and sampler descriptors of a nested
+ // constant buffer will "leak" into those of the
+ // parent type, and we need to account for them
+ // whenever we allocate storage.
+ //
+ objectCounts.resource = subObjectLayout->getTotalResourceDescriptorCount();
+ objectCounts.sampler = subObjectLayout->getTotalSamplerDescriptorCount();
+ objectCounts.rootParam = subObjectRange.layout->getChildRootParameterCount();
+ }
+ break;
case slang::BindingType::ParameterBlock:
- {
- SLANG_ASSERT(subObjectLayout);
+ {
+ SLANG_ASSERT(subObjectLayout);
- // In contrast to a constant buffer, a parameter block can hide
- // the resource and sampler descriptor allocation it uses (since they
- // are allocated into the tables that make up the parameter block.
- //
- // The only resource usage that leaks into the surrounding context
- // is the number of root parameters consumed.
- //
- objectCounts.rootParam = subObjectRange.layout->getTotalRootTableParameterCount();
- }
- break;
+ // In contrast to a constant buffer, a parameter block can hide
+ // the resource and sampler descriptor allocation it uses (since they
+ // are allocated into the tables that make up the parameter block.
+ //
+ // The only resource usage that leaks into the surrounding context
+ // is the number of root parameters consumed.
+ //
+ objectCounts.rootParam = subObjectRange.layout->getTotalRootTableParameterCount();
+ }
+ break;
case slang::BindingType::ExistentialValue:
// An unspecialized existential/interface value cannot consume any resources
@@ -446,7 +449,8 @@ void RootShaderObjectLayoutImpl::Builder::addGlobalParams(
}
void RootShaderObjectLayoutImpl::Builder::addEntryPoint(
- SlangStage stage, ShaderObjectLayoutImpl* entryPointLayout)
+ SlangStage stage,
+ ShaderObjectLayoutImpl* entryPointLayout)
{
EntryPointInfo info;
info.layout = entryPointLayout;
@@ -465,7 +469,8 @@ void RootShaderObjectLayoutImpl::Builder::addEntryPoint(
}
Result RootShaderObjectLayoutImpl::RootSignatureDescBuilder::translateDescriptorRangeType(
- slang::BindingType c, D3D12_DESCRIPTOR_RANGE_TYPE* outType)
+ slang::BindingType c,
+ D3D12_DESCRIPTOR_RANGE_TYPE* outType)
{
switch (c)
{
@@ -486,8 +491,7 @@ Result RootShaderObjectLayoutImpl::RootSignatureDescBuilder::translateDescriptor
case slang::BindingType::Sampler:
*outType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
return SLANG_OK;
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
}
}
@@ -592,11 +596,14 @@ Result RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addDescriptorRange(
bool isRootParameter)
{
auto bindingType = typeLayout->getDescriptorSetDescriptorRangeType(
- logicalDescriptorSetIndex, descriptorRangeIndex);
+ logicalDescriptorSetIndex,
+ descriptorRangeIndex);
auto count = typeLayout->getDescriptorSetDescriptorRangeDescriptorCount(
- logicalDescriptorSetIndex, descriptorRangeIndex);
+ logicalDescriptorSetIndex,
+ descriptorRangeIndex);
auto index = typeLayout->getDescriptorSetDescriptorRangeIndexOffset(
- logicalDescriptorSetIndex, descriptorRangeIndex);
+ logicalDescriptorSetIndex,
+ descriptorRangeIndex);
auto space = typeLayout->getDescriptorSetSpaceOffset(logicalDescriptorSetIndex);
D3D12_DESCRIPTOR_RANGE_TYPE rangeType;
@@ -662,7 +669,8 @@ void RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addBindingRange(
}
void RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addAsValue(
- slang::VariableLayoutReflection* varLayout, Index physicalDescriptorSetIndex)
+ slang::VariableLayoutReflection* varLayout,
+ Index physicalDescriptorSetIndex)
{
BindingRegisterOffsetPair offset(varLayout);
auto elementOffset = offset;
@@ -697,7 +705,8 @@ void RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addAsConstantBuffer(
if (typeLayout->getSize(SLANG_PARAMETER_CATEGORY_UNIFORM) != 0)
{
auto descriptorRangeType = D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
- auto& offsetForRangeType = offsetForOrdinaryChildren.primary.offsetForRangeType[descriptorRangeType];
+ auto& offsetForRangeType =
+ offsetForOrdinaryChildren.primary.offsetForRangeType[descriptorRangeType];
addDescriptorRange(
physicalDescriptorSetIndex,
descriptorRangeType,
@@ -708,7 +717,11 @@ void RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addAsConstantBuffer(
offsetForRangeType++;
}
- addAsValue(typeLayout, physicalDescriptorSetIndex, offsetForChildrenThatNeedNewSpace, offsetForOrdinaryChildren);
+ addAsValue(
+ typeLayout,
+ physicalDescriptorSetIndex,
+ offsetForChildrenThatNeedNewSpace,
+ offsetForOrdinaryChildren);
}
void RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addAsValue(
@@ -735,11 +748,9 @@ void RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addAsValue(
{
case slang::BindingType::ConstantBuffer:
case slang::BindingType::ParameterBlock:
- case slang::BindingType::ExistentialValue:
- continue;
+ case slang::BindingType::ExistentialValue: continue;
- default:
- break;
+ default: break;
}
// For binding ranges that don't represent sub-objects, we will add
@@ -756,7 +767,7 @@ void RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addAsValue(
// Next we need to recursively include everything bound via sub-objects
Index subObjectRangeCount = typeLayout->getSubObjectRangeCount();
for (Index subObjectRangeIndex = 0; subObjectRangeIndex < subObjectRangeCount;
- subObjectRangeIndex++)
+ subObjectRangeIndex++)
{
auto bindingRangeIndex =
typeLayout->getSubObjectRangeBindingRangeIndex(subObjectRangeIndex);
@@ -776,86 +787,90 @@ void RootShaderObjectLayoutImpl::RootSignatureDescBuilder::addAsValue(
switch (bindingType)
{
case slang::BindingType::ConstantBuffer:
- {
- auto containerVarLayout = subObjectTypeLayout->getContainerVarLayout();
- SLANG_ASSERT(containerVarLayout);
+ {
+ auto containerVarLayout = subObjectTypeLayout->getContainerVarLayout();
+ SLANG_ASSERT(containerVarLayout);
- auto elementVarLayout = subObjectTypeLayout->getElementVarLayout();
- SLANG_ASSERT(elementVarLayout);
+ auto elementVarLayout = subObjectTypeLayout->getElementVarLayout();
+ SLANG_ASSERT(elementVarLayout);
- auto elementTypeLayout = elementVarLayout->getTypeLayout();
- SLANG_ASSERT(elementTypeLayout);
+ auto elementTypeLayout = elementVarLayout->getTypeLayout();
+ SLANG_ASSERT(elementTypeLayout);
- BindingRegisterOffsetPair containerOffset = subObjectRangeContainerOffset;
- containerOffset += BindingRegisterOffsetPair(containerVarLayout);
+ BindingRegisterOffsetPair containerOffset = subObjectRangeContainerOffset;
+ containerOffset += BindingRegisterOffsetPair(containerVarLayout);
- BindingRegisterOffsetPair elementOffset = subObjectRangeElementOffset;
- elementOffset += BindingRegisterOffsetPair(elementVarLayout);
+ BindingRegisterOffsetPair elementOffset = subObjectRangeElementOffset;
+ elementOffset += BindingRegisterOffsetPair(elementVarLayout);
- addAsConstantBuffer(
- elementTypeLayout, physicalDescriptorSetIndex, containerOffset, elementOffset);
- }
- break;
+ addAsConstantBuffer(
+ elementTypeLayout,
+ physicalDescriptorSetIndex,
+ containerOffset,
+ elementOffset);
+ }
+ break;
case slang::BindingType::ParameterBlock:
- {
- auto containerVarLayout = subObjectTypeLayout->getContainerVarLayout();
- SLANG_ASSERT(containerVarLayout);
-
- auto elementVarLayout = subObjectTypeLayout->getElementVarLayout();
- SLANG_ASSERT(elementVarLayout);
-
- auto elementTypeLayout = elementVarLayout->getTypeLayout();
- SLANG_ASSERT(elementTypeLayout);
-
- BindingRegisterOffsetPair subDescriptorSetOffset;
- subDescriptorSetOffset.primary.spaceOffset =
- subObjectRangeContainerOffset.primary.spaceOffset;
- subDescriptorSetOffset.pending.spaceOffset =
- subObjectRangeContainerOffset.pending.spaceOffset;
-
- auto subPhysicalDescriptorSetIndex = addDescriptorSet();
-
- // We recursively call `addAsConstantBuffer` to actually generate
- // the root signature bindings for children in the parameter block.
- // We must compute `containerOffset`, which include a space offset
- // that any sub ParameterBlocks should start from, and `elementOffset`
- // that encodes the space offset of the current parameter block.
- // The space offset of the current parameter block can be obtained from the
- // `containerVarLayout`, and the space offset of any sub ParameterBlocks
- // are obatined from `elementVarLayout`.
- BindingRegisterOffsetPair offsetForChildrenThatNeedNewSpace = subDescriptorSetOffset;
- offsetForChildrenThatNeedNewSpace += BindingRegisterOffsetPair(elementVarLayout);
- BindingRegisterOffsetPair offsetForOrindaryChildren = subDescriptorSetOffset;
- offsetForOrindaryChildren += BindingRegisterOffsetPair(containerVarLayout);
-
- addAsConstantBuffer(
- elementTypeLayout,
- subPhysicalDescriptorSetIndex,
- offsetForChildrenThatNeedNewSpace,
- offsetForOrindaryChildren);
- }
- break;
+ {
+ auto containerVarLayout = subObjectTypeLayout->getContainerVarLayout();
+ SLANG_ASSERT(containerVarLayout);
+
+ auto elementVarLayout = subObjectTypeLayout->getElementVarLayout();
+ SLANG_ASSERT(elementVarLayout);
+
+ auto elementTypeLayout = elementVarLayout->getTypeLayout();
+ SLANG_ASSERT(elementTypeLayout);
+
+ BindingRegisterOffsetPair subDescriptorSetOffset;
+ subDescriptorSetOffset.primary.spaceOffset =
+ subObjectRangeContainerOffset.primary.spaceOffset;
+ subDescriptorSetOffset.pending.spaceOffset =
+ subObjectRangeContainerOffset.pending.spaceOffset;
+
+ auto subPhysicalDescriptorSetIndex = addDescriptorSet();
+
+ // We recursively call `addAsConstantBuffer` to actually generate
+ // the root signature bindings for children in the parameter block.
+ // We must compute `containerOffset`, which include a space offset
+ // that any sub ParameterBlocks should start from, and `elementOffset`
+ // that encodes the space offset of the current parameter block.
+ // The space offset of the current parameter block can be obtained from the
+ // `containerVarLayout`, and the space offset of any sub ParameterBlocks
+ // are obatined from `elementVarLayout`.
+ BindingRegisterOffsetPair offsetForChildrenThatNeedNewSpace =
+ subDescriptorSetOffset;
+ offsetForChildrenThatNeedNewSpace += BindingRegisterOffsetPair(elementVarLayout);
+ BindingRegisterOffsetPair offsetForOrindaryChildren = subDescriptorSetOffset;
+ offsetForOrindaryChildren += BindingRegisterOffsetPair(containerVarLayout);
+
+ addAsConstantBuffer(
+ elementTypeLayout,
+ subPhysicalDescriptorSetIndex,
+ offsetForChildrenThatNeedNewSpace,
+ offsetForOrindaryChildren);
+ }
+ break;
case slang::BindingType::ExistentialValue:
- {
- // Any nested binding ranges in the sub-object will "leak" into the
- // binding ranges for the surrounding context.
- //
- auto specializedTypeLayout = subObjectTypeLayout->getPendingDataTypeLayout();
- if (specializedTypeLayout)
{
- BindingRegisterOffsetPair pendingOffset;
- pendingOffset.primary = subObjectRangeElementOffset.pending;
-
- addAsValue(
- specializedTypeLayout,
- physicalDescriptorSetIndex,
- pendingOffset,
- pendingOffset);
+ // Any nested binding ranges in the sub-object will "leak" into the
+ // binding ranges for the surrounding context.
+ //
+ auto specializedTypeLayout = subObjectTypeLayout->getPendingDataTypeLayout();
+ if (specializedTypeLayout)
+ {
+ BindingRegisterOffsetPair pendingOffset;
+ pendingOffset.primary = subObjectRangeElementOffset.pending;
+
+ addAsValue(
+ specializedTypeLayout,
+ physicalDescriptorSetIndex,
+ pendingOffset,
+ pendingOffset);
+ }
}
- }
- break;
+ break;
}
}
}
@@ -957,9 +972,9 @@ Result RootShaderObjectLayoutImpl::createRootSignatureFromSlang(
ComPtr<ID3DBlob> signature;
ComPtr<ID3DBlob> error;
if (SLANG_FAILED(device->m_D3D12SerializeVersionedRootSignature(
- &versionedDesc,
- signature.writeRef(),
- error.writeRef())))
+ &versionedDesc,
+ signature.writeRef(),
+ error.writeRef())))
{
getDebugCallback()->handleMessage(
DebugMessageType::Error,
@@ -1001,7 +1016,10 @@ Result RootShaderObjectLayoutImpl::create(
auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
RefPtr<ShaderObjectLayoutImpl> entryPointLayout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- device, program->getSession(), slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
+ device,
+ program->getSession(),
+ slangEntryPoint->getTypeLayout(),
+ entryPointLayout.writeRef()));
builder.addEntryPoint(slangEntryPoint->getStage(), entryPointLayout);
}
@@ -1017,7 +1035,11 @@ Result RootShaderObjectLayoutImpl::create(
// We build out this array along with root signature construction and store
// it in `m_gpuDescriptorSetInfos`.
SLANG_RETURN_ON_FAIL(createRootSignatureFromSlang(
- device, layout, program, layout->m_rootSignature.writeRef(), outError));
+ device,
+ layout,
+ program,
+ layout->m_rootSignature.writeRef(),
+ outError));
}
*outLayout = layout.detach();
diff --git a/tools/gfx/d3d12/d3d12-shader-object-layout.h b/tools/gfx/d3d12/d3d12-shader-object-layout.h
index 2b27a1d98..c6219d1a2 100644
--- a/tools/gfx/d3d12/d3d12-shader-object-layout.h
+++ b/tools/gfx/d3d12/d3d12-shader-object-layout.h
@@ -71,7 +71,8 @@ public:
bool isRootParameter;
- /// Is this binding range represent a specialization point, such as an existential value, or a `ParameterBlock<IFoo>`.
+ /// Is this binding range represent a specialization point, such as an existential value, or
+ /// a `ParameterBlock<IFoo>`.
bool isSpecializable;
};
@@ -129,7 +130,8 @@ public:
public:
Builder(RendererBase* renderer, slang::ISession* session)
: m_renderer(renderer), m_session(session)
- {}
+ {
+ }
RendererBase* m_renderer;
slang::ISession* m_session;
@@ -246,7 +248,8 @@ public:
: Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
- {}
+ {
+ }
Result build(RootShaderObjectLayoutImpl** outLayout);
@@ -277,7 +280,8 @@ public:
RootSignatureDescBuilder(DeviceImpl* device)
: m_device(device)
- {}
+ {
+ }
// We will use one descriptor set for the global scope and one additional
// descriptor set for each `ParameterBlock` binding range in the shader object
@@ -289,7 +293,8 @@ public:
D3D12_ROOT_SIGNATURE_DESC1 m_rootSignatureDesc = {};
static Result translateDescriptorRangeType(
- slang::BindingType c, D3D12_DESCRIPTOR_RANGE_TYPE* outType);
+ slang::BindingType c,
+ D3D12_DESCRIPTOR_RANGE_TYPE* outType);
/// Stores offset information to apply to the reflected register/space for a descriptor
/// range.
@@ -309,7 +314,7 @@ public:
/// Note that the `D3D12_DESCRIPTOR_RANGE_TYPE` enumeration has
/// values between 0 and 3, inclusive.
///
- uint32_t offsetForRangeType[kRangeTypeCount] = { 0, 0, 0, 0 };
+ uint32_t offsetForRangeType[kRangeTypeCount] = {0, 0, 0, 0};
uint32_t& operator[](D3D12_DESCRIPTOR_RANGE_TYPE type)
{
@@ -327,8 +332,8 @@ public:
{
if (varLayout)
{
- spaceOffset =
- (UINT)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_SUB_ELEMENT_REGISTER_SPACE);
+ spaceOffset = (UINT)varLayout->getOffset(
+ SLANG_PARAMETER_CATEGORY_SUB_ELEMENT_REGISTER_SPACE);
offsetForRangeType[D3D12_DESCRIPTOR_RANGE_TYPE_CBV] =
(UINT)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER);
offsetForRangeType[D3D12_DESCRIPTOR_RANGE_TYPE_SRV] =
@@ -358,9 +363,9 @@ public:
BindingRegisterOffsetPair() {}
BindingRegisterOffsetPair(slang::VariableLayoutReflection* varLayout)
- : primary(varLayout)
- , pending(varLayout->getPendingDataLayout())
- {}
+ : primary(varLayout), pending(varLayout->getPendingDataLayout())
+ {
+ }
void operator+=(BindingRegisterOffsetPair const& other)
{
@@ -433,7 +438,8 @@ public:
Index bindingRangeIndex);
void addAsValue(
- slang::VariableLayoutReflection* varLayout, Index physicalDescriptorSetIndex);
+ slang::VariableLayoutReflection* varLayout,
+ Index physicalDescriptorSetIndex);
/// Add binding ranges and parameter blocks to the root signature.
///
diff --git a/tools/gfx/d3d12/d3d12-shader-object.cpp b/tools/gfx/d3d12/d3d12-shader-object.cpp
index beb88b636..77d3553ba 100644
--- a/tools/gfx/d3d12/d3d12-shader-object.cpp
+++ b/tools/gfx/d3d12/d3d12-shader-object.cpp
@@ -4,13 +4,12 @@
#include "d3d12-buffer.h"
#include "d3d12-command-encoder.h"
#include "d3d12-device.h"
+#include "d3d12-helper-functions.h"
#include "d3d12-resource-views.h"
#include "d3d12-sampler.h"
#include "d3d12-shader-object-layout.h"
#include "d3d12-transient-heap.h"
-#include "d3d12-helper-functions.h"
-
namespace gfx
{
namespace d3d12
@@ -18,7 +17,10 @@ namespace d3d12
using namespace Slang;
-GfxCount ShaderObjectImpl::getEntryPointCount() { return 0; }
+GfxCount ShaderObjectImpl::getEntryPointCount()
+{
+ return 0;
+}
Result ShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
{
@@ -26,9 +28,15 @@ Result ShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryP
return SLANG_OK;
}
-const void* ShaderObjectImpl::getRawData() { return m_data.getBuffer(); }
+const void* ShaderObjectImpl::getRawData()
+{
+ return m_data.getBuffer();
+}
-Size ShaderObjectImpl::getSize() { return (Size)m_data.getCount(); }
+Size ShaderObjectImpl::getSize()
+{
+ return (Size)m_data.getCount();
+}
// TODO: Change Index to Offset/Size?
Result ShaderObjectImpl::setData(ShaderOffset const& inOffset, void const* data, size_t inSize)
@@ -97,7 +105,9 @@ Result ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* s
}
Result ShaderObjectImpl::setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler)
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler)
{
#if 0
if (offset.bindingRangeIndex < 0)
@@ -182,7 +192,7 @@ Result ShaderObjectImpl::init(
// freed while the object is still live.
//
// The doubling here is because any buffer resource could
- // have a counter buffer associated with it, which we
+ // have a counter buffer associated with it, which we
// also need to ensure isn't destroyed prematurely.
m_boundResources.setCount(resourceCount);
m_boundCounterResources.setCount(resourceCount);
@@ -354,7 +364,8 @@ bool ShaderObjectImpl::shouldAllocateConstantBuffer(TransientResourceHeapImpl* t
/// Ensure that the `m_ordinaryDataBuffer` has been created, if it is needed
Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(
- PipelineCommandEncoder* encoder, ShaderObjectLayoutImpl* specializedLayout)
+ PipelineCommandEncoder* encoder,
+ ShaderObjectLayoutImpl* specializedLayout)
{
// If data has been changed since last allocation/filling of constant buffer,
// we will need to allocate a new one.
@@ -385,7 +396,9 @@ Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(
//
auto alignedConstantBufferSize = D3DUtil::calcAligned(m_constantBufferSize, 256);
SLANG_RETURN_ON_FAIL(encoder->m_commandBuffer->m_transientHeap->allocateConstantBuffer(
- alignedConstantBufferSize, m_constantBufferWeakPtr, m_constantBufferOffset));
+ alignedConstantBufferSize,
+ m_constantBufferWeakPtr,
+ m_constantBufferOffset));
// Once the buffer is allocated, we can use `_writeOrdinaryData` to fill it in.
//
@@ -410,9 +423,9 @@ Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(
auto descriptorTable = m_descriptorSet.resourceTable;
D3D12_CONSTANT_BUFFER_VIEW_DESC viewDesc = {};
viewDesc.BufferLocation = static_cast<BufferResourceImpl*>(m_constantBufferWeakPtr)
- ->m_resource.getResource()
- ->GetGPUVirtualAddress() +
- m_constantBufferOffset;
+ ->m_resource.getResource()
+ ->GetGPUVirtualAddress() +
+ m_constantBufferOffset;
viewDesc.SizeInBytes = (UINT)alignedConstantBufferSize;
encoder->m_device->CreateConstantBufferView(&viewDesc, descriptorTable.getCpuHandle());
}
@@ -426,21 +439,22 @@ void ShaderObjectImpl::updateSubObjectsRecursive()
return;
auto& subObjectRanges = getLayout()->getSubObjectRanges();
for (Slang::Index subObjectRangeIndex = 0; subObjectRangeIndex < subObjectRanges.getCount();
- subObjectRangeIndex++)
+ subObjectRangeIndex++)
{
auto const& subObjectRange = subObjectRanges[subObjectRangeIndex];
auto const& bindingRange = getLayout()->getBindingRange(subObjectRange.bindingRangeIndex);
Slang::Index count = bindingRange.count;
for (Slang::Index subObjectIndexInRange = 0; subObjectIndexInRange < count;
- subObjectIndexInRange++)
+ subObjectIndexInRange++)
{
Slang::Index objectIndex = bindingRange.subObjectIndex + subObjectIndexInRange;
auto subObject = m_objects[objectIndex].Ptr();
if (!subObject)
continue;
subObject->updateSubObjectsRecursive();
- if (m_subObjectVersions.getCount() > objectIndex && m_subObjectVersions[objectIndex] != m_objects[objectIndex]->m_version)
+ if (m_subObjectVersions.getCount() > objectIndex &&
+ m_subObjectVersions[objectIndex] != m_objects[objectIndex]->m_version)
{
ShaderOffset offset;
offset.bindingRangeIndex = (GfxIndex)subObjectRange.bindingRangeIndex;
@@ -516,7 +530,8 @@ Result ShaderObjectImpl::prepareToBindAsParameterBlock(
// root parameter.
//
auto tableRootParamIndex = rootParamIndex++;
- context->pendingTableBindings->add(PendingDescriptorTableBinding{ tableRootParamIndex, table.getGpuHandle() });
+ context->pendingTableBindings->add(
+ PendingDescriptorTableBinding{tableRootParamIndex, table.getGpuHandle()});
}
if (auto descriptorCount = specializedLayout->getTotalSamplerDescriptorCount())
{
@@ -539,7 +554,8 @@ Result ShaderObjectImpl::prepareToBindAsParameterBlock(
// root parameter.
//
auto tableRootParamIndex = rootParamIndex++;
- context->pendingTableBindings->add(PendingDescriptorTableBinding{ tableRootParamIndex, table.getGpuHandle() });
+ context->pendingTableBindings->add(
+ PendingDescriptorTableBinding{tableRootParamIndex, table.getGpuHandle()});
}
return SLANG_OK;
@@ -553,16 +569,16 @@ bool ShaderObjectImpl::checkIfCachedDescriptorSetIsValidRecursive(BindingContext
return false;
if (m_cachedGPUDescriptorSet.resourceTable.getDescriptorCount() != 0 &&
m_cachedGPUDescriptorSet.resourceTable.m_heap.ptr.linearHeap->getHeap() !=
- m_cachedTransientHeap->getCurrentViewHeap().getHeap())
+ m_cachedTransientHeap->getCurrentViewHeap().getHeap())
return false;
if (m_cachedGPUDescriptorSet.samplerTable.getDescriptorCount() != 0 &&
m_cachedGPUDescriptorSet.samplerTable.m_heap.ptr.linearHeap->getHeap() !=
- m_cachedTransientHeap->getCurrentSamplerHeap().getHeap())
+ m_cachedTransientHeap->getCurrentSamplerHeap().getHeap())
return false;
auto& subObjectRanges = getLayout()->getSubObjectRanges();
for (Slang::Index subObjectRangeIndex = 0; subObjectRangeIndex < subObjectRanges.getCount();
- subObjectRangeIndex++)
+ subObjectRangeIndex++)
{
auto const& subObjectRange = subObjectRanges[subObjectRangeIndex];
auto const& bindingRange = getLayout()->getBindingRange(subObjectRange.bindingRangeIndex);
@@ -571,7 +587,7 @@ bool ShaderObjectImpl::checkIfCachedDescriptorSetIsValidRecursive(BindingContext
Slang::Index count = bindingRange.count;
for (Slang::Index subObjectIndexInRange = 0; subObjectIndexInRange < count;
- subObjectIndexInRange++)
+ subObjectIndexInRange++)
{
Slang::Index objectIndex = bindingRange.subObjectIndex + subObjectIndexInRange;
auto subObject = m_objects[objectIndex].Ptr();
@@ -587,7 +603,9 @@ bool ShaderObjectImpl::checkIfCachedDescriptorSetIsValidRecursive(BindingContext
/// Bind this object as a `ParameterBlock<X>`
Result ShaderObjectImpl::bindAsParameterBlock(
- BindingContext* context, BindingOffset const& offset, ShaderObjectLayoutImpl* specializedLayout)
+ BindingContext* context,
+ BindingOffset const& offset,
+ ShaderObjectLayoutImpl* specializedLayout)
{
if (checkIfCachedDescriptorSetIsValidRecursive(context))
{
@@ -598,13 +616,15 @@ Result ShaderObjectImpl::bindAsParameterBlock(
{
auto tableRootParamIndex = rootParamIndex++;
context->submitter->setRootDescriptorTable(
- tableRootParamIndex, m_cachedGPUDescriptorSet.resourceTable.getGpuHandle());
+ tableRootParamIndex,
+ m_cachedGPUDescriptorSet.resourceTable.getGpuHandle());
}
if (m_cachedGPUDescriptorSet.samplerTable.getDescriptorCount())
{
auto tableRootParamIndex = rootParamIndex++;
context->submitter->setRootDescriptorTable(
- tableRootParamIndex, m_cachedGPUDescriptorSet.samplerTable.getGpuHandle());
+ tableRootParamIndex,
+ m_cachedGPUDescriptorSet.samplerTable.getGpuHandle());
}
return SLANG_OK;
}
@@ -619,7 +639,10 @@ Result ShaderObjectImpl::bindAsParameterBlock(
context->pendingTableBindings = &pendingTableBindings;
SLANG_RETURN_ON_FAIL(prepareToBindAsParameterBlock(
- context, /* inout */ subOffset, specializedLayout, m_cachedGPUDescriptorSet));
+ context,
+ /* inout */ subOffset,
+ specializedLayout,
+ m_cachedGPUDescriptorSet));
// Next we bind the object into that descriptor set as if it were being used
// as a `ConstantBuffer<X>`.
@@ -766,30 +789,33 @@ Result ShaderObjectImpl::_bindImpl(
switch (bindingRange.bindingType)
{
case slang::BindingType::ConstantBuffer:
- {
- auto objOffset = rangeOffset;
- for (uint32_t j = 0; j < bindingRange.count; j++)
{
- auto& object = m_objects[subObjectIndex + j];
- SLANG_RETURN_ON_FAIL(object->bindAsConstantBuffer(
- context, descriptorSet, objOffset, subObjectLayout));
- objOffset += rangeStride;
+ auto objOffset = rangeOffset;
+ for (uint32_t j = 0; j < bindingRange.count; j++)
+ {
+ auto& object = m_objects[subObjectIndex + j];
+ SLANG_RETURN_ON_FAIL(object->bindAsConstantBuffer(
+ context,
+ descriptorSet,
+ objOffset,
+ subObjectLayout));
+ objOffset += rangeStride;
+ }
}
- }
- break;
+ break;
case slang::BindingType::ParameterBlock:
- {
- auto objOffset = rangeOffset;
- for (uint32_t j = 0; j < bindingRange.count; j++)
{
- auto& object = m_objects[subObjectIndex + j];
- SLANG_RETURN_ON_FAIL(
- object->bindAsParameterBlock(context, objOffset, subObjectLayout));
- objOffset += rangeStride;
+ auto objOffset = rangeOffset;
+ for (uint32_t j = 0; j < bindingRange.count; j++)
+ {
+ auto& object = m_objects[subObjectIndex + j];
+ SLANG_RETURN_ON_FAIL(
+ object->bindAsParameterBlock(context, objOffset, subObjectLayout));
+ objOffset += rangeStride;
+ }
}
- }
- break;
+ break;
case slang::BindingType::ExistentialValue:
if (subObjectLayout)
@@ -824,8 +850,7 @@ Result ShaderObjectImpl::bindRootArguments(BindingContext* context, uint32_t& in
case IResourceView::Type::UnorderedAccess:
context->submitter->setRootUAV(index, m_rootArguments[i]);
break;
- default:
- continue;
+ default: continue;
}
index++;
}
@@ -897,31 +922,31 @@ Result ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView*
switch (resourceView->getViewDesc()->type)
{
case IResourceView::Type::AccelerationStructure:
- {
- auto resourceViewImpl = static_cast<AccelerationStructureImpl*>(resourceView);
- rootArg = resourceViewImpl->getDeviceAddress();
- }
- break;
- case IResourceView::Type::ShaderResource:
- case IResourceView::Type::UnorderedAccess:
- {
- auto resourceViewImpl = static_cast<ResourceViewImpl*>(resourceView);
- if (resourceViewImpl->m_resource->isBuffer())
{
- rootArg = static_cast<BufferResourceImpl*>(resourceViewImpl->m_resource.Ptr())
- ->getDeviceAddress();
+ auto resourceViewImpl = static_cast<AccelerationStructureImpl*>(resourceView);
+ rootArg = resourceViewImpl->getDeviceAddress();
}
- else
+ break;
+ case IResourceView::Type::ShaderResource:
+ case IResourceView::Type::UnorderedAccess:
{
- getDebugCallback()->handleMessage(
- DebugMessageType::Error,
- DebugMessageSource::Layer,
- "The shader parameter at the specified offset is a root parameter, and "
- "therefore can only be a buffer view.");
- return SLANG_FAIL;
+ auto resourceViewImpl = static_cast<ResourceViewImpl*>(resourceView);
+ if (resourceViewImpl->m_resource->isBuffer())
+ {
+ rootArg = static_cast<BufferResourceImpl*>(resourceViewImpl->m_resource.Ptr())
+ ->getDeviceAddress();
+ }
+ else
+ {
+ getDebugCallback()->handleMessage(
+ DebugMessageType::Error,
+ DebugMessageSource::Layer,
+ "The shader parameter at the specified offset is a root parameter, and "
+ "therefore can only be a buffer view.");
+ return SLANG_FAIL;
+ }
}
- }
- break;
+ break;
}
return SLANG_OK;
}
@@ -945,23 +970,23 @@ Result ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView*
{
#if SLANG_GFX_HAS_DXR_SUPPORT
case IResourceView::Type::AccelerationStructure:
- {
- auto asImpl = static_cast<AccelerationStructureImpl*>(resourceView);
- // Hold a reference to the resource to prevent its destruction.
- m_boundResources[bindingRange.baseIndex + offset.bindingArrayIndex] = asImpl->m_buffer;
- internalResourceView = asImpl;
- }
- break;
+ {
+ auto asImpl = static_cast<AccelerationStructureImpl*>(resourceView);
+ // Hold a reference to the resource to prevent its destruction.
+ m_boundResources[bindingRange.baseIndex + offset.bindingArrayIndex] = asImpl->m_buffer;
+ internalResourceView = asImpl;
+ }
+ break;
#endif
default:
- {
- // Hold a reference to the resource to prevent its destruction.
- const auto resourceOffset = bindingRange.baseIndex + offset.bindingArrayIndex;
- m_boundResources[resourceOffset] = resourceViewImpl->m_resource;
- m_boundCounterResources[resourceOffset] = resourceViewImpl->m_counterResource;
- internalResourceView = resourceViewImpl;
- }
- break;
+ {
+ // Hold a reference to the resource to prevent its destruction.
+ const auto resourceOffset = bindingRange.baseIndex + offset.bindingArrayIndex;
+ m_boundResources[resourceOffset] = resourceViewImpl->m_resource;
+ m_boundCounterResources[resourceOffset] = resourceViewImpl->m_counterResource;
+ internalResourceView = resourceViewImpl;
+ }
+ break;
}
auto descriptorSlotIndex = bindingRange.baseIndex + (int32_t)offset.bindingArrayIndex;
@@ -999,7 +1024,9 @@ Result ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView*
}
Result ShaderObjectImpl::create(
- DeviceImpl* device, ShaderObjectLayoutImpl* layout, ShaderObjectImpl** outShaderObject)
+ DeviceImpl* device,
+ ShaderObjectLayoutImpl* layout,
+ ShaderObjectImpl** outShaderObject)
{
auto object = RefPtr<ShaderObjectImpl>(new ShaderObjectImpl());
SLANG_RETURN_ON_FAIL(
@@ -1008,14 +1035,20 @@ Result ShaderObjectImpl::create(
return SLANG_OK;
}
-ShaderObjectImpl::~ShaderObjectImpl() { m_descriptorSet.freeIfSupported(); }
+ShaderObjectImpl::~ShaderObjectImpl()
+{
+ m_descriptorSet.freeIfSupported();
+}
RootShaderObjectLayoutImpl* RootShaderObjectImpl::getLayout()
{
return static_cast<RootShaderObjectLayoutImpl*>(m_layout.Ptr());
}
-GfxCount RootShaderObjectImpl::getEntryPointCount() { return (GfxCount)m_entryPoints.getCount(); }
+GfxCount RootShaderObjectImpl::getEntryPointCount()
+{
+ return (GfxCount)m_entryPoints.getCount();
+}
SlangResult RootShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
{
@@ -1141,7 +1174,8 @@ Result RootShaderObjectImpl::copyFrom(IShaderObject* object, ITransientResourceH
}
Result RootShaderObjectImpl::bindAsRoot(
- BindingContext* context, RootShaderObjectLayoutImpl* specializedLayout)
+ BindingContext* context,
+ RootShaderObjectLayoutImpl* specializedLayout)
{
// Pull updates from sub-objects when this is a mutable root shader object.
updateSubObjectsRecursive();
@@ -1159,13 +1193,16 @@ Result RootShaderObjectImpl::bindAsRoot(
context->pendingTableBindings = &pendingTableBindings;
BindingOffset rootOffset;
-
+
// Bind all root parameters first.
Super::bindRootArguments(context, rootOffset.rootParam);
DescriptorSet descriptorSet;
SLANG_RETURN_ON_FAIL(prepareToBindAsParameterBlock(
- context, /* inout */ rootOffset, specializedLayout, descriptorSet));
+ context,
+ /* inout */ rootOffset,
+ specializedLayout,
+ descriptorSet));
SLANG_RETURN_ON_FAIL(
Super::bindAsConstantBuffer(context, descriptorSet, rootOffset, specializedLayout));
@@ -1182,7 +1219,10 @@ Result RootShaderObjectImpl::bindAsRoot(
entryPoint->updateSubObjectsRecursive();
SLANG_RETURN_ON_FAIL(entryPoint->bindAsConstantBuffer(
- context, descriptorSet, entryPointOffset, entryPointInfo.layout));
+ context,
+ descriptorSet,
+ entryPointOffset,
+ entryPointInfo.layout));
}
bindPendingTables(context);
@@ -1214,10 +1254,16 @@ Result RootShaderObjectImpl::resetImpl(
}
Result RootShaderObjectImpl::reset(
- DeviceImpl* device, RootShaderObjectLayoutImpl* layout, TransientResourceHeapImpl* heap)
+ DeviceImpl* device,
+ RootShaderObjectLayoutImpl* layout,
+ TransientResourceHeapImpl* heap)
{
return resetImpl(
- device, layout, &heap->m_stagingCpuViewHeap, &heap->m_stagingCpuSamplerHeap, false);
+ device,
+ layout,
+ &heap->m_stagingCpuViewHeap,
+ &heap->m_stagingCpuSamplerHeap,
+ false);
}
} // namespace d3d12
diff --git a/tools/gfx/d3d12/d3d12-shader-object.h b/tools/gfx/d3d12/d3d12-shader-object.h
index 6251a970c..f0276fa7f 100644
--- a/tools/gfx/d3d12/d3d12-shader-object.h
+++ b/tools/gfx/d3d12/d3d12-shader-object.h
@@ -88,7 +88,9 @@ class ShaderObjectImpl
public:
static Result create(
- DeviceImpl* device, ShaderObjectLayoutImpl* layout, ShaderObjectImpl** outShaderObject);
+ DeviceImpl* device,
+ ShaderObjectLayoutImpl* layout,
+ ShaderObjectImpl** outShaderObject);
~ShaderObjectImpl();
@@ -97,7 +99,7 @@ public:
virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override;
@@ -105,18 +107,20 @@ public:
// TODO: What to do with size_t?
virtual SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& inOffset, void const* data, size_t inSize) override;
+ setData(ShaderOffset const& inOffset, void const* data, size_t inSize) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setObject(ShaderOffset const& offset, IShaderObject* object) override;
+ setObject(ShaderOffset const& offset, IShaderObject* object) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) override;
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) override;
protected:
Result init(
@@ -138,7 +142,8 @@ protected:
/// Ensure that the `m_ordinaryDataBuffer` has been created, if it is needed
Result _ensureOrdinaryDataBufferCreatedIfNeeded(
- PipelineCommandEncoder* encoder, ShaderObjectLayoutImpl* specializedLayout);
+ PipelineCommandEncoder* encoder,
+ ShaderObjectLayoutImpl* specializedLayout);
public:
void updateSubObjectsRecursive();
@@ -255,10 +260,10 @@ public:
virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- copyFrom(IShaderObject* object, ITransientResourceHeap* transientHeap) override;
+ copyFrom(IShaderObject* object, ITransientResourceHeap* transientHeap) override;
public:
Result bindAsRoot(BindingContext* context, RootShaderObjectLayoutImpl* specializedLayout);
@@ -274,7 +279,9 @@ public:
bool isMutable);
Result reset(
- DeviceImpl* device, RootShaderObjectLayoutImpl* layout, TransientResourceHeapImpl* heap);
+ DeviceImpl* device,
+ RootShaderObjectLayoutImpl* layout,
+ TransientResourceHeapImpl* heap);
protected:
virtual Result _createSpecializedLayout(ShaderObjectLayoutImpl** outLayout) override;
diff --git a/tools/gfx/d3d12/d3d12-shader-program.cpp b/tools/gfx/d3d12/d3d12-shader-program.cpp
index f2476232c..a39f20465 100644
--- a/tools/gfx/d3d12/d3d12-shader-program.cpp
+++ b/tools/gfx/d3d12/d3d12-shader-program.cpp
@@ -9,7 +9,8 @@ namespace d3d12
using namespace Slang;
Result ShaderProgramImpl::createShaderModule(
- slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode)
+ slang::EntryPointReflection* entryPointInfo,
+ ComPtr<ISlangBlob> kernelCode)
{
ShaderBinary shaderBin;
shaderBin.stage = entryPointInfo->getStage();
diff --git a/tools/gfx/d3d12/d3d12-shader-program.h b/tools/gfx/d3d12/d3d12-shader-program.h
index eafa898fe..669bce960 100644
--- a/tools/gfx/d3d12/d3d12-shader-program.h
+++ b/tools/gfx/d3d12/d3d12-shader-program.h
@@ -26,7 +26,8 @@ public:
List<ShaderBinary> m_shaders;
virtual Result createShaderModule(
- slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode) override;
+ slang::EntryPointReflection* entryPointInfo,
+ ComPtr<ISlangBlob> kernelCode) override;
};
} // namespace d3d12
diff --git a/tools/gfx/d3d12/d3d12-shader-table.cpp b/tools/gfx/d3d12/d3d12-shader-table.cpp
index f54b7c5e9..be537c737 100644
--- a/tools/gfx/d3d12/d3d12-shader-table.cpp
+++ b/tools/gfx/d3d12/d3d12-shader-table.cpp
@@ -24,9 +24,11 @@ RefPtr<BufferResource> ShaderTableImpl::createDeviceBuffer(
m_rayGenTableOffset = 0;
m_missTableOffset = raygenTableSize;
m_hitGroupTableOffset = (uint32_t)D3DUtil::calcAligned(
- m_missTableOffset + missTableSize, D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT);
+ m_missTableOffset + missTableSize,
+ D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT);
m_callableTableOffset = (uint32_t)D3DUtil::calcAligned(
- m_hitGroupTableOffset + hitgroupTableSize, D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT);
+ m_hitGroupTableOffset + hitgroupTableSize,
+ D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT);
uint32_t tableSize = m_callableTableOffset + callableTableSize;
auto pipelineImpl = static_cast<RayTracingPipelineStateImpl*>(pipeline);
@@ -47,8 +49,8 @@ RefPtr<BufferResource> ShaderTableImpl::createDeviceBuffer(
IBufferResource* stagingBuffer = nullptr;
Offset stagingBufferOffset = 0;
- transientHeapImpl->allocateStagingBuffer(
- tableSize, stagingBuffer, stagingBufferOffset, MemoryType::Upload);
+ transientHeapImpl
+ ->allocateStagingBuffer(tableSize, stagingBuffer, stagingBufferOffset, MemoryType::Upload);
assert(stagingBuffer);
void* stagingPtr = nullptr;
diff --git a/tools/gfx/d3d12/d3d12-submitter.cpp b/tools/gfx/d3d12/d3d12-submitter.cpp
index 0abd21d70..2870d8836 100644
--- a/tools/gfx/d3d12/d3d12-submitter.cpp
+++ b/tools/gfx/d3d12/d3d12-submitter.cpp
@@ -11,7 +11,8 @@ namespace d3d12
using namespace Slang;
void GraphicsSubmitter::setRootConstantBufferView(
- int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation)
+ int index,
+ D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation)
{
m_commandList->SetGraphicsRootConstantBufferView(index, gpuBufferLocation);
}
@@ -27,7 +28,8 @@ void GraphicsSubmitter::setRootSRV(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBuffe
}
void GraphicsSubmitter::setRootDescriptorTable(
- int index, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor)
+ int index,
+ D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor)
{
m_commandList->SetGraphicsRootDescriptorTable(index, baseDescriptor);
}
@@ -44,7 +46,10 @@ void GraphicsSubmitter::setRootConstants(
void const* srcData)
{
m_commandList->SetGraphicsRoot32BitConstants(
- UINT(rootParamIndex), UINT(countOf32BitValues), srcData, UINT(dstOffsetIn32BitValues));
+ UINT(rootParamIndex),
+ UINT(countOf32BitValues),
+ srcData,
+ UINT(dstOffsetIn32BitValues));
}
void GraphicsSubmitter::setPipelineState(PipelineStateBase* pipeline)
@@ -54,7 +59,8 @@ void GraphicsSubmitter::setPipelineState(PipelineStateBase* pipeline)
}
void ComputeSubmitter::setRootConstantBufferView(
- int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation)
+ int index,
+ D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation)
{
m_commandList->SetComputeRootConstantBufferView(index, gpuBufferLocation);
}
@@ -69,8 +75,7 @@ void ComputeSubmitter::setRootSRV(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBuffer
m_commandList->SetComputeRootShaderResourceView(index, gpuBufferLocation);
}
-void ComputeSubmitter::setRootDescriptorTable(
- int index, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor)
+void ComputeSubmitter::setRootDescriptorTable(int index, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor)
{
m_commandList->SetComputeRootDescriptorTable(index, baseDescriptor);
}
@@ -87,7 +92,10 @@ void ComputeSubmitter::setRootConstants(
void const* srcData)
{
m_commandList->SetComputeRoot32BitConstants(
- UINT(rootParamIndex), UINT(countOf32BitValues), srcData, UINT(dstOffsetIn32BitValues));
+ UINT(rootParamIndex),
+ UINT(countOf32BitValues),
+ srcData,
+ UINT(dstOffsetIn32BitValues));
}
void ComputeSubmitter::setPipelineState(PipelineStateBase* pipeline)
diff --git a/tools/gfx/d3d12/d3d12-submitter.h b/tools/gfx/d3d12/d3d12-submitter.h
index 77c3f8c0d..3c605ad17 100644
--- a/tools/gfx/d3d12/d3d12-submitter.h
+++ b/tools/gfx/d3d12/d3d12-submitter.h
@@ -13,7 +13,8 @@ using namespace Slang;
struct Submitter
{
virtual void setRootConstantBufferView(
- int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) = 0;
+ int index,
+ D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) = 0;
virtual void setRootUAV(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) = 0;
virtual void setRootSRV(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) = 0;
virtual void setRootDescriptorTable(int index, D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor) = 0;
@@ -28,12 +29,12 @@ struct Submitter
struct GraphicsSubmitter : public Submitter
{
- virtual void setRootConstantBufferView(
- int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) override;
+ virtual void setRootConstantBufferView(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation)
+ override;
virtual void setRootUAV(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) override;
virtual void setRootSRV(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) override;
- virtual void setRootDescriptorTable(
- int index, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor) override;
+ virtual void setRootDescriptorTable(int index, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor)
+ override;
virtual void setRootSignature(ID3D12RootSignature* rootSignature) override;
virtual void setRootConstants(
Index rootParamIndex,
@@ -44,19 +45,20 @@ struct GraphicsSubmitter : public Submitter
GraphicsSubmitter(ID3D12GraphicsCommandList* commandList)
: m_commandList(commandList)
- {}
+ {
+ }
ID3D12GraphicsCommandList* m_commandList;
};
struct ComputeSubmitter : public Submitter
{
- virtual void setRootConstantBufferView(
- int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) override;
+ virtual void setRootConstantBufferView(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation)
+ override;
virtual void setRootUAV(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) override;
virtual void setRootSRV(int index, D3D12_GPU_VIRTUAL_ADDRESS gpuBufferLocation) override;
- virtual void setRootDescriptorTable(
- int index, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor) override;
+ virtual void setRootDescriptorTable(int index, D3D12_GPU_DESCRIPTOR_HANDLE baseDescriptor)
+ override;
virtual void setRootSignature(ID3D12RootSignature* rootSignature) override;
virtual void setRootConstants(
Index rootParamIndex,
@@ -66,7 +68,8 @@ struct ComputeSubmitter : public Submitter
virtual void setPipelineState(PipelineStateBase* pipeline) override;
ComputeSubmitter(ID3D12GraphicsCommandList* commandList)
: m_commandList(commandList)
- {}
+ {
+ }
ID3D12GraphicsCommandList* m_commandList;
};
diff --git a/tools/gfx/d3d12/d3d12-swap-chain.cpp b/tools/gfx/d3d12/d3d12-swap-chain.cpp
index 8d4e723ea..098156c90 100644
--- a/tools/gfx/d3d12/d3d12-swap-chain.cpp
+++ b/tools/gfx/d3d12/d3d12-swap-chain.cpp
@@ -13,13 +13,18 @@ namespace d3d12
using namespace Slang;
Result SwapchainImpl::init(
- DeviceImpl* renderer, const ISwapchain::Desc& swapchainDesc, WindowHandle window)
+ DeviceImpl* renderer,
+ const ISwapchain::Desc& swapchainDesc,
+ WindowHandle window)
{
m_queue = static_cast<CommandQueueImpl*>(swapchainDesc.queue)->m_d3dQueue;
m_dxgiFactory = renderer->m_deviceInfo.m_dxgiFactory;
SLANG_RETURN_ON_FAIL(
D3DSwapchainBase::init(swapchainDesc, window, DXGI_SWAP_EFFECT_FLIP_DISCARD));
- SLANG_RETURN_ON_FAIL(renderer->m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(m_fence.writeRef())));
+ SLANG_RETURN_ON_FAIL(renderer->m_device->CreateFence(
+ 0,
+ D3D12_FENCE_FLAG_NONE,
+ IID_PPV_ARGS(m_fence.writeRef())));
SLANG_RETURN_ON_FAIL(m_swapChain->QueryInterface(m_swapChain3.writeRef()));
for (GfxIndex i = 0; i < swapchainDesc.imageCount; i++)
@@ -51,7 +56,9 @@ void SwapchainImpl::createSwapchainBufferImages()
m_swapChain->GetBuffer(i, IID_PPV_ARGS(d3dResource.writeRef()));
ITextureResource::Desc imageDesc = {};
imageDesc.allowedStates = ResourceStateSet(
- ResourceState::Present, ResourceState::RenderTarget, ResourceState::CopyDestination);
+ ResourceState::Present,
+ ResourceState::RenderTarget,
+ ResourceState::CopyDestination);
imageDesc.type = IResource::Type::Texture2D;
imageDesc.arraySize = 0;
imageDesc.format = m_desc.format;
@@ -80,7 +87,8 @@ int SwapchainImpl::acquireNextImage()
Result SwapchainImpl::present()
{
m_fence->SetEventOnCompletion(
- fenceValue, m_frameEvents[m_swapChain3->GetCurrentBackBufferIndex()]);
+ fenceValue,
+ m_frameEvents[m_swapChain3->GetCurrentBackBufferIndex()]);
SLANG_RETURN_ON_FAIL(D3DSwapchainBase::present());
fenceValue++;
m_queue->Signal(m_fence, fenceValue);
diff --git a/tools/gfx/d3d12/d3d12-texture.cpp b/tools/gfx/d3d12/d3d12-texture.cpp
index 9f47760e5..fdd9aab1b 100644
--- a/tools/gfx/d3d12/d3d12-texture.cpp
+++ b/tools/gfx/d3d12/d3d12-texture.cpp
@@ -9,9 +9,9 @@ namespace d3d12
using namespace Slang;
TextureResourceImpl::TextureResourceImpl(const Desc& desc)
- : Parent(desc)
- , m_defaultState(D3DUtil::getResourceState(desc.defaultState))
-{}
+ : Parent(desc), m_defaultState(D3DUtil::getResourceState(desc.defaultState))
+{
+}
TextureResourceImpl::~TextureResourceImpl()
{
@@ -45,7 +45,11 @@ Result TextureResourceImpl::getSharedHandle(InteropHandle* outHandle)
auto pResource = m_resource.getResource();
pResource->GetDevice(IID_PPV_ARGS(pDevice.writeRef()));
SLANG_RETURN_ON_FAIL(pDevice->CreateSharedHandle(
- pResource, NULL, GENERIC_ALL, nullptr, (HANDLE*)&outHandle->handleValue));
+ pResource,
+ NULL,
+ GENERIC_ALL,
+ nullptr,
+ (HANDLE*)&outHandle->handleValue));
outHandle->api = InteropHandleAPI::D3D12;
return SLANG_OK;
#endif
diff --git a/tools/gfx/d3d12/d3d12-texture.h b/tools/gfx/d3d12/d3d12-texture.h
index 3f6ed398b..e8bc4aa66 100644
--- a/tools/gfx/d3d12/d3d12-texture.h
+++ b/tools/gfx/d3d12/d3d12-texture.h
@@ -23,7 +23,7 @@ public:
D3D12_RESOURCE_STATES m_defaultState;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeResourceHandle(InteropHandle* outHandle) override;
+ getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
diff --git a/tools/gfx/d3d12/d3d12-transient-heap.cpp b/tools/gfx/d3d12/d3d12-transient-heap.cpp
index 60f40cc66..92b4de544 100644
--- a/tools/gfx/d3d12/d3d12-transient-heap.cpp
+++ b/tools/gfx/d3d12/d3d12-transient-heap.cpp
@@ -1,9 +1,9 @@
// d3d12-transient-heap.cpp
#include "d3d12-transient-heap.h"
-#include "d3d12-device.h"
#include "d3d12-buffer.h"
#include "d3d12-command-buffer.h"
+#include "d3d12-device.h"
namespace gfx
{
@@ -15,7 +15,10 @@ using namespace Slang;
Result TransientResourceHeapImpl::synchronize()
{
WaitForMultipleObjects(
- (DWORD)m_waitHandles.getCount(), m_waitHandles.getArrayView().getBuffer(), TRUE, INFINITE);
+ (DWORD)m_waitHandles.getCount(),
+ m_waitHandles.getArrayView().getBuffer(),
+ TRUE,
+ INFINITE);
m_waitHandles.clear();
return SLANG_OK;
}
@@ -139,7 +142,8 @@ Result TransientResourceHeapImpl::init(
auto d3dDevice = device->m_device;
SLANG_RETURN_ON_FAIL(d3dDevice->CreateCommandAllocator(
- D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(m_commandAllocator.writeRef())));
+ D3D12_COMMAND_LIST_TYPE_DIRECT,
+ IID_PPV_ARGS(m_commandAllocator.writeRef())));
allocateNewViewDescriptorHeap(device);
allocateNewSamplerDescriptorHeap(device);
diff --git a/tools/gfx/d3d12/d3d12-transient-heap.h b/tools/gfx/d3d12/d3d12-transient-heap.h
index 6b05367e8..1986d6326 100644
--- a/tools/gfx/d3d12/d3d12-transient-heap.h
+++ b/tools/gfx/d3d12/d3d12-transient-heap.h
@@ -11,8 +11,8 @@ namespace d3d12
using namespace Slang;
class TransientResourceHeapImpl
- : public TransientResourceHeapBaseImpl<DeviceImpl, BufferResourceImpl>
- , public ITransientResourceHeapD3D12
+ : public TransientResourceHeapBaseImpl<DeviceImpl, BufferResourceImpl>,
+ public ITransientResourceHeapD3D12
{
private:
typedef TransientResourceHeapBaseImpl<DeviceImpl, BufferResourceImpl> Super;
@@ -39,7 +39,7 @@ public:
//
// We will thus keep a single heap of each type that we hope will hold
// all the descriptors that actually get needed in a frame.
- ShortList<D3D12DescriptorHeap, 4> m_viewHeaps; // Cbv, Srv, Uav
+ ShortList<D3D12DescriptorHeap, 4> m_viewHeaps; // Cbv, Srv, Uav
ShortList<D3D12DescriptorHeap, 4> m_samplerHeaps; // Heap for samplers
int32_t m_currentViewHeapIndex = -1;
int32_t m_currentSamplerHeapIndex = -1;
@@ -55,7 +55,7 @@ public:
D3D12LinearExpandingDescriptorHeap m_stagingCpuSamplerHeap;
virtual SLANG_NO_THROW Result SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject) override;
+ queryInterface(SlangUUID const& uuid, void** outObject) override;
virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return Super::addRef(); }
virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return Super::release(); }
@@ -81,7 +81,7 @@ public:
Result allocateNewSamplerDescriptorHeap(DeviceImpl* device);
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
+ createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
Result synchronize();
diff --git a/tools/gfx/debug-layer/debug-base.h b/tools/gfx/debug-layer/debug-base.h
index aa269cc7b..c235102c4 100644
--- a/tools/gfx/debug-layer/debug-base.h
+++ b/tools/gfx/debug-layer/debug-base.h
@@ -1,11 +1,11 @@
// debug-base.h
#pragma once
-#include "slang-gfx.h"
-#include "slang-com-ptr.h"
-#include "core/slang-com-object.h"
#include "../command-encoder-com-forward.h"
#include "../renderer-shared.h"
+#include "core/slang-com-object.h"
+#include "slang-com-ptr.h"
+#include "slang-gfx.h"
namespace gfx
{
@@ -14,61 +14,57 @@ using namespace Slang;
namespace debug
{
- class DebugObjectBase : public Slang::ComObject
+class DebugObjectBase : public Slang::ComObject
+{
+public:
+ uint64_t uid;
+ DebugObjectBase()
{
- public:
- uint64_t uid;
- DebugObjectBase()
- {
- static uint64_t uidCounter = 0;
- uid = ++uidCounter;
- }
- };
+ static uint64_t uidCounter = 0;
+ uid = ++uidCounter;
+ }
+};
- template<typename TInterface>
- class DebugObject
- : public TInterface
- , public DebugObjectBase
- {
- public:
- Slang::ComPtr<TInterface> baseObject;
- };
+template<typename TInterface>
+class DebugObject : public TInterface, public DebugObjectBase
+{
+public:
+ Slang::ComPtr<TInterface> baseObject;
+};
- template <typename TInterface>
- class UnownedDebugObject
- : public TInterface
- , public DebugObjectBase
- {
- public:
- TInterface* baseObject = nullptr;
- };
+template<typename TInterface>
+class UnownedDebugObject : public TInterface, public DebugObjectBase
+{
+public:
+ TInterface* baseObject = nullptr;
+};
- class DebugDevice;
- class DebugShaderTable;
- class DebugQueryPool;
- class DebugBufferResource;
- class DebugTextureResource;
- class DebugResourceView;
- class DebugAccelerationStructure;
- class DebugSamplerState;
- class DebugShaderObject;
- class DebugRootShaderObject;
- class DebugCommandBuffer;
- class DebugResourceCommandEncoderImpl;
- class DebugComputeCommandEncoder;
- class DebugResourceCommandEncoder;
- class DebugRenderCommandEncoder;
- class DebugRayTracingCommandEncoder;
- class DebugFence;
- class DebugCommandQueue;
- class DebugFramebuffer;
- class DebugFramebufferLayout;
- class DebugInputLayout;
- class DebugPipelineState;
- class DebugRenderPassLayout;
- class DebugShaderProgram;
- class DebugTransientResourceHeap;
- class DebugSwapchain;
+class DebugDevice;
+class DebugShaderTable;
+class DebugQueryPool;
+class DebugBufferResource;
+class DebugTextureResource;
+class DebugResourceView;
+class DebugAccelerationStructure;
+class DebugSamplerState;
+class DebugShaderObject;
+class DebugRootShaderObject;
+class DebugCommandBuffer;
+class DebugResourceCommandEncoderImpl;
+class DebugComputeCommandEncoder;
+class DebugResourceCommandEncoder;
+class DebugRenderCommandEncoder;
+class DebugRayTracingCommandEncoder;
+class DebugFence;
+class DebugCommandQueue;
+class DebugFramebuffer;
+class DebugFramebufferLayout;
+class DebugInputLayout;
+class DebugPipelineState;
+class DebugRenderPassLayout;
+class DebugShaderProgram;
+class DebugTransientResourceHeap;
+class DebugSwapchain;
} // namespace debug
} // namespace gfx
diff --git a/tools/gfx/debug-layer/debug-buffer.h b/tools/gfx/debug-layer/debug-buffer.h
index 56c79c3d5..95720324c 100644
--- a/tools/gfx/debug-layer/debug-buffer.h
+++ b/tools/gfx/debug-layer/debug-buffer.h
@@ -19,14 +19,15 @@ public:
virtual SLANG_NO_THROW Type SLANG_MCALL getType() override;
virtual SLANG_NO_THROW Desc* SLANG_MCALL getDesc() override;
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
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;
+ map(MemoryRange* rangeToRead, void** outPointer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override;
};
diff --git a/tools/gfx/debug-layer/debug-command-buffer.cpp b/tools/gfx/debug-layer/debug-command-buffer.cpp
index f3c71cb77..37e1c9e71 100644
--- a/tools/gfx/debug-layer/debug-command-buffer.cpp
+++ b/tools/gfx/debug-layer/debug-command-buffer.cpp
@@ -2,9 +2,8 @@
#include "debug-command-buffer.h"
#include "debug-framebuffer.h"
-#include "debug-render-pass.h"
-
#include "debug-helper-functions.h"
+#include "debug-render-pass.h"
namespace gfx
{
@@ -43,7 +42,9 @@ void DebugCommandBuffer::encodeRenderCommands(
auto innerFramebuffer = getInnerObj(framebuffer);
m_renderCommandEncoder.isOpen = true;
baseObject->encodeRenderCommands(
- innerRenderPass, innerFramebuffer, &m_renderCommandEncoder.baseObject);
+ innerRenderPass,
+ innerFramebuffer,
+ &m_renderCommandEncoder.baseObject);
if (m_renderCommandEncoder.baseObject)
*outEncoder = &m_renderCommandEncoder;
else
@@ -116,15 +117,15 @@ void DebugCommandBuffer::close()
}
if (m_computeCommandEncoder.isOpen)
{
- GFX_DIAGNOSE_ERROR(
- "A compute command encoder on this command buffer is still open. "
- "IComputeCommandEncoder::endEncoding() must be called before closing a command buffer.");
+ GFX_DIAGNOSE_ERROR("A compute command encoder on this command buffer is still open. "
+ "IComputeCommandEncoder::endEncoding() must be called before closing a "
+ "command buffer.");
}
if (m_resourceCommandEncoder.isOpen)
{
- GFX_DIAGNOSE_ERROR(
- "A resource command encoder on this command buffer is still open. "
- "IResourceCommandEncoder::endEncoding() must be called before closing a command buffer.");
+ GFX_DIAGNOSE_ERROR("A resource command encoder on this command buffer is still open. "
+ "IResourceCommandEncoder::endEncoding() must be called before closing a "
+ "command buffer.");
}
isOpen = false;
baseObject->close();
@@ -140,9 +141,12 @@ void DebugCommandBuffer::invalidateDescriptorHeapBinding()
{
SLANG_GFX_API_FUNC;
ComPtr<ICommandBufferD3D12> cmdBuf;
- if (SLANG_FAILED(baseObject->queryInterface(SlangUUID SLANG_UUID_ICommandBufferD3D12, (void**)cmdBuf.writeRef())))
+ if (SLANG_FAILED(baseObject->queryInterface(
+ SlangUUID SLANG_UUID_ICommandBufferD3D12,
+ (void**)cmdBuf.writeRef())))
{
- GFX_DIAGNOSE_ERROR("The current command buffer implementation does not provide ICommandBufferD3D12 interface.");
+ GFX_DIAGNOSE_ERROR("The current command buffer implementation does not provide "
+ "ICommandBufferD3D12 interface.");
return;
}
return cmdBuf->invalidateDescriptorHeapBinding();
@@ -152,9 +156,12 @@ void DebugCommandBuffer::ensureInternalDescriptorHeapsBound()
{
SLANG_GFX_API_FUNC;
ComPtr<ICommandBufferD3D12> cmdBuf;
- if (SLANG_FAILED(baseObject->queryInterface(SlangUUID SLANG_UUID_ICommandBufferD3D12, (void**)cmdBuf.writeRef())))
+ if (SLANG_FAILED(baseObject->queryInterface(
+ SlangUUID SLANG_UUID_ICommandBufferD3D12,
+ (void**)cmdBuf.writeRef())))
{
- GFX_DIAGNOSE_ERROR("The current command buffer implementation does not provide ICommandBufferD3D12 interface.");
+ GFX_DIAGNOSE_ERROR("The current command buffer implementation does not provide "
+ "ICommandBufferD3D12 interface.");
return;
}
return cmdBuf->ensureInternalDescriptorHeapsBound();
diff --git a/tools/gfx/debug-layer/debug-command-buffer.h b/tools/gfx/debug-layer/debug-command-buffer.h
index 33709fb2c..d2d6a1365 100644
--- a/tools/gfx/debug-layer/debug-command-buffer.h
+++ b/tools/gfx/debug-layer/debug-command-buffer.h
@@ -1,7 +1,6 @@
// debug-command-buffer.h
#pragma once
#include "debug-base.h"
-
#include "debug-command-encoder.h"
#include "debug-shader-object.h"
@@ -19,6 +18,7 @@ public:
public:
DebugTransientResourceHeap* m_transientHeap;
+
private:
DebugRenderCommandEncoder m_renderCommandEncoder;
DebugComputeCommandEncoder m_computeCommandEncoder;
@@ -33,11 +33,11 @@ public:
IFramebuffer* framebuffer,
IRenderCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
+ encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
+ encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
+ encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL close() override;
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW void SLANG_MCALL invalidateDescriptorHeapBinding() override;
@@ -46,6 +46,7 @@ public:
private:
void checkEncodersClosedBeforeNewEncoder();
void checkCommandBufferOpenWhenCreatingEncoder();
+
public:
DebugRootShaderObject rootObject;
bool isOpen = true;
diff --git a/tools/gfx/debug-layer/debug-command-encoder.cpp b/tools/gfx/debug-layer/debug-command-encoder.cpp
index 6838732a0..f09130d98 100644
--- a/tools/gfx/debug-layer/debug-command-encoder.cpp
+++ b/tools/gfx/debug-layer/debug-command-encoder.cpp
@@ -3,13 +3,12 @@
#include "debug-buffer.h"
#include "debug-command-buffer.h"
+#include "debug-helper-functions.h"
#include "debug-pipeline-state.h"
#include "debug-query.h"
#include "debug-resource-views.h"
#include "debug-texture.h"
-#include "debug-helper-functions.h"
-
namespace gfx
{
using namespace Slang;
@@ -40,7 +39,8 @@ Result DebugComputeCommandEncoder::bindPipeline(
}
Result DebugComputeCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* state, IShaderObject* rootObject)
+ IPipelineState* state,
+ IShaderObject* rootObject)
{
SLANG_GFX_API_FUNC;
return baseObject->bindPipelineWithRootObject(getInnerObj(state), getInnerObj(rootObject));
@@ -53,7 +53,8 @@ Result DebugComputeCommandEncoder::dispatchCompute(int x, int y, int z)
}
Result DebugComputeCommandEncoder::dispatchComputeIndirect(
- IBufferResource* cmdBuffer, Offset offset)
+ IBufferResource* cmdBuffer,
+ Offset offset)
{
SLANG_GFX_API_FUNC;
return baseObject->dispatchComputeIndirect(getInnerObj(cmdBuffer), offset);
@@ -82,7 +83,8 @@ Result DebugRenderCommandEncoder::bindPipeline(
}
Result DebugRenderCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* state, IShaderObject* rootObject)
+ IPipelineState* state,
+ IShaderObject* rootObject)
{
SLANG_GFX_API_FUNC;
return baseObject->bindPipelineWithRootObject(getInnerObj(state), getInnerObj(rootObject));
@@ -123,7 +125,9 @@ void DebugRenderCommandEncoder::setVertexBuffers(
}
void DebugRenderCommandEncoder::setIndexBuffer(
- IBufferResource* buffer, Format indexFormat, Offset offset)
+ IBufferResource* buffer,
+ Format indexFormat,
+ Offset offset)
{
SLANG_GFX_API_FUNC;
auto innerBuffer = static_cast<DebugBufferResource*>(buffer)->baseObject.get();
@@ -137,7 +141,9 @@ Result DebugRenderCommandEncoder::draw(GfxCount vertexCount, GfxIndex startVerte
}
Result DebugRenderCommandEncoder::drawIndexed(
- GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex)
+ GfxCount indexCount,
+ GfxIndex startIndex,
+ GfxIndex baseVertex)
{
SLANG_GFX_API_FUNC;
return baseObject->drawIndexed(indexCount, startIndex, baseVertex);
@@ -152,7 +158,11 @@ Result DebugRenderCommandEncoder::drawIndirect(
{
SLANG_GFX_API_FUNC;
return baseObject->drawIndirect(
- maxDrawCount, getInnerObj(argBuffer), argOffset, getInnerObj(countBuffer), countOffset);
+ maxDrawCount,
+ getInnerObj(argBuffer),
+ argOffset,
+ getInnerObj(countBuffer),
+ countOffset);
}
Result DebugRenderCommandEncoder::drawIndexedIndirect(
@@ -164,7 +174,11 @@ Result DebugRenderCommandEncoder::drawIndexedIndirect(
{
SLANG_GFX_API_FUNC;
return baseObject->drawIndexedIndirect(
- maxDrawCount, getInnerObj(argBuffer), argOffset, getInnerObj(countBuffer), countOffset);
+ maxDrawCount,
+ getInnerObj(argBuffer),
+ argOffset,
+ getInnerObj(countBuffer),
+ countOffset);
}
void DebugRenderCommandEncoder::setStencilReference(uint32_t referenceValue)
@@ -174,7 +188,9 @@ void DebugRenderCommandEncoder::setStencilReference(uint32_t referenceValue)
}
Result DebugRenderCommandEncoder::setSamplePositions(
- GfxCount samplesPerPixel, GfxCount pixelCount, const SamplePosition* samplePositions)
+ GfxCount samplesPerPixel,
+ GfxCount pixelCount,
+ const SamplePosition* samplePositions)
{
SLANG_GFX_API_FUNC;
return baseObject->setSamplePositions(samplesPerPixel, pixelCount, samplePositions);
@@ -187,8 +203,8 @@ Result DebugRenderCommandEncoder::drawInstanced(
GfxIndex startInstanceLocation)
{
SLANG_GFX_API_FUNC;
- return baseObject->drawInstanced(
- vertexCount, instanceCount, startVertex, startInstanceLocation);
+ return baseObject
+ ->drawInstanced(vertexCount, instanceCount, startVertex, startInstanceLocation);
}
Result DebugRenderCommandEncoder::drawIndexedInstanced(
@@ -200,7 +216,11 @@ Result DebugRenderCommandEncoder::drawIndexedInstanced(
{
SLANG_GFX_API_FUNC;
return baseObject->drawIndexedInstanced(
- indexCount, instanceCount, startIndexLocation, baseVertexLocation, startInstanceLocation);
+ indexCount,
+ instanceCount,
+ startIndexLocation,
+ baseVertexLocation,
+ startInstanceLocation);
}
Result DebugRenderCommandEncoder::drawMeshTasks(int x, int y, int z)
@@ -232,8 +252,8 @@ void DebugResourceCommandEncoderImpl::copyBuffer(
SLANG_GFX_API_FUNC;
auto dstImpl = static_cast<DebugBufferResource*>(dst);
auto srcImpl = static_cast<DebugBufferResource*>(src);
- getBaseResourceEncoder()->copyBuffer(
- dstImpl->baseObject, dstOffset, srcImpl->baseObject, srcOffset, size);
+ getBaseResourceEncoder()
+ ->copyBuffer(dstImpl->baseObject, dstOffset, srcImpl->baseObject, srcOffset, size);
}
void DebugResourceCommandEncoderImpl::uploadBufferData(
@@ -272,7 +292,7 @@ void DebugResourceCommandEncoderImpl::bufferBarrier(
SLANG_GFX_API_FUNC;
List<IBufferResource*> innerBuffers;
- for(GfxIndex i = 0; i < count; i++)
+ for (GfxIndex i = 0; i < count; i++)
{
innerBuffers.add(static_cast<DebugBufferResource*>(buffers[i])->baseObject.get());
}
@@ -313,19 +333,25 @@ void DebugResourceCommandEncoderImpl::uploadTextureData(
{
SLANG_GFX_API_FUNC;
getBaseResourceEncoder()->uploadTextureData(
- getInnerObj(dst), subResourceRange, offset, extent, subResourceData, subResourceDataCount);
+ getInnerObj(dst),
+ subResourceRange,
+ offset,
+ extent,
+ subResourceData,
+ subResourceDataCount);
}
void DebugResourceCommandEncoderImpl::clearResourceView(
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags)
+ IResourceView* view,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags)
{
SLANG_GFX_API_FUNC;
switch (view->getViewDesc()->type)
{
case IResourceView::Type::DepthStencil:
case IResourceView::Type::RenderTarget:
- case IResourceView::Type::UnorderedAccess:
- break;
+ case IResourceView::Type::UnorderedAccess: break;
default:
GFX_DIAGNOSE_ERROR_FORMAT(
"Resource view %lld cannot be cleared. Only DepthStencil, "
@@ -345,14 +371,24 @@ void DebugResourceCommandEncoderImpl::resolveResource(
{
SLANG_GFX_API_FUNC;
getBaseResourceEncoder()->resolveResource(
- getInnerObj(source), sourceState, sourceRange, getInnerObj(dest), destState, destRange);
+ getInnerObj(source),
+ sourceState,
+ sourceRange,
+ getInnerObj(dest),
+ destState,
+ destRange);
}
void DebugResourceCommandEncoderImpl::resolveQuery(
- IQueryPool* queryPool, GfxIndex index, GfxCount count, IBufferResource* buffer, Offset offset)
+ IQueryPool* queryPool,
+ GfxIndex index,
+ GfxCount count,
+ IBufferResource* buffer,
+ Offset offset)
{
SLANG_GFX_API_FUNC;
- getBaseResourceEncoder()->resolveQuery(getInnerObj(queryPool), index, count, getInnerObj(buffer), offset);
+ getBaseResourceEncoder()
+ ->resolveQuery(getInnerObj(queryPool), index, count, getInnerObj(buffer), offset);
}
void DebugResourceCommandEncoderImpl::copyTextureToBuffer(
@@ -368,7 +404,15 @@ void DebugResourceCommandEncoderImpl::copyTextureToBuffer(
{
SLANG_GFX_API_FUNC;
getBaseResourceEncoder()->copyTextureToBuffer(
- getInnerObj(dst), dstOffset, dstSize, dstRowStride, getInnerObj(src), srcState, srcSubresource, srcOffset, extent);
+ getInnerObj(dst),
+ dstOffset,
+ dstSize,
+ dstRowStride,
+ getInnerObj(src),
+ srcState,
+ srcSubresource,
+ srcOffset,
+ extent);
}
void DebugResourceCommandEncoderImpl::textureSubresourceBarrier(
@@ -378,8 +422,8 @@ void DebugResourceCommandEncoderImpl::textureSubresourceBarrier(
ResourceState dst)
{
SLANG_GFX_API_FUNC;
- getBaseResourceEncoder()->textureSubresourceBarrier(
- getInnerObj(texture), subresourceRange, src, dst);
+ getBaseResourceEncoder()
+ ->textureSubresourceBarrier(getInnerObj(texture), subresourceRange, src, dst);
}
void DebugResourceCommandEncoderImpl::beginDebugEvent(const char* name, float rgbColor[3])
@@ -418,7 +462,9 @@ void DebugRayTracingCommandEncoder::buildAccelerationStructure(
}
validateAccelerationStructureBuildInputs(desc.inputs);
baseObject->buildAccelerationStructure(
- innerDesc, propertyQueryCount, innerQueryDescs.getBuffer());
+ innerDesc,
+ propertyQueryCount,
+ innerQueryDescs.getBuffer());
}
void DebugRayTracingCommandEncoder::copyAccelerationStructure(
@@ -451,7 +497,10 @@ void DebugRayTracingCommandEncoder::queryAccelerationStructureProperties(
innerQueryDesc.queryPool = getInnerObj(innerQueryDesc.queryPool);
}
baseObject->queryAccelerationStructureProperties(
- accelerationStructureCount, innerAS.getBuffer(), queryCount, innerQueryDescs.getBuffer());
+ accelerationStructureCount,
+ innerAS.getBuffer(),
+ queryCount,
+ innerQueryDescs.getBuffer());
}
void DebugRayTracingCommandEncoder::serializeAccelerationStructure(
@@ -471,7 +520,8 @@ void DebugRayTracingCommandEncoder::deserializeAccelerationStructure(
}
Result DebugRayTracingCommandEncoder::bindPipeline(
- IPipelineState* state, IShaderObject** outRootObject)
+ IPipelineState* state,
+ IShaderObject** outRootObject)
{
SLANG_GFX_API_FUNC;
auto innerPipeline = getInnerObj(state);
@@ -484,7 +534,8 @@ Result DebugRayTracingCommandEncoder::bindPipeline(
}
Result DebugRayTracingCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* state, IShaderObject* rootObject)
+ IPipelineState* state,
+ IShaderObject* rootObject)
{
SLANG_GFX_API_FUNC;
return baseObject->bindPipelineWithRootObject(getInnerObj(state), getInnerObj(rootObject));
@@ -498,7 +549,8 @@ Result DebugRayTracingCommandEncoder::dispatchRays(
GfxCount depth)
{
SLANG_GFX_API_FUNC;
- return baseObject->dispatchRays(rayGenShaderIndex, getInnerObj(shaderTable), width, height, depth);
+ return baseObject
+ ->dispatchRays(rayGenShaderIndex, getInnerObj(shaderTable), width, height, depth);
}
} // namespace debug
diff --git a/tools/gfx/debug-layer/debug-command-encoder.h b/tools/gfx/debug-layer/debug-command-encoder.h
index 152a1a733..467c52828 100644
--- a/tools/gfx/debug-layer/debug-command-encoder.h
+++ b/tools/gfx/debug-layer/debug-command-encoder.h
@@ -27,6 +27,7 @@ public:
}
uint32_t addRef() { return 1; }
uint32_t release() { return 1; }
+
public:
virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer(
IBufferResource* dst,
@@ -35,9 +36,8 @@ public:
Offset srcOffset,
Size size);
virtual SLANG_NO_THROW void SLANG_MCALL
- uploadBufferData(IBufferResource* dst, Offset offset, Size size, void* data);
- virtual SLANG_NO_THROW void SLANG_MCALL
- writeTimestamp(IQueryPool* pool, GfxIndex index);
+ uploadBufferData(IBufferResource* dst, Offset offset, Size size, void* data);
+ virtual SLANG_NO_THROW void SLANG_MCALL writeTimestamp(IQueryPool* pool, GfxIndex index);
virtual SLANG_NO_THROW void SLANG_MCALL textureBarrier(
GfxCount count,
ITextureResource* const* textures,
@@ -66,7 +66,9 @@ public:
ITextureResource::SubresourceData* subResourceData,
GfxCount subResourceDataCount);
virtual SLANG_NO_THROW void SLANG_MCALL clearResourceView(
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags);
+ IResourceView* view,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags);
virtual SLANG_NO_THROW void SLANG_MCALL resolveResource(
ITextureResource* source,
ResourceState sourceState,
@@ -99,9 +101,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent();
};
-class DebugComputeCommandEncoder
- : public UnownedDebugObject<IComputeCommandEncoder>
- , public DebugResourceCommandEncoderImpl
+class DebugComputeCommandEncoder : public UnownedDebugObject<IComputeCommandEncoder>,
+ public DebugResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(DebugResourceCommandEncoderImpl)
@@ -110,7 +111,8 @@ public:
virtual IResourceCommandEncoder* getBaseResourceEncoder() override { return baseObject; }
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
@@ -120,21 +122,20 @@ public:
public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootShaderObject) override;
+ bindPipeline(IPipelineState* state, IShaderObject** outRootShaderObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL dispatchCompute(int x, int y, int z) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- dispatchComputeIndirect(IBufferResource* cmdBuffer, Offset offset) override;
+ dispatchComputeIndirect(IBufferResource* cmdBuffer, Offset offset) override;
public:
DebugCommandBuffer* commandBuffer;
bool isOpen = false;
};
-class DebugResourceCommandEncoder
- : public UnownedDebugObject<IResourceCommandEncoder>
- , public DebugResourceCommandEncoderImpl
+class DebugResourceCommandEncoder : public UnownedDebugObject<IResourceCommandEncoder>,
+ public DebugResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(DebugResourceCommandEncoderImpl)
@@ -158,49 +159,47 @@ public:
bool isOpen = false;
};
-class DebugRenderCommandEncoder
- : public UnownedDebugObject<IRenderCommandEncoder>
- , public DebugResourceCommandEncoderImpl
+class DebugRenderCommandEncoder : public UnownedDebugObject<IRenderCommandEncoder>,
+ public DebugResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(DebugResourceCommandEncoderImpl)
- virtual DebugCommandBuffer* getCommandBuffer() override
- {
- return commandBuffer;
- }
+ virtual DebugCommandBuffer* getCommandBuffer() override { return commandBuffer; }
virtual bool getIsOpen() override { return isOpen; }
virtual IResourceCommandEncoder* getBaseResourceEncoder() override { return baseObject; }
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
return nullptr;
}
+
public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootShaderObject) override;
+ bindPipeline(IPipelineState* state, IShaderObject** outRootShaderObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setViewports(GfxCount count, const Viewport* viewports) override;
+ setViewports(GfxCount count, const Viewport* viewports) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setScissorRects(GfxCount count, const ScissorRect* scissors) override;
+ setScissorRects(GfxCount count, const ScissorRect* scissors) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setPrimitiveTopology(PrimitiveTopology topology) override;
+ setPrimitiveTopology(PrimitiveTopology topology) override;
virtual SLANG_NO_THROW void SLANG_MCALL setVertexBuffers(
GfxIndex startSlot,
GfxCount slotCount,
IBufferResource* const* buffers,
const Offset* offsets) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) override;
+ setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- draw(GfxCount vertexCount, GfxIndex startVertex = 0) override;
+ draw(GfxCount vertexCount, GfxIndex startVertex = 0) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override;
+ drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override;
virtual SLANG_NO_THROW Result SLANG_MCALL drawIndirect(
GfxCount maxDrawCount,
IBufferResource* argBuffer,
@@ -231,17 +230,15 @@ public:
GfxIndex baseVertexLocation,
GfxIndex startInstanceLocation) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- drawMeshTasks(int x, int y, int z) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL drawMeshTasks(int x, int y, int z) override;
public:
DebugCommandBuffer* commandBuffer;
bool isOpen = false;
};
-class DebugRayTracingCommandEncoder
- : public UnownedDebugObject<IRayTracingCommandEncoder>
- , public DebugResourceCommandEncoderImpl
+class DebugRayTracingCommandEncoder : public UnownedDebugObject<IRayTracingCommandEncoder>,
+ public DebugResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(DebugResourceCommandEncoderImpl)
@@ -250,12 +247,14 @@ public:
virtual IResourceCommandEncoder* getBaseResourceEncoder() override { return baseObject; }
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRayTracingCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IRayTracingCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
return nullptr;
}
+
public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW void SLANG_MCALL buildAccelerationStructure(
@@ -272,14 +271,13 @@ public:
GfxCount queryCount,
AccelerationStructureQueryDesc* queryDescs) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- serializeAccelerationStructure(DeviceAddress dest, IAccelerationStructure* source) override;
- virtual SLANG_NO_THROW void SLANG_MCALL deserializeAccelerationStructure(
- IAccelerationStructure* dest,
- DeviceAddress source) override;
+ serializeAccelerationStructure(DeviceAddress dest, IAccelerationStructure* source) override;
+ virtual SLANG_NO_THROW void SLANG_MCALL
+ deserializeAccelerationStructure(IAccelerationStructure* dest, DeviceAddress source) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL dispatchRays(
GfxIndex rayGenShaderIndex,
IShaderTable* shaderTable,
diff --git a/tools/gfx/debug-layer/debug-command-queue.cpp b/tools/gfx/debug-layer/debug-command-queue.cpp
index d094f3438..3759b07b8 100644
--- a/tools/gfx/debug-layer/debug-command-queue.cpp
+++ b/tools/gfx/debug-layer/debug-command-queue.cpp
@@ -3,9 +3,8 @@
#include "debug-command-buffer.h"
#include "debug-fence.h"
-#include "debug-transient-heap.h"
-
#include "debug-helper-functions.h"
+#include "debug-transient-heap.h"
namespace gfx
{
@@ -20,7 +19,11 @@ const ICommandQueue::Desc& DebugCommandQueue::getDesc()
return baseObject->getDesc();
}
-void DebugCommandQueue::executeCommandBuffers(GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
+void DebugCommandQueue::executeCommandBuffers(
+ GfxCount count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal)
{
SLANG_GFX_API_FUNC;
List<ICommandBuffer*> innerCommandBuffers;
@@ -46,10 +49,15 @@ void DebugCommandQueue::executeCommandBuffers(GfxCount count, ICommandBuffer* co
}
}
}
- baseObject->executeCommandBuffers(count, innerCommandBuffers.getBuffer(), getInnerObj(fence), valueToSignal);
+ baseObject->executeCommandBuffers(
+ count,
+ innerCommandBuffers.getBuffer(),
+ getInnerObj(fence),
+ valueToSignal);
if (fence)
{
- getDebugObj(fence)->maxValueToSignal = Math::Max(getDebugObj(fence)->maxValueToSignal, valueToSignal);
+ getDebugObj(fence)->maxValueToSignal =
+ Math::Max(getDebugObj(fence)->maxValueToSignal, valueToSignal);
}
}
@@ -60,7 +68,9 @@ void DebugCommandQueue::waitOnHost()
}
Result DebugCommandQueue::waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* waitValues)
{
SLANG_GFX_API_FUNC;
List<IFence*> innerFences;
diff --git a/tools/gfx/debug-layer/debug-command-queue.h b/tools/gfx/debug-layer/debug-command-queue.h
index 3c9afa98b..417e9888a 100644
--- a/tools/gfx/debug-layer/debug-command-queue.h
+++ b/tools/gfx/debug-layer/debug-command-queue.h
@@ -17,11 +17,14 @@ public:
public:
ICommandQueue* getInterface(const Slang::Guid& guid);
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override;
- virtual SLANG_NO_THROW void SLANG_MCALL
- executeCommandBuffers(GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal) override;
+ virtual SLANG_NO_THROW void SLANG_MCALL executeCommandBuffers(
+ GfxCount count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal) override;
virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ waitForFenceValuesOnDevice(GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
};
diff --git a/tools/gfx/debug-layer/debug-device.cpp b/tools/gfx/debug-layer/debug-device.cpp
index 44ca1de7a..c5798710a 100644
--- a/tools/gfx/debug-layer/debug-device.cpp
+++ b/tools/gfx/debug-layer/debug-device.cpp
@@ -45,7 +45,10 @@ Result DebugDevice::getNativeDeviceHandles(InteropHandles* outHandles)
return baseObject->getNativeDeviceHandles(outHandles);
}
-Result DebugDevice::getFeatures(const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount)
+Result DebugDevice::getFeatures(
+ const char** outFeatures,
+ Size bufferSize,
+ GfxCount* outFeatureCount)
{
SLANG_GFX_API_FUNC;
@@ -116,7 +119,10 @@ Result DebugDevice::createTextureFromNativeHandle(
SLANG_GFX_API_FUNC;
RefPtr<DebugTextureResource> outObject = new DebugTextureResource();
- auto result = baseObject->createTextureFromNativeHandle(handle, srcDesc, outObject->baseObject.writeRef());
+ auto result = baseObject->createTextureFromNativeHandle(
+ handle,
+ srcDesc,
+ outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
returnComPtr(outResource, outObject);
@@ -132,7 +138,11 @@ Result DebugDevice::createTextureFromSharedHandle(
SLANG_GFX_API_FUNC;
RefPtr<DebugTextureResource> outObject = new DebugTextureResource();
- auto result = baseObject->createTextureFromSharedHandle(handle, srcDesc, size, outObject->baseObject.writeRef());
+ auto result = baseObject->createTextureFromSharedHandle(
+ handle,
+ srcDesc,
+ size,
+ outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
returnComPtr(outResource, outObject);
@@ -147,7 +157,8 @@ Result DebugDevice::createBufferResource(
SLANG_GFX_API_FUNC;
RefPtr<DebugBufferResource> outObject = new DebugBufferResource();
- auto result = baseObject->createBufferResource(desc, initData, outObject->baseObject.writeRef());
+ auto result =
+ baseObject->createBufferResource(desc, initData, outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
returnComPtr(outResource, outObject);
@@ -162,7 +173,8 @@ Result DebugDevice::createBufferFromNativeHandle(
SLANG_GFX_API_FUNC;
RefPtr<DebugBufferResource> outObject = new DebugBufferResource();
- auto result = baseObject->createBufferFromNativeHandle(handle, srcDesc, outObject->baseObject.writeRef());
+ auto result =
+ baseObject->createBufferFromNativeHandle(handle, srcDesc, outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
returnComPtr(outResource, outObject);
@@ -177,7 +189,8 @@ Result DebugDevice::createBufferFromSharedHandle(
SLANG_GFX_API_FUNC;
RefPtr<DebugBufferResource> outObject = new DebugBufferResource();
- auto result = baseObject->createBufferFromSharedHandle(handle, srcDesc, outObject->baseObject.writeRef());
+ auto result =
+ baseObject->createBufferFromSharedHandle(handle, srcDesc, outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
returnComPtr(outResource, outObject);
@@ -204,10 +217,8 @@ Result DebugDevice::createTextureView(
SLANG_GFX_API_FUNC;
RefPtr<DebugResourceView> outObject = new DebugResourceView();
- auto result = baseObject->createTextureView(
- getInnerObj(texture),
- desc,
- outObject->baseObject.writeRef());
+ auto result =
+ baseObject->createTextureView(getInnerObj(texture), desc, outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
returnComPtr(outView, outObject);
@@ -251,7 +262,8 @@ Result DebugDevice::createAccelerationStructure(
auto innerDesc = desc;
innerDesc.buffer = getInnerObj(innerDesc.buffer);
RefPtr<DebugAccelerationStructure> outObject = new DebugAccelerationStructure();
- auto result = baseObject->createAccelerationStructure(innerDesc, outObject->baseObject.writeRef());
+ auto result =
+ baseObject->createAccelerationStructure(innerDesc, outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
returnComPtr(outAS, outObject);
@@ -329,15 +341,12 @@ Result DebugDevice::createSwapchain(
return Result();
}
-Result DebugDevice::createInputLayout(
- IInputLayout::Desc const& desc,
- IInputLayout** outLayout)
+Result DebugDevice::createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout)
{
SLANG_GFX_API_FUNC;
RefPtr<DebugInputLayout> outObject = new DebugInputLayout();
- auto result = baseObject->createInputLayout(
- desc, outObject->baseObject.writeRef());
+ auto result = baseObject->createInputLayout(desc, outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
returnComPtr(outLayout, outObject);
@@ -386,8 +395,11 @@ Result DebugDevice::createShaderObject2(
RefPtr<DebugShaderObject> outObject = new DebugShaderObject();
auto typeName = type->getName();
- auto result =
- baseObject->createShaderObject2(session, type, containerType, outObject->baseObject.writeRef());
+ auto result = baseObject->createShaderObject2(
+ session,
+ type,
+ containerType,
+ outObject->baseObject.writeRef());
outObject->m_typeName = typeName;
outObject->m_device = this;
outObject->m_slangType = type;
@@ -406,8 +418,10 @@ Result DebugDevice::createMutableShaderObject(
RefPtr<DebugShaderObject> outObject = new DebugShaderObject();
auto typeName = type->getName();
- auto result =
- baseObject->createMutableShaderObject(type, containerType, outObject->baseObject.writeRef());
+ auto result = baseObject->createMutableShaderObject(
+ type,
+ containerType,
+ outObject->baseObject.writeRef());
outObject->m_typeName = typeName;
outObject->m_device = this;
outObject->m_slangType = type;
@@ -427,8 +441,11 @@ Result DebugDevice::createMutableShaderObject2(
RefPtr<DebugShaderObject> outObject = new DebugShaderObject();
auto typeName = type->getName();
- auto result =
- baseObject->createMutableShaderObject2(session, type, containerType, outObject->baseObject.writeRef());
+ auto result = baseObject->createMutableShaderObject2(
+ session,
+ type,
+ containerType,
+ outObject->baseObject.writeRef());
outObject->m_typeName = typeName;
outObject->m_device = this;
outObject->m_slangType = type;
@@ -439,12 +456,14 @@ Result DebugDevice::createMutableShaderObject2(
}
Result DebugDevice::createMutableRootShaderObject(
- IShaderProgram* program, IShaderObject** outRootObject)
+ IShaderProgram* program,
+ IShaderObject** outRootObject)
{
SLANG_GFX_API_FUNC;
RefPtr<DebugShaderObject> outObject = new DebugShaderObject();
auto result = baseObject->createMutableRootShaderObject(
- getInnerObj(program), outObject->baseObject.writeRef());
+ getInnerObj(program),
+ outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
outObject->m_device = this;
@@ -455,12 +474,14 @@ Result DebugDevice::createMutableRootShaderObject(
}
Result DebugDevice::createShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outShaderObject)
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outShaderObject)
{
SLANG_GFX_API_FUNC;
RefPtr<DebugShaderObject> outObject = new DebugShaderObject();
- auto result = baseObject->createShaderObjectFromTypeLayout(typeLayout, outObject->baseObject.writeRef());
+ auto result =
+ baseObject->createShaderObjectFromTypeLayout(typeLayout, outObject->baseObject.writeRef());
auto type = typeLayout->getType();
auto typeName = type->getName();
outObject->m_typeName = typeName;
@@ -473,12 +494,14 @@ Result DebugDevice::createShaderObjectFromTypeLayout(
}
Result DebugDevice::createMutableShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outShaderObject)
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outShaderObject)
{
SLANG_GFX_API_FUNC;
RefPtr<DebugShaderObject> outObject = new DebugShaderObject();
auto result = baseObject->createMutableShaderObjectFromTypeLayout(
- typeLayout, outObject->baseObject.writeRef());
+ typeLayout,
+ outObject->baseObject.writeRef());
if (SLANG_FAILED(result))
return result;
auto type = typeLayout->getType();
@@ -491,7 +514,9 @@ Result DebugDevice::createMutableShaderObjectFromTypeLayout(
}
Result DebugDevice::createProgram(
- const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnostics)
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnostics)
{
SLANG_GFX_API_FUNC;
@@ -505,12 +530,15 @@ Result DebugDevice::createProgram(
}
Result DebugDevice::createProgram2(
- const IShaderProgram::CreateDesc2& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnostics)
+ const IShaderProgram::CreateDesc2& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnostics)
{
SLANG_GFX_API_FUNC;
IShaderProgram::Desc desc1 = {};
RefPtr<DebugShaderProgram> outObject = new DebugShaderProgram();
- auto result = baseObject->createProgram2(desc, outObject->baseObject.writeRef(), outDiagnostics);
+ auto result =
+ baseObject->createProgram2(desc, outObject->baseObject.writeRef(), outDiagnostics);
if (SLANG_FAILED(result))
return result;
auto base = static_cast<ShaderProgramBase*>(outObject->baseObject.get());
@@ -582,8 +610,8 @@ SlangResult DebugDevice::readTextureResource(
size_t* outPixelSize)
{
SLANG_GFX_API_FUNC;
- return baseObject->readTextureResource(
- getInnerObj(resource), state, outBlob, outRowPitch, outPixelSize);
+ return baseObject
+ ->readTextureResource(getInnerObj(resource), state, outBlob, outRowPitch, outPixelSize);
}
SlangResult DebugDevice::readBufferResource(
@@ -622,7 +650,11 @@ Result DebugDevice::createFence(const IFence::Desc& desc, IFence** outFence)
}
Result DebugDevice::waitForFences(
- GfxCount fenceCount, IFence** fences, uint64_t* values , bool waitForAll, uint64_t timeout)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* values,
+ bool waitForAll,
+ uint64_t timeout)
{
SLANG_GFX_API_FUNC;
ShortList<IFence*> innerFences;
@@ -630,11 +662,18 @@ Result DebugDevice::waitForFences(
{
innerFences.add(getInnerObj(fences[i]));
}
- return baseObject->waitForFences(fenceCount, innerFences.getArrayView().getBuffer(), values, waitForAll, timeout);
+ return baseObject->waitForFences(
+ fenceCount,
+ innerFences.getArrayView().getBuffer(),
+ values,
+ waitForAll,
+ timeout);
}
Result DebugDevice::getTextureAllocationInfo(
- const ITextureResource::Desc& desc, size_t* outSize, size_t* outAlignment)
+ const ITextureResource::Desc& desc,
+ size_t* outSize,
+ size_t* outAlignment)
{
SLANG_GFX_API_FUNC;
return baseObject->getTextureAllocationInfo(desc, outSize, outAlignment);
diff --git a/tools/gfx/debug-layer/debug-device.h b/tools/gfx/debug-layer/debug-device.h
index 90feaa37e..a4debd2e7 100644
--- a/tools/gfx/debug-layer/debug-device.h
+++ b/tools/gfx/debug-layer/debug-device.h
@@ -12,22 +12,24 @@ namespace debug
class DebugDevice : public DebugObject<IDevice>
{
public:
- SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) noexcept override;
+ SlangResult SLANG_MCALL
+ queryInterface(SlangUUID const& uuid, void** outObject) noexcept override;
SLANG_COM_OBJECT_IUNKNOWN_ADD_REF;
SLANG_COM_OBJECT_IUNKNOWN_RELEASE;
public:
DebugDevice();
IDevice* getInterface(const Slang::Guid& guid);
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeDeviceHandles(InteropHandles* outHandles) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeDeviceHandles(InteropHandles* outHandles) override;
virtual SLANG_NO_THROW bool SLANG_MCALL hasFeature(const char* feature) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getFeatures(const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount) override;
+ getFeatures(const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
+ getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getSlangSession(slang::ISession** outSlangSession) override;
+ getSlangSession(slang::ISession** outSlangSession) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap(
const ITransientResourceHeap::Desc& desc,
ITransientResourceHeap** outHeap) override;
@@ -57,7 +59,7 @@ public:
const IBufferResource::Desc& srcDesc,
IBufferResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
+ createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView(
ITextureResource* texture,
IResourceView::Desc const& desc,
@@ -77,7 +79,7 @@ public:
IFramebufferLayout::Desc const& desc,
IFramebufferLayout** outFrameBuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffer** outFrameBuffer) override;
+ createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffer** outFrameBuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createRenderPassLayout(
const IRenderPassLayout::Desc& desc,
IRenderPassLayout** outRenderPassLayout) override;
@@ -85,11 +87,10 @@ public:
ISwapchain::Desc const& desc,
WindowHandle window,
ISwapchain** outSwapchain) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL createInputLayout(
- IInputLayout::Desc const& desc,
- IInputLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
+ createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObject(
slang::TypeReflection* type,
ShaderObjectContainerType container,
@@ -109,15 +110,21 @@ public:
ShaderObjectContainerType container,
IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject) override;
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnostics) override;
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createProgram2(const IShaderProgram::CreateDesc2& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnostics) override;
+ createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL createProgram(
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnostics) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL createProgram2(
+ const IShaderProgram::CreateDesc2& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnostics) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
const GraphicsPipelineStateDesc& desc,
IPipelineState** outState) override;
@@ -139,11 +146,10 @@ public:
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;
+ 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 waitForFences(
GfxCount fenceCount,
IFence** fences,
@@ -151,10 +157,12 @@ public:
bool waitForAll,
uint64_t timeout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureAllocationInfo(
- const ITextureResource::Desc& desc, size_t* outSize, size_t* outAlignment) override;
+ const ITextureResource::Desc& desc,
+ size_t* outSize,
+ size_t* outAlignment) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureRowAlignment(size_t* outAlignment) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outTable) override;
+ createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outTable) override;
};
} // namespace debug
diff --git a/tools/gfx/debug-layer/debug-fence.cpp b/tools/gfx/debug-layer/debug-fence.cpp
index 66c541618..4e8673578 100644
--- a/tools/gfx/debug-layer/debug-fence.cpp
+++ b/tools/gfx/debug-layer/debug-fence.cpp
@@ -33,7 +33,10 @@ Result DebugFence::setCurrentValue(uint64_t value)
SLANG_GFX_API_FUNC;
if (value < maxValueToSignal)
{
- GFX_DIAGNOSE_ERROR_FORMAT("Cannot set fence value (%d) to lower than pending signal value (%d) on the fence.", value, maxValueToSignal);
+ GFX_DIAGNOSE_ERROR_FORMAT(
+ "Cannot set fence value (%d) to lower than pending signal value (%d) on the fence.",
+ value,
+ maxValueToSignal);
}
return baseObject->setCurrentValue(value);
}
diff --git a/tools/gfx/debug-layer/debug-fence.h b/tools/gfx/debug-layer/debug-fence.h
index 1f61fac33..de61e5838 100644
--- a/tools/gfx/debug-layer/debug-fence.h
+++ b/tools/gfx/debug-layer/debug-fence.h
@@ -17,7 +17,9 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentValue(uint64_t* outValue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL setCurrentValue(uint64_t value) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outNativeHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeHandle(InteropHandle* outNativeHandle) override;
+
public:
uint64_t maxValueToSignal = 0;
};
diff --git a/tools/gfx/debug-layer/debug-framebuffer.h b/tools/gfx/debug-layer/debug-framebuffer.h
index 76e05040c..a7ab637de 100644
--- a/tools/gfx/debug-layer/debug-framebuffer.h
+++ b/tools/gfx/debug-layer/debug-framebuffer.h
@@ -9,8 +9,7 @@ using namespace Slang;
namespace debug
{
-class DebugFramebuffer
- : public DebugObject<IFramebuffer>
+class DebugFramebuffer : public DebugObject<IFramebuffer>
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL;
diff --git a/tools/gfx/debug-layer/debug-helper-functions.cpp b/tools/gfx/debug-layer/debug-helper-functions.cpp
index e75d0a3c3..adeff9d2e 100644
--- a/tools/gfx/debug-layer/debug-helper-functions.cpp
+++ b/tools/gfx/debug-layer/debug-helper-functions.cpp
@@ -54,14 +54,14 @@ void validateAccelerationStructureBuildInputs(
if (!buildInputs.instanceDescs)
{
GFX_DIAGNOSE_WARNING("IAccelerationStructure::BuildInputs::instanceDescs is null "
- "when creating a top-level acceleration structure.");
+ "when creating a top-level acceleration structure.");
}
break;
case IAccelerationStructure::Kind::BottomLevel:
if (!buildInputs.geometryDescs)
{
GFX_DIAGNOSE_WARNING("IAccelerationStructure::BuildInputs::geometryDescs is null "
- "when creating a bottom-level acceleration structure.");
+ "when creating a bottom-level acceleration structure.");
}
for (int i = 0; i < buildInputs.descCount; i++)
{
@@ -75,12 +75,13 @@ void validateAccelerationStructureBuildInputs(
case Format::R16G16B16A16_FLOAT:
case Format::R16G16_FLOAT:
case Format::R16G16B16A16_SNORM:
- case Format::R16G16_SNORM:
- break;
+ case Format::R16G16_SNORM: break;
default:
GFX_DIAGNOSE_ERROR(
- "Unsupported IAccelerationStructure::TriangleDesc::vertexFormat. Valid "
- "values are R32G32B32_FLOAT, R32G32_FLOAT, R16G16B16A16_FLOAT, R16G16_FLOAT, "
+ "Unsupported "
+ "IAccelerationStructure::TriangleDesc::vertexFormat. Valid "
+ "values are R32G32B32_FLOAT, R32G32_FLOAT, R16G16B16A16_FLOAT, "
+ "R16G16_FLOAT, "
"R16G16B16A16_SNORM or R16G16_SNORM.");
}
if (buildInputs.geometryDescs[i].content.triangles.indexCount)
@@ -88,17 +89,18 @@ void validateAccelerationStructureBuildInputs(
switch (buildInputs.geometryDescs[i].content.triangles.indexFormat)
{
case Format::R32_UINT:
- case Format::R16_UINT:
- break;
+ case Format::R16_UINT: break;
default:
GFX_DIAGNOSE_ERROR(
- "Unsupported IAccelerationStructure::TriangleDesc::indexFormat. Valid "
+ "Unsupported "
+ "IAccelerationStructure::TriangleDesc::indexFormat. Valid "
"values are Unknown, R32_UINT or R16_UINT.");
}
if (!buildInputs.geometryDescs[i].content.triangles.indexData)
{
GFX_DIAGNOSE_ERROR(
- "IAccelerationStructure::TriangleDesc::indexData cannot be null if "
+ "IAccelerationStructure::TriangleDesc::indexData cannot be "
+ "null if "
"IAccelerationStructure::TriangleDesc::indexCount is not 0");
}
}
@@ -106,14 +108,16 @@ void validateAccelerationStructureBuildInputs(
{
if (buildInputs.geometryDescs[i].content.triangles.indexCount == 0)
{
- GFX_DIAGNOSE_ERROR(
- "IAccelerationStructure::TriangleDesc::indexCount cannot be 0 if "
- "IAccelerationStructure::TriangleDesc::indexFormat is not Format::Unknown");
+ GFX_DIAGNOSE_ERROR("IAccelerationStructure::TriangleDesc::"
+ "indexCount cannot be 0 if "
+ "IAccelerationStructure::TriangleDesc::"
+ "indexFormat is not Format::Unknown");
}
if (buildInputs.geometryDescs[i].content.triangles.indexData == 0)
{
GFX_DIAGNOSE_ERROR(
- "IAccelerationStructure::TriangleDesc::indexData cannot be null if "
+ "IAccelerationStructure::TriangleDesc::indexData cannot be "
+ "null if "
"IAccelerationStructure::TriangleDesc::indexFormat is not "
"Format::Unknown");
}
@@ -130,7 +134,8 @@ void validateAccelerationStructureBuildInputs(
if (buildInputs.geometryDescs[i].content.triangles.indexData != 0)
{
GFX_DIAGNOSE_ERROR(
- "IAccelerationStructure::TriangleDesc::indexData must be null if "
+ "IAccelerationStructure::TriangleDesc::indexData must be null "
+ "if "
"IAccelerationStructure::TriangleDesc::indexFormat is "
"Format::Unknown");
}
@@ -144,9 +149,7 @@ void validateAccelerationStructureBuildInputs(
}
}
break;
- default:
- GFX_DIAGNOSE_ERROR("Invalid value of IAccelerationStructure::Kind.");
- break;
+ default: GFX_DIAGNOSE_ERROR("Invalid value of IAccelerationStructure::Kind."); break;
}
}
diff --git a/tools/gfx/debug-layer/debug-helper-functions.h b/tools/gfx/debug-layer/debug-helper-functions.h
index f2edd0d84..8fad98f8a 100644
--- a/tools/gfx/debug-layer/debug-helper-functions.h
+++ b/tools/gfx/debug-layer/debug-helper-functions.h
@@ -1,7 +1,6 @@
// debug-helper-functions.h
#pragma once
#include "debug-base.h"
-
#include "debug-buffer.h"
#include "debug-command-buffer.h"
#include "debug-command-queue.h"
@@ -29,13 +28,13 @@ namespace debug
{
#ifdef __FUNCSIG__
-# define SLANG_FUNC_SIG __FUNCSIG__
+#define SLANG_FUNC_SIG __FUNCSIG__
#elif defined(__PRETTY_FUNCTION__)
-# define SLANG_FUNC_SIG __FUNCSIG__
+#define SLANG_FUNC_SIG __FUNCSIG__
#elif defined(__FUNCTION__)
-# define SLANG_FUNC_SIG __FUNCTION__
+#define SLANG_FUNC_SIG __FUNCTION__
#else
-# define SLANG_FUNC_SIG "UnknownFunction"
+#define SLANG_FUNC_SIG "UnknownFunction"
#endif
extern thread_local const char* _currentFunctionName;
@@ -50,12 +49,12 @@ struct SetCurrentFuncRAII
/// Returns the public API function name from a `SLANG_FUNC_SIG` string.
String _gfxGetFuncName(const char* input);
-template <typename... TArgs>
+template<typename... TArgs>
char* _gfxDiagnoseFormat(
- char* buffer, // Initial buffer to output formatted string.
- size_t shortBufferSize, // Size of the initial buffer.
+ char* buffer, // Initial buffer to output formatted string.
+ size_t shortBufferSize, // Size of the initial buffer.
List<char>& bufferArray, // A list for allocating a large buffer if needed.
- const char* format, // The format string.
+ const char* format, // The format string.
TArgs... args)
{
int length = sprintf_s(buffer, shortBufferSize, format, args...);
@@ -70,7 +69,7 @@ char* _gfxDiagnoseFormat(
return buffer;
}
-template <typename... TArgs>
+template<typename... TArgs>
void _gfxDiagnoseImpl(DebugMessageType type, const char* format, TArgs... args)
{
char shortBuffer[256];
@@ -103,7 +102,11 @@ void _gfxDiagnoseImpl(DebugMessageType type, const char* format, TArgs... args)
char shortBuffer[256]; \
List<char> bufferArray; \
auto message = _gfxDiagnoseFormat( \
- shortBuffer, sizeof(shortBuffer), bufferArray, format, __VA_ARGS__); \
+ shortBuffer, \
+ sizeof(shortBuffer), \
+ bufferArray, \
+ format, \
+ __VA_ARGS__); \
_gfxDiagnoseImpl( \
type, \
"%s: %s", \
@@ -117,16 +120,16 @@ void _gfxDiagnoseImpl(DebugMessageType type, const char* format, TArgs... args)
I##typeName* Debug##typeName::getInterface(const Slang::Guid& guid) \
{ \
return (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_I##typeName) \
- ? static_cast<I##typeName*>(this) \
- : nullptr; \
+ ? static_cast<I##typeName*>(this) \
+ : nullptr; \
}
#define SLANG_GFX_DEBUG_GET_INTERFACE_IMPL_PARENT(typeName, parentType) \
I##typeName* Debug##typeName::getInterface(const Slang::Guid& guid) \
{ \
return (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_I##typeName || \
guid == GfxGUID::IID_I##parentType) \
- ? static_cast<I##typeName*>(this) \
- : nullptr; \
+ ? static_cast<I##typeName*>(this) \
+ : nullptr; \
}
// Utility conversion functions to get Debug* object or the inner object from a user provided
diff --git a/tools/gfx/debug-layer/debug-query.h b/tools/gfx/debug-layer/debug-query.h
index 890745387..a1faa966b 100644
--- a/tools/gfx/debug-layer/debug-query.h
+++ b/tools/gfx/debug-layer/debug-query.h
@@ -15,10 +15,11 @@ public:
SLANG_COM_OBJECT_IUNKNOWN_ALL;
IQueryPool::Desc desc;
+
public:
IQueryPool* getInterface(const Slang::Guid& guid);
virtual SLANG_NO_THROW Result SLANG_MCALL
- getResult(GfxIndex index, GfxCount count, uint64_t* data) override;
+ getResult(GfxIndex index, GfxCount count, uint64_t* data) override;
virtual SLANG_NO_THROW Result SLANG_MCALL reset() override;
};
diff --git a/tools/gfx/debug-layer/debug-resource-views.h b/tools/gfx/debug-layer/debug-resource-views.h
index b9a9b4539..625860a08 100644
--- a/tools/gfx/debug-layer/debug-resource-views.h
+++ b/tools/gfx/debug-layer/debug-resource-views.h
@@ -17,7 +17,8 @@ public:
public:
IResourceView* getInterface(const Slang::Guid& guid);
virtual SLANG_NO_THROW Desc* SLANG_MCALL getViewDesc() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outNativeHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeHandle(InteropHandle* outNativeHandle) override;
};
class DebugAccelerationStructure : public DebugObject<IAccelerationStructure>
@@ -29,7 +30,7 @@ public:
IAccelerationStructure* getInterface(const Slang::Guid& guid);
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeHandle(InteropHandle* outNativeHandle) override;
+ getNativeHandle(InteropHandle* outNativeHandle) override;
virtual SLANG_NO_THROW Desc* SLANG_MCALL getViewDesc() override;
};
diff --git a/tools/gfx/debug-layer/debug-sampler-state.h b/tools/gfx/debug-layer/debug-sampler-state.h
index d0b082ec5..0cabd8da7 100644
--- a/tools/gfx/debug-layer/debug-sampler-state.h
+++ b/tools/gfx/debug-layer/debug-sampler-state.h
@@ -17,7 +17,7 @@ public:
public:
ISamplerState* getInterface(const Slang::Guid& guid);
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeHandle(InteropHandle* outNativeHandle) override;
+ getNativeHandle(InteropHandle* outNativeHandle) override;
};
} // namespace debug
diff --git a/tools/gfx/debug-layer/debug-shader-object.cpp b/tools/gfx/debug-layer/debug-shader-object.cpp
index eb67c46ab..c262320f5 100644
--- a/tools/gfx/debug-layer/debug-shader-object.cpp
+++ b/tools/gfx/debug-layer/debug-shader-object.cpp
@@ -1,11 +1,10 @@
// debug-shader-object.cpp
#include "debug-shader-object.h"
+#include "debug-helper-functions.h"
#include "debug-resource-views.h"
#include "debug-sampler-state.h"
-#include "debug-helper-functions.h"
-
namespace gfx
{
using namespace Slang;
@@ -142,7 +141,9 @@ Result DebugShaderObject::setCombinedTextureSampler(
m_resources[ShaderOffsetKey{offset}] = viewImpl;
m_initializedBindingRanges.add(offset.bindingRangeIndex);
return baseObject->setCombinedTextureSampler(
- offset, getInnerObj(viewImpl), getInnerObj(sampler));
+ offset,
+ getInnerObj(viewImpl),
+ getInnerObj(sampler));
}
Result DebugShaderObject::setSpecializationArgs(
@@ -155,11 +156,13 @@ Result DebugShaderObject::setSpecializationArgs(
}
Result DebugShaderObject::getCurrentVersion(
- ITransientResourceHeap* transientHeap, IShaderObject** outObject)
+ ITransientResourceHeap* transientHeap,
+ IShaderObject** outObject)
{
SLANG_GFX_API_FUNC;
ComPtr<IShaderObject> innerObject;
- SLANG_RETURN_ON_FAIL(baseObject->getCurrentVersion(getInnerObj(transientHeap), innerObject.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ baseObject->getCurrentVersion(getInnerObj(transientHeap), innerObject.writeRef()));
RefPtr<DebugShaderObject> debugShaderObject = new DebugShaderObject();
debugShaderObject->baseObject = innerObject;
debugShaderObject->m_typeName = innerObject->getElementTypeLayout()->getName();
diff --git a/tools/gfx/debug-layer/debug-shader-object.h b/tools/gfx/debug-layer/debug-shader-object.h
index b5a268892..56fda0622 100644
--- a/tools/gfx/debug-layer/debug-shader-object.h
+++ b/tools/gfx/debug-layer/debug-shader-object.h
@@ -15,8 +15,8 @@ struct ShaderOffsetKey
bool operator==(ShaderOffsetKey other) const
{
return offset.bindingArrayIndex == other.offset.bindingArrayIndex &&
- offset.bindingRangeIndex == other.offset.bindingRangeIndex &&
- offset.uniformOffset == other.offset.uniformOffset;
+ offset.bindingRangeIndex == other.offset.bindingRangeIndex &&
+ offset.uniformOffset == other.offset.uniformOffset;
}
Slang::HashCode getHashCode() const
{
@@ -40,17 +40,17 @@ public:
virtual SLANG_NO_THROW ShaderObjectContainerType SLANG_MCALL getContainerType() override;
virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** entryPoint) override;
+ getEntryPoint(GfxIndex index, IShaderObject** entryPoint) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& offset, void const* data, size_t size) override;
+ setData(ShaderOffset const& offset, void const* data, size_t size) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getObject(ShaderOffset const& offset, IShaderObject** object) override;
+ getObject(ShaderOffset const& offset, IShaderObject** object) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setObject(ShaderOffset const& offset, IShaderObject* object) override;
+ setObject(ShaderOffset const& offset, IShaderObject* object) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
ShaderOffset const& offset,
IResourceView* textureView,
@@ -60,12 +60,12 @@ public:
const slang::SpecializationArg* args,
GfxCount count) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentVersion(
- ITransientResourceHeap* transientHeap, IShaderObject** outObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getCurrentVersion(ITransientResourceHeap* transientHeap, IShaderObject** outObject) override;
virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override;
virtual SLANG_NO_THROW size_t SLANG_MCALL getSize() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setConstantBufferOverride(IBufferResource* constantBuffer) override;
+ setConstantBufferOverride(IBufferResource* constantBuffer) override;
public:
// Type name of an ordinary shader object.
diff --git a/tools/gfx/debug-layer/debug-shader-program.h b/tools/gfx/debug-layer/debug-shader-program.h
index 0f154f2a3..a98a40ded 100644
--- a/tools/gfx/debug-layer/debug-shader-program.h
+++ b/tools/gfx/debug-layer/debug-shader-program.h
@@ -16,7 +16,9 @@ public:
public:
IShaderProgram* getInterface(const Slang::Guid& guid);
- virtual SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL findTypeByName(const char* name) override;
+ virtual SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL
+ findTypeByName(const char* name) override;
+
public:
Slang::ComPtr<slang::IComponentType> m_slangProgram;
};
diff --git a/tools/gfx/debug-layer/debug-swap-chain.cpp b/tools/gfx/debug-layer/debug-swap-chain.cpp
index b1d3bc201..904d8d0c6 100644
--- a/tools/gfx/debug-layer/debug-swap-chain.cpp
+++ b/tools/gfx/debug-layer/debug-swap-chain.cpp
@@ -2,9 +2,8 @@
#include "debug-swap-chain.h"
#include "debug-command-queue.h"
-#include "debug-texture.h"
-
#include "debug-helper-functions.h"
+#include "debug-texture.h"
namespace gfx
{
diff --git a/tools/gfx/debug-layer/debug-swap-chain.h b/tools/gfx/debug-layer/debug-swap-chain.h
index 83a467d65..92accb4fd 100644
--- a/tools/gfx/debug-layer/debug-swap-chain.h
+++ b/tools/gfx/debug-layer/debug-swap-chain.h
@@ -18,7 +18,7 @@ public:
ISwapchain* getInterface(const Slang::Guid& guid);
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getImage(GfxIndex index, ITextureResource** outResource) override;
+ getImage(GfxIndex index, ITextureResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL present() override;
virtual SLANG_NO_THROW int SLANG_MCALL acquireNextImage() override;
virtual SLANG_NO_THROW Result SLANG_MCALL resize(GfxCount width, GfxCount height) override;
diff --git a/tools/gfx/debug-layer/debug-texture.cpp b/tools/gfx/debug-layer/debug-texture.cpp
index ad3dce4fe..87ca019b0 100644
--- a/tools/gfx/debug-layer/debug-texture.cpp
+++ b/tools/gfx/debug-layer/debug-texture.cpp
@@ -39,7 +39,10 @@ Result DebugTextureResource::setDebugName(const char* name)
return baseObject->setDebugName(name);
}
-const char* DebugTextureResource::getDebugName() { return baseObject->getDebugName(); }
+const char* DebugTextureResource::getDebugName()
+{
+ return baseObject->getDebugName();
+}
} // namespace debug
} // namespace gfx
diff --git a/tools/gfx/debug-layer/debug-texture.h b/tools/gfx/debug-layer/debug-texture.h
index 79e3aa3cf..a560f6a56 100644
--- a/tools/gfx/debug-layer/debug-texture.h
+++ b/tools/gfx/debug-layer/debug-texture.h
@@ -18,7 +18,8 @@ public:
ITextureResource* getInterface(const Slang::Guid& guid);
virtual SLANG_NO_THROW Type SLANG_MCALL getType() override;
virtual SLANG_NO_THROW Desc* SLANG_MCALL getDesc() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL setDebugName(const char* name) override;
diff --git a/tools/gfx/debug-layer/debug-transient-heap.cpp b/tools/gfx/debug-layer/debug-transient-heap.cpp
index 84861297a..424a8feb1 100644
--- a/tools/gfx/debug-layer/debug-transient-heap.cpp
+++ b/tools/gfx/debug-layer/debug-transient-heap.cpp
@@ -2,7 +2,6 @@
#include "debug-transient-heap.h"
#include "debug-command-buffer.h"
-
#include "debug-helper-functions.h"
namespace gfx
@@ -79,7 +78,10 @@ Result DebugTransientResourceHeapD3D12::allocateTransientDescriptorTable(
SLANG_GFX_API_FUNC;
return baseObject->allocateTransientDescriptorTable(
- type, count, outDescriptorOffset, outD3DDescriptorHeapHandle);
+ type,
+ count,
+ outDescriptorOffset,
+ outD3DDescriptorHeapHandle);
}
} // namespace debug
diff --git a/tools/gfx/debug-layer/debug-transient-heap.h b/tools/gfx/debug-layer/debug-transient-heap.h
index 60430228d..4b4b4e227 100644
--- a/tools/gfx/debug-layer/debug-transient-heap.h
+++ b/tools/gfx/debug-layer/debug-transient-heap.h
@@ -16,12 +16,13 @@ public:
SLANG_COM_OBJECT_IUNKNOWN_RELEASE;
public:
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) override;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ queryInterface(SlangUUID const& uuid, void** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL synchronizeAndReset() override;
virtual SLANG_NO_THROW Result SLANG_MCALL finish() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
+ createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
};
class DebugTransientResourceHeapD3D12 : public DebugObject<ITransientResourceHeapD3D12>
@@ -29,8 +30,10 @@ class DebugTransientResourceHeapD3D12 : public DebugObject<ITransientResourceHea
public:
SLANG_COM_OBJECT_IUNKNOWN_ADD_REF;
SLANG_COM_OBJECT_IUNKNOWN_RELEASE;
+
public:
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) override;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL
+ queryInterface(SlangUUID const& uuid, void** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL allocateTransientDescriptorTable(
DescriptorType type,
GfxCount count,
diff --git a/tools/gfx/flag-combiner.cpp b/tools/gfx/flag-combiner.cpp
index f67f869ce..4a3332f98 100644
--- a/tools/gfx/flag-combiner.cpp
+++ b/tools/gfx/flag-combiner.cpp
@@ -1,6 +1,7 @@
#include "flag-combiner.h"
-namespace gfx {
+namespace gfx
+{
using namespace Slang;
void FlagCombiner::add(uint32_t flags, ChangeType type)
diff --git a/tools/gfx/flag-combiner.h b/tools/gfx/flag-combiner.h
index db8c6863b..2b14be277 100644
--- a/tools/gfx/flag-combiner.h
+++ b/tools/gfx/flag-combiner.h
@@ -3,7 +3,8 @@
#include "../../source/core/slang-list.h"
-namespace gfx {
+namespace gfx
+{
/* A default set of flags that can be used for checking devices */
typedef uint32_t DeviceCheckFlags;
@@ -11,19 +12,20 @@ struct DeviceCheckFlag
{
enum Enum : DeviceCheckFlags
{
- UseFullFeatureLevel = 0x1, //< If set will use full feature level (on dx this is D3D_FEATURE_LEVEL_11_1 else will try D3D_FEATURE_LEVEL_11_0)
- UseHardwareDevice = 0x2, //< If set will try a hardware device
- UseDebug = 0x4, //< If set will enable use of debug
+ UseFullFeatureLevel = 0x1, //< If set will use full feature level (on dx this is
+ // D3D_FEATURE_LEVEL_11_1 else will try D3D_FEATURE_LEVEL_11_0)
+ UseHardwareDevice = 0x2, //< If set will try a hardware device
+ UseDebug = 0x4, //< If set will enable use of debug
};
};
/* Controls how and the order flags are changed, on the FlagCombiner */
enum class ChangeType
{
- On, ///< Always on
- Off, ///< Always off
- OnOff, ///< Initially on then off
- OffOn, ///< Initially off then on
+ On, ///< Always on
+ Off, ///< Always off
+ OnOff, ///< Initially on then off
+ OffOn, ///< Initially off then on
};
/* Calculates all the combinations of flags as controlled by the change types.
@@ -36,32 +38,32 @@ for (first added) {
}
}
-So the last added flags will have the highest frequency.
+So the last added flags will have the highest frequency.
*/
class FlagCombiner
{
public:
- /// Add a flag and how it changes over the combinations
- /// NOTE! That the order flags are added controls the order they change when combinations are calculated - earlier added
- /// flags will change with the highest frequency
+ /// Add a flag and how it changes over the combinations
+ /// NOTE! That the order flags are added controls the order they change when combinations are
+ /// calculated - earlier added flags will change with the highest frequency
void add(uint32_t flags, ChangeType changeType);
- /// Calculate all of the combinations and place in an array
+ /// Calculate all of the combinations and place in an array
void calcCombinations(Slang::List<uint32_t>& outCombinations) const;
- /// Reset back to initial state
- void reset();
+ /// Reset back to initial state
+ void reset();
- /// Get the total amount of combinations
+ /// Get the total amount of combinations
int getNumCombinations() const { return 1 << m_numChangingBits; }
- /// Get the combination at i
+ /// Get the combination at i
uint32_t getCombination(int i) const;
protected:
uint32_t m_changingBits[32];
int m_numChangingBits = 0;
- uint32_t m_usedFlags = 0;
+ uint32_t m_usedFlags = 0;
uint32_t m_invertBits = 0;
};
diff --git a/tools/gfx/immediate-renderer-base.cpp b/tools/gfx/immediate-renderer-base.cpp
index 4043512c6..e993ce319 100644
--- a/tools/gfx/immediate-renderer-base.cpp
+++ b/tools/gfx/immediate-renderer-base.cpp
@@ -1,10 +1,11 @@
#include "immediate-renderer-base.h"
-#include "simple-render-pass-layout.h"
-#include "simple-transient-resource-heap.h"
+
+#include "command-encoder-com-forward.h"
#include "command-writer.h"
#include "core/slang-basic.h"
#include "core/slang-blob.h"
-#include "command-encoder-com-forward.h"
+#include "simple-render-pass-layout.h"
+#include "simple-transient-resource-heap.h"
namespace gfx
{
@@ -44,10 +45,7 @@ public:
m_transientHeap = transientHeap;
}
- void reset()
- {
- m_writer.clear();
- }
+ void reset() { m_writer.clear(); }
class ResourceCommandEncoderImpl : public IResourceCommandEncoder
{
@@ -62,14 +60,15 @@ public:
virtual void* getInterface(SlangUUID const& uuid)
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
return nullptr;
}
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject) override
+ queryInterface(SlangUUID const& uuid, void** outObject) override
{
if (auto ptr = getInterface(uuid))
{
@@ -93,13 +92,13 @@ public:
}
virtual SLANG_NO_THROW void SLANG_MCALL
- uploadBufferData(IBufferResource* dst, size_t offset, size_t size, void* data) override
+ uploadBufferData(IBufferResource* dst, size_t offset, size_t size, void* data) override
{
m_writer->uploadBufferData(dst, offset, size, data);
}
virtual SLANG_NO_THROW void SLANG_MCALL
- writeTimestamp(IQueryPool* pool, GfxIndex index) override
+ writeTimestamp(IQueryPool* pool, GfxIndex index) override
{
m_writer->writeTimestamp(pool, index);
}
@@ -109,14 +108,16 @@ public:
ITextureResource* const* textures,
ResourceState src,
ResourceState dst) override
- {}
+ {
+ }
virtual SLANG_NO_THROW void SLANG_MCALL bufferBarrier(
GfxCount count,
IBufferResource* const* buffers,
ResourceState src,
ResourceState dst) override
- {}
+ {
+ }
virtual SLANG_NO_THROW void SLANG_MCALL copyTexture(
ITextureResource* dst,
@@ -238,43 +239,44 @@ public:
}
virtual SLANG_NO_THROW void SLANG_MCALL
- beginDebugEvent(const char* name, float rgbColor[3]) override
+ beginDebugEvent(const char* name, float rgbColor[3]) override
{
SLANG_UNUSED(name);
SLANG_UNUSED(rgbColor);
}
- virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override
- {
- }
+ virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override {}
};
ResourceCommandEncoderImpl m_resourceCommandEncoder;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeResourceCommands(IResourceCommandEncoder** outEncoder) override
+ encodeResourceCommands(IResourceCommandEncoder** outEncoder) override
{
m_resourceCommandEncoder.init(this);
*outEncoder = &m_resourceCommandEncoder;
}
- class RenderCommandEncoderImpl
- : public IRenderCommandEncoder
- , public ResourceCommandEncoderImpl
+ class RenderCommandEncoderImpl : public IRenderCommandEncoder, public ResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderImpl)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
return nullptr;
}
+
public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override {}
- void init(CommandBufferImpl* cmdBuffer, SimpleRenderPassLayout* renderPass, IFramebuffer* framebuffer)
+ void init(
+ CommandBufferImpl* cmdBuffer,
+ SimpleRenderPassLayout* renderPass,
+ IFramebuffer* framebuffer)
{
ResourceCommandEncoderImpl::init(cmdBuffer);
@@ -310,38 +312,43 @@ public:
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override
+ bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override
{
m_writer->setPipelineState(state);
auto stateImpl = static_cast<PipelineStateBase*>(state);
SLANG_RETURN_ON_FAIL(m_commandBuffer->m_renderer->createRootShaderObject(
- stateImpl->m_program, m_commandBuffer->m_rootShaderObject.writeRef()));
+ stateImpl->m_program,
+ m_commandBuffer->m_rootShaderObject.writeRef()));
*outRootObject = m_commandBuffer->m_rootShaderObject.Ptr();
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override
{
m_writer->setPipelineState(state);
auto stateImpl = static_cast<PipelineStateBase*>(state);
SLANG_RETURN_ON_FAIL(m_commandBuffer->m_renderer->createRootShaderObject(
- stateImpl->m_program, m_commandBuffer->m_rootShaderObject.writeRef()));
- m_commandBuffer->m_rootShaderObject->copyFrom(rootObject, m_commandBuffer->m_transientHeap);
+ stateImpl->m_program,
+ m_commandBuffer->m_rootShaderObject.writeRef()));
+ m_commandBuffer->m_rootShaderObject->copyFrom(
+ rootObject,
+ m_commandBuffer->m_transientHeap);
return SLANG_OK;
}
virtual SLANG_NO_THROW void SLANG_MCALL
- setViewports(GfxCount count, const Viewport* viewports) override
+ setViewports(GfxCount count, const Viewport* viewports) override
{
m_writer->setViewports(count, viewports);
}
virtual SLANG_NO_THROW void SLANG_MCALL
- setScissorRects(GfxCount count, const ScissorRect* scissors) override
+ setScissorRects(GfxCount count, const ScissorRect* scissors) override
{
m_writer->setScissorRects(count, scissors);
}
- virtual SLANG_NO_THROW void SLANG_MCALL setPrimitiveTopology(PrimitiveTopology topology) override
+ virtual SLANG_NO_THROW void SLANG_MCALL
+ setPrimitiveTopology(PrimitiveTopology topology) override
{
m_writer->setPrimitiveTopology(topology);
}
@@ -355,13 +362,13 @@ public:
}
virtual SLANG_NO_THROW void SLANG_MCALL
- setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset) override
+ setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset) override
{
m_writer->setIndexBuffer(buffer, indexFormat, offset);
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- draw(GfxCount vertexCount, GfxIndex startVertex) override
+ draw(GfxCount vertexCount, GfxIndex startVertex) override
{
m_writer->bindRootShaderObject(m_commandBuffer->m_rootShaderObject);
m_writer->draw(vertexCount, startVertex);
@@ -369,14 +376,15 @@ public:
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- drawIndexed(GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex) override
+ drawIndexed(GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex) override
{
m_writer->bindRootShaderObject(m_commandBuffer->m_rootShaderObject);
m_writer->drawIndexed(indexCount, startIndex, baseVertex);
return SLANG_OK;
}
- virtual SLANG_NO_THROW void SLANG_MCALL setStencilReference(uint32_t referenceValue) override
+ virtual SLANG_NO_THROW void SLANG_MCALL
+ setStencilReference(uint32_t referenceValue) override
{
m_writer->setStencilReference(referenceValue);
}
@@ -448,7 +456,12 @@ public:
GfxIndex startInstanceLocation) override
{
m_writer->bindRootShaderObject(m_commandBuffer->m_rootShaderObject);
- m_writer->drawIndexedInstanced(indexCount, instanceCount, startIndexLocation, baseVertexLocation, startInstanceLocation);
+ m_writer->drawIndexedInstanced(
+ indexCount,
+ instanceCount,
+ startIndexLocation,
+ baseVertexLocation,
+ startInstanceLocation);
return SLANG_OK;
}
};
@@ -466,45 +479,47 @@ public:
*outEncoder = &m_renderCommandEncoder;
}
- class ComputeCommandEncoderImpl
- : public IComputeCommandEncoder
- , public ResourceCommandEncoderImpl
+ class ComputeCommandEncoderImpl : public IComputeCommandEncoder,
+ public ResourceCommandEncoderImpl
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderImpl)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
return nullptr;
}
+
public:
- virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override
- {
- }
+ virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override {}
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override
+ bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override
{
m_writer->setPipelineState(state);
auto stateImpl = static_cast<PipelineStateBase*>(state);
SLANG_RETURN_ON_FAIL(m_commandBuffer->m_renderer->createRootShaderObject(
- stateImpl->m_program, m_commandBuffer->m_rootShaderObject.writeRef()));
+ stateImpl->m_program,
+ m_commandBuffer->m_rootShaderObject.writeRef()));
*outRootObject = m_commandBuffer->m_rootShaderObject.Ptr();
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override
+ bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override
{
m_writer->setPipelineState(state);
auto stateImpl = static_cast<PipelineStateBase*>(state);
SLANG_RETURN_ON_FAIL(m_commandBuffer->m_renderer->createRootShaderObject(
- stateImpl->m_program, m_commandBuffer->m_rootShaderObject.writeRef()));
+ stateImpl->m_program,
+ m_commandBuffer->m_rootShaderObject.writeRef()));
m_commandBuffer->m_rootShaderObject->copyFrom(
- rootObject, m_commandBuffer->m_transientHeap);
+ rootObject,
+ m_commandBuffer->m_transientHeap);
return SLANG_OK;
}
@@ -515,7 +530,8 @@ public:
return SLANG_OK;
}
- virtual SLANG_NO_THROW Result SLANG_MCALL dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override
{
SLANG_UNIMPLEMENTED_X("ImmediateRenderBase::dispatchComputeIndirect");
}
@@ -523,19 +539,19 @@ public:
ComputeCommandEncoderImpl m_computeCommandEncoder;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeComputeCommands(IComputeCommandEncoder** outEncoder) override
+ encodeComputeCommands(IComputeCommandEncoder** outEncoder) override
{
m_computeCommandEncoder.init(this);
*outEncoder = &m_computeCommandEncoder;
}
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override
+ encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override
{
*outEncoder = nullptr;
}
- virtual SLANG_NO_THROW void SLANG_MCALL close() override { }
+ virtual SLANG_NO_THROW void SLANG_MCALL close() override {}
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override
{
@@ -550,25 +566,31 @@ public:
switch (name)
{
case CommandName::SetPipelineState:
- m_renderer->setPipelineState(m_writer.getObject<PipelineStateBase>(cmd.operands[0]));
+ m_renderer->setPipelineState(
+ m_writer.getObject<PipelineStateBase>(cmd.operands[0]));
break;
case CommandName::BindRootShaderObject:
- m_renderer->bindRootShaderObject(m_writer.getObject<ShaderObjectBase>(cmd.operands[0]));
+ m_renderer->bindRootShaderObject(
+ m_writer.getObject<ShaderObjectBase>(cmd.operands[0]));
break;
case CommandName::SetFramebuffer:
m_renderer->setFramebuffer(m_writer.getObject<FramebufferBase>(cmd.operands[0]));
break;
case CommandName::ClearFrame:
m_renderer->clearFrame(
- cmd.operands[0], (cmd.operands[1] != 0), (cmd.operands[2] != 0));
+ cmd.operands[0],
+ (cmd.operands[1] != 0),
+ (cmd.operands[2] != 0));
break;
case CommandName::SetViewports:
m_renderer->setViewports(
- (UInt)cmd.operands[0], m_writer.getData<Viewport>(cmd.operands[1]));
+ (UInt)cmd.operands[0],
+ m_writer.getData<Viewport>(cmd.operands[1]));
break;
case CommandName::SetScissorRects:
m_renderer->setScissorRects(
- (UInt)cmd.operands[0], m_writer.getData<ScissorRect>(cmd.operands[1]));
+ (UInt)cmd.operands[0],
+ m_writer.getData<ScissorRect>(cmd.operands[1]));
break;
case CommandName::SetPrimitiveTopology:
m_renderer->setPrimitiveTopology((PrimitiveTopology)cmd.operands[0]);
@@ -594,27 +616,33 @@ public:
(Format)cmd.operands[1],
(UInt)cmd.operands[2]);
break;
- case CommandName::Draw:
- m_renderer->draw(cmd.operands[0], cmd.operands[1]);
- break;
+ case CommandName::Draw: m_renderer->draw(cmd.operands[0], cmd.operands[1]); break;
case CommandName::DrawIndexed:
- m_renderer->drawIndexed(
- cmd.operands[0], cmd.operands[1], cmd.operands[2]);
+ m_renderer->drawIndexed(cmd.operands[0], cmd.operands[1], cmd.operands[2]);
break;
case CommandName::DrawInstanced:
m_renderer->drawInstanced(
- cmd.operands[0], cmd.operands[1], cmd.operands[2], cmd.operands[3]);
+ cmd.operands[0],
+ cmd.operands[1],
+ cmd.operands[2],
+ cmd.operands[3]);
break;
case CommandName::DrawIndexedInstanced:
m_renderer->drawIndexedInstanced(
- cmd.operands[0], cmd.operands[1], cmd.operands[2], cmd.operands[3], cmd.operands[4]);
+ cmd.operands[0],
+ cmd.operands[1],
+ cmd.operands[2],
+ cmd.operands[3],
+ cmd.operands[4]);
break;
case CommandName::SetStencilReference:
m_renderer->setStencilReference(cmd.operands[0]);
break;
case CommandName::DispatchCompute:
m_renderer->dispatchCompute(
- int(cmd.operands[0]), int(cmd.operands[1]), int(cmd.operands[2]));
+ int(cmd.operands[0]),
+ int(cmd.operands[1]),
+ int(cmd.operands[2]));
break;
case CommandName::UploadBufferData:
m_renderer->uploadBufferData(
@@ -632,11 +660,11 @@ public:
cmd.operands[4]);
break;
case CommandName::WriteTimestamp:
- m_renderer->writeTimestamp(m_writer.getObject<QueryPoolBase>(cmd.operands[0]), (GfxIndex)cmd.operands[1]);
- break;
- default:
- assert(!"unknown command");
+ m_renderer->writeTimestamp(
+ m_writer.getObject<QueryPoolBase>(cmd.operands[0]),
+ (GfxIndex)cmd.operands[1]);
break;
+ default: assert(!"unknown command"); break;
}
}
m_writer.clear();
@@ -668,7 +696,10 @@ public:
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override { return m_desc; }
virtual SLANG_NO_THROW void SLANG_MCALL executeCommandBuffers(
- GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal) override
+ GfxCount count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal) override
{
// TODO: implement fence signal.
assert(fence == nullptr);
@@ -676,7 +707,8 @@ public:
CommandBufferInfo info = {};
for (GfxIndex i = 0; i < count; i++)
{
- info.hasWriteTimestamps |= static_cast<CommandBufferImpl*>(commandBuffers[i])->m_writer.m_hasWriteTimestamps;
+ info.hasWriteTimestamps |=
+ static_cast<CommandBufferImpl*>(commandBuffers[i])->m_writer.m_hasWriteTimestamps;
}
static_cast<ImmediateRendererBase*>(m_renderer.get())->beginCommandBuffer(info);
for (GfxIndex i = 0; i < count; i++)
@@ -688,8 +720,8 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL waitOnHost() override { getRenderer()->waitForGpu(); }
- virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ waitForFenceValuesOnDevice(GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override
{
return SLANG_FAIL;
}
@@ -703,7 +735,7 @@ public:
using TransientResourceHeapImpl =
SimpleTransientResourceHeap<ImmediateRendererBase, CommandBufferImpl>;
-}
+} // namespace
ImmediateRendererBase::ImmediateRendererBase()
{
@@ -720,9 +752,8 @@ SLANG_NO_THROW Result SLANG_MCALL ImmediateRendererBase::createTransientResource
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL ImmediateRendererBase::createCommandQueue(
- const ICommandQueue::Desc& desc,
- ICommandQueue** outQueue)
+SLANG_NO_THROW Result SLANG_MCALL
+ImmediateRendererBase::createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue)
{
SLANG_UNUSED(desc);
// Only one queue is supported.
@@ -775,4 +806,4 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ImmediateRendererBase::readBufferResource
return SLANG_OK;
}
-}
+} // namespace gfx
diff --git a/tools/gfx/immediate-renderer-base.h b/tools/gfx/immediate-renderer-base.h
index 894d00bf7..28aa52a70 100644
--- a/tools/gfx/immediate-renderer-base.h
+++ b/tools/gfx/immediate-renderer-base.h
@@ -17,9 +17,7 @@ enum class MapFlavor
WriteDiscard,
};
-class ImmediateCommandQueueBase
- : public ICommandQueue
- , public Slang::ComObject
+class ImmediateCommandQueueBase : public ICommandQueue, public Slang::ComObject
{
public:
// Immediate device also holds a strong reference to an instance of `ImmediateCommandQueue`,
@@ -64,11 +62,12 @@ public:
GfxCount slotCount,
IBufferResource* const* buffers,
const Offset* offsets) = 0;
- virtual void setIndexBuffer(
- IBufferResource* buffer, Format indexFormat, Offset offset = 0) = 0;
+ virtual void setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) = 0;
virtual void draw(GfxCount vertexCount, GfxIndex startVertex = 0) = 0;
virtual void drawIndexed(
- GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) = 0;
+ GfxCount indexCount,
+ GfxIndex startIndex = 0,
+ GfxIndex baseVertex = 0) = 0;
virtual void drawInstanced(
GfxCount vertexCount,
GfxCount instanceCount,
@@ -103,7 +102,7 @@ public:
ImmediateRendererBase();
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
+ createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap(
const ITransientResourceHeap::Desc& desc,
ITransientResourceHeap** outHeap) override;
@@ -111,10 +110,7 @@ public:
const IRenderPassLayout::Desc& desc,
IRenderPassLayout** outRenderPassLayout) override;
- void uploadBufferData(
- IBufferResource* dst,
- Offset offset,
- Size size, void* data);
+ void uploadBufferData(IBufferResource* dst, Offset offset, Size size, void* data);
virtual SLANG_NO_THROW SlangResult SLANG_MCALL readBufferResource(
IBufferResource* buffer,
@@ -159,8 +155,7 @@ public:
SLANG_UNUSED(buffers);
SLANG_UNUSED(offsets);
}
- virtual void setIndexBuffer(
- IBufferResource* buffer, Format indexFormat, Offset offset = 0)
+ virtual void setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0)
override
{
SLANG_UNUSED(buffer);
@@ -172,8 +167,8 @@ public:
SLANG_UNUSED(vertexCount);
SLANG_UNUSED(startVertex);
}
- virtual void drawIndexed(
- GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override
+ virtual void drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0)
+ override
{
SLANG_UNUSED(indexCount);
SLANG_UNUSED(startIndex);
@@ -228,7 +223,7 @@ public:
return SLANG_FAIL;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override
+ createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outFramebuffer);
@@ -243,9 +238,8 @@ public:
return SLANG_FAIL;
}
- virtual SLANG_NO_THROW Result SLANG_MCALL createInputLayout(
- IInputLayout::Desc const& desc,
- IInputLayout** outLayout) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outLayout);
@@ -274,4 +268,4 @@ public:
return SLANG_E_NOT_AVAILABLE;
}
};
-}
+} // namespace gfx
diff --git a/tools/gfx/metal/metal-api.cpp b/tools/gfx/metal/metal-api.cpp
index aa13a605f..8537cc630 100644
--- a/tools/gfx/metal/metal-api.cpp
+++ b/tools/gfx/metal/metal-api.cpp
@@ -4,5 +4,5 @@
#define CA_PRIVATE_IMPLEMENTATION
#define MTL_PRIVATE_IMPLEMENTATION
#include <Foundation/Foundation.hpp>
-#include <QuartzCore/QuartzCore.hpp>
#include <Metal/Metal.hpp>
+#include <QuartzCore/QuartzCore.hpp>
diff --git a/tools/gfx/metal/metal-base.h b/tools/gfx/metal/metal-base.h
index b1650a655..1a7a9eaff 100644
--- a/tools/gfx/metal/metal-base.h
+++ b/tools/gfx/metal/metal-base.h
@@ -14,41 +14,41 @@ namespace gfx
namespace metal
{
- class DeviceImpl;
- class InputLayoutImpl;
- class BufferResourceImpl;
- class FenceImpl;
- class TextureResourceImpl;
- class SamplerStateImpl;
- class ResourceViewImpl;
- class BufferResourceViewImpl;
- class TextureResourceViewImpl;
- class TexelBufferResourceViewImpl;
- class PlainBufferResourceViewImpl;
- class AccelerationStructureImpl;
- class FramebufferLayoutImpl;
- class RenderPassLayoutImpl;
- class FramebufferImpl;
- class PipelineStateImpl;
- class RayTracingPipelineStateImpl;
- class ShaderObjectLayoutImpl;
- class EntryPointLayout;
- class RootShaderObjectLayoutImpl;
- class ShaderProgramImpl;
- class PipelineCommandEncoder;
- class ShaderObjectImpl;
- class MutableShaderObjectImpl;
- class RootShaderObjectImpl;
- class ShaderTableImpl;
- class ResourceCommandEncoder;
- class RenderCommandEncoder;
- class ComputeCommandEncoder;
- class RayTracingCommandEncoder;
- class CommandBufferImpl;
- class CommandQueueImpl;
- class TransientResourceHeapImpl;
- class QueryPoolImpl;
- class SwapchainImpl;
+class DeviceImpl;
+class InputLayoutImpl;
+class BufferResourceImpl;
+class FenceImpl;
+class TextureResourceImpl;
+class SamplerStateImpl;
+class ResourceViewImpl;
+class BufferResourceViewImpl;
+class TextureResourceViewImpl;
+class TexelBufferResourceViewImpl;
+class PlainBufferResourceViewImpl;
+class AccelerationStructureImpl;
+class FramebufferLayoutImpl;
+class RenderPassLayoutImpl;
+class FramebufferImpl;
+class PipelineStateImpl;
+class RayTracingPipelineStateImpl;
+class ShaderObjectLayoutImpl;
+class EntryPointLayout;
+class RootShaderObjectLayoutImpl;
+class ShaderProgramImpl;
+class PipelineCommandEncoder;
+class ShaderObjectImpl;
+class MutableShaderObjectImpl;
+class RootShaderObjectImpl;
+class ShaderTableImpl;
+class ResourceCommandEncoder;
+class RenderCommandEncoder;
+class ComputeCommandEncoder;
+class RayTracingCommandEncoder;
+class CommandBufferImpl;
+class CommandQueueImpl;
+class TransientResourceHeapImpl;
+class QueryPoolImpl;
+class SwapchainImpl;
} // namespace metal
} // namespace gfx
diff --git a/tools/gfx/metal/metal-buffer.cpp b/tools/gfx/metal/metal-buffer.cpp
index 4f2964c5b..ebb48382e 100644
--- a/tools/gfx/metal/metal-buffer.cpp
+++ b/tools/gfx/metal/metal-buffer.cpp
@@ -1,5 +1,6 @@
// metal-buffer.cpp
#include "metal-buffer.h"
+
#include "metal-util.h"
namespace gfx
@@ -11,14 +12,11 @@ namespace metal
{
BufferResourceImpl::BufferResourceImpl(const IBufferResource::Desc& desc, DeviceImpl* device)
- : Parent(desc)
- , m_device(device)
+ : Parent(desc), m_device(device)
{
}
-BufferResourceImpl::~BufferResourceImpl()
-{
-}
+BufferResourceImpl::~BufferResourceImpl() {}
DeviceAddress BufferResourceImpl::getDeviceAddress()
{
diff --git a/tools/gfx/metal/metal-buffer.h b/tools/gfx/metal/metal-buffer.h
index 3f8f60d0e..d8e95c1f1 100644
--- a/tools/gfx/metal/metal-buffer.h
+++ b/tools/gfx/metal/metal-buffer.h
@@ -25,11 +25,13 @@ public:
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) 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;
diff --git a/tools/gfx/metal/metal-command-buffer.cpp b/tools/gfx/metal/metal-command-buffer.cpp
index 3f9923bf8..19708cfb6 100644
--- a/tools/gfx/metal/metal-command-buffer.cpp
+++ b/tools/gfx/metal/metal-command-buffer.cpp
@@ -1,10 +1,10 @@
// metal-command-buffer.cpp
#include "metal-command-buffer.h"
-#include "metal-device.h"
#include "metal-command-encoder.h"
-#include "metal-shader-object.h"
#include "metal-command-queue.h"
+#include "metal-device.h"
+#include "metal-shader-object.h"
namespace gfx
{
@@ -29,7 +29,9 @@ Result CommandBufferImpl::init(DeviceImpl* device, TransientResourceHeapImpl* tr
}
void CommandBufferImpl::encodeRenderCommands(
- IRenderPassLayout* renderPass, IFramebuffer* framebuffer, IRenderCommandEncoder** outEncoder)
+ IRenderPassLayout* renderPass,
+ IFramebuffer* framebuffer,
+ IRenderCommandEncoder** outEncoder)
{
if (!m_renderCommandEncoder)
{
@@ -72,7 +74,7 @@ void CommandBufferImpl::encodeRayTracingCommands(IRayTracingCommandEncoder** out
void CommandBufferImpl::close()
{
- //m_commandBuffer->commit();
+ // m_commandBuffer->commit();
}
Result CommandBufferImpl::getNativeHandle(InteropHandle* outHandle)
@@ -82,12 +84,14 @@ Result CommandBufferImpl::getNativeHandle(InteropHandle* outHandle)
return SLANG_OK;
}
-MTL::RenderCommandEncoder* CommandBufferImpl::getMetalRenderCommandEncoder(MTL::RenderPassDescriptor* renderPassDesc)
+MTL::RenderCommandEncoder* CommandBufferImpl::getMetalRenderCommandEncoder(
+ MTL::RenderPassDescriptor* renderPassDesc)
{
if (!m_metalRenderCommandEncoder)
{
endMetalCommandEncoder();
- m_metalRenderCommandEncoder = NS::RetainPtr(m_commandBuffer->renderCommandEncoder(renderPassDesc));
+ m_metalRenderCommandEncoder =
+ NS::RetainPtr(m_commandBuffer->renderCommandEncoder(renderPassDesc));
}
return m_metalRenderCommandEncoder.get();
}
diff --git a/tools/gfx/metal/metal-command-buffer.h b/tools/gfx/metal/metal-command-buffer.h
index f0b36898d..1f791d174 100644
--- a/tools/gfx/metal/metal-command-buffer.h
+++ b/tools/gfx/metal/metal-command-buffer.h
@@ -1,10 +1,10 @@
// metal-command-buffer.h
#pragma once
+#include "../simple-transient-resource-heap.h"
#include "metal-base.h"
-#include "metal-shader-object.h"
#include "metal-command-encoder.h"
-#include "../simple-transient-resource-heap.h"
+#include "metal-shader-object.h"
namespace gfx
{
@@ -14,9 +14,7 @@ using namespace Slang;
namespace metal
{
-class CommandBufferImpl
- : public ICommandBuffer
- , public ComObject
+class CommandBufferImpl : public ICommandBuffer, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -45,7 +43,8 @@ public:
void beginCommandBuffer();
- MTL::RenderCommandEncoder* getMetalRenderCommandEncoder(MTL::RenderPassDescriptor* renderPassDesc);
+ MTL::RenderCommandEncoder* getMetalRenderCommandEncoder(
+ MTL::RenderPassDescriptor* renderPassDesc);
MTL::ComputeCommandEncoder* getMetalComputeCommandEncoder();
MTL::BlitCommandEncoder* getMetalBlitCommandEncoder();
void endMetalCommandEncoder();
@@ -56,11 +55,11 @@ public:
IFramebuffer* framebuffer,
IRenderCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
+ encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
+ encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
+ encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL close() override;
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
};
diff --git a/tools/gfx/metal/metal-command-encoder.cpp b/tools/gfx/metal/metal-command-encoder.cpp
index 442c216aa..f4c393193 100644
--- a/tools/gfx/metal/metal-command-encoder.cpp
+++ b/tools/gfx/metal/metal-command-encoder.cpp
@@ -3,6 +3,7 @@
#include "metal-buffer.h"
#include "metal-command-buffer.h"
+#include "metal-helper-functions.h"
#include "metal-query.h"
#include "metal-render-pass.h"
#include "metal-resource-views.h"
@@ -12,8 +13,6 @@
#include "metal-texture.h"
#include "metal-util.h"
-#include "metal-helper-functions.h"
-
namespace gfx
{
@@ -33,7 +32,9 @@ void PipelineCommandEncoder::endEncodingImpl()
m_commandBuffer->endMetalCommandEncoder();
}
-Result PipelineCommandEncoder::setPipelineStateImpl(IPipelineState* state, IShaderObject** outRootObject)
+Result PipelineCommandEncoder::setPipelineStateImpl(
+ IPipelineState* state,
+ IShaderObject** outRootObject)
{
m_currentPipeline = static_cast<PipelineStateImpl*>(state);
// m_commandBuffer->m_mutableRootShaderObject = nullptr;
@@ -52,11 +53,18 @@ void ResourceCommandEncoder::endEncoding()
void ResourceCommandEncoder::writeTimestamp(IQueryPool* queryPool, GfxIndex index)
{
auto encoder = m_commandBuffer->getMetalBlitCommandEncoder();
- encoder->sampleCountersInBuffer(static_cast<QueryPoolImpl*>(queryPool)->m_counterSampleBuffer.get(), index, true);
+ encoder->sampleCountersInBuffer(
+ static_cast<QueryPoolImpl*>(queryPool)->m_counterSampleBuffer.get(),
+ index,
+ true);
}
void ResourceCommandEncoder::copyBuffer(
- IBufferResource* dst, Offset dstOffset, IBufferResource* src, Offset srcOffset, Size size)
+ IBufferResource* dst,
+ Offset dstOffset,
+ IBufferResource* src,
+ Offset srcOffset,
+ Size size)
{
auto encoder = m_commandBuffer->getMetalBlitCommandEncoder();
encoder->copyFromBuffer(
@@ -80,7 +88,8 @@ void ResourceCommandEncoder::copyTexture(
{
auto encoder = m_commandBuffer->getMetalBlitCommandEncoder();
- if (dstSubresource.layerCount == 0 && dstSubresource.mipLevelCount == 0 && srcSubresource.layerCount == 0 && srcSubresource.mipLevelCount == 0)
+ if (dstSubresource.layerCount == 0 && dstSubresource.mipLevelCount == 0 &&
+ srcSubresource.layerCount == 0 && srcSubresource.mipLevelCount == 0)
{
encoder->copyFromTexture(
static_cast<TextureResourceImpl*>(src)->m_texture.get(),
@@ -131,7 +140,10 @@ void ResourceCommandEncoder::copyTextureToBuffer(
}
void ResourceCommandEncoder::uploadBufferData(
- IBufferResource* buffer, Offset offset, Size size, void* data)
+ IBufferResource* buffer,
+ Offset offset,
+ Size size,
+ void* data)
{
SLANG_UNIMPLEMENTED_X("uploadBufferData");
}
@@ -148,13 +160,19 @@ void ResourceCommandEncoder::uploadTextureData(
}
void ResourceCommandEncoder::bufferBarrier(
- GfxCount count, IBufferResource* const* buffers, ResourceState src, ResourceState dst)
+ GfxCount count,
+ IBufferResource* const* buffers,
+ ResourceState src,
+ ResourceState dst)
{
// We use automatic hazard tracking for now, no need for barriers.
}
void ResourceCommandEncoder::textureBarrier(
- GfxCount count, ITextureResource* const* textures, ResourceState src, ResourceState dst)
+ GfxCount count,
+ ITextureResource* const* textures,
+ ResourceState src,
+ ResourceState dst)
{
// We use automatic hazard tracking for now, no need for barriers.
}
@@ -169,7 +187,9 @@ void ResourceCommandEncoder::textureSubresourceBarrier(
}
void ResourceCommandEncoder::clearResourceView(
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags)
+ IResourceView* view,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags)
{
SLANG_UNIMPLEMENTED_X("clearResourceView");
}
@@ -186,7 +206,11 @@ void ResourceCommandEncoder::resolveResource(
}
void ResourceCommandEncoder::resolveQuery(
- IQueryPool* queryPool, GfxIndex index, GfxCount count, IBufferResource* buffer, Offset offset)
+ IQueryPool* queryPool,
+ GfxIndex index,
+ GfxCount count,
+ IBufferResource* buffer,
+ Offset offset)
{
auto encoder = m_commandBuffer->getMetalBlitCommandEncoder();
encoder->resolveCounters(
@@ -226,7 +250,8 @@ void RenderCommandEncoder::beginPass(IRenderPassLayout* renderPass, IFramebuffer
for (Index i = 0; i < m_framebuffer->m_renderTargetViews.getCount(); ++i)
{
TextureResourceViewImpl* renderTargetView = m_framebuffer->m_renderTargetViews[i];
- MTL::RenderPassColorAttachmentDescriptor* colorAttachment = m_renderPassDesc->colorAttachments()->object(i);
+ MTL::RenderPassColorAttachmentDescriptor* colorAttachment =
+ m_renderPassDesc->colorAttachments()->object(i);
colorAttachment->setTexture(renderTargetView->m_textureView.get());
colorAttachment->setLevel(renderTargetView->m_desc.subresourceRange.mipLevel);
colorAttachment->setSlice(renderTargetView->m_desc.subresourceRange.baseArrayLayer);
@@ -235,17 +260,20 @@ void RenderCommandEncoder::beginPass(IRenderPassLayout* renderPass, IFramebuffer
if (m_framebuffer->m_depthStencilView)
{
TextureResourceViewImpl* depthStencilView = m_framebuffer->m_depthStencilView.get();
- MTL::PixelFormat pixelFormat = MetalUtil::translatePixelFormat(depthStencilView->m_desc.format);
+ MTL::PixelFormat pixelFormat =
+ MetalUtil::translatePixelFormat(depthStencilView->m_desc.format);
if (MetalUtil::isDepthFormat(pixelFormat))
{
- MTL::RenderPassDepthAttachmentDescriptor* depthAttachment = m_renderPassDesc->depthAttachment();
+ MTL::RenderPassDepthAttachmentDescriptor* depthAttachment =
+ m_renderPassDesc->depthAttachment();
depthAttachment->setTexture(depthStencilView->m_textureView.get());
depthAttachment->setLevel(depthStencilView->m_desc.subresourceRange.mipLevel);
depthAttachment->setSlice(depthStencilView->m_desc.subresourceRange.baseArrayLayer);
}
if (MetalUtil::isStencilFormat(pixelFormat))
{
- MTL::RenderPassStencilAttachmentDescriptor* stencilAttachment = m_renderPassDesc->stencilAttachment();
+ MTL::RenderPassStencilAttachmentDescriptor* stencilAttachment =
+ m_renderPassDesc->stencilAttachment();
stencilAttachment->setTexture(depthStencilView->m_textureView.get());
stencilAttachment->setLevel(depthStencilView->m_desc.subresourceRange.mipLevel);
stencilAttachment->setSlice(depthStencilView->m_desc.subresourceRange.baseArrayLayer);
@@ -259,13 +287,15 @@ void RenderCommandEncoder::endEncoding()
}
Result RenderCommandEncoder::bindPipeline(
- IPipelineState* pipelineState, IShaderObject** outRootObject)
+ IPipelineState* pipelineState,
+ IShaderObject** outRootObject)
{
return setPipelineStateImpl(pipelineState, outRootObject);
}
Result RenderCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject)
+ IPipelineState* pipelineState,
+ IShaderObject* rootObject)
{
return SLANG_E_NOT_IMPLEMENTED;
}
@@ -324,21 +354,18 @@ void RenderCommandEncoder::setVertexBuffers(
}
void RenderCommandEncoder::setIndexBuffer(
- IBufferResource* buffer, Format indexFormat, Offset offset)
+ IBufferResource* buffer,
+ Format indexFormat,
+ Offset offset)
{
m_indexBuffer = static_cast<BufferResourceImpl*>(buffer)->m_buffer.get();
m_indexBufferOffset = offset;
switch (indexFormat)
{
- case Format::R16_UINT:
- m_indexBufferType = MTL::IndexTypeUInt16;
- break;
- case Format::R32_UINT:
- m_indexBufferType = MTL::IndexTypeUInt32;
- break;
- default:
- assert(!"unsupported index format");
+ case Format::R16_UINT: m_indexBufferType = MTL::IndexTypeUInt16; break;
+ case Format::R32_UINT: m_indexBufferType = MTL::IndexTypeUInt32; break;
+ default: assert(!"unsupported index format");
}
}
@@ -348,7 +375,9 @@ void RenderCommandEncoder::setStencilReference(uint32_t referenceValue)
}
Result RenderCommandEncoder::setSamplePositions(
- GfxCount samplesPerPixel, GfxCount pixelCount, const SamplePosition* samplePositions)
+ GfxCount samplesPerPixel,
+ GfxCount pixelCount,
+ const SamplePosition* samplePositions)
{
return SLANG_E_NOT_AVAILABLE;
}
@@ -368,7 +397,10 @@ Result RenderCommandEncoder::prepareDraw(MTL::RenderCommandEncoder*& encoder)
for (Index i = 0; i < m_vertexBuffers.getCount(); ++i)
{
- encoder->setVertexBuffer(m_vertexBuffers[i], m_vertexBufferOffsets[i], m_currentPipeline->m_vertexBufferOffset + i);
+ encoder->setVertexBuffer(
+ m_vertexBuffers[i],
+ m_vertexBufferOffsets[i],
+ m_currentPipeline->m_vertexBufferOffset + i);
}
encoder->setViewports(m_viewports.getArrayView().getBuffer(), m_viewports.getCount());
@@ -378,8 +410,13 @@ Result RenderCommandEncoder::prepareDraw(MTL::RenderCommandEncoder*& encoder)
const DepthStencilDesc& depthStencilDesc = pipeline->desc.graphics.depthStencil;
encoder->setFrontFacingWinding(MetalUtil::translateWinding(rasterDesc.frontFace));
encoder->setCullMode(MetalUtil::translateCullMode(rasterDesc.cullMode));
- encoder->setDepthClipMode(rasterDesc.depthClipEnable ? MTL::DepthClipModeClip : MTL::DepthClipModeClamp); // TODO correct?
- encoder->setDepthBias(rasterDesc.depthBias, rasterDesc.slopeScaledDepthBias, rasterDesc.depthBiasClamp);
+ encoder->setDepthClipMode(
+ rasterDesc.depthClipEnable ? MTL::DepthClipModeClip
+ : MTL::DepthClipModeClamp); // TODO correct?
+ encoder->setDepthBias(
+ rasterDesc.depthBias,
+ rasterDesc.slopeScaledDepthBias,
+ rasterDesc.depthBiasClamp);
encoder->setTriangleFillMode(MetalUtil::translateTriangleFillMode(rasterDesc.fillMode));
// encoder->setBlendColor(); // not supported by gfx
if (m_framebuffer->m_depthStencilView)
@@ -400,12 +437,19 @@ Result RenderCommandEncoder::draw(GfxCount vertexCount, GfxIndex startVertex)
}
Result RenderCommandEncoder::drawIndexed(
- GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex)
+ GfxCount indexCount,
+ GfxIndex startIndex,
+ GfxIndex baseVertex)
{
MTL::RenderCommandEncoder* encoder;
SLANG_RETURN_ON_FAIL(prepareDraw(encoder));
// TODO baseVertex is not supported by Metal
- encoder->drawIndexedPrimitives(m_primitiveType, indexCount, m_indexBufferType, m_indexBuffer, m_indexBufferOffset);
+ encoder->drawIndexedPrimitives(
+ m_primitiveType,
+ indexCount,
+ m_indexBufferType,
+ m_indexBuffer,
+ m_indexBufferOffset);
return SLANG_OK;
}
@@ -437,7 +481,12 @@ Result RenderCommandEncoder::drawInstanced(
{
MTL::RenderCommandEncoder* encoder;
SLANG_RETURN_ON_FAIL(prepareDraw(encoder));
- encoder->drawPrimitives(m_primitiveType, startVertex, vertexCount, instanceCount, startInstanceLocation);
+ encoder->drawPrimitives(
+ m_primitiveType,
+ startVertex,
+ vertexCount,
+ instanceCount,
+ startInstanceLocation);
return SLANG_OK;
}
@@ -450,7 +499,15 @@ Result RenderCommandEncoder::drawIndexedInstanced(
{
MTL::RenderCommandEncoder* encoder;
SLANG_RETURN_ON_FAIL(prepareDraw(encoder));
- encoder->drawIndexedPrimitives(m_primitiveType, indexCount, m_indexBufferType, m_indexBuffer, startIndexLocation, instanceCount, baseVertexLocation, startIndexLocation);
+ encoder->drawIndexedPrimitives(
+ m_primitiveType,
+ indexCount,
+ m_indexBufferType,
+ m_indexBuffer,
+ startIndexLocation,
+ instanceCount,
+ baseVertexLocation,
+ startIndexLocation);
return SLANG_OK;
}
@@ -465,13 +522,15 @@ void ComputeCommandEncoder::endEncoding()
}
Result ComputeCommandEncoder::bindPipeline(
- IPipelineState* pipelineState, IShaderObject** outRootObject)
+ IPipelineState* pipelineState,
+ IShaderObject** outRootObject)
{
return setPipelineStateImpl(pipelineState, outRootObject);
}
Result ComputeCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject)
+ IPipelineState* pipelineState,
+ IShaderObject* rootObject)
{
return SLANG_E_NOT_IMPLEMENTED;
}
@@ -489,16 +548,18 @@ Result ComputeCommandEncoder::dispatchCompute(int x, int y, int z)
RootShaderObjectImpl* rootObjectImpl = &m_commandBuffer->m_rootObject;
RefPtr<PipelineStateBase> newPipeline;
SLANG_RETURN_ON_FAIL(m_commandBuffer->m_device->maybeSpecializePipeline(
- m_currentPipeline, rootObjectImpl, newPipeline));
+ m_currentPipeline,
+ rootObjectImpl,
+ newPipeline));
PipelineStateImpl* newPipelineImpl = static_cast<PipelineStateImpl*>(newPipeline.Ptr());
SLANG_RETURN_ON_FAIL(newPipelineImpl->ensureAPIPipelineStateCreated());
m_currentPipeline = newPipelineImpl;
-
+
m_currentPipeline->ensureAPIPipelineStateCreated();
encoder->setComputePipelineState(m_currentPipeline->m_computePipelineState.get());
-
+
encoder->dispatchThreadgroups(MTL::Size(x, y, z), m_currentPipeline->m_threadGroupSize);
return SLANG_OK;
@@ -533,7 +594,9 @@ void RayTracingCommandEncoder::buildAccelerationStructure(
}
void RayTracingCommandEncoder::copyAccelerationStructure(
- IAccelerationStructure* dest, IAccelerationStructure* src, AccelerationStructureCopyMode mode)
+ IAccelerationStructure* dest,
+ IAccelerationStructure* src,
+ AccelerationStructureCopyMode mode)
{
}
@@ -544,26 +607,34 @@ void RayTracingCommandEncoder::queryAccelerationStructureProperties(
AccelerationStructureQueryDesc* queryDescs)
{
_queryAccelerationStructureProperties(
- accelerationStructureCount, accelerationStructures, queryCount, queryDescs);
+ accelerationStructureCount,
+ accelerationStructures,
+ queryCount,
+ queryDescs);
}
void RayTracingCommandEncoder::serializeAccelerationStructure(
- DeviceAddress dest, IAccelerationStructure* source)
+ DeviceAddress dest,
+ IAccelerationStructure* source)
{
}
void RayTracingCommandEncoder::deserializeAccelerationStructure(
- IAccelerationStructure* dest, DeviceAddress source)
+ IAccelerationStructure* dest,
+ DeviceAddress source)
{
}
-Result RayTracingCommandEncoder::bindPipeline(IPipelineState* pipeline, IShaderObject** outRootObject)
+Result RayTracingCommandEncoder::bindPipeline(
+ IPipelineState* pipeline,
+ IShaderObject** outRootObject)
{
return SLANG_E_NOT_IMPLEMENTED;
}
Result RayTracingCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject)
+ IPipelineState* pipelineState,
+ IShaderObject* rootObject)
{
return SLANG_E_NOT_IMPLEMENTED;
}
@@ -578,7 +649,7 @@ Result RayTracingCommandEncoder::dispatchRays(
return SLANG_E_NOT_IMPLEMENTED;
}
-void RayTracingCommandEncoder::endEncoding() { }
+void RayTracingCommandEncoder::endEncoding() {}
} // namespace metal
} // namespace gfx
diff --git a/tools/gfx/metal/metal-command-encoder.h b/tools/gfx/metal/metal-command-encoder.h
index 8ef9e5fb5..9ca53f745 100644
--- a/tools/gfx/metal/metal-command-encoder.h
+++ b/tools/gfx/metal/metal-command-encoder.h
@@ -24,12 +24,9 @@ public:
void endEncodingImpl();
Result setPipelineStateImpl(IPipelineState* state, IShaderObject** outRootObject);
-
};
-class ResourceCommandEncoder
- : public IResourceCommandEncoder
- , public PipelineCommandEncoder
+class ResourceCommandEncoder : public IResourceCommandEncoder, public PipelineCommandEncoder
{
public:
virtual void* getInterface(SlangUUID const& guid)
@@ -39,7 +36,7 @@ public:
return nullptr;
}
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject) override
+ queryInterface(SlangUUID const& uuid, void** outObject) override
{
if (auto ptr = getInterface(uuid))
{
@@ -54,7 +51,7 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW void SLANG_MCALL
- writeTimestamp(IQueryPool* queryPool, GfxIndex index) override;
+ writeTimestamp(IQueryPool* queryPool, GfxIndex index) override;
virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer(
IBufferResource* dst,
@@ -86,7 +83,7 @@ public:
ITextureResource::Extents extent) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- uploadBufferData(IBufferResource* buffer, Offset offset, Size size, void* data) override;
+ uploadBufferData(IBufferResource* buffer, Offset offset, Size size, void* data) override;
virtual SLANG_NO_THROW void SLANG_MCALL uploadTextureData(
ITextureResource* dst,
@@ -122,7 +119,9 @@ public:
ClearResourceViewFlags::Enum flags);
virtual SLANG_NO_THROW void SLANG_MCALL clearResourceView(
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags) override;
+ IResourceView* view,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags) override;
virtual SLANG_NO_THROW void SLANG_MCALL resolveResource(
ITextureResource* source,
@@ -140,25 +139,24 @@ public:
Offset offset) override;
-
virtual SLANG_NO_THROW void SLANG_MCALL
- beginDebugEvent(const char* name, float rgbColor[3]) override;
+ beginDebugEvent(const char* name, float rgbColor[3]) override;
virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override;
};
-class RenderCommandEncoder
- : public IRenderCommandEncoder
- , public ResourceCommandEncoder
+class RenderCommandEncoder : public IRenderCommandEncoder, public ResourceCommandEncoder
{
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
return nullptr;
}
+
public:
RefPtr<RenderPassLayoutImpl> m_renderPassLayout;
RefPtr<FramebufferImpl> m_framebuffer;
@@ -183,19 +181,19 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* pipelineState, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* pipelineState, IShaderObject** outRootObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ bindPipelineWithRootObject(IPipelineState* pipelineState, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setViewports(GfxCount count, const Viewport* viewports) override;
+ setViewports(GfxCount count, const Viewport* viewports) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setScissorRects(GfxCount count, const ScissorRect* rects) override;
+ setScissorRects(GfxCount count, const ScissorRect* rects) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setPrimitiveTopology(PrimitiveTopology topology) override;
+ setPrimitiveTopology(PrimitiveTopology topology) override;
virtual SLANG_NO_THROW void SLANG_MCALL setVertexBuffers(
GfxIndex startSlot,
@@ -204,7 +202,7 @@ public:
const Offset* offsets) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) override;
+ setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) override;
virtual SLANG_NO_THROW void SLANG_MCALL setStencilReference(uint32_t referenceValue) override;
@@ -216,9 +214,9 @@ public:
Result prepareDraw(MTL::RenderCommandEncoder*& encoder);
virtual SLANG_NO_THROW Result SLANG_MCALL
- draw(GfxCount vertexCount, GfxIndex startVertex = 0) override;
+ draw(GfxCount vertexCount, GfxIndex startVertex = 0) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override;
+ drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override;
virtual SLANG_NO_THROW Result SLANG_MCALL drawIndirect(
GfxCount maxDrawCount,
@@ -247,19 +245,17 @@ public:
GfxIndex baseVertexLocation,
GfxIndex startInstanceLocation) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- drawMeshTasks(int x, int y, int z) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL drawMeshTasks(int x, int y, int z) override;
};
-class ComputeCommandEncoder
- : public IComputeCommandEncoder
- , public ResourceCommandEncoder
+class ComputeCommandEncoder : public IComputeCommandEncoder, public ResourceCommandEncoder
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
@@ -269,33 +265,32 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* pipelineState, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* pipelineState, IShaderObject** outRootObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ bindPipelineWithRootObject(IPipelineState* pipelineState, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL dispatchCompute(int x, int y, int z) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
+ dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
};
-class RayTracingCommandEncoder
- : public IRayTracingCommandEncoder
- , public ResourceCommandEncoder
+class RayTracingCommandEncoder : public IRayTracingCommandEncoder, public ResourceCommandEncoder
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRayTracingCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IRayTracingCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
return nullptr;
}
-public:
+public:
void _memoryBarrier(
int count,
IAccelerationStructure* const* structures,
@@ -325,16 +320,16 @@ public:
AccelerationStructureQueryDesc* queryDescs) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- serializeAccelerationStructure(DeviceAddress dest, IAccelerationStructure* source) override;
+ serializeAccelerationStructure(DeviceAddress dest, IAccelerationStructure* source) override;
- virtual SLANG_NO_THROW void SLANG_MCALL deserializeAccelerationStructure(
- IAccelerationStructure* dest, DeviceAddress source) override;
+ virtual SLANG_NO_THROW void SLANG_MCALL
+ deserializeAccelerationStructure(IAccelerationStructure* dest, DeviceAddress source) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* pipeline, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* pipeline, IShaderObject** outRootObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ bindPipelineWithRootObject(IPipelineState* pipelineState, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL dispatchRays(
GfxIndex raygenShaderIndex,
diff --git a/tools/gfx/metal/metal-command-queue.cpp b/tools/gfx/metal/metal-command-queue.cpp
index 920b6ef7e..4175076da 100644
--- a/tools/gfx/metal/metal-command-queue.cpp
+++ b/tools/gfx/metal/metal-command-queue.cpp
@@ -10,7 +10,7 @@ namespace gfx
using namespace Slang;
-namespace metal
+namespace metal
{
ICommandQueue* CommandQueueImpl::getInterface(const Guid& guid)
@@ -20,9 +20,7 @@ ICommandQueue* CommandQueueImpl::getInterface(const Guid& guid)
return nullptr;
}
-CommandQueueImpl::~CommandQueueImpl()
-{
-}
+CommandQueueImpl::~CommandQueueImpl() {}
void CommandQueueImpl::init(DeviceImpl* device, NS::SharedPtr<MTL::CommandQueue> commandQueue)
{
@@ -42,10 +40,15 @@ Result CommandQueueImpl::getNativeHandle(InteropHandle* outHandle)
return SLANG_OK;
}
-const CommandQueueImpl::Desc& CommandQueueImpl::getDesc() { return m_desc; }
+const CommandQueueImpl::Desc& CommandQueueImpl::getDesc()
+{
+ return m_desc;
+}
Result CommandQueueImpl::waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* waitValues)
{
for (GfxCount i = 0; i < fenceCount; ++i)
{
@@ -58,7 +61,10 @@ Result CommandQueueImpl::waitForFenceValuesOnDevice(
}
void CommandQueueImpl::queueSubmitImpl(
- uint32_t count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
+ uint32_t count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal)
{
// If there are any pending wait fences, encode them to a new command buffer.
// Metal ensures that command buffers are executed in the order they are committed.
@@ -79,7 +85,9 @@ void CommandQueueImpl::queueSubmitImpl(
// If this is the last command buffer and a fence is provided, signal the fence.
if (i == count - 1 && fence != nullptr)
{
- cmdBufImpl->m_commandBuffer->encodeSignalEvent(static_cast<FenceImpl*>(fence)->m_event.get(), valueToSignal);
+ cmdBufImpl->m_commandBuffer->encodeSignalEvent(
+ static_cast<FenceImpl*>(fence)->m_event.get(),
+ valueToSignal);
}
cmdBufImpl->m_commandBuffer->commit();
}
@@ -88,13 +96,18 @@ void CommandQueueImpl::queueSubmitImpl(
if (count == 0 && fence != nullptr)
{
MTL::CommandBuffer* commandBuffer = m_commandQueue->commandBuffer();
- commandBuffer->encodeSignalEvent(static_cast<FenceImpl*>(fence)->m_event.get(), valueToSignal);
+ commandBuffer->encodeSignalEvent(
+ static_cast<FenceImpl*>(fence)->m_event.get(),
+ valueToSignal);
commandBuffer->commit();
}
}
void CommandQueueImpl::executeCommandBuffers(
- GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
+ GfxCount count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal)
{
AUTORELEASEPOOL
diff --git a/tools/gfx/metal/metal-command-queue.h b/tools/gfx/metal/metal-command-queue.h
index 045f4ed73..1f825360b 100644
--- a/tools/gfx/metal/metal-command-queue.h
+++ b/tools/gfx/metal/metal-command-queue.h
@@ -9,12 +9,10 @@ namespace gfx
using namespace Slang;
-namespace metal
+namespace metal
{
-class CommandQueueImpl
- : public ICommandQueue
- , public ComObject
+class CommandQueueImpl : public ICommandQueue, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -42,8 +40,8 @@ public:
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ waitForFenceValuesOnDevice(GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
void queueSubmitImpl(
uint32_t count,
diff --git a/tools/gfx/metal/metal-device.cpp b/tools/gfx/metal/metal-device.cpp
index 609c1bf27..ff534a78c 100644
--- a/tools/gfx/metal/metal-device.cpp
+++ b/tools/gfx/metal/metal-device.cpp
@@ -1,25 +1,25 @@
// metal-device.cpp
#include "metal-device.h"
-#include "metal-swap-chain.h"
-#include "metal-util.h"
#include "../resource-desc-utils.h"
-#include "metal-texture.h"
+#include "metal-buffer.h"
#include "metal-render-pass.h"
-#include "metal-vertex-layout.h"
#include "metal-shader-program.h"
-#include "metal-buffer.h"
-//#include "metal-command-queue.h"
+#include "metal-swap-chain.h"
+#include "metal-texture.h"
+#include "metal-util.h"
+#include "metal-vertex-layout.h"
+// #include "metal-command-queue.h"
#include "metal-fence.h"
#include "metal-query.h"
-//#include "metal-resource-views.h"
+// #include "metal-resource-views.h"
#include "metal-sampler.h"
-#include "metal-shader-object.h"
#include "metal-shader-object-layout.h"
-//#include "metal-shader-table.h"
+#include "metal-shader-object.h"
+// #include "metal-shader-table.h"
#include "metal-transient-heap.h"
-//#include "metal-pipeline-dump-layer.h"
-//#include "metal-helper-functions.h"
+// #include "metal-pipeline-dump-layer.h"
+// #include "metal-helper-functions.h"
#include "source/core/slang-platform.h"
namespace gfx
@@ -37,9 +37,7 @@ static bool shouldDumpPipeline()
return dumpPipelineSettings.produceString() == "1";
}
-DeviceImpl::~DeviceImpl()
-{
-}
+DeviceImpl::~DeviceImpl() {}
Result DeviceImpl::getNativeDeviceHandles(InteropHandles* outHandles)
{
@@ -59,7 +57,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
m_info.projectionStyle = ProjectionStyle::Metal;
m_info.deviceType = DeviceType::Metal;
m_info.adapterName = "default";
- static const float kIdentity[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
+ static const float kIdentity[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
::memcpy(m_info.identityProjectionMatrix, kIdentity, sizeof(kIdentity));
}
@@ -83,23 +81,27 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
desc.extendedDescs,
SLANG_METAL_LIB,
"",
- makeArray(slang::PreprocessorMacroDesc{ "__METAL__", "1" }).getView()));
+ makeArray(slang::PreprocessorMacroDesc{"__METAL__", "1"}).getView()));
// TODO: expose via some other means
if (captureEnabled())
{
MTL::CaptureManager* captureManager = MTL::CaptureManager::sharedCaptureManager();
MTL::CaptureDescriptor* d = MTL::CaptureDescriptor::alloc()->init();
- MTL::CaptureDestination captureDest = MTL::CaptureDestination::CaptureDestinationGPUTraceDocument;
+ MTL::CaptureDestination captureDest =
+ MTL::CaptureDestination::CaptureDestinationGPUTraceDocument;
if (!captureManager->supportsDestination(MTL::CaptureDestinationGPUTraceDocument))
{
- std::cout << "Cannot capture MTL calls to document; ensure that Info.plist exists with 'MetalCaptureEnabled' set to 'true'." << std::endl;
+ std::cout << "Cannot capture MTL calls to document; ensure that Info.plist exists with "
+ "'MetalCaptureEnabled' set to 'true'."
+ << std::endl;
exit(1);
}
d->setDestination(MTL::CaptureDestinationGPUTraceDocument);
d->setCaptureObject(m_device.get());
NS::SharedPtr<NS::String> path = MetalUtil::createString("frame.gputrace");
- NS::SharedPtr<NS::URL> url = NS::TransferPtr(NS::URL::alloc()->initFileURLWithPath(path.get()));
+ NS::SharedPtr<NS::URL> url =
+ NS::TransferPtr(NS::URL::alloc()->initFileURLWithPath(path.get()));
d->setOutputURL(url.get());
NS::Error* errorCode = NS::Error::alloc();
if (!captureManager->startCapture(d, &errorCode))
@@ -113,7 +115,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
return SLANG_OK;
}
-//void DeviceImpl::waitForGpu() { m_deviceQueue.flushAndWait(); }
+// void DeviceImpl::waitForGpu() { m_deviceQueue.flushAndWait(); }
const DeviceInfo& DeviceImpl::getDeviceInfo() const
@@ -121,7 +123,9 @@ const DeviceInfo& DeviceImpl::getDeviceInfo() const
return m_info;
}
-Result DeviceImpl::createTransientResourceHeap(const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap)
+Result DeviceImpl::createTransientResourceHeap(
+ const ITransientResourceHeap::Desc& desc,
+ ITransientResourceHeap** outHeap)
{
AUTORELEASEPOOL
@@ -146,7 +150,9 @@ Result DeviceImpl::createCommandQueue(const ICommandQueue::Desc& desc, ICommandQ
}
Result DeviceImpl::createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain)
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain)
{
AUTORELEASEPOOL
@@ -156,7 +162,9 @@ Result DeviceImpl::createSwapchain(
return SLANG_OK;
}
-Result DeviceImpl::createFramebufferLayout(const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout)
+Result DeviceImpl::createFramebufferLayout(
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout)
{
AUTORELEASEPOOL
@@ -166,7 +174,9 @@ Result DeviceImpl::createFramebufferLayout(const IFramebufferLayout::Desc& desc,
return SLANG_OK;
}
-Result DeviceImpl::createRenderPassLayout(const IRenderPassLayout::Desc& desc, IRenderPassLayout** outRenderPassLayout)
+Result DeviceImpl::createRenderPassLayout(
+ const IRenderPassLayout::Desc& desc,
+ IRenderPassLayout** outRenderPassLayout)
{
AUTORELEASEPOOL
@@ -199,7 +209,7 @@ SlangResult DeviceImpl::readTextureResource(
if (textureImpl->getDesc()->sampleDesc.numSamples > 1)
{
- return SLANG_E_NOT_IMPLEMENTED;
+ return SLANG_E_NOT_IMPLEMENTED;
}
NS::SharedPtr<MTL::Texture> srcTexture = textureImpl->m_texture;
@@ -220,7 +230,8 @@ SlangResult DeviceImpl::readTextureResource(
*outPixelSize = bytesPerPixel;
// create staging buffer
- NS::SharedPtr<MTL::Buffer> stagingBuffer = NS::TransferPtr(m_device->newBuffer(bufferSize, MTL::StorageModeShared));
+ NS::SharedPtr<MTL::Buffer> stagingBuffer =
+ NS::TransferPtr(m_device->newBuffer(bufferSize, MTL::StorageModeShared));
if (!stagingBuffer)
{
return SLANG_FAIL;
@@ -229,8 +240,15 @@ SlangResult DeviceImpl::readTextureResource(
MTL::CommandBuffer* commandBuffer = m_commandQueue->commandBuffer();
MTL::BlitCommandEncoder* encoder = commandBuffer->blitCommandEncoder();
encoder->copyFromTexture(
- srcTexture.get(), 0, 0, MTL::Origin(0, 0, 0), MTL::Size(width, height, depth),
- stagingBuffer.get(), 0, bytesPerRow, bytesPerSlice);
+ srcTexture.get(),
+ 0,
+ 0,
+ MTL::Origin(0, 0, 0),
+ MTL::Size(width, height, depth),
+ stagingBuffer.get(),
+ 0,
+ bytesPerRow,
+ bytesPerSlice);
encoder->endEncoding();
commandBuffer->commit();
commandBuffer->waitUntilCompleted();
@@ -245,12 +263,16 @@ SlangResult DeviceImpl::readTextureResource(
}
SlangResult DeviceImpl::readBufferResource(
- IBufferResource* buffer, Offset offset, Size size, ISlangBlob** outBlob)
+ IBufferResource* buffer,
+ Offset offset,
+ Size size,
+ ISlangBlob** outBlob)
{
AUTORELEASEPOOL
// create staging buffer
- NS::SharedPtr<MTL::Buffer> stagingBuffer = NS::TransferPtr(m_device->newBuffer(size, MTL::StorageModeShared));
+ NS::SharedPtr<MTL::Buffer> stagingBuffer =
+ NS::TransferPtr(m_device->newBuffer(size, MTL::StorageModeShared));
if (!stagingBuffer)
{
return SLANG_FAIL;
@@ -258,7 +280,12 @@ SlangResult DeviceImpl::readBufferResource(
MTL::CommandBuffer* commandBuffer = m_commandQueue->commandBuffer();
MTL::BlitCommandEncoder* blitEncoder = commandBuffer->blitCommandEncoder();
- blitEncoder->copyFromBuffer(static_cast<BufferResourceImpl*>(buffer)->m_buffer.get(), offset, stagingBuffer.get(), 0, size);
+ blitEncoder->copyFromBuffer(
+ static_cast<BufferResourceImpl*>(buffer)->m_buffer.get(),
+ offset,
+ stagingBuffer.get(),
+ 0,
+ size);
blitEncoder->endEncoding();
commandBuffer->commit();
commandBuffer->waitUntilCompleted();
@@ -282,7 +309,8 @@ Result DeviceImpl::getAccelerationStructurePrebuildInfo(
}
Result DeviceImpl::createAccelerationStructure(
- const IAccelerationStructure::CreateDesc& desc, IAccelerationStructure** outAS)
+ const IAccelerationStructure::CreateDesc& desc,
+ IAccelerationStructure** outAS)
{
AUTORELEASEPOOL
@@ -290,13 +318,14 @@ Result DeviceImpl::createAccelerationStructure(
}
Result DeviceImpl::getTextureAllocationInfo(
- const ITextureResource::Desc& descIn, Size* outSize, Size* outAlignment)
+ const ITextureResource::Desc& descIn,
+ Size* outSize,
+ Size* outAlignment)
{
AUTORELEASEPOOL
- auto alignTo = [&](Size size, Size alignment) -> Size {
- return ((size + alignment - 1) / alignment) * alignment;
- };
+ auto alignTo = [&](Size size, Size alignment) -> Size
+ { return ((size + alignment - 1) / alignment) * alignment; };
TextureResource::Desc desc = fixupTextureDesc(descIn);
FormatInfo formatInfo;
@@ -311,7 +340,8 @@ Result DeviceImpl::getTextureAllocationInfo(
for (Int i = 0; i < desc.numMipLevels; ++i)
{
- Size rowSize = ((extents.width + formatInfo.blockWidth - 1) / formatInfo.blockWidth) * formatInfo.blockSizeInBytes;
+ Size rowSize = ((extents.width + formatInfo.blockWidth - 1) / formatInfo.blockWidth) *
+ formatInfo.blockSizeInBytes;
rowSize = alignTo(rowSize, alignment);
Size sliceSize = rowSize * alignTo(extents.height, formatInfo.blockHeight);
size += sliceSize * extents.depth;
@@ -358,19 +388,16 @@ Result DeviceImpl::createTextureResource(
RefPtr<TextureResourceImpl> textureImpl(new TextureResourceImpl(desc, this));
- NS::SharedPtr<MTL::TextureDescriptor> textureDesc = NS::TransferPtr(MTL::TextureDescriptor::alloc()->init());
+ NS::SharedPtr<MTL::TextureDescriptor> textureDesc =
+ NS::TransferPtr(MTL::TextureDescriptor::alloc()->init());
switch (desc.memoryType)
{
- case MemoryType::DeviceLocal:
- textureDesc->setStorageMode(MTL::StorageModePrivate);
- break;
+ case MemoryType::DeviceLocal: textureDesc->setStorageMode(MTL::StorageModePrivate); break;
case MemoryType::Upload:
textureDesc->setStorageMode(MTL::StorageModeShared);
textureDesc->setCpuCacheMode(MTL::CPUCacheModeWriteCombined);
break;
- case MemoryType::ReadBack:
- textureDesc->setStorageMode(MTL::StorageModeShared);
- break;
+ case MemoryType::ReadBack: textureDesc->setStorageMode(MTL::StorageModeShared); break;
}
bool isArray = desc.arraySize > 0;
@@ -384,7 +411,8 @@ Result DeviceImpl::createTextureResource(
case IResource::Type::Texture2D:
if (desc.sampleDesc.numSamples > 1)
{
- textureDesc->setTextureType(isArray ? MTL::TextureType2DMultisampleArray : MTL::TextureType2DMultisample);
+ textureDesc->setTextureType(
+ isArray ? MTL::TextureType2DMultisampleArray : MTL::TextureType2DMultisample);
textureDesc->setSampleCount(desc.sampleDesc.numSamples);
}
else
@@ -405,9 +433,7 @@ Result DeviceImpl::createTextureResource(
textureDesc->setHeight(descIn.size.height);
textureDesc->setDepth(descIn.size.depth);
break;
- default:
- assert("!Unsupported texture type");
- return SLANG_FAIL;
+ default: assert("!Unsupported texture type"); return SLANG_FAIL;
}
MTL::TextureUsage textureUsage = MTL::TextureUsageUnknown;
@@ -430,9 +456,7 @@ Result DeviceImpl::createTextureResource(
case Format::R32_UINT:
case Format::R32_SINT:
case Format::R32G32_UINT:
- case Format::R32G32_SINT:
- textureUsage |= MTL::TextureUsageShaderAtomic;
- break;
+ case Format::R32G32_SINT: textureUsage |= MTL::TextureUsageShaderAtomic; break;
}
}
@@ -456,7 +480,8 @@ Result DeviceImpl::createTextureResource(
{
textureDesc->setStorageMode(MTL::StorageModeManaged);
textureDesc->setCpuCacheMode(MTL::CPUCacheModeDefaultCache);
- NS::SharedPtr<MTL::Texture> stagingTexture = NS::TransferPtr(m_device->newTexture(textureDesc.get()));
+ NS::SharedPtr<MTL::Texture> stagingTexture =
+ NS::TransferPtr(m_device->newTexture(textureDesc.get()));
MTL::CommandBuffer* commandBuffer = m_commandQueue->commandBuffer();
MTL::BlitCommandEncoder* encoder = commandBuffer->blitCommandEncoder();
@@ -480,12 +505,22 @@ Result DeviceImpl::createTextureResource(
{
if (level >= desc.numMipLevels)
continue;
- const ITextureResource::SubresourceData& subresourceData = initData[slice * initMipLevels + level];
- stagingTexture->replaceRegion(region, level, slice, subresourceData.data, subresourceData.strideY, subresourceData.strideZ);
+ const ITextureResource::SubresourceData& subresourceData =
+ initData[slice * initMipLevels + level];
+ stagingTexture->replaceRegion(
+ region,
+ level,
+ slice,
+ subresourceData.data,
+ subresourceData.strideY,
+ subresourceData.strideZ);
encoder->synchronizeTexture(stagingTexture.get(), slice, level);
- region.size.width = region.size.width > 0 ? Math::Max(1ul, region.size.width >> 1) : 0;
- region.size.height = region.size.height > 0 ? Math::Max(1ul, region.size.height >> 1) : 0;
- region.size.depth = region.size.depth > 0 ? Math::Max(1ul, region.size.depth >> 1) : 0;
+ region.size.width =
+ region.size.width > 0 ? Math::Max(1ul, region.size.width >> 1) : 0;
+ region.size.height =
+ region.size.height > 0 ? Math::Max(1ul, region.size.height >> 1) : 0;
+ region.size.depth =
+ region.size.depth > 0 ? Math::Max(1ul, region.size.depth >> 1) : 0;
}
}
@@ -500,7 +535,9 @@ Result DeviceImpl::createTextureResource(
}
Result DeviceImpl::createBufferResource(
- const IBufferResource::Desc& descIn, const void* initData, IBufferResource** outResource)
+ const IBufferResource::Desc& descIn,
+ const void* initData,
+ IBufferResource** outResource)
{
AUTORELEASEPOOL
@@ -511,17 +548,15 @@ Result DeviceImpl::createBufferResource(
MTL::ResourceOptions resourceOptions = MTL::ResourceOptions(0);
switch (desc.memoryType)
{
- case MemoryType::DeviceLocal:
- resourceOptions = MTL::ResourceStorageModePrivate;
- break;
+ case MemoryType::DeviceLocal: resourceOptions = MTL::ResourceStorageModePrivate; break;
case MemoryType::Upload:
resourceOptions = MTL::ResourceStorageModeShared | MTL::CPUCacheModeWriteCombined;
break;
- case MemoryType::ReadBack:
- resourceOptions = MTL::ResourceStorageModeShared;
- break;
+ case MemoryType::ReadBack: resourceOptions = MTL::ResourceStorageModeShared; break;
}
- resourceOptions |= (desc.memoryType == MemoryType::DeviceLocal) ? MTL::ResourceStorageModePrivate : MTL::ResourceStorageModeShared;
+ resourceOptions |= (desc.memoryType == MemoryType::DeviceLocal)
+ ? MTL::ResourceStorageModePrivate
+ : MTL::ResourceStorageModeShared;
RefPtr<BufferResourceImpl> bufferImpl(new BufferResourceImpl(desc, this));
bufferImpl->m_buffer = NS::TransferPtr(m_device->newBuffer(bufferSize, resourceOptions));
@@ -533,7 +568,9 @@ Result DeviceImpl::createBufferResource(
if (initData)
{
NS::SharedPtr<MTL::Buffer> stagingBuffer = NS::TransferPtr(m_device->newBuffer(
- initData, bufferSize, MTL::ResourceStorageModeShared | MTL::CPUCacheModeWriteCombined));
+ initData,
+ bufferSize,
+ MTL::ResourceStorageModeShared | MTL::CPUCacheModeWriteCombined));
MTL::CommandBuffer* commandBuffer = m_commandQueue->commandBuffer();
MTL::BlitCommandEncoder* encoder = commandBuffer->blitCommandEncoder();
if (!stagingBuffer || !commandBuffer || !encoder)
@@ -551,7 +588,9 @@ Result DeviceImpl::createBufferResource(
}
Result DeviceImpl::createBufferFromNativeHandle(
- InteropHandle handle, const IBufferResource::Desc& srcDesc, IBufferResource** outResource)
+ InteropHandle handle,
+ const IBufferResource::Desc& srcDesc,
+ IBufferResource** outResource)
{
AUTORELEASEPOOL
@@ -569,7 +608,9 @@ Result DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerS
}
Result DeviceImpl::createTextureView(
- ITextureResource* texture, IResourceView::Desc const& desc, IResourceView** outView)
+ ITextureResource* texture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView)
{
AUTORELEASEPOOL
@@ -586,7 +627,8 @@ Result DeviceImpl::createTextureView(
const ITextureResource::Desc& textureDesc = *textureImpl->getDesc();
SubresourceRange sr = desc.subresourceRange;
- sr.mipLevelCount = sr.mipLevelCount == 0 ? textureDesc.numMipLevels - sr.mipLevel : sr.mipLevelCount;
+ sr.mipLevelCount =
+ sr.mipLevelCount == 0 ? textureDesc.numMipLevels - sr.mipLevel : sr.mipLevelCount;
sr.layerCount = sr.layerCount == 0 ? textureDesc.arraySize - sr.baseArrayLayer : sr.layerCount;
if (sr.mipLevel == 0 && sr.mipLevelCount == textureDesc.numMipLevels &&
sr.baseArrayLayer == 0 && sr.layerCount == textureDesc.arraySize)
@@ -596,11 +638,17 @@ Result DeviceImpl::createTextureView(
return SLANG_OK;
}
- MTL::PixelFormat pixelFormat = desc.format == Format::Unknown ? textureImpl->m_pixelFormat : MetalUtil::translatePixelFormat(desc.format);
+ MTL::PixelFormat pixelFormat = desc.format == Format::Unknown
+ ? textureImpl->m_pixelFormat
+ : MetalUtil::translatePixelFormat(desc.format);
NS::Range levelRange(sr.baseArrayLayer, sr.layerCount);
NS::Range sliceRange(sr.mipLevel, sr.mipLevelCount);
- viewImpl->m_textureView = NS::TransferPtr(textureImpl->m_texture->newTextureView(pixelFormat, textureImpl->m_textureType, levelRange, sliceRange));
+ viewImpl->m_textureView = NS::TransferPtr(textureImpl->m_texture->newTextureView(
+ pixelFormat,
+ textureImpl->m_textureType,
+ levelRange,
+ sliceRange));
if (!viewImpl->m_textureView)
{
return SLANG_FAIL;
@@ -651,7 +699,8 @@ Result DeviceImpl::createBufferView(
return SLANG_FAIL;
}
- if (desc.type != IResourceView::Type::UnorderedAccess && desc.type != IResourceView::Type::ShaderResource)
+ if (desc.type != IResourceView::Type::UnorderedAccess &&
+ desc.type != IResourceView::Type::ShaderResource)
{
return SLANG_FAIL;
}
@@ -662,7 +711,8 @@ Result DeviceImpl::createBufferView(
viewImpl->m_desc = desc;
viewImpl->m_buffer = bufferImpl;
viewImpl->m_offset = desc.bufferRange.offset;
- viewImpl->m_size = desc.bufferRange.size == 0 ? bufferImpl->getDesc()->sizeInBytes : desc.bufferRange.size;
+ viewImpl->m_size =
+ desc.bufferRange.size == 0 ? bufferImpl->getDesc()->sizeInBytes : desc.bufferRange.size;
returnComPtr(outView, viewImpl);
return SLANG_OK;
}
@@ -678,7 +728,9 @@ Result DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayou
}
Result DeviceImpl::createProgram(
- const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnosticBlob)
{
AUTORELEASEPOOL
@@ -708,8 +760,8 @@ Result DeviceImpl::createShaderObjectLayout(
AUTORELEASEPOOL
RefPtr<ShaderObjectLayoutImpl> layout;
- SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- this, session, typeLayout, layout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ ShaderObjectLayoutImpl::createForElementType(this, session, typeLayout, layout.writeRef()));
returnRefPtrMove(outLayout, layout);
return SLANG_OK;
}
@@ -719,14 +771,17 @@ Result DeviceImpl::createShaderObject(ShaderObjectLayoutBase* layout, IShaderObj
AUTORELEASEPOOL
RefPtr<ShaderObjectImpl> shaderObject;
- SLANG_RETURN_ON_FAIL(ShaderObjectImpl::create(this,
- static_cast<ShaderObjectLayoutImpl*>(layout), shaderObject.writeRef()));
+ SLANG_RETURN_ON_FAIL(ShaderObjectImpl::create(
+ this,
+ static_cast<ShaderObjectLayoutImpl*>(layout),
+ shaderObject.writeRef()));
returnComPtr(outObject, shaderObject);
return SLANG_OK;
}
Result DeviceImpl::createMutableShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject)
{
AUTORELEASEPOOL
@@ -747,7 +802,9 @@ Result DeviceImpl::createShaderTable(const IShaderTable::Desc& desc, IShaderTabl
return SLANG_E_NOT_IMPLEMENTED;
}
-Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc& desc, IPipelineState** outState)
+Result DeviceImpl::createGraphicsPipelineState(
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState)
{
AUTORELEASEPOOL
@@ -757,7 +814,9 @@ Result DeviceImpl::createGraphicsPipelineState(const GraphicsPipelineStateDesc&
return SLANG_OK;
}
-Result DeviceImpl::createComputePipelineState(const ComputePipelineStateDesc& desc, IPipelineState** outState)
+Result DeviceImpl::createComputePipelineState(
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState)
{
AUTORELEASEPOOL
@@ -768,7 +827,9 @@ Result DeviceImpl::createComputePipelineState(const ComputePipelineStateDesc& de
return SLANG_OK;
}
-Result DeviceImpl::createRayTracingPipelineState(const RayTracingPipelineStateDesc& desc, IPipelineState** outState)
+Result DeviceImpl::createRayTracingPipelineState(
+ const RayTracingPipelineStateDesc& desc,
+ IPipelineState** outState)
{
AUTORELEASEPOOL
@@ -796,7 +857,11 @@ Result DeviceImpl::createFence(const IFence::Desc& desc, IFence** outFence)
}
Result DeviceImpl::waitForFences(
- GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* fenceValues,
+ bool waitForAll,
+ uint64_t timeout)
{
return SLANG_E_NOT_IMPLEMENTED;
}
diff --git a/tools/gfx/metal/metal-device.h b/tools/gfx/metal/metal-device.h
index 50eb0e88d..b22066f61 100644
--- a/tools/gfx/metal/metal-device.h
+++ b/tools/gfx/metal/metal-device.h
@@ -1,9 +1,9 @@
// metal-device.h
#pragma once
+#include "../simple-transient-resource-heap.h"
#include "metal-base.h"
#include "metal-device.h"
-#include "../simple-transient-resource-heap.h"
#include "metal-framebuffer.h"
namespace gfx
@@ -11,7 +11,7 @@ namespace gfx
using namespace Slang;
-namespace metal
+namespace metal
{
class DeviceImpl : public RendererBase
@@ -20,19 +20,24 @@ public:
// Renderer implementation
virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const Desc& desc) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
+ getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap(
- const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap) override;
+ const ITransientResourceHeap::Desc& desc,
+ ITransientResourceHeap** outHeap) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
+ createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override;
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
+ createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createRenderPassLayout(
- const IRenderPassLayout::Desc& desc, IRenderPassLayout** outRenderPassLayout) override;
+ const IRenderPassLayout::Desc& desc,
+ IRenderPassLayout** outRenderPassLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureResource(
const ITextureResource::Desc& desc,
const ITextureResource::SubresourceData* initData,
@@ -46,7 +51,7 @@ public:
const IBufferResource::Desc& srcDesc,
IBufferResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
+ createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView(
ITextureResource* texture,
@@ -59,33 +64,37 @@ public:
IResourceView** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
+ createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
virtual Result createShaderObjectLayout(
slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) override;
- virtual Result createShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
+ virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ override;
virtual Result createMutableShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
+ createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outShaderTable) override;
+ createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outShaderTable) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createProgram(
const IShaderProgram::Desc& desc,
IShaderProgram** outProgram,
ISlangBlob** outDiagnosticBlob) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& desc, IPipelineState** outState) override;
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createRayTracingPipelineState(
- const RayTracingPipelineStateDesc& desc, IPipelineState** outState) override;
+ const RayTracingPipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
+ createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL readTextureResource(
ITextureResource* texture,
@@ -95,22 +104,28 @@ public:
Size* outPixelSize) override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL readBufferResource(
- IBufferResource* buffer, Offset offset, Size size, ISlangBlob** outBlob) override;
+ IBufferResource* buffer,
+ Offset offset,
+ Size size,
+ ISlangBlob** outBlob) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getAccelerationStructurePrebuildInfo(
const IAccelerationStructure::BuildInputs& buildInputs,
IAccelerationStructure::PrebuildInfo* outPrebuildInfo) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createAccelerationStructure(
- const IAccelerationStructure::CreateDesc& desc, IAccelerationStructure** outView) override;
+ const IAccelerationStructure::CreateDesc& desc,
+ IAccelerationStructure** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureAllocationInfo(
- const ITextureResource::Desc& desc, Size* outSize, Size* outAlignment) override;
+ const ITextureResource::Desc& desc,
+ Size* outSize,
+ Size* outAlignment) override;
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;
+ createFence(const IFence::Desc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL waitForFences(
GfxCount fenceCount,
@@ -119,10 +134,10 @@ public:
bool waitForAll,
uint64_t timeout) override;
- //void waitForGpu();
+ // void waitForGpu();
virtual SLANG_NO_THROW const DeviceInfo& SLANG_MCALL getDeviceInfo() const override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeDeviceHandles(InteropHandles* outHandles) override;
+ getNativeDeviceHandles(InteropHandles* outHandles) override;
~DeviceImpl();
public:
diff --git a/tools/gfx/metal/metal-fence.cpp b/tools/gfx/metal/metal-fence.cpp
index a908a8493..0de7d8ffb 100644
--- a/tools/gfx/metal/metal-fence.cpp
+++ b/tools/gfx/metal/metal-fence.cpp
@@ -1,5 +1,6 @@
// metal-fence.cpp
#include "metal-fence.h"
+
#include "metal-device.h"
namespace gfx
@@ -10,9 +11,7 @@ using namespace Slang;
namespace metal
{
-FenceImpl::~FenceImpl()
-{
-}
+FenceImpl::~FenceImpl() {}
Result FenceImpl::init(DeviceImpl* device, const IFence::Desc& desc)
{
diff --git a/tools/gfx/metal/metal-fence.h b/tools/gfx/metal/metal-fence.h
index d8aed7dfe..434f2f65d 100644
--- a/tools/gfx/metal/metal-fence.h
+++ b/tools/gfx/metal/metal-fence.h
@@ -24,11 +24,12 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentValue(uint64_t* outValue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL setCurrentValue(uint64_t value) override;
-
+
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outNativeHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeHandle(InteropHandle* outNativeHandle) override;
};
-} // namespace metal
+} // namespace metal
} // namespace gfx
diff --git a/tools/gfx/metal/metal-framebuffer.cpp b/tools/gfx/metal/metal-framebuffer.cpp
index 76e944b4a..e7d04a63a 100644
--- a/tools/gfx/metal/metal-framebuffer.cpp
+++ b/tools/gfx/metal/metal-framebuffer.cpp
@@ -1,8 +1,9 @@
// metal-framebuffer.cpp
#include "metal-framebuffer.h"
+
#include "metal-device.h"
-#include "metal-resource-views.h"
#include "metal-helper-functions.h"
+#include "metal-resource-views.h"
namespace gfx
{
@@ -39,7 +40,7 @@ Result FramebufferImpl::init(DeviceImpl* device, const IFramebuffer::Desc& desc)
m_renderTargetViews[i] = static_cast<TextureResourceViewImpl*>(desc.renderTargetViews[i]);
}
m_depthStencilView = static_cast<TextureResourceViewImpl*>(desc.depthStencilView);
-
+
// Determine framebuffer dimensions & sample count;
m_width = 1;
m_height = 1;
@@ -49,8 +50,11 @@ Result FramebufferImpl::init(DeviceImpl* device, const IFramebuffer::Desc& desc)
{
const ITextureResource::Desc* textureDesc = view->m_texture->getDesc();
const IResourceView::Desc* viewDesc = view->getViewDesc();
- m_width = Math::Max(1u, uint32_t(textureDesc->size.width >> viewDesc->subresourceRange.mipLevel));
- m_height = Math::Max(1u, uint32_t(textureDesc->size.height >> viewDesc->subresourceRange.mipLevel));
+ m_width =
+ Math::Max(1u, uint32_t(textureDesc->size.width >> viewDesc->subresourceRange.mipLevel));
+ m_height = Math::Max(
+ 1u,
+ uint32_t(textureDesc->size.height >> viewDesc->subresourceRange.mipLevel));
m_sampleCount = Math::Max(m_sampleCount, uint32_t(textureDesc->sampleDesc.numSamples));
return SLANG_OK;
};
diff --git a/tools/gfx/metal/metal-helper-functions.cpp b/tools/gfx/metal/metal-helper-functions.cpp
index 69c4327ad..dc528f8ce 100644
--- a/tools/gfx/metal/metal-helper-functions.cpp
+++ b/tools/gfx/metal/metal-helper-functions.cpp
@@ -1,5 +1,6 @@
// metal-helper-functions.cpp
#include "metal-helper-functions.h"
+
#include "metal-device.h"
#include "metal-util.h"
diff --git a/tools/gfx/metal/metal-pipeline-state.cpp b/tools/gfx/metal/metal-pipeline-state.cpp
index d8ca3f793..c2a9afaac 100644
--- a/tools/gfx/metal/metal-pipeline-state.cpp
+++ b/tools/gfx/metal/metal-pipeline-state.cpp
@@ -2,10 +2,10 @@
#include "metal-pipeline-state.h"
#include "metal-device.h"
-#include "metal-shader-program.h"
#include "metal-shader-object-layout.h"
-#include "metal-vertex-layout.h"
+#include "metal-shader-program.h"
#include "metal-util.h"
+#include "metal-vertex-layout.h"
namespace gfx
{
@@ -20,9 +20,7 @@ PipelineStateImpl::PipelineStateImpl(DeviceImpl* device)
{
}
-PipelineStateImpl::~PipelineStateImpl()
-{
-}
+PipelineStateImpl::~PipelineStateImpl() {}
void PipelineStateImpl::init(const GraphicsPipelineStateDesc& desc)
{
@@ -54,25 +52,22 @@ Result PipelineStateImpl::createMetalRenderPipelineState()
if (!programImpl)
return SLANG_FAIL;
- NS::SharedPtr<MTL::RenderPipelineDescriptor> pd = NS::TransferPtr(MTL::RenderPipelineDescriptor::alloc()->init());
+ NS::SharedPtr<MTL::RenderPipelineDescriptor> pd =
+ NS::TransferPtr(MTL::RenderPipelineDescriptor::alloc()->init());
for (const ShaderProgramImpl::Module& module : programImpl->m_modules)
{
auto functionName = MetalUtil::createString(module.entryPointName.getBuffer());
- NS::SharedPtr<MTL::Function> function = NS::TransferPtr(module.library->newFunction(functionName.get()));
+ NS::SharedPtr<MTL::Function> function =
+ NS::TransferPtr(module.library->newFunction(functionName.get()));
if (!function)
return SLANG_FAIL;
switch (module.stage)
{
- case SLANG_STAGE_VERTEX:
- pd->setVertexFunction(function.get());
- break;
- case SLANG_STAGE_FRAGMENT:
- pd->setFragmentFunction(function.get());
- break;
- default:
- return SLANG_FAIL;
+ case SLANG_STAGE_VERTEX: pd->setVertexFunction(function.get()); break;
+ case SLANG_STAGE_FRAGMENT: pd->setFragmentFunction(function.get()); break;
+ default: return SLANG_FAIL;
}
}
@@ -81,12 +76,15 @@ Result PipelineStateImpl::createMetalRenderPipelineState()
// The +1 is to account for a potential constant buffer at index 0.
m_vertexBufferOffset = programImpl->m_rootObjectLayout->getBufferCount() + 1;
auto inputLayoutImpl = static_cast<InputLayoutImpl*>(desc.graphics.inputLayout);
- NS::SharedPtr<MTL::VertexDescriptor> vertexDescriptor = inputLayoutImpl->createVertexDescriptor(m_vertexBufferOffset);
+ NS::SharedPtr<MTL::VertexDescriptor> vertexDescriptor =
+ inputLayoutImpl->createVertexDescriptor(m_vertexBufferOffset);
pd->setVertexDescriptor(vertexDescriptor.get());
- pd->setInputPrimitiveTopology(MetalUtil::translatePrimitiveTopologyClass(desc.graphics.primitiveType));
+ pd->setInputPrimitiveTopology(
+ MetalUtil::translatePrimitiveTopologyClass(desc.graphics.primitiveType));
// Set rasterization state
- auto framebufferLayoutImpl = static_cast<FramebufferLayoutImpl*>(desc.graphics.framebufferLayout);
+ auto framebufferLayoutImpl =
+ static_cast<FramebufferLayoutImpl*>(desc.graphics.framebufferLayout);
const auto& blend = desc.graphics.blend;
GfxCount sampleCount = 1;
@@ -96,26 +94,36 @@ Result PipelineStateImpl::createMetalRenderPipelineState()
for (Index i = 0; i < framebufferLayoutImpl->m_renderTargets.getCount(); ++i)
{
- const IFramebufferLayout::TargetLayout& targetLayout = framebufferLayoutImpl->m_renderTargets[i];
- MTL::RenderPipelineColorAttachmentDescriptor* colorAttachment = pd->colorAttachments()->object(i);
+ const IFramebufferLayout::TargetLayout& targetLayout =
+ framebufferLayoutImpl->m_renderTargets[i];
+ MTL::RenderPipelineColorAttachmentDescriptor* colorAttachment =
+ pd->colorAttachments()->object(i);
colorAttachment->setPixelFormat(MetalUtil::translatePixelFormat(targetLayout.format));
if (i < blend.targetCount)
{
const TargetBlendDesc& targetBlendDesc = blend.targets[i];
colorAttachment->setBlendingEnabled(targetBlendDesc.enableBlend);
- colorAttachment->setSourceRGBBlendFactor(MetalUtil::translateBlendFactor(targetBlendDesc.color.srcFactor));
- colorAttachment->setDestinationRGBBlendFactor(MetalUtil::translateBlendFactor(targetBlendDesc.color.dstFactor));
- colorAttachment->setRgbBlendOperation(MetalUtil::translateBlendOperation(targetBlendDesc.color.op));
- colorAttachment->setSourceAlphaBlendFactor(MetalUtil::translateBlendFactor(targetBlendDesc.alpha.srcFactor));
- colorAttachment->setDestinationAlphaBlendFactor(MetalUtil::translateBlendFactor(targetBlendDesc.alpha.dstFactor));
- colorAttachment->setAlphaBlendOperation(MetalUtil::translateBlendOperation(targetBlendDesc.alpha.op));
- colorAttachment->setWriteMask(MetalUtil::translateColorWriteMask(targetBlendDesc.writeMask));
+ colorAttachment->setSourceRGBBlendFactor(
+ MetalUtil::translateBlendFactor(targetBlendDesc.color.srcFactor));
+ colorAttachment->setDestinationRGBBlendFactor(
+ MetalUtil::translateBlendFactor(targetBlendDesc.color.dstFactor));
+ colorAttachment->setRgbBlendOperation(
+ MetalUtil::translateBlendOperation(targetBlendDesc.color.op));
+ colorAttachment->setSourceAlphaBlendFactor(
+ MetalUtil::translateBlendFactor(targetBlendDesc.alpha.srcFactor));
+ colorAttachment->setDestinationAlphaBlendFactor(
+ MetalUtil::translateBlendFactor(targetBlendDesc.alpha.dstFactor));
+ colorAttachment->setAlphaBlendOperation(
+ MetalUtil::translateBlendOperation(targetBlendDesc.alpha.op));
+ colorAttachment->setWriteMask(
+ MetalUtil::translateColorWriteMask(targetBlendDesc.writeMask));
}
sampleCount = Math::Max(sampleCount, targetLayout.sampleCount);
}
if (framebufferLayoutImpl->m_depthStencil.format != Format::Unknown)
{
- const IFramebufferLayout::TargetLayout& depthStencil = framebufferLayoutImpl->m_depthStencil;
+ const IFramebufferLayout::TargetLayout& depthStencil =
+ framebufferLayoutImpl->m_depthStencil;
MTL::PixelFormat pixelFormat = MetalUtil::translatePixelFormat(depthStencil.format);
if (MetalUtil::isDepthFormat(pixelFormat))
{
@@ -123,14 +131,16 @@ Result PipelineStateImpl::createMetalRenderPipelineState()
}
if (MetalUtil::isStencilFormat(pixelFormat))
{
- pd->setStencilAttachmentPixelFormat(MetalUtil::translatePixelFormat(depthStencil.format));
+ pd->setStencilAttachmentPixelFormat(
+ MetalUtil::translatePixelFormat(depthStencil.format));
}
}
pd->setRasterSampleCount(sampleCount);
-
+
NS::Error* error;
- m_renderPipelineState = NS::TransferPtr(m_device->m_device->newRenderPipelineState(pd.get(), &error));
+ m_renderPipelineState =
+ NS::TransferPtr(m_device->m_device->newRenderPipelineState(pd.get(), &error));
if (!m_renderPipelineState)
{
std::cout << error->localizedDescription()->utf8String() << std::endl;
@@ -138,34 +148,52 @@ Result PipelineStateImpl::createMetalRenderPipelineState()
}
// Create depth stencil state
- auto createStencilDesc = [](const DepthStencilOpDesc& desc, uint32_t readMask, uint32_t writeMask) -> NS::SharedPtr<MTL::StencilDescriptor>
+ auto createStencilDesc = [](const DepthStencilOpDesc& desc,
+ uint32_t readMask,
+ uint32_t writeMask) -> NS::SharedPtr<MTL::StencilDescriptor>
{
- NS::SharedPtr<MTL::StencilDescriptor> stencilDesc = NS::TransferPtr(MTL::StencilDescriptor::alloc()->init());
- stencilDesc->setStencilCompareFunction(MetalUtil::translateCompareFunction(desc.stencilFunc));
- stencilDesc->setStencilFailureOperation(MetalUtil::translateStencilOperation(desc.stencilFailOp));
- stencilDesc->setDepthFailureOperation(MetalUtil::translateStencilOperation(desc.stencilDepthFailOp));
- stencilDesc->setDepthStencilPassOperation(MetalUtil::translateStencilOperation(desc.stencilPassOp));
+ NS::SharedPtr<MTL::StencilDescriptor> stencilDesc =
+ NS::TransferPtr(MTL::StencilDescriptor::alloc()->init());
+ stencilDesc->setStencilCompareFunction(
+ MetalUtil::translateCompareFunction(desc.stencilFunc));
+ stencilDesc->setStencilFailureOperation(
+ MetalUtil::translateStencilOperation(desc.stencilFailOp));
+ stencilDesc->setDepthFailureOperation(
+ MetalUtil::translateStencilOperation(desc.stencilDepthFailOp));
+ stencilDesc->setDepthStencilPassOperation(
+ MetalUtil::translateStencilOperation(desc.stencilPassOp));
stencilDesc->setReadMask(readMask);
stencilDesc->setWriteMask(writeMask);
return stencilDesc;
};
const auto& depthStencil = desc.graphics.depthStencil;
- NS::SharedPtr<MTL::DepthStencilDescriptor> depthStencilDesc = NS::TransferPtr(MTL::DepthStencilDescriptor::alloc()->init());
- m_depthStencilState = NS::TransferPtr(m_device->m_device->newDepthStencilState(depthStencilDesc.get()));
+ NS::SharedPtr<MTL::DepthStencilDescriptor> depthStencilDesc =
+ NS::TransferPtr(MTL::DepthStencilDescriptor::alloc()->init());
+ m_depthStencilState =
+ NS::TransferPtr(m_device->m_device->newDepthStencilState(depthStencilDesc.get()));
if (!m_depthStencilState)
{
return SLANG_FAIL;
}
if (depthStencil.depthTestEnable)
{
- depthStencilDesc->setDepthCompareFunction(MetalUtil::translateCompareFunction(depthStencil.depthFunc));
+ depthStencilDesc->setDepthCompareFunction(
+ MetalUtil::translateCompareFunction(depthStencil.depthFunc));
}
depthStencilDesc->setDepthWriteEnabled(depthStencil.depthWriteEnable);
if (depthStencil.stencilEnable)
{
- depthStencilDesc->setFrontFaceStencil(createStencilDesc(depthStencil.frontFace, depthStencil.stencilReadMask, depthStencil.stencilWriteMask).get());
- depthStencilDesc->setBackFaceStencil(createStencilDesc(depthStencil.backFace, depthStencil.stencilReadMask, depthStencil.stencilWriteMask).get());
+ depthStencilDesc->setFrontFaceStencil(createStencilDesc(
+ depthStencil.frontFace,
+ depthStencil.stencilReadMask,
+ depthStencil.stencilWriteMask)
+ .get());
+ depthStencilDesc->setBackFaceStencil(createStencilDesc(
+ depthStencil.backFace,
+ depthStencil.stencilReadMask,
+ depthStencil.stencilWriteMask)
+ .get());
}
return SLANG_OK;
@@ -179,16 +207,20 @@ Result PipelineStateImpl::createMetalComputePipelineState()
const ShaderProgramImpl::Module& module = programImpl->m_modules[0];
auto functionName = MetalUtil::createString(module.entryPointName.getBuffer());
- NS::SharedPtr<MTL::Function> function = NS::TransferPtr(module.library->newFunction(functionName.get()));
+ NS::SharedPtr<MTL::Function> function =
+ NS::TransferPtr(module.library->newFunction(functionName.get()));
if (!function)
return SLANG_FAIL;
- NS::Error *error;
- m_computePipelineState = NS::TransferPtr(m_device->m_device->newComputePipelineState(function.get(), &error));
+ NS::Error* error;
+ m_computePipelineState =
+ NS::TransferPtr(m_device->m_device->newComputePipelineState(function.get(), &error));
// Query thread group size for use during dispatch.
SlangUInt threadGroupSize[3];
- programImpl->linkedProgram->getLayout()->getEntryPointByIndex(0)->getComputeThreadGroupSize(3, threadGroupSize);
+ programImpl->linkedProgram->getLayout()->getEntryPointByIndex(0)->getComputeThreadGroupSize(
+ 3,
+ threadGroupSize);
m_threadGroupSize = MTL::Size(threadGroupSize[0], threadGroupSize[1], threadGroupSize[2]);
return m_computePipelineState ? SLANG_OK : SLANG_FAIL;
@@ -197,16 +229,14 @@ Result PipelineStateImpl::createMetalComputePipelineState()
Result PipelineStateImpl::ensureAPIPipelineStateCreated()
{
AUTORELEASEPOOL
-
+
switch (desc.type)
{
case PipelineType::Compute:
return m_computePipelineState ? SLANG_OK : createMetalComputePipelineState();
case PipelineType::Graphics:
return m_renderPipelineState ? SLANG_OK : createMetalRenderPipelineState();
- default:
- SLANG_UNREACHABLE("Unknown pipeline type.");
- return SLANG_FAIL;
+ default: SLANG_UNREACHABLE("Unknown pipeline type."); return SLANG_FAIL;
}
return SLANG_OK;
}
@@ -229,7 +259,8 @@ SLANG_NO_THROW Result SLANG_MCALL PipelineStateImpl::getNativeHandle(InteropHand
RayTracingPipelineStateImpl::RayTracingPipelineStateImpl(DeviceImpl* device)
: PipelineStateImpl(device)
-{}
+{
+}
Result RayTracingPipelineStateImpl::ensureAPIPipelineStateCreated()
{
@@ -242,6 +273,5 @@ Result RayTracingPipelineStateImpl::getNativeHandle(InteropHandle* outHandle)
}
-
} // namespace metal
} // namespace gfx
diff --git a/tools/gfx/metal/metal-query.cpp b/tools/gfx/metal/metal-query.cpp
index 4e1d09d77..6075d5549 100644
--- a/tools/gfx/metal/metal-query.cpp
+++ b/tools/gfx/metal/metal-query.cpp
@@ -1,7 +1,7 @@
// metal-query.cpp
#include "metal-query.h"
-//#include "metal-util.h"
+// #include "metal-util.h"
namespace gfx
{
@@ -11,9 +11,7 @@ using namespace Slang;
namespace metal
{
-QueryPoolImpl::~QueryPoolImpl()
-{
-}
+QueryPoolImpl::~QueryPoolImpl() {}
static MTL::CounterSet* findCounterSet(MTL::Device* device, QueryType queryType)
{
@@ -26,7 +24,8 @@ static MTL::CounterSet* findCounterSet(MTL::Device* device, QueryType queryType)
for (int i = 0; i < device->counterSets()->count(); ++i)
{
- MTL::CounterSet* counterSet = static_cast<MTL::CounterSet*>(device->counterSets()->object(i));
+ MTL::CounterSet* counterSet =
+ static_cast<MTL::CounterSet*>(device->counterSets()->object(i));
for (int j = 0; j < counterSet->counters()->count(); ++j)
{
MTL::Counter* counter = static_cast<MTL::Counter*>(counterSet->counters()->object(j));
@@ -50,7 +49,8 @@ Result QueryPoolImpl::init(DeviceImpl* device, const IQueryPool::Desc& desc)
return SLANG_E_NOT_AVAILABLE;
}
- NS::SharedPtr<MTL::CounterSampleBufferDescriptor> counterSampleBufferDesc = NS::TransferPtr(MTL::CounterSampleBufferDescriptor::alloc()->init());
+ NS::SharedPtr<MTL::CounterSampleBufferDescriptor> counterSampleBufferDesc =
+ NS::TransferPtr(MTL::CounterSampleBufferDescriptor::alloc()->init());
counterSampleBufferDesc->setStorageMode(MTL::StorageModeShared);
counterSampleBufferDesc->setSampleCount(m_desc.count);
counterSampleBufferDesc->setCounterSet(counterSet);
@@ -58,7 +58,8 @@ Result QueryPoolImpl::init(DeviceImpl* device, const IQueryPool::Desc& desc)
m_device->m_device->counterSets();
NS::Error* error;
- m_counterSampleBuffer = NS::TransferPtr(m_device->m_device->newCounterSampleBuffer(counterSampleBufferDesc.get(), &error));
+ m_counterSampleBuffer = NS::TransferPtr(
+ m_device->m_device->newCounterSampleBuffer(counterSampleBufferDesc.get(), &error));
return m_counterSampleBuffer ? SLANG_OK : SLANG_FAIL;
}
diff --git a/tools/gfx/metal/metal-query.h b/tools/gfx/metal/metal-query.h
index 3b3e28489..55dc9ebbe 100644
--- a/tools/gfx/metal/metal-query.h
+++ b/tools/gfx/metal/metal-query.h
@@ -23,8 +23,7 @@ public:
Result init(DeviceImpl* device, const IQueryPool::Desc& desc);
virtual SLANG_NO_THROW Result SLANG_MCALL
- getResult(GfxIndex index, GfxCount count, uint64_t* data) override;
-
+ getResult(GfxIndex index, GfxCount count, uint64_t* data) override;
};
} // namespace metal
diff --git a/tools/gfx/metal/metal-render-pass.cpp b/tools/gfx/metal/metal-render-pass.cpp
index bc60cf746..49e470028 100644
--- a/tools/gfx/metal/metal-render-pass.cpp
+++ b/tools/gfx/metal/metal-render-pass.cpp
@@ -1,7 +1,7 @@
// metal-render-pass.cpp
#include "metal-render-pass.h"
-//#include "metal-helper-functions.h"
+// #include "metal-helper-functions.h"
namespace gfx
{
@@ -22,14 +22,10 @@ static inline MTL::LoadAction translateLoadOp(IRenderPassLayout::TargetLoadOp lo
{
switch (loadOp)
{
- case IRenderPassLayout::TargetLoadOp::Load:
- return MTL::LoadActionLoad;
- case IRenderPassLayout::TargetLoadOp::Clear:
- return MTL::LoadActionClear;
- case IRenderPassLayout::TargetLoadOp::DontCare:
- return MTL::LoadActionDontCare;
- default:
- return MTL::LoadAction(0);
+ case IRenderPassLayout::TargetLoadOp::Load: return MTL::LoadActionLoad;
+ case IRenderPassLayout::TargetLoadOp::Clear: return MTL::LoadActionClear;
+ case IRenderPassLayout::TargetLoadOp::DontCare: return MTL::LoadActionDontCare;
+ default: return MTL::LoadAction(0);
}
}
@@ -37,12 +33,9 @@ static inline MTL::StoreAction translateStoreOp(IRenderPassLayout::TargetStoreOp
{
switch (storeOp)
{
- case IRenderPassLayout::TargetStoreOp::Store:
- return MTL::StoreActionStore;
- case IRenderPassLayout::TargetStoreOp::DontCare:
- return MTL::StoreActionDontCare;
- default:
- return MTL::StoreAction(0);
+ case IRenderPassLayout::TargetStoreOp::Store: return MTL::StoreActionStore;
+ case IRenderPassLayout::TargetStoreOp::DontCare: return MTL::StoreActionDontCare;
+ default: return MTL::StoreAction(0);
}
}
@@ -50,25 +43,32 @@ Result RenderPassLayoutImpl::init(DeviceImpl* device, const IRenderPassLayout::D
{
m_device = device;
- FramebufferLayoutImpl* framebufferLayout = static_cast<FramebufferLayoutImpl*>(desc.framebufferLayout);
+ FramebufferLayoutImpl* framebufferLayout =
+ static_cast<FramebufferLayoutImpl*>(desc.framebufferLayout);
assert(framebufferLayout);
- // Initialize render pass descriptor, filling in attachment metadata, but leaving texture data unbound.
+ // Initialize render pass descriptor, filling in attachment metadata, but leaving texture data
+ // unbound.
m_renderPassDesc = NS::TransferPtr(MTL::RenderPassDescriptor::alloc()->init());
m_renderPassDesc->setRenderTargetArrayLength(desc.renderTargetCount);
for (GfxIndex i = 0; i < desc.renderTargetCount; ++i)
{
- MTL::RenderPassColorAttachmentDescriptor* colorAttachment = m_renderPassDesc->colorAttachments()->object(i);
+ MTL::RenderPassColorAttachmentDescriptor* colorAttachment =
+ m_renderPassDesc->colorAttachments()->object(i);
colorAttachment->setLoadAction(translateLoadOp(desc.renderTargetAccess[i].loadOp));
colorAttachment->setStoreAction(translateStoreOp(desc.renderTargetAccess[i].storeOp));
}
- m_renderPassDesc->depthAttachment()->setLoadAction(translateLoadOp(desc.depthStencilAccess->loadOp));
- m_renderPassDesc->depthAttachment()->setStoreAction(translateStoreOp(desc.depthStencilAccess->storeOp));
+ m_renderPassDesc->depthAttachment()->setLoadAction(
+ translateLoadOp(desc.depthStencilAccess->loadOp));
+ m_renderPassDesc->depthAttachment()->setStoreAction(
+ translateStoreOp(desc.depthStencilAccess->storeOp));
- m_renderPassDesc->stencilAttachment()->setLoadAction(translateLoadOp(desc.depthStencilAccess->loadOp));
- m_renderPassDesc->stencilAttachment()->setStoreAction(translateStoreOp(desc.depthStencilAccess->storeOp));
+ m_renderPassDesc->stencilAttachment()->setLoadAction(
+ translateLoadOp(desc.depthStencilAccess->loadOp));
+ m_renderPassDesc->stencilAttachment()->setStoreAction(
+ translateStoreOp(desc.depthStencilAccess->storeOp));
return SLANG_OK;
}
diff --git a/tools/gfx/metal/metal-render-pass.h b/tools/gfx/metal/metal-render-pass.h
index ee66b0c4d..94659a561 100644
--- a/tools/gfx/metal/metal-render-pass.h
+++ b/tools/gfx/metal/metal-render-pass.h
@@ -12,9 +12,7 @@ using namespace Slang;
namespace metal
{
-class RenderPassLayoutImpl
- : public IRenderPassLayout
- , public ComObject
+class RenderPassLayoutImpl : public IRenderPassLayout, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
diff --git a/tools/gfx/metal/metal-resource-views.cpp b/tools/gfx/metal/metal-resource-views.cpp
index ea5c23c10..2f8a4b16e 100644
--- a/tools/gfx/metal/metal-resource-views.cpp
+++ b/tools/gfx/metal/metal-resource-views.cpp
@@ -9,9 +9,7 @@ using namespace Slang;
namespace metal
{
-TextureResourceViewImpl::~TextureResourceViewImpl()
-{
-}
+TextureResourceViewImpl::~TextureResourceViewImpl() {}
Result TextureResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
{
@@ -20,9 +18,7 @@ Result TextureResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
return SLANG_OK;
}
-BufferResourceViewImpl::~BufferResourceViewImpl()
-{
-}
+BufferResourceViewImpl::~BufferResourceViewImpl() {}
Result BufferResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
{
@@ -33,12 +29,11 @@ Result BufferResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
TexelBufferResourceViewImpl::TexelBufferResourceViewImpl(DeviceImpl* device)
: ResourceViewImpl(ViewType::TexelBuffer, device)
-{}
-
-TexelBufferResourceViewImpl::~TexelBufferResourceViewImpl()
{
}
+TexelBufferResourceViewImpl::~TexelBufferResourceViewImpl() {}
+
Result TexelBufferResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
{
return SLANG_E_NOT_IMPLEMENTED;
@@ -54,9 +49,7 @@ Result AccelerationStructureImpl::getNativeHandle(InteropHandle* outHandle)
return SLANG_E_NOT_IMPLEMENTED;
}
-AccelerationStructureImpl::~AccelerationStructureImpl()
-{
-}
+AccelerationStructureImpl::~AccelerationStructureImpl() {}
} // namespace metal
} // namespace gfx
diff --git a/tools/gfx/metal/metal-resource-views.h b/tools/gfx/metal/metal-resource-views.h
index 89986f19d..ae494c2fb 100644
--- a/tools/gfx/metal/metal-resource-views.h
+++ b/tools/gfx/metal/metal-resource-views.h
@@ -26,9 +26,9 @@ public:
public:
ResourceViewImpl(ViewType viewType, DeviceImpl* device)
- : m_type(viewType)
- , m_device(device)
- {}
+ : m_type(viewType), m_device(device)
+ {
+ }
ViewType m_type;
RefPtr<DeviceImpl> m_device;
};
@@ -38,7 +38,8 @@ class TextureResourceViewImpl : public ResourceViewImpl
public:
TextureResourceViewImpl(DeviceImpl* device)
: ResourceViewImpl(ViewType::Texture, device)
- {}
+ {
+ }
~TextureResourceViewImpl();
RefPtr<TextureResourceImpl> m_texture;
NS::SharedPtr<MTL::Texture> m_textureView;
@@ -51,7 +52,8 @@ class BufferResourceViewImpl : public ResourceViewImpl
public:
BufferResourceViewImpl(DeviceImpl* device)
: ResourceViewImpl(ViewType::Buffer, device)
- {}
+ {
+ }
~BufferResourceViewImpl();
RefPtr<BufferResourceImpl> m_buffer;
Offset m_offset;
diff --git a/tools/gfx/metal/metal-sampler.cpp b/tools/gfx/metal/metal-sampler.cpp
index 561b93ea2..6f0c0e36b 100644
--- a/tools/gfx/metal/metal-sampler.cpp
+++ b/tools/gfx/metal/metal-sampler.cpp
@@ -1,5 +1,6 @@
// metal-sampler.cpp
#include "metal-sampler.h"
+
#include "metal-util.h"
namespace gfx
@@ -10,15 +11,14 @@ using namespace Slang;
namespace metal
{
-SamplerStateImpl::~SamplerStateImpl()
-{
-}
+SamplerStateImpl::~SamplerStateImpl() {}
Result SamplerStateImpl::init(DeviceImpl* device, const ISamplerState::Desc& desc)
{
m_device = device;
- NS::SharedPtr<MTL::SamplerDescriptor> samplerDesc = NS::TransferPtr(MTL::SamplerDescriptor::alloc()->init());
+ NS::SharedPtr<MTL::SamplerDescriptor> samplerDesc =
+ NS::TransferPtr(MTL::SamplerDescriptor::alloc()->init());
samplerDesc->setMinFilter(MetalUtil::translateSamplerMinMagFilter(desc.minFilter));
samplerDesc->setMagFilter(MetalUtil::translateSamplerMinMagFilter(desc.magFilter));
@@ -45,7 +45,7 @@ Result SamplerStateImpl::init(DeviceImpl* device, const ISamplerState::Desc& des
// TODO: no support for reduction op
m_samplerState = NS::TransferPtr(m_device->m_device->newSamplerState(samplerDesc.get()));
-
+
return m_samplerState ? SLANG_OK : SLANG_FAIL;
}
diff --git a/tools/gfx/metal/metal-sampler.h b/tools/gfx/metal/metal-sampler.h
index c7156cb2e..0d94a6d2d 100644
--- a/tools/gfx/metal/metal-sampler.h
+++ b/tools/gfx/metal/metal-sampler.h
@@ -21,7 +21,7 @@ public:
~SamplerStateImpl();
Result init(DeviceImpl* device, const ISamplerState::Desc& desc);
-
+
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
};
diff --git a/tools/gfx/metal/metal-shader-object-layout.cpp b/tools/gfx/metal/metal-shader-object-layout.cpp
index 94bcb6db6..e674b830a 100644
--- a/tools/gfx/metal/metal-shader-object-layout.cpp
+++ b/tools/gfx/metal/metal-shader-object-layout.cpp
@@ -29,7 +29,8 @@ ShaderObjectLayoutImpl::SubObjectRangeStride::SubObjectRangeStride(
}
}
-Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutReflection* typeLayout)
+Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(
+ slang::TypeLayoutReflection* typeLayout)
{
typeLayout = _unwrapParameterGroups(typeLayout, m_containerType);
@@ -94,8 +95,7 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
m_textureCount += count;
m_textureRanges.add(r);
break;
- default:
- break;
+ default: break;
}
// We'd like to extract the information on the Metal resource
@@ -125,7 +125,9 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
SLANG_ASSERT(descriptorSetIndex == 0);
SlangInt descriptorRangeIndex = typeLayout->getBindingRangeFirstDescriptorRangeIndex(r);
- auto registerOffset = typeLayout->getDescriptorSetDescriptorRangeIndexOffset(descriptorSetIndex, descriptorRangeIndex);
+ auto registerOffset = typeLayout->getDescriptorSetDescriptorRangeIndexOffset(
+ descriptorSetIndex,
+ descriptorRangeIndex);
bindingRangeInfo.registerOffset = (uint32_t)registerOffset;
}
@@ -160,18 +162,18 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
switch (slangBindingType)
{
default:
- {
- // In the case of `ConstantBuffer<X>` or `ParameterBlock<X>`
- // we can construct a layout from the element type directly.
- //
- auto elementTypeLayout = slangLeafTypeLayout->getElementTypeLayout();
- createForElementType(
- m_renderer,
- m_session,
- elementTypeLayout,
- subObjectLayout.writeRef());
- }
- break;
+ {
+ // In the case of `ConstantBuffer<X>` or `ParameterBlock<X>`
+ // we can construct a layout from the element type directly.
+ //
+ auto elementTypeLayout = slangLeafTypeLayout->getElementTypeLayout();
+ createForElementType(
+ m_renderer,
+ m_session,
+ elementTypeLayout,
+ subObjectLayout.writeRef());
+ }
+ break;
case slang::BindingType::ExistentialValue:
// In the case of an interface-type sub-object range, we can only
// construct a layout if we have static specialization information
@@ -193,8 +195,9 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
// increase the size of the ordinary data buffer we need to
// allocate for the parent object.
//
- uint32_t ordinaryDataEnd = subObjectRange.offset.pendingOrdinaryData
- + (uint32_t)bindingRange.count * subObjectRange.stride.pendingOrdinaryData;
+ uint32_t ordinaryDataEnd =
+ subObjectRange.offset.pendingOrdinaryData +
+ (uint32_t)bindingRange.count * subObjectRange.stride.pendingOrdinaryData;
if (ordinaryDataEnd > m_totalOrdinaryDataSize)
{
@@ -211,8 +214,7 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
SlangResult ShaderObjectLayoutImpl::Builder::build(ShaderObjectLayoutImpl** outLayout)
{
- auto layout =
- RefPtr<ShaderObjectLayoutImpl>(new ShaderObjectLayoutImpl());
+ auto layout = RefPtr<ShaderObjectLayoutImpl>(new ShaderObjectLayoutImpl());
SLANG_RETURN_ON_FAIL(layout->_init(this));
returnRefPtrMove(outLayout, layout);
@@ -224,7 +226,9 @@ slang::TypeLayoutReflection* ShaderObjectLayoutImpl::getParameterBlockTypeLayout
if (!m_parameterBlockTypeLayout)
{
m_parameterBlockTypeLayout = m_slangSession->getTypeLayout(
- m_elementTypeLayout->getType(), 0, slang::LayoutRules::MetalArgumentBufferTier2);
+ m_elementTypeLayout->getType(),
+ 0,
+ slang::LayoutRules::MetalArgumentBufferTier2);
}
return m_parameterBlockTypeLayout;
}
@@ -272,13 +276,16 @@ Result RootShaderObjectLayoutImpl::Builder::build(RootShaderObjectLayoutImpl** o
return SLANG_OK;
}
-void RootShaderObjectLayoutImpl::Builder::addGlobalParams(slang::VariableLayoutReflection* globalsLayout)
+void RootShaderObjectLayoutImpl::Builder::addGlobalParams(
+ slang::VariableLayoutReflection* globalsLayout)
{
setElementTypeLayout(globalsLayout->getTypeLayout());
}
void RootShaderObjectLayoutImpl::Builder::addEntryPoint(
- SlangStage stage, ShaderObjectLayoutImpl* entryPointLayout, slang::EntryPointLayout* slangEntryPoint)
+ SlangStage stage,
+ ShaderObjectLayoutImpl* entryPointLayout,
+ slang::EntryPointLayout* slangEntryPoint)
{
EntryPointInfo info;
info.layout = entryPointLayout;
@@ -301,7 +308,10 @@ Result RootShaderObjectLayoutImpl::create(
auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
RefPtr<ShaderObjectLayoutImpl> entryPointLayout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- renderer, program->getSession(), slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
+ renderer,
+ program->getSession(),
+ slangEntryPoint->getTypeLayout(),
+ entryPointLayout.writeRef()));
builder.addEntryPoint(slangEntryPoint->getStage(), entryPointLayout, slangEntryPoint);
}
diff --git a/tools/gfx/metal/metal-shader-object-layout.h b/tools/gfx/metal/metal-shader-object-layout.h
index 24a969c89..02833e4ca 100644
--- a/tools/gfx/metal/metal-shader-object-layout.h
+++ b/tools/gfx/metal/metal-shader-object-layout.h
@@ -63,8 +63,7 @@ public:
/// Offset information for a sub-object range
struct SubObjectRangeOffset : BindingOffset
{
- SubObjectRangeOffset()
- {}
+ SubObjectRangeOffset() {}
SubObjectRangeOffset(slang::VariableLayoutReflection* varLayout);
@@ -75,8 +74,7 @@ public:
/// Stride information for a sub-object range
struct SubObjectRangeStride : BindingOffset
{
- SubObjectRangeStride()
- {}
+ SubObjectRangeStride() {}
SubObjectRangeStride(slang::TypeLayoutReflection* typeLayout);
@@ -105,7 +103,8 @@ public:
public:
Builder(RendererBase* renderer, slang::ISession* session)
: m_renderer(renderer), m_session(session)
- {}
+ {
+ }
RendererBase* m_renderer;
slang::ISession* m_session;
@@ -129,7 +128,7 @@ public:
Index m_subObjectCount = 0;
uint32_t m_totalOrdinaryDataSize = 0;
-
+
/// The container type of this shader object. When `m_containerType` is
/// `StructuredBuffer` or `Array`, this shader object represents a collection
/// instead of a single object.
@@ -161,10 +160,7 @@ public:
RendererBase* getRenderer() { return m_renderer; }
- slang::TypeReflection* getType()
- {
- return m_elementTypeLayout->getType();
- }
+ slang::TypeReflection* getType() { return m_elementTypeLayout->getType(); }
/// Get the indices that represent all the buffer ranges in this type
List<Index> const& getBufferRanges() const { return m_bufferRanges; }
@@ -178,6 +174,7 @@ public:
uint32_t getTotalOrdinaryDataSize() const { return m_totalOrdinaryDataSize; }
slang::TypeLayoutReflection* getParameterBlockTypeLayout();
+
protected:
Result _init(Builder const* builder);
@@ -204,7 +201,8 @@ public:
{
RefPtr<ShaderObjectLayoutImpl> layout;
- /// The offset for this entry point's parameters, relative to the starting offset for the program
+ /// The offset for this entry point's parameters, relative to the starting offset for the
+ /// program
BindingOffset offset;
};
@@ -217,11 +215,15 @@ public:
: Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
- {}
+ {
+ }
Result build(RootShaderObjectLayoutImpl** outLayout);
void addGlobalParams(slang::VariableLayoutReflection* globalsLayout);
- void addEntryPoint(SlangStage stage, ShaderObjectLayoutImpl* entryPointLayout, slang::EntryPointLayout* slangEntryPoint);
+ void addEntryPoint(
+ SlangStage stage,
+ ShaderObjectLayoutImpl* entryPointLayout,
+ slang::EntryPointLayout* slangEntryPoint);
slang::IComponentType* m_program;
slang::ProgramLayout* m_programLayout;
@@ -244,7 +246,7 @@ public:
protected:
Result _init(Builder const* builder);
- ComPtr<slang::IComponentType> m_program;
+ ComPtr<slang::IComponentType> m_program;
slang::ProgramLayout* m_programLayout = nullptr;
List<EntryPointInfo> m_entryPoints;
diff --git a/tools/gfx/metal/metal-shader-object.cpp b/tools/gfx/metal/metal-shader-object.cpp
index 6d421e065..7ee7e8023 100644
--- a/tools/gfx/metal/metal-shader-object.cpp
+++ b/tools/gfx/metal/metal-shader-object.cpp
@@ -1,8 +1,8 @@
// metal-shader-object.cpp
#include "metal-shader-object.h"
-#include "metal-sampler.h"
#include "metal-device.h"
+#include "metal-sampler.h"
namespace gfx
{
@@ -24,12 +24,10 @@ Result ShaderObjectImpl::create(
return SLANG_OK;
}
-ShaderObjectImpl::~ShaderObjectImpl()
-{
-}
+ShaderObjectImpl::~ShaderObjectImpl() {}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setData(ShaderOffset const& inOffset, void const* data, size_t inSize)
+ShaderObjectImpl::setData(ShaderOffset const& inOffset, void const* data, size_t inSize)
{
Index offset = inOffset.uniformOffset;
Index size = inSize;
@@ -59,7 +57,7 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL
- ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* resourceView)
+ShaderObjectImpl::setResource(ShaderOffset const& offset, IResourceView* resourceView)
{
if (offset.bindingRangeIndex < 0)
return SLANG_E_INVALID_ARG;
@@ -74,26 +72,30 @@ SLANG_NO_THROW Result SLANG_MCALL
case slang::BindingType::Texture:
case slang::BindingType::MutableTexture:
SLANG_ASSERT(resourceViewImpl->m_type == ResourceViewImpl::ViewType::Texture);
- m_textures[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<TextureResourceViewImpl*>(resourceView);
+ m_textures[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<TextureResourceViewImpl*>(resourceView);
break;
case slang::BindingType::RawBuffer:
case slang::BindingType::ConstantBuffer:
case slang::BindingType::MutableRawBuffer:
SLANG_ASSERT(resourceViewImpl->m_type == ResourceViewImpl::ViewType::Buffer);
- m_buffers[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<BufferResourceViewImpl*>(resourceView);
+ m_buffers[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<BufferResourceViewImpl*>(resourceView);
break;
case slang::BindingType::TypedBuffer:
case slang::BindingType::MutableTypedBuffer:
SLANG_ASSERT(!"Not implemented");
// SLANG_ASSERT(resourceViewImpl->m_type == ResourceViewImpl::ViewType::TexelBuffer);
- // m_textures[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<TextureResourceViewImpl*>(resourceView);
+ // m_textures[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ // static_cast<TextureResourceViewImpl*>(resourceView);
break;
}
m_isArgumentBufferDirty = true;
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* sampler)
+SLANG_NO_THROW Result SLANG_MCALL
+ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* sampler)
{
if (offset.bindingRangeIndex < 0)
return SLANG_E_INVALID_ARG;
@@ -102,7 +104,8 @@ SLANG_NO_THROW Result SLANG_MCALL ShaderObjectImpl::setSampler(ShaderOffset cons
return SLANG_E_INVALID_ARG;
auto& bindingRange = layout->getBindingRange(offset.bindingRangeIndex);
- m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<SamplerStateImpl*>(sampler);
+ m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<SamplerStateImpl*>(sampler);
m_isArgumentBufferDirty = true;
return SLANG_OK;
}
@@ -169,7 +172,7 @@ Result ShaderObjectImpl::init(IDevice* device, ShaderObjectLayoutImpl* layout)
Result ShaderObjectImpl::_writeOrdinaryData(
void* dest,
- size_t destSize,
+ size_t destSize,
ShaderObjectLayoutImpl* layout)
{
// We start by simply writing in the ordinary data contained directly in this object.
@@ -197,7 +200,8 @@ Result ShaderObjectImpl::_writeOrdinaryData(
for (auto const& subObjectRangeInfo : layout->getSubObjectRanges())
{
Index subObjectRangeIndex = subObjectRangeCounter++;
- auto const& bindingRangeInfo = layout->getBindingRange(subObjectRangeInfo.bindingRangeIndex);
+ auto const& bindingRangeInfo =
+ layout->getBindingRange(subObjectRangeInfo.bindingRangeIndex);
// We only need to handle sub-object ranges for interface/existential-type fields,
// because fields of constant-buffer or parameter-block type are responsible for
@@ -250,11 +254,15 @@ Result ShaderObjectImpl::_writeOrdinaryData(
ShaderObjectLayoutImpl* subObjectLayout = subObject->getLayout();
- auto subObjectOffset = subObjectRangePendingDataOffset + i * subObjectRangePendingDataStride;
+ auto subObjectOffset =
+ subObjectRangePendingDataOffset + i * subObjectRangePendingDataStride;
auto subObjectDest = (char*)dest + subObjectOffset;
- subObject->_writeOrdinaryData(subObjectDest, destSize - subObjectOffset, subObjectLayout);
+ subObject->_writeOrdinaryData(
+ subObjectDest,
+ destSize - subObjectOffset,
+ subObjectLayout);
}
}
return SLANG_OK;
@@ -294,7 +302,7 @@ Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(
// don't need or want to inline it into this call site.
//
- MemoryRange range = { 0, ordinaryDataSize };
+ MemoryRange range = {0, ordinaryDataSize};
void* ordinaryData;
SLANG_RETURN_ON_FAIL(m_ordinaryDataBuffer->map(&range, &ordinaryData));
auto result = _writeOrdinaryData(ordinaryData, ordinaryDataSize, layout);
@@ -389,78 +397,98 @@ BufferResourceImpl* ShaderObjectImpl::_ensureArgumentBufferUpToDate(
// the offsets for each field.
//
auto dataSize = typeLayout->getSize();
- MemoryRange range = { 0, dataSize };
+ MemoryRange range = {0, dataSize};
void* argumentData;
SLANG_RETURN_NULL_ON_FAIL(m_argumentBuffer->map(&range, &argumentData));
// Now fill in argument values to `argumentData`.
int bindingRangeIndex = 0;
- SLANG_ASSERT(defaultTypeLayout->getBindingRangeCount() == typeLayout->getBindingRangeCount());
+ SLANG_ASSERT(
+ defaultTypeLayout->getBindingRangeCount() == typeLayout->getBindingRangeCount());
int bufferBindingIndexOffset = layout->getTotalOrdinaryDataSize() != 0 ? 1 : 0;
-
- for (unsigned int bindingRangeIndex = 0; bindingRangeIndex < defaultTypeLayout->getBindingRangeCount(); bindingRangeIndex++)
+
+ for (unsigned int bindingRangeIndex = 0;
+ bindingRangeIndex < defaultTypeLayout->getBindingRangeCount();
+ bindingRangeIndex++)
{
int bindingCount = defaultTypeLayout->getBindingRangeBindingCount(bindingRangeIndex);
int setIndex = defaultTypeLayout->getBindingRangeDescriptorSetIndex(bindingRangeIndex);
- int rangeIndex = defaultTypeLayout->getBindingRangeFirstDescriptorRangeIndex(bindingRangeIndex);
- int bindingOffset = defaultTypeLayout->getDescriptorSetDescriptorRangeIndexOffset(setIndex, rangeIndex);
+ int rangeIndex =
+ defaultTypeLayout->getBindingRangeFirstDescriptorRangeIndex(bindingRangeIndex);
+ int bindingOffset =
+ defaultTypeLayout->getDescriptorSetDescriptorRangeIndexOffset(setIndex, rangeIndex);
auto bindingType = defaultTypeLayout->getBindingRangeType(bindingRangeIndex);
for (int i = 0; i < bindingCount; i++)
{
- auto argumentDataOffset = typeLayout->getDescriptorSetDescriptorRangeIndexOffset(setIndex, rangeIndex) + i * sizeof(uint64_t);
+ auto argumentDataOffset =
+ typeLayout->getDescriptorSetDescriptorRangeIndexOffset(setIndex, rangeIndex) +
+ i * sizeof(uint64_t);
auto argumentPtr = (uint8_t*)argumentData + argumentDataOffset;
auto resourceIndex = bindingOffset + i;
switch (bindingType)
{
case slang::BindingType::ConstantBuffer:
case slang::BindingType::ParameterBlock:
- {
- if (m_objects[resourceIndex])
{
- auto subArgumentBuffer = m_objects[resourceIndex]->_ensureArgumentBufferUpToDate(device, m_objects[resourceIndex]->getLayout());
- if (subArgumentBuffer)
+ if (m_objects[resourceIndex])
{
- gfx::DeviceAddress bufferPtr = subArgumentBuffer->m_buffer->gpuAddress();
- memcpy(argumentPtr, &bufferPtr, sizeof(bufferPtr));
+ auto subArgumentBuffer =
+ m_objects[resourceIndex]->_ensureArgumentBufferUpToDate(
+ device,
+ m_objects[resourceIndex]->getLayout());
+ if (subArgumentBuffer)
+ {
+ gfx::DeviceAddress bufferPtr =
+ subArgumentBuffer->m_buffer->gpuAddress();
+ memcpy(argumentPtr, &bufferPtr, sizeof(bufferPtr));
+ }
}
+ break;
}
- break;
- }
case slang::BindingType::RawBuffer:
case slang::BindingType::MutableRawBuffer:
- {
- auto bufferViewImpl = static_cast<BufferResourceViewImpl*>(m_buffers[resourceIndex + bufferBindingIndexOffset].get());
-
- if (bufferViewImpl)
{
- gfx::DeviceAddress bufferPtr = bufferViewImpl->m_buffer->getDeviceAddress() + bufferViewImpl->m_offset;
- memcpy(argumentPtr, &bufferPtr, sizeof(bufferPtr));
+ auto bufferViewImpl = static_cast<BufferResourceViewImpl*>(
+ m_buffers[resourceIndex + bufferBindingIndexOffset].get());
+
+ if (bufferViewImpl)
+ {
+ gfx::DeviceAddress bufferPtr =
+ bufferViewImpl->m_buffer->getDeviceAddress() +
+ bufferViewImpl->m_offset;
+ memcpy(argumentPtr, &bufferPtr, sizeof(bufferPtr));
+ }
+ break;
}
- break;
- }
case slang::BindingType::Texture:
case slang::BindingType::MutableTexture:
- {
- auto textureViewImpl = static_cast<TextureResourceViewImpl*>(m_textures[resourceIndex].get());
- if (textureViewImpl)
{
- auto resourceId = textureViewImpl->m_textureView->gpuResourceID();
- memcpy(argumentPtr, &resourceId, sizeof(resourceId));
+ auto textureViewImpl =
+ static_cast<TextureResourceViewImpl*>(m_textures[resourceIndex].get());
+ if (textureViewImpl)
+ {
+ auto resourceId = textureViewImpl->m_textureView->gpuResourceID();
+ memcpy(argumentPtr, &resourceId, sizeof(resourceId));
+ }
+ break;
}
- break;
- }
case slang::BindingType::Sampler:
- {
- auto samplerStateImpl = static_cast<SamplerStateImpl*>(m_samplers[resourceIndex].get());
- auto resourceId = samplerStateImpl->m_samplerState->gpuResourceID();
- memcpy(argumentPtr, &resourceId, sizeof(resourceId));
- break;
- }
+ {
+ auto samplerStateImpl =
+ static_cast<SamplerStateImpl*>(m_samplers[resourceIndex].get());
+ auto resourceId = samplerStateImpl->m_samplerState->gpuResourceID();
+ memcpy(argumentPtr, &resourceId, sizeof(resourceId));
+ break;
+ }
}
}
}
- writeOrdinaryDataIntoArgumentBuffer(typeLayout, defaultTypeLayout, (uint8_t*)argumentData, (uint8_t*)m_data.getBuffer());
+ writeOrdinaryDataIntoArgumentBuffer(
+ typeLayout,
+ defaultTypeLayout,
+ (uint8_t*)argumentData,
+ (uint8_t*)m_data.getBuffer());
m_argumentBuffer->unmap(&range);
m_isArgumentBufferDirty = false;
}
@@ -475,7 +503,7 @@ Result ShaderObjectImpl::bindAsParameterBlock(
{
if (!context->device->m_hasArgumentBufferTier2)
return SLANG_FAIL;
-
+
auto argumentBuffer = _ensureArgumentBufferUpToDate(context->device, layout);
if (m_argumentBuffer)
@@ -531,7 +559,9 @@ Result ShaderObjectImpl::bindAsValue(
for (uint32_t i = 0; i < count; ++i)
{
auto buffer = m_buffers[baseIndex + i];
- context->setBuffer(buffer ? buffer->m_buffer->m_buffer.get() : nullptr, registerOffset + i);
+ context->setBuffer(
+ buffer ? buffer->m_buffer->m_buffer.get() : nullptr,
+ registerOffset + i);
}
}
@@ -544,7 +574,9 @@ Result ShaderObjectImpl::bindAsValue(
for (uint32_t i = 0; i < count; ++i)
{
auto texture = m_textures[baseIndex + i];
- context->setTexture(texture ? texture->m_textureView.get() : nullptr, registerOffset + i);
+ context->setTexture(
+ texture ? texture->m_textureView.get() : nullptr,
+ registerOffset + i);
}
}
@@ -557,7 +589,9 @@ Result ShaderObjectImpl::bindAsValue(
for (uint32_t i = 0; i < count; ++i)
{
auto sampler = m_samplers[baseIndex + i];
- context->setSampler(sampler ? sampler->m_samplerState.get() : nullptr, registerOffset + i);
+ context->setSampler(
+ sampler ? sampler->m_samplerState.get() : nullptr,
+ registerOffset + i);
}
}
@@ -585,31 +619,33 @@ Result ShaderObjectImpl::bindAsValue(
switch (bindingRange.bindingType)
{
case slang::BindingType::ConstantBuffer:
- {
- BindingOffset objOffset = rangeOffset;
- for (Index i = 0; i < count; ++i)
{
- auto subObject = m_objects[subObjectIndex + i];
+ BindingOffset objOffset = rangeOffset;
+ for (Index i = 0; i < count; ++i)
+ {
+ auto subObject = m_objects[subObjectIndex + i];
- // Unsurprisingly, we bind each object in the range as
- // a constant buffer.
- //
- SLANG_RETURN_ON_FAIL(subObject->bindAsConstantBuffer(context, objOffset, subObjectLayout));
+ // Unsurprisingly, we bind each object in the range as
+ // a constant buffer.
+ //
+ SLANG_RETURN_ON_FAIL(
+ subObject->bindAsConstantBuffer(context, objOffset, subObjectLayout));
- objOffset += rangeStride;
+ objOffset += rangeStride;
+ }
+ break;
}
- break;
- }
case slang::BindingType::ParameterBlock:
- {
- BindingOffset objOffset = rangeOffset;
- for (Index i = 0; i < count; ++i)
{
- auto subObject = m_objects[subObjectIndex + i];
- SLANG_RETURN_ON_FAIL(subObject->bindAsParameterBlock(context, objOffset, subObjectLayout));
- objOffset += rangeStride;
+ BindingOffset objOffset = rangeOffset;
+ for (Index i = 0; i < count; ++i)
+ {
+ auto subObject = m_objects[subObjectIndex + i];
+ SLANG_RETURN_ON_FAIL(
+ subObject->bindAsParameterBlock(context, objOffset, subObjectLayout));
+ objOffset += rangeStride;
+ }
}
- }
break;
#if 0
@@ -638,8 +674,7 @@ Result ShaderObjectImpl::bindAsValue(
break;
#endif
- default:
- break;
+ default: break;
}
}
@@ -668,9 +703,7 @@ Result RootShaderObjectImpl::collectSpecializationArgs(ExtendedShaderObjectTypeL
return SLANG_OK;
}
-Result RootShaderObjectImpl::bindAsRoot(
- BindingContext* context,
- RootShaderObjectLayoutImpl* layout)
+Result RootShaderObjectImpl::bindAsRoot(BindingContext* context, RootShaderObjectLayoutImpl* layout)
{
// When binding an entire root shader object, we need to deal with
// the way that specialization might have allocated space for "pending"
@@ -724,7 +757,8 @@ Result RootShaderObjectImpl::bindAsRoot(
// the absolute offsets as are used for the global scope do not apply
// (because entry points don't need to deal with explicit bindings).
//
- SLANG_RETURN_ON_FAIL(entryPoint->bindAsConstantBuffer(context, entryPointOffset, entryPointInfo.layout));
+ SLANG_RETURN_ON_FAIL(
+ entryPoint->bindAsConstantBuffer(context, entryPointOffset, entryPointInfo.layout));
}
return SLANG_OK;
diff --git a/tools/gfx/metal/metal-shader-object.h b/tools/gfx/metal/metal-shader-object.h
index 8a3d5d392..256995fe4 100644
--- a/tools/gfx/metal/metal-shader-object.h
+++ b/tools/gfx/metal/metal-shader-object.h
@@ -1,12 +1,11 @@
// metal-shader-object.h
#pragma once
#include "metal-base.h"
+#include "metal-helper-functions.h"
#include "metal-resource-views.h"
#include "metal-sampler.h"
#include "metal-shader-object-layout.h"
-#include "metal-helper-functions.h"
-
namespace gfx
{
@@ -16,10 +15,7 @@ namespace metal
{
class ShaderObjectImpl
- : public ShaderObjectBaseImpl<
- ShaderObjectImpl,
- ShaderObjectLayoutImpl,
- SimpleShaderObjectData>
+ : public ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, SimpleShaderObjectData>
{
public:
static Result create(
@@ -51,33 +47,31 @@ public:
}
SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& inOffset, void const* data, size_t inSize) SLANG_OVERRIDE;
+ setData(ShaderOffset const& inOffset, void const* data, size_t inSize) SLANG_OVERRIDE;
SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView) SLANG_OVERRIDE;
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) SLANG_OVERRIDE;
SLANG_NO_THROW Result SLANG_MCALL setSampler(ShaderOffset const& offset, ISamplerState* sampler)
SLANG_OVERRIDE;
SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) SLANG_OVERRIDE
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) SLANG_OVERRIDE
{
return SLANG_E_NOT_IMPLEMENTED;
}
public:
-
-
protected:
friend class ProgramVars;
Result init(IDevice* device, ShaderObjectLayoutImpl* layout);
- /// Write the uniform/ordinary data of this object into the given `dest` buffer at the given `offset`
- Result _writeOrdinaryData(
- void* dest,
- size_t destSize,
- ShaderObjectLayoutImpl* layout);
+ /// Write the uniform/ordinary data of this object into the given `dest` buffer at the given
+ /// `offset`
+ Result _writeOrdinaryData(void* dest, size_t destSize, ShaderObjectLayoutImpl* layout);
/// Ensure that the `m_ordinaryDataBuffer` has been created, if it is needed
///
@@ -162,10 +156,9 @@ public:
};
class MutableShaderObjectImpl
- : public MutableShaderObject<
- MutableShaderObjectImpl,
- ShaderObjectLayoutImpl>
-{};
+ : public MutableShaderObject<MutableShaderObjectImpl, ShaderObjectLayoutImpl>
+{
+};
class RootShaderObjectImpl : public ShaderObjectImpl
{
@@ -175,14 +168,24 @@ public:
virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
- static Result create(IDevice* device, RootShaderObjectLayoutImpl* layout, RootShaderObjectImpl** outShaderObject);
+ static Result create(
+ IDevice* device,
+ RootShaderObjectLayoutImpl* layout,
+ RootShaderObjectImpl** outShaderObject);
Result init(IDevice* device, RootShaderObjectLayoutImpl* layout);
- RootShaderObjectLayoutImpl* getLayout() { return static_cast<RootShaderObjectLayoutImpl*>(m_layout.Ptr()); }
+ RootShaderObjectLayoutImpl* getLayout()
+ {
+ return static_cast<RootShaderObjectLayoutImpl*>(m_layout.Ptr());
+ }
- GfxCount SLANG_MCALL getEntryPointCount() SLANG_OVERRIDE { return (GfxCount)m_entryPoints.getCount(); }
- SlangResult SLANG_MCALL getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) SLANG_OVERRIDE
+ GfxCount SLANG_MCALL getEntryPointCount() SLANG_OVERRIDE
+ {
+ return (GfxCount)m_entryPoints.getCount();
+ }
+ SlangResult SLANG_MCALL getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
+ SLANG_OVERRIDE
{
returnComPtr(outEntryPoint, m_entryPoints[index]);
return SLANG_OK;
@@ -191,9 +194,7 @@ public:
virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) override;
/// Bind this object as a root shader object
- Result bindAsRoot(
- BindingContext* context,
- RootShaderObjectLayoutImpl* specializedLayout);
+ Result bindAsRoot(BindingContext* context, RootShaderObjectLayoutImpl* specializedLayout);
protected:
List<RefPtr<ShaderObjectImpl>> m_entryPoints;
diff --git a/tools/gfx/metal/metal-shader-program.cpp b/tools/gfx/metal/metal-shader-program.cpp
index e0f973eb6..c95e99d04 100644
--- a/tools/gfx/metal/metal-shader-program.cpp
+++ b/tools/gfx/metal/metal-shader-program.cpp
@@ -1,5 +1,6 @@
// metal-shader-program.cpp
#include "metal-shader-program.h"
+
#include "metal-device.h"
#include "metal-util.h"
@@ -16,18 +17,22 @@ ShaderProgramImpl::ShaderProgramImpl(DeviceImpl* device)
{
}
-ShaderProgramImpl::~ShaderProgramImpl()
-{
-}
+ShaderProgramImpl::~ShaderProgramImpl() {}
-Result ShaderProgramImpl::createShaderModule(slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode)
+Result ShaderProgramImpl::createShaderModule(
+ slang::EntryPointReflection* entryPointInfo,
+ ComPtr<ISlangBlob> kernelCode)
{
Module module;
module.stage = entryPointInfo->getStage();
module.entryPointName = entryPointInfo->getNameOverride();
module.code = kernelCode;
-
- dispatch_data_t data = dispatch_data_create(kernelCode->getBufferPointer(), kernelCode->getBufferSize(), dispatch_get_main_queue(), NULL);
+
+ dispatch_data_t data = dispatch_data_create(
+ kernelCode->getBufferPointer(),
+ kernelCode->getBufferSize(),
+ dispatch_get_main_queue(),
+ NULL);
NS::Error* error;
module.library = NS::TransferPtr(m_device->m_device->newLibrary(data, &error));
if (!module.library)
diff --git a/tools/gfx/metal/metal-shader-program.h b/tools/gfx/metal/metal-shader-program.h
index d6deb6574..691e12c9e 100644
--- a/tools/gfx/metal/metal-shader-program.h
+++ b/tools/gfx/metal/metal-shader-program.h
@@ -31,7 +31,9 @@ public:
ShaderProgramImpl(DeviceImpl* device);
~ShaderProgramImpl();
- virtual Result createShaderModule(slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode) override;
+ virtual Result createShaderModule(
+ slang::EntryPointReflection* entryPointInfo,
+ ComPtr<ISlangBlob> kernelCode) override;
};
diff --git a/tools/gfx/metal/metal-swap-chain.cpp b/tools/gfx/metal/metal-swap-chain.cpp
index 1478c8bf4..75bb5afa1 100644
--- a/tools/gfx/metal/metal-swap-chain.cpp
+++ b/tools/gfx/metal/metal-swap-chain.cpp
@@ -1,8 +1,8 @@
// metal-swap-chain.cpp
#include "metal-swap-chain.h"
-#include "metal-util.h"
#include "../apple/cocoa-util.h"
+#include "metal-util.h"
namespace gfx
{
@@ -31,7 +31,10 @@ void SwapchainImpl::createImages()
{
ITextureResource::Desc imageDesc = {};
imageDesc.allowedStates = ResourceStateSet(
- ResourceState::Present, ResourceState::RenderTarget, ResourceState::CopyDestination, ResourceState::CopySource);
+ ResourceState::Present,
+ ResourceState::RenderTarget,
+ ResourceState::CopyDestination,
+ ResourceState::CopySource);
imageDesc.type = IResource::Type::Texture2D;
imageDesc.arraySize = 0;
imageDesc.format = m_desc.format;
@@ -40,7 +43,10 @@ void SwapchainImpl::createImages()
imageDesc.size.depth = 1;
imageDesc.numMipLevels = 1;
imageDesc.defaultState = ResourceState::Present;
- m_device->createTextureResource(imageDesc, nullptr, (gfx::ITextureResource**)m_images[i].writeRef());
+ m_device->createTextureResource(
+ imageDesc,
+ nullptr,
+ (gfx::ITextureResource**)m_images[i].writeRef());
}
}
@@ -105,7 +111,9 @@ Result SwapchainImpl::present()
MTL::CommandBuffer* commandBuffer = m_device->m_commandQueue->commandBuffer();
MTL::BlitCommandEncoder* encoder = commandBuffer->blitCommandEncoder();
- encoder->copyFromTexture(m_images[m_currentImageIndex]->m_texture.get(), m_currentDrawable->texture());
+ encoder->copyFromTexture(
+ m_images[m_currentImageIndex]->m_texture.get(),
+ m_currentDrawable->texture());
encoder->endEncoding();
commandBuffer->presentDrawable(m_currentDrawable.get());
commandBuffer->commit();
@@ -146,5 +154,5 @@ Result SwapchainImpl::setFullScreenMode(bool mode)
return SLANG_E_NOT_AVAILABLE;
}
-} // namespace metal
+} // namespace metal
} // namespace gfx
diff --git a/tools/gfx/metal/metal-swap-chain.h b/tools/gfx/metal/metal-swap-chain.h
index b7d57e271..957db1ad9 100644
--- a/tools/gfx/metal/metal-swap-chain.h
+++ b/tools/gfx/metal/metal-swap-chain.h
@@ -14,9 +14,7 @@ using namespace Slang;
namespace metal
{
-class SwapchainImpl
- : public ISwapchain
- , public ComObject
+class SwapchainImpl : public ISwapchain, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -42,7 +40,7 @@ public:
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override { return m_desc; }
virtual SLANG_NO_THROW Result SLANG_MCALL
- getImage(GfxIndex index, ITextureResource** outResource) override;
+ getImage(GfxIndex index, ITextureResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL resize(GfxCount width, GfxCount height) override;
virtual SLANG_NO_THROW Result SLANG_MCALL present() override;
virtual SLANG_NO_THROW int SLANG_MCALL acquireNextImage() override;
diff --git a/tools/gfx/metal/metal-texture.cpp b/tools/gfx/metal/metal-texture.cpp
index 81625aa7e..996a0b333 100644
--- a/tools/gfx/metal/metal-texture.cpp
+++ b/tools/gfx/metal/metal-texture.cpp
@@ -1,5 +1,6 @@
// metal-texture.cpp
#include "metal-texture.h"
+
#include "metal-util.h"
namespace gfx
@@ -11,14 +12,12 @@ namespace metal
{
TextureResourceImpl::TextureResourceImpl(const Desc& desc, DeviceImpl* device)
- : Parent(desc)
- , m_device(device)
-{}
-
-TextureResourceImpl::~TextureResourceImpl()
+ : Parent(desc), m_device(device)
{
}
+TextureResourceImpl::~TextureResourceImpl() {}
+
Result TextureResourceImpl::getNativeResourceHandle(InteropHandle* outHandle)
{
outHandle->api = InteropHandleAPI::Metal;
diff --git a/tools/gfx/metal/metal-texture.h b/tools/gfx/metal/metal-texture.h
index aff49beb6..fe923e965 100644
--- a/tools/gfx/metal/metal-texture.h
+++ b/tools/gfx/metal/metal-texture.h
@@ -25,7 +25,8 @@ public:
MTL::TextureType m_textureType;
MTL::PixelFormat m_pixelFormat;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
diff --git a/tools/gfx/metal/metal-transient-heap.cpp b/tools/gfx/metal/metal-transient-heap.cpp
index 8810897dd..16c883f67 100644
--- a/tools/gfx/metal/metal-transient-heap.cpp
+++ b/tools/gfx/metal/metal-transient-heap.cpp
@@ -22,9 +22,7 @@ Result TransientResourceHeapImpl::init(const ITransientResourceHeap::Desc& desc,
return SLANG_OK;
}
-TransientResourceHeapImpl::~TransientResourceHeapImpl()
-{
-}
+TransientResourceHeapImpl::~TransientResourceHeapImpl() {}
Result TransientResourceHeapImpl::createCommandBuffer(ICommandBuffer** outCmdBuffer)
{
diff --git a/tools/gfx/metal/metal-transient-heap.h b/tools/gfx/metal/metal-transient-heap.h
index 4b3f6dee9..963b5bd1b 100644
--- a/tools/gfx/metal/metal-transient-heap.h
+++ b/tools/gfx/metal/metal-transient-heap.h
@@ -27,7 +27,7 @@ public:
public:
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
+ createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL synchronizeAndReset() override;
};
diff --git a/tools/gfx/metal/metal-util.cpp b/tools/gfx/metal/metal-util.cpp
index ed96eb487..fd2e9e009 100644
--- a/tools/gfx/metal/metal-util.cpp
+++ b/tools/gfx/metal/metal-util.cpp
@@ -1,117 +1,119 @@
// metal-util.cpp
#include "metal-util.h"
+
#include "core/slang-math.h"
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
-namespace gfx {
+namespace gfx
+{
MTL::PixelFormat MetalUtil::translatePixelFormat(Format format)
{
switch (format)
{
- case Format::R32G32B32A32_TYPELESS: return MTL::PixelFormatRGBA32Float;
- case Format::R32G32B32_TYPELESS: return MTL::PixelFormatInvalid;
- case Format::R32G32_TYPELESS: return MTL::PixelFormatRG32Float;
- case Format::R32_TYPELESS: return MTL::PixelFormatR32Float;
-
- case Format::R16G16B16A16_TYPELESS: return MTL::PixelFormatRGBA16Float;
- case Format::R16G16_TYPELESS: return MTL::PixelFormatRG16Float;
- case Format::R16_TYPELESS: return MTL::PixelFormatR16Float;
-
- case Format::R8G8B8A8_TYPELESS: return MTL::PixelFormatRGBA8Unorm;
- case Format::R8G8_TYPELESS: return MTL::PixelFormatRG8Unorm;
- case Format::R8_TYPELESS: return MTL::PixelFormatR8Unorm;
- case Format::B8G8R8A8_TYPELESS: return MTL::PixelFormatBGRA8Unorm;
-
- case Format::R32G32B32A32_FLOAT: return MTL::PixelFormatRGBA32Float;
- case Format::R32G32B32_FLOAT: return MTL::PixelFormatInvalid;
- case Format::R32G32_FLOAT: return MTL::PixelFormatRG32Float;
- case Format::R32_FLOAT: return MTL::PixelFormatR32Float;
-
- case Format::R16G16B16A16_FLOAT: return MTL::PixelFormatRGBA16Float;
- case Format::R16G16_FLOAT: return MTL::PixelFormatRG16Float;
- case Format::R16_FLOAT: return MTL::PixelFormatR16Float;
-
- case Format::R32G32B32A32_UINT: return MTL::PixelFormatRGBA32Uint;
- case Format::R32G32B32_UINT: return MTL::PixelFormatInvalid;
- case Format::R32G32_UINT: return MTL::PixelFormatRG32Uint;
- case Format::R32_UINT: return MTL::PixelFormatR32Uint;
-
- case Format::R16G16B16A16_UINT: return MTL::PixelFormatRGBA16Uint;
- case Format::R16G16_UINT: return MTL::PixelFormatRG16Uint;
- case Format::R16_UINT: return MTL::PixelFormatR16Uint;
-
- case Format::R8G8B8A8_UINT: return MTL::PixelFormatRGBA8Uint;
- case Format::R8G8_UINT: return MTL::PixelFormatRG8Uint;
- case Format::R8_UINT: return MTL::PixelFormatR8Uint;
-
- case Format::R32G32B32A32_SINT: return MTL::PixelFormatRGBA32Sint;
- case Format::R32G32B32_SINT: return MTL::PixelFormatInvalid;
- case Format::R32G32_SINT: return MTL::PixelFormatRG32Sint;
- case Format::R32_SINT: return MTL::PixelFormatR32Sint;
-
- case Format::R16G16B16A16_SINT: return MTL::PixelFormatRGBA16Sint;
- case Format::R16G16_SINT: return MTL::PixelFormatRG16Sint;
- case Format::R16_SINT: return MTL::PixelFormatR16Sint;
-
- case Format::R8G8B8A8_SINT: return MTL::PixelFormatRGBA8Sint;
- case Format::R8G8_SINT: return MTL::PixelFormatRG8Sint;
- case Format::R8_SINT: return MTL::PixelFormatR8Sint;
-
- case Format::R16G16B16A16_UNORM: return MTL::PixelFormatRGBA16Unorm;
- case Format::R16G16_UNORM: return MTL::PixelFormatRG16Unorm;
- case Format::R16_UNORM: return MTL::PixelFormatR16Unorm;
-
- case Format::R8G8B8A8_UNORM: return MTL::PixelFormatRGBA8Unorm;
- case Format::R8G8B8A8_UNORM_SRGB: return MTL::PixelFormatRGBA8Unorm_sRGB;
- case Format::R8G8_UNORM: return MTL::PixelFormatRG8Unorm;
- case Format::R8_UNORM: return MTL::PixelFormatR8Unorm;
- case Format::B8G8R8A8_UNORM: return MTL::PixelFormatBGRA8Unorm;
- case Format::B8G8R8A8_UNORM_SRGB: return MTL::PixelFormatBGRA8Unorm_sRGB;
- case Format::B8G8R8X8_UNORM: return MTL::PixelFormatInvalid;
- case Format::B8G8R8X8_UNORM_SRGB: return MTL::PixelFormatInvalid;
-
- case Format::R16G16B16A16_SNORM: return MTL::PixelFormatRGBA16Snorm;
- case Format::R16G16_SNORM: return MTL::PixelFormatRG16Snorm;
- case Format::R16_SNORM: return MTL::PixelFormatR16Snorm;
-
- case Format::R8G8B8A8_SNORM: return MTL::PixelFormatRGBA8Snorm;
- case Format::R8G8_SNORM: return MTL::PixelFormatRG8Snorm;
- case Format::R8_SNORM: return MTL::PixelFormatR8Snorm;
-
- case Format::D32_FLOAT: return MTL::PixelFormatDepth32Float;
- case Format::D16_UNORM: return MTL::PixelFormatDepth16Unorm;
- case Format::D32_FLOAT_S8_UINT: return MTL::PixelFormatDepth32Float_Stencil8;
- case Format::R32_FLOAT_X32_TYPELESS: return MTL::PixelFormatInvalid;
-
- case Format::B4G4R4A4_UNORM: return MTL::PixelFormatABGR4Unorm;
- case Format::B5G6R5_UNORM: return MTL::PixelFormatB5G6R5Unorm;
- case Format::B5G5R5A1_UNORM: return MTL::PixelFormatA1BGR5Unorm;
-
- case Format::R9G9B9E5_SHAREDEXP: return MTL::PixelFormatRGB9E5Float;
- case Format::R10G10B10A2_TYPELESS: return MTL::PixelFormatInvalid;
- case Format::R10G10B10A2_UINT: return MTL::PixelFormatRGB10A2Uint;
- case Format::R10G10B10A2_UNORM: return MTL::PixelFormatRGB10A2Unorm;
- case Format::R11G11B10_FLOAT: return MTL::PixelFormatRG11B10Float;
-
- case Format::BC1_UNORM: return MTL::PixelFormatBC1_RGBA;
- case Format::BC1_UNORM_SRGB: return MTL::PixelFormatBC1_RGBA_sRGB;
- case Format::BC2_UNORM: return MTL::PixelFormatBC2_RGBA;
- case Format::BC2_UNORM_SRGB: return MTL::PixelFormatBC2_RGBA_sRGB;
- case Format::BC3_UNORM: return MTL::PixelFormatBC3_RGBA;
- case Format::BC3_UNORM_SRGB: return MTL::PixelFormatBC3_RGBA_sRGB;
- case Format::BC4_UNORM: return MTL::PixelFormatBC4_RUnorm;
- case Format::BC4_SNORM: return MTL::PixelFormatBC4_RSnorm;
- case Format::BC5_UNORM: return MTL::PixelFormatBC5_RGUnorm;
- case Format::BC5_SNORM: return MTL::PixelFormatBC5_RGSnorm;
- case Format::BC6H_UF16: return MTL::PixelFormatBC6H_RGBUfloat;
- case Format::BC6H_SF16: return MTL::PixelFormatBC6H_RGBFloat;
- case Format::BC7_UNORM: return MTL::PixelFormatBC7_RGBAUnorm;
- case Format::BC7_UNORM_SRGB: return MTL::PixelFormatBC7_RGBAUnorm_sRGB;
-
- default: return MTL::PixelFormatInvalid;
+ case Format::R32G32B32A32_TYPELESS: return MTL::PixelFormatRGBA32Float;
+ case Format::R32G32B32_TYPELESS: return MTL::PixelFormatInvalid;
+ case Format::R32G32_TYPELESS: return MTL::PixelFormatRG32Float;
+ case Format::R32_TYPELESS: return MTL::PixelFormatR32Float;
+
+ case Format::R16G16B16A16_TYPELESS: return MTL::PixelFormatRGBA16Float;
+ case Format::R16G16_TYPELESS: return MTL::PixelFormatRG16Float;
+ case Format::R16_TYPELESS: return MTL::PixelFormatR16Float;
+
+ case Format::R8G8B8A8_TYPELESS: return MTL::PixelFormatRGBA8Unorm;
+ case Format::R8G8_TYPELESS: return MTL::PixelFormatRG8Unorm;
+ case Format::R8_TYPELESS: return MTL::PixelFormatR8Unorm;
+ case Format::B8G8R8A8_TYPELESS: return MTL::PixelFormatBGRA8Unorm;
+
+ case Format::R32G32B32A32_FLOAT: return MTL::PixelFormatRGBA32Float;
+ case Format::R32G32B32_FLOAT: return MTL::PixelFormatInvalid;
+ case Format::R32G32_FLOAT: return MTL::PixelFormatRG32Float;
+ case Format::R32_FLOAT: return MTL::PixelFormatR32Float;
+
+ case Format::R16G16B16A16_FLOAT: return MTL::PixelFormatRGBA16Float;
+ case Format::R16G16_FLOAT: return MTL::PixelFormatRG16Float;
+ case Format::R16_FLOAT: return MTL::PixelFormatR16Float;
+
+ case Format::R32G32B32A32_UINT: return MTL::PixelFormatRGBA32Uint;
+ case Format::R32G32B32_UINT: return MTL::PixelFormatInvalid;
+ case Format::R32G32_UINT: return MTL::PixelFormatRG32Uint;
+ case Format::R32_UINT: return MTL::PixelFormatR32Uint;
+
+ case Format::R16G16B16A16_UINT: return MTL::PixelFormatRGBA16Uint;
+ case Format::R16G16_UINT: return MTL::PixelFormatRG16Uint;
+ case Format::R16_UINT: return MTL::PixelFormatR16Uint;
+
+ case Format::R8G8B8A8_UINT: return MTL::PixelFormatRGBA8Uint;
+ case Format::R8G8_UINT: return MTL::PixelFormatRG8Uint;
+ case Format::R8_UINT: return MTL::PixelFormatR8Uint;
+
+ case Format::R32G32B32A32_SINT: return MTL::PixelFormatRGBA32Sint;
+ case Format::R32G32B32_SINT: return MTL::PixelFormatInvalid;
+ case Format::R32G32_SINT: return MTL::PixelFormatRG32Sint;
+ case Format::R32_SINT: return MTL::PixelFormatR32Sint;
+
+ case Format::R16G16B16A16_SINT: return MTL::PixelFormatRGBA16Sint;
+ case Format::R16G16_SINT: return MTL::PixelFormatRG16Sint;
+ case Format::R16_SINT: return MTL::PixelFormatR16Sint;
+
+ case Format::R8G8B8A8_SINT: return MTL::PixelFormatRGBA8Sint;
+ case Format::R8G8_SINT: return MTL::PixelFormatRG8Sint;
+ case Format::R8_SINT: return MTL::PixelFormatR8Sint;
+
+ case Format::R16G16B16A16_UNORM: return MTL::PixelFormatRGBA16Unorm;
+ case Format::R16G16_UNORM: return MTL::PixelFormatRG16Unorm;
+ case Format::R16_UNORM: return MTL::PixelFormatR16Unorm;
+
+ case Format::R8G8B8A8_UNORM: return MTL::PixelFormatRGBA8Unorm;
+ case Format::R8G8B8A8_UNORM_SRGB: return MTL::PixelFormatRGBA8Unorm_sRGB;
+ case Format::R8G8_UNORM: return MTL::PixelFormatRG8Unorm;
+ case Format::R8_UNORM: return MTL::PixelFormatR8Unorm;
+ case Format::B8G8R8A8_UNORM: return MTL::PixelFormatBGRA8Unorm;
+ case Format::B8G8R8A8_UNORM_SRGB: return MTL::PixelFormatBGRA8Unorm_sRGB;
+ case Format::B8G8R8X8_UNORM: return MTL::PixelFormatInvalid;
+ case Format::B8G8R8X8_UNORM_SRGB: return MTL::PixelFormatInvalid;
+
+ case Format::R16G16B16A16_SNORM: return MTL::PixelFormatRGBA16Snorm;
+ case Format::R16G16_SNORM: return MTL::PixelFormatRG16Snorm;
+ case Format::R16_SNORM: return MTL::PixelFormatR16Snorm;
+
+ case Format::R8G8B8A8_SNORM: return MTL::PixelFormatRGBA8Snorm;
+ case Format::R8G8_SNORM: return MTL::PixelFormatRG8Snorm;
+ case Format::R8_SNORM: return MTL::PixelFormatR8Snorm;
+
+ case Format::D32_FLOAT: return MTL::PixelFormatDepth32Float;
+ case Format::D16_UNORM: return MTL::PixelFormatDepth16Unorm;
+ case Format::D32_FLOAT_S8_UINT: return MTL::PixelFormatDepth32Float_Stencil8;
+ case Format::R32_FLOAT_X32_TYPELESS: return MTL::PixelFormatInvalid;
+
+ case Format::B4G4R4A4_UNORM: return MTL::PixelFormatABGR4Unorm;
+ case Format::B5G6R5_UNORM: return MTL::PixelFormatB5G6R5Unorm;
+ case Format::B5G5R5A1_UNORM: return MTL::PixelFormatA1BGR5Unorm;
+
+ case Format::R9G9B9E5_SHAREDEXP: return MTL::PixelFormatRGB9E5Float;
+ case Format::R10G10B10A2_TYPELESS: return MTL::PixelFormatInvalid;
+ case Format::R10G10B10A2_UINT: return MTL::PixelFormatRGB10A2Uint;
+ case Format::R10G10B10A2_UNORM: return MTL::PixelFormatRGB10A2Unorm;
+ case Format::R11G11B10_FLOAT: return MTL::PixelFormatRG11B10Float;
+
+ case Format::BC1_UNORM: return MTL::PixelFormatBC1_RGBA;
+ case Format::BC1_UNORM_SRGB: return MTL::PixelFormatBC1_RGBA_sRGB;
+ case Format::BC2_UNORM: return MTL::PixelFormatBC2_RGBA;
+ case Format::BC2_UNORM_SRGB: return MTL::PixelFormatBC2_RGBA_sRGB;
+ case Format::BC3_UNORM: return MTL::PixelFormatBC3_RGBA;
+ case Format::BC3_UNORM_SRGB: return MTL::PixelFormatBC3_RGBA_sRGB;
+ case Format::BC4_UNORM: return MTL::PixelFormatBC4_RUnorm;
+ case Format::BC4_SNORM: return MTL::PixelFormatBC4_RSnorm;
+ case Format::BC5_UNORM: return MTL::PixelFormatBC5_RGUnorm;
+ case Format::BC5_SNORM: return MTL::PixelFormatBC5_RGSnorm;
+ case Format::BC6H_UF16: return MTL::PixelFormatBC6H_RGBUfloat;
+ case Format::BC6H_SF16: return MTL::PixelFormatBC6H_RGBFloat;
+ case Format::BC7_UNORM: return MTL::PixelFormatBC7_RGBAUnorm;
+ case Format::BC7_UNORM_SRGB: return MTL::PixelFormatBC7_RGBAUnorm_sRGB;
+
+ default: return MTL::PixelFormatInvalid;
}
}
@@ -119,60 +121,60 @@ MTL::VertexFormat MetalUtil::translateVertexFormat(Format format)
{
switch (format)
{
- case Format::R8G8_UINT: return MTL::VertexFormatUChar2;
+ case Format::R8G8_UINT: return MTL::VertexFormatUChar2;
// VertexFormatUChar3
- case Format::R8G8B8A8_UINT: return MTL::VertexFormatUChar4;
- case Format::R8G8_SINT: return MTL::VertexFormatChar2;
+ case Format::R8G8B8A8_UINT: return MTL::VertexFormatUChar4;
+ case Format::R8G8_SINT: return MTL::VertexFormatChar2;
// return VertexFormatChar3
- case Format::R8G8B8A8_SINT: return MTL::VertexFormatChar4;
- case Format::R8G8_UNORM: return MTL::VertexFormatUChar2Normalized;
+ case Format::R8G8B8A8_SINT: return MTL::VertexFormatChar4;
+ case Format::R8G8_UNORM: return MTL::VertexFormatUChar2Normalized;
// return VertexFormatUChar3Normalized;
- case Format::R8G8B8A8_UNORM: return MTL::VertexFormatUChar4Normalized;
- case Format::R8G8_SNORM: return MTL::VertexFormatChar2Normalized;
+ case Format::R8G8B8A8_UNORM: return MTL::VertexFormatUChar4Normalized;
+ case Format::R8G8_SNORM: return MTL::VertexFormatChar2Normalized;
// return VertexFormatChar3Normalized
- case Format::R8G8B8A8_SNORM: return MTL::VertexFormatChar4Normalized;
- case Format::R16G16_UINT: return MTL::VertexFormatUShort2;
+ case Format::R8G8B8A8_SNORM: return MTL::VertexFormatChar4Normalized;
+ case Format::R16G16_UINT: return MTL::VertexFormatUShort2;
// return VertexFormatUShort3;
- case Format::R16G16B16A16_UINT: return MTL::VertexFormatUShort4;
- case Format::R16G16_SINT: return MTL::VertexFormatShort2;
+ case Format::R16G16B16A16_UINT: return MTL::VertexFormatUShort4;
+ case Format::R16G16_SINT: return MTL::VertexFormatShort2;
// return VertexFormatShort3;
- case Format::R16G16B16A16_SINT: return MTL::VertexFormatShort4;
- case Format::R16G16_UNORM: return MTL::VertexFormatUShort2Normalized;
+ case Format::R16G16B16A16_SINT: return MTL::VertexFormatShort4;
+ case Format::R16G16_UNORM: return MTL::VertexFormatUShort2Normalized;
// return VertexFormatUShort3Normalized;
- case Format::R16G16B16A16_UNORM: return MTL::VertexFormatUShort4Normalized;
- case Format::R16G16_SNORM: return MTL::VertexFormatShort2Normalized;
+ case Format::R16G16B16A16_UNORM: return MTL::VertexFormatUShort4Normalized;
+ case Format::R16G16_SNORM: return MTL::VertexFormatShort2Normalized;
// return VertexFormatShort3Normalized;
- case Format::R16G16B16A16_SNORM: return MTL::VertexFormatShort4Normalized;
- case Format::R16G16_FLOAT: return MTL::VertexFormatHalf2;
+ case Format::R16G16B16A16_SNORM: return MTL::VertexFormatShort4Normalized;
+ case Format::R16G16_FLOAT: return MTL::VertexFormatHalf2;
// return VertexFormatHalf3;
- case Format::R16G16B16A16_FLOAT: return MTL::VertexFormatHalf4;
- case Format::R32_FLOAT: return MTL::VertexFormatFloat;
- case Format::R32G32_FLOAT: return MTL::VertexFormatFloat2;
- case Format::R32G32B32_FLOAT: return MTL::VertexFormatFloat3;
- case Format::R32G32B32A32_FLOAT: return MTL::VertexFormatFloat4;
- case Format::R32_SINT: return MTL::VertexFormatInt;
- case Format::R32G32_SINT: return MTL::VertexFormatInt2;
- case Format::R32G32B32_SINT: return MTL::VertexFormatInt3;
- case Format::R32G32B32A32_SINT: return MTL::VertexFormatInt4;
- case Format::R32_UINT: return MTL::VertexFormatUInt;
- case Format::R32G32_UINT: return MTL::VertexFormatUInt2;
- case Format::R32G32B32_UINT: return MTL::VertexFormatUInt3;
- case Format::R32G32B32A32_UINT: return MTL::VertexFormatUInt4;
+ case Format::R16G16B16A16_FLOAT: return MTL::VertexFormatHalf4;
+ case Format::R32_FLOAT: return MTL::VertexFormatFloat;
+ case Format::R32G32_FLOAT: return MTL::VertexFormatFloat2;
+ case Format::R32G32B32_FLOAT: return MTL::VertexFormatFloat3;
+ case Format::R32G32B32A32_FLOAT: return MTL::VertexFormatFloat4;
+ case Format::R32_SINT: return MTL::VertexFormatInt;
+ case Format::R32G32_SINT: return MTL::VertexFormatInt2;
+ case Format::R32G32B32_SINT: return MTL::VertexFormatInt3;
+ case Format::R32G32B32A32_SINT: return MTL::VertexFormatInt4;
+ case Format::R32_UINT: return MTL::VertexFormatUInt;
+ case Format::R32G32_UINT: return MTL::VertexFormatUInt2;
+ case Format::R32G32B32_UINT: return MTL::VertexFormatUInt3;
+ case Format::R32G32B32A32_UINT: return MTL::VertexFormatUInt4;
// return VertexFormatInt1010102Normalized;
- case Format::R10G10B10A2_UNORM: return MTL::VertexFormatUInt1010102Normalized;
- case Format::B4G4R4A4_UNORM: return MTL::VertexFormatUChar4Normalized_BGRA;
- case Format::R8_UINT: return MTL::VertexFormatUChar;
- case Format::R8_SINT: return MTL::VertexFormatChar;
- case Format::R8_UNORM: return MTL::VertexFormatUCharNormalized;
- case Format::R8_SNORM: return MTL::VertexFormatCharNormalized;
- case Format::R16_UINT: return MTL::VertexFormatUShort;
- case Format::R16_SINT: return MTL::VertexFormatShort;
- case Format::R16_UNORM: return MTL::VertexFormatUShortNormalized;
- case Format::R16_SNORM: return MTL::VertexFormatShortNormalized;
- case Format::R16_FLOAT: return MTL::VertexFormatHalf;
- case Format::R11G11B10_FLOAT: return MTL::VertexFormatFloatRG11B10;
- case Format::R9G9B9E5_SHAREDEXP: return MTL::VertexFormatFloatRGB9E5;
- default: return MTL::VertexFormatInvalid;
+ case Format::R10G10B10A2_UNORM: return MTL::VertexFormatUInt1010102Normalized;
+ case Format::B4G4R4A4_UNORM: return MTL::VertexFormatUChar4Normalized_BGRA;
+ case Format::R8_UINT: return MTL::VertexFormatUChar;
+ case Format::R8_SINT: return MTL::VertexFormatChar;
+ case Format::R8_UNORM: return MTL::VertexFormatUCharNormalized;
+ case Format::R8_SNORM: return MTL::VertexFormatCharNormalized;
+ case Format::R16_UINT: return MTL::VertexFormatUShort;
+ case Format::R16_SINT: return MTL::VertexFormatShort;
+ case Format::R16_UNORM: return MTL::VertexFormatUShortNormalized;
+ case Format::R16_SNORM: return MTL::VertexFormatShortNormalized;
+ case Format::R16_FLOAT: return MTL::VertexFormatHalf;
+ case Format::R11G11B10_FLOAT: return MTL::VertexFormatFloatRG11B10;
+ case Format::R9G9B9E5_SHAREDEXP: return MTL::VertexFormatFloatRGB9E5;
+ default: return MTL::VertexFormatInvalid;
}
}
@@ -183,10 +185,8 @@ bool MetalUtil::isDepthFormat(MTL::PixelFormat format)
case MTL::PixelFormatDepth16Unorm:
case MTL::PixelFormatDepth32Float:
case MTL::PixelFormatDepth24Unorm_Stencil8:
- case MTL::PixelFormatDepth32Float_Stencil8:
- return true;
- default:
- return false;
+ case MTL::PixelFormatDepth32Float_Stencil8: return true;
+ default: return false;
}
}
@@ -198,10 +198,8 @@ bool MetalUtil::isStencilFormat(MTL::PixelFormat format)
case MTL::PixelFormatDepth24Unorm_Stencil8:
case MTL::PixelFormatDepth32Float_Stencil8:
case MTL::PixelFormatX32_Stencil8:
- case MTL::PixelFormatX24_Stencil8:
- return true;
- default:
- return false;
+ case MTL::PixelFormatX24_Stencil8: return true;
+ default: return false;
}
}
@@ -209,12 +207,9 @@ MTL::SamplerMinMagFilter MetalUtil::translateSamplerMinMagFilter(TextureFilterin
{
switch (mode)
{
- case TextureFilteringMode::Point:
- return MTL::SamplerMinMagFilterNearest;
- case TextureFilteringMode::Linear:
- return MTL::SamplerMinMagFilterLinear;
- default:
- return MTL::SamplerMinMagFilter(0);
+ case TextureFilteringMode::Point: return MTL::SamplerMinMagFilterNearest;
+ case TextureFilteringMode::Linear: return MTL::SamplerMinMagFilterLinear;
+ default: return MTL::SamplerMinMagFilter(0);
}
}
@@ -222,31 +217,22 @@ MTL::SamplerMipFilter MetalUtil::translateSamplerMipFilter(TextureFilteringMode
{
switch (mode)
{
- case TextureFilteringMode::Point:
- return MTL::SamplerMipFilterNearest;
- case TextureFilteringMode::Linear:
- return MTL::SamplerMipFilterLinear;
- default:
- return MTL::SamplerMipFilter(0);
- }
+ case TextureFilteringMode::Point: return MTL::SamplerMipFilterNearest;
+ case TextureFilteringMode::Linear: return MTL::SamplerMipFilterLinear;
+ default: return MTL::SamplerMipFilter(0);
+ }
}
MTL::SamplerAddressMode MetalUtil::translateSamplerAddressMode(TextureAddressingMode mode)
{
switch (mode)
{
- case TextureAddressingMode::Wrap:
- return MTL::SamplerAddressModeRepeat;
- case TextureAddressingMode::ClampToEdge:
- return MTL::SamplerAddressModeClampToEdge;
- case TextureAddressingMode::ClampToBorder:
- return MTL::SamplerAddressModeClampToBorderColor;
- case TextureAddressingMode::MirrorRepeat:
- return MTL::SamplerAddressModeMirrorRepeat;
- case TextureAddressingMode::MirrorOnce:
- return MTL::SamplerAddressModeMirrorClampToEdge;
- default:
- return MTL::SamplerAddressMode(0);
+ case TextureAddressingMode::Wrap: return MTL::SamplerAddressModeRepeat;
+ case TextureAddressingMode::ClampToEdge: return MTL::SamplerAddressModeClampToEdge;
+ case TextureAddressingMode::ClampToBorder: return MTL::SamplerAddressModeClampToBorderColor;
+ case TextureAddressingMode::MirrorRepeat: return MTL::SamplerAddressModeMirrorRepeat;
+ case TextureAddressingMode::MirrorOnce: return MTL::SamplerAddressModeMirrorClampToEdge;
+ default: return MTL::SamplerAddressMode(0);
}
}
@@ -254,24 +240,15 @@ MTL::CompareFunction MetalUtil::translateCompareFunction(ComparisonFunc func)
{
switch (func)
{
- case ComparisonFunc::Never:
- return MTL::CompareFunctionNever;
- case ComparisonFunc::Less:
- return MTL::CompareFunctionLess;
- case ComparisonFunc::Equal:
- return MTL::CompareFunctionEqual;
- case ComparisonFunc::LessEqual:
- return MTL::CompareFunctionLessEqual;
- case ComparisonFunc::Greater:
- return MTL::CompareFunctionGreater;
- case ComparisonFunc::NotEqual:
- return MTL::CompareFunctionNotEqual;
- case ComparisonFunc::GreaterEqual:
- return MTL::CompareFunctionGreaterEqual;
- case ComparisonFunc::Always:
- return MTL::CompareFunctionAlways;
- default:
- return MTL::CompareFunction(0);
+ case ComparisonFunc::Never: return MTL::CompareFunctionNever;
+ case ComparisonFunc::Less: return MTL::CompareFunctionLess;
+ case ComparisonFunc::Equal: return MTL::CompareFunctionEqual;
+ case ComparisonFunc::LessEqual: return MTL::CompareFunctionLessEqual;
+ case ComparisonFunc::Greater: return MTL::CompareFunctionGreater;
+ case ComparisonFunc::NotEqual: return MTL::CompareFunctionNotEqual;
+ case ComparisonFunc::GreaterEqual: return MTL::CompareFunctionGreaterEqual;
+ case ComparisonFunc::Always: return MTL::CompareFunctionAlways;
+ default: return MTL::CompareFunction(0);
}
}
@@ -279,24 +256,15 @@ MTL::StencilOperation MetalUtil::translateStencilOperation(StencilOp op)
{
switch (op)
{
- case StencilOp::Keep:
- return MTL::StencilOperationKeep;
- case StencilOp::Zero:
- return MTL::StencilOperationZero;
- case StencilOp::Replace:
- return MTL::StencilOperationReplace;
- case StencilOp::IncrementSaturate:
- return MTL::StencilOperationIncrementClamp;
- case StencilOp::DecrementSaturate:
- return MTL::StencilOperationDecrementClamp;
- case StencilOp::Invert:
- return MTL::StencilOperationInvert;
- case StencilOp::IncrementWrap:
- return MTL::StencilOperationIncrementWrap;
- case StencilOp::DecrementWrap:
- return MTL::StencilOperationDecrementWrap;
- default:
- return MTL::StencilOperation(0);
+ case StencilOp::Keep: return MTL::StencilOperationKeep;
+ case StencilOp::Zero: return MTL::StencilOperationZero;
+ case StencilOp::Replace: return MTL::StencilOperationReplace;
+ case StencilOp::IncrementSaturate: return MTL::StencilOperationIncrementClamp;
+ case StencilOp::DecrementSaturate: return MTL::StencilOperationDecrementClamp;
+ case StencilOp::Invert: return MTL::StencilOperationInvert;
+ case StencilOp::IncrementWrap: return MTL::StencilOperationIncrementWrap;
+ case StencilOp::DecrementWrap: return MTL::StencilOperationDecrementWrap;
+ default: return MTL::StencilOperation(0);
}
}
@@ -304,12 +272,9 @@ MTL::VertexStepFunction MetalUtil::translateVertexStepFunction(InputSlotClass sl
{
switch (slotClass)
{
- case InputSlotClass::PerVertex:
- return MTL::VertexStepFunctionPerVertex;
- case InputSlotClass::PerInstance:
- return MTL::VertexStepFunctionPerInstance;
- default:
- return MTL::VertexStepFunctionPerVertex;
+ case InputSlotClass::PerVertex: return MTL::VertexStepFunctionPerVertex;
+ case InputSlotClass::PerInstance: return MTL::VertexStepFunctionPerInstance;
+ default: return MTL::VertexStepFunctionPerVertex;
}
}
@@ -317,18 +282,12 @@ MTL::PrimitiveType MetalUtil::translatePrimitiveType(PrimitiveTopology topology)
{
switch (topology)
{
- case PrimitiveTopology::TriangleList:
- return MTL::PrimitiveTypeTriangle;
- case PrimitiveTopology::TriangleStrip:
- return MTL::PrimitiveTypeTriangleStrip;
- case PrimitiveTopology::PointList:
- return MTL::PrimitiveTypePoint;
- case PrimitiveTopology::LineList:
- return MTL::PrimitiveTypeLine;
- case PrimitiveTopology::LineStrip:
- return MTL::PrimitiveTypeLineStrip;
- default:
- return MTL::PrimitiveType(0);
+ case PrimitiveTopology::TriangleList: return MTL::PrimitiveTypeTriangle;
+ case PrimitiveTopology::TriangleStrip: return MTL::PrimitiveTypeTriangleStrip;
+ case PrimitiveTopology::PointList: return MTL::PrimitiveTypePoint;
+ case PrimitiveTopology::LineList: return MTL::PrimitiveTypeLine;
+ case PrimitiveTopology::LineStrip: return MTL::PrimitiveTypeLineStrip;
+ default: return MTL::PrimitiveType(0);
}
}
@@ -336,15 +295,11 @@ MTL::PrimitiveTopologyClass MetalUtil::translatePrimitiveTopologyClass(Primitive
{
switch (type)
{
- case PrimitiveType::Point:
- return MTL::PrimitiveTopologyClassPoint;
- case PrimitiveType::Line:
- return MTL::PrimitiveTopologyClassLine;
- case PrimitiveType::Triangle:
- return MTL::PrimitiveTopologyClassTriangle;
+ case PrimitiveType::Point: return MTL::PrimitiveTopologyClassPoint;
+ case PrimitiveType::Line: return MTL::PrimitiveTopologyClassLine;
+ case PrimitiveType::Triangle: return MTL::PrimitiveTopologyClassTriangle;
case PrimitiveType::Patch:
- default:
- return MTL::PrimitiveTopologyClassUnspecified;
+ default: return MTL::PrimitiveTopologyClassUnspecified;
}
}
@@ -352,42 +307,24 @@ MTL::BlendFactor MetalUtil::translateBlendFactor(BlendFactor factor)
{
switch (factor)
{
- case BlendFactor::Zero:
- return MTL::BlendFactorZero;
- case BlendFactor::One:
- return MTL::BlendFactorOne;
- case BlendFactor::SrcColor:
- return MTL::BlendFactorSourceColor;
- case BlendFactor::InvSrcColor:
- return MTL::BlendFactorOneMinusSourceColor;
- case BlendFactor::SrcAlpha:
- return MTL::BlendFactorSourceAlpha;
- case BlendFactor::InvSrcAlpha:
- return MTL::BlendFactorOneMinusSourceAlpha;
- case BlendFactor::DestAlpha:
- return MTL::BlendFactorDestinationAlpha;
- case BlendFactor::InvDestAlpha:
- return MTL::BlendFactorOneMinusDestinationAlpha;
- case BlendFactor::DestColor:
- return MTL::BlendFactorDestinationColor;
- case BlendFactor::InvDestColor:
- return MTL::BlendFactorOneMinusDestinationColor;
- case BlendFactor::SrcAlphaSaturate:
- return MTL::BlendFactorSourceAlphaSaturated;
- case BlendFactor::BlendColor:
- return MTL::BlendFactorBlendColor;
- case BlendFactor::InvBlendColor:
- return MTL::BlendFactorOneMinusBlendColor;
- case BlendFactor::SecondarySrcColor:
- return MTL::BlendFactorSource1Color;
- case BlendFactor::InvSecondarySrcColor:
- return MTL::BlendFactorOneMinusSource1Color;
- case BlendFactor::SecondarySrcAlpha:
- return MTL::BlendFactorSource1Alpha;
- case BlendFactor::InvSecondarySrcAlpha:
- return MTL::BlendFactorOneMinusSource1Alpha;
- default:
- return MTL::BlendFactor(0);
+ case BlendFactor::Zero: return MTL::BlendFactorZero;
+ case BlendFactor::One: return MTL::BlendFactorOne;
+ case BlendFactor::SrcColor: return MTL::BlendFactorSourceColor;
+ case BlendFactor::InvSrcColor: return MTL::BlendFactorOneMinusSourceColor;
+ case BlendFactor::SrcAlpha: return MTL::BlendFactorSourceAlpha;
+ case BlendFactor::InvSrcAlpha: return MTL::BlendFactorOneMinusSourceAlpha;
+ case BlendFactor::DestAlpha: return MTL::BlendFactorDestinationAlpha;
+ case BlendFactor::InvDestAlpha: return MTL::BlendFactorOneMinusDestinationAlpha;
+ case BlendFactor::DestColor: return MTL::BlendFactorDestinationColor;
+ case BlendFactor::InvDestColor: return MTL::BlendFactorOneMinusDestinationColor;
+ case BlendFactor::SrcAlphaSaturate: return MTL::BlendFactorSourceAlphaSaturated;
+ case BlendFactor::BlendColor: return MTL::BlendFactorBlendColor;
+ case BlendFactor::InvBlendColor: return MTL::BlendFactorOneMinusBlendColor;
+ case BlendFactor::SecondarySrcColor: return MTL::BlendFactorSource1Color;
+ case BlendFactor::InvSecondarySrcColor: return MTL::BlendFactorOneMinusSource1Color;
+ case BlendFactor::SecondarySrcAlpha: return MTL::BlendFactorSource1Alpha;
+ case BlendFactor::InvSecondarySrcAlpha: return MTL::BlendFactorOneMinusSource1Alpha;
+ default: return MTL::BlendFactor(0);
}
}
@@ -395,18 +332,12 @@ MTL::BlendOperation MetalUtil::translateBlendOperation(BlendOp op)
{
switch (op)
{
- case BlendOp::Add:
- return MTL::BlendOperationAdd;
- case BlendOp::Subtract:
- return MTL::BlendOperationSubtract;
- case BlendOp::ReverseSubtract:
- return MTL::BlendOperationReverseSubtract;
- case BlendOp::Min:
- return MTL::BlendOperationMin;
- case BlendOp::Max:
- return MTL::BlendOperationMax;
- default:
- return MTL::BlendOperation(0);
+ case BlendOp::Add: return MTL::BlendOperationAdd;
+ case BlendOp::Subtract: return MTL::BlendOperationSubtract;
+ case BlendOp::ReverseSubtract: return MTL::BlendOperationReverseSubtract;
+ case BlendOp::Min: return MTL::BlendOperationMin;
+ case BlendOp::Max: return MTL::BlendOperationMax;
+ default: return MTL::BlendOperation(0);
}
}
@@ -428,12 +359,9 @@ MTL::Winding MetalUtil::translateWinding(FrontFaceMode mode)
{
switch (mode)
{
- case FrontFaceMode::CounterClockwise:
- return MTL::WindingCounterClockwise;
- case FrontFaceMode::Clockwise:
- return MTL::WindingClockwise;
- default:
- return MTL::Winding(0);
+ case FrontFaceMode::CounterClockwise: return MTL::WindingCounterClockwise;
+ case FrontFaceMode::Clockwise: return MTL::WindingClockwise;
+ default: return MTL::Winding(0);
}
}
@@ -441,14 +369,10 @@ MTL::CullMode MetalUtil::translateCullMode(CullMode mode)
{
switch (mode)
{
- case CullMode::None:
- return MTL::CullModeNone;
- case CullMode::Front:
- return MTL::CullModeFront;
- case CullMode::Back:
- return MTL::CullModeBack;
- default:
- return MTL::CullMode(0);
+ case CullMode::None: return MTL::CullModeNone;
+ case CullMode::Front: return MTL::CullModeFront;
+ case CullMode::Back: return MTL::CullModeBack;
+ default: return MTL::CullMode(0);
}
}
@@ -456,12 +380,9 @@ MTL::TriangleFillMode MetalUtil::translateTriangleFillMode(FillMode mode)
{
switch (mode)
{
- case FillMode::Solid:
- return MTL::TriangleFillModeFill;
- case FillMode::Wireframe:
- return MTL::TriangleFillModeLines;
- default:
- return MTL::TriangleFillMode(0);
+ case FillMode::Solid: return MTL::TriangleFillModeFill;
+ case FillMode::Wireframe: return MTL::TriangleFillModeLines;
+ default: return MTL::TriangleFillMode(0);
}
}
diff --git a/tools/gfx/metal/metal-util.h b/tools/gfx/metal/metal-util.h
index 279f0c67e..bcf988c3b 100644
--- a/tools/gfx/metal/metal-util.h
+++ b/tools/gfx/metal/metal-util.h
@@ -5,20 +5,28 @@
#include "metal-api.h"
#include "slang-gfx.h"
-namespace gfx {
+namespace gfx
+{
// Utility functions for Metal
-struct MetalUtil
+struct MetalUtil
{
- static NS::SharedPtr<NS::String> createString(const char* str, NS::StringEncoding encoding = NS::UTF8StringEncoding)
+ static NS::SharedPtr<NS::String> createString(
+ const char* str,
+ NS::StringEncoding encoding = NS::UTF8StringEncoding)
{
- NS::SharedPtr<NS::String> nsString = NS::TransferPtr(NS::String::alloc()->init(str, encoding));
+ NS::SharedPtr<NS::String> nsString =
+ NS::TransferPtr(NS::String::alloc()->init(str, encoding));
return nsString;
}
- static NS::SharedPtr<NS::String> createStringView(void* bytes, size_t len, NS::StringEncoding encoding = NS::UTF8StringEncoding)
+ static NS::SharedPtr<NS::String> createStringView(
+ void* bytes,
+ size_t len,
+ NS::StringEncoding encoding = NS::UTF8StringEncoding)
{
- NS::SharedPtr<NS::String> nsString = NS::TransferPtr(NS::String::alloc()->init(bytes, len, encoding, false));
+ NS::SharedPtr<NS::String> nsString =
+ NS::TransferPtr(NS::String::alloc()->init(bytes, len, encoding, false));
return nsString;
}
@@ -31,7 +39,7 @@ struct MetalUtil
static MTL::SamplerMinMagFilter translateSamplerMinMagFilter(TextureFilteringMode mode);
static MTL::SamplerMipFilter translateSamplerMipFilter(TextureFilteringMode mode);
static MTL::SamplerAddressMode translateSamplerAddressMode(TextureAddressingMode mode);
- static MTL::CompareFunction translateCompareFunction(ComparisonFunc func);
+ static MTL::CompareFunction translateCompareFunction(ComparisonFunc func);
static MTL::StencilOperation translateStencilOperation(StencilOp op);
static MTL::VertexStepFunction translateVertexStepFunction(InputSlotClass slotClass);
@@ -46,7 +54,6 @@ struct MetalUtil
static MTL::Winding translateWinding(FrontFaceMode mode);
static MTL::CullMode translateCullMode(CullMode mode);
static MTL::TriangleFillMode translateTriangleFillMode(FillMode mode);
-
};
struct ScopedAutoreleasePool
diff --git a/tools/gfx/metal/metal-vertex-layout.cpp b/tools/gfx/metal/metal-vertex-layout.cpp
index 686f3ad0c..722d5396d 100644
--- a/tools/gfx/metal/metal-vertex-layout.cpp
+++ b/tools/gfx/metal/metal-vertex-layout.cpp
@@ -1,5 +1,6 @@
// metal-vertex-layout.cpp
#include "metal-vertex-layout.h"
+
#include "metal-util.h"
namespace gfx
@@ -14,7 +15,8 @@ Result InputLayoutImpl::init(const IInputLayout::Desc& desc)
{
for (Index i = 0; i < desc.inputElementCount; i++)
{
- if (MetalUtil::translateVertexFormat(desc.inputElements[i].format) == MTL::VertexFormatInvalid)
+ if (MetalUtil::translateVertexFormat(desc.inputElements[i].format) ==
+ MTL::VertexFormatInvalid)
{
return SLANG_E_INVALID_ARG;
}
@@ -27,9 +29,11 @@ Result InputLayoutImpl::init(const IInputLayout::Desc& desc)
return SLANG_OK;
}
-NS::SharedPtr<MTL::VertexDescriptor> InputLayoutImpl::createVertexDescriptor(NS::UInteger vertexBufferIndexOffset)
+NS::SharedPtr<MTL::VertexDescriptor> InputLayoutImpl::createVertexDescriptor(
+ NS::UInteger vertexBufferIndexOffset)
{
- NS::SharedPtr<MTL::VertexDescriptor> vertexDescriptor = NS::TransferPtr(MTL::VertexDescriptor::alloc()->init());
+ NS::SharedPtr<MTL::VertexDescriptor> vertexDescriptor =
+ NS::TransferPtr(MTL::VertexDescriptor::alloc()->init());
for (Index i = 0; i < m_inputElements.getCount(); i++)
{
@@ -44,9 +48,13 @@ NS::SharedPtr<MTL::VertexDescriptor> InputLayoutImpl::createVertexDescriptor(NS:
for (Index i = 0; i < m_vertexStreams.getCount(); i++)
{
const auto& vertexStream = m_vertexStreams[i];
- MTL::VertexBufferLayoutDescriptor* desc = vertexDescriptor->layouts()->object(i + vertexBufferIndexOffset);
+ MTL::VertexBufferLayoutDescriptor* desc =
+ vertexDescriptor->layouts()->object(i + vertexBufferIndexOffset);
desc->setStepFunction(MetalUtil::translateVertexStepFunction(vertexStream.slotClass));
- desc->setStepRate(vertexStream.slotClass == InputSlotClass::PerVertex ? 1 : vertexStream.instanceDataStepRate);
+ desc->setStepRate(
+ vertexStream.slotClass == InputSlotClass::PerVertex
+ ? 1
+ : vertexStream.instanceDataStepRate);
desc->setStride(vertexStream.stride);
}
diff --git a/tools/gfx/metal/metal-vertex-layout.h b/tools/gfx/metal/metal-vertex-layout.h
index 5cfdf3dc6..26af7f496 100644
--- a/tools/gfx/metal/metal-vertex-layout.h
+++ b/tools/gfx/metal/metal-vertex-layout.h
@@ -18,7 +18,8 @@ public:
List<VertexStreamDesc> m_vertexStreams;
Result init(const IInputLayout::Desc& desc);
- NS::SharedPtr<MTL::VertexDescriptor> createVertexDescriptor(NS::UInteger vertexBufferIndexOffset);
+ NS::SharedPtr<MTL::VertexDescriptor> createVertexDescriptor(
+ NS::UInteger vertexBufferIndexOffset);
};
} // namespace metal
diff --git a/tools/gfx/mutable-shader-object.h b/tools/gfx/mutable-shader-object.h
index 1864be158..420ba08fe 100644
--- a/tools/gfx/mutable-shader-object.h
+++ b/tools/gfx/mutable-shader-object.h
@@ -1,390 +1,392 @@
#pragma once
-#include "slang-gfx.h"
#include "core/slang-basic.h"
#include "core/slang-com-object.h"
#include "renderer-shared.h"
+#include "slang-gfx.h"
namespace gfx
{
- class ShaderObjectLayoutBase;
-
- template<typename T>
- class VersionedObjectPool
- {
- public:
- struct ObjectVersion
- {
- Slang::RefPtr<T> object;
- Slang::RefPtr<TransientResourceHeapBase> transientHeap;
- uint64_t transientHeapVersion;
- bool canRecycle()
- {
- return (transientHeap->getVersion() != transientHeapVersion);
- }
- };
- Slang::List<ObjectVersion> objects;
- SlangInt lastAllocationIndex = -1;
- ObjectVersion& allocate(TransientResourceHeapBase* currentTransientHeap)
- {
- for (SlangInt i = 0; i < objects.getCount(); i++)
- {
- auto& object = objects[i];
- if (object.canRecycle())
- {
- object.transientHeap = currentTransientHeap;
- object.transientHeapVersion = currentTransientHeap->getVersion();
- lastAllocationIndex = i;
- return object;
- }
- }
- ObjectVersion v;
- v.transientHeap = currentTransientHeap;
- v.transientHeapVersion = currentTransientHeap->getVersion();
- objects.add(v);
- lastAllocationIndex = objects.getCount() - 1;
- return objects.getLast();
- }
- ObjectVersion& getLastAllocation() { return objects[lastAllocationIndex]; }
- };
+class ShaderObjectLayoutBase;
- class MutableShaderObjectData
+template<typename T>
+class VersionedObjectPool
+{
+public:
+ struct ObjectVersion
{
- public:
- // Any "ordinary" / uniform data for this object
- Slang::List<char> m_ordinaryData;
-
- bool m_dirty = true;
-
- Slang::Index getCount() { return m_ordinaryData.getCount(); }
- void setCount(Slang::Index count) { m_ordinaryData.setCount(count); }
- char* getBuffer() { return m_ordinaryData.getBuffer(); }
- void markDirty() { m_dirty = true; }
-
- // We don't actually create any GPU buffers here, since they will be handled
- // by the immutable shader objects once the user calls `getCurrentVersion`.
- ResourceViewBase* getResourceView(
- RendererBase* device,
- slang::TypeLayoutReflection* elementLayout,
- slang::BindingType bindingType)
- {
- return nullptr;
- }
+ Slang::RefPtr<T> object;
+ Slang::RefPtr<TransientResourceHeapBase> transientHeap;
+ uint64_t transientHeapVersion;
+ bool canRecycle() { return (transientHeap->getVersion() != transientHeapVersion); }
};
-
- template<typename TShaderObject, typename TShaderObjectLayoutImpl>
- class MutableShaderObject : public ShaderObjectBaseImpl<
- TShaderObject,
- TShaderObjectLayoutImpl,
- MutableShaderObjectData>
+ Slang::List<ObjectVersion> objects;
+ SlangInt lastAllocationIndex = -1;
+ ObjectVersion& allocate(TransientResourceHeapBase* currentTransientHeap)
{
- typedef ShaderObjectBaseImpl<
- TShaderObject,
- TShaderObjectLayoutImpl,
- MutableShaderObjectData> Super;
- protected:
- Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<ResourceViewBase>> m_resources;
- Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<SamplerStateBase>> m_samplers;
- Slang::OrderedHashSet<ShaderOffset> m_objectOffsets;
- VersionedObjectPool<ShaderObjectBase> m_shaderObjectVersions;
- bool m_dirty = true;
- bool isDirty()
+ for (SlangInt i = 0; i < objects.getCount(); i++)
{
- if (m_dirty) return true;
- if (this->m_data.m_dirty) return true;
- for (auto& object : this->m_objects)
+ auto& object = objects[i];
+ if (object.canRecycle())
{
- if (object && object->isDirty())
- return true;
+ object.transientHeap = currentTransientHeap;
+ object.transientHeapVersion = currentTransientHeap->getVersion();
+ lastAllocationIndex = i;
+ return object;
}
- return false;
- }
-
- void markDirty()
- {
- m_dirty = true;
- }
- public:
- Result init(RendererBase* device, ShaderObjectLayoutBase* layout)
- {
- this->m_device = device;
- auto layoutImpl = static_cast<TShaderObjectLayoutImpl*>(layout);
- this->m_layout = layoutImpl;
- Slang::Index subObjectCount = layoutImpl->getSubObjectCount();
- this->m_objects.setCount(subObjectCount);
- auto dataSize = layoutImpl->getElementTypeLayout()->getSize();
- assert(dataSize >= 0);
- this->m_data.setCount(dataSize);
- memset(this->m_data.getBuffer(), 0, dataSize);
- return SLANG_OK;
- }
- public:
- virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override
- {
- return this->m_data.getBuffer();
- }
- virtual SLANG_NO_THROW size_t SLANG_MCALL getSize() override
- {
- return this->m_data.getCount();
- }
- virtual SLANG_NO_THROW Result SLANG_MCALL setData(ShaderOffset const& offset, void const* data, size_t size) override
- {
- if (!size) return SLANG_OK;
- if (SlangInt(offset.uniformOffset + size) > this->m_data.getCount())
- this->m_data.setCount(offset.uniformOffset + size);
- memcpy(this->m_data.getBuffer() + offset.uniformOffset, data, size);
- this->m_data.markDirty();
- markDirty();
- return SLANG_OK;
}
+ ObjectVersion v;
+ v.transientHeap = currentTransientHeap;
+ v.transientHeapVersion = currentTransientHeap->getVersion();
+ objects.add(v);
+ lastAllocationIndex = objects.getCount() - 1;
+ return objects.getLast();
+ }
+ ObjectVersion& getLastAllocation() { return objects[lastAllocationIndex]; }
+};
+
+class MutableShaderObjectData
+{
+public:
+ // Any "ordinary" / uniform data for this object
+ Slang::List<char> m_ordinaryData;
+
+ bool m_dirty = true;
+
+ Slang::Index getCount() { return m_ordinaryData.getCount(); }
+ void setCount(Slang::Index count) { m_ordinaryData.setCount(count); }
+ char* getBuffer() { return m_ordinaryData.getBuffer(); }
+ void markDirty() { m_dirty = true; }
+
+ // We don't actually create any GPU buffers here, since they will be handled
+ // by the immutable shader objects once the user calls `getCurrentVersion`.
+ ResourceViewBase* getResourceView(
+ RendererBase* device,
+ slang::TypeLayoutReflection* elementLayout,
+ slang::BindingType bindingType)
+ {
+ return nullptr;
+ }
+};
- virtual SLANG_NO_THROW Result SLANG_MCALL
- setObject(ShaderOffset const& offset, IShaderObject* object) override
+template<typename TShaderObject, typename TShaderObjectLayoutImpl>
+class MutableShaderObject
+ : public ShaderObjectBaseImpl<TShaderObject, TShaderObjectLayoutImpl, MutableShaderObjectData>
+{
+ typedef ShaderObjectBaseImpl<TShaderObject, TShaderObjectLayoutImpl, MutableShaderObjectData>
+ Super;
+
+protected:
+ Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<ResourceViewBase>> m_resources;
+ Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<SamplerStateBase>> m_samplers;
+ Slang::OrderedHashSet<ShaderOffset> m_objectOffsets;
+ VersionedObjectPool<ShaderObjectBase> m_shaderObjectVersions;
+ bool m_dirty = true;
+ bool isDirty()
+ {
+ if (m_dirty)
+ return true;
+ if (this->m_data.m_dirty)
+ return true;
+ for (auto& object : this->m_objects)
{
- Super::setObject(offset, object);
- m_objectOffsets.add(offset);
- markDirty();
- return SLANG_OK;
+ if (object && object->isDirty())
+ return true;
}
+ return false;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL setResource(ShaderOffset const& offset, IResourceView* resourceView) override
- {
- m_resources[offset] = static_cast<ResourceViewBase*>(resourceView);
- markDirty();
- return SLANG_OK;
- }
+ void markDirty() { m_dirty = true; }
- virtual SLANG_NO_THROW Result SLANG_MCALL setSampler(ShaderOffset const& offset, ISamplerState* sampler) override
- {
- m_samplers[offset] = static_cast<SamplerStateBase*>(sampler);
- markDirty();
+public:
+ Result init(RendererBase* device, ShaderObjectLayoutBase* layout)
+ {
+ this->m_device = device;
+ auto layoutImpl = static_cast<TShaderObjectLayoutImpl*>(layout);
+ this->m_layout = layoutImpl;
+ Slang::Index subObjectCount = layoutImpl->getSubObjectCount();
+ this->m_objects.setCount(subObjectCount);
+ auto dataSize = layoutImpl->getElementTypeLayout()->getSize();
+ assert(dataSize >= 0);
+ this->m_data.setCount(dataSize);
+ memset(this->m_data.getBuffer(), 0, dataSize);
+ return SLANG_OK;
+ }
+
+public:
+ virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override
+ {
+ return this->m_data.getBuffer();
+ }
+ virtual SLANG_NO_THROW size_t SLANG_MCALL getSize() override { return this->m_data.getCount(); }
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setData(ShaderOffset const& offset, void const* data, size_t size) override
+ {
+ if (!size)
return SLANG_OK;
- }
+ if (SlangInt(offset.uniformOffset + size) > this->m_data.getCount())
+ this->m_data.setCount(offset.uniformOffset + size);
+ memcpy(this->m_data.getBuffer() + offset.uniformOffset, data, size);
+ this->m_data.markDirty();
+ markDirty();
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setObject(ShaderOffset const& offset, IShaderObject* object) override
+ {
+ Super::setObject(offset, object);
+ m_objectOffsets.add(offset);
+ markDirty();
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) override
+ {
+ m_resources[offset] = static_cast<ResourceViewBase*>(resourceView);
+ markDirty();
+ return SLANG_OK;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) override
+ {
+ m_samplers[offset] = static_cast<SamplerStateBase*>(sampler);
+ markDirty();
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) override
+ {
+ m_samplers[offset] = static_cast<SamplerStateBase*>(sampler);
+ m_resources[offset] = static_cast<ResourceViewBase*>(textureView);
+ markDirty();
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getCurrentVersion(ITransientResourceHeap* transientHeap, IShaderObject** outObject) override
+ {
+ if (!isDirty())
{
- m_samplers[offset] = static_cast<SamplerStateBase*>(sampler);
- m_resources[offset] = static_cast<ResourceViewBase*>(textureView);
- markDirty();
+ returnComPtr(outObject, getLastAllocatedShaderObject());
return SLANG_OK;
}
- virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentVersion(
- ITransientResourceHeap* transientHeap, IShaderObject** outObject) override
- {
- if (!isDirty())
- {
- returnComPtr(outObject, getLastAllocatedShaderObject());
- return SLANG_OK;
- }
-
- Slang::RefPtr<ShaderObjectBase> object =
- allocateShaderObject(static_cast<TransientResourceHeapBase*>(transientHeap));
- SLANG_RETURN_ON_FAIL(object->setData(ShaderOffset(), this->m_data.getBuffer(), this->m_data.getCount()));
- for (auto res : m_resources)
- SLANG_RETURN_ON_FAIL(object->setResource(res.key, res.value));
- for (auto sampler : m_samplers)
- SLANG_RETURN_ON_FAIL(object->setSampler(sampler.key, sampler.value));
- for (auto offset : m_objectOffsets)
- {
- if (offset.bindingRangeIndex < 0)
- return SLANG_E_INVALID_ARG;
- auto layout = this->getLayout();
- if (offset.bindingRangeIndex >= layout->getBindingRangeCount())
- return SLANG_E_INVALID_ARG;
- auto bindingRange = layout->getBindingRange(offset.bindingRangeIndex);
-
- auto subObject = this->m_objects[bindingRange.subObjectIndex + offset.bindingArrayIndex];
- if (subObject)
- {
- ComPtr<IShaderObject> subObjectVersion;
- SLANG_RETURN_ON_FAIL(subObject->getCurrentVersion(transientHeap, subObjectVersion.writeRef()));
- SLANG_RETURN_ON_FAIL(object->setObject(offset, subObjectVersion));
- }
- }
- m_dirty = false;
- this->m_data.m_dirty = false;
- returnComPtr(outObject, object);
- return SLANG_OK;
- }
- public:
- Slang::RefPtr<ShaderObjectBase> allocateShaderObject(TransientResourceHeapBase* transientHeap)
- {
- auto& version = m_shaderObjectVersions.allocate(transientHeap);
- if (!version.object)
+ Slang::RefPtr<ShaderObjectBase> object =
+ allocateShaderObject(static_cast<TransientResourceHeapBase*>(transientHeap));
+ SLANG_RETURN_ON_FAIL(
+ object->setData(ShaderOffset(), this->m_data.getBuffer(), this->m_data.getCount()));
+ for (auto res : m_resources)
+ SLANG_RETURN_ON_FAIL(object->setResource(res.key, res.value));
+ for (auto sampler : m_samplers)
+ SLANG_RETURN_ON_FAIL(object->setSampler(sampler.key, sampler.value));
+ for (auto offset : m_objectOffsets)
+ {
+ if (offset.bindingRangeIndex < 0)
+ return SLANG_E_INVALID_ARG;
+ auto layout = this->getLayout();
+ if (offset.bindingRangeIndex >= layout->getBindingRangeCount())
+ return SLANG_E_INVALID_ARG;
+ auto bindingRange = layout->getBindingRange(offset.bindingRangeIndex);
+
+ auto subObject =
+ this->m_objects[bindingRange.subObjectIndex + offset.bindingArrayIndex];
+ if (subObject)
{
- ComPtr<IShaderObject> shaderObject;
- SLANG_RETURN_NULL_ON_FAIL(this->m_device->createShaderObject(this->m_layout, shaderObject.writeRef()));
- version.object = static_cast<ShaderObjectBase*>(shaderObject.get());
+ ComPtr<IShaderObject> subObjectVersion;
+ SLANG_RETURN_ON_FAIL(
+ subObject->getCurrentVersion(transientHeap, subObjectVersion.writeRef()));
+ SLANG_RETURN_ON_FAIL(object->setObject(offset, subObjectVersion));
}
- return version.object;
- }
- Slang::RefPtr<ShaderObjectBase> getLastAllocatedShaderObject()
- {
- return m_shaderObjectVersions.getLastAllocation().object;
}
- };
+ m_dirty = false;
+ this->m_data.m_dirty = false;
+ returnComPtr(outObject, object);
+ return SLANG_OK;
+ }
- // A proxy shader object to hold mutable shader parameters for global scope and entry-points.
- class MutableRootShaderObject : public ShaderObjectBase
+public:
+ Slang::RefPtr<ShaderObjectBase> allocateShaderObject(TransientResourceHeapBase* transientHeap)
{
- public:
- Slang::List<uint8_t> m_data;
- Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<ResourceViewBase>> m_resources;
- Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<SamplerStateBase>> m_samplers;
- Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<ShaderObjectBase>> m_objects;
- Slang::OrderedDictionary<ShaderOffset, Slang::List<slang::SpecializationArg>> m_specializationArgs;
- Slang::List<Slang::RefPtr<MutableRootShaderObject>> m_entryPoints;
- Slang::RefPtr<BufferResource> m_constantBufferOverride;
- slang::TypeLayoutReflection* m_elementTypeLayout;
-
- MutableRootShaderObject(RendererBase* device, slang::TypeLayoutReflection* entryPointLayout)
- {
- this->m_device = device;
- m_elementTypeLayout = entryPointLayout;
- m_data.setCount(entryPointLayout->getSize());
- memset(m_data.begin(), 0, m_data.getCount());
- }
-
- MutableRootShaderObject(RendererBase* device, Slang::RefPtr<ShaderProgramBase> program)
+ auto& version = m_shaderObjectVersions.allocate(transientHeap);
+ if (!version.object)
{
- this->m_device = device;
- auto programLayout = program->slangGlobalScope->getLayout();
- SlangInt entryPointCount = programLayout->getEntryPointCount();
- for (SlangInt e = 0; e < entryPointCount; ++e)
- {
- auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
- Slang::RefPtr<MutableRootShaderObject> entryPointObject =
- new MutableRootShaderObject(device, slangEntryPoint->getTypeLayout()->getElementTypeLayout());
-
- m_entryPoints.add(entryPointObject);
- }
- m_data.setCount(programLayout->getGlobalParamsTypeLayout()->getSize());
- memset(m_data.begin(), 0, m_data.getCount());
- m_elementTypeLayout = programLayout->getGlobalParamsTypeLayout();
+ ComPtr<IShaderObject> shaderObject;
+ SLANG_RETURN_NULL_ON_FAIL(
+ this->m_device->createShaderObject(this->m_layout, shaderObject.writeRef()));
+ version.object = static_cast<ShaderObjectBase*>(shaderObject.get());
}
+ return version.object;
+ }
+ Slang::RefPtr<ShaderObjectBase> getLastAllocatedShaderObject()
+ {
+ return m_shaderObjectVersions.getLastAllocation().object;
+ }
+};
+// A proxy shader object to hold mutable shader parameters for global scope and entry-points.
+class MutableRootShaderObject : public ShaderObjectBase
+{
+public:
+ Slang::List<uint8_t> m_data;
+ Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<ResourceViewBase>> m_resources;
+ Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<SamplerStateBase>> m_samplers;
+ Slang::OrderedDictionary<ShaderOffset, Slang::RefPtr<ShaderObjectBase>> m_objects;
+ Slang::OrderedDictionary<ShaderOffset, Slang::List<slang::SpecializationArg>>
+ m_specializationArgs;
+ Slang::List<Slang::RefPtr<MutableRootShaderObject>> m_entryPoints;
+ Slang::RefPtr<BufferResource> m_constantBufferOverride;
+ slang::TypeLayoutReflection* m_elementTypeLayout;
+
+ MutableRootShaderObject(RendererBase* device, slang::TypeLayoutReflection* entryPointLayout)
+ {
+ this->m_device = device;
+ m_elementTypeLayout = entryPointLayout;
+ m_data.setCount(entryPointLayout->getSize());
+ memset(m_data.begin(), 0, m_data.getCount());
+ }
- virtual SLANG_NO_THROW slang::TypeLayoutReflection* SLANG_MCALL
- getElementTypeLayout() override
+ MutableRootShaderObject(RendererBase* device, Slang::RefPtr<ShaderProgramBase> program)
+ {
+ this->m_device = device;
+ auto programLayout = program->slangGlobalScope->getLayout();
+ SlangInt entryPointCount = programLayout->getEntryPointCount();
+ for (SlangInt e = 0; e < entryPointCount; ++e)
{
- return m_elementTypeLayout;
- }
+ auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
+ Slang::RefPtr<MutableRootShaderObject> entryPointObject = new MutableRootShaderObject(
+ device,
+ slangEntryPoint->getTypeLayout()->getElementTypeLayout());
- virtual SLANG_NO_THROW ShaderObjectContainerType SLANG_MCALL getContainerType() override
- {
- return ShaderObjectContainerType::None;
+ m_entryPoints.add(entryPointObject);
}
+ m_data.setCount(programLayout->getGlobalParamsTypeLayout()->getSize());
+ memset(m_data.begin(), 0, m_data.getCount());
+ m_elementTypeLayout = programLayout->getGlobalParamsTypeLayout();
+ }
- virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override
- {
- return (GfxCount)m_entryPoints.getCount();
- }
- virtual SLANG_NO_THROW Result SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** entryPoint) override
- {
- returnComPtr(entryPoint, m_entryPoints[index]);
- return SLANG_OK;
- }
+ virtual SLANG_NO_THROW slang::TypeLayoutReflection* SLANG_MCALL getElementTypeLayout() override
+ {
+ return m_elementTypeLayout;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& offset, void const* data, Size size) override
- {
- auto newSize = Slang::Index(size + offset.uniformOffset);
- if (newSize > m_data.getCount())
- m_data.setCount((Slang::Index)newSize);
- memcpy(m_data.begin() + offset.uniformOffset, data, size);
- return SLANG_OK;
- }
+ virtual SLANG_NO_THROW ShaderObjectContainerType SLANG_MCALL getContainerType() override
+ {
+ return ShaderObjectContainerType::None;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL
- getObject(ShaderOffset const& offset, IShaderObject** object) override
- {
- *object = nullptr;
+ virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override
+ {
+ return (GfxCount)m_entryPoints.getCount();
+ }
- Slang::RefPtr<ShaderObjectBase> subObject;
- if (m_objects.tryGetValue(offset, subObject))
- {
- returnComPtr(object, subObject);
- }
- return SLANG_OK;
- }
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getEntryPoint(GfxIndex index, IShaderObject** entryPoint) override
+ {
+ returnComPtr(entryPoint, m_entryPoints[index]);
+ return SLANG_OK;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL
- setObject(ShaderOffset const& offset, IShaderObject* object) override
- {
- m_objects[offset] = static_cast<ShaderObjectBase*>(object);
- return SLANG_OK;
- }
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setData(ShaderOffset const& offset, void const* data, Size size) override
+ {
+ auto newSize = Slang::Index(size + offset.uniformOffset);
+ if (newSize > m_data.getCount())
+ m_data.setCount((Slang::Index)newSize);
+ memcpy(m_data.begin() + offset.uniformOffset, data, size);
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getObject(ShaderOffset const& offset, IShaderObject** object) override
+ {
+ *object = nullptr;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView) override
+ Slang::RefPtr<ShaderObjectBase> subObject;
+ if (m_objects.tryGetValue(offset, subObject))
{
- m_resources[offset] = static_cast<ResourceViewBase*>(resourceView);
- return SLANG_OK;
+ returnComPtr(object, subObject);
}
+ return SLANG_OK;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL
- setSampler(ShaderOffset const& offset, ISamplerState* sampler) override
- {
- m_samplers[offset] = static_cast<SamplerStateBase*>(sampler);
- return SLANG_OK;
- }
- virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) override
- {
- m_resources[offset] = static_cast<ResourceViewBase*>(textureView);
- m_samplers[offset] = static_cast<SamplerStateBase*>(sampler);
- return SLANG_OK;
- }
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setObject(ShaderOffset const& offset, IShaderObject* object) override
+ {
+ m_objects[offset] = static_cast<ShaderObjectBase*>(object);
+ return SLANG_OK;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL setSpecializationArgs(
- ShaderOffset const& offset,
- const slang::SpecializationArg* args,
- GfxCount count) override
- {
- Slang::List<slang::SpecializationArg> specArgs;
- specArgs.addRange(args, count);
- m_specializationArgs[offset] = specArgs;
- return SLANG_OK;
- }
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) override
+ {
+ m_resources[offset] = static_cast<ResourceViewBase*>(resourceView);
+ return SLANG_OK;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentVersion(
- ITransientResourceHeap* transientHeap, IShaderObject** outObject) override
- {
- return SLANG_FAIL;
- }
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) override
+ {
+ m_samplers[offset] = static_cast<SamplerStateBase*>(sampler);
+ return SLANG_OK;
+ }
+ virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) override
+ {
+ m_resources[offset] = static_cast<ResourceViewBase*>(textureView);
+ m_samplers[offset] = static_cast<SamplerStateBase*>(sampler);
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL setSpecializationArgs(
+ ShaderOffset const& offset,
+ const slang::SpecializationArg* args,
+ GfxCount count) override
+ {
+ Slang::List<slang::SpecializationArg> specArgs;
+ specArgs.addRange(args, count);
+ m_specializationArgs[offset] = specArgs;
+ return SLANG_OK;
+ }
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getCurrentVersion(ITransientResourceHeap* transientHeap, IShaderObject** outObject) override
+ {
+ return SLANG_FAIL;
+ }
- virtual SLANG_NO_THROW Result SLANG_MCALL copyFrom(IShaderObject* other, ITransientResourceHeap* transientHeap) override
- {
- auto otherObject = static_cast<MutableRootShaderObject*>(other);
- *this = *otherObject;
- return SLANG_OK;
- }
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ copyFrom(IShaderObject* other, ITransientResourceHeap* transientHeap) override
+ {
+ auto otherObject = static_cast<MutableRootShaderObject*>(other);
+ *this = *otherObject;
+ return SLANG_OK;
+ }
- virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override
- {
- return m_data.begin();
- }
+ virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override { return m_data.begin(); }
- virtual SLANG_NO_THROW Size SLANG_MCALL getSize() override
- {
- return (Size)m_data.getCount();
- }
+ virtual SLANG_NO_THROW Size SLANG_MCALL getSize() override { return (Size)m_data.getCount(); }
- virtual SLANG_NO_THROW Result SLANG_MCALL
- setConstantBufferOverride(IBufferResource* constantBuffer) override
- {
- m_constantBufferOverride = static_cast<BufferResource*>(constantBuffer);
- return SLANG_OK;
- }
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setConstantBufferOverride(IBufferResource* constantBuffer) override
+ {
+ m_constantBufferOverride = static_cast<BufferResource*>(constantBuffer);
+ return SLANG_OK;
+ }
- virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) override
- {
- SLANG_UNUSED(args);
- return SLANG_OK;
- }
- };
+ virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) override
+ {
+ SLANG_UNUSED(args);
+ return SLANG_OK;
+ }
+};
-}
+} // namespace gfx
diff --git a/tools/gfx/nvapi/nvapi-include.h b/tools/gfx/nvapi/nvapi-include.h
index 513977048..45a8ca77b 100644
--- a/tools/gfx/nvapi/nvapi-include.h
+++ b/tools/gfx/nvapi/nvapi-include.h
@@ -6,20 +6,19 @@
#ifdef GFX_NVAPI
// On windows if we include NVAPI, we must include windows.h first
-# ifdef _WIN32
-# pragma push_macro("WIN32_LEAN_AND_MEAN")
-# pragma push_macro("NOMINMAX")
-# undef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-# undef NOMINMAX
-# define NOMINMAX
-# include <windows.h>
-# pragma pop_macro("NOMINMAX")
-# pragma pop_macro("WIN32_LEAN_AND_MEAN")
-# endif
+#ifdef _WIN32
+#pragma push_macro("WIN32_LEAN_AND_MEAN")
+#pragma push_macro("NOMINMAX")
+#undef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#undef NOMINMAX
+#define NOMINMAX
+#include <windows.h>
+#pragma pop_macro("NOMINMAX")
+#pragma pop_macro("WIN32_LEAN_AND_MEAN")
+#endif
-# include <nvapi.h>
-# include <nvShaderExtnEnums.h>
+#include <nvShaderExtnEnums.h>
+#include <nvapi.h>
#endif
-
diff --git a/tools/gfx/nvapi/nvapi-util.cpp b/tools/gfx/nvapi/nvapi-util.cpp
index 63bcc65fc..efb053c07 100644
--- a/tools/gfx/nvapi/nvapi-util.cpp
+++ b/tools/gfx/nvapi/nvapi-util.cpp
@@ -2,11 +2,12 @@
#include "nvapi-include.h"
-namespace gfx {
+namespace gfx
+{
static SlangResult g_initStatus = SLANG_E_UNINITIALIZED;
-/* static */SlangResult NVAPIUtil::initialize()
+/* static */ SlangResult NVAPIUtil::initialize()
{
#ifdef GFX_NVAPI
if (g_initStatus == SLANG_E_UNINITIALIZED)
@@ -22,9 +23,9 @@ static SlangResult g_initStatus = SLANG_E_UNINITIALIZED;
return g_initStatus;
}
-/* static */bool NVAPIUtil::isAvailable()
+/* static */ bool NVAPIUtil::isAvailable()
{
return SLANG_SUCCEEDED(g_initStatus);
}
-} // gfx
+} // namespace gfx
diff --git a/tools/gfx/nvapi/nvapi-util.h b/tools/gfx/nvapi/nvapi-util.h
index 0bcab7d36..7715df8c6 100644
--- a/tools/gfx/nvapi/nvapi-util.h
+++ b/tools/gfx/nvapi/nvapi-util.h
@@ -4,16 +4,17 @@
#include "slang-com-helper.h"
#include "slang-com-ptr.h"
-namespace gfx {
+namespace gfx
+{
struct NVAPIUtil
{
- /// Set up NVAPI for use. Must be called before any other function is used.
+ /// Set up NVAPI for use. Must be called before any other function is used.
static SlangResult initialize();
- /// True if the NVAPI is available, can be called even if initialize fails.
- /// If initialize has not been called will return false
+ /// True if the NVAPI is available, can be called even if initialize fails.
+ /// If initialize has not been called will return false
static bool isAvailable();
};
-} // gfx
+} // namespace gfx
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index 4b2acd094..3a1460a5b 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -1,11 +1,9 @@
// render-gl.cpp
#include "render-gl.h"
-#include "../nvapi/nvapi-util.h"
-
#include "../immediate-renderer-base.h"
#include "../mutable-shader-object.h"
-
+#include "../nvapi/nvapi-util.h"
#include "core/slang-basic.h"
#include "core/slang-blob.h"
#include "core/slang-secure-crt.h"
@@ -43,61 +41,62 @@
// We define an "X-macro" for mapping over loadable OpenGL
// extension entry point that we will use, so that we can
// easily write generic code to iterate over them.
-#define MAP_GL_EXTENSION_FUNCS(F) \
- F(glCreateProgram, PFNGLCREATEPROGRAMPROC) \
- F(glCreateShader, PFNGLCREATESHADERPROC) \
- F(glShaderSource, PFNGLSHADERSOURCEPROC) \
- F(glCompileShader, PFNGLCOMPILESHADERPROC) \
- F(glGetShaderiv, PFNGLGETSHADERIVPROC) \
- F(glDeleteShader, PFNGLDELETESHADERPROC) \
- F(glAttachShader, PFNGLATTACHSHADERPROC) \
- F(glLinkProgram, PFNGLLINKPROGRAMPROC) \
- F(glGetProgramiv, PFNGLGETPROGRAMIVPROC) \
- F(glGetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC) \
- F(glDeleteProgram, PFNGLDELETEPROGRAMPROC) \
- F(glGetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC) \
- F(glGenBuffers, PFNGLGENBUFFERSPROC) \
- F(glBindBuffer, PFNGLBINDBUFFERPROC) \
- F(glBufferData, PFNGLBUFFERDATAPROC) \
- F(glCopyBufferSubData, PFNGLCOPYBUFFERSUBDATAPROC) \
- F(glDeleteBuffers, PFNGLDELETEBUFFERSPROC) \
- F(glMapBuffer, PFNGLMAPBUFFERPROC) \
- F(glUnmapBuffer, PFNGLUNMAPBUFFERPROC) \
- F(glUseProgram, PFNGLUSEPROGRAMPROC) \
- F(glBindBufferBase, PFNGLBINDBUFFERBASEPROC) \
- F(glBindBufferRange, PFNGLBINDBUFFERRANGEPROC) \
- F(glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \
- F(glEnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYPROC) \
- F(glDisableVertexAttribArray, PFNGLDISABLEVERTEXATTRIBARRAYPROC) \
- F(glDebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC) \
- F(glDispatchCompute, PFNGLDISPATCHCOMPUTEPROC) \
- F(glActiveTexture, PFNGLACTIVETEXTUREPROC) \
- F(glCreateSamplers, PFNGLCREATESAMPLERSPROC) \
- F(glDeleteSamplers, PFNGLDELETESAMPLERSPROC) \
- F(glBindSampler, PFNGLBINDSAMPLERPROC) \
- F(glTexImage3D, PFNGLTEXIMAGE3DPROC) \
- F(glBindImageTexture, PFNGLBINDIMAGETEXTUREPROC) \
- F(glSamplerParameteri, PFNGLSAMPLERPARAMETERIPROC) \
- F(glGenFramebuffers, PFNGLGENFRAMEBUFFERSPROC) \
- F(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC) \
- F(glBindFramebuffer, PFNGLBINDFRAMEBUFFERPROC) \
- F(glDrawBuffers, PFNGLDRAWBUFFERSPROC) \
- F(glFramebufferTexture2D, PFNGLFRAMEBUFFERTEXTURE2DPROC) \
- F(glFramebufferTextureLayer, PFNGLFRAMEBUFFERTEXTURELAYERPROC) \
- F(glBlitFramebuffer, PFNGLBLITFRAMEBUFFERPROC) \
- F(glCheckFramebufferStatus, PFNGLCHECKFRAMEBUFFERSTATUSPROC) \
- F(glGenVertexArrays, PFNGLGENVERTEXARRAYSPROC) \
- F(glBindVertexArray, PFNGLBINDVERTEXARRAYPROC) \
- F(glDeleteVertexArrays, PFNGLDELETEVERTEXARRAYSPROC) \
- F(glDrawElementsBaseVertex, PFNGLDRAWELEMENTSBASEVERTEXPROC) \
+#define MAP_GL_EXTENSION_FUNCS(F) \
+ F(glCreateProgram, PFNGLCREATEPROGRAMPROC) \
+ F(glCreateShader, PFNGLCREATESHADERPROC) \
+ F(glShaderSource, PFNGLSHADERSOURCEPROC) \
+ F(glCompileShader, PFNGLCOMPILESHADERPROC) \
+ F(glGetShaderiv, PFNGLGETSHADERIVPROC) \
+ F(glDeleteShader, PFNGLDELETESHADERPROC) \
+ F(glAttachShader, PFNGLATTACHSHADERPROC) \
+ F(glLinkProgram, PFNGLLINKPROGRAMPROC) \
+ F(glGetProgramiv, PFNGLGETPROGRAMIVPROC) \
+ F(glGetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC) \
+ F(glDeleteProgram, PFNGLDELETEPROGRAMPROC) \
+ F(glGetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC) \
+ F(glGenBuffers, PFNGLGENBUFFERSPROC) \
+ F(glBindBuffer, PFNGLBINDBUFFERPROC) \
+ F(glBufferData, PFNGLBUFFERDATAPROC) \
+ F(glCopyBufferSubData, PFNGLCOPYBUFFERSUBDATAPROC) \
+ F(glDeleteBuffers, PFNGLDELETEBUFFERSPROC) \
+ F(glMapBuffer, PFNGLMAPBUFFERPROC) \
+ F(glUnmapBuffer, PFNGLUNMAPBUFFERPROC) \
+ F(glUseProgram, PFNGLUSEPROGRAMPROC) \
+ F(glBindBufferBase, PFNGLBINDBUFFERBASEPROC) \
+ F(glBindBufferRange, PFNGLBINDBUFFERRANGEPROC) \
+ F(glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \
+ F(glEnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYPROC) \
+ F(glDisableVertexAttribArray, PFNGLDISABLEVERTEXATTRIBARRAYPROC) \
+ F(glDebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC) \
+ F(glDispatchCompute, PFNGLDISPATCHCOMPUTEPROC) \
+ F(glActiveTexture, PFNGLACTIVETEXTUREPROC) \
+ F(glCreateSamplers, PFNGLCREATESAMPLERSPROC) \
+ F(glDeleteSamplers, PFNGLDELETESAMPLERSPROC) \
+ F(glBindSampler, PFNGLBINDSAMPLERPROC) \
+ F(glTexImage3D, PFNGLTEXIMAGE3DPROC) \
+ F(glBindImageTexture, PFNGLBINDIMAGETEXTUREPROC) \
+ F(glSamplerParameteri, PFNGLSAMPLERPARAMETERIPROC) \
+ F(glGenFramebuffers, PFNGLGENFRAMEBUFFERSPROC) \
+ F(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC) \
+ F(glBindFramebuffer, PFNGLBINDFRAMEBUFFERPROC) \
+ F(glDrawBuffers, PFNGLDRAWBUFFERSPROC) \
+ F(glFramebufferTexture2D, PFNGLFRAMEBUFFERTEXTURE2DPROC) \
+ F(glFramebufferTextureLayer, PFNGLFRAMEBUFFERTEXTURELAYERPROC) \
+ F(glBlitFramebuffer, PFNGLBLITFRAMEBUFFERPROC) \
+ F(glCheckFramebufferStatus, PFNGLCHECKFRAMEBUFFERSTATUSPROC) \
+ F(glGenVertexArrays, PFNGLGENVERTEXARRAYSPROC) \
+ F(glBindVertexArray, PFNGLBINDVERTEXARRAYPROC) \
+ F(glDeleteVertexArrays, PFNGLDELETEVERTEXARRAYSPROC) \
+ F(glDrawElementsBaseVertex, PFNGLDRAWELEMENTSBASEVERTEXPROC) \
/* end */
-#define MAP_WGL_EXTENSION_FUNCS(F) \
+#define MAP_WGL_EXTENSION_FUNCS(F) \
F(wglCreateContextAttribsARB, PFNWGLCREATECONTEXTATTRIBSARBPROC) \
/* end */
using namespace Slang;
-namespace gfx {
+namespace gfx
+{
class GLDevice : public ImmediateRendererBase
{
@@ -106,12 +105,14 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const Desc& desc) override;
virtual void clearFrame(uint32_t mask, bool clearDepth, bool clearStencil) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL createFramebuffer(
- const IFramebuffer::Desc& desc,
- IFramebuffer** outFramebuffer) override;
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
virtual void setFramebuffer(IFramebuffer* frameBuffer) override;
virtual void setStencilReference(uint32_t referenceValue) override;
@@ -124,27 +125,32 @@ public:
const void* initData,
IBufferResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
+ createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView(
- ITextureResource* texture, IResourceView::Desc const& desc, IResourceView** outView) override;
+ ITextureResource* texture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createBufferView(
IBufferResource* buffer,
IBufferResource* counterBuffer,
IResourceView::Desc const& desc,
IResourceView** outView) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL createInputLayout(
- IInputLayout::Desc const& desc,
- IInputLayout** outLayout) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
virtual Result createShaderObjectLayout(
slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) override;
- virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
- virtual Result createMutableShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
- virtual Result createRootShaderObject(IShaderProgram* program, ShaderObjectBase** outObject) override;
+ virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ override;
+ virtual Result createMutableShaderObject(
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject) override;
+ virtual Result createRootShaderObject(IShaderProgram* program, ShaderObjectBase** outObject)
+ override;
virtual void bindRootShaderObject(IShaderObject* shaderObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createProgram(
@@ -152,9 +158,11 @@ public:
IShaderProgram** outProgram,
ISlangBlob** outDiagnosticBlob) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& desc, IPipelineState** outState) override;
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual void copyBuffer(
IBufferResource* dst,
@@ -163,7 +171,11 @@ public:
size_t srcOffset,
size_t size) override;
virtual SLANG_NO_THROW Result SLANG_MCALL readTextureResource(
- ITextureResource* texture, ResourceState state, ISlangBlob** outBlob, size_t* outRowPitch, size_t* outPixelSize) override;
+ ITextureResource* texture,
+ ResourceState state,
+ ISlangBlob** outBlob,
+ size_t* outRowPitch,
+ size_t* outPixelSize) override;
virtual void* map(IBufferResource* buffer, MapFlavor flavor) override;
virtual void unmap(IBufferResource* buffer, size_t offsetWritten, size_t sizeWritten) override;
@@ -174,14 +186,14 @@ public:
GfxCount slotCount,
IBufferResource* const* buffers,
const Offset* offsets) override;
- virtual void setIndexBuffer(
- IBufferResource* buffer, Format indexFormat, Offset offset) override;
+ virtual void setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset)
+ override;
virtual void setViewports(GfxCount count, Viewport const* viewports) override;
virtual void setScissorRects(GfxCount count, ScissorRect const* rects) override;
virtual void setPipelineState(IPipelineState* state) override;
virtual void draw(GfxCount vertexCount, GfxCount startVertex) override;
- virtual void drawIndexed(
- GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex) override;
+ virtual void drawIndexed(GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex)
+ override;
virtual void drawInstanced(
GfxCount vertexCount,
GfxCount instanceCount,
@@ -201,8 +213,8 @@ public:
SLANG_UNUSED(pool);
SLANG_UNUSED(index);
}
- virtual SLANG_NO_THROW Result SLANG_MCALL createQueryPool(
- const IQueryPool::Desc& desc, IQueryPool** pool) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ createQueryPool(const IQueryPool::Desc& desc, IQueryPool** pool) override
{
SLANG_UNUSED(desc);
*pool = nullptr;
@@ -217,7 +229,7 @@ public:
GLDevice();
~GLDevice();
- protected:
+protected:
enum
{
kMaxVertexAttributes = 16,
@@ -226,20 +238,20 @@ public:
};
struct VertexAttributeFormat
{
- GLint componentCount;
- GLenum componentType;
- GLboolean normalized;
+ GLint componentCount;
+ GLenum componentType;
+ GLboolean normalized;
};
struct VertexAttributeDesc
{
- VertexAttributeFormat format;
- GLuint streamIndex;
- GLsizei offset;
+ VertexAttributeFormat format;
+ GLuint streamIndex;
+ GLsizei offset;
};
class InputLayoutImpl : public InputLayoutBase
- {
+ {
public:
VertexAttributeDesc m_attributes[kMaxVertexAttributes];
VertexStreamDesc m_streams[kMaxVertexStreams];
@@ -247,38 +259,36 @@ public:
UInt m_streamCount = 0;
};
- class BufferResourceImpl: public BufferResource
- {
- public:
+ class BufferResourceImpl : public BufferResource
+ {
+ public:
typedef BufferResource Parent;
- BufferResourceImpl(const Desc& desc, WeakSink<GLDevice>* renderer, GLuint id, GLenum target):
- Parent(desc),
- m_renderer(renderer),
- m_handle(id),
- m_target(target),
- m_size(desc.sizeInBytes)
- {}
- ~BufferResourceImpl()
- {
- if (auto renderer = m_renderer->get())
- {
- renderer->glDeleteBuffers(1, &m_handle);
- }
- }
-
- RefPtr<WeakSink<GLDevice>> m_renderer;
- GLuint m_handle;
+ BufferResourceImpl(const Desc& desc, WeakSink<GLDevice>* renderer, GLuint id, GLenum target)
+ : Parent(desc)
+ , m_renderer(renderer)
+ , m_handle(id)
+ , m_target(target)
+ , m_size(desc.sizeInBytes)
+ {
+ }
+ ~BufferResourceImpl()
+ {
+ if (auto renderer = m_renderer->get())
+ {
+ renderer->glDeleteBuffers(1, &m_handle);
+ }
+ }
+
+ RefPtr<WeakSink<GLDevice>> m_renderer;
+ GLuint m_handle;
GLenum m_target;
UInt m_size;
- virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override
- {
- return 0;
- }
+ virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override { return 0; }
virtual SLANG_NO_THROW Result SLANG_MCALL
- map(MemoryRange* rangeToRead, void** outPointer) override
+ map(MemoryRange* rangeToRead, void** outPointer) override
{
SLANG_UNUSED(rangeToRead);
SLANG_UNUSED(outPointer);
@@ -290,16 +300,15 @@ public:
SLANG_UNUSED(writtenRange);
return SLANG_FAIL;
}
- };
+ };
- class TextureResourceImpl: public TextureResource
+ class TextureResourceImpl : public TextureResource
{
- public:
+ public:
typedef TextureResource Parent;
- TextureResourceImpl(const Desc& desc, WeakSink<GLDevice>* renderer):
- Parent(desc),
- m_renderer(renderer)
+ TextureResourceImpl(const Desc& desc, WeakSink<GLDevice>* renderer)
+ : Parent(desc), m_renderer(renderer)
{
m_target = 0;
m_handle = 0;
@@ -311,7 +320,7 @@ public:
{
glDeleteTextures(1, &m_handle);
}
- }
+ }
RefPtr<WeakSink<GLDevice>> m_renderer;
GLenum m_target;
@@ -329,7 +338,8 @@ public:
public:
enum class Type
{
- Texture, Buffer
+ Texture,
+ Buffer
};
Type type;
};
@@ -342,7 +352,8 @@ public:
GLuint m_target;
enum class TextureViewType
{
- Texture, Image
+ Texture,
+ Image
};
TextureViewType textureViewType;
GLint level;
@@ -355,8 +366,8 @@ public:
class BufferViewImpl : public ResourceViewImpl
{
public:
- RefPtr<BufferResourceImpl> m_resource;
- GLuint m_bufferID;
+ RefPtr<BufferResourceImpl> m_resource;
+ GLuint m_bufferID;
};
class FramebufferLayoutImpl : public FramebufferLayoutBase
@@ -379,7 +390,10 @@ public:
bool m_sameClearValues = true;
DepthStencilClearValue m_depthStencilClearValue;
- FramebufferImpl(WeakSink<GLDevice>* renderer) :m_renderer(renderer) {}
+ FramebufferImpl(WeakSink<GLDevice>* renderer)
+ : m_renderer(renderer)
+ {
+ }
~FramebufferImpl()
{
if (auto renderer = m_renderer->get())
@@ -398,7 +412,11 @@ public:
{
auto rtv = renderTargetViews[i].Ptr();
renderer->glFramebufferTexture2D(
- GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + (uint32_t)i, GL_TEXTURE_2D, rtv->m_textureID, 0);
+ GL_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0 + (uint32_t)i,
+ GL_TEXTURE_2D,
+ rtv->m_textureID,
+ 0);
m_drawBuffers.add((GLenum)(GL_COLOR_ATTACHMENT0 + i));
if (rtv->m_resource->getDesc()->optimalClearValue)
{
@@ -444,9 +462,7 @@ public:
}
};
- class SwapchainImpl
- : public ISwapchain
- , public ComObject
+ class SwapchainImpl : public ISwapchain, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -503,7 +519,11 @@ public:
m_renderer->get()->glGenFramebuffers(1, &m_framebuffer);
m_renderer->get()->glBindFramebuffer(GL_READ_FRAMEBUFFER, m_framebuffer);
m_renderer->get()->glFramebufferTexture2D(
- GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_backBuffer, 0);
+ GL_READ_FRAMEBUFFER,
+ GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D,
+ m_backBuffer,
+ 0);
m_images.clear();
for (GfxIndex i = 0; i < m_desc.imageCount; i++)
@@ -545,7 +565,7 @@ public:
}
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override { return m_desc; }
virtual SLANG_NO_THROW Result SLANG_MCALL
- getImage(GfxIndex index, ITextureResource** outResource) override
+ getImage(GfxIndex index, ITextureResource** outResource) override
{
returnComPtr(outResource, m_images[index]);
return SLANG_OK;
@@ -592,10 +612,7 @@ public:
return SLANG_OK;
}
- virtual SLANG_NO_THROW bool SLANG_MCALL isOccluded() override
- {
- return false;
- }
+ virtual SLANG_NO_THROW bool SLANG_MCALL isOccluded() override { return false; }
virtual SLANG_NO_THROW Result SLANG_MCALL setFullScreenMode(bool mode) override
{
return SLANG_FAIL;
@@ -615,30 +632,29 @@ public:
ShortList<RefPtr<TextureResourceImpl>> m_images;
};
- class ShaderProgramImpl : public ShaderProgramBase
- {
- public:
- ShaderProgramImpl(WeakSink<GLDevice>* renderer, GLuint id):
- m_renderer(renderer),
- m_id(id)
- {
- }
- ~ShaderProgramImpl()
- {
- if (auto renderer = m_renderer->get())
- {
- renderer->glDeleteProgram(m_id);
- }
- }
-
- GLuint m_id;
- RefPtr<WeakSink<GLDevice>> m_renderer;
- };
+ class ShaderProgramImpl : public ShaderProgramBase
+ {
+ public:
+ ShaderProgramImpl(WeakSink<GLDevice>* renderer, GLuint id)
+ : m_renderer(renderer), m_id(id)
+ {
+ }
+ ~ShaderProgramImpl()
+ {
+ if (auto renderer = m_renderer->get())
+ {
+ renderer->glDeleteProgram(m_id);
+ }
+ }
+
+ GLuint m_id;
+ RefPtr<WeakSink<GLDevice>> m_renderer;
+ };
class PipelineStateImpl : public PipelineStateBase
{
public:
- RefPtr<InputLayoutImpl> m_inputLayout;
+ RefPtr<InputLayoutImpl> m_inputLayout;
void init(const GraphicsPipelineStateDesc& inDesc)
{
PipelineStateDesc pipelineDesc;
@@ -687,7 +703,8 @@ public:
public:
Builder(RendererBase* renderer, slang::ISession* session)
: m_renderer(renderer), m_session(session)
- {}
+ {
+ }
RendererBase* m_renderer;
slang::ISession* m_session;
@@ -748,8 +765,7 @@ public:
bindingRangeInfo.baseIndex = m_storageBufferCount;
m_storageBufferCount += count;
break;
- case slang::BindingType::Sampler:
- break;
+ case slang::BindingType::Sampler: break;
case slang::BindingType::Texture:
case slang::BindingType::CombinedTextureSampler:
@@ -767,11 +783,8 @@ public:
m_storageBufferCount += count;
break;
case slang::BindingType::VaryingInput:
- case slang::BindingType::VaryingOutput:
- break;
- default:
- SLANG_ASSERT(!"unsupported binding type.");
- break;
+ case slang::BindingType::VaryingOutput: break;
+ default: SLANG_ASSERT(!"unsupported binding type."); break;
}
m_bindingRanges.add(bindingRangeInfo);
}
@@ -812,8 +825,7 @@ public:
SlangResult build(ShaderObjectLayoutImpl** outLayout)
{
- auto layout =
- RefPtr<ShaderObjectLayoutImpl>(new ShaderObjectLayoutImpl());
+ auto layout = RefPtr<ShaderObjectLayoutImpl>(new ShaderObjectLayoutImpl());
SLANG_RETURN_ON_FAIL(layout->_init(this));
returnRefPtrMove(outLayout, layout);
@@ -843,15 +855,16 @@ public:
Index getStorageBufferCount() { return m_storageBufferCount; }
Index getSubObjectCount() { return m_subObjectCount; }
- SubObjectRangeInfo const& getSubObjectRange(Index index) { return m_subObjectRanges[index]; }
+ SubObjectRangeInfo const& getSubObjectRange(Index index)
+ {
+ return m_subObjectRanges[index];
+ }
List<SubObjectRangeInfo> const& getSubObjectRanges() { return m_subObjectRanges; }
RendererBase* getRenderer() { return m_renderer; }
- slang::TypeReflection* getType()
- {
- return m_elementTypeLayout->getType();
- }
+ slang::TypeReflection* getType() { return m_elementTypeLayout->getType(); }
+
protected:
Result _init(Builder const* builder)
{
@@ -898,7 +911,8 @@ public:
: Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
- {}
+ {
+ }
Result build(RootShaderObjectLayoutImpl** outLayout)
{
@@ -945,7 +959,10 @@ public:
auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
RefPtr<ShaderObjectLayoutImpl> entryPointLayout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- renderer, program->getSession(), slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
+ renderer,
+ program->getSession(),
+ slangEntryPoint->getTypeLayout(),
+ entryPointLayout.writeRef()));
builder.addEntryPoint(slangEntryPoint->getStage(), entryPointLayout);
}
@@ -970,17 +987,16 @@ public:
return SLANG_OK;
}
- ComPtr<slang::IComponentType> m_program;
+ ComPtr<slang::IComponentType> m_program;
slang::ProgramLayout* m_programLayout = nullptr;
List<EntryPointInfo> m_entryPoints;
};
- class ShaderObjectImpl
- : public ShaderObjectBaseImpl<
- ShaderObjectImpl,
- ShaderObjectLayoutImpl,
- SimpleShaderObjectData>
+ class ShaderObjectImpl : public ShaderObjectBaseImpl<
+ ShaderObjectImpl,
+ ShaderObjectLayoutImpl,
+ SimpleShaderObjectData>
{
public:
static Result create(
@@ -999,8 +1015,8 @@ public:
SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() SLANG_OVERRIDE { return 0; }
- SLANG_NO_THROW Result SLANG_MCALL getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
- SLANG_OVERRIDE
+ SLANG_NO_THROW Result SLANG_MCALL
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) SLANG_OVERRIDE
{
*outEntryPoint = nullptr;
return SLANG_OK;
@@ -1022,7 +1038,7 @@ public:
}
SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& inOffset, void const* data, size_t inSize) SLANG_OVERRIDE
+ setData(ShaderOffset const& inOffset, void const* data, size_t inSize) SLANG_OVERRIDE
{
Index offset = inOffset.uniformOffset;
Index size = inSize;
@@ -1051,7 +1067,7 @@ public:
SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView) SLANG_OVERRIDE
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) SLANG_OVERRIDE
{
if (offset.bindingRangeIndex < 0)
return SLANG_E_INVALID_ARG;
@@ -1067,21 +1083,24 @@ public:
case slang::BindingType::MutableTypedBuffer:
case slang::BindingType::RawBuffer:
case slang::BindingType::TypedBuffer:
- m_storageBuffers[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<BufferViewImpl*>(resourceView);
+ m_storageBuffers[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<BufferViewImpl*>(resourceView);
break;
case slang::BindingType::MutableTexture:
- m_images[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<TextureViewImpl*>(resourceView);
+ m_images[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<TextureViewImpl*>(resourceView);
break;
case slang::BindingType::Texture:
- m_textures[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<TextureViewImpl*>(resourceView);
+ m_textures[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<TextureViewImpl*>(resourceView);
m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] = nullptr;
break;
}
return SLANG_OK;
}
- SLANG_NO_THROW Result SLANG_MCALL setSampler(ShaderOffset const& offset, ISamplerState* sampler)
- SLANG_OVERRIDE
+ SLANG_NO_THROW Result SLANG_MCALL
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) SLANG_OVERRIDE
{
if (offset.bindingRangeIndex < 0)
return SLANG_E_INVALID_ARG;
@@ -1090,12 +1109,15 @@ public:
return SLANG_E_INVALID_ARG;
auto& bindingRange = layout->getBindingRange(offset.bindingRangeIndex);
- m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<SamplerStateImpl*>(sampler);
+ m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<SamplerStateImpl*>(sampler);
return SLANG_OK;
}
SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) SLANG_OVERRIDE
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) SLANG_OVERRIDE
{
if (offset.bindingRangeIndex < 0)
return SLANG_E_INVALID_ARG;
@@ -1103,13 +1125,14 @@ public:
if (offset.bindingRangeIndex >= layout->getBindingRangeCount())
return SLANG_E_INVALID_ARG;
auto& bindingRange = layout->getBindingRange(offset.bindingRangeIndex);
- m_textures[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<TextureViewImpl*>(textureView);
- m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] = static_cast<SamplerStateImpl*>(sampler);
+ m_textures[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<TextureViewImpl*>(textureView);
+ m_samplers[bindingRange.baseIndex + offset.bindingArrayIndex] =
+ static_cast<SamplerStateImpl*>(sampler);
return SLANG_OK;
}
public:
-
protected:
friend class ProgramVars;
@@ -1161,7 +1184,8 @@ public:
// in each entry in this range, based on the layout
// information we already have.
- auto& bindingRangeInfo = layout->getBindingRange(subObjectRangeInfo.bindingRangeIndex);
+ auto& bindingRangeInfo =
+ layout->getBindingRange(subObjectRangeInfo.bindingRangeIndex);
for (Index i = 0; i < bindingRangeInfo.count; ++i)
{
RefPtr<ShaderObjectImpl> subObject;
@@ -1174,12 +1198,13 @@ public:
return SLANG_OK;
}
- /// Write the uniform/ordinary data of this object into the given `dest` buffer at the given `offset`
+ /// Write the uniform/ordinary data of this object into the given `dest` buffer at the given
+ /// `offset`
Result _writeOrdinaryData(
GLDevice* device,
BufferResourceImpl* buffer,
size_t offset,
- size_t destSize,
+ size_t destSize,
ShaderObjectLayoutImpl* specializedLayout)
{
auto src = m_data.getBuffer();
@@ -1207,7 +1232,8 @@ public:
for (auto const& subObjectRangeInfo : specializedLayout->getSubObjectRanges())
{
Index subObjectRangeIndex = subObjectRangeCounter++;
- auto const& bindingRangeInfo = specializedLayout->getBindingRange(subObjectRangeInfo.bindingRangeIndex);
+ auto const& bindingRangeInfo =
+ specializedLayout->getBindingRange(subObjectRangeInfo.bindingRangeIndex);
// We only need to handle sub-object ranges for interface/existential-type fields,
// because fields of constant-buffer or parameter-block type are responsible for
@@ -1231,24 +1257,27 @@ public:
// of the parent object's type layout.
//
// Here we assume that the Slang reflection API can provide us with a single byte
- // offset and stride for the location of the pending data allocation in the specialized
- // type layout, which will store the values for this sub-object range.
+ // offset and stride for the location of the pending data allocation in the
+ // specialized type layout, which will store the values for this sub-object range.
//
// TODO: The reflection API functions we are assuming here haven't been implemented
// yet, so the functions being called here are stubs.
//
// TODO: It might not be that a single sub-object range can reliably map to a single
- // contiguous array with a single stride; we need to carefully consider what the layout
- // logic does for complex cases with multiple layers of nested arrays and structures.
+ // contiguous array with a single stride; we need to carefully consider what the
+ // layout logic does for complex cases with multiple layers of nested arrays and
+ // structures.
//
- size_t subObjectRangePendingDataOffset = 0; //subObjectRangeInfo.offset.pendingOrdinaryData;
- size_t subObjectRangePendingDataStride = 0; //subObjectRangeInfo.stride.pendingOrdinaryData;
+ size_t subObjectRangePendingDataOffset =
+ 0; // subObjectRangeInfo.offset.pendingOrdinaryData;
+ size_t subObjectRangePendingDataStride =
+ 0; // subObjectRangeInfo.stride.pendingOrdinaryData;
// If the range doesn't actually need/use the "pending" allocation at all, then
// we need to detect that case and skip such ranges.
//
- // TODO: This should probably be handled on a per-object basis by caching a "does it fit?"
- // bit as part of the information for bound sub-objects, given that we already
+ // TODO: This should probably be handled on a per-object basis by caching a "does it
+ // fit?" bit as part of the information for bound sub-objects, given that we already
// compute the "does it fit?" status as part of `setObject()`.
//
if (subObjectRangePendingDataOffset == 0)
@@ -1259,11 +1288,18 @@ public:
auto subObject = m_objects[bindingRangeInfo.subObjectIndex + i];
RefPtr<ShaderObjectLayoutImpl> subObjectLayout;
- SLANG_RETURN_ON_FAIL(subObject->_getSpecializedLayout(subObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ subObject->_getSpecializedLayout(subObjectLayout.writeRef()));
- auto subObjectOffset = subObjectRangePendingDataOffset + i * subObjectRangePendingDataStride;
+ auto subObjectOffset =
+ subObjectRangePendingDataOffset + i * subObjectRangePendingDataStride;
- subObject->_writeOrdinaryData(device, buffer, offset + subObjectOffset, destSize - subObjectOffset, subObjectLayout);
+ subObject->_writeOrdinaryData(
+ device,
+ buffer,
+ offset + subObjectOffset,
+ destSize - subObjectOffset,
+ subObjectLayout);
}
}
@@ -1325,15 +1361,18 @@ public:
// where this object contains interface/existential-type fields, so we
// don't need or want to inline it into this call site.
//
- SLANG_RETURN_ON_FAIL(_writeOrdinaryData(device, m_ordinaryDataBuffer, 0, specializedOrdinaryDataSize, specializedLayout));
+ SLANG_RETURN_ON_FAIL(_writeOrdinaryData(
+ device,
+ m_ordinaryDataBuffer,
+ 0,
+ specializedOrdinaryDataSize,
+ specializedLayout));
return SLANG_OK;
}
/// Bind the buffer for ordinary/uniform data, if needed
- Result _bindOrdinaryDataBufferIfNeeded(
- GLDevice* device,
- RootBindingState* bindingState)
+ Result _bindOrdinaryDataBufferIfNeeded(GLDevice* device, RootBindingState* bindingState)
{
// We start by ensuring that the buffer is created, if it is needed.
//
@@ -1349,6 +1388,7 @@ public:
return SLANG_OK;
}
+
public:
virtual Result bindObject(GLDevice* device, RootBindingState* bindingState)
{
@@ -1376,10 +1416,8 @@ public:
{
case slang::BindingType::ConstantBuffer:
case slang::BindingType::ParameterBlock:
- case slang::BindingType::ExistentialValue:
- break;
- default:
- continue;
+ case slang::BindingType::ExistentialValue: break;
+ default: continue;
}
for (Index i = 0; i < bindingRange.count; i++)
@@ -1444,17 +1482,24 @@ public:
RefPtr<ShaderObjectLayoutImpl> m_specializedLayout;
};
- class MutableShaderObjectImpl : public MutableShaderObject<MutableShaderObjectImpl, ShaderObjectLayoutImpl>
- {};
+ class MutableShaderObjectImpl
+ : public MutableShaderObject<MutableShaderObjectImpl, ShaderObjectLayoutImpl>
+ {
+ };
class RootShaderObjectImpl : public ShaderObjectImpl
{
typedef ShaderObjectImpl Super;
+
public:
virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
+
public:
- static Result create(IDevice* device, RootShaderObjectLayoutImpl* layout, RootShaderObjectImpl** outShaderObject)
+ static Result create(
+ IDevice* device,
+ RootShaderObjectLayoutImpl* layout,
+ RootShaderObjectImpl** outShaderObject)
{
RefPtr<RootShaderObjectImpl> object = new RootShaderObjectImpl();
SLANG_RETURN_ON_FAIL(object->init(device, layout));
@@ -1463,10 +1508,17 @@ public:
return SLANG_OK;
}
- RootShaderObjectLayoutImpl* getLayout() { return static_cast<RootShaderObjectLayoutImpl*>(m_layout.Ptr()); }
+ RootShaderObjectLayoutImpl* getLayout()
+ {
+ return static_cast<RootShaderObjectLayoutImpl*>(m_layout.Ptr());
+ }
- GfxCount SLANG_MCALL getEntryPointCount() SLANG_OVERRIDE { return (GfxCount)m_entryPoints.getCount(); }
- SlangResult SLANG_MCALL getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) SLANG_OVERRIDE
+ GfxCount SLANG_MCALL getEntryPointCount() SLANG_OVERRIDE
+ {
+ return (GfxCount)m_entryPoints.getCount();
+ }
+ SlangResult SLANG_MCALL getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
+ SLANG_OVERRIDE
{
*outEntryPoint = m_entryPoints[index];
m_entryPoints[index]->addRef();
@@ -1552,8 +1604,9 @@ public:
// parmaeters, but their layouts are also independent of one another.
//
// Furthermore, in this example, loading another entry point into the system would not
- // rquire re-computing the layouts (or generated kernel code) for any of the entry points
- // that had already been loaded (in contrast to a compose-then-specialize approach).
+ // rquire re-computing the layouts (or generated kernel code) for any of the entry
+ // points that had already been loaded (in contrast to a compose-then-specialize
+ // approach).
//
ComPtr<slang::IComponentType> specializedComponentType;
ComPtr<slang::IBlob> diagnosticBlob;
@@ -1570,7 +1623,11 @@ public:
auto slangSpecializedLayout = specializedComponentType->getLayout();
RefPtr<RootShaderObjectLayoutImpl> specializedLayout;
- RootShaderObjectLayoutImpl::create(getRenderer(), specializedComponentType, slangSpecializedLayout, specializedLayout.writeRef());
+ RootShaderObjectLayoutImpl::create(
+ getRenderer(),
+ specializedComponentType,
+ slangSpecializedLayout,
+ specializedLayout.writeRef());
// Note: Computing the layout for the specialized program will have also computed
// the layouts for the entry points, and we really need to attach that information
@@ -1608,22 +1665,40 @@ public:
struct GlPixelFormatInfo
{
- GLint internalFormat; // such as GL_RGBA8
- GLenum format; // such as GL_RGBA
- GLenum formatType; // such as GL_UNSIGNED_BYTE
+ GLint internalFormat; // such as GL_RGBA8
+ GLenum format; // such as GL_RGBA
+ GLenum formatType; // such as GL_UNSIGNED_BYTE
};
-// void destroyBindingEntries(const BindingState::Desc& desc, const BindingDetail* details);
+ // void destroyBindingEntries(const BindingState::Desc& desc, const BindingDetail* details);
- void bindBufferImpl(int target, UInt startSlot, UInt slotCount, BufferResource*const* buffers, const UInt* offsets);
+ void bindBufferImpl(
+ int target,
+ UInt startSlot,
+ UInt slotCount,
+ BufferResource* const* buffers,
+ const UInt* offsets);
void flushStateForDraw();
GLuint loadShader(GLenum stage, char const* source);
- void debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message);
-
- /// Returns GlPixelFormat::Unknown if not an equivalent
+ void debugCallback(
+ GLenum source,
+ GLenum type,
+ GLuint id,
+ GLenum severity,
+ GLsizei length,
+ const GLchar* message);
+
+ /// Returns GlPixelFormat::Unknown if not an equivalent
static GlPixelFormat _getGlPixelFormat(Format format);
- static void APIENTRY staticDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam);
+ static void APIENTRY staticDebugCallback(
+ GLenum source,
+ GLenum type,
+ GLuint id,
+ GLenum severity,
+ GLsizei length,
+ const GLchar* message,
+ const void* userParam);
static VertexAttributeFormat getVertexAttributeFormat(Format format);
static void compileTimeAsserts();
@@ -1633,8 +1708,8 @@ public:
DeviceInfo m_info;
String m_adapterName;
- HDC m_hdc;
- HGLRC m_glContext = 0;
+ HDC m_hdc;
+ HGLRC m_glContext = 0;
uint32_t m_stencilRef = 0;
GLuint m_vao;
@@ -1645,80 +1720,96 @@ public:
RootBindingState m_rootBindingState;
GLenum m_boundPrimitiveTopology = GL_TRIANGLES;
- GLuint m_boundVertexStreamBuffers[kMaxVertexStreams];
- UInt m_boundVertexStreamOffsets[kMaxVertexStreams];
+ GLuint m_boundVertexStreamBuffers[kMaxVertexStreams];
+ UInt m_boundVertexStreamOffsets[kMaxVertexStreams];
GLuint m_boundIndexBuffer = 0;
UInt m_boundIndexBufferOffset = 0;
UInt m_boundIndexBufferSize = 0;
Desc m_desc;
WindowHandle m_windowHandle;
- // Declare a function pointer for each OpenGL
- // extension function we need to load
+// Declare a function pointer for each OpenGL
+// extension function we need to load
#define DECLARE_GL_EXTENSION_FUNC(NAME, TYPE) TYPE NAME;
MAP_GL_EXTENSION_FUNCS(DECLARE_GL_EXTENSION_FUNC)
MAP_WGL_EXTENSION_FUNCS(DECLARE_GL_EXTENSION_FUNC)
#undef DECLARE_GL_EXTENSION_FUNC
- static const GlPixelFormatInfo s_pixelFormatInfos[]; /// Maps GlPixelFormat to a format info
+ static const GlPixelFormatInfo s_pixelFormatInfos[]; /// Maps GlPixelFormat to a format info
};
-/* static */GLDevice::GlPixelFormat GLDevice::_getGlPixelFormat(Format format)
+/* static */ GLDevice::GlPixelFormat GLDevice::_getGlPixelFormat(Format format)
{
switch (format)
{
- case Format::R8G8B8A8_UNORM: return GlPixelFormat::R8G8B8A8_UNORM;
- case Format::D32_FLOAT: return GlPixelFormat::D32_FLOAT;
- //case Format::D24_UNORM_S8_UINT: return GlPixelFormat::D_Unorm24_S8;
- case Format::D32_FLOAT_S8_UINT: return GlPixelFormat::D32_FLOAT_S8;
+ case Format::R8G8B8A8_UNORM: return GlPixelFormat::R8G8B8A8_UNORM;
+ case Format::D32_FLOAT: return GlPixelFormat::D32_FLOAT;
+ // case Format::D24_UNORM_S8_UINT: return GlPixelFormat::D_Unorm24_S8;
+ case Format::D32_FLOAT_S8_UINT: return GlPixelFormat::D32_FLOAT_S8;
- default: return GlPixelFormat::Unknown;
+ default: return GlPixelFormat::Unknown;
}
}
-/* static */ const GLDevice::GlPixelFormatInfo GLDevice::s_pixelFormatInfos[] =
-{
+/* static */ const GLDevice::GlPixelFormatInfo GLDevice::s_pixelFormatInfos[] = {
// internalType, format, formatType
- { 0, 0, 0}, // GlPixelFormat::Unknown
- { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE }, // GlPixelFormat::R8G8B8A8_UNORM
- { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE}, // GlPixelFormat::D32_FLOAT
- { GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE}, // GlPixelFormat::D_Unorm24_S8
- { GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, // GlPixelFormat::D32_FLOAT_S8
+ {0, 0, 0}, // GlPixelFormat::Unknown
+ {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // GlPixelFormat::R8G8B8A8_UNORM
+ {GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE}, // GlPixelFormat::D32_FLOAT
+ {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE}, // GlPixelFormat::D_Unorm24_S8
+ {GL_DEPTH32F_STENCIL8,
+ GL_DEPTH_STENCIL,
+ GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, // GlPixelFormat::D32_FLOAT_S8
};
-/* static */void GLDevice::compileTimeAsserts()
+/* static */ void GLDevice::compileTimeAsserts()
{
SLANG_COMPILE_TIME_ASSERT(SLANG_COUNT_OF(s_pixelFormatInfos) == int(GlPixelFormat::CountOf));
}
-void GLDevice::debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message)
+void GLDevice::debugCallback(
+ GLenum source,
+ GLenum type,
+ GLuint id,
+ GLenum severity,
+ GLsizei length,
+ const GLchar* message)
{
DebugMessageType msgType = DebugMessageType::Info;
- switch(type)
+ switch (type)
{
- case GL_DEBUG_TYPE_ERROR:
- msgType = DebugMessageType::Error;
- break;
- default:
- break;
+ case GL_DEBUG_TYPE_ERROR: msgType = DebugMessageType::Error; break;
+ default: break;
}
getDebugCallback()->handleMessage(msgType, DebugMessageSource::Driver, message);
}
-/* static */void APIENTRY GLDevice::staticDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
+/* static */ void APIENTRY GLDevice::staticDebugCallback(
+ GLenum source,
+ GLenum type,
+ GLuint id,
+ GLenum severity,
+ GLsizei length,
+ const GLchar* message,
+ const void* userParam)
{
((GLDevice*)userParam)->debugCallback(source, type, id, severity, length, message);
}
-/* static */GLDevice::VertexAttributeFormat GLDevice::getVertexAttributeFormat(Format format)
+/* static */ GLDevice::VertexAttributeFormat GLDevice::getVertexAttributeFormat(Format format)
{
switch (format)
{
- default: assert(!"unexpected"); return VertexAttributeFormat();
+ default: assert(!"unexpected"); return VertexAttributeFormat();
-#define CASE(NAME, COUNT, TYPE, NORMALIZED) \
- case Format::NAME: do { VertexAttributeFormat result = {COUNT, TYPE, NORMALIZED}; return result; } while (0)
+#define CASE(NAME, COUNT, TYPE, NORMALIZED) \
+ case Format::NAME: \
+ do \
+ { \
+ VertexAttributeFormat result = {COUNT, TYPE, NORMALIZED}; \
+ return result; \
+ } while (0)
CASE(R32G32B32A32_FLOAT, 4, GL_FLOAT, GL_FALSE);
CASE(R32G32B32_FLOAT, 3, GL_FLOAT, GL_FALSE);
@@ -1728,7 +1819,12 @@ void GLDevice::debugCallback(GLenum source, GLenum type, GLuint id, GLenum sever
}
}
-void GLDevice::bindBufferImpl(int target, UInt startSlot, UInt slotCount, BufferResource*const* buffers, const UInt* offsets)
+void GLDevice::bindBufferImpl(
+ int target,
+ UInt startSlot,
+ UInt slotCount,
+ BufferResource* const* buffers,
+ const UInt* offsets)
{
for (UInt ii = 0; ii < slotCount; ++ii)
{
@@ -1780,7 +1876,12 @@ void GLDevice::flushStateForDraw()
}
if (m_boundIndexBuffer)
{
- glBindBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, m_boundIndexBuffer, m_boundIndexBufferOffset, m_boundIndexBufferSize);
+ glBindBufferRange(
+ GL_ELEMENT_ARRAY_BUFFER,
+ 0,
+ m_boundIndexBuffer,
+ m_boundIndexBufferOffset,
+ m_boundIndexBufferSize);
}
}
@@ -1822,7 +1923,10 @@ GLuint GLDevice::loadShader(GLenum stage, const char* source)
versionEnd = sourceBegin;
}
- enum { kMaxSourceStringCount = 16 };
+ enum
+ {
+ kMaxSourceStringCount = 16
+ };
const GLchar* sourceStrings[kMaxSourceStringCount];
GLint sourceStringLengths[kMaxSourceStringCount];
@@ -1831,7 +1935,8 @@ GLuint GLDevice::loadShader(GLenum stage, const char* source)
const char* stagePrelude = "\n";
switch (stage)
{
-#define CASE(NAME) case GL_##NAME##_SHADER: stagePrelude = "#define __GLSL_" #NAME "__ 1\n"; break
+#define CASE(NAME) \
+ case GL_##NAME##_SHADER: stagePrelude = "#define __GLSL_" #NAME "__ 1\n"; break
CASE(VERTEX);
CASE(TESS_CONTROL);
@@ -1843,19 +1948,15 @@ GLuint GLDevice::loadShader(GLenum stage, const char* source)
#undef CASE
}
- const char* prelude =
- "#define __GLSL__ 1\n"
- ;
+ const char* prelude = "#define __GLSL__ 1\n";
-#define ADD_SOURCE_STRING_SPAN(BEGIN, END) \
- sourceStrings[sourceStringCount] = BEGIN; \
- sourceStringLengths[sourceStringCount++] = GLint(END - BEGIN) \
- /* end */
+#define ADD_SOURCE_STRING_SPAN(BEGIN, END) \
+ sourceStrings[sourceStringCount] = BEGIN; \
+ sourceStringLengths[sourceStringCount++] = GLint(END - BEGIN) /* end */
-#define ADD_SOURCE_STRING(BEGIN) \
- sourceStrings[sourceStringCount] = BEGIN; \
- sourceStringLengths[sourceStringCount++] = GLint(strlen(BEGIN)) \
- /* end */
+#define ADD_SOURCE_STRING(BEGIN) \
+ sourceStrings[sourceStringCount] = BEGIN; \
+ sourceStringLengths[sourceStringCount++] = GLint(strlen(BEGIN)) /* end */
ADD_SOURCE_STRING_SPAN(versionBegin, versionEnd);
ADD_SOURCE_STRING(stagePrelude);
@@ -1864,11 +1965,7 @@ GLuint GLDevice::loadShader(GLenum stage, const char* source)
ADD_SOURCE_STRING_SPAN(versionEnd, sourceEnd);
auto shaderID = glCreateShader(stage);
- glShaderSource(
- shaderID,
- sourceStringCount,
- &sourceStrings[0],
- &sourceStringLengths[0]);
+ glShaderSource(shaderID, sourceStringCount, &sourceStrings[0], &sourceStringLengths[0]);
glCompileShader(shaderID);
GLint success = GL_FALSE;
@@ -1922,19 +2019,19 @@ WindowHandle createWindow()
}
HWND hwnd = CreateWindowEx(
- 0, // Optional window styles.
- className, // Window class
- L"GLWindow", // Window text
+ 0, // Optional window styles.
+ className, // Window class
+ L"GLWindow", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
- NULL, // Parent window
- NULL, // Menu
+ NULL, // Parent window
+ NULL, // Menu
hInstance, // Instance handle
- NULL // Additional application data
+ NULL // Additional application data
);
if (hwnd == NULL)
@@ -1953,7 +2050,10 @@ void destroyWindow(WindowHandle window)
#endif
}
-GLDevice::GLDevice() { m_weakRenderer = new WeakSink<GLDevice>(this); }
+GLDevice::GLDevice()
+{
+ m_weakRenderer = new WeakSink<GLDevice>(this);
+}
GLDevice::~GLDevice()
{
@@ -2013,8 +2113,7 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::initialize(const Desc& desc)
desc.extendedDescs,
SLANG_GLSL,
"glsl_440",
- makeArray(
- slang::PreprocessorMacroDesc{ "__GL__", "1" }).getView()));
+ makeArray(slang::PreprocessorMacroDesc{"__GL__", "1"}).getView()));
SLANG_RETURN_ON_FAIL(RendererBase::initialize(desc));
@@ -2033,7 +2132,7 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::initialize(const Desc& desc)
m_hdc = ::GetDC((HWND)m_windowHandle.handleValues[0]);
- PIXELFORMATDESCRIPTOR pixelFormatDesc = { sizeof(PIXELFORMATDESCRIPTOR) };
+ PIXELFORMATDESCRIPTOR pixelFormatDesc = {sizeof(PIXELFORMATDESCRIPTOR)};
pixelFormatDesc.nVersion = 1;
pixelFormatDesc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pixelFormatDesc.iPixelType = PFD_TYPE_RGBA;
@@ -2068,7 +2167,7 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::initialize(const Desc& desc)
// Load each of our extension functions by name
-#define LOAD_GL_EXTENSION_FUNC(NAME, TYPE) NAME = (TYPE) wglGetProcAddress(#NAME);
+#define LOAD_GL_EXTENSION_FUNC(NAME, TYPE) NAME = (TYPE)wglGetProcAddress(#NAME);
MAP_GL_EXTENSION_FUNCS(LOAD_GL_EXTENSION_FUNC)
MAP_WGL_EXTENSION_FUNCS(LOAD_GL_EXTENSION_FUNC)
#undef LOAD_GL_EXTENSION_FUNC
@@ -2141,7 +2240,9 @@ void GLDevice::clearFrame(uint32_t mask, bool clearDepth, bool clearStencil)
}
if (clearBuffers.getCount())
{
- glDrawBuffers((GLsizei)clearBuffers.getCount(), clearBuffers.getArrayView().getBuffer());
+ glDrawBuffers(
+ (GLsizei)clearBuffers.getCount(),
+ clearBuffers.getArrayView().getBuffer());
clearMask |= GL_COLOR_BUFFER_BIT;
}
glClear(clearMask);
@@ -2175,7 +2276,9 @@ void GLDevice::clearFrame(uint32_t mask, bool clearDepth, bool clearStencil)
}
SLANG_NO_THROW Result SLANG_MCALL GLDevice::createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain)
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain)
{
RefPtr<SwapchainImpl> swapchain = new SwapchainImpl();
SLANG_RETURN_ON_FAIL(swapchain->init(this, desc, window));
@@ -2185,7 +2288,8 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createSwapchain(
}
SLANG_NO_THROW Result SLANG_MCALL GLDevice::createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout)
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout)
{
RefPtr<FramebufferLayoutImpl> layout = new FramebufferLayoutImpl();
layout->m_renderTargets.setCount(desc.renderTargetCount);
@@ -2208,7 +2312,7 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createFramebufferLayout(
}
SLANG_NO_THROW Result SLANG_MCALL
- GLDevice::createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer)
+GLDevice::createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer)
{
RefPtr<FramebufferImpl> framebuffer = new FramebufferImpl(m_weakRenderer);
framebuffer->renderTargetViews.setCount(desc.renderTargetCount);
@@ -2249,7 +2353,11 @@ void GLDevice::copyBuffer(
}
SLANG_NO_THROW Result SLANG_MCALL GLDevice::readTextureResource(
- ITextureResource* texture, ResourceState state, ISlangBlob** outBlob, Size* outRowPitch, Size* outPixelSize)
+ ITextureResource* texture,
+ ResourceState state,
+ ISlangBlob** outBlob,
+ Size* outRowPitch,
+ Size* outPixelSize)
{
SLANG_UNUSED(state);
auto resource = static_cast<TextureResourceImpl*>(texture);
@@ -2319,7 +2427,7 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createTextureResource(
switch (srcDesc.type)
{
- case IResource::Type::Texture1D:
+ case IResource::Type::Texture1D:
{
if (srcDesc.arraySize > 0)
{
@@ -2364,8 +2472,8 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createTextureResource(
}
break;
}
- case IResource::Type::TextureCube:
- case IResource::Type::Texture2D:
+ case IResource::Type::TextureCube:
+ case IResource::Type::Texture2D:
{
if (srcDesc.arraySize > 0)
{
@@ -2445,7 +2553,7 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createTextureResource(
}
break;
}
- case IResource::Type::Texture3D:
+ case IResource::Type::Texture3D:
{
target = GL_TEXTURE_3D;
glBindTexture(target, handle);
@@ -2465,8 +2573,7 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createTextureResource(
}
break;
}
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
}
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -2488,10 +2595,8 @@ static GLenum _calcUsage(ResourceState state)
{
switch (state)
{
- case ResourceState::ConstantBuffer:
- return GL_DYNAMIC_DRAW;
- default:
- return GL_STATIC_READ;
+ case ResourceState::ConstantBuffer: return GL_DYNAMIC_DRAW;
+ default: return GL_STATIC_READ;
}
}
@@ -2499,10 +2604,8 @@ static GLenum _calcTarget(ResourceState state)
{
switch (state)
{
- case ResourceState::ConstantBuffer:
- return GL_UNIFORM_BUFFER;
- default:
- return GL_SHADER_STORAGE_BUFFER;
+ case ResourceState::ConstantBuffer: return GL_UNIFORM_BUFFER;
+ default: return GL_SHADER_STORAGE_BUFFER;
}
}
@@ -2522,13 +2625,14 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createBufferResource(
glBufferData(target, descIn.sizeInBytes, initData, usage);
- RefPtr<BufferResourceImpl> resourceImpl = new BufferResourceImpl(desc, m_weakRenderer, bufferID, target);
+ RefPtr<BufferResourceImpl> resourceImpl =
+ new BufferResourceImpl(desc, m_weakRenderer, bufferID, target);
returnComPtr(outResource, resourceImpl);
return SLANG_OK;
}
SLANG_NO_THROW Result SLANG_MCALL
- GLDevice::createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler)
+GLDevice::createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler)
{
GLuint samplerID;
glCreateSamplers(1, &samplerID);
@@ -2540,7 +2644,9 @@ SLANG_NO_THROW Result SLANG_MCALL
}
SLANG_NO_THROW Result SLANG_MCALL GLDevice::createTextureView(
- ITextureResource* texture, IResourceView::Desc const& desc, IResourceView** outView)
+ ITextureResource* texture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView)
{
auto resourceImpl = static_cast<TextureResourceImpl*>(texture);
@@ -2578,7 +2684,7 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createBufferView(
IResourceView::Desc const& desc,
IResourceView** outView)
{
- auto resourceImpl = (BufferResourceImpl*) buffer;
+ auto resourceImpl = (BufferResourceImpl*)buffer;
// TODO: actually do something?
@@ -2592,8 +2698,8 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::createBufferView(
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL GLDevice::createInputLayout(
- IInputLayout::Desc const& desc, IInputLayout** outLayout)
+SLANG_NO_THROW Result SLANG_MCALL
+GLDevice::createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout)
{
RefPtr<InputLayoutImpl> inputLayout = new InputLayoutImpl;
@@ -2625,18 +2731,14 @@ void* GLDevice::map(IBufferResource* bufferIn, MapFlavor flavor)
{
BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(bufferIn);
- //GLenum target = GL_UNIFORM_BUFFER;
+ // GLenum target = GL_UNIFORM_BUFFER;
GLuint access = 0;
switch (flavor)
{
- case MapFlavor::WriteDiscard:
- case MapFlavor::HostWrite:
- access = GL_WRITE_ONLY;
- break;
- case MapFlavor::HostRead:
- access = GL_READ_ONLY;
- break;
+ case MapFlavor::WriteDiscard:
+ case MapFlavor::HostWrite: access = GL_WRITE_ONLY; break;
+ case MapFlavor::HostRead: access = GL_READ_ONLY; break;
}
glBindBuffer(buffer->m_target, buffer->m_handle);
@@ -2657,7 +2759,8 @@ void GLDevice::setPrimitiveTopology(PrimitiveTopology topology)
GLenum glTopology = 0;
switch (topology)
{
-#define CASE(NAME, VALUE) case PrimitiveTopology::NAME: glTopology = VALUE; break
+#define CASE(NAME, VALUE) \
+ case PrimitiveTopology::NAME: glTopology = VALUE; break
CASE(TriangleList, GL_TRIANGLES);
@@ -2697,17 +2800,17 @@ void GLDevice::setViewports(GfxCount count, Viewport const* viewports)
assert(count == 1);
auto viewport = viewports[0];
glViewport(
- (GLint) viewport.originX,
- (GLint) viewport.originY,
- (GLsizei) viewport.extentX,
- (GLsizei) viewport.extentY);
+ (GLint)viewport.originX,
+ (GLint)viewport.originY,
+ (GLsizei)viewport.extentX,
+ (GLsizei)viewport.extentY);
glDepthRange(viewport.minZ, viewport.maxZ);
}
void GLDevice::setScissorRects(GfxCount count, ScissorRect const* rects)
{
assert(count <= 1);
- if( count )
+ if (count)
{
// TODO: this isn't goign to be quite right because of the
// flipped coordinate system in GL.
@@ -2758,7 +2861,7 @@ void GLDevice::drawIndexed(GfxCount indexCount, GfxIndex startIndex, GfxIndex ba
m_boundPrimitiveTopology,
(GLsizei)indexCount,
GL_UNSIGNED_INT,
- (GLvoid*)(startIndex*sizeof(uint32_t)),
+ (GLvoid*)(startIndex * sizeof(uint32_t)),
(GLint)baseVertex);
}
@@ -2787,7 +2890,9 @@ void GLDevice::dispatchCompute(int x, int y, int z)
}
Result GLDevice::createProgram(
- const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnosticBlob)
{
if (desc.slangGlobalScope->getSpecializationParamCount() != 0)
{
@@ -2805,8 +2910,12 @@ Result GLDevice::createProgram(
{
ComPtr<ISlangBlob> kernelCode;
ComPtr<ISlangBlob> diagnostics;
- auto compileResult = getEntryPointCodeFromShaderCache(desc.slangGlobalScope,
- i, 0, kernelCode.writeRef(), diagnostics.writeRef());
+ auto compileResult = getEntryPointCodeFromShaderCache(
+ desc.slangGlobalScope,
+ i,
+ 0,
+ kernelCode.writeRef(),
+ diagnostics.writeRef());
if (diagnostics)
{
getDebugCallback()->handleMessage(
@@ -2821,27 +2930,13 @@ Result GLDevice::createProgram(
auto stage = programLayout->getEntryPointByIndex(i)->getStage();
switch (stage)
{
- case SLANG_STAGE_COMPUTE:
- glShaderType = GL_COMPUTE_SHADER;
- break;
- case SLANG_STAGE_VERTEX:
- glShaderType = GL_VERTEX_SHADER;
- break;
- case SLANG_STAGE_FRAGMENT:
- glShaderType = GL_FRAGMENT_SHADER;
- break;
- case SLANG_STAGE_GEOMETRY:
- glShaderType = GL_GEOMETRY_SHADER;
- break;
- case SLANG_STAGE_DOMAIN:
- glShaderType = GL_TESS_CONTROL_SHADER;
- break;
- case SLANG_STAGE_HULL:
- glShaderType = GL_TESS_EVALUATION_SHADER;
- break;
- default:
- SLANG_ASSERT(!"unsupported shader type.");
- break;
+ case SLANG_STAGE_COMPUTE: glShaderType = GL_COMPUTE_SHADER; break;
+ case SLANG_STAGE_VERTEX: glShaderType = GL_VERTEX_SHADER; break;
+ case SLANG_STAGE_FRAGMENT: glShaderType = GL_FRAGMENT_SHADER; break;
+ case SLANG_STAGE_GEOMETRY: glShaderType = GL_GEOMETRY_SHADER; break;
+ case SLANG_STAGE_DOMAIN: glShaderType = GL_TESS_CONTROL_SHADER; break;
+ case SLANG_STAGE_HULL: glShaderType = GL_TESS_EVALUATION_SHADER; break;
+ default: SLANG_ASSERT(!"unsupported shader type."); break;
}
auto shaderID = loadShader(glShaderType, (char const*)kernelCode->getBufferPointer());
shaderIDs.add(shaderID);
@@ -2879,12 +2974,14 @@ Result GLDevice::createProgram(
return SLANG_OK;
}
-Result GLDevice::createGraphicsPipelineState(const GraphicsPipelineStateDesc& inDesc, IPipelineState** outState)
+Result GLDevice::createGraphicsPipelineState(
+ const GraphicsPipelineStateDesc& inDesc,
+ IPipelineState** outState)
{
GraphicsPipelineStateDesc desc = inDesc;
- auto programImpl = (ShaderProgramImpl*) desc.program;
- auto inputLayoutImpl = (InputLayoutImpl*) desc.inputLayout;
+ auto programImpl = (ShaderProgramImpl*)desc.program;
+ auto inputLayoutImpl = (InputLayoutImpl*)desc.inputLayout;
RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl();
pipelineStateImpl->m_inputLayout = inputLayoutImpl;
@@ -2893,11 +2990,13 @@ Result GLDevice::createGraphicsPipelineState(const GraphicsPipelineStateDesc& in
return SLANG_OK;
}
-Result GLDevice::createComputePipelineState(const ComputePipelineStateDesc& inDesc, IPipelineState** outState)
+Result GLDevice::createComputePipelineState(
+ const ComputePipelineStateDesc& inDesc,
+ IPipelineState** outState)
{
ComputePipelineStateDesc desc = inDesc;
- auto programImpl = (ShaderProgramImpl*) desc.program;
+ auto programImpl = (ShaderProgramImpl*)desc.program;
RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl();
pipelineStateImpl->m_program = programImpl;
@@ -2912,8 +3011,8 @@ Result GLDevice::createShaderObjectLayout(
ShaderObjectLayoutBase** outLayout)
{
RefPtr<ShaderObjectLayoutImpl> layout;
- SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- this, session, typeLayout, layout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ ShaderObjectLayoutImpl::createForElementType(this, session, typeLayout, layout.writeRef()));
returnRefPtrMove(outLayout, layout);
return SLANG_OK;
}
@@ -2921,13 +3020,17 @@ Result GLDevice::createShaderObjectLayout(
Result GLDevice::createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
{
RefPtr<ShaderObjectImpl> shaderObject;
- SLANG_RETURN_ON_FAIL(ShaderObjectImpl::create(this,
- static_cast<ShaderObjectLayoutImpl*>(layout), shaderObject.writeRef()));
+ SLANG_RETURN_ON_FAIL(ShaderObjectImpl::create(
+ this,
+ static_cast<ShaderObjectLayoutImpl*>(layout),
+ shaderObject.writeRef()));
returnComPtr(outObject, shaderObject);
return SLANG_OK;
}
-Result GLDevice::createMutableShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+Result GLDevice::createMutableShaderObject(
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject)
{
auto layoutImpl = static_cast<ShaderObjectLayoutImpl*>(layout);
@@ -2944,9 +3047,12 @@ Result GLDevice::createRootShaderObject(IShaderProgram* program, ShaderObjectBas
RefPtr<RootShaderObjectImpl> shaderObject;
RefPtr<RootShaderObjectLayoutImpl> rootLayout;
SLANG_RETURN_ON_FAIL(RootShaderObjectLayoutImpl::create(
- this, programImpl->slangGlobalScope, programImpl->slangGlobalScope->getLayout(), rootLayout.writeRef()));
- SLANG_RETURN_ON_FAIL(RootShaderObjectImpl::create(
- this, rootLayout.Ptr(), shaderObject.writeRef()));
+ this,
+ programImpl->slangGlobalScope,
+ programImpl->slangGlobalScope->getLayout(),
+ rootLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ RootShaderObjectImpl::create(this, rootLayout.Ptr(), shaderObject.writeRef()));
returnRefPtrMove(outObject, shaderObject);
return SLANG_OK;
}
@@ -2967,7 +3073,14 @@ void GLDevice::bindRootShaderObject(IShaderObject* shaderObject)
for (Index i = 0; i < m_rootBindingState.imageBindings.getCount(); i++)
{
auto binding = m_rootBindingState.imageBindings[i];
- glBindImageTexture((GLuint)i, binding->m_textureID, binding->level, binding->layered, binding->layer, binding->access, binding->format);
+ glBindImageTexture(
+ (GLuint)i,
+ binding->m_textureID,
+ binding->level,
+ binding->layered,
+ binding->layer,
+ binding->access,
+ binding->format);
}
for (Index i = 0; i < m_rootBindingState.textureBindings.getCount(); i++)
{
@@ -2979,7 +3092,10 @@ void GLDevice::bindRootShaderObject(IShaderObject* shaderObject)
}
for (Index i = 0; i < m_rootBindingState.storageBufferBindings.getCount(); i++)
{
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, (GLuint)i, m_rootBindingState.storageBufferBindings[i]);
+ glBindBufferBase(
+ GL_SHADER_STORAGE_BUFFER,
+ (GLuint)i,
+ m_rootBindingState.storageBufferBindings[i]);
}
for (Index i = 0; i < m_rootBindingState.uniformBufferBindings.getCount(); i++)
{
@@ -2995,16 +3111,16 @@ SlangResult SLANG_MCALL createGLDevice(const IDevice::Desc* desc, IDevice** outR
return SLANG_OK;
}
-} // gfx
+} // namespace gfx
#else
namespace gfx
{
- SlangResult SLANG_MCALL createGLDevice(const IDevice::Desc* desc, IDevice** outRenderer)
- {
- *outRenderer = nullptr;
- return SLANG_FAIL;
- }
+SlangResult SLANG_MCALL createGLDevice(const IDevice::Desc* desc, IDevice** outRenderer)
+{
+ *outRenderer = nullptr;
+ return SLANG_FAIL;
}
+} // namespace gfx
#endif
diff --git a/tools/gfx/open-gl/render-gl.h b/tools/gfx/open-gl/render-gl.h
index 8595e95d3..89232c088 100644
--- a/tools/gfx/open-gl/render-gl.h
+++ b/tools/gfx/open-gl/render-gl.h
@@ -3,8 +3,9 @@
#include "../renderer-shared.h"
-namespace gfx {
+namespace gfx
+{
SlangResult SLANG_MCALL createGLDevice(const IDevice::Desc* desc, IDevice** outDevice);
-} // gfx
+} // namespace gfx
diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp
index 0dd1e5bf5..49d55acc8 100644
--- a/tools/gfx/render.cpp
+++ b/tools/gfx/render.cpp
@@ -1,13 +1,14 @@
// render.cpp
-#include "renderer-shared.h"
-#include "../../source/core/slang-math.h"
#include "../../source/core/slang-blob.h"
-#include "open-gl/render-gl.h"
+#include "../../source/core/slang-math.h"
#include "debug-layer/debug-device.h"
+#include "open-gl/render-gl.h"
+#include "renderer-shared.h"
#include <cstring>
-namespace gfx {
+namespace gfx
+{
using namespace Slang;
Result SLANG_MCALL createD3D11Device(const IDevice::Desc* desc, IDevice** outDevice);
@@ -26,16 +27,16 @@ Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters);
Result SLANG_MCALL reportD3DLiveObjects();
static bool debugLayerEnabled = false;
-bool isGfxDebugLayerEnabled() { return debugLayerEnabled; }
+bool isGfxDebugLayerEnabled()
+{
+ return debugLayerEnabled;
+}
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Global Renderer Functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
#define GFX_FORMAT_SIZE(name, blockSizeInBytes, pixelsPerBlock) {blockSizeInBytes, pixelsPerBlock},
-static const uint32_t s_formatSizeInfo[][2] =
-{
- GFX_FORMAT(GFX_FORMAT_SIZE)
-};
+static const uint32_t s_formatSizeInfo[][2] = {GFX_FORMAT(GFX_FORMAT_SIZE)};
static bool _checkFormat()
{
@@ -43,7 +44,8 @@ static bool _checkFormat()
Index count = 0;
// Check the values are in the same order
-#define GFX_FORMAT_CHECK(name, blockSizeInBytes, pixelsPerblock) count += Index(Index(Format::name) == value++);
+#define GFX_FORMAT_CHECK(name, blockSizeInBytes, pixelsPerblock) \
+ count += Index(Index(Format::name) == value++);
GFX_FORMAT(GFX_FORMAT_CHECK)
const bool r = (count == Index(Format::_Count));
@@ -170,7 +172,12 @@ struct FormatInfoMap
set(Format::BC7_UNORM_SRGB, SLANG_SCALAR_TYPE_FLOAT32, 4, 4, 4);
}
- void set(Format format, SlangScalarType type, Index channelCount, uint32_t blockWidth = 1, uint32_t blockHeight = 1)
+ void set(
+ Format format,
+ SlangScalarType type,
+ Index channelCount,
+ uint32_t blockWidth = 1,
+ uint32_t blockHeight = 1)
{
FormatInfo& info = m_infos[Index(format)];
info.channelCount = uint8_t(channelCount);
@@ -214,10 +221,8 @@ extern "C"
case Format::BC6H_UF16:
case Format::BC6H_SF16:
case Format::BC7_UNORM:
- case Format::BC7_UNORM_SRGB:
- return true;
- default:
- return false;
+ case Format::BC7_UNORM_SRGB: return true;
+ default: return false;
}
}
@@ -236,10 +241,8 @@ extern "C"
case Format::R8G8_TYPELESS:
case Format::R8_TYPELESS:
case Format::B8G8R8A8_TYPELESS:
- case Format::R10G10B10A2_TYPELESS:
- return true;
- default:
- return false;
+ case Format::R10G10B10A2_TYPELESS: return true;
+ default: return false;
}
}
@@ -249,48 +252,35 @@ extern "C"
return SLANG_OK;
}
- SLANG_GFX_API SlangResult SLANG_MCALL gfxGetAdapters(DeviceType type, ISlangBlob** outAdaptersBlob)
+ SLANG_GFX_API SlangResult SLANG_MCALL
+ gfxGetAdapters(DeviceType type, ISlangBlob** outAdaptersBlob)
{
List<AdapterInfo> adapters;
switch (type)
{
#if SLANG_ENABLE_DIRECTX
- case DeviceType::DirectX11:
- SLANG_RETURN_ON_FAIL(getD3D11Adapters(adapters));
- break;
- case DeviceType::DirectX12:
- SLANG_RETURN_ON_FAIL(getD3D12Adapters(adapters));
- break;
+ case DeviceType::DirectX11: SLANG_RETURN_ON_FAIL(getD3D11Adapters(adapters)); break;
+ case DeviceType::DirectX12: SLANG_RETURN_ON_FAIL(getD3D12Adapters(adapters)); break;
#endif
#if SLANG_WINDOWS_FAMILY
- case DeviceType::OpenGl:
- return SLANG_E_NOT_IMPLEMENTED;
+ case DeviceType::OpenGl: return SLANG_E_NOT_IMPLEMENTED;
#endif
#if SLANG_WINDOWS_FAMILY || SLANG_LINUX_FAMILY
// Assume no Vulkan or CUDA on MacOS or Cygwin
- case DeviceType::Vulkan:
- SLANG_RETURN_ON_FAIL(getVKAdapters(adapters));
- break;
- case DeviceType::CUDA:
- SLANG_RETURN_ON_FAIL(getCUDAAdapters(adapters));
- break;
+ case DeviceType::Vulkan: SLANG_RETURN_ON_FAIL(getVKAdapters(adapters)); break;
+ case DeviceType::CUDA: SLANG_RETURN_ON_FAIL(getCUDAAdapters(adapters)); break;
#endif
#if SLANG_APPLE_FAMILY
- case DeviceType::Vulkan:
- SLANG_RETURN_ON_FAIL(getVKAdapters(adapters));
- break;
- case DeviceType::Metal:
- SLANG_RETURN_ON_FAIL(getMetalAdapters(adapters));
- break;
+ case DeviceType::Vulkan: SLANG_RETURN_ON_FAIL(getVKAdapters(adapters)); break;
+ case DeviceType::Metal: SLANG_RETURN_ON_FAIL(getMetalAdapters(adapters)); break;
#endif
- case DeviceType::CPU:
- return SLANG_E_NOT_IMPLEMENTED;
- default:
- return SLANG_E_INVALID_ARG;
+ case DeviceType::CPU: return SLANG_E_NOT_IMPLEMENTED;
+ default: return SLANG_E_INVALID_ARG;
}
- auto adaptersBlob = RawBlob::create(adapters.getBuffer(), adapters.getCount() * sizeof(AdapterInfo));
+ auto adaptersBlob =
+ RawBlob::create(adapters.getBuffer(), adapters.getCount() * sizeof(AdapterInfo));
if (outAdaptersBlob)
returnComPtr(outAdaptersBlob, adaptersBlob);
@@ -340,37 +330,37 @@ extern "C"
break;
#elif SLANG_APPLE_FAMILY
case DeviceType::Vulkan:
- {
- return createVKDevice(desc, outDevice);
- }
+ {
+ return createVKDevice(desc, outDevice);
+ }
case DeviceType::Metal:
- {
- return createMetalDevice(desc, outDevice);
- }
+ {
+ return createMetalDevice(desc, outDevice);
+ }
case DeviceType::Default:
- {
- IDevice::Desc newDesc = *desc;
- newDesc.deviceType = DeviceType::Metal;
- if (_createDevice(&newDesc, outDevice) == SLANG_OK)
- return SLANG_OK;
- newDesc.deviceType = DeviceType::Vulkan;
- if (_createDevice(&newDesc, outDevice) == SLANG_OK)
- return SLANG_OK;
- return SLANG_FAIL;
- }
+ {
+ IDevice::Desc newDesc = *desc;
+ newDesc.deviceType = DeviceType::Metal;
+ if (_createDevice(&newDesc, outDevice) == SLANG_OK)
+ return SLANG_OK;
+ newDesc.deviceType = DeviceType::Vulkan;
+ if (_createDevice(&newDesc, outDevice) == SLANG_OK)
+ return SLANG_OK;
+ return SLANG_FAIL;
+ }
#elif SLANG_LINUX_FAMILY && !defined(__CYGWIN__)
case DeviceType::Vulkan:
- {
- return createVKDevice(desc, outDevice);
- }
+ {
+ return createVKDevice(desc, outDevice);
+ }
case DeviceType::Default:
- {
- IDevice::Desc newDesc = *desc;
- newDesc.deviceType = DeviceType::Vulkan;
- if (_createDevice(&newDesc, outDevice) == SLANG_OK)
- return SLANG_OK;
- return SLANG_FAIL;
- }
+ {
+ IDevice::Desc newDesc = *desc;
+ newDesc.deviceType = DeviceType::Vulkan;
+ if (_createDevice(&newDesc, outDevice) == SLANG_OK)
+ return SLANG_OK;
+ return SLANG_FAIL;
+ }
#endif
case DeviceType::CUDA:
{
@@ -382,13 +372,12 @@ extern "C"
}
break;
- default:
- return SLANG_FAIL;
+ default: return SLANG_FAIL;
}
}
SLANG_GFX_API SlangResult SLANG_MCALL
- gfxCreateDevice(const IDevice::Desc* desc, IDevice** outDevice)
+ gfxCreateDevice(const IDevice::Desc* desc, IDevice** outDevice)
{
ComPtr<IDevice> innerDevice;
auto resultCode = _createDevice(desc, innerDevice.writeRef());
@@ -405,8 +394,7 @@ extern "C"
return resultCode;
}
- SLANG_GFX_API SlangResult SLANG_MCALL
- gfxReportLiveObjects()
+ SLANG_GFX_API SlangResult SLANG_MCALL gfxReportLiveObjects()
{
#if SLANG_ENABLE_DIRECTX
SLANG_RETURN_ON_FAIL(reportD3DLiveObjects());
@@ -429,26 +417,16 @@ extern "C"
{
switch (type)
{
- case gfx::DeviceType::Unknown:
- return "Unknown";
- case gfx::DeviceType::Default:
- return "Default";
- case gfx::DeviceType::DirectX11:
- return "DirectX11";
- case gfx::DeviceType::DirectX12:
- return "DirectX12";
- case gfx::DeviceType::OpenGl:
- return "OpenGL";
- case gfx::DeviceType::Vulkan:
- return "Vulkan";
- case gfx::DeviceType::Metal:
- return "Metal";
- case gfx::DeviceType::CPU:
- return "CPU";
- case gfx::DeviceType::CUDA:
- return "CUDA";
- default:
- return "?";
+ case gfx::DeviceType::Unknown: return "Unknown";
+ case gfx::DeviceType::Default: return "Default";
+ case gfx::DeviceType::DirectX11: return "DirectX11";
+ case gfx::DeviceType::DirectX12: return "DirectX12";
+ case gfx::DeviceType::OpenGl: return "OpenGL";
+ case gfx::DeviceType::Vulkan: return "Vulkan";
+ case gfx::DeviceType::Metal: return "Metal";
+ case gfx::DeviceType::CPU: return "CPU";
+ case gfx::DeviceType::CUDA: return "CUDA";
+ default: return "?";
}
}
@@ -478,4 +456,4 @@ extern "C"
}
}
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp
index 65a14c8cb..5a7aa4b64 100644
--- a/tools/gfx/renderer-shared.cpp
+++ b/tools/gfx/renderer-shared.cpp
@@ -1,11 +1,10 @@
#include "renderer-shared.h"
-#include "mutable-shader-object.h"
-#include "core/slang-io.h"
-#include "core/slang-token-reader.h"
-#include "../../source/core/slang-stable-hash.h"
#include "../../source/core/slang-file-system.h"
-
+#include "../../source/core/slang-stable-hash.h"
+#include "core/slang-io.h"
+#include "core/slang-token-reader.h"
+#include "mutable-shader-object.h"
#include "slang.h"
using namespace Slang;
@@ -45,8 +44,10 @@ const Slang::Guid GfxGUID::IID_IQueryPool = SLANG_UUID_IQueryPool;
const Slang::Guid GfxGUID::IID_IAccelerationStructure = SLANG_UUID_IAccelerationStructure;
const Slang::Guid GfxGUID::IID_IFence = SLANG_UUID_IFence;
const Slang::Guid GfxGUID::IID_IShaderTable = SLANG_UUID_IShaderTable;
-const Slang::Guid GfxGUID::IID_IPipelineCreationAPIDispatcher = SLANG_UUID_IPipelineCreationAPIDispatcher;
-const Slang::Guid GfxGUID::IID_IVulkanPipelineCreationAPIDispatcher = SLANG_UUID_IVulkanPipelineCreationAPIDispatcher;
+const Slang::Guid GfxGUID::IID_IPipelineCreationAPIDispatcher =
+ SLANG_UUID_IPipelineCreationAPIDispatcher;
+const Slang::Guid GfxGUID::IID_IVulkanPipelineCreationAPIDispatcher =
+ SLANG_UUID_IVulkanPipelineCreationAPIDispatcher;
const Slang::Guid GfxGUID::IID_ITransientResourceHeapD3D12 = SLANG_UUID_ITransientResourceHeapD3D12;
@@ -54,13 +55,10 @@ StageType translateStage(SlangStage slangStage)
{
switch (slangStage)
{
- default:
- SLANG_ASSERT(!"unhandled case");
- return gfx::StageType::Unknown;
+ default: SLANG_ASSERT(!"unhandled case"); return gfx::StageType::Unknown;
-#define CASE(FROM, TO) \
-case SLANG_STAGE_##FROM: \
-return gfx::StageType::TO
+#define CASE(FROM, TO) \
+ case SLANG_STAGE_##FROM: return gfx::StageType::TO
CASE(VERTEX, Vertex);
CASE(HULL, Hull);
@@ -96,8 +94,14 @@ IResource* BufferResource::getInterface(const Slang::Guid& guid)
return nullptr;
}
-SLANG_NO_THROW IResource::Type SLANG_MCALL BufferResource::getType() { return m_type; }
-SLANG_NO_THROW IBufferResource::Desc* SLANG_MCALL BufferResource::getDesc() { return &m_desc; }
+SLANG_NO_THROW IResource::Type SLANG_MCALL BufferResource::getType()
+{
+ return m_type;
+}
+SLANG_NO_THROW IBufferResource::Desc* SLANG_MCALL BufferResource::getDesc()
+{
+ return &m_desc;
+}
Result BufferResource::getNativeResourceHandle(InteropHandle* outHandle)
{
@@ -121,8 +125,14 @@ IResource* TextureResource::getInterface(const Slang::Guid& guid)
return nullptr;
}
-SLANG_NO_THROW IResource::Type SLANG_MCALL TextureResource::getType() { return m_type; }
-SLANG_NO_THROW ITextureResource::Desc* SLANG_MCALL TextureResource::getDesc() { return &m_desc; }
+SLANG_NO_THROW IResource::Type SLANG_MCALL TextureResource::getType()
+{
+ return m_type;
+}
+SLANG_NO_THROW ITextureResource::Desc* SLANG_MCALL TextureResource::getDesc()
+{
+ return &m_desc;
+}
Result TextureResource::getNativeResourceHandle(InteropHandle* outHandle)
{
@@ -140,25 +150,24 @@ Result TextureResource::getSharedHandle(InteropHandle* outHandle)
StageType mapStage(SlangStage stage)
{
- switch( stage )
+ switch (stage)
{
- default:
- return StageType::Unknown;
-
- case SLANG_STAGE_AMPLIFICATION: return gfx::StageType::Amplification;
- case SLANG_STAGE_ANY_HIT: return gfx::StageType::AnyHit;
- case SLANG_STAGE_CALLABLE: return gfx::StageType::Callable;
- case SLANG_STAGE_CLOSEST_HIT: return gfx::StageType::ClosestHit;
- case SLANG_STAGE_COMPUTE: return gfx::StageType::Compute;
- case SLANG_STAGE_DOMAIN: return gfx::StageType::Domain;
- case SLANG_STAGE_FRAGMENT: return gfx::StageType::Fragment;
- case SLANG_STAGE_GEOMETRY: return gfx::StageType::Geometry;
- case SLANG_STAGE_HULL: return gfx::StageType::Hull;
- case SLANG_STAGE_INTERSECTION: return gfx::StageType::Intersection;
- case SLANG_STAGE_MESH: return gfx::StageType::Mesh;
- case SLANG_STAGE_MISS: return gfx::StageType::Miss;
- case SLANG_STAGE_RAY_GENERATION: return gfx::StageType::RayGeneration;
- case SLANG_STAGE_VERTEX: return gfx::StageType::Vertex;
+ default: return StageType::Unknown;
+
+ case SLANG_STAGE_AMPLIFICATION: return gfx::StageType::Amplification;
+ case SLANG_STAGE_ANY_HIT: return gfx::StageType::AnyHit;
+ case SLANG_STAGE_CALLABLE: return gfx::StageType::Callable;
+ case SLANG_STAGE_CLOSEST_HIT: return gfx::StageType::ClosestHit;
+ case SLANG_STAGE_COMPUTE: return gfx::StageType::Compute;
+ case SLANG_STAGE_DOMAIN: return gfx::StageType::Domain;
+ case SLANG_STAGE_FRAGMENT: return gfx::StageType::Fragment;
+ case SLANG_STAGE_GEOMETRY: return gfx::StageType::Geometry;
+ case SLANG_STAGE_HULL: return gfx::StageType::Hull;
+ case SLANG_STAGE_INTERSECTION: return gfx::StageType::Intersection;
+ case SLANG_STAGE_MESH: return gfx::StageType::Mesh;
+ case SLANG_STAGE_MISS: return gfx::StageType::Miss;
+ case SLANG_STAGE_RAY_GENERATION: return gfx::StageType::RayGeneration;
+ case SLANG_STAGE_VERTEX: return gfx::StageType::Vertex;
}
}
@@ -199,8 +208,8 @@ IAccelerationStructure* AccelerationStructureBase::getInterface(const Slang::Gui
}
bool _doesValueFitInExistentialPayload(
- slang::TypeLayoutReflection* concreteTypeLayout,
- slang::TypeLayoutReflection* existentialTypeLayout)
+ slang::TypeLayoutReflection* concreteTypeLayout,
+ slang::TypeLayoutReflection* existentialTypeLayout)
{
// Our task here is to figure out if a value of `concreteTypeLayout`
// can fit into an existential value using `existentialTypelayout`.
@@ -220,7 +229,7 @@ bool _doesValueFitInExistentialPayload(
// If the concrete type consumes more ordinary bytes than we have in the payload,
// it cannot possibly fit.
//
- if(concreteValueSize > existentialPayloadSize)
+ if (concreteValueSize > existentialPayloadSize)
return false;
// It is possible that the ordinary bytes of `concreteTypeLayout` can fit
@@ -229,25 +238,24 @@ bool _doesValueFitInExistentialPayload(
// data can't fit in the payload at all.
//
auto categoryCount = concreteTypeLayout->getCategoryCount();
- for(unsigned int i = 0; i < categoryCount; ++i)
+ for (unsigned int i = 0; i < categoryCount; ++i)
{
auto category = concreteTypeLayout->getCategoryByIndex(i);
- switch(category)
+ switch (category)
{
// We want to ignore any ordinary/uniform data usage, since that
// was already checked above.
//
- case slang::ParameterCategory::Uniform:
- break;
+ case slang::ParameterCategory::Uniform: break;
// Any other kind of data consumed means the value cannot possibly fit.
default:
return false;
- // TODO: Are there any cases of resource usage that need to be ignored here?
- // E.g., if the sub-object contains its own existential-type fields (which
- // get reflected as consuming "existential value" storage) should that be
- // ignored?
+ // TODO: Are there any cases of resource usage that need to be ignored here?
+ // E.g., if the sub-object contains its own existential-type fields (which
+ // get reflected as consuming "existential value" storage) should that be
+ // ignored?
}
}
@@ -356,7 +364,11 @@ Result RendererBase::getEntryPointCodeFromShaderCache(
if (persistentShaderCache->readEntry(cacheKey, codeBlob.writeRef()) != SLANG_OK)
{
// No cached entry found. Generate the code and add it to the cache.
- SLANG_RETURN_ON_FAIL(program->getEntryPointCode(entryPointIndex, targetIndex, codeBlob.writeRef(), outDiagnostics));
+ SLANG_RETURN_ON_FAIL(program->getEntryPointCode(
+ entryPointIndex,
+ targetIndex,
+ codeBlob.writeRef(),
+ outDiagnostics));
persistentShaderCache->writeEntry(cacheKey, codeBlob);
}
@@ -419,8 +431,8 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::getNativeDeviceHandles(InteropHa
return SLANG_OK;
}
-SLANG_NO_THROW Result SLANG_MCALL RendererBase::getFeatures(
- const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount)
+SLANG_NO_THROW Result SLANG_MCALL
+RendererBase::getFeatures(const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount)
{
if (bufferSize >= (UInt)m_features.getCount())
{
@@ -534,7 +546,8 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObject2(
IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangSession, type, container, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ getShaderObjectLayout(slangSession, type, container, shaderObjectLayout.writeRef()));
return createShaderObject(shaderObjectLayout, outObject);
}
@@ -553,7 +566,8 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObject2(
IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangSession, type, containerType, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ getShaderObjectLayout(slangSession, type, containerType, shaderObjectLayout.writeRef()));
return createMutableShaderObject(shaderObjectLayout, outObject);
}
@@ -567,7 +581,7 @@ Result RendererBase::createProgram2(
ComPtr<slang::IBlob> diagnosticsBlob;
switch (desc.sourceType)
{
- case ShaderModuleSourceType::SlangSourceFile:
+ case ShaderModuleSourceType::SlangSourceFile:
{
auto fileName = (char*)desc.sourceData;
module = slangSession->loadModule(fileName, diagnosticsBlob.writeRef());
@@ -575,18 +589,21 @@ Result RendererBase::createProgram2(
return SLANG_FAIL;
break;
}
- case ShaderModuleSourceType::SlangSource:
+ case ShaderModuleSourceType::SlangSource:
{
auto hash = getStableHashCode32((char*)desc.sourceData, desc.sourceDataSize);
auto hashStr = String(hash);
auto srcBlob = UnownedRawBlob::create(desc.sourceData, desc.sourceDataSize);
- module = slangSession->loadModuleFromSource(hashStr.getBuffer(), hashStr.getBuffer(), srcBlob, diagnosticsBlob.writeRef());
+ module = slangSession->loadModuleFromSource(
+ hashStr.getBuffer(),
+ hashStr.getBuffer(),
+ srcBlob,
+ diagnosticsBlob.writeRef());
if (!module)
return SLANG_FAIL;
break;
}
- default:
- SLANG_RELEASE_ASSERT(false);
+ default: SLANG_RELEASE_ASSERT(false);
}
Slang::List<ComPtr<slang::IComponentType>> componentTypes;
@@ -606,7 +623,8 @@ Result RendererBase::createProgram2(
for (GfxCount i = 0; i < desc.entryPointCount; i++)
{
ComPtr<slang::IEntryPoint> entryPoint;
- SLANG_RETURN_ON_FAIL(module->findEntryPointByName(desc.entryPointNames[i], entryPoint.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ module->findEntryPointByName(desc.entryPointNames[i], entryPoint.writeRef()));
componentTypes.add(ComPtr<slang::IComponentType>(entryPoint.get()));
}
}
@@ -631,18 +649,22 @@ Result RendererBase::createProgram2(
}
SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject)
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
return createShaderObject(shaderObjectLayout, outObject);
}
SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject)
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
return createMutableShaderObject(shaderObjectLayout, outObject);
}
@@ -671,7 +693,9 @@ Result RendererBase::createShaderTable(const IShaderTable::Desc& desc, IShaderTa
return SLANG_E_NOT_AVAILABLE;
}
-Result RendererBase::createRayTracingPipelineState(const RayTracingPipelineStateDesc& desc, IPipelineState** outState)
+Result RendererBase::createRayTracingPipelineState(
+ const RayTracingPipelineStateDesc& desc,
+ IPipelineState** outState)
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outState);
@@ -679,7 +703,8 @@ Result RendererBase::createRayTracingPipelineState(const RayTracingPipelineState
}
Result RendererBase::createMutableRootShaderObject(
- IShaderProgram* program, IShaderObject** outObject)
+ IShaderProgram* program,
+ IShaderObject** outObject)
{
SLANG_UNUSED(program);
SLANG_UNUSED(outObject);
@@ -694,7 +719,11 @@ Result RendererBase::createFence(const IFence::Desc& desc, IFence** outFence)
}
Result RendererBase::waitForFences(
- GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* fenceValues,
+ bool waitForAll,
+ uint64_t timeout)
{
SLANG_UNUSED(fenceCount);
SLANG_UNUSED(fences);
@@ -705,7 +734,9 @@ Result RendererBase::waitForFences(
}
Result RendererBase::getTextureAllocationInfo(
- const ITextureResource::Desc& desc, Size* outSize, Size* outAlignment)
+ const ITextureResource::Desc& desc,
+ Size* outSize,
+ Size* outAlignment)
{
SLANG_UNUSED(desc);
*outSize = 0;
@@ -733,8 +764,7 @@ Result RendererBase::getShaderObjectLayout(
case ShaderObjectContainerType::Array:
type = session->getContainerType(type, slang::ContainerType::UnsizedArray);
break;
- default:
- break;
+ default: break;
}
auto typeLayout = session->getTypeLayout(type);
@@ -751,7 +781,8 @@ Result RendererBase::getShaderObjectLayout(
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
if (!m_shaderObjectLayoutCache.tryGetValue(typeLayout, shaderObjectLayout))
{
- SLANG_RETURN_ON_FAIL(createShaderObjectLayout(session, typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ createShaderObjectLayout(session, typeLayout, shaderObjectLayout.writeRef()));
m_shaderObjectLayoutCache.add(typeLayout, shaderObjectLayout);
}
*outLayout = shaderObjectLayout.detach();
@@ -799,16 +830,17 @@ ShaderComponentID ShaderCache::getComponentId(slang::TypeReflection* type)
StringBuilder builder;
builder.append(UnownedTerminatedStringSlice(baseType->getName()));
- auto rawType = (SlangReflectionType*) type;
+ auto rawType = (SlangReflectionType*)type;
builder.appendChar('<');
SlangInt argCount = spReflectionType_getSpecializedTypeArgCount(rawType);
- for(SlangInt a = 0; a < argCount; ++a)
+ for (SlangInt a = 0; a < argCount; ++a)
{
- if(a != 0) builder.appendChar(',');
- if(auto rawArgType = spReflectionType_getSpecializedTypeArgType(rawType, a))
+ if (a != 0)
+ builder.appendChar(',');
+ if (auto rawArgType = spReflectionType_getSpecializedTypeArgType(rawType, a))
{
- auto argType = (slang::TypeReflection*) rawArgType;
+ auto argType = (slang::TypeReflection*)rawArgType;
builder.append(argType->getName());
}
}
@@ -819,8 +851,7 @@ ShaderComponentID ShaderCache::getComponentId(slang::TypeReflection* type)
}
// TODO: collect specialization arguments and append them to `key`.
SLANG_UNIMPLEMENTED_X("specialized type");
- default:
- break;
+ default: break;
}
key.updateHash();
return getComponentId(key);
@@ -848,12 +879,17 @@ ShaderComponentID ShaderCache::getComponentId(ComponentKey key)
return resultId;
}
-void ShaderCache::addSpecializedPipeline(PipelineKey key, Slang::RefPtr<PipelineStateBase> specializedPipeline)
+void ShaderCache::addSpecializedPipeline(
+ PipelineKey key,
+ Slang::RefPtr<PipelineStateBase> specializedPipeline)
{
specializedPipelines[key] = specializedPipeline;
}
-void ShaderObjectLayoutBase::initBase(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* elementTypeLayout)
+void ShaderObjectLayoutBase::initBase(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::TypeLayoutReflection* elementTypeLayout)
{
m_renderer = renderer;
m_slangSession = session;
@@ -861,8 +897,9 @@ void ShaderObjectLayoutBase::initBase(RendererBase* renderer, slang::ISession* s
m_componentID = m_renderer->shaderCache.getComponentId(m_elementTypeLayout->getType());
}
-// Get the final type this shader object represents. If the shader object's type has existential fields,
-// this function will return a specialized type using the bound sub-objects' type as specialization argument.
+// Get the final type this shader object represents. If the shader object's type has existential
+// fields, this function will return a specialized type using the bound sub-objects' type as
+// specialization argument.
Result ShaderObjectBase::getSpecializedShaderObjectType(ExtendedShaderObjectType* outType)
{
return _getSpecializedShaderObjectType(outType);
@@ -883,8 +920,10 @@ Result ShaderObjectBase::_getSpecializedShaderObjectType(ExtendedShaderObjectTyp
{
shaderObjectType.slangType = getRenderer()->slangContext.session->specializeType(
_getElementTypeLayout()->getType(),
- specializationArgs.components.getArrayView().getBuffer(), specializationArgs.getCount());
- shaderObjectType.componentID = getRenderer()->shaderCache.getComponentId(shaderObjectType.slangType);
+ specializationArgs.components.getArrayView().getBuffer(),
+ specializationArgs.getCount());
+ shaderObjectType.componentID =
+ getRenderer()->shaderCache.getComponentId(shaderObjectType.slangType);
}
*outType = shaderObjectType;
return SLANG_OK;
@@ -917,7 +956,9 @@ Result ShaderObjectBase::setExistentialHeader(
//
uint32_t conformanceID = 0xFFFFFFFF;
SLANG_RETURN_ON_FAIL(getLayoutBase()->m_slangSession->getTypeConformanceWitnessSequentialID(
- concreteType, existentialType, &conformanceID));
+ concreteType,
+ existentialType,
+ &conformanceID));
//
// Once we have the conformance ID, then we can write it into the object
// at the required offset.
@@ -945,7 +986,9 @@ ResourceViewBase* SimpleShaderObjectData::getResourceView(
desc.sizeInBytes = (Size)m_ordinaryData.getCount();
ComPtr<IBufferResource> bufferResource;
SLANG_RETURN_NULL_ON_FAIL(device->createBufferResource(
- desc, m_ordinaryData.getBuffer(), bufferResource.writeRef()));
+ desc,
+ m_ordinaryData.getBuffer(),
+ bufferResource.writeRef()));
m_structuredBuffer = static_cast<BufferResource*>(bufferResource.get());
// Create read-only (shader-resource) and mutable (unordered access) views.
@@ -954,24 +997,25 @@ ResourceViewBase* SimpleShaderObjectData::getResourceView(
viewDesc.format = Format::Unknown;
viewDesc.type = IResourceView::Type::ShaderResource;
SLANG_RETURN_NULL_ON_FAIL(device->createBufferView(
- bufferResource.get(), nullptr, viewDesc, resourceView.writeRef()));
+ bufferResource.get(),
+ nullptr,
+ viewDesc,
+ resourceView.writeRef()));
m_structuredBufferView = static_cast<ResourceViewBase*>(resourceView.get());
viewDesc.type = IResourceView::Type::UnorderedAccess;
- SLANG_RETURN_NULL_ON_FAIL(
- device->createBufferView(
- bufferResource.get(), nullptr, viewDesc, resourceView.writeRef()));
+ SLANG_RETURN_NULL_ON_FAIL(device->createBufferView(
+ bufferResource.get(),
+ nullptr,
+ viewDesc,
+ resourceView.writeRef()));
m_rwStructuredBufferView = static_cast<ResourceViewBase*>(resourceView.get());
}
switch (bindingType)
{
- case slang::BindingType::RawBuffer:
- return m_structuredBufferView.Ptr();
- case slang::BindingType::MutableRawBuffer:
- return m_rwStructuredBufferView.Ptr();
- default:
- SLANG_ASSERT(false && "Invalid binding type.");
- return nullptr;
+ case slang::BindingType::RawBuffer: return m_structuredBufferView.Ptr();
+ case slang::BindingType::MutableRawBuffer: return m_rwStructuredBufferView.Ptr();
+ default: SLANG_ASSERT(false && "Invalid binding type."); return nullptr;
}
}
@@ -1002,7 +1046,9 @@ void ShaderProgramBase::init(const IShaderProgram::Desc& inDesc)
components.add(desc.slangEntryPoints[i]);
}
session->createCompositeComponentType(
- components.getBuffer(), components.getCount(), linkedProgram.writeRef());
+ components.getBuffer(),
+ components.getCount(),
+ linkedProgram.writeRef());
}
else
{
@@ -1011,10 +1057,13 @@ void ShaderProgramBase::init(const IShaderProgram::Desc& inDesc)
if (desc.slangGlobalScope)
{
slang::IComponentType* entryPointComponents[2] = {
- desc.slangGlobalScope, desc.slangEntryPoints[i]};
+ desc.slangGlobalScope,
+ desc.slangEntryPoints[i]};
ComPtr<slang::IComponentType> linkedEntryPoint;
session->createCompositeComponentType(
- entryPointComponents, 2, linkedEntryPoint.writeRef());
+ entryPointComponents,
+ 2,
+ linkedEntryPoint.writeRef());
linkedEntryPoints.add(linkedEntryPoint);
}
else
@@ -1036,8 +1085,12 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
auto stage = entryPointInfo->getStage();
ComPtr<ISlangBlob> kernelCode;
ComPtr<ISlangBlob> diagnostics;
- auto compileResult = device->getEntryPointCodeFromShaderCache(entryPointComponent,
- entryPointIndex, 0, kernelCode.writeRef(), diagnostics.writeRef());
+ auto compileResult = device->getEntryPointCodeFromShaderCache(
+ entryPointComponent,
+ entryPointIndex,
+ 0,
+ kernelCode.writeRef(),
+ diagnostics.writeRef());
if (diagnostics)
{
DebugMessageType msgType = DebugMessageType::Warning;
@@ -1061,7 +1114,9 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
for (SlangUInt i = 0; i < programReflection->getEntryPointCount(); i++)
{
SLANG_RETURN_ON_FAIL(compileShader(
- programReflection->getEntryPointByIndex(i), linkedProgram, (SlangInt)i));
+ programReflection->getEntryPointByIndex(i),
+ linkedProgram,
+ (SlangInt)i));
}
}
else
@@ -1078,7 +1133,8 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
}
Result ShaderProgramBase::createShaderModule(
- slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode)
+ slang::EntryPointReflection* entryPointInfo,
+ ComPtr<ISlangBlob> kernelCode)
{
SLANG_UNUSED(entryPointInfo);
SLANG_UNUSED(kernelCode);
@@ -1089,17 +1145,17 @@ bool ShaderProgramBase::isMeshShaderProgram() const
{
// Similar to above, interrogate either explicity specified entry point
// componenets or the ones in the linked program entry point array
- if(linkedEntryPoints.getCount())
+ if (linkedEntryPoints.getCount())
{
- for(const auto& e : linkedEntryPoints)
- if(e->getLayout()->getEntryPointByIndex(0)->getStage() == SLANG_STAGE_MESH)
+ for (const auto& e : linkedEntryPoints)
+ if (e->getLayout()->getEntryPointByIndex(0)->getStage() == SLANG_STAGE_MESH)
return true;
}
else
{
const auto programReflection = linkedProgram->getLayout();
- for(SlangUInt i = 0; i < programReflection->getEntryPointCount(); ++i)
- if(programReflection->getEntryPointByIndex(i)->getStage() == SLANG_STAGE_MESH)
+ for (SlangUInt i = 0; i < programReflection->getEntryPointCount(); ++i)
+ if (programReflection->getEntryPointByIndex(i)->getStage() == SLANG_STAGE_MESH)
return true;
}
return false;
@@ -1111,11 +1167,12 @@ Result RendererBase::maybeSpecializePipeline(
RefPtr<PipelineStateBase>& outNewPipeline)
{
outNewPipeline = static_cast<PipelineStateBase*>(currentPipeline);
-
+
auto pipelineType = currentPipeline->desc.type;
if (currentPipeline->unspecializedPipelineState)
currentPipeline = currentPipeline->unspecializedPipelineState;
- // If the currently bound pipeline is specializable, we need to specialize it based on bound shader objects.
+ // If the currently bound pipeline is specializable, we need to specialize it based on bound
+ // shader objects.
if (currentPipeline->isSpecializable)
{
specializationArgs.clear();
@@ -1127,13 +1184,14 @@ Result RendererBase::maybeSpecializePipeline(
pipelineKey.specializationArgs.addRange(specializationArgs.componentIDs);
pipelineKey.updateHash();
- RefPtr<PipelineStateBase> specializedPipelineState = shaderCache.getSpecializedPipelineState(pipelineKey);
+ RefPtr<PipelineStateBase> specializedPipelineState =
+ shaderCache.getSpecializedPipelineState(pipelineKey);
// Try to find specialized pipeline from shader cache.
if (!specializedPipelineState)
{
- auto unspecializedProgram = static_cast<ShaderProgramBase*>(pipelineType == PipelineType::Compute
- ? currentPipeline->desc.compute.program
- : currentPipeline->desc.graphics.program);
+ auto unspecializedProgram = static_cast<ShaderProgramBase*>(
+ pipelineType == PipelineType::Compute ? currentPipeline->desc.compute.program
+ : currentPipeline->desc.graphics.program);
auto unspecializedProgramLayout = unspecializedProgram->linkedProgram->getLayout();
ComPtr<slang::IComponentType> specializedComponentType;
@@ -1159,50 +1217,56 @@ Result RendererBase::maybeSpecializePipeline(
if (specializedProgramDesc.linkingStyle == IShaderProgram::LinkingStyle::SingleProgram)
{
- // When linking style is GraphicsCompute, the specialized global scope already contains
- // entry-points, so we do not need to supply them again when creating the specialized
- // pipeline.
+ // When linking style is GraphicsCompute, the specialized global scope already
+ // contains entry-points, so we do not need to supply them again when creating the
+ // specialized pipeline.
specializedProgramDesc.entryPointCount = 0;
}
- SLANG_RETURN_ON_FAIL(createProgram(specializedProgramDesc, specializedProgram.writeRef()));
+ SLANG_RETURN_ON_FAIL(
+ createProgram(specializedProgramDesc, specializedProgram.writeRef()));
// Create specialized pipeline state.
ComPtr<IPipelineState> specializedPipelineComPtr;
switch (pipelineType)
{
case PipelineType::Compute:
- {
- auto pipelineDesc = currentPipeline->desc.compute;
- pipelineDesc.program = specializedProgram;
- SLANG_RETURN_ON_FAIL(
- createComputePipelineState(pipelineDesc, specializedPipelineComPtr.writeRef()));
- break;
- }
+ {
+ auto pipelineDesc = currentPipeline->desc.compute;
+ pipelineDesc.program = specializedProgram;
+ SLANG_RETURN_ON_FAIL(createComputePipelineState(
+ pipelineDesc,
+ specializedPipelineComPtr.writeRef()));
+ break;
+ }
case PipelineType::Graphics:
- {
- auto pipelineDesc = currentPipeline->desc.graphics;
- pipelineDesc.program = static_cast<ShaderProgramBase*>(specializedProgram.get());
- SLANG_RETURN_ON_FAIL(createGraphicsPipelineState(
- pipelineDesc, specializedPipelineComPtr.writeRef()));
- break;
- }
+ {
+ auto pipelineDesc = currentPipeline->desc.graphics;
+ pipelineDesc.program =
+ static_cast<ShaderProgramBase*>(specializedProgram.get());
+ SLANG_RETURN_ON_FAIL(createGraphicsPipelineState(
+ pipelineDesc,
+ specializedPipelineComPtr.writeRef()));
+ break;
+ }
case PipelineType::RayTracing:
- {
- auto pipelineDesc = currentPipeline->desc.rayTracing;
- pipelineDesc.program = static_cast<ShaderProgramBase*>(specializedProgram.get());
- SLANG_RETURN_ON_FAIL(createRayTracingPipelineState(
- pipelineDesc.get(), specializedPipelineComPtr.writeRef()));
- break;
- }
- default:
- break;
+ {
+ auto pipelineDesc = currentPipeline->desc.rayTracing;
+ pipelineDesc.program =
+ static_cast<ShaderProgramBase*>(specializedProgram.get());
+ SLANG_RETURN_ON_FAIL(createRayTracingPipelineState(
+ pipelineDesc.get(),
+ specializedPipelineComPtr.writeRef()));
+ break;
+ }
+ default: break;
}
specializedPipelineState =
static_cast<PipelineStateBase*>(specializedPipelineComPtr.get());
specializedPipelineState->unspecializedPipelineState = currentPipeline;
shaderCache.addSpecializedPipeline(pipelineKey, specializedPipelineState);
}
- auto specializedPipelineStateBase = static_cast<PipelineStateBase*>(specializedPipelineState.Ptr());
+ auto specializedPipelineStateBase =
+ static_cast<PipelineStateBase*>(specializedPipelineState.Ptr());
outNewPipeline = specializedPipelineStateBase;
}
return SLANG_OK;
@@ -1218,7 +1282,7 @@ class NullDebugCallback : public IDebugCallback
{
public:
virtual SLANG_NO_THROW void SLANG_MCALL
- handleMessage(DebugMessageType type, DebugMessageSource source, const char* message) override
+ handleMessage(DebugMessageType type, DebugMessageSource source, const char* message) override
{
SLANG_UNUSED(type);
SLANG_UNUSED(source);
@@ -1235,7 +1299,10 @@ Result ShaderObjectBase::copyFrom(IShaderObject* object, ITransientResourceHeap*
{
if (auto srcObj = dynamic_cast<MutableRootShaderObject*>(object))
{
- setData(gfx::ShaderOffset(), srcObj->m_data.begin(), (size_t)srcObj->m_data.getCount()); // TODO: Change size_t to Count?
+ setData(
+ gfx::ShaderOffset(),
+ srcObj->m_data.begin(),
+ (size_t)srcObj->m_data.getCount()); // TODO: Change size_t to Count?
for (auto& kv : srcObj->m_objects)
{
ComPtr<IShaderObject> subObject;
@@ -1265,8 +1332,12 @@ Result ShaderTableBase::init(const IShaderTable::Desc& desc)
m_missShaderCount = desc.missShaderCount;
m_hitGroupCount = desc.hitGroupCount;
m_callableShaderCount = desc.callableShaderCount;
- m_shaderGroupNames.reserve(desc.hitGroupCount + desc.missShaderCount + desc.rayGenShaderCount + desc.callableShaderCount);
- m_recordOverwrites.reserve(desc.hitGroupCount + desc.missShaderCount + desc.rayGenShaderCount + desc.callableShaderCount);
+ m_shaderGroupNames.reserve(
+ desc.hitGroupCount + desc.missShaderCount + desc.rayGenShaderCount +
+ desc.callableShaderCount);
+ m_recordOverwrites.reserve(
+ desc.hitGroupCount + desc.missShaderCount + desc.rayGenShaderCount +
+ desc.callableShaderCount);
for (GfxIndex i = 0; i < desc.rayGenShaderCount; i++)
{
m_shaderGroupNames.add(desc.rayGenShaderEntryPointNames[i]);
@@ -1324,10 +1395,8 @@ bool isDepthFormat(Format format)
{
case Format::D16_UNORM:
case Format::D32_FLOAT:
- case Format::D32_FLOAT_S8_UINT:
- return true;
- default:
- return false;
+ case Format::D32_FLOAT_S8_UINT: return true;
+ default: return false;
}
}
@@ -1335,12 +1404,9 @@ bool isStencilFormat(Format format)
{
switch (format)
{
- case Format::D32_FLOAT_S8_UINT:
- return true;
- default:
- return false;
+ case Format::D32_FLOAT_S8_UINT: return true;
+ default: return false;
}
}
} // namespace gfx
-
diff --git a/tools/gfx/renderer-shared.h b/tools/gfx/renderer-shared.h
index 952beb2c1..72b35d8fa 100644
--- a/tools/gfx/renderer-shared.h
+++ b/tools/gfx/renderer-shared.h
@@ -1,12 +1,11 @@
#pragma once
-#include "slang-gfx.h"
-#include "slang-context.h"
#include "core/slang-basic.h"
#include "core/slang-com-object.h"
#include "core/slang-persistent-cache.h"
-
#include "resource-desc-utils.h"
+#include "slang-context.h"
+#include "slang-gfx.h"
namespace gfx
{
@@ -64,7 +63,7 @@ bool isGfxDebugLayerEnabled();
// If we know there is a cyclic reference between an API object and the device/pool that creates it,
// we can break the cycle when there is no longer any public references that come from `ComPtr`s to
// the API object, by turning the reference to the device object from the API object to a weak
-// reference.
+// reference.
// The following example illustrate how this mechanism works:
// Suppose we have
// ```
@@ -80,24 +79,25 @@ bool isGfxDebugLayerEnabled();
// device->m_currentResource = res;
// ```
// This setup is robust to any destruction ordering. If user releases reference to `device` first,
-// then the device object will not be freed yet, since there is still a strong reference to the device
-// implementation via `res->m_device`. Next when the user releases reference to `res`, the public
-// reference count to `res` via `ComPtr`s will go to 0, therefore triggering the call to
-// `res->m_device.breakStrongReference()`, releasing the remaining reference to device. This will cause
-// `device` to start destruction, which will release its strong reference to `res` during execution of
-// its destructor. Finally, this will triger the actual destruction of `res`.
-// On the other hand, if the user releases reference to `res` first, then the strong reference to `device`
-// will be broken immediately, but the actual destruction of `res` will not start. Next when the user
-// releases `device`, there will no longer be any other references to `device`, so the destruction of
-// `device` will start, causing the release of the internal reference to `res`, leading to its destruction.
-// Note that the above logic only works if it is known that there is a cyclic reference. If there are no
-// such cyclic reference, then it will be incorrect to break the strong reference to `IDevice` upon
-// public reference counter dropping to 0. This is because the actual destructor of `res` take place
-// after breaking the cycle, but if the resource's strong reference to the device is already the last reference,
-// turning that reference to weak reference will immediately trigger destruction of `device`, after which
-// we can no longer destruct `res` if the destructor needs `device`. Therefore we need to be careful
-// when using `BreakableReference`, and make sure we only call `breakStrongReference` only when it is known
-// that there is a cyclic reference. Luckily for all scenarios so far this is statically known.
+// then the device object will not be freed yet, since there is still a strong reference to the
+// device implementation via `res->m_device`. Next when the user releases reference to `res`, the
+// public reference count to `res` via `ComPtr`s will go to 0, therefore triggering the call to
+// `res->m_device.breakStrongReference()`, releasing the remaining reference to device. This will
+// cause `device` to start destruction, which will release its strong reference to `res` during
+// execution of its destructor. Finally, this will triger the actual destruction of `res`. On the
+// other hand, if the user releases reference to `res` first, then the strong reference to `device`
+// will be broken immediately, but the actual destruction of `res` will not start. Next when the
+// user releases `device`, there will no longer be any other references to `device`, so the
+// destruction of `device` will start, causing the release of the internal reference to `res`,
+// leading to its destruction. Note that the above logic only works if it is known that there is a
+// cyclic reference. If there are no such cyclic reference, then it will be incorrect to break the
+// strong reference to `IDevice` upon public reference counter dropping to 0. This is because the
+// actual destructor of `res` take place after breaking the cycle, but if the resource's strong
+// reference to the device is already the last reference, turning that reference to weak reference
+// will immediately trigger destruction of `device`, after which we can no longer destruct `res` if
+// the destructor needs `device`. Therefore we need to be careful when using `BreakableReference`,
+// and make sure we only call `breakStrongReference` only when it is known that there is a cyclic
+// reference. Luckily for all scenarios so far this is statically known.
template<typename T>
class BreakableReference
{
@@ -112,7 +112,11 @@ public:
BreakableReference(Slang::RefPtr<T> const& p) { *this = p; }
- void setWeakReference(T* p) { m_weakPtr = p; m_strongPtr = nullptr; }
+ void setWeakReference(T* p)
+ {
+ m_weakPtr = p;
+ m_strongPtr = nullptr;
+ }
T& operator*() const { return *get(); }
@@ -150,7 +154,7 @@ void returnComPtr(TInterface** outInterface, TImpl* rawPtr)
*outInterface = rawPtr;
}
-template <typename TInterface, typename TImpl>
+template<typename TInterface, typename TImpl>
void returnComPtr(TInterface** outInterface, const Slang::RefPtr<TImpl>& refPtr)
{
static_assert(
@@ -160,7 +164,7 @@ void returnComPtr(TInterface** outInterface, const Slang::RefPtr<TImpl>& refPtr)
*outInterface = refPtr.Ptr();
}
-template <typename TInterface, typename TImpl>
+template<typename TInterface, typename TImpl>
void returnComPtr(TInterface** outInterface, Slang::ComPtr<TImpl>& comPtr)
{
static_assert(
@@ -170,24 +174,28 @@ void returnComPtr(TInterface** outInterface, Slang::ComPtr<TImpl>& comPtr)
}
// Helpers for returning an object implementation as RefPtr.
-template <typename TDest, typename TImpl>
+template<typename TDest, typename TImpl>
void returnRefPtr(TDest** outPtr, Slang::RefPtr<TImpl>& refPtr)
{
static_assert(
- std::is_base_of<Slang::RefObject, TDest>::value, "TDest must be a non-interface type.");
+ std::is_base_of<Slang::RefObject, TDest>::value,
+ "TDest must be a non-interface type.");
static_assert(
- std::is_base_of<Slang::RefObject, TImpl>::value, "TImpl must be a non-interface type.");
+ std::is_base_of<Slang::RefObject, TImpl>::value,
+ "TImpl must be a non-interface type.");
*outPtr = refPtr.Ptr();
refPtr->addReference();
}
-template <typename TDest, typename TImpl>
+template<typename TDest, typename TImpl>
void returnRefPtrMove(TDest** outPtr, Slang::RefPtr<TImpl>& refPtr)
{
static_assert(
- std::is_base_of<Slang::RefObject, TDest>::value, "TDest must be a non-interface type.");
+ std::is_base_of<Slang::RefObject, TDest>::value,
+ "TDest must be a non-interface type.");
static_assert(
- std::is_base_of<Slang::RefObject, TImpl>::value, "TImpl must be a non-interface type.");
+ std::is_base_of<Slang::RefObject, TImpl>::value,
+ "TImpl must be a non-interface type.");
*outPtr = refPtr.detach();
}
@@ -199,6 +207,7 @@ class FenceBase : public IFence, public Slang::ComObject
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
IFence* getInterface(const Slang::Guid& guid);
+
protected:
InteropHandle sharedHandle = {};
};
@@ -209,13 +218,18 @@ public:
/// Get the type
SLANG_FORCE_INLINE IResource::Type getType() const { return m_type; }
/// True if it's a texture derived type
- SLANG_FORCE_INLINE bool isTexture() const { return int(m_type) >= int(IResource::Type::Texture1D); }
+ SLANG_FORCE_INLINE bool isTexture() const
+ {
+ return int(m_type) >= int(IResource::Type::Texture1D);
+ }
/// True if it's a buffer derived type
SLANG_FORCE_INLINE bool isBuffer() const { return m_type == IResource::Type::Buffer; }
+
protected:
Resource(IResource::Type type)
: m_type(type)
- {}
+ {
+ }
IResource::Type m_type;
InteropHandle sharedHandle = {};
@@ -233,14 +247,16 @@ public:
/// Ctor
BufferResource(const Desc& desc)
- : Parent(Type::Buffer)
- , m_desc(desc)
- {}
+ : Parent(Type::Buffer), m_desc(desc)
+ {
+ }
virtual SLANG_NO_THROW IResource::Type SLANG_MCALL getType() SLANG_OVERRIDE;
virtual SLANG_NO_THROW IBufferResource::Desc* SLANG_MCALL getDesc() SLANG_OVERRIDE;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) SLANG_OVERRIDE;
- virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle)
+ SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle)
+ SLANG_OVERRIDE;
virtual SLANG_NO_THROW Result SLANG_MCALL setDebugName(const char* name) override
{
@@ -267,14 +283,16 @@ public:
/// Ctor
TextureResource(const Desc& desc)
- : Parent(desc.type)
- , m_desc(desc)
- {}
+ : Parent(desc.type), m_desc(desc)
+ {
+ }
virtual SLANG_NO_THROW IResource::Type SLANG_MCALL getType() SLANG_OVERRIDE;
virtual SLANG_NO_THROW ITextureResource::Desc* SLANG_MCALL getDesc() SLANG_OVERRIDE;
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) SLANG_OVERRIDE;
- virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle)
+ SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle)
+ SLANG_OVERRIDE;
virtual SLANG_NO_THROW Result SLANG_MCALL setDebugName(const char* name) override
{
@@ -291,11 +309,10 @@ protected:
};
class ResourceViewInternalBase : public Slang::ComObject
-{};
+{
+};
-class ResourceViewBase
- : public IResourceView
- , public ResourceViewInternalBase
+class ResourceViewBase : public IResourceView, public ResourceViewInternalBase
{
public:
Desc m_desc = {};
@@ -313,9 +330,7 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
};
-class AccelerationStructureBase
- : public IAccelerationStructure
- , public ResourceViewInternalBase
+class AccelerationStructureBase : public IAccelerationStructure, public ResourceViewInternalBase
{
public:
IResourceView::Desc m_desc = {};
@@ -343,7 +358,8 @@ struct ExtendedShaderObjectTypeList
void add(const ExtendedShaderObjectType& component)
{
componentIDs.add(component.componentID);
- components.add(slang::SpecializationArg{ slang::SpecializationArg::Kind::Type, {component.slangType} });
+ components.add(
+ slang::SpecializationArg{slang::SpecializationArg::Kind::Type, {component.slangType}});
}
void addRange(const ExtendedShaderObjectTypeList& list)
{
@@ -364,16 +380,13 @@ struct ExtendedShaderObjectTypeList
componentIDs.clear();
components.clear();
}
- Slang::Index getCount() const
- {
- return componentIDs.getCount();
- }
+ Slang::Index getCount() const { return componentIDs.getCount(); }
};
-struct ExtendedShaderObjectTypeListObject
- : public ExtendedShaderObjectTypeList
- , public Slang::RefObject
-{};
+struct ExtendedShaderObjectTypeListObject : public ExtendedShaderObjectTypeList,
+ public Slang::RefObject
+{
+};
class ShaderObjectLayoutBase : public Slang::RefObject
{
@@ -426,8 +439,7 @@ public:
case slang::TypeReflection::Kind::ParameterBlock:
typeLayout = typeLayout->getElementTypeLayout();
continue;
- default:
- return typeLayout;
+ default: return typeLayout;
}
}
}
@@ -436,17 +448,14 @@ public:
public:
RendererBase* getDevice() { return m_renderer; }
- slang::TypeLayoutReflection* getElementTypeLayout()
- {
- return m_elementTypeLayout;
- }
+ slang::TypeLayoutReflection* getElementTypeLayout() { return m_elementTypeLayout; }
- ShaderComponentID getComponentID()
- {
- return m_componentID;
- }
+ ShaderComponentID getComponentID() { return m_componentID; }
- void initBase(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* elementTypeLayout);
+ void initBase(
+ RendererBase* renderer,
+ slang::ISession* session,
+ slang::TypeLayoutReflection* elementTypeLayout);
};
class SimpleShaderObjectData
@@ -473,8 +482,8 @@ public:
};
bool _doesValueFitInExistentialPayload(
- slang::TypeLayoutReflection* concreteTypeLayout,
- slang::TypeLayoutReflection* existentialFieldLayout);
+ slang::TypeLayoutReflection* concreteTypeLayout,
+ slang::TypeLayoutReflection* existentialFieldLayout);
class ShaderObjectBase : public IShaderObject, public Slang::ComObject
{
@@ -483,9 +492,10 @@ public:
IShaderObject* getInterface(const Slang::Guid& guid)
{
if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_IShaderObject)
- return static_cast<IShaderObject *>(this);
+ return static_cast<IShaderObject*>(this);
return nullptr;
}
+
protected:
// A strong reference to `IDevice` to make sure the weak device reference in
// `ShaderObjectLayout`s are valid whenever they might be used.
@@ -495,23 +505,23 @@ protected:
Slang::RefPtr<ShaderObjectLayoutBase> m_layout = nullptr;
// The specialized shader object type.
- ExtendedShaderObjectType shaderObjectType = { nullptr, kInvalidComponentID };
+ ExtendedShaderObjectType shaderObjectType = {nullptr, kInvalidComponentID};
Result _getSpecializedShaderObjectType(ExtendedShaderObjectType* outType);
slang::TypeLayoutReflection* _getElementTypeLayout()
{
return m_layout->getElementTypeLayout();
}
+
public:
void breakStrongReferenceToDevice() { m_device.breakStrongReference(); }
+
public:
- ShaderComponentID getComponentID()
- {
- return shaderObjectType.componentID;
- }
+ ShaderComponentID getComponentID() { return shaderObjectType.componentID; }
- // Get the final type this shader object represents. If the shader object's type has existential fields,
- // this function will return a specialized type using the bound sub-objects' type as specialization argument.
+ // Get the final type this shader object represents. If the shader object's type has existential
+ // fields, this function will return a specialized type using the bound sub-objects' type as
+ // specialization argument.
virtual Result getSpecializedShaderObjectType(ExtendedShaderObjectType* outType);
virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) = 0;
@@ -546,22 +556,20 @@ public:
return m_layout->getContainerType();
}
- virtual SLANG_NO_THROW Result SLANG_MCALL getCurrentVersion(
- ITransientResourceHeap* transientHeap, IShaderObject** outObject) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ getCurrentVersion(ITransientResourceHeap* transientHeap, IShaderObject** outObject) override
{
returnComPtr(outObject, this);
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- copyFrom(IShaderObject* object, ITransientResourceHeap* transientHeap);
+ copyFrom(IShaderObject* object, ITransientResourceHeap* transientHeap);
- virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override
- {
- return nullptr;
- }
+ virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override { return nullptr; }
- virtual SLANG_NO_THROW Result SLANG_MCALL setConstantBufferOverride(IBufferResource* outBuffer) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ setConstantBufferOverride(IBufferResource* outBuffer) override
{
return SLANG_E_NOT_AVAILABLE;
}
@@ -588,7 +596,7 @@ public:
size_t getBufferSize() { return (size_t)m_data.getCount(); } // TODO: Change size_t to Count?
virtual SLANG_NO_THROW Result SLANG_MCALL
- getObject(ShaderOffset const& offset, IShaderObject** outObject) SLANG_OVERRIDE
+ getObject(ShaderOffset const& offset, IShaderObject** outObject) SLANG_OVERRIDE
{
SLANG_ASSERT(outObject);
if (offset.bindingRangeIndex < 0)
@@ -612,7 +620,7 @@ public:
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- setObject(ShaderOffset const& offset, IShaderObject* object) SLANG_OVERRIDE
+ setObject(ShaderOffset const& offset, IShaderObject* object) SLANG_OVERRIDE
{
auto layout = getLayout();
auto subObject = static_cast<TShaderObjectImpl*>(object);
@@ -741,7 +749,9 @@ public:
// its bytes into that area.
//
setData(
- payloadOffset, subObject->m_data.getBuffer(), subObject->m_data.getCount());
+ payloadOffset,
+ subObject->m_data.getBuffer(),
+ subObject->m_data.getCount());
}
else
{
@@ -816,7 +826,9 @@ public:
m_userProvidedSpecializationArgs[objectIndex]->clear();
}
SLANG_RETURN_ON_FAIL(getExtendedShaderTypeListFromSpecializationArgs(
- *m_userProvidedSpecializationArgs[objectIndex], args, count));
+ *m_userProvidedSpecializationArgs[objectIndex],
+ args,
+ count));
return SLANG_OK;
}
@@ -863,47 +875,40 @@ public:
Slang::Result compileShaders(RendererBase* device);
virtual Slang::Result createShaderModule(
- slang::EntryPointReflection* entryPointInfo, Slang::ComPtr<ISlangBlob> kernelCode);
+ slang::EntryPointReflection* entryPointInfo,
+ Slang::ComPtr<ISlangBlob> kernelCode);
- virtual SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL findTypeByName(const char* name) override
+ virtual SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL
+ findTypeByName(const char* name) override
{
return linkedProgram->getLayout()->findTypeByName(name);
}
bool isMeshShaderProgram() const;
-
};
-class InputLayoutBase
- : public IInputLayout
- , public Slang::ComObject
+class InputLayoutBase : public IInputLayout, public Slang::ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
IInputLayout* getInterface(const Slang::Guid& guid);
};
-class FramebufferLayoutBase
- : public IFramebufferLayout
- , public Slang::ComObject
+class FramebufferLayoutBase : public IFramebufferLayout, public Slang::ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
IFramebufferLayout* getInterface(const Slang::Guid& guid);
};
-class FramebufferBase
- : public IFramebuffer
- , public Slang::ComObject
+class FramebufferBase : public IFramebuffer, public Slang::ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
IFramebuffer* getInterface(const Slang::Guid& guid);
};
-class QueryPoolBase
- : public IQueryPool
- , public Slang::ComObject
+class QueryPoolBase : public IQueryPool, public Slang::ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -988,9 +993,7 @@ struct OwnedRayTracingPipelineStateDesc
}
};
-class PipelineStateBase
- : public IPipelineState
- , public Slang::ComObject
+class PipelineStateBase : public IPipelineState, public Slang::ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -1006,10 +1009,8 @@ public:
{
switch (type)
{
- case PipelineType::Compute:
- return static_cast<ShaderProgramBase*>(compute.program);
- case PipelineType::Graphics:
- return static_cast<ShaderProgramBase*>(graphics.program);
+ case PipelineType::Compute: return static_cast<ShaderProgramBase*>(compute.program);
+ case PipelineType::Graphics: return static_cast<ShaderProgramBase*>(graphics.program);
case PipelineType::RayTracing:
return static_cast<ShaderProgramBase*>(rayTracing.program);
}
@@ -1030,7 +1031,8 @@ public:
// pipeline cannot be used directly and must be specialized first.
bool isSpecializable = false;
Slang::RefPtr<ShaderProgramBase> m_program;
- template <typename TProgram> TProgram* getProgram()
+ template<typename TProgram>
+ TProgram* getProgram()
{
return static_cast<TProgram*>(m_program.Ptr());
}
@@ -1047,10 +1049,7 @@ struct ComponentKey
Slang::UnownedStringSlice typeName;
Slang::ShortList<ShaderComponentID> specializationArgs;
Slang::HashCode hash;
- Slang::HashCode getHashCode() const
- {
- return hash;
- }
+ Slang::HashCode getHashCode() const { return hash; }
void updateHash()
{
hash = typeName.getHashCode();
@@ -1064,10 +1063,7 @@ struct PipelineKey
PipelineStateBase* pipeline;
Slang::ShortList<ShaderComponentID> specializationArgs;
Slang::HashCode hash;
- Slang::HashCode getHashCode() const
- {
- return hash;
- }
+ Slang::HashCode getHashCode() const { return hash; }
void updateHash()
{
hash = Slang::getHashCode(pipeline);
@@ -1094,10 +1090,7 @@ struct OwningComponentKey
Slang::String typeName;
Slang::ShortList<ShaderComponentID> specializationArgs;
Slang::HashCode hash;
- Slang::HashCode getHashCode() const
- {
- return hash;
- }
+ Slang::HashCode getHashCode() const { return hash; }
template<typename KeyType>
bool operator==(const KeyType& other) const
{
@@ -1153,11 +1146,9 @@ public:
static uint64_t version = 1;
return version;
}
- TransientResourceHeapBase()
- {
- m_version = getVersionCounter()++;
- }
+ TransientResourceHeapBase() { m_version = getVersionCounter()++; }
virtual ~TransientResourceHeapBase() {}
+
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
ITransientResourceHeap* getInterface(const Slang::Guid& guid)
@@ -1172,9 +1163,7 @@ public:
static const int kRayGenRecordSize = 64; // D3D12_RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT;
-class ShaderTableBase
- : public IShaderTable
- , public Slang::ComObject
+class ShaderTableBase : public IShaderTable, public Slang::ComObject
{
public:
Slang::List<Slang::String> m_shaderGroupNames;
@@ -1222,19 +1211,24 @@ public:
class RendererBase : public IDevice, public IShaderCache, public Slang::ComObject
{
friend class ShaderObjectBase;
+
public:
SLANG_COM_OBJECT_IUNKNOWN_ADD_REF
SLANG_COM_OBJECT_IUNKNOWN_RELEASE
- virtual SLANG_NO_THROW Result SLANG_MCALL getNativeDeviceHandles(InteropHandles* outHandles) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW Result SLANG_MCALL getNativeDeviceHandles(InteropHandles* outHandles)
+ SLANG_OVERRIDE;
virtual SLANG_NO_THROW Result SLANG_MCALL getFeatures(
- const char** outFeatures, Size bufferSize, GfxCount* outFeatureCount) SLANG_OVERRIDE;
+ const char** outFeatures,
+ Size bufferSize,
+ GfxCount* outFeatureCount) SLANG_OVERRIDE;
virtual SLANG_NO_THROW bool SLANG_MCALL hasFeature(const char* featureName) SLANG_OVERRIDE;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL getSlangSession(slang::ISession** outSlangSession) SLANG_OVERRIDE;
+ getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL getSlangSession(slang::ISession** outSlangSession)
+ SLANG_OVERRIDE;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject) SLANG_OVERRIDE;
+ queryInterface(SlangUUID const& uuid, void** outObject) SLANG_OVERRIDE;
IDevice* getInterface(const Slang::Guid& guid);
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureFromNativeHandle(
@@ -1286,10 +1280,12 @@ public:
IShaderObject** outObject) SLANG_OVERRIDE;
virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject) override;
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObjectFromTypeLayout(
- slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject) override;
+ slang::TypeLayoutReflection* typeLayout,
+ IShaderObject** outObject) override;
// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE for platforms
// without ray tracing support.
@@ -1306,28 +1302,35 @@ public:
// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE for platforms
// without ray tracing support.
virtual SLANG_NO_THROW Result SLANG_MCALL
- createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outTable) override;
+ createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outTable) override;
// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE for platforms
// without ray tracing support.
virtual SLANG_NO_THROW Result SLANG_MCALL createRayTracingPipelineState(
- const RayTracingPipelineStateDesc& desc, IPipelineState** outState) override;
+ const RayTracingPipelineStateDesc& desc,
+ IPipelineState** outState) override;
// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE.
virtual SLANG_NO_THROW Result SLANG_MCALL
- createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
+ 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;
+ createFence(const IFence::Desc& desc, IFence** outFence) override;
// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE.
- virtual SLANG_NO_THROW Result SLANG_MCALL
- waitForFences(GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL waitForFences(
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* fenceValues,
+ bool waitForAll,
+ uint64_t timeout) override;
// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE.
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureAllocationInfo(
- const ITextureResource::Desc& desc, Size* outSize, Size* outAlignment) override;
+ const ITextureResource::Desc& desc,
+ Size* outSize,
+ Size* outAlignment) override;
// Provides a default implementation that returns SLANG_E_NOT_AVAILABLE.
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureRowAlignment(size_t* outAlignment) override;
@@ -1340,10 +1343,10 @@ public:
slang::IBlob** outDiagnostics = nullptr);
Result getShaderObjectLayout(
- slang::ISession* session,
- slang::TypeReflection* type,
- ShaderObjectContainerType container,
- ShaderObjectLayoutBase** outLayout);
+ slang::ISession* session,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType container,
+ ShaderObjectLayoutBase** outLayout);
Result getShaderObjectLayout(
slang::ISession* session,
@@ -1352,9 +1355,9 @@ public:
public:
ExtendedShaderObjectTypeList specializationArgs;
- // Given current pipeline and root shader object binding, generate and bind a specialized pipeline if necessary.
- // The newly specialized pipeline is held alive by the pipeline cache so users of `outNewPipeline` do not
- // need to maintain its lifespan.
+ // Given current pipeline and root shader object binding, generate and bind a specialized
+ // pipeline if necessary. The newly specialized pipeline is held alive by the pipeline cache so
+ // users of `outNewPipeline` do not need to maintain its lifespan.
Result maybeSpecializePipeline(
PipelineStateBase* currentPipeline,
ShaderObjectBase* rootObject,
@@ -1368,29 +1371,33 @@ public:
virtual Result createShaderObject(
ShaderObjectLayoutBase* layout,
- IShaderObject** outObject) = 0;
+ IShaderObject** outObject) = 0;
virtual Result createMutableShaderObject(
ShaderObjectLayoutBase* layout,
IShaderObject** outObject) = 0;
- public:
+public:
// IShaderCache interface
virtual SLANG_NO_THROW Result SLANG_MCALL clearShaderCache() SLANG_OVERRIDE;
- virtual SLANG_NO_THROW Result SLANG_MCALL getShaderCacheStats(ShaderCacheStats* outStats) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW Result SLANG_MCALL getShaderCacheStats(ShaderCacheStats* outStats)
+ SLANG_OVERRIDE;
virtual SLANG_NO_THROW Result SLANG_MCALL resetShaderCacheStats() SLANG_OVERRIDE;
protected:
virtual SLANG_NO_THROW SlangResult SLANG_MCALL initialize(const Desc& desc);
+
protected:
Slang::List<Slang::String> m_features;
+
public:
SlangContext slangContext;
ShaderCache shaderCache;
Slang::RefPtr<Slang::PersistentCache> persistentShaderCache;
- Slang::Dictionary<slang::TypeLayoutReflection*, Slang::RefPtr<ShaderObjectLayoutBase>> m_shaderObjectLayoutCache;
+ Slang::Dictionary<slang::TypeLayoutReflection*, Slang::RefPtr<ShaderObjectLayoutBase>>
+ m_shaderObjectLayoutCache;
Slang::ComPtr<IPipelineCreationAPIDispatcher> m_pipelineCreationAPIDispatcher;
};
@@ -1416,7 +1423,8 @@ inline IDebugCallback* getDebugCallback()
//--------------------------------------------------------------------------------
template<typename TShaderObjectImpl, typename TShaderObjectLayoutImpl, typename TShaderObjectData>
-void ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderObjectData>::setSpecializationArgsForContainerElement(ExtendedShaderObjectTypeList& specializationArgs)
+void ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderObjectData>::
+ setSpecializationArgsForContainerElement(ExtendedShaderObjectTypeList& specializationArgs)
{
// Compute specialization args for the structured buffer object.
// If we haven't filled anything to `m_structuredBufferSpecializationArgs` yet,
@@ -1451,10 +1459,11 @@ void ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderObj
//--------------------------------------------------------------------------------
template<typename TShaderObjectImpl, typename TShaderObjectLayoutImpl, typename TShaderObjectData>
-Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderObjectData>::getExtendedShaderTypeListFromSpecializationArgs(
- ExtendedShaderObjectTypeList& list,
- const slang::SpecializationArg* args,
- uint32_t count)
+Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderObjectData>::
+ getExtendedShaderTypeListFromSpecializationArgs(
+ ExtendedShaderObjectTypeList& list,
+ const slang::SpecializationArg* args,
+ uint32_t count)
{
auto device = getRenderer();
for (uint32_t i = 0; i < count; i++)
@@ -1462,13 +1471,13 @@ Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderO
gfx::ExtendedShaderObjectType extendedType;
switch (args[i].kind)
{
- case slang::SpecializationArg::Kind::Type:
- extendedType.slangType = args[i].type;
- extendedType.componentID = device->shaderCache.getComponentId(args[i].type);
- break;
- default:
- SLANG_ASSERT(false && "Unexpected specialization argument kind.");
- return SLANG_FAIL;
+ case slang::SpecializationArg::Kind::Type:
+ extendedType.slangType = args[i].type;
+ extendedType.componentID = device->shaderCache.getComponentId(args[i].type);
+ break;
+ default:
+ SLANG_ASSERT(false && "Unexpected specialization argument kind.");
+ return SLANG_FAIL;
}
list.add(extendedType);
}
@@ -1477,7 +1486,8 @@ Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderO
//--------------------------------------------------------------------------------
template<typename TShaderObjectImpl, typename TShaderObjectLayoutImpl, typename TShaderObjectData>
-Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderObjectData>::collectSpecializationArgs(ExtendedShaderObjectTypeList& args)
+Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderObjectData>::
+ collectSpecializationArgs(ExtendedShaderObjectTypeList& args)
{
if (m_layout->getContainerType() != ShaderObjectContainerType::None)
{
@@ -1494,18 +1504,17 @@ Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderO
Slang::Index subObjectRangeCount = subObjectRanges.getCount();
for (Slang::Index subObjectRangeIndex = 0; subObjectRangeIndex < subObjectRangeCount;
- subObjectRangeIndex++)
+ subObjectRangeIndex++)
{
auto const& subObjectRange = subObjectRanges[subObjectRangeIndex];
- auto const& bindingRange =
- getLayout()->getBindingRange(subObjectRange.bindingRangeIndex);
+ auto const& bindingRange = getLayout()->getBindingRange(subObjectRange.bindingRangeIndex);
Slang::Index oldArgsCount = args.getCount();
Slang::Index count = bindingRange.count;
for (Slang::Index subObjectIndexInRange = 0; subObjectIndexInRange < count;
- subObjectIndexInRange++)
+ subObjectIndexInRange++)
{
ExtendedShaderObjectTypeList typeArgs;
Slang::Index objectIndex = bindingRange.subObjectIndex + subObjectIndexInRange;
@@ -1523,7 +1532,7 @@ Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderO
switch (bindingRange.bindingType)
{
- case slang::BindingType::ExistentialValue:
+ case slang::BindingType::ExistentialValue:
{
// A binding type of `ExistentialValue` means the sub-object represents a
// interface-typed field. In this case the specialization argument for this
@@ -1539,25 +1548,26 @@ Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderO
typeArgs.add(specializedSubObjType);
break;
}
- case slang::BindingType::ParameterBlock:
- case slang::BindingType::ConstantBuffer:
- case slang::BindingType::RawBuffer:
- case slang::BindingType::MutableRawBuffer:
- // If the field's type is `ParameterBlock<IFoo>`, we want to pull in the type argument
- // from the sub object for specialization.
- if (bindingRange.isSpecializable)
- {
- ExtendedShaderObjectType specializedSubObjType;
- SLANG_RETURN_ON_FAIL(
- subObject->getSpecializedShaderObjectType(&specializedSubObjType));
- typeArgs.add(specializedSubObjType);
- }
+ case slang::BindingType::ParameterBlock:
+ case slang::BindingType::ConstantBuffer:
+ case slang::BindingType::RawBuffer:
+ case slang::BindingType::MutableRawBuffer:
+ // If the field's type is `ParameterBlock<IFoo>`, we want to pull in the type
+ // argument from the sub object for specialization.
+ if (bindingRange.isSpecializable)
+ {
+ ExtendedShaderObjectType specializedSubObjType;
+ SLANG_RETURN_ON_FAIL(
+ subObject->getSpecializedShaderObjectType(&specializedSubObjType));
+ typeArgs.add(specializedSubObjType);
+ }
- // If field's type is `ParameterBlock<SomeStruct>` or `ConstantBuffer<SomeStruct>`, where
- // `SomeStruct` is a struct type (not directly an interface type), we need to recursively
- // collect the specialization arguments from the bound sub object.
- SLANG_RETURN_ON_FAIL(subObject->collectSpecializationArgs(typeArgs));
- break;
+ // If field's type is `ParameterBlock<SomeStruct>` or
+ // `ConstantBuffer<SomeStruct>`, where `SomeStruct` is a struct type (not
+ // directly an interface type), we need to recursively collect the
+ // specialization arguments from the bound sub object.
+ SLANG_RETURN_ON_FAIL(subObject->collectSpecializationArgs(typeArgs));
+ break;
}
auto addedTypeArgCountForCurrentRange = args.getCount() - oldArgsCount;
@@ -1586,4 +1596,4 @@ Result ShaderObjectBaseImpl<TShaderObjectImpl, TShaderObjectLayoutImpl, TShaderO
}
return SLANG_OK;
}
-}
+} // namespace gfx
diff --git a/tools/gfx/resource-desc-utils.cpp b/tools/gfx/resource-desc-utils.cpp
index b36e765e5..ab20c78a8 100644
--- a/tools/gfx/resource-desc-utils.cpp
+++ b/tools/gfx/resource-desc-utils.cpp
@@ -22,22 +22,14 @@ Format srgbToLinearFormat(Format format)
{
switch (format)
{
- case Format::BC1_UNORM_SRGB:
- return Format::BC1_UNORM;
- case Format::BC2_UNORM_SRGB:
- return Format::BC2_UNORM;
- case Format::BC3_UNORM_SRGB:
- return Format::BC3_UNORM;
- case Format::BC7_UNORM_SRGB:
- return Format::BC7_UNORM;
- case Format::B8G8R8A8_UNORM_SRGB:
- return Format::B8G8R8A8_UNORM;
- case Format::B8G8R8X8_UNORM_SRGB:
- return Format::B8G8R8X8_UNORM;
- case Format::R8G8B8A8_UNORM_SRGB:
- return Format::R8G8B8A8_UNORM;
- default:
- return format;
+ case Format::BC1_UNORM_SRGB: return Format::BC1_UNORM;
+ case Format::BC2_UNORM_SRGB: return Format::BC2_UNORM;
+ case Format::BC3_UNORM_SRGB: return Format::BC3_UNORM;
+ case Format::BC7_UNORM_SRGB: return Format::BC7_UNORM;
+ case Format::B8G8R8A8_UNORM_SRGB: return Format::B8G8R8A8_UNORM;
+ case Format::B8G8R8X8_UNORM_SRGB: return Format::B8G8R8X8_UNORM;
+ case Format::R8G8B8A8_UNORM_SRGB: return Format::R8G8B8A8_UNORM;
+ default: return format;
}
}
-}
+} // namespace gfx
diff --git a/tools/gfx/resource-desc-utils.h b/tools/gfx/resource-desc-utils.h
index 25dcc43b6..cdfeb4c25 100644
--- a/tools/gfx/resource-desc-utils.h
+++ b/tools/gfx/resource-desc-utils.h
@@ -1,7 +1,7 @@
#pragma once
-#include "slang-gfx.h"
#include "core/slang-math.h"
+#include "slang-gfx.h"
namespace gfx
{
@@ -35,12 +35,9 @@ inline int calcEffectiveArraySize(const ITextureResource::Desc& desc)
{
return arrSize;
}
- case IResource::Type::TextureCube:
- return arrSize * 6;
- case IResource::Type::Texture3D:
- return 1;
- default:
- return 0;
+ case IResource::Type::TextureCube: return arrSize * 6;
+ case IResource::Type::Texture3D: return 1;
+ default: return 0;
}
}
@@ -49,8 +46,7 @@ inline int calcMaxDimension(ITextureResource::Extents size, IResource::Type type
{
switch (type)
{
- case IResource::Type::Texture1D:
- return size.width;
+ case IResource::Type::Texture1D: return size.width;
case IResource::Type::Texture3D:
return Slang::Math::Max(Slang::Math::Max(size.width, size.height), size.depth);
case IResource::Type::TextureCube: // fallthru
@@ -58,8 +54,7 @@ inline int calcMaxDimension(ITextureResource::Extents size, IResource::Type type
{
return Slang::Math::Max(size.width, size.height);
}
- default:
- return 0;
+ default: return 0;
}
}
@@ -89,8 +84,7 @@ inline int calcNumSubResources(const ITextureResource::Desc& desc)
// There are 6 faces to a cubemap
return numMipMaps * arrSize * 6;
}
- default:
- return 0;
+ default: return 0;
}
}
@@ -99,4 +93,4 @@ ITextureResource::Desc fixupTextureDesc(const ITextureResource::Desc& desc);
Format srgbToLinearFormat(Format format);
-}
+} // namespace gfx
diff --git a/tools/gfx/simple-render-pass-layout.h b/tools/gfx/simple-render-pass-layout.h
index ae3ef1166..8ac41de0c 100644
--- a/tools/gfx/simple-render-pass-layout.h
+++ b/tools/gfx/simple-render-pass-layout.h
@@ -5,16 +5,14 @@
// desc value. Used by targets that does not expose an API object for the render pass
// concept.
-#include "slang-gfx.h"
-#include "core/slang-com-object.h"
#include "core/slang-basic.h"
+#include "core/slang-com-object.h"
+#include "slang-gfx.h"
namespace gfx
{
-class SimpleRenderPassLayout
- : public IRenderPassLayout
- , public Slang::ComObject
+class SimpleRenderPassLayout : public IRenderPassLayout, public Slang::ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -27,4 +25,4 @@ public:
void init(const IRenderPassLayout::Desc& desc);
};
-}
+} // namespace gfx
diff --git a/tools/gfx/simple-transient-resource-heap.h b/tools/gfx/simple-transient-resource-heap.h
index 4e3a04094..1a7261481 100644
--- a/tools/gfx/simple-transient-resource-heap.h
+++ b/tools/gfx/simple-transient-resource-heap.h
@@ -22,7 +22,8 @@ public:
m_device = device;
IBufferResource::Desc bufferDesc = {};
bufferDesc.type = IResource::Type::Buffer;
- bufferDesc.allowedStates = ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
+ bufferDesc.allowedStates =
+ ResourceStateSet(ResourceState::ConstantBuffer, ResourceState::CopyDestination);
bufferDesc.defaultState = ResourceState::ConstantBuffer;
bufferDesc.sizeInBytes = desc.constantBufferSize;
bufferDesc.memoryType = MemoryType::Upload;
@@ -31,7 +32,7 @@ public:
return SLANG_OK;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandBuffer(ICommandBuffer** outCommandBuffer) override
+ createCommandBuffer(ICommandBuffer** outCommandBuffer) override
{
Slang::RefPtr<TCommandBuffer> newCmdBuffer = new TCommandBuffer();
newCmdBuffer->init(m_device, this);
@@ -45,4 +46,4 @@ public:
return SLANG_OK;
}
};
-}
+} // namespace gfx
diff --git a/tools/gfx/slang-context.h b/tools/gfx/slang-context.h
index 79f39c3e6..719c70b50 100644
--- a/tools/gfx/slang-context.h
+++ b/tools/gfx/slang-context.h
@@ -1,67 +1,69 @@
#pragma once
-#include "slang-gfx.h"
#include "core/slang-basic.h"
+#include "slang-gfx.h"
namespace gfx
{
- class SlangContext
+class SlangContext
+{
+public:
+ Slang::ComPtr<slang::IGlobalSession> globalSession;
+ Slang::ComPtr<slang::ISession> session;
+ Result initialize(
+ const gfx::IDevice::SlangDesc& desc,
+ uint32_t extendedDescCount,
+ void** extendedDescs,
+ SlangCompileTarget compileTarget,
+ const char* defaultProfileName,
+ Slang::ConstArrayView<slang::PreprocessorMacroDesc> additionalMacros)
{
- public:
- Slang::ComPtr<slang::IGlobalSession> globalSession;
- Slang::ComPtr<slang::ISession> session;
- Result initialize(const gfx::IDevice::SlangDesc& desc,
- uint32_t extendedDescCount,
- void** extendedDescs,
- SlangCompileTarget compileTarget,
- const char* defaultProfileName,
- Slang::ConstArrayView<slang::PreprocessorMacroDesc> additionalMacros)
+ if (desc.slangGlobalSession)
{
- if (desc.slangGlobalSession)
- {
- globalSession = desc.slangGlobalSession;
- }
- else
- {
- SLANG_RETURN_ON_FAIL(slang::createGlobalSession(globalSession.writeRef()));
- }
+ globalSession = desc.slangGlobalSession;
+ }
+ else
+ {
+ SLANG_RETURN_ON_FAIL(slang::createGlobalSession(globalSession.writeRef()));
+ }
- slang::SessionDesc slangSessionDesc = {};
- slangSessionDesc.defaultMatrixLayoutMode = desc.defaultMatrixLayoutMode;
- slangSessionDesc.searchPathCount = desc.searchPathCount;
- slangSessionDesc.searchPaths = desc.searchPaths;
- slangSessionDesc.preprocessorMacroCount = desc.preprocessorMacroCount + additionalMacros.getCount();
- Slang::List<slang::PreprocessorMacroDesc> macros;
- macros.addRange(desc.preprocessorMacros, desc.preprocessorMacroCount);
- macros.addRange(additionalMacros.getBuffer(), additionalMacros.getCount());
- slangSessionDesc.preprocessorMacros = macros.getBuffer();
- slang::TargetDesc targetDesc = {};
- targetDesc.format = compileTarget;
- auto targetProfile = desc.targetProfile;
- if (targetProfile == nullptr)
- targetProfile = defaultProfileName;
- targetDesc.profile = globalSession->findProfile(targetProfile);
- targetDesc.floatingPointMode = desc.floatingPointMode;
- targetDesc.lineDirectiveMode = desc.lineDirectiveMode;
- targetDesc.flags = desc.targetFlags;
- targetDesc.forceGLSLScalarBufferLayout = true;
+ slang::SessionDesc slangSessionDesc = {};
+ slangSessionDesc.defaultMatrixLayoutMode = desc.defaultMatrixLayoutMode;
+ slangSessionDesc.searchPathCount = desc.searchPathCount;
+ slangSessionDesc.searchPaths = desc.searchPaths;
+ slangSessionDesc.preprocessorMacroCount =
+ desc.preprocessorMacroCount + additionalMacros.getCount();
+ Slang::List<slang::PreprocessorMacroDesc> macros;
+ macros.addRange(desc.preprocessorMacros, desc.preprocessorMacroCount);
+ macros.addRange(additionalMacros.getBuffer(), additionalMacros.getCount());
+ slangSessionDesc.preprocessorMacros = macros.getBuffer();
+ slang::TargetDesc targetDesc = {};
+ targetDesc.format = compileTarget;
+ auto targetProfile = desc.targetProfile;
+ if (targetProfile == nullptr)
+ targetProfile = defaultProfileName;
+ targetDesc.profile = globalSession->findProfile(targetProfile);
+ targetDesc.floatingPointMode = desc.floatingPointMode;
+ targetDesc.lineDirectiveMode = desc.lineDirectiveMode;
+ targetDesc.flags = desc.targetFlags;
+ targetDesc.forceGLSLScalarBufferLayout = true;
- slangSessionDesc.targets = &targetDesc;
- slangSessionDesc.targetCount = 1;
+ slangSessionDesc.targets = &targetDesc;
+ slangSessionDesc.targetCount = 1;
- for (uint32_t i = 0; i < extendedDescCount; i++)
+ for (uint32_t i = 0; i < extendedDescCount; i++)
+ {
+ if ((*(StructType*)extendedDescs[i]) == StructType::SlangSessionExtendedDesc)
{
- if ((*(StructType*)extendedDescs[i]) == StructType::SlangSessionExtendedDesc)
- {
- auto extDesc = (SlangSessionExtendedDesc*)extendedDescs[i];
- slangSessionDesc.compilerOptionEntryCount = extDesc->compilerOptionEntryCount;
- slangSessionDesc.compilerOptionEntries = extDesc->compilerOptionEntries;
- break;
- }
+ auto extDesc = (SlangSessionExtendedDesc*)extendedDescs[i];
+ slangSessionDesc.compilerOptionEntryCount = extDesc->compilerOptionEntryCount;
+ slangSessionDesc.compilerOptionEntries = extDesc->compilerOptionEntries;
+ break;
}
-
- SLANG_RETURN_ON_FAIL(globalSession->createSession(slangSessionDesc, session.writeRef()));
- return SLANG_OK;
}
- };
-}
+
+ SLANG_RETURN_ON_FAIL(globalSession->createSession(slangSessionDesc, session.writeRef()));
+ return SLANG_OK;
+ }
+};
+} // namespace gfx
diff --git a/tools/gfx/transient-resource-heap-base.h b/tools/gfx/transient-resource-heap-base.h
index 1b86b983c..9d7cb165a 100644
--- a/tools/gfx/transient-resource-heap-base.h
+++ b/tools/gfx/transient-resource-heap-base.h
@@ -32,7 +32,11 @@ public:
const size_t kStagingBufferDefaultPageSize = 16 * 1024 * 1024;
- void init(TDevice* device, MemoryType memoryType, uint32_t alignment, ResourceStateSet allowedStates)
+ void init(
+ TDevice* device,
+ MemoryType memoryType,
+ uint32_t alignment,
+ ResourceStateSet allowedStates)
{
m_device = device;
m_memoryType = memoryType;
@@ -129,7 +133,7 @@ public:
}
};
-template <typename TDevice, typename TBufferResource>
+template<typename TDevice, typename TBufferResource>
class TransientResourceHeapBaseImpl : public TransientResourceHeapBase
{
public:
@@ -158,11 +162,9 @@ public:
device,
MemoryType::Upload,
256,
- ResourceStateSet(
- ResourceState::CopySource,
- ResourceState::CopyDestination));
+ ResourceStateSet(ResourceState::CopySource, ResourceState::CopyDestination));
- m_readbackBufferPool.init(
+ m_readbackBufferPool.init(
device,
MemoryType::ReadBack,
256,
@@ -173,7 +175,12 @@ public:
return SLANG_OK;
}
- Result allocateStagingBuffer(size_t size, IBufferResource*& outBufferWeakPtr, size_t& offset, MemoryType memoryType, bool forceLargePage = false)
+ Result allocateStagingBuffer(
+ size_t size,
+ IBufferResource*& outBufferWeakPtr,
+ size_t& offset,
+ MemoryType memoryType,
+ bool forceLargePage = false)
{
switch (memoryType)
{
diff --git a/tools/gfx/vulkan/vk-api.cpp b/tools/gfx/vulkan/vk-api.cpp
index 8f5e4235b..3d2042a8d 100644
--- a/tools/gfx/vulkan/vk-api.cpp
+++ b/tools/gfx/vulkan/vk-api.cpp
@@ -3,22 +3,23 @@
#include "core/slang-list.h"
-namespace gfx {
+namespace gfx
+{
using namespace Slang;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! VulkanApi !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-#define VK_API_CHECK_FUNCTION(x) && (x != nullptr)
-#define VK_API_CHECK_FUNCTIONS(FUNCTION_LIST) true FUNCTION_LIST(VK_API_CHECK_FUNCTION)
+#define VK_API_CHECK_FUNCTION(x) &&(x != nullptr)
+#define VK_API_CHECK_FUNCTIONS(FUNCTION_LIST) true FUNCTION_LIST(VK_API_CHECK_FUNCTION)
bool VulkanApi::areDefined(ProcType type) const
{
switch (type)
{
- case ProcType::Global: return VK_API_CHECK_FUNCTIONS(VK_API_ALL_GLOBAL_PROCS);
- case ProcType::Instance: return VK_API_CHECK_FUNCTIONS(VK_API_ALL_INSTANCE_PROCS);
- case ProcType::Device: return VK_API_CHECK_FUNCTIONS(VK_API_DEVICE_PROCS);
- default:
+ case ProcType::Global: return VK_API_CHECK_FUNCTIONS(VK_API_ALL_GLOBAL_PROCS);
+ case ProcType::Instance: return VK_API_CHECK_FUNCTIONS(VK_API_ALL_INSTANCE_PROCS);
+ case ProcType::Device: return VK_API_CHECK_FUNCTIONS(VK_API_DEVICE_PROCS);
+ default:
{
assert(!"Unhandled type");
return false;
@@ -49,7 +50,7 @@ Slang::Result VulkanApi::initInstanceProcs(VkInstance instance)
VK_API_ALL_INSTANCE_PROCS(VK_API_GET_INSTANCE_PROC)
- // Get optional
+ // Get optional
VK_API_INSTANCE_PROCS_OPT(VK_API_GET_INSTANCE_PROC)
if (!areDefined(ProcType::Instance))
@@ -108,7 +109,7 @@ int VulkanApi::findMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags prop
// bit holds current test bit against typeBits. Ie bit == 1 << typeBits
uint32_t bit = 1;
- for (int i = 0; i < numMemoryTypes; ++i, bit += bit)
+ for (int i = 0; i < numMemoryTypes; ++i, bit += bit)
{
auto const& memoryType = m_deviceMemoryProperties.memoryTypes[i];
if ((typeBits & bit) && (memoryType.propertyFlags & properties) == properties)
@@ -117,7 +118,7 @@ int VulkanApi::findMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags prop
}
}
- //assert(!"failed to find a usable memory type");
+ // assert(!"failed to find a usable memory type");
return -1;
}
@@ -130,10 +131,13 @@ int VulkanApi::findQueue(VkQueueFlags reqFlags) const
Slang::List<VkQueueFamilyProperties> queueFamilies;
queueFamilies.setCount(numQueueFamilies);
- vkGetPhysicalDeviceQueueFamilyProperties(m_physicalDevice, &numQueueFamilies, queueFamilies.getBuffer());
+ vkGetPhysicalDeviceQueueFamilyProperties(
+ m_physicalDevice,
+ &numQueueFamilies,
+ queueFamilies.getBuffer());
// Find a queue that can service our needs
- //VkQueueFlags reqQueueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT;
+ // VkQueueFlags reqQueueFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT;
int queueFamilyIndex = -1;
for (int i = 0; i < int(numQueueFamilies); ++i)
@@ -147,4 +151,4 @@ int VulkanApi::findQueue(VkQueueFlags reqFlags) const
return -1;
}
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-api.h b/tools/gfx/vulkan/vk-api.h
index 04744369a..8b86bc281 100644
--- a/tools/gfx/vulkan/vk-api.h
+++ b/tools/gfx/vulkan/vk-api.h
@@ -3,7 +3,8 @@
#include "vk-module.h"
-namespace gfx {
+namespace gfx
+{
// clang-format off
#define VK_API_GLOBAL_PROCS(x) \
@@ -242,86 +243,66 @@ struct VulkanExtendedFeatureProperties
{
// 16 bit storage features
VkPhysicalDevice16BitStorageFeatures storage16BitFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR};
// Atomic Float features
VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomicFloatFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT};
VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT atomicFloat2Features = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_2_FEATURES_EXT
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_2_FEATURES_EXT};
// Image int64 atomic features
VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT imageInt64AtomicFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_IMAGE_ATOMIC_INT64_FEATURES_EXT
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_IMAGE_ATOMIC_INT64_FEATURES_EXT};
// Extended dynamic state features
VkPhysicalDeviceExtendedDynamicStateFeaturesEXT extendedDynamicStateFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT};
// Acceleration structure features
VkPhysicalDeviceAccelerationStructureFeaturesKHR accelerationStructureFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR};
// Ray tracing pipeline features
VkPhysicalDeviceRayTracingPipelineFeaturesKHR rayTracingPipelineFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR};
// Ray query (inline ray-tracing) features
VkPhysicalDeviceRayQueryFeaturesKHR rayQueryFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR};
// Inline uniform block features
VkPhysicalDeviceInlineUniformBlockFeaturesEXT inlineUniformBlockFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT};
// Robustness2 features
VkPhysicalDeviceRobustness2FeaturesEXT robustness2Features = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT};
VkPhysicalDeviceRayTracingInvocationReorderFeaturesNV rayTracingInvocationReorderFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_INVOCATION_REORDER_FEATURES_NV
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_INVOCATION_REORDER_FEATURES_NV};
VkPhysicalDeviceVariablePointerFeaturesKHR variablePointersFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR};
VkPhysicalDeviceComputeShaderDerivativesFeaturesNV computeShaderDerivativeFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV};
// Clock features
- VkPhysicalDeviceShaderClockFeaturesKHR clockFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR
- };
+ VkPhysicalDeviceShaderClockFeaturesKHR clockFeatures = {
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR};
// Mesh shader features
VkPhysicalDeviceMeshShaderFeaturesEXT meshShaderFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT};
// Multiview features
VkPhysicalDeviceMultiviewFeaturesKHR multiviewFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR};
// Fragment shading rate features
VkPhysicalDeviceFragmentShadingRateFeaturesKHR fragmentShadingRateFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_FEATURES_KHR};
// Vulkan 1.2 features.
VkPhysicalDeviceVulkan12Features vulkan12Features = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES
- };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES};
// Ray tracing validation features
VkPhysicalDeviceRayTracingValidationFeaturesNV rayTracingValidationFeatures = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_VALIDATION_FEATURES_NV
- };
-
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_VALIDATION_FEATURES_NV};
};
struct VulkanApi
@@ -335,38 +316,38 @@ struct VulkanApi
Device,
};
- /// Returns true if all the functions in the class are defined
+ /// Returns true if all the functions in the class are defined
bool areDefined(ProcType type) const;
- /// Sets up global parameters
+ /// Sets up global parameters
Slang::Result initGlobalProcs(const VulkanModule& module);
- /// Initialize the instance functions
+ /// Initialize the instance functions
Slang::Result initInstanceProcs(VkInstance instance);
- /// Called before initDevice
+ /// Called before initDevice
Slang::Result initPhysicalDevice(VkPhysicalDevice physicalDevice);
- /// Initialize the device functions
+ /// Initialize the device functions
Slang::Result initDeviceProcs(VkDevice device);
- /// Type bits control which indices are tested against bit 0 for testing at index 0
- /// properties - a memory type must have all the bits set as passed in
- /// Returns -1 if couldn't find an appropriate memory type index
+ /// Type bits control which indices are tested against bit 0 for testing at index 0
+ /// properties - a memory type must have all the bits set as passed in
+ /// Returns -1 if couldn't find an appropriate memory type index
int findMemoryTypeIndex(uint32_t typeBits, VkMemoryPropertyFlags properties) const;
- /// Given queue required flags, finds a queue
+ /// Given queue required flags, finds a queue
int findQueue(VkQueueFlags reqFlags) const;
- const VulkanModule* m_module = nullptr; ///< Module this was all loaded from
+ const VulkanModule* m_module = nullptr; ///< Module this was all loaded from
VkInstance m_instance = VK_NULL_HANDLE;
VkDevice m_device = VK_NULL_HANDLE;
VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
- VkPhysicalDeviceProperties m_deviceProperties;
- VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties;
- VkPhysicalDeviceFeatures m_deviceFeatures;
- VkPhysicalDeviceMemoryProperties m_deviceMemoryProperties;
- VulkanExtendedFeatureProperties m_extendedFeatures;
+ VkPhysicalDeviceProperties m_deviceProperties;
+ VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties;
+ VkPhysicalDeviceFeatures m_deviceFeatures;
+ VkPhysicalDeviceMemoryProperties m_deviceMemoryProperties;
+ VulkanExtendedFeatureProperties m_extendedFeatures;
};
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-base.h b/tools/gfx/vulkan/vk-base.h
index 3d765b42f..0e36c4454 100644
--- a/tools/gfx/vulkan/vk-base.h
+++ b/tools/gfx/vulkan/vk-base.h
@@ -16,41 +16,41 @@ namespace gfx
namespace vk
{
- class DeviceImpl;
- class InputLayoutImpl;
- class BufferResourceImpl;
- class FenceImpl;
- class TextureResourceImpl;
- class SamplerStateImpl;
- class ResourceViewImpl;
- class TextureResourceViewImpl;
- class TexelBufferResourceViewImpl;
- class PlainBufferResourceViewImpl;
- class AccelerationStructureImpl;
- class FramebufferLayoutImpl;
- class RenderPassLayoutImpl;
- class FramebufferImpl;
- class PipelineStateImpl;
- class RayTracingPipelineStateImpl;
- class ShaderObjectLayoutImpl;
- class EntryPointLayout;
- class RootShaderObjectLayout;
- class ShaderProgramImpl;
- class PipelineCommandEncoder;
- class ShaderObjectImpl;
- class MutableShaderObjectImpl;
- class RootShaderObjectImpl;
- class MutableRootShaderObjectImpl;
- class ShaderTableImpl;
- class ResourceCommandEncoder;
- class RenderCommandEncoder;
- class ComputeCommandEncoder;
- class RayTracingCommandEncoder;
- class CommandBufferImpl;
- class CommandQueueImpl;
- class TransientResourceHeapImpl;
- class QueryPoolImpl;
- class SwapchainImpl;
+class DeviceImpl;
+class InputLayoutImpl;
+class BufferResourceImpl;
+class FenceImpl;
+class TextureResourceImpl;
+class SamplerStateImpl;
+class ResourceViewImpl;
+class TextureResourceViewImpl;
+class TexelBufferResourceViewImpl;
+class PlainBufferResourceViewImpl;
+class AccelerationStructureImpl;
+class FramebufferLayoutImpl;
+class RenderPassLayoutImpl;
+class FramebufferImpl;
+class PipelineStateImpl;
+class RayTracingPipelineStateImpl;
+class ShaderObjectLayoutImpl;
+class EntryPointLayout;
+class RootShaderObjectLayout;
+class ShaderProgramImpl;
+class PipelineCommandEncoder;
+class ShaderObjectImpl;
+class MutableShaderObjectImpl;
+class RootShaderObjectImpl;
+class MutableRootShaderObjectImpl;
+class ShaderTableImpl;
+class ResourceCommandEncoder;
+class RenderCommandEncoder;
+class ComputeCommandEncoder;
+class RayTracingCommandEncoder;
+class CommandBufferImpl;
+class CommandQueueImpl;
+class TransientResourceHeapImpl;
+class QueryPoolImpl;
+class SwapchainImpl;
} // namespace vk
} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-buffer.cpp b/tools/gfx/vulkan/vk-buffer.cpp
index 721886d9f..76e64c32f 100644
--- a/tools/gfx/vulkan/vk-buffer.cpp
+++ b/tools/gfx/vulkan/vk-buffer.cpp
@@ -3,7 +3,7 @@
#include "vk-util.h"
#if SLANG_WINDOWS_FAMILY
-# include <dxgi1_2.h>
+#include <dxgi1_2.h>
#endif
namespace gfx
@@ -28,20 +28,21 @@ Result VKBufferHandleRAII::init(
m_memory = VK_NULL_HANDLE;
m_buffer = VK_NULL_HANDLE;
- VkBufferCreateInfo bufferCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
+ VkBufferCreateInfo bufferCreateInfo = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
bufferCreateInfo.size = bufferSize;
bufferCreateInfo.usage = usage;
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
VkExternalMemoryBufferCreateInfo externalMemoryBufferCreateInfo = {
- VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO };
+ VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO};
if (isShared)
{
externalMemoryBufferCreateInfo.handleTypes = extMemHandleType;
bufferCreateInfo.pNext = &externalMemoryBufferCreateInfo;
}
- SLANG_VK_RETURN_ON_FAIL(api.vkCreateBuffer(api.m_device, &bufferCreateInfo, nullptr, &m_buffer));
+ SLANG_VK_RETURN_ON_FAIL(
+ api.vkCreateBuffer(api.m_device, &bufferCreateInfo, nullptr, &m_buffer));
VkMemoryRequirements memoryReqs = {};
api.vkGetBufferMemoryRequirements(api.m_device, m_buffer, &memoryReqs);
@@ -51,15 +52,15 @@ Result VKBufferHandleRAII::init(
VkMemoryPropertyFlags actualMemoryProperites =
api.m_deviceMemoryProperties.memoryTypes[memoryTypeIndex].propertyFlags;
- VkMemoryAllocateInfo allocateInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
+ VkMemoryAllocateInfo allocateInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
allocateInfo.allocationSize = memoryReqs.size;
allocateInfo.memoryTypeIndex = memoryTypeIndex;
#if SLANG_WINDOWS_FAMILY
VkExportMemoryWin32HandleInfoKHR exportMemoryWin32HandleInfo = {
- VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR };
+ VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR};
#endif
VkExportMemoryAllocateInfoKHR exportMemoryAllocateInfo = {
- VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR };
+ VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR};
if (isShared)
{
#if SLANG_WINDOWS_FAMILY
@@ -71,13 +72,13 @@ Result VKBufferHandleRAII::init(
exportMemoryAllocateInfo.pNext =
extMemHandleType & VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR
- ? &exportMemoryWin32HandleInfo
- : nullptr;
+ ? &exportMemoryWin32HandleInfo
+ : nullptr;
#endif
exportMemoryAllocateInfo.handleTypes = extMemHandleType;
allocateInfo.pNext = &exportMemoryAllocateInfo;
}
- VkMemoryAllocateFlagsInfo flagInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO };
+ VkMemoryAllocateFlagsInfo flagInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO};
if (usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT)
{
flagInfo.deviceMask = 1;
@@ -94,8 +95,7 @@ Result VKBufferHandleRAII::init(
}
BufferResourceImpl::BufferResourceImpl(const IBufferResource::Desc& desc, DeviceImpl* renderer)
- : Parent(desc)
- , m_renderer(renderer)
+ : Parent(desc), m_renderer(renderer)
{
assert(renderer);
}
diff --git a/tools/gfx/vulkan/vk-buffer.h b/tools/gfx/vulkan/vk-buffer.h
index c824f3529..cc82cef90 100644
--- a/tools/gfx/vulkan/vk-buffer.h
+++ b/tools/gfx/vulkan/vk-buffer.h
@@ -29,7 +29,8 @@ public:
VKBufferHandleRAII()
: m_api(nullptr)
- {}
+ {
+ }
~VKBufferHandleRAII()
{
@@ -61,12 +62,12 @@ public:
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeResourceHandle(InteropHandle* outHandle) override;
+ getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- map(MemoryRange* rangeToRead, void** outPointer) override;
+ map(MemoryRange* rangeToRead, void** outPointer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) override;
diff --git a/tools/gfx/vulkan/vk-command-buffer.cpp b/tools/gfx/vulkan/vk-command-buffer.cpp
index 8e0b35750..320212c9a 100644
--- a/tools/gfx/vulkan/vk-command-buffer.cpp
+++ b/tools/gfx/vulkan/vk-command-buffer.cpp
@@ -24,10 +24,15 @@ ICommandBuffer* CommandBufferImpl::getInterface(const Guid& guid)
return nullptr;
}
-void CommandBufferImpl::comFree() { m_transientHeap.breakStrongReference(); }
+void CommandBufferImpl::comFree()
+{
+ m_transientHeap.breakStrongReference();
+}
Result CommandBufferImpl::init(
- DeviceImpl* renderer, VkCommandPool pool, TransientResourceHeapImpl* transientHeap)
+ DeviceImpl* renderer,
+ VkCommandPool pool,
+ TransientResourceHeapImpl* transientHeap)
{
m_renderer = renderer;
m_transientHeap = transientHeap;
@@ -89,7 +94,9 @@ VkCommandBuffer CommandBufferImpl::getPreCommandBuffer()
}
void CommandBufferImpl::encodeRenderCommands(
- IRenderPassLayout* renderPass, IFramebuffer* framebuffer, IRenderCommandEncoder** outEncoder)
+ IRenderPassLayout* renderPass,
+ IFramebuffer* framebuffer,
+ IRenderCommandEncoder** outEncoder)
{
if (!m_renderCommandEncoder)
{
diff --git a/tools/gfx/vulkan/vk-command-buffer.h b/tools/gfx/vulkan/vk-command-buffer.h
index 1c1c76ebd..aa45fc56e 100644
--- a/tools/gfx/vulkan/vk-command-buffer.h
+++ b/tools/gfx/vulkan/vk-command-buffer.h
@@ -14,9 +14,7 @@ using namespace Slang;
namespace vk
{
-class CommandBufferImpl
- : public ICommandBuffer
- , public ComObject
+class CommandBufferImpl : public ICommandBuffer, public ComObject
{
public:
// There are a pair of cyclic references between a `TransientResourceHeap` and
@@ -59,11 +57,11 @@ public:
IFramebuffer* framebuffer,
IRenderCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
+ encodeComputeCommands(IComputeCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
+ encodeResourceCommands(IResourceCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
+ encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override;
virtual SLANG_NO_THROW void SLANG_MCALL close() override;
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override;
};
diff --git a/tools/gfx/vulkan/vk-command-encoder.cpp b/tools/gfx/vulkan/vk-command-encoder.cpp
index 7f3110ea5..f9caff437 100644
--- a/tools/gfx/vulkan/vk-command-encoder.cpp
+++ b/tools/gfx/vulkan/vk-command-encoder.cpp
@@ -3,6 +3,7 @@
#include "vk-buffer.h"
#include "vk-command-buffer.h"
+#include "vk-helper-functions.h"
#include "vk-query.h"
#include "vk-render-pass.h"
#include "vk-resource-views.h"
@@ -12,8 +13,6 @@
#include "vk-texture.h"
#include "vk-transient-heap.h"
-#include "vk-helper-functions.h"
-
namespace gfx
{
@@ -26,15 +25,10 @@ int PipelineCommandEncoder::getBindPointIndex(VkPipelineBindPoint bindPoint)
{
switch (bindPoint)
{
- case VK_PIPELINE_BIND_POINT_GRAPHICS:
- return 0;
- case VK_PIPELINE_BIND_POINT_COMPUTE:
- return 1;
- case VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR:
- return 2;
- default:
- assert(!"unknown pipeline type.");
- return -1;
+ case VK_PIPELINE_BIND_POINT_GRAPHICS: return 0;
+ case VK_PIPELINE_BIND_POINT_COMPUTE: return 1;
+ case VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR: return 2;
+ default: assert(!"unknown pipeline type."); return -1;
}
}
@@ -63,8 +57,8 @@ void PipelineCommandEncoder::_uploadBufferData(
auto& api = buffer->m_renderer->m_api;
IBufferResource* stagingBuffer = nullptr;
Offset stagingBufferOffset = 0;
- transientHeap->allocateStagingBuffer(
- size, stagingBuffer, stagingBufferOffset, MemoryType::Upload);
+ transientHeap
+ ->allocateStagingBuffer(size, stagingBuffer, stagingBufferOffset, MemoryType::Upload);
BufferResourceImpl* stagingBufferImpl = static_cast<BufferResourceImpl*>(stagingBuffer);
@@ -93,7 +87,10 @@ void PipelineCommandEncoder::_uploadBufferData(
}
void PipelineCommandEncoder::uploadBufferDataImpl(
- IBufferResource* buffer, Offset offset, Size size, void* data)
+ IBufferResource* buffer,
+ Offset offset,
+ Size size,
+ void* data)
{
m_vkPreCommandBuffer = m_commandBuffer->getPreCommandBuffer();
_uploadBufferData(
@@ -105,7 +102,9 @@ void PipelineCommandEncoder::uploadBufferDataImpl(
data);
}
-Result PipelineCommandEncoder::bindRootShaderObjectImpl(RootShaderObjectImpl* rootShaderObject, VkPipelineBindPoint bindPoint)
+Result PipelineCommandEncoder::bindRootShaderObjectImpl(
+ RootShaderObjectImpl* rootShaderObject,
+ VkPipelineBindPoint bindPoint)
{
// Obtain specialized root layout.
auto specializedLayout = rootShaderObject->getSpecializedLayout();
@@ -162,7 +161,8 @@ Result PipelineCommandEncoder::bindRootShaderObjectImpl(RootShaderObjectImpl* ro
}
Result PipelineCommandEncoder::setPipelineStateImpl(
- IPipelineState* state, IShaderObject** outRootObject)
+ IPipelineState* state,
+ IShaderObject** outRootObject)
{
m_currentPipeline = static_cast<PipelineStateImpl*>(state);
m_commandBuffer->m_mutableRootShaderObject = nullptr;
@@ -174,10 +174,12 @@ Result PipelineCommandEncoder::setPipelineStateImpl(
}
Result PipelineCommandEncoder::setPipelineStateWithRootObjectImpl(
- IPipelineState* state, IShaderObject* rootObject)
+ IPipelineState* state,
+ IShaderObject* rootObject)
{
m_currentPipeline = static_cast<PipelineStateImpl*>(state);
- m_commandBuffer->m_mutableRootShaderObject = static_cast<MutableRootShaderObjectImpl*>(rootObject);
+ m_commandBuffer->m_mutableRootShaderObject =
+ static_cast<MutableRootShaderObjectImpl*>(rootObject);
return SLANG_OK;
}
@@ -188,11 +190,11 @@ Result PipelineCommandEncoder::bindRenderState(VkPipelineBindPoint pipelineBindP
// Get specialized pipeline state and bind it.
//
RootShaderObjectImpl* rootObjectImpl = m_commandBuffer->m_mutableRootShaderObject
- ? m_commandBuffer->m_mutableRootShaderObject.Ptr()
- : &m_commandBuffer->m_rootObject;
+ ? m_commandBuffer->m_mutableRootShaderObject.Ptr()
+ : &m_commandBuffer->m_rootObject;
RefPtr<PipelineStateBase> newPipeline;
- SLANG_RETURN_ON_FAIL(m_device->maybeSpecializePipeline(
- m_currentPipeline, rootObjectImpl, newPipeline));
+ SLANG_RETURN_ON_FAIL(
+ m_device->maybeSpecializePipeline(m_currentPipeline, rootObjectImpl, newPipeline));
PipelineStateImpl* newPipelineImpl = static_cast<PipelineStateImpl*>(newPipeline.Ptr());
SLANG_RETURN_ON_FAIL(newPipelineImpl->ensureAPIPipelineStateCreated());
@@ -206,12 +208,16 @@ Result PipelineCommandEncoder::bindRenderState(VkPipelineBindPoint pipelineBindP
api.vkCmdBindPipeline(m_vkCommandBuffer, pipelineBindPoint, newPipelineImpl->m_pipeline);
m_boundPipelines[pipelineBindPointId] = newPipelineImpl->m_pipeline;
}
-
+
return SLANG_OK;
}
void ResourceCommandEncoder::copyBuffer(
- IBufferResource* dst, Offset dstOffset, IBufferResource* src, Offset srcOffset, Size size)
+ IBufferResource* dst,
+ Offset dstOffset,
+ IBufferResource* src,
+ Offset srcOffset,
+ Size size)
{
auto& vkAPI = m_commandBuffer->m_renderer->m_api;
@@ -236,7 +242,10 @@ void ResourceCommandEncoder::copyBuffer(
}
void ResourceCommandEncoder::uploadBufferData(
- IBufferResource* buffer, Offset offset, Size size, void* data)
+ IBufferResource* buffer,
+ Offset offset,
+ Size size,
+ void* data)
{
PipelineCommandEncoder::_uploadBufferData(
m_commandBuffer->m_commandBuffer,
@@ -248,7 +257,10 @@ void ResourceCommandEncoder::uploadBufferData(
}
void ResourceCommandEncoder::textureBarrier(
- GfxCount count, ITextureResource* const* textures, ResourceState src, ResourceState dst)
+ GfxCount count,
+ ITextureResource* const* textures,
+ ResourceState src,
+ ResourceState dst)
{
ShortList<VkImageMemoryBarrier, 16> barriers;
@@ -262,7 +274,8 @@ void ResourceCommandEncoder::textureBarrier(
barrier.image = image->m_image;
barrier.oldLayout = translateImageLayout(src);
barrier.newLayout = translateImageLayout(dst);
- barrier.subresourceRange.aspectMask = getAspectMaskFromFormat(VulkanUtil::getVkFormat(desc->format));
+ barrier.subresourceRange.aspectMask =
+ getAspectMaskFromFormat(VulkanUtil::getVkFormat(desc->format));
barrier.subresourceRange.baseArrayLayer = 0;
barrier.subresourceRange.baseMipLevel = 0;
barrier.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
@@ -291,7 +304,10 @@ void ResourceCommandEncoder::textureBarrier(
// TODO: Change size_t to Count?
void ResourceCommandEncoder::bufferBarrier(
- GfxCount count, IBufferResource* const* buffers, ResourceState src, ResourceState dst)
+ GfxCount count,
+ IBufferResource* const* buffers,
+ ResourceState src,
+ ResourceState dst)
{
List<VkBufferMemoryBarrier> barriers;
barriers.reserve(count);
@@ -352,7 +368,10 @@ void ResourceCommandEncoder::endEncoding()
void ResourceCommandEncoder::writeTimestamp(IQueryPool* queryPool, GfxIndex index)
{
_writeTimestamp(
- &m_commandBuffer->m_renderer->m_api, m_commandBuffer->m_commandBuffer, queryPool, index);
+ &m_commandBuffer->m_renderer->m_api,
+ m_commandBuffer->m_commandBuffer,
+ queryPool,
+ index);
}
void ResourceCommandEncoder::copyTexture(
@@ -389,12 +408,14 @@ void ResourceCommandEncoder::copyTexture(
srcSubresource.mipLevelCount = dstDesc->numMipLevels;
}
VkImageCopy region = {};
- region.srcSubresource.aspectMask = VulkanUtil::getAspectMask(srcSubresource.aspectMask, srcImage->m_vkformat);
+ region.srcSubresource.aspectMask =
+ VulkanUtil::getAspectMask(srcSubresource.aspectMask, srcImage->m_vkformat);
region.srcSubresource.baseArrayLayer = srcSubresource.baseArrayLayer;
region.srcSubresource.mipLevel = srcSubresource.mipLevel;
region.srcSubresource.layerCount = srcSubresource.layerCount;
region.srcOffset = {(int32_t)srcOffset.x, (int32_t)srcOffset.y, (int32_t)srcOffset.z};
- region.dstSubresource.aspectMask = VulkanUtil::getAspectMask(dstSubresource.aspectMask, dstImage->m_vkformat);
+ region.dstSubresource.aspectMask =
+ VulkanUtil::getAspectMask(dstSubresource.aspectMask, dstImage->m_vkformat);
region.dstSubresource.baseArrayLayer = dstSubresource.baseArrayLayer;
region.dstSubresource.mipLevel = dstSubresource.mipLevel;
region.dstSubresource.layerCount = dstSubresource.layerCount;
@@ -450,8 +471,8 @@ void ResourceCommandEncoder::uploadTextureData(
IBufferResource* uploadBuffer = nullptr;
Offset uploadBufferOffset = 0;
- m_commandBuffer->m_transientHeap->allocateStagingBuffer(
- bufferSize, uploadBuffer, uploadBufferOffset, MemoryType::Upload);
+ m_commandBuffer->m_transientHeap
+ ->allocateStagingBuffer(bufferSize, uploadBuffer, uploadBufferOffset, MemoryType::Upload);
// Copy into upload buffer
{
@@ -535,7 +556,9 @@ void ResourceCommandEncoder::uploadTextureData(
region.imageSubresource.layerCount = 1;
region.imageOffset = {0, 0, 0};
region.imageExtent = {
- uint32_t(mipSize.width), uint32_t(mipSize.height), uint32_t(mipSize.depth)};
+ uint32_t(mipSize.width),
+ uint32_t(mipSize.height),
+ uint32_t(mipSize.depth)};
// Do the copy (do all depths in a single go)
vkApi.vkCmdCopyBufferToImage(
@@ -554,7 +577,8 @@ void ResourceCommandEncoder::uploadTextureData(
}
void ResourceCommandEncoder::_clearColorImage(
- TextureResourceViewImpl* viewImpl, ClearValue* clearValue)
+ TextureResourceViewImpl* viewImpl,
+ ClearValue* clearValue)
{
auto& api = m_commandBuffer->m_renderer->m_api;
auto layout = viewImpl->m_layout;
@@ -601,7 +625,9 @@ void ResourceCommandEncoder::_clearColorImage(
}
void ResourceCommandEncoder::_clearDepthImage(
- TextureResourceViewImpl* viewImpl, ClearValue* clearValue, ClearResourceViewFlags::Enum flags)
+ TextureResourceViewImpl* viewImpl,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags)
{
auto& api = m_commandBuffer->m_renderer->m_api;
auto layout = viewImpl->m_layout;
@@ -662,17 +688,26 @@ void ResourceCommandEncoder::_clearDepthImage(
}
void ResourceCommandEncoder::_clearBuffer(
- VkBuffer buffer, uint64_t bufferSize, const IResourceView::Desc& desc, uint32_t clearValue)
+ VkBuffer buffer,
+ uint64_t bufferSize,
+ const IResourceView::Desc& desc,
+ uint32_t clearValue)
{
auto& api = m_commandBuffer->m_renderer->m_api;
auto clearOffset = desc.bufferRange.offset;
auto clearSize = desc.bufferRange.size == 0 ? bufferSize - clearOffset : desc.bufferRange.size;
api.vkCmdFillBuffer(
- m_commandBuffer->m_commandBuffer, buffer, clearOffset, clearSize, clearValue);
+ m_commandBuffer->m_commandBuffer,
+ buffer,
+ clearOffset,
+ clearSize,
+ clearValue);
}
void ResourceCommandEncoder::clearResourceView(
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags)
+ IResourceView* view,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags)
{
auto& api = m_commandBuffer->m_renderer->m_api;
switch (view->getViewDesc()->type)
@@ -770,18 +805,22 @@ void ResourceCommandEncoder::resolveResource(
for (GfxIndex mip = 0; mip < sourceRange.mipLevelCount; ++mip)
{
VkImageResolve region = {};
- region.srcSubresource.aspectMask = VulkanUtil::getAspectMask(sourceRange.aspectMask, srcTexture->m_vkformat);
+ region.srcSubresource.aspectMask =
+ VulkanUtil::getAspectMask(sourceRange.aspectMask, srcTexture->m_vkformat);
region.srcSubresource.baseArrayLayer = layer + sourceRange.baseArrayLayer;
region.srcSubresource.layerCount = 1;
region.srcSubresource.mipLevel = mip + sourceRange.mipLevel;
region.srcOffset = {0, 0, 0};
- region.dstSubresource.aspectMask = VulkanUtil::getAspectMask(destRange.aspectMask, dstTexture->m_vkformat);
+ region.dstSubresource.aspectMask =
+ VulkanUtil::getAspectMask(destRange.aspectMask, dstTexture->m_vkformat);
region.dstSubresource.baseArrayLayer = layer + destRange.baseArrayLayer;
region.dstSubresource.layerCount = 1;
region.dstSubresource.mipLevel = mip + destRange.mipLevel;
region.dstOffset = {0, 0, 0};
region.extent = {
- (uint32_t)srcExtent.width, (uint32_t)srcExtent.height, (uint32_t)srcExtent.depth};
+ (uint32_t)srcExtent.width,
+ (uint32_t)srcExtent.height,
+ (uint32_t)srcExtent.depth};
auto& vkApi = m_commandBuffer->m_renderer->m_api;
vkApi.vkCmdResolveImage(
@@ -797,7 +836,11 @@ void ResourceCommandEncoder::resolveResource(
}
void ResourceCommandEncoder::resolveQuery(
- IQueryPool* queryPool, GfxIndex index, GfxCount count, IBufferResource* buffer, Offset offset)
+ IQueryPool* queryPool,
+ GfxIndex index,
+ GfxCount count,
+ IBufferResource* buffer,
+ Offset offset)
{
auto& vkApi = m_commandBuffer->m_renderer->m_api;
auto poolImpl = static_cast<QueryPoolImpl*>(queryPool);
@@ -835,7 +878,8 @@ void ResourceCommandEncoder::copyTextureToBuffer(
region.bufferOffset = dstOffset;
region.bufferRowLength = 0;
region.bufferImageHeight = 0;
- region.imageSubresource.aspectMask = VulkanUtil::getAspectMask(srcSubresource.aspectMask, image->m_vkformat);
+ region.imageSubresource.aspectMask =
+ VulkanUtil::getAspectMask(srcSubresource.aspectMask, image->m_vkformat);
region.imageSubresource.mipLevel = srcSubresource.mipLevel;
region.imageSubresource.baseArrayLayer = srcSubresource.baseArrayLayer;
region.imageSubresource.layerCount = srcSubresource.layerCount;
@@ -867,7 +911,8 @@ void ResourceCommandEncoder::textureSubresourceBarrier(
barrier.image = image->m_image;
barrier.oldLayout = translateImageLayout(src);
barrier.newLayout = translateImageLayout(dst);
- barrier.subresourceRange.aspectMask = VulkanUtil::getAspectMask(subresourceRange.aspectMask, image->m_vkformat);
+ barrier.subresourceRange.aspectMask =
+ VulkanUtil::getAspectMask(subresourceRange.aspectMask, image->m_vkformat);
barrier.subresourceRange.baseArrayLayer = subresourceRange.baseArrayLayer;
barrier.subresourceRange.baseMipLevel = subresourceRange.mipLevel;
barrier.subresourceRange.layerCount = subresourceRange.layerCount;
@@ -948,13 +993,15 @@ void RenderCommandEncoder::endEncoding()
}
Result RenderCommandEncoder::bindPipeline(
- IPipelineState* pipelineState, IShaderObject** outRootObject)
+ IPipelineState* pipelineState,
+ IShaderObject** outRootObject)
{
return setPipelineStateImpl(pipelineState, outRootObject);
}
Result RenderCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject)
+ IPipelineState* pipelineState,
+ IShaderObject* rootObject)
{
return setPipelineStateWithRootObjectImpl(pipelineState, rootObject);
}
@@ -1009,14 +1056,14 @@ void RenderCommandEncoder::setPrimitiveTopology(PrimitiveTopology topology)
if (api.vkCmdSetPrimitiveTopologyEXT)
{
api.vkCmdSetPrimitiveTopologyEXT(
- m_vkCommandBuffer, VulkanUtil::getVkPrimitiveTopology(topology));
+ m_vkCommandBuffer,
+ VulkanUtil::getVkPrimitiveTopology(topology));
}
else
{
switch (topology)
{
- case PrimitiveTopology::TriangleList:
- break;
+ case PrimitiveTopology::TriangleList: break;
default:
// We are using a non-list topology, but we don't have dynmaic state
// extension, error out.
@@ -1043,31 +1090,35 @@ void RenderCommandEncoder::setVertexBuffers(
VkDeviceSize offset = VkDeviceSize(offsets[i]);
m_api->vkCmdBindVertexBuffers(
- m_vkCommandBuffer, (uint32_t)slotIndex, 1, vertexBuffers, &offset);
+ m_vkCommandBuffer,
+ (uint32_t)slotIndex,
+ 1,
+ vertexBuffers,
+ &offset);
}
}
}
void RenderCommandEncoder::setIndexBuffer(
- IBufferResource* buffer, Format indexFormat, Offset offset)
+ IBufferResource* buffer,
+ Format indexFormat,
+ Offset offset)
{
VkIndexType indexType = VK_INDEX_TYPE_UINT16;
switch (indexFormat)
{
- case Format::R16_UINT:
- indexType = VK_INDEX_TYPE_UINT16;
- break;
- case Format::R32_UINT:
- indexType = VK_INDEX_TYPE_UINT32;
- break;
- default:
- assert(!"unsupported index format");
+ case Format::R16_UINT: indexType = VK_INDEX_TYPE_UINT16; break;
+ case Format::R32_UINT: indexType = VK_INDEX_TYPE_UINT32; break;
+ default: assert(!"unsupported index format");
}
BufferResourceImpl* bufferImpl = static_cast<BufferResourceImpl*>(buffer);
m_api->vkCmdBindIndexBuffer(
- m_vkCommandBuffer, bufferImpl->m_buffer.m_buffer, (VkDeviceSize)offset, indexType);
+ m_vkCommandBuffer,
+ bufferImpl->m_buffer.m_buffer,
+ (VkDeviceSize)offset,
+ indexType);
}
Result RenderCommandEncoder::prepareDraw()
@@ -1090,7 +1141,9 @@ Result RenderCommandEncoder::draw(GfxCount vertexCount, GfxIndex startVertex)
}
Result RenderCommandEncoder::drawIndexed(
- GfxCount indexCount, GfxIndex startIndex, GfxIndex baseVertex)
+ GfxCount indexCount,
+ GfxIndex startIndex,
+ GfxIndex baseVertex)
{
SLANG_RETURN_ON_FAIL(prepareDraw());
auto& api = *m_api;
@@ -1152,7 +1205,9 @@ Result RenderCommandEncoder::drawIndexedIndirect(
}
Result RenderCommandEncoder::setSamplePositions(
- GfxCount samplesPerPixel, GfxCount pixelCount, const SamplePosition* samplePositions)
+ GfxCount samplesPerPixel,
+ GfxCount pixelCount,
+ const SamplePosition* samplePositions)
{
if (m_api->vkCmdSetSampleLocationsEXT)
{
@@ -1175,7 +1230,11 @@ Result RenderCommandEncoder::drawInstanced(
SLANG_RETURN_ON_FAIL(prepareDraw());
auto& api = *m_api;
api.vkCmdDraw(
- m_vkCommandBuffer, vertexCount, instanceCount, startVertex, startInstanceLocation);
+ m_vkCommandBuffer,
+ vertexCount,
+ instanceCount,
+ startVertex,
+ startInstanceLocation);
return SLANG_OK;
}
@@ -1206,16 +1265,21 @@ Result RenderCommandEncoder::drawMeshTasks(int x, int y, int z)
return SLANG_OK;
}
-void ComputeCommandEncoder::endEncoding() { endEncodingImpl(); }
+void ComputeCommandEncoder::endEncoding()
+{
+ endEncodingImpl();
+}
Result ComputeCommandEncoder::bindPipeline(
- IPipelineState* pipelineState, IShaderObject** outRootObject)
+ IPipelineState* pipelineState,
+ IShaderObject** outRootObject)
{
return setPipelineStateImpl(pipelineState, outRootObject);
}
Result ComputeCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject)
+ IPipelineState* pipelineState,
+ IShaderObject* rootObject)
{
return setPipelineStateWithRootObjectImpl(pipelineState, rootObject);
}
@@ -1303,8 +1367,7 @@ void RayTracingCommandEncoder::_queryAccelerationStructureProperties(
case QueryType::AccelerationStructureSerializedSize:
queryType = VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR;
break;
- case QueryType::AccelerationStructureCurrentSize:
- continue;
+ case QueryType::AccelerationStructureCurrentSize: continue;
default:
getDebugCallback()->handleMessage(
DebugMessageType::Error,
@@ -1362,7 +1425,10 @@ void RayTracingCommandEncoder::buildAccelerationStructure(
auto rangeInfoPtr = rangeInfos.getBuffer();
m_commandBuffer->m_renderer->m_api.vkCmdBuildAccelerationStructuresKHR(
- m_commandBuffer->m_commandBuffer, 1, &geomInfoBuilder.buildInfo, &rangeInfoPtr);
+ m_commandBuffer->m_commandBuffer,
+ 1,
+ &geomInfoBuilder.buildInfo,
+ &rangeInfoPtr);
if (propertyQueryCount)
{
@@ -1372,7 +1438,9 @@ void RayTracingCommandEncoder::buildAccelerationStructure(
}
void RayTracingCommandEncoder::copyAccelerationStructure(
- IAccelerationStructure* dest, IAccelerationStructure* src, AccelerationStructureCopyMode mode)
+ IAccelerationStructure* dest,
+ IAccelerationStructure* src,
+ AccelerationStructureCopyMode mode)
{
VkCopyAccelerationStructureInfoKHR copyInfo = {
VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_INFO_KHR};
@@ -1394,7 +1462,8 @@ void RayTracingCommandEncoder::copyAccelerationStructure(
return;
}
m_commandBuffer->m_renderer->m_api.vkCmdCopyAccelerationStructureKHR(
- m_commandBuffer->m_commandBuffer, &copyInfo);
+ m_commandBuffer->m_commandBuffer,
+ &copyInfo);
}
void RayTracingCommandEncoder::queryAccelerationStructureProperties(
@@ -1404,11 +1473,15 @@ void RayTracingCommandEncoder::queryAccelerationStructureProperties(
AccelerationStructureQueryDesc* queryDescs)
{
_queryAccelerationStructureProperties(
- accelerationStructureCount, accelerationStructures, queryCount, queryDescs);
+ accelerationStructureCount,
+ accelerationStructures,
+ queryCount,
+ queryDescs);
}
void RayTracingCommandEncoder::serializeAccelerationStructure(
- DeviceAddress dest, IAccelerationStructure* source)
+ DeviceAddress dest,
+ IAccelerationStructure* source)
{
VkCopyAccelerationStructureToMemoryInfoKHR copyInfo = {
VK_STRUCTURE_TYPE_COPY_ACCELERATION_STRUCTURE_TO_MEMORY_INFO_KHR};
@@ -1416,11 +1489,13 @@ void RayTracingCommandEncoder::serializeAccelerationStructure(
copyInfo.dst.deviceAddress = dest;
copyInfo.mode = VK_COPY_ACCELERATION_STRUCTURE_MODE_SERIALIZE_KHR;
m_commandBuffer->m_renderer->m_api.vkCmdCopyAccelerationStructureToMemoryKHR(
- m_commandBuffer->m_commandBuffer, &copyInfo);
+ m_commandBuffer->m_commandBuffer,
+ &copyInfo);
}
void RayTracingCommandEncoder::deserializeAccelerationStructure(
- IAccelerationStructure* dest, DeviceAddress source)
+ IAccelerationStructure* dest,
+ DeviceAddress source)
{
VkCopyMemoryToAccelerationStructureInfoKHR copyInfo = {
VK_STRUCTURE_TYPE_COPY_MEMORY_TO_ACCELERATION_STRUCTURE_INFO_KHR};
@@ -1428,16 +1503,20 @@ void RayTracingCommandEncoder::deserializeAccelerationStructure(
copyInfo.dst = static_cast<AccelerationStructureImpl*>(dest)->m_vkHandle;
copyInfo.mode = VK_COPY_ACCELERATION_STRUCTURE_MODE_DESERIALIZE_KHR;
m_commandBuffer->m_renderer->m_api.vkCmdCopyMemoryToAccelerationStructureKHR(
- m_commandBuffer->m_commandBuffer, &copyInfo);
+ m_commandBuffer->m_commandBuffer,
+ &copyInfo);
}
-Result RayTracingCommandEncoder::bindPipeline(IPipelineState* pipeline, IShaderObject** outRootObject)
+Result RayTracingCommandEncoder::bindPipeline(
+ IPipelineState* pipeline,
+ IShaderObject** outRootObject)
{
return setPipelineStateImpl(pipeline, outRootObject);
}
Result RayTracingCommandEncoder::bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject)
+ IPipelineState* pipelineState,
+ IShaderObject* rootObject)
{
return setPipelineStateWithRootObjectImpl(pipelineState, rootObject);
}
@@ -1498,7 +1577,10 @@ Result RayTracingCommandEncoder::dispatchRays(
return SLANG_OK;
}
-void RayTracingCommandEncoder::endEncoding() { endEncodingImpl(); }
+void RayTracingCommandEncoder::endEncoding()
+{
+ endEncodingImpl();
+}
} // namespace vk
} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-command-encoder.h b/tools/gfx/vulkan/vk-command-encoder.h
index 05c47920e..ec9854b30 100644
--- a/tools/gfx/vulkan/vk-command-encoder.h
+++ b/tools/gfx/vulkan/vk-command-encoder.h
@@ -40,7 +40,9 @@ public:
void uploadBufferDataImpl(IBufferResource* buffer, Offset offset, Size size, void* data);
- Result bindRootShaderObjectImpl(RootShaderObjectImpl* rootShaderObject, VkPipelineBindPoint bindPoint);
+ Result bindRootShaderObjectImpl(
+ RootShaderObjectImpl* rootShaderObject,
+ VkPipelineBindPoint bindPoint);
Result setPipelineStateImpl(IPipelineState* state, IShaderObject** outRootObject);
@@ -49,9 +51,7 @@ public:
Result bindRenderState(VkPipelineBindPoint pipelineBindPoint);
};
-class ResourceCommandEncoder
- : public IResourceCommandEncoder
- , public PipelineCommandEncoder
+class ResourceCommandEncoder : public IResourceCommandEncoder, public PipelineCommandEncoder
{
public:
virtual void* getInterface(SlangUUID const& guid)
@@ -61,7 +61,7 @@ public:
return nullptr;
}
virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- queryInterface(SlangUUID const& uuid, void** outObject) override
+ queryInterface(SlangUUID const& uuid, void** outObject) override
{
if (auto ptr = getInterface(uuid))
{
@@ -80,7 +80,7 @@ public:
Offset srcOffset,
Size size) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- uploadBufferData(IBufferResource* buffer, Offset offset, Size size, void* data) override;
+ uploadBufferData(IBufferResource* buffer, Offset offset, Size size, void* data) override;
virtual SLANG_NO_THROW void SLANG_MCALL textureBarrier(
GfxCount count,
ITextureResource* const* textures,
@@ -94,7 +94,7 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW void SLANG_MCALL
- writeTimestamp(IQueryPool* queryPool, GfxIndex index) override;
+ writeTimestamp(IQueryPool* queryPool, GfxIndex index) override;
virtual SLANG_NO_THROW void SLANG_MCALL copyTexture(
ITextureResource* dst,
@@ -123,10 +123,15 @@ public:
ClearResourceViewFlags::Enum flags);
void _clearBuffer(
- VkBuffer buffer, uint64_t bufferSize, const IResourceView::Desc& desc, uint32_t clearValue);
+ VkBuffer buffer,
+ uint64_t bufferSize,
+ const IResourceView::Desc& desc,
+ uint32_t clearValue);
virtual SLANG_NO_THROW void SLANG_MCALL clearResourceView(
- IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags) override;
+ IResourceView* view,
+ ClearValue* clearValue,
+ ClearResourceViewFlags::Enum flags) override;
virtual SLANG_NO_THROW void SLANG_MCALL resolveResource(
ITextureResource* source,
@@ -161,18 +166,17 @@ public:
ResourceState dst) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- beginDebugEvent(const char* name, float rgbColor[3]) override;
+ beginDebugEvent(const char* name, float rgbColor[3]) override;
virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override;
};
-class RenderCommandEncoder
- : public IRenderCommandEncoder
- , public ResourceCommandEncoder
+class RenderCommandEncoder : public IRenderCommandEncoder, public ResourceCommandEncoder
{
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IRenderCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
@@ -189,19 +193,19 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* pipelineState, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* pipelineState, IShaderObject** outRootObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ bindPipelineWithRootObject(IPipelineState* pipelineState, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setViewports(GfxCount count, const Viewport* viewports) override;
+ setViewports(GfxCount count, const Viewport* viewports) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setScissorRects(GfxCount count, const ScissorRect* rects) override;
+ setScissorRects(GfxCount count, const ScissorRect* rects) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setPrimitiveTopology(PrimitiveTopology topology) override;
+ setPrimitiveTopology(PrimitiveTopology topology) override;
virtual SLANG_NO_THROW void SLANG_MCALL setVertexBuffers(
GfxIndex startSlot,
@@ -210,14 +214,14 @@ public:
const Offset* offsets) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) override;
+ setIndexBuffer(IBufferResource* buffer, Format indexFormat, Offset offset = 0) override;
Result prepareDraw();
virtual SLANG_NO_THROW Result SLANG_MCALL
- draw(GfxCount vertexCount, GfxIndex startVertex = 0) override;
+ draw(GfxCount vertexCount, GfxIndex startVertex = 0) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override;
+ drawIndexed(GfxCount indexCount, GfxIndex startIndex = 0, GfxIndex baseVertex = 0) override;
virtual SLANG_NO_THROW void SLANG_MCALL setStencilReference(uint32_t referenceValue) override;
@@ -253,19 +257,17 @@ public:
GfxIndex baseVertexLocation,
GfxIndex startInstanceLocation) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- drawMeshTasks(int x, int y, int z) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL drawMeshTasks(int x, int y, int z) override;
};
-class ComputeCommandEncoder
- : public IComputeCommandEncoder
- , public ResourceCommandEncoder
+class ComputeCommandEncoder : public IComputeCommandEncoder, public ResourceCommandEncoder
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
@@ -275,33 +277,32 @@ public:
virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* pipelineState, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* pipelineState, IShaderObject** outRootObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ bindPipelineWithRootObject(IPipelineState* pipelineState, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL dispatchCompute(int x, int y, int z) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
+ dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
};
-class RayTracingCommandEncoder
- : public IRayTracingCommandEncoder
- , public ResourceCommandEncoder
+class RayTracingCommandEncoder : public IRayTracingCommandEncoder, public ResourceCommandEncoder
{
public:
SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoder)
virtual void* getInterface(SlangUUID const& uuid) override
{
- if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == GfxGUID::IID_IRayTracingCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
+ if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
+ uuid == GfxGUID::IID_IRayTracingCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
{
return this;
}
return nullptr;
}
-public:
+public:
void _memoryBarrier(
int count,
IAccelerationStructure* const* structures,
@@ -331,16 +332,16 @@ public:
AccelerationStructureQueryDesc* queryDescs) override;
virtual SLANG_NO_THROW void SLANG_MCALL
- serializeAccelerationStructure(DeviceAddress dest, IAccelerationStructure* source) override;
+ serializeAccelerationStructure(DeviceAddress dest, IAccelerationStructure* source) override;
- virtual SLANG_NO_THROW void SLANG_MCALL deserializeAccelerationStructure(
- IAccelerationStructure* dest, DeviceAddress source) override;
+ virtual SLANG_NO_THROW void SLANG_MCALL
+ deserializeAccelerationStructure(IAccelerationStructure* dest, DeviceAddress source) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- bindPipeline(IPipelineState* pipeline, IShaderObject** outRootObject) override;
+ bindPipeline(IPipelineState* pipeline, IShaderObject** outRootObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL bindPipelineWithRootObject(
- IPipelineState* pipelineState, IShaderObject* rootObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ bindPipelineWithRootObject(IPipelineState* pipelineState, IShaderObject* rootObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL dispatchRays(
GfxIndex raygenShaderIndex,
diff --git a/tools/gfx/vulkan/vk-command-queue.cpp b/tools/gfx/vulkan/vk-command-queue.cpp
index 58d4fa972..232e7f0b1 100644
--- a/tools/gfx/vulkan/vk-command-queue.cpp
+++ b/tools/gfx/vulkan/vk-command-queue.cpp
@@ -36,8 +36,8 @@ void CommandQueueImpl::init(DeviceImpl* renderer, VkQueue queue, uint32_t queueF
VkSemaphoreCreateInfo semaphoreCreateInfo = {};
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
semaphoreCreateInfo.flags = 0;
- m_renderer->m_api.vkCreateSemaphore(
- m_renderer->m_api.m_device, &semaphoreCreateInfo, nullptr, &m_semaphore);
+ m_renderer->m_api
+ .vkCreateSemaphore(m_renderer->m_api.m_device, &semaphoreCreateInfo, nullptr, &m_semaphore);
}
void CommandQueueImpl::waitOnHost()
@@ -53,10 +53,15 @@ Result CommandQueueImpl::getNativeHandle(InteropHandle* outHandle)
return SLANG_OK;
}
-const CommandQueueImpl::Desc& CommandQueueImpl::getDesc() { return m_desc; }
+const CommandQueueImpl::Desc& CommandQueueImpl::getDesc()
+{
+ return m_desc;
+}
Result CommandQueueImpl::waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* waitValues)
{
for (GfxIndex i = 0; i < fenceCount; ++i)
{
@@ -69,7 +74,10 @@ Result CommandQueueImpl::waitForFenceValuesOnDevice(
}
void CommandQueueImpl::queueSubmitImpl(
- uint32_t count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
+ uint32_t count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal)
{
auto& vkAPI = m_renderer->m_api;
m_submitCommandBuffers.clear();
@@ -89,7 +97,8 @@ void CommandQueueImpl::queueSubmitImpl(
VkSubmitInfo submitInfo = {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
VkPipelineStageFlags stageFlag[] = {
- VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT};
+ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
+ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT};
submitInfo.pWaitDstStageMask = stageFlag;
submitInfo.commandBufferCount = (uint32_t)m_submitCommandBuffers.getCount();
submitInfo.pCommandBuffers = m_submitCommandBuffers.getBuffer();
@@ -144,7 +153,10 @@ void CommandQueueImpl::queueSubmitImpl(
}
void CommandQueueImpl::executeCommandBuffers(
- GfxCount count, ICommandBuffer* const* commandBuffers, IFence* fence, uint64_t valueToSignal)
+ GfxCount count,
+ ICommandBuffer* const* commandBuffers,
+ IFence* fence,
+ uint64_t valueToSignal)
{
if (count == 0 && fence == nullptr)
return;
diff --git a/tools/gfx/vulkan/vk-command-queue.h b/tools/gfx/vulkan/vk-command-queue.h
index c7d4e3eb4..07b3e14e6 100644
--- a/tools/gfx/vulkan/vk-command-queue.h
+++ b/tools/gfx/vulkan/vk-command-queue.h
@@ -12,9 +12,7 @@ using namespace Slang;
namespace vk
{
-class CommandQueueImpl
- : public ICommandQueue
- , public ComObject
+class CommandQueueImpl : public ICommandQueue, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -44,8 +42,8 @@ public:
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override;
- virtual SLANG_NO_THROW Result SLANG_MCALL waitForFenceValuesOnDevice(
- GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL
+ waitForFenceValuesOnDevice(GfxCount fenceCount, IFence** fences, uint64_t* waitValues) override;
void queueSubmitImpl(
uint32_t count,
diff --git a/tools/gfx/vulkan/vk-descriptor-allocator.cpp b/tools/gfx/vulkan/vk-descriptor-allocator.cpp
index 49199091d..afaa836ca 100644
--- a/tools/gfx/vulkan/vk-descriptor-allocator.cpp
+++ b/tools/gfx/vulkan/vk-descriptor-allocator.cpp
@@ -1,4 +1,5 @@
#include "vk-descriptor-allocator.h"
+
#include "vk-util.h"
namespace gfx
@@ -31,13 +32,17 @@ VkDescriptorPool DescriptorSetAllocator::newPool()
descriptorPoolInfo.pPoolSizes = poolSizes.getBuffer();
descriptorPoolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
- VkDescriptorPoolInlineUniformBlockCreateInfo inlineUniformBlockInfo = { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_INLINE_UNIFORM_BLOCK_CREATE_INFO };
+ VkDescriptorPoolInlineUniformBlockCreateInfo inlineUniformBlockInfo = {
+ VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_INLINE_UNIFORM_BLOCK_CREATE_INFO};
inlineUniformBlockInfo.maxInlineUniformBlockBindings = 16;
descriptorPoolInfo.pNext = &inlineUniformBlockInfo;
VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
SLANG_VK_CHECK(m_api->vkCreateDescriptorPool(
- m_api->m_device, &descriptorPoolInfo, nullptr, &descriptorPool));
+ m_api->m_device,
+ &descriptorPoolInfo,
+ nullptr,
+ &descriptorPool));
pools.add(descriptorPool);
return descriptorPool;
}
@@ -77,4 +82,4 @@ VulkanDescriptorSet DescriptorSetAllocator::allocate(VkDescriptorSetLayout layou
assert(!"descriptor set allocation failed.");
return rs;
}
-}
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-descriptor-allocator.h b/tools/gfx/vulkan/vk-descriptor-allocator.h
index 3d5c441ad..5be1cfae2 100644
--- a/tools/gfx/vulkan/vk-descriptor-allocator.h
+++ b/tools/gfx/vulkan/vk-descriptor-allocator.h
@@ -2,8 +2,8 @@
#pragma once
-#include "vk-api.h"
#include "core/slang-list.h"
+#include "vk-api.h"
namespace gfx
{
diff --git a/tools/gfx/vulkan/vk-device-queue.cpp b/tools/gfx/vulkan/vk-device-queue.cpp
index 1bcfe28c8..8a98d68ec 100644
--- a/tools/gfx/vulkan/vk-device-queue.cpp
+++ b/tools/gfx/vulkan/vk-device-queue.cpp
@@ -1,11 +1,12 @@
// vk-device-queue.cpp
#include "vk-device-queue.h"
-#include <stdlib.h>
-#include <stdio.h>
#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
-namespace gfx {
+namespace gfx
+{
using namespace Slang;
VulkanDeviceQueue::~VulkanDeviceQueue()
@@ -24,7 +25,8 @@ void VulkanDeviceQueue::destroy()
for (int i = 0; i < m_numCommandBuffers; i++)
{
- m_api->vkFreeCommandBuffers(m_api->m_device, m_commandPools[i], 1, &m_commandBuffers[i]);
+ m_api
+ ->vkFreeCommandBuffers(m_api->m_device, m_commandPools[i], 1, &m_commandBuffers[i]);
m_api->vkDestroyFence(m_api->m_device, m_fences[i].fence, nullptr);
m_api->vkDestroyCommandPool(m_api->m_device, m_commandPools[i], nullptr);
}
@@ -35,7 +37,7 @@ void VulkanDeviceQueue::destroy()
SlangResult VulkanDeviceQueue::init(const VulkanApi& api, VkQueue queue, int queueIndex)
{
assert(m_api == nullptr);
-
+
for (int i = 0; i < int(EventType::CountOf); ++i)
{
m_semaphores[i] = VK_NULL_HANDLE;
@@ -135,7 +137,7 @@ void VulkanDeviceQueue::flushStepA()
makeCompleted(EventType::EndFrame);
}
-void VulkanDeviceQueue::_updateFenceAtIndex( int fenceIndex, bool blocking)
+void VulkanDeviceQueue::_updateFenceAtIndex(int fenceIndex, bool blocking)
{
Fence& fence = m_fences[fenceIndex];
@@ -143,7 +145,8 @@ void VulkanDeviceQueue::_updateFenceAtIndex( int fenceIndex, bool blocking)
{
uint64_t timeout = blocking ? ~uint64_t(0) : 0;
- if (VK_SUCCESS == m_api->vkWaitForFences(m_api->m_device, 1, &fence.fence, VK_TRUE, timeout))
+ if (VK_SUCCESS ==
+ m_api->vkWaitForFences(m_api->m_device, 1, &fence.fence, VK_TRUE, timeout))
{
m_api->vkResetFences(m_api->m_device, 1, &fence.fence);
@@ -211,4 +214,4 @@ void VulkanDeviceQueue::makeCompleted(EventType eventType)
m_currentSemaphores[int(eventType)] = VK_NULL_HANDLE;
}
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-device-queue.h b/tools/gfx/vulkan/vk-device-queue.h
index 38d8f2bd6..174e20850 100644
--- a/tools/gfx/vulkan/vk-device-queue.h
+++ b/tools/gfx/vulkan/vk-device-queue.h
@@ -4,7 +4,8 @@
#include "vk-api.h"
#include "vk-descriptor-allocator.h"
-namespace gfx {
+namespace gfx
+{
struct VulkanDeviceQueue
{
@@ -20,53 +21,56 @@ struct VulkanDeviceQueue
CountOf,
};
- /// Initialize - must be called before anything else can be done
+ /// Initialize - must be called before anything else can be done
SlangResult init(const VulkanApi& api, VkQueue queue, int queueIndex);
- /// Flushes the current command list, and steps to next (internally this is equivalent to a stepA followed by stepB)
+ /// Flushes the current command list, and steps to next (internally this is equivalent to a
+ /// stepA followed by stepB)
void flush();
- /// Performs a full flush, and then waits for idle.
+ /// Performs a full flush, and then waits for idle.
void flushAndWait();
- /// Blocks until all work submitted to GPU has completed
+ /// Blocks until all work submitted to GPU has completed
void waitForIdle() { m_api->vkQueueWaitIdle(m_queue); }
- /// Get the graphics queue index (as set on init)
+ /// Get the graphics queue index (as set on init)
int getQueueIndex() const { return m_queueIndex; }
- /// Make the specified event 'current' - meaning it's semaphore must be waited on
+ /// Make the specified event 'current' - meaning it's semaphore must be waited on
VkSemaphore makeCurrent(EventType eventType);
VkSemaphore getSemaphore(EventType eventType);
- /// Makes the event no longer required to be waited on
+ /// Makes the event no longer required to be waited on
void makeCompleted(EventType eventType);
- /// Returns true if the event is already current
- SLANG_FORCE_INLINE bool isCurrent(EventType eventType) const { return m_currentSemaphores[int(eventType)] != VK_NULL_HANDLE; }
+ /// Returns true if the event is already current
+ SLANG_FORCE_INLINE bool isCurrent(EventType eventType) const
+ {
+ return m_currentSemaphores[int(eventType)] != VK_NULL_HANDLE;
+ }
- /// Get the command buffer
+ /// Get the command buffer
VkCommandBuffer getCommandBuffer() const { return m_commandBuffer; }
- /// Get the queue
+ /// Get the queue
VkQueue getQueue() const { return m_queue; }
- /// Get the API
+ /// Get the API
const VulkanApi* getApi() const { return m_api; }
- /// Flushes the current command list
+ /// Flushes the current command list
void flushStepA();
- /// Steps to next command buffer and opens. May block if command buffer is still in use
+ /// Steps to next command buffer and opens. May block if command buffer is still in use
void flushStepB();
- /// Destroy the device queue
+ /// Destroy the device queue
void destroy();
- /// True if the queue appears to be valid and has been initialized
+ /// True if the queue appears to be valid and has been initialized
bool isValid() const { return m_api != nullptr; }
- /// Dtor
+ /// Dtor
~VulkanDeviceQueue();
- protected:
-
+protected:
struct Fence
{
VkFence fence;
@@ -82,9 +86,9 @@ struct VulkanDeviceQueue
int m_commandBufferIndex = 0;
// There are the same amount of command buffers as fences
VkCommandPool m_commandPools[kMaxCommandBuffers] = {VK_NULL_HANDLE};
- VkCommandBuffer m_commandBuffers[kMaxCommandBuffers] = { VK_NULL_HANDLE };
+ VkCommandBuffer m_commandBuffers[kMaxCommandBuffers] = {VK_NULL_HANDLE};
- Fence m_fences[kMaxCommandBuffers] = { {VK_NULL_HANDLE, 0, 0u} };
+ Fence m_fences[kMaxCommandBuffers] = {{VK_NULL_HANDLE, 0, 0u}};
VkCommandBuffer m_commandBuffer = VK_NULL_HANDLE;
VkCommandPool m_commandPool = VK_NULL_HANDLE;
@@ -99,4 +103,4 @@ struct VulkanDeviceQueue
const VulkanApi* m_api = nullptr;
};
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-device.cpp b/tools/gfx/vulkan/vk-device.cpp
index bc1641aff..68b8ba1db 100644
--- a/tools/gfx/vulkan/vk-device.cpp
+++ b/tools/gfx/vulkan/vk-device.cpp
@@ -1,30 +1,28 @@
// vk-device.cpp
#include "vk-device.h"
+#include "source/core/slang-platform.h"
#include "vk-buffer.h"
#include "vk-command-queue.h"
#include "vk-fence.h"
+#include "vk-helper-functions.h"
+#include "vk-pipeline-dump-layer.h"
#include "vk-query.h"
#include "vk-render-pass.h"
#include "vk-resource-views.h"
#include "vk-sampler.h"
-#include "vk-shader-object.h"
#include "vk-shader-object-layout.h"
+#include "vk-shader-object.h"
#include "vk-shader-program.h"
#include "vk-shader-table.h"
#include "vk-swap-chain.h"
#include "vk-transient-heap.h"
#include "vk-vertex-layout.h"
-#include "vk-pipeline-dump-layer.h"
-
-#include "vk-helper-functions.h"
-
-#include "source/core/slang-platform.h"
#ifdef GFX_NV_AFTERMATH
-# include "GFSDK_Aftermath.h"
-# include "GFSDK_Aftermath_Defines.h"
-# include "GFSDK_Aftermath_GpuCrashDump.h"
+#include "GFSDK_Aftermath.h"
+#include "GFSDK_Aftermath_Defines.h"
+#include "GFSDK_Aftermath_GpuCrashDump.h"
#endif
namespace gfx
@@ -150,12 +148,14 @@ static bool _hasAnySetBits(const T& val, size_t offset)
{
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(&val);
for (size_t i = offset; i < sizeof(val); i++)
- if (ptr[i]) return true;
+ if (ptr[i])
+ return true;
return false;
}
Result DeviceImpl::initVulkanInstanceAndDevice(
- const InteropHandle* handles, bool useValidationLayer)
+ const InteropHandle* handles,
+ bool useValidationLayer)
{
m_features.clear();
@@ -171,7 +171,9 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
switch (stype)
{
case StructType::RayTracingValidationDesc:
- enableRayTracingValidation = static_cast<RayTracingValidationDesc*>(m_desc.extendedDescs[i])->enableRaytracingValidation;
+ enableRayTracingValidation =
+ static_cast<RayTracingValidationDesc*>(m_desc.extendedDescs[i])
+ ->enableRaytracingValidation;
break;
}
}
@@ -180,7 +182,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
VkInstance instance = VK_NULL_HANDLE;
if (handles[0].handleValue == 0)
{
- VkApplicationInfo applicationInfo = { VK_STRUCTURE_TYPE_APPLICATION_INFO };
+ VkApplicationInfo applicationInfo = {VK_STRUCTURE_TYPE_APPLICATION_INFO};
applicationInfo.pApplicationName = "slang-gfx";
applicationInfo.pEngineName = "slang-gfx";
applicationInfo.apiVersion = VK_API_VERSION_1_1;
@@ -215,7 +217,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
if (ENABLE_VALIDATION_LAYER || isGfxDebugLayerEnabled())
instanceExtensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
- VkInstanceCreateInfo instanceCreateInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
+ VkInstanceCreateInfo instanceCreateInfo = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
#if SLANG_APPLE_FAMILY
instanceCreateInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
#endif
@@ -223,10 +225,11 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.getCount();
instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0];
- const char* layerNames[] = { nullptr };
+ const char* layerNames[] = {nullptr};
VkValidationFeaturesEXT validationFeatures = {};
- VkValidationFeatureEnableEXT enabledValidationFeatures[1] = { VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT };
+ VkValidationFeatureEnableEXT enabledValidationFeatures[1] = {
+ VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT};
if (useValidationLayer)
{
// Depending on driver version, validation layer may or may not exist.
@@ -245,9 +248,9 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
for (auto& layer : availableLayers)
{
if (strncmp(
- layer.layerName,
- "VK_LAYER_KHRONOS_validation",
- sizeof("VK_LAYER_KHRONOS_validation")) == 0)
+ layer.layerName,
+ "VK_LAYER_KHRONOS_validation",
+ sizeof("VK_LAYER_KHRONOS_validation")) == 0)
{
layerNames[0] = "VK_LAYER_KHRONOS_validation";
break;
@@ -260,9 +263,9 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
for (auto& layer : availableLayers)
{
if (strncmp(
- layer.layerName,
- "VK_LAYER_LUNARG_standard_validation",
- sizeof("VK_LAYER_LUNARG_standard_validation")) == 0)
+ layer.layerName,
+ "VK_LAYER_LUNARG_standard_validation",
+ sizeof("VK_LAYER_LUNARG_standard_validation")) == 0)
{
layerNames[0] = "VK_LAYER_LUNARG_standard_validation";
break;
@@ -281,7 +284,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
instanceCreateInfo.pNext = &validationFeatures;
}
}
- uint32_t apiVersionsToTry[] = { VK_API_VERSION_1_2, VK_API_VERSION_1_1, VK_API_VERSION_1_0 };
+ uint32_t apiVersionsToTry[] = {VK_API_VERSION_1_2, VK_API_VERSION_1_1, VK_API_VERSION_1_0};
for (auto apiVersion : apiVersionsToTry)
{
applicationInfo.apiVersion = apiVersion;
@@ -290,7 +293,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
// the layer is known earlier). It might, for example, be absent
// from the system library search path, and not referenced with an
// absolute path in VkLayer_khronos_validation.json.
- const auto r = m_api.vkCreateInstance(&instanceCreateInfo, nullptr, &instance) ;
+ const auto r = m_api.vkCreateInstance(&instanceCreateInfo, nullptr, &instance);
if (r == VK_SUCCESS)
{
break;
@@ -311,13 +314,16 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
VkDebugReportCallbackCreateInfoEXT debugCreateInfo = {
- VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT };
+ VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT};
debugCreateInfo.pfnCallback = &debugMessageCallback;
debugCreateInfo.pUserData = this;
debugCreateInfo.flags = debugFlags;
SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateDebugReportCallbackEXT(
- instance, &debugCreateInfo, nullptr, &m_debugReportCallback));
+ instance,
+ &debugCreateInfo,
+ nullptr,
+ &m_debugReportCallback));
}
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
@@ -330,7 +336,9 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
List<VkPhysicalDevice> physicalDevices;
physicalDevices.setCount(numPhysicalDevices);
SLANG_VK_RETURN_ON_FAIL(m_api.vkEnumeratePhysicalDevices(
- instance, &numPhysicalDevices, physicalDevices.getBuffer()));
+ instance,
+ &numPhysicalDevices,
+ physicalDevices.getBuffer()));
// Use first physical device by default.
Index selectedDeviceIndex = 0;
@@ -373,12 +381,14 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
// Query the available extensions
uint32_t extensionCount = 0;
- m_api.vkEnumerateDeviceExtensionProperties(
- m_api.m_physicalDevice, NULL, &extensionCount, NULL);
+ m_api.vkEnumerateDeviceExtensionProperties(m_api.m_physicalDevice, NULL, &extensionCount, NULL);
Slang::List<VkExtensionProperties> extensions;
extensions.setCount(extensionCount);
m_api.vkEnumerateDeviceExtensionProperties(
- m_api.m_physicalDevice, NULL, &extensionCount, extensions.getBuffer());
+ m_api.m_physicalDevice,
+ NULL,
+ &extensionCount,
+ extensions.getBuffer());
HashSet<String> extensionNames;
for (const auto& e : extensions)
extensionNames.add(e.extensionName);
@@ -390,7 +400,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
deviceExtensions.add("VK_KHR_portability_subset");
#endif
- VkDeviceCreateInfo deviceCreateInfo = { VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO };
+ VkDeviceCreateInfo deviceCreateInfo = {VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO};
deviceCreateInfo.queueCreateInfoCount = 1;
deviceCreateInfo.pEnabledFeatures = &m_api.m_deviceFeatures;
@@ -480,7 +490,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
// Variable pointer features.
extendedFeatures.variablePointersFeatures.pNext = deviceFeatures2.pNext;
deviceFeatures2.pNext = &extendedFeatures.variablePointersFeatures;
-
+
// Compute shader derivative features.
extendedFeatures.computeShaderDerivativeFeatures.pNext = deviceFeatures2.pNext;
deviceFeatures2.pNext = &extendedFeatures.computeShaderDerivativeFeatures;
@@ -501,7 +511,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
extendedFeatures.clockFeatures.pNext = deviceFeatures2.pNext;
deviceFeatures2.pNext = &extendedFeatures.clockFeatures;
- // Atomic Float
+ // Atomic Float
// To detect atomic float we need
// https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkPhysicalDeviceShaderAtomicFloatFeaturesEXT.html
@@ -564,12 +574,14 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
m_features.add("half");
}
- const auto addFeatureExtension = [&](const bool feature, auto& featureStruct, const char* extension = nullptr){
- if(!feature)
+ const auto addFeatureExtension =
+ [&](const bool feature, auto& featureStruct, const char* extension = nullptr)
+ {
+ if (!feature)
return false;
- if(extension)
+ if (extension)
{
- if(!extensionNames.contains(extension))
+ if (!extensionNames.contains(extension))
return false;
deviceExtensions.add(extension);
}
@@ -585,51 +597,47 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
// linked into the deviceCreateInfo chain and the features added to the
// supported features list.
#define SIMPLE_EXTENSION_FEATURE(s, m, e, ...) \
- do{ \
- const static auto fs = {__VA_ARGS__}; \
- if(addFeatureExtension(s.m, s, e)) \
- for(const auto& p : fs) \
- m_features.add(p); \
- } while(0)
+ do \
+ { \
+ const static auto fs = {__VA_ARGS__}; \
+ if (addFeatureExtension(s.m, s, e)) \
+ for (const auto& p : fs) \
+ m_features.add(p); \
+ } while (0)
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.storage16BitFeatures,
storageBuffer16BitAccess,
VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
- "16-bit-storage"
- );
+ "16-bit-storage");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.atomicFloatFeatures,
shaderBufferFloat32Atomics,
VK_EXT_SHADER_ATOMIC_FLOAT_EXTENSION_NAME,
- "atomic-float"
- );
+ "atomic-float");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.atomicFloat2Features,
shaderBufferFloat16Atomics,
VK_EXT_SHADER_ATOMIC_FLOAT_2_EXTENSION_NAME,
- "atomic-float-2"
- );
+ "atomic-float-2");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.imageInt64AtomicFeatures,
shaderImageInt64Atomics,
VK_EXT_SHADER_IMAGE_ATOMIC_INT64_EXTENSION_NAME,
- "image-atomic-int64"
- );
+ "image-atomic-int64");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.extendedDynamicStateFeatures,
extendedDynamicState,
VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME,
- "extended-dynamic-states"
- );
+ "extended-dynamic-states");
- if (extendedFeatures.accelerationStructureFeatures.accelerationStructure
- && extensionNames.contains(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME)
- && extensionNames.contains(VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME))
+ if (extendedFeatures.accelerationStructureFeatures.accelerationStructure &&
+ extensionNames.contains(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME) &&
+ extensionNames.contains(VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME))
{
extendedFeatures.accelerationStructureFeatures.pNext = (void*)deviceCreateInfo.pNext;
deviceCreateInfo.pNext = &extendedFeatures.accelerationStructureFeatures;
@@ -644,89 +652,78 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
rayQuery,
VK_KHR_RAY_QUERY_EXTENSION_NAME,
"ray-query",
- "ray-tracing"
- );
+ "ray-tracing");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.rayTracingPipelineFeatures,
rayTracingPipeline,
VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME,
- "ray-tracing-pipeline"
- );
+ "ray-tracing-pipeline");
}
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.inlineUniformBlockFeatures,
inlineUniformBlock,
VK_EXT_INLINE_UNIFORM_BLOCK_EXTENSION_NAME,
- "inline-uniform-block",
- );
+ "inline-uniform-block", );
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.robustness2Features,
nullDescriptor,
VK_EXT_ROBUSTNESS_2_EXTENSION_NAME,
- "robustness2",
- );
+ "robustness2", );
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.clockFeatures,
shaderDeviceClock,
VK_KHR_SHADER_CLOCK_EXTENSION_NAME,
- "realtime-clock"
- );
+ "realtime-clock");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.meshShaderFeatures,
meshShader,
VK_EXT_MESH_SHADER_EXTENSION_NAME,
- "mesh-shader"
- );
+ "mesh-shader");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.multiviewFeatures,
multiview,
VK_KHR_MULTIVIEW_EXTENSION_NAME,
- "multiview"
- );
+ "multiview");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.fragmentShadingRateFeatures,
primitiveFragmentShadingRate,
VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME,
- "fragment-shading-rate"
- );
+ "fragment-shading-rate");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.rayTracingInvocationReorderFeatures,
rayTracingInvocationReorder,
VK_NV_RAY_TRACING_INVOCATION_REORDER_EXTENSION_NAME,
- "shader-execution-reorder"
- );
+ "shader-execution-reorder");
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.variablePointersFeatures,
variablePointers,
VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME,
- "variable-pointer"
- );
-
+ "variable-pointer");
+
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.computeShaderDerivativeFeatures,
computeDerivativeGroupLinear,
VK_NV_COMPUTE_SHADER_DERIVATIVES_EXTENSION_NAME,
- "computeDerivativeGroupLinear"
- );
+ "computeDerivativeGroupLinear");
// Only enable raytracing validation if both requested and supported
- if(enableRayTracingValidation && extendedFeatures.rayTracingValidationFeatures.rayTracingValidation)
+ if (enableRayTracingValidation &&
+ extendedFeatures.rayTracingValidationFeatures.rayTracingValidation)
{
SIMPLE_EXTENSION_FEATURE(
extendedFeatures.rayTracingValidationFeatures,
rayTracingValidation,
VK_NV_RAY_TRACING_VALIDATION_EXTENSION_NAME,
- "ray-tracing-validation"
- );
+ "ray-tracing-validation");
}
#undef SIMPLE_EXTENSION_FEATURE
@@ -752,11 +749,11 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
}
VkPhysicalDeviceProperties2 extendedProps = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
VkPhysicalDeviceRayTracingPipelinePropertiesKHR rtProps = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
VkPhysicalDeviceSubgroupProperties subgroupProps = {
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES };
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES};
rtProps.pNext = extendedProps.pNext;
extendedProps.pNext = &rtProps;
@@ -767,16 +764,12 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
m_api.m_rtProperties = rtProps;
// Approximate DX12's WaveOps boolean
- if(subgroupProps.supportedOperations &
- ( VK_SUBGROUP_FEATURE_BASIC_BIT
- | VK_SUBGROUP_FEATURE_VOTE_BIT
- | VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
- | VK_SUBGROUP_FEATURE_BALLOT_BIT
- | VK_SUBGROUP_FEATURE_SHUFFLE_BIT
- | VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
- | VK_SUBGROUP_FEATURE_CLUSTERED_BIT
- | VK_SUBGROUP_FEATURE_QUAD_BIT
- | VK_SUBGROUP_FEATURE_PARTITIONED_BIT_NV))
+ if (subgroupProps.supportedOperations &
+ (VK_SUBGROUP_FEATURE_BASIC_BIT | VK_SUBGROUP_FEATURE_VOTE_BIT |
+ VK_SUBGROUP_FEATURE_ARITHMETIC_BIT | VK_SUBGROUP_FEATURE_BALLOT_BIT |
+ VK_SUBGROUP_FEATURE_SHUFFLE_BIT | VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT |
+ VK_SUBGROUP_FEATURE_CLUSTERED_BIT | VK_SUBGROUP_FEATURE_QUAD_BIT |
+ VK_SUBGROUP_FEATURE_PARTITIONED_BIT_NV))
{
m_features.add("wave-ops");
}
@@ -860,13 +853,32 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
// Derive approximate DX12 shader model.
const char* featureTable[] = {
- "sm_6_0", "wave-ops", "atomic-int64", nullptr,
- "sm_6_1", "barycentrics", "multiview", nullptr,
- "sm_6_2", "half", nullptr,
- "sm_6_3", "ray-tracing-pipeline", nullptr,
- "sm_6_4", "fragment-shading-rate", nullptr,
- "sm_6_5", "ray-query", "mesh-shader", nullptr,
- "sm_6_6", "wave-ops", "atomic-float", "atomic-int64", nullptr,
+ "sm_6_0",
+ "wave-ops",
+ "atomic-int64",
+ nullptr,
+ "sm_6_1",
+ "barycentrics",
+ "multiview",
+ nullptr,
+ "sm_6_2",
+ "half",
+ nullptr,
+ "sm_6_3",
+ "ray-tracing-pipeline",
+ nullptr,
+ "sm_6_4",
+ "fragment-shading-rate",
+ nullptr,
+ "sm_6_5",
+ "ray-query",
+ "mesh-shader",
+ nullptr,
+ "sm_6_6",
+ "wave-ops",
+ "atomic-float",
+ "atomic-int64",
+ nullptr,
nullptr,
};
@@ -924,11 +936,17 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
// Set up device creation info for Aftermath feature flag configuration.
VkDeviceDiagnosticsConfigFlagsNV aftermathFlags =
- VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV | // Enable automatic call stack checkpoints.
- VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV | // Enable tracking of resources.
- VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV; // Generate debug information for shaders.
- // Not available on the version of Vulkan currently building with.
- //VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_ERROR_REPORTING_BIT_NV; // Enable additional runtime shader error reporting.
+ VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV | // Enable automatic
+ // call stack
+ // checkpoints.
+ VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV | // Enable tracking of
+ // resources.
+ VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV; // Generate debug
+ // information for
+ // shaders.
+ // Not available on the version of Vulkan currently building with.
+ // VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_ERROR_REPORTING_BIT_NV; // Enable additional
+ // runtime shader error reporting.
aftermathInfo.sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV;
aftermathInfo.flags = aftermathFlags;
@@ -941,7 +959,7 @@ Result DeviceImpl::initVulkanInstanceAndDevice(
if (handles[2].handleValue == 0)
{
float queuePriority = 0.0f;
- VkDeviceQueueCreateInfo queueCreateInfo = { VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO };
+ VkDeviceQueueCreateInfo queueCreateInfo = {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO};
queueCreateInfo.queueFamilyIndex = m_queueFamilyIndex;
queueCreateInfo.queueCount = 1;
queueCreateInfo.pQueuePriorities = &queuePriority;
@@ -978,7 +996,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
m_info.bindingStyle = BindingStyle::Vulkan;
m_info.projectionStyle = ProjectionStyle::Vulkan;
m_info.deviceType = DeviceType::Vulkan;
- static const float kIdentity[] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
+ static const float kIdentity[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
::memcpy(m_info.identityProjectionMatrix, kIdentity, sizeof(kIdentity));
}
@@ -997,7 +1015,8 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
continue;
descriptorSetAllocator.m_api = &m_api;
initDeviceResult = initVulkanInstanceAndDevice(
- desc.existingDeviceHandles.handles, ENABLE_VALIDATION_LAYER != 0 || isGfxDebugLayerEnabled());
+ desc.existingDeviceHandles.handles,
+ ENABLE_VALIDATION_LAYER != 0 || isGfxDebugLayerEnabled());
if (initDeviceResult == SLANG_OK)
break;
}
@@ -1015,11 +1034,11 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
desc.extendedDescs,
SLANG_SPIRV,
"sm_5_1",
- makeArray(slang::PreprocessorMacroDesc{ "__VK__", "1" }).getView()));
+ makeArray(slang::PreprocessorMacroDesc{"__VK__", "1"}).getView()));
// Create default sampler.
{
- VkSamplerCreateInfo samplerInfo = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO };
+ VkSamplerCreateInfo samplerInfo = {VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
samplerInfo.magFilter = VK_FILTER_NEAREST;
samplerInfo.minFilter = VK_FILTER_NEAREST;
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
@@ -1056,12 +1075,19 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
return SLANG_OK;
}
-void DeviceImpl::waitForGpu() { m_deviceQueue.flushAndWait(); }
+void DeviceImpl::waitForGpu()
+{
+ m_deviceQueue.flushAndWait();
+}
-SLANG_NO_THROW const DeviceInfo& SLANG_MCALL DeviceImpl::getDeviceInfo() const { return m_info; }
+SLANG_NO_THROW const DeviceInfo& SLANG_MCALL DeviceImpl::getDeviceInfo() const
+{
+ return m_info;
+}
Result DeviceImpl::createTransientResourceHeap(
- const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap)
+ const ITransientResourceHeap::Desc& desc,
+ ITransientResourceHeap** outHeap)
{
RefPtr<TransientResourceHeapImpl> result = new TransientResourceHeapImpl();
SLANG_RETURN_ON_FAIL(result->init(desc, this));
@@ -1085,7 +1111,9 @@ Result DeviceImpl::createCommandQueue(const ICommandQueue::Desc& desc, ICommandQ
}
Result DeviceImpl::createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain)
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain)
{
#if !defined(SLANG_ENABLE_XLIB)
if (window.type == WindowHandle::Type::XLibHandle)
@@ -1101,7 +1129,8 @@ Result DeviceImpl::createSwapchain(
}
Result DeviceImpl::createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout)
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout)
{
RefPtr<FramebufferLayoutImpl> layout = new FramebufferLayoutImpl();
SLANG_RETURN_ON_FAIL(layout->init(this, desc));
@@ -1110,7 +1139,8 @@ Result DeviceImpl::createFramebufferLayout(
}
Result DeviceImpl::createRenderPassLayout(
- const IRenderPassLayout::Desc& desc, IRenderPassLayout** outRenderPassLayout)
+ const IRenderPassLayout::Desc& desc,
+ IRenderPassLayout** outRenderPassLayout)
{
RefPtr<RenderPassLayoutImpl> result = new RenderPassLayoutImpl();
SLANG_RETURN_ON_FAIL(result->init(this, desc));
@@ -1196,16 +1226,24 @@ SlangResult DeviceImpl::readTextureResource(
region.bufferRowLength = 0;
region.bufferImageHeight = 0;
- region.imageSubresource.aspectMask = getAspectMaskFromFormat(VulkanUtil::getVkFormat(desc->format));
+ region.imageSubresource.aspectMask =
+ getAspectMaskFromFormat(VulkanUtil::getVkFormat(desc->format));
region.imageSubresource.mipLevel = uint32_t(j);
region.imageSubresource.baseArrayLayer = i;
region.imageSubresource.layerCount = 1;
- region.imageOffset = { 0, 0, 0 };
+ region.imageOffset = {0, 0, 0};
region.imageExtent = {
- uint32_t(mipSize.width), uint32_t(mipSize.height), uint32_t(mipSize.depth) };
+ uint32_t(mipSize.width),
+ uint32_t(mipSize.height),
+ uint32_t(mipSize.depth)};
m_api.vkCmdCopyImageToBuffer(
- commandBuffer, srcImage, srcImageLayout, staging.m_buffer, 1, &region);
+ commandBuffer,
+ srcImage,
+ srcImageLayout,
+ staging.m_buffer,
+ 1,
+ &region);
dstOffset += rowSizeInBytes * numRows * mipSize.depth;
}
@@ -1231,7 +1269,10 @@ SlangResult DeviceImpl::readTextureResource(
}
SlangResult DeviceImpl::readBufferResource(
- IBufferResource* inBuffer, Offset offset, Size size, ISlangBlob** outBlob)
+ IBufferResource* inBuffer,
+ Offset offset,
+ Size size,
+ ISlangBlob** outBlob)
{
BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(inBuffer);
@@ -1280,7 +1321,7 @@ Result DeviceImpl::getAccelerationStructurePrebuildInfo(
return SLANG_E_NOT_AVAILABLE;
}
VkAccelerationStructureBuildSizesInfoKHR sizeInfo = {
- VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR };
+ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR};
AccelerationStructureBuildGeometryInfoBuilder geomInfoBuilder;
SLANG_RETURN_ON_FAIL(geomInfoBuilder.build(buildInputs, getDebugCallback()));
m_api.vkGetAccelerationStructureBuildSizesKHR(
@@ -1296,7 +1337,8 @@ Result DeviceImpl::getAccelerationStructurePrebuildInfo(
}
Result DeviceImpl::createAccelerationStructure(
- const IAccelerationStructure::CreateDesc& desc, IAccelerationStructure** outAS)
+ const IAccelerationStructure::CreateDesc& desc,
+ IAccelerationStructure** outAS)
{
if (!m_api.vkCreateAccelerationStructureKHR)
{
@@ -1309,7 +1351,7 @@ Result DeviceImpl::createAccelerationStructure(
resultAS->m_device = this;
resultAS->m_desc.type = IResourceView::Type::AccelerationStructure;
VkAccelerationStructureCreateInfoKHR createInfo = {
- VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR };
+ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR};
createInfo.buffer = resultAS->m_buffer->m_buffer.m_buffer;
createInfo.offset = desc.offset;
createInfo.size = desc.size;
@@ -1330,7 +1372,10 @@ Result DeviceImpl::createAccelerationStructure(
}
SLANG_VK_RETURN_ON_FAIL(m_api.vkCreateAccelerationStructureKHR(
- m_api.m_device, &createInfo, nullptr, &resultAS->m_vkHandle));
+ m_api.m_device,
+ &createInfo,
+ nullptr,
+ &resultAS->m_vkHandle));
returnComPtr(outAS, resultAS);
return SLANG_OK;
}
@@ -1367,7 +1412,16 @@ void DeviceImpl::_transitionImageLayout(
VkPipelineStageFlags destinationStage = calcPipelineStageFlagsFromImageLayout(newLayout);
m_api.vkCmdPipelineBarrier(
- commandBuffer, sourceStage, destinationStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
+ commandBuffer,
+ sourceStage,
+ destinationStage,
+ 0,
+ 0,
+ nullptr,
+ 0,
+ nullptr,
+ 1,
+ &barrier);
}
uint32_t DeviceImpl::getQueueFamilyIndex(ICommandQueue::QueueType queueType)
@@ -1375,8 +1429,7 @@ uint32_t DeviceImpl::getQueueFamilyIndex(ICommandQueue::QueueType queueType)
switch (queueType)
{
case ICommandQueue::QueueType::Graphics:
- default:
- return m_queueFamilyIndex;
+ default: return m_queueFamilyIndex;
}
}
@@ -1392,7 +1445,9 @@ void DeviceImpl::_transitionImageLayout(
}
Result DeviceImpl::getTextureAllocationInfo(
- const ITextureResource::Desc& descIn, Size* outSize, Size* outAlignment)
+ const ITextureResource::Desc& descIn,
+ Size* outSize,
+ Size* outAlignment)
{
TextureResource::Desc desc = fixupTextureDesc(descIn);
@@ -1404,47 +1459,47 @@ Result DeviceImpl::getTextureAllocationInfo(
}
const int arraySize = calcEffectiveArraySize(desc);
- VkImageCreateInfo imageInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
+ VkImageCreateInfo imageInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
switch (desc.type)
{
case IResource::Type::Texture1D:
- {
- imageInfo.imageType = VK_IMAGE_TYPE_1D;
- imageInfo.extent = VkExtent3D{ uint32_t(descIn.size.width), 1, 1 };
- break;
- }
+ {
+ imageInfo.imageType = VK_IMAGE_TYPE_1D;
+ imageInfo.extent = VkExtent3D{uint32_t(descIn.size.width), 1, 1};
+ break;
+ }
case IResource::Type::Texture2D:
- {
- imageInfo.imageType = VK_IMAGE_TYPE_2D;
- imageInfo.extent =
- VkExtent3D{ uint32_t(descIn.size.width), uint32_t(descIn.size.height), 1 };
- break;
- }
+ {
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.extent =
+ VkExtent3D{uint32_t(descIn.size.width), uint32_t(descIn.size.height), 1};
+ break;
+ }
case IResource::Type::TextureCube:
- {
- imageInfo.imageType = VK_IMAGE_TYPE_2D;
- imageInfo.extent =
- VkExtent3D{ uint32_t(descIn.size.width), uint32_t(descIn.size.height), 1 };
- imageInfo.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
- break;
- }
+ {
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.extent =
+ VkExtent3D{uint32_t(descIn.size.width), uint32_t(descIn.size.height), 1};
+ imageInfo.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
+ break;
+ }
case IResource::Type::Texture3D:
- {
- // Can't have an array and 3d texture
- assert(desc.arraySize <= 1);
-
- imageInfo.imageType = VK_IMAGE_TYPE_3D;
- imageInfo.extent = VkExtent3D{
- uint32_t(descIn.size.width),
- uint32_t(descIn.size.height),
- uint32_t(descIn.size.depth) };
- break;
- }
+ {
+ // Can't have an array and 3d texture
+ assert(desc.arraySize <= 1);
+
+ imageInfo.imageType = VK_IMAGE_TYPE_3D;
+ imageInfo.extent = VkExtent3D{
+ uint32_t(descIn.size.width),
+ uint32_t(descIn.size.height),
+ uint32_t(descIn.size.depth)};
+ break;
+ }
default:
- {
- assert(!"Unhandled type");
- return SLANG_FAIL;
- }
+ {
+ assert(!"Unhandled type");
+ return SLANG_FAIL;
+ }
}
imageInfo.mipLevels = desc.numMipLevels;
@@ -1497,47 +1552,47 @@ Result DeviceImpl::createTextureResource(
texture->m_vkformat = format;
// Create the image
- VkImageCreateInfo imageInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };
+ VkImageCreateInfo imageInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
switch (desc.type)
{
case IResource::Type::Texture1D:
- {
- imageInfo.imageType = VK_IMAGE_TYPE_1D;
- imageInfo.extent = VkExtent3D{ uint32_t(descIn.size.width), 1, 1 };
- break;
- }
+ {
+ imageInfo.imageType = VK_IMAGE_TYPE_1D;
+ imageInfo.extent = VkExtent3D{uint32_t(descIn.size.width), 1, 1};
+ break;
+ }
case IResource::Type::Texture2D:
- {
- imageInfo.imageType = VK_IMAGE_TYPE_2D;
- imageInfo.extent =
- VkExtent3D{ uint32_t(descIn.size.width), uint32_t(descIn.size.height), 1 };
- break;
- }
+ {
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.extent =
+ VkExtent3D{uint32_t(descIn.size.width), uint32_t(descIn.size.height), 1};
+ break;
+ }
case IResource::Type::TextureCube:
- {
- imageInfo.imageType = VK_IMAGE_TYPE_2D;
- imageInfo.extent =
- VkExtent3D{ uint32_t(descIn.size.width), uint32_t(descIn.size.height), 1 };
- imageInfo.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
- break;
- }
+ {
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.extent =
+ VkExtent3D{uint32_t(descIn.size.width), uint32_t(descIn.size.height), 1};
+ imageInfo.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
+ break;
+ }
case IResource::Type::Texture3D:
- {
- // Can't have an array and 3d texture
- assert(desc.arraySize <= 1);
-
- imageInfo.imageType = VK_IMAGE_TYPE_3D;
- imageInfo.extent = VkExtent3D{
- uint32_t(descIn.size.width),
- uint32_t(descIn.size.height),
- uint32_t(descIn.size.depth) };
- break;
- }
+ {
+ // Can't have an array and 3d texture
+ assert(desc.arraySize <= 1);
+
+ imageInfo.imageType = VK_IMAGE_TYPE_3D;
+ imageInfo.extent = VkExtent3D{
+ uint32_t(descIn.size.width),
+ uint32_t(descIn.size.height),
+ uint32_t(descIn.size.depth)};
+ break;
+ }
default:
- {
- assert(!"Unhandled type");
- return SLANG_FAIL;
- }
+ {
+ assert(!"Unhandled type");
+ return SLANG_FAIL;
+ }
}
imageInfo.mipLevels = desc.numMipLevels;
@@ -1552,7 +1607,7 @@ Result DeviceImpl::createTextureResource(
imageInfo.samples = (VkSampleCountFlagBits)desc.sampleDesc.numSamples;
VkExternalMemoryImageCreateInfo externalMemoryImageCreateInfo = {
- VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO };
+ VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO};
VkExternalMemoryHandleTypeFlags extMemoryHandleType =
#if SLANG_WINDOWS_FAMILY
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT;
@@ -1578,15 +1633,15 @@ Result DeviceImpl::createTextureResource(
VkMemoryPropertyFlags actualMemoryProperites =
m_api.m_deviceMemoryProperties.memoryTypes[memoryTypeIndex].propertyFlags;
- VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
+ VkMemoryAllocateInfo allocInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
allocInfo.allocationSize = memRequirements.size;
allocInfo.memoryTypeIndex = memoryTypeIndex;
#if SLANG_WINDOWS_FAMILY
VkExportMemoryWin32HandleInfoKHR exportMemoryWin32HandleInfo = {
- VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR };
+ VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR};
#endif
VkExportMemoryAllocateInfoKHR exportMemoryAllocateInfo = {
- VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR };
+ VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR};
if (descIn.isShared)
{
#if SLANG_WINDOWS_FAMILY
@@ -1598,8 +1653,8 @@ Result DeviceImpl::createTextureResource(
exportMemoryAllocateInfo.pNext =
extMemoryHandleType & VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR
- ? &exportMemoryWin32HandleInfo
- : nullptr;
+ ? &exportMemoryWin32HandleInfo
+ : nullptr;
#endif
exportMemoryAllocateInfo.handleTypes = extMemoryHandleType;
allocInfo.pNext = &exportMemoryAllocateInfo;
@@ -1705,7 +1760,7 @@ Result DeviceImpl::createTextureResource(
VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
- if(desc.sampleDesc.numSamples != 1)
+ if (desc.sampleDesc.numSamples != 1)
{
// Handle senario where texture is sampled. We cannot use
// a simple buffer copy for sampled textures. ClearColorImage
@@ -1714,70 +1769,81 @@ Result DeviceImpl::createTextureResource(
gfxGetFormatInfo(desc.format, &formatInfo);
uint32_t data = 0;
VkClearColorValue clearColor;
- switch(formatInfo.channelType)
+ switch (formatInfo.channelType)
{
case SLANG_SCALAR_TYPE_INT32:
- for(int i = 0; i < 4; i++)
- clearColor.int32[i] = *reinterpret_cast<int32_t*>(const_cast<void*>(initData->data));
+ for (int i = 0; i < 4; i++)
+ clearColor.int32[i] =
+ *reinterpret_cast<int32_t*>(const_cast<void*>(initData->data));
break;
case SLANG_SCALAR_TYPE_UINT32:
- for(int i = 0; i < 4; i++)
- clearColor.uint32[i] = *reinterpret_cast<uint32_t*>(const_cast<void*>(initData->data));
+ for (int i = 0; i < 4; i++)
+ clearColor.uint32[i] =
+ *reinterpret_cast<uint32_t*>(const_cast<void*>(initData->data));
break;
case SLANG_SCALAR_TYPE_INT64:
- {
- for(int i = 0; i < 4; i++)
- clearColor.int32[i] = int32_t(*reinterpret_cast<int64_t*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.int32[i] =
+ int32_t(*reinterpret_cast<int64_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
case SLANG_SCALAR_TYPE_UINT64:
- {
- for(int i = 0; i < 4; i++)
- clearColor.uint32[i] = uint32_t(*reinterpret_cast<uint64_t*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.uint32[i] = uint32_t(
+ *reinterpret_cast<uint64_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
case SLANG_SCALAR_TYPE_FLOAT16:
- {
- for(int i = 0; i < 4; i++)
- clearColor.float32[i] = HalfToFloat(*reinterpret_cast<uint16_t*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.float32[i] = HalfToFloat(
+ *reinterpret_cast<uint16_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
case SLANG_SCALAR_TYPE_FLOAT32:
- {
- for(int i = 0; i < 4; i++)
- clearColor.float32[i] = (*reinterpret_cast<float*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.float32[i] =
+ (*reinterpret_cast<float*>(const_cast<void*>(initData->data)));
+ break;
+ }
case SLANG_SCALAR_TYPE_FLOAT64:
- {
- for(int i = 0; i < 4; i++)
- clearColor.float32[i] = float(*reinterpret_cast<double*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.float32[i] =
+ float(*reinterpret_cast<double*>(const_cast<void*>(initData->data)));
+ break;
+ }
case SLANG_SCALAR_TYPE_INT8:
- {
- for(int i = 0; i < 4; i++)
- clearColor.int32[i] = int32_t(*reinterpret_cast<int8_t*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.int32[i] =
+ int32_t(*reinterpret_cast<int8_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
case SLANG_SCALAR_TYPE_UINT8:
- {
- for(int i = 0; i < 4; i++)
- clearColor.uint32[i] = uint32_t(*reinterpret_cast<uint8_t*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.uint32[i] = uint32_t(
+ *reinterpret_cast<uint8_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
case SLANG_SCALAR_TYPE_INT16:
- {
- for(int i = 0; i < 4; i++)
- clearColor.int32[i] = int32_t(*reinterpret_cast<int16_t*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.int32[i] =
+ int32_t(*reinterpret_cast<int16_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
case SLANG_SCALAR_TYPE_UINT16:
- {
- for(int i = 0; i < 4; i++)
- clearColor.uint32[i] = uint32_t(*reinterpret_cast<uint16_t*>(const_cast<void*>(initData->data)));
- break;
- }
+ {
+ for (int i = 0; i < 4; i++)
+ clearColor.uint32[i] = uint32_t(
+ *reinterpret_cast<uint16_t*>(const_cast<void*>(initData->data)));
+ break;
+ }
};
VkImageSubresourceRange range{};
@@ -1824,9 +1890,11 @@ Result DeviceImpl::createTextureResource(
region.imageSubresource.mipLevel = uint32_t(j);
region.imageSubresource.baseArrayLayer = i;
region.imageSubresource.layerCount = 1;
- region.imageOffset = { 0, 0, 0 };
+ region.imageOffset = {0, 0, 0};
region.imageExtent = {
- uint32_t(mipSize.width), uint32_t(mipSize.height), uint32_t(mipSize.depth) };
+ uint32_t(mipSize.width),
+ uint32_t(mipSize.height),
+ uint32_t(mipSize.depth)};
// Do the copy (do all depths in a single go)
m_api.vkCmdCopyBufferToImage(
@@ -1869,7 +1937,9 @@ Result DeviceImpl::createTextureResource(
}
Result DeviceImpl::createBufferResource(
- const IBufferResource::Desc& descIn, const void* initData, IBufferResource** outResource)
+ const IBufferResource::Desc& descIn,
+ const void* initData,
+ IBufferResource** outResource)
{
return createBufferResourceImpl(descIn, 0, initData, outResource);
}
@@ -1947,7 +2017,12 @@ Result DeviceImpl::createBufferResourceImpl(
// Copy into staging buffer
void* mappedData = nullptr;
SLANG_VK_CHECK(m_api.vkMapMemory(
- m_device, buffer->m_uploadBuffer.m_memory, 0, bufferSize, 0, &mappedData));
+ m_device,
+ buffer->m_uploadBuffer.m_memory,
+ 0,
+ bufferSize,
+ 0,
+ &mappedData));
::memcpy(mappedData, initData, bufferSize);
m_api.vkUnmapMemory(m_device, buffer->m_uploadBuffer.m_memory);
@@ -1969,7 +2044,12 @@ Result DeviceImpl::createBufferResourceImpl(
// Copy into mapped buffer directly
void* mappedData = nullptr;
SLANG_VK_CHECK(m_api.vkMapMemory(
- m_device, buffer->m_buffer.m_memory, 0, bufferSize, 0, &mappedData));
+ m_device,
+ buffer->m_buffer.m_memory,
+ 0,
+ bufferSize,
+ 0,
+ &mappedData));
::memcpy(mappedData, initData, bufferSize);
m_api.vkUnmapMemory(m_device, buffer->m_buffer.m_memory);
}
@@ -1980,7 +2060,9 @@ Result DeviceImpl::createBufferResourceImpl(
}
Result DeviceImpl::createBufferFromNativeHandle(
- InteropHandle handle, const IBufferResource::Desc& srcDesc, IBufferResource** outResource)
+ InteropHandle handle,
+ const IBufferResource::Desc& srcDesc,
+ IBufferResource** outResource)
{
RefPtr<BufferResourceImpl> buffer(new BufferResourceImpl(srcDesc, this));
@@ -1999,7 +2081,7 @@ Result DeviceImpl::createBufferFromNativeHandle(
Result DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler)
{
- VkSamplerCreateInfo samplerInfo = { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO };
+ VkSamplerCreateInfo samplerInfo = {VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
samplerInfo.magFilter = VulkanUtil::translateFilterMode(desc.minFilter);
samplerInfo.minFilter = VulkanUtil::translateFilterMode(desc.magFilter);
@@ -2021,7 +2103,8 @@ Result DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerS
samplerInfo.minLod = Math::Max(0.0f, desc.minLOD);
samplerInfo.maxLod = Math::Clamp(desc.maxLOD, samplerInfo.minLod, VK_LOD_CLAMP_NONE);
- VkSamplerReductionModeCreateInfo reductionInfo = { VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO };
+ VkSamplerReductionModeCreateInfo reductionInfo = {
+ VK_STRUCTURE_TYPE_SAMPLER_REDUCTION_MODE_CREATE_INFO};
reductionInfo.reductionMode = VulkanUtil::translateReductionOp(desc.reductionOp);
samplerInfo.pNext = &reductionInfo;
@@ -2035,7 +2118,9 @@ Result DeviceImpl::createSamplerState(ISamplerState::Desc const& desc, ISamplerS
}
Result DeviceImpl::createTextureView(
- ITextureResource* texture, IResourceView::Desc const& desc, IResourceView** outView)
+ ITextureResource* texture,
+ IResourceView::Desc const& desc,
+ IResourceView** outView)
{
auto resourceImpl = static_cast<TextureResourceImpl*>(texture);
RefPtr<TextureResourceViewImpl> view = new TextureResourceViewImpl(this);
@@ -2053,14 +2138,14 @@ Result DeviceImpl::createTextureView(
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
createInfo.flags = 0;
createInfo.format = gfxIsTypelessFormat(texture->getDesc()->format)
- ? VulkanUtil::getVkFormat(desc.format)
- : resourceImpl->m_vkformat;
+ ? VulkanUtil::getVkFormat(desc.format)
+ : resourceImpl->m_vkformat;
createInfo.image = resourceImpl->m_image;
createInfo.components = VkComponentMapping{
VK_COMPONENT_SWIZZLE_R,
VK_COMPONENT_SWIZZLE_G,
VK_COMPONENT_SWIZZLE_B,
- VK_COMPONENT_SWIZZLE_A };
+ VK_COMPONENT_SWIZZLE_A};
switch (resourceImpl->getType())
{
case IResource::Type::Texture1D:
@@ -2069,15 +2154,11 @@ Result DeviceImpl::createTextureView(
case IResource::Type::Texture2D:
createInfo.viewType = isArray ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D;
break;
- case IResource::Type::Texture3D:
- createInfo.viewType = VK_IMAGE_VIEW_TYPE_3D;
- break;
+ case IResource::Type::Texture3D: createInfo.viewType = VK_IMAGE_VIEW_TYPE_3D; break;
case IResource::Type::TextureCube:
createInfo.viewType = isArray ? VK_IMAGE_VIEW_TYPE_CUBE_ARRAY : VK_IMAGE_VIEW_TYPE_CUBE;
break;
- default:
- SLANG_UNIMPLEMENTED_X("Unknown Texture type.");
- break;
+ default: SLANG_UNIMPLEMENTED_X("Unknown Texture type."); break;
}
createInfo.subresourceRange.aspectMask = getAspectMaskFromFormat(resourceImpl->m_vkformat);
@@ -2094,8 +2175,8 @@ Result DeviceImpl::createTextureView(
}
}
createInfo.subresourceRange.levelCount = desc.subresourceRange.mipLevelCount == 0
- ? VK_REMAINING_MIP_LEVELS
- : desc.subresourceRange.mipLevelCount;
+ ? VK_REMAINING_MIP_LEVELS
+ : desc.subresourceRange.mipLevelCount;
switch (desc.type)
{
case IResourceView::Type::DepthStencil:
@@ -2109,12 +2190,8 @@ Result DeviceImpl::createTextureView(
case IResourceView::Type::ShaderResource:
view->m_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
break;
- case IResourceView::Type::UnorderedAccess:
- view->m_layout = VK_IMAGE_LAYOUT_GENERAL;
- break;
- default:
- SLANG_UNIMPLEMENTED_X("Unknown TextureViewDesc type.");
- break;
+ case IResourceView::Type::UnorderedAccess: view->m_layout = VK_IMAGE_LAYOUT_GENERAL; break;
+ default: SLANG_UNIMPLEMENTED_X("Unknown TextureViewDesc type."); break;
}
m_api.vkCreateImageView(m_device, &createInfo, nullptr, &view->m_view);
returnComPtr(outView, view);
@@ -2129,7 +2206,9 @@ Result DeviceImpl::getFormatSupportedResourceStates(Format format, ResourceState
VkFormatProperties supportedProperties = {};
m_api.vkGetPhysicalDeviceFormatProperties(
- m_api.m_physicalDevice, vkFormat, &supportedProperties);
+ m_api.m_physicalDevice,
+ vkFormat,
+ &supportedProperties);
HashSet<VkFormat> presentableFormats;
// TODO: enable this once we have VK_GOOGLE_surfaceless_query.
@@ -2147,8 +2226,8 @@ Result DeviceImpl::getFormatSupportedResourceStates(Format format, ResourceState
presentableFormats.add(surfaceFormat.format);
}
#else
-// Until we have a solution to query presentable formats without needing a surface,
-// hard code presentable formats that is supported by most drivers.
+ // Until we have a solution to query presentable formats without needing a surface,
+ // hard code presentable formats that is supported by most drivers.
presentableFormats.add(VK_FORMAT_R8G8B8A8_UNORM);
presentableFormats.add(VK_FORMAT_B8G8R8A8_UNORM);
presentableFormats.add(VK_FORMAT_R8G8B8A8_SRGB);
@@ -2167,11 +2246,8 @@ Result DeviceImpl::getFormatSupportedResourceStates(Format format, ResourceState
switch (format)
{
case Format::R32_UINT:
- case Format::R16_UINT:
- allowedStates.add(ResourceState::IndexBuffer);
- break;
- default:
- break;
+ case Format::R16_UINT: allowedStates.add(ResourceState::IndexBuffer); break;
+ default: break;
}
// ConstantBuffer
allowedStates.add(ResourceState::ConstantBuffer);
@@ -2186,7 +2262,7 @@ Result DeviceImpl::getFormatSupportedResourceStates(Format format, ResourceState
(VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT))
allowedStates.add(ResourceState::UnorderedAccess);
if (bufferFeatures & (VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT |
- VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT))
+ VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT))
allowedStates.add(ResourceState::UnorderedAccess);
// RenderTarget
if (imageFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)
@@ -2235,8 +2311,8 @@ Result DeviceImpl::createBufferView(
VkDeviceSize offset = (VkDeviceSize)desc.bufferRange.offset;
VkDeviceSize size = desc.bufferRange.size == 0
- ? (buffer ? resourceImpl->getDesc()->sizeInBytes : 0)
- : (VkDeviceSize)desc.bufferRange.size;
+ ? (buffer ? resourceImpl->getDesc()->sizeInBytes : 0)
+ : (VkDeviceSize)desc.bufferRange.size;
// There are two different cases we need to think about for buffers.
//
@@ -2259,9 +2335,7 @@ Result DeviceImpl::createBufferView(
switch (desc.type)
{
- default:
- assert(!"unhandled");
- return SLANG_FAIL;
+ default: assert(!"unhandled"); return SLANG_FAIL;
case IResourceView::Type::UnorderedAccess:
case IResourceView::Type::ShaderResource:
@@ -2286,7 +2360,7 @@ Result DeviceImpl::createBufferView(
//
// FALLTHROUGH
{
- VkBufferViewCreateInfo info = { VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO };
+ VkBufferViewCreateInfo info = {VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO};
VkBufferView view = VK_NULL_HANDLE;
@@ -2352,8 +2426,8 @@ Result DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayou
dstStream.stride = (uint32_t)srcStream.stride;
dstStream.binding = (uint32_t)i;
dstStream.inputRate = (srcStream.slotClass == InputSlotClass::PerInstance)
- ? VK_VERTEX_INPUT_RATE_INSTANCE
- : VK_VERTEX_INPUT_RATE_VERTEX;
+ ? VK_VERTEX_INPUT_RATE_INSTANCE
+ : VK_VERTEX_INPUT_RATE_VERTEX;
}
for (Int i = 0; i < numElements; ++i)
@@ -2380,7 +2454,9 @@ Result DeviceImpl::createInputLayout(IInputLayout::Desc const& desc, IInputLayou
}
Result DeviceImpl::createProgram(
- const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnosticBlob)
{
RefPtr<ShaderProgramImpl> shaderProgram = new ShaderProgramImpl(this);
shaderProgram->init(desc);
@@ -2418,13 +2494,16 @@ Result DeviceImpl::createShaderObject(ShaderObjectLayoutBase* layout, IShaderObj
{
RefPtr<ShaderObjectImpl> shaderObject;
SLANG_RETURN_ON_FAIL(ShaderObjectImpl::create(
- this, static_cast<ShaderObjectLayoutImpl*>(layout), shaderObject.writeRef()));
+ this,
+ static_cast<ShaderObjectLayoutImpl*>(layout),
+ shaderObject.writeRef()));
returnComPtr(outObject, shaderObject);
return SLANG_OK;
}
Result DeviceImpl::createMutableShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject)
{
auto layoutImpl = static_cast<ShaderObjectLayoutImpl*>(layout);
@@ -2454,7 +2533,8 @@ Result DeviceImpl::createShaderTable(const IShaderTable::Desc& desc, IShaderTabl
}
Result DeviceImpl::createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& inDesc, IPipelineState** outState)
+ const GraphicsPipelineStateDesc& inDesc,
+ IPipelineState** outState)
{
GraphicsPipelineStateDesc desc = inDesc;
RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl(this);
@@ -2467,7 +2547,8 @@ Result DeviceImpl::createGraphicsPipelineState(
}
Result DeviceImpl::createComputePipelineState(
- const ComputePipelineStateDesc& inDesc, IPipelineState** outState)
+ const ComputePipelineStateDesc& inDesc,
+ IPipelineState** outState)
{
ComputePipelineStateDesc desc = inDesc;
RefPtr<PipelineStateImpl> pipelineStateImpl = new PipelineStateImpl(this);
@@ -2479,7 +2560,8 @@ Result DeviceImpl::createComputePipelineState(
}
Result DeviceImpl::createRayTracingPipelineState(
- const RayTracingPipelineStateDesc& desc, IPipelineState** outState)
+ const RayTracingPipelineStateDesc& desc,
+ IPipelineState** outState)
{
RefPtr<RayTracingPipelineStateImpl> pipelineStateImpl = new RayTracingPipelineStateImpl(this);
pipelineStateImpl->init(desc);
@@ -2506,7 +2588,11 @@ Result DeviceImpl::createFence(const IFence::Desc& desc, IFence** outFence)
}
Result DeviceImpl::waitForFences(
- GfxCount fenceCount, IFence** fences, uint64_t* fenceValues, bool waitForAll, uint64_t timeout)
+ GfxCount fenceCount,
+ IFence** fences,
+ uint64_t* fenceValues,
+ bool waitForAll,
+ uint64_t timeout)
{
ShortList<VkSemaphore> semaphores;
for (GfxIndex i = 0; i < fenceCount; ++i)
diff --git a/tools/gfx/vulkan/vk-device.h b/tools/gfx/vulkan/vk-device.h
index 89c7aa103..3b6c83103 100644
--- a/tools/gfx/vulkan/vk-device.h
+++ b/tools/gfx/vulkan/vk-device.h
@@ -19,19 +19,24 @@ public:
Result initVulkanInstanceAndDevice(const InteropHandle* handles, bool useValidationLayer);
virtual SLANG_NO_THROW Result SLANG_MCALL initialize(const Desc& desc) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
+ getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap(
- const ITransientResourceHeap::Desc& desc, ITransientResourceHeap** outHeap) override;
+ const ITransientResourceHeap::Desc& desc,
+ ITransientResourceHeap** outHeap) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
+ createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createSwapchain(
- const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;
+ const ISwapchain::Desc& desc,
+ WindowHandle window,
+ ISwapchain** outSwapchain) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createFramebufferLayout(
- const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override;
+ const IFramebufferLayout::Desc& desc,
+ IFramebufferLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
+ createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createRenderPassLayout(
- const IRenderPassLayout::Desc& desc, IRenderPassLayout** outRenderPassLayout) override;
+ const IRenderPassLayout::Desc& desc,
+ IRenderPassLayout** outRenderPassLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureResource(
const ITextureResource::Desc& desc,
const ITextureResource::SubresourceData* initData,
@@ -50,7 +55,7 @@ public:
const IBufferResource::Desc& srcDesc,
IBufferResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
+ createSamplerState(ISamplerState::Desc const& desc, ISamplerState** outSampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTextureView(
ITextureResource* texture,
@@ -63,33 +68,37 @@ public:
IResourceView** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
+ createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
virtual Result createShaderObjectLayout(
slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) override;
- virtual Result createShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
+ virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject)
+ override;
virtual Result createMutableShaderObject(
- ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
+ ShaderObjectLayoutBase* layout,
+ IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
+ createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outShaderTable) override;
+ createShaderTable(const IShaderTable::Desc& desc, IShaderTable** outShaderTable) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createProgram(
const IShaderProgram::Desc& desc,
IShaderProgram** outProgram,
ISlangBlob** outDiagnosticBlob) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
- const GraphicsPipelineStateDesc& desc, IPipelineState** outState) override;
+ const GraphicsPipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
- const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
+ const ComputePipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createRayTracingPipelineState(
- const RayTracingPipelineStateDesc& desc, IPipelineState** outState) override;
+ const RayTracingPipelineStateDesc& desc,
+ IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
+ createQueryPool(const IQueryPool::Desc& desc, IQueryPool** outPool) override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL readTextureResource(
ITextureResource* texture,
@@ -99,22 +108,28 @@ public:
Size* outPixelSize) override;
virtual SLANG_NO_THROW SlangResult SLANG_MCALL readBufferResource(
- IBufferResource* buffer, Offset offset, Size size, ISlangBlob** outBlob) override;
+ IBufferResource* buffer,
+ Offset offset,
+ Size size,
+ ISlangBlob** outBlob) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getAccelerationStructurePrebuildInfo(
const IAccelerationStructure::BuildInputs& buildInputs,
IAccelerationStructure::PrebuildInfo* outPrebuildInfo) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createAccelerationStructure(
- const IAccelerationStructure::CreateDesc& desc, IAccelerationStructure** outView) override;
+ const IAccelerationStructure::CreateDesc& desc,
+ IAccelerationStructure** outView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureAllocationInfo(
- const ITextureResource::Desc& desc, Size* outSize, Size* outAlignment) override;
+ const ITextureResource::Desc& desc,
+ Size* outSize,
+ Size* outAlignment) override;
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;
+ createFence(const IFence::Desc& desc, IFence** outFence) override;
virtual SLANG_NO_THROW Result SLANG_MCALL waitForFences(
GfxCount fenceCount,
@@ -128,7 +143,7 @@ public:
virtual SLANG_NO_THROW const DeviceInfo& SLANG_MCALL getDeviceInfo() const override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeDeviceHandles(InteropHandles* outHandles) override;
+ getNativeDeviceHandles(InteropHandles* outHandles) override;
~DeviceImpl();
@@ -146,7 +161,8 @@ public:
VkDebugReportFlagsEXT flags,
VkDebugReportObjectTypeEXT objType,
uint64_t srcObject,
- Size location, // TODO: Is "location" still needed? Calls handleDebugMessage() which doesn't use it
+ Size location, // TODO: Is "location" still needed? Calls handleDebugMessage() which doesn't
+ // use it
int32_t msgCode,
const char* pLayerPrefix,
const char* pMsg,
diff --git a/tools/gfx/vulkan/vk-fence.cpp b/tools/gfx/vulkan/vk-fence.cpp
index d71847dcb..9ecbcb712 100644
--- a/tools/gfx/vulkan/vk-fence.cpp
+++ b/tools/gfx/vulkan/vk-fence.cpp
@@ -18,7 +18,8 @@ namespace vk
FenceImpl::FenceImpl(DeviceImpl* device)
: m_device(device)
-{}
+{
+}
FenceImpl::~FenceImpl()
{
@@ -51,11 +52,12 @@ Result FenceImpl::init(const IFence::Desc& desc)
if (desc.isShared)
{
#if SLANG_WINDOWS_FAMILY
- exportSemaphoreWin32HandleInfoKHR.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR;
+ exportSemaphoreWin32HandleInfoKHR.sType =
+ VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR;
exportSemaphoreWin32HandleInfoKHR.pNext = timelineCreateInfo.pNext;
exportSemaphoreWin32HandleInfoKHR.pAttributes = nullptr;
exportSemaphoreWin32HandleInfoKHR.dwAccess = GENERIC_ALL;
- exportSemaphoreWin32HandleInfoKHR.name = (LPCWSTR)nullptr;
+ exportSemaphoreWin32HandleInfoKHR.name = (LPCWSTR) nullptr;
#endif
exportSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO_KHR;
#if SLANG_WINDOWS_FAMILY
@@ -69,7 +71,10 @@ Result FenceImpl::init(const IFence::Desc& desc)
}
SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkCreateSemaphore(
- m_device->m_api.m_device, &createInfo, nullptr, &m_semaphore));
+ m_device->m_api.m_device,
+ &createInfo,
+ nullptr,
+ &m_semaphore));
return SLANG_OK;
}
@@ -77,7 +82,9 @@ Result FenceImpl::init(const IFence::Desc& desc)
Result FenceImpl::getCurrentValue(uint64_t* outValue)
{
SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkGetSemaphoreCounterValue(
- m_device->m_api.m_device, m_semaphore, outValue));
+ m_device->m_api.m_device,
+ m_semaphore,
+ outValue));
return SLANG_OK;
}
@@ -85,7 +92,9 @@ Result FenceImpl::setCurrentValue(uint64_t value)
{
uint64_t currentValue = 0;
SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkGetSemaphoreCounterValue(
- m_device->m_api.m_device, m_semaphore, &currentValue));
+ m_device->m_api.m_device,
+ m_semaphore,
+ &currentValue));
if (currentValue < value)
{
VkSemaphoreSignalInfo signalInfo;
@@ -117,16 +126,19 @@ Result FenceImpl::getSharedHandle(InteropHandle* outHandle)
handleInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT;
SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkGetSemaphoreWin32HandleKHR(
- m_device->m_api.m_device, &handleInfo, (HANDLE*)&sharedHandle.handleValue));
+ m_device->m_api.m_device,
+ &handleInfo,
+ (HANDLE*)&sharedHandle.handleValue));
#else
- VkSemaphoreGetFdInfoKHR fdInfo = {
- VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR};
+ VkSemaphoreGetFdInfoKHR fdInfo = {VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR};
fdInfo.pNext = nullptr;
fdInfo.semaphore = m_semaphore;
fdInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT;
SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkGetSemaphoreFdKHR(
- m_device->m_api.m_device, &fdInfo, (int*)&sharedHandle.handleValue));
+ m_device->m_api.m_device,
+ &fdInfo,
+ (int*)&sharedHandle.handleValue));
#endif
sharedHandle.api = InteropHandleAPI::Vulkan;
diff --git a/tools/gfx/vulkan/vk-fence.h b/tools/gfx/vulkan/vk-fence.h
index 46b0ebc2b..a70334ac2 100644
--- a/tools/gfx/vulkan/vk-fence.h
+++ b/tools/gfx/vulkan/vk-fence.h
@@ -30,7 +30,7 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeHandle(InteropHandle* outNativeHandle) override;
+ getNativeHandle(InteropHandle* outNativeHandle) override;
};
} // namespace vk
diff --git a/tools/gfx/vulkan/vk-framebuffer.cpp b/tools/gfx/vulkan/vk-framebuffer.cpp
index 7f91b0d19..3eef533fa 100644
--- a/tools/gfx/vulkan/vk-framebuffer.cpp
+++ b/tools/gfx/vulkan/vk-framebuffer.cpp
@@ -2,9 +2,8 @@
#include "vk-framebuffer.h"
#include "vk-device.h"
-#include "vk-resource-views.h"
-
#include "vk-helper-functions.h"
+#include "vk-resource-views.h"
namespace gfx
{
@@ -106,7 +105,10 @@ Result FramebufferLayoutImpl::init(DeviceImpl* renderer, const IFramebufferLayou
renderPassCreateInfo.subpassCount = 1;
renderPassCreateInfo.pSubpasses = &subpassDesc;
SLANG_VK_RETURN_ON_FAIL(m_renderer->m_api.vkCreateRenderPass(
- m_renderer->m_api.m_device, &renderPassCreateInfo, nullptr, &m_renderPass));
+ m_renderer->m_api.m_device,
+ &renderPassCreateInfo,
+ nullptr,
+ &m_renderPass));
return SLANG_OK;
}
@@ -142,7 +144,9 @@ Result FramebufferImpl::init(DeviceImpl* renderer, const IFramebuffer::Desc& des
auto size = resourceDesc->size;
m_width = getMipLevelSize(viewDesc->subresourceRange.mipLevel, size.width);
m_height = getMipLevelSize(viewDesc->subresourceRange.mipLevel, size.height);
- layerCount = (resourceDesc->type == IResource::Type::Texture3D) ? size.depth : viewDesc->subresourceRange.layerCount;
+ layerCount = (resourceDesc->type == IResource::Type::Texture3D)
+ ? size.depth
+ : viewDesc->subresourceRange.layerCount;
}
else
{
@@ -200,7 +204,10 @@ Result FramebufferImpl::init(DeviceImpl* renderer, const IFramebuffer::Desc& des
framebufferInfo.layers = layerCount;
SLANG_VK_RETURN_ON_FAIL(m_renderer->m_api.vkCreateFramebuffer(
- m_renderer->m_api.m_device, &framebufferInfo, nullptr, &m_handle));
+ m_renderer->m_api.m_device,
+ &framebufferInfo,
+ nullptr,
+ &m_handle));
return SLANG_OK;
}
diff --git a/tools/gfx/vulkan/vk-helper-functions.cpp b/tools/gfx/vulkan/vk-helper-functions.cpp
index 1f7c6b6ff..b7bbeec2b 100644
--- a/tools/gfx/vulkan/vk-helper-functions.cpp
+++ b/tools/gfx/vulkan/vk-helper-functions.cpp
@@ -31,12 +31,9 @@ VkAttachmentLoadOp translateLoadOp(IRenderPassLayout::TargetLoadOp loadOp)
{
switch (loadOp)
{
- case IRenderPassLayout::TargetLoadOp::Clear:
- return VK_ATTACHMENT_LOAD_OP_CLEAR;
- case IRenderPassLayout::TargetLoadOp::Load:
- return VK_ATTACHMENT_LOAD_OP_LOAD;
- default:
- return VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ case IRenderPassLayout::TargetLoadOp::Clear: return VK_ATTACHMENT_LOAD_OP_CLEAR;
+ case IRenderPassLayout::TargetLoadOp::Load: return VK_ATTACHMENT_LOAD_OP_LOAD;
+ default: return VK_ATTACHMENT_LOAD_OP_DONT_CARE;
}
}
@@ -44,10 +41,8 @@ VkAttachmentStoreOp translateStoreOp(IRenderPassLayout::TargetStoreOp storeOp)
{
switch (storeOp)
{
- case IRenderPassLayout::TargetStoreOp::Store:
- return VK_ATTACHMENT_STORE_OP_STORE;
- default:
- return VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ case IRenderPassLayout::TargetStoreOp::Store: return VK_ATTACHMENT_STORE_OP_STORE;
+ default: return VK_ATTACHMENT_STORE_OP_DONT_CARE;
}
}
@@ -71,33 +66,21 @@ VkImageLayout translateImageLayout(ResourceState state)
{
switch (state)
{
- case ResourceState::Undefined:
- return VK_IMAGE_LAYOUT_UNDEFINED;
- case ResourceState::PreInitialized:
- return VK_IMAGE_LAYOUT_PREINITIALIZED;
- case ResourceState::UnorderedAccess:
- return VK_IMAGE_LAYOUT_GENERAL;
- case ResourceState::RenderTarget:
- return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
- case ResourceState::DepthRead:
- return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
- case ResourceState::DepthWrite:
- return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+ case ResourceState::Undefined: return VK_IMAGE_LAYOUT_UNDEFINED;
+ case ResourceState::PreInitialized: return VK_IMAGE_LAYOUT_PREINITIALIZED;
+ case ResourceState::UnorderedAccess: return VK_IMAGE_LAYOUT_GENERAL;
+ case ResourceState::RenderTarget: return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ case ResourceState::DepthRead: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
+ case ResourceState::DepthWrite: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
case ResourceState::ShaderResource:
case ResourceState::NonPixelShaderResource:
- case ResourceState::PixelShaderResource:
- return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+ case ResourceState::PixelShaderResource: return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
case ResourceState::ResolveDestination:
- case ResourceState::CopyDestination:
- return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ case ResourceState::CopyDestination: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
case ResourceState::ResolveSource:
- case ResourceState::CopySource:
- return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
- case ResourceState::Present:
- return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
- default:
- assert(!"Unsupported");
- return VK_IMAGE_LAYOUT_UNDEFINED;
+ case ResourceState::CopySource: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
+ case ResourceState::Present: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+ default: assert(!"Unsupported"); return VK_IMAGE_LAYOUT_UNDEFINED;
}
}
@@ -107,37 +90,28 @@ VkAccessFlagBits calcAccessFlags(ResourceState state)
{
case ResourceState::Undefined:
case ResourceState::Present:
- case ResourceState::PreInitialized:
- return VkAccessFlagBits(0);
- case ResourceState::VertexBuffer:
- return VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
- case ResourceState::ConstantBuffer:
- return VK_ACCESS_UNIFORM_READ_BIT;
- case ResourceState::IndexBuffer:
- return VK_ACCESS_INDEX_READ_BIT;
+ case ResourceState::PreInitialized: return VkAccessFlagBits(0);
+ case ResourceState::VertexBuffer: return VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
+ case ResourceState::ConstantBuffer: return VK_ACCESS_UNIFORM_READ_BIT;
+ case ResourceState::IndexBuffer: return VK_ACCESS_INDEX_READ_BIT;
case ResourceState::RenderTarget:
return VkAccessFlagBits(
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT);
case ResourceState::ShaderResource:
case ResourceState::NonPixelShaderResource:
- case ResourceState::PixelShaderResource:
- return VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
+ case ResourceState::PixelShaderResource: return VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
case ResourceState::UnorderedAccess:
return VkAccessFlagBits(VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT);
- case ResourceState::DepthRead:
- return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
+ case ResourceState::DepthRead: return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
case ResourceState::DepthWrite:
return VkAccessFlagBits(
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT);
- case ResourceState::IndirectArgument:
- return VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
+ case ResourceState::IndirectArgument: return VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
case ResourceState::ResolveDestination:
- case ResourceState::CopyDestination:
- return VK_ACCESS_TRANSFER_WRITE_BIT;
+ case ResourceState::CopyDestination: return VK_ACCESS_TRANSFER_WRITE_BIT;
case ResourceState::ResolveSource:
- case ResourceState::CopySource:
- return VK_ACCESS_TRANSFER_READ_BIT;
+ case ResourceState::CopySource: return VK_ACCESS_TRANSFER_READ_BIT;
case ResourceState::AccelerationStructure:
return VkAccessFlagBits(
VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR |
@@ -146,9 +120,7 @@ VkAccessFlagBits calcAccessFlags(ResourceState state)
return VkAccessFlagBits(VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR);
case ResourceState::General:
return VkAccessFlagBits(VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT);
- default:
- assert(!"Unsupported");
- return VkAccessFlagBits(0);
+ default: assert(!"Unsupported"); return VkAccessFlagBits(0);
}
}
@@ -157,12 +129,9 @@ VkPipelineStageFlagBits calcPipelineStageFlags(ResourceState state, bool src)
switch (state)
{
case ResourceState::Undefined:
- case ResourceState::PreInitialized:
- assert(src);
- return VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
+ case ResourceState::PreInitialized: assert(src); return VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
case ResourceState::VertexBuffer:
- case ResourceState::IndexBuffer:
- return VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
+ case ResourceState::IndexBuffer: return VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
case ResourceState::ConstantBuffer:
case ResourceState::UnorderedAccess:
return VkPipelineStageFlagBits(
@@ -173,27 +142,22 @@ VkPipelineStageFlagBits calcPipelineStageFlags(ResourceState state, bool src)
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR);
case ResourceState::ShaderResource:
case ResourceState::NonPixelShaderResource:
- case ResourceState::PixelShaderResource:
- return VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
- case ResourceState::RenderTarget:
- return VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
+ case ResourceState::PixelShaderResource: return VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
+ case ResourceState::RenderTarget: return VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
case ResourceState::DepthRead:
case ResourceState::DepthWrite:
return VkPipelineStageFlagBits(
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
- case ResourceState::IndirectArgument:
- return VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT;
+ case ResourceState::IndirectArgument: return VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT;
case ResourceState::CopySource:
case ResourceState::CopyDestination:
case ResourceState::ResolveSource:
- case ResourceState::ResolveDestination:
- return VK_PIPELINE_STAGE_TRANSFER_BIT;
+ case ResourceState::ResolveDestination: return VK_PIPELINE_STAGE_TRANSFER_BIT;
case ResourceState::Present:
return src ? VkPipelineStageFlagBits(
- VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT)
- : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
- case ResourceState::General:
- return VkPipelineStageFlagBits(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
+ VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT)
+ : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
+ case ResourceState::General: return VkPipelineStageFlagBits(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
case ResourceState::AccelerationStructure:
return VkPipelineStageFlagBits(
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT |
@@ -204,9 +168,7 @@ VkPipelineStageFlagBits calcPipelineStageFlags(ResourceState state, bool src)
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR);
case ResourceState::AccelerationStructureBuildInput:
return VkPipelineStageFlagBits(VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR);
- default:
- assert(!"Unsupported");
- return VkPipelineStageFlagBits(0);
+ default: assert(!"Unsupported"); return VkPipelineStageFlagBits(0);
}
}
@@ -215,7 +177,7 @@ VkAccessFlags translateAccelerationStructureAccessFlag(AccessFlag access)
VkAccessFlags result = 0;
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;
+ VK_ACCESS_TRANSFER_READ_BIT;
if ((uint32_t)access & (uint32_t)AccessFlag::Write)
result |= VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR;
return result;
@@ -225,41 +187,33 @@ VkBufferUsageFlagBits _calcBufferUsageFlags(ResourceState state)
{
switch (state)
{
- case ResourceState::VertexBuffer:
- return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
- case ResourceState::IndexBuffer:
- return VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
- case ResourceState::ConstantBuffer:
- return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
- case ResourceState::StreamOutput:
- return VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT;
+ case ResourceState::VertexBuffer: return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
+ case ResourceState::IndexBuffer: return VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
+ case ResourceState::ConstantBuffer: return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
+ case ResourceState::StreamOutput: return VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT;
case ResourceState::RenderTarget:
case ResourceState::DepthRead:
case ResourceState::DepthWrite:
- {
- assert(!"Invalid resource state for buffer resource.");
- return VkBufferUsageFlagBits(0);
- }
+ {
+ assert(!"Invalid resource state for buffer resource.");
+ return VkBufferUsageFlagBits(0);
+ }
case ResourceState::UnorderedAccess:
- return (
- VkBufferUsageFlagBits)(VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
+ return (VkBufferUsageFlagBits)(VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT |
+ VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
case ResourceState::ShaderResource:
case ResourceState::NonPixelShaderResource:
case ResourceState::PixelShaderResource:
- return (
- VkBufferUsageFlagBits)(VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
- case ResourceState::CopySource:
- return VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
- case ResourceState::CopyDestination:
- return VK_BUFFER_USAGE_TRANSFER_DST_BIT;
+ return (VkBufferUsageFlagBits)(VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
+ VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
+ case ResourceState::CopySource: return VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
+ case ResourceState::CopyDestination: return VK_BUFFER_USAGE_TRANSFER_DST_BIT;
case ResourceState::AccelerationStructure:
return VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR;
- case ResourceState::IndirectArgument:
- return VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT;
+ case ResourceState::IndirectArgument: return VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT;
case ResourceState::AccelerationStructureBuildInput:
return VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR;
- default:
- return VkBufferUsageFlagBits(0);
+ default: return VkBufferUsageFlagBits(0);
}
}
@@ -279,36 +233,25 @@ VkImageUsageFlagBits _calcImageUsageFlags(ResourceState state)
{
switch (state)
{
- case ResourceState::RenderTarget:
- return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
- case ResourceState::DepthWrite:
- return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
- case ResourceState::DepthRead:
- return VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
+ case ResourceState::RenderTarget: return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+ case ResourceState::DepthWrite: return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
+ case ResourceState::DepthRead: return VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
case ResourceState::ShaderResource:
case ResourceState::NonPixelShaderResource:
- case ResourceState::PixelShaderResource:
- return VK_IMAGE_USAGE_SAMPLED_BIT;
- case ResourceState::UnorderedAccess:
- return VK_IMAGE_USAGE_STORAGE_BIT;
- case ResourceState::CopySource:
- return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
- case ResourceState::CopyDestination:
- return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
- case ResourceState::ResolveSource:
- return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
- case ResourceState::ResolveDestination:
- return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
- case ResourceState::Present:
- return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
+ case ResourceState::PixelShaderResource: return VK_IMAGE_USAGE_SAMPLED_BIT;
+ case ResourceState::UnorderedAccess: return VK_IMAGE_USAGE_STORAGE_BIT;
+ case ResourceState::CopySource: return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
+ case ResourceState::CopyDestination: return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
+ case ResourceState::ResolveSource: return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
+ case ResourceState::ResolveDestination: return VK_IMAGE_USAGE_TRANSFER_DST_BIT;
+ case ResourceState::Present: return VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
case ResourceState::Undefined:
- case ResourceState::General:
- return (VkImageUsageFlagBits)0;
+ case ResourceState::General: return (VkImageUsageFlagBits)0;
default:
- {
- assert(!"Unsupported");
- return VkImageUsageFlagBits(0);
- }
+ {
+ assert(!"Unsupported");
+ return VkImageUsageFlagBits(0);
+ }
}
}
@@ -323,17 +266,16 @@ VkImageViewType _calcImageViewType(ITextureResource::Type type, const ITextureRe
case IResource::Type::TextureCube:
return desc.arraySize > 1 ? VK_IMAGE_VIEW_TYPE_CUBE_ARRAY : VK_IMAGE_VIEW_TYPE_CUBE;
case IResource::Type::Texture3D:
- {
- // Can't have an array and 3d texture
- assert(desc.arraySize <= 1);
- if (desc.arraySize <= 1)
{
- return VK_IMAGE_VIEW_TYPE_3D;
+ // Can't have an array and 3d texture
+ assert(desc.arraySize <= 1);
+ if (desc.arraySize <= 1)
+ {
+ return VK_IMAGE_VIEW_TYPE_3D;
+ }
+ break;
}
- break;
- }
- default:
- break;
+ default: break;
}
return VK_IMAGE_VIEW_TYPE_MAX_ENUM;
@@ -352,7 +294,9 @@ VkImageUsageFlagBits _calcImageUsageFlags(ResourceStateSet states)
}
VkImageUsageFlags _calcImageUsageFlags(
- ResourceStateSet states, MemoryType memoryType, const void* initData)
+ ResourceStateSet states,
+ MemoryType memoryType,
+ const void* initData)
{
VkImageUsageFlags usage = _calcImageUsageFlags(states);
@@ -387,12 +331,9 @@ VkAccessFlags calcAccessFlagsFromImageLayout(VkImageLayout layout)
case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL:
case VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL:
return VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
- case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
- return VK_ACCESS_SHADER_READ_BIT;
- case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
- return VK_ACCESS_TRANSFER_READ_BIT;
- case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
- return VK_ACCESS_TRANSFER_WRITE_BIT;
+ case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: return VK_ACCESS_SHADER_READ_BIT;
+ case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: return VK_ACCESS_TRANSFER_READ_BIT;
+ case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: return VK_ACCESS_TRANSFER_WRITE_BIT;
default:
assert(!"Unsupported VkImageLayout");
return (VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT);
@@ -406,16 +347,13 @@ VkPipelineStageFlags calcPipelineStageFlagsFromImageLayout(VkImageLayout layout)
case VK_IMAGE_LAYOUT_UNDEFINED:
case VK_IMAGE_LAYOUT_PREINITIALIZED:
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
- case VK_IMAGE_LAYOUT_GENERAL:
- return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+ case VK_IMAGE_LAYOUT_GENERAL: return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
return VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL:
return (VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
- case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
- return VK_PIPELINE_STAGE_TRANSFER_BIT;
- case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
- return VK_PIPELINE_STAGE_TRANSFER_BIT;
+ case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: return VK_PIPELINE_STAGE_TRANSFER_BIT;
+ case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: return VK_PIPELINE_STAGE_TRANSFER_BIT;
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL:
@@ -426,9 +364,7 @@ VkPipelineStageFlags calcPipelineStageFlagsFromImageLayout(VkImageLayout layout)
case VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL:
return (
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT);
- default:
- assert(!"Unsupported VkImageLayout");
- return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+ default: assert(!"Unsupported VkImageLayout"); return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
}
}
@@ -442,12 +378,9 @@ VkImageAspectFlags getAspectMaskFromFormat(VkFormat format)
return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
case VK_FORMAT_D16_UNORM:
case VK_FORMAT_D32_SFLOAT:
- case VK_FORMAT_X8_D24_UNORM_PACK32:
- return VK_IMAGE_ASPECT_DEPTH_BIT;
- case VK_FORMAT_S8_UINT:
- return VK_IMAGE_ASPECT_STENCIL_BIT;
- default:
- return VK_IMAGE_ASPECT_COLOR_BIT;
+ case VK_FORMAT_X8_D24_UNORM_PACK32: return VK_IMAGE_ASPECT_DEPTH_BIT;
+ case VK_FORMAT_S8_UINT: return VK_IMAGE_ASPECT_STENCIL_BIT;
+ default: return VK_IMAGE_ASPECT_COLOR_BIT;
}
}
@@ -455,8 +388,8 @@ AdapterLUID getAdapterLUID(VulkanApi api, VkPhysicalDevice physicalDevice)
{
AdapterLUID luid = {};
- VkPhysicalDeviceIDPropertiesKHR idProps = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR };
- VkPhysicalDeviceProperties2 props = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
+ VkPhysicalDeviceIDPropertiesKHR idProps = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR};
+ VkPhysicalDeviceProperties2 props = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
props.pNext = &idProps;
SLANG_ASSERT(api.vkGetPhysicalDeviceFeatures2);
api.vkGetPhysicalDeviceProperties2(physicalDevice, &props);
@@ -487,7 +420,7 @@ Result SLANG_MCALL getVKAdapters(List<AdapterInfo>& outAdapters)
if (api.initGlobalProcs(module) != SLANG_OK)
continue;
- VkInstanceCreateInfo instanceCreateInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
+ VkInstanceCreateInfo instanceCreateInfo = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
const char* instanceExtensions[] = {
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
#if SLANG_APPLE_FAMILY
@@ -509,18 +442,25 @@ Result SLANG_MCALL getVKAdapters(List<AdapterInfo>& outAdapters)
if (api.vkEnumeratePhysicalDevices || api.vkGetPhysicalDeviceProperties)
{
uint32_t numPhysicalDevices = 0;
- SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, nullptr));
+ SLANG_VK_RETURN_ON_FAIL(
+ api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, nullptr));
List<VkPhysicalDevice> physicalDevices;
physicalDevices.setCount(numPhysicalDevices);
- SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(instance, &numPhysicalDevices, physicalDevices.getBuffer()));
+ SLANG_VK_RETURN_ON_FAIL(api.vkEnumeratePhysicalDevices(
+ instance,
+ &numPhysicalDevices,
+ physicalDevices.getBuffer()));
for (const auto& physicalDevice : physicalDevices)
{
VkPhysicalDeviceProperties props;
api.vkGetPhysicalDeviceProperties(physicalDevice, &props);
AdapterInfo info = {};
- memcpy(info.name, props.deviceName, Math::Min(strlen(props.deviceName), sizeof(AdapterInfo::name) - 1));
+ memcpy(
+ info.name,
+ props.deviceName,
+ Math::Min(strlen(props.deviceName), sizeof(AdapterInfo::name) - 1));
info.vendorID = props.vendorID;
info.deviceID = props.deviceID;
info.luid = vk::getAdapterLUID(api, physicalDevice);
diff --git a/tools/gfx/vulkan/vk-helper-functions.h b/tools/gfx/vulkan/vk-helper-functions.h
index 8eab863f4..59dc61230 100644
--- a/tools/gfx/vulkan/vk-helper-functions.h
+++ b/tools/gfx/vulkan/vk-helper-functions.h
@@ -1,30 +1,30 @@
// vk-helper-functions.h
#pragma once
-#include "vk-base.h"
#include "core/slang-blob.h"
+#include "vk-base.h"
#include "vk-util.h"
// Vulkan has a different coordinate system to ogl
// http://anki3d.org/vulkan-coordinate-system/
#ifndef ENABLE_VALIDATION_LAYER
-# if _DEBUG
-# define ENABLE_VALIDATION_LAYER 1
-# else
-# define ENABLE_VALIDATION_LAYER 0
-# endif
+#if _DEBUG
+#define ENABLE_VALIDATION_LAYER 1
+#else
+#define ENABLE_VALIDATION_LAYER 0
+#endif
#endif
#ifdef _MSC_VER
-# include <stddef.h>
-# pragma warning(disable : 4996)
-# if (_MSC_VER < 1900)
-# define snprintf sprintf_s
-# endif
+#include <stddef.h>
+#pragma warning(disable : 4996)
+#if (_MSC_VER < 1900)
+#define snprintf sprintf_s
+#endif
#endif
#if SLANG_WINDOWS_FAMILY
-# include <dxgi1_2.h>
+#include <dxgi1_2.h>
#endif
namespace gfx
@@ -108,13 +108,14 @@ struct BindingOffset : SimpleBindingOffset
/// Create an offset from a simple offset
explicit BindingOffset(SimpleBindingOffset const& offset)
: SimpleBindingOffset(offset)
- {}
+ {
+ }
/// Create an offset based on offset information in the given Slang `varLayout`
BindingOffset(slang::VariableLayoutReflection* varLayout)
- : SimpleBindingOffset(varLayout)
- , pending(varLayout->getPendingDataLayout())
- {}
+ : SimpleBindingOffset(varLayout), pending(varLayout->getPendingDataLayout())
+ {
+ }
/// Add any values in the given `offset`
void operator+=(SimpleBindingOffset const& offset) { SimpleBindingOffset::operator+=(offset); }
@@ -166,7 +167,9 @@ VkImageUsageFlagBits _calcImageUsageFlags(ResourceState state);
VkImageViewType _calcImageViewType(ITextureResource::Type type, const ITextureResource::Desc& desc);
VkImageUsageFlagBits _calcImageUsageFlags(ResourceStateSet states);
VkImageUsageFlags _calcImageUsageFlags(
- ResourceStateSet states, MemoryType memoryType, const void* initData);
+ ResourceStateSet states,
+ MemoryType memoryType,
+ const void* initData);
VkAccessFlags calcAccessFlagsFromImageLayout(VkImageLayout layout);
VkPipelineStageFlags calcPipelineStageFlagsFromImageLayout(VkImageLayout layout);
diff --git a/tools/gfx/vulkan/vk-module.cpp b/tools/gfx/vulkan/vk-module.cpp
index 0e4df8e7f..6a3d4e095 100644
--- a/tools/gfx/vulkan/vk-module.cpp
+++ b/tools/gfx/vulkan/vk-module.cpp
@@ -1,19 +1,20 @@
// module.cpp
#include "vk-module.h"
-#include <stdlib.h>
-#include <stdio.h>
#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
#if SLANG_WINDOWS_FAMILY
-# include <windows.h>
+#include <windows.h>
#else
-# include <dlfcn.h>
+#include <dlfcn.h>
#endif
#include "../renderer-shared.h"
-namespace gfx {
+namespace gfx
+{
using namespace Slang;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! VulkanModule !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -81,4 +82,4 @@ void VulkanModule::destroy()
m_module = nullptr;
}
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-module.h b/tools/gfx/vulkan/vk-module.h
index 062c953f6..4ee04dbc8 100644
--- a/tools/gfx/vulkan/vk-module.h
+++ b/tools/gfx/vulkan/vk-module.h
@@ -1,18 +1,17 @@
// vk-module.h
#pragma once
-#include "slang.h"
-
#include "slang-com-helper.h"
+#include "slang.h"
#if SLANG_WINDOWS_FAMILY
-# define VK_USE_PLATFORM_WIN32_KHR 1
+#define VK_USE_PLATFORM_WIN32_KHR 1
#elif SLANG_APPLE_FAMILY
-# define VK_USE_PLATFORM_METAL_EXT 1
+#define VK_USE_PLATFORM_METAL_EXT 1
#else
-# if SLANG_ENABLE_XLIB
-# define VK_USE_PLATFORM_XLIB_KHR 1
-# endif
+#if SLANG_ENABLE_XLIB
+#define VK_USE_PLATFORM_XLIB_KHR 1
+#endif
#endif
#define VK_NO_PROTOTYPES
@@ -21,36 +20,37 @@
// Undef xlib macros
#ifdef Always
-# undef Always
+#undef Always
#endif
#ifdef None
-# undef None
+#undef None
#endif
-namespace gfx {
+namespace gfx
+{
struct VulkanModule
{
- /// true if has been initialized
+ /// true if has been initialized
SLANG_FORCE_INLINE bool isInitialized() const { return m_module != nullptr; }
- /// Get a function by name
+ /// Get a function by name
PFN_vkVoidFunction getFunction(const char* name) const;
- /// true if using a software Vulkan implementation.
+ /// true if using a software Vulkan implementation.
bool isSoftware() const { return m_isSoftware; }
- /// Initialize
+ /// Initialize
Slang::Result init(bool useSoftwareImpl);
- /// Destroy
+ /// Destroy
void destroy();
- /// Dtor
+ /// Dtor
~VulkanModule() { destroy(); }
- protected:
- void* m_module = nullptr;
- bool m_isSoftware = false;
+protected:
+ void* m_module = nullptr;
+ bool m_isSoftware = false;
};
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-pipeline-dump-layer.cpp b/tools/gfx/vulkan/vk-pipeline-dump-layer.cpp
index 959eee15d..e17dea1f9 100644
--- a/tools/gfx/vulkan/vk-pipeline-dump-layer.cpp
+++ b/tools/gfx/vulkan/vk-pipeline-dump-layer.cpp
@@ -1,152 +1,182 @@
#include "vk-pipeline-dump-layer.h"
+
#include "core/slang-basic.h"
#include "core/slang-stream.h"
-namespace gfx {
- using namespace Slang;
-
- struct PipelineDumpContext
- {
- Dictionary<VkPipelineLayout, Index> pipelineLayouts;
- Dictionary<VkShaderModule, Index> shaderModules;
- Dictionary<VkDescriptorSetLayout, Index> descriptorSets;
- Dictionary<VkPipeline, Index> computePipelines;
-
- List<uint8_t> serializedBytes;
-
- VulkanApi api;
-
- template<typename T>
- void writeRaw(T v)
- {
- auto startIndex = serializedBytes.getCount();
- serializedBytes.growToCount(startIndex + sizeof(T));
- memcpy(serializedBytes.getBuffer() + startIndex, &v, sizeof(T));
- }
-
- template<typename T>
- void writeArray(uint32_t elementCount, const T* data)
- {
- writeRaw(elementCount);
-
- auto startIndex = serializedBytes.getCount();
- serializedBytes.growToCount(startIndex + sizeof(T) * elementCount);
- memcpy(serializedBytes.getBuffer() + startIndex, data, sizeof(T) * elementCount);
- }
-
- void writeStr(const char* str)
- {
- auto len = (uint32_t)strlen(str) + 1;
- writeRaw(len);
-
- auto startIndex = serializedBytes.getCount();
- serializedBytes.growToCount(startIndex + len);
- memcpy(serializedBytes.getBuffer() + startIndex, str, len - 1);
- serializedBytes[startIndex + len - 1] = 0;
- }
+namespace gfx
+{
+using namespace Slang;
- void writePipelineLayout(VkPipelineLayout layout, const VkPipelineLayoutCreateInfo* createInfo)
- {
- auto startIndex = serializedBytes.getCount();
- writeRaw(createInfo->sType);
- writeRaw(createInfo->flags);
- writeRaw(createInfo->setLayoutCount);
- for (uint32_t i = 0; i < createInfo->setLayoutCount; i++)
- writeRaw(descriptorSets.getValue(createInfo->pSetLayouts[i]));
- writeArray(createInfo->pushConstantRangeCount, createInfo->pPushConstantRanges);
- pipelineLayouts[layout] = startIndex;
- }
+struct PipelineDumpContext
+{
+ Dictionary<VkPipelineLayout, Index> pipelineLayouts;
+ Dictionary<VkShaderModule, Index> shaderModules;
+ Dictionary<VkDescriptorSetLayout, Index> descriptorSets;
+ Dictionary<VkPipeline, Index> computePipelines;
- void writeShaderModule(VkShaderModule module, const VkShaderModuleCreateInfo* createInfo)
- {
- auto startIndex = serializedBytes.getCount();
- writeRaw(createInfo->sType);
- writeRaw(createInfo->flags);
- writeArray((uint32_t)(createInfo->codeSize/sizeof(uint32_t)), createInfo->pCode);
- shaderModules[module] = startIndex;
- }
+ List<uint8_t> serializedBytes;
- void writeDescriptorSetLayout(VkDescriptorSetLayout layout, const VkDescriptorSetLayoutCreateInfo* createInfo)
- {
- auto startIndex = serializedBytes.getCount();
- writeRaw(createInfo->sType);
- writeRaw(createInfo->flags);
- writeArray(createInfo->bindingCount, createInfo->pBindings);
- descriptorSets[layout] = startIndex;
- }
+ VulkanApi api;
- void writePipeline(VkPipeline pipeline, const VkComputePipelineCreateInfo* createInfo)
- {
- auto startIndex = serializedBytes.getCount();
- writeRaw(createInfo->sType);
- writeRaw(createInfo->flags);
- writeRaw(createInfo->stage.sType);
- writeRaw(createInfo->stage.flags);
- writeRaw(createInfo->stage.stage);
- writeRaw(shaderModules.getValue(createInfo->stage.module));
- writeStr(createInfo->stage.pName);
- writeRaw(pipelineLayouts.getValue(createInfo->layout));
- computePipelines[pipeline] = startIndex;
- }
+ template<typename T>
+ void writeRaw(T v)
+ {
+ auto startIndex = serializedBytes.getCount();
+ serializedBytes.growToCount(startIndex + sizeof(T));
+ memcpy(serializedBytes.getBuffer() + startIndex, &v, sizeof(T));
+ }
- void writeToFile(UnownedStringSlice path)
- {
- RefPtr<FileStream> fs = new FileStream();
- fs->init(path, FileMode::Create);
- uint32_t pipelineCount = (uint32_t)computePipelines.getCount();
- fs->write(&pipelineCount, sizeof(uint32_t));
- for (auto& pair : computePipelines)
- {
- fs->write(KeyValueDetail::getValue(&pair), sizeof(Index));
- }
- Index blobSize = serializedBytes.getCount();
- fs->write(&blobSize, sizeof(blobSize));
- fs->write(serializedBytes.getBuffer(), serializedBytes.getCount());
- fs->close();
- }
- };
+ template<typename T>
+ void writeArray(uint32_t elementCount, const T* data)
+ {
+ writeRaw(elementCount);
- PipelineDumpContext dumpContext;
+ auto startIndex = serializedBytes.getCount();
+ serializedBytes.growToCount(startIndex + sizeof(T) * elementCount);
+ memcpy(serializedBytes.getBuffer() + startIndex, data, sizeof(T) * elementCount);
+ }
- VkResult SLANG_MCALL createPipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo* createInfo, const VkAllocationCallbacks* callbacks, VkPipelineLayout* outLayout)
+ void writeStr(const char* str)
{
- auto result = dumpContext.api.vkCreatePipelineLayout(device, createInfo, callbacks, outLayout);
- dumpContext.writePipelineLayout(*outLayout, createInfo);
- return result;
+ auto len = (uint32_t)strlen(str) + 1;
+ writeRaw(len);
+
+ auto startIndex = serializedBytes.getCount();
+ serializedBytes.growToCount(startIndex + len);
+ memcpy(serializedBytes.getBuffer() + startIndex, str, len - 1);
+ serializedBytes[startIndex + len - 1] = 0;
}
- VkResult SLANG_MCALL createComputePipelines(VkDevice device, VkPipelineCache cache, uint32_t createInfoCount, const VkComputePipelineCreateInfo* createInfos, const VkAllocationCallbacks* callbacks, VkPipeline* outPipelines)
+ void writePipelineLayout(VkPipelineLayout layout, const VkPipelineLayoutCreateInfo* createInfo)
{
- auto result = dumpContext.api.vkCreateComputePipelines(device, cache, createInfoCount, createInfos, callbacks, outPipelines);
- for (uint32_t i = 0; i < createInfoCount; i++)
- dumpContext.writePipeline(outPipelines[i], createInfos + i);
- return result;
+ auto startIndex = serializedBytes.getCount();
+ writeRaw(createInfo->sType);
+ writeRaw(createInfo->flags);
+ writeRaw(createInfo->setLayoutCount);
+ for (uint32_t i = 0; i < createInfo->setLayoutCount; i++)
+ writeRaw(descriptorSets.getValue(createInfo->pSetLayouts[i]));
+ writeArray(createInfo->pushConstantRangeCount, createInfo->pPushConstantRanges);
+ pipelineLayouts[layout] = startIndex;
}
- VkResult SLANG_MCALL createShaderModule(VkDevice device, const VkShaderModuleCreateInfo* createInfo, const VkAllocationCallbacks* callbacks, VkShaderModule* outShaderModule)
+ void writeShaderModule(VkShaderModule module, const VkShaderModuleCreateInfo* createInfo)
{
- auto result = dumpContext.api.vkCreateShaderModule(device, createInfo, callbacks, outShaderModule);
- dumpContext.writeShaderModule(*outShaderModule, createInfo);
- return result;
+ auto startIndex = serializedBytes.getCount();
+ writeRaw(createInfo->sType);
+ writeRaw(createInfo->flags);
+ writeArray((uint32_t)(createInfo->codeSize / sizeof(uint32_t)), createInfo->pCode);
+ shaderModules[module] = startIndex;
}
- VkResult SLANG_MCALL createDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo* createInfo, const VkAllocationCallbacks* callbacks, VkDescriptorSetLayout* outDescSetLayout)
+ void writeDescriptorSetLayout(
+ VkDescriptorSetLayout layout,
+ const VkDescriptorSetLayoutCreateInfo* createInfo)
{
- auto result = dumpContext.api.vkCreateDescriptorSetLayout(device, createInfo, callbacks, outDescSetLayout);
- dumpContext.writeDescriptorSetLayout(*outDescSetLayout, createInfo);
- return result;
+ auto startIndex = serializedBytes.getCount();
+ writeRaw(createInfo->sType);
+ writeRaw(createInfo->flags);
+ writeArray(createInfo->bindingCount, createInfo->pBindings);
+ descriptorSets[layout] = startIndex;
}
- void installPipelineDumpLayer(VulkanApi& api)
+ void writePipeline(VkPipeline pipeline, const VkComputePipelineCreateInfo* createInfo)
{
- dumpContext.api = api;
- api.vkCreatePipelineLayout = createPipelineLayout;
- api.vkCreateComputePipelines = createComputePipelines;
- api.vkCreateShaderModule = createShaderModule;
- api.vkCreateDescriptorSetLayout = createDescriptorSetLayout;
+ auto startIndex = serializedBytes.getCount();
+ writeRaw(createInfo->sType);
+ writeRaw(createInfo->flags);
+ writeRaw(createInfo->stage.sType);
+ writeRaw(createInfo->stage.flags);
+ writeRaw(createInfo->stage.stage);
+ writeRaw(shaderModules.getValue(createInfo->stage.module));
+ writeStr(createInfo->stage.pName);
+ writeRaw(pipelineLayouts.getValue(createInfo->layout));
+ computePipelines[pipeline] = startIndex;
}
- void writePipelineDump(UnownedStringSlice path)
+ void writeToFile(UnownedStringSlice path)
{
- dumpContext.writeToFile(path);
+ RefPtr<FileStream> fs = new FileStream();
+ fs->init(path, FileMode::Create);
+ uint32_t pipelineCount = (uint32_t)computePipelines.getCount();
+ fs->write(&pipelineCount, sizeof(uint32_t));
+ for (auto& pair : computePipelines)
+ {
+ fs->write(KeyValueDetail::getValue(&pair), sizeof(Index));
+ }
+ Index blobSize = serializedBytes.getCount();
+ fs->write(&blobSize, sizeof(blobSize));
+ fs->write(serializedBytes.getBuffer(), serializedBytes.getCount());
+ fs->close();
}
-} // renderer_test
+};
+
+PipelineDumpContext dumpContext;
+
+VkResult SLANG_MCALL createPipelineLayout(
+ VkDevice device,
+ const VkPipelineLayoutCreateInfo* createInfo,
+ const VkAllocationCallbacks* callbacks,
+ VkPipelineLayout* outLayout)
+{
+ auto result = dumpContext.api.vkCreatePipelineLayout(device, createInfo, callbacks, outLayout);
+ dumpContext.writePipelineLayout(*outLayout, createInfo);
+ return result;
+}
+
+VkResult SLANG_MCALL createComputePipelines(
+ VkDevice device,
+ VkPipelineCache cache,
+ uint32_t createInfoCount,
+ const VkComputePipelineCreateInfo* createInfos,
+ const VkAllocationCallbacks* callbacks,
+ VkPipeline* outPipelines)
+{
+ auto result = dumpContext.api.vkCreateComputePipelines(
+ device,
+ cache,
+ createInfoCount,
+ createInfos,
+ callbacks,
+ outPipelines);
+ for (uint32_t i = 0; i < createInfoCount; i++)
+ dumpContext.writePipeline(outPipelines[i], createInfos + i);
+ return result;
+}
+
+VkResult SLANG_MCALL createShaderModule(
+ VkDevice device,
+ const VkShaderModuleCreateInfo* createInfo,
+ const VkAllocationCallbacks* callbacks,
+ VkShaderModule* outShaderModule)
+{
+ auto result =
+ dumpContext.api.vkCreateShaderModule(device, createInfo, callbacks, outShaderModule);
+ dumpContext.writeShaderModule(*outShaderModule, createInfo);
+ return result;
+}
+
+VkResult SLANG_MCALL createDescriptorSetLayout(
+ VkDevice device,
+ const VkDescriptorSetLayoutCreateInfo* createInfo,
+ const VkAllocationCallbacks* callbacks,
+ VkDescriptorSetLayout* outDescSetLayout)
+{
+ auto result = dumpContext.api
+ .vkCreateDescriptorSetLayout(device, createInfo, callbacks, outDescSetLayout);
+ dumpContext.writeDescriptorSetLayout(*outDescSetLayout, createInfo);
+ return result;
+}
+
+void installPipelineDumpLayer(VulkanApi& api)
+{
+ dumpContext.api = api;
+ api.vkCreatePipelineLayout = createPipelineLayout;
+ api.vkCreateComputePipelines = createComputePipelines;
+ api.vkCreateShaderModule = createShaderModule;
+ api.vkCreateDescriptorSetLayout = createDescriptorSetLayout;
+}
+
+void writePipelineDump(UnownedStringSlice path)
+{
+ dumpContext.writeToFile(path);
+}
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-pipeline-dump-layer.h b/tools/gfx/vulkan/vk-pipeline-dump-layer.h
index c514f7f3e..75f4b32cc 100644
--- a/tools/gfx/vulkan/vk-pipeline-dump-layer.h
+++ b/tools/gfx/vulkan/vk-pipeline-dump-layer.h
@@ -1,11 +1,11 @@
// vk-api.cpp
-#include "vk-api.h"
-
#include "core/slang-string.h"
+#include "vk-api.h"
-namespace gfx {
+namespace gfx
+{
void installPipelineDumpLayer(VulkanApi& api);
void writePipelineDump(Slang::UnownedStringSlice path);
-} // renderer_test
+} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-pipeline-state.cpp b/tools/gfx/vulkan/vk-pipeline-state.cpp
index 2e7bb1c0a..8fd0c5680 100644
--- a/tools/gfx/vulkan/vk-pipeline-state.cpp
+++ b/tools/gfx/vulkan/vk-pipeline-state.cpp
@@ -2,12 +2,11 @@
#include "vk-pipeline-state.h"
#include "vk-device.h"
-#include "vk-shader-program.h"
+#include "vk-helper-functions.h"
#include "vk-shader-object-layout.h"
+#include "vk-shader-program.h"
#include "vk-vertex-layout.h"
-#include "vk-helper-functions.h"
-
namespace gfx
{
@@ -35,9 +34,15 @@ PipelineStateImpl::~PipelineStateImpl()
}
}
-void PipelineStateImpl::establishStrongDeviceReference() { m_device.establishStrongReference(); }
+void PipelineStateImpl::establishStrongDeviceReference()
+{
+ m_device.establishStrongReference();
+}
-void PipelineStateImpl::comFree() { m_device.breakStrongReference(); }
+void PipelineStateImpl::comFree()
+{
+ m_device.breakStrongReference();
+}
void PipelineStateImpl::init(const GraphicsPipelineStateDesc& inDesc)
{
@@ -159,8 +164,8 @@ Result PipelineStateImpl::createVKGraphicsPipelineState()
multisampling.alphaToCoverageEnable = blendDesc.alphaToCoverageEnable;
multisampling.alphaToOneEnable = VK_FALSE;
- auto targetCount =
- GfxCount(Math::Min(framebufferLayoutImpl->m_renderTargetCount, (uint32_t)blendDesc.targetCount));
+ auto targetCount = GfxCount(
+ Math::Min(framebufferLayoutImpl->m_renderTargetCount, (uint32_t)blendDesc.targetCount));
List<VkPipelineColorBlendAttachmentState> colorBlendTargets;
// Regardless of whether blending is enabled, Vulkan always applies the color write mask
@@ -222,7 +227,8 @@ Result PipelineStateImpl::createVKGraphicsPipelineState()
dynamicStates.add(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
// It's not valid to specify VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT when
// the pipeline contains a mesh shader.
- if (!m_program->isMeshShaderProgram() && m_device->m_api.m_extendedFeatures.extendedDynamicStateFeatures.extendedDynamicState)
+ if (!m_program->isMeshShaderProgram() &&
+ m_device->m_api.m_extendedFeatures.extendedDynamicStateFeatures.extendedDynamicState)
{
dynamicStates.add(VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT);
@@ -275,17 +281,21 @@ Result PipelineStateImpl::createVKGraphicsPipelineState()
if (m_device->m_pipelineCreationAPIDispatcher)
{
- SLANG_RETURN_ON_FAIL(
- m_device->m_pipelineCreationAPIDispatcher->createGraphicsPipelineState(
- m_device,
- programImpl->linkedProgram.get(),
- &pipelineInfo,
- (void**)&m_pipeline));
+ SLANG_RETURN_ON_FAIL(m_device->m_pipelineCreationAPIDispatcher->createGraphicsPipelineState(
+ m_device,
+ programImpl->linkedProgram.get(),
+ &pipelineInfo,
+ (void**)&m_pipeline));
}
else
{
SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkCreateGraphicsPipelines(
- m_device->m_device, pipelineCache, 1, &pipelineInfo, nullptr, &m_pipeline));
+ m_device->m_device,
+ pipelineCache,
+ 1,
+ &pipelineInfo,
+ nullptr,
+ &m_pipeline));
}
return SLANG_OK;
@@ -300,24 +310,28 @@ Result PipelineStateImpl::createVKComputePipelineState()
}
VkComputePipelineCreateInfo computePipelineInfo = {
- VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO};
+ VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO};
computePipelineInfo.stage = programImpl->m_stageCreateInfos[0];
computePipelineInfo.layout = programImpl->m_rootObjectLayout->m_pipelineLayout;
if (m_device->m_pipelineCreationAPIDispatcher)
{
- SLANG_RETURN_ON_FAIL(
- m_device->m_pipelineCreationAPIDispatcher->createComputePipelineState(
- m_device,
- programImpl->linkedProgram.get(),
- &computePipelineInfo,
- (void**)&m_pipeline));
+ SLANG_RETURN_ON_FAIL(m_device->m_pipelineCreationAPIDispatcher->createComputePipelineState(
+ m_device,
+ programImpl->linkedProgram.get(),
+ &computePipelineInfo,
+ (void**)&m_pipeline));
}
else
{
VkPipelineCache pipelineCache = VK_NULL_HANDLE;
SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkCreateComputePipelines(
- m_device->m_device, pipelineCache, 1, &computePipelineInfo, nullptr, &m_pipeline));
+ m_device->m_device,
+ pipelineCache,
+ 1,
+ &computePipelineInfo,
+ nullptr,
+ &m_pipeline));
}
return SLANG_OK;
}
@@ -329,13 +343,9 @@ Result PipelineStateImpl::ensureAPIPipelineStateCreated()
switch (desc.type)
{
- case PipelineType::Compute:
- return createVKComputePipelineState();
- case PipelineType::Graphics:
- return createVKGraphicsPipelineState();
- default:
- SLANG_UNREACHABLE("Unknown pipeline type.");
- return SLANG_FAIL;
+ case PipelineType::Compute: return createVKComputePipelineState();
+ case PipelineType::Graphics: return createVKGraphicsPipelineState();
+ default: SLANG_UNREACHABLE("Unknown pipeline type."); return SLANG_FAIL;
}
}
SLANG_NO_THROW Result SLANG_MCALL PipelineStateImpl::getNativeHandle(InteropHandle* outHandle)
@@ -349,9 +359,11 @@ SLANG_NO_THROW Result SLANG_MCALL PipelineStateImpl::getNativeHandle(InteropHand
RayTracingPipelineStateImpl::RayTracingPipelineStateImpl(DeviceImpl* device)
: PipelineStateImpl(device)
-{}
+{
+}
uint32_t RayTracingPipelineStateImpl::findEntryPointIndexByName(
- const Dictionary<String, Index>& entryPointNameToIndex, const char* name)
+ const Dictionary<String, Index>& entryPointNameToIndex,
+ const char* name)
{
if (!name)
return VK_SHADER_UNUSED_KHR;
@@ -451,7 +463,8 @@ Result RayTracingPipelineStateImpl::createVKRayTracingPipelineState()
if (m_device->m_pipelineCreationAPIDispatcher)
{
m_device->m_pipelineCreationAPIDispatcher->beforeCreateRayTracingState(
- m_device, programImpl->linkedProgram.get());
+ m_device,
+ programImpl->linkedProgram.get());
}
VkPipelineCache pipelineCache = VK_NULL_HANDLE;
@@ -468,7 +481,8 @@ Result RayTracingPipelineStateImpl::createVKRayTracingPipelineState()
if (m_device->m_pipelineCreationAPIDispatcher)
{
m_device->m_pipelineCreationAPIDispatcher->afterCreateRayTracingState(
- m_device, programImpl->linkedProgram.get());
+ m_device,
+ programImpl->linkedProgram.get());
}
return SLANG_OK;
}
@@ -479,11 +493,8 @@ Result RayTracingPipelineStateImpl::ensureAPIPipelineStateCreated()
switch (desc.type)
{
- case PipelineType::RayTracing:
- return createVKRayTracingPipelineState();
- default:
- SLANG_UNREACHABLE("Unknown pipeline type.");
- return SLANG_FAIL;
+ case PipelineType::RayTracing: return createVKRayTracingPipelineState();
+ default: SLANG_UNREACHABLE("Unknown pipeline type."); return SLANG_FAIL;
}
}
Result RayTracingPipelineStateImpl::getNativeHandle(InteropHandle* outHandle)
diff --git a/tools/gfx/vulkan/vk-pipeline-state.h b/tools/gfx/vulkan/vk-pipeline-state.h
index 3e84ca158..4bf585d7e 100644
--- a/tools/gfx/vulkan/vk-pipeline-state.h
+++ b/tools/gfx/vulkan/vk-pipeline-state.h
@@ -50,7 +50,8 @@ public:
RayTracingPipelineStateImpl(DeviceImpl* device);
uint32_t findEntryPointIndexByName(
- const Dictionary<String, Index>& entryPointNameToIndex, const char* name);
+ const Dictionary<String, Index>& entryPointNameToIndex,
+ const char* name);
Result createVKRayTracingPipelineState();
diff --git a/tools/gfx/vulkan/vk-query.cpp b/tools/gfx/vulkan/vk-query.cpp
index ccdb84647..694896966 100644
--- a/tools/gfx/vulkan/vk-query.cpp
+++ b/tools/gfx/vulkan/vk-query.cpp
@@ -19,9 +19,7 @@ Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
createInfo.queryCount = (uint32_t)desc.count;
switch (desc.type)
{
- case QueryType::Timestamp:
- createInfo.queryType = VK_QUERY_TYPE_TIMESTAMP;
- break;
+ case QueryType::Timestamp: createInfo.queryType = VK_QUERY_TYPE_TIMESTAMP; break;
case QueryType::AccelerationStructureCompactedSize:
createInfo.queryType = VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR;
break;
@@ -31,8 +29,7 @@ Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
case QueryType::AccelerationStructureCurrentSize:
// Vulkan does not support CurrentSize query, will not create actual pools here.
return SLANG_OK;
- default:
- return SLANG_E_INVALID_ARG;
+ default: return SLANG_E_INVALID_ARG;
}
SLANG_VK_RETURN_ON_FAIL(
m_device->m_api.vkCreateQueryPool(m_device->m_api.m_device, &createInfo, nullptr, &m_pool));
@@ -67,12 +64,18 @@ Result QueryPoolImpl::getResult(GfxIndex index, GfxCount count, uint64_t* data)
}
void _writeTimestamp(
- VulkanApi* api, VkCommandBuffer vkCmdBuffer, IQueryPool* queryPool, SlangInt index)
+ VulkanApi* api,
+ VkCommandBuffer vkCmdBuffer,
+ IQueryPool* queryPool,
+ SlangInt index)
{
auto queryPoolImpl = static_cast<QueryPoolImpl*>(queryPool);
api->vkCmdResetQueryPool(vkCmdBuffer, queryPoolImpl->m_pool, (uint32_t)index, 1);
api->vkCmdWriteTimestamp(
- vkCmdBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, queryPoolImpl->m_pool, (uint32_t)index);
+ vkCmdBuffer,
+ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
+ queryPoolImpl->m_pool,
+ (uint32_t)index);
}
} // namespace vk
diff --git a/tools/gfx/vulkan/vk-query.h b/tools/gfx/vulkan/vk-query.h
index b9cda2557..2ff20d5ab 100644
--- a/tools/gfx/vulkan/vk-query.h
+++ b/tools/gfx/vulkan/vk-query.h
@@ -20,7 +20,7 @@ public:
public:
virtual SLANG_NO_THROW Result SLANG_MCALL
- getResult(GfxIndex index, GfxCount count, uint64_t* data) override;
+ getResult(GfxIndex index, GfxCount count, uint64_t* data) override;
public:
VkQueryPool m_pool;
@@ -28,7 +28,10 @@ public:
};
void _writeTimestamp(
- VulkanApi* api, VkCommandBuffer vkCmdBuffer, IQueryPool* queryPool, SlangInt index);
+ VulkanApi* api,
+ VkCommandBuffer vkCmdBuffer,
+ IQueryPool* queryPool,
+ SlangInt index);
} // namespace vk
} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-render-pass.cpp b/tools/gfx/vulkan/vk-render-pass.cpp
index 25a39c58a..10453fadb 100644
--- a/tools/gfx/vulkan/vk-render-pass.cpp
+++ b/tools/gfx/vulkan/vk-render-pass.cpp
@@ -67,9 +67,8 @@ Result RenderPassLayoutImpl::init(DeviceImpl* renderer, const IRenderPassLayout:
subpassDesc.colorAttachmentCount = desc.renderTargetCount;
subpassDesc.pColorAttachments = framebufferLayout->m_colorReferences.getBuffer();
subpassDesc.pResolveAttachments = nullptr;
- subpassDesc.pDepthStencilAttachment = framebufferLayout->m_hasDepthStencilTarget
- ? &framebufferLayout->m_depthReference
- : nullptr;
+ subpassDesc.pDepthStencilAttachment =
+ framebufferLayout->m_hasDepthStencilTarget ? &framebufferLayout->m_depthReference : nullptr;
subpassDesc.preserveAttachmentCount = 0u;
subpassDesc.pPreserveAttachments = nullptr;
@@ -80,7 +79,10 @@ Result RenderPassLayoutImpl::init(DeviceImpl* renderer, const IRenderPassLayout:
renderPassCreateInfo.subpassCount = 1;
renderPassCreateInfo.pSubpasses = &subpassDesc;
SLANG_VK_RETURN_ON_FAIL(m_renderer->m_api.vkCreateRenderPass(
- m_renderer->m_api.m_device, &renderPassCreateInfo, nullptr, &m_renderPass));
+ m_renderer->m_api.m_device,
+ &renderPassCreateInfo,
+ nullptr,
+ &m_renderPass));
return SLANG_OK;
}
diff --git a/tools/gfx/vulkan/vk-render-pass.h b/tools/gfx/vulkan/vk-render-pass.h
index 7cc1a581f..9fa3808c3 100644
--- a/tools/gfx/vulkan/vk-render-pass.h
+++ b/tools/gfx/vulkan/vk-render-pass.h
@@ -12,9 +12,7 @@ using namespace Slang;
namespace vk
{
-class RenderPassLayoutImpl
- : public IRenderPassLayout
- , public ComObject
+class RenderPassLayoutImpl : public IRenderPassLayout, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
diff --git a/tools/gfx/vulkan/vk-resource-views.cpp b/tools/gfx/vulkan/vk-resource-views.cpp
index 10d96ed54..b6b97b9f5 100644
--- a/tools/gfx/vulkan/vk-resource-views.cpp
+++ b/tools/gfx/vulkan/vk-resource-views.cpp
@@ -23,7 +23,8 @@ Result TextureResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
TexelBufferResourceViewImpl::TexelBufferResourceViewImpl(DeviceImpl* device)
: ResourceViewImpl(ViewType::TexelBuffer, device)
-{}
+{
+}
TexelBufferResourceViewImpl::~TexelBufferResourceViewImpl()
{
@@ -39,7 +40,8 @@ Result TexelBufferResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
PlainBufferResourceViewImpl::PlainBufferResourceViewImpl(DeviceImpl* device)
: ResourceViewImpl(ViewType::PlainBuffer, device)
-{}
+{
+}
Result PlainBufferResourceViewImpl::getNativeHandle(InteropHandle* outHandle)
{
@@ -63,7 +65,9 @@ AccelerationStructureImpl::~AccelerationStructureImpl()
if (m_device)
{
m_device->m_api.vkDestroyAccelerationStructureKHR(
- m_device->m_api.m_device, m_vkHandle, nullptr);
+ m_device->m_api.m_device,
+ m_vkHandle,
+ nullptr);
}
}
diff --git a/tools/gfx/vulkan/vk-resource-views.h b/tools/gfx/vulkan/vk-resource-views.h
index bba99f704..e8b4fbb0a 100644
--- a/tools/gfx/vulkan/vk-resource-views.h
+++ b/tools/gfx/vulkan/vk-resource-views.h
@@ -26,9 +26,9 @@ public:
public:
ResourceViewImpl(ViewType viewType, DeviceImpl* device)
- : m_type(viewType)
- , m_device(device)
- {}
+ : m_type(viewType), m_device(device)
+ {
+ }
ViewType m_type;
RefPtr<DeviceImpl> m_device;
};
@@ -38,7 +38,8 @@ class TextureResourceViewImpl : public ResourceViewImpl
public:
TextureResourceViewImpl(DeviceImpl* device)
: ResourceViewImpl(ViewType::Texture, device)
- {}
+ {
+ }
~TextureResourceViewImpl();
RefPtr<TextureResourceImpl> m_texture;
VkImageView m_view;
diff --git a/tools/gfx/vulkan/vk-sampler.cpp b/tools/gfx/vulkan/vk-sampler.cpp
index e07cff753..ee9357609 100644
--- a/tools/gfx/vulkan/vk-sampler.cpp
+++ b/tools/gfx/vulkan/vk-sampler.cpp
@@ -11,7 +11,8 @@ namespace vk
SamplerStateImpl::SamplerStateImpl(DeviceImpl* device)
: m_device(device)
-{}
+{
+}
SamplerStateImpl::~SamplerStateImpl()
{
diff --git a/tools/gfx/vulkan/vk-shader-object-layout.cpp b/tools/gfx/vulkan/vk-shader-object-layout.cpp
index d84627e86..6129246cb 100644
--- a/tools/gfx/vulkan/vk-shader-object-layout.cpp
+++ b/tools/gfx/vulkan/vk-shader-object-layout.cpp
@@ -31,33 +31,22 @@ VkDescriptorType ShaderObjectLayoutImpl::Builder::_mapDescriptorType(
switch (slangBindingType)
{
case slang::BindingType::PushConstant:
- default:
- SLANG_ASSERT("unsupported binding type");
- return VK_DESCRIPTOR_TYPE_MAX_ENUM;
+ default: SLANG_ASSERT("unsupported binding type"); return VK_DESCRIPTOR_TYPE_MAX_ENUM;
- case slang::BindingType::Sampler:
- return VK_DESCRIPTOR_TYPE_SAMPLER;
+ case slang::BindingType::Sampler: return VK_DESCRIPTOR_TYPE_SAMPLER;
case slang::BindingType::CombinedTextureSampler:
return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
- case slang::BindingType::Texture:
- return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
- case slang::BindingType::MutableTexture:
- return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
- case slang::BindingType::TypedBuffer:
- return VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
- case slang::BindingType::MutableTypedBuffer:
- return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
+ case slang::BindingType::Texture: return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
+ case slang::BindingType::MutableTexture: return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
+ case slang::BindingType::TypedBuffer: return VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
+ case slang::BindingType::MutableTypedBuffer: return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
case slang::BindingType::RawBuffer:
- case slang::BindingType::MutableRawBuffer:
- return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
- case slang::BindingType::InputRenderTarget:
- return VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
- case slang::BindingType::InlineUniformData:
- return VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT;
+ case slang::BindingType::MutableRawBuffer: return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
+ case slang::BindingType::InputRenderTarget: return VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
+ case slang::BindingType::InlineUniformData: return VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT;
case slang::BindingType::RayTracingAccelerationStructure:
return VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
- case slang::BindingType::ConstantBuffer:
- return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+ case slang::BindingType::ConstantBuffer: return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
}
}
@@ -65,7 +54,8 @@ VkDescriptorType ShaderObjectLayoutImpl::Builder::_mapDescriptorType(
/// sub-object described by `typeLayout`, at the given `offset`.
void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue(
- slang::TypeLayoutReflection* typeLayout, BindingOffset const& offset)
+ slang::TypeLayoutReflection* typeLayout,
+ BindingOffset const& offset)
{
// First we will scan through all the descriptor sets that the Slang reflection
// information believes go into making up the given type.
@@ -94,8 +84,7 @@ void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue(
auto bindingRangeType = typeLayout->getBindingRangeType(bindingRangeIndex);
switch (bindingRangeType)
{
- default:
- break;
+ default: break;
// We will skip over ranges that represent sub-objects for now, and handle
// them in a separate pass.
@@ -103,8 +92,7 @@ void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue(
case slang::BindingType::ParameterBlock:
case slang::BindingType::ConstantBuffer:
case slang::BindingType::ExistentialValue:
- case slang::BindingType::PushConstant:
- continue;
+ case slang::BindingType::PushConstant: continue;
}
// Given a binding range we are interested in, we will then enumerate
@@ -126,7 +114,8 @@ void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue(
{
Index descriptorRangeIndex = firstDescriptorRangeIndex + j;
auto slangDescriptorType = typeLayout->getDescriptorSetDescriptorRangeType(
- slangDescriptorSetIndex, descriptorRangeIndex);
+ slangDescriptorSetIndex,
+ descriptorRangeIndex);
// Certain kinds of descriptor ranges reflected by Slang do not
// manifest as descriptors at the Vulkan level, so we will skip those.
@@ -135,20 +124,20 @@ void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue(
{
case slang::BindingType::ExistentialValue:
case slang::BindingType::InlineUniformData:
- case slang::BindingType::PushConstant:
- continue;
- default:
- break;
+ case slang::BindingType::PushConstant: continue;
+ default: break;
}
auto vkDescriptorType = _mapDescriptorType(slangDescriptorType);
VkDescriptorSetLayoutBinding vkBindingRangeDesc = {};
vkBindingRangeDesc.binding =
offset.binding + (uint32_t)typeLayout->getDescriptorSetDescriptorRangeIndexOffset(
- slangDescriptorSetIndex, descriptorRangeIndex);
+ slangDescriptorSetIndex,
+ descriptorRangeIndex);
vkBindingRangeDesc.descriptorCount =
(uint32_t)typeLayout->getDescriptorSetDescriptorRangeDescriptorCount(
- slangDescriptorSetIndex, descriptorRangeIndex);
+ slangDescriptorSetIndex,
+ descriptorRangeIndex);
vkBindingRangeDesc.descriptorType = vkDescriptorType;
vkBindingRangeDesc.stageFlags = VK_SHADER_STAGE_ALL;
@@ -181,8 +170,7 @@ void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue(
// decriptor sets of a parent object.
//
case slang::BindingType::ParameterBlock:
- default:
- break;
+ default: break;
case slang::BindingType::ExistentialValue:
// An interest/existential-typed sub-object range will only contribute
@@ -221,7 +209,9 @@ void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue(
elementOffset += BindingOffset(elementVarLayout);
_addDescriptorRangesAsConstantBuffer(
- elementTypeLayout, containerOffset, elementOffset);
+ elementTypeLayout,
+ containerOffset,
+ elementOffset);
}
break;
@@ -252,7 +242,9 @@ void ShaderObjectLayoutImpl::Builder::_addDescriptorRangesAsValue(
elementOffset += BindingOffset(elementVarLayout);
_addDescriptorRangesAsPushConstantBuffer(
- elementTypeLayout, containerOffset, elementOffset);
+ elementTypeLayout,
+ containerOffset,
+ elementOffset);
}
break;
}
@@ -416,7 +408,8 @@ void ShaderObjectLayoutImpl::Builder::addBindingRanges(slang::TypeLayoutReflecti
auto set = typeLayout->getDescriptorSetSpaceOffset(descriptorSetIndex);
auto bindingOffset = typeLayout->getDescriptorSetDescriptorRangeIndexOffset(
- descriptorSetIndex, descriptorRangeIndex);
+ descriptorSetIndex,
+ descriptorRangeIndex);
bindingRangeInfo.setOffset = uint32_t(set);
bindingRangeInfo.bindingOffset = uint32_t(bindingOffset);
@@ -449,7 +442,10 @@ void ShaderObjectLayoutImpl::Builder::addBindingRanges(slang::TypeLayoutReflecti
auto varLayout = slangLeafTypeLayout->getElementVarLayout();
auto subTypeLayout = varLayout->getTypeLayout();
ShaderObjectLayoutImpl::createForElementType(
- m_renderer, m_session, subTypeLayout, subObjectLayout.writeRef());
+ m_renderer,
+ m_session,
+ subTypeLayout,
+ subObjectLayout.writeRef());
}
break;
@@ -457,7 +453,10 @@ void ShaderObjectLayoutImpl::Builder::addBindingRanges(slang::TypeLayoutReflecti
if (auto pendingTypeLayout = slangLeafTypeLayout->getPendingDataTypeLayout())
{
ShaderObjectLayoutImpl::createForElementType(
- m_renderer, m_session, pendingTypeLayout, subObjectLayout.writeRef());
+ m_renderer,
+ m_session,
+ pendingTypeLayout,
+ subObjectLayout.writeRef());
}
break;
}
@@ -509,8 +508,7 @@ void ShaderObjectLayoutImpl::Builder::addBindingRanges(slang::TypeLayoutReflecti
}
break;
- default:
- break;
+ default: break;
}
m_subObjectRanges.add(subObjectRange);
@@ -602,7 +600,9 @@ Result ShaderObjectLayoutImpl::createForElementType(
// since that is how things will be laid out inside the parameter block.
//
builder._addDescriptorRangesAsConstantBuffer(
- builder.m_elementTypeLayout, containerOffset, elementOffset);
+ builder.m_elementTypeLayout,
+ containerOffset,
+ elementOffset);
return builder.build(outLayout);
}
@@ -611,7 +611,9 @@ ShaderObjectLayoutImpl::~ShaderObjectLayoutImpl()
for (auto& descSetInfo : m_descriptorSetInfos)
{
getDevice()->m_api.vkDestroyDescriptorSetLayout(
- getDevice()->m_api.m_device, descSetInfo.descriptorSetLayout, nullptr);
+ getDevice()->m_api.m_device,
+ descSetInfo.descriptorSetLayout,
+ nullptr);
}
}
@@ -645,7 +647,10 @@ Result ShaderObjectLayoutImpl::_init(Builder const* builder)
createInfo.bindingCount = (uint32_t)descriptorSetInfo.vkBindings.getCount();
VkDescriptorSetLayout vkDescSetLayout;
SLANG_RETURN_ON_FAIL(renderer->m_api.vkCreateDescriptorSetLayout(
- renderer->m_api.m_device, &createInfo, nullptr, &vkDescSetLayout));
+ renderer->m_api.m_device,
+ &createInfo,
+ nullptr,
+ &vkDescSetLayout));
descriptorSetInfo.descriptorSetLayout = vkDescSetLayout;
}
return SLANG_OK;
@@ -693,7 +698,9 @@ RootShaderObjectLayout::~RootShaderObjectLayout()
if (m_pipelineLayout)
{
m_renderer->m_api.vkDestroyPipelineLayout(
- m_renderer->m_api.m_device, m_pipelineLayout, nullptr);
+ m_renderer->m_api.m_device,
+ m_pipelineLayout,
+ nullptr);
}
}
@@ -790,7 +797,10 @@ Result RootShaderObjectLayout::_init(Builder const* builder)
pipelineLayoutCreateInfo.pPushConstantRanges = m_allPushConstantRanges.getBuffer();
}
SLANG_RETURN_ON_FAIL(m_renderer->m_api.vkCreatePipelineLayout(
- m_renderer->m_api.m_device, &pipelineLayoutCreateInfo, nullptr, &m_pipelineLayout));
+ m_renderer->m_api.m_device,
+ &pipelineLayoutCreateInfo,
+ nullptr,
+ &m_pipelineLayout));
return SLANG_OK;
}
diff --git a/tools/gfx/vulkan/vk-shader-object-layout.h b/tools/gfx/vulkan/vk-shader-object-layout.h
index 3f60e6b89..bc95097f8 100644
--- a/tools/gfx/vulkan/vk-shader-object-layout.h
+++ b/tools/gfx/vulkan/vk-shader-object-layout.h
@@ -136,7 +136,8 @@ public:
public:
Builder(DeviceImpl* renderer, slang::ISession* session)
: m_renderer(renderer), m_session(session)
- {}
+ {
+ }
DeviceImpl* m_renderer;
slang::ISession* m_session;
@@ -180,7 +181,8 @@ public:
/// Add any descriptor ranges implied by this object containing a leaf
/// sub-object described by `typeLayout`, at the given `offset`.
void _addDescriptorRangesAsValue(
- slang::TypeLayoutReflection* typeLayout, BindingOffset const& offset);
+ slang::TypeLayoutReflection* typeLayout,
+ BindingOffset const& offset);
/// Add the descriptor ranges implied by a `ConstantBuffer<X>` where `X` is
/// described by `elementTypeLayout`.
@@ -325,7 +327,8 @@ public:
{
Builder(DeviceImpl* device, slang::ISession* session)
: Super::Builder(device, session)
- {}
+ {
+ }
Result build(EntryPointLayout** outLayout);
@@ -372,7 +375,8 @@ public:
: Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
- {}
+ {
+ }
Result build(RootShaderObjectLayout** outLayout);
diff --git a/tools/gfx/vulkan/vk-shader-object.cpp b/tools/gfx/vulkan/vk-shader-object.cpp
index 37edd8efa..862f6137a 100644
--- a/tools/gfx/vulkan/vk-shader-object.cpp
+++ b/tools/gfx/vulkan/vk-shader-object.cpp
@@ -14,7 +14,9 @@ namespace vk
{
Result ShaderObjectImpl::create(
- IDevice* device, ShaderObjectLayoutImpl* layout, ShaderObjectImpl** outShaderObject)
+ IDevice* device,
+ ShaderObjectLayoutImpl* layout,
+ ShaderObjectImpl** outShaderObject)
{
auto object = RefPtr<ShaderObjectImpl>(new ShaderObjectImpl());
SLANG_RETURN_ON_FAIL(object->init(device, layout));
@@ -23,9 +25,15 @@ Result ShaderObjectImpl::create(
return SLANG_OK;
}
-RendererBase* ShaderObjectImpl::getDevice() { return m_layout->getDevice(); }
+RendererBase* ShaderObjectImpl::getDevice()
+{
+ return m_layout->getDevice();
+}
-GfxCount ShaderObjectImpl::getEntryPointCount() { return 0; }
+GfxCount ShaderObjectImpl::getEntryPointCount()
+{
+ return 0;
+}
Result ShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
{
@@ -33,9 +41,15 @@ Result ShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryP
return SLANG_OK;
}
-const void* ShaderObjectImpl::getRawData() { return m_data.getBuffer(); }
+const void* ShaderObjectImpl::getRawData()
+{
+ return m_data.getBuffer();
+}
-Size ShaderObjectImpl::getSize() { return (Size)m_data.getCount(); }
+Size ShaderObjectImpl::getSize()
+{
+ return (Size)m_data.getCount();
+}
// TODO: Change size_t and Index to Size?
Result ShaderObjectImpl::setData(ShaderOffset const& inOffset, void const* data, size_t inSize)
@@ -110,7 +124,9 @@ Result ShaderObjectImpl::setSampler(ShaderOffset const& offset, ISamplerState* s
}
Result ShaderObjectImpl::setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler)
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler)
{
if (offset.bindingRangeIndex < 0)
return SLANG_E_INVALID_ARG;
@@ -307,7 +323,8 @@ Result ShaderObjectImpl::_writeOrdinaryData(
}
void ShaderObjectImpl::writeDescriptor(
- RootBindingContext& context, VkWriteDescriptorSet const& write)
+ RootBindingContext& context,
+ VkWriteDescriptorSet const& write)
{
auto device = context.device;
device->m_api.vkUpdateDescriptorSets(device->m_device, 1, &write, 0, nullptr);
@@ -350,7 +367,12 @@ void ShaderObjectImpl::writeBufferDescriptor(
BufferResourceImpl* buffer)
{
writeBufferDescriptor(
- context, offset, descriptorType, buffer, 0, buffer->getDesc()->sizeInBytes);
+ context,
+ offset,
+ descriptorType,
+ buffer,
+ 0,
+ buffer->getDesc()->sizeInBytes);
}
void ShaderObjectImpl::writePlainBufferDescriptor(
@@ -586,7 +608,8 @@ bool ShaderObjectImpl::shouldAllocateConstantBuffer(TransientResourceHeapImpl* t
}
Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(
- PipelineCommandEncoder* encoder, ShaderObjectLayoutImpl* specializedLayout)
+ PipelineCommandEncoder* encoder,
+ ShaderObjectLayoutImpl* specializedLayout)
{
// If data has been changed since last allocation/filling of constant buffer,
// we will need to allocate a new one.
@@ -609,7 +632,9 @@ Result ShaderObjectImpl::_ensureOrdinaryDataBufferCreatedIfNeeded(
// it from the transient resource heap.
//
SLANG_RETURN_ON_FAIL(encoder->m_commandBuffer->m_transientHeap->allocateConstantBuffer(
- m_constantBufferSize, m_constantBuffer, m_constantBufferOffset));
+ m_constantBufferSize,
+ m_constantBuffer,
+ m_constantBufferOffset));
// Once the buffer is allocated, we can use `_writeOrdinaryData` to fill it in.
//
@@ -647,8 +672,7 @@ Result ShaderObjectImpl::bindAsValue(
{
case slang::BindingType::ConstantBuffer:
case slang::BindingType::ParameterBlock:
- case slang::BindingType::ExistentialValue:
- break;
+ case slang::BindingType::ExistentialValue: break;
case slang::BindingType::Texture:
rangeOffset.bindingSet += bindingRangeInfo.setOffset;
@@ -727,8 +751,7 @@ Result ShaderObjectImpl::bindAsValue(
m_resourceViews.getArrayView(baseIndex, count));
break;
case slang::BindingType::VaryingInput:
- case slang::BindingType::VaryingOutput:
- break;
+ case slang::BindingType::VaryingOutput: break;
default:
SLANG_ASSERT(!"unsupported binding type");
@@ -824,8 +847,8 @@ Result ShaderObjectImpl::bindAsValue(
// already.
//
ShaderObjectImpl* subObject = m_objects[subObjectIndex + i];
- subObject->bindAsValue(
- encoder, context, BindingOffset(objOffset), subObjectLayout);
+ subObject
+ ->bindAsValue(encoder, context, BindingOffset(objOffset), subObjectLayout);
objOffset += objStride;
}
}
@@ -987,7 +1010,9 @@ Result ShaderObjectImpl::_createSpecializedLayout(ShaderObjectLayoutImpl** outLa
}
Result EntryPointShaderObject::create(
- IDevice* device, EntryPointLayout* layout, EntryPointShaderObject** outShaderObject)
+ IDevice* device,
+ EntryPointLayout* layout,
+ EntryPointShaderObject** outShaderObject)
{
RefPtr<EntryPointShaderObject> object = new EntryPointShaderObject();
SLANG_RETURN_ON_FAIL(object->init(device, layout));
@@ -1080,7 +1105,10 @@ List<RefPtr<EntryPointShaderObject>> const& RootShaderObjectImpl::getEntryPoints
return m_entryPoints;
}
-GfxCount RootShaderObjectImpl::getEntryPointCount() { return (GfxCount)m_entryPoints.getCount(); }
+GfxCount RootShaderObjectImpl::getEntryPointCount()
+{
+ return (GfxCount)m_entryPoints.getCount();
+}
Result RootShaderObjectImpl::getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint)
{
@@ -1103,7 +1131,9 @@ Result RootShaderObjectImpl::copyFrom(IShaderObject* object, ITransientResourceH
}
Result RootShaderObjectImpl::bindAsRoot(
- PipelineCommandEncoder* encoder, RootBindingContext& context, RootShaderObjectLayout* layout)
+ PipelineCommandEncoder* encoder,
+ RootBindingContext& context,
+ RootShaderObjectLayout* layout)
{
BindingOffset offset = {};
offset.pending = layout->getPendingDataOffset();
@@ -1141,8 +1171,8 @@ Result RootShaderObjectImpl::bindAsRoot(
// `RootShaderObjectLayout` has already baked any offsets
// from the global layout into the `entryPointInfo`.
- entryPoint->bindAsEntryPoint(
- encoder, context, entryPointInfo.offset, entryPointInfo.layout);
+ entryPoint
+ ->bindAsEntryPoint(encoder, context, entryPointInfo.offset, entryPointInfo.layout);
}
return SLANG_OK;
diff --git a/tools/gfx/vulkan/vk-shader-object.h b/tools/gfx/vulkan/vk-shader-object.h
index efd8842cb..fafeb67f1 100644
--- a/tools/gfx/vulkan/vk-shader-object.h
+++ b/tools/gfx/vulkan/vk-shader-object.h
@@ -2,10 +2,10 @@
#pragma once
#include "vk-base.h"
+#include "vk-helper-functions.h"
#include "vk-resource-views.h"
#include "vk-sampler.h"
#include "vk-shader-object-layout.h"
-#include "vk-helper-functions.h"
namespace gfx
{
@@ -27,14 +27,16 @@ class ShaderObjectImpl
{
public:
static Result create(
- IDevice* device, ShaderObjectLayoutImpl* layout, ShaderObjectImpl** outShaderObject);
+ IDevice* device,
+ ShaderObjectLayoutImpl* layout,
+ ShaderObjectImpl** outShaderObject);
RendererBase* getDevice();
virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override;
@@ -42,16 +44,18 @@ public:
// TODO: Changed size_t to Size? inSize assigned to an Index variable inside implementation
virtual SLANG_NO_THROW Result SLANG_MCALL
- setData(ShaderOffset const& inOffset, void const* data, size_t inSize) override;
+ setData(ShaderOffset const& inOffset, void const* data, size_t inSize) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
+ setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
+ setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
- ShaderOffset const& offset, IResourceView* textureView, ISamplerState* sampler) override;
+ ShaderOffset const& offset,
+ IResourceView* textureView,
+ ISamplerState* sampler) override;
protected:
friend class RootShaderObjectLayout;
@@ -125,7 +129,8 @@ public:
/// Ensure that the `m_ordinaryDataBuffer` has been created, if it is needed
Result _ensureOrdinaryDataBufferCreatedIfNeeded(
- PipelineCommandEncoder* encoder, ShaderObjectLayoutImpl* specializedLayout);
+ PipelineCommandEncoder* encoder,
+ ShaderObjectLayoutImpl* specializedLayout);
public:
/// Bind this shader object as a "value"
@@ -211,7 +216,9 @@ class EntryPointShaderObject : public ShaderObjectImpl
public:
static Result create(
- IDevice* device, EntryPointLayout* layout, EntryPointShaderObject** outShaderObject);
+ IDevice* device,
+ EntryPointLayout* layout,
+ EntryPointShaderObject** outShaderObject);
EntryPointLayout* getLayout();
@@ -244,10 +251,11 @@ public:
List<RefPtr<EntryPointShaderObject>> const& getEntryPoints() const;
virtual GfxCount SLANG_MCALL getEntryPointCount() override;
- virtual Result SLANG_MCALL getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
+ virtual Result SLANG_MCALL
+ getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- copyFrom(IShaderObject* object, ITransientResourceHeap* transientHeap) override;
+ copyFrom(IShaderObject* object, ITransientResourceHeap* transientHeap) override;
/// Bind this object as a root shader object
Result bindAsRoot(
diff --git a/tools/gfx/vulkan/vk-shader-program.cpp b/tools/gfx/vulkan/vk-shader-program.cpp
index 4159561d1..43a295786 100644
--- a/tools/gfx/vulkan/vk-shader-program.cpp
+++ b/tools/gfx/vulkan/vk-shader-program.cpp
@@ -30,7 +30,10 @@ ShaderProgramImpl::~ShaderProgramImpl()
}
}
-void ShaderProgramImpl::comFree() { m_device.breakStrongReference(); }
+void ShaderProgramImpl::comFree()
+{
+ m_device.breakStrongReference();
+}
VkPipelineShaderStageCreateInfo ShaderProgramImpl::compileEntryPoint(
const char* entryPointName,
@@ -50,7 +53,10 @@ VkPipelineShaderStageCreateInfo ShaderProgramImpl::compileEntryPoint(
VkShaderModule module;
SLANG_VK_CHECK(m_device->m_api.vkCreateShaderModule(
- m_device->m_device, &moduleCreateInfo, nullptr, &module));
+ m_device->m_device,
+ &moduleCreateInfo,
+ nullptr,
+ &module));
outShaderModule = module;
VkPipelineShaderStageCreateInfo shaderStageCreateInfo = {
@@ -64,7 +70,8 @@ VkPipelineShaderStageCreateInfo ShaderProgramImpl::compileEntryPoint(
}
Result ShaderProgramImpl::createShaderModule(
- slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode)
+ slang::EntryPointReflection* entryPointInfo,
+ ComPtr<ISlangBlob> kernelCode)
{
m_codeBlobs.add(kernelCode);
VkShaderModule shaderModule;
diff --git a/tools/gfx/vulkan/vk-shader-program.h b/tools/gfx/vulkan/vk-shader-program.h
index 49fd6d256..3fd56669a 100644
--- a/tools/gfx/vulkan/vk-shader-program.h
+++ b/tools/gfx/vulkan/vk-shader-program.h
@@ -36,7 +36,8 @@ public:
VkShaderModule& outShaderModule);
virtual Result createShaderModule(
- slang::EntryPointReflection* entryPointInfo, ComPtr<ISlangBlob> kernelCode) override;
+ slang::EntryPointReflection* entryPointInfo,
+ ComPtr<ISlangBlob> kernelCode) override;
};
diff --git a/tools/gfx/vulkan/vk-shader-table.cpp b/tools/gfx/vulkan/vk-shader-table.cpp
index beb826111..4d47a2b96 100644
--- a/tools/gfx/vulkan/vk-shader-table.cpp
+++ b/tools/gfx/vulkan/vk-shader-table.cpp
@@ -2,9 +2,8 @@
#include "vk-shader-table.h"
#include "vk-device.h"
-#include "vk-transient-heap.h"
-
#include "vk-helper-functions.h"
+#include "vk-transient-heap.h"
namespace gfx
{
@@ -24,11 +23,14 @@ RefPtr<BufferResource> ShaderTableImpl::createDeviceBuffer(
uint32_t handleSize = rtProps.shaderGroupHandleSize;
m_raygenTableSize = m_rayGenShaderCount * rtProps.shaderGroupBaseAlignment;
m_missTableSize = (uint32_t)VulkanUtil::calcAligned(
- m_missShaderCount * handleSize, rtProps.shaderGroupBaseAlignment);
+ m_missShaderCount * handleSize,
+ rtProps.shaderGroupBaseAlignment);
m_hitTableSize = (uint32_t)VulkanUtil::calcAligned(
- m_hitGroupCount * handleSize, rtProps.shaderGroupBaseAlignment);
+ m_hitGroupCount * handleSize,
+ rtProps.shaderGroupBaseAlignment);
m_callableTableSize = (uint32_t)VulkanUtil::calcAligned(
- m_callableShaderCount * handleSize, rtProps.shaderGroupBaseAlignment);
+ m_callableShaderCount * handleSize,
+ rtProps.shaderGroupBaseAlignment);
uint32_t tableSize = m_raygenTableSize + m_missTableSize + m_hitTableSize + m_callableTableSize;
auto pipelineImpl = static_cast<RayTracingPipelineStateImpl*>(pipeline);
@@ -51,8 +53,8 @@ RefPtr<BufferResource> ShaderTableImpl::createDeviceBuffer(
IBufferResource* stagingBuffer = nullptr;
Offset stagingBufferOffset = 0;
- transientHeapImpl->allocateStagingBuffer(
- tableSize, stagingBuffer, stagingBufferOffset, MemoryType::Upload);
+ transientHeapImpl
+ ->allocateStagingBuffer(tableSize, stagingBuffer, stagingBufferOffset, MemoryType::Upload);
assert(stagingBuffer);
void* stagingPtr = nullptr;
diff --git a/tools/gfx/vulkan/vk-swap-chain.cpp b/tools/gfx/vulkan/vk-swap-chain.cpp
index 7580e01b3..4f9bd3ca2 100644
--- a/tools/gfx/vulkan/vk-swap-chain.cpp
+++ b/tools/gfx/vulkan/vk-swap-chain.cpp
@@ -1,8 +1,8 @@
// vk-swap-chain.cpp
#include "vk-swap-chain.h"
-#include "vk-util.h"
#include "../apple/cocoa-util.h"
+#include "vk-util.h"
namespace gfx
{
@@ -44,7 +44,9 @@ void SwapchainImpl::getWindowSize(int* widthOut, int* heightOut) const
#elif defined(SLANG_ENABLE_XLIB)
XWindowAttributes winAttr = {};
XGetWindowAttributes(
- (Display*)m_windowHandle.handleValues[0], (Window)m_windowHandle.handleValues[1], &winAttr);
+ (Display*)m_windowHandle.handleValues[0],
+ (Window)m_windowHandle.handleValues[1],
+ &winAttr);
*widthOut = winAttr.width;
*heightOut = winAttr.height;
@@ -78,22 +80,32 @@ Result SwapchainImpl::createSwapchainAndImages()
VkSurfaceCapabilitiesKHR surfaceCaps;
SLANG_VK_RETURN_ON_FAIL(m_api->vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
- m_api->m_physicalDevice, m_surface, &surfaceCaps));
+ m_api->m_physicalDevice,
+ m_surface,
+ &surfaceCaps));
}
VkPresentModeKHR presentMode;
List<VkPresentModeKHR> presentModes;
uint32_t numPresentModes = 0;
m_api->vkGetPhysicalDeviceSurfacePresentModesKHR(
- m_api->m_physicalDevice, m_surface, &numPresentModes, nullptr);
+ m_api->m_physicalDevice,
+ m_surface,
+ &numPresentModes,
+ nullptr);
presentModes.setCount(numPresentModes);
m_api->vkGetPhysicalDeviceSurfacePresentModesKHR(
- m_api->m_physicalDevice, m_surface, &numPresentModes, presentModes.getBuffer());
+ m_api->m_physicalDevice,
+ m_surface,
+ &numPresentModes,
+ presentModes.getBuffer());
{
int numCheckPresentOptions = 3;
VkPresentModeKHR presentOptions[] = {
- VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_FIFO_KHR};
+ VK_PRESENT_MODE_IMMEDIATE_KHR,
+ VK_PRESENT_MODE_MAILBOX_KHR,
+ VK_PRESENT_MODE_FIFO_KHR};
if (m_desc.enableVSync)
{
presentOptions[0] = VK_PRESENT_MODE_FIFO_KHR;
@@ -147,14 +159,19 @@ Result SwapchainImpl::createSwapchainAndImages()
{
vkImages.setCount(numSwapChainImages);
m_api->vkGetSwapchainImagesKHR(
- m_api->m_device, m_swapChain, &numSwapChainImages, vkImages.getBuffer());
+ m_api->m_device,
+ m_swapChain,
+ &numSwapChainImages,
+ vkImages.getBuffer());
}
for (GfxIndex i = 0; i < m_desc.imageCount; i++)
{
ITextureResource::Desc imageDesc = {};
imageDesc.allowedStates = ResourceStateSet(
- ResourceState::Present, ResourceState::RenderTarget, ResourceState::CopyDestination);
+ ResourceState::Present,
+ ResourceState::RenderTarget,
+ ResourceState::CopyDestination);
imageDesc.type = IResource::Type::Texture2D;
imageDesc.arraySize = 0;
imageDesc.format = m_desc.format;
@@ -213,7 +230,10 @@ Result SwapchainImpl::init(DeviceImpl* renderer, const ISwapchain::Desc& desc, W
VkSemaphoreCreateInfo semaphoreCreateInfo = {};
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
SLANG_VK_RETURN_ON_FAIL(renderer->m_api.vkCreateSemaphore(
- renderer->m_api.m_device, &semaphoreCreateInfo, nullptr, &m_nextImageSemaphore));
+ renderer->m_api.m_device,
+ &semaphoreCreateInfo,
+ nullptr,
+ &m_nextImageSemaphore));
m_queue = static_cast<CommandQueueImpl*>(desc.queue);
@@ -247,15 +267,24 @@ Result SwapchainImpl::init(DeviceImpl* renderer, const ISwapchain::Desc& desc, W
VkBool32 supported = false;
m_api->vkGetPhysicalDeviceSurfaceSupportKHR(
- m_api->m_physicalDevice, renderer->m_queueFamilyIndex, m_surface, &supported);
+ m_api->m_physicalDevice,
+ renderer->m_queueFamilyIndex,
+ m_surface,
+ &supported);
uint32_t numSurfaceFormats = 0;
List<VkSurfaceFormatKHR> surfaceFormats;
m_api->vkGetPhysicalDeviceSurfaceFormatsKHR(
- m_api->m_physicalDevice, m_surface, &numSurfaceFormats, nullptr);
+ m_api->m_physicalDevice,
+ m_surface,
+ &numSurfaceFormats,
+ nullptr);
surfaceFormats.setCount(int(numSurfaceFormats));
m_api->vkGetPhysicalDeviceSurfaceFormatsKHR(
- m_api->m_physicalDevice, m_surface, &numSurfaceFormats, surfaceFormats.getBuffer());
+ m_api->m_physicalDevice,
+ m_surface,
+ &numSurfaceFormats,
+ surfaceFormats.getBuffer());
// Look for a suitable format
List<VkFormat> formats;
@@ -360,8 +389,7 @@ int SwapchainImpl::acquireNextImage()
VK_NULL_HANDLE,
(uint32_t*)&m_currentImageIndex);
- if (
- result != VK_SUCCESS
+ if (result != VK_SUCCESS
#if SLANG_APPLE_FAMILY
&& result != VK_SUBOPTIMAL_KHR
#endif
@@ -376,7 +404,10 @@ int SwapchainImpl::acquireNextImage()
return m_currentImageIndex;
}
-Result SwapchainImpl::setFullScreenMode(bool mode) { return SLANG_FAIL; }
+Result SwapchainImpl::setFullScreenMode(bool mode)
+{
+ return SLANG_FAIL;
+}
} // namespace vk
} // namespace gfx
diff --git a/tools/gfx/vulkan/vk-swap-chain.h b/tools/gfx/vulkan/vk-swap-chain.h
index 50878cd7b..166140cce 100644
--- a/tools/gfx/vulkan/vk-swap-chain.h
+++ b/tools/gfx/vulkan/vk-swap-chain.h
@@ -14,9 +14,7 @@ using namespace Slang;
namespace vk
{
-class SwapchainImpl
- : public ISwapchain
- , public ComObject
+class SwapchainImpl : public ISwapchain, public ComObject
{
public:
SLANG_COM_OBJECT_IUNKNOWN_ALL
@@ -53,7 +51,7 @@ public:
virtual SLANG_NO_THROW const Desc& SLANG_MCALL getDesc() override { return m_desc; }
virtual SLANG_NO_THROW Result SLANG_MCALL
- getImage(GfxIndex index, ITextureResource** outResource) override;
+ getImage(GfxIndex index, ITextureResource** outResource) override;
virtual SLANG_NO_THROW Result SLANG_MCALL resize(GfxCount width, GfxCount height) override;
virtual SLANG_NO_THROW Result SLANG_MCALL present() override;
virtual SLANG_NO_THROW int SLANG_MCALL acquireNextImage() override;
diff --git a/tools/gfx/vulkan/vk-texture.cpp b/tools/gfx/vulkan/vk-texture.cpp
index 13775cef0..ea305c1a1 100644
--- a/tools/gfx/vulkan/vk-texture.cpp
+++ b/tools/gfx/vulkan/vk-texture.cpp
@@ -10,9 +10,9 @@ namespace vk
{
TextureResourceImpl::TextureResourceImpl(const Desc& desc, DeviceImpl* device)
- : Parent(desc)
- , m_device(device)
-{}
+ : Parent(desc), m_device(device)
+{
+}
TextureResourceImpl::~TextureResourceImpl()
{
diff --git a/tools/gfx/vulkan/vk-texture.h b/tools/gfx/vulkan/vk-texture.h
index 95e3b779e..58ef420fe 100644
--- a/tools/gfx/vulkan/vk-texture.h
+++ b/tools/gfx/vulkan/vk-texture.h
@@ -26,7 +26,7 @@ public:
RefPtr<DeviceImpl> m_device;
virtual SLANG_NO_THROW Result SLANG_MCALL
- getNativeResourceHandle(InteropHandle* outHandle) override;
+ getNativeResourceHandle(InteropHandle* outHandle) override;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) override;
diff --git a/tools/gfx/vulkan/vk-transient-heap.cpp b/tools/gfx/vulkan/vk-transient-heap.cpp
index fa4eb718b..afc062d0f 100644
--- a/tools/gfx/vulkan/vk-transient-heap.cpp
+++ b/tools/gfx/vulkan/vk-transient-heap.cpp
@@ -22,7 +22,10 @@ void TransientResourceHeapImpl::advanceFence()
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceCreateInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
m_device->m_api.vkCreateFence(
- m_device->m_api.m_device, &fenceCreateInfo, nullptr, &m_fences[m_fenceIndex]);
+ m_device->m_api.m_device,
+ &fenceCreateInfo,
+ nullptr,
+ &m_fences[m_fenceIndex]);
}
}
@@ -40,8 +43,8 @@ Result TransientResourceHeapImpl::init(const ITransientResourceHeap::Desc& desc,
poolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
poolCreateInfo.queueFamilyIndex =
device->getQueueFamilyIndex(ICommandQueue::QueueType::Graphics);
- device->m_api.vkCreateCommandPool(
- device->m_api.m_device, &poolCreateInfo, nullptr, &m_commandPool);
+ device->m_api
+ .vkCreateCommandPool(device->m_api.m_device, &poolCreateInfo, nullptr, &m_commandPool);
advanceFence();
return SLANG_OK;
@@ -83,8 +86,11 @@ Result TransientResourceHeapImpl::synchronizeAndReset()
m_commandBufferAllocId = 0;
auto& api = m_device->m_api;
if (api.vkWaitForFences(
- api.m_device, (uint32_t)m_fences.getCount(), m_fences.getBuffer(), 1, UINT64_MAX) !=
- VK_SUCCESS)
+ api.m_device,
+ (uint32_t)m_fences.getCount(),
+ m_fences.getBuffer(),
+ 1,
+ UINT64_MAX) != VK_SUCCESS)
{
return SLANG_FAIL;
}
diff --git a/tools/gfx/vulkan/vk-transient-heap.h b/tools/gfx/vulkan/vk-transient-heap.h
index e41d760f2..8a0f7a74d 100644
--- a/tools/gfx/vulkan/vk-transient-heap.h
+++ b/tools/gfx/vulkan/vk-transient-heap.h
@@ -34,7 +34,7 @@ public:
public:
virtual SLANG_NO_THROW Result SLANG_MCALL
- createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
+ createCommandBuffer(ICommandBuffer** outCommandBuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL synchronizeAndReset() override;
};
diff --git a/tools/gfx/vulkan/vk-util.cpp b/tools/gfx/vulkan/vk-util.cpp
index 1a571c812..696e80fc7 100644
--- a/tools/gfx/vulkan/vk-util.cpp
+++ b/tools/gfx/vulkan/vk-util.cpp
@@ -1,121 +1,123 @@
// vk-util.cpp
#include "vk-util.h"
+
#include "core/slang-math.h"
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
-namespace gfx {
+namespace gfx
+{
-/* static */VkFormat VulkanUtil::getVkFormat(Format format)
+/* static */ VkFormat VulkanUtil::getVkFormat(Format format)
{
switch (format)
{
- case Format::R32G32B32A32_TYPELESS: return VK_FORMAT_R32G32B32A32_SFLOAT;
- case Format::R32G32B32_TYPELESS: return VK_FORMAT_R32G32B32_SFLOAT;
- case Format::R32G32_TYPELESS: return VK_FORMAT_R32G32_SFLOAT;
- case Format::R32_TYPELESS: return VK_FORMAT_R32_SFLOAT;
-
- case Format::R16G16B16A16_TYPELESS: return VK_FORMAT_R16G16B16A16_SFLOAT;
- case Format::R16G16_TYPELESS: return VK_FORMAT_R16G16_SFLOAT;
- case Format::R16_TYPELESS: return VK_FORMAT_R16_SFLOAT;
-
- case Format::R8G8B8A8_TYPELESS: return VK_FORMAT_R8G8B8A8_UNORM;
- case Format::R8G8_TYPELESS: return VK_FORMAT_R8G8_UNORM;
- case Format::R8_TYPELESS: return VK_FORMAT_R8_UNORM;
- case Format::B8G8R8A8_TYPELESS: return VK_FORMAT_B8G8R8A8_UNORM;
-
- case Format::R64_UINT: return VK_FORMAT_R64_UINT;
-
- case Format::R32G32B32A32_FLOAT: return VK_FORMAT_R32G32B32A32_SFLOAT;
- case Format::R32G32B32_FLOAT: return VK_FORMAT_R32G32B32_SFLOAT;
- case Format::R32G32_FLOAT: return VK_FORMAT_R32G32_SFLOAT;
- case Format::R32_FLOAT: return VK_FORMAT_R32_SFLOAT;
-
- case Format::R16G16B16A16_FLOAT: return VK_FORMAT_R16G16B16A16_SFLOAT;
- case Format::R16G16_FLOAT: return VK_FORMAT_R16G16_SFLOAT;
- case Format::R16_FLOAT: return VK_FORMAT_R16_SFLOAT;
-
- case Format::R32G32B32A32_UINT: return VK_FORMAT_R32G32B32A32_UINT;
- case Format::R32G32B32_UINT: return VK_FORMAT_R32G32B32_UINT;
- case Format::R32G32_UINT: return VK_FORMAT_R32G32_UINT;
- case Format::R32_UINT: return VK_FORMAT_R32_UINT;
-
- case Format::R16G16B16A16_UINT: return VK_FORMAT_R16G16B16A16_UINT;
- case Format::R16G16_UINT: return VK_FORMAT_R16G16_UINT;
- case Format::R16_UINT: return VK_FORMAT_R16_UINT;
-
- case Format::R8G8B8A8_UINT: return VK_FORMAT_R8G8B8A8_UINT;
- case Format::R8G8_UINT: return VK_FORMAT_R8G8_UINT;
- case Format::R8_UINT: return VK_FORMAT_R8_UINT;
-
- case Format::R64_SINT: return VK_FORMAT_R64_SINT;
-
- case Format::R32G32B32A32_SINT: return VK_FORMAT_R32G32B32A32_SINT;
- case Format::R32G32B32_SINT: return VK_FORMAT_R32G32B32_SINT;
- case Format::R32G32_SINT: return VK_FORMAT_R32G32_SINT;
- case Format::R32_SINT: return VK_FORMAT_R32_SINT;
-
- case Format::R16G16B16A16_SINT: return VK_FORMAT_R16G16B16A16_SINT;
- case Format::R16G16_SINT: return VK_FORMAT_R16G16_SINT;
- case Format::R16_SINT: return VK_FORMAT_R16_SINT;
-
- case Format::R8G8B8A8_SINT: return VK_FORMAT_R8G8B8A8_SINT;
- case Format::R8G8_SINT: return VK_FORMAT_R8G8_SINT;
- case Format::R8_SINT: return VK_FORMAT_R8_SINT;
-
- case Format::R16G16B16A16_UNORM: return VK_FORMAT_R16G16B16A16_UNORM;
- case Format::R16G16_UNORM: return VK_FORMAT_R16G16_UNORM;
- case Format::R16_UNORM: return VK_FORMAT_R16_UNORM;
-
- case Format::R8G8B8A8_UNORM: return VK_FORMAT_R8G8B8A8_UNORM;
- case Format::R8G8B8A8_UNORM_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
- case Format::R8G8_UNORM: return VK_FORMAT_R8G8_UNORM;
- 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;
- case Format::R16_SNORM: return VK_FORMAT_R16_SNORM;
-
- case Format::R8G8B8A8_SNORM: return VK_FORMAT_R8G8B8A8_SNORM;
- case Format::R8G8_SNORM: return VK_FORMAT_R8G8_SNORM;
- case Format::R8_SNORM: return VK_FORMAT_R8_SNORM;
-
- case Format::D32_FLOAT: return VK_FORMAT_D32_SFLOAT;
- case Format::D16_UNORM: return VK_FORMAT_D16_UNORM;
- case Format::D32_FLOAT_S8_UINT: return VK_FORMAT_D32_SFLOAT_S8_UINT;
- case Format::R32_FLOAT_X32_TYPELESS: return VK_FORMAT_R32_SFLOAT;
-
- case Format::B4G4R4A4_UNORM: return VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT;
- case Format::B5G6R5_UNORM: return VK_FORMAT_R5G6B5_UNORM_PACK16;
- case Format::B5G5R5A1_UNORM: return VK_FORMAT_A1R5G5B5_UNORM_PACK16;
-
- case Format::R9G9B9E5_SHAREDEXP: return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
- case Format::R10G10B10A2_TYPELESS: return VK_FORMAT_A2B10G10R10_UINT_PACK32;
- case Format::R10G10B10A2_UINT: return VK_FORMAT_A2B10G10R10_UINT_PACK32;
- case Format::R10G10B10A2_UNORM: return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
- case Format::R11G11B10_FLOAT: return VK_FORMAT_B10G11R11_UFLOAT_PACK32;
-
- case Format::BC1_UNORM: return VK_FORMAT_BC1_RGBA_UNORM_BLOCK;
- case Format::BC1_UNORM_SRGB: return VK_FORMAT_BC1_RGBA_SRGB_BLOCK;
- case Format::BC2_UNORM: return VK_FORMAT_BC2_UNORM_BLOCK;
- case Format::BC2_UNORM_SRGB: return VK_FORMAT_BC2_SRGB_BLOCK;
- case Format::BC3_UNORM: return VK_FORMAT_BC3_UNORM_BLOCK;
- case Format::BC3_UNORM_SRGB: return VK_FORMAT_BC3_SRGB_BLOCK;
- case Format::BC4_UNORM: return VK_FORMAT_BC4_UNORM_BLOCK;
- case Format::BC4_SNORM: return VK_FORMAT_BC4_SNORM_BLOCK;
- case Format::BC5_UNORM: return VK_FORMAT_BC5_UNORM_BLOCK;
- case Format::BC5_SNORM: return VK_FORMAT_BC5_SNORM_BLOCK;
- case Format::BC6H_UF16: return VK_FORMAT_BC6H_UFLOAT_BLOCK;
- case Format::BC6H_SF16: return VK_FORMAT_BC6H_SFLOAT_BLOCK;
- case Format::BC7_UNORM: return VK_FORMAT_BC7_UNORM_BLOCK;
- case Format::BC7_UNORM_SRGB: return VK_FORMAT_BC7_SRGB_BLOCK;
-
- default: return VK_FORMAT_UNDEFINED;
+ case Format::R32G32B32A32_TYPELESS: return VK_FORMAT_R32G32B32A32_SFLOAT;
+ case Format::R32G32B32_TYPELESS: return VK_FORMAT_R32G32B32_SFLOAT;
+ case Format::R32G32_TYPELESS: return VK_FORMAT_R32G32_SFLOAT;
+ case Format::R32_TYPELESS: return VK_FORMAT_R32_SFLOAT;
+
+ case Format::R16G16B16A16_TYPELESS: return VK_FORMAT_R16G16B16A16_SFLOAT;
+ case Format::R16G16_TYPELESS: return VK_FORMAT_R16G16_SFLOAT;
+ case Format::R16_TYPELESS: return VK_FORMAT_R16_SFLOAT;
+
+ case Format::R8G8B8A8_TYPELESS: return VK_FORMAT_R8G8B8A8_UNORM;
+ case Format::R8G8_TYPELESS: return VK_FORMAT_R8G8_UNORM;
+ case Format::R8_TYPELESS: return VK_FORMAT_R8_UNORM;
+ case Format::B8G8R8A8_TYPELESS: return VK_FORMAT_B8G8R8A8_UNORM;
+
+ case Format::R64_UINT: return VK_FORMAT_R64_UINT;
+
+ case Format::R32G32B32A32_FLOAT: return VK_FORMAT_R32G32B32A32_SFLOAT;
+ case Format::R32G32B32_FLOAT: return VK_FORMAT_R32G32B32_SFLOAT;
+ case Format::R32G32_FLOAT: return VK_FORMAT_R32G32_SFLOAT;
+ case Format::R32_FLOAT: return VK_FORMAT_R32_SFLOAT;
+
+ case Format::R16G16B16A16_FLOAT: return VK_FORMAT_R16G16B16A16_SFLOAT;
+ case Format::R16G16_FLOAT: return VK_FORMAT_R16G16_SFLOAT;
+ case Format::R16_FLOAT: return VK_FORMAT_R16_SFLOAT;
+
+ case Format::R32G32B32A32_UINT: return VK_FORMAT_R32G32B32A32_UINT;
+ case Format::R32G32B32_UINT: return VK_FORMAT_R32G32B32_UINT;
+ case Format::R32G32_UINT: return VK_FORMAT_R32G32_UINT;
+ case Format::R32_UINT: return VK_FORMAT_R32_UINT;
+
+ case Format::R16G16B16A16_UINT: return VK_FORMAT_R16G16B16A16_UINT;
+ case Format::R16G16_UINT: return VK_FORMAT_R16G16_UINT;
+ case Format::R16_UINT: return VK_FORMAT_R16_UINT;
+
+ case Format::R8G8B8A8_UINT: return VK_FORMAT_R8G8B8A8_UINT;
+ case Format::R8G8_UINT: return VK_FORMAT_R8G8_UINT;
+ case Format::R8_UINT: return VK_FORMAT_R8_UINT;
+
+ case Format::R64_SINT: return VK_FORMAT_R64_SINT;
+
+ case Format::R32G32B32A32_SINT: return VK_FORMAT_R32G32B32A32_SINT;
+ case Format::R32G32B32_SINT: return VK_FORMAT_R32G32B32_SINT;
+ case Format::R32G32_SINT: return VK_FORMAT_R32G32_SINT;
+ case Format::R32_SINT: return VK_FORMAT_R32_SINT;
+
+ case Format::R16G16B16A16_SINT: return VK_FORMAT_R16G16B16A16_SINT;
+ case Format::R16G16_SINT: return VK_FORMAT_R16G16_SINT;
+ case Format::R16_SINT: return VK_FORMAT_R16_SINT;
+
+ case Format::R8G8B8A8_SINT: return VK_FORMAT_R8G8B8A8_SINT;
+ case Format::R8G8_SINT: return VK_FORMAT_R8G8_SINT;
+ case Format::R8_SINT: return VK_FORMAT_R8_SINT;
+
+ case Format::R16G16B16A16_UNORM: return VK_FORMAT_R16G16B16A16_UNORM;
+ case Format::R16G16_UNORM: return VK_FORMAT_R16G16_UNORM;
+ case Format::R16_UNORM: return VK_FORMAT_R16_UNORM;
+
+ case Format::R8G8B8A8_UNORM: return VK_FORMAT_R8G8B8A8_UNORM;
+ case Format::R8G8B8A8_UNORM_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
+ case Format::R8G8_UNORM: return VK_FORMAT_R8G8_UNORM;
+ 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;
+ case Format::R16_SNORM: return VK_FORMAT_R16_SNORM;
+
+ case Format::R8G8B8A8_SNORM: return VK_FORMAT_R8G8B8A8_SNORM;
+ case Format::R8G8_SNORM: return VK_FORMAT_R8G8_SNORM;
+ case Format::R8_SNORM: return VK_FORMAT_R8_SNORM;
+
+ case Format::D32_FLOAT: return VK_FORMAT_D32_SFLOAT;
+ case Format::D16_UNORM: return VK_FORMAT_D16_UNORM;
+ case Format::D32_FLOAT_S8_UINT: return VK_FORMAT_D32_SFLOAT_S8_UINT;
+ case Format::R32_FLOAT_X32_TYPELESS: return VK_FORMAT_R32_SFLOAT;
+
+ case Format::B4G4R4A4_UNORM: return VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT;
+ case Format::B5G6R5_UNORM: return VK_FORMAT_R5G6B5_UNORM_PACK16;
+ case Format::B5G5R5A1_UNORM: return VK_FORMAT_A1R5G5B5_UNORM_PACK16;
+
+ case Format::R9G9B9E5_SHAREDEXP: return VK_FORMAT_E5B9G9R9_UFLOAT_PACK32;
+ case Format::R10G10B10A2_TYPELESS: return VK_FORMAT_A2B10G10R10_UINT_PACK32;
+ case Format::R10G10B10A2_UINT: return VK_FORMAT_A2B10G10R10_UINT_PACK32;
+ case Format::R10G10B10A2_UNORM: return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
+ case Format::R11G11B10_FLOAT: return VK_FORMAT_B10G11R11_UFLOAT_PACK32;
+
+ case Format::BC1_UNORM: return VK_FORMAT_BC1_RGBA_UNORM_BLOCK;
+ case Format::BC1_UNORM_SRGB: return VK_FORMAT_BC1_RGBA_SRGB_BLOCK;
+ case Format::BC2_UNORM: return VK_FORMAT_BC2_UNORM_BLOCK;
+ case Format::BC2_UNORM_SRGB: return VK_FORMAT_BC2_SRGB_BLOCK;
+ case Format::BC3_UNORM: return VK_FORMAT_BC3_UNORM_BLOCK;
+ case Format::BC3_UNORM_SRGB: return VK_FORMAT_BC3_SRGB_BLOCK;
+ case Format::BC4_UNORM: return VK_FORMAT_BC4_UNORM_BLOCK;
+ case Format::BC4_SNORM: return VK_FORMAT_BC4_SNORM_BLOCK;
+ case Format::BC5_UNORM: return VK_FORMAT_BC5_UNORM_BLOCK;
+ case Format::BC5_SNORM: return VK_FORMAT_BC5_SNORM_BLOCK;
+ case Format::BC6H_UF16: return VK_FORMAT_BC6H_UFLOAT_BLOCK;
+ case Format::BC6H_SF16: return VK_FORMAT_BC6H_SFLOAT_BLOCK;
+ case Format::BC7_UNORM: return VK_FORMAT_BC7_UNORM_BLOCK;
+ case Format::BC7_UNORM_SRGB: return VK_FORMAT_BC7_SRGB_BLOCK;
+
+ default: return VK_FORMAT_UNDEFINED;
}
}
@@ -132,38 +134,26 @@ VkImageAspectFlags VulkanUtil::getAspectMask(TextureAspect aspect, VkFormat form
return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
case VK_FORMAT_D16_UNORM:
case VK_FORMAT_D32_SFLOAT:
- case VK_FORMAT_X8_D24_UNORM_PACK32:
- return VK_IMAGE_ASPECT_DEPTH_BIT;
- case VK_FORMAT_S8_UINT:
- return VK_IMAGE_ASPECT_STENCIL_BIT;
- default:
- return VK_IMAGE_ASPECT_COLOR_BIT;
+ case VK_FORMAT_X8_D24_UNORM_PACK32: return VK_IMAGE_ASPECT_DEPTH_BIT;
+ case VK_FORMAT_S8_UINT: return VK_IMAGE_ASPECT_STENCIL_BIT;
+ default: return VK_IMAGE_ASPECT_COLOR_BIT;
}
- case TextureAspect::Color:
- return VK_IMAGE_ASPECT_COLOR_BIT;
- case TextureAspect::Depth:
- return VK_IMAGE_ASPECT_DEPTH_BIT;
+ case TextureAspect::Color: return VK_IMAGE_ASPECT_COLOR_BIT;
+ case TextureAspect::Depth: return VK_IMAGE_ASPECT_DEPTH_BIT;
case TextureAspect::DepthStencil:
return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
- case TextureAspect::Stencil:
- return VK_IMAGE_ASPECT_STENCIL_BIT;
- case TextureAspect::Plane0:
- return VK_IMAGE_ASPECT_PLANE_0_BIT;
- case TextureAspect::Plane1:
- return VK_IMAGE_ASPECT_PLANE_1_BIT;
-
- case TextureAspect::Plane2:
- return VK_IMAGE_ASPECT_PLANE_2_BIT;
-
- case TextureAspect::MetaData:
- return VK_IMAGE_ASPECT_METADATA_BIT;
- default:
- SLANG_UNREACHABLE("getAspectMask");
- return 0;
+ case TextureAspect::Stencil: return VK_IMAGE_ASPECT_STENCIL_BIT;
+ case TextureAspect::Plane0: return VK_IMAGE_ASPECT_PLANE_0_BIT;
+ case TextureAspect::Plane1: return VK_IMAGE_ASPECT_PLANE_1_BIT;
+
+ case TextureAspect::Plane2: return VK_IMAGE_ASPECT_PLANE_2_BIT;
+
+ case TextureAspect::MetaData: return VK_IMAGE_ASPECT_METADATA_BIT;
+ default: SLANG_UNREACHABLE("getAspectMask"); return 0;
}
}
-/* static */SlangResult VulkanUtil::toSlangResult(VkResult res)
+/* static */ SlangResult VulkanUtil::toSlangResult(VkResult res)
{
return (res == VK_SUCCESS) ? SLANG_OK : SLANG_FAIL;
}
@@ -172,37 +162,21 @@ VkShaderStageFlags VulkanUtil::getShaderStage(SlangStage stage)
{
switch (stage)
{
- case SLANG_STAGE_ANY_HIT:
- return VK_SHADER_STAGE_ANY_HIT_BIT_KHR;
- case SLANG_STAGE_CALLABLE:
- return VK_SHADER_STAGE_CALLABLE_BIT_KHR;
- case SLANG_STAGE_CLOSEST_HIT:
- return VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
- case SLANG_STAGE_COMPUTE:
- return VK_SHADER_STAGE_COMPUTE_BIT;
- case SLANG_STAGE_DOMAIN:
- return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
- case SLANG_STAGE_FRAGMENT:
- return VK_SHADER_STAGE_FRAGMENT_BIT;
- case SLANG_STAGE_GEOMETRY:
- return VK_SHADER_STAGE_GEOMETRY_BIT;
- case SLANG_STAGE_HULL:
- return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
- case SLANG_STAGE_INTERSECTION:
- return VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
- case SLANG_STAGE_MISS:
- return VK_SHADER_STAGE_MISS_BIT_KHR;
- case SLANG_STAGE_RAY_GENERATION:
- return VK_SHADER_STAGE_RAYGEN_BIT_KHR;
- case SLANG_STAGE_VERTEX:
- return VK_SHADER_STAGE_VERTEX_BIT;
- case SLANG_STAGE_MESH:
- return VK_SHADER_STAGE_MESH_BIT_EXT;
- case SLANG_STAGE_AMPLIFICATION:
- return VK_SHADER_STAGE_TASK_BIT_EXT;
- default:
- assert(!"unsupported stage.");
- return VkShaderStageFlags(-1);
+ case SLANG_STAGE_ANY_HIT: return VK_SHADER_STAGE_ANY_HIT_BIT_KHR;
+ case SLANG_STAGE_CALLABLE: return VK_SHADER_STAGE_CALLABLE_BIT_KHR;
+ case SLANG_STAGE_CLOSEST_HIT: return VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
+ case SLANG_STAGE_COMPUTE: return VK_SHADER_STAGE_COMPUTE_BIT;
+ case SLANG_STAGE_DOMAIN: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
+ case SLANG_STAGE_FRAGMENT: return VK_SHADER_STAGE_FRAGMENT_BIT;
+ case SLANG_STAGE_GEOMETRY: return VK_SHADER_STAGE_GEOMETRY_BIT;
+ case SLANG_STAGE_HULL: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
+ case SLANG_STAGE_INTERSECTION: return VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
+ case SLANG_STAGE_MISS: return VK_SHADER_STAGE_MISS_BIT_KHR;
+ case SLANG_STAGE_RAY_GENERATION: return VK_SHADER_STAGE_RAYGEN_BIT_KHR;
+ case SLANG_STAGE_VERTEX: return VK_SHADER_STAGE_VERTEX_BIT;
+ case SLANG_STAGE_MESH: return VK_SHADER_STAGE_MESH_BIT_EXT;
+ case SLANG_STAGE_AMPLIFICATION: return VK_SHADER_STAGE_TASK_BIT_EXT;
+ default: assert(!"unsupported stage."); return VkShaderStageFlags(-1);
}
}
@@ -212,29 +186,18 @@ VkImageLayout VulkanUtil::getImageLayoutFromState(ResourceState state)
{
case ResourceState::ShaderResource:
case ResourceState::PixelShaderResource:
- case ResourceState::NonPixelShaderResource:
- return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+ case ResourceState::NonPixelShaderResource: return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
case ResourceState::UnorderedAccess:
- case ResourceState::General:
- return VK_IMAGE_LAYOUT_GENERAL;
- case ResourceState::Present:
- return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
- case ResourceState::CopySource:
- return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
- case ResourceState::CopyDestination:
- return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
- case ResourceState::RenderTarget:
- return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
- case ResourceState::DepthWrite:
- return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
- case ResourceState::DepthRead:
- return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
- case ResourceState::ResolveSource:
- return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
- case ResourceState::ResolveDestination:
- return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
- default:
- return VK_IMAGE_LAYOUT_UNDEFINED;
+ case ResourceState::General: return VK_IMAGE_LAYOUT_GENERAL;
+ case ResourceState::Present: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+ case ResourceState::CopySource: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
+ case ResourceState::CopyDestination: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ case ResourceState::RenderTarget: return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ case ResourceState::DepthWrite: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+ case ResourceState::DepthRead: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
+ case ResourceState::ResolveSource: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
+ case ResourceState::ResolveDestination: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ default: return VK_IMAGE_LAYOUT_UNDEFINED;
}
return VkImageLayout();
}
@@ -243,23 +206,14 @@ VkSampleCountFlagBits VulkanUtil::translateSampleCount(uint32_t sampleCount)
{
switch (sampleCount)
{
- case 1:
- return VK_SAMPLE_COUNT_1_BIT;
- case 2:
- return VK_SAMPLE_COUNT_2_BIT;
- case 4:
- return VK_SAMPLE_COUNT_4_BIT;
- case 8:
- return VK_SAMPLE_COUNT_8_BIT;
- case 16:
- return VK_SAMPLE_COUNT_16_BIT;
- case 32:
- return VK_SAMPLE_COUNT_32_BIT;
- case 64:
- return VK_SAMPLE_COUNT_64_BIT;
- default:
- assert(!"Unsupported sample count");
- return VK_SAMPLE_COUNT_1_BIT;
+ case 1: return VK_SAMPLE_COUNT_1_BIT;
+ case 2: return VK_SAMPLE_COUNT_2_BIT;
+ case 4: return VK_SAMPLE_COUNT_4_BIT;
+ case 8: return VK_SAMPLE_COUNT_8_BIT;
+ case 16: return VK_SAMPLE_COUNT_16_BIT;
+ case 32: return VK_SAMPLE_COUNT_32_BIT;
+ case 64: return VK_SAMPLE_COUNT_64_BIT;
+ default: assert(!"Unsupported sample count"); return VK_SAMPLE_COUNT_1_BIT;
}
}
@@ -267,15 +221,10 @@ VkCullModeFlags VulkanUtil::translateCullMode(CullMode cullMode)
{
switch (cullMode)
{
- case CullMode::None:
- return VK_CULL_MODE_NONE;
- case CullMode::Front:
- return VK_CULL_MODE_FRONT_BIT;
- case CullMode::Back:
- return VK_CULL_MODE_BACK_BIT;
- default:
- assert(!"Unsupported cull mode");
- return VK_CULL_MODE_NONE;
+ case CullMode::None: return VK_CULL_MODE_NONE;
+ case CullMode::Front: return VK_CULL_MODE_FRONT_BIT;
+ case CullMode::Back: return VK_CULL_MODE_BACK_BIT;
+ default: assert(!"Unsupported cull mode"); return VK_CULL_MODE_NONE;
}
}
@@ -283,13 +232,9 @@ VkFrontFace VulkanUtil::translateFrontFaceMode(FrontFaceMode frontFaceMode)
{
switch (frontFaceMode)
{
- case FrontFaceMode::CounterClockwise:
- return VK_FRONT_FACE_COUNTER_CLOCKWISE;
- case FrontFaceMode::Clockwise:
- return VK_FRONT_FACE_CLOCKWISE;
- default:
- assert(!"Unsupported front face mode");
- return VK_FRONT_FACE_CLOCKWISE;
+ case FrontFaceMode::CounterClockwise: return VK_FRONT_FACE_COUNTER_CLOCKWISE;
+ case FrontFaceMode::Clockwise: return VK_FRONT_FACE_CLOCKWISE;
+ default: assert(!"Unsupported front face mode"); return VK_FRONT_FACE_CLOCKWISE;
}
}
@@ -297,13 +242,9 @@ VkPolygonMode VulkanUtil::translateFillMode(FillMode fillMode)
{
switch (fillMode)
{
- case FillMode::Solid:
- return VK_POLYGON_MODE_FILL;
- case FillMode::Wireframe:
- return VK_POLYGON_MODE_LINE;
- default:
- assert(!"Unsupported fill mode");
- return VK_POLYGON_MODE_FILL;
+ case FillMode::Solid: return VK_POLYGON_MODE_FILL;
+ case FillMode::Wireframe: return VK_POLYGON_MODE_LINE;
+ default: assert(!"Unsupported fill mode"); return VK_POLYGON_MODE_FILL;
}
}
@@ -311,44 +252,25 @@ VkBlendFactor VulkanUtil::translateBlendFactor(BlendFactor blendFactor)
{
switch (blendFactor)
{
- case BlendFactor::Zero:
- return VK_BLEND_FACTOR_ZERO;
- case BlendFactor::One:
- return VK_BLEND_FACTOR_ONE;
- case BlendFactor::SrcColor:
- return VK_BLEND_FACTOR_SRC_COLOR;
- case BlendFactor::InvSrcColor:
- return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
- case BlendFactor::SrcAlpha:
- return VK_BLEND_FACTOR_SRC_ALPHA;
- case BlendFactor::InvSrcAlpha:
- return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
- case BlendFactor::DestAlpha:
- return VK_BLEND_FACTOR_DST_ALPHA;
- case BlendFactor::InvDestAlpha:
- return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
- case BlendFactor::DestColor:
- return VK_BLEND_FACTOR_DST_COLOR;
- case BlendFactor::InvDestColor:
- return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
- case BlendFactor::SrcAlphaSaturate:
- return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE;
- case BlendFactor::BlendColor:
- return VK_BLEND_FACTOR_CONSTANT_COLOR;
- case BlendFactor::InvBlendColor:
- return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
- case BlendFactor::SecondarySrcColor:
- return VK_BLEND_FACTOR_SRC1_COLOR;
- case BlendFactor::InvSecondarySrcColor:
- return VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR;
- case BlendFactor::SecondarySrcAlpha:
- return VK_BLEND_FACTOR_SRC1_ALPHA;
- case BlendFactor::InvSecondarySrcAlpha:
- return VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA;
-
- default:
- assert(!"Unsupported blend factor");
- return VK_BLEND_FACTOR_ONE;
+ case BlendFactor::Zero: return VK_BLEND_FACTOR_ZERO;
+ case BlendFactor::One: return VK_BLEND_FACTOR_ONE;
+ case BlendFactor::SrcColor: return VK_BLEND_FACTOR_SRC_COLOR;
+ case BlendFactor::InvSrcColor: return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
+ case BlendFactor::SrcAlpha: return VK_BLEND_FACTOR_SRC_ALPHA;
+ case BlendFactor::InvSrcAlpha: return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
+ case BlendFactor::DestAlpha: return VK_BLEND_FACTOR_DST_ALPHA;
+ case BlendFactor::InvDestAlpha: return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
+ case BlendFactor::DestColor: return VK_BLEND_FACTOR_DST_COLOR;
+ case BlendFactor::InvDestColor: return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
+ case BlendFactor::SrcAlphaSaturate: return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE;
+ case BlendFactor::BlendColor: return VK_BLEND_FACTOR_CONSTANT_COLOR;
+ case BlendFactor::InvBlendColor: return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
+ case BlendFactor::SecondarySrcColor: return VK_BLEND_FACTOR_SRC1_COLOR;
+ case BlendFactor::InvSecondarySrcColor: return VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR;
+ case BlendFactor::SecondarySrcAlpha: return VK_BLEND_FACTOR_SRC1_ALPHA;
+ case BlendFactor::InvSecondarySrcAlpha: return VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA;
+
+ default: assert(!"Unsupported blend factor"); return VK_BLEND_FACTOR_ONE;
}
}
@@ -356,38 +278,24 @@ VkBlendOp VulkanUtil::translateBlendOp(BlendOp op)
{
switch (op)
{
- case BlendOp::Add:
- return VK_BLEND_OP_ADD;
- case BlendOp::Subtract:
- return VK_BLEND_OP_SUBTRACT;
- case BlendOp::ReverseSubtract:
- return VK_BLEND_OP_REVERSE_SUBTRACT;
- case BlendOp::Min:
- return VK_BLEND_OP_MIN;
- case BlendOp::Max:
- return VK_BLEND_OP_MAX;
- default:
- assert(!"Unsupported blend op");
- return VK_BLEND_OP_ADD;
+ case BlendOp::Add: return VK_BLEND_OP_ADD;
+ case BlendOp::Subtract: return VK_BLEND_OP_SUBTRACT;
+ case BlendOp::ReverseSubtract: return VK_BLEND_OP_REVERSE_SUBTRACT;
+ case BlendOp::Min: return VK_BLEND_OP_MIN;
+ case BlendOp::Max: return VK_BLEND_OP_MAX;
+ default: assert(!"Unsupported blend op"); return VK_BLEND_OP_ADD;
}
}
-VkPrimitiveTopology VulkanUtil::translatePrimitiveTypeToListTopology(
- PrimitiveType primitiveType)
+VkPrimitiveTopology VulkanUtil::translatePrimitiveTypeToListTopology(PrimitiveType primitiveType)
{
switch (primitiveType)
{
- case PrimitiveType::Point:
- return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
- case PrimitiveType::Line:
- return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
- case PrimitiveType::Triangle:
- return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
- case PrimitiveType::Patch:
- return VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
- default:
- assert(!"unknown topology type.");
- return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
+ case PrimitiveType::Point: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
+ case PrimitiveType::Line: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
+ case PrimitiveType::Triangle: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
+ case PrimitiveType::Patch: return VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
+ default: assert(!"unknown topology type."); return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
}
}
@@ -395,24 +303,15 @@ VkStencilOp VulkanUtil::translateStencilOp(StencilOp op)
{
switch (op)
{
- case StencilOp::DecrementSaturate:
- return VK_STENCIL_OP_DECREMENT_AND_CLAMP;
- case StencilOp::DecrementWrap:
- return VK_STENCIL_OP_DECREMENT_AND_WRAP;
- case StencilOp::IncrementSaturate:
- return VK_STENCIL_OP_INCREMENT_AND_CLAMP;
- case StencilOp::IncrementWrap:
- return VK_STENCIL_OP_INCREMENT_AND_WRAP;
- case StencilOp::Invert:
- return VK_STENCIL_OP_INVERT;
- case StencilOp::Keep:
- return VK_STENCIL_OP_KEEP;
- case StencilOp::Replace:
- return VK_STENCIL_OP_REPLACE;
- case StencilOp::Zero:
- return VK_STENCIL_OP_ZERO;
- default:
- return VK_STENCIL_OP_KEEP;
+ case StencilOp::DecrementSaturate: return VK_STENCIL_OP_DECREMENT_AND_CLAMP;
+ case StencilOp::DecrementWrap: return VK_STENCIL_OP_DECREMENT_AND_WRAP;
+ case StencilOp::IncrementSaturate: return VK_STENCIL_OP_INCREMENT_AND_CLAMP;
+ case StencilOp::IncrementWrap: return VK_STENCIL_OP_INCREMENT_AND_WRAP;
+ case StencilOp::Invert: return VK_STENCIL_OP_INVERT;
+ case StencilOp::Keep: return VK_STENCIL_OP_KEEP;
+ case StencilOp::Replace: return VK_STENCIL_OP_REPLACE;
+ case StencilOp::Zero: return VK_STENCIL_OP_ZERO;
+ default: return VK_STENCIL_OP_KEEP;
}
}
@@ -420,12 +319,10 @@ VkFilter VulkanUtil::translateFilterMode(TextureFilteringMode mode)
{
switch (mode)
{
- default:
- return VkFilter(0);
+ default: return VkFilter(0);
-#define CASE(SRC, DST) \
- case TextureFilteringMode::SRC: \
- return VK_FILTER_##DST
+#define CASE(SRC, DST) \
+ case TextureFilteringMode::SRC: return VK_FILTER_##DST
CASE(Point, NEAREST);
CASE(Linear, LINEAR);
@@ -438,12 +335,10 @@ VkSamplerMipmapMode VulkanUtil::translateMipFilterMode(TextureFilteringMode mode
{
switch (mode)
{
- default:
- return VkSamplerMipmapMode(0);
+ default: return VkSamplerMipmapMode(0);
-#define CASE(SRC, DST) \
- case TextureFilteringMode::SRC: \
- return VK_SAMPLER_MIPMAP_MODE_##DST
+#define CASE(SRC, DST) \
+ case TextureFilteringMode::SRC: return VK_SAMPLER_MIPMAP_MODE_##DST
CASE(Point, NEAREST);
CASE(Linear, LINEAR);
@@ -456,12 +351,10 @@ VkSamplerAddressMode VulkanUtil::translateAddressingMode(TextureAddressingMode m
{
switch (mode)
{
- default:
- return VkSamplerAddressMode(0);
+ default: return VkSamplerAddressMode(0);
-#define CASE(SRC, DST) \
- case TextureAddressingMode::SRC: \
- return VK_SAMPLER_ADDRESS_MODE_##DST
+#define CASE(SRC, DST) \
+ case TextureAddressingMode::SRC: return VK_SAMPLER_ADDRESS_MODE_##DST
CASE(Wrap, REPEAT);
CASE(ClampToEdge, CLAMP_TO_EDGE);
@@ -481,9 +374,8 @@ VkCompareOp VulkanUtil::translateComparisonFunc(ComparisonFunc func)
// TODO: need to report failures
return VK_COMPARE_OP_ALWAYS;
-#define CASE(FROM, TO) \
- case ComparisonFunc::FROM: \
- return VK_COMPARE_OP_##TO
+#define CASE(FROM, TO) \
+ case ComparisonFunc::FROM: return VK_COMPARE_OP_##TO
CASE(Never, NEVER);
CASE(Less, LESS);
@@ -514,16 +406,13 @@ VkSamplerReductionMode VulkanUtil::translateReductionOp(TextureReductionOp op)
{
switch (op)
{
- case gfx::TextureReductionOp::Minimum:
- return VK_SAMPLER_REDUCTION_MODE_MIN;
- case gfx::TextureReductionOp::Maximum:
- return VK_SAMPLER_REDUCTION_MODE_MAX;
- default:
- return VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE;
+ case gfx::TextureReductionOp::Minimum: return VK_SAMPLER_REDUCTION_MODE_MIN;
+ case gfx::TextureReductionOp::Maximum: return VK_SAMPLER_REDUCTION_MODE_MAX;
+ default: return VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE;
}
}
-/* static */Slang::Result VulkanUtil::handleFail(VkResult res)
+/* static */ Slang::Result VulkanUtil::handleFail(VkResult res)
{
if (res != VK_SUCCESS)
{
@@ -532,29 +421,22 @@ VkSamplerReductionMode VulkanUtil::translateReductionOp(TextureReductionOp op)
return toSlangResult(res);
}
-/* static */void VulkanUtil::checkFail(VkResult res)
+/* static */ void VulkanUtil::checkFail(VkResult res)
{
assert(res != VK_SUCCESS);
assert(!"Vulkan check failed");
-
}
-/* static */VkPrimitiveTopology VulkanUtil::getVkPrimitiveTopology(PrimitiveTopology topology)
+/* static */ VkPrimitiveTopology VulkanUtil::getVkPrimitiveTopology(PrimitiveTopology topology)
{
switch (topology)
{
- case PrimitiveTopology::LineList:
- return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
- case PrimitiveTopology::LineStrip:
- return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
- case PrimitiveTopology::TriangleList:
- return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
- case PrimitiveTopology::TriangleStrip:
- return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
- case PrimitiveTopology::PointList:
- return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
- default:
- break;
+ case PrimitiveTopology::LineList: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
+ case PrimitiveTopology::LineStrip: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
+ case PrimitiveTopology::TriangleList: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
+ case PrimitiveTopology::TriangleStrip: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
+ case PrimitiveTopology::PointList: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
+ default: break;
}
assert(!"Unknown topology");
return VK_PRIMITIVE_TOPOLOGY_MAX_ENUM;
@@ -564,32 +446,20 @@ VkImageLayout VulkanUtil::mapResourceStateToLayout(ResourceState state)
{
switch (state)
{
- case ResourceState::Undefined:
- return VK_IMAGE_LAYOUT_UNDEFINED;
+ case ResourceState::Undefined: return VK_IMAGE_LAYOUT_UNDEFINED;
case ResourceState::ShaderResource:
case ResourceState::PixelShaderResource:
- case ResourceState::NonPixelShaderResource:
- return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
- case ResourceState::UnorderedAccess:
- return VK_IMAGE_LAYOUT_GENERAL;
- case ResourceState::RenderTarget:
- return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
- case ResourceState::DepthRead:
- return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
- case ResourceState::DepthWrite:
- return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
- case ResourceState::Present:
- return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
- case ResourceState::CopySource:
- return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
- case ResourceState::CopyDestination:
- return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
- case ResourceState::ResolveSource:
- return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
- case ResourceState::ResolveDestination:
- return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
- default:
- return VK_IMAGE_LAYOUT_UNDEFINED;
+ case ResourceState::NonPixelShaderResource: return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+ case ResourceState::UnorderedAccess: return VK_IMAGE_LAYOUT_GENERAL;
+ case ResourceState::RenderTarget: return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ case ResourceState::DepthRead: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
+ case ResourceState::DepthWrite: return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+ case ResourceState::Present: return VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+ case ResourceState::CopySource: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
+ case ResourceState::CopyDestination: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ case ResourceState::ResolveSource: return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
+ case ResourceState::ResolveDestination: return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ default: return VK_IMAGE_LAYOUT_UNDEFINED;
}
}
@@ -676,12 +546,8 @@ Result AccelerationStructureBuildGeometryInfoBuilder::build(
vkGeomData.triangles.maxVertex = geomDesc.content.triangles.vertexCount - 1;
switch (geomDesc.content.triangles.indexFormat)
{
- case Format::R32_UINT:
- vkGeomData.triangles.indexType = VK_INDEX_TYPE_UINT32;
- break;
- case Format::R16_UINT:
- vkGeomData.triangles.indexType = VK_INDEX_TYPE_UINT16;
- break;
+ case Format::R32_UINT: vkGeomData.triangles.indexType = VK_INDEX_TYPE_UINT32; break;
+ case Format::R16_UINT: vkGeomData.triangles.indexType = VK_INDEX_TYPE_UINT16; break;
case Format::Unknown:
vkGeomData.triangles.indexType = VK_INDEX_TYPE_NONE_KHR;
break;
diff --git a/tools/gfx/vulkan/vk-util.h b/tools/gfx/vulkan/vk-util.h
index ade62ba59..a22c76fc3 100644
--- a/tools/gfx/vulkan/vk-util.h
+++ b/tools/gfx/vulkan/vk-util.h
@@ -2,44 +2,69 @@
#pragma once
#include "core/slang-basic.h"
-#include "vk-api.h"
#include "slang-gfx.h"
+#include "vk-api.h"
// Macros to make testing vulkan return codes simpler
-/// SLANG_VK_RETURN_ON_FAIL can be used in a similar way to SLANG_RETURN_ON_FAIL macro, except it will turn a vulkan failure into Slang::Result in the process
-/// Calls handleFail which on debug builds asserts
-#define SLANG_VK_RETURN_ON_FAIL(x) { VkResult _res = x; if (_res != VK_SUCCESS) { return VulkanUtil::handleFail(_res); } }
+/// SLANG_VK_RETURN_ON_FAIL can be used in a similar way to SLANG_RETURN_ON_FAIL macro, except it
+/// will turn a vulkan failure into Slang::Result in the process Calls handleFail which on debug
+/// builds asserts
+#define SLANG_VK_RETURN_ON_FAIL(x) \
+ { \
+ VkResult _res = x; \
+ if (_res != VK_SUCCESS) \
+ { \
+ return VulkanUtil::handleFail(_res); \
+ } \
+ }
-#define SLANG_VK_RETURN_NULL_ON_FAIL(x) { VkResult _res = x; if (_res != VK_SUCCESS) { VulkanUtil::handleFail(_res); return nullptr; } }
+#define SLANG_VK_RETURN_NULL_ON_FAIL(x) \
+ { \
+ VkResult _res = x; \
+ if (_res != VK_SUCCESS) \
+ { \
+ VulkanUtil::handleFail(_res); \
+ return nullptr; \
+ } \
+ }
-/// Is similar to SLANG_VK_RETURN_ON_FAIL, but does not return. Will call checkFail on failure - which asserts on debug builds.
-#define SLANG_VK_CHECK(x) { VkResult _res = x; if (_res != VK_SUCCESS) { VulkanUtil::checkFail(_res); } }
+/// Is similar to SLANG_VK_RETURN_ON_FAIL, but does not return. Will call checkFail on failure -
+/// which asserts on debug builds.
+#define SLANG_VK_CHECK(x) \
+ { \
+ VkResult _res = x; \
+ if (_res != VK_SUCCESS) \
+ { \
+ VulkanUtil::checkFail(_res); \
+ } \
+ }
-namespace gfx {
+namespace gfx
+{
// Utility functions for Vulkan
struct VulkanUtil
{
- /// Get the equivalent VkFormat from the format
- /// Returns VK_FORMAT_UNDEFINED if a match is not found
+ /// Get the equivalent VkFormat from the format
+ /// Returns VK_FORMAT_UNDEFINED if a match is not found
static VkFormat getVkFormat(Format format);
static VkImageAspectFlags getAspectMask(TextureAspect aspect, VkFormat format);
- /// Called by SLANG_VK_RETURN_FAIL if a res is a failure.
- /// On debug builds this will cause an assertion on failure.
+ /// Called by SLANG_VK_RETURN_FAIL if a res is a failure.
+ /// On debug builds this will cause an assertion on failure.
static Slang::Result handleFail(VkResult res);
- /// Called when a failure has occurred with SLANG_VK_CHECK - will typically assert.
+ /// Called when a failure has occurred with SLANG_VK_CHECK - will typically assert.
static void checkFail(VkResult res);
- /// Get the VkPrimitiveTopology for the given topology.
- /// Returns VK_PRIMITIVE_TOPOLOGY_MAX_ENUM on failure
+ /// Get the VkPrimitiveTopology for the given topology.
+ /// Returns VK_PRIMITIVE_TOPOLOGY_MAX_ENUM on failure
static VkPrimitiveTopology getVkPrimitiveTopology(PrimitiveTopology topology);
static VkImageLayout mapResourceStateToLayout(ResourceState state);
- /// Returns Slang::Result equivalent of a VkResult
+ /// Returns Slang::Result equivalent of a VkResult
static Slang::Result toSlangResult(VkResult res);
static VkShaderStageFlags getShaderStage(SlangStage stage);
@@ -47,7 +72,10 @@ struct VulkanUtil
static VkImageLayout getImageLayoutFromState(ResourceState state);
/// Calculate size taking into account alignment. Alignment must be a power of 2
- static UInt calcAligned(UInt size, UInt alignment) { return (size + alignment - 1) & ~(alignment - 1); }
+ static UInt calcAligned(UInt size, UInt alignment)
+ {
+ return (size + alignment - 1) & ~(alignment - 1);
+ }
static inline bool isDepthFormat(VkFormat format)
{
@@ -57,8 +85,7 @@ struct VulkanUtil
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_X8_D24_UNORM_PACK32:
case VK_FORMAT_D32_SFLOAT:
- case VK_FORMAT_D32_SFLOAT_S8_UINT:
- return true;
+ case VK_FORMAT_D32_SFLOAT_S8_UINT: return true;
}
return false;
}
@@ -69,8 +96,7 @@ struct VulkanUtil
{
case VK_FORMAT_S8_UINT:
case VK_FORMAT_D24_UNORM_S8_UINT:
- case VK_FORMAT_D32_SFLOAT_S8_UINT:
- return true;
+ case VK_FORMAT_D32_SFLOAT_S8_UINT: return true;
}
return false;
}
@@ -87,11 +113,10 @@ struct VulkanUtil
static VkBlendOp translateBlendOp(BlendOp op);
- static VkPrimitiveTopology translatePrimitiveTypeToListTopology(
- PrimitiveType primitiveType);
+ static VkPrimitiveTopology translatePrimitiveTypeToListTopology(PrimitiveType primitiveType);
static VkStencilOp translateStencilOp(StencilOp op);
-
+
static VkFilter translateFilterMode(TextureFilteringMode mode);
static VkSamplerMipmapMode translateMipFilterMode(TextureFilteringMode mode);
@@ -103,7 +128,6 @@ struct VulkanUtil
static VkStencilOpState translateStencilState(DepthStencilOpDesc desc);
static VkSamplerReductionMode translateReductionOp(TextureReductionOp op);
-
};
struct AccelerationStructureBuildGeometryInfoBuilder
@@ -124,4 +148,4 @@ private:
};
-} // renderer_test
+} // namespace gfx