Skip to content

Commit

Permalink
Vertex input state check all formats
Browse files Browse the repository at this point in the history
Reviewed By: syeh1, maliarov

Differential Revision: D64200345

fbshipit-source-id: d8824a804e08b7a4067b4b1e13446429bf63d340
  • Loading branch information
Kyle Fung authored and facebook-github-bot committed Oct 10, 2024
1 parent c444118 commit 2144068
Showing 1 changed file with 136 additions and 1 deletion.
137 changes: 136 additions & 1 deletion src/igl/tests/ogl/VertexInputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

#include "../data/ShaderData.h"
#include "../util/Common.h"
#include "../util/TestDevice.h"

Expand Down Expand Up @@ -138,4 +137,140 @@ TEST_F(VertexInputStateOGLTest, TwoAttribTwoBinding) {
ASSERT_TRUE(vertexInputState != nullptr);
}

// Test creating attributes with every data format
TEST_F(VertexInputStateOGLTest, AllFormats0) {
const char SomeName[] = "Name";

constexpr size_t sizes[] = {
// float1 float2 etc
sizeof(float) * 1,
sizeof(float) * 2,
sizeof(float) * 3,
sizeof(float) * 4,
// byte1 byte2 etc
sizeof(char) * 1,
sizeof(char) * 2,
sizeof(char) * 3,
sizeof(char) * 4,
// ubyte1 ubyte2 etc
sizeof(char) * 1,
sizeof(char) * 2,
sizeof(char) * 3,
sizeof(char) * 4,
// short1 short2 etc
sizeof(short) * 1,
sizeof(short) * 2,
sizeof(short) * 3,
sizeof(short) * 4,
// ushort1 ushort2 etc
sizeof(short) * 1,
sizeof(short) * 2,
sizeof(short) * 3,
sizeof(short) * 4,
// byte1norm byte2norm etc
sizeof(char) * 1,
sizeof(char) * 2,
sizeof(char) * 3,
sizeof(char) * 4,
// uByte1Norm uByte1Norm etc
sizeof(char) * 1,
sizeof(char) * 2,
sizeof(char) * 3,
sizeof(char) * 4,
// short1Norm short2Norm etc
sizeof(short) * 1,
sizeof(short) * 2,
sizeof(short) * 3,
sizeof(short) * 4,
// ushort1norm ushort2norm etc
sizeof(short) * 1,
sizeof(short) * 2,
sizeof(short) * 3,
sizeof(short) * 4,
// int1 int2 etc
sizeof(int) * 1,
sizeof(int) * 2,
sizeof(int) * 3,
sizeof(int) * 4,
// uint1 uint2 etc
sizeof(int) * 1,
sizeof(int) * 2,
sizeof(int) * 3,
sizeof(int) * 4,
// half1 half2 etc
sizeof(uint16_t) * 1,
sizeof(uint16_t) * 2,
sizeof(uint16_t) * 3,
sizeof(uint16_t) * 4,
// Int_2_10_10_10_REV
sizeof(int),
};

// There are 49 formats, but only 24 fit inside one vertex input state so we test the 24 formats,
// the next 24, and the last format on its own
{
// First 24 formats
VertexInputStateDesc inputDesc_;
for (int i = 0; i < IGL_VERTEX_ATTRIBUTES_MAX; i++) {
inputDesc_.attributes[i].format = static_cast<VertexAttributeFormat>(i);
inputDesc_.attributes[i].offset = 0;
inputDesc_.attributes[i].location = 0;
inputDesc_.attributes[i].bufferIndex = i;
inputDesc_.attributes[i].name = SomeName;
inputDesc_.inputBindings[i].stride = sizes[i];
}

// numAttributes has to equal to bindings when using more than 1 buffer
inputDesc_.numAttributes = inputDesc_.numInputBindings = IGL_VERTEX_ATTRIBUTES_MAX;

Result ret;
std::shared_ptr<IVertexInputState> vertexInputState;
vertexInputState = iglDev_->createVertexInputState(inputDesc_, &ret);
ASSERT_EQ(ret.code, Result::Code::Ok);
ASSERT_TRUE(vertexInputState != nullptr);
}
{
// Next 24 formats
VertexInputStateDesc inputDesc_;
for (int i = 0; i < IGL_VERTEX_ATTRIBUTES_MAX; i++) {
inputDesc_.attributes[i].format =
static_cast<VertexAttributeFormat>(i + IGL_VERTEX_ATTRIBUTES_MAX);
inputDesc_.attributes[i].offset = 0;
inputDesc_.attributes[i].location = 0;
inputDesc_.attributes[i].bufferIndex = i;
inputDesc_.attributes[i].name = SomeName;
inputDesc_.inputBindings[i].stride = sizes[i + IGL_VERTEX_ATTRIBUTES_MAX];
}

// numAttributes has to equal to bindings when using more than 1 buffer
inputDesc_.numAttributes = inputDesc_.numInputBindings = IGL_VERTEX_ATTRIBUTES_MAX;

Result ret;
std::shared_ptr<IVertexInputState> vertexInputState;
vertexInputState = iglDev_->createVertexInputState(inputDesc_, &ret);
ASSERT_EQ(ret.code, Result::Code::Ok);
ASSERT_TRUE(vertexInputState != nullptr);
}
{
// Last format
VertexInputStateDesc inputDesc_;
inputDesc_.attributes[0].format = VertexAttributeFormat::Int_2_10_10_10_REV;
inputDesc_.attributes[0].offset = 0;
inputDesc_.attributes[0].location = 0;
inputDesc_.attributes[0].bufferIndex = 0;
inputDesc_.attributes[0].name = SomeName;
inputDesc_.inputBindings[0].stride =
sizes[static_cast<size_t>(VertexAttributeFormat::Int_2_10_10_10_REV)];

// numAttributes has to equal to bindings when using more than 1 buffer
inputDesc_.numAttributes = inputDesc_.numInputBindings = 1;

Result ret;
std::shared_ptr<IVertexInputState> vertexInputState;
vertexInputState = iglDev_->createVertexInputState(inputDesc_, &ret);
ASSERT_EQ(ret.code, Result::Code::Ok);
ASSERT_TRUE(vertexInputState != nullptr);
}
}

} // namespace igl::tests

0 comments on commit 2144068

Please sign in to comment.