<feed xmlns='http://www.w3.org/2005/Atom'>
<title>slang.git/source/slang/slang-emit.h, branch master</title>
<subtitle>Making it easier to work with shaders</subtitle>
<id>https://git.yummers.dev/slang.git/atom?h=master</id>
<link rel='self' href='https://git.yummers.dev/slang.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/'/>
<updated>2022-04-11T19:01:31+00:00</updated>
<entry>
<title>Refactor: eliminate BackEndCompileRequest (#2178)</title>
<updated>2022-04-11T19:01:31+00:00</updated>
<author>
<name>Theresa Foley</name>
<email>10618364+tangent-vector@users.noreply.github.com</email>
</author>
<published>2022-04-11T19:01:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=1409a5379d38ac153eabb4c19c7f4463a8b030ca'/>
<id>urn:sha1:1409a5379d38ac153eabb4c19c7f4463a8b030ca</id>
<content type='text'>
An earlier refactoring pass over the compiler codebase split the
type that had been called `CompileRequest` into three distinct
pieces:

* `FrontEndCompileRequest` which was supposed to own state and
  options related to running the compiler front end and producing
  IR + reflection (e.g., what translation units and source
  files/strings are included).

* `BackEndCompileRequest` which was supposed to own state and options
  related to running the compiler back end to translate the IR
  for a `ComponentType` (program) into output code. (Note that the
  `BackEndCompileRequest` was conceived of as orthogonal to the
  `TargetRequest`s, which store per-target and target-specific
  options.)

* `EndToEndCompileRequest` which was an umbrella object that owns
  separate front-end and back-end requests, plus any state that is
  only relevant when doing a true end-to-end compile (such as the
  kinds of compiles initiated with `slangc`). As originally conceived,
  the only state that this type was supposed to own was stuff related
  to "pass-through" compilation, as well as state related to writing
  of generated code to output files.

That refactoring work was very useful at the time, because it allowed
us to "scrub" the back end compilation steps to remove all
dependencies on front-end and AST state (this was important for our
goals of enabling linking and codegen from serialized Slang IR).

At this point, however, it is clear that the hierarchy that was built
up serves very little purpose:

* The `BackEndCompileRequest` type is only used in two places:

    * As part of an `EndToEndCompileRequest`, where the settings on
      the `BackEndCompileRequest` can be configured, but only through
      the `EndToEndCompileRequest`

    * As part of on-demand code generation through the `IComponentType`
      APIs. In this case, the settings stored on the
      `BackEndCompileRequest` are not accessible to the application
      at all, and will always use their default values, so that
      instantiating a "request" object doesn't really make any sense.

* The `FrontEndCompileRequest` type has a similar situation:

    * Front-end compilation as part of an `EndToEndCompileRequest`
      supports user configuration of `FrontEndCompileRequest` settings,
      but only through the `EndToEndCompileRequest`

    * Front-end compilation triggered by an `import` or a `loadModule()`
      call does not support user configuration of settings at all. It
      will always derive all relevant settings from thsoe on the
      session ("linkage").

In addition, subsequent changes have been made to the compiler that
show a bit of a "code smell" and/or forward-looking worries for this
decomposition:

* In some cases we've had to add the same setting to multiple types
  in the breakdown (front-end, back-end, end-to-end, linkage, target,
  etc.) which makes it harder for us to validate that all the possible
  mixtures of state work correctly.

* Related to the above, in some cases we have manual logic that copies
  state from one of the objects in the breakdown to another, in order
  to ensure that the user's intention is actually followed.

* As a forward-looking concern, it seems that developers have sometimes
  added new configuration options and state to places that don't really
  make sense according to the rationale of the original decomposition
  (e.g., we probably don't want to have a lot of state that is only
  available via end-to-end requests, given that the API structure is
  meant to push users *away* from end-to-end compiles).

As a result of all of the above, I've been planning a large refactor
with the following big-picture goals:

* Eliminate `BackEndCompileRequest`

    * Move all relevant state/options from the back-end request to
      the end-to-end request, since that is the only place they could
      be set anyway.

    * Introduce a transient "context" type to be used for the duration
      of code generation that serves the main functions that back-end
      requests really served in the codebase

* Make `EndToEndCompileRequest` be a subclass of
  `FrontEndCompileRequest`

    * Consider addding a transient "context" type for front-end
      compiles that can be used in `import`-like cases rather than
      needing a full front-end request object. If this works, then
      eliminate `FrontEndCompileRequest` and be back to world with
      just a single `CompileRequest` type

* Move *all* compiler configuration options to a distinct type (named
  something like `CompilerConfig` or `CompilerOptions` or whatever)
  which stores setting as key-value pairs, and has a notion of
  "inheritance" such that one configuration can extend or build on top
  of another. Make all the relevant types use this catch-all structure
  instead of redundantly storing flags in many places.

This change deals with the first of those bullets: removeal of
`BackEndCompileRequest`. The addition of the `CodeGenContext` type is
perhaps an unncessary additional step, but making that change helps
clean up a bunch of the code related to per-target code generation,
so I think it is the right choice.

Co-authored-by: Yong He &lt;yonghe@outlook.com&gt;</content>
</entry>
<entry>
<title>Glslang refactor bugfix (#1863)</title>
<updated>2021-05-28T21:15:12+00:00</updated>
<author>
<name>jsmall-nvidia</name>
<email>jsmall@nvidia.com</email>
</author>
<published>2021-05-28T21:15:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=67486ee516ddc33806003727682cbfc68ab1f726'/>
<id>urn:sha1:67486ee516ddc33806003727682cbfc68ab1f726</id>
<content type='text'>
* #include an absolute path didn't work - because paths were taken to always be relative.

* Fix issue with with SLANG_ENABLE_GLSLANG_SUPPORT

* Update expected output from glslang-error.glsl

* Fix bug in glsl dissassembly.

* Make ExtensionTracker available even if source is not emitted.

* Only explicitly set extension tracker based on capability bits, if we are in pass through.

* Small simplification of invoke sourceEmit.</content>
</entry>
<entry>
<title>Multiple Entry Point Backend (#1437)</title>
<updated>2020-07-20T18:53:23+00:00</updated>
<author>
<name>Dietrich Geisler</name>
<email>dag368@cornell.edu</email>
</author>
<published>2020-07-20T18:53:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=115920406ebd747e02e1e6a8e4595f7d88eef0d9'/>
<id>urn:sha1:115920406ebd747e02e1e6a8e4595f7d88eef0d9</id>
<content type='text'>
* Multiple Entry Point Backend

This PR introduces changes to the IR linking, emitting, and options for
multiple entry points.  Specifically, this PR updates several locations
to support a (potentially empty) list of entry points, adding list infrastructure and looping over entry points as appropriate.

* Formatting change

* Updated unknown target case to not require an entry point

* Formatting and list consts updates

Co-authored-by: Tim Foley &lt;tfoleyNV@users.noreply.github.com&gt;</content>
</entry>
<entry>
<title>Fix bug in slang-dxc-support where it didn't get the source path correctly (#1420)</title>
<updated>2020-07-01T18:20:42+00:00</updated>
<author>
<name>jsmall-nvidia</name>
<email>jsmall@nvidia.com</email>
</author>
<published>2020-07-01T18:20:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=5c153295205d2d5d6340f3d569a550f4697946c5'/>
<id>urn:sha1:5c153295205d2d5d6340f3d569a550f4697946c5</id>
<content type='text'>
* Fix handling of UniformState from #1396

* * Fix bug in slang-dxc-support where it didn't get the source path correctly
* Make entryPointIndices const List&lt;Int&gt;&amp;</content>
</entry>
<entry>
<title>Backend for Multiple Entry Points (#1411)</title>
<updated>2020-06-29T21:42:12+00:00</updated>
<author>
<name>Dietrich Geisler</name>
<email>dgeisler50@gmail.com</email>
</author>
<published>2020-06-29T21:42:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=47b43f8b15ef35c520b9b287fd17ff25e36bfe95'/>
<id>urn:sha1:47b43f8b15ef35c520b9b287fd17ff25e36bfe95</id>
<content type='text'>
* Backend for Multiple Entry Points

Introduces the basic backend on the compiler for zero or more entry
points.  Entry points have been extended to lists for several functions,
with loopFunctions have been extended to take in entry points and
indices as appropriate, to allow for multiple entry points once the
frontend is expanded.  Several functions are currently being assumed to
have a single entry point for simplicity and provide a work in progress
commit.

* Progress on debugging fixes

* Tests passing

* Refactored emitEntryPoints

* Updated lists to be by constant reference

* Fixes to formatting

* Refactoring updates for the compiler

* Fix for compilation errors

* Reformatting

* More reformatting

* Moved struct around to help with compilation

Co-authored-by: Tim Foley &lt;tfoleyNV@users.noreply.github.com&gt;</content>
</entry>
<entry>
<title>Feature/glslang spirv version (#1256)</title>
<updated>2020-03-05T15:59:54+00:00</updated>
<author>
<name>jsmall-nvidia</name>
<email>jsmall@nvidia.com</email>
</author>
<published>2020-03-05T15:59:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=6684d32db1f5693bcfb4971558cb30e855cd3bad'/>
<id>urn:sha1:6684d32db1f5693bcfb4971558cb30e855cd3bad</id>
<content type='text'>
* WIP add support for __spirv_version .

* Added IRRequireSPIRVVersionDecoration

* SPIR-V version passed to glslang.
Enable VK wave tests.
Split ExtensionTracker out, so can be cast and used externally to emit.
Added SourceResult.

* Fix warning on Clang.

* Missing hlsl.meta.h

* Refactor communication/parsing of __spirv_version with glslang.

* Fix some debug typos.
Be more precise in handling of substring handling.

* Make glslang forwards and backwards binary compatible.

* Small comment improvements.

* Added slang-spirv-target-info.h/cpp

* Fix for major/minor on gcc.

* Another fix for gcc/clang.

* VS projects include slang-spirv-target-info.h/cpp

* Removed SPIRVTargetInfo
Added SemanticVersion.
Don't bother with passing a target to glslang. Should be separate from 'version'.

* Renamed slang-emit-glsl-extension-tracker.cpp/.h -&gt; slang-glsl-extension-tracker.cpp/.h
Fixed some VS project issues.

* Fix a comment.

* Added slang-semantic-version.cpp/.h

* Added slang-glsl-extension-tracker.cpp/.h

* Added split that can check for input has all been parsed.

* Fix problem on x86 win build.
</content>
</entry>
<entry>
<title>WIP CUDA source emit (#1157)</title>
<updated>2019-12-19T16:23:14+00:00</updated>
<author>
<name>jsmall-nvidia</name>
<email>jsmall@nvidia.com</email>
</author>
<published>2019-12-19T16:23:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=e3fe0319467546bae070137c58dcf8f9fbe93c79'/>
<id>urn:sha1:e3fe0319467546bae070137c58dcf8f9fbe93c79</id>
<content type='text'>
* CPPCompiler -&gt; DownstreamCompiler

* Added DownstreamCompileResult to start abstraction such that we don't need files.

* * Split out slang-blob.cpp
* Made CompileResult hold a DownstreamCompileResult - for access to binary or ISlangSharedLibrary

* Keep temporary files in scope.

* Add a hash to the hex dump stream.

* Move all file tracking into DownstreamCompiler.

* WIP support for nvrtc.

* WIP: Adding support for nvrtc compiler.
Adding enum types, wiring up the nvrtc into slang.

* Fix remaining CPPCompiler references.

* Fix order issue on target string matching.

* Use ISlangSharedLibrary for nvrtc.

* Use DownstreamCompiler for nvrtc.

* WIP first pass at compilation win nvrtc.

* Added testing if file is on file system into CommandLineDownstreamCompiler.
Added sourceContentsPath.

* Make test cuda-compile.cu work by just compiling not comparing output.

* Genearlize DownstreamCompiler usage.

* Fix warning on clang.

* Remove CompilerType from DownstreamCompiler.

* Use DownstreamCompiler interface for all compilers.

NOTE for FXC, DXC and GLSLANG this doesn't mean using 'compile' - it's still extracting functions from shared library.

* Replace DownstreamCompiler::SourceType -&gt; SlangSourceLanguage

* Replace _canCompile with something data driven.

* Fix compiling on gcc/clang for DownstreamCompiler.

* Moved some text conversions into DownstreamCompiler.

* Fix problem on non-vc builds with not having return on locateCompilers for VS.

* Change so no warning for code not reachable on locateCompilers for vs.

* WIP: CUDA code generation - currently just using CPU layout and HLSL.

* emitXXXForEntryPoint -&gt; emitEntryPointSource
emitSourceForEntryPoint -&gt; emitEntryPointSourceFromIR
Fix up generating cuda to get PTX.

* WIP emitting cuda for IR.

* Small improvements to CUDA ouput.

* Disable the CUDA emit test, as output not currently compilable.
</content>
</entry>
<entry>
<title>Initial work on direct emission of SPIR-V (#1118)</title>
<updated>2019-11-14T21:11:07+00:00</updated>
<author>
<name>Tim Foley</name>
<email>tfoleyNV@users.noreply.github.com</email>
</author>
<published>2019-11-14T21:11:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=ce4829b03622c7c23096253b0ee80b0fc923321e'/>
<id>urn:sha1:ce4829b03622c7c23096253b0ee80b0fc923321e</id>
<content type='text'>
* Initial work on direct emission of SPIR-V

This change adds a first vertical slice of support for emitting SPIR-V code directly from the Slang IR, instead of generating it indirectly via GLSL.
This work isn't usable for anything valuable right now; the goal is just to get something checked in that we can incrementally extend over time.

When invoking `slangc`, the `-emit-spirv-directly` option can be used to turn on the new code path.
I have not bothered to add an equivalent API option, because this flag is only intended to be used for testing in the immediate future.

The existing `emitEntryPoint()` function has become `emitEntryPointSource()` to more accurately reflect its role in a world where we can also emit entry points to a binary format.

Much of the logic that was inside `emitEntryPoint()` had to do with linking and then optimizing/transforming Slang IR code to get it ready for emission on a particular target.
This logic has been factored into a new `linkAndOptimizeIR()` function that can be shared between the path that emits source and the new one that emits SPIR-V.

The meat of the change is then the `emitSPIRVFromIR()` function in `slang-emit-spirv.cpp`, which is called *after* all the optimizations and transformations have been applied to the Slang IR to get it ready.
Rather than repeat myself here, I will try to make the comments in `slang-emit-spirv.cpp` usable as documentation of the approach being taken.

Smaller notes:

* I've included a test case that compares `slangc` output directly to expected SPIR-V. This is perhaps not an ideal plan for how to test SPIR-V emission going forward, but it suffices for now.

* The `external/` directory needed to be added to the include dirs for the `slang` project so that the new code can depend on the SPIR-V header.

* In `slang-ir-link`, the direct SPIR-V generation path means that we now link with a target of SPIR-V instead of GLSL. In principle this can be used to ensure that appropriate variants of intrinsics are selected based on the knowledge that we are emitting SPIR-V. In practice, that isn't being used at all.

* Fixup: path for SPIR-V headers

While working on this PR I used a copy of `spirv.h` that I placed into the repository tree manually, but since I started the work we ended up with SPIR-V headers in our tree anyway, albeit at a different path.

This change tries to fix things up so that my code uses the headers that were already placed in the repository.

* fixup; 64-bit build issue

* fixup: typo fixes based on review
</content>
</entry>
<entry>
<title>Initial work on representing layout at IR level (#1079)</title>
<updated>2019-10-18T00:34:31+00:00</updated>
<author>
<name>Tim Foley</name>
<email>tfoleyNV@users.noreply.github.com</email>
</author>
<published>2019-10-18T00:34:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=a854bf2fde6e466aa698f4132971faadc827913a'/>
<id>urn:sha1:a854bf2fde6e466aa698f4132971faadc827913a</id>
<content type='text'>
* Initial work on representing layout at IR level

This change starts the process of making the back-end of the compiler independent of the AST-level layout information (`TypeLayout`, `VarLayout`, etc.) so that it instead only relies on layout information that is embedded into IR modules. This brings us incrementally closer to a world in which the back-end could be run without the AST-level structures even existing (e.g., for an application that just wants to ship IR without any AST information for IP protection, while still supporting some amount of linking and specialization).

The main parts of the change are:

* There is a bunch of incidental churn related to specifying entry points by index instead of the `EntryPoint` object for certain operations. This ends up being a better choice because we can use the index to look up side-band information about the entry point that might not be stored on the `EntryPoint` object itself. In particular...

* We expand the `ComponentType` interface to support looking up the mangled name of an entry point by index. In common cases (no generic/interface specialization) this would be the same as asking the `EntryPoint` for its mangled name, but in cases where we have specialized a generic entry point, the mangled name would include speicalization arguments that are only available on the `SpecializedComponentType` that wraps the entry point. This part of the change isn't ideal and there might be a better solution waiting to be invented. Note that we store mangled entry point names as strings rather than using `DeclRef`s because that ensures that the information could be serialized and deserialized without a dependence on the AST.

* The `TargetProgram` type (which represents binding a specific `ComponentType` for a shader program to a specific `TargetRequest` that represents the target platform) is expanded to include an `IRModule` that represents layout information, in addition to the AST-level `ProgramLayout` it already contained. We create both of these objects at the same time (on-demand) to simplify the overall flow (so that any code that triggers creation of the AST-level layout will also ensure that the IR-level layout exists).

* A bunch of code in the emit passes that was passing down layout-related objects has been eliminated. It appears that most of those objects weren't actually being used, so this is just a cleanup, but it helps ensure that the back-end steps are "clean" and don't depend on the AST-level information. The one big exception here is that the emit logic needs to know the stage for the entry point being emitted (to deal with one wrinkle in translating DXR to VKRT).

* A big change (actually introduced by @jsmall-nvidia in a branch that this change copied and then built from) is to introduce some more explicit IR instructions to represent layout information, notably an `IRTypeLayout` and an `IRVarLayout`. For now these objects still reference their AST equivalents, but the separation gives us an incremental path to move information from the AST-level objects over to the IR ones. This work includes logic in `IRBuilder` to construct the IR-level layout objects from the AST-level ones on-demand, so that the existing code paths that try to attach AST-level layout will continue to work for now.

* Because layout information is now embedded in the IR, the `slang-ir-link.cpp` logic loses a lot of cases that used to deal with attaching AST-level layout objects to IR-level instructions during the linking process. Instead, the linker now assumes that one (or more) of the input IR modules will have layout information associated with it, and the linker makes sure to copy layout decorations (and the instructions they reference) from the input IR module(s) to the output using its more ordinary mechanisms.

* Inside `slang-lower-to-ir.cpp`, we add logic to construct an IR module in a `TargetProgram` that simply references the global shader parameters, entry points, etc. and attaches IR layout decorations to them. This is akin to the existing pass in the same file that constructs IR to represent specialization information, and both of these passes share infrastructure with the main AST-&gt;IR lowering pass. Eventually, it is expected that this pass will encompass more of the logic for copying AST-level layout information over to IR-level equivalents.

* One small wrinkle with this change was that the output for an HLSL generation test case changed some of its `#line` directives. The old code was actually more inaccurate than the new, so this change just updated the baseline. It also added some logic in the linker to make sure that when an IR instruction has multiple definitions, we try to pick up a source location from any of them, in case the "main" one somehow didn't get a location.

* Another small fix was that the key/value map in `StructTypeLayout` for mapping fields/members to their layouts was keyed on `Decl*` when it really should have been `VarDeclBase*`.

This change should in principle be a pure refactoring with no functionality changes, so no new tests were added. It is unfortunately also a change that has a high probability of breaking at least *some* client code, so we may want to be defensive and mark this with a new major version number (well, a new *minor* version number since we are pre-`1.0`) to give us some room for releasing hotfixes to the old version if needed.

* fixup: infinite recursion bug detected by clang

* fixup: remove commented-out code
</content>
</entry>
<entry>
<title>Use slang- prefix on slang compiler and core source (#973)</title>
<updated>2019-05-31T21:20:37+00:00</updated>
<author>
<name>jsmall-nvidia</name>
<email>jsmall@nvidia.com</email>
</author>
<published>2019-05-31T21:20:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=6cbc3929a54d37bd23cb5efa8e3320ba02f78b2f'/>
<id>urn:sha1:6cbc3929a54d37bd23cb5efa8e3320ba02f78b2f</id>
<content type='text'>
* Prefixing source files in source/slang with slang-

* Prefix source in source/slang with slang- prefix.

* Rename core source files with slang- prefix.

* Update project files.

* Fix problems from automatic merge.
</content>
</entry>
</feed>
