diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-12-01 17:29:01 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-01 17:29:01 -0500 |
| commit | 200e236d64a02d9e85cb4a459477e073b81f5182 (patch) | |
| tree | 7c1c7b75eb8d95238afe154ff826ec065767104b /slang.h | |
| parent | 339422dc91e10d15cf861ba3006025e3cec250c5 (diff) | |
Make SlangCompileRequest COM type (#1620)
* #include an absolute path didn't work - because paths were taken to always be relative.
* WIP for COM CompileRequest.
* Add more methods to IGlobalSession.
* Fix createCompileRequest.
Made slangc tool use COM style methods.
* m_ prefix variables in EndToEndCompileRequest
Diffstat (limited to 'slang.h')
| -rw-r--r-- | slang.h | 1042 |
1 files changed, 669 insertions, 373 deletions
@@ -1140,23 +1140,22 @@ extern "C" namespace slang { struct IGlobalSession; + struct ICompileRequest; } // namespace slang /*! @brief An instance of the Slang library. */ typedef slang::IGlobalSession SlangSession; + typedef struct SlangProgramLayout SlangProgramLayout; /*! @brief A request for one or more compilation actions to be performed. */ - typedef struct SlangCompileRequest SlangCompileRequest; + typedef struct slang::ICompileRequest SlangCompileRequest; - namespace slang { - struct IGlobalSession; - } // namespace slang /*! @brief Initialize an instance of the Slang library. @@ -1169,133 +1168,113 @@ extern "C" SLANG_API void spDestroySession( SlangSession* session); - /*! - @brief Set the session shared library loader. If this changes the loader, it may cause shared libraries to be unloaded - @param session Session to set the loader on - @param loader The loader to set. Setting nullptr sets the default loader. + /** @see slang::IGlobalSession::setSharedLibraryLoader */ SLANG_API void spSessionSetSharedLibraryLoader( SlangSession* session, ISlangSharedLibraryLoader* loader); - /*! - @brief Gets the currently set shared library loader - @param session Session to get the loader from - @return Gets the currently set loader. If returns nullptr, it's the default loader + /** @see slang::IGlobalSession::getSharedLibraryLoader */ SLANG_API ISlangSharedLibraryLoader* spSessionGetSharedLibraryLoader( SlangSession* session); - /*! - @brief Returns SLANG_OK if a the compilation target is supported for this session - @param session Session - @param target The compilation target to test - @return SLANG_OK if the target is available - SLANG_E_NOT_IMPLEMENTED if not implemented in this build - SLANG_E_NOT_FOUND if other resources (such as shared libraries) required to make target work could not be found - SLANG_FAIL other kinds of failures */ + /** @see slang::IGlobalSession::checkCompileTargetSupport + */ SLANG_API SlangResult spSessionCheckCompileTargetSupport( SlangSession* session, SlangCompileTarget target); - /*! - @brief Returns SLANG_OK if a the pass through support is supported for this session - @param session Session - @param target The compilation target to test - @return SLANG_OK if the target is available - SLANG_E_NOT_IMPLEMENTED if not implemented in this build - SLANG_E_NOT_FOUND if other resources (such as shared libraries) required to make target work could not be found - SLANG_FAIL other kinds of failures */ + /** @see slang::IGlobalSession::checkPassThroughSupport + */ SLANG_API SlangResult spSessionCheckPassThroughSupport( SlangSession* session, SlangPassThrough passThrough ); - /*! - @brief Add new builtin declarations to be used in subsequent compiles. + /** @see slang::IGlobalSession::addBuiltins */ SLANG_API void spAddBuiltins( SlangSession* session, char const* sourcePath, char const* sourceString); + /*! + @brief Callback type used for diagnostic output. + */ + typedef void(*SlangDiagnosticCallback)( + char const* message, + void* userData); + /*! - @brief Create a compile request. + @brief Get the build version 'tag' string. The string is the same as produced via `git describe --tags` + for the project. If Slang is built separately from the automated build scripts + the contents will by default be 'unknown'. Any string can be set by changing the + contents of 'slang-tag-version.h' file and recompiling the project. + + This function will return exactly the same result as the method getBuildTag string on IGlobalSession. + + An advantage of using this function over the method is that doing so does not require the creation of + a session, which can be a fairly costly operation. + + @return The build tag string + */ + SLANG_API const char* spGetBuildTagString(); + + /* @see slang::IGlobalSession::createCompileRequest */ SLANG_API SlangCompileRequest* spCreateCompileRequest( SlangSession* session); /*! @brief Destroy a compile request. + Note a request is a COM object and can be destroyed via 'Release'. */ SLANG_API void spDestroyCompileRequest( SlangCompileRequest* request); - /** Set the filesystem hook to use for a compile request - - The provided `fileSystem` will be used to load any files that - need to be loaded during processing of the compile `request`. - This includes: - - - Source files loaded via `spAddTranslationUnitSourceFile` - - Files referenced via `#include` - - Files loaded to resolve `#import` operations - - */ + /*! @see slang::ICompileRequest::setFileSystem */ SLANG_API void spSetFileSystem( SlangCompileRequest* request, ISlangFileSystem* fileSystem); - - /*! - @brief Set flags to be used for compilation. - */ + /*! @see slang::ICompileRequest::setCompileFlags */ SLANG_API void spSetCompileFlags( SlangCompileRequest* request, SlangCompileFlags flags); - /*! - @brief Set whether to dump intermediate results (for debugging) or not. - */ + /*! @see slang::ICompileRequest::setDumpIntermediates */ SLANG_API void spSetDumpIntermediates( SlangCompileRequest* request, int enable); + /*! @see slang::ICompileRequest::setDumpIntermediatePrefix */ SLANG_API void spSetDumpIntermediatePrefix( SlangCompileRequest* request, const char* prefix); - /*! - @brief Set whether (and how) `#line` directives should be output. - */ + /*! @see slang::ICompileRequest::setLineDirectiveMode */ SLANG_API void spSetLineDirectiveMode( SlangCompileRequest* request, SlangLineDirectiveMode mode); - /*! - @brief Sets the target for code generation. - @param request The compilation context. - @param target The code generation target. Possible values are: - - SLANG_GLSL. Generates GLSL code. - - SLANG_HLSL. Generates HLSL code. - - SLANG_SPIRV. Generates SPIR-V code. - */ + /*! @see slang::ICompileRequest::setCodeGenTarget */ SLANG_API void spSetCodeGenTarget( SlangCompileRequest* request, SlangCompileTarget target); - /*! - @brief Add a code-generation target to be used. - */ + /*! @see slang::ICompileRequest::addCodeGenTarget */ SLANG_API int spAddCodeGenTarget( SlangCompileRequest* request, SlangCompileTarget target); + /*! @see slang::ICompileRequest::setTargetProfile */ SLANG_API void spSetTargetProfile( SlangCompileRequest* request, int targetIndex, SlangProfileID profile); + /*! @see slang::ICompileRequest::setTargetFlags */ SLANG_API void spSetTargetFlags( SlangCompileRequest* request, int targetIndex, @@ -1303,9 +1282,7 @@ extern "C" - /*! - @brief Set the floating point mode (e.g., precise or fast) to use a target. - */ + /*! @see slang::ICompileRequest::setTargetFloatingPointMode */ SLANG_API void spSetTargetFloatingPointMode( SlangCompileRequest* request, int targetIndex, @@ -1317,122 +1294,80 @@ extern "C" int targetIndex, SlangMatrixLayoutMode mode); + /*! @see slang::ICompileRequest::setMatrixLayoutMode */ SLANG_API void spSetMatrixLayoutMode( SlangCompileRequest* request, SlangMatrixLayoutMode mode); - /*! - @brief Set the level of debug information to produce. - */ + /*! @see slang::ICompileRequest::setDebugInfoLevel */ SLANG_API void spSetDebugInfoLevel( SlangCompileRequest* request, SlangDebugInfoLevel level); - /*! - @brief Set the level of optimization to perform. - */ + /*! @see slang::ICompileRequest::setOptimizationLevel */ SLANG_API void spSetOptimizationLevel( SlangCompileRequest* request, SlangOptimizationLevel level); - /*! - @brief Get the build version 'tag' string. The string is the same as produced via `git describe --tags` - for the project. If Slang is built separately from the automated build scripts - the contents will by default be 'unknown'. Any string can be set by changing the - contents of 'slang-tag-version.h' file and recompiling the project. - - This function will return exactly the same result as the method getBuildTag string on IGlobalSession. - - An advantage of using this function over the method is that doing so does not require the creation of - a session, which can be a fairly costly operation. - - @return The build tag string - */ - SLANG_API const char* spGetBuildTagString(); - - /*! - @brief Set the container format to be used for binary output. - */ + + /*! @see slang::ICompileRequest::setOutputContainerFormat */ SLANG_API void spSetOutputContainerFormat( SlangCompileRequest* request, SlangContainerFormat format); + /*! @see slang::ICompileRequest::setPassThrough */ SLANG_API void spSetPassThrough( SlangCompileRequest* request, SlangPassThrough passThrough); - typedef void(*SlangDiagnosticCallback)( - char const* message, - void* userData); - + /*! @see slang::ICompileRequest::setDiagnosticCallback */ SLANG_API void spSetDiagnosticCallback( SlangCompileRequest* request, SlangDiagnosticCallback callback, void const* userData); + /*! @see slang::ICompileRequest::setWriter */ SLANG_API void spSetWriter( SlangCompileRequest* request, SlangWriterChannel channel, ISlangWriter* writer); + /*! @see slang::ICompileRequest::getWriter */ SLANG_API ISlangWriter* spGetWriter( SlangCompileRequest* request, SlangWriterChannel channel); - /*! - @brief Add a path to use when searching for referenced files. - This will be used for both `#include` directives and also for explicit `__import` declarations. - @param ctx The compilation context. - @param searchDir The additional search directory. - */ + /*! @see slang::ICompileRequest::addSearchPath */ SLANG_API void spAddSearchPath( SlangCompileRequest* request, const char* searchDir); - /*! - @brief Add a macro definition to be used during preprocessing. - @param key The name of the macro to define. - @param value The value of the macro to define. - */ + /*! @see slang::ICompileRequest::addPreprocessorDefine */ SLANG_API void spAddPreprocessorDefine( SlangCompileRequest* request, const char* key, const char* value); - /*! - @brief Set options using arguments as if specified via command line. - @return Returns SlangResult. On success SLANG_SUCCEEDED(result) is true. - */ + /*! @see slang::ICompileRequest::processCommandLineArguments */ SLANG_API SlangResult spProcessCommandLineArguments( SlangCompileRequest* request, char const* const* args, int argCount); - /** Add a distinct translation unit to the compilation request - - `name` is optional. - Returns the zero-based index of the translation unit created. - */ + /*! @see slang::ICompileRequest::addTranslationUnit */ SLANG_API int spAddTranslationUnit( SlangCompileRequest* request, SlangSourceLanguage language, char const* name); - /** Set a default module name. Translation units will default to this module name if one is not - passed. If not set each translation unit will get a unique name. - */ + /*! @see slang::ICompileRequest::setDefaultModuleName */ SLANG_API void spSetDefaultModuleName( SlangCompileRequest* request, const char* defaultModuleName); - /** Add a preprocessor definition that is scoped to a single translation unit. - - @param translationUnitIndex The index of the translation unit to get the definition. - @param key The name of the macro to define. - @param value The value of the macro to define. - */ + /*! @see slang::ICompileRequest::addPreprocessorDefine */ SLANG_API void spTranslationUnit_addPreprocessorDefine( SlangCompileRequest* request, int translationUnitIndex, @@ -1440,36 +1375,13 @@ extern "C" const char* value); - /** Add a source file to the given translation unit. - - If a user-defined file system has been specified via - `spSetFileSystem`, then it will be used to load the - file at `path`. Otherwise, Slang will use the OS - file system. - - This function does *not* search for a file using - the registered search paths (`spAddSearchPath`), - and instead using the given `path` as-is. - */ + /*! @see slang::ICompileRequest::addTranslationUnitSourceFile */ SLANG_API void spAddTranslationUnitSourceFile( SlangCompileRequest* request, int translationUnitIndex, char const* path); - /** Add a source string to the given translation unit. - - @param request The compile request that owns the translation unit. - @param translationUnitIndex The index of the translation unit to add source to. - @param path The file-system path that should be assumed for the source code. - @param source A null-terminated UTF-8 encoded string of source code. - - The implementation will make a copy of the source code data. - An application may free the buffer immediately after this call returns. - - The `path` will be used in any diagnostic output, as well - as to determine the base path when resolving relative - `#include`s. - */ + /*! @see slang::ICompileRequest::addTranslationUnitSourceString */ SLANG_API void spAddTranslationUnitSourceString( SlangCompileRequest* request, int translationUnitIndex, @@ -1477,33 +1389,13 @@ extern "C" char const* source); - /** Add a slang library - such that its contents can be referenced during linking. - This is equivalent to the -r command line option. - - @param request The compile request - @param libData The library data - @param libDataSize The size of the library data - */ + /*! @see slang::ICompileRequest::addLibraryReference */ SLANG_API SlangResult spAddLibraryReference( SlangCompileRequest* request, const void* libData, size_t libDataSize); - /** Add a source string to the given translation unit. - - @param request The compile request that owns the translation unit. - @param translationUnitIndex The index of the translation unit to add source to. - @param path The file-system path that should be assumed for the source code. - @param sourceBegin A pointer to a buffer of UTF-8 encoded source code. - @param sourceEnd A pointer to to the end of the buffer specified in `sourceBegin` - - The implementation will make a copy of the source code data. - An application may free the buffer immediately after this call returns. - - The `path` will be used in any diagnostic output, as well - as to determine the base path when resolving relative - `#include`s. - */ + /*! @see slang::ICompileRequest::addTranslationUnitSourceStringSpan */ SLANG_API void spAddTranslationUnitSourceStringSpan( SlangCompileRequest* request, int translationUnitIndex, @@ -1511,46 +1403,26 @@ extern "C" char const* sourceBegin, char const* sourceEnd); - /** Add a blob of source code to the given translation unit. - - @param request The compile request that owns the translation unit. - @param translationUnitIndex The index of the translation unit to add source to. - @param path The file-system path that should be assumed for the source code. - @param sourceBlob A blob containing UTF-8 encoded source code. - @param sourceEnd A pointer to to the end of the buffer specified in `sourceBegin` - - The compile request will retain a reference to the blob. - - The `path` will be used in any diagnostic output, as well - as to determine the base path when resolving relative - `#include`s. - */ + /*! @see slang::ICompileRequest::addTranslationUnitSourceBlob */ SLANG_API void spAddTranslationUnitSourceBlob( SlangCompileRequest* request, int translationUnitIndex, char const* path, ISlangBlob* sourceBlob); - /** Look up a compilation profile by name. - - For example, one could look up the string `"ps_5_0"` to find the corresponding target ID. - */ + /*! @see slang::ICompileRequest::findProfile */ SLANG_API SlangProfileID spFindProfile( SlangSession* session, char const* name); - /** Add an entry point in a particular translation unit - */ + /*! @see slang::ICompileRequest::addEntryPoint */ SLANG_API int spAddEntryPoint( SlangCompileRequest* request, int translationUnitIndex, char const* name, SlangStage stage); - /** Add an entry point in a particular translation unit, - with additional arguments that specify the concrete - type names for entry-point generic type parameters. - */ + /*! @see slang::ICompileRequest::addEntryPointEx */ SLANG_API int spAddEntryPointEx( SlangCompileRequest* request, int translationUnitIndex, @@ -1559,248 +1431,121 @@ extern "C" int genericArgCount, char const** genericArgs); - /** Specify the arguments to use for global generic parameters. - */ + /*! @see slang::ICompileRequest::setGlobalGenericArgs */ SLANG_API SlangResult spSetGlobalGenericArgs( SlangCompileRequest* request, int genericArgCount, char const** genericArgs); - /** Specify the concrete type to be used for a global "existential slot." - - Every shader parameter (or leaf field of a `struct`-type shader parameter) - that has an interface or array-of-interface type introduces an existential - slot. The number of slots consumed by a shader parameter, and the starting - slot of each parameter can be queried via the reflection API using - `SLANG_PARAMETER_CATEGORY_EXISTENTIAL_TYPE_PARAM`. - - In order to generate specialized code, a concrete type needs to be specified - for each existential slot. This function specifies the name of the type - (or in general a type *expression*) to use for a specific slot at the - global scope. - */ + /*! @see slang::ICompileRequest::setTypeNameForGlobalExistentialTypeParam */ SLANG_API SlangResult spSetTypeNameForGlobalExistentialTypeParam( SlangCompileRequest* request, int slotIndex, char const* typeName); - /** Specify the concrete type to be used for an entry-point "existential slot." - - Every shader parameter (or leaf field of a `struct`-type shader parameter) - that has an interface or array-of-interface type introduces an existential - slot. The number of slots consumed by a shader parameter, and the starting - slot of each parameter can be queried via the reflection API using - `SLANG_PARAMETER_CATEGORY_EXISTENTIAL_TYPE_PARAM`. - - In order to generate specialized code, a concrete type needs to be specified - for each existential slot. This function specifies the name of the type - (or in general a type *expression*) to use for a specific slot at the - entry-point scope. - */ + /*! @see slang::ICompileRequest::setTypeNameForEntryPointExistentialTypeParam */ SLANG_API SlangResult spSetTypeNameForEntryPointExistentialTypeParam( SlangCompileRequest* request, int entryPointIndex, int slotIndex, char const* typeName); - /** Execute the compilation request. - - @returns SlangResult, SLANG_OK on success. Use SLANG_SUCCEEDED() and SLANG_FAILED() to test SlangResult. - */ + /*! @see slang::ICompileRequest::compile */ SLANG_API SlangResult spCompile( SlangCompileRequest* request); - /** Get any diagnostic messages reported by the compiler. - - @returns A null-terminated UTF-8 encoded string of diagnostic messages. - - The returned pointer is only guaranteed to be valid - until `request` is destroyed. Applications that wish to - hold on to the diagnostic output for longer should use - `spGetDiagnosticOutputBlob`. - */ + /*! @see slang::ICompileRequest::getDiagnosticOutput */ SLANG_API char const* spGetDiagnosticOutput( SlangCompileRequest* request); - /** Get diagnostic messages reported by the compiler. - - @param request The compile request to get output from. - @param outBlob A pointer to receive a blob holding a nul-terminated UTF-8 encoded string of diagnostic messages. - @returns A `SlangResult` indicating success or failure. - */ + /*! @see slang::ICompileRequest::getDiagnosticOutputBlob */ SLANG_API SlangResult spGetDiagnosticOutputBlob( SlangCompileRequest* request, ISlangBlob** outBlob); - /** Get the number of files that this compilation depended on. - - This includes both the explicit source files, as well as any - additional files that were transitively referenced (e.g., via - a `#include` directive). - */ + /*! @see slang::ICompileRequest::getDependencyFileCount */ SLANG_API int spGetDependencyFileCount( SlangCompileRequest* request); - /** Get the path to a file this compilation depended on. - */ + /*! @see slang::ICompileRequest::getDependencyFilePath */ SLANG_API char const* spGetDependencyFilePath( SlangCompileRequest* request, int index); - /** Get the number of translation units associated with the compilation request - */ + /*! @see slang::ICompileRequest::getTranslationUnitCount */ SLANG_API int spGetTranslationUnitCount( SlangCompileRequest* request); - /** Get the output source code associated with a specific entry point. - - The lifetime of the output pointer is the same as `request`. - */ + /*! @see slang::ICompileRequest::getEntryPointSource */ SLANG_API char const* spGetEntryPointSource( SlangCompileRequest* request, int entryPointIndex); - /** Get the output bytecode associated with a specific entry point. - - The lifetime of the output pointer is the same as `request`. - */ + /*! @see slang::ICompileRequest::getEntryPointCode */ SLANG_API void const* spGetEntryPointCode( SlangCompileRequest* request, int entryPointIndex, size_t* outSize); - /** Get the output code associated with a specific entry point. - - @param request The request - @param entryPointIndex The index of the entry point to get code for. - @param targetIndex The index of the target to get code for (default: zero). - @param outBlob A pointer that will receive the blob of code - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getEntryPointCodeBlob */ SLANG_API SlangResult spGetEntryPointCodeBlob( SlangCompileRequest* request, int entryPointIndex, int targetIndex, ISlangBlob** outBlob); - /** Get entry point 'callable' functions accessible through the ISlangSharedLibrary interface. - - That the functions remain in scope as long as the ISlangSharedLibrary interface is in scope. - - NOTE! Requires a compilation target of SLANG_HOST_CALLABLE. - - @param request The request - @param entryPointIndex The index of the entry point to get code for. - @param targetIndex The index of the target to get code for (default: zero). - @param outSharedLibrary A pointer to a ISharedLibrary interface which functions can be queried on. - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getEntryPointHostCallable */ SLANG_API SlangResult spGetEntryPointHostCallable( SlangCompileRequest* request, int entryPointIndex, int targetIndex, ISlangSharedLibrary** outSharedLibrary); - /** Get the output code associated with a specific target. - - @param request The request - @param targetIndex The index of the target to get code for (default: zero). - @param outBlob A pointer that will receive the blob of code - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getTargetCodeBlob */ SLANG_API SlangResult spGetTargetCodeBlob( SlangCompileRequest* request, int targetIndex, ISlangBlob** outBlob); - /** Get 'callable' functions for a target accessible through the ISlangSharedLibrary interface. - - That the functions remain in scope as long as the ISlangSharedLibrary interface is in scope. - - NOTE! Requires a compilation target of SLANG_HOST_CALLABLE. - - @param request The request - @param targetIndex The index of the target to get code for (default: zero). - @param outSharedLibrary A pointer to a ISharedLibrary interface which functions can be queried on. - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getTargetHostCallable */ SLANG_API SlangResult spGetTargetHostCallable( SlangCompileRequest* request, int targetIndex, ISlangSharedLibrary** outSharedLibrary); - /** Get the output bytecode associated with an entire compile request. - - The lifetime of the output pointer is the same as `request` and the last spCompile. - - @param request The request - @param outSize The size of the containers contents in bytes. Will be zero if there is no code available. - @returns Pointer to start of the contained data, or nullptr if there is no code available. - */ + /*! @see slang::ICompileRequest::getCompileRequestCode */ SLANG_API void const* spGetCompileRequestCode( SlangCompileRequest* request, size_t* outSize); - /** Return the container code as a blob. The container blob is created as part of a compilation (with spCompile), - and a container is produced with a suitable ContainerFormat. - - @param request The request - @param outSize The blob containing the container data. - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getContainerCode */ SLANG_API SlangResult spGetContainerCode( SlangCompileRequest* request, ISlangBlob** outBlob); - /** Load repro from memory specified. - - Should only be performed on a newly created request. - - NOTE! When using the fileSystem, files will be loaded via their `unique names` as if they are part of the flat file system. This - mechanism is described more fully in docs/repro.md. - - @param request The request - @param fileSystem An (optional) filesystem. Pass nullptr to just use contents of repro held in data. - @param data The data to load from. - @param size The size of the data to load from. - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::loadRepro */ SLANG_API SlangResult spLoadRepro( SlangCompileRequest* request, ISlangFileSystem* fileSystem, const void* data, size_t size); - /** Save repro state. Should *typically* be performed after spCompile, so that everything - that is needed for a compilation is available. - - @param request The request - @param outBlob Blob that will hold the serialized state - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::saveRepro */ SLANG_API SlangResult spSaveRepro( SlangCompileRequest* request, ISlangBlob** outBlob ); - /** Enable repro capture. - - Should be set after any ISlangFileSystem has been set, but before any compilation. It ensures that everything - that the ISlangFileSystem accesses will be correctly recorded. - Note that if a ISlangFileSystem/ISlangFileSystemExt isn't explicitly set (ie the default is used), then the - request will automatically be set up to record everything appropriate. - - @param request The request - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::enableReproCapture */ SLANG_API SlangResult spEnableReproCapture( SlangCompileRequest* request); + /** Extract contents of a repro. Writes the contained files and manifest with their 'unique' names into fileSystem. For more details read the @@ -3032,7 +2777,48 @@ namespace slang SlangSourceLanguage sourceLanguage, ISlangBlob** outPrelude) = 0; - + /** Create a compile request. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL createCompileRequest( + slang::ICompileRequest** outCompileRequest) = 0; + + /** Add new builtin declarations to be used in subsequent compiles. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addBuiltins( + char const* sourcePath, + char const* sourceString) = 0; + + /** Set the session shared library loader. If this changes the loader, it may cause shared libraries to be unloaded + @param loader The loader to set. Setting nullptr sets the default loader. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setSharedLibraryLoader( + ISlangSharedLibraryLoader* loader) = 0; + + /** Gets the currently set shared library loader + @return Gets the currently set loader. If returns nullptr, it's the default loader + */ + virtual SLANG_NO_THROW ISlangSharedLibraryLoader* SLANG_MCALL getSharedLibraryLoader() = 0; + + /** Returns SLANG_OK if a the compilation target is supported for this session + + @param target The compilation target to test + @return SLANG_OK if the target is available + SLANG_E_NOT_IMPLEMENTED if not implemented in this build + SLANG_E_NOT_FOUND if other resources (such as shared libraries) required to make target work could not be found + SLANG_FAIL other kinds of failures */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL checkCompileTargetSupport( + SlangCompileTarget target) = 0; + + /** Returns SLANG_OK if a the pass through support is supported for this session + @param session Session + @param target The compilation target to test + @return SLANG_OK if the target is available + SLANG_E_NOT_IMPLEMENTED if not implemented in this build + SLANG_E_NOT_FOUND if other resources (such as shared libraries) required to make target work could not be found + SLANG_FAIL other kinds of failures */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL checkPassThroughSupport( + SlangPassThrough passThrough) = 0; + /** Compile from (embedded source) the StdLib on the session. Will return a failure if there is already a StdLib available NOTE! API is experimental and not ready for production code @@ -3051,6 +2837,541 @@ namespace slang #define SLANG_UUID_IGlobalSession { 0xc140b5fd, 0xc78, 0x452e, { 0xba, 0x7c, 0x1a, 0x1e, 0x70, 0xc7, 0xf7, 0x1c } }; + /*! + @brief A request for one or more compilation actions to be performed. + */ + struct ICompileRequest : public ISlangUnknown + { + public: + + /** Set the filesystem hook to use for a compile request + + The provided `fileSystem` will be used to load any files that + need to be loaded during processing of the compile `request`. + This includes: + + - Source files loaded via `spAddTranslationUnitSourceFile` + - Files referenced via `#include` + - Files loaded to resolve `#import` operations + */ + virtual SLANG_NO_THROW void SLANG_MCALL setFileSystem( + ISlangFileSystem* fileSystem) = 0; + + /*! + @brief Set flags to be used for compilation. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setCompileFlags( + SlangCompileFlags flags) = 0; + + /*! + @brief Set whether to dump intermediate results (for debugging) or not. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setDumpIntermediates( + int enable) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setDumpIntermediatePrefix( + const char* prefix) = 0; + + /*! + @brief Set whether (and how) `#line` directives should be output. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setLineDirectiveMode( + SlangLineDirectiveMode mode) = 0; + + /*! + @brief Sets the target for code generation. + @param target The code generation target. Possible values are: + - SLANG_GLSL. Generates GLSL code. + - SLANG_HLSL. Generates HLSL code. + - SLANG_SPIRV. Generates SPIR-V code. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setCodeGenTarget( + SlangCompileTarget target) = 0; + + /*! + @brief Add a code-generation target to be used. + */ + virtual SLANG_NO_THROW int SLANG_MCALL addCodeGenTarget( + SlangCompileTarget target) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setTargetProfile( + int targetIndex, + SlangProfileID profile) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setTargetFlags( + int targetIndex, + SlangTargetFlags flags) = 0; + + + /*! + @brief Set the floating point mode (e.g., precise or fast) to use a target. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setTargetFloatingPointMode( + int targetIndex, + SlangFloatingPointMode mode) = 0; + + /* DEPRECATED: use `spSetMatrixLayoutMode` instead. */ + virtual SLANG_NO_THROW void SLANG_MCALL setTargetMatrixLayoutMode( + int targetIndex, + SlangMatrixLayoutMode mode) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setMatrixLayoutMode( + SlangMatrixLayoutMode mode) = 0; + + /*! + @brief Set the level of debug information to produce. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setDebugInfoLevel( + SlangDebugInfoLevel level) = 0; + + /*! + @brief Set the level of optimization to perform. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setOptimizationLevel( + SlangOptimizationLevel level) = 0; + + + + /*! + @brief Set the container format to be used for binary output. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setOutputContainerFormat( + SlangContainerFormat format) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setPassThrough( + SlangPassThrough passThrough) = 0; + + + virtual SLANG_NO_THROW void SLANG_MCALL setDiagnosticCallback( + SlangDiagnosticCallback callback, + void const* userData) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setWriter( + SlangWriterChannel channel, + ISlangWriter* writer) = 0; + + virtual SLANG_NO_THROW ISlangWriter* SLANG_MCALL getWriter( + SlangWriterChannel channel) = 0; + + /*! + @brief Add a path to use when searching for referenced files. + This will be used for both `#include` directives and also for explicit `__import` declarations. + @param ctx The compilation context. + @param searchDir The additional search directory. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addSearchPath( + const char* searchDir) = 0; + + /*! + @brief Add a macro definition to be used during preprocessing. + @param key The name of the macro to define. + @param value The value of the macro to define. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addPreprocessorDefine( + const char* key, + const char* value) = 0; + + /*! + @brief Set options using arguments as if specified via command line. + @return Returns SlangResult. On success SLANG_SUCCEEDED(result) is true. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL processCommandLineArguments( + char const* const* args, + int argCount) = 0; + + /** Add a distinct translation unit to the compilation request + + `name` is optional. + Returns the zero-based index of the translation unit created. + */ + virtual SLANG_NO_THROW int SLANG_MCALL addTranslationUnit( + SlangSourceLanguage language, + char const* name) = 0; + + + /** Set a default module name. Translation units will default to this module name if one is not + passed. If not set each translation unit will get a unique name. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setDefaultModuleName( + const char* defaultModuleName) = 0; + + /** Add a preprocessor definition that is scoped to a single translation unit. + + @param translationUnitIndex The index of the translation unit to get the definition. + @param key The name of the macro to define. + @param value The value of the macro to define. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitPreprocessorDefine( + int translationUnitIndex, + const char* key, + const char* value) = 0; + + + /** Add a source file to the given translation unit. + + If a user-defined file system has been specified via + `spSetFileSystem`, then it will be used to load the + file at `path`. Otherwise, Slang will use the OS + file system. + + This function does *not* search for a file using + the registered search paths (`spAddSearchPath`), + and instead using the given `path` as-is. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceFile( + int translationUnitIndex, + char const* path) = 0; + + /** Add a source string to the given translation unit. + + @param translationUnitIndex The index of the translation unit to add source to. + @param path The file-system path that should be assumed for the source code. + @param source A null-terminated UTF-8 encoded string of source code. + + The implementation will make a copy of the source code data. + An application may free the buffer immediately after this call returns. + + The `path` will be used in any diagnostic output, as well + as to determine the base path when resolving relative + `#include`s. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceString( + int translationUnitIndex, + char const* path, + char const* source) = 0; + + + /** Add a slang library - such that its contents can be referenced during linking. + This is equivalent to the -r command line option. + + @param libData The library data + @param libDataSize The size of the library data + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL addLibraryReference( + const void* libData, + size_t libDataSize) = 0; + + /** Add a source string to the given translation unit. + + @param translationUnitIndex The index of the translation unit to add source to. + @param path The file-system path that should be assumed for the source code. + @param sourceBegin A pointer to a buffer of UTF-8 encoded source code. + @param sourceEnd A pointer to to the end of the buffer specified in `sourceBegin` + + The implementation will make a copy of the source code data. + An application may free the buffer immediately after this call returns. + + The `path` will be used in any diagnostic output, as well + as to determine the base path when resolving relative + `#include`s. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceStringSpan( + int translationUnitIndex, + char const* path, + char const* sourceBegin, + char const* sourceEnd) = 0; + + /** Add a blob of source code to the given translation unit. + + @param translationUnitIndex The index of the translation unit to add source to. + @param path The file-system path that should be assumed for the source code. + @param sourceBlob A blob containing UTF-8 encoded source code. + @param sourceEnd A pointer to to the end of the buffer specified in `sourceBegin` + + The compile request will retain a reference to the blob. + + The `path` will be used in any diagnostic output, as well + as to determine the base path when resolving relative + `#include`s. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceBlob( + int translationUnitIndex, + char const* path, + ISlangBlob* sourceBlob) = 0; + + /** Add an entry point in a particular translation unit + */ + virtual SLANG_NO_THROW int SLANG_MCALL addEntryPoint( + int translationUnitIndex, + char const* name, + SlangStage stage) = 0; + + /** Add an entry point in a particular translation unit, + with additional arguments that specify the concrete + type names for entry-point generic type parameters. + */ + virtual SLANG_NO_THROW int SLANG_MCALL addEntryPointEx( + int translationUnitIndex, + char const* name, + SlangStage stage, + int genericArgCount, + char const** genericArgs) = 0; + + /** Specify the arguments to use for global generic parameters. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setGlobalGenericArgs( + int genericArgCount, + char const** genericArgs) = 0; + + /** Specify the concrete type to be used for a global "existential slot." + + Every shader parameter (or leaf field of a `struct`-type shader parameter) + that has an interface or array-of-interface type introduces an existential + slot. The number of slots consumed by a shader parameter, and the starting + slot of each parameter can be queried via the reflection API using + `SLANG_PARAMETER_CATEGORY_EXISTENTIAL_TYPE_PARAM`. + + In order to generate specialized code, a concrete type needs to be specified + for each existential slot. This function specifies the name of the type + (or in general a type *expression*) to use for a specific slot at the + global scope. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setTypeNameForGlobalExistentialTypeParam( + int slotIndex, + char const* typeName) = 0; + + /** Specify the concrete type to be used for an entry-point "existential slot." + + Every shader parameter (or leaf field of a `struct`-type shader parameter) + that has an interface or array-of-interface type introduces an existential + slot. The number of slots consumed by a shader parameter, and the starting + slot of each parameter can be queried via the reflection API using + `SLANG_PARAMETER_CATEGORY_EXISTENTIAL_TYPE_PARAM`. + + In order to generate specialized code, a concrete type needs to be specified + for each existential slot. This function specifies the name of the type + (or in general a type *expression*) to use for a specific slot at the + entry-point scope. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setTypeNameForEntryPointExistentialTypeParam( + int entryPointIndex, + int slotIndex, + char const* typeName) = 0; + + /** Execute the compilation request. + + @returns SlangResult, SLANG_OK on success. Use SLANG_SUCCEEDED() and SLANG_FAILED() to test SlangResult. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL compile() = 0; + + + /** Get any diagnostic messages reported by the compiler. + + @returns A null-terminated UTF-8 encoded string of diagnostic messages. + + The returned pointer is only guaranteed to be valid + until `request` is destroyed. Applications that wish to + hold on to the diagnostic output for longer should use + `getDiagnosticOutputBlob`. + */ + virtual SLANG_NO_THROW char const* SLANG_MCALL getDiagnosticOutput() = 0; + + /** Get diagnostic messages reported by the compiler. + + @param outBlob A pointer to receive a blob holding a nul-terminated UTF-8 encoded string of diagnostic messages. + @returns A `SlangResult` indicating success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getDiagnosticOutputBlob( + ISlangBlob** outBlob) = 0; + + + /** Get the number of files that this compilation depended on. + + This includes both the explicit source files, as well as any + additional files that were transitively referenced (e.g., via + a `#include` directive). + */ + virtual SLANG_NO_THROW int SLANG_MCALL getDependencyFileCount() = 0; + + /** Get the path to a file this compilation depended on. + */ + virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath( + int index) = 0; + + /** Get the number of translation units associated with the compilation request + */ + virtual SLANG_NO_THROW int SLANG_MCALL getTranslationUnitCount() = 0; + + /** Get the output source code associated with a specific entry point. + + The lifetime of the output pointer is the same as `request`. + */ + virtual SLANG_NO_THROW char const* SLANG_MCALL getEntryPointSource( + int entryPointIndex) = 0; + + /** Get the output bytecode associated with a specific entry point. + + The lifetime of the output pointer is the same as `request`. + */ + virtual SLANG_NO_THROW void const* SLANG_MCALL getEntryPointCode( + int entryPointIndex, + size_t* outSize) = 0; + + /** Get the output code associated with a specific entry point. + + @param entryPointIndex The index of the entry point to get code for. + @param targetIndex The index of the target to get code for (default: zero). + @param outBlob A pointer that will receive the blob of code + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCodeBlob( + int entryPointIndex, + int targetIndex, + ISlangBlob** outBlob) = 0; + + /** Get entry point 'callable' functions accessible through the ISlangSharedLibrary interface. + + That the functions remain in scope as long as the ISlangSharedLibrary interface is in scope. + + NOTE! Requires a compilation target of SLANG_HOST_CALLABLE. + + @param entryPointIndex The index of the entry point to get code for. + @param targetIndex The index of the target to get code for (default: zero). + @param outSharedLibrary A pointer to a ISharedLibrary interface which functions can be queried on. + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointHostCallable( + int entryPointIndex, + int targetIndex, + ISlangSharedLibrary** outSharedLibrary) = 0; + + /** Get the output code associated with a specific target. + + @param targetIndex The index of the target to get code for (default: zero). + @param outBlob A pointer that will receive the blob of code + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCodeBlob( + int targetIndex, + ISlangBlob** outBlob) = 0; + + /** Get 'callable' functions for a target accessible through the ISlangSharedLibrary interface. + + That the functions remain in scope as long as the ISlangSharedLibrary interface is in scope. + + NOTE! Requires a compilation target of SLANG_HOST_CALLABLE. + + @param targetIndex The index of the target to get code for (default: zero). + @param outSharedLibrary A pointer to a ISharedLibrary interface which functions can be queried on. + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetHostCallable( + int targetIndex, + ISlangSharedLibrary** outSharedLibrary) = 0; + + /** Get the output bytecode associated with an entire compile request. + + The lifetime of the output pointer is the same as `request` and the last spCompile. + + @param outSize The size of the containers contents in bytes. Will be zero if there is no code available. + @returns Pointer to start of the contained data, or nullptr if there is no code available. + */ + virtual SLANG_NO_THROW void const* SLANG_MCALL getCompileRequestCode( + size_t* outSize) = 0; + + /** Return the container code as a blob. The container blob is created as part of a compilation (with spCompile), + and a container is produced with a suitable ContainerFormat. + + @param outSize The blob containing the container data. + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getContainerCode( + ISlangBlob** outBlob) = 0; + + /** Load repro from memory specified. + + Should only be performed on a newly created request. + + NOTE! When using the fileSystem, files will be loaded via their `unique names` as if they are part of the flat file system. This + mechanism is described more fully in docs/repro.md. + + @param fileSystem An (optional) filesystem. Pass nullptr to just use contents of repro held in data. + @param data The data to load from. + @param size The size of the data to load from. + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadRepro( + ISlangFileSystem* fileSystem, + const void* data, + size_t size) = 0; + + /** Save repro state. Should *typically* be performed after spCompile, so that everything + that is needed for a compilation is available. + + @param outBlob Blob that will hold the serialized state + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveRepro( + ISlangBlob** outBlob) = 0; + + /** Enable repro capture. + + Should be set after any ISlangFileSystem has been set, but before any compilation. It ensures that everything + that the ISlangFileSystem accesses will be correctly recorded. + Note that if a ISlangFileSystem/ISlangFileSystemExt isn't explicitly set (ie the default is used), then the + request will automatically be set up to record everything appropriate. + + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL enableReproCapture() = 0; + + /** Get the (linked) program for a compile request. + + The linked program will include all of the global-scope modules for the + translation units in the program, plus any modules that they `import` + (transitively), specialized to any global specialization arguments that + were provided via the API. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getProgram( + slang::IComponentType** outProgram) = 0; + + /** Get the (partially linked) component type for an entry point. + + The returned component type will include the entry point at the + given index, and will be specialized using any specialization arguments + that were provided for it via the API. + + The returned component will *not* include the modules representing + the global scope and its dependencies/specialization, so a client + program will typically want to compose this component type with + the one returned by `spCompileRequest_getProgram` to get a complete + and usable component type from which kernel code can be requested. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPoint( + SlangInt entryPointIndex, + slang::IComponentType** outEntryPoint) = 0; + + /** Get the (un-linked) module for a translation unit. + + The returned module will not be linked against any dependencies, + nor against any entry points (even entry points declared inside + the module). Similarly, the module will not be specialized + to the arguments that might have been provided via the API. + + This function provides an atomic unit of loaded code that + is suitable for looking up types and entry points in the + given module, and for linking together to produce a composite + program that matches the needs of an application. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getModule( + SlangInt translationUnitIndex, + slang::IModule** outModule) = 0; + + /** Get the `ISession` handle behind the `SlangCompileRequest`. + TODO(JS): Arguably this should just return the session pointer. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getSession( + slang::ISession** outSession) = 0; + + /** get reflection data from a compilation request */ + virtual SLANG_NO_THROW SlangReflection* SLANG_MCALL getReflection() = 0; + + /** Make output specially handled for command line output */ + virtual SLANG_NO_THROW void SLANG_MCALL setCommandLineCompilerMode() = 0; + }; + + #define SLANG_UUID_ICompileRequest { 0x96d33993, 0x317c, 0x4db5, { 0xaf, 0xd8, 0x66, 0x6e, 0xe7, 0x72, 0x48, 0xe2 } }; + /** Description of a code generation target. */ struct TargetDesc @@ -3225,7 +3546,7 @@ namespace slang TypeReflection* interfaceType, ISlangBlob** outNameBlob) = 0; - /** Get the sequantial ID used to identify a type witness in a dynamic object. + /** Get the sequential ID used to identify a type witness in a dynamic object. */ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTypeConformanceWitnessSequentialID( slang::TypeReflection* type, @@ -3471,52 +3792,27 @@ namespace slang } } -/** Get the (linked) program for a compile request. - -The linked program will include all of the global-scope modules for the -translation units in the program, plus any modules that they `import` -(transitively), specialized to any global specialization arguments that -were provided via the API. +/** @see slang::ICompileRequest::getProgram */ SLANG_API SlangResult spCompileRequest_getProgram( SlangCompileRequest* request, slang::IComponentType** outProgram); -/** Get the (partially linked) component type for an entry point. - -The returned component type will include the entry point at the -given index, and will be specialized using any specialization arguments -that were provided for it via the API. - -The returned component will *not* include the modules representing -the global scope and its dependencies/specialization, so a client -program will typically want to compose this component type with -the one returned by `spCompileRequest_getProgram` to get a complete -and usable component type from which kernel code can be requested. +/** @see slang::ICompileRequest::getEntryPoint */ SLANG_API SlangResult spCompileRequest_getEntryPoint( SlangCompileRequest* request, SlangInt entryPointIndex, slang::IComponentType** outEntryPoint); -/** Get the (un-linked) module for a translation unit. - -The returned module will not be linked against any dependencies, -nor against any entry points (even entry points declared inside -the module). Similarly, the module will not be specialized -to the arguments that might have been provided via the API. - -This function provides an atomic unit of loaded code that -is suitable for looking up types and entry points in the -given module, and for linking together to produce a composite -program that matches the needs of an application. +/** @see slang::ICompileRequest::getModule */ SLANG_API SlangResult spCompileRequest_getModule( SlangCompileRequest* request, SlangInt translationUnitIndex, slang::IModule** outModule); -/** Get the `ISession` handle behind the `SlangCompileRequest`. +/** @see slang::ICompileRequest::getSession */ SLANG_API SlangResult spCompileRequest_getSession( SlangCompileRequest* request, |
