This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/vulkan/vk_backend.hh
Jeroen Bakker 9c0d822737 GPU: Compile vulkan shaders to Spir-V binaries.
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.
```

Reviewed By: fclem

Maniphest Tasks: T102760

Differential Revision: https://developer.blender.org/D16610
2022-12-12 12:25:22 +01:00

74 lines
1.8 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2022 Blender Foundation. All rights reserved. */
/** \file
* \ingroup gpu
*/
#pragma once
#include "gpu_backend.hh"
#ifdef __APPLE__
# include <MoltenVK/vk_mvk_moltenvk.h>
#else
# include <vulkan/vulkan.h>
#endif
#include "shaderc/shaderc.hpp"
namespace blender::gpu {
class VKContext;
class VKBackend : public GPUBackend {
private:
shaderc::Compiler shaderc_compiler_;
public:
VKBackend()
{
VKBackend::init_platform();
}
virtual ~VKBackend()
{
VKBackend::platform_exit();
}
void delete_resources() override;
void samplers_update() override;
void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override;
void compute_dispatch_indirect(StorageBuf *indirect_buf) override;
Context *context_alloc(void *ghost_window, void *ghost_context) override;
Batch *batch_alloc() override;
DrawList *drawlist_alloc(int list_length) override;
Fence *fence_alloc() override;
FrameBuffer *framebuffer_alloc(const char *name) override;
IndexBuf *indexbuf_alloc() override;
PixelBuffer *pixelbuf_alloc(uint size) override;
QueryPool *querypool_alloc() override;
Shader *shader_alloc(const char *name) override;
Texture *texture_alloc(const char *name) override;
UniformBuf *uniformbuf_alloc(int size, const char *name) override;
StorageBuf *storagebuf_alloc(int size, GPUUsageType usage, const char *name) override;
VertBuf *vertbuf_alloc() override;
/* Render Frame Coordination --
* Used for performing per-frame actions globally */
void render_begin() override;
void render_end() override;
void render_step() override;
shaderc::Compiler &get_shaderc_compiler();
static void capabilities_init(VKContext &context);
private:
static void init_platform();
static void platform_exit();
};
} // namespace blender::gpu