rhi: add support for short and ushort vertex attributes
[ChangeLog][RHI] Add support for short and ushort vertex attributes Change-Id: I6111a02d442bbad2ec9667ac0336107dd3ab7b62 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>bb10
parent
f70e113b2e
commit
803abb6323
|
|
@ -1672,12 +1672,22 @@ QDebug operator<<(QDebug dbg, const QRhiVertexInputBinding &b)
|
|||
\value Half3 Three component half precision (16 bit) float vector
|
||||
\value Half2 Two component half precision (16 bit) float vector
|
||||
\value Half Half precision (16 bit) float
|
||||
\value UShort4 Four component unsigned short (16 bit) integer vector
|
||||
\value UShort3 Three component unsigned short (16 bit) integer vector
|
||||
\value UShort2 Two component unsigned short (16 bit) integer vector
|
||||
\value UShort Unsigned short (16 bit) integer
|
||||
\value SShort4 Four component signed short (16 bit) integer vector
|
||||
\value SShort3 Three component signed short (16 bit) integer vector
|
||||
\value SShort2 Two component signed short (16 bit) integer vector
|
||||
\value SShort Signed short (16 bit) integer
|
||||
|
||||
\note Support for half precision floating point attributes is indicated at
|
||||
run time by the QRhi::Feature::HalfAttributes feature flag. Note that
|
||||
Direct3D 11/12 supports half input attributes, but does not support the
|
||||
Half3 type. The D3D backends pass through Half3 as Half4. To ensure cross
|
||||
platform compatibility, Half3 inputs should be padded to 8 bytes.
|
||||
run time by the QRhi::Feature::HalfAttributes feature flag.
|
||||
|
||||
\note Direct3D 11/12 supports 16 bit input attributes, but does not support
|
||||
the Half3, UShort3 or SShort3 types. The D3D backends pass through Half3 as
|
||||
Half4, UShort3 as UShort4, and SShort3 as SShort4. To ensure cross platform
|
||||
compatibility, 16 bit inputs should be padded to 8 bytes.
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
|
@ -1889,6 +1899,24 @@ quint32 QRhiImplementation::byteSizePerVertexForVertexInputFormat(QRhiVertexInpu
|
|||
case QRhiVertexInputAttribute::Half:
|
||||
return sizeof(qfloat16);
|
||||
|
||||
case QRhiVertexInputAttribute::UShort4:
|
||||
return 4 * sizeof(quint16);
|
||||
case QRhiVertexInputAttribute::UShort3:
|
||||
return 4 * sizeof(quint16); // ivec3 still takes 8 bytes
|
||||
case QRhiVertexInputAttribute::UShort2:
|
||||
return 2 * sizeof(quint16);
|
||||
case QRhiVertexInputAttribute::UShort:
|
||||
return sizeof(quint16);
|
||||
|
||||
case QRhiVertexInputAttribute::SShort4:
|
||||
return 4 * sizeof(qint16);
|
||||
case QRhiVertexInputAttribute::SShort3:
|
||||
return 4 * sizeof(qint16); // uvec3 still takes 8 bytes
|
||||
case QRhiVertexInputAttribute::SShort2:
|
||||
return 2 * sizeof(qint16);
|
||||
case QRhiVertexInputAttribute::SShort:
|
||||
return sizeof(qint16);
|
||||
|
||||
default:
|
||||
Q_UNREACHABLE_RETURN(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,7 +250,15 @@ public:
|
|||
Half4,
|
||||
Half3,
|
||||
Half2,
|
||||
Half
|
||||
Half,
|
||||
UShort4,
|
||||
UShort3,
|
||||
UShort2,
|
||||
UShort,
|
||||
SShort4,
|
||||
SShort3,
|
||||
SShort2,
|
||||
SShort,
|
||||
};
|
||||
|
||||
QRhiVertexInputAttribute() = default;
|
||||
|
|
|
|||
|
|
@ -4214,6 +4214,22 @@ static inline DXGI_FORMAT toD3DAttributeFormat(QRhiVertexInputAttribute::Format
|
|||
return DXGI_FORMAT_R16G16_FLOAT;
|
||||
case QRhiVertexInputAttribute::Half:
|
||||
return DXGI_FORMAT_R16_FLOAT;
|
||||
case QRhiVertexInputAttribute::UShort4:
|
||||
// Note: D3D does not support UShort3. Pass through UShort3 as UShort4.
|
||||
case QRhiVertexInputAttribute::UShort3:
|
||||
return DXGI_FORMAT_R16G16B16A16_UINT;
|
||||
case QRhiVertexInputAttribute::UShort2:
|
||||
return DXGI_FORMAT_R16G16_UINT;
|
||||
case QRhiVertexInputAttribute::UShort:
|
||||
return DXGI_FORMAT_R16_UINT;
|
||||
case QRhiVertexInputAttribute::SShort4:
|
||||
// Note: D3D does not support SShort3. Pass through SShort3 as SShort4.
|
||||
case QRhiVertexInputAttribute::SShort3:
|
||||
return DXGI_FORMAT_R16G16B16A16_SINT;
|
||||
case QRhiVertexInputAttribute::SShort2:
|
||||
return DXGI_FORMAT_R16G16_SINT;
|
||||
case QRhiVertexInputAttribute::SShort:
|
||||
return DXGI_FORMAT_R16_SINT;
|
||||
default:
|
||||
Q_UNREACHABLE();
|
||||
return DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||
|
|
|
|||
|
|
@ -5490,6 +5490,22 @@ static inline DXGI_FORMAT toD3DAttributeFormat(QRhiVertexInputAttribute::Format
|
|||
return DXGI_FORMAT_R16G16_FLOAT;
|
||||
case QRhiVertexInputAttribute::Half:
|
||||
return DXGI_FORMAT_R16_FLOAT;
|
||||
case QRhiVertexInputAttribute::UShort4:
|
||||
// Note: D3D does not support UShort3. Pass through UShort3 as UShort4.
|
||||
case QRhiVertexInputAttribute::UShort3:
|
||||
return DXGI_FORMAT_R16G16B16A16_UINT;
|
||||
case QRhiVertexInputAttribute::UShort2:
|
||||
return DXGI_FORMAT_R16G16_UINT;
|
||||
case QRhiVertexInputAttribute::UShort:
|
||||
return DXGI_FORMAT_R16_UINT;
|
||||
case QRhiVertexInputAttribute::SShort4:
|
||||
// Note: D3D does not support SShort3. Pass through SShort3 as SShort4.
|
||||
case QRhiVertexInputAttribute::SShort3:
|
||||
return DXGI_FORMAT_R16G16B16A16_SINT;
|
||||
case QRhiVertexInputAttribute::SShort2:
|
||||
return DXGI_FORMAT_R16G16_SINT;
|
||||
case QRhiVertexInputAttribute::SShort:
|
||||
return DXGI_FORMAT_R16_SINT;
|
||||
}
|
||||
Q_UNREACHABLE_RETURN(DXGI_FORMAT_R32G32B32A32_FLOAT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3089,6 +3089,38 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
|
|||
type = GL_HALF_FLOAT;
|
||||
size = 1;
|
||||
break;
|
||||
case QRhiVertexInputAttribute::UShort4:
|
||||
type = GL_UNSIGNED_SHORT;
|
||||
size = 4;
|
||||
break;
|
||||
case QRhiVertexInputAttribute::UShort3:
|
||||
type = GL_UNSIGNED_SHORT;
|
||||
size = 3;
|
||||
break;
|
||||
case QRhiVertexInputAttribute::UShort2:
|
||||
type = GL_UNSIGNED_SHORT;
|
||||
size = 2;
|
||||
break;
|
||||
case QRhiVertexInputAttribute::UShort:
|
||||
type = GL_UNSIGNED_SHORT;
|
||||
size = 1;
|
||||
break;
|
||||
case QRhiVertexInputAttribute::SShort4:
|
||||
type = GL_SHORT;
|
||||
size = 4;
|
||||
break;
|
||||
case QRhiVertexInputAttribute::SShort3:
|
||||
type = GL_SHORT;
|
||||
size = 3;
|
||||
break;
|
||||
case QRhiVertexInputAttribute::SShort2:
|
||||
type = GL_SHORT;
|
||||
size = 2;
|
||||
break;
|
||||
case QRhiVertexInputAttribute::SShort:
|
||||
type = GL_SHORT;
|
||||
size = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4430,6 +4430,22 @@ static inline MTLVertexFormat toMetalAttributeFormat(QRhiVertexInputAttribute::F
|
|||
return MTLVertexFormatHalf2;
|
||||
case QRhiVertexInputAttribute::Half:
|
||||
return MTLVertexFormatHalf;
|
||||
case QRhiVertexInputAttribute::UShort4:
|
||||
return MTLVertexFormatUShort4;
|
||||
case QRhiVertexInputAttribute::UShort3:
|
||||
return MTLVertexFormatUShort3;
|
||||
case QRhiVertexInputAttribute::UShort2:
|
||||
return MTLVertexFormatUShort2;
|
||||
case QRhiVertexInputAttribute::UShort:
|
||||
return MTLVertexFormatUShort;
|
||||
case QRhiVertexInputAttribute::SShort4:
|
||||
return MTLVertexFormatShort4;
|
||||
case QRhiVertexInputAttribute::SShort3:
|
||||
return MTLVertexFormatShort3;
|
||||
case QRhiVertexInputAttribute::SShort2:
|
||||
return MTLVertexFormatShort2;
|
||||
case QRhiVertexInputAttribute::SShort:
|
||||
return MTLVertexFormatShort;
|
||||
default:
|
||||
Q_UNREACHABLE();
|
||||
return MTLVertexFormatFloat4;
|
||||
|
|
|
|||
|
|
@ -5616,6 +5616,22 @@ static inline VkFormat toVkAttributeFormat(QRhiVertexInputAttribute::Format form
|
|||
return VK_FORMAT_R16G16_SFLOAT;
|
||||
case QRhiVertexInputAttribute::Half:
|
||||
return VK_FORMAT_R16_SFLOAT;
|
||||
case QRhiVertexInputAttribute::UShort4:
|
||||
return VK_FORMAT_R16G16B16A16_UINT;
|
||||
case QRhiVertexInputAttribute::UShort3:
|
||||
return VK_FORMAT_R16G16B16_UINT;
|
||||
case QRhiVertexInputAttribute::UShort2:
|
||||
return VK_FORMAT_R16G16_UINT;
|
||||
case QRhiVertexInputAttribute::UShort:
|
||||
return VK_FORMAT_R16_UINT;
|
||||
case QRhiVertexInputAttribute::SShort4:
|
||||
return VK_FORMAT_R16G16B16A16_SINT;
|
||||
case QRhiVertexInputAttribute::SShort3:
|
||||
return VK_FORMAT_R16G16B16_SINT;
|
||||
case QRhiVertexInputAttribute::SShort2:
|
||||
return VK_FORMAT_R16G16_SINT;
|
||||
case QRhiVertexInputAttribute::SShort:
|
||||
return VK_FORMAT_R16_SINT;
|
||||
default:
|
||||
Q_UNREACHABLE_RETURN(VK_FORMAT_R32G32B32A32_SFLOAT);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue