|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +#include <gtest/gtest.h> |
| 9 | + |
| 10 | +#include <igl/Shader.h> |
| 11 | + |
| 12 | +namespace igl::tests { |
| 13 | + |
| 14 | +TEST(ShaderStageTest, EnumValues) { |
| 15 | + EXPECT_EQ(static_cast<uint8_t>(ShaderStage::Vertex), 0u); |
| 16 | + EXPECT_EQ(static_cast<uint8_t>(ShaderStage::Fragment), 1u); |
| 17 | + EXPECT_EQ(static_cast<uint8_t>(ShaderStage::Compute), 2u); |
| 18 | + EXPECT_EQ(static_cast<uint8_t>(ShaderStage::Task), 3u); |
| 19 | + EXPECT_EQ(static_cast<uint8_t>(ShaderStage::Mesh), 4u); |
| 20 | +} |
| 21 | + |
| 22 | +TEST(ShaderStageTest, ValuesAreDistinct) { |
| 23 | + const uint8_t vertex = static_cast<uint8_t>(ShaderStage::Vertex); |
| 24 | + const uint8_t fragment = static_cast<uint8_t>(ShaderStage::Fragment); |
| 25 | + const uint8_t compute = static_cast<uint8_t>(ShaderStage::Compute); |
| 26 | + const uint8_t task = static_cast<uint8_t>(ShaderStage::Task); |
| 27 | + const uint8_t mesh = static_cast<uint8_t>(ShaderStage::Mesh); |
| 28 | + EXPECT_NE(vertex, fragment); |
| 29 | + EXPECT_NE(vertex, compute); |
| 30 | + EXPECT_NE(fragment, compute); |
| 31 | + EXPECT_NE(task, mesh); |
| 32 | +} |
| 33 | + |
| 34 | +TEST(ConstantValueTypeTest, InvalidIsZero) { |
| 35 | + EXPECT_EQ(static_cast<uint8_t>(ConstantValueType::Invalid), 0u); |
| 36 | +} |
| 37 | + |
| 38 | +TEST(ConstantValueTypeTest, GetSizeInvalid) { |
| 39 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Invalid), 0u); |
| 40 | +} |
| 41 | + |
| 42 | +TEST(ConstantValueTypeTest, GetSizeFloatTypes) { |
| 43 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Float1), 4u); |
| 44 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Float2), 8u); |
| 45 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Float3), 12u); |
| 46 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Float4), 16u); |
| 47 | +} |
| 48 | + |
| 49 | +TEST(ConstantValueTypeTest, GetSizeBooleanTypes) { |
| 50 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Boolean1), 4u); |
| 51 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Boolean2), 8u); |
| 52 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Boolean3), 12u); |
| 53 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Boolean4), 16u); |
| 54 | +} |
| 55 | + |
| 56 | +TEST(ConstantValueTypeTest, GetSizeIntTypes) { |
| 57 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Int1), 4u); |
| 58 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Int2), 8u); |
| 59 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Int3), 12u); |
| 60 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Int4), 16u); |
| 61 | +} |
| 62 | + |
| 63 | +TEST(ConstantValueTypeTest, GetSizeMatrixTypes) { |
| 64 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Mat2x2), 16u); |
| 65 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Mat3x3), 36u); |
| 66 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Mat4x4), 64u); |
| 67 | +} |
| 68 | + |
| 69 | +TEST(ConstantValueTypeTest, ScalarSizesAreConsistent) { |
| 70 | + const size_t floatSize = getConstantValueSize(ConstantValueType::Float1); |
| 71 | + const size_t boolSize = getConstantValueSize(ConstantValueType::Boolean1); |
| 72 | + const size_t intSize = getConstantValueSize(ConstantValueType::Int1); |
| 73 | + EXPECT_EQ(floatSize, boolSize); |
| 74 | + EXPECT_EQ(floatSize, intSize); |
| 75 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Float2), floatSize * 2); |
| 76 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Float3), floatSize * 3); |
| 77 | + EXPECT_EQ(getConstantValueSize(ConstantValueType::Float4), floatSize * 4); |
| 78 | +} |
| 79 | + |
| 80 | +} // namespace igl::tests |
0 commit comments