diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-08-18 13:42:46 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-18 13:42:46 -0400 |
| commit | 9abcb6ea24dbc7184c3a2ad9f4458f63f8901928 (patch) | |
| tree | 155ae80bbd15efae88b5852b7bb24804a70af405 /source/slang/slang-dxc-support.cpp | |
| parent | 697e7fbbbb5dcb448c03a9887e6ef09e328505ef (diff) | |
Support for float atomics on RWByteAddressBuffer (#1502)
* Fix premake5.lua so it uses the new path needed for OpenCLDebugInfo100.h
* Keep including the includes directory.
* Added the spirv-tools-generated files.
* We don't need to include the spirv/unified1 path because the files needed are actually in the spirv-tools-generated folder.
* Put the build_info.h glslang generated files in external/glslang-generated. Alter premake5.lua to pick up that header.
* First pass at documenting how to build glslang and spirv-tools.
* Improved glsl/spir-v tools README.md
* Added revision.h
* Change how gResources is calculated.
Update about revision.h
* Update docs a little.
* Split out spirv-tools into a separate project for building glslang. This was not necessary on linux, but *is* necessary on windows, because there is a file disassemble.cpp in spirv-tools and in glslang, and this leads to VS choosing only one. With the separate library, the problem is resolved.
* Fix direct-spirv-emit output.
* Update to latest version of spirv headers and spirv-tools.
* Upgrade submodule version of glslang in external.
* Add fPIC to build options of slang-spirv-tools
* WIP adding support for InterlockedAddFp32
* Upgrade slang-binaries to have new glslang.
* Fix issues with Windows slang-glslang binaries, via update of slang-binaries used.
* WIP - atomicAdd. This solution can't work as we can't do (float*) in glsl.
* WIP on atomic float ops.
* Added checking for multiple decls that takes into account __target_intrinsic and __specialized_for_target.
First pass impl of atomic add on float for glsl.
* Split __atomicAdd so extensions are applied appropriately.
* Made Dxc/Fxc support includes.
Use HLSL prelude to pass the path to nvapi
Added -nv-api-path
* Refactor around IncludeHandler and impl of IncludeSystem
* slang-include-handler -> slang-include-system
Have IncludeHandler/Impl defined in slang-preprocessor
* Small comment improvements.
* Document atomic float add addition in target-compatibility.md.
* CUDA float atomic support on RWByteAddressBuffer.
* Add atomic-float-byte-address-buffer-cross.slang
* Removed inappropriate-once.slang - the test is no longer valid when a file is loaded and has a unique identity by default. A test could be made, but would require an API call to create the file (so no unique id).
Improved handling of loadFile - uses uniqueId if has one.
* Work around for testing target overlaps - to avoid exceptions on adding targets.
Simplify PathInfo setup.
Modify single-target-intrinsic.slang - it no longer failed because there were no longer multiple definitions for the same target.
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-dxc-support.cpp')
| -rwxr-xr-x | source/slang/slang-dxc-support.cpp | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/source/slang/slang-dxc-support.cpp b/source/slang/slang-dxc-support.cpp index 6f8151921..b0938ed12 100755 --- a/source/slang/slang-dxc-support.cpp +++ b/source/slang/slang-dxc-support.cpp @@ -45,6 +45,82 @@ namespace Slang return UnownedStringSlice(); } + // IDxcIncludeHandler + // 7f61fc7d-950d-467f-b3e3-3c02fb49187c + static const Guid IID_IDxcIncludeHandler = { 0x7f61fc7d, 0x950d, 0x467f, { 0x3c, 0x02, 0xfb, 0x49, 0x18, 0x7c } }; + static const Guid IID_IUnknown = SLANG_UUID_ISlangUnknown; + + class DxcIncludeHandler : public IDxcIncludeHandler, public RefObject + { + public: + // Implement IUnknown + SLANG_NO_THROW HRESULT SLANG_MCALL QueryInterface(const IID& uuid, void** out) + { + ISlangUnknown* intf = getInterface(reinterpret_cast<const Guid&>(uuid)); + if (intf) + { + addReference(); + *out = intf; + return SLANG_OK; + } + return SLANG_E_NO_INTERFACE; + } + SLANG_NO_THROW ULONG SLANG_MCALL AddRef() SLANG_OVERRIDE { return (uint32_t)addReference(); } + SLANG_NO_THROW ULONG SLANG_MCALL Release() SLANG_OVERRIDE { return (uint32_t)releaseReference(); } + + // Implement IDxcIncludeHandler + virtual HRESULT SLANG_MCALL LoadSource(LPCWSTR inFilename, IDxcBlob** outSource) SLANG_OVERRIDE + { + // Hmm DXC does something a bit odd - when it sees a path, it just passes that in with ./ in front!! + // NOTE! It doesn't make any difference if it is "" or <> quoted. + + // So we just do a work around where we strip if we see a path starting with ./ + String filePath = String::fromWString(inFilename); + + // If it starts with ./ then attempt to strip it + if (filePath.startsWith("./")) + { + String remaining(filePath.subString(2, filePath.getLength() - 2)); + + // Okay if we strip ./ and what we have is absolute, then it's the absolute path that we care about, + // otherwise we just leave as is. + if (Path::isAbsolute(remaining)) + { + filePath = remaining; + } + } + + ComPtr<ISlangBlob> blob; + PathInfo pathInfo; + SlangResult res = m_system.findAndLoadFile(filePath, String(), pathInfo, blob); + + // NOTE! This only works because ISlangBlob is *binary compatible* with IDxcBlob, if either + // change things could go boom + *outSource = (IDxcBlob*)blob.detach(); + return res; + } + + DxcIncludeHandler(SearchDirectoryList* searchDirectories, ISlangFileSystemExt* fileSystemExt, SourceManager* sourceManager = nullptr) : + m_system(searchDirectories, fileSystemExt, sourceManager) + { + } + + protected: + + // Used by QueryInterface for casting + ISlangUnknown* getInterface(const Guid& guid) + { + if (guid == IID_IUnknown || guid == IID_IDxcIncludeHandler) + { + return (ISlangUnknown*)(static_cast<IDxcIncludeHandler*>(this)); + } + return nullptr; + } + + IncludeSystem m_system; + }; + + SlangResult emitDXILForEntryPointUsingDXC( ComponentType* program, BackEndCompileRequest* compileRequest, @@ -194,6 +270,8 @@ namespace Slang const String sourcePath = calcSourcePathForEntryPoint(endToEndReq, entryPointIndex); + ComPtr<DxcIncludeHandler> includeHandler(new DxcIncludeHandler(&linkage->searchDirectories, linkage->getFileSystemExt())); + ComPtr<IDxcOperationResult> dxcResult; SLANG_RETURN_ON_FAIL(dxcCompiler->Compile(dxcSourceBlob, sourcePath.toWString().begin(), @@ -203,7 +281,7 @@ namespace Slang argCount, nullptr, // `#define`s 0, // `#define` count - nullptr, // `#include` handler + includeHandler, // `#include` handler dxcResult.writeRef())); // Retrieve result. |
