GPU: Multithread compilation of shaders during tests

This commit is contained in:
Clément Foucault
2024-11-01 18:57:17 +01:00
parent d2c378984d
commit 9ee81411bf
2 changed files with 29 additions and 10 deletions

View File

@@ -75,7 +75,7 @@ using BatchHandle = int64_t;
* Request the creation of multiple shaders at once, allowing the backend to use multithreaded
* compilation. Returns a handle that can be used to poll if all shaders have been compiled, and to
* retrieve the compiled shaders.
* NOTE: This function is asynchronous on OpenGL, but it's blocking on Vulkan and Metal.
* NOTE: This function is asynchronous on OpenGL, but it's blocking on Vulkan.
* WARNING: The GPUShaderCreateInfo pointers should be valid until `GPU_shader_batch_finalize` has
* returned.
*/

View File

@@ -607,11 +607,15 @@ void gpu_shader_create_info_exit()
bool gpu_shader_create_info_compile(const char *name_starts_with_filter)
{
using namespace blender;
using namespace blender::gpu;
int success = 0;
int skipped_filter = 0;
int skipped = 0;
int total = 0;
Vector<const GPUShaderCreateInfo *> infos;
for (ShaderCreateInfo *info : g_create_infos->values()) {
info->finalize();
if (info->do_static_compilation_) {
@@ -629,14 +633,29 @@ bool gpu_shader_create_info_compile(const char *name_starts_with_filter)
continue;
}
total++;
GPUShader *shader = GPU_shader_create_from_info(
reinterpret_cast<const GPUShaderCreateInfo *>(info));
if (shader == nullptr) {
std::cerr << "Compilation " << info->name_.c_str() << " Failed\n";
}
else {
success++;
infos.append(reinterpret_cast<const GPUShaderCreateInfo *>(info));
}
}
Vector<GPUShader *> result;
if (GPU_use_parallel_compilation() == false) {
for (const GPUShaderCreateInfo *info : infos) {
result.append(GPU_shader_create_from_info(info));
}
}
else {
BatchHandle batch = GPU_shader_batch_create_from_infos(infos);
result = GPU_shader_batch_finalize(batch);
}
for (int i : result.index_range()) {
const ShaderCreateInfo *info = reinterpret_cast<const ShaderCreateInfo *>(infos[i]);
if (result[i] == nullptr) {
std::cerr << "Compilation " << info->name_.c_str() << " Failed\n";
}
else {
success++;
#if 0 /* TODO(fclem): This is too verbose for now. Make it a cmake option. */
/* Test if any resource is optimized out and print a warning if that's the case. */
/* TODO(fclem): Limit this to OpenGL backend. */
@@ -677,10 +696,10 @@ bool gpu_shader_create_info_compile(const char *name_starts_with_filter)
}
}
#endif
}
GPU_shader_free(shader);
GPU_shader_free(result[i]);
}
}
printf("Shader Test compilation result: %d / %d passed", success, total);
if (skipped_filter > 0) {
printf(" (skipped %d when filtering)", skipped_filter);