Files
test2/source/blender/gpu/vulkan/vk_shader_module.hh
Jeroen Bakker ec7fc8fef4 Vulkan: Parallel shader compilation
This PR introduces parallel shader compilation for Vulkan shader
modules. This will improve shader compilation when switching to material
preview or EEVEE render preview. It also improves material compilation.
However in order to measure the differences shaderc needs to be updated.

PR has been created so we can already start with the code review. This
PR doesn't include SPIR-V caching, what will land in a separate PR as
it needs more validation.

Parallel shader compilation has been tested on AMD/NVIDIA on Linux.
Testing on other platforms is planned in the upcoming days.

**Performance**

```
AMD Ryzen™ 9 7950X × 32, 64GB Ram
Operating system: Linux-6.8.0-44-generic-x86_64-with-glibc2.39 64 Bits, X11 UI
Graphics card: Quadro RTX 6000/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 550.107.02
```

*Test*: Start blender, open barbershop_interior.blend and wait until the viewport
has fully settled.

| Backend | Test                      | Duration |
| ------- | ------------------------- | -------- |
| OpenGL  | Coldstart/No subprocesses | 1:52     |
| OpenGL  | Coldstart/8 Subprocesses  | 0:54     |
| OpenGL  | Warmstart/8 Subprocesses  | 0:06     |
| Vulkan  | Coldstart Without PR      | 0:59     |
| Vulkan  | Warmstart Without PR      | 0:58     |
| Vulkan  | Coldstart With PR         | 0:33     |
| Vulkan  | Warmstart With PR         | 0:08     |

The difference in time (why OpenGL is faster in a warm start is that all
shaders are cached). Vulkan in this case doesn't cache anything and all
shaders are recompiled each time. Caching the shaders will be part of
a future PR. Main reason not to add it to this PR directly is that SPIR-V
cannot easily be validated and would require a sidecar to keep SPIR-V
compatible with external tools..

**NOTE**:
- This PR was extracted from #127418
- This PR requires #127564 to land and libraries to update. Linux lib
  is available as attachment in this PR. It works without, but is as slow as
  single threaded compilation.

Pull Request: https://projects.blender.org/blender/blender/pulls/127698
2024-09-20 08:30:09 +02:00

77 lines
1.9 KiB
C++

/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*/
#pragma once
#include "gpu_shader_private.hh"
#include "vk_common.hh"
#include "shaderc/shaderc.hpp"
namespace blender::gpu {
class VKShader;
/**
* Shader module.
*
* A shader module contains shader code and can be used as a vertex/geometry/fragment/compute stage
* of a shader. The shader code in this sense doesn't need to be GLSL, but can also be SPIR-V
* binary.
*
* For now this is just a data container so code can be reused when working with multiple shader
* stages.
*
* Later we could load the SPIR-V binary directly from disk to skip front end compilation
* phase completely or skip shader module at all when the cache is already aware of this shader by
* using VK_EXT_shader_module_identifier.
*/
class VKShaderModule {
public:
/**
* Single string containing GLSL source code.
*
* Is cleared after compilation phase has completed. (VKShader::finalize_post).
*/
std::string combined_sources;
std::string sources_hash;
/**
* Vulkan handler of the shader module.
*/
VkShaderModule vk_shader_module = VK_NULL_HANDLE;
/**
* Compilation result when compiling the shader module.
*
* Is cleared after compilation phase has completed. (VKShader::finalize_post).
*/
shaderc::SpvCompilationResult compilation_result;
/**
* Is compilation needed and is the compilation step done.
*
* Is set to false when GLSL sources are loaded and will be set to true again after the
* compilation step. It will also be true when compilation has failed.
*/
bool is_ready = true;
~VKShaderModule();
/**
* Finalize the shader module.
*
* When compilation succeeded the VkShaderModule will be created and stored in
* `vk_shader_module`.
*/
void finalize(StringRefNull name);
};
} // namespace blender::gpu