From 556025ba149e5451485d0d65667fbe168db08f1c Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Thu, 30 May 2024 18:19:00 -0400 Subject: [PATCH] Escape subnormal values (#1953) Currently we don't escape subnormal values when generating image data. In sampler read tests, we use `!=` to check the two values even when it is floating-point data, which requires the two values are bitwise equal. However, a sampler might flush subnormal values, causing the test case to fail. In this patch, when generating random image data, we escape subnormal values. --- test_common/harness/imageHelpers.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test_common/harness/imageHelpers.cpp b/test_common/harness/imageHelpers.cpp index 2211924d20..e13404b9a5 100644 --- a/test_common/harness/imageHelpers.cpp +++ b/test_common/harness/imageHelpers.cpp @@ -1128,13 +1128,15 @@ cl_ulong get_image_size_mb(image_descriptor const *imageInfo) uint64_t gRoundingStartValue = 0; -void escape_inf_nan_values(char *data, size_t allocSize) +void escape_inf_nan_subnormal_values(char *data, size_t allocSize) { // filter values with 8 not-quite-highest bits unsigned int *intPtr = (unsigned int *)data; for (size_t i = 0; i> 2; i++) { if ((intPtr[i] & 0x7F800000) == 0x7F800000) intPtr[i] ^= 0x40000000; + else if ((intPtr[i] & 0x7F800000) == 0) + intPtr[i] ^= 0x40000000; } // Ditto with half floats (16-bit numbers with the 5 not-quite-highest bits @@ -1143,6 +1145,8 @@ void escape_inf_nan_values(char *data, size_t allocSize) for (size_t i = 0; i> 1; i++) { if ((shortPtr[i] & 0x7C00) == 0x7C00) shortPtr[i] ^= 0x4000; + else if ((shortPtr[i] & 0x7C00) == 0) + shortPtr[i] ^= 0x4000; } } @@ -1221,7 +1225,7 @@ char *generate_random_image_data(image_descriptor *imageInfo, // Note: inf or nan float values would cause problems, although we don't // know this will actually be a float, so we just know what to look for - escape_inf_nan_values(data, allocSize); + escape_inf_nan_subnormal_values(data, allocSize); return data; } @@ -1233,7 +1237,7 @@ char *generate_random_image_data(image_descriptor *imageInfo, // Note: inf or nan float values would cause problems, although we don't // know this will actually be a float, so we just know what to look for - escape_inf_nan_values(data, allocSize); + escape_inf_nan_subnormal_values(data, allocSize); if (/*!gTestMipmaps*/ imageInfo->num_mip_levels < 2) {