diff options
| author | Yong He <yonghe@outlook.com> | 2022-10-05 19:35:47 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-05 19:35:47 -0700 |
| commit | cf34d2830a3103b2b47a4140d27d054b797705f2 (patch) | |
| tree | 3620bc07e53edc6c959777d069b1931aa28691e4 /tools | |
| parent | 364e43264b9f69957ddaed8890392d82fb25c822 (diff) | |
Various gfx fixes. (#2434)
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/gfx/d3d12/d3d12-command-encoder.cpp | 1 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-device.cpp | 37 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-helper-functions.cpp | 31 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-helper-functions.h | 8 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-shader-object.cpp | 28 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-shader-object.cpp | 24 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-shader-object.h | 2 | ||||
| -rw-r--r-- | tools/gfx/vulkan/vk-device.cpp | 3 |
8 files changed, 111 insertions, 23 deletions
diff --git a/tools/gfx/d3d12/d3d12-command-encoder.cpp b/tools/gfx/d3d12/d3d12-command-encoder.cpp index 59498856c..a9245bebc 100644 --- a/tools/gfx/d3d12/d3d12-command-encoder.cpp +++ b/tools/gfx/d3d12/d3d12-command-encoder.cpp @@ -353,6 +353,7 @@ void ResourceCommandEncoderImpl::clearResourceView( IResourceView* view, ClearValue* clearValue, ClearResourceViewFlags::Enum flags) { auto viewImpl = static_cast<ResourceViewImpl*>(view); + m_commandBuffer->bindDescriptorHeaps(); switch (view->getViewDesc()->type) { case IResourceView::Type::RenderTarget: diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp index 37b26e78c..c1db6c6ba 100644 --- a/tools/gfx/d3d12/d3d12-device.cpp +++ b/tools/gfx/d3d12/d3d12-device.cpp @@ -440,30 +440,31 @@ Result DeviceImpl::initialize(const Desc& desc) (PFN_EndEventOnCommandList)GetProcAddress(pixModule, "PIXEndEventOnCommandList"); } -#if ENABLE_DEBUG_LAYER - m_D3D12GetDebugInterface = - (PFN_D3D12_GET_DEBUG_INTERFACE)loadProc(d3dModule, "D3D12GetDebugInterface"); - if (m_D3D12GetDebugInterface) + if (ENABLE_DEBUG_LAYER || isGfxDebugLayerEnabled()) { - if (SLANG_SUCCEEDED(m_D3D12GetDebugInterface(IID_PPV_ARGS(m_dxDebug.writeRef())))) + m_D3D12GetDebugInterface = + (PFN_D3D12_GET_DEBUG_INTERFACE)loadProc(d3dModule, "D3D12GetDebugInterface"); + if (m_D3D12GetDebugInterface) { -# 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 - // added directly to the shader. However, it can slow things down a lot, especially for applications with numerous - // PSOs.Time to see the first render frame may take several minutes. - // [INITIALIZATION MESSAGE #1016: CREATEDEVICE_DEBUG_LAYER_STARTUP_OPTIONS] - - ComPtr<ID3D12Debug1> debug1; - if (SLANG_SUCCEEDED(m_dxDebug->QueryInterface(debug1.writeRef()))) + if (SLANG_SUCCEEDED(m_D3D12GetDebugInterface(IID_PPV_ARGS(m_dxDebug.writeRef())))) { - debug1->SetEnableGPUBasedValidation(true); - } +# 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 + // added directly to the shader. However, it can slow things down a lot, especially for applications with numerous + // PSOs.Time to see the first render frame may take several minutes. + // [INITIALIZATION MESSAGE #1016: CREATEDEVICE_DEBUG_LAYER_STARTUP_OPTIONS] + + ComPtr<ID3D12Debug1> debug1; + if (SLANG_SUCCEEDED(m_dxDebug->QueryInterface(debug1.writeRef()))) + { + debug1->SetEnableGPUBasedValidation(true); + } # endif + } } } -#endif m_D3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)loadProc(d3dModule, "D3D12CreateDevice"); if (!m_D3D12CreateDevice) diff --git a/tools/gfx/d3d12/d3d12-helper-functions.cpp b/tools/gfx/d3d12/d3d12-helper-functions.cpp index ee937ed4a..5f9102d0c 100644 --- a/tools/gfx/d3d12/d3d12-helper-functions.cpp +++ b/tools/gfx/d3d12/d3d12-helper-functions.cpp @@ -533,6 +533,37 @@ Result createNullDescriptor( d3dDevice->CreateShaderResourceView(nullptr, &srvDesc, destDescriptor); } 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; + } + d3dDevice->CreateUnorderedAccessView(nullptr, nullptr, &uavDesc, destDescriptor); + } + break; default: break; } diff --git a/tools/gfx/d3d12/d3d12-helper-functions.h b/tools/gfx/d3d12/d3d12-helper-functions.h index 4882e0034..97f75a654 100644 --- a/tools/gfx/d3d12/d3d12-helper-functions.h +++ b/tools/gfx/d3d12/d3d12-helper-functions.h @@ -5,6 +5,7 @@ #include "d3d12-base.h" #include "d3d12-shader-object-layout.h" #include "d3d12-submitter.h" +#include "../../../source/core/slang-short-list.h" #ifndef __ID3D12GraphicsCommandList1_FWD_DEFINED__ // If can't find a definition of CommandList1, just use an empty definition @@ -19,6 +20,12 @@ using namespace Slang; namespace d3d12 { +struct PendingDescriptorTableBinding +{ + uint32_t rootIndex; + D3D12_GPU_DESCRIPTOR_HANDLE handle; +}; + /// Contextual data and operations required when binding shader objects to the pipeline state struct BindingContext { @@ -28,6 +35,7 @@ struct BindingContext DeviceImpl* device; D3D12_DESCRIPTOR_HEAP_TYPE outOfMemoryHeap; // The type of descriptor heap that is OOM during binding. + ShortList<PendingDescriptorTableBinding>* pendingTableBindings; }; bool isSupportedNVAPIOp(ID3D12Device* dev, uint32_t op); diff --git a/tools/gfx/d3d12/d3d12-shader-object.cpp b/tools/gfx/d3d12/d3d12-shader-object.cpp index e5875f55c..fd92dbfa0 100644 --- a/tools/gfx/d3d12/d3d12-shader-object.cpp +++ b/tools/gfx/d3d12/d3d12-shader-object.cpp @@ -447,6 +447,14 @@ void ShaderObjectImpl::updateSubObjectsRecursive() } } +static void bindPendingTables(BindingContext* context) +{ + for (auto& binding : *context->pendingTableBindings) + { + context->submitter->setRootDescriptorTable(binding.rootIndex, binding.handle); + } +} + /// Prepare to bind this object as a parameter block. /// /// This involves allocating and binding any descriptor tables necessary @@ -504,7 +512,7 @@ Result ShaderObjectImpl::prepareToBindAsParameterBlock( // root parameter. // auto tableRootParamIndex = rootParamIndex++; - submitter->setRootDescriptorTable(tableRootParamIndex, table.getGpuHandle()); + context->pendingTableBindings->add(PendingDescriptorTableBinding{ tableRootParamIndex, table.getGpuHandle() }); } if (auto descriptorCount = specializedLayout->getTotalSamplerDescriptorCount()) { @@ -527,7 +535,7 @@ Result ShaderObjectImpl::prepareToBindAsParameterBlock( // root parameter. // auto tableRootParamIndex = rootParamIndex++; - submitter->setRootDescriptorTable(tableRootParamIndex, table.getGpuHandle()); + context->pendingTableBindings->add(PendingDescriptorTableBinding{ tableRootParamIndex, table.getGpuHandle() }); } return SLANG_OK; @@ -602,6 +610,10 @@ Result ShaderObjectImpl::bindAsParameterBlock( // descriptor table) to represent its values. // BindingOffset subOffset = offset; + ShortList<PendingDescriptorTableBinding> pendingTableBindings; + auto oldPendingTableBindings = context->pendingTableBindings; + context->pendingTableBindings = &pendingTableBindings; + SLANG_RETURN_ON_FAIL(prepareToBindAsParameterBlock( context, /* inout */ subOffset, specializedLayout, m_cachedGPUDescriptorSet)); @@ -611,6 +623,9 @@ Result ShaderObjectImpl::bindAsParameterBlock( SLANG_RETURN_ON_FAIL( bindAsConstantBuffer(context, m_cachedGPUDescriptorSet, subOffset, specializedLayout)); + bindPendingTables(context); + context->pendingTableBindings = oldPendingTableBindings; + m_cachedGPUDescriptorSetVersion = m_version; return SLANG_OK; } @@ -1116,8 +1131,12 @@ Result RootShaderObjectImpl::bindAsRoot( // need to bind the entry points into the same descriptor set that is // being used for the root object. - BindingOffset rootOffset; + ShortList<PendingDescriptorTableBinding> pendingTableBindings; + auto oldPendingTableBindings = context->pendingTableBindings; + context->pendingTableBindings = &pendingTableBindings; + BindingOffset rootOffset; + // Bind all root parameters first. Super::bindRootArguments(context, rootOffset.rootParam); @@ -1143,6 +1162,9 @@ Result RootShaderObjectImpl::bindAsRoot( context, descriptorSet, entryPointOffset, entryPointInfo.layout)); } + bindPendingTables(context); + context->pendingTableBindings = oldPendingTableBindings; + return SLANG_OK; } diff --git a/tools/gfx/debug-layer/debug-shader-object.cpp b/tools/gfx/debug-layer/debug-shader-object.cpp index 036e743ec..d078ba583 100644 --- a/tools/gfx/debug-layer/debug-shader-object.cpp +++ b/tools/gfx/debug-layer/debug-shader-object.cpp @@ -19,6 +19,25 @@ ShaderObjectContainerType DebugShaderObject::getContainerType() return baseObject->getContainerType(); } +void DebugShaderObject::checkCompleteness() +{ + auto layout = baseObject->getElementTypeLayout(); + for (Index i = 0; i < layout->getBindingRangeCount(); i++) + { + if (layout->getBindingRangeBindingCount(i) != 0) + { + if (!m_initializedBindingRanges.Contains(i)) + { + auto var = layout->getBindingRangeLeafVariable(i); + GFX_DIAGNOSE_ERROR_FORMAT( + "shader parameter '%s' is not initialized in the shader object of type '%s'.", + var->getName(), + m_slangType->getName()); + } + } + } +} + slang::TypeLayoutReflection* DebugShaderObject::getElementTypeLayout() { SLANG_GFX_API_FUNC; @@ -88,6 +107,8 @@ Result DebugShaderObject::setObject(ShaderOffset const& offset, IShaderObject* o SLANG_GFX_API_FUNC; auto objectImpl = getDebugObj(object); m_objects[ShaderOffsetKey{offset}] = objectImpl; + m_initializedBindingRanges.Add(offset.bindingRangeIndex); + objectImpl->checkCompleteness(); return baseObject->setObject(offset, getInnerObj(object)); } @@ -96,6 +117,7 @@ Result DebugShaderObject::setResource(ShaderOffset const& offset, IResourceView* SLANG_GFX_API_FUNC; auto viewImpl = getDebugObj(resourceView); m_resources[ShaderOffsetKey{offset}] = viewImpl; + m_initializedBindingRanges.Add(offset.bindingRangeIndex); return baseObject->setResource(offset, getInnerObj(resourceView)); } @@ -104,6 +126,7 @@ Result DebugShaderObject::setSampler(ShaderOffset const& offset, ISamplerState* SLANG_GFX_API_FUNC; auto samplerImpl = getDebugObj(sampler); m_samplers[ShaderOffsetKey{offset}] = samplerImpl; + m_initializedBindingRanges.Add(offset.bindingRangeIndex); return baseObject->setSampler(offset, getInnerObj(sampler)); } @@ -117,6 +140,7 @@ Result DebugShaderObject::setCombinedTextureSampler( m_samplers[ShaderOffsetKey{offset}] = samplerImpl; auto viewImpl = getDebugObj(textureView); m_resources[ShaderOffsetKey{offset}] = viewImpl; + m_initializedBindingRanges.Add(offset.bindingRangeIndex); return baseObject->setCombinedTextureSampler( offset, getInnerObj(viewImpl), getInnerObj(sampler)); } diff --git a/tools/gfx/debug-layer/debug-shader-object.h b/tools/gfx/debug-layer/debug-shader-object.h index 8007e653a..9f368a2c1 100644 --- a/tools/gfx/debug-layer/debug-shader-object.h +++ b/tools/gfx/debug-layer/debug-shader-object.h @@ -32,6 +32,7 @@ class DebugShaderObject : public DebugObject<IShaderObject> { public: SLANG_COM_OBJECT_IUNKNOWN_ALL; + void checkCompleteness(); public: IShaderObject* getInterface(const Slang::Guid& guid); @@ -83,6 +84,7 @@ public: Slang::Dictionary<ShaderOffsetKey, Slang::RefPtr<DebugShaderObject>> m_objects; Slang::Dictionary<ShaderOffsetKey, Slang::RefPtr<DebugResourceView>> m_resources; Slang::Dictionary<ShaderOffsetKey, Slang::RefPtr<DebugSamplerState>> m_samplers; + Slang::HashSet<SlangInt> m_initializedBindingRanges; }; class DebugRootShaderObject : public DebugShaderObject diff --git a/tools/gfx/vulkan/vk-device.cpp b/tools/gfx/vulkan/vk-device.cpp index 462c1b44c..b5a681de7 100644 --- a/tools/gfx/vulkan/vk-device.cpp +++ b/tools/gfx/vulkan/vk-device.cpp @@ -158,9 +158,8 @@ Result DeviceImpl::initVulkanInstanceAndDevice( #elif defined(SLANG_ENABLE_XLIB) instanceExtensions.add(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); #endif -#if ENABLE_VALIDATION_LAYER + if (ENABLE_VALIDATION_LAYER || isGfxDebugLayerEnabled()) instanceExtensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); -#endif } VkInstanceCreateInfo instanceCreateInfo = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO }; |
