diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-04-23 22:08:11 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-02 21:49:38 +0300 |
commit | 12570c737356a06e21052cdc767b26ed7584a948 (patch) | |
tree | 3dcda29aa3596d96642e1249c3bf0665819beeb5 /source/blender/gpu/shaders | |
parent | 26021984859b6c522a532e3613fe65ffed6cbc19 (diff) |
GPUShader: Add GPU_SHADER_2D_IMAGE_MULTISAMPLE_2/4/8/16
This shader is used instead of blitting back and forth to a single sample
buffer.
This means it resolves the color and depth samples and outputs a fragment
which can be depth tested and blended on top of an existing framebuffer.
We do static shader variation with manual loop unrolling for performance
reason. In my test I get 25% more perf with intel integrated gpu and 75%
performance gain with dedicated nvidia card compared to a single shader
with a uniform for sample count.
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl new file mode 100644 index 00000000000..de1fd8b6b58 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl @@ -0,0 +1,67 @@ + +uniform sampler2DMS depthMulti; +uniform sampler2DMS colorMulti; + +out vec4 fragColor; + +#if SAMPLES > 16 +#error "Too many samples" +#endif + +void main() +{ + ivec2 texel = ivec2(gl_FragCoord.xy); + + float depth = 1.0; + depth = min(depth, texelFetch(depthMulti, texel, 0).r); + depth = min(depth, texelFetch(depthMulti, texel, 1).r); +#if SAMPLES > 2 + depth = min(depth, texelFetch(depthMulti, texel, 2).r); + depth = min(depth, texelFetch(depthMulti, texel, 3).r); +#endif +#if SAMPLES > 4 + depth = min(depth, texelFetch(depthMulti, texel, 4).r); + depth = min(depth, texelFetch(depthMulti, texel, 5).r); + depth = min(depth, texelFetch(depthMulti, texel, 6).r); + depth = min(depth, texelFetch(depthMulti, texel, 7).r); +#endif +#if SAMPLES > 8 + depth = min(depth, texelFetch(depthMulti, texel, 8).r); + depth = min(depth, texelFetch(depthMulti, texel, 9).r); + depth = min(depth, texelFetch(depthMulti, texel, 10).r); + depth = min(depth, texelFetch(depthMulti, texel, 11).r); + depth = min(depth, texelFetch(depthMulti, texel, 12).r); + depth = min(depth, texelFetch(depthMulti, texel, 13).r); + depth = min(depth, texelFetch(depthMulti, texel, 14).r); + depth = min(depth, texelFetch(depthMulti, texel, 15).r); +#endif + + vec4 color = vec4(0.0); + color += texelFetch(colorMulti, texel, 0); + color += texelFetch(colorMulti, texel, 1); +#if SAMPLES > 2 + color += texelFetch(colorMulti, texel, 2); + color += texelFetch(colorMulti, texel, 3); +#endif +#if SAMPLES > 4 + color += texelFetch(colorMulti, texel, 4); + color += texelFetch(colorMulti, texel, 5); + color += texelFetch(colorMulti, texel, 6); + color += texelFetch(colorMulti, texel, 7); +#endif +#if SAMPLES > 8 + color += texelFetch(colorMulti, texel, 8); + color += texelFetch(colorMulti, texel, 9); + color += texelFetch(colorMulti, texel, 10); + color += texelFetch(colorMulti, texel, 11); + color += texelFetch(colorMulti, texel, 12); + color += texelFetch(colorMulti, texel, 13); + color += texelFetch(colorMulti, texel, 14); + color += texelFetch(colorMulti, texel, 15); +#endif + + const float inv_samples = 1.0 / float(SAMPLES); + + fragColor = color * inv_samples; + gl_FragDepth = depth; +} |