summaryrefslogtreecommitdiff
path: root/source
AgeCommit message (Collapse)Author
2024-07-08Language server performance and document symbol fix. (#4561)Yong He
2024-07-08Treat global variables and parameters as non-differentiable when checking ↵Sai Praveen Bangaru
derivative data-flow (#4526) Global parameters are by-default not differentiable (even if they are of a differentiable type), because our auto-diff passes do not touch anything outside of function bodies. The solution is to use wrapper objects with differentiable getter/setter methods (and we should provide a few such objects in the stdlib). Fixes: #3289 This is a potentially breaking change: User code that was previously working with global variables of a differentiable type will now throw an error (previously the gradient would be dropped without warning). The solution is to use `detach()` to keep same behavior as before or rewrite the access using differentiable getter/setter methods.
2024-07-05Add vector overloads for or and and (#4529)Ellie Hermaszewska
* Add vector overloads for or and and Closes #4441 and #4434 * Disable cuda checks which use unsupported bool vectors * Add tests for 4531
2024-07-05Add specializations for 1 vectors in functions using the $N glsl intrinsic ↵Ellie Hermaszewska
placement (#4534) Closes #4533 Fixes part of #4531
2024-07-02Emit errors when invalid capabilities are used (#4510)ArielG-NV
* Fix invalid capabilities being allowed fixes: #4506 fixes: #4508 1. As per #4506, no longer allow invalid `[require(...)]` 2. As per #4508, no longer allow mismatch between `case` and `require` of a calling function 3. Fixes incorrect hlsl.meta capabilities 4. Added a ref to the parent function/decl for when erroring with capabilities to help debug meta.slang files for when weird source locations are generated. * rename vars and copy lambdas by value * fix some more capabilities * incorrect capabilities on a texture test * push capabilities fix note: seperated capabilities for glsl,spirv,cuda,hlsl since not all functions support all targets (source of capability error) * fix cmd line arg by using `xslang` to passthrough to slangc * let auto-infer run for certain capabilities to reduce simple mistakes --------- Co-authored-by: Jay Kwak <82421531+jkwak-work@users.noreply.github.com>
2024-07-01Fix the type error in kIROp_RWStructuredBufferLoad (#4523)kaizhangNV
* Fix the type error in kIROp_RWStructuredBufferLoad In StructuredBuffer::Load(), we allow any type of integer as the input. However, when emitting glsl code, StructuredBuffer::Load(index) will be translated to the subscript index of the buffer, e.g. buffer[index], however, glsl doesn't allow 64bit integer as the subscript. So the easiest fix is to convert the index to uint when emitting glsl. * Add commit
2024-07-01Support HLSL `.sample` operators for MS textures (#4524)venkataram-nv
* Add `.sample` operator for MS texture types * Adding filecheck tests for `.sample`
2024-07-01Supply SPIRV capability for textureQueryLod (#4522)venkataram-nv
2024-07-01Error out when constructing tensor views from tensors with 0 stride. (#4516)Sai Praveen Bangaru
This avoids a problem with broadcasted tensors. Our tensor-view platform is designed to allow unrestricted access to tensor memory, while broadcasted tensors were designed for 'read-only' use-cases. Trying to write into a broadcasted tensor needs re-allocation, which Slang is not designed to do. For now, we enforce contiguity on tensors with any 0 strides. In the future, we will introduce a ConstTensorView object to allow such tensors to be used as an input. This patch also propagates name-hint information through structs & arrays of tensors, to allow sensible names for the error messages (before this the error messages were temporary inst numbers, which is nearly impossible to debug)
2024-06-28Parse scope for local variable declaration (#4507)Jay Kwak
When a local variable is declaraed, a scope(::) was not properly parsed for its type name. This commit fixes it. Close #4457
2024-06-28Implement CheckAccessFullyMapped (#4509)Jay Kwak
* Implement CheckAccessFullyMapped Closes #4438 Closes #4445 Closes #1712 Related to #4495 This commit implements "CheckAccessFullyMapped()" for HLSL target. All of other "status" variants for Sample/Load are limited to HLSL by the capability system, because they not properly implemented yet.
2024-06-29Nested initialization list in struct crash fix (#4491)ArielG-NV
2024-06-28fix `WorkgroupSize()` compiler failiure (#4505)ArielG-NV
in some cases was not destroying the hoisted to global `WorkgroupSize()` function removed capability requirement on `gl_WorkGroupSize` since no longer appies (kIROp of `WorkgroupSize` is implemented for all targets) change when destroying inst
2024-06-28Implement HLSL resource bindings and default type `float4` to ↵ArielG-NV
`SubpassInput<T>` (#4462) * Add case to `emitVectorReshape` for `vector<>` type, `scalar` value 1. Add new case 2. Add test * fix warning * fix warning * Implement HLSL resource bindings and default type `float4` to `SubpassInput<T>` fixes: #4440 1. Removed GLSLInputAttachmentIndexLayout modifier and the somewhat 'hacky' binding model 'Input Attachment' previously relied upon. This was changed to work with the slang-type-layout rules system. This change allows Slang automatic bindings, HLSL bindings, GLSL bindings, and translation of GLSL to and from HLSL bindings to work. 2. Added default argument `float4` to SubpassInput<T>. 3. Merged glsl.meta and hlsl.meta SubpassInput logic. * fix InputAttachment attribute checks fix InputAttachment attribute checks for HLSL and GLSL syntax * remove unused var * validate attribute correctly Attributes do not have type information. We must check the type expression to validate attribute usage. * remove hacky validation type based validation before types are fully resolved is quite hacky and unstable to changes and wrapped types * fix warning * remove redundant `!= nullptr` * remove extra `!= nullptr` * fix some warnings/errors * subpass capability to limit to dxc & remove default values in some functions * revert logic to previous logic revert logic to return if we have a binding regardless of if a VarDecl is given the binding
2024-06-27Extend `countbits` intrinsic for vector types (#4499)venkataram-nv
* Extend `countbits` intrinsic for vector types This commit implements the overloading function for `countbits` function. Because HLSL has following overloadings, ``` uint count_bits(uint value); uint2 count_bits(uint2 value); uint3 count_bits(uint3 value); uint4 count_bits(uint4 value); ``` https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/countbits
2024-06-27Cache address-space-legalization of `kIROp_Store` (#4480)ArielG-NV
* Cache address-space-legalization of `kIROp_Store` without caching we will infinetly loop re-processing the same `kIROp_Store` * uncomment tests which should now work with metal * disable gfx backend failing tests
2024-06-27Add API for querying dependency files on IModule (#4493)skallweitNV
* Add API for querying dependency files on IModule * return nullptr
2024-06-27Implement `uint2` variant of `asdouble` intrinsic (#4488)venkataram-nv
* Implement asdouble2 intrinsic and tests Fixes #4437 Adds a new asdouble2 intrinsic for all platforms except Metal. Extends the test for asdouble to test asdouble2 as well.
2024-06-27Remove returned-array-legalization pass for metal (#4478)ArielG-NV
* disable return array optimization pass for metal targets fixes: #4468
2024-06-26Fix Texture2DMSArray (#4485)Jay Kwak
* Fix Texture2DMSArray Close #4427 We had the postfix order wrong for the keyword MS. This commit changes the incorrect name Texture2DArrayMS to Texture2DMSArray.
2024-06-26Expand upon existing `ImageSubscript` support (Metal, GLSL, SPIRV) (#4408)ArielG-NV
* Add additional `ImageSubscript` features: 1. Added ImageSubscript support for Metal & a test case * Merge GLSL/SPIRV/Metal `ImageSubscript` legalization pass 2. Added multisample support to glsl/spirv/metal for when using ImageSubscript * Added in this PR since the overhaul of the code merges together GLSL/SPIRV/Metal implementation 3. Fixed minor metal texture `Load`/`Read` bugs * [HLSL methods of access do not support subscript accessor for texture cube array](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/texturecubearray) * removed swizzling of uint/int/float * other odd bugs which were causing compile errors note: Compute tests do not work due to what seems to be the GFX backend (causes crash without error report). The tests are disabled. * disable LOD with texture 1d seems that LOD for 1d textures need to be a compile time constant as per an error metal throws * syntax error in hlsl.meta * static_assert alone with intrinsic_asm error provides cleaner errors Note: `static_assert` seems to be unstable and not be fully respected (still require `intrinsic_asm` to avoid a stdlib compile error) * change comment to `// lod is not supported for 1D texture * add `static_assert` in related code gen paths * address review * address review * add asserts as per review comment, NOTE: unclear if these should be release 'asserts' as well
2024-06-25Support atomic intrinsics for Metal (#4473)Jay Kwak
* Support atomic intrinsics for Metal This commit adds a support for the atomic intrinsics in Metal. The atomic member functions for buffers is not implemented yet. Metal requires the first argument for the atomic functions to be an atomic data type. This implementation rely on the fact that we can do a C-style type casting from a regular data type to an atomic data type.
2024-06-25Fix return type address space checking. (#4465)ArielG-NV
solves: `func-resource-result-simple.slang`, related to #4291 when getting the address space of a function return we now check the return address of the inst if the return type is a non pointer type.
2024-06-25Add intrinsic for `IsHelperLane()` in HLSL (#4471)venkataram-nv
Add InHelperLane() intrinsic for HLSL, GLSL, Metal and Spirv.
2024-06-24Add case to `emitVectorReshape` for when using a `vector<M, N>` type with ↵ArielG-NV
`T` value (#4419) * Add case to `emitVectorReshape` for `vector<>` type, `scalar` value 1. Add new case 2. Add test * fix warning * fix warning
2024-06-24Added float2x2 cast to float4 (and vise versa) (#4432)ArielG-NV
* added float4x4<->float4 casting (and related) Note: not adding `matrix<1,N>` and `matrix<N,1>` translations since this will bloat stdlib with many expensive to process `extension` operations. `matrix<N,1>` is already planned to be treated as vectors (which should solve this problem by proxy). * address review * explicit cast mat to vec
2024-06-24Implementing `tbuffer` layout(s) (#4436)ArielG-NV
* Implementing `tbuffer` layouts. 1. Add to layout options 'TextureBuffer' layouts. 2. Add on to existing logic a way to allocate appropriate registers for TextureBufferType (this was made to work with parameter block logic). 3. Added asserts so objects missing a layout will gracefully crash This means `tbuffer` now works for hlsl,glsl,metal targets, spirv has yet to implement logic for `TextureBufferType`. * disable metal tests and fix emitting code a bit fixing the emitting code means metal compilation emits a useful error (help point users/developers to #4435) * fix warning
2024-06-20Add capture logic to other interfaces. (#4412)kaizhangNV
* Add capture logic to other interfaces. Add capture logics to ISession, IModule, ITypeConformance, IEntryPoint ICompositeComponentType. Add few encode methods to encode the array. Fix some capture logic in global session. We will not need to encode the null_ptr output before actual actual of the captured APIs. Previously we used this as a place holder, but it's actually not necessary, it can be detected if the output is not captured during replay. * capture/replay: dump the shader files to disk Dump the shader files to disk. Also set a default directory for the capture files.
2024-06-20Disambiguate int type matrix multiply (#4425)Jay Kwak
Closes #4414
2024-06-18Metal: Implement fix for non vector4 texture Load/Sample (#4417)ArielG-NV
* Metal: Implement fix for non vector4 texture Load/Sample 1. Fixes buffer-swizzle-store 2. Added test cases to texture.slang to cover all types * remove 1d lod support and buffer swizzle store this can be enabled later
2024-06-17Feature/capture (#4397)kaizhangNV
* Add the function tailer for appending the output - The basic format for the capture encode is as follow: Header: 4 bytes: magic number ('H' 'E' 'A' 'D' ) 4 bytes: call id - specify the method name 8 bytes: handle id - specify 'this' pointer 8 bytes: payload size in bytes - specify the data size of parameters 8 bytes: thread id Payload: Encode for all the parameters. Tailer (optional): Tailer is an optional, it only used when the output of the method is also stored in the method. Usually it just the opaque handle allocated by slang. 4 bytes: magic number ('T' 'A' 'I' 'L') 4 bytes: payload size in bytes. - Fix some issues in checking the result of write of output stream. * Encoding methods of IGlobalSession Add encoding logic for all the member functions of IGlobalSession, except those query functions that do not impact the internal state of slang. Because some get functions will invoke allocations by slang, these functions are account for the "query functions". Therefore those functions are still captured. All the allocations are stored by using their address, because those allocations are opaque and will finally be used as inputs for other APIs, there is no need to store the data. We just need to track those address and know which APIs will consume them. * Add SLANG_CAPTURE_CHECK macro Add SLANG_CAPTURE_CHECK macro to check SLANG_OK is returned. * Fix build error
2024-06-17Fixed gl_LocalInvocationIndex being uvec3 instead of uint (#4403)gan_
2024-06-14remove inline that crashes old glibc version (#4398)ArielG-NV
2024-06-14Improve Direct SPIRV Backend Test Coverage (#4396)ArielG-NV
'raytracing' and 'texture-footprint' tests fixed texture-footprint bug changed when we emit raytracing/rayquery extensions with glsl backend (to reduce incorrect extension emitting)
2024-06-14[Metal] Fix global constant array emit. (#4392)Yong He
* [Metal] Fix global constant array emit. * Try enable more tests.
2024-06-14Make unknown attributes a warning instead of an error. (#4391)Yong He
2024-06-13[Metal] Support SV_TargetN. (#4390)Yong He
* [Metal] Support SV_TargetN. * Fix.
2024-06-13Implement for metal `SV_GroupIndex` (#4385)ArielG-NV
* Implement for metal `SV_GroupIndex` 1. If we don't have `sv_GroupThreadId` available we create one using `SV_GroupIndex`s location data. 2. We emit code emulating `sv_GroupThreadId` from the same logic that CUDA/CPP uses. * address most review comments Addressed all but two: [1](https://github.com/shader-slang/slang/pull/4385#discussion_r1639058473) and [2](https://github.com/shader-slang/slang/pull/4385#issuecomment-2166934855) I want to enable tests and be sure there is no bugs using CI before I redesign the code so I have a working fallback. * address comment, enable tests enable now functioning tests due to `SV_GroupIndex` working with metal * syntax error with groupThreadID search did `= param` instead of `= i.param` * add `sv_groupid` for test + test fixes * disable test that won't work regardless
2024-06-13fix the clang/gcc warning (#4382)ArielG-NV
* fix the clang/gcc warning * use macro for maybe unused * (code style) macro to start of function --------- Co-authored-by: Jay Kwak <82421531+jkwak-work@users.noreply.github.com>
2024-06-13Metal: misc fixes and enable more tests. (#4374)Yong He
* Fix and enable tests for metal. * Fix. * Fix. * Fix tests. * Fix warnings. * Fix. --------- Co-authored-by: Yong He <yonghe@Yongs-Mac-mini.local>
2024-06-13SPIR-V `SV_InstanceId` support in pixel shader (#4368)ArielG-NV
* solve issue by making 'non SV for SPIRV' system semantics, no longer an SV once diagnosed by slang Problem: 1. SV_InstanceID (HLSL) is allowed as an output semantic with HLSL, it is also allowed for input into pixel shader. We need to account for multiple entry points in 1 file using both of these scenarios at once. 2. SPIRV does not allow `SV_InstanceID` as a builtin, `SV_InstanceID` must be passed as a regular `flat` `Input` from vertex shader. Solution: Slang needs to treat these SV objects as non built-in's. As a result: 1. Slang needs to allocate for vertex output and fragment Input binding slots for all SV_InstanceID uses (if the target is SPIRV). This allows Slang to prepare an open slot to bind these SV objects to. 2. Slang needs to not emit built in modifier for these not actual built in variables (under the specific circumstances described). note: `VarLayout` was made not `HOISTABLE` since I don't believe it needs to be `HOISTABLE`. * The code can be made to work even if `VarLayout` is `HOISTABLE`. * fix compile warnings * address review comments and reimplement operand removal 1. remove an operand by selectively copying operands 2. test to ensure `Flat` is in the test shaders * we do not need to manually add `Flat` in the code since this is done for us in emit-spirv. This is the behavior since `uint` on a fragment `Input` must be `Flat`, else it is a VK validation error. * address review remove clone logic * address review remove unused function reserve instead of setCount with ShortList
2024-06-13Remove `IRHLSLExportDecoration` and `IRKeepAliveDecoration` for ↵Sai Praveen Bangaru
non-CUDA/Torch targets (#4364) * Remove `IRHLSLExportDecoration` and `IRKeepAliveDecoration` for non-CUDA/Torch targets * Update hlsl-torch-cross-compile.slang
2024-06-13capture/replay: implement infrastructure for capture (#4372)kaizhangNV
* Define api call ID for each being captured methods * Add parameter encoder interface * Add outputStream and capture manager Add infrastructure for output stream This is the interface to record the method and parameter, and also provide functionality to write all the serialized data into file. Add capture manager: Capture manager is associated to global session object, it will provide the functionality to actual record all the APIs. Implement some of parameter encoder functions. * Fix some Windows & cmake build error * remove unused headers
2024-06-13Fix cuda/cpp/metal crash for when using GLSL style shader inputs (#4378)ArielG-NV
Decorations were not expected as an input, this causes a crash.
2024-06-12Implement Sampler2D for CPP target (#4371)Jay Kwak
Closes #4267 Co-authored-by: Yong He <yonghe@outlook.com>
2024-06-12Delete glsl_vulkan and glsl_vulkan_one_desc targets. (#4361)Yong He
2024-06-12Fix emit logic for getElementPtr. (#4362)Yong He
* Fix emit logic for getElementPtr. * Legalize `getElementPtr(vector, id)` for metal. * Fix compiler error. * Fix warnings. * Fix test. * Fix.
2024-06-12Capability System: Implicit capability upgrade warning/error (#4241)ArielG-NV
* capability upgrade warning/error adjusted implementation + tests to support a warning/error if capabilities are implicitly upgraded and test accordingly. * add glsl profile caps * add GLSL and HLSL capabilities to the associated capability * syntax error in capdef * only error if user explicitly enables capabilities 1. changed testing infrastructure to not set a `profile` explicitly, 2. Added tests to be sure this works as intended with user API and with slangc command line * Change capability atom definitions and how Slang manages them to fix errors 1. most `glsl_spirv` version atoms have been removed from `.capdef`, instead we will translate `spirv` version atoms into `glsl_spirv` since there is no point in writing the same code twice in `.capdef` files to define `spirv` versions. 2. add spirv version, and hlsl sm version (and equivlent) capability dependencies 3. removed some stage requirments which were set on objects, keep the wrapper capabilities. I am keeping the wrapper capabilities since I am unaware on if there are stage limitations (spec says code in practice does not work). * check internal version instead of version profile (_spirv_1_5 vs. spirv_1_5) * remove unused OpCapability. adjust SPIRV version'ing again for glsl_spirv * apply workaround for glslang bug with rayquery usage * ensure capabilities targetted by a profile and added together by a user are valid * remove additions to `spirv_1_*` wrapper * spirv_* -> glsl_spirv fix * fix bug where incompatable profiles would cause invalid target caps * try to avoid joining invalid capabilities * fix the warning/error & printing * run through tests to fix capability system and test mistakes many mistakes were mesh shaders doing `-profile glsl_450+spirv_1_4`. This is not allowed for a few reasons 1. the test tooling does not handle arguments the same as `slangc` 2. glsl_450 core profile does not support mesh shaders, nor does spirv_1_4. sm_6_5 does work in this senario * set some sm_4_1 intrinsics to sm_4_0 * replace `GLSL_` defs with `glsl_` * swap the unsupported render-test syntax for working syntax * set d3d11/d3d12 profile defaults this is required since sm version changes compiled code & behavior * adjusted nvapi capabilities with atomics + d3d11 set to use sm_5_0 as per default * cleanup * address review * incorrect styling * change `bitscanForward` to work as intended on 32 bit targets --------- Co-authored-by: Yong He <yonghe@outlook.com>
2024-06-12Add constant folding for % operator. (#4359)Yong He
2024-06-12Fix merge error. (#4358)Yong He