summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-wgsl.cpp
Commit message (Collapse)AuthorAge
* Defer `IRCastStorageToLogicalDeref` in lowerBufferElementType pass. (#8668)Yong He2025-10-10
| | | | | | | | | | | | Fix a regression on metal test. In `lowerBufferElementTypeToStorageType` pass, not only we want to defer an argument that is `CastStorageToLogical` to the callee, but also apply the same defer logic to `CastStorageToLogicalDeref` as well. Because `CastStorageToLogicalDeref` will appear as argumnet if `lowerBufferElementTypeToStorageType` is run before we apply the `in->borrow` transformation pass, which is the case for metal parameter block legalization.
* Rename some symbols related to pointers types (#8592)Theresa Foley2025-10-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Note that while this change touched a large numer of files, there are no changes to functionality being made here. The only things being done are renaming various symbols and, in a few cases, updating or adding comments for consistency with the new names. The core of the naming changes are: * Most things named to refer to `OutType` (e.g., `IROutType`, `IRBuilder::getOutType()`, etc.) have been consistently renamed to refer to `OutParamType`, to emphasize that the relevant AST/IR node types are only intended for use to represent `out` parameters. * The same change as described above for `OutType` is also made for `RefType`, which becomes `RefParamType` in most cases. One mess that this exposes is the way that the `ExplicitRef<T>` type in the core module currently lowers to `IRRefParamType`. This change sticks to the rule of not making functional changes, so that mess is left as-is for now. * Names referring to `InOutType` have been changed to instead refer to `BorrowInOutType`. The intention with this naming change is to emphasize that the Slang rules for `inout` are semantically those of a borrow (or at least our interpretation of what a borrow means). * Names referring to `ConstRefType` have been changed to instead refer to `BorrowInType`. This change starts work on clarifying that the existing `__constref` modifier was never intended to be a read-only analogue of `__ref`, and instead is the input-only analogue of `inout`. * The `ParameterDirection` enum type has been changed to `ParamPassingMode`, to reflect the fact that the concept of "direction" fails to capture what is actually being encoded, particularly once we have modes beyond simple `in`/`out`/`inout`. While this change does not alter behavior in any case (the user-exposed Slang language is unchanged), it is intended to set up subsequence changes that will work to make the handling of these types in the compiler more nuanced and correct. Breaking this part of the change out separately is primarily motivated by a desire to minimize the effort for reviewers. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Enhance buffer load specialization pass to specialize past field extracts. ↵Yong He2025-09-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#8547) This allows us to specialize functions whose argument is a sub element of a constant buffer, instead of being only applicable to entire buffer element. Closes #8421. This change also implements a proper heuristic to determine when to specialize the calls and defer the buffer loads. This PR addresses a pathological case exposed in `slangpy\slangpy\benchmarks\test_benchmark_tensor.py`, which used to take 27ms to finish, and now takes 1.25ms. For example, given: ``` struct Bottom { float bigArray[1024]; [mutating] void setVal(int index, float value) { bigArray[index] = value; } } struct Root { Bottom top[2]; [mutating] void setTopVal(int x, int y, float value) { top[x].setVal(y, value); } } RWStructuredBuffer<Root> sb; [shader("compute")] [numthreads(1, 1, 1)] void compute_main(uint3 tid: SV_DispatchThreadID) { sb[0].setTopVal(1, 2, 100.0f); } ``` We are now able to specialize the call to `setTopVal` into: ``` void compute_main(uint3 tid: SV_DispatchThreadID) { setTopVal_specialized(0, 1, 2, 100.0f); } void setTopVal_specialized(int sbIdx, int x, int y, float value) { Bottom_setVal_specialized(sbIdx, x, y, value); } void Bottom_setVal_specialized(int sbIdx, int x, int y, float value) { sb[sbIdx].top[x].bigArray[y] = value; } ``` And get rid of all unnecessary loads. Achieving this requires a combination of function call specialization and buffer-load-defer pass. The buffer-load-defer pass has been completely rewritten to be more correct and avoid introducing redundant loads. This PR also adds tests to make sure pointers, bindless handles, and loads from structured buffer or constant buffers works as expected.
* Lowering unsupported matrix types for GLSL/WGSL/Metal targets (#7936)venkataram-nv2025-07-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add emit cases for WGSL and GLSL * Fix compilation warnings Modify short cutting test to reflect change in emit logic Lower matrix for metal as well Add emit matrix logic for metal Fix compiler warning Brace initializer for lowered matrices Fix compiler warnings * Tests for metal * Fix mult, any, and determinant * Fix matrix-matrix multiplication * Fix mat mul to be element-wise * Fix compiler warning * Move makeMatrix to legalization * Move unary and binary arithmetic operator lowering to legalization * Remove emit logic and move final comparison operators to legalization * Handle vector/matrix negation for WGSL * Restore older SPIR-V emit logic * Address PR comments * Revert to zero minus for negation * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Fix int16_t/uint16_t support for WGSL target (#7692)Copilot2025-07-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Initial plan * Implement int16_t/uint16_t support for WGSL target Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Change int16_t/uint16_t to emit proper diagnostics instead of auto-promoting Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Implement diagnoseOnce to prevent duplicate diagnostics Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Optimize diagnoseOnce to use HashSet::add() return value Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Apply code formatting to slang-emit-c-like.h Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix diagnoseOnce to use all parameters instead of first parameter only Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
* extend fiddle to allow custom lua splices in more places (#7559)Ellie Hermaszewska2025-07-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add fkYAML submodule * Generate slang-ir-inst-defs.h from slang-ir-inst-defs.yaml * generate ir-inst-defs.h * neaten things * neaten inst def parser * add rapidyaml submodule * remove fkyaml * remove fkyaml submodule * remove use of ir-inst-defs.h * format and warnings * fix wasm build * tidy * remove rapidyaml * Extend fiddle to allow custom splices in more places * Use lua to describe ir insts * fix * neaten * neaten * neaten * spelling * neaten * comment comment out assert * merge
* Fix generation of wgsl case arms (#7374)Swoorup Joshi2025-06-25
| | | | | | | | | * Fix generation of wgsl case arms * Added test case to test generation of switch case --------- Co-authored-by: Harsh Aggarwal (NVIDIA) <haaggarwal@nvidia.com>
* Add `vk::offset` to specify member offsets for push constants (#6797)Darren Wihandi2025-04-21
| | | | | | | | | | | | | * Add struct member offset qualifier for SPIRV * Implement for GLSL target and add tests * clean up * fix formatting * fix typo * renamed GLSLStructOffset to VkStructOffset and added emit-spirv-via-glsl test case
* Use correct syntax for WGSL array transpiling (#6693)jarcherNV2025-04-02
| | | | | | Fixes issue #6533 This patch updates handling of Array and ConstantBuffer types for WGSL transpiling, giving correct syntax for arrays of buffers in WGSL.
* Implement GetDimensions for structured buffers on WGSL (#6609)Darren Wihandi2025-03-14
| | | | | | | | | | | | | * Implement structured buffer GetDimensions for WGSL * byte address buffer fix * enable wgsl test and minor fixups * maybe fix get equivalent structured buffer * remove unnecessary include * clean up some code in meta file
* Add Slang-specific intrinsics for integer pack/unpack (#6459)Darren Wihandi2025-02-28
| | | | | | | | | | | | | | | | | | | | | * update hlsl meta * update test * use slang syntax in meta file * improve meta file * fix pack clamp u8 * remove builtin packed types, use typealias instead * fix wgsl pack clamp * fix formatting --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Add WaveGetLane* support for Metal and WGSL (#6371)Darren Wihandi2025-02-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * support WaveGetLane* for WGSL and Metal * update test and glsl support * address review comments and fix metal test * add missing pragma guard * update test * Revert "update test" This reverts commit f2b97e91c29de154190710580c343bd0764aedbb. * update failing glsl metal test and added new test * make hlsl and glsl outputs similar * update test * disable tests for Metal and cleanup * comment fix * add expected failures * correct expected failures list * remove expected failure * add tests to expected failure --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Use and() and or() functions for logical-AND and OR (#6310)Jay Kwak2025-02-07
| | | | | | | | | | | | * Use and() and or() functions for logical-AND and OR With this commit, Slang will emit function calls to `and()` and `or()` for the logical-AND and logical-OR when the operands are non-scalar and the target profile is SM6.0 and above. This is required change from SM6.0. For WGSL, there is no operator overloadings of `&&` and `||` when the operands are non-scalar. Unlike HLSL, WGSL also don't have `and()` nor `or()`. Alternatively, we can use `select()`.
* Add support for WGSL subgroup operations (#6213)Darren Wihandi2025-02-02
| | | | | | | | | | | | | | | | | | | | | * initial work * more work * more work on glsl intrinsics * add subgroup broadcast for glsl * wip add wgsl extension tracking * enable tests, enable extensions and added some todos * format and warning fixes * fix wgsl extension tracker --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Add bgra8 format (#6163)Darren Wihandi2025-01-24
| | | | | | | | | | | | | | | | | * add brga8 format * add tests * minor fixes * cleanup * maybe fix broken quad control test * add missing xslang flag on test --------- Co-authored-by: Yong He <yonghe@outlook.com>
* WGSL: Convert signed vector shift amounts to unsigned (#6023)Anders Leino2025-01-10
| | | | | | | | | | | | | | | | | | | | | | | | | * WGSL: Fixes for signed shift amounts - Handle the case of vector shift amounts - Closes #5985 - Move handling of scalar case from emit to legalization - Add tests for bitshifts. * Move the binary operator legalization function to a common place * Metal: Legalize binary operations Closes #6029. * Fix Metal filecheck test The int shift amounts are now converted to unsigned. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
* Initial implementation of SP#015 `DescriptorHandle<T>`. (#6028)Yong He2025-01-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Initial implementation of `ResourcePtr<T>`. * Update docs * Fix build error. * Add more discussion. * Update documentation. * Update TOC. * Fix. * Fix. * Add test case for custom `getResourceFromBindlessHandle`. * Add namehint to generated descriptor heap param. * Fix. * Fix. * format code * Rename to `DescriptorHandle`, and add `T.Handle` alias. * Fix compiler error. * Fix. * Fix build. * Renames. * Fix documentation. * Documentation fix. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Add packed 8bit builtin types (#5939)Darren Wihandi2024-12-26
| | | | | * Add packed bytes builtin type * fix test
* Implement bitcast for 64-bit date type (#5895)kaizhangNV2024-12-17
| | | | | | | Close #5470 * implement bitcast for 64-bit date type * Move 'ensurePrelude' to base class to remove duplication * Assert on 'double' type for Metal target, as Metal doesn't have 'double' support
* Fix wgsl float texture format inference silent failure (#5831)Devon2024-12-11
|
* Support specialization constant on WGSL and Metal. (#5780)Yong He2024-12-06
|
* Implement explciit binding for metal and wgsl. (#5778)Yong He2024-12-06
| | | | | | | | | | | | | | | * Respect explicit bindings in wgsl emit. * Implement explciit binding generation for metal and wgsl. * Update toc. * Fix warnings in tests. * Fix tests. --------- Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
* Add wgsl missing float image format inference (#5716)Devon2024-12-05
| | | | | | | | | | | | | | | | | * Add missing float image format inference * Drop float4 inference and adjust test * Do wgsl float format fix at emit time * improve formatting * format code --------- Co-authored-by: Yong He <yonghe@outlook.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
* Support interpolation modifiers for WGSL (#5641)Anders Leino2024-11-25
| | | | | | | | | | | | * wgsl: Support interpolation modifiers * Move struct key decorations to flattened structs. ** This includes interpolation mode decorations, which must be in the flattened struct. * Emit interpolation attribute. * Enable tests/render/nointerpolation.hlsl for WGSL, as a result. This closes #5625. * Add new expected output for 'nointerpolation' test
* Fix WGSL emit for '&' and add bindings for thread group size (#5557)Sai Praveen Bangaru2024-11-13
| | | Co-authored-by: Yong He <yonghe@outlook.com>
* Various fixes to enable some WGSL graphics tests (#5548)Anders Leino2024-11-13
| | | | | | | | | | | | | | | | | | | | | * Update Slang-RHI to get WGPU backend fixes * render-test: Use device local memory type for vertex buffers This helps to avoid https://github.com/shader-slang/slang-rhi/issues/104 * Fix bug in WGSL emitter layout code. There was a "kinds" vs. "kind flags" mismatch, and also getBindingOffsetForKinds was not being used. This patch enables a bunch of tests for WGPU. This helps to address issue #4943. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* [WGSL] [WASM] Add reflection endpoints + Fix bit manipulation operations (#5499)Sai Praveen Bangaru2024-11-08
| | | | | | | | | | | | | | | | * Add key reflection endpoints for WASM * Fix WGSL output around bit-manipulation operators * format code * Fix pointer ownership * fix formatting --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
* Fix WGSL parameter block binding. (#5500)Yong He2024-11-06
| | | | | | | | | | | | | * Fix WGSL parameter block binding. * Re-enable tests. * Update failure list. * Fix entrypoint parameters. * Update tests. * Enable stat-var test.
* Legalize the Entry-point for WGSL (#5498)Jay Kwak2024-11-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Legalize the Entry-point for WGSL The return type of the entry-point needs to be legalized when targeting WGSL. This commit flattens the nested-structs of the return type and the input parameters of the entry-point. Most of code is copied from the legalization code for Metal. The following functions are exactly same to the implementation for Metal or almost same. - flattenInputParameters() : 136 lines - reportUnsupportedSystemAttribute() : 7 lines - ensureResultStructHasUserSemantic() : 46 lines - struct MapStructToFlatStruct : 176 lines - flattenNestedStructs() : 95 lines - maybeFlattenNestedStructs() : 42 lines - _replaceAllReturnInst() : 19 lines - _returnNonOverlappingAttributeIndex() : 16 lines - _replaceAttributeOfLayout() : 23 lines - tryConvertValue() : 41 lines - legalizeSystemValueParameters() : 11 lines They need to be refactored to reduce the duplication later. The test case, `tests/compute/assoctype-lookup.slang`, had a bug that the compute shader was trying to use the varying input/output with the user defined semantics. This commit removes the user defined semantics, because the compute shaders cannot use the user defined semantics. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Fix issue of infinity float literal (#5489)kaizhangNV2024-11-05
| | | | | | | | | | | | | | | | | | * Fix issue of infinity float literal * add parameters for the test * Correct the way to construct inf and nan In WGSL, expression of "1.0/0.0" is not allowed, it will report compile error, so to construct infinity or nan, we have to assign the float literal to a variable and then use it to bypass the compile error. By doing so, we add getInfinity and getNan functions to the builtin prelude to wgsl. --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Move switch statement bodies to their own lines (#5493)Ellie Hermaszewska2024-11-05
| | | | | | | | | * Move switch statement bodies to their own lines * format --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Various WGSL fixes. (#5490)Yong He2024-11-04
| | | | | | | | | | | | | | | | | | | * [WGSL] make sure switch has a default label. * Various WGSL fixes. * Update rhi submodule commit * format code * Remove unnecessary DISABLE_TEST directive on not applicable test. * Matrix comp mul + `select`. * Legalize binary ops for wgsl. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Write only texture types. (#5454)Yong He2024-10-30
| | | | | | | | | | | | | | | | * Add support for write-only textures. * Fix capabilities. * Fix implementation. * Fix. * format code --------- Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* formatEllie Hermaszewska2024-10-29
| | | | | | | * format * Minor test fixes * enable checking cpp format in ci
* Properly check switch case. (#5341)Yong He2024-10-20
|
* WGSL: Enable load & store from byte-addressible buffers (#5252)Anders Leino2024-10-11
|
* WGSL emitter: Specify private address space for global non-handle variable ↵Anders Leino2024-10-08
| | | | | declarations (#5236) Closes issue #5229.
* Implement texture_storage_Xd in WGSL (#5158)Jay Kwak2024-09-26
| | | | | | | | | | | | | | | | | | | * Implement texture_storage_Xd in WGSL This commit implements `texture_storage_Xd` in WGSL, which is similar to RWTextureXD in HLSL. It is intresting that `texture_storage_Xd` doesn't take the shader type as its input argument at all. Instead, it takes "texel format" enum value as its first template parameter, which can be found here: https://www.w3.org/TR/WGSL/#storage-texel-formats As an example, `texture_storage_2d<rg32uint, read_write>` expects vec4<u32> as a value type for `Load` and `Store`, where Z-component will be ignored and treated as zero and W-component will be treated always as 1. The type `u32` is inferred from the enum value `rg32uint`. Note that the number of component is always fixed to 4 regardless how many components are actually stored.
* Fix handling of pointer logic in wgsl backend. (#5129)Yong He2024-09-20
|
* WGSL implement texture intrinsics except gather and sampler-less (#5123)Jay Kwak2024-09-20
| | | | | | | | | | | | | This commit implements all of the texture intrinsics for WGSL except "Gather" and sampler-less. They will be implemented in a separate PR. A few things to note: - texture sampling functions are available only for the fragment shader stage; not for compute - WGSL doesn't have any functions similar to CalculateLevelOfDetail or CalculateLevelOfDetailUnclamped. - WGSL doesn't have a function overlaoding for textureSample with "clamp" or "status" arguments. - WGSL doesn't support Load operation with offset for texture_multisampled_XX and texture_storage_XX. - WGSL supports only four types of depth textures: 2D, 2D_array, cube and cube_array. - WGSL doesn't support "offset" variants for cube and cube_array.
* Initial `Atomic<T>` type implementation. (#5125)Yong He2024-09-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Initial Atomic<T> type implementation. * Update design doc. * Fix. * Add test. * Fixes and add tests. * Fix WGSL. * Fix glsl. * Fix metal. * experiemnt with github metal. * experiment github metal 2 * github metal experiment 3 * experiment with github metal 4. * experiment with metal 5. * experiment 7. * metal experiment 8. * Fix metal tests. --------- Co-authored-by: Yong He <yhe@nvidia.com>
* Add WGSL pack/unpack, constructor, derivatives & misc intrinsics (#5102)Anders Leino2024-09-18
| | | | | | | | | | | | | | | | | | * Add WGSL pack/unpack intrinsics This addresses issue #5080. * Add WGSL constructor intrinsics This addresses issue #5081. * Add WGSL derivative and miscellaneous intrinsics This addresses issue #5083. * Add some missing WGSL intrinsics - degrees - faceforward
* Initial WGSL support (#5006)Anders Leino2024-09-09
* Add WGSL as a target This is required for #4807. * C-like emitter: Allow the function header emission to be overloaded WGSL-style function headers are pretty different from normal C-style headers: Normal C-style headers: ReturnType Func(...) void VoidFunc(...) WGSL-style headers: fn Func(...) -> ReturnType fn VoidFunc(...) This change allows the header style to be overloaded, in order to accomodate WGSL-style headers as required to resolve issue #4807, but retains normal C-style headers as the default implementation. [1] https://www.w3.org/TR/WGSL/#function-declaration-sec * C-like emitter: Allow emission of switch case selectors to be overloaded The C-like emitter will emit code like this: switch(a.x) { case 0: case 1: { ... } break; ... } This is not allowed in WGSL. Instead, selectors for cases that share a body must [1] be separated by commas, like this: switch(a.x) { case 0, 1: { ... } break; ... } To prepare for addressing issue #4807, this patch makes the emission of switch case selectors overloadable. [1] https://www.w3.org/TR/WGSL/#syntax-case_selectors * C-like emitter: Support WGSL-style declarations This patch helps to address issue 4807. C-like languages declare variables like this: i32 a; WGSL declares variables like this: var a : i32 The patch introduces overloads so that the forthcoming WGSL emitter can output WGSL-style declarations, which helps to resolve #4807. * C-like emitter: Support overloading of declarators Unlike C-like languages, WGSL does not support the following types at the syntax level, via declarators: - arrays - pointers - references For this reason, this patch introduces support for overloading the declarator emitter, in order to help address issue #4807. C-like languages: int a[3]; // Array-ness of type is mixed into the "declarator" WGSL: var a : array<int, 3>; // Array-ness of type is part of the... type_specifier! * C-like emitter: Allow struct declaration separator to be overridden C-like languages use ';' as a separator, and languages like e.g. WGSL use ','. This change prepares for addressing issue #4807. * C-like emitter: Allow overriding of whether pointer-like syntax is necessary Things like e.g. structured buffers map to "ptr-to-array" in WGSL, but ptr-typed expressions don't always need C-style pointer-like syntax. Therefore, make it overrideable whether or not such syntax is emitted in various cases in order to address #4807. * C-like emitter: Emit parenthesis to avoid warning about & and + precedence This helps with #4807 because WGSL compilers (e.g. Tint) treat absence of parenthesis as an error. * C-like emitter: Add hook for emitting struct field attributes WGSL requires @align attributes to specify explicit field alignment in certain cases. Thus, this patch prepares for addressing #4807. * C-like emitter: Add hook for emitting global param types Declarations of structured buffers map to global array declarations in WGSL. However, in all other cases such as when structured buffers are used in operands, their types map to *ptr*-to-array. This patch makes it possible for the WGSL back-end to say that structured buffers generally map to "ptr-to-array" types, but still have a special case of just "array" when declaring the global shader parameter. Thus, this patch helps with addressing #4807. * IR lowering: Use std140 for WGSL uniform buffers This patch just cuts out some logic that prevented std140 to be chosen for WGSL uniform buffers. Note that WGSL buffers in the uniform address space is not quite std140, but for now it's close enough to avoid compile issues. Later on, a custom layout should be created for WGSL uniform buffers. When that's done, this change will be revisited, but for now it helps to resolve #4807. * Don't emit line directives in WGSL by default WGSL does not support line directives [1]. The plan currently seems to be to instead support source-map [2]. This is part of addressing issue #4807. [1] https://github.com/gpuweb/gpuweb/issues/606 [2] https://github.com/mozilla/source-map * WGSL IR legalization: Map SV's The implementation closely follows the cooresponding one for Metal. Supported: - DispatchThreadID - GroupID - GroupThreadID - GroupThreadID Unsupported: - GSInstanceID This is not complete, but it helps to address #4807. * WGSL emitter: Add support for basic language constructs A lot of the basics are added in order to generate correct WGSL code for basic Slang language constructs. This addresses issue #4807. This adds support for at least the following: - statments - if statements - ternary operator - while statement - for statements - variable declarations - switch statements - Note: Slang may emit non-constant case expressions, see issue 4834 - literals - integer literals - u?int[16|32|64]_t - float and half literals - bool literals - vector literals and splatting (e.g 1.xxx) - function definitions - assignments - +=, *=, /= - array assignments - vector assignments/updates - swizzles of other vectors - from matrix rows ('m[i]' notation) - from matrix cols (using swizzle notation, e.g 'm._11_12_13') - matrix assignments/updates - to rows ('m[i]' notation) - to cols (using swizzle notation, e.g 'm._11_12_13') - declarations - arrays [1] https://www.w3.org/TR/WGSL/#syntax-switch_body * Add some WGSL capabilities This patch registers some WGSL capabilities required to pass many of the initial compute shader compile tests. Many capabilities still remain to be added -- this is just an initial set to help resolve issue #4807. - asint - min and max - cos and sin - all and any * WGSL and C-like emitters: Add hack to bitcast case expression In WGSL, the switch condition and case types must match. https://www.w3.org/TR/WGSL/#switch-statement Slang currently allows these types to mismatch, as pointed out in #4921. Issue #4921 should eventually be addressed in the front-end by a patch like [1]. However, at the moment that would break Falcor tests. Thus, this patch temporarily works around the issue in the WGSL emitter only in order to help resolve #4807. In the future, the Falcor tests should be fixed, this patch should be dropped and [1] should be merged instead. [1] a32156ef52f43b8503b2c77f2f1d51220ab9bdea