summaryrefslogtreecommitdiff
path: root/source/slang
AgeCommit message (Collapse)Author
2023-08-16Use ankerl/unordered_dense as a hashmap implementation (#3036)Ellie Hermaszewska
* Correct namespace for getClockFrequency * missing const * Add missing assignment operator * Remove unused variables * Return correct modified variable * Use stable hash code for file system identity * terse static_assert * Structured binding for map iteration * Make (==) and getHashCode const on many structs * Add ConstIterator for LinkedList * Replace uses of ItemProxy::getValue with Dictionary::at * Extract list of loads from gradientsMap before updating it * Const correctness in type layout * Add unordered_dense hashmap submodule * Use wyhash or getHashCode in slang-hash.h * refactor slang-hash.h * Use ankerl/unordered_dense as a hashmap implementation Notable changes: - The subscript operator returns a reference directly to the value, rather than a lazy ItemProxy (pair of dict pointer and key) slang-profile time (95% over 10 runs): - Before: 6.3913906 (±0.0746) - After: 5.9276123 (±0.0964) * 64 bit hash for strings So they have the same hash as char buffers with the same contents * Narrowing warnings for gcc to match msvc * revert back to c++17 * Correct c++ version for msvc * Use path to unordered_dense which keeps tests happy * Do not assign to and read from map in same expression * Remove redundant map operations in primal-hoist * Split out stable hash functions into slang-stable-hash.h * 64 bit hash by default * regenerate vs projects * Correct return type from HashSetBase::getCount() * correct width for call to Dictionary::reserve * Use stable hash for obfuscated module ids * Signed int for reserve * clearer variable naming * Parameterize Dictionary on hash and equality functors * Allow heterogenous lookup for Dictionary * missing const * Use set over operator[] in some places * Remove unused function * s/at/getValue
2023-08-15Fix ByteAddressBuffer array legalization. (#3106)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-15Fix bug with overload resolution under nested generics (#3107)Sai Praveen Bangaru
* Add test for generic param inference bug for nested generics * Change description & simplify test * Add expected file * Check parent decl before unifying type parameters
2023-08-15SPIR-V WIP (#3064)Ellie Hermaszewska
* Add type layout for structured buffer * Default to generating spirv directly * vk test for compute simple * Add spirv-dis as a downstream compiler * Emit Array types in SPIR-V * makevector for spirv * Dump whole spirv module on validation failure * register array types todo, use emitTypeInst * Neater formatting for unhandled inst printing * break out emitCompositeConstruct * Correct array type generation * neaten * Allow getElement for vector * Remove unused * Allow predicating target intrinsics on types * Consider functions with intrinsics to have definitions We need to specialize these if they are predicated on types * Correct array type generation * makeArray for spir-v * replace getElement with getElementPtr for spirv * Correct translation of field access for spirv * Push layouts to types for spirv * Spirv intrinsics * operator now makes a pointer * Add structured buffer of struct test * Preserve type layout in spirv structured buffer legalization * neaten * makeVectorFromScalar for SPIRV * placeholder for layouts on param groups * More type safe spirv op construction * Know that constants and types only go in one section * Remove emitTypeInst * Add todo for spirv sampling * Add links to spirv documentation on emit functions * OpTypeImage support for SPIR-V * Add simpler texture test for spirv * s/spirv_direct/spirv/g * Allow several string literals in target_intrinsic * Handle global params without a var layour for SPIR-V For example groupshared vars * uint spirv asm type * Add todo for isDefinition It is currently too broad * Some atomic op spirv intrinsics * Strip ConstantBuffer wrappers for spirv * Add todo for matrix annotations * Do not associate decorations insts with spirv counterparts * Correct entry point parameter generation * Spelling * Assert that fieldAddress is returning a pointer * Add error for existential type layout getting to spir-v emit * Add IRTupleTypeLayout Unused so far * Allow getElementPtr to work with vectors * Correct target name in test * Hide default spirv direct behind a premake option --default-spirv-direct=true * Do not insert space at start of intrinsic def * Correct asm rendering in tests * remove redundant option * Emit directly from direct test * Add source language options for spirv-dis * Add comments to spirv dis * Add dead debug print for before spirv module * Correct asm rendering in tests * s/spirv_direct/spirv/g * Only specialize intrinsic functions with predicates * regenerate vs projects * squash warnings * squash warnings * remove duplication * Silence warnings from msvc * squash warnings * Overload for zero sized array * More msvc warnings * warnings * Add spirv-tools to path for tests * Do not be specific about dxc version for diag test * Normalize line endings from spirv-dis * Correct filecheck matches * Temporarily disable two spirv tests Failing on CI, undebuggable hang :/ * Do not emit storage class more than once for spirv snippet * Do not pass spir-v to spirv-dis by stdin * Do not get spirv-dis output via stream, use file * normalize file endings in spirv-dis output
2023-08-14Add auto-diff support for `IRSwizzleStore` (#3102)Sai Praveen Bangaru
* Add auto-diff support for `IRSwizzleStore` - Lower IRSwizzleStore to multiple stores during AD preprocess. - Fix typo in `transcribeNonDiffInst` * Remove unnecessary file & add more robust check for 'local' addresses * Fix. * Update slang-ir-autodiff-fwd.cpp --------- Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-14Support per field matrix layout (#3101)Yong He
* Support per field matrix layout * Fix warnings. * Fix. * Fix tests. * Fix spiv gen. * Fix. * More test fixes. * Fix. * Run only GPU tests on self-hosted servers. * Remove -use-glsl-matrix-layout-modifier. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-14Fix issue with nested loop unrolling (#3100)Sai Praveen Bangaru
* Do not eliminate single-iter-loops that have inner loops using their break label. * Add test * Delete out-old.hlsl * Update slang-ir-autodiff-cfg-norm.cpp * Fix whitespace
2023-08-11Make sure glsl source in spirv is included when compiling with -g3 (#3099)Yong He
* Make sure glsl source in spirv is included when compiling with -g3. * Exclude vulkan tests on github linux CI. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-10Add scalar version of `distance`. (#3096)Yong He
2023-08-10Fix `Texture2D.Load()` with offset. (#3094)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-10Add support for ConstBufferPointer on Vulkan. (#3089)Yong He
* Add support for `ConstBufferPointer` on Vulkan. * Add spv compilation test. * Fix. * Fix code review issues. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-10Allow member lookup through modified type. (#3091)Yong He
* Allow member lookup through modified type. * Disable `lockFileSync` test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-09Support nested structs in function bodies. (#3078)Yong He
2023-08-09Support implciit casted swizzled lvalue. (#3077)Yong He
* Support implciit casted swizzled lvalue. * Fix warnings. * Fix. * fix comment. * Prefer mangled linkage name for global params. * Update tests. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-09Various fixes in GLSL emit. (#3074)Yong He
* Fix name mangling of modified types. * Add `InterlockedAdd(__ref uint, int)` overload. * Fix. * Fix type error in ImageStore legalization. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-09Clean up and improve Val deduplication performance. (#3069)Yong He
* Clean up and improve Val deuplication performance. * Fix. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-08Support `-fvk-use-gl-layout` for ByteAddressBuffer load/store. (#3068)Yong He
* Support `-fvk-use-gl-layout` for ByteAddressBuffer load/store. * Fix. * Fix. * Add test for unaligned load. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-07Add warning on mutation of function parameter (#3067)Theresa Foley
By default, function parameters in HLSL are mutable, but any changes to a parameter do not affect the values of the arguments after a call: void f(int a) { a++; // allowed, but kind of useless } ... int b = 0; f(b); // b is still zero Because the above behavior is a part of HLSL, we cannot easily diagnose such cases as errors without breaking backward compatibility with existing code. This change makes it an error to invoke a `[mutating]` method on a function parameter, which cannot affect backward compatibility since the notion of `[mutating]` methods is not present in existing HLSL code: struct Counter { int _state; [mutating] void increment() { _state++; } } void f(Counter a) { a.increment(); // ERROR } ... Counter b = { 0 }; f(b); // b is still zero The compiler will also diagnose calls to `[mutating]` methods on a field or array element extracted out of a function parameter. This change does not affect code that directly mutates a function parameter via assignment, or via passing the parameter onward as an argument to an `out` or `inout` call (or, equivalently, as the left-hand operand to a compound assignment operator). This is a breaking change to existing Slang code, since it could diagnose an error on code that used to be allowed. Indeed, two tests in the Slang test suite had to be updated to avoid such errors. It would be possible to turn this diagnostic into a warning, and simply encourage users to enable it as an error. On balance, though, it seems best to not allow this idiom since it has such a high probability to be an error. Note: the specific case that motivated this change is use of `RayQuery` values as function parameters. The root of the problem there is that dxc treats `RayQuery` values as copyable handles to mutable state, while Slang prefers to capture the mutation that occurs through marking the appropriate methods as `[mutating]`. The Slang approach makes portable codegen for D3D/Vulkan simpler, but requires that we *also* treat a type like `RayQuery` as non-copyable. This change does not address the problem that the Slang compiler does not enforce the requirement that values of non-copyable types do not get copied. Instead, the diagnostic here just happens to issue a diagnostic in one important case where a copy would typically occur. Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-07Add spirv-dis as a downstream compiler (#3059)Ellie Hermaszewska
* Add spirv-dis as a downstream compiler * Add TODO for spirv-dis downstream compiler * Do not use SpirvDis by default * tabs to spaces * regenerate vs projects * correct test * correct calling convention --------- Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-07Default target intrinsic should not apply to SPIR-V (#3054)Ellie Hermaszewska
* Default target intrinsic should not apply to SPIR-V * CapabilitySet is a conjunction * Add TEXTUAL_SOURCE capability class
2023-08-07Fix -fvk-use-entrypoint-name. (#3066)Yong He
* Fix -fvk-use-entrypoint-name. * Remove irrelevant changes. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-07Validate generated SPIR-V on output (#3061)Ellie Hermaszewska
* Validate generated SPIR-V * regenerate vs projects * Do not fail compiles if spirv-val is not available --------- Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-07Unify Type and Constant sections for SPIR-V (#3057)Ellie Hermaszewska
Types can depend on constants (for example fixed sized arrays) Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-07Casting and vector/scalar correct arithmetic ops for SPIR-V (#3056)Ellie Hermaszewska
* types for cast instructions * Information getting functions for int and float types * Implement spirv casting * Broadcast operands for SPIR-V arithmetic SPIR-V doesn't allow vector/sclar arithmetic ops * Simplify spirv int/float type generation --------- Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-07Diagnostic improvements for direct spirv (#3053)Ellie Hermaszewska
* Fail on an unhandled spv operand * Diagnose on emitting a function with no definition or intrinsic * clearer error message * Add assert * Add assert * remove unused assert * Disagnostic on snippet parsing failure * Mention unimplemented instruction in error message * mention unhandled local instruction for spirv in error message * Allow specifying dump options in dumpIRToString --------- Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-07Fix `Val` deduplication bug. (#3050)Yong He
* Fix `Val` deduplication bug. * Fix * Concat stdlib files into a single module. * Remove unnecessary logic in `resolve`. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-08Allow parsing some SPIR-V enums in intrinsics (#3062)Ellie Hermaszewska
* Add TokenReader::AdvanceIf overlaod for TokenType * Add some spirv defs to parser * Add comment
2023-08-08Simplify SpvTypeInstKey (#3063)Ellie Hermaszewska
2023-08-08sv_groupindex support for spirv (#3060)Ellie Hermaszewska
2023-08-08Fail on an unhandled spv operand (#3052)Ellie Hermaszewska
Co-authored-by: Yong He <yonghe@outlook.com>
2023-08-07Correct return type for emitFieldAddress (#3051)Ellie Hermaszewska
2023-08-04Add option to use original entrypoint in spirv output. (#3047)Yong He
* Add option to use original entrypoint in spirv output. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-04Redesign `DeclRef` and systematic `Val` deduplication (#3049)Yong He
* Redesign DeclRef + Deduplicate Val. * Update project files * Fix warning. * Fix. * Fix. * Remove `Val::_equalsImplOverride`. * Rmove `Val::_getHashCodeOverride`. * Remove `semanticVisitor` param from `resolve`. * Cleanups. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-08-03Fix around texture footprint support for NVAPI. (#3046)jsmall-nvidia
2023-08-03Disable code motion for expensive insts (call & div) (#3042)Sai Praveen Bangaru
* Disable code motion for expensive insts (call & div) The current redundancy removal pass does not consider control-flow within loops and as a result can sometimes move dynamic dispatch code outside their switch blocks, if they are nested in a single-iter-loop. * Update liveness.slang.expected
2023-08-01Fix literals needing cast (#3039)jsmall-nvidia
* Cast integer literals. * Fix expected output. * For CUDA, search global instructions to see what types are used. Improve lookup for fp16 header in CUDA. * Fix issue with f16tof32 * Small improvement around finding used base types.
2023-08-01Generalize collectInductionValues (#3031)Ellie Hermaszewska
* Generalize collectInductionValues * Support affine transformations of loop index as induction variables * Test for generalized induction value collection * Neaten inductive variable finding * Store the type of implication success when finding inductive variables * Test that loop induction finding does not alway succeed * Support chains of additions and branches of additions in induction variable finding * Use c++17 for downstream compilers
2023-07-31Fix for #elif evaluation issue (#3038)jsmall-nvidia
* A more way robust way to handle resource consumption might use multiple `kind`s on GLSL emit. * Improve method naming and some comments. * Small consistency fix. * Fix issue with #elif evaluation. * Add a test.
2023-07-27Fix push constant on global variables. (#3034)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2023-07-27Fix -fvk-u-shift not applying to global constant buffer. (#3033)Yong He
* Fix -fvk-u-shift not applying to global constant buffer. * Fix test. * Fix. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-07-26Refactor `dmul(This, Differential)` to `dmul<T:Real>(T, Differential)` (#3029)Sai Praveen Bangaru
* Refactor `dmul(This, Differential)` to `dmul<T:Real>(T, Differential)` - Add AST synthesis support for generic containers - Refactor relevant tests * Merge dmul synthesis with dadd and dzero, and disambiguate using an enum * Fix trailing spaces
2023-07-26Fix scalar swizzle causes invalid glsl output. (#3028)Yong He
* Fix -fvk-u-shift not applying to RWStructuredBuffer on glsl output. * Add `transpose` to `ObjectToWorld4x3`. * Fix scalar swizzle causes invalid glsl output. Fixes #3026. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-07-26Fix -fvk-u-shift not applying to RWStructuredBuffer on glsl output. (#3027)Yong He
* Fix -fvk-u-shift not applying to RWStructuredBuffer on glsl output. * Add `transpose` to `ObjectToWorld4x3`. --------- Co-authored-by: Yong He <yhe@nvidia.com>
2023-07-26Add glsl intrinsics for CalculateLevelOfDetail (#3023)Ellie Hermaszewska
Translates to textureQueryLod().x (with the Unclameped variant being returned in the .y component) Co-authored-by: Yong He <yonghe@outlook.com>
2023-07-26Add GatherCmp* for texture objects (#3024)Ellie Hermaszewska
The translation to GLSL is incomplete as intrinsics only exist for some combination of comparison and channel (just channel 0) Closes https://github.com/shader-slang/slang/issues/3021
2023-07-25Add slang.natjmc. (#3018)Yong He
This allows Visual Studio debugger to skip over AST visitor dispatch functions and stop directly at the `visit*` functions when stepping into a `dispatch*` call. Co-authored-by: Yong He <yhe@nvidia.com>
2023-07-25Allow parsing more than 10 intrinsic arguments (#3014)Ellie Hermaszewska
2023-07-24Remove [__readNone] on clip. (#3016)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2023-07-21Add support for `-fvk-invert-y`. (#3012)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>
2023-07-21Add sampleCount parameter for read-only textures. (#3011)Yong He
Co-authored-by: Yong He <yhe@nvidia.com>