summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-11-07 08:34:35 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-11-07 08:34:35 +0000
commitbc359543f2023a325957cdff9153eee11c2af501 (patch)
treec04fbcd7821341748ee8ca3bcc14591af2c88267 /Graphics
parentFixed clang warning (diff)
downloadDiligentCore-bc359543f2023a325957cdff9153eee11c2af501.tar.gz
DiligentCore-bc359543f2023a325957cdff9153eee11c2af501.zip
BLASTriangleDesc: fixed VertexValueType and VertexComponentCount handling
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/interface/BottomLevelAS.h15
-rw-r--r--Graphics/GraphicsEngine/src/BottomLevelASBase.cpp9
-rw-r--r--Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp38
3 files changed, 43 insertions, 19 deletions
diff --git a/Graphics/GraphicsEngine/interface/BottomLevelAS.h b/Graphics/GraphicsEngine/interface/BottomLevelAS.h
index c93319da..be9eb0c1 100644
--- a/Graphics/GraphicsEngine/interface/BottomLevelAS.h
+++ b/Graphics/GraphicsEngine/interface/BottomLevelAS.h
@@ -58,19 +58,14 @@ struct BLASTriangleDesc
Uint32 MaxVertexCount DEFAULT_INITIALIZER(0);
/// The type of vertices in this geometry, see Diligent::VALUE_TYPE.
-
- /// \remarks Only the following combinations of VertexValueType and VertexComponentCount
- /// are allowed:
- /// * FLOAT32 x 2 (third component is assumed 0)
- /// * FLOAT32 x 3
- /// * FLOAT16 x 2 (third component is assumed 0)
- /// * FLOAT16 x 4 (fourth component is ignored)
- /// * INT16 x 2 (16-bit signed-normalized, third component is assumed 0)
- /// * INT16 x 4 (16-bit signed-normalized, fourth component is ignored)
+ ///
+ /// \remarks Only the following values are allowed: VT_FLOAT32, VT_FLOAT16, VT_INT16.
+ /// VT_INT16 defines 16-bit signed normalized vertex components.
VALUE_TYPE VertexValueType DEFAULT_INITIALIZER(VT_UNDEFINED);
/// The number of components in the vertex.
- /// See VertexValueType for the list of allowed VertexValueType and VertexComponentCount combinations.
+ ///
+ /// \remarks Only 2 or 3 are allowed values. For 2-component formats, the third component is assumed 0.
Uint8 VertexComponentCount DEFAULT_INITIALIZER(0);
/// The maximum primitive count in this geometry.
diff --git a/Graphics/GraphicsEngine/src/BottomLevelASBase.cpp b/Graphics/GraphicsEngine/src/BottomLevelASBase.cpp
index c0e8f058..1059f451 100644
--- a/Graphics/GraphicsEngine/src/BottomLevelASBase.cpp
+++ b/Graphics/GraphicsEngine/src/BottomLevelASBase.cpp
@@ -63,11 +63,12 @@ void ValidateBottomLevelASDesc(const BottomLevelASDesc& Desc) noexcept(false)
if (tri.GeometryName == nullptr)
LOG_BLAS_ERROR_AND_THROW("pTriangles[", i, "].GeometryName must not be null");
- if (!((tri.VertexValueType == VT_FLOAT32 && (tri.VertexComponentCount == 2 || tri.VertexComponentCount == 3)) ||
- (tri.VertexValueType == VT_FLOAT16 && (tri.VertexComponentCount == 2 || tri.VertexComponentCount == 4)) ||
- (tri.VertexValueType == VT_INT16 && (tri.VertexComponentCount == 2 || tri.VertexComponentCount == 4))))
+ if (tri.VertexValueType != VT_FLOAT32 && tri.VertexValueType != VT_FLOAT16 && tri.VertexValueType != VT_INT16)
LOG_BLAS_ERROR_AND_THROW("pTriangles[", i, "].VertexValueType (", GetValueTypeString(tri.VertexValueType),
- ") and .VertexComponentCount (", tri.VertexComponentCount, ") is not a valid combination");
+ ") is invalid. Only the following values are allowed: VT_FLOAT32, VT_FLOAT16, VT_INT16");
+
+ if (tri.VertexComponentCount != 2 && tri.VertexComponentCount != 3)
+ LOG_BLAS_ERROR_AND_THROW("pTriangles[", i, "].VertexComponentCount (", tri.VertexComponentCount, ") is invalid. Only 2 or 3 are allowed.");
if (tri.MaxVertexCount == 0)
LOG_BLAS_ERROR_AND_THROW("pTriangles[", i, "].MaxVertexCount must be greater than 0");
diff --git a/Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp
index 5bb182dc..1aecb097 100644
--- a/Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/BottomLevelASD3D12Impl.cpp
@@ -76,11 +76,39 @@ BottomLevelASD3D12Impl::BottomLevelASD3D12Impl(IReferenceCounters* pRef
// * DXGI_FORMAT_R16G16B16A16_FLOAT - A16 component is ignored, other data can be packed there, such as setting vertex stride to 6 bytes.
// * DXGI_FORMAT_R16G16_SNORM - third component is assumed 0
// * DXGI_FORMAT_R16G16B16A16_SNORM - A16 component is ignored, other data can be packed there, such as setting vertex stride to 6 bytes.
- dst.Triangles.VertexFormat = TypeToDXGI_Format(src.VertexValueType, src.VertexComponentCount, src.VertexValueType < VT_FLOAT16);
- VERIFY(dst.Triangles.VertexFormat == DXGI_FORMAT_R32G32_FLOAT || dst.Triangles.VertexFormat == DXGI_FORMAT_R32G32B32_FLOAT ||
- dst.Triangles.VertexFormat == DXGI_FORMAT_R16G16_FLOAT || dst.Triangles.VertexFormat == DXGI_FORMAT_R16G16B16A16_FLOAT ||
- dst.Triangles.VertexFormat == DXGI_FORMAT_R16G16_SNORM || dst.Triangles.VertexFormat == DXGI_FORMAT_R16G16B16A16_SNORM,
- "Unsupported vertex format");
+ // Note that DXGI_FORMAT_R16G16B16A16_FLOAT and DXGI_FORMAT_R16G16B16A16_SNORM are workarounds for missing 16-bit 3-component DXGI formats
+ switch (src.VertexValueType)
+ {
+ case VT_FLOAT16:
+ switch (src.VertexComponentCount)
+ {
+ case 2: dst.Triangles.VertexFormat = DXGI_FORMAT_R16G16_FLOAT; break;
+ case 3: dst.Triangles.VertexFormat = DXGI_FORMAT_R16G16B16A16_FLOAT; break;
+ default: UNEXPECTED("Only 2 and 3 component vertex formats are expected");
+ }
+ break;
+
+ case VT_FLOAT32:
+ switch (src.VertexComponentCount)
+ {
+ case 2: dst.Triangles.VertexFormat = DXGI_FORMAT_R32G32_FLOAT; break;
+ case 3: dst.Triangles.VertexFormat = DXGI_FORMAT_R32G32B32_FLOAT; break;
+ default: UNEXPECTED("Only 2 and 3 component vertex formats are expected");
+ }
+ break;
+
+ case VT_INT16:
+ switch (src.VertexComponentCount)
+ {
+ case 2: dst.Triangles.VertexFormat = DXGI_FORMAT_R16G16_SNORM; break;
+ case 3: dst.Triangles.VertexFormat = DXGI_FORMAT_R16G16B16A16_SNORM; break;
+ default: UNEXPECTED("Only 2 and 3 component vertex formats are expected");
+ }
+ break;
+
+ default:
+ UNEXPECTED(GetValueTypeString(src.VertexValueType), " is not a valid vertex component type");
+ }
dst.Triangles.VertexCount = src.MaxVertexCount;
dst.Triangles.IndexCount = src.IndexType == VT_UNDEFINED ? 0 : src.MaxPrimitiveCount * 3;