summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-spirv.cpp
AgeCommit message (Collapse)Author
2025-07-02Defer immutable buffer loads when emitting spirv. (#7579)Yong He
* Defer immutable buffer loads when emitting spirv. * Fix. * Fix. * Fix. * Fix tests. * Fix test.
2025-07-01extend fiddle to allow custom lua splices in more places (#7559)Ellie Hermaszewska
* 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
2025-07-01Add arguments for controlling floating point denormal mode (#7461)aidanfnv
* Implement -fp-denorm-mode slangc arg * Split fp-denorm-mode into 3 args for fp16/32/64 * Remove redundant option categories * Use emitInst for multiple of the same OpExecutionMode * Fix formatting * Remove -denorm any * Re-add option categories * emitinst for ftz * Use enums for type text * Remove extra categories again * Add tests for denorm mode * Move denorm mode to post linking * format code (#8) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * regenerate command line reference (#9) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Clean up tests * Fix option text * format code (#10) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Add tests for "any" mode * Return "any" enum if option not set * Simplify emission logic * Add support for generic entrypoints * Move denorm modes to end of CompilerOptionName enum * format code (#11) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> * Move new enum members to before CountOf * Add not checks to tests, fix generic test, add functionality tests * Rename denorm to fpDenormal * Clean up functional test * Rename denorm test dir * Fix formatting, regenerate cmdline ref * Fold simple tests into functional tests, add more dxil checks * Remove no-op DX tests, make tests more consistent * Disable VK functionality tests that will fail on the CI configs * Fix formatting * Add comments to disabled tests explaining why --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
2025-06-30Emit sample index when constructing a `OpImageTexelPointer` (#7563)ArielG-NV
* fix #7554 * format code * test ms and non ms texture --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
2025-06-29Support the GLSL/SPIR-V Built-in variable `DeviceIndex` (#7552)ArielG-NV
* Support DeviceIndex * format code * regenerate command line reference --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
2025-06-26Fix for OpUConvert producing invalid opcode when to/from signs differ (#7398)Jerran Schmidt
* Fix for OpUConvert outputting scalar type for mixed sign vector type conversions * Fix compiler warning * Added regression test for UConvert vector fix * Formatting * getUnsignedType helper * Formatting * Fix for addtional int types * Helper function to convert signed type to unsigned type
2025-06-26Fix the invalid SPIRV decoration issue (#7527)kaizhangNV
* Fix the invalid SPIRV decoration issue Close #7508. SPIRV doesn't allow decoration on type with Private or Function storage class. In our lowering logic, if the array type is used by buffer type it will always have stride operand after lowering, so if the array is not used by buffer type, it must be used only by thread_local or group_shared variable, and it will not have stride operand. For this case, we don't need to emit stride decoration for SPIRV.
2025-06-26Correct the scope for DebugLocalVariable (#7516)Lujin Wang
* Correct the scope for DebugLocalVariable All of the DebugLocalVariable instructions have their scope set to DebugCompilationUnit. The scope should instead be set to a DebugFunction, or a DebugLexicalBlock which is recursively inside a DebugFunction. Register the debug info for the function instructions, which helps findDebugScope() to find the right DebugFunction scope for DebugLocalVariable. * Add a test for DebugLocalVariable To check the scope, which should be a DebugFunction.
2025-06-19Always emit DepthReplacing execution mode when writing to FragDepth (#7450)dubiousconst282
2025-06-16Fix for missing signedness cast in SwizzleIR (#7448)Jerran Schmidt
* Cast if there is a signedness mismatch on the swizzle * Move isSignedType to slang-util and add test --------- Co-authored-by: Yong He <yonghe@outlook.com>
2025-06-06Add command line option for separate debug info (#7178)jarcherNV
* Add command line option for separate debug info Add command line arg -separate-debug-info which, if provided, produces both a .spv and a .dbg.spv file. The .dbg.spv file contains full debug info and the .spv file has all debug info stripped out. Also add a DebugBuildIdentifier instruction to store a unique hash in both the output files, so they can be more easily matched together. A matching API is provided to allow using the Slang API to retrieve a base and debug SPIRV as well as the debug build identifier string.
2025-05-29Fix SPIRV `OpSpecConstantOp` emit (#7158)Darren Wihandi
* Fix SPIRV specialization constant with floating-point operations * Improve test * WIP * Restrict `OpSpecConstantOp` allowed operations based on SPIRV specifications * Fix typo on floating type check * Emit error on float to int spec cosnt int val casts
2025-05-29Implement MapElement for CoopMat (#7159)Jay Kwak
With this PR, MapElement works for the following signatures: - CoopMat<...>::MapElement(functype(...)); - CoopMat<...>::MapElement(capturing-lambda); - CoopMat<...>::MapElement(not-capturing-lambda); - Tuple<CoopMat<...>,...>::MapElement(functype(...)); - Tuple<CoopMat<...>,...>::MapElement(capturing-lambda); - Tuple<CoopMat<...>,...>::MapElement(not-capturing-lambda);
2025-05-23Add CoopVec load/store pointer overloads (#6822)Darren Wihandi
* Add pointer/T* variants for coop vec load/store * fix stride decoration and improved test * fix compile warnings * Improve test * Use `coopVecLoad` function in test
2025-05-19Map `SV_VertexID` to `gl_VertexIndex-gl_BaseVertex`, add `SV_Vulkan*ID` ↵Darren Wihandi
semantics (#7150) * Map SV_VertexID to `gl_VertexIndex - gl_BaseVertex`, provide SV_Vulkan* SV semantics * Fix docs * Regenerate toc * Fix affected pointer-2 test * Add tests --------- Co-authored-by: Yong He <yonghe@outlook.com>
2025-05-16Support Vulkan memory model (#7057)Jay Kwak
The user can explicitly use Vulkan memory model, or it will be automatically used when cooperative-matrix is used. When vulkan memory model is used, two keywords, "Coherent" and "Volatile", are not allowed. There are many differences regarding atomic and texture but this PR has changes limited to support `globallycoherent` keyword. When variables with `globallycoherent` is used with `OpLoad`, it will use additional options, `MakePointerAvailable|NonPrivatePointer`, that will provide the same effect. For `OpStore`, it will use `MakePointerVisible|NonPrivatePointer`.
2025-05-16Address structured buffer `GetDimensions` issues for WGSL, GLSL and SPIRV ↵Darren Wihandi
(#7010) * Fix structured buffer get dimensions * Further fixes and added tests * Remove unnecessary include * Fix test issues * attempt to fix wgpu crash * test remove half usage in test * attempt to fix WGPU test issue * Another attempt to fix WGSL test - make test similar to the existing GetDimensions test --------- Co-authored-by: Yong He <yonghe@outlook.com>
2025-05-15Support tensor addressing (#7060)Jay Kwak
This commit implements two new types and related Load/Store functions in CoopMat. tensor_addrressing.TensorLayout tensor_addressing.TensorView CoopMat.Load(..., TensorLayout) CoopMat.Load(..., TensorLayout, TensorView) CoopMat.Store(..., TensorLayout) CoopMat.Store(..., TensorLayout, TensorView) CoopMat.Load(..., TensorLayout, TensorView)
2025-05-14support specialization constant sized array (#6871)kaizhangNV
Close #6859 Goal of this PR We want to support an array whose size can be specialization constant for shared/global variable e.g. layout (constant_id = 0) const uint BLOCK_SIZE = 64; shared float buf_a[(BLOCK_SIZE + 5) * 4]; Overview of the solution: During IndexExpr check, we will loose the restriction to allow SpecConst passing, but the size parameter will not be a constant value because it cannot be folded into a constant, so we will make it follow the same logic as generic parameter value, and the size will be represented by FuncCallIntVal/PolynomialIntVal/DeclRefIntVal. During IR lowering, we will detect whether there is spec constant in the IntVal, and wrap the IRInst with a SpecConstRateType, and propagate the type though the lowering logic, such that the IntVal representing the array size will have SpecConstRateType. During spirv emit stage, if we detect that a IRInst has SpecConstRateType, we will emit it as SpecConstantOp. We have to implement new logic to emit OpSpecConstantOp, the existing emit logic doesn't support emitting OpSpecConstantOp, especially this op can embed arithmetic operation at global scope, where we can only emit arithmetic instruct at local. But there are only few instructs we need to support. Overview of the solution: This PR doesn't support generic, and we will create a separate PR to extend that, tracked in #6840.
2025-05-12cluster acceleration structure optix 6431 (#7028)Harsh Aggarwal (NVIDIA)
* Add cluster geometry intrinsics for ray tracing - Added GetClusterID() method to HitObject class - Added CandidateClusterID() and CommittedClusterID() methods to RayQuery class - Added SPV_NV_cluster_acceleration_structure extension support - Added GL_NV_cluster_acceleration_structure extension support - Added test files for RayQuery and HitObject cluster methods Fixes #6431 * OpRayQueryGetIntersectionClusterIdNV - unrecognized spirv Disabling spirv backend for SPV_NV_cluster_acceleration_structure hlsl.meta.slang(18674): error 29100: unrecognized spirv opcode: OpRayQueryGetIntersectionClusterIdNV result:$$int = OpRayQueryGetIntersectionClusterIdNV &this $iCandidateOrCommitted; ^~~~~~ hlsl.meta.slang(18670): error 30019: expected an expression of type 'int', got 'void' return spirv_asm ^~~~~~~~~ ninja: build stopped: subcommand failed. * 6431 - Fix spirv opcode * Remove tests * Add relevant tests * Review - Simplify tests
2025-05-10Add debug information for slang inling (#6621)Mukund Keshava
2025-05-09Fix SPIRV unsigned to signed widening casts (#7051)Darren Wihandi
* Fix unsigned to signed casts for SPIRV * Add test * Fix ICE crash
2025-04-27Emit SPIRV NonReadable decoration for WTexture* (#6922)Darren Wihandi
2025-04-15Add cooperative matrix 1 support (#6565)Darren Wihandi
* initial wip for spirv * working tiled example * clean up store and load * minor fixes * fix loadAny name * add initial tests, including broken/unimplemented intrinsics * fix subscript * run tests at 16x16, remove not supported arithmetic tests * minor fixups on implementation * rename CoopMatMatrixUse * Update tests to pass validation layers locally * Add mat-mul-add test and minor fixes * Add more tests * Remove dead code * Add coopMatLoad function and tests, enforce constexpr for matrix layout * Use getVectorOrCoopMatrixElementType in place of getVectorElementType
2025-04-14Add SV_PointCoord to match gl_PointCoord (#6795)Julius Ikkala
* Add gl_PointCoord support in GLSL compat mode * Add SV_PointCoord * Test on metal as well * Update SPIRV system value semantics table in docs * Update metal docs for SV_PointCoord
2025-03-26Fix SPV_KHR_maximal_reconvergence extension name spelling (#6687)Pavel Asyutchenko
* Fix SPV_KHR_maximal_reconvergence extension name spelling Vulkan validation layers emit warnings on lowercase khr. * Move OpExtension check
2025-03-22Support spirv ops added by multiple extensions (#6615)Dario Mylonopoulos
* spirv: add support for ops added by multiple extensions Some spirv ops are added by multiple extensions and capabilities. This commit adds support to avoid emitting unnecessary extensions and capabilities if one of the options is already required by some other op. * spirv: allow OpRaytracingAccelerationStructure to use multiple extensions This Op is provided by both SPV_KHR_ray_tracing and SPV_KHR_ray_query and the respective capabilities. Use one if already available and otherwise fall back to SPV_KHR_ray_tracing. * tests/vkray: add negative checks for RayTracingKHR and RayQueryKHR - Add new rayquery-compute.slang to test that only RayQueryKHR is needed in compute shaders. - Add checks for RayTracingKHR and RayQueryKHR capabilities and extensions in raygen.slang --------- Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
2025-03-21Apply pixel interlock execution mode to entry-point functions only (#6661)Darren Wihandi
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
2025-03-19Output SPV_KHR_compute_shader_derivatives extension string instead of the NV ↵Darren Wihandi
extension (#6641) * Output SPV_KHR_compute_shader_derivatives instead of the NV extension * add alias for nv extension
2025-03-19Add SPIRV atomic debug type (#6616)Darren Wihandi
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
2025-03-13Add mesh shader output topology checks (#6592)Darren Wihandi
* initial wip * more wip * add test * add unexpected for invalid target * fixups and improve error message * fixups and improve error message * remove incorrect comment --------- Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
2025-03-07Fix SPIRV generator ID. (#6536)Yong He
2025-03-06Update SPIRV-Tools and fix new validation errors. (#6511)Yong He
* Update SPIRV-Tools and fix new validation errors. * Implement pointers for glsl target. * Reworked packStorage/unpackStorage code gen to operate on pointers rather than values.
2025-02-28Add Slang-specific intrinsics for integer pack/unpack (#6459)Darren Wihandi
* 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>
2025-02-27Map `SV_InstanceID` to `gl_InstanceIndex-gl_BaseInstance` (#6468)Yong He
* Map `SV_InstanceID` to `gl_InstanceIndex-gl_BaseInstance` * Fix ci.
2025-02-26Fix regression when using Atomic<T> in struct. (#6472)Yong He
2025-02-26[SPIRV]: Emit missing storage class in atomic insts. (#6456)Yong He
2025-02-11Emit missing atomic64 capability, fix int-typed builtin used in both vs and ↵Yong He
fs. (#6314) Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
2025-01-30Declare `VariablePointers` capability when needed. (#6231)Yong He
2025-01-30Support cooperative vector (#6223)Jay Kwak
* Support cooperative vector without Vulkan-header update Adding a Slang support for cooperative vector. But this commit doesn't have Vulkan-header update.
2025-01-29Update SPIRV submodules and fix tests (#6222)Jay Kwak
2025-01-24Add bgra8 format (#6163)Darren Wihandi
* 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>
2025-01-17Implement Quad Control intrinsics (#5981)Darren Wihandi
2025-01-14Implement specialization constant support in numthreads / local_size (#5963)Julius Ikkala
* Allow using specialization constants in numthreads attribute * Add support for GLSL local_size_x_id syntax * Fix overeager specialization constant parsing * Add diagnostics for specialization constant numthreads * Remove unused variable * Fix local_size_x_id not finding existing specialization constant * Allow materializeGetWorkGroupSize to reference specialization constants * Use SpvOpExecutionModeId for modes that require it * Cleanup specialization constant numthreads code * Add tests for specialization constant work group sizes * Fix implicit Slang::Int -> int32_t cast * Fix querying thread group size in reflection API --------- Co-authored-by: Yong He <yonghe@outlook.com>
2025-01-10Initial implementation of SP#015 `DescriptorHandle<T>`. (#6028)Yong He
* 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>
2025-01-09Support a storage class, NodePayloadAMDX, for SPIRV work-graphs (#6052)Jay Kwak
In order to unblock experiments with SPIRV work-graphs, Slang needs to support the storage class, `NodePayloadAMDX`. Note that this commit is only to support a storage class, `NodePayloadAMDX`. There are many parts required for work-graphs hasn't been implemented yet. The implementation of `DispatchNodeInputRecord` is not required, but it is implemented mostly for a testing purpose. Closes #6049 Co-authored-by: Yong He <yonghe@outlook.com>
2025-01-07Use disassemble API from SPIRV-Tools (#6001)Jay Kwak
* Use disassemble API from SPIRV-Tools This commit uses C API version of SPIRV disassemble function rather than calling spirv-dis.exe. This allows us to use a correct version of SPIRV disassble function that Slangc.exe is using. The implementation is mostly copied from external/spirv-tools/tools/dis/dis.cpp, which is a source file for building spirv-dis.exe. This commit also includes a fix for a bug in RPC communication to `test-server`. When an RPC connection to `test-server.exe` is reused and the second test abruptly fails due to a compile error or SPIRV validation error, the output from the first test run was incorrectly reused as the output for the second test. This commit resets the RPC result before waiting for the response so that even when the RPC connection is erratically disconnected, the result from the previous run will not be reused incorrectly. Some of the tests appear to be relying on this type of behavior. By using an option, `-skip-spirv-validation`, the RPC connection will continue without an interruption.
2024-12-26Add packed 8bit builtin types (#5939)Darren Wihandi
* Add packed bytes builtin type * fix test
2024-12-19Add base vertex and base instance system values (#5918)Darren Wihandi
* Add base vertex and base instance system values * Fixed incorrect stage in tests
2024-12-19Report error when generated spirv is empty. (#5899)Yong He
* Report error when generated spirv is empty. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>