Skip to content

Implement the EvaluateAttributeSnapped HLSL Function #99111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
9 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 0 comments
Open
9 tasks
Tracked by #99235

Implement the EvaluateAttributeSnapped HLSL Function #99111

farzonl opened this issue Jul 16, 2024 · 0 comments
Labels
backend:DirectX bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • Implement EvaluateAttributeSnapped clang builtin,
  • Link EvaluateAttributeSnapped clang builtin with hlsl_intrinsics.h
  • Add sema checks for EvaluateAttributeSnapped to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for EvaluateAttributeSnapped to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/EvaluateAttributeSnapped.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/EvaluateAttributeSnapped-errors.hlsl
  • Create the int_dx_EvaluateAttributeSnapped intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_EvaluateAttributeSnapped to 87 in DXIL.td
  • Create the EvaluateAttributeSnapped.ll and EvaluateAttributeSnapped_errors.ll tests in llvm/test/CodeGen/DirectX/

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
87 EvalSnapped 6.0 ('pixel',)

SPIR-V

There is no support for EvaluateAttributeSnapped when targeting SPIR-V.

Test Case(s)

Example 1

//dxc EvaluateAttributeSnapped_test.hlsl -T lib_6_8 -enable-16bit-types -O0

[numthreads(1, 1, 1)]
[shader("pixel")]
float4 fn(float4 p1 : COLOR ) : SV_Target {
	int2 p2;
	return EvaluateAttributeSnapped(p1, p2);
}

HLSL:

Evaluates at the pixel centroid with an offset.

Syntax

numeric EvaluateAttributeSnapped(
  in attrib numeric value,
  in 
            int2 offset
);

Parameters

value [in]

Type: attrib numeric

The input value.

offset [in]

Type: int2

A 2D offset from the pixel center using a 16x16 grid.

Remarks

The range for the offset parameter must be defined by the following byte code.

Only the least significant 4 bits of the first two components (U, V) of the pixel offset are used. The conversion from the 4-bit fixed point to float is as follows (MSB...LSB), where the MSB is both a part of the fraction and determines the sign:

  • 1000 = -0.5f (-8 / 16)
  • 1001 = -0.4375f (-7 / 16)
  • 1010 = -0.375f (-6 / 16)
  • 1011 = -0.3125f (-5 / 16)
  • 1100 = -0.25f (-4 / 16)
  • 1101 = -0.1875f (-3 / 16)
  • 1110 = -0.125f (-2 / 16)
  • 1111 = -0.0625f (-1 / 16)
  • 0000 = 0.0f ( 0 / 16)
  • 0001 = 0.0625f ( 1 / 16)
  • 0010 = 0.125f ( 2 / 16)
  • 0011 = 0.1875f ( 3 / 16)
  • 0100 = 0.25f ( 4 / 16)
  • 0101 = 0.3125f ( 5 / 16)
  • 0110 = 0.375f ( 6 / 16)
  • 0111 = 0.4375f ( 7 / 16)

Note

The left and top edges of a pixel are included in the offset; however, the bottom and right edges are not included. All other bits in the 32-bit integer U and V offset values are ignored.

 

An implementation can take the offset provided by the shader and obtain a full 32-bit fixed point value (28.4), which spans the valid range, by performing the following calculation:

iU = (iU<<28)>>28  // keep lowest 4 bits and sign extend, which yields [-8..7]

If an implementation must map the offset to a floating-point offset, it performs the following calculation:

fU = ((float)iU)/16

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 5 and higher shader models yes

 

This function is supported in the following types of shaders:

Vertex Hull Domain Geometry Pixel Compute
x

 

See also

Intrinsic Functions

Shader Model 5

@farzonl farzonl added backend:DirectX bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Jul 16, 2024
@damyanp damyanp moved this to Ready in HLSL Support Oct 30, 2024
@damyanp damyanp moved this from Ready to Planning in HLSL Support Oct 30, 2024
@pow2clk pow2clk moved this from Planning to Designing in HLSL Support Nov 19, 2024
@damyanp damyanp removed the status in HLSL Support Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: No status
Development

No branches or pull requests

1 participant