Add handling for MSAA Array textures on GL/GLSL shaders. Closes #1333

This commit is contained in:
baldurk
2019-04-01 11:59:11 +01:00
parent 4bdc07a770
commit afb7fa3771
7 changed files with 190 additions and 10 deletions
+86
View File
@@ -44,6 +44,7 @@ uniform usampler2DRect texUInt2DRect;
uniform usamplerBuffer texUIntBuffer;
#ifdef TEXSAMPLE_MULTISAMPLE
uniform usampler2DMS texUInt2DMS;
uniform usampler2DMSArray texUInt2DMSArray;
#endif
vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes,
@@ -84,6 +85,17 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp
col = texelFetch(texUInt2DMS, ivec2(pos * texRes.xy), sampleIdx);
#else
col = uvec4(0u, 0u, 0u, 0u);
#endif
}
else if(type == RESTYPE_TEX2DMSARRAY)
{
#ifdef TEXSAMPLE_MULTISAMPLE
if(sampleIdx < 0)
sampleIdx = 0;
col = texelFetch(texUInt2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
#else
col = uvec4(0u, 0u, 0u, 0u);
#endif
}
else if(type == RESTYPE_TEX2DARRAY)
@@ -118,6 +130,7 @@ uniform isampler2DRect texSInt2DRect;
uniform isamplerBuffer texSIntBuffer;
#ifdef TEXSAMPLE_MULTISAMPLE
uniform isampler2DMS texSInt2DMS;
uniform isampler2DMSArray texSInt2DMSArray;
#endif
vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes,
@@ -163,6 +176,17 @@ ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int samp
col = texelFetch(texSInt2DMS, ivec2(pos * texRes.xy), sampleIdx);
#else
col = ivec4(0, 0, 0, 0);
#endif
}
else if(type == RESTYPE_TEX2DMSARRAY)
{
#ifdef TEXSAMPLE_MULTISAMPLE
if(sampleIdx < 0)
sampleIdx = 0;
col = texelFetch(texSInt2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
#else
col = ivec4(0, 0, 0, 0);
#endif
}
else if(type == RESTYPE_TEX2DARRAY)
@@ -194,6 +218,7 @@ uniform sampler2DRect tex2DRect;
uniform samplerBuffer texBuffer;
#ifdef TEXSAMPLE_MULTISAMPLE
uniform sampler2DMS tex2DMS;
uniform sampler2DMSArray tex2DMSArray;
#endif
vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes,
@@ -279,6 +304,67 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp
}
#else
col = vec4(0.0f, 0.0f, 0.0f, 0.0f);
#endif
}
else if(type == RESTYPE_TEX2DMSARRAY)
{
#ifdef TEXSAMPLE_MULTISAMPLE
if(sampleIdx < 0)
{
int sampleCount = -sampleIdx;
// worst resolve you've seen in your life
// it's manually unrolled because doing it as a dynamic loop on
// sampleCount seems to produce crazy artifacts on nvidia - probably a compiler bug
if(sampleCount == 2)
{
col += 0.5f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 0);
col += 0.5f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 1);
}
else if(sampleCount == 4)
{
col += 0.25f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 0);
col += 0.25f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 1);
col += 0.25f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 2);
col += 0.25f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 3);
}
else if(sampleCount == 8)
{
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 0);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 1);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 2);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 3);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 4);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 5);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 6);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 7);
}
else if(sampleCount == 16)
{
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 0);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 1);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 2);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 3);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 4);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 5);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 6);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 7);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 8);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 9);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 10);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 11);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 12);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 13);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 14);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 15);
}
}
else
{
col = texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
}
#else
col = vec4(0.0f, 0.0f, 0.0f, 0.0f);
#endif
}
else if(type == RESTYPE_TEX2DARRAY)
+86
View File
@@ -51,6 +51,7 @@ uniform PRECISION usamplerBuffer texUIntBuffer;
#endif
#ifdef TEXSAMPLE_MULTISAMPLE
uniform PRECISION usampler2DMS texUInt2DMS;
uniform PRECISION usampler2DMSArray texUInt2DMSArray;
#endif
vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes,
@@ -83,6 +84,17 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp
col = texelFetch(texUInt2DMS, ivec2(pos * texRes.xy), sampleIdx);
#else
col = uvec4(0u, 0u, 0u, 0u);
#endif
}
else if(type == RESTYPE_TEX2DMSARRAY)
{
#ifdef TEXSAMPLE_MULTISAMPLE
if(sampleIdx < 0)
sampleIdx = 0;
col = texelFetch(texUInt2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
#else
col = uvec4(0u, 0u, 0u, 0u);
#endif
}
else if(type == RESTYPE_TEX2DARRAY)
@@ -119,6 +131,7 @@ uniform PRECISION isamplerBuffer texSIntBuffer;
#endif
#ifdef TEXSAMPLE_MULTISAMPLE
uniform PRECISION isampler2DMS texSInt2DMS;
uniform PRECISION isampler2DMSArray texSInt2DMSArray;
#endif
vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes,
@@ -156,6 +169,17 @@ ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int samp
col = texelFetch(texSInt2DMS, ivec2(pos * texRes.xy), sampleIdx);
#else
col = ivec4(0, 0, 0, 0);
#endif
}
else if(type == RESTYPE_TEX2DMSARRAY)
{
#ifdef TEXSAMPLE_MULTISAMPLE
if(sampleIdx < 0)
sampleIdx = 0;
col = texelFetch(texSInt2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
#else
col = ivec4(0, 0, 0, 0);
#endif
}
else if(type == RESTYPE_TEX2DARRAY)
@@ -189,6 +213,7 @@ uniform PRECISION samplerBuffer texBuffer;
#endif
#ifdef TEXSAMPLE_MULTISAMPLE
uniform PRECISION sampler2DMS tex2DMS;
uniform PRECISION sampler2DMSArray tex2DMSArray;
#endif
vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes,
@@ -272,6 +297,67 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp
}
#else
col = vec4(0.0f, 0.0f, 0.0f, 0.0f);
#endif
}
else if(type == RESTYPE_TEX2DMSARRAY)
{
#ifdef TEXSAMPLE_MULTISAMPLE
if(sampleIdx < 0)
{
int sampleCount = -sampleIdx;
// worst resolve you've seen in your life
// it's manually unrolled because doing it as a dynamic loop on
// sampleCount seems to produce crazy artifacts on nvidia - probably a compiler bug
if(sampleCount == 2)
{
col += 0.5f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 0);
col += 0.5f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 1);
}
else if(sampleCount == 4)
{
col += 0.25f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 0);
col += 0.25f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 1);
col += 0.25f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 2);
col += 0.25f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 3);
}
else if(sampleCount == 8)
{
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 0);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 1);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 2);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 3);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 4);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 5);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 6);
col += 0.125f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 7);
}
else if(sampleCount == 16)
{
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 0);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 1);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 2);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 3);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 4);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 5);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 6);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 7);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 8);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 9);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 10);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 11);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 12);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 13);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 14);
col += 0.0625f * texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), 15);
}
}
else
{
col = texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
}
#else
col = vec4(0.0f, 0.0f, 0.0f, 0.0f);
#endif
}
else if(type == RESTYPE_TEX2DARRAY)
+2 -1
View File
@@ -126,7 +126,8 @@ vec3 CalcCubeCoord(vec2 uv, int face)
#define RESTYPE_TEXRECT 0x8
#define RESTYPE_TEXBUFFER 0x9
#define RESTYPE_TEX2DMS 0xA
#define RESTYPE_TEXTYPEMAX 0xA
#define RESTYPE_TEX2DMSARRAY 0xB
#define RESTYPE_TEXTYPEMAX 0xB
#endif
+7 -7
View File
@@ -28,7 +28,7 @@
layout(binding = 6) uniform sampler1DArray tex1DArray;
layout(binding = 7) uniform sampler2DArray tex2DArray;
layout(binding = 8) uniform sampler3D tex3D;
layout(binding = 9) uniform sampler2DMS tex2DMS;
layout(binding = 9) uniform sampler2DMSArray tex2DMSArray;
layout(binding = 10) uniform sampler2DArray texYUV[2];
vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes,
@@ -61,13 +61,13 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp
// worst resolve you've seen in your life
for(int i = 0; i < sampleCount; i++)
col += texelFetch(tex2DMS, ivec2(pos * texRes.xy), i);
col += texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), i);
col /= float(sampleCount);
}
else
{
col = texelFetch(tex2DMS, ivec2(pos * texRes.xy), sampleIdx);
col = texelFetch(tex2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
}
#endif
}
@@ -142,7 +142,7 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp
layout(binding = 11) uniform usampler1DArray texUInt1DArray;
layout(binding = 12) uniform usampler2DArray texUInt2DArray;
layout(binding = 13) uniform usampler3D texUInt3D;
layout(binding = 14) uniform usampler2DMS texUInt2DMS;
layout(binding = 14) uniform usampler2DMSArray texUInt2DMSArray;
uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes)
{
@@ -166,7 +166,7 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp
if(sampleIdx < 0)
sampleIdx = 0;
col = texelFetch(texUInt2DMS, ivec2(pos * texRes.xy), sampleIdx);
col = texelFetch(texUInt2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
}
#endif
@@ -179,7 +179,7 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp
layout(binding = 16) uniform isampler1DArray texSInt1DArray;
layout(binding = 17) uniform isampler2DArray texSInt2DArray;
layout(binding = 18) uniform isampler3D texSInt3D;
layout(binding = 19) uniform isampler2DMS texSInt2DMS;
layout(binding = 19) uniform isampler2DMSArray texSInt2DMSArray;
ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes)
{
@@ -203,7 +203,7 @@ ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int samp
if(sampleIdx < 0)
sampleIdx = 0;
col = texelFetch(texSInt2DMS, ivec2(pos * texRes.xy), sampleIdx);
col = texelFetch(texSInt2DMSArray, ivec3(pos * texRes.xy, slice), sampleIdx);
}
#endif
+5
View File
@@ -254,6 +254,7 @@ void GLReplay::ConfigureTexDisplayProgramBindings(GLuint program)
SET_TEX_BINDING("texUInt2DRect", 8);
SET_TEX_BINDING("texUIntBuffer", 9);
SET_TEX_BINDING("texUInt2DMS", 10);
SET_TEX_BINDING("texUInt2DMSArray", 11);
SET_TEX_BINDING("texSInt1D", 1);
SET_TEX_BINDING("texSInt2D", 2);
@@ -263,6 +264,7 @@ void GLReplay::ConfigureTexDisplayProgramBindings(GLuint program)
SET_TEX_BINDING("texSInt2DRect", 8);
SET_TEX_BINDING("texSIntBuffer", 9);
SET_TEX_BINDING("texSInt2DMS", 10);
SET_TEX_BINDING("texSInt2DMSArray", 11);
SET_TEX_BINDING("tex1D", 1);
SET_TEX_BINDING("tex2D", 2);
@@ -274,6 +276,7 @@ void GLReplay::ConfigureTexDisplayProgramBindings(GLuint program)
SET_TEX_BINDING("tex2DRect", 8);
SET_TEX_BINDING("texBuffer", 9);
SET_TEX_BINDING("tex2DMS", 10);
SET_TEX_BINDING("tex2DMSArray", 11);
#undef SET_TEX_BINDING
}
@@ -1303,6 +1306,7 @@ bool GLReplay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, uin
// fall through
case eGL_TEXTURE_2D: texSlot = RESTYPE_TEX2D; break;
case eGL_TEXTURE_2D_MULTISAMPLE: texSlot = RESTYPE_TEX2DMS; break;
case eGL_TEXTURE_2D_MULTISAMPLE_ARRAY: texSlot = RESTYPE_TEX2DMSARRAY; break;
case eGL_TEXTURE_RECTANGLE: texSlot = RESTYPE_TEXRECT; break;
case eGL_TEXTURE_BUFFER: texSlot = RESTYPE_TEXBUFFER; break;
case eGL_TEXTURE_3D: texSlot = RESTYPE_TEX3D; break;
@@ -1526,6 +1530,7 @@ bool GLReplay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mip,
// fall through
case eGL_TEXTURE_2D: texSlot = RESTYPE_TEX2D; break;
case eGL_TEXTURE_2D_MULTISAMPLE: texSlot = RESTYPE_TEX2DMS; break;
case eGL_TEXTURE_2D_MULTISAMPLE_ARRAY: texSlot = RESTYPE_TEX2DMSARRAY; break;
case eGL_TEXTURE_RECTANGLE: texSlot = RESTYPE_TEXRECT; break;
case eGL_TEXTURE_BUFFER: texSlot = RESTYPE_TEXBUFFER; break;
case eGL_TEXTURE_3D: texSlot = RESTYPE_TEX3D; break;
+3 -1
View File
@@ -70,6 +70,7 @@ bool GLReplay::RenderTextureInternal(TextureDisplay cfg, int flags)
// fall through
case eGL_TEXTURE_2D: resType = RESTYPE_TEX2D; break;
case eGL_TEXTURE_2D_MULTISAMPLE: resType = RESTYPE_TEX2DMS; break;
case eGL_TEXTURE_2D_MULTISAMPLE_ARRAY: resType = RESTYPE_TEX2DMSARRAY; break;
case eGL_TEXTURE_RECTANGLE: resType = RESTYPE_TEXRECT; break;
case eGL_TEXTURE_BUFFER: resType = RESTYPE_TEXBUFFER; break;
case eGL_TEXTURE_3D: resType = RESTYPE_TEX3D; break;
@@ -295,7 +296,8 @@ bool GLReplay::RenderTextureInternal(TextureDisplay cfg, int flags)
}
else
{
if(resType == RESTYPE_TEXRECT || resType == RESTYPE_TEX2DMS || resType == RESTYPE_TEXBUFFER)
if(resType == RESTYPE_TEXRECT || resType == RESTYPE_TEX2DMS ||
resType == RESTYPE_TEX2DMSARRAY || resType == RESTYPE_TEXBUFFER)
mode = TextureSamplerMode::PointNoMip;
else
mode = TextureSamplerMode::Point;
+1 -1
View File
@@ -1804,7 +1804,7 @@ void VulkanReplay::TextureRendering::Init(WrappedVulkan *driver, VkDescriptorPoo
VkFormat formats[] = {VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UINT, VK_FORMAT_R8G8B8A8_SINT};
VkImageType types[] = {VK_IMAGE_TYPE_1D, VK_IMAGE_TYPE_2D, VK_IMAGE_TYPE_3D, VK_IMAGE_TYPE_2D};
VkImageViewType viewtypes[] = {VK_IMAGE_VIEW_TYPE_1D_ARRAY, VK_IMAGE_VIEW_TYPE_2D_ARRAY,
VK_IMAGE_VIEW_TYPE_3D, VK_IMAGE_VIEW_TYPE_2D};
VK_IMAGE_VIEW_TYPE_3D, VK_IMAGE_VIEW_TYPE_2D_ARRAY};
VkSampleCountFlagBits sampleCounts[] = {VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT,
VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_4_BIT};