diff options
| author | Yong He <yonghe@outlook.com> | 2021-06-02 16:58:25 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-02 16:58:25 -0700 |
| commit | e67af5b1a3993529c702ff2924dea11fd1017d2e (patch) | |
| tree | c4359fb6df6110d81a658278aef9ab7244af5496 | |
| parent | 8e571669b3c8d4ac8236d0aed7a960bf88ad2bd1 (diff) | |
Various Fixes to gfx, reflection and emit. (#1867)
* Various Fixes to gfx, reflection and emit.
- Fix GLSL emit to properly output `*bitsTo*` functions for `IRBitCast` insts.
- Add line directive mode setting for `ISession`.
- Extend `TypeLayout::getElementStride` to handle `VectorType` case.
- Fix `IDevice::readBufferResource` 's D3D12 implementation to copy only the requested bytes out.
- Fix `render-test` to use the `ISession` from `gfx` instead of creating its own `ISession` to make sure `gfx` and `render-test` agree on WitnessTable and RTTI IDs.
- Extend `render-test` to support filling vector and matrix values in the new `set x = ...` TEST_INPUT syntax.
- Add a `dynamic-dispatch-15` test case to make sure packing / unpacking works correctly across all targets, and to make sure render-test's RTTI/WitnessTable ID filling logic is correct for non-trivial cases.
* Remove default-major test
* Fix cyclic reference in `ExtendedTypeLayout`.
* Move `lineDirectiveMode` setting to `TargetDesc`.
Add `structureSize` to `TargetDesc` and `SessionDesc` for future binary compatibility.
* Cleanup.
Co-authored-by: Yong He <yhe@nvidia.com>
| -rw-r--r-- | slang-gfx.h | 1 | ||||
| -rw-r--r-- | slang.h | 27 | ||||
| -rw-r--r-- | source/slang/slang-api.cpp | 9 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/slang/slang-compiler.cpp | 1 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 26 | ||||
| -rw-r--r-- | source/slang/slang-emit-c-like.h | 1 | ||||
| -rw-r--r-- | source/slang/slang-emit-glsl.cpp | 31 | ||||
| -rw-r--r-- | source/slang/slang-emit.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-reflection-api.cpp | 15 | ||||
| -rw-r--r-- | source/slang/slang-repro.cpp | 1 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 40 | ||||
| -rw-r--r-- | tests/compute/default-major.slang | 11 | ||||
| -rw-r--r-- | tests/compute/dynamic-dispatch-15.slang | 82 | ||||
| -rw-r--r-- | tests/compute/dynamic-dispatch-15.slang.expected.txt | 2 | ||||
| -rw-r--r-- | tools/gfx-util/shader-cursor.cpp | 13 | ||||
| -rw-r--r-- | tools/gfx/d3d12/render-d3d12.cpp | 10 | ||||
| -rw-r--r-- | tools/gfx/slang-context.h | 1 | ||||
| -rw-r--r-- | tools/render-test/render-test-main.cpp | 7 | ||||
| -rw-r--r-- | tools/render-test/slang-support.cpp | 25 | ||||
| -rw-r--r-- | tools/render-test/slang-support.h | 10 |
20 files changed, 260 insertions, 55 deletions
diff --git a/slang-gfx.h b/slang-gfx.h index 959f3282b..83ecd0b29 100644 --- a/slang-gfx.h +++ b/slang-gfx.h @@ -1140,6 +1140,7 @@ public: SlangFloatingPointMode floatingPointMode = SLANG_FLOATING_POINT_MODE_DEFAULT; SlangOptimizationLevel optimizationLevel = SLANG_OPTIMIZATION_LEVEL_DEFAULT; SlangTargetFlags targetFlags = 0; + SlangLineDirectiveMode lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_DEFAULT; }; struct Desc @@ -1317,10 +1317,17 @@ extern "C" SlangCompileRequest* request, const char* prefix); - /*! @see slang::ICompileRequest::setLineDirectiveMode */ + /*! DEPRECATED: use `spSetTargetLineDirectiveMode` instead. + @see slang::ICompileRequest::setLineDirectiveMode */ SLANG_API void spSetLineDirectiveMode( SlangCompileRequest* request, SlangLineDirectiveMode mode); + + /*! @see slang::ICompileRequest::setTargetLineDirectiveMode */ + SLANG_API void spSetTargetLineDirectiveMode( + SlangCompileRequest* request, + int targetIndex, + SlangLineDirectiveMode mode); /*! @see slang::ICompileRequest::setCodeGenTarget */ SLANG_API void spSetCodeGenTarget( @@ -3784,6 +3791,11 @@ namespace slang virtual SLANG_NO_THROW SlangResult SLANG_MCALL getProgramWithEntryPoints( slang::IComponentType** outProgram) = 0; + /** Set the line directive mode for a target. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setTargetLineDirectiveMode( + SlangInt targetIndex, + SlangLineDirectiveMode mode) = 0; }; #define SLANG_UUID_ICompileRequest ICompileRequest::getTypeGuid() @@ -3792,6 +3804,10 @@ namespace slang */ struct TargetDesc { + /** The size of this structure, in bytes. + */ + size_t structureSize = sizeof(TargetDesc); + /** The target format to generate code for (e.g., SPIR-V, DXIL, etc.) */ SlangCompileTarget format = SLANG_TARGET_UNKNOWN; @@ -3810,6 +3826,10 @@ namespace slang /** Optimization level to use for the target. */ SlangOptimizationLevel optimizationLevel = SLANG_OPTIMIZATION_LEVEL_DEFAULT; + + /** The line directive mode for output source code. + */ + SlangLineDirectiveMode lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_DEFAULT; }; typedef uint32_t SessionFlags; @@ -3836,6 +3856,10 @@ namespace slang struct SessionDesc { + /** The size of this structure, in bytes. + */ + size_t structureSize = sizeof(SessionDesc); + /** Code generation targets to include in the session. */ TargetDesc const* targets = nullptr; @@ -3856,7 +3880,6 @@ namespace slang PreprocessorMacroDesc const* preprocessorMacros = nullptr; SlangInt preprocessorMacroCount = 0; - }; enum class ContainerType diff --git a/source/slang/slang-api.cpp b/source/slang/slang-api.cpp index 8347b8c30..a00d993e3 100644 --- a/source/slang/slang-api.cpp +++ b/source/slang/slang-api.cpp @@ -272,6 +272,15 @@ SLANG_API void spSetLineDirectiveMode( request->setLineDirectiveMode(mode); } +SLANG_API void spSetTargetLineDirectiveMode( + slang::ICompileRequest* request, + int targetIndex, + SlangLineDirectiveMode mode) +{ + SLANG_ASSERT(request); + request->setTargetLineDirectiveMode(targetIndex, mode); +} + SLANG_API void spSetCommandLineCompilerMode( slang::ICompileRequest* request) { diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index c90b12722..d909a190c 100755..100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -1961,7 +1961,6 @@ namespace Slang m_program->getLinkage(), sink, m_program); - backEndRequest->shouldDumpIR = (m_targetReq->getTargetFlags() & SLANG_TARGET_FLAG_DUMP_IR) != 0; diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 8aaf1bb0b..0742859f1 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -1178,6 +1178,10 @@ namespace Slang { floatingPointMode = mode; } + void setLineDirectiveMode(LineDirectiveMode mode) + { + lineDirectiveMode = mode; + } void addCapability(CapabilityAtom capability); @@ -1190,6 +1194,7 @@ namespace Slang CodeGenTarget getTarget() { return format; } Profile getTargetProfile() { return targetProfile; } FloatingPointMode getFloatingPointMode() { return floatingPointMode; } + LineDirectiveMode getLineDirectiveMode() { return lineDirectiveMode; } SlangTargetFlags getTargetFlags() { return targetFlags; } CapabilitySet getTargetCaps(); @@ -1211,6 +1216,7 @@ namespace Slang FloatingPointMode floatingPointMode = FloatingPointMode::Default; List<CapabilityAtom> rawCapabilities; CapabilitySet cookedCapabilities; + LineDirectiveMode lineDirectiveMode = LineDirectiveMode::Default; }; /// Are we generating code for a D3D API? @@ -1867,11 +1873,6 @@ namespace Slang // Should we dump intermediate results along the way, for debugging? bool shouldDumpIntermediates = false; - // How should `#line` directives be emitted (if at all)? - LineDirectiveMode lineDirectiveMode = LineDirectiveMode::Default; - - LineDirectiveMode getLineDirectiveMode() { return lineDirectiveMode; } - ComponentType* getProgram() { return m_program; } void setProgram(ComponentType* program) { m_program = program; } @@ -1976,7 +1977,9 @@ namespace Slang virtual SLANG_NO_THROW void SLANG_MCALL setCommandLineCompilerMode() SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL addTargetCapability(SlangInt targetIndex, SlangCapabilityID capability) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL getProgramWithEntryPoints(slang::IComponentType** outProgram) SLANG_OVERRIDE; - + virtual SLANG_NO_THROW void SLANG_MCALL setTargetLineDirectiveMode( + SlangInt targetIndex, + SlangLineDirectiveMode mode) SLANG_OVERRIDE; EndToEndCompileRequest( Session* session); @@ -2018,6 +2021,11 @@ namespace Slang /// A blob holding the diagnostic output ComPtr<ISlangBlob> m_diagnosticOutputBlob; + /// Line directive mode for new targets to be added to this request. + /// This is needed to support the legacy `setLineDirectiveMode` API. + /// We can remove this field if we move to `setTargetLineDirectiveMode`. + LineDirectiveMode m_lineDirectiveMode = LineDirectiveMode::Default; + /// Per-entry-point information not tracked by other compile requests class EntryPointInfo : public RefObject { @@ -2083,7 +2091,11 @@ namespace Slang { return m_specializedEntryPoints[index]; } - + ~EndToEndCompileRequest() + { + m_linkage = nullptr; + m_frontEndReq = nullptr; + } private: ISlangUnknown* getInterface(const Guid& guid); diff --git a/source/slang/slang-emit-c-like.h b/source/slang/slang-emit-c-like.h index 16d03989c..90db7476c 100644 --- a/source/slang/slang-emit-c-like.h +++ b/source/slang/slang-emit-c-like.h @@ -195,7 +195,6 @@ public: /// Get the diagnostic sink DiagnosticSink* getSink() { return m_compileRequest->getSink();} - LineDirectiveMode getLineDirectiveMode() { return m_compileRequest->getLineDirectiveMode(); } /// Get the code gen target CodeGenTarget getTarget() { return m_target; } diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index b5eec456a..82804c6b5 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -1404,6 +1404,7 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu case kIROp_BitCast: { auto toType = extractBaseType(inst->getDataType()); + auto fromType = extractBaseType(inst->getOperand(0)->getDataType()); switch (toType) { default: @@ -1411,14 +1412,40 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu break; case BaseType::UInt: + if (fromType == BaseType::Float) + { + m_writer->emit("floatBitsToUint"); + } + else + { + emitType(inst->getDataType()); + } break; case BaseType::Int: - emitType(inst->getDataType()); + if (fromType == BaseType::Float) + { + m_writer->emit("floatBitsToInt"); + } + else + { + emitType(inst->getDataType()); + } break; case BaseType::Float: - m_writer->emit("uintBitsToFloat"); + switch (fromType) + { + case BaseType::Int: + m_writer->emit("intBitsToFloat"); + break; + case BaseType::UInt: + m_writer->emit("uintBitsToFloat"); + break; + default: + emitType(inst->getDataType()); + break; + } break; } diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 623b79a1f..12dd80135 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -729,7 +729,7 @@ SlangResult emitEntryPointsSourceFromIR( auto sink = compileRequest->getSink(); auto program = compileRequest->getProgram(); - auto lineDirectiveMode = compileRequest->getLineDirectiveMode(); + auto lineDirectiveMode = targetRequest->getLineDirectiveMode(); // To try to make the default behavior reasonable, we will // always use C-style line directives (to give the user // good source locations on error messages from downstream diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 059de0be8..00ecfdbc1 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -946,6 +946,12 @@ SLANG_API size_t spReflectionTypeLayout_GetElementStride(SlangReflectionTypeLayo return 0; } } + else if (auto vectorTypeLayout = as<VectorTypeLayout>(typeLayout)) + { + auto resInfo = vectorTypeLayout->elementTypeLayout->FindResourceInfo(LayoutResourceKind::Uniform); + if (!resInfo) return 0; + return resInfo->count.getFiniteValue(); + } return 0; } @@ -971,7 +977,14 @@ SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_GetElementTypeLayout { return convert(specializedTypeLayout->baseTypeLayout.Ptr()); } - + else if (auto vectorTypeLayout = as<VectorTypeLayout>(typeLayout)) + { + return convert(vectorTypeLayout->elementTypeLayout); + } + else if (auto matrixTypeLayout = as<MatrixTypeLayout>(typeLayout)) + { + return convert(matrixTypeLayout->elementTypeLayout); + } return nullptr; } diff --git a/source/slang/slang-repro.cpp b/source/slang/slang-repro.cpp index d8688f4a3..4b3148278 100644 --- a/source/slang/slang-repro.cpp +++ b/source/slang/slang-repro.cpp @@ -363,7 +363,6 @@ static String _scrubName(const String& in) dst->compileFlags = request->getFrontEndReq()->compileFlags; dst->shouldDumpIntermediates = request->getBackEndReq()->shouldDumpIntermediates; - dst->lineDirectiveMode = request->getBackEndReq()->lineDirectiveMode; dst->debugInfoLevel = linkage->debugInfoLevel; dst->optimizationLevel = linkage->optimizationLevel; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 613992354..9d2d766b9 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -445,9 +445,16 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::createSession( RefPtr<Linkage> linkage = new Linkage(this, astBuilder, getBuiltinLinkage()); Int targetCount = desc.targetCount; + const uint8_t* targetDescPtr = reinterpret_cast<const uint8_t*>(desc.targets); for(Int ii = 0; ii < targetCount; ++ii) { - linkage->addTarget(desc.targets[ii]); + slang::TargetDesc targetDesc; + // Copy the size field first. + memcpy(&targetDesc.structureSize, targetDescPtr, sizeof(size_t)); + // Copy the entire desc structure. + memcpy(&targetDesc, targetDescPtr, targetDesc.structureSize); + linkage->addTarget(targetDesc); + targetDescPtr += targetDesc.structureSize; } if(desc.flags & slang::kSessionFlag_FalcorCustomSharedKeywordSemantics) @@ -793,6 +800,7 @@ void Linkage::addTarget( target->setFloatingPointMode(FloatingPointMode(desc.floatingPointMode)); target->addTargetFlags(desc.flags); target->setTargetProfile(Profile(desc.profile)); + target->setLineDirectiveMode(LineDirectiveMode(desc.lineDirectiveMode)); } #if 0 @@ -1034,6 +1042,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Linkage::createCompileRequest( SlangCompileRequest** outCompileRequest) { auto compileRequest = new EndToEndCompileRequest(this); + compileRequest->addRef(); *outCompileRequest = asExternal(compileRequest); return SLANG_OK; } @@ -1060,7 +1069,6 @@ SlangResult Linkage::setMatrixLayoutMode( return SLANG_OK; } - // // TargetRequest // @@ -2009,7 +2017,9 @@ BackEndCompileRequest::BackEndCompileRequest( : CompileRequestBase(linkage, sink) , m_program(program) , m_dumpIntermediatePrefix("slang-dump-") -{} + +{ +} EndToEndCompileRequest::EndToEndCompileRequest( Session* session) @@ -3840,8 +3850,16 @@ void EndToEndCompileRequest::setDumpIntermediatePrefix(const char* prefix) void EndToEndCompileRequest::setLineDirectiveMode(SlangLineDirectiveMode mode) { - // TODO: validation - getBackEndReq()->lineDirectiveMode = LineDirectiveMode(mode); + // This method is deprecated and user should call `setTargetLineDirectiveMode` instead. + // We provide the implementation here for backward compatibility. + // Targets added later will use `m_lineDirectiveMode`, so we update it to the new `mode` + // set by the user. + m_lineDirectiveMode = LineDirectiveMode(mode); + + // Change all existing targets to use the new mode. + auto linkage = getLinkage(); + for (auto& target : linkage->targets) + target->setLineDirectiveMode(m_lineDirectiveMode); } void EndToEndCompileRequest::setCommandLineCompilerMode() @@ -3854,11 +3872,14 @@ void EndToEndCompileRequest::setCodeGenTarget(SlangCompileTarget target) auto linkage = getLinkage(); linkage->targets.clear(); linkage->addTarget(CodeGenTarget(target)); + linkage->targets[0]->setLineDirectiveMode(m_lineDirectiveMode); } int EndToEndCompileRequest::addCodeGenTarget(SlangCompileTarget target) { - return (int)getLinkage()->addTarget(CodeGenTarget(target)); + int targetIndex = (int)getLinkage()->addTarget(CodeGenTarget(target)); + getLinkage()->targets[targetIndex]->setLineDirectiveMode(m_lineDirectiveMode); + return targetIndex; } void EndToEndCompileRequest::setTargetProfile(int targetIndex, SlangProfileID profile) @@ -3887,6 +3908,13 @@ void EndToEndCompileRequest::setTargetMatrixLayoutMode(int targetIndex, SlangMat setMatrixLayoutMode(mode); } +void EndToEndCompileRequest::setTargetLineDirectiveMode( + SlangInt targetIndex, + SlangLineDirectiveMode mode) +{ + getLinkage()->targets[targetIndex]->setLineDirectiveMode(LineDirectiveMode(mode)); +} + SlangResult EndToEndCompileRequest::addTargetCapability(SlangInt targetIndex, SlangCapabilityID capability) { auto& targets = getLinkage()->targets; diff --git a/tests/compute/default-major.slang b/tests/compute/default-major.slang index 743dbe656..858ca5632 100644 --- a/tests/compute/default-major.slang +++ b/tests/compute/default-major.slang @@ -1,11 +1,14 @@ // default-major.slang -// The default layout should be column. Unfortunately CPU and CUDA only work with row layout, so they have to be disabled here. +// The default layout should be column. +// This test is disabled because `gfx` layer always initializes Slang to use row-major layout. +// To test this behavior we need to find a way to make `gfx` use Slang default instead. +// Unfortunately CPU and CUDA only work with row layout, so they have to be disabled here. //DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -compile-arg -O3 -shaderobj -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -shaderobj -//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -shaderobj +//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type -dx12 -shaderobj +//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -shaderobj //DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type -shaderobj // This data is in column major layout order.... diff --git a/tests/compute/dynamic-dispatch-15.slang b/tests/compute/dynamic-dispatch-15.slang new file mode 100644 index 000000000..5e2be1a4c --- /dev/null +++ b/tests/compute/dynamic-dispatch-15.slang @@ -0,0 +1,82 @@ +// Test packing/unpacking different types of fields into `AnyValue`s. + +//dTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu -output-using-type +//dTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -output-using-type +//dTEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -use-dxil -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0 -output-using-type + +[anyValueSize(16)] +interface IInterface +{ + float run(); +} + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=gOutputBuffer +RWStructuredBuffer<float> gOutputBuffer; + +//TEST_INPUT: set gObj = dynamic new StructuredBuffer<IInterface>[new FloatVal{1.0}, new Float4Val{{[2.0, 3.0, 4.0, 5.0]}}, new IntVal{6}, new Int4Val{[7,8,9,10]}]; +RWStructuredBuffer<IInterface> gObj; + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + // Test unpacking. + float result = 0.0; + for (int i = 0; i < 4; i++) + { + IInterface v0 = gObj.Load(i); + result += v0.run(); + } + + // Test packing. + IInterface v[2]; + Float4Val cval; + cval.val.val = float4(1,2,3,4); + v[0] = cval; + + Int4Val ival; + ival.val = int4(2,3,4,5); + v[1] = ival; + + for (int i = 0; i < 2; i++) + { + result += v[i].run(); + } + gOutputBuffer[0] = result; +} + +// Type must be marked `public` to ensure it is visible in the generated DLL. +public struct FloatVal : IInterface +{ + float val; + float run() + { + return val; + } +}; +interface ISomething{void g();} +struct Float4Struct : ISomething { float4 val; void g() {} } +public struct Float4Val : IInterface +{ + Float4Struct val; + float run() + { + return val.val.x; + } +}; +public struct IntVal : IInterface +{ + int val; + float run() + { + return val; + } +}; +public struct Int4Val : IInterface +{ + int4 val; + float run() + { + return val.x; + } +};
\ No newline at end of file diff --git a/tests/compute/dynamic-dispatch-15.slang.expected.txt b/tests/compute/dynamic-dispatch-15.slang.expected.txt new file mode 100644 index 000000000..efbae0290 --- /dev/null +++ b/tests/compute/dynamic-dispatch-15.slang.expected.txt @@ -0,0 +1,2 @@ +type: float +19.0 diff --git a/tools/gfx-util/shader-cursor.cpp b/tools/gfx-util/shader-cursor.cpp index afb1540d5..efdde44b8 100644 --- a/tools/gfx-util/shader-cursor.cpp +++ b/tools/gfx-util/shader-cursor.cpp @@ -195,6 +195,19 @@ ShaderCursor ShaderCursor::getElement(SlangInt index) const return fieldCursor; } break; + + case slang::TypeReflection::Kind::Vector: + case slang::TypeReflection::Kind::Matrix: + { + ShaderCursor fieldCursor; + fieldCursor.m_baseObject = m_baseObject; + fieldCursor.m_typeLayout = m_typeLayout->getElementTypeLayout(); + fieldCursor.m_offset.uniformOffset = m_offset.uniformOffset + m_typeLayout->getElementStride(SLANG_PARAMETER_CATEGORY_UNIFORM) * index; + fieldCursor.m_offset.bindingRangeIndex = m_offset.bindingRangeIndex; + fieldCursor.m_offset.bindingArrayIndex = m_offset.bindingArrayIndex; + return fieldCursor; + } + break; } return ShaderCursor(); diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index 26b774b1a..8b5721cda 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -5225,13 +5225,13 @@ Result D3D12Device::readBufferResource( // Resource to readback to D3D12_RESOURCE_DESC stagingDesc; - _initBufferResourceDesc(bufferSize, stagingDesc); + _initBufferResourceDesc(size, stagingDesc); D3D12Resource stageBuf; SLANG_RETURN_ON_FAIL(stageBuf.initCommitted(m_device, heapProps, D3D12_HEAP_FLAG_NONE, stagingDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr)); // Do the copy - encodeInfo.d3dCommandList->CopyBufferRegion(stageBuf, 0, resource, 0, bufferSize); + encodeInfo.d3dCommandList->CopyBufferRegion(stageBuf, 0, resource, offset, size); // Wait until complete submitResourceCommandsAndWait(encodeInfo); @@ -5240,13 +5240,13 @@ Result D3D12Device::readBufferResource( RefPtr<ListBlob> blob = new ListBlob(); { UINT8* data; - D3D12_RANGE readRange = { 0, bufferSize }; + D3D12_RANGE readRange = { 0, size }; SLANG_RETURN_ON_FAIL(stageBuf.getResource()->Map(0, &readRange, reinterpret_cast<void**>(&data))); // Copy to memory buffer - blob->m_data.setCount(bufferSize); - ::memcpy(blob->m_data.getBuffer(), data, bufferSize); + blob->m_data.setCount(size); + ::memcpy(blob->m_data.getBuffer(), data, size); stageBuf.getResource()->Unmap(0, nullptr); } diff --git a/tools/gfx/slang-context.h b/tools/gfx/slang-context.h index be6539da5..b58d6cc18 100644 --- a/tools/gfx/slang-context.h +++ b/tools/gfx/slang-context.h @@ -34,6 +34,7 @@ namespace gfx targetDesc.profile = globalSession->findProfile(targetProfile); targetDesc.optimizationLevel = desc.optimizationLevel; targetDesc.floatingPointMode = desc.floatingPointMode; + targetDesc.lineDirectiveMode = desc.lineDirectiveMode; targetDesc.flags = desc.targetFlags; slangSessionDesc.targetCount = 1; slangSessionDesc.targets = &targetDesc; diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp index ab73af5b5..a846f4a33 100644 --- a/tools/render-test/render-test-main.cpp +++ b/tools/render-test/render-test-main.cpp @@ -470,7 +470,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(session, options, input, m_compilationOutput)); + SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession(), options, input, m_compilationOutput)); m_shaderInputLayout = m_compilationOutput.layout; // Once the shaders have been compiled we load them via the underlying API. @@ -551,7 +551,7 @@ Result RenderTestApp::_initializeShaders( Options::ShaderProgramType shaderType, const ShaderCompilerUtil::Input& input) { - SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(session, m_options, input, m_compilationOutput)); + SLANG_RETURN_ON_FAIL(ShaderCompilerUtil::compileWithLayout(device->getSlangSession(), 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; @@ -672,6 +672,7 @@ void RenderTestApp::runCompute(IComputeCommandEncoder* encoder) void RenderTestApp::finalize() { + m_compilationOutput.output.reset(); } Result RenderTestApp::writeBindingOutput(const String& fileName) @@ -1099,6 +1100,8 @@ static SlangResult _innerMain(Slang::StdWriters* stdWriters, SlangSession* sessi desc.deviceType = options.deviceType; desc.adapter = options.adapter.getBuffer(); + desc.slang.lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_NONE; + List<const char*> requiredFeatureList; for (auto& name : options.renderFeatures) requiredFeatureList.add(name.getBuffer()); diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp index adfea337c..a533a6378 100644 --- a/tools/render-test/slang-support.cpp +++ b/tools/render-test/slang-support.cpp @@ -66,26 +66,19 @@ void ShaderCompilerUtil::Output::reset() desc.slangProgram = nullptr; } - if (m_requestForKernels && session) - { - spDestroyCompileRequest(m_requestForKernels); - } - if (m_extraRequestForReflection && session) - { - spDestroyCompileRequest(m_extraRequestForReflection); - } session = nullptr; m_requestForKernels = nullptr; m_extraRequestForReflection = nullptr; } -/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(SlangSession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out) +/* static */ SlangResult ShaderCompilerUtil::_compileProgramImpl(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out) { out.reset(); - SlangCompileRequest* slangRequest = spCreateCompileRequest(session); + ComPtr<SlangCompileRequest> slangRequest = nullptr; + session->createCompileRequest(slangRequest.writeRef()); out.m_requestForKernels = slangRequest; - out.session = session; + out.session = session->getGlobalSession(); // Parse all the extra args { @@ -102,7 +95,7 @@ void ShaderCompilerUtil::Output::reset() } spSetCodeGenTarget(slangRequest, input.target); - spSetTargetProfile(slangRequest, 0, spFindProfile(session, input.profile.getBuffer())); + spSetTargetProfile(slangRequest, 0, spFindProfile(out.session, input.profile.getBuffer())); // Define a macro so that shader code in a test can detect what language we // are nominally working with. @@ -241,11 +234,10 @@ void ShaderCompilerUtil::Output::reset() } out.set(input.pipelineType, linkedSlangProgram); - return SLANG_OK; } -/* static */ SlangResult ShaderCompilerUtil::compileProgram(SlangSession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out) +/* static */ SlangResult ShaderCompilerUtil::compileProgram(slang::ISession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out) { if( input.passThrough == SLANG_PASS_THROUGH_NONE ) { @@ -319,7 +311,7 @@ void ShaderCompilerUtil::Output::reset() return SLANG_OK; } -/* static */SlangResult ShaderCompilerUtil::compileWithLayout(SlangSession* session, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output) +/* static */SlangResult ShaderCompilerUtil::compileWithLayout(slang::ISession* session, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output) { String sourcePath = options.sourcePath; auto shaderType = options.shaderType; @@ -331,7 +323,7 @@ void ShaderCompilerUtil::Output::reset() { // Add an include of the prelude ComPtr<ISlangBlob> prelude; - session->getLanguagePrelude(input.sourceLanguage, prelude.writeRef()); + session->getGlobalSession()->getLanguagePrelude(input.sourceLanguage, prelude.writeRef()); String preludeString = StringUtil::getString(prelude); @@ -421,7 +413,6 @@ void ShaderCompilerUtil::Output::reset() } compileRequest.globalSpecializationArgs = layout.globalSpecializationArgs; compileRequest.entryPointSpecializationArgs = layout.entryPointSpecializationArgs; - return ShaderCompilerUtil::compileProgram(session, options, input, compileRequest, output.output); } diff --git a/tools/render-test/slang-support.h b/tools/render-test/slang-support.h index 3404aac1d..da1f379fd 100644 --- a/tools/render-test/slang-support.h +++ b/tools/render-test/slang-support.h @@ -67,10 +67,10 @@ struct ShaderCompilerUtil IShaderProgram::Desc desc = {}; /// Compile request that owns the lifetime of compiled kernel code. - SlangCompileRequest* m_requestForKernels = nullptr; + ComPtr<SlangCompileRequest> m_requestForKernels = nullptr; /// Compile request that owns the lifetime of reflection information. - SlangCompileRequest* m_extraRequestForReflection = nullptr; + ComPtr<SlangCompileRequest> m_extraRequestForReflection = nullptr; SlangCompileRequest* getRequestForKernels() const { return m_requestForKernels; } SlangCompileRequest* getRequestForReflection() const { return m_extraRequestForReflection ? m_extraRequestForReflection : m_requestForKernels; } @@ -86,12 +86,12 @@ struct ShaderCompilerUtil Slang::String sourcePath; }; - static SlangResult compileWithLayout(SlangSession* session, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output); + static SlangResult compileWithLayout(slang::ISession* session, const Options& options, const ShaderCompilerUtil::Input& input, OutputAndLayout& output); static SlangResult readSource(const Slang::String& inSourcePath, Slang::List<char>& outSourceText); - static SlangResult _compileProgramImpl(SlangSession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out); - static SlangResult compileProgram(SlangSession* session, const Options& options, const Input& input, const ShaderCompileRequest& request, Output& out); + 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); }; |
