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 /tools | |
| 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 'tools')
| -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 |
6 files changed, 37 insertions, 29 deletions
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); }; |
