Skip to content

Commit b5a4161

Browse files
jsmall-zzzTim Foley
and
Tim Foley
authored
Remove IncludeHandler. (shader-slang#1505)
nvAPI -> NVAPI nvAPIPath -> nvapiPath DxcIncludeHandler don't reference count. nv-api-path -> nvapi-path Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
1 parent 2fffbc5 commit b5a4161

12 files changed

+35
-81
lines changed

docs/target-compatibility.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ void RWByteAddressBuffer::InterlockedAddI64(uint byteAddress, int64_t valueToAdd
192192
void RWByteAddressBuffer::InterlockedAddI64(uint byteAddress, int64_t valueToAdd);
193193
```
194194

195-
On HLSL based targets this functionality is achieved using [nvAPI](https://developer.nvidia.com/nvapi) based functionality. Therefore for the feature to work you must have nvAPI installed on your system. Then the 'prelude' functionality allows via the API for an include (or the text) of the relevent files. To see how to do this in practice look at the function `setSessionDefaultPrelude`. This makes the prelude for HLSL hold an include to the *absolute* path to the required include file `nvHLSLExtns.h`. As an absolute path is used, it means other includes that includes, look in the correct place without having to set up special include paths.
195+
On HLSL based targets this functionality is achieved using [NVAPI](https://developer.nvidia.com/nvapi) based functionality. Therefore for the feature to work you must have NVAPI installed on your system. Then the 'prelude' functionality allows via the API for an include (or the text) of the relevent files. To see how to do this in practice look at the function `setSessionDefaultPrelude`. This makes the prelude for HLSL hold an include to the *absolute* path to the required include file `nvHLSLExtns.h`. As an absolute path is used, it means other includes that includes, look in the correct place without having to set up special include paths.
196196

197-
To use nvAPI it is nessary to specify a unordered access views (UAV) based 'u' register that will be used to communicate with nvAPI. Note! Slang does not do any special handling around this, it will be necessary for application code to ensure the UAV is either guarenteed to not collide with what Slang assigns, or it's specified (but not used) in the Slang source. The u register number has to be specified also to the nvAPI runtime library.
197+
To use NVAPI it is nessary to specify a unordered access views (UAV) based 'u' register that will be used to communicate with NVAPI. Note! Slang does not do any special handling around this, it will be necessary for application code to ensure the UAV is either guarenteed to not collide with what Slang assigns, or it's specified (but not used) in the Slang source. The u register number has to be specified also to the NVAPI runtime library.
198198

199199
On Vulkan, for float the [`GL_EXT_shader_atomic_float`](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_EXT_shader_atomic_float.html) extension is required. For int64 the [`GL_EXT_shader_atomic_int64`](https://raw.githubusercontent.com/KhronosGroup/GLSL/master/extensions/ext/GL_EXT_shader_atomic_int64.txt) extension is required.
200200

source/core/slang-test-tool-util.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ static SlangResult _addCUDAPrelude(const String& parentPath, slang::IGlobalSessi
100100
}
101101
}
102102
// If the nvAPI path is set, and we find nvHLSLExtns.h, put that in the HLSL prelude
103-
if (info.nvAPIPath)
103+
if (info.nvapiPath)
104104
{
105105
String includePath;
106-
if (SLANG_SUCCEEDED(_calcIncludePath(info.nvAPIPath, "nvHLSLExtns.h", includePath)))
106+
if (SLANG_SUCCEEDED(_calcIncludePath(info.nvapiPath, "nvHLSLExtns.h", includePath)))
107107
{
108108
StringBuilder buf;
109109

source/core/slang-test-tool-util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct TestToolUtil
3939
struct PreludeInfo
4040
{
4141
const char* exePath = nullptr;
42-
const char* nvAPIPath = nullptr;
42+
const char* nvapiPath = nullptr;
4343
};
4444

4545
typedef SlangResult(*InnerMainFunc)(Slang::StdWriters* stdWriters, SlangSession* session, int argc, const char*const* argv);

source/slang/hlsl.meta.slang

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ ${{{{
196196

197197
// float32 and int64 atomic support. This is a Slang specific extension, it uses
198198
// GL_EXT_shader_atomic_float on vk
199-
// NvAPI support on DX
200-
// NOTE! To use this feature on HLSL, the shader needs to include 'nvHLSLExtns.h' from the NvAPI SDK
199+
// NVAPI support on DX
200+
// NOTE! To use this feature on HLSL, the shader needs to include 'nvHLSLExtns.h' from the NVAPI SDK
201201
//
202202

203203
// Fp32

source/slang/slang-check-decl.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -3520,25 +3520,6 @@ namespace Slang
35203520
return subst;
35213521
}
35223522

3523-
#if 0
3524-
// For simplicity we will make having a definition of a function include having a body or a target intrinsics defined.
3525-
// It may be useful to add other modifiers to mark as having body - for example perhaps
3526-
// any target intrinsic modifier (like SPIR-V version) should be included.
3527-
//
3528-
// Note that not having this check around TargetIntrinsicModifier can lead to a crash in the compiler
3529-
// with a definition, followed by a declaration with a target intrinsic.
3530-
// That this doesn't appear to be the case with other modifiers.
3531-
// TODO:
3532-
// We may want to be able to add target intrinsics with other declarations, that being the case this logic
3533-
// would need to change.
3534-
// We might also want are more precise error that pointed out the actually problem - because strictly speaking
3535-
// having a target intrinsic isn't a 'body'.
3536-
bool _isDefinition(FuncDecl* decl)
3537-
{
3538-
return decl->body || decl->hasModifier<TargetIntrinsicModifier>();
3539-
}
3540-
#endif
3541-
35423523
typedef Dictionary<Name*, CallableDecl*> TargetDeclDictionary;
35433524

35443525
static void _addTargetModifiers(CallableDecl* decl, TargetDeclDictionary& ioDict)

source/slang/slang-dxc-support.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace Slang
5050
static const Guid IID_IDxcIncludeHandler = { 0x7f61fc7d, 0x950d, 0x467f, { 0x3c, 0x02, 0xfb, 0x49, 0x18, 0x7c } };
5151
static const Guid IID_IUnknown = SLANG_UUID_ISlangUnknown;
5252

53-
class DxcIncludeHandler : public IDxcIncludeHandler, public RefObject
53+
class DxcIncludeHandler : public IDxcIncludeHandler
5454
{
5555
public:
5656
// Implement IUnknown
@@ -59,14 +59,13 @@ namespace Slang
5959
ISlangUnknown* intf = getInterface(reinterpret_cast<const Guid&>(uuid));
6060
if (intf)
6161
{
62-
addReference();
6362
*out = intf;
6463
return SLANG_OK;
6564
}
6665
return SLANG_E_NO_INTERFACE;
6766
}
68-
SLANG_NO_THROW ULONG SLANG_MCALL AddRef() SLANG_OVERRIDE { return (uint32_t)addReference(); }
69-
SLANG_NO_THROW ULONG SLANG_MCALL Release() SLANG_OVERRIDE { return (uint32_t)releaseReference(); }
67+
SLANG_NO_THROW ULONG SLANG_MCALL AddRef() SLANG_OVERRIDE { return 1; }
68+
SLANG_NO_THROW ULONG SLANG_MCALL Release() SLANG_OVERRIDE { return 1; }
7069

7170
// Implement IDxcIncludeHandler
7271
virtual HRESULT SLANG_MCALL LoadSource(LPCWSTR inFilename, IDxcBlob** outSource) SLANG_OVERRIDE
@@ -270,7 +269,7 @@ namespace Slang
270269

271270
const String sourcePath = calcSourcePathForEntryPoint(endToEndReq, entryPointIndex);
272271

273-
ComPtr<DxcIncludeHandler> includeHandler(new DxcIncludeHandler(&linkage->searchDirectories, linkage->getFileSystemExt()));
272+
DxcIncludeHandler includeHandler(&linkage->searchDirectories, linkage->getFileSystemExt(), compileRequest->getSourceManager());
274273

275274
ComPtr<IDxcOperationResult> dxcResult;
276275
SLANG_RETURN_ON_FAIL(dxcCompiler->Compile(dxcSourceBlob,
@@ -279,9 +278,9 @@ namespace Slang
279278
wideProfileName.begin(),
280279
args,
281280
argCount,
282-
nullptr, // `#define`s
283-
0, // `#define` count
284-
includeHandler, // `#include` handler
281+
nullptr, // `#define`s
282+
0, // `#define` count
283+
&includeHandler, // `#include` handler
285284
dxcResult.writeRef()));
286285

