-
Notifications
You must be signed in to change notification settings - Fork 984
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
[spv-in] Spirv Shader with Uniform Sampling/TextureGrad Fails Uniformity Analysis #4359
Comments
It's a problem with SPV-in, the generated IR doesn't have anything about grads:
|
Interesting, the grad code is there 🤔 |
It seems that it should been spewing zero: level = if options.compare {
log::debug!(
"Assuming gradients {:?} and {:?} are not greater than 1",
grad_x_handle,
grad_y_handle
);
crate::SampleLevel::Zero
} else {
crate::SampleLevel::Gradient {
x: grad_x_handle,
y: grad_y_handle,
}
}; But the resulting IR has |
Your shader does have an implicit sample Spir-v disassembly
You have this in the debug data if (MATERIAL_FLAG(FLAGS_UNLIT)) {
o_color = pixel.albedo;
// o_normal = vec4(i_normal, 0.0);
} else {
vec3 v = -normalize(i_view_position.xyz);
vec3 color = vec3(pixel.emissive);
for (uint i = 0; i < directional_light_header.total_lights; ++i) {
DirectionalLight light = directional_lights[i];
vec3 shadow_ndc = (directional_lights[i].view_proj * uniforms.inv_view * i_view_position).xyz;
vec2 shadow_flipped = (shadow_ndc.xy * 0.5) + 0.5;
vec4 shadow_shadow_coords = vec4(shadow_flipped.x, 1 - shadow_flipped.y, float(i), shadow_ndc.z);
float shadow_value;
shadow_value = texture(sampler2DArrayShadow(shadow, shadow_sampler), shadow_shadow_coords);
if (shadow_shadow_coords.x < 0 || shadow_shadow_coords.x > 1 || shadow_shadow_coords.y < 0 || shadow_shadow_coords.y > 1 || shadow_ndc.z < -1 || shadow_ndc.z > 1) {
shadow_value = 1.0;
}
color += surface_shading(directional_lights[i], pixel, v, shadow_value * pixel.ambient_occlusion);
}
o_color = max(vec4(color, pixel.albedo.a), uniforms.ambient * pixel.albedo);
// o_normal = vec4(pixel.normal, 0.0);
} Clearly there's a |
Having the texture call in an |
Yeah the if and the for loop are both based on uniform values, and as such should be valid to use implicit derivatives there. Incidentally, I'm only using implicit derivatives there because textureLod doesn't exist for sampler2DArrayShadow in GLSL :| |
This is related to #4320 Also had this problem,
|
This is unfortunately not available through glslang, there was a PR, but it went stale and got closed. |
wdym? This worked for me on glslang #version 460
layout (location = 0) out vec4 fragColor;
layout (set = 0, binding = 0) uniform texture2DArray tex;
layout (set = 0, binding = 0) uniform sampler samp;
void main()
{
float a = textureGrad(sampler2DArrayShadow(tex,samp), vec4(0), vec2(0), vec2(0));
fragColor = vec4(a);
} http://shader-playground.timjones.io/50f33d0eb84ce1eb744225e701d882fc |
Well hot diggity dog, I didn't realize that worked, I must have thought I tried it, but didn't. |
Let's track this in #4369. |
A shader which passed validation in 0.6.3 fails to validate in naga master due to:
This shader uses either textureGrad or sampling inside of uniform control flow. and shouldn't fail.
opaque.frag.cpu.zip
This was found because I found a hlsl compile error in naga 0.6.3 that I wondered might be fixed by the new spirv control flow stuff. If you compile this shader to hlsl with 0.6.3, it'll try to use a inside-scope variable outside of that scope, causing a compile error.
The text was updated successfully, but these errors were encountered: