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 /source | |
| 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>
Diffstat (limited to 'source')
| -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 |
9 files changed, 106 insertions, 20 deletions
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; |
