Add precise keyword to the depth and forward pass shaders. (#6536)
* Add precise keyword to the depth and forward pass shaders. Make sure metal shader pipeline passes the invariant along Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com> * Update with VickyAtAZ's feedback, split the preserve invariance into a separate string Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com> * Fix attribute comment alignment in the shaders Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>
This commit is contained in:
@@ -82,8 +82,7 @@ namespace AZ
|
||||
// Register Shader Asset Builder
|
||||
AssetBuilderSDK::AssetBuilderDesc shaderAssetBuilderDescriptor;
|
||||
shaderAssetBuilderDescriptor.m_name = "Shader Asset Builder";
|
||||
shaderAssetBuilderDescriptor.m_version = 108; // The Build Time Stamp of ShaderAsset And ShaderVariantAsset Should Be Based On GetTimeUTCMilliSecond()
|
||||
// .shader file changes trigger rebuilds
|
||||
shaderAssetBuilderDescriptor.m_version = 109; // Modify Metal shader platform to permit the precise keyword to fix depth bitwise mismatch between passes
|
||||
shaderAssetBuilderDescriptor.m_patterns.push_back(AssetBuilderSDK::AssetBuilderPattern( AZStd::string::format("*.%s", RPI::ShaderSourceData::Extension), AssetBuilderSDK::AssetBuilderPattern::PatternType::Wildcard));
|
||||
shaderAssetBuilderDescriptor.m_busId = azrtti_typeid<ShaderAssetBuilder>();
|
||||
shaderAssetBuilderDescriptor.m_createJobFunction = AZStd::bind(&ShaderAssetBuilder::CreateJobs, &m_shaderAssetBuilder, AZStd::placeholders::_1, AZStd::placeholders::_2);
|
||||
|
||||
@@ -29,7 +29,7 @@ struct VSInput
|
||||
struct VSDepthOutput
|
||||
{
|
||||
// "centroid" is needed for SV_Depth to compile
|
||||
linear centroid float4 m_position : SV_Position;
|
||||
precise linear centroid float4 m_position : SV_Position;
|
||||
float2 m_uv[UvSetCount] : UV1;
|
||||
|
||||
// only used for parallax depth calculation
|
||||
|
||||
@@ -62,7 +62,7 @@ struct VSOutput
|
||||
{
|
||||
// Base fields (required by the template azsli file)...
|
||||
// "centroid" is needed for SV_Depth to compile
|
||||
linear centroid float4 m_position : SV_Position;
|
||||
precise linear centroid float4 m_position : SV_Position;
|
||||
float3 m_normal: NORMAL;
|
||||
float3 m_tangent : TANGENT;
|
||||
float3 m_bitangent : BITANGENT;
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ static const float MinRoughnessA = 0.0005f;
|
||||
|
||||
class BasePbrSurfaceData
|
||||
{
|
||||
float3 position; //!< Position in world-space
|
||||
precise float3 position; //!< Position in world-space
|
||||
float3 normal; //!< Normal in world-space
|
||||
float3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
|
||||
float3 specularF0; //!< Fresnel f0 spectral value of the surface
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ class Surface
|
||||
|
||||
// ------- BasePbrSurfaceData -------
|
||||
|
||||
float3 position; //!< Position in world-space
|
||||
precise float3 position; //!< Position in world-space
|
||||
float3 normal; //!< Normal in world-space
|
||||
float3 vertexNormal; //!< Vertex normal in world-space
|
||||
float3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
|
||||
|
||||
@@ -347,7 +347,7 @@ namespace AZ
|
||||
// spirv cross compiler executable
|
||||
static const char* spirvCrossRelativePath = "Builders/SPIRVCross/spirv-cross";
|
||||
|
||||
AZStd::string spirvCrossCommandOptions = AZStd::string::format("--msl --msl-version 20100 --msl-argument-buffers --msl-decoration-binding --msl-texture-buffer-native --output \"%s\" \"%s\"", shaderMSLOutputFile.c_str(), shaderSpirvOutputFile.c_str());
|
||||
AZStd::string spirvCrossCommandOptions = AZStd::string::format("--msl --msl-version 20100 --msl-invariant-float-math --msl-argument-buffers --msl-decoration-binding --msl-texture-buffer-native --output \"%s\" \"%s\"", shaderMSLOutputFile.c_str(), shaderSpirvOutputFile.c_str());
|
||||
|
||||
// Run spirv cross
|
||||
if (!RHI::ExecuteShaderCompiler(spirvCrossRelativePath, spirvCrossCommandOptions, shaderSpirvOutputFile, "SpirvCross"))
|
||||
@@ -426,6 +426,8 @@ namespace AZ
|
||||
//Debug symbols are always enabled at the moment. Need to turn them off for optimized shader assets.
|
||||
AZStd::string shaderDebugInfo = "-gline-tables-only -MO";
|
||||
|
||||
AZStd::string shaderMslToAirOptions = "-fpreserve-invariance";
|
||||
|
||||
//Apply the correct platform sdk option
|
||||
AZStd::string platformSdk = "macosx";
|
||||
if (platform.HasTag("mobile"))
|
||||
@@ -434,7 +436,7 @@ namespace AZ
|
||||
}
|
||||
|
||||
//Convert to air file
|
||||
AZStd::string mslToAirCommandOptions = AZStd::string::format("-sdk %s metal \"%s\" %s -c -o \"%s\"", platformSdk.c_str(), inputMetalFile.c_str(), shaderDebugInfo.c_str(), outputAirFile.c_str());
|
||||
AZStd::string mslToAirCommandOptions = AZStd::string::format("-sdk %s metal \"%s\" %s %s -c -o \"%s\"", platformSdk.c_str(), inputMetalFile.c_str(), shaderDebugInfo.c_str(), shaderMslToAirOptions.c_str(), outputAirFile.c_str());
|
||||
|
||||
if (!RHI::ExecuteShaderCompiler("/usr/bin/xcrun", mslToAirCommandOptions, inputMetalFile, "MslToAir"))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user