summaryrefslogtreecommitdiffstats
path: root/tools/gfx
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-01-14 13:08:46 -0800
committerGitHub <noreply@github.com>2022-01-14 13:08:46 -0800
commitb2f4cb118ef15cbf522be0335e4084ac6db57672 (patch)
tree37c2d6c3519ef7fc3d60142a4a31cbe16708e0bc /tools/gfx
parentd3f904cbfa1568366bc8c8d231a57a03d47ddc98 (diff)
Various fixes to GFX, nested parameter block test for d3d12. (#2081)
* Various fixes. * Add nested parameter block test. * Remove slang-llvm licence info * Ingore slang-llvm/ directory. * Fixup. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/gfx')
-rw-r--r--tools/gfx/cpu/render-cpu.cpp6
-rw-r--r--tools/gfx/cuda/render-cuda.cpp8
-rw-r--r--tools/gfx/d3d11/render-d3d11.cpp17
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp205
-rw-r--r--tools/gfx/debug-layer.cpp5
-rw-r--r--tools/gfx/debug-layer.h2
-rw-r--r--tools/gfx/open-gl/render-gl.cpp11
-rw-r--r--tools/gfx/vulkan/render-vk.cpp11
8 files changed, 198 insertions, 67 deletions
diff --git a/tools/gfx/cpu/render-cpu.cpp b/tools/gfx/cpu/render-cpu.cpp
index 723dba10e..38b72e28b 100644
--- a/tools/gfx/cpu/render-cpu.cpp
+++ b/tools/gfx/cpu/render-cpu.cpp
@@ -1260,8 +1260,10 @@ public:
return SLANG_OK;
}
- virtual SLANG_NO_THROW Result SLANG_MCALL
- createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL createProgram(
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnosticBlob) override
{
RefPtr<CPUShaderProgram> cpuProgram = new CPUShaderProgram();
diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp
index 46f5be9cb..2c3f1eb56 100644
--- a/tools/gfx/cuda/render-cuda.cpp
+++ b/tools/gfx/cuda/render-cuda.cpp
@@ -2160,8 +2160,10 @@ public:
return SLANG_OK;
}
- virtual SLANG_NO_THROW Result SLANG_MCALL
- createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram) override
+ virtual SLANG_NO_THROW Result SLANG_MCALL createProgram(
+ const IShaderProgram::Desc& desc,
+ IShaderProgram** outProgram,
+ ISlangBlob** outDiagnosticBlob) override
{
// If this is a specializable program, we just keep a reference to the slang program and
// don't actually create any kernels. This program will be specialized later when we know
@@ -2186,6 +2188,8 @@ public:
compileResult == SLANG_OK ? DebugMessageType::Warning : DebugMessageType::Error,
DebugMessageSource::Slang,
(char*)diagnostics->getBufferPointer());
+ if (outDiagnosticBlob)
+ returnComPtr(outDiagnosticBlob, diagnostics);
}
SLANG_RETURN_ON_FAIL(compileResult);
diff --git a/tools/gfx/d3d11/render-d3d11.cpp b/tools/gfx/d3d11/render-d3d11.cpp
index 530b67055..2e3963c30 100644
--- a/tools/gfx/d3d11/render-d3d11.cpp
+++ b/tools/gfx/d3d11/render-d3d11.cpp
@@ -113,8 +113,10 @@ public:
override;
virtual void bindRootShaderObject(IShaderObject* shaderObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram) 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;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
@@ -3114,7 +3116,7 @@ Result D3D11Device::createInputLayout(IInputLayout::Desc const& desc, IInputLayo
auto inputElementCount = desc.inputElementCount;
auto inputElementsIn = desc.inputElements;
- for (UInt ii = 0; ii < inputElementCount; ++ii)
+ for (Int ii = 0; ii < inputElementCount; ++ii)
{
auto vertexStreamIndex = inputElementsIn[ii].bufferSlotIndex;
auto& vertexStream = desc.vertexStreams[vertexStreamIndex];
@@ -3122,11 +3124,11 @@ Result D3D11Device::createInputLayout(IInputLayout::Desc const& desc, IInputLayo
inputElements[ii].SemanticName = inputElementsIn[ii].semanticName;
inputElements[ii].SemanticIndex = (UINT)inputElementsIn[ii].semanticIndex;
inputElements[ii].Format = D3DUtil::getMapFormat(inputElementsIn[ii].format);
- inputElements[ii].InputSlot = vertexStreamIndex;
+ 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].InstanceDataStepRate = vertexStream.instanceDataStepRate;
+ inputElements[ii].InstanceDataStepRate = (UINT)vertexStream.instanceDataStepRate;
if (ii != 0)
{
@@ -3478,7 +3480,8 @@ void D3D11Device::drawIndexedInstanced(
startInstanceLocation);
}
-Result D3D11Device::createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram)
+Result D3D11Device::createProgram(
+ const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
{
SLANG_ASSERT(desc.slangProgram);
@@ -3520,6 +3523,8 @@ Result D3D11Device::createProgram(const IShaderProgram::Desc& desc, IShaderProgr
compileResult == SLANG_OK ? DebugMessageType::Warning : DebugMessageType::Error,
DebugMessageSource::Slang,
(char*)diagnostics->getBufferPointer());
+ if (outDiagnosticBlob)
+ returnComPtr(outDiagnosticBlob, diagnostics);
}
SLANG_RETURN_ON_FAIL(compileResult);
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index 494dfd0f0..c30389ec2 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -71,6 +71,9 @@ public:
// Renderer implementation
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;
+
+ virtual SLANG_NO_THROW Result SLANG_MCALL
createCommandQueue(const ICommandQueue::Desc& desc, ICommandQueue** outQueue) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createTransientResourceHeap(
const ITransientResourceHeap::Desc& desc,
@@ -134,7 +137,7 @@ public:
createMutableRootShaderObject(IShaderProgram* program, IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
- createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram) override;
+ createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnostics) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
const GraphicsPipelineStateDesc& desc, IPipelineState** outState) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
@@ -1690,7 +1693,8 @@ public:
Result addDescriptorRange(
slang::TypeLayoutReflection* typeLayout,
Index physicalDescriptorSetIndex,
- BindingRegisterOffset const& offset,
+ BindingRegisterOffset const& containerOffset,
+ BindingRegisterOffset const& elementOffset,
Index logicalDescriptorSetIndex,
Index descriptorRangeIndex)
{
@@ -1705,8 +1709,8 @@ public:
return addDescriptorRange(
physicalDescriptorSetIndex,
rangeType,
- (UINT)index + offset[rangeType],
- (UINT)space,
+ (UINT)index + elementOffset[rangeType],
+ (UINT)space + containerOffset.spaceOffset,
(UINT)count);
}
@@ -1726,7 +1730,8 @@ public:
void addBindingRange(
slang::TypeLayoutReflection* typeLayout,
Index physicalDescriptorSetIndex,
- BindingRegisterOffset const& offset,
+ BindingRegisterOffset const& containerOffset,
+ BindingRegisterOffset const& elementOffset,
Index bindingRangeIndex)
{
auto logicalDescriptorSetIndex = typeLayout->getBindingRangeDescriptorSetIndex(bindingRangeIndex);
@@ -1740,7 +1745,13 @@ public:
// want to silently skip any ranges that represent kinds of bindings that
// don't actually exist in D3D12.
//
- addDescriptorRange(typeLayout, physicalDescriptorSetIndex, offset, logicalDescriptorSetIndex, descriptorRangeIndex);
+ addDescriptorRange(
+ typeLayout,
+ physicalDescriptorSetIndex,
+ containerOffset,
+ elementOffset,
+ logicalDescriptorSetIndex,
+ descriptorRangeIndex);
}
}
@@ -1749,7 +1760,7 @@ public:
Index physicalDescriptorSetIndex)
{
BindingRegisterOffsetPair offset(varLayout);
- addAsValue(varLayout->getTypeLayout(), physicalDescriptorSetIndex, offset);
+ addAsValue(varLayout->getTypeLayout(), physicalDescriptorSetIndex, offset, offset);
}
@@ -1783,13 +1794,14 @@ public:
1);
}
- addAsValue(typeLayout, physicalDescriptorSetIndex, elementOffset);
+ addAsValue(typeLayout, physicalDescriptorSetIndex, containerOffset, elementOffset);
}
void addAsValue(
slang::TypeLayoutReflection* typeLayout,
Index physicalDescriptorSetIndex,
- BindingRegisterOffsetPair const& offset)
+ BindingRegisterOffsetPair const& containerOffset,
+ BindingRegisterOffsetPair const& elementOffset)
{
// Our first task is to add the binding ranges for stuff that is
// directly contained in `typeLayout` rather than via sub-objects.
@@ -1819,7 +1831,12 @@ public:
// For binding ranges that don't represent sub-objects, we will add
// all of the descriptor ranges they encompass to the root signature.
//
- addBindingRange(typeLayout, physicalDescriptorSetIndex, offset.primary, bindingRangeIndex);
+ addBindingRange(
+ typeLayout,
+ physicalDescriptorSetIndex,
+ containerOffset.primary,
+ elementOffset.primary,
+ bindingRangeIndex);
}
// Next we need to recursively include everything bound via sub-objects
@@ -1831,8 +1848,12 @@ public:
auto subObjectTypeLayout = typeLayout->getBindingRangeLeafTypeLayout(bindingRangeIndex);
- BindingRegisterOffsetPair subObjectRangeOffset = offset;
- subObjectRangeOffset += BindingRegisterOffsetPair(typeLayout->getSubObjectRangeOffset(subObjectRangeIndex));
+ BindingRegisterOffsetPair subObjectRangeContainerOffset = containerOffset;
+ subObjectRangeContainerOffset += BindingRegisterOffsetPair(
+ typeLayout->getSubObjectRangeOffset(subObjectRangeIndex));
+ BindingRegisterOffsetPair subObjectRangeElementOffset = elementOffset;
+ subObjectRangeElementOffset += BindingRegisterOffsetPair(
+ typeLayout->getSubObjectRangeOffset(subObjectRangeIndex));
switch(bindingType)
{
@@ -1847,10 +1868,10 @@ public:
auto elementTypeLayout = elementVarLayout->getTypeLayout();
SLANG_ASSERT(elementTypeLayout);
- BindingRegisterOffsetPair containerOffset = subObjectRangeOffset;
+ BindingRegisterOffsetPair containerOffset = subObjectRangeContainerOffset;
containerOffset += BindingRegisterOffsetPair(containerVarLayout);
- BindingRegisterOffsetPair elementOffset = subObjectRangeOffset;
+ BindingRegisterOffsetPair elementOffset = subObjectRangeElementOffset;
elementOffset += BindingRegisterOffsetPair(elementVarLayout);
addAsConstantBuffer(elementTypeLayout, physicalDescriptorSetIndex, containerOffset, elementOffset);
@@ -1869,8 +1890,10 @@ public:
SLANG_ASSERT(elementTypeLayout);
BindingRegisterOffsetPair subDescriptorSetOffset;
- subDescriptorSetOffset.primary.spaceOffset = subObjectRangeOffset.primary.spaceOffset;
- subDescriptorSetOffset.pending.spaceOffset = subObjectRangeOffset.pending.spaceOffset;
+ subDescriptorSetOffset.primary.spaceOffset =
+ subObjectRangeElementOffset.primary.spaceOffset;
+ subDescriptorSetOffset.pending.spaceOffset =
+ subObjectRangeElementOffset.pending.spaceOffset;
auto subPhysicalDescriptorSetIndex = addDescriptorSet();
@@ -1893,9 +1916,13 @@ public:
if(specializedTypeLayout)
{
BindingRegisterOffsetPair pendingOffset;
- pendingOffset.primary = subObjectRangeOffset.pending;
+ pendingOffset.primary = subObjectRangeElementOffset.pending;
- addAsValue(specializedTypeLayout, physicalDescriptorSetIndex, pendingOffset);
+ addAsValue(
+ specializedTypeLayout,
+ physicalDescriptorSetIndex,
+ pendingOffset,
+ pendingOffset);
}
}
break;
@@ -1959,7 +1986,8 @@ public:
D3D12Device* device,
RootShaderObjectLayoutImpl* rootLayout,
slang::IComponentType* program,
- ID3D12RootSignature** outRootSignature)
+ ID3D12RootSignature** outRootSignature,
+ ID3DBlob** outError)
{
// We are going to build up the root signature by adding
// binding/descritpor ranges and nested parameter blocks
@@ -2013,10 +2041,15 @@ public:
signature.writeRef(),
error.writeRef())))
{
- fprintf(stderr, "error: D3D12SerializeRootSignature failed");
+ getDebugCallback()->handleMessage(DebugMessageType::Error, DebugMessageSource::Layer, "error: D3D12SerializeRootSignature failed");
if (error)
{
- fprintf(stderr, ": %s\n", (const char*)error->GetBufferPointer());
+ getDebugCallback()->handleMessage(
+ DebugMessageType::Error,
+ DebugMessageSource::Driver,
+ (const char*)error->GetBufferPointer());
+ if (outError)
+ returnComPtr(outError, error);
}
return SLANG_FAIL;
}
@@ -2033,7 +2066,8 @@ public:
D3D12Device* device,
slang::IComponentType* program,
slang::ProgramLayout* programLayout,
- RootShaderObjectLayoutImpl** outLayout)
+ RootShaderObjectLayoutImpl** outLayout,
+ ID3DBlob** outError)
{
RootShaderObjectLayoutImpl::Builder builder(device, program, programLayout);
builder.addGlobalParams(programLayout->getGlobalParamsVarLayout());
@@ -2063,7 +2097,8 @@ public:
device,
layout,
program,
- layout->m_rootSignature.writeRef()));
+ layout->m_rootSignature.writeRef(),
+ outError));
}
*outLayout = layout.detach();
@@ -2301,7 +2336,6 @@ public:
m_descriptorSet.samplerTable.allocate(samplerHeap, samplerCount);
}
-
// If the layout specifies that we have any sub-objects, then
// we need to size the array to account for them.
//
@@ -3020,18 +3054,31 @@ public:
specializedComponentType.writeRef(),
diagnosticBlob.writeRef());
- // TODO: print diagnostic message via debug output interface.
+ if (diagnosticBlob && diagnosticBlob->getBufferSize())
+ {
+ getDebugCallback()->handleMessage(
+ SLANG_FAILED(result) ? DebugMessageType::Error : DebugMessageType::Info,
+ DebugMessageSource::Layer,
+ (const char*)diagnosticBlob->getBufferPointer());
+ }
- if (result != SLANG_OK)
+ if (SLANG_FAILED(result))
return result;
+ ComPtr<ID3DBlob> d3dDiagnosticBlob;
auto slangSpecializedLayout = specializedComponentType->getLayout();
RefPtr<RootShaderObjectLayoutImpl> specializedLayout;
- RootShaderObjectLayoutImpl::create(
+ auto rootLayoutResult = RootShaderObjectLayoutImpl::create(
static_cast<D3D12Device*>(getRenderer()),
specializedComponentType,
slangSpecializedLayout,
- specializedLayout.writeRef());
+ specializedLayout.writeRef(),
+ d3dDiagnosticBlob.writeRef());
+
+ if (SLANG_FAILED(rootLayoutResult))
+ {
+ return rootLayoutResult;
+ }
// 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
@@ -5350,17 +5397,20 @@ Result D3D12Device::initialize(const Desc& desc)
m_cpuViewHeap = new D3D12GeneralDescriptorHeap();
SLANG_RETURN_ON_FAIL(m_cpuViewHeap->init(
- m_device, 8192, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
+ m_device,
+ 1024 * 1024,
+ D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
+ D3D12_DESCRIPTOR_HEAP_FLAG_NONE));
m_cpuSamplerHeap = new D3D12GeneralDescriptorHeap();
SLANG_RETURN_ON_FAIL(m_cpuSamplerHeap->init(
- m_device, 1024, 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 D3D12GeneralDescriptorHeap();
SLANG_RETURN_ON_FAIL(m_rtvAllocator->init(
- m_device, 16, 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 D3D12GeneralDescriptorHeap();
SLANG_RETURN_ON_FAIL(m_dsvAllocator->init(
- m_device, 16, 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)
@@ -6154,6 +6204,53 @@ Result D3D12Device::createTextureView(ITextureResource* texture, IResourceView::
return SLANG_OK;
}
+Result D3D12Device::getFormatSupportedResourceStates(Format format, ResourceStateSet* outStates)
+{
+ D3D12_FEATURE_DATA_FORMAT_SUPPORT support;
+ support.Format = D3DUtil::getMapFormat(format);
+ SLANG_RETURN_ON_FAIL(m_device->CheckFeatureSupport(
+ D3D12_FEATURE_FORMAT_SUPPORT, &support, sizeof(support)));
+
+ ResourceStateSet allowedStates;
+
+ auto dxgi1 = support.Support1;
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_BUFFER)
+ allowedStates.add(ResourceState::ConstantBuffer);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_IA_VERTEX_BUFFER)
+ allowedStates.add(ResourceState::VertexBuffer);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_IA_INDEX_BUFFER)
+ allowedStates.add(ResourceState::IndexBuffer);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_SO_BUFFER)
+ allowedStates.add(ResourceState::StreamOutput);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_TEXTURE1D)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_TEXTURE2D)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_TEXTURE3D)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_TEXTURECUBE)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_LOAD)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE_COMPARISON)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_GATHER)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_SHADER_GATHER_COMPARISON)
+ allowedStates.add(ResourceState::ShaderResource);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_RENDER_TARGET)
+ allowedStates.add(ResourceState::RenderTarget);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_DEPTH_STENCIL)
+ allowedStates.add(ResourceState::DepthWrite);
+ if (dxgi1 & D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW)
+ allowedStates.add(ResourceState::UnorderedAccess);
+
+ *outStates = allowedStates;
+ return SLANG_OK;
+}
+
Result D3D12Device::createBufferView(IBufferResource* buffer, IResourceView::Desc const& desc, IResourceView** outView)
{
auto resourceImpl = (BufferResourceImpl*) buffer;
@@ -6174,22 +6271,21 @@ Result D3D12Device::createBufferView(IBufferResource* buffer, IResourceView::Des
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
uavDesc.Format = D3DUtil::getMapFormat(desc.format);
uavDesc.Buffer.FirstElement = desc.bufferRange.firstElement;
-
- if (resourceDesc.elementSize)
+ if (desc.bufferElementSize)
{
- uavDesc.Buffer.StructureByteStride = resourceDesc.elementSize;
+ uavDesc.Buffer.StructureByteStride = desc.bufferElementSize;
uavDesc.Buffer.NumElements =
desc.bufferRange.elementCount == 0
- ? UINT(resourceDesc.sizeInBytes / resourceDesc.elementSize)
+ ? UINT(resourceDesc.sizeInBytes / desc.bufferElementSize)
: desc.bufferRange.elementCount;
}
else if(desc.format == Format::Unknown)
{
- uavDesc.Buffer.Flags |= D3D12_BUFFER_UAV_FLAG_RAW;
uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
uavDesc.Buffer.NumElements = desc.bufferRange.elementCount == 0
? UINT(resourceDesc.sizeInBytes / 4)
: desc.bufferRange.elementCount / 4;
+ uavDesc.Buffer.Flags |= D3D12_BUFFER_UAV_FLAG_RAW;
}
else
{
@@ -6220,22 +6316,21 @@ Result D3D12Device::createBufferView(IBufferResource* buffer, IResourceView::Des
srvDesc.Buffer.StructureByteStride = 0;
srvDesc.Buffer.FirstElement = desc.bufferRange.firstElement;
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- if(resourceDesc.elementSize)
+ if (desc.bufferElementSize)
{
- srvDesc.Buffer.StructureByteStride = resourceDesc.elementSize;
+ srvDesc.Buffer.StructureByteStride = desc.bufferElementSize;
srvDesc.Buffer.NumElements =
desc.bufferRange.elementCount == 0
- ? UINT(resourceDesc.sizeInBytes / resourceDesc.elementSize)
+ ? UINT(resourceDesc.sizeInBytes / desc.bufferElementSize)
: desc.bufferRange.elementCount;
}
- else if(desc.format == Format::Unknown)
+ else if (desc.format == Format::Unknown)
{
- srvDesc.Buffer.Flags |= D3D12_BUFFER_SRV_FLAG_RAW;
srvDesc.Format = DXGI_FORMAT_R32_TYPELESS;
srvDesc.Buffer.NumElements = desc.bufferRange.elementCount == 0
? UINT(resourceDesc.sizeInBytes / 4)
: desc.bufferRange.elementCount / 4;
-
+ srvDesc.Buffer.Flags |= D3D12_BUFFER_SRV_FLAG_RAW;
}
else
{
@@ -6351,7 +6446,7 @@ Result D3D12Device::createInputLayout(IInputLayout::Desc const& desc, IInputLayo
elements.setCount(inputElementCount);
- for (UInt i = 0; i < inputElementCount; ++i)
+ for (Int i = 0; i < inputElementCount; ++i)
{
const InputElementDesc& srcEle = inputElements[i];
const auto& srcStream = vertexStreams[srcEle.bufferSlotIndex];
@@ -6378,7 +6473,7 @@ Result D3D12Device::createInputLayout(IInputLayout::Desc const& desc, IInputLayo
auto& vertexStreamStrides = layout->m_vertexStreamStrides;
vertexStreamStrides.setCount(vertexStreamCount);
- for (UInt i = 0; i < vertexStreamCount; ++i)
+ for (Int i = 0; i < vertexStreamCount; ++i)
{
vertexStreamStrides[i] = vertexStreams[i].stride;
}
@@ -6448,15 +6543,27 @@ Result D3D12Device::readBufferResource(
return SLANG_OK;
}
-Result D3D12Device::createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram)
+Result D3D12Device::createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
{
RefPtr<ShaderProgramImpl> shaderProgram = new ShaderProgramImpl();
shaderProgram->slangProgram = desc.slangProgram;
- RootShaderObjectLayoutImpl::create(
+ ComPtr<ID3DBlob> d3dDiagnosticBlob;
+ auto rootShaderLayoutResult = RootShaderObjectLayoutImpl::create(
this,
desc.slangProgram,
desc.slangProgram->getLayout(),
- shaderProgram->m_rootObjectLayout.writeRef());
+ shaderProgram->m_rootObjectLayout.writeRef(),
+ d3dDiagnosticBlob.writeRef());
+ if (!SLANG_SUCCEEDED(rootShaderLayoutResult))
+ {
+ if (outDiagnosticBlob && d3dDiagnosticBlob)
+ {
+ RefPtr<StringBlob> diagnosticBlob =
+ new StringBlob(String((const char*)d3dDiagnosticBlob->GetBufferPointer()));
+ returnComPtr(outDiagnosticBlob, diagnosticBlob);
+ }
+ return rootShaderLayoutResult;
+ }
if (desc.slangProgram->getSpecializationParamCount() != 0)
{
// For a specializable program, we don't invoke any actual slang compilation yet.
@@ -6479,6 +6586,8 @@ Result D3D12Device::createProgram(const IShaderProgram::Desc& desc, IShaderProgr
compileResult == SLANG_OK ? DebugMessageType::Warning : DebugMessageType::Error,
DebugMessageSource::Slang,
(char*)diagnostics->getBufferPointer());
+ if (outDiagnosticBlob)
+ returnComPtr(outDiagnosticBlob, diagnostics);
}
SLANG_RETURN_ON_FAIL(compileResult);
ShaderBinary shaderBin;
diff --git a/tools/gfx/debug-layer.cpp b/tools/gfx/debug-layer.cpp
index b0b3ae30b..63f1e6d43 100644
--- a/tools/gfx/debug-layer.cpp
+++ b/tools/gfx/debug-layer.cpp
@@ -666,12 +666,13 @@ Result DebugDevice::createMutableRootShaderObject(
return result;
}
-Result DebugDevice::createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram)
+Result DebugDevice::createProgram(
+ const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnostics)
{
SLANG_GFX_API_FUNC;
RefPtr<DebugShaderProgram> outObject = new DebugShaderProgram(desc);
- auto result = baseObject->createProgram(desc, outObject->baseObject.writeRef());
+ auto result = baseObject->createProgram(desc, outObject->baseObject.writeRef(), outDiagnostics);
if (SLANG_FAILED(result))
return result;
returnComPtr(outProgram, outObject);
diff --git a/tools/gfx/debug-layer.h b/tools/gfx/debug-layer.h
index 83bcb736f..d848676db 100644
--- a/tools/gfx/debug-layer.h
+++ b/tools/gfx/debug-layer.h
@@ -121,7 +121,7 @@ public:
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) override;
+ createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnostics) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createGraphicsPipelineState(
const GraphicsPipelineStateDesc& desc,
IPipelineState** outState) override;
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index bcdaae8c0..63c20fbea 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -144,8 +144,10 @@ public:
virtual Result createRootShaderObject(IShaderProgram* program, ShaderObjectBase** outObject) override;
virtual void bindRootShaderObject(IShaderObject* shaderObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram) 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;
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
@@ -2754,7 +2756,8 @@ void GLDevice::dispatchCompute(int x, int y, int z)
glDispatchCompute(x, y, z);
}
-Result GLDevice::createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram)
+Result GLDevice::createProgram(
+ const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
{
if (desc.slangProgram->getSpecializationParamCount() != 0)
{
@@ -2780,6 +2783,8 @@ Result GLDevice::createProgram(const IShaderProgram::Desc& desc, IShaderProgram*
compileResult == SLANG_OK ? DebugMessageType::Warning : DebugMessageType::Error,
DebugMessageSource::Slang,
(char*)diagnostics->getBufferPointer());
+ if (outDiagnosticBlob)
+ returnComPtr(outDiagnosticBlob, diagnostics);
}
SLANG_RETURN_ON_FAIL(compileResult);
GLenum glShaderType = 0;
diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp
index 0952e7ea5..96e11eb27 100644
--- a/tools/gfx/vulkan/render-vk.cpp
+++ b/tools/gfx/vulkan/render-vk.cpp
@@ -109,8 +109,10 @@ public:
createMutableRootShaderObject(
IShaderProgram* program, IShaderObject** outObject) override;
- virtual SLANG_NO_THROW Result SLANG_MCALL
- createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram) 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;
@@ -8002,7 +8004,8 @@ static VkImageViewType _calcImageViewType(ITextureResource::Type type, const ITe
return VK_IMAGE_VIEW_TYPE_MAX_ENUM;
}
-Result VKDevice::createProgram(const IShaderProgram::Desc& desc, IShaderProgram** outProgram)
+Result VKDevice::createProgram(
+ const IShaderProgram::Desc& desc, IShaderProgram** outProgram, ISlangBlob** outDiagnosticBlob)
{
RefPtr<ShaderProgramImpl> shaderProgram = new ShaderProgramImpl(this);
shaderProgram->slangProgram = desc.slangProgram;
@@ -8036,6 +8039,8 @@ Result VKDevice::createProgram(const IShaderProgram::Desc& desc, IShaderProgram*
compileResult == SLANG_OK ? DebugMessageType::Warning : DebugMessageType::Error,
DebugMessageSource::Slang,
(char*)diagnostics->getBufferPointer());
+ if (outDiagnosticBlob)
+ returnComPtr(outDiagnosticBlob, diagnostics);
}
SLANG_RETURN_ON_FAIL(compileResult);
shaderProgram->m_codeBlobs.add(kernelCode);