Skip to content

Commit

Permalink
Add UShort1 and UShort3 Normalized Vertex Attribute Format
Browse files Browse the repository at this point in the history
Summary: Supported in underlying libraries but missing in IGL spec

Reviewed By: corporateshark

Differential Revision: D50658968

fbshipit-source-id: 86119fb983a3d08a57a16e371e9d2c2088c7906c
  • Loading branch information
MetaAndre authored and facebook-github-bot committed Oct 26, 2023
1 parent 9306948 commit 834d756
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/igl/VertexInputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ size_t VertexInputStateDesc::sizeForVertexAttributeFormat(VertexAttributeFormat
return sizeof(int16_t[4]);

case VertexAttributeFormat::UShort1:
case VertexAttributeFormat::UShort1Norm:
return sizeof(uint16_t);

case VertexAttributeFormat::UShort2:
case VertexAttributeFormat::UShort2Norm:
return sizeof(uint16_t[2]);

case VertexAttributeFormat::UShort3:
case VertexAttributeFormat::UShort3Norm:
return sizeof(uint16_t[3]);

case VertexAttributeFormat::UShort4:
Expand Down
2 changes: 2 additions & 0 deletions src/igl/VertexInputState.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ enum class VertexAttributeFormat {
Short3Norm,
Short4Norm,

UShort1Norm,
UShort2Norm,
UShort3Norm,
UShort4Norm,

Int1,
Expand Down
4 changes: 4 additions & 0 deletions src/igl/metal/VertexInputState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@
case VertexAttributeFormat::Short4Norm:
return MTLVertexFormatShort4Normalized;

case VertexAttributeFormat::UShort1Norm:
return MTLVertexFormatUShortNormalized;
case VertexAttributeFormat::UShort2Norm:
return MTLVertexFormatUShort2Normalized;
case VertexAttributeFormat::UShort3Norm:
return MTLVertexFormatUShort3Normalized;
case VertexAttributeFormat::UShort4Norm:
return MTLVertexFormatUShort4Normalized;

Expand Down
12 changes: 12 additions & 0 deletions src/igl/opengl/VertexInputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,24 @@ static void toOGLAttribute(const VertexAttribute& attrib,
normalized = GL_TRUE;
break;

case VertexAttributeFormat::UShort1Norm:
numComponents = 1;
componentType = GL_UNSIGNED_SHORT;
normalized = GL_TRUE;
break;

case VertexAttributeFormat::UShort2Norm:
numComponents = 2;
componentType = GL_UNSIGNED_SHORT;
normalized = GL_TRUE;
break;

case VertexAttributeFormat::UShort3Norm:
numComponents = 3;
componentType = GL_UNSIGNED_SHORT;
normalized = GL_TRUE;
break;

case VertexAttributeFormat::UShort4Norm:
numComponents = 4;
componentType = GL_UNSIGNED_SHORT;
Expand Down
4 changes: 4 additions & 0 deletions src/igl/tests/VertexInputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ TEST_F(VertexInputStateTest, VertexAttributeSizes) {
VertexInputStateDesc::sizeForVertexAttributeFormat(VertexAttributeFormat::Short3Norm));
ASSERT_EQ(8,
VertexInputStateDesc::sizeForVertexAttributeFormat(VertexAttributeFormat::Short4Norm));
ASSERT_EQ(2,
VertexInputStateDesc::sizeForVertexAttributeFormat(VertexAttributeFormat::UShort1Norm));
ASSERT_EQ(4,
VertexInputStateDesc::sizeForVertexAttributeFormat(VertexAttributeFormat::UShort2Norm));
ASSERT_EQ(6,
VertexInputStateDesc::sizeForVertexAttributeFormat(VertexAttributeFormat::UShort3Norm));
ASSERT_EQ(8,
VertexInputStateDesc::sizeForVertexAttributeFormat(VertexAttributeFormat::UShort4Norm));
ASSERT_EQ(2,
Expand Down
6 changes: 6 additions & 0 deletions src/igl/tests/metal/VertexInputState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,15 @@ void TearDown() override {}
ASSERT_EQ(igl::metal::VertexInputState::convertAttributeFormat(VertexAttributeFormat::Short4Norm),
MTLVertexFormatShort4Normalized);

ASSERT_EQ(
igl::metal::VertexInputState::convertAttributeFormat(VertexAttributeFormat::UShort1Norm),
MTLVertexFormatUShortNormalized);
ASSERT_EQ(
igl::metal::VertexInputState::convertAttributeFormat(VertexAttributeFormat::UShort2Norm),
MTLVertexFormatUShort2Normalized);
ASSERT_EQ(
igl::metal::VertexInputState::convertAttributeFormat(VertexAttributeFormat::UShort3Norm),
MTLVertexFormatUShort3Normalized);
ASSERT_EQ(
igl::metal::VertexInputState::convertAttributeFormat(VertexAttributeFormat::UShort4Norm),
MTLVertexFormatUShort4Normalized);
Expand Down
4 changes: 4 additions & 0 deletions src/igl/vulkan/RenderPipelineState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ VkFormat vertexAttributeFormatToVkFormat(igl::VertexAttributeFormat fmt) {
return VK_FORMAT_R16G16B16_SNORM;
case VertexAttributeFormat::Short4Norm:
return VK_FORMAT_R16G16B16A16_SNORM;
case VertexAttributeFormat::UShort1Norm:
return VK_FORMAT_R16_UNORM;
case VertexAttributeFormat::UShort2Norm:
return VK_FORMAT_R16G16_UNORM;
case VertexAttributeFormat::UShort3Norm:
return VK_FORMAT_R16G16B16_UNORM;
case VertexAttributeFormat::UShort4Norm:
return VK_FORMAT_R16G16B16A16_UNORM;
// Integer formats
Expand Down

0 comments on commit 834d756

Please sign in to comment.