Skip to content
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

Set the HLSL supported compiler version to 2018 #6502

Merged
merged 3 commits into from
Mar 12, 2025

Conversation

zlatinski
Copy link
Contributor

@zlatinski zlatinski commented Mar 1, 2025

Set the HLSL-supported compiler version to 2018

Fixes #6462

The compiler is already supporting the new HLSL 2021 features, such as:

Slang is already enforcing ternary operator behavior
Slang supports HLSL 2021 features like select()

However, SLANG does not support templates. So we are rolling back the version to 2018.

// Test file with HLSL 2021 compliant code

// Simple entry point
float4 main() : SV_Target0
{
    // HLSL 2021 compliant example
    float4 a = float4(1.0, 2.0, 3.0, 4.0);
    float3 b = float3(5.0, 6.0, 7.0);
    bool condition = true;
    
    // This is valid in HLSL 2021 - explicit conversion
    float4 result = condition ? a : float4(b, 1.0);
    
    return result;
}
// Test file using HLSL 2021 select() function

// Simple entry point
float4 main() : SV_Target0
{
    float2 v = float2(0.5, -0.3);
    
    // Using select() function (HLSL 2021 style)
    float2 result = (1.0 - abs(v.yx)) * select(v.xy >= 0.0, 1.0, -1.0);
    
    return float4(result, 0.0, 1.0);
}
// Test file to check HLSL 2021 conditional operator behavior

// Simple entry point
float4 main() : SV_Target0
{
    // Pre-HLSL 2021 behavior example
    float4 a = float4(1.0, 2.0, 3.0, 4.0);
    float3 b = float3(5.0, 6.0, 7.0);
    bool condition = true;
    
    // This would work in pre-2021 HLSL but fail in HLSL 2021
    // (implicit conversion from float3 to float4)
    float4 result = condition ? a : b;
    
    return result;
}

@zlatinski zlatinski requested a review from a team as a code owner March 1, 2025 01:45
@zlatinski zlatinski added the pr: non-breaking PRs without breaking changes label Mar 1, 2025
@zlatinski
Copy link
Contributor Author

Fixes #6462

@zlatinski zlatinski force-pushed the hlsl/hlsl-set-supported-versio-to-2021 branch from 3a2be61 to 0cf7420 Compare March 3, 2025 16:58
@zlatinski zlatinski changed the title Set the HLSL supported compiler version to 2021 Set the HLSL supported compiler version to 2018 Mar 3, 2025
@zlatinski zlatinski force-pushed the hlsl/hlsl-set-supported-versio-to-2021 branch from 0cf7420 to c70b551 Compare March 3, 2025 17:34
@zlatinski zlatinski force-pushed the hlsl/hlsl-set-supported-versio-to-2021 branch from c70b551 to d57b580 Compare March 4, 2025 19:10
@jkwak-work
Copy link
Collaborator

Wouldn't this PR conflict with the PR 6445?

I am going to submit 6445 this week; if not today.

@zlatinski
Copy link
Contributor Author

zlatinski commented Mar 5, 2025

Wouldn't this PR conflict with the PR 6445?

I am going to submit 6445 this week; if not today.

Maybe? There was a big discussion about the HLSL version supported in SLANG.

csyonghe, do you want to comment on that?

@csyonghe
Copy link
Collaborator

csyonghe commented Mar 6, 2025

These are two different things.

  1. What should we #define HLSL_VERSION to the input HLSL code to Slang? -- Should be 2018.
  2. What is the version of the HLSL code the Slang outputs? It is 2021, so we should pass -HV2021 when compiling the output HLSL code through DXC.

Copy link
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Another PR of mine is not going to make it any time soon.
#6445

@zlatinski zlatinski merged commit 133d705 into master Mar 12, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HLSL sets __HLSL_VERSION to invalid version
3 participants