summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-stdlib-textures.cpp
Commit message (Collapse)AuthorAge
* Replace stdlib with core-module on files and projects (#5411)Jay Kwak2024-10-25
| | | | | | | This commit renames the files and projects to prefer "core-module" over "stdlib". The directory name `source/slang-stdlib` needs to be renamed too, and there will be another commit for it soon.
* Fix incorrect use of pointer in WGSL (#5144)Jay Kwak2024-09-23
| | | | | | | | Closes #5143 Recently there was a commit that changed the behavior of the memory pointer for WGSL. This commit fixes some issues came up after the change.
* 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.
* Emit errors when invalid capabilities are used (#4510)ArielG-NV2024-07-02
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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>
* Implement texture functions for Metal target (#4158)Jay Kwak2024-05-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Impl texture APIs for Metal target This commit is to implement texture functions for Metal target. The following functions are implemented and tested. - GetDimensions() - CalculateLevelOfDetail() - CalculateLevelOfDetailUnclamped() - Sample() - SampleBias() - SampleLevel() - SampleCmp() - SampleCmpLevelZero() - Gather() - SampleGrad() - Load() Metal has limited support for the texture functions compared to HLSL. - LOD is not supported for 1D texture, - Depth textures are limited to 2D, 2DArray, Cube and CubeArray textures. - "Offset" variants are limited to 2D, 2DArray, 2D-Depth, 2DArray-Depth and 3D textures. The functions that cannot be implemented for Metal should properly be handled by the capability system later. * Fix the failing test, multi-file.hlsl I am not sure why this change is needed. * Fix compile errors on macOS 2nd try * Remove a typo character to fix the compile error * Trivial clean up * Remove `as_type` where it was intended as static_cast * Use a simpler sytax for __intrinsic_asm * Trivial clean up * Remove TEST_AFTER_FIXING_CAPABILITY_PROBLEM after fixing normalize * Fix the failing test properly * Fix an incorrect setup of Depth-cube texture --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Initial pass to add capability declarations to stdlib intrinsics. (#3912)ArielG-NV2024-04-19
|
* Fix #3566. (#3574)Yong He2024-02-12
|
* Implement GLSL build-in functions related to texture (#3544)Jay Kwak2024-02-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Implement GLSL texture related built-in functions Partially resolves #3362 This change implemented GLSL build-in functions described in the following sections of "OpenGL Spec" document. 8.9.1. Texture Query Functions 8.9.2. Texel Lookup Functions 8.9.4. Texture Gather Functions 8.9.5. Compatibility Profile Texture Functions About 200 functions are newly implemented. Most of the functions are calling the HLSL implementation so they are expected to work for all targets but they haven't been tested throughly yet. __TextureImpl got a new generic parameter, "isRectangle", to support sampler2DRect and sampler2DRectShadow. It is a sampler for rectangular texture with no mipmaps. For the reason, its "GetDimentions()" doesn't return mip information. The sampling needs to happen in an integer coordinate not in a normalized [0,1] range. but this hasn't been implemenented yet. Texture functions whose name include "Offset" takes an integer type parameter and those values are required to be a compile-time constant. However, our currentl implementation of slangc seems to make the values not-compile-time constant. As a workaround, the test case uses __LINE__ macro to use a unique numbers so that slangc wouldn't collect them into a runtime variable. I put "constexpr" on "offset" parameters as much as possible. But the issue was still reproduced when targetting SPIRV. Texture functions whose name include "Proj" are emulated by dividing the coordinate value with its last component. For that reason, they take one additional component for its coordinate value. As an example, following function takes two components for sampler1D, instead of one: vec4 textureProj(sampler1D sampler, vec2 p); All shadow samplers stores depth-compare-value at the last component. But sampler1DShadow take one extra component, which is vec3 not vec2. It is unclear what the reason is but the second component is unused in this case. Here is an example, float texture(sampler1DShadow sampler, vec3 p); samplerCubeArrayShadow takes five components for its coordinate and the depth-compare-value cannot be stored in the last component of the cooridnate. It is separated out as an independent parameter, float texture(samplerCubeArrayShadow sampler, vec4 p, float compare); TextureGather functions got some modifications. The existing implementation was calling textureGatherOffset[s] with the parameters in a wrong order. This mistake is corrected. * Bring back GatherCmpRed/Green/Blue/Alpha HLSL has GatherCmpRed/Green/Blue/Alpha functions and it was removed from my previous change by a mistake. This change brings them back. * Disabling two failing tests in intrinsic-texture The new test file, intrinsic-texture.slang, has five test settings and two of them are currently failing; they are targetting HLSL and CPP. This change disables them to avoid confusion. * Remove "isRectangle" parameter from __TextureInfo Partially resolves #3362 This commit has a few changes based on the feedback from the code reviews. 1. Remove "isRectangle" parameter from __TextureInfo, because "sampler2DRect" can be replaced with "sampler2D" that always uses lod level 0. All functions associated to "Rect" are also removed. 2. Enabled tests for "samplerBuffer". 3. Removed "__target_intrinsic(glsl)" from glsl.meta.slang, because we want to stay away from it in the future. 4. Some tests in intrinsic-texture.slang are disabled if the functions take constant offset values or take MultiSample samplers. --------- Co-authored-by: Yong He <yonghe@outlook.com>
* Update the GetDimension hlsl builtin for spirv path. In case of sampler, a ↵Pankaj Mistry2024-01-02
| | | | combined sampled image needs an OpImage to be generated. (#3424)
* Unify stdlib `Texture` types into one generic type. (#3327)Yong He2023-11-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Unify Texture types in stdlib into 1 generic type. * Fixes. * Fix. * Fixes. * Fix reflection. * Fix binding reflection. * Add gather intrinsics. * Fix gather intrinsics. * Fix texture type toText. * Fix intrinsic. * fix cuda intrinsic. * Fix project files. * cleanup. * Fix. * Fix. * Fix sampler feedback test. * Fix getDimension intrinsics. * Fix spirv sample image intrinsics. * Fix test. * Fix GLSL intrinsic. * Cleanup. --------- Co-authored-by: Yong He <yhe@nvidia.com>
* Add GLSL Compatibility. (#3321)Yong He2023-11-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Parse glsl buffer blocks to GLSLInterfaceBlockDecl * Parse glsl local size layout declarations * Parse (and ignore) glsl version directives * spelling * Better l-value interpretation for glsl interface blocks * Better l-value interpretation for glsl interface blocks * Add compile flag for enabling glsl * Parse and ignore precision modifiers. * Automatically import `glsl` module for compatiblity. * Complete vector and matrix types for glsl * Remove generated file from repo * Bump .gitignore * do not mark out globals as params * Synthesize entrypoint layout from global inout vars. * update test result. * Allow HLSL semantic on global variables. * Fix. * Fix test. * Fix win32 compile error. * Add more builtin input/output and texture intrinsics. * Add struct/array constructor syntax. * Skip `#extension` lines. * overide operator * for matrix/vector multiplication. * Add `matrixCompMult`. * Parse modifiers in for loop init var declr. * Add more glsl intrinsics, add stage into to var layout. * Allow `int[3] x` syntax. * Fix array type syntax. --------- Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com> Co-authored-by: Yong He <yhe@nvidia.com>
* Various SPIRV fixes. (#3231)Yong He2023-09-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Various SPIRV fixes. - Geometry shader support (WIP). - Fix texture get dimension and load. - Fold global GetElement(MakeArray/MakeVector) insts. - Call spvopt to inline all functions. - Translate OpImageSubscript. - Emit struct member names and global variable names. - Fix lowering of OpBitNot -> OpNot, instead of OpBitReverse. * Fix test. * Fix geometry shader. * Fix geometry shader emit. * Add atomic Image access test. * Fix tests. * don't fail if spirv-opt fails. * Update comments. * Fix test. * Cleanups. * indentation --------- Co-authored-by: Yong He <yhe@nvidia.com> Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
* Misc SPIRV fixes. (#3220)Yong He2023-09-21
| | | Co-authored-by: Yong He <yhe@nvidia.com>
* Update prebuilt glslang binaries (#3189)Yong He2023-09-06
| | | | | | | | | | | * Update prebuilt glslang binaries * Add test for GL_EXT_texture_shadow_lod functions. * fix --------- Co-authored-by: Yong He <yhe@nvidia.com>
* SPIR-V image operations (#3163)Ellie Hermaszewska2023-09-05
* Add __truncate and __sampledType for spirv_asm Allows some texture tests to start passing * add __isVector Currently unused * Add 1-vector legalization pass (WIP) * Add capabilities for image types * neaten instruction dumping * add 1-vector test * Add a couple of cases to vec1 legalization * Remove texture tests from expected failures * comment * regenerate vs projects * Remove redundant define form synchapi emulation * refactoring image methods * All sample functions refactored * Remove incorrect glsl intrinsics Partially addresses https://github.com/shader-slang/slang/issues/3174 * __subscript image ops via writing funcs * Extract texture struct writing from core.meta.slang * Abstract out cuda intrinsic * Remvoe erroneous call to opDecorateIndex * spirv asm IR utils * Correct position of loads for SPIR-V asm inst operands * Raise constructors to global scope during spir-v legalization * Correct snippet output * Implement most texture sampling ops for SPIR-V * Legalize 1-vectors for glsl too * Make SPIR-V inst operands non-hoistable * Better 1-vector legalization * Put textures in ptrs for spirv * insert missing break * Add vec1 legalization test * Add some missing pieces to slang-ir-insts * Greatly neaten vec1 legalization * a * Neaten vec1 legalization * Add image read and write intrinsics for spir-v * Squash warnings * regenerate vs projects * Drop redundant guards * Drop 5 tests from expected failure list * Inst numbering changes to cross compile tests * vec1 legalization tests only on vk * Correct location of asm op emit * Inline constant in spirv-asm * Correct signedness for lane in wave intrinsics * Extract element from float1 for cuda * squash warnings * Neaten spirv-emit * dedupe more capabilities * warnings * neaten assert * comments * comments