Skip to content

Commit f69c63c

Browse files
Dxc compatibility (#14)
* Add initial changes for SRP compatibility with the DXC compiler * 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. * Fix more DXC specific issues visible in HDRP_Tests project. * Disable wave intrinsic usage errors when compiling with DXC * Updated CHANGELOG.md files * Replace all uses of COLOR semantic with SV_Target in pixel shader outputs * Add comments explaning why certain changes were performed Co-authored-by: lukas.taparauskas <[email protected]> Co-authored-by: sebastienlagarde <[email protected]>
1 parent 3213af3 commit f69c63c

File tree

21 files changed

+83
-27
lines changed

21 files changed

+83
-27
lines changed

TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Shader "HDRenderPipeline/GraphicTests/2004_AnimatedCookie_AnimMat"
2222
float4 _Color;
2323
sampler2D _Tex;
2424

25-
float4 frag(v2f_customrendertexture IN) : COLOR
25+
float4 frag(v2f_customrendertexture IN) : SV_Target
2626
{
2727
float f = _Time.y % 3;
2828

TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/2x_Lighting/2004_AnimatedCookie/AnimatedCookie_Shader2.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Shader "HDRenderPipeline/GraphicTests/2004_AnimatedCookie_AnimMat2"
129129
if (_StarsAnim[frame*STAR_COL*STAR_ROW + uv.y*STAR_ROW +uv.x]) c = 1;
130130
}
131131

132-
float4 frag(v2f_customrendertexture IN) : COLOR
132+
float4 frag(v2f_customrendertexture IN) : SV_Target
133133
{
134134
float4 c = float4(12.0/255.0, 65.0/255.0, 121.0/255.0, 1); // background color
135135

com.unity.render-pipelines.core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4949
- Replaced calls to deprecated PlayerSettings.virtualRealitySupported property.
5050
- Enable RWTexture2D, RWTexture2DArray, RWTexture3D in gles 3.1
5151
- Updated macros to be compatible with the new shader preprocessor.
52+
- Updated shaders to be compatible with Microsoft's DXC.
5253

5354
## [7.1.1] - 2019-09-05
5455

com.unity.render-pipelines.core/Editor/LookDev/Compositor.shader

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ Shader "Hidden/LookDev/Compositor"
391391
#pragma target 3.0
392392

393393
float4 frag(float2 texcoord : TEXCOORD0,
394-
UNITY_VPOS_TYPE vpos : VPOS) : COLOR
394+
UNITY_VPOS_TYPE vpos : VPOS) : SV_Target
395395
{
396396
float4 color = float4(ComputeColor(_Tex0MainView, _Tex0Shadows, ShadowMultiplier0, _ShadowColor0, texcoord) * exp2(ExposureValue1), 1.0);
397397
color.rgb = ApplyToneMap(color.rgb);
@@ -409,7 +409,7 @@ Shader "Hidden/LookDev/Compositor"
409409
#pragma target 3.0
410410

411411
float4 frag(float2 texcoord : TEXCOORD0,
412-
UNITY_VPOS_TYPE vpos : VPOS) : COLOR
412+
UNITY_VPOS_TYPE vpos : VPOS) : SV_Target
413413
{
414414
float4 color = float4(ComputeColor(_Tex1MainView, _Tex1Shadows, ShadowMultiplier1, _ShadowColor1, texcoord) * exp2(ExposureValue2), 1.0);
415415
color.rgb = ApplyToneMap(color.rgb);
@@ -427,7 +427,7 @@ Shader "Hidden/LookDev/Compositor"
427427
#pragma target 3.0
428428

429429
float4 frag(float2 texcoord : TEXCOORD0,
430-
UNITY_VPOS_TYPE vpos : VPOS) : COLOR
430+
UNITY_VPOS_TYPE vpos : VPOS) : SV_Target
431431
{
432432
float3 color1 = ComputeColor(_Tex0MainView, _Tex0Shadows, ShadowMultiplier0, _ShadowColor0, texcoord) * exp2(ExposureValue1);
433433
float3 color2 = ComputeColor(_Tex1MainView, _Tex1Shadows, ShadowMultiplier1, _ShadowColor1, texcoord) * exp2(ExposureValue2);

com.unity.render-pipelines.core/Editor/LookDev/CubeToLatlong.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Shader "Hidden/LookDev/CubeToLatlong"
4545

4646
float4 frag( float2 texcoord : TEXCOORD0,
4747
UNITY_VPOS_TYPE vpos : VPOS
48-
) : COLOR
48+
) : SV_Target
4949
{
5050
float2 texCoord = texcoord.xy;
5151
float theta = texCoord.y * UNITY_PI;

com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@
199199
#define LODDitheringTransition ERROR_ON_UNSUPPORTED_FUNCTION(LODDitheringTransition)
200200
#endif
201201

202-
// On everything but GCN consoles we error on cross-lane operations
203-
#ifndef PLATFORM_SUPPORTS_WAVE_INTRINSICS
202+
// On everything but GCN consoles or DXC compiled shaders we error on cross-lane operations
203+
#if !defined(PLATFORM_SUPPORTS_WAVE_INTRINSICS) && !defined(UNITY_COMPILER_DXC)
204204
#define WaveActiveAllTrue ERROR_ON_UNSUPPORTED_FUNCTION(WaveActiveAllTrue)
205205
#define WaveActiveAnyTrue ERROR_ON_UNSUPPORTED_FUNCTION(WaveActiveAnyTrue)
206206
#define WaveGetLaneIndex ERROR_ON_UNSUPPORTED_FUNCTION(WaveGetLaneIndex)
@@ -701,6 +701,48 @@ uint GetMipCount(Texture2D tex)
701701
// Texture format sampling
702702
// ----------------------------------------------------------------------------
703703

704+
// DXC no longer supports DX9-style HLSL syntax for sampler2D, tex2D and the like.
705+
// These are emulated for backwards compatibilit using our own small structs and functions which manually combine samplers and textures.
706+
#if defined(UNITY_COMPILER_DXC) && !defined(DXC_SAMPLER_COMPATIBILITY)
707+
#define DXC_SAMPLER_COMPATIBILITY 1
708+
struct sampler1D { Texture1D t; SamplerState s; };
709+
struct sampler2D { Texture2D t; SamplerState s; };
710+
struct sampler3D { Texture3D t; SamplerState s; };
711+
struct samplerCUBE { TextureCube t; SamplerState s; };
712+
713+
float4 tex1D(sampler1D x, float v) { return x.t.Sample(x.s, v); }
714+
float4 tex2D(sampler2D x, float2 v) { return x.t.Sample(x.s, v); }
715+
float4 tex3D(sampler3D x, float3 v) { return x.t.Sample(x.s, v); }
716+
float4 texCUBE(samplerCUBE x, float3 v) { return x.t.Sample(x.s, v); }
717+
718+
float4 tex1Dbias(sampler1D x, in float4 t) { return x.t.SampleBias(x.s, t.x, t.w); }
719+
float4 tex2Dbias(sampler2D x, in float4 t) { return x.t.SampleBias(x.s, t.xy, t.w); }
720+
float4 tex3Dbias(sampler3D x, in float4 t) { return x.t.SampleBias(x.s, t.xyz, t.w); }
721+
float4 texCUBEbias(samplerCUBE x, in float4 t) { return x.t.SampleBias(x.s, t.xyz, t.w); }
722+
723+
float4 tex1Dlod(sampler1D x, in float4 t) { return x.t.SampleLevel(x.s, t.x, t.w); }
724+
float4 tex2Dlod(sampler2D x, in float4 t) { return x.t.SampleLevel(x.s, t.xy, t.w); }
725+
float4 tex3Dlod(sampler3D x, in float4 t) { return x.t.SampleLevel(x.s, t.xyz, t.w); }
726+
float4 texCUBElod(samplerCUBE x, in float4 t) { return x.t.SampleLevel(x.s, t.xyz, t.w); }
727+
728+
float4 tex1Dgrad(sampler1D x, float t, float dx, float dy) { return x.t.SampleGrad(x.s, t, dx, dy); }
729+
float4 tex2Dgrad(sampler2D x, float2 t, float2 dx, float2 dy) { return x.t.SampleGrad(x.s, t, dx, dy); }
730+
float4 tex3Dgrad(sampler3D x, float3 t, float3 dx, float3 dy) { return x.t.SampleGrad(x.s, t, dx, dy); }
731+
float4 texCUBEgrad(samplerCUBE x, float3 t, float3 dx, float3 dy) { return x.t.SampleGrad(x.s, t, dx, dy); }
732+
733+
float4 tex1D(sampler1D x, float t, float dx, float dy) { return x.t.SampleGrad(x.s, t, dx, dy); }
734+
float4 tex2D(sampler2D x, float2 t, float2 dx, float2 dy) { return x.t.SampleGrad(x.s, t, dx, dy); }
735+
float4 tex3D(sampler3D x, float3 t, float3 dx, float3 dy) { return x.t.SampleGrad(x.s, t, dx, dy); }
736+
float4 texCUBE(samplerCUBE x, float3 t, float3 dx, float3 dy) { return x.t.SampleGrad(x.s, t, dx, dy); }
737+
738+
float4 tex1Dproj(sampler1D s, in float2 t) { return tex1D(s, t.x / t.y); }
739+
float4 tex1Dproj(sampler1D s, in float4 t) { return tex1D(s, t.x / t.w); }
740+
float4 tex2Dproj(sampler2D s, in float3 t) { return tex2D(s, t.xy / t.z); }
741+
float4 tex2Dproj(sampler2D s, in float4 t) { return tex2D(s, t.xy / t.w); }
742+
float4 tex3Dproj(sampler3D s, in float4 t) { return tex3D(s, t.xyz / t.w); }
743+
float4 texCUBEproj(samplerCUBE s, in float4 t) { return texCUBE(s, t.xyz / t.w); }
744+
#endif
745+
704746
float2 DirectionToLatLongCoordinate(float3 unDir)
705747
{
706748
float3 dir = normalize(unDir);

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
506506
- Fix for issue that prevented scene from being completely saved when baked reflection probes are present and lighting is set to auto generate.
507507
- Fixed drag area width at left of Light's intensity field in Inspector.
508508
- Fixed light type resolution when performing a reset on HDAdditionalLightData (case 1220931)
509+
- Fixed reliance on atan2 undefined behavior in motion vector debug shader.
509510

510511
### Changed
511512
- Color buffer pyramid is not allocated anymore if neither refraction nor distortion are enabled
@@ -614,6 +615,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
614615
- Temporal Anti aliasing improvements.
615616
- Optimized PrepareLightsForGPU (cost reduced by over 25%) and PrepareGPULightData (around twice as fast now).
616617
- Moved scene view camera settings for HDRP from the preferences window to the scene view camera settings window.
618+
- Updated shaders to be compatible with Microsoft's DXC.
617619

618620
## [7.1.1] - 2019-09-05
619621

com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ Shader "Hidden/HDRP/DebugFullScreen"
241241
d = 1.0 - saturate(d);
242242
}
243243

244+
// Explicitly handling the case where mv == float2(0, 0) as atan2(mv.x, mv.y) above would be atan2(0,0) which
245+
// is undefined and in practice can be incosistent between compilers (e.g. NaN on FXC and ~pi/2 on DXC)
246+
if(!any(mv))
247+
color = float3(0, 0, 0);
248+
244249
return float4(color + d.xxx, 1.0);
245250
}
246251
if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_COLOR_LOG)

