diff --git a/guest/bundle/Makefile b/guest/bundle/Makefile index 386ec8958..265494eb1 100644 --- a/guest/bundle/Makefile +++ b/guest/bundle/Makefile @@ -174,10 +174,11 @@ $(patsubst src/%.mm,$(BUILD)/obj/$(ARCH)/shell/%.o,$(wildcard src/RgfxMetalDevic # --- the serialiser check (x86_64, Rosetta) ---------------------------------- $(SER_TESTBIN): $(CORE_OBJ_ARCH) tests/serializer_tests.cpp tests/slab_tests.cpp \ - tests/library_stream_tests.cpp $(HEADERS) $(TESTHEADERS) Makefile + tests/library_stream_tests.cpp tests/function_constants_tests.cpp $(HEADERS) $(TESTHEADERS) \ + Makefile @mkdir -p $(@D) $(CXX) -arch $(ARCH) $(CXXFLAGS) -I tests $(CORE_OBJ_ARCH) tests/serializer_tests.cpp \ - tests/slab_tests.cpp tests/library_stream_tests.cpp -o $@ + tests/slab_tests.cpp tests/library_stream_tests.cpp tests/function_constants_tests.cpp -o $@ # --- the Metal-shell wrapper/routing check (native arch) --------------------- # The NSObject wrappers + serialiser core + the routing test; no device shell. diff --git a/guest/bundle/src/RgfxFunctionConstants.cpp b/guest/bundle/src/RgfxFunctionConstants.cpp index 4aedab301..56aebc775 100644 --- a/guest/bundle/src/RgfxFunctionConstants.cpp +++ b/guest/bundle/src/RgfxFunctionConstants.cpp @@ -97,16 +97,88 @@ uint32_t rgfxConstantSize(uint32_t type) return f ? f->lane * lanes : 0; } +namespace { + +// MTLDataType's values that are no scalar or vector of a family, and their names after +// "MTLDataType" (Metal's MTLDataType.h, macOS 27 SDK). Metal's errors name every value of the +// enum so (measured: oracle_names on the AMD Radeon Pro 5300M and the Intel UHD Graphics 630, +// macOS 26.7.1). +struct Named { + uint32_t type; + const char *name; +}; +constexpr Named kNamed[] = { + { 0, "None" }, + { 1, "Struct" }, + { 2, "Array" }, + { 7, "Float2x2" }, + { 8, "Float2x3" }, + { 9, "Float2x4" }, + { 10, "Float3x2" }, + { 11, "Float3x3" }, + { 12, "Float3x4" }, + { 13, "Float4x2" }, + { 14, "Float4x3" }, + { 15, "Float4x4" }, + { 20, "Half2x2" }, + { 21, "Half2x3" }, + { 22, "Half2x4" }, + { 23, "Half3x2" }, + { 24, "Half3x3" }, + { 25, "Half3x4" }, + { 26, "Half4x2" }, + { 27, "Half4x3" }, + { 28, "Half4x4" }, + { 58, "Texture" }, + { 59, "Sampler" }, + { 60, "Pointer" }, + { 62, "R8Unorm" }, + { 63, "R8Snorm" }, + { 64, "R16Unorm" }, + { 65, "R16Snorm" }, + { 66, "RG8Unorm" }, + { 67, "RG8Snorm" }, + { 68, "RG16Unorm" }, + { 69, "RG16Snorm" }, + { 70, "RGBA8Unorm" }, + { 71, "RGBA8Unorm_sRGB" }, + { 72, "RGBA8Snorm" }, + { 73, "RGBA16Unorm" }, + { 74, "RGBA16Snorm" }, + { 75, "RGB10A2Unorm" }, + { 76, "RG11B10Float" }, + { 77, "RGB9E5Float" }, + { 78, "RenderPipeline" }, + { 79, "ComputePipeline" }, + { 80, "IndirectCommandBuffer" }, + { 115, "VisibleFunctionTable" }, + { 116, "IntersectionFunctionTable" }, + { 117, "PrimitiveAccelerationStructure" }, + { 118, "InstanceAccelerationStructure" }, + { 121, "BFloat" }, + { 122, "BFloat2" }, + { 123, "BFloat3" }, + { 124, "BFloat4" }, +}; + +} // namespace + std::string rgfxDataTypeName(uint32_t type) { uint32_t lanes = 0; const Family *f = familyOf(type, &lanes); - if (f == nullptr) - return type == 0 ? "MTLDataTypeNone" : "MTLDataType(" + std::to_string(type) + ")"; - std::string name = std::string("MTLDataType") + f->name; - if (lanes > 1) - name += std::to_string(lanes); - return name; + if (f != nullptr) { + std::string name = std::string("MTLDataType") + f->name; + if (lanes > 1) + name += std::to_string(lanes); + return name; + } + for (const Named &n : kNamed) { + if (n.type == type) + return std::string("MTLDataType") + n.name; + } + // A value outside the enum: ours. + return "MTLDataType(" + std::to_string(type) + ")"; } bool rgfxReadConstantTable(const uint8_t *bytes, size_t length, uint64_t offset, diff --git a/guest/bundle/tests/function_constants_tests.cpp b/guest/bundle/tests/function_constants_tests.cpp new file mode 100644 index 000000000..9c05189d0 --- /dev/null +++ b/guest/bundle/tests/function_constants_tests.cpp @@ -0,0 +1,134 @@ +/* + * function_constants_tests: the names Metal's errors give MTLDataType's values + * (RgfxFunctionConstants.hpp), part of the serialiser check (serializer_tests.cpp calls + * rgfxFunctionConstantsTests; guest/bundle/Makefile `test`). No Metal. + */ + +#include +#include +#include + +#include "RgfxFunctionConstants.hpp" +#include "rgfx_test_ring.hpp" // CHECK, g_checks + +namespace { + +// Every MTLDataType value and the name Metal's error gave it, a value of that type set for an int +// constant (measured: guest/bundle/tools/oracle/oracle_names, the same on the AMD Radeon Pro +// 5300M and the Intel UHD Graphics 630, macOS 26.7.1). +struct Measured { + uint32_t type; + const char *name; +}; +constexpr Measured kMeasured[] = { + { 0, "MTLDataTypeNone" }, + { 1, "MTLDataTypeStruct" }, + { 2, "MTLDataTypeArray" }, + { 3, "MTLDataTypeFloat" }, + { 4, "MTLDataTypeFloat2" }, + { 5, "MTLDataTypeFloat3" }, + { 6, "MTLDataTypeFloat4" }, + { 7, "MTLDataTypeFloat2x2" }, + { 8, "MTLDataTypeFloat2x3" }, + { 9, "MTLDataTypeFloat2x4" }, + { 10, "MTLDataTypeFloat3x2" }, + { 11, "MTLDataTypeFloat3x3" }, + { 12, "MTLDataTypeFloat3x4" }, + { 13, "MTLDataTypeFloat4x2" }, + { 14, "MTLDataTypeFloat4x3" }, + { 15, "MTLDataTypeFloat4x4" }, + { 16, "MTLDataTypeHalf" }, + { 17, "MTLDataTypeHalf2" }, + { 18, "MTLDataTypeHalf3" }, + { 19, "MTLDataTypeHalf4" }, + { 20, "MTLDataTypeHalf2x2" }, + { 21, "MTLDataTypeHalf2x3" }, + { 22, "MTLDataTypeHalf2x4" }, + { 23, "MTLDataTypeHalf3x2" }, + { 24, "MTLDataTypeHalf3x3" }, + { 25, "MTLDataTypeHalf3x4" }, + { 26, "MTLDataTypeHalf4x2" }, + { 27, "MTLDataTypeHalf4x3" }, + { 28, "MTLDataTypeHalf4x4" }, + { 29, "MTLDataTypeInt" }, + { 30, "MTLDataTypeInt2" }, + { 31, "MTLDataTypeInt3" }, + { 32, "MTLDataTypeInt4" }, + { 33, "MTLDataTypeUInt" }, + { 34, "MTLDataTypeUInt2" }, + { 35, "MTLDataTypeUInt3" }, + { 36, "MTLDataTypeUInt4" }, + { 37, "MTLDataTypeShort" }, + { 38, "MTLDataTypeShort2" }, + { 39, "MTLDataTypeShort3" }, + { 40, "MTLDataTypeShort4" }, + { 41, "MTLDataTypeUShort" }, + { 42, "MTLDataTypeUShort2" }, + { 43, "MTLDataTypeUShort3" }, + { 44, "MTLDataTypeUShort4" }, + { 45, "MTLDataTypeChar" }, + { 46, "MTLDataTypeChar2" }, + { 47, "MTLDataTypeChar3" }, + { 48, "MTLDataTypeChar4" }, + { 49, "MTLDataTypeUChar" }, + { 50, "MTLDataTypeUChar2" }, + { 51, "MTLDataTypeUChar3" }, + { 52, "MTLDataTypeUChar4" }, + { 53, "MTLDataTypeBool" }, + { 54, "MTLDataTypeBool2" }, + { 55, "MTLDataTypeBool3" }, + { 56, "MTLDataTypeBool4" }, + { 58, "MTLDataTypeTexture" }, + { 59, "MTLDataTypeSampler" }, + { 60, "MTLDataTypePointer" }, + { 62, "MTLDataTypeR8Unorm" }, + { 63, "MTLDataTypeR8Snorm" }, + { 64, "MTLDataTypeR16Unorm" }, + { 65, "MTLDataTypeR16Snorm" }, + { 66, "MTLDataTypeRG8Unorm" }, + { 67, "MTLDataTypeRG8Snorm" }, + { 68, "MTLDataTypeRG16Unorm" }, + { 69, "MTLDataTypeRG16Snorm" }, + { 70, "MTLDataTypeRGBA8Unorm" }, + { 71, "MTLDataTypeRGBA8Unorm_sRGB" }, + { 72, "MTLDataTypeRGBA8Snorm" }, + { 73, "MTLDataTypeRGBA16Unorm" }, + { 74, "MTLDataTypeRGBA16Snorm" }, + { 75, "MTLDataTypeRGB10A2Unorm" }, + { 76, "MTLDataTypeRG11B10Float" }, + { 77, "MTLDataTypeRGB9E5Float" }, + { 78, "MTLDataTypeRenderPipeline" }, + { 79, "MTLDataTypeComputePipeline" }, + { 80, "MTLDataTypeIndirectCommandBuffer" }, + { 81, "MTLDataTypeLong" }, + { 82, "MTLDataTypeLong2" }, + { 83, "MTLDataTypeLong3" }, + { 84, "MTLDataTypeLong4" }, + { 85, "MTLDataTypeULong" }, + { 86, "MTLDataTypeULong2" }, + { 87, "MTLDataTypeULong3" }, + { 88, "MTLDataTypeULong4" }, + { 115, "MTLDataTypeVisibleFunctionTable" }, + { 116, "MTLDataTypeIntersectionFunctionTable" }, + { 117, "MTLDataTypePrimitiveAccelerationStructure" }, + { 118, "MTLDataTypeInstanceAccelerationStructure" }, + { 121, "MTLDataTypeBFloat" }, + { 122, "MTLDataTypeBFloat2" }, + { 123, "MTLDataTypeBFloat3" }, + { 124, "MTLDataTypeBFloat4" }, +}; + +} // namespace + +void rgfxFunctionConstantsTests() +{ + for (const Measured &m : kMeasured) { + if (rgfxDataTypeName(m.type) != m.name) + std::fprintf(stderr, "type %u: %s, Metal's %s\n", m.type, + rgfxDataTypeName(m.type).c_str(), m.name); + CHECK(rgfxDataTypeName(m.type) == m.name); + } + // A value outside the enum: ours. + CHECK(rgfxDataTypeName(57) == "MTLDataType(57)"); + CHECK(rgfxDataTypeName(1000) == "MTLDataType(1000)"); +} diff --git a/guest/bundle/tests/serializer_tests.cpp b/guest/bundle/tests/serializer_tests.cpp index cc786f0ac..d91331356 100644 --- a/guest/bundle/tests/serializer_tests.cpp +++ b/guest/bundle/tests/serializer_tests.cpp @@ -41,6 +41,7 @@ void rgfxSlabTests(); void rgfxLibraryStreamTests(); +void rgfxFunctionConstantsTests(); namespace { @@ -2471,6 +2472,7 @@ int main() test_argument_layout_parse(); rgfxSlabTests(); rgfxLibraryStreamTests(); + rgfxFunctionConstantsTests(); std::printf("serializer_tests: OK (%d checks)\n", g_checks); return 0; }