summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-02-20 12:24:00 -0800
committerGitHub <noreply@github.com>2024-02-20 12:24:00 -0800
commit4d20fd329956ac89408b1628a8291fea01bc9a6d (patch)
tree8e62d9c1ec05142fd25d0b31073fdb56d44691b0 /tools
parent8e9b61e3bac69dbb37a1451b62302e688a017ced (diff)
Refactor compiler option representations. (#3598)
* Refactor compiler option representation. * Fix binary compatibility. * Add a test for specifying compiler options at link time. * Fix binary compatibility. * Fix binary compatibility. * Fix backward compatibility on matrix layout. * Fix. * Fix. * Fix. * Fix gfx. * Fix gfx. * Fix dynamic dispatch. * Polish.
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx-unit-test/link-time-options.cpp152
-rw-r--r--tools/gfx-unit-test/link-time-options.slang20
-rw-r--r--tools/gfx/cpu/cpu-device.cpp5
-rw-r--r--tools/gfx/cpu/cpu-device.h1
-rw-r--r--tools/gfx/cpu/cpu-shader-object-layout.cpp13
-rw-r--r--tools/gfx/cpu/cpu-shader-object-layout.h7
-rw-r--r--tools/gfx/cuda/cuda-device.cpp3
-rw-r--r--tools/gfx/cuda/cuda-device.h1
-rw-r--r--tools/gfx/cuda/cuda-shader-object-layout.cpp9
-rw-r--r--tools/gfx/cuda/cuda-shader-object-layout.h2
-rw-r--r--tools/gfx/d3d11/d3d11-device.cpp3
-rw-r--r--tools/gfx/d3d11/d3d11-device.h1
-rw-r--r--tools/gfx/d3d11/d3d11-shader-object-layout.cpp11
-rw-r--r--tools/gfx/d3d11/d3d11-shader-object-layout.h8
-rw-r--r--tools/gfx/d3d11/d3d11-shader-object.cpp1
-rw-r--r--tools/gfx/d3d12/d3d12-device.cpp6
-rw-r--r--tools/gfx/d3d12/d3d12-device.h2
-rw-r--r--tools/gfx/d3d12/d3d12-shader-object-layout.cpp10
-rw-r--r--tools/gfx/d3d12/d3d12-shader-object-layout.h8
-rw-r--r--tools/gfx/d3d12/d3d12-shader-object.cpp1
-rw-r--r--tools/gfx/debug-layer/debug-device.cpp42
-rw-r--r--tools/gfx/debug-layer/debug-device.h10
-rw-r--r--tools/gfx/open-gl/render-gl.cpp20
-rw-r--r--tools/gfx/renderer-shared.cpp51
-rw-r--r--tools/gfx/renderer-shared.h20
-rw-r--r--tools/gfx/slang.slang12
-rw-r--r--tools/gfx/vulkan/vk-device.cpp6
-rw-r--r--tools/gfx/vulkan/vk-device.h4
-rw-r--r--tools/gfx/vulkan/vk-shader-object-layout.cpp11
-rw-r--r--tools/gfx/vulkan/vk-shader-object-layout.h12
-rw-r--r--tools/gfx/vulkan/vk-shader-object.cpp1
-rw-r--r--tools/render-test/options.cpp1
-rw-r--r--tools/render-test/render-test-main.cpp21
-rw-r--r--tools/render-test/slang-support.cpp30
-rw-r--r--tools/render-test/slang-support.h6
-rw-r--r--tools/slang-test/slangc-tool.cpp9
36 files changed, 409 insertions, 111 deletions
diff --git a/tools/gfx-unit-test/link-time-options.cpp b/tools/gfx-unit-test/link-time-options.cpp
new file mode 100644
index 000000000..f14a918e8
--- /dev/null
+++ b/tools/gfx-unit-test/link-time-options.cpp
@@ -0,0 +1,152 @@
+#include "tools/unit-test/slang-unit-test.h"
+
+#include "slang-gfx.h"
+#include "gfx-test-util.h"
+#include "tools/gfx-util/shader-cursor.h"
+#include "source/core/slang-basic.h"
+#include "source/core/slang-blob.h"
+
+using namespace gfx;
+
+namespace gfx_test
+{
+ // In this test,
+ // we will run a compute shader that compiles to HLSL with a reference to the macro "DOWNSTREAM_VALUE"
+ // that will be provided to dxc through slang's link-time compiler options.
+ // The test verifies that `IComponentType2::linkWithOptions()` is able to produce a linked IComponentType
+ // with additional compiler options. Here we will specify a DownstreamArg compiler option to define
+ // the value of DOWNSTREAM_VALUE when running dxc.
+ //
+ static Slang::Result loadProgram(
+ gfx::IDevice* device,
+ Slang::ComPtr<gfx::IShaderProgram>& outShaderProgram,
+ const char* shaderModuleName,
+ const char* entryPointName,
+ slang::ProgramLayout*& slangReflection)
+ {
+ Slang::ComPtr<slang::ISession> slangSession;
+ SLANG_RETURN_ON_FAIL(device->getSlangSession(slangSession.writeRef()));
+ Slang::ComPtr<slang::IBlob> diagnosticsBlob;
+ slang::IModule* module = slangSession->loadModule(shaderModuleName, diagnosticsBlob.writeRef());
+ diagnoseIfNeeded(diagnosticsBlob);
+ if (!module)
+ return SLANG_FAIL;
+
+ ComPtr<slang::IEntryPoint> computeEntryPoint;
+ SLANG_RETURN_ON_FAIL(
+ module->findEntryPointByName(entryPointName, computeEntryPoint.writeRef()));
+
+ Slang::List<slang::IComponentType*> componentTypes;
+ componentTypes.add(module);
+ componentTypes.add(computeEntryPoint);
+
+ Slang::ComPtr<slang::IComponentType> composedProgram;
+ SlangResult result = slangSession->createCompositeComponentType(
+ componentTypes.getBuffer(),
+ componentTypes.getCount(),
+ composedProgram.writeRef(),
+ diagnosticsBlob.writeRef());
+ diagnoseIfNeeded(diagnosticsBlob);
+ SLANG_RETURN_ON_FAIL(result);
+
+ ComPtr<slang::IComponentType> linkedProgram;
+ slang::CompilerOptionEntry entry;
+ entry.name = slang::CompilerOptionName::DownstreamArgs;
+ entry.value.kind = slang::CompilerOptionValueKind::String;
+ entry.value.stringValue0 = "dxc";
+ entry.value.stringValue1 = "-DDOWNSTREAM_VALUE=4.0";
+ result = composedProgram->linkWithOptions(linkedProgram.writeRef(), 1, &entry, diagnosticsBlob.writeRef());
+ diagnoseIfNeeded(diagnosticsBlob);
+ SLANG_RETURN_ON_FAIL(result);
+
+ composedProgram = linkedProgram;
+ slangReflection = composedProgram->getLayout();
+
+ gfx::IShaderProgram::Desc programDesc = {};
+ programDesc.slangGlobalScope = composedProgram.get();
+
+ auto shaderProgram = device->createProgram(programDesc);
+
+ outShaderProgram = shaderProgram;
+ return SLANG_OK;
+ }
+
+ void linkTimeOptionTestImpl(IDevice* device, UnitTestContext* context)
+ {
+ Slang::ComPtr<ITransientResourceHeap> transientHeap;
+ ITransientResourceHeap::Desc transientHeapDesc = {};
+ transientHeapDesc.constantBufferSize = 4096;
+ GFX_CHECK_CALL_ABORT(
+ device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef()));
+
+ ComPtr<IShaderProgram> shaderProgram;
+ slang::ProgramLayout* slangReflection;
+ GFX_CHECK_CALL_ABORT(loadProgram(device, shaderProgram, "link-time-options", "computeMain", slangReflection));
+
+ ComputePipelineStateDesc pipelineDesc = {};
+ pipelineDesc.program = shaderProgram.get();
+ ComPtr<gfx::IPipelineState> pipelineState;
+ GFX_CHECK_CALL_ABORT(
+ device->createComputePipelineState(pipelineDesc, pipelineState.writeRef()));
+
+ const int numberCount = 4;
+ float initialData[] = { 0.0f, 0.0f, 0.0f, 0.0f };
+ IBufferResource::Desc bufferDesc = {};
+ bufferDesc.sizeInBytes = numberCount * sizeof(float);
+ bufferDesc.format = gfx::Format::Unknown;
+ bufferDesc.elementSize = sizeof(float);
+ bufferDesc.allowedStates = ResourceStateSet(
+ ResourceState::ShaderResource,
+ ResourceState::UnorderedAccess,
+ ResourceState::CopyDestination,
+ ResourceState::CopySource);
+ bufferDesc.defaultState = ResourceState::UnorderedAccess;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
+
+ ComPtr<IBufferResource> numbersBuffer;
+ GFX_CHECK_CALL_ABORT(device->createBufferResource(
+ bufferDesc,
+ (void*)initialData,
+ numbersBuffer.writeRef()));
+
+ ComPtr<IResourceView> bufferView;
+ IResourceView::Desc viewDesc = {};
+ viewDesc.type = IResourceView::Type::UnorderedAccess;
+ viewDesc.format = Format::Unknown;
+ GFX_CHECK_CALL_ABORT(
+ device->createBufferView(numbersBuffer, nullptr, viewDesc, bufferView.writeRef()));
+
+ // We have done all the set up work, now it is time to start recording a command buffer for
+ // GPU execution.
+ {
+ ICommandQueue::Desc queueDesc = { ICommandQueue::QueueType::Graphics };
+ auto queue = device->createCommandQueue(queueDesc);
+
+ auto commandBuffer = transientHeap->createCommandBuffer();
+ auto encoder = commandBuffer->encodeComputeCommands();
+
+ auto rootObject = encoder->bindPipeline(pipelineState);
+
+ ShaderCursor entryPointCursor(
+ rootObject->getEntryPoint(0)); // get a cursor the the first entry-point.
+ // Bind buffer view to the entry point.
+ entryPointCursor.getPath("buffer").setResource(bufferView);
+
+ encoder->dispatchCompute(1, 1, 1);
+ encoder->endEncoding();
+ commandBuffer->close();
+ queue->executeCommandBuffer(commandBuffer);
+ queue->waitOnHost();
+ }
+
+ compareComputeResult(
+ device,
+ numbersBuffer,
+ Slang::makeArray<float>(4.0));
+ }
+
+ SLANG_UNIT_TEST(linkTimeOptionD3D12)
+ {
+ runTestImpl(linkTimeOptionTestImpl, unitTestContext, Slang::RenderApiFlag::D3D12);
+ }
+}
diff --git a/tools/gfx-unit-test/link-time-options.slang b/tools/gfx-unit-test/link-time-options.slang
new file mode 100644
index 000000000..e168c19fe
--- /dev/null
+++ b/tools/gfx-unit-test/link-time-options.slang
@@ -0,0 +1,20 @@
+// link-time-options.slang
+
+// Test that we can pass in additional compiler options
+// at link time.
+
+// Lowers to `DOWNSTREAM_VALUE`, a macro that we will define
+// for downstream compilation through link-time options.
+float getMacroDefinedForDownstream()
+{
+ __intrinsic_asm "(DOWNSTREAM_VALUE)";
+}
+
+[shader("compute")]
+[numthreads(4,1,1)]
+void computeMain(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID,
+ uniform RWStructuredBuffer<float> buffer)
+{
+ buffer[sv_dispatchThreadID.x] = getMacroDefinedForDownstream();
+}
diff --git a/tools/gfx/cpu/cpu-device.cpp b/tools/gfx/cpu/cpu-device.cpp
index 4b8595e82..f248cf52a 100644
--- a/tools/gfx/cpu/cpu-device.cpp
+++ b/tools/gfx/cpu/cpu-device.cpp
@@ -106,10 +106,11 @@ namespace cpu
}
Result DeviceImpl::createShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout)
{
- RefPtr<ShaderObjectLayoutImpl> cpuLayout = new ShaderObjectLayoutImpl(this, typeLayout);
+ RefPtr<ShaderObjectLayoutImpl> cpuLayout = new ShaderObjectLayoutImpl(this, session, typeLayout);
returnRefPtrMove(outLayout, cpuLayout);
return SLANG_OK;
@@ -166,7 +167,7 @@ namespace cpu
if (!slangProgramLayout)
return SLANG_FAIL;
- RefPtr<RootShaderObjectLayoutImpl> cpuProgramLayout = new RootShaderObjectLayoutImpl(this, slangProgramLayout);
+ RefPtr<RootShaderObjectLayoutImpl> cpuProgramLayout = new RootShaderObjectLayoutImpl(this, slangGlobalScope->getSession(), slangProgramLayout);
cpuProgramLayout->m_programLayout = slangProgramLayout;
cpuProgram->layout = cpuProgramLayout;
diff --git a/tools/gfx/cpu/cpu-device.h b/tools/gfx/cpu/cpu-device.h
index d90ce1e8b..c7b80e26d 100644
--- a/tools/gfx/cpu/cpu-device.h
+++ b/tools/gfx/cpu/cpu-device.h
@@ -39,6 +39,7 @@ public:
IResourceView** outView) override;
virtual Result createShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) override;
diff --git a/tools/gfx/cpu/cpu-shader-object-layout.cpp b/tools/gfx/cpu/cpu-shader-object-layout.cpp
index 2ff89efff..4f4c33a6a 100644
--- a/tools/gfx/cpu/cpu-shader-object-layout.cpp
+++ b/tools/gfx/cpu/cpu-shader-object-layout.cpp
@@ -8,13 +8,13 @@ using namespace Slang;
namespace cpu
{
-ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::TypeLayoutReflection* layout)
+ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* layout)
{
- initBase(renderer, layout);
+ initBase(renderer, session, layout);
m_subObjectCount = 0;
m_resourceCount = 0;
-
+
m_elementTypeLayout = _unwrapParameterGroups(layout, m_containerType);
m_size = m_elementTypeLayout->getSize();
@@ -104,7 +104,7 @@ ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::Ty
if (slangBindingType != slang::BindingType::ExistentialValue)
{
subObjectLayout =
- new ShaderObjectLayoutImpl(renderer, slangLeafTypeLayout->getElementTypeLayout());
+ new ShaderObjectLayoutImpl(renderer, m_slangSession, slangLeafTypeLayout->getElementTypeLayout());
}
SubObjectRangeInfo subObjectRange;
@@ -130,14 +130,15 @@ const char* EntryPointLayoutImpl::getEntryPointName()
return m_entryPointLayout->getName();
}
-RootShaderObjectLayoutImpl::RootShaderObjectLayoutImpl(RendererBase* renderer, slang::ProgramLayout* programLayout)
- : ShaderObjectLayoutImpl(renderer, programLayout->getGlobalParamsTypeLayout())
+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++)
{
m_entryPointLayouts.add(new EntryPointLayoutImpl(
renderer,
+ session,
programLayout->getEntryPointByIndex(i)));
}
diff --git a/tools/gfx/cpu/cpu-shader-object-layout.h b/tools/gfx/cpu/cpu-shader-object-layout.h
index e421918f1..3bf2e2aa7 100644
--- a/tools/gfx/cpu/cpu-shader-object-layout.h
+++ b/tools/gfx/cpu/cpu-shader-object-layout.h
@@ -55,7 +55,7 @@ public:
Index m_subObjectCount = 0;
Index m_resourceCount = 0;
- ShaderObjectLayoutImpl(RendererBase* renderer, slang::TypeLayoutReflection* layout);
+ ShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* layout);
size_t getSize();
Index getResourceCount() const;
@@ -73,8 +73,9 @@ private:
public:
EntryPointLayoutImpl(
RendererBase* renderer,
+ slang::ISession* session,
slang::EntryPointLayout* entryPointLayout)
- : ShaderObjectLayoutImpl(renderer, entryPointLayout->getTypeLayout())
+ : ShaderObjectLayoutImpl(renderer, session, entryPointLayout->getTypeLayout())
, m_entryPointLayout(entryPointLayout)
{}
@@ -87,7 +88,7 @@ public:
slang::ProgramLayout* m_programLayout = nullptr;
List<RefPtr<EntryPointLayoutImpl>> m_entryPointLayouts;
- RootShaderObjectLayoutImpl(RendererBase* renderer, 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/cuda/cuda-device.cpp b/tools/gfx/cuda/cuda-device.cpp
index 7f931afa1..377a5aba2 100644
--- a/tools/gfx/cuda/cuda-device.cpp
+++ b/tools/gfx/cuda/cuda-device.cpp
@@ -908,11 +908,12 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::createQueryPool(
}
Result DeviceImpl::createShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout)
{
RefPtr<ShaderObjectLayoutImpl> cudaLayout;
- cudaLayout = new ShaderObjectLayoutImpl(this, typeLayout);
+ cudaLayout = new ShaderObjectLayoutImpl(this, session, typeLayout);
returnRefPtrMove(outLayout, cudaLayout);
return SLANG_OK;
}
diff --git a/tools/gfx/cuda/cuda-device.h b/tools/gfx/cuda/cuda-device.h
index bfaf1be6e..e711dc261 100644
--- a/tools/gfx/cuda/cuda-device.h
+++ b/tools/gfx/cuda/cuda-device.h
@@ -73,6 +73,7 @@ public:
IQueryPool** outPool) override;
virtual Result createShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) override;
diff --git a/tools/gfx/cuda/cuda-shader-object-layout.cpp b/tools/gfx/cuda/cuda-shader-object-layout.cpp
index eacae0fc0..f527d78de 100644
--- a/tools/gfx/cuda/cuda-shader-object-layout.cpp
+++ b/tools/gfx/cuda/cuda-shader-object-layout.cpp
@@ -9,11 +9,11 @@ using namespace Slang;
namespace cuda
{
-ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::TypeLayoutReflection* layout)
+ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* layout)
{
m_elementTypeLayout = _unwrapParameterGroups(layout, m_containerType);
- initBase(renderer, m_elementTypeLayout);
+ initBase(renderer, session, m_elementTypeLayout);
// Compute the binding ranges that are used to store
// the logical contents of the object in memory. These will relate
@@ -101,7 +101,7 @@ ShaderObjectLayoutImpl::ShaderObjectLayoutImpl(RendererBase* renderer, slang::Ty
if (slangBindingType != slang::BindingType::ExistentialValue)
{
subObjectLayout =
- new ShaderObjectLayoutImpl(renderer, slangLeafTypeLayout->getElementTypeLayout());
+ new ShaderObjectLayoutImpl(renderer, session, slangLeafTypeLayout->getElementTypeLayout());
}
SubObjectRangeInfo subObjectRange;
@@ -118,13 +118,14 @@ BindingRangeInfo ShaderObjectLayoutImpl::getBindingRange(Index index) { return m
Index ShaderObjectLayoutImpl::getBindingRangeCount() const { return m_bindingRanges.getCount(); }
RootShaderObjectLayoutImpl::RootShaderObjectLayoutImpl(RendererBase* renderer, slang::ProgramLayout* inProgramLayout)
- : ShaderObjectLayoutImpl(renderer, inProgramLayout->getGlobalParamsTypeLayout())
+ : ShaderObjectLayoutImpl(renderer, inProgramLayout->getSession(), inProgramLayout->getGlobalParamsTypeLayout())
, programLayout(inProgramLayout)
{
for (UInt i = 0; i < programLayout->getEntryPointCount(); i++)
{
entryPointLayouts.add(new ShaderObjectLayoutImpl(
renderer,
+ programLayout->getSession(),
programLayout->getEntryPointByIndex(i)->getTypeLayout()));
}
diff --git a/tools/gfx/cuda/cuda-shader-object-layout.h b/tools/gfx/cuda/cuda-shader-object-layout.h
index 5d3a2d52a..edec0c352 100644
--- a/tools/gfx/cuda/cuda-shader-object-layout.h
+++ b/tools/gfx/cuda/cuda-shader-object-layout.h
@@ -50,7 +50,7 @@ public:
Index m_subObjectCount = 0;
Index m_resourceCount = 0;
- ShaderObjectLayoutImpl(RendererBase* renderer, slang::TypeLayoutReflection* layout);
+ ShaderObjectLayoutImpl(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* layout);
Index getResourceCount() const;
Index getSubObjectCount() const;
diff --git a/tools/gfx/d3d11/d3d11-device.cpp b/tools/gfx/d3d11/d3d11-device.cpp
index 96a5043fb..20e17b082 100644
--- a/tools/gfx/d3d11/d3d11-device.cpp
+++ b/tools/gfx/d3d11/d3d11-device.cpp
@@ -1413,12 +1413,13 @@ Result DeviceImpl::createProgram(
}
Result DeviceImpl::createShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout)
{
RefPtr<ShaderObjectLayoutImpl> layout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- this, typeLayout, layout.writeRef()));
+ this, session, typeLayout, layout.writeRef()));
returnRefPtrMove(outLayout, layout);
return SLANG_OK;
}
diff --git a/tools/gfx/d3d11/d3d11-device.h b/tools/gfx/d3d11/d3d11-device.h
index 608411912..42fffa3c9 100644
--- a/tools/gfx/d3d11/d3d11-device.h
+++ b/tools/gfx/d3d11/d3d11-device.h
@@ -59,6 +59,7 @@ public:
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)
diff --git a/tools/gfx/d3d11/d3d11-shader-object-layout.cpp b/tools/gfx/d3d11/d3d11-shader-object-layout.cpp
index 8032719b0..70204e4c0 100644
--- a/tools/gfx/d3d11/d3d11-shader-object-layout.cpp
+++ b/tools/gfx/d3d11/d3d11-shader-object-layout.cpp
@@ -180,6 +180,7 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
auto elementTypeLayout = slangLeafTypeLayout->getElementTypeLayout();
createForElementType(
m_renderer,
+ m_session,
elementTypeLayout,
subObjectLayout.writeRef());
}
@@ -198,6 +199,7 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(slang::TypeLayoutRe
{
createForElementType(
m_renderer,
+ m_session,
pendingTypeLayout,
subObjectLayout.writeRef());
@@ -233,10 +235,11 @@ SlangResult ShaderObjectLayoutImpl::Builder::build(ShaderObjectLayoutImpl** outL
Result ShaderObjectLayoutImpl::createForElementType(
RendererBase* renderer,
+ slang::ISession* session,
slang::TypeLayoutReflection* elementType,
ShaderObjectLayoutImpl** outLayout)
{
- Builder builder(renderer);
+ Builder builder(renderer, session);
builder.setElementTypeLayout(elementType);
return builder.build(outLayout);
}
@@ -245,7 +248,7 @@ Result ShaderObjectLayoutImpl::_init(Builder const* builder)
{
auto renderer = builder->m_renderer;
- initBase(renderer, builder->m_elementTypeLayout);
+ initBase(renderer, builder->m_session, builder->m_elementTypeLayout);
m_bindingRanges = builder->m_bindingRanges;
m_srvRanges = builder->m_srvRanges;
@@ -303,7 +306,7 @@ Result RootShaderObjectLayoutImpl::create(
auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
RefPtr<ShaderObjectLayoutImpl> entryPointLayout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- renderer, slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
+ renderer, program->getSession(), slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
builder.addEntryPoint(slangEntryPoint->getStage(), entryPointLayout, slangEntryPoint);
}
@@ -322,6 +325,8 @@ Result RootShaderObjectLayoutImpl::_init(Builder const* builder)
m_programLayout = builder->m_programLayout;
m_entryPoints = builder->m_entryPoints;
m_pendingDataOffset = builder->m_pendingDataOffset;
+ m_slangSession = m_program->getSession();
+
return SLANG_OK;
}
diff --git a/tools/gfx/d3d11/d3d11-shader-object-layout.h b/tools/gfx/d3d11/d3d11-shader-object-layout.h
index e029a7b76..e18c91c2e 100644
--- a/tools/gfx/d3d11/d3d11-shader-object-layout.h
+++ b/tools/gfx/d3d11/d3d11-shader-object-layout.h
@@ -107,11 +107,12 @@ public:
struct Builder
{
public:
- Builder(RendererBase* renderer)
- : m_renderer(renderer)
+ Builder(RendererBase* renderer, slang::ISession* session)
+ : m_renderer(renderer), m_session(session)
{}
RendererBase* m_renderer;
+ slang::ISession* m_session;
slang::TypeLayoutReflection* m_elementTypeLayout;
List<BindingRangeInfo> m_bindingRanges;
@@ -144,6 +145,7 @@ public:
static Result createForElementType(
RendererBase* renderer,
+ slang::ISession* session,
slang::TypeLayoutReflection* elementType,
ShaderObjectLayoutImpl** outLayout);
@@ -216,7 +218,7 @@ public:
RendererBase* renderer,
slang::IComponentType* program,
slang::ProgramLayout* programLayout)
- : Super::Builder(renderer)
+ : Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
{}
diff --git a/tools/gfx/d3d11/d3d11-shader-object.cpp b/tools/gfx/d3d11/d3d11-shader-object.cpp
index 285cc60b6..40d671843 100644
--- a/tools/gfx/d3d11/d3d11-shader-object.cpp
+++ b/tools/gfx/d3d11/d3d11-shader-object.cpp
@@ -495,6 +495,7 @@ Result ShaderObjectImpl::_createSpecializedLayout(ShaderObjectLayoutImpl** outLa
auto renderer = getRenderer();
RefPtr<ShaderObjectLayoutImpl> layout;
SLANG_RETURN_ON_FAIL(renderer->getShaderObjectLayout(
+ m_layout->m_slangSession,
extendedType.slangType,
m_layout->getContainerType(),
(ShaderObjectLayoutBase**)layout.writeRef()));
diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp
index cd4dfb7a3..bbf27b4f7 100644
--- a/tools/gfx/d3d12/d3d12-device.cpp
+++ b/tools/gfx/d3d12/d3d12-device.cpp
@@ -2034,11 +2034,13 @@ Result DeviceImpl::createProgram(
}
Result DeviceImpl::createShaderObjectLayout(
- slang::TypeLayoutReflection* typeLayout, ShaderObjectLayoutBase** outLayout)
+ slang::ISession* session,
+ slang::TypeLayoutReflection* typeLayout,
+ ShaderObjectLayoutBase** outLayout)
{
RefPtr<ShaderObjectLayoutImpl> layout;
SLANG_RETURN_ON_FAIL(
- ShaderObjectLayoutImpl::createForElementType(this, typeLayout, layout.writeRef()));
+ ShaderObjectLayoutImpl::createForElementType(this, session, typeLayout, layout.writeRef()));
returnRefPtrMove(outLayout, layout);
return SLANG_OK;
}
diff --git a/tools/gfx/d3d12/d3d12-device.h b/tools/gfx/d3d12/d3d12-device.h
index 6bbdde9d0..a38e3c68e 100644
--- a/tools/gfx/d3d12/d3d12-device.h
+++ b/tools/gfx/d3d12/d3d12-device.h
@@ -152,7 +152,7 @@ public:
createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
virtual Result createShaderObjectLayout(
- slang::TypeLayoutReflection* typeLayout, ShaderObjectLayoutBase** outLayout) override;
+ slang::ISession* session, slang::TypeLayoutReflection* typeLayout, ShaderObjectLayoutBase** outLayout) override;
virtual Result createShaderObject(
ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
virtual Result createMutableShaderObject(
diff --git a/tools/gfx/d3d12/d3d12-shader-object-layout.cpp b/tools/gfx/d3d12/d3d12-shader-object-layout.cpp
index c43d3881e..0c0095621 100644
--- a/tools/gfx/d3d12/d3d12-shader-object-layout.cpp
+++ b/tools/gfx/d3d12/d3d12-shader-object-layout.cpp
@@ -50,10 +50,11 @@ bool ShaderObjectLayoutImpl::isBindingRangeRootParameter(
Result ShaderObjectLayoutImpl::createForElementType(
RendererBase* renderer,
+ slang::ISession* session,
slang::TypeLayoutReflection* elementType,
ShaderObjectLayoutImpl** outLayout)
{
- Builder builder(renderer);
+ Builder builder(renderer, session);
builder.setElementTypeLayout(elementType);
return builder.build(outLayout);
}
@@ -62,7 +63,7 @@ Result ShaderObjectLayoutImpl::init(Builder* builder)
{
auto renderer = builder->m_renderer;
- initBase(renderer, builder->m_elementTypeLayout);
+ initBase(renderer, builder->m_session, builder->m_elementTypeLayout);
m_containerType = builder->m_containerType;
@@ -223,13 +224,14 @@ Result ShaderObjectLayoutImpl::Builder::setElementTypeLayout(
{
if (auto pendingTypeLayout = slangLeafTypeLayout->getPendingDataTypeLayout())
{
- createForElementType(m_renderer, pendingTypeLayout, subObjectLayout.writeRef());
+ createForElementType(m_renderer, m_session, pendingTypeLayout, subObjectLayout.writeRef());
}
}
else
{
createForElementType(
m_renderer,
+ m_session,
slangLeafTypeLayout->getElementTypeLayout(),
subObjectLayout.writeRef());
}
@@ -982,7 +984,7 @@ Result RootShaderObjectLayoutImpl::create(
auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
RefPtr<ShaderObjectLayoutImpl> entryPointLayout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- device, slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
+ device, program->getSession(), slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
builder.addEntryPoint(slangEntryPoint->getStage(), entryPointLayout);
}
diff --git a/tools/gfx/d3d12/d3d12-shader-object-layout.h b/tools/gfx/d3d12/d3d12-shader-object-layout.h
index accd30aa9..4b46df0b0 100644
--- a/tools/gfx/d3d12/d3d12-shader-object-layout.h
+++ b/tools/gfx/d3d12/d3d12-shader-object-layout.h
@@ -124,11 +124,12 @@ public:
struct Builder
{
public:
- Builder(RendererBase* renderer)
- : m_renderer(renderer)
+ Builder(RendererBase* renderer, slang::ISession* session)
+ : m_renderer(renderer), m_session(session)
{}
RendererBase* m_renderer;
+ slang::ISession* m_session;
slang::TypeLayoutReflection* m_elementTypeLayout;
List<BindingRangeInfo> m_bindingRanges;
List<SubObjectRangeInfo> m_subObjectRanges;
@@ -165,6 +166,7 @@ public:
static Result createForElementType(
RendererBase* renderer,
+ slang::ISession* session,
slang::TypeLayoutReflection* elementType,
ShaderObjectLayoutImpl** outLayout);
@@ -238,7 +240,7 @@ public:
RendererBase* renderer,
slang::IComponentType* program,
slang::ProgramLayout* programLayout)
- : Super::Builder(renderer)
+ : Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
{}
diff --git a/tools/gfx/d3d12/d3d12-shader-object.cpp b/tools/gfx/d3d12/d3d12-shader-object.cpp
index 5227579ce..1b7b51106 100644
--- a/tools/gfx/d3d12/d3d12-shader-object.cpp
+++ b/tools/gfx/d3d12/d3d12-shader-object.cpp
@@ -868,6 +868,7 @@ Result ShaderObjectImpl::_createSpecializedLayout(ShaderObjectLayoutImpl** outLa
auto renderer = getRenderer();
RefPtr<ShaderObjectLayoutImpl> layout;
SLANG_RETURN_ON_FAIL(renderer->getShaderObjectLayout(
+ m_layout->m_slangSession,
extendedType.slangType,
m_layout->getContainerType(),
(ShaderObjectLayoutBase**)layout.writeRef()));
diff --git a/tools/gfx/debug-layer/debug-device.cpp b/tools/gfx/debug-layer/debug-device.cpp
index 45374b64f..44ca1de7a 100644
--- a/tools/gfx/debug-layer/debug-device.cpp
+++ b/tools/gfx/debug-layer/debug-device.cpp
@@ -376,6 +376,27 @@ Result DebugDevice::createShaderObject(
return result;
}
+Result DebugDevice::createShaderObject2(
+ slang::ISession* session,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType containerType,
+ IShaderObject** outShaderObject)
+{
+ SLANG_GFX_API_FUNC;
+
+ RefPtr<DebugShaderObject> outObject = new DebugShaderObject();
+ auto typeName = type->getName();
+ auto result =
+ baseObject->createShaderObject2(session, type, containerType, outObject->baseObject.writeRef());
+ outObject->m_typeName = typeName;
+ outObject->m_device = this;
+ outObject->m_slangType = type;
+ if (SLANG_FAILED(result))
+ return result;
+ returnComPtr(outShaderObject, outObject);
+ return result;
+}
+
Result DebugDevice::createMutableShaderObject(
slang::TypeReflection* type,
ShaderObjectContainerType containerType,
@@ -396,6 +417,27 @@ Result DebugDevice::createMutableShaderObject(
return result;
}
+Result DebugDevice::createMutableShaderObject2(
+ slang::ISession* session,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType containerType,
+ IShaderObject** outShaderObject)
+{
+ SLANG_GFX_API_FUNC;
+
+ RefPtr<DebugShaderObject> outObject = new DebugShaderObject();
+ auto typeName = type->getName();
+ auto result =
+ baseObject->createMutableShaderObject2(session, type, containerType, outObject->baseObject.writeRef());
+ outObject->m_typeName = typeName;
+ outObject->m_device = this;
+ outObject->m_slangType = type;
+ if (SLANG_FAILED(result))
+ return result;
+ returnComPtr(outShaderObject, outObject);
+ return result;
+}
+
Result DebugDevice::createMutableRootShaderObject(
IShaderProgram* program, IShaderObject** outRootObject)
{
diff --git a/tools/gfx/debug-layer/debug-device.h b/tools/gfx/debug-layer/debug-device.h
index 5b8424093..90feaa37e 100644
--- a/tools/gfx/debug-layer/debug-device.h
+++ b/tools/gfx/debug-layer/debug-device.h
@@ -94,10 +94,20 @@ public:
slang::TypeReflection* type,
ShaderObjectContainerType container,
IShaderObject** outObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObject2(
+ slang::ISession* session,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType container,
+ IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObject(
slang::TypeReflection* type,
ShaderObjectContainerType container,
IShaderObject** outObject) override;
+ virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObject2(
+ slang::ISession* session,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType container,
+ IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObjectFromTypeLayout(
slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject) override;
virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObjectFromTypeLayout(
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index c9eb1d94d..b5ab14fe8 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -137,6 +137,7 @@ public:
IInputLayout** outLayout) override;
virtual Result createShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) override;
virtual Result createShaderObject(ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
@@ -682,11 +683,12 @@ public:
struct Builder
{
public:
- Builder(RendererBase* renderer)
- : m_renderer(renderer)
+ Builder(RendererBase* renderer, slang::ISession* session)
+ : m_renderer(renderer), m_session(session)
{}
RendererBase* m_renderer;
+ slang::ISession* m_session;
slang::TypeLayoutReflection* m_elementTypeLayout;
/// The container type of this shader object. When `m_containerType` is
@@ -792,6 +794,7 @@ public:
{
createForElementType(
m_renderer,
+ m_session,
slangLeafTypeLayout->getElementTypeLayout(),
subObjectLayout.writeRef());
}
@@ -818,10 +821,11 @@ public:
static Result createForElementType(
RendererBase* renderer,
+ slang::ISession* session,
slang::TypeLayoutReflection* elementType,
ShaderObjectLayoutImpl** outLayout)
{
- Builder builder(renderer);
+ Builder builder(renderer, session);
builder.setElementTypeLayout(elementType);
return builder.build(outLayout);
}
@@ -851,7 +855,7 @@ public:
{
auto renderer = builder->m_renderer;
- initBase(renderer, builder->m_elementTypeLayout);
+ initBase(renderer, builder->m_session, builder->m_elementTypeLayout);
m_bindingRanges = builder->m_bindingRanges;
@@ -889,7 +893,7 @@ public:
RendererBase* renderer,
slang::IComponentType* program,
slang::ProgramLayout* programLayout)
- : Super::Builder(renderer)
+ : Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
{}
@@ -939,7 +943,7 @@ public:
auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
RefPtr<ShaderObjectLayoutImpl> entryPointLayout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- renderer, slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
+ renderer, program->getSession(), slangEntryPoint->getTypeLayout(), entryPointLayout.writeRef()));
builder.addEntryPoint(slangEntryPoint->getStage(), entryPointLayout);
}
@@ -1426,6 +1430,7 @@ public:
auto renderer = getRenderer();
RefPtr<ShaderObjectLayoutImpl> layout;
SLANG_RETURN_ON_FAIL(renderer->getShaderObjectLayout(
+ m_layout->m_slangSession,
extendedType.slangType,
m_layout->getContainerType(),
(ShaderObjectLayoutBase**)layout.writeRef()));
@@ -2898,12 +2903,13 @@ Result GLDevice::createComputePipelineState(const ComputePipelineStateDesc& inDe
}
Result GLDevice::createShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout)
{
RefPtr<ShaderObjectLayoutImpl> layout;
SLANG_RETURN_ON_FAIL(ShaderObjectLayoutImpl::createForElementType(
- this, typeLayout, layout.writeRef()));
+ this, session, typeLayout, layout.writeRef()));
returnRefPtrMove(outLayout, layout);
return SLANG_OK;
}
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp
index 54311dd47..911d4712c 100644
--- a/tools/gfx/renderer-shared.cpp
+++ b/tools/gfx/renderer-shared.cpp
@@ -524,8 +524,17 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObject(
ShaderObjectContainerType container,
IShaderObject** outObject)
{
+ return createShaderObject2(slangContext.session, type, container, outObject);
+}
+
+SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObject2(
+ slang::ISession* slangSession,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType container,
+ IShaderObject** outObject)
+{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(type, container, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangSession, type, container, shaderObjectLayout.writeRef()));
return createShaderObject(shaderObjectLayout, outObject);
}
@@ -534,8 +543,17 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObject(
ShaderObjectContainerType containerType,
IShaderObject** outObject)
{
+ return createMutableShaderObject2(slangContext.session, type, containerType, outObject);
+}
+
+SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObject2(
+ slang::ISession* slangSession,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType containerType,
+ IShaderObject** outObject)
+{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(type, containerType, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangSession, type, containerType, shaderObjectLayout.writeRef()));
return createMutableShaderObject(shaderObjectLayout, outObject);
}
@@ -616,7 +634,7 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createShaderObjectFromTypeLayout
slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
return createShaderObject(shaderObjectLayout, outObject);
}
@@ -624,7 +642,7 @@ SLANG_NO_THROW Result SLANG_MCALL RendererBase::createMutableShaderObjectFromTyp
slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
- SLANG_RETURN_ON_FAIL(getShaderObjectLayout(typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(getShaderObjectLayout(slangContext.session, typeLayout, shaderObjectLayout.writeRef()));
return createMutableShaderObject(shaderObjectLayout, outObject);
}
@@ -702,6 +720,7 @@ Result RendererBase::getTextureRowAlignment(Size* outAlignment)
}
Result RendererBase::getShaderObjectLayout(
+ slang::ISession* session,
slang::TypeReflection* type,
ShaderObjectContainerType container,
ShaderObjectLayoutBase** outLayout)
@@ -709,26 +728,30 @@ Result RendererBase::getShaderObjectLayout(
switch (container)
{
case ShaderObjectContainerType::StructuredBuffer:
- type = slangContext.session->getContainerType(type, slang::ContainerType::StructuredBuffer);
+ type = session->getContainerType(type, slang::ContainerType::StructuredBuffer);
break;
case ShaderObjectContainerType::Array:
- type = slangContext.session->getContainerType(type, slang::ContainerType::UnsizedArray);
+ type = session->getContainerType(type, slang::ContainerType::UnsizedArray);
break;
default:
break;
}
- auto typeLayout = slangContext.session->getTypeLayout(type);
- return getShaderObjectLayout(typeLayout, outLayout);
+ auto typeLayout = session->getTypeLayout(type);
+ SLANG_RETURN_ON_FAIL(getShaderObjectLayout(session, typeLayout, outLayout));
+ (*outLayout)->m_slangSession = session;
+ return SLANG_OK;
}
Result RendererBase::getShaderObjectLayout(
- slang::TypeLayoutReflection* typeLayout, ShaderObjectLayoutBase** outLayout)
+ slang::ISession* session,
+ slang::TypeLayoutReflection* typeLayout,
+ ShaderObjectLayoutBase** outLayout)
{
RefPtr<ShaderObjectLayoutBase> shaderObjectLayout;
if (!m_shaderObjectLayoutCache.tryGetValue(typeLayout, shaderObjectLayout))
{
- SLANG_RETURN_ON_FAIL(createShaderObjectLayout(typeLayout, shaderObjectLayout.writeRef()));
+ SLANG_RETURN_ON_FAIL(createShaderObjectLayout(session, typeLayout, shaderObjectLayout.writeRef()));
m_shaderObjectLayoutCache.add(typeLayout, shaderObjectLayout);
}
*outLayout = shaderObjectLayout.detach();
@@ -830,9 +853,10 @@ void ShaderCache::addSpecializedPipeline(PipelineKey key, Slang::RefPtr<Pipeline
specializedPipelines[key] = specializedPipeline;
}
-void ShaderObjectLayoutBase::initBase(RendererBase* renderer, slang::TypeLayoutReflection* elementTypeLayout)
+void ShaderObjectLayoutBase::initBase(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* elementTypeLayout)
{
m_renderer = renderer;
+ m_slangSession = session;
m_elementTypeLayout = elementTypeLayout;
m_componentID = m_renderer->shaderCache.getComponentId(m_elementTypeLayout->getType());
}
@@ -887,15 +911,12 @@ Result ShaderObjectBase::setExistentialHeader(
// Slang runtime, so we can look up the ID for this particular conformance (which
// will create it on demand).
//
- ComPtr<slang::ISession> slangSession;
- SLANG_RETURN_ON_FAIL(getRenderer()->getSlangSession(slangSession.writeRef()));
- //
// Note: If the type doesn't actually conform to the required interface for
// this sub-object range, then this is the point where we will detect that
// fact and error out.
//
uint32_t conformanceID = 0xFFFFFFFF;
- SLANG_RETURN_ON_FAIL(slangSession->getTypeConformanceWitnessSequentialID(
+ SLANG_RETURN_ON_FAIL(getLayoutBase()->m_slangSession->getTypeConformanceWitnessSequentialID(
concreteType, existentialType, &conformanceID));
//
// Once we have the conformance ID, then we can write it into the object
diff --git a/tools/gfx/renderer-shared.h b/tools/gfx/renderer-shared.h
index 5c67de885..4d88f945b 100644
--- a/tools/gfx/renderer-shared.h
+++ b/tools/gfx/renderer-shared.h
@@ -390,6 +390,8 @@ protected:
ShaderObjectContainerType m_containerType = ShaderObjectContainerType::None;
public:
+ ComPtr<slang::ISession> m_slangSession;
+
ShaderObjectContainerType getContainerType() { return m_containerType; }
static slang::TypeLayoutReflection* _unwrapParameterGroups(
@@ -444,7 +446,7 @@ public:
return m_componentID;
}
- void initBase(RendererBase* renderer, slang::TypeLayoutReflection* elementTypeLayout);
+ void initBase(RendererBase* renderer, slang::ISession* session, slang::TypeLayoutReflection* elementTypeLayout);
};
class SimpleShaderObjectData
@@ -495,7 +497,6 @@ protected:
// The specialized shader object type.
ExtendedShaderObjectType shaderObjectType = { nullptr, kInvalidComponentID };
-
Result _getSpecializedShaderObjectType(ExtendedShaderObjectType* outType);
slang::TypeLayoutReflection* _getElementTypeLayout()
{
@@ -1265,11 +1266,23 @@ public:
ShaderObjectContainerType containerType,
IShaderObject** outObject) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObject2(
+ slang::ISession* session,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType containerType,
+ IShaderObject** outObject) SLANG_OVERRIDE;
+
virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObject(
slang::TypeReflection* type,
ShaderObjectContainerType containerType,
IShaderObject** outObject) SLANG_OVERRIDE;
+ virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObject2(
+ slang::ISession* session,
+ slang::TypeReflection* type,
+ ShaderObjectContainerType containerType,
+ IShaderObject** outObject) SLANG_OVERRIDE;
+
virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObjectFromTypeLayout(
slang::TypeLayoutReflection* typeLayout, IShaderObject** outObject) override;
@@ -1325,11 +1338,13 @@ public:
slang::IBlob** outDiagnostics = nullptr);
Result getShaderObjectLayout(
+ slang::ISession* session,
slang::TypeReflection* type,
ShaderObjectContainerType container,
ShaderObjectLayoutBase** outLayout);
Result getShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout);
@@ -1345,6 +1360,7 @@ public:
virtual Result createShaderObjectLayout(
+ slang::ISession* session,
slang::TypeLayoutReflection* typeLayout,
ShaderObjectLayoutBase** outLayout) = 0;
diff --git a/tools/gfx/slang.slang b/tools/gfx/slang.slang
index 4e2700c2c..26ad7dce0 100644
--- a/tools/gfx/slang.slang
+++ b/tools/gfx/slang.slang
@@ -331,17 +331,7 @@ public struct TargetDesc
public enum SessionFlags
{
- kSessionFlags_None = 0,
-
- /** Use application-specific policy for semantics of the `shared` keyword.
-
- This is a legacy/compatibility flag to help an existing Slang client
- migrate to new language features, and should *not* be used by other
- clients. This feature may be removed in a future release without a
- deprecation warning, and this bit may be re-used for another feature.
- You have been warned.
- */
- kSessionFlag_FalcorCustomSharedKeywordSemantics = 1 << 0,
+ kSessionFlags_None = 0
};
public struct PreprocessorMacroDesc
diff --git a/tools/gfx/vulkan/vk-device.cpp b/tools/gfx/vulkan/vk-device.cpp
index 4f2899f1b..e1b1eaf27 100644
--- a/tools/gfx/vulkan/vk-device.cpp
+++ b/tools/gfx/vulkan/vk-device.cpp
@@ -2168,11 +2168,13 @@ Result DeviceImpl::createProgram(
}
Result DeviceImpl::createShaderObjectLayout(
- slang::TypeLayoutReflection* typeLayout, ShaderObjectLayoutBase** outLayout)
+ slang::ISession* session,
+ slang::TypeLayoutReflection* typeLayout,
+ ShaderObjectLayoutBase** outLayout)
{
RefPtr<ShaderObjectLayoutImpl> layout;
SLANG_RETURN_ON_FAIL(
- ShaderObjectLayoutImpl::createForElementType(this, typeLayout, layout.writeRef()));
+ ShaderObjectLayoutImpl::createForElementType(this, session, typeLayout, layout.writeRef()));
returnRefPtrMove(outLayout, layout);
return SLANG_OK;
}
diff --git a/tools/gfx/vulkan/vk-device.h b/tools/gfx/vulkan/vk-device.h
index 9731fd1d4..89c7aa103 100644
--- a/tools/gfx/vulkan/vk-device.h
+++ b/tools/gfx/vulkan/vk-device.h
@@ -66,7 +66,9 @@ public:
createInputLayout(IInputLayout::Desc const& desc, IInputLayout** outLayout) override;
virtual Result createShaderObjectLayout(
- slang::TypeLayoutReflection* typeLayout, ShaderObjectLayoutBase** outLayout) override;
+ slang::ISession* session,
+ slang::TypeLayoutReflection* typeLayout,
+ ShaderObjectLayoutBase** outLayout) override;
virtual Result createShaderObject(
ShaderObjectLayoutBase* layout, IShaderObject** outObject) override;
virtual Result createMutableShaderObject(
diff --git a/tools/gfx/vulkan/vk-shader-object-layout.cpp b/tools/gfx/vulkan/vk-shader-object-layout.cpp
index d7f0d0fd0..d84627e86 100644
--- a/tools/gfx/vulkan/vk-shader-object-layout.cpp
+++ b/tools/gfx/vulkan/vk-shader-object-layout.cpp
@@ -449,7 +449,7 @@ void ShaderObjectLayoutImpl::Builder::addBindingRanges(slang::TypeLayoutReflecti
auto varLayout = slangLeafTypeLayout->getElementVarLayout();
auto subTypeLayout = varLayout->getTypeLayout();
ShaderObjectLayoutImpl::createForElementType(
- m_renderer, subTypeLayout, subObjectLayout.writeRef());
+ m_renderer, m_session, subTypeLayout, subObjectLayout.writeRef());
}
break;
@@ -457,7 +457,7 @@ void ShaderObjectLayoutImpl::Builder::addBindingRanges(slang::TypeLayoutReflecti
if (auto pendingTypeLayout = slangLeafTypeLayout->getPendingDataTypeLayout())
{
ShaderObjectLayoutImpl::createForElementType(
- m_renderer, pendingTypeLayout, subObjectLayout.writeRef());
+ m_renderer, m_session, pendingTypeLayout, subObjectLayout.writeRef());
}
break;
}
@@ -551,10 +551,11 @@ SlangResult ShaderObjectLayoutImpl::Builder::build(ShaderObjectLayoutImpl** outL
Result ShaderObjectLayoutImpl::createForElementType(
DeviceImpl* renderer,
+ slang::ISession* session,
slang::TypeLayoutReflection* elementType,
ShaderObjectLayoutImpl** outLayout)
{
- Builder builder(renderer);
+ Builder builder(renderer, session);
builder.setElementTypeLayout(elementType);
// When constructing a shader object layout directly from a reflected
@@ -618,7 +619,7 @@ Result ShaderObjectLayoutImpl::_init(Builder const* builder)
{
auto renderer = builder->m_renderer;
- initBase(renderer, builder->m_elementTypeLayout);
+ initBase(renderer, builder->m_session, builder->m_elementTypeLayout);
m_bindingRanges = builder->m_bindingRanges;
@@ -722,7 +723,7 @@ Result RootShaderObjectLayout::create(
{
auto slangEntryPoint = programLayout->getEntryPointByIndex(e);
- EntryPointLayout::Builder entryPointBuilder(renderer);
+ EntryPointLayout::Builder entryPointBuilder(renderer, program->getSession());
entryPointBuilder.addEntryPointParams(slangEntryPoint);
RefPtr<EntryPointLayout> entryPointLayout;
diff --git a/tools/gfx/vulkan/vk-shader-object-layout.h b/tools/gfx/vulkan/vk-shader-object-layout.h
index 1d2b08b6c..3f60e6b89 100644
--- a/tools/gfx/vulkan/vk-shader-object-layout.h
+++ b/tools/gfx/vulkan/vk-shader-object-layout.h
@@ -134,11 +134,12 @@ public:
struct Builder
{
public:
- Builder(DeviceImpl* renderer)
- : m_renderer(renderer)
+ Builder(DeviceImpl* renderer, slang::ISession* session)
+ : m_renderer(renderer), m_session(session)
{}
DeviceImpl* m_renderer;
+ slang::ISession* m_session;
slang::TypeLayoutReflection* m_elementTypeLayout;
/// The container type of this shader object. When `m_containerType` is
@@ -214,6 +215,7 @@ public:
static Result createForElementType(
DeviceImpl* renderer,
+ slang::ISession* session,
slang::TypeLayoutReflection* elementType,
ShaderObjectLayoutImpl** outLayout);
@@ -321,8 +323,8 @@ class EntryPointLayout : public ShaderObjectLayoutImpl
public:
struct Builder : Super::Builder
{
- Builder(DeviceImpl* device)
- : Super::Builder(device)
+ Builder(DeviceImpl* device, slang::ISession* session)
+ : Super::Builder(device, session)
{}
Result build(EntryPointLayout** outLayout);
@@ -367,7 +369,7 @@ public:
DeviceImpl* renderer,
slang::IComponentType* program,
slang::ProgramLayout* programLayout)
- : Super::Builder(renderer)
+ : Super::Builder(renderer, program->getSession())
, m_program(program)
, m_programLayout(programLayout)
{}
diff --git a/tools/gfx/vulkan/vk-shader-object.cpp b/tools/gfx/vulkan/vk-shader-object.cpp
index 31422429b..77707eac0 100644
--- a/tools/gfx/vulkan/vk-shader-object.cpp
+++ b/tools/gfx/vulkan/vk-shader-object.cpp
@@ -977,6 +977,7 @@ Result ShaderObjectImpl::_createSpecializedLayout(ShaderObjectLayoutImpl** outLa
auto device = getDevice();
RefPtr<ShaderObjectLayoutImpl> layout;
SLANG_RETURN_ON_FAIL(device->getShaderObjectLayout(
+ m_layout->m_slangSession,
extendedType.slangType,
m_layout->getContainerType(),
(ShaderObjectLayoutBase**)layout.writeRef()));
diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp
index 4b62eb60b..1d7c3cc2e 100644
--- a/tools/render-test/options.cpp
+++ b/tools/render-test/options.cpp
@@ -62,7 +62,6 @@ static gfx::DeviceType _toRenderType(Slang::RenderApiType apiType)
{
args.setArgs(argv, argc);
}
-
SLANG_RETURN_ON_FAIL(outOptions.downstreamArgs.stripDownstreamArgs(args, 0, &sink));
CommandLineReader reader(&args, &sink);
diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp
index 1f2b3a5ae..02c0ea86a 100644
--- a/tools/render-test/render-test-main.cpp
+++ b/tools/render-test/render-test-main.cpp
@@ -153,16 +153,19 @@ protected:
struct AssignValsFromLayoutContext
{
IDevice* device;
+ slang::ISession* slangSession;
ShaderOutputPlan& outputPlan;
slang::ProgramLayout* slangReflection;
IAccelerationStructure* accelerationStructure;
AssignValsFromLayoutContext(
IDevice* device,
+ slang::ISession* slangSession,
ShaderOutputPlan& outputPlan,
slang::ProgramLayout* slangReflection,
IAccelerationStructure* accelerationStructure)
: device(device)
+ , slangSession(slangSession)
, outputPlan(outputPlan)
, slangReflection(slangReflection)
, accelerationStructure(accelerationStructure)
@@ -389,7 +392,8 @@ struct AssignValsFromLayoutContext
slangType = slangTypeLayout->getType();
}
- ComPtr<IShaderObject> shaderObject = device->createShaderObject(slangType);
+ ComPtr<IShaderObject> shaderObject;
+ device->createShaderObject2(slangSession, slangType, ShaderObjectContainerType::None, shaderObject.writeRef());
SLANG_RETURN_ON_FAIL(assign(ShaderCursor(shaderObject), srcVal->contentVal));
dstCursor.setObject(shaderObject);
@@ -478,15 +482,16 @@ struct AssignValsFromLayoutContext
};
SlangResult _assignVarsFromLayout(
- IDevice* device,
- IShaderObject* shaderObject,
+ IDevice* device,
+ slang::ISession* slangSession,
+ IShaderObject* shaderObject,
ShaderInputLayout const& layout,
ShaderOutputPlan& ioOutputPlan,
slang::ProgramLayout* slangReflection,
IAccelerationStructure* accelerationStructure)
{
AssignValsFromLayoutContext context(
- device, ioOutputPlan, slangReflection, accelerationStructure);
+ device, slangSession, ioOutputPlan, slangReflection, accelerationStructure);
ShaderCursor rootCursor = ShaderCursor(shaderObject);
return context.assign(rootCursor, layout.rootVal);
}
@@ -495,6 +500,8 @@ Result RenderTestApp::applyBinding(PipelineType pipelineType, ICommandEncoder* e
{
auto slangReflection = (slang::ProgramLayout*)spGetReflection(
m_compilationOutput.output.getRequestForReflection());
+ ComPtr<slang::ISession> slangSession;
+ m_compilationOutput.output.m_requestForKernels->getSession(slangSession.writeRef());
switch (pipelineType)
{
@@ -504,6 +511,7 @@ Result RenderTestApp::applyBinding(PipelineType pipelineType, ICommandEncoder* e
auto rootObject = computeEncoder->bindPipeline(m_pipelineState);
SLANG_RETURN_ON_FAIL(_assignVarsFromLayout(
m_device,
+ slangSession,
rootObject,
m_compilationOutput.layout,
m_outputPlan,
@@ -517,6 +525,7 @@ Result RenderTestApp::applyBinding(PipelineType pipelineType, ICommandEncoder* e
auto rootObject = renderEncoder->bindPipeline(m_pipelineState);
SLANG_RETURN_ON_FAIL(_assignVarsFromLayout(
m_device,
+ slangSession,
rootObject,
m_compilationOutput.layout,
m_outputPlan,
@@ -541,7 +550,7 @@ SlangResult RenderTestApp::initialize(
// We begin by compiling the shader file and entry points that specified via the options.
//
- SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession(), options, input, m_compilationOutput));
+ SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession()->getGlobalSession(), options, input, m_compilationOutput));
m_shaderInputLayout = m_compilationOutput.layout;
// Once the shaders have been compiled we load them via the underlying API.
@@ -641,7 +650,7 @@ Result RenderTestApp::_initializeShaders(
Options::ShaderProgramType shaderType,
const ShaderCompilerUtil::Input& input)
{
- SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession(), m_options, input, m_compilationOutput));
+ SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession()->getGlobalSession(), m_options, input, m_compilationOutput));
m_shaderInputLayout = m_compilationOutput.layout;
m_shaderProgram = device->createProgram(m_compilationOutput.output.desc);
return m_shaderProgram ? SLANG_OK : SLANG_FAIL;
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index c598e4ea5..f585abe5b 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -71,14 +71,19 @@ void ShaderCompilerUtil::Output::reset()
m_extraRequestForReflection = nullptr;
}
-/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
+/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(slang::IGlobalSession* globalSession, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
{
out.reset();
+ slang::SessionDesc sessionDesc = {};
+ List<slang::PreprocessorMacroDesc> macros;
+ sessionDesc.preprocessorMacroCount = (SlangInt)macros.getCount();
+ sessionDesc.preprocessorMacros = macros.getBuffer();
+
ComPtr<SlangCompileRequest> slangRequest = nullptr;
- session->createCompileRequest(slangRequest.writeRef());
+ globalSession->createCompileRequest(slangRequest.writeRef());
out.m_requestForKernels = slangRequest;
- out.session = session->getGlobalSession();
+ out.session = globalSession;
// Parse all the extra args
{
@@ -104,7 +109,6 @@ void ShaderCompilerUtil::Output::reset()
}
}
}
-
spSetCodeGenTarget(slangRequest, input.target);
spSetTargetProfile(slangRequest, 0, spFindProfile(out.session, input.profile.getBuffer()));
if (options.generateSPIRVDirectly)
@@ -283,11 +287,11 @@ void ShaderCompilerUtil::Output::reset()
return SLANG_OK;
}
-/* static */ SlangResult ShaderCompilerUtil::compileProgram(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
+/* static */ SlangResult ShaderCompilerUtil::compileProgram(slang::IGlobalSession* globalSession, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out)
{
if( input.passThrough == SLANG_PASS_THROUGH_NONE )
{
- return _compileProgramImpl(session, options, input, request, out);
+ return _compileProgramImpl(globalSession, options, input, request, out);
}
else
{
@@ -317,7 +321,7 @@ void ShaderCompilerUtil::Output::reset()
// TODO: we want to pass along a flag to skip codegen...
- SLANG_RETURN_ON_FAIL(_compileProgramImpl(session, options, slangInput, request, slangOutput));
+ SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, slangInput, request, slangOutput));
}
// Now we have what we need to be able to do the downstream compile better.
@@ -326,7 +330,7 @@ void ShaderCompilerUtil::Output::reset()
// to fill in the actual entry points to be used for this compilation,
// so that discovery of entry points via `[shader(...)]` attributes will work.
//
- SLANG_RETURN_ON_FAIL(_compileProgramImpl(session, options, input, request, out));
+ SLANG_RETURN_ON_FAIL(_compileProgramImpl(globalSession, options, input, request, out));
out.m_extraRequestForReflection = slangOutput.getRequestForReflection();
out.desc.slangGlobalScope = slangOutput.desc.slangGlobalScope;
@@ -361,7 +365,11 @@ void ShaderCompilerUtil::Output::reset()
return SLANG_OK;
}
-/* static */SlangResult ShaderCompilerUtil::compileWithLayout(slang::ISession* session, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output)
+/* static */SlangResult ShaderCompilerUtil::compileWithLayout(
+ slang::IGlobalSession* globalSession,
+ const Options& options,
+ const ShaderCompilerUtil::Input& input,
+ OutputAndLayout& output)
{
String sourcePath = options.sourcePath;
auto shaderType = options.shaderType;
@@ -373,7 +381,7 @@ void ShaderCompilerUtil::Output::reset()
{
// Add an include of the prelude
ComPtr<ISlangBlob> prelude;
- session->getGlobalSession()->getLanguagePrelude(input.sourceLanguage, prelude.writeRef());
+ globalSession->getLanguagePrelude(input.sourceLanguage, prelude.writeRef());
String preludeString = StringUtil::getString(prelude);
@@ -498,7 +506,7 @@ void ShaderCompilerUtil::Output::reset()
c.idOverride = conformance.idOverride;
compileRequest.typeConformances.add(c);
}
- return ShaderCompilerUtil::compileProgram(session, options, input, compileRequest, output.output);
+ return ShaderCompilerUtil::compileProgram(globalSession, options, input, compileRequest, output.output);
}
} // renderer_test
diff --git a/tools/render-test/slang-support.h b/tools/render-test/slang-support.h
index 9e06ef77c..6eef93edc 100644
--- a/tools/render-test/slang-support.h
+++ b/tools/render-test/slang-support.h
@@ -93,12 +93,12 @@ struct ShaderCompilerUtil
Slang::String sourcePath;
};
- static SlangResult compileWithLayout(slang::ISession* session, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output);
+ static SlangResult compileWithLayout(slang::IGlobalSession* globalSession, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output);
static SlangResult readSource(const Slang::String& inSourcePath, Slang::List<char>& outSourceText);
- static SlangResult _compileProgramImpl(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out);
- static SlangResult compileProgram(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out);
+ static SlangResult _compileProgramImpl(slang::IGlobalSession* globalSession, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out);
+ static SlangResult compileProgram(slang::IGlobalSession* globalSession, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out);
};
diff --git a/tools/slang-test/slangc-tool.cpp b/tools/slang-test/slangc-tool.cpp
index 4c2a3244c..55788d06b 100644
--- a/tools/slang-test/slangc-tool.cpp
+++ b/tools/slang-test/slangc-tool.cpp
@@ -45,14 +45,7 @@ SlangResult SlangCTool::innerMain(StdWriters* stdWriters, slang::IGlobalSession*
compileRequest->setDiagnosticCallback(&_diagnosticCallback, nullptr);
compileRequest->setCommandLineCompilerMode();
- {
- const SlangResult res = compileRequest->processCommandLineArguments(&argv[1], argc - 1);
- if (SLANG_FAILED(res))
- {
- StdWriters::getOut().print("%s", compileRequest->getDiagnosticOutput());
- return res;
- }
- }
+ SLANG_RETURN_ON_FAIL(compileRequest->processCommandLineArguments(&argv[1], argc - 1));
SlangResult compileRes = SLANG_OK;