Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/tests/gpu_texture_test.cc
- This file was added.
| /* Apache License, Version 2.0 */ | |||||
| #include "testing/testing.h" | |||||
| #include "CLG_log.h" | |||||
| #include "GPU_capabilities.h" | |||||
| #include "GPU_context.h" | |||||
| #include "GPU_texture.h" | |||||
| #include "gpu_testing.hh" | |||||
| namespace blender::gpu { | |||||
| static CLG_LogRef LOG = {"gpu"}; | |||||
| static bool test_texture_size_2d(int width, int height, int mips, eGPUTextureFormat format) | |||||
| { | |||||
| GPUTexture *texture = GPU_texture_create_2d(__func__, width, height, mips, format, nullptr); | |||||
| if (texture == nullptr) { | |||||
| return false; | |||||
| } | |||||
| const int driver_reported_size = GPU_max_texture_size(); | |||||
| EXPECT_TRUE(GPU_texture_width(texture) <= driver_reported_size); | |||||
| EXPECT_TRUE(GPU_texture_height(texture) <= driver_reported_size); | |||||
| GPU_texture_free(texture); | |||||
| return true; | |||||
| } | |||||
| /* Texture sizes a driver reports back isn't well defined. Data types and texture features may | |||||
| * require smaller textures than reported by the driver. This test case will give us a better | |||||
| * understanding what is supported and where the current implementation fails. */ | |||||
| TEST_F(GPUTest, gpu_texture_size_2d) | |||||
| { | |||||
| CLG_logref_init(&LOG); | |||||
| const int driver_reported_size = GPU_max_texture_size(); | |||||
| CLOG_INFO(&LOG, 0, "Driver reported max texture size: %d", driver_reported_size); | |||||
| const int max_size_to_test = driver_reported_size * 1.2; | |||||
| const int max_mips_to_test = 24; | |||||
| const int start_size = driver_reported_size * 0.5; | |||||
| const int step_size = 2048; | |||||
| /* Set to true to output a CSV to stdout. When set to false only warnings will be reported. */ | |||||
| const int csv_report = false; | |||||
| int num_failures = 0; | |||||
| eGPUTextureFormat formats_to_test[] = { | |||||
| GPU_RGBA8UI, GPU_RGBA8I, GPU_RGBA8, GPU_RGBA32UI, GPU_RGBA32I, GPU_RGBA32F, | |||||
| GPU_RGBA16UI, GPU_RGBA16I, GPU_RGBA16F, GPU_RGBA16, GPU_RG8UI, GPU_RG8I, | |||||
| GPU_RG8, GPU_RG32UI, GPU_RG32I, GPU_RG32F, GPU_RG16UI, GPU_RG16I, | |||||
| GPU_RG16F, GPU_RG16, GPU_R8UI, GPU_R8I, GPU_R8, GPU_R32UI, | |||||
| GPU_R32I, GPU_R32F, GPU_R16UI, GPU_R16I, GPU_R16F, GPU_R16, | |||||
| }; | |||||
| const char *format_names[] = { | |||||
| STRINGIFY(GPU_RGBA8UI), STRINGIFY(GPU_RGBA8I), STRINGIFY(GPU_RGBA8), | |||||
| STRINGIFY(GPU_RGBA32UI), STRINGIFY(GPU_RGBA32I), STRINGIFY(GPU_RGBA32F), | |||||
| STRINGIFY(GPU_RGBA16UI), STRINGIFY(GPU_RGBA16I), STRINGIFY(GPU_RGBA16F), | |||||
| STRINGIFY(GPU_RGBA16), STRINGIFY(GPU_RG8UI), STRINGIFY(GPU_RG8I), | |||||
| STRINGIFY(GPU_RG8), STRINGIFY(GPU_RG32UI), STRINGIFY(GPU_RG32I), | |||||
| STRINGIFY(GPU_RG32F), STRINGIFY(GPU_RG16UI), STRINGIFY(GPU_RG16I), | |||||
| STRINGIFY(GPU_RG16F), STRINGIFY(GPU_RG16), STRINGIFY(GPU_R8UI), | |||||
| STRINGIFY(GPU_R8I), STRINGIFY(GPU_R8), STRINGIFY(GPU_R32UI), | |||||
| STRINGIFY(GPU_R32I), STRINGIFY(GPU_R32F), STRINGIFY(GPU_R16UI), | |||||
| STRINGIFY(GPU_R16I), STRINGIFY(GPU_R16F), STRINGIFY(GPU_R16), | |||||
| }; | |||||
| const int len_formats_to_test = sizeof(formats_to_test) / sizeof(eGPUTextureFormat); | |||||
| for (int height = start_size; height < max_size_to_test; height += step_size) { | |||||
| for (int width = start_size; width < max_size_to_test; width += step_size) { | |||||
| for (int format_index = 0; format_index < len_formats_to_test; format_index++) { | |||||
| for (int mips = 1; mips <= max_mips_to_test; mips += 1) { | |||||
| bool texture_created = test_texture_size_2d( | |||||
| width, height, mips, formats_to_test[format_index]); | |||||
jbakker: clang format | |||||
| if (csv_report) { | |||||
| std::cout << width << ", " << height << ", " << mips << ", " | |||||
| << format_names[format_index] << ", " << (texture_created ? "OK" : "FAIL") | |||||
| << "\n"; | |||||
| } | |||||
| if (texture_created) | |||||
| continue; | |||||
Done Inline Actionsclang format jbakker: clang format | |||||
| num_failures++; | |||||
| if (!csv_report) { | |||||
| CLOG_WARN(&LOG, | |||||
| "Failed to create texture `GPU_texture_create_2d(w: %d, h: %d, s: %d, m: " | |||||
| "%d, d: %s)`", | |||||
| width, | |||||
| height, | |||||
| width * height, | |||||
| mips, | |||||
| format_names[format_index]); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| EXPECT_EQ(num_failures, 0); | |||||
| } | |||||
| } // namespace blender::gpu | |||||
| No newline at end of file | |||||
clang format