https://github.com/shader-slang/slang
Revision a88a7db9b3c215be890d4a9da6414959f9f9a3c1 authored by Jay Kwak on 06 February 2024, 01:03:04 UTC, committed by GitHub on 06 February 2024, 01:03:04 UTC
* 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>
1 parent 71439f7
History
Tip revision: a88a7db9b3c215be890d4a9da6414959f9f9a3c1 authored by Jay Kwak on 06 February 2024, 01:03:04 UTC
Implement GLSL build-in functions related to texture (#3544)
Tip revision: a88a7db
File Mode Size
.github
build
cmake
deps
docs
examples
external
extras
prelude
source
tests
tools
.editorconfig -rw-r--r-- 984 bytes
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 1.5 KB
.gitmodules -rw-r--r-- 1.2 KB
.mailmap -rw-r--r-- 84 bytes
CMakeLists.txt -rw-r--r-- 19.3 KB
CMakePresets.json -rw-r--r-- 4.0 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
CONTRIBUTION.md -rw-r--r-- 10.0 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 7.3 KB
github_build.sh -rw-r--r-- 1.3 KB
github_macos_build.sh -rw-r--r-- 1.2 KB
github_test.sh -rw-r--r-- 1.1 KB
make-slang-tag-version.bat -rw-r--r-- 210 bytes
premake.bat -rw-r--r-- 120 bytes
premake5.lua -rw-r--r-- 65.4 KB
slang-com-helper.h -rw-r--r-- 4.9 KB
slang-com-ptr.h -rw-r--r-- 5.0 KB
slang-gfx.h -rw-r--r-- 87.3 KB
slang-tag-version.h -rw-r--r-- 36 bytes
slang.h -rw-r--r-- 197.3 KB
slang.sln -rw-r--r-- 51.5 KB
test.bat -rw-r--r-- 1.4 KB
test.ps1 -rw-r--r-- 154 bytes

README.md

back to top