Support signed integer attributes on QRHI

Previous UIntAttributes feature is renamed as IntAttributes.

Change-Id: I4b4a87a0eebf37291da832605f7bee8fb2d4e62b
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Inho Lee 2020-09-16 14:38:58 +02:00
parent 0148c6925e
commit 2a7d6e2779
7 changed files with 71 additions and 19 deletions

View File

@ -591,12 +591,12 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
unsupported with OpenGL ES 2.0, while it will likely be supported everywhere unsupported with OpenGL ES 2.0, while it will likely be supported everywhere
else. else.
\value UIntAttributes Indicates that specifying input attributes with an unsigned \value IntAttributes Indicates that specifying input attributes with
integer type for a shader pipeline is supported. When not supported, build() signed and unsigned integer types for a shader pipeline is supported. When
will succeed but just show a warning message and the values of unsigned int not supported, build() will succeed but just show a warning message and the
type attributes will be broken. In practice this feature will be unsupported values of the target attributes will be broken. In practice this feature
with OpenGL ES 2.0 and OpenGL 2.x, while it will likely be supported will be unsupported with OpenGL ES 2.0 and OpenGL 2.x, while it will likely
everywhere else. be supported everywhere else.
\value ScreenSpaceDerivatives Indicates that functions such as dFdx(), \value ScreenSpaceDerivatives Indicates that functions such as dFdx(),
dFdy(), and fwidth() are supported in shaders. dFdy(), and fwidth() are supported in shaders.
@ -1188,6 +1188,14 @@ QDebug operator<<(QDebug dbg, const QRhiVertexInputBinding &b)
\value UNormByte4 Four component normalized unsigned byte vector \value UNormByte4 Four component normalized unsigned byte vector
\value UNormByte2 Two component normalized unsigned byte vector \value UNormByte2 Two component normalized unsigned byte vector
\value UNormByte Normalized unsigned byte \value UNormByte Normalized unsigned byte
\value UInt4 Four component unsigned integer vector
\value UInt3 Three component unsigned integer vector
\value UInt2 Two component unsigned integer vector
\value UInt Unsigned integer
\value SInt4 Four component signed integer vector
\value SInt3 Three component signed integer vector
\value SInt2 Two component signed integer vector
\value SInt Signed integer
*/ */
/*! /*!

View File

@ -204,7 +204,11 @@ public:
UInt4, UInt4,
UInt3, UInt3,
UInt2, UInt2,
UInt UInt,
SInt4,
SInt3,
SInt2,
SInt
}; };
QRhiVertexInputAttribute() = default; QRhiVertexInputAttribute() = default;
@ -1470,7 +1474,7 @@ public:
ReadBackNonBaseMipLevel, ReadBackNonBaseMipLevel,
TexelFetch, TexelFetch,
RenderToNonBaseMipLevel, RenderToNonBaseMipLevel,
UIntAttributes, IntAttributes,
ScreenSpaceDerivatives, ScreenSpaceDerivatives,
ReadBackAnyTextureFormat ReadBackAnyTextureFormat
}; };

View File

@ -525,7 +525,7 @@ bool QRhiD3D11::isFeatureSupported(QRhi::Feature feature) const
return true; return true;
case QRhi::RenderToNonBaseMipLevel: case QRhi::RenderToNonBaseMipLevel:
return true; return true;
case QRhi::UIntAttributes: case QRhi::IntAttributes:
return true; return true;
case QRhi::ScreenSpaceDerivatives: case QRhi::ScreenSpaceDerivatives:
return true; return true;
@ -3591,6 +3591,14 @@ static inline DXGI_FORMAT toD3DAttributeFormat(QRhiVertexInputAttribute::Format
return DXGI_FORMAT_R32G32_UINT; return DXGI_FORMAT_R32G32_UINT;
case QRhiVertexInputAttribute::UInt: case QRhiVertexInputAttribute::UInt:
return DXGI_FORMAT_R32_UINT; return DXGI_FORMAT_R32_UINT;
case QRhiVertexInputAttribute::SInt4:
return DXGI_FORMAT_R32G32B32A32_SINT;
case QRhiVertexInputAttribute::SInt3:
return DXGI_FORMAT_R32G32B32_SINT;
case QRhiVertexInputAttribute::SInt2:
return DXGI_FORMAT_R32G32_SINT;
case QRhiVertexInputAttribute::SInt:
return DXGI_FORMAT_R32_SINT;
default: default:
Q_UNREACHABLE(); Q_UNREACHABLE();
return DXGI_FORMAT_R32G32B32A32_FLOAT; return DXGI_FORMAT_R32G32B32A32_FLOAT;

View File

@ -553,7 +553,7 @@ bool QRhiGles2::create(QRhi::Flags flags)
caps.nonBaseLevelFramebufferTexture = true; caps.nonBaseLevelFramebufferTexture = true;
caps.texelFetch = caps.ctxMajor >= 3; // 3.0 or ES 3.0 caps.texelFetch = caps.ctxMajor >= 3; // 3.0 or ES 3.0
caps.uintAttributes = caps.ctxMajor >= 3; // 3.0 or ES 3.0 caps.intAttributes = caps.ctxMajor >= 3; // 3.0 or ES 3.0
caps.screenSpaceDerivatives = f->hasOpenGLExtension(QOpenGLExtensions::StandardDerivatives); caps.screenSpaceDerivatives = f->hasOpenGLExtension(QOpenGLExtensions::StandardDerivatives);
// TO DO: We could also check for ARB_texture_multisample but it is not // TO DO: We could also check for ARB_texture_multisample but it is not
@ -928,8 +928,8 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
return caps.texelFetch; return caps.texelFetch;
case QRhi::RenderToNonBaseMipLevel: case QRhi::RenderToNonBaseMipLevel:
return caps.nonBaseLevelFramebufferTexture; return caps.nonBaseLevelFramebufferTexture;
case QRhi::UIntAttributes: case QRhi::IntAttributes:
return caps.uintAttributes; return caps.intAttributes;
case QRhi::ScreenSpaceDerivatives: case QRhi::ScreenSpaceDerivatives:
return caps.screenSpaceDerivatives; return caps.screenSpaceDerivatives;
case QRhi::ReadBackAnyTextureFormat: case QRhi::ReadBackAnyTextureFormat:
@ -2253,18 +2253,34 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
type = GL_UNSIGNED_INT; type = GL_UNSIGNED_INT;
size = 1; size = 1;
break; break;
case QRhiVertexInputAttribute::SInt4:
type = GL_INT;
size = 4;
break;
case QRhiVertexInputAttribute::SInt3:
type = GL_INT;
size = 3;
break;
case QRhiVertexInputAttribute::SInt2:
type = GL_INT;
size = 2;
break;
case QRhiVertexInputAttribute::SInt:
type = GL_INT;
size = 1;
break;
default: default:
break; break;
} }
const int locationIdx = it->location(); const int locationIdx = it->location();
quint32 ofs = it->offset() + cmd.args.bindVertexBuffer.offset; quint32 ofs = it->offset() + cmd.args.bindVertexBuffer.offset;
if (type == GL_UNSIGNED_INT) { if (type == GL_UNSIGNED_INT || type == GL_INT) {
if (caps.uintAttributes) { if (caps.intAttributes) {
f->glVertexAttribIPointer(GLuint(locationIdx), size, type, stride, f->glVertexAttribIPointer(GLuint(locationIdx), size, type, stride,
reinterpret_cast<const GLvoid *>(quintptr(ofs))); reinterpret_cast<const GLvoid *>(quintptr(ofs)));
} else { } else {
qWarning("Current RHI backend does not support UIntAttributes. Check supported features."); qWarning("Current RHI backend does not support IntAttributes. Check supported features.");
// This is a trick to disable this attribute // This is a trick to disable this attribute
if (locationIdx < TRACKED_ATTRIB_COUNT) if (locationIdx < TRACKED_ATTRIB_COUNT)
enabledAttribArrays[locationIdx] = true; enabledAttribArrays[locationIdx] = true;

View File

@ -880,7 +880,7 @@ public:
properMapBuffer(false), properMapBuffer(false),
nonBaseLevelFramebufferTexture(false), nonBaseLevelFramebufferTexture(false),
texelFetch(false), texelFetch(false),
uintAttributes(true), intAttributes(true),
screenSpaceDerivatives(false) screenSpaceDerivatives(false)
{ } { }
int ctxMajor; int ctxMajor;
@ -921,7 +921,7 @@ public:
uint properMapBuffer : 1; uint properMapBuffer : 1;
uint nonBaseLevelFramebufferTexture : 1; uint nonBaseLevelFramebufferTexture : 1;
uint texelFetch : 1; uint texelFetch : 1;
uint uintAttributes : 1; uint intAttributes : 1;
uint screenSpaceDerivatives : 1; uint screenSpaceDerivatives : 1;
} caps; } caps;
QGles2SwapChain *currentSwapChain = nullptr; QGles2SwapChain *currentSwapChain = nullptr;

View File

@ -562,7 +562,7 @@ bool QRhiMetal::isFeatureSupported(QRhi::Feature feature) const
return true; return true;
case QRhi::RenderToNonBaseMipLevel: case QRhi::RenderToNonBaseMipLevel:
return true; return true;
case QRhi::UIntAttributes: case QRhi::IntAttributes:
return true; return true;
case QRhi::ScreenSpaceDerivatives: case QRhi::ScreenSpaceDerivatives:
return true; return true;
@ -3090,6 +3090,14 @@ static inline MTLVertexFormat toMetalAttributeFormat(QRhiVertexInputAttribute::F
return MTLVertexFormatUInt2; return MTLVertexFormatUInt2;
case QRhiVertexInputAttribute::UInt: case QRhiVertexInputAttribute::UInt:
return MTLVertexFormatUInt; return MTLVertexFormatUInt;
case QRhiVertexInputAttribute::SInt4:
return MTLVertexFormatInt4;
case QRhiVertexInputAttribute::SInt3:
return MTLVertexFormatInt3;
case QRhiVertexInputAttribute::SInt2:
return MTLVertexFormatInt2;
case QRhiVertexInputAttribute::SInt:
return MTLVertexFormatInt;
default: default:
Q_UNREACHABLE(); Q_UNREACHABLE();
return MTLVertexFormatFloat4; return MTLVertexFormatFloat4;

View File

@ -4099,7 +4099,7 @@ bool QRhiVulkan::isFeatureSupported(QRhi::Feature feature) const
return true; return true;
case QRhi::RenderToNonBaseMipLevel: case QRhi::RenderToNonBaseMipLevel:
return true; return true;
case QRhi::UIntAttributes: case QRhi::IntAttributes:
return true; return true;
case QRhi::ScreenSpaceDerivatives: case QRhi::ScreenSpaceDerivatives:
return true; return true;
@ -4958,6 +4958,14 @@ static inline VkFormat toVkAttributeFormat(QRhiVertexInputAttribute::Format form
return VK_FORMAT_R32G32_UINT; return VK_FORMAT_R32G32_UINT;
case QRhiVertexInputAttribute::UInt: case QRhiVertexInputAttribute::UInt:
return VK_FORMAT_R32_UINT; return VK_FORMAT_R32_UINT;
case QRhiVertexInputAttribute::SInt4:
return VK_FORMAT_R32G32B32A32_SINT;
case QRhiVertexInputAttribute::SInt3:
return VK_FORMAT_R32G32B32_SINT;
case QRhiVertexInputAttribute::SInt2:
return VK_FORMAT_R32G32_SINT;
case QRhiVertexInputAttribute::SInt:
return VK_FORMAT_R32_SINT;
default: default:
Q_UNREACHABLE(); Q_UNREACHABLE();
return VK_FORMAT_R32G32B32A32_SFLOAT; return VK_FORMAT_R32G32B32A32_SFLOAT;