summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-compiler.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-08-18 13:42:46 -0400
committerGitHub <noreply@github.com>2020-08-18 13:42:46 -0400
commit9abcb6ea24dbc7184c3a2ad9f4458f63f8901928 (patch)
tree155ae80bbd15efae88b5852b7bb24804a70af405 /source/slang/slang-compiler.cpp
parent697e7fbbbb5dcb448c03a9887e6ef09e328505ef (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-compiler.cpp')
-rwxr-xr-xsource/slang/slang-compiler.cpp109
1 files changed, 32 insertions, 77 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index c643f825a..72cf2dfbe 100755
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -8,7 +8,6 @@
#include "../core/slang-riff.h"
#include "../core/slang-type-text-util.h"
-
#include "slang-check.h"
#include "slang-compiler.h"
#include "slang-lexer.h"
@@ -841,83 +840,39 @@ namespace Slang
return UnownedStringSlice();
}
- /// Read a file in the context of handling a preprocessor directive
- static SlangResult readFile(
- Linkage* linkage,
- String const& path,
- ISlangBlob** outBlob)
- {
- // The actual file loading will be handled by the file system
- // associated with the parent linkage.
- //
- auto fileSystemExt = linkage->getFileSystemExt();
- SLANG_RETURN_ON_FAIL(fileSystemExt->loadFile(path.getBuffer(), outBlob));
-
- return SLANG_OK;
- }
-
struct FxcIncludeHandler : ID3DInclude
{
- Linkage* linkage;
- DiagnosticSink* sink;
- IncludeHandler* includeHandler;
- PathInfo rootPathInfo;
-
- STDMETHOD(Open)(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes) override
+
+ STDMETHOD(Open)(D3D_INCLUDE_TYPE includeType, LPCSTR fileName, LPCVOID parentData, LPCVOID* outData, UINT* outSize) override
{
- SLANG_UNUSED(IncludeType);
- SLANG_UNUSED(pParentData);
-
- String path(pFileName);
+ SLANG_UNUSED(includeType);
+ // NOTE! The pParentData means the *text* of any previous include.
+ // In order to work out what *path* that came from, we need to seach which source file it came from, and
+ // use it's path
- SourceLoc loc;
+ // Assume the root pathInfo initially
+ PathInfo includedFromPathInfo = m_rootPathInfo;
- PathInfo includedFromPathInfo = rootPathInfo;
-
- if (!includeHandler)
+ // Lets try and find the parent source if there is any
+ if (parentData)
{
- return SLANG_E_NOT_IMPLEMENTED;
- }
-
- // Find the path relative to the foundPath
- PathInfo filePathInfo;
- if (SLANG_FAILED(includeHandler->findFile(path, includedFromPathInfo.foundPath, filePathInfo)))
- {
- return SLANG_E_CANNOT_OPEN;
- }
-
- // We must have a uniqueIdentity to be compare
- if (!filePathInfo.hasUniqueIdentity())
- {
- return SLANG_E_ABORT;
- }
-
- // Simplify the path
- filePathInfo.foundPath = includeHandler->simplifyPath(filePathInfo.foundPath);
-
- // See if this an already loaded source file
- auto sourceManager = linkage->getSourceManager();
- SourceFile* sourceFile = sourceManager->findSourceFileRecursively(filePathInfo.uniqueIdentity);
-
- // If not create a new one, and add to the list of known source files
- if (!sourceFile)
- {
- ComPtr<ISlangBlob> foundSourceBlob;
- if (SLANG_FAILED(readFile(linkage, filePathInfo.foundPath, foundSourceBlob.writeRef())))
+ SourceFile* foundSourceFile = m_system.getSourceManager()->findSourceFileByContentRecursively((const char*)parentData);
+ if (foundSourceFile)
{
- return SLANG_E_CANNOT_OPEN;
+ includedFromPathInfo = foundSourceFile->getPathInfo();
}
-
- sourceFile = sourceManager->createSourceFileWithBlob(filePathInfo, foundSourceBlob);
- sourceManager->addSourceFile(filePathInfo.uniqueIdentity, sourceFile);
}
- // This is a new parse (even if it's a pre-existing source file), so create a new SourceUnit
- SourceView* sourceView = sourceManager->createSourceView(sourceFile, &filePathInfo);
+ String path(fileName);
+ PathInfo pathInfo;
+ ComPtr<ISlangBlob> blob;
- *ppData = sourceView->getContent().begin();
- *pBytes = (UINT) sourceView->getContentSize();
+ SLANG_RETURN_ON_FAIL(m_system.findAndLoadFile(path, includedFromPathInfo.foundPath, pathInfo, blob));
+ // Return the data
+ *outData = blob->getBufferPointer();
+ *outSize = (UINT) blob->getBufferSize();
+
return S_OK;
}
@@ -926,6 +881,13 @@ namespace Slang
SLANG_UNUSED(pData);
return S_OK;
}
+ FxcIncludeHandler(SearchDirectoryList* searchDirectories, ISlangFileSystemExt* fileSystemExt, SourceManager* sourceManager):
+ m_system(searchDirectories, fileSystemExt, sourceManager)
+ {
+ }
+
+ PathInfo m_rootPathInfo;
+ IncludeSystem m_system;
};
SlangResult emitDXBytecodeForEntryPoint(
@@ -967,13 +929,9 @@ namespace Slang
List<D3D_SHADER_MACRO> dxMacrosStorage;
D3D_SHADER_MACRO const* dxMacros = nullptr;
- IncludeHandlerImpl includeHandler;
- includeHandler.linkage = linkage;
- includeHandler.searchDirectories = &linkage->searchDirectories;
-
- FxcIncludeHandler fxcIncludeHandlerStorage;
- FxcIncludeHandler* fxcIncludeHandler = nullptr;
-
+ FxcIncludeHandler fxcIncludeHandlerStorage(&linkage->searchDirectories, linkage->getFileSystemExt(), sink->getSourceManager());
+ FxcIncludeHandler* fxcIncludeHandler = &fxcIncludeHandlerStorage;
+
if(auto translationUnit = findPassThroughTranslationUnit(endToEndReq, entryPointIndex))
{
for( auto& define : translationUnit->compileRequest->preprocessorDefinitions )
@@ -996,10 +954,7 @@ namespace Slang
dxMacros = dxMacrosStorage.getBuffer();
fxcIncludeHandler = &fxcIncludeHandlerStorage;
- fxcIncludeHandler->linkage = linkage;
- fxcIncludeHandler->sink = compileRequest->getSink();
- fxcIncludeHandler->includeHandler = &includeHandler;
- fxcIncludeHandler->rootPathInfo = translationUnit->m_sourceFiles[0]->getPathInfo();
+ fxcIncludeHandlerStorage.m_rootPathInfo = translationUnit->m_sourceFiles[0]->getPathInfo();
}
DWORD flags = 0;