Page MenuHome

GPU: Compile vulkan shaders to Spir-V binaries.
ClosedPublic

Authored by Jeroen Bakker (jbakker) on Nov 25 2022, 10:10 AM.

Details

Summary

Compile each static shader using shaderc to Spir-V binaries.

The main goal is to make sure that the GLSL created using ShaderCreateInfo and able to compile to Spir-V.
For the second stage a correct pipeline needs to be created and some shader would need more
adjustments (push constants size).

With this patch future changes to GLSL sources can already be checked against vulkan, without the
backend finished.

Mechanism has been tested using MacOS and MoltenVK. For other OS, we should finetune CMake
files to find the right location to shaderc.

************************************************************
*** Build Mon 12 Dec 2022 11:08:07 CET
************************************************************
Shader Test compilation result: 463 / 463 passed (skipped 118 for compatibility reasons)
OpenGL backend shader compilation succeeded.
Shader Test compilation result: 529 / 529 passed (skipped 52 for compatibility reasons)
Vulkan backend shader compilation succeeded.

Diff Detail

Repository
rB Blender
Branch
temp-vulkan-shader
Build Status
Buildable 24916
Build 24916: arc lint + arc unit

Event Timeline

source/blender/gpu/CMakeLists.txt
47

Should be removed

282

Should be removed

source/blender/gpu/intern/gpu_context.cc
324

Could be added to master directly.

source/blender/gpu/intern/gpu_init_exit.c
37–38

Should be removed before merging to master.

source/blender/gpu/intern/gpu_shader_builder.cc
106

should be enabled before merging to master.

source/blender/gpu/vulkan/vk_shader.hh
15

Include not needed.

source/blender/gpu/vulkan/vk_shader_log.cc
17

https://github.com/google/shaderc/blob/main/libshaderc_util/src/message_test.cc has test files that parse different source files from the error message.

Perhaps we should add a #pragma to include the correct filename in the error message.

  • Copied over GLSL code gen functions from GLShader.
  • Improve shader log to add correct filenames.
  • Remove unused cmake includes/libs.
  • Merge branch 'master' into temp-vulkan-shader
  • Fixed stage interface declaration.
  • regular stage interfaces working.
  • Remove debug code.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Nov 29 2022, 2:47 PM
  • Fixed geometry layout.
  • Add glsl shader defines.
  • Add definition of gl_InstanceID.
  • Use correct layout location.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Nov 29 2022, 3:56 PM
  • Fix vulkan compilation of common_smaa_lib.glsl
  • Fix compilation issues in workbench shadow.
  • Fix gpencil shaders.
  • Fix compilation of line dashed shader.
  • Enable OpenGL/Metal shader compilation. (was disabled for debugging).
  • Moved debug code.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Dec 2 2022, 10:34 AM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
source/blender/gpu/vulkan/vk_shader.cc
340

gpu_InstanceIndex should point to the global instance index, not offset from the base.
Haven't found a solution to provide the correct gpu_BaseInstance (yet).

419

debug code should eventually be removed.

source/blender/gpu/vulkan/vk_shader.hh
15

It is now required.

  • Fix motion patch shaders.
  • Added support for compute and shader storage.
  • Remove warning (pragma once not implemented).
  • Fix sampler is a keyword, do not use a parameter name.
  • Fix Eevee-next depth of field compilation.
  • Fixed lens distortion compilation.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Dec 2 2022, 12:07 PM
  • Revert change to device restriction.
  • Removed debug code.
  • Tweaked gpu_InstanceIndex.
Jeroen Bakker (jbakker) requested review of this revision.Dec 2 2022, 12:39 PM
Jeroen Bakker (jbakker) retitled this revision from GPU: Compile vulkan shaders. to GPU: Compile vulkan shaders to Spir-V binaries..
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
  • Removed debug code.
  • Remove code that hides missing feature in master as it is now fixed in master.
  • Revert whitespace change.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Dec 2 2022, 1:47 PM
source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_tiles_flatten_comp.glsl
29–32

The const can be removed in the non vulkan case directly. I don't think it makes a difference.

source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
16–18

I think using choke here is kind of misplaced. It is a violent term for just describing a bug.

18

I'm thinking we could instead remove the macros.

Diff to add shaderc to window. Note that epoch isn't working out of the box so shaderc is still failing.

Fix is first to compile blender to make sure the dll's are copied, after that shaderc seems to work. Will need to find a way to do this as part of shader builder.

Jeroen Bakker (jbakker) marked 3 inline comments as done.
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
  • Remove const keyword from shader global.
  • Converted world_clip_planes macros to functions.
  • Nicer comments describing the issue.
  • Enable performance optimizations.
Work around shaderc issue by converting view macros to functions.
source/blender/draw/intern/shaders/common_view_lib.glsl
251 ↗(On Diff #58346)

Macros using ModelMatrix/ModelMatrixInverse might not be defined yet (or at all) keeping them as macros for now, as it requires bigger changes.
After eevee has been converted to use create infos I don't mind looking into it.

  • Prefix push constants to work around double macro expansion.
  • Vulkan: add cube map array.

Seems to be in great shape!

source/blender/draw/engines/eevee_next/eevee_defines.hh
12–14

Use #ifndef GPU_SHADER instead.

source/blender/gpu/shaders/gpu_shader_cfg_world_clip_lib.glsl
13 ↗(On Diff #58503)

I would avoid this copy. This might not be optimized by compilers.

This revision is now accepted and ready to land.Dec 12 2022, 11:22 AM
Jeroen Bakker (jbakker) marked 2 inline comments as done.
  • Use GPU_SHADER; not GPU_VULKAN.
  • Don't make a local variable to load the WorldClipPlanes.