-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2233 from cdavis5e/agx-cube-grad-fixup
MSL: Work around broken cube texture gradients on Apple Silicon.
- Loading branch information
Showing
13 changed files
with
382 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...rs-msl/asm/frag/depth-array-texture-lod.lod-as-grad.1d-as-2d.agx-cube-grad.msl23.asm.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
static inline gradientcube spvGradientCube(float3 P, float3 dPdx, float3 dPdy) | ||
{ | ||
// Major axis selection | ||
float3 absP = abs(P); | ||
bool xMajor = absP.x >= max(absP.y, absP.z); | ||
bool yMajor = absP.y >= absP.z; | ||
float3 Q = xMajor ? P.yzx : (yMajor ? P.xzy : P); | ||
float3 dQdx = xMajor ? dPdx.yzx : (yMajor ? dPdx.xzy : dPdx); | ||
float3 dQdy = xMajor ? dPdy.yzx : (yMajor ? dPdy.xzy : dPdy); | ||
|
||
// Skip a couple of operations compared to usual projection | ||
float4 d = float4(dQdx.xy, dQdy.xy) - (Q.xy / Q.z).xyxy * float4(dQdx.zz, dQdy.zz); | ||
|
||
// Final swizzle to put the intermediate values into non-ignored components | ||
// X major: X and Z | ||
// Y major: X and Y | ||
// Z major: Y and Z | ||
return gradientcube(xMajor ? d.xxy : d.xyx, xMajor ? d.zzw : d.zwz); | ||
} | ||
|
||
struct main0_out | ||
{ | ||
float4 o_color [[color(0)]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float4 v_texCoord [[user(locn0)]]; | ||
float2 v_drefLodBias [[user(locn1)]]; | ||
}; | ||
|
||
fragment main0_out main0(main0_in in [[stage_in]], depthcube_array<float> u_sampler [[texture(0)]], sampler u_samplerSmplr [[sampler(0)]]) | ||
{ | ||
main0_out out = {}; | ||
out.o_color = float4(u_sampler.sample_compare(u_samplerSmplr, in.v_texCoord.xyz, uint(rint(in.v_texCoord.w)), in.v_drefLodBias.x, spvGradientCube(in.v_texCoord.xyz, exp2(in.v_drefLodBias.y - 0.5) / float3(u_sampler.get_width()), exp2(in.v_drefLodBias.y - 0.5) / float3(u_sampler.get_width()))), 0.0, 0.0, 1.0); | ||
return out; | ||
} | ||
|
44 changes: 44 additions & 0 deletions
44
reference/opt/shaders-msl/frag/sampler-cube-grad.agx-cube-grad.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
static inline gradientcube spvGradientCube(float3 P, float3 dPdx, float3 dPdy) | ||
{ | ||
// Major axis selection | ||
float3 absP = abs(P); | ||
bool xMajor = absP.x >= max(absP.y, absP.z); | ||
bool yMajor = absP.y >= absP.z; | ||
float3 Q = xMajor ? P.yzx : (yMajor ? P.xzy : P); | ||
float3 dQdx = xMajor ? dPdx.yzx : (yMajor ? dPdx.xzy : dPdx); | ||
float3 dQdy = xMajor ? dPdy.yzx : (yMajor ? dPdy.xzy : dPdy); | ||
|
||
// Skip a couple of operations compared to usual projection | ||
float4 d = float4(dQdx.xy, dQdy.xy) - (Q.xy / Q.z).xyxy * float4(dQdx.zz, dQdy.zz); | ||
|
||
// Final swizzle to put the intermediate values into non-ignored components | ||
// X major: X and Z | ||
// Y major: X and Y | ||
// Z major: Y and Z | ||
return gradientcube(xMajor ? d.xxy : d.xyx, xMajor ? d.zzw : d.zwz); | ||
} | ||
|
||
struct main0_out | ||
{ | ||
float4 FragColor [[color(0)]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float3 vTex [[user(locn0), flat]]; | ||
}; | ||
|
||
fragment main0_out main0(main0_in in [[stage_in]], texturecube<float> uSampler [[texture(0)]], sampler uSamplerSmplr [[sampler(0)]]) | ||
{ | ||
main0_out out = {}; | ||
out.FragColor += uSampler.sample(uSamplerSmplr, in.vTex, spvGradientCube(in.vTex, float3(5.0), float3(8.0))); | ||
return out; | ||
} | ||
|
55 changes: 55 additions & 0 deletions
55
...rs-msl/asm/frag/depth-array-texture-lod.lod-as-grad.1d-as-2d.agx-cube-grad.msl23.asm.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
static inline gradientcube spvGradientCube(float3 P, float3 dPdx, float3 dPdy) | ||
{ | ||
// Major axis selection | ||
float3 absP = abs(P); | ||
bool xMajor = absP.x >= max(absP.y, absP.z); | ||
bool yMajor = absP.y >= absP.z; | ||
float3 Q = xMajor ? P.yzx : (yMajor ? P.xzy : P); | ||
float3 dQdx = xMajor ? dPdx.yzx : (yMajor ? dPdx.xzy : dPdx); | ||
float3 dQdy = xMajor ? dPdy.yzx : (yMajor ? dPdy.xzy : dPdy); | ||
|
||
// Skip a couple of operations compared to usual projection | ||
float4 d = float4(dQdx.xy, dQdy.xy) - (Q.xy / Q.z).xyxy * float4(dQdx.zz, dQdy.zz); | ||
|
||
// Final swizzle to put the intermediate values into non-ignored components | ||
// X major: X and Z | ||
// Y major: X and Y | ||
// Z major: Y and Z | ||
return gradientcube(xMajor ? d.xxy : d.xyx, xMajor ? d.zzw : d.zwz); | ||
} | ||
|
||
struct buf0 | ||
{ | ||
float4 u_scale; | ||
}; | ||
|
||
struct buf1 | ||
{ | ||
float4 u_bias; | ||
}; | ||
|
||
struct main0_out | ||
{ | ||
float4 o_color [[color(0)]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float4 v_texCoord [[user(locn0)]]; | ||
float2 v_drefLodBias [[user(locn1)]]; | ||
}; | ||
|
||
fragment main0_out main0(main0_in in [[stage_in]], depthcube_array<float> u_sampler [[texture(0)]], sampler u_samplerSmplr [[sampler(0)]]) | ||
{ | ||
main0_out out = {}; | ||
out.o_color = float4(u_sampler.sample_compare(u_samplerSmplr, in.v_texCoord.xyz, uint(rint(in.v_texCoord.w)), in.v_drefLodBias.x, spvGradientCube(in.v_texCoord.xyz, exp2(in.v_drefLodBias.y - 0.5) / float3(u_sampler.get_width()), exp2(in.v_drefLodBias.y - 0.5) / float3(u_sampler.get_width()))), 0.0, 0.0, 1.0); | ||
return out; | ||
} | ||
|
44 changes: 44 additions & 0 deletions
44
reference/shaders-msl/frag/sampler-cube-grad.agx-cube-grad.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
static inline gradientcube spvGradientCube(float3 P, float3 dPdx, float3 dPdy) | ||
{ | ||
// Major axis selection | ||
float3 absP = abs(P); | ||
bool xMajor = absP.x >= max(absP.y, absP.z); | ||
bool yMajor = absP.y >= absP.z; | ||
float3 Q = xMajor ? P.yzx : (yMajor ? P.xzy : P); | ||
float3 dQdx = xMajor ? dPdx.yzx : (yMajor ? dPdx.xzy : dPdx); | ||
float3 dQdy = xMajor ? dPdy.yzx : (yMajor ? dPdy.xzy : dPdy); | ||
|
||
// Skip a couple of operations compared to usual projection | ||
float4 d = float4(dQdx.xy, dQdy.xy) - (Q.xy / Q.z).xyxy * float4(dQdx.zz, dQdy.zz); | ||
|
||
// Final swizzle to put the intermediate values into non-ignored components | ||
// X major: X and Z | ||
// Y major: X and Y | ||
// Z major: Y and Z | ||
return gradientcube(xMajor ? d.xxy : d.xyx, xMajor ? d.zzw : d.zwz); | ||
} | ||
|
||
struct main0_out | ||
{ | ||
float4 FragColor [[color(0)]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float3 vTex [[user(locn0), flat]]; | ||
}; | ||
|
||
fragment main0_out main0(main0_in in [[stage_in]], texturecube<float> uSampler [[texture(0)]], sampler uSamplerSmplr [[sampler(0)]]) | ||
{ | ||
main0_out out = {}; | ||
out.FragColor += uSampler.sample(uSamplerSmplr, in.vTex, spvGradientCube(in.vTex, float3(5.0), float3(8.0))); | ||
return out; | ||
} | ||
|
86 changes: 86 additions & 0 deletions
86
...rs-msl/asm/frag/depth-array-texture-lod.lod-as-grad.1d-as-2d.agx-cube-grad.msl23.asm.frag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
; SPIR-V | ||
; Version: 1.3 | ||
; Generator: Khronos Glslang Reference Front End; 11 | ||
; Bound: 45 | ||
; Schema: 0 | ||
OpCapability Shader | ||
OpCapability SampledCubeArray | ||
%1 = OpExtInstImport "GLSL.std.450" | ||
OpMemoryModel Logical GLSL450 | ||
OpEntryPoint Fragment %main "main" %o_color %v_texCoord %v_drefLodBias | ||
OpExecutionMode %main OriginUpperLeft | ||
|
||
; Debug Information | ||
OpSource GLSL 450 | ||
OpName %main "main" ; id %4 | ||
OpName %o_color "o_color" ; id %9 | ||
OpName %u_sampler "u_sampler" ; id %13 | ||
OpName %v_texCoord "v_texCoord" ; id %16 | ||
OpName %v_drefLodBias "v_drefLodBias" ; id %21 | ||
OpName %buf0 "buf0" ; id %39 | ||
OpMemberName %buf0 0 "u_scale" | ||
OpName %_ "" ; id %41 | ||
OpName %buf1 "buf1" ; id %42 | ||
OpMemberName %buf1 0 "u_bias" | ||
OpName %__0 "" ; id %44 | ||
|
||
; Annotations | ||
OpDecorate %o_color RelaxedPrecision | ||
OpDecorate %o_color Location 0 | ||
OpDecorate %u_sampler DescriptorSet 0 | ||
OpDecorate %u_sampler Binding 0 | ||
OpDecorate %v_texCoord Location 0 | ||
OpDecorate %v_drefLodBias Location 1 | ||
OpMemberDecorate %buf0 0 Offset 0 | ||
OpDecorate %buf0 Block | ||
OpDecorate %_ DescriptorSet 0 | ||
OpDecorate %_ Binding 1 | ||
OpMemberDecorate %buf1 0 Offset 0 | ||
OpDecorate %buf1 Block | ||
OpDecorate %__0 DescriptorSet 0 | ||
OpDecorate %__0 Binding 2 | ||
|
||
; Types, variables and constants | ||
%void = OpTypeVoid | ||
%3 = OpTypeFunction %void | ||
%float = OpTypeFloat 32 | ||
%v4float = OpTypeVector %float 4 | ||
%_ptr_Output_v4float = OpTypePointer Output %v4float | ||
%o_color = OpVariable %_ptr_Output_v4float Output | ||
%10 = OpTypeImage %float Cube 1 1 0 1 Unknown | ||
%11 = OpTypeSampledImage %10 | ||
%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11 | ||
%u_sampler = OpVariable %_ptr_UniformConstant_11 UniformConstant | ||
%_ptr_Input_v4float = OpTypePointer Input %v4float | ||
%v_texCoord = OpVariable %_ptr_Input_v4float Input | ||
%v2float = OpTypeVector %float 2 | ||
%_ptr_Input_v2float = OpTypePointer Input %v2float | ||
%v_drefLodBias = OpVariable %_ptr_Input_v2float Input | ||
%uint = OpTypeInt 32 0 | ||
%uint_0 = OpConstant %uint 0 | ||
%_ptr_Input_float = OpTypePointer Input %float | ||
%v3float = OpTypeVector %float 3 | ||
%uint_1 = OpConstant %uint 1 | ||
%float_0 = OpConstant %float 0 | ||
%float_1 = OpConstant %float 1 | ||
%buf0 = OpTypeStruct %v4float | ||
%_ptr_Uniform_buf0 = OpTypePointer Uniform %buf0 | ||
%_ = OpVariable %_ptr_Uniform_buf0 Uniform | ||
%buf1 = OpTypeStruct %v4float | ||
%_ptr_Uniform_buf1 = OpTypePointer Uniform %buf1 | ||
%__0 = OpVariable %_ptr_Uniform_buf1 Uniform | ||
|
||
; Function main | ||
%main = OpFunction %void None %3 | ||
%5 = OpLabel | ||
%14 = OpLoad %11 %u_sampler | ||
%18 = OpLoad %v4float %v_texCoord | ||
%25 = OpAccessChain %_ptr_Input_float %v_drefLodBias %uint_0 | ||
%26 = OpLoad %float %25 | ||
%32 = OpAccessChain %_ptr_Input_float %v_drefLodBias %uint_1 | ||
%33 = OpLoad %float %32 | ||
%35 = OpImageSampleDrefExplicitLod %float %14 %18 %26 Lod %33 | ||
%38 = OpCompositeConstruct %v4float %35 %float_0 %float_0 %float_1 | ||
OpStore %o_color %38 | ||
OpReturn | ||
OpFunctionEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#version 450 | ||
|
||
layout(location = 0) out vec4 FragColor; | ||
layout(location = 0) flat in vec3 vTex; | ||
layout(binding = 0) uniform samplerCube uSampler; | ||
|
||
void main() | ||
{ | ||
FragColor += textureGrad(uSampler, vTex, vec3(5.0), vec3(8.0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.