diff options
author | Aurélien Brooke <aurelien@bahiasoft.fr> | 2024-02-27 11:38:47 +0100 |
---|---|---|
committer | Aurélien Brooke <aurelien@bahiasoft.fr> | 2024-03-01 16:01:45 +0100 |
commit | 803abb6323ca7f6a8ea8041aa16d511af727f318 (patch) | |
tree | da1acc13aaefc5f018987827d52c8c8619a226ba | |
parent | f70e113b2e895fb71db4ee6fb77a91f65e2deae9 (diff) |
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>
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 36 | ||||
-rw-r--r-- | src/gui/rhi/qrhi.h | 10 | ||||
-rw-r--r-- | src/gui/rhi/qrhid3d11.cpp | 16 | ||||
-rw-r--r-- | src/gui/rhi/qrhid3d12.cpp | 16 | ||||
-rw-r--r-- | src/gui/rhi/qrhigles2.cpp | 32 | ||||
-rw-r--r-- | src/gui/rhi/qrhimetal.mm | 16 | ||||
-rw-r--r-- | src/gui/rhi/qrhivulkan.cpp | 16 |
7 files changed, 137 insertions, 5 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 60efc92527..8912eb548b 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -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); } diff --git a/src/gui/rhi/qrhi.h b/src/gui/rhi/qrhi.h index f7a49dc292..6515abdded 100644 --- a/src/gui/rhi/qrhi.h +++ b/src/gui/rhi/qrhi.h @@ -250,7 +250,15 @@ public: Half4, Half3, Half2, - Half + Half, + UShort4, + UShort3, + UShort2, + UShort, + SShort4, + SShort3, + SShort2, + SShort, }; QRhiVertexInputAttribute() = default; diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 9f13784426..3f8358b2b4 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -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; diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index 9b139d5e56..5a0219bbd6 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -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); } diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 154ace305b..23aedeb876 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -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; } diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index e02ab9a278..0c3e9dcb31 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -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; diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index 4d7b361f80..874d5a1253 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -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); } |