Skip to content

Dxc compatibility #14

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

Merged
merged 8 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 44 additions & 2 deletions com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,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)
Expand Down Expand Up @@ -701,6 +701,48 @@ 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; };
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)
{
float3 dir = normalize(unDir);
Expand Down
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix for issue that prevented scene from being completely saved when baked reflection probes are present and lighting is set to auto generate.
- Fixed drag area width at left of Light's intensity field in Inspector.
- Fixed light type resolution when performing a reset on HDAdditionalLightData (case 1220931)
- 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
Expand Down Expand Up @@ -614,6 +615,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Temporal Anti aliasing improvements.
- Optimized PrepareLightsForGPU (cost reduced by over 25%) and PrepareGPULightData (around twice as fast now).
- Moved scene view camera settings for HDRP from the preferences window to the scene view camera settings window.
- Updated shaders to be compatible with Microsoft's DXC.

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TEXTURE2D(_DecalAtlas2D);
SAMPLER(_trilinear_clamp_sampler_DecalAtlas2D);

#ifdef PLATFORM_SUPPORTS_BUFFER_ATOMICS_IN_PIXEL_SHADER
RWStructuredBuffer<uint> _DecalPropertyMaskBuffer;
RWStructuredBuffer<uint> _DecalPropertyMaskBuffer : register(u4);
StructuredBuffer<uint> _DecalPropertyMaskBufferSRV;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1791,9 +1791,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Shader "Hidden/HDRP/TemporalAA"
TEXTURE2D_X(_DepthTexture);
TEXTURE2D_X(_InputTexture);
TEXTURE2D_X(_InputHistoryTexture);
RW_TEXTURE2D_X(CTYPE, _OutputHistoryTexture);
RW_TEXTURE2D_X(CTYPE, _OutputHistoryTexture) : register(u1);


#define _HistorySharpening _TaaPostParameters.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
#define TEXTURE2D_X_UINT(textureName) Texture2DArray<uint> textureName
#define TEXTURE2D_X_UINT2(textureName) Texture2DArray<uint2> textureName
#define TEXTURE2D_X_UINT4(textureName) Texture2DArray<uint4> textureName
#define TEXTURE2D_X_MSAA(type, textureName) Texture2DMSArray<type> 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<type, 1> 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)
Expand All @@ -90,7 +91,8 @@
#define TEXTURE2D_X_UINT(textureName) Texture2D<uint> textureName
#define TEXTURE2D_X_UINT2(textureName) Texture2D<uint2> textureName
#define TEXTURE2D_X_UINT4(textureName) Texture2D<uint4> textureName
#define TEXTURE2D_X_MSAA(type, textureName) Texture2DMS<type> 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<type, 1> textureName

#define RW_TEXTURE2D_X RW_TEXTURE2D
#define LOAD_TEXTURE2D_X LOAD_TEXTURE2D
Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- URP shaders that contain a priority slider now no longer have an offset of 50 by default.
- The virtual ScriptableRenderer.FrameCleanup() function has been marked obsolete and replaced by ScriptableRenderer.OnCameraCleanup() to better describe when the function gets invoked by the renderer.
- DepthOnlyPass, CopyDepthPass and CopyColorPass now use OnCameraSetup() instead of Configure() to set up their passes before executing as they only need to get their rendertextures once per camera instead of once per eye.
- Updated shaders to be compatible with Microsoft's DXC.

### Fixed
- Fixed an issue where linear to sRGB conversion occurred twice on certain Android devices.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,4 +20,8 @@

#include "SpeedTree7CommonInput.hlsl"

#ifdef GEOM_TYPE_BRANCH_DETAIL
sampler2D _DetailTex;
#endif

#endif
1 change: 1 addition & 0 deletions com.unity.shadergraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Changed the `Branch` node so that it uses a ternary operator (`Out = bool ? a : B`) instead of a linear interpolate function.
- Copied nodes are now pasted at the cursor location instead of slightly offset from their original location
- Error messages reported on Sub Graph output nodes for invalid previews now present clearer information, with documentation support.
- 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion com.unity.testing.hdrp/Shaders/DistordFromTex.shader
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion com.unity.testing.hdrp/Shaders/DistordTest.shader
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down