From 9d4b5c0c595d3a6c1e057df2baaa1aa16a30b787 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 5 May 2016 09:19:38 +0200 Subject: [PATCH] Use texel fetch instead of normalized sampling for subpass. Cleaner output code, and matches more directly to how subpass reads work. --- reference/shaders-vulkan/frag/input-attachment.frag | 2 +- spirv_glsl.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/reference/shaders-vulkan/frag/input-attachment.frag b/reference/shaders-vulkan/frag/input-attachment.frag index c441373c..9d7b675b 100644 --- a/reference/shaders-vulkan/frag/input-attachment.frag +++ b/reference/shaders-vulkan/frag/input-attachment.frag @@ -9,6 +9,6 @@ layout(location = 0) out vec4 FragColor; void main() { - FragColor = (texture(uSubpass0, gl_FragCoord.xy / vec2(textureSize(uSubpass0, 0).xy)) + texture(uSubpass1, gl_FragCoord.xy / vec2(textureSize(uSubpass1, 0).xy))); + FragColor = (texelFetch(uSubpass0, ivec2(gl_FragCoord.xy), 0) + texelFetch(uSubpass1, ivec2(gl_FragCoord.xy), 0)); } diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index c1f8120a..d06bf444 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -3104,8 +3104,8 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) { // Implement subpass loads via texture barrier style sampling. // Fairly ugly, but should essentially work as a fallback for desktop. - imgexpr = join("texture(", to_expression(ops[2]), - ", gl_FragCoord.xy / vec2(textureSize(", to_expression(ops[2]), ", 0).xy))"); + imgexpr = join("texelFetch(", to_expression(ops[2]), + ", ivec2(gl_FragCoord.xy), 0)"); pure = true; } else