forked from nannou-org/nannou
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add manual msaa resolve to TextureReshaper. Solves validation error.
Previously a validation error was occurring due to passing a sampled texture to the bind group without declaring that the texture was multisampled in the fragment shader. This adds some new multisampled shaders that correctly declare the texture and do the multisampling resolve manually. Dedicated shaders have been added for common sample counts with unrolled loops to avoid having the shader deal with conditions based on uniform data. A fallback shader is provided for all other sample counts. Closes nannou-org#462.
- Loading branch information
1 parent
f035233
commit 8f0239c
Showing
14 changed files
with
274 additions
and
51 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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,34 @@ | ||
// NOTE: This shader requires being manually compiled to SPIR-V in order to | ||
// avoid having downstream users require building shaderc and compiling the | ||
// shader themselves. If you update this shader, be sure to also re-compile it | ||
// and update `frag_msaa.spv`. You can do so using `glslangValidator` with the | ||
// following command: `glslangValidator -V -o frag_msaa.spv shader_msaa.frag` | ||
|
||
#version 450 | ||
|
||
layout(location = 0) in vec2 tex_coords; | ||
layout(location = 0) out vec4 f_color; | ||
|
||
layout(set = 0, binding = 0) uniform texture2DMS tex; | ||
layout(set = 0, binding = 1) uniform sampler tex_sampler; | ||
layout(set = 0, binding = 2) uniform Data { | ||
uint sample_count; | ||
} uniforms; | ||
|
||
void main() { | ||
// Get the integer tex coordinates. | ||
ivec2 tex_size = textureSize(sampler2DMS(tex, tex_sampler)); | ||
int tex_x = int(tex_size.x * tex_coords.x); | ||
int tex_y = int(tex_size.y * tex_coords.y); | ||
ivec2 itex_coords = ivec2(tex_x, tex_y); | ||
|
||
// Perform the resolve. | ||
vec4 color = vec4(0); | ||
for (int i = 0; i < uniforms.sample_count; i++) { | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, i); | ||
} | ||
color /= float(uniforms.sample_count); | ||
|
||
// Assign the resolved color to the output. | ||
f_color = color; | ||
} |
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 @@ | ||
// NOTE: This shader requires being manually compiled to SPIR-V in order to | ||
// avoid having downstream users require building shaderc and compiling the | ||
// shader themselves. If you update this shader, be sure to also re-compile it | ||
// and update `frag_msaa16.spv`. You can do so using `glslangValidator` with | ||
// the following command: | ||
// `glslangValidator -V -o frag_msaa16.spv shader_msaa16.frag` | ||
|
||
#version 450 | ||
|
||
layout(location = 0) in vec2 tex_coords; | ||
layout(location = 0) out vec4 f_color; | ||
|
||
layout(set = 0, binding = 0) uniform texture2DMS tex; | ||
layout(set = 0, binding = 1) uniform sampler tex_sampler; | ||
|
||
void main() { | ||
// Get the integer tex coordinates. | ||
ivec2 tex_size = textureSize(sampler2DMS(tex, tex_sampler)); | ||
int tex_x = int(tex_size.x * tex_coords.x); | ||
int tex_y = int(tex_size.y * tex_coords.y); | ||
ivec2 itex_coords = ivec2(tex_x, tex_y); | ||
|
||
// Manually unroll the resolve. The less conditions the better! | ||
vec4 color = vec4(0); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 0); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 1); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 2); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 3); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 4); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 5); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 6); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 7); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 8); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 9); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 10); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 11); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 12); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 13); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 14); | ||
color += texelFetch(sampler2DMS(tex, tex_sampler), itex_coords, 15); | ||
color *= 0.0625; | ||
|
||
// Assign the resolved color to the output. | ||
f_color = color; | ||
} |
Oops, something went wrong.