287286
// Retrieve result.

source/slang/slang-preprocessor.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,8 @@ struct Preprocessor
203203
// diagnostics sink to use when writing messages
204204
DiagnosticSink* sink;
205205

206-
// An external callback interface to use when looking
207-
// for files in a `#include` directive
208-
IncludeHandler* includeHandler;
206+
// Functionality for looking up files in a `#include` directive
207+
IncludeSystem* includeSystem;
209208

210209
// Current input stream (top of the stack of input)
211210
PreprocessorInputStream* inputStream;
@@ -1818,8 +1817,8 @@ static void HandleIncludeDirective(PreprocessorDirectiveContext* context)
18181817

18191818
PathInfo includedFromPathInfo = context->preprocessor->getSourceManager()->getPathInfo(directiveLoc, SourceLocType::Actual);
18201819

1821-
IncludeHandler* includeHandler = context->preprocessor->includeHandler;
1822-
if (!includeHandler)
1820+
IncludeSystem* includeSystem = context->preprocessor->includeSystem;
1821+
if (!includeSystem)
18231822
{
18241823
GetSink(context)->diagnose(pathToken.loc, Diagnostics::includeFailed, path);
18251824
GetSink(context)->diagnose(pathToken.loc, Diagnostics::noIncludeHandlerSpecified);
@@ -1828,7 +1827,7 @@ static void HandleIncludeDirective(PreprocessorDirectiveContext* context)
18281827

18291828
/* Find the path relative to the foundPath */
18301829
PathInfo filePathInfo;
1831-
if (SLANG_FAILED(includeHandler->findFile(path, includedFromPathInfo.foundPath, filePathInfo)))
1830+
if (SLANG_FAILED(includeSystem->findFile(path, includedFromPathInfo.foundPath, filePathInfo)))
18321831
{
18331832
GetSink(context)->diagnose(pathToken.loc, Diagnostics::includeFailed, path);
18341833
return;
@@ -1853,7 +1852,7 @@ static void HandleIncludeDirective(PreprocessorDirectiveContext* context)
18531852
}
18541853

18551854
// Simplify the path
1856-
filePathInfo.foundPath = includeHandler->simplifyPath(filePathInfo.foundPath);
1855+
filePathInfo.foundPath = includeSystem->simplifyPath(filePathInfo.foundPath);
18571856

18581857
// Push the new file onto our stack of input streams
18591858
// TODO(tfoley): check if we have made our include stack too deep
@@ -2355,7 +2354,7 @@ static void InitializePreprocessor(
23552354
DiagnosticSink* sink)
23562355
{
23572356
preprocessor->sink = sink;
2358-
preprocessor->includeHandler = NULL;
2357+
preprocessor->includeSystem = NULL;
23592358
preprocessor->endOfFileToken.type = TokenType::EndOfFile;
23602359
preprocessor->endOfFileToken.flags = TokenFlag::AtStartOfLine;
23612360
}
@@ -2451,7 +2450,7 @@ static TokenList ReadAllTokens(
24512450
TokenList preprocessSource(
24522451
SourceFile* file,
24532452
DiagnosticSink* sink,
2454-
IncludeHandler* includeHandler,
2453+
IncludeSystem* includeSystem,
24552454
Dictionary<String, String> defines,
24562455
Linkage* linkage,
24572456
Module* parentModule)
@@ -2461,7 +2460,7 @@ TokenList preprocessSource(
24612460
preprocessor.linkage = linkage;
24622461
preprocessor.parentModule = parentModule;
24632462

2464-
preprocessor.includeHandler = includeHandler;
2463+
preprocessor.includeSystem = includeSystem;
24652464
for (auto p : defines)
24662465
{
24672466
DefineMacro(&preprocessor, p.Key, p.Value);

source/slang/slang-preprocessor.h

+1-26
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,11 @@ class Linkage;
1515
class Module;
1616
class ModuleDecl;
1717

18-
// Callback interface for the preprocessor to use when looking
19-
// for files in `#include` directives.
20-
struct IncludeHandler
21-
{
22-
virtual SlangResult findFile(const String& pathToInclude, const String& pathIncludedFrom, PathInfo& outPathInfo) = 0;
23-
virtual String simplifyPath(const String& path) = 0;
24-
};
25-
26-
// A default implementation that uses IncludeSystem to implement functionality
27-
struct IncludeHandlerImpl : IncludeHandler
28-
{
29-
virtual SlangResult findFile(const String& pathToInclude, const String& pathIncludedFrom, PathInfo& outPathInfo) override
30-
{
31-
return m_system.findFile(pathToInclude, pathIncludedFrom, outPathInfo);
32-
}
33-
virtual String simplifyPath(const String& path) override { return m_system.simplifyPath(path); }
34-
35-
IncludeHandlerImpl(SearchDirectoryList* searchDirectories, ISlangFileSystemExt* fileSystemExt, SourceManager* sourceManager = nullptr) :
36-
m_system(searchDirectories, fileSystemExt, sourceManager)
37-
{
38-
}
39-
protected:
40-
IncludeSystem m_system;
41-
};
42-
4318
// Take a string of source code and preprocess it into a list of tokens.
4419
TokenList preprocessSource(
4520
SourceFile* file,
4621
DiagnosticSink* sink,
47-
IncludeHandler* includeHandler,
22+
IncludeSystem* includeSystem,
4823
Dictionary<String, String> defines,
4924
Linkage* linkage,
5025
Module* parentModule);

source/slang/slang.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,7 @@ void FrontEndCompileRequest::parseTranslationUnit(
897897
// Here we should probably be using the searchDirectories on the FrontEndCompileRequest.
898898
// If searchDirectories.parent pointed to the one in the Linkage would mean linkage paths
899899
// would be checked too (after those on the FrontEndCompileRequest).
900-
901-
IncludeHandlerImpl includeHandler(&linkage->searchDirectories, linkage->getFileSystemExt());
900+
IncludeSystem includeSystem(&linkage->searchDirectories, linkage->getFileSystemExt(), linkage->getSourceManager());
902901

903902
RefPtr<Scope> languageScope;
904903
switch (translationUnit->sourceLanguage)
@@ -956,7 +955,7 @@ void FrontEndCompileRequest::parseTranslationUnit(
956955
auto tokens = preprocessSource(
957956
sourceFile,
958957
getSink(),
959-
&includeHandler,
958+
&includeSystem,
960959
combinedPreprocessorDefinitions,
961960
getLinkage(),
962961
module);
@@ -1651,14 +1650,14 @@ RefPtr<Module> Linkage::findOrImportModule(
16511650
// Next, try to find the file of the given name,
16521651
// using our ordinary include-handling logic.
16531652

1654-
IncludeHandlerImpl includeHandler(&searchDirectories, getFileSystemExt());
1653+
IncludeSystem includeSystem(&searchDirectories, getFileSystemExt(), getSourceManager());
16551654

16561655
// Get the original path info
16571656
PathInfo pathIncludedFromInfo = getSourceManager()->getPathInfo(loc, SourceLocType::Actual);
16581657
PathInfo filePathInfo;
16591658

16601659
// We have to load via the found path - as that is how file was originally loaded
1661-
if (SLANG_FAILED(includeHandler.findFile(fileName, pathIncludedFromInfo.foundPath, filePathInfo)))
1660+
if (SLANG_FAILED(includeSystem.findFile(fileName, pathIncludedFromInfo.foundPath, filePathInfo)))
16621661
{
16631662
sink->diagnose(loc, Diagnostics::cannotFindFile, fileName);
16641663
mapNameToLoadedModules[name] = nullptr;
@@ -1671,7 +1670,7 @@ RefPtr<Module> Linkage::findOrImportModule(
16711670

16721671
// Try to load it
16731672
ComPtr<ISlangBlob> fileContents;
1674-
if(SLANG_FAILED(getFileSystemExt()->loadFile(filePathInfo.foundPath.getBuffer(), fileContents.writeRef())))
1673+
if(SLANG_FAILED(includeSystem.loadFile(filePathInfo, fileContents)))
16751674
{
16761675
sink->diagnose(loc, Diagnostics::cannotOpenFile, fileName);
16771676
mapNameToLoadedModules[name] = nullptr;

tools/slang-test/options.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,15 @@ static bool _isSubCommand(const char* arg)
266266
return res;
267267
}
268268
}
269-
else if (strcmp(arg, "-nv-api-path") == 0)
269+
else if (strcmp(arg, "-nvapi-path") == 0)
270270
{
271271
if (argCursor == argEnd)
272272
{
273273
stdError.print("error: expected operand for '%s'\n", arg);
274274
return SLANG_FAIL;
275275
}
276276

277-
optionsOut->nvAPIPath = *argCursor++;
277+
optionsOut->nvapiPath = *argCursor++;
278278
}
279279
else
280280
{

tools/slang-test/options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ struct Options
9898
// The adapter to use. If empty will match first found adapter.
9999
Slang::String adapter;
100100

101-
Slang::String nvAPIPath;
101+
// The path to NVAPI if available.
102+
Slang::String nvapiPath;
102103

103104
/// Parse the args, report any errors into stdError, and write the results into optionsOut
104105
static SlangResult parse(int argc, char** argv, TestCategorySet* categorySet, Slang::WriterHelper stdError, Options* optionsOut);

tools/slang-test/slang-test-main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3275,9 +3275,9 @@ SlangResult innerMain(int argc, char** argv)
32753275
TestToolUtil::PreludeInfo info;
32763276
info.exePath = argv[0];
32773277

3278-
if (options.nvAPIPath.getLength())
3278+
if (options.nvapiPath.getLength())
32793279
{
3280-
info.nvAPIPath = options.nvAPIPath.getBuffer();
3280+
info.nvapiPath = options.nvapiPath.getBuffer();
32813281
}
32823282

32833283
TestToolUtil::setSessionDefaultPrelude(info, context.getSession());

0 commit comments

Comments
 (0)