From 4f93a92ac086fdde2e45a69fb7a88e94e61866db Mon Sep 17 00:00:00 2001 From: "lukas.taparauskas" Date: Fri, 28 Feb 2020 10:10:35 +0200 Subject: [PATCH 1/7] Add initial changes for SRP compatibility with the DXC compiler --- .../ShaderLibrary/Common.hlsl | 39 +++++++++++++++++++ .../ShaderLibrary/UnityInstancing.hlsl | 15 ++++++- .../Material/Decal/DecalUtilities.hlsl | 4 +- .../Runtime/Material/Lit/Lit.hlsl | 4 +- .../ShaderLibrary/MetaInput.hlsl | 5 +-- .../Shaders/Nature/SpeedTree7Input.hlsl | 7 ++-- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl index 52c4e5392b6..09e7e5a5730 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl @@ -663,6 +663,45 @@ uint GetMipCount(Texture2D tex) // ---------------------------------------------------------------------------- // Texture format sampling // ---------------------------------------------------------------------------- +#if defined(UNITY_COMPILER_DXC) && !defined(DXC_SAMPLER_COMPATIBILITY) +#define DXC_SAMPLER_COMPATIBILITY 1 +struct sampler1D { Texture1D t; SamplerState s; }; +struct sampler2D { Texture2D t; SamplerState s; }; +struct sampler3D { Texture3D t; SamplerState s; }; +struct samplerCUBE { TextureCube t; SamplerState s; }; + +float4 tex1D(sampler1D x, float v) { return x.t.Sample(x.s, v); } +float4 tex2D(sampler2D x, float2 v) { return x.t.Sample(x.s, v); } +float4 tex3D(sampler3D x, float3 v) { return x.t.Sample(x.s, v); } +float4 texCUBE(samplerCUBE x, float3 v) { return x.t.Sample(x.s, v); } + +float4 tex1Dbias(sampler1D x, in float4 t) { return x.t.SampleBias(x.s, t.x, t.w); } +float4 tex2Dbias(sampler2D x, in float4 t) { return x.t.SampleBias(x.s, t.xy, t.w); } +float4 tex3Dbias(sampler3D x, in float4 t) { return x.t.SampleBias(x.s, t.xyz, t.w); } +float4 texCUBEbias(samplerCUBE x, in float4 t) { return x.t.SampleBias(x.s, t.xyz, t.w); } + +float4 tex1Dlod(sampler1D x, in float4 t) { return x.t.SampleLevel(x.s, t.x, t.w); } +float4 tex2Dlod(sampler2D x, in float4 t) { return x.t.SampleLevel(x.s, t.xy, t.w); } +float4 tex3Dlod(sampler3D x, in float4 t) { return x.t.SampleLevel(x.s, t.xyz, t.w); } +float4 texCUBElod(samplerCUBE x, in float4 t) { return x.t.SampleLevel(x.s, t.xyz, t.w); } + +float4 tex1Dgrad(sampler1D x, float t, float dx, float dy) { return x.t.SampleGrad(x.s, t, dx, dy); } +float4 tex2Dgrad(sampler2D x, float2 t, float2 dx, float2 dy) { return x.t.SampleGrad(x.s, t, dx, dy); } +float4 tex3Dgrad(sampler3D x, float3 t, float3 dx, float3 dy) { return x.t.SampleGrad(x.s, t, dx, dy); } +float4 texCUBEgrad(samplerCUBE x, float3 t, float3 dx, float3 dy) { return x.t.SampleGrad(x.s, t, dx, dy); } + +float4 tex1D(sampler1D x, float t, float dx, float dy) { return x.t.SampleGrad(x.s, t, dx, dy); } +float4 tex2D(sampler2D x, float2 t, float2 dx, float2 dy) { return x.t.SampleGrad(x.s, t, dx, dy); } +float4 tex3D(sampler3D x, float3 t, float3 dx, float3 dy) { return x.t.SampleGrad(x.s, t, dx, dy); } +float4 texCUBE(samplerCUBE x, float3 t, float3 dx, float3 dy) { return x.t.SampleGrad(x.s, t, dx, dy); } + +float4 tex1Dproj(sampler1D s, in float2 t) { return tex1D(s, t.x / t.y); } +float4 tex1Dproj(sampler1D s, in float4 t) { return tex1D(s, t.x / t.w); } +float4 tex2Dproj(sampler2D s, in float3 t) { return tex2D(s, t.xy / t.z); } +float4 tex2Dproj(sampler2D s, in float4 t) { return tex2D(s, t.xy / t.w); } +float4 tex3Dproj(sampler3D s, in float4 t) { return tex3D(s, t.xyz / t.w); } +float4 texCUBEproj(samplerCUBE s, in float4 t) { return texCUBE(s, t.xyz / t.w); } +#endif float2 DirectionToLatLongCoordinate(float3 unDir) { diff --git a/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl index 7b45891f2dc..a4f7c2435c0 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl @@ -335,10 +335,21 @@ #define CALL_MERGE_UNITY_BUILTINS_INDEX(X) MERGE_UNITY_BUILTINS_INDEX(X) #ifdef MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING #define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray)) - #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray)) + //#define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray)) + #ifdef UNITY_ASSUME_UNIFORM_SCALING + #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_WorldToObjectArray)) + #else + #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_WorldToObjectArray)) + #endif #else #define UNITY_MATRIX_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray) - #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray) + + //#define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray) + #ifdef UNITY_ASSUME_UNIFORM_SCALING + #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_WorldToObjectArray) + #else + #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_WorldToObjectArray) + #endif #endif #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl index dfea286cb2d..be2bdb5cbeb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl @@ -204,7 +204,7 @@ DecalSurfaceData GetDecalSurfaceData(PositionInputs posInput, inout float alpha) { uint mask = 0; // the code in the macros, gets moved inside the conditionals by the compiler - FETCH_DBUFFER(DBuffer, _DBufferTexture, posInput.positionSS); + FETCH_DBUFFER(DBuffer, _DBufferTexture, int2(posInput.positionSS.xy)); #if defined(_SURFACE_TYPE_TRANSPARENT) && defined(HAS_LIGHTLOOP) // forward transparent using clustered decals uint decalCount, decalStart; @@ -258,7 +258,7 @@ DecalSurfaceData GetDecalSurfaceData(PositionInputs posInput, inout float alpha) if (!fastPath) { - // If we are not in fast path, v_lightIdx is not scalar, so we need to query the Min value across the wave. + // If we are not in fast path, v_lightIdx is not scalar, so we need to query the Min value across the wave. s_decalIdx = WaveActiveMin(v_decalIdx); // If WaveActiveMin returns 0xffffffff it means that all lanes are actually dead, so we can safely ignore the loop and move forward. // This could happen as an helper lane could reach this point, hence having a valid v_lightIdx, but their values will be ignored by the WaveActiveMin diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index d4dcfc77194..86b06e81b5b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -1773,9 +1773,9 @@ IndirectLighting EvaluateBSDF_ScreenspaceRefraction(LightLoopContext lightLoopCo refractionOffsetMultiplier *= (hitLinearDepth > posInput.linearDepth); float2 samplingPositionNDC = lerp(posInput.positionNDC, hit.positionNDC, refractionOffsetMultiplier); - float3 preLD = SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, - // Offset by half a texel to properly interpolate between this pixel and its mips + float3 preLD = SAMPLE_TEXTURE2D_X_LOD(_ColorPyramidTexture, s_trilinear_clamp_sampler, \ samplingPositionNDC * _ColorPyramidScale.xy, preLightData.transparentSSMipLevel).rgb; + // Offset by half a texel to properly interpolate between this pixel and its mips // Inverse pre-exposure preLD *= GetInverseCurrentExposureMultiplier(); diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl index 53f39c98818..e03ccd3e8e9 100644 --- a/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl +++ b/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl @@ -51,11 +51,8 @@ half4 MetaFragment(MetaInput input) { res = half4(input.Albedo, 1.0); - // d3d9 shader compiler doesn't like NaNs and infinity. - unity_OneOverOutputBoost = saturate(unity_OneOverOutputBoost); - // Apply Albedo Boost from LightmapSettings. - res.rgb = clamp(PositivePow(res.rgb, unity_OneOverOutputBoost), 0, unity_MaxOutputValue); + res.rgb = clamp(PositivePow(res.rgb, saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue); } if (unity_MetaFragmentControl.y) { diff --git a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Input.hlsl b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Input.hlsl index 7331734767a..84b4ac56537 100644 --- a/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Input.hlsl +++ b/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree7Input.hlsl @@ -7,9 +7,6 @@ #define GEOM_TYPE_BRANCH #endif -#ifdef GEOM_TYPE_BRANCH_DETAIL - sampler2D _DetailTex; -#endif #if defined(GEOM_TYPE_FROND) || defined(GEOM_TYPE_LEAF) || defined(GEOM_TYPE_FACING_LEAF) #define SPEEDTREE_ALPHATEST @@ -23,4 +20,8 @@ #include "SpeedTree7CommonInput.hlsl" +#ifdef GEOM_TYPE_BRANCH_DETAIL + sampler2D _DetailTex; +#endif + #endif From 3a82f4a15cf597a0d6f8ee579509624a974c4c0b Mon Sep 17 00:00:00 2001 From: "lukas.taparauskas" Date: Wed, 4 Mar 2020 13:50:36 +0200 Subject: [PATCH 2/7] Add missing explicit binding specifications for UAVs used from PS. Undo involved preprocessor macro fix. *Add explicit binding specifiers for UAVs used from pixel shadersx. This is needed to avoid binding index inconsistencies between SM 5.0 (our FXC use) and SM 5.1. (we want DXC as it can target SM > 5.0 in the first place) *Remove compex macro change to avoid potentially introducing new bugs as this is an issue with the new preprocessor and not DXC which can work around it with the -flegacy-macro-expansion flag. --- .../ShaderLibrary/UnityInstancing.hlsl | 15 ++------------- .../Material/Decal/ShaderVariablesDecal.hlsl | 2 +- .../Shaders/TemporalAntiAliasing.shader | 2 +- .../ShaderLibrary/ResolveStencilBuffer.compute | 6 +++++- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl index a4f7c2435c0..7b45891f2dc 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl @@ -335,21 +335,10 @@ #define CALL_MERGE_UNITY_BUILTINS_INDEX(X) MERGE_UNITY_BUILTINS_INDEX(X) #ifdef MODIFY_MATRIX_FOR_CAMERA_RELATIVE_RENDERING #define UNITY_MATRIX_M ApplyCameraTranslationToMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray)) - //#define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray)) - #ifdef UNITY_ASSUME_UNIFORM_SCALING - #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_WorldToObjectArray)) - #else - #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_WorldToObjectArray)) - #endif + #define UNITY_MATRIX_I_M ApplyCameraTranslationToInverseMatrix(UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray)) #else #define UNITY_MATRIX_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_ObjectToWorldArray) - - //#define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray) - #ifdef UNITY_ASSUME_UNIFORM_SCALING - #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins1, unity_WorldToObjectArray) - #else - #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(unity_Builtins0, unity_WorldToObjectArray) - #endif + #define UNITY_MATRIX_I_M UNITY_ACCESS_INSTANCED_PROP(CALL_MERGE_UNITY_BUILTINS_INDEX(UNITY_WORLDTOOBJECTARRAY_CB), unity_WorldToObjectArray) #endif #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/ShaderVariablesDecal.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/ShaderVariablesDecal.hlsl index d5210169a42..de886e269cc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/ShaderVariablesDecal.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/ShaderVariablesDecal.hlsl @@ -10,7 +10,7 @@ TEXTURE2D(_DecalAtlas2D); SAMPLER(_trilinear_clamp_sampler_DecalAtlas2D); #ifdef PLATFORM_SUPPORTS_BUFFER_ATOMICS_IN_PIXEL_SHADER -RWStructuredBuffer _DecalPropertyMaskBuffer; +RWStructuredBuffer _DecalPropertyMaskBuffer : register(u4); StructuredBuffer _DecalPropertyMaskBufferSRV; #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntiAliasing.shader b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntiAliasing.shader index 9ed2596df37..ea7855f28ea 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntiAliasing.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/TemporalAntiAliasing.shader @@ -23,7 +23,7 @@ Shader "Hidden/HDRP/TemporalAntialiasing" TEXTURE2D_X(_InputTexture); TEXTURE2D_X(_InputHistoryTexture); - RW_TEXTURE2D_X(CTYPE, _OutputHistoryTexture); + RW_TEXTURE2D_X(CTYPE, _OutputHistoryTexture) : register(u1); struct Attributes { diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ResolveStencilBuffer.compute b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ResolveStencilBuffer.compute index 7069861cd18..eb9e38be74f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ResolveStencilBuffer.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ResolveStencilBuffer.compute @@ -84,9 +84,13 @@ void KERNEL_NAME(uint3 groupId : SV_GroupID, #endif + //This temp is needed outside the if(isFirstThread) condition to workaround a DXC DXIL codegen + // issue https://github.com/microsoft/DirectXShaderCompiler/issues/2743 until it's fixed + uint perThreadCoarseStencilValue = coarseStencilValue; + if (isFirstThread) { uint addressIndex = Get1DAddressFromPixelCoord(groupId.xy, _CoarseStencilBufferSize.xy, groupId.z); - _CoarseStencilBuffer[addressIndex] = coarseStencilValue; + _CoarseStencilBuffer[addressIndex] = perThreadCoarseStencilValue; } } From e6c9169315d88b27b6b8810c41c9558266b33f50 Mon Sep 17 00:00:00 2001 From: "lukas.taparauskas" Date: Fri, 20 Mar 2020 09:25:41 +0200 Subject: [PATCH 3/7] Fix more DXC specific issues visible in HDRP_Tests project. --- .../2004_AnimatedCookie/AnimatedCookie_Shader2.shader | 2 +- .../Runtime/Debug/DebugFullScreen.shader | 5 +++++ .../Runtime/ShaderLibrary/TextureXR.hlsl | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader2.shader b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader2.shader index 55d73c551bf..a5b406d3613 100644 --- a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader2.shader +++ b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader2.shader @@ -129,7 +129,7 @@ Shader "HDRenderPipeline/GraphicTests/2004_AnimatedCookie_AnimMat2" if (_StarsAnim[frame*STAR_COL*STAR_ROW + uv.y*STAR_ROW +uv.x]) c = 1; } - float4 frag(v2f_customrendertexture IN) : COLOR + float4 frag(v2f_customrendertexture IN) : SV_Target { float4 c = float4(12.0/255.0, 65.0/255.0, 121.0/255.0, 1); // background color diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader index f5bfaf2b24b..c1d8cfa1b77 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader @@ -241,6 +241,11 @@ Shader "Hidden/HDRP/DebugFullScreen" d = 1.0 - saturate(d); } + // Explicitly handling the case where mv == float2(0, 0) as atan2(mv.x, mv.y) above would be atan2(0,0) which + // is undefined and in practice can be incosistent between compilers (e.g. NaN on FXC and ~pi/2 on DXC) + if(!any(mv)) + color = float3(0, 0, 0); + return float4(color + d.xxx, 1.0); } if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_COLOR_LOG) diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl index 90a58f909ab..195af360dc2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl @@ -63,7 +63,7 @@ #define TEXTURE2D_X_UINT(textureName) Texture2DArray textureName #define TEXTURE2D_X_UINT2(textureName) Texture2DArray textureName #define TEXTURE2D_X_UINT4(textureName) Texture2DArray textureName - #define TEXTURE2D_X_MSAA(type, textureName) Texture2DMSArray textureName + #define TEXTURE2D_X_MSAA(type, textureName) Texture2DMSArray textureName #define RW_TEXTURE2D_X(type, textureName) RW_TEXTURE2D_ARRAY(type, textureName) #define LOAD_TEXTURE2D_X(textureName, unCoord2) LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, SLICE_ARRAY_INDEX) @@ -90,7 +90,7 @@ #define TEXTURE2D_X_UINT(textureName) Texture2D textureName #define TEXTURE2D_X_UINT2(textureName) Texture2D textureName #define TEXTURE2D_X_UINT4(textureName) Texture2D textureName - #define TEXTURE2D_X_MSAA(type, textureName) Texture2DMS textureName + #define TEXTURE2D_X_MSAA(type, textureName) Texture2DMS textureName #define RW_TEXTURE2D_X RW_TEXTURE2D #define LOAD_TEXTURE2D_X LOAD_TEXTURE2D From 3eec249c03acbf8acf74237bf2a3331e164bc163 Mon Sep 17 00:00:00 2001 From: "lukas.taparauskas" Date: Fri, 20 Mar 2020 12:36:01 +0200 Subject: [PATCH 4/7] Disable wave intrinsic usage errors when compiling with DXC --- com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl index 09e7e5a5730..9e17d37de64 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl @@ -197,8 +197,8 @@ #define LODDitheringTransition ERROR_ON_UNSUPPORTED_FUNCTION(LODDitheringTransition) #endif -// On everything but GCN consoles we error on cross-lane operations -#ifndef PLATFORM_SUPPORTS_WAVE_INTRINSICS +// On everything but GCN consoles or DXC compiled shaders we error on cross-lane operations +#if !defined(PLATFORM_SUPPORTS_WAVE_INTRINSICS) && !defined(UNITY_COMPILER_DXC) #define WaveActiveAllTrue ERROR_ON_UNSUPPORTED_FUNCTION(WaveActiveAllTrue) #define WaveActiveAnyTrue ERROR_ON_UNSUPPORTED_FUNCTION(WaveActiveAnyTrue) #define WaveGetLaneIndex ERROR_ON_UNSUPPORTED_FUNCTION(WaveGetLaneIndex) From 86431ebe275b3410a7a01f6dda274757f46f3c93 Mon Sep 17 00:00:00 2001 From: "lukas.taparauskas" Date: Fri, 20 Mar 2020 13:08:53 +0200 Subject: [PATCH 5/7] Updated CHANGELOG.md files --- com.unity.render-pipelines.core/CHANGELOG.md | 1 + com.unity.render-pipelines.high-definition/CHANGELOG.md | 2 ++ com.unity.render-pipelines.universal/CHANGELOG.md | 1 + 3 files changed, 4 insertions(+) diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index 2b8ebeae595..3ee326d8bc6 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Replaced calls to deprecated PlayerSettings.virtualRealitySupported property. - Enable RWTexture2D, RWTexture2DArray, RWTexture3D in gles 3.1 - Updated macros to be compatible with the new shader preprocessor. +- Updated shaders to be compatible with Microsoft's DXC. ## [7.1.1] - 2019-09-05 diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index ad4590227f9..f6ef9f373fb 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -407,6 +407,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed an issue with MipRatio debug mode showing _DebugMatCapTexture not being set. - Fixed missing initialization of input params in Blit for VR. - Fix Inf source in LTC for area lights. +- Fixed reliance on atan2 undefined behavior in motion vector debug shader. ### Changed - Color buffer pyramid is not allocated anymore if neither refraction nor distortion are enabled @@ -491,6 +492,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Transform result from CIE XYZ to sRGB color space in EvalSensitivity for iridescence. - Hide the Probes section in the Renderer editos because it was unused. - Moved BeginCameraRendering callback right before culling. +- Updated shaders to be compatible with Microsoft's DXC. ## [7.1.1] - 2019-09-05 diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 4b81774345f..80eb9be4522 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Made MaterialDescriptionPreprocessors private. - UniversalRenderPipelineAsset no longer supports presets [case 1197020](https://issuetracker.unity3d.com/issues/urp-reset-functionality-does-not-work-on-preset-of-universalrenderpipelineassets) - The number of maximum visible lights is now determined by whether the platform is mobile or not. +- Updated shaders to be compatible with Microsoft's DXC. ### Fixed - Fixed an issue where linear to sRGB conversion occurred twice on certain Android devices. From 46d9d141db8fe367541c7c9acde55dfc1b08920c Mon Sep 17 00:00:00 2001 From: "lukas.taparauskas" Date: Sat, 21 Mar 2020 13:49:22 +0200 Subject: [PATCH 6/7] Replace all uses of COLOR semantic with SV_Target in pixel shader outputs --- .../2004_AnimatedCookie/AnimatedCookie_Shader.shader | 2 +- .../Editor/LookDev/Compositor.shader | 6 +++--- .../Editor/LookDev/CubeToLatlong.shader | 2 +- com.unity.shadergraph/CHANGELOG.md | 1 + .../Editor/Resources/Shaders/Checkerboard.shader | 2 +- com.unity.testing.hdrp/Shaders/DistordFromTex.shader | 2 +- com.unity.testing.hdrp/Shaders/DistordTest.shader | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader.shader b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader.shader index bcf1df8c83f..404192adb0e 100644 --- a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader.shader +++ b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader.shader @@ -22,7 +22,7 @@ Shader "HDRenderPipeline/GraphicTests/2004_AnimatedCookie_AnimMat" float4 _Color; sampler2D _Tex; - float4 frag(v2f_customrendertexture IN) : COLOR + float4 frag(v2f_customrendertexture IN) : SV_Target { float f = _Time.y % 3; diff --git a/com.unity.render-pipelines.core/Editor/LookDev/Compositor.shader b/com.unity.render-pipelines.core/Editor/LookDev/Compositor.shader index 9bece36d382..82eee388d92 100644 --- a/com.unity.render-pipelines.core/Editor/LookDev/Compositor.shader +++ b/com.unity.render-pipelines.core/Editor/LookDev/Compositor.shader @@ -391,7 +391,7 @@ Shader "Hidden/LookDev/Compositor" #pragma target 3.0 float4 frag(float2 texcoord : TEXCOORD0, - UNITY_VPOS_TYPE vpos : VPOS) : COLOR + UNITY_VPOS_TYPE vpos : VPOS) : SV_Target { float4 color = float4(ComputeColor(_Tex0MainView, _Tex0Shadows, ShadowMultiplier0, _ShadowColor0, texcoord) * exp2(ExposureValue1), 1.0); color.rgb = ApplyToneMap(color.rgb); @@ -409,7 +409,7 @@ Shader "Hidden/LookDev/Compositor" #pragma target 3.0 float4 frag(float2 texcoord : TEXCOORD0, - UNITY_VPOS_TYPE vpos : VPOS) : COLOR + UNITY_VPOS_TYPE vpos : VPOS) : SV_Target { float4 color = float4(ComputeColor(_Tex1MainView, _Tex1Shadows, ShadowMultiplier1, _ShadowColor1, texcoord) * exp2(ExposureValue2), 1.0); color.rgb = ApplyToneMap(color.rgb); @@ -427,7 +427,7 @@ Shader "Hidden/LookDev/Compositor" #pragma target 3.0 float4 frag(float2 texcoord : TEXCOORD0, - UNITY_VPOS_TYPE vpos : VPOS) : COLOR + UNITY_VPOS_TYPE vpos : VPOS) : SV_Target { float3 color1 = ComputeColor(_Tex0MainView, _Tex0Shadows, ShadowMultiplier0, _ShadowColor0, texcoord) * exp2(ExposureValue1); float3 color2 = ComputeColor(_Tex1MainView, _Tex1Shadows, ShadowMultiplier1, _ShadowColor1, texcoord) * exp2(ExposureValue2); diff --git a/com.unity.render-pipelines.core/Editor/LookDev/CubeToLatlong.shader b/com.unity.render-pipelines.core/Editor/LookDev/CubeToLatlong.shader index 4cbadcce9ca..7921a02520a 100644 --- a/com.unity.render-pipelines.core/Editor/LookDev/CubeToLatlong.shader +++ b/com.unity.render-pipelines.core/Editor/LookDev/CubeToLatlong.shader @@ -45,7 +45,7 @@ Shader "Hidden/LookDev/CubeToLatlong" float4 frag( float2 texcoord : TEXCOORD0, UNITY_VPOS_TYPE vpos : VPOS - ) : COLOR + ) : SV_Target { float2 texCoord = texcoord.xy; float theta = texCoord.y * UNITY_PI; diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index f714e56e7cc..beb9367779b 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Changed the `Branch` node so that it uses a ternary operator (`Out = bool ? a : B`) instead of a linear interpolate function. +- Updated legacy COLOR output semantic to SV_Target in pixel shader for compatibility with DXC ### Fixed - Edges no longer produce errors when you save a Shader Graph. diff --git a/com.unity.shadergraph/Editor/Resources/Shaders/Checkerboard.shader b/com.unity.shadergraph/Editor/Resources/Shaders/Checkerboard.shader index f5c457b2419..e090fbd9461 100644 --- a/com.unity.shadergraph/Editor/Resources/Shaders/Checkerboard.shader +++ b/com.unity.shadergraph/Editor/Resources/Shaders/Checkerboard.shader @@ -16,7 +16,7 @@ Shader "Hidden/Checkerboard" static const float rows = 24; static const float columns = 24; - float4 frag(v2f_img i) : COLOR + float4 frag(v2f_img i) : SV_Target { float3 col1 = float3(32.0/255.0, 32.0/255.0, 32.0/255.0); float3 col2 = float3(42.0/255.0, 42.0/255.0, 42.0/255.0); diff --git a/com.unity.testing.hdrp/Shaders/DistordFromTex.shader b/com.unity.testing.hdrp/Shaders/DistordFromTex.shader index 252e9b41165..7091ef3b490 100644 --- a/com.unity.testing.hdrp/Shaders/DistordFromTex.shader +++ b/com.unity.testing.hdrp/Shaders/DistordFromTex.shader @@ -22,7 +22,7 @@ Shader "Hidden/DistordFromTex" sampler2D _Tex; float _Scale, _Bias; - float4 frag(v2f_customrendertexture IN) : COLOR + float4 frag(v2f_customrendertexture IN) : SV_Target { float4 c = float4(0,0,0,0); diff --git a/com.unity.testing.hdrp/Shaders/DistordTest.shader b/com.unity.testing.hdrp/Shaders/DistordTest.shader index 9274bd908e0..8c90b129649 100644 --- a/com.unity.testing.hdrp/Shaders/DistordTest.shader +++ b/com.unity.testing.hdrp/Shaders/DistordTest.shader @@ -18,7 +18,7 @@ Shader "Hidden/DistordTest" #define CENTER 0.15 - float4 frag(v2f_customrendertexture IN) : COLOR + float4 frag(v2f_customrendertexture IN) : SV_Target { float4 col = float4(0,0,0,1); From 0f63ae679917d461a7a07772f573cdc7cde49265 Mon Sep 17 00:00:00 2001 From: "lukas.taparauskas" Date: Sat, 21 Mar 2020 15:54:00 +0200 Subject: [PATCH 7/7] Add comments explaning why certain changes were performed --- com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl | 3 +++ .../Runtime/ShaderLibrary/TextureXR.hlsl | 2 ++ 2 files changed, 5 insertions(+) diff --git a/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl b/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl index 9e17d37de64..5634fb9fb24 100644 --- a/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl +++ b/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl @@ -663,6 +663,9 @@ uint GetMipCount(Texture2D tex) // ---------------------------------------------------------------------------- // Texture format sampling // ---------------------------------------------------------------------------- + +// DXC no longer supports DX9-style HLSL syntax for sampler2D, tex2D and the like. +// These are emulated for backwards compatibilit using our own small structs and functions which manually combine samplers and textures. #if defined(UNITY_COMPILER_DXC) && !defined(DXC_SAMPLER_COMPATIBILITY) #define DXC_SAMPLER_COMPATIBILITY 1 struct sampler1D { Texture1D t; SamplerState s; }; diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl index 195af360dc2..4c8522d962b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl @@ -63,6 +63,7 @@ #define TEXTURE2D_X_UINT(textureName) Texture2DArray textureName #define TEXTURE2D_X_UINT2(textureName) Texture2DArray textureName #define TEXTURE2D_X_UINT4(textureName) Texture2DArray textureName + //Using explicit sample count of 1 to force DXC to actually reflect the texture as MS. The actual count appears to be irrelevant and any 2D MS texture array should bind to it #define TEXTURE2D_X_MSAA(type, textureName) Texture2DMSArray textureName #define RW_TEXTURE2D_X(type, textureName) RW_TEXTURE2D_ARRAY(type, textureName) @@ -90,6 +91,7 @@ #define TEXTURE2D_X_UINT(textureName) Texture2D textureName #define TEXTURE2D_X_UINT2(textureName) Texture2D textureName #define TEXTURE2D_X_UINT4(textureName) Texture2D textureName + //Using explicit sample count of 1 to force DXC to actually reflect the texture as MS. The actual count appears to be irrelevant and any 2D MS texture should bind to it #define TEXTURE2D_X_MSAA(type, textureName) Texture2DMS textureName #define RW_TEXTURE2D_X RW_TEXTURE2D