com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ DecalSurfaceData GetDecalSurfaceData(PositionInputs posInput, inout float alpha)
204204
{
205205
uint mask = 0;
206206
// the code in the macros, gets moved inside the conditionals by the compiler
207-
FETCH_DBUFFER(DBuffer, _DBufferTexture, posInput.positionSS);
207+
FETCH_DBUFFER(DBuffer, _DBufferTexture, int2(posInput.positionSS.xy));
208208

209209
#if defined(_SURFACE_TYPE_TRANSPARENT) && defined(HAS_LIGHTLOOP) // forward transparent using clustered decals
210210
uint decalCount, decalStart;
@@ -258,7 +258,7 @@ DecalSurfaceData GetDecalSurfaceData(PositionInputs posInput, inout float alpha)
258258

259259
if (!fastPath)
260260
{
261-
// If we are not in fast path, v_lightIdx is not scalar, so we need to query the Min value across the wave.
261+
// If we are not in fast path, v_lightIdx is not scalar, so we need to query the Min value across the wave.
262262
s_decalIdx = WaveActiveMin(v_decalIdx);
263263
// If WaveActiveMin returns 0xffffffff it means that all lanes are actually dead, so we can safely ignore the loop and move forward.
264264
// 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

com.unity.render-pipelines.high-definition/Runtime/Material/Decal/ShaderVariablesDecal.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TEXTURE2D(_DecalAtlas2D);
1010
SAMPLER(_trilinear_clamp_sampler_DecalAtlas2D);
1111

1212
#ifdef PLATFORM_SUPPORTS_BUFFER_ATOMICS_IN_PIXEL_SHADER
13-
RWStructuredBuffer<uint> _DecalPropertyMaskBuffer;
13+
RWStructuredBuffer<uint> _DecalPropertyMaskBuffer : register(u4);
1414
StructuredBuffer<uint> _DecalPropertyMaskBufferSRV;
1515
#endif
1616

0 commit comments

Comments
 (0)