2022-03-27 21:22:24 +00:00
|
|
|
// Copyright 2019-2022, Collabora, Ltd.
|
2020-10-09 16:14:17 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Shader loading code.
|
|
|
|
* @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
2021-11-03 17:45:39 +00:00
|
|
|
* @ingroup comp_render
|
2020-10-09 16:14:17 +00:00
|
|
|
*/
|
|
|
|
|
2022-05-15 17:03:41 +00:00
|
|
|
#include "render/render_interface.h"
|
2020-10-09 16:14:17 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2022-04-12 19:35:39 +00:00
|
|
|
#if defined(__GNUC__)
|
2020-10-09 16:14:17 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wpragmas"
|
|
|
|
#pragma GCC diagnostic ignored "-Wnewline-eof"
|
2022-04-12 19:35:39 +00:00
|
|
|
#endif
|
2020-10-09 16:14:17 +00:00
|
|
|
|
2021-05-04 17:24:38 +00:00
|
|
|
#include "shaders/clear.comp.h"
|
|
|
|
#include "shaders/distortion.comp.h"
|
2020-10-09 16:14:17 +00:00
|
|
|
#include "shaders/layer.frag.h"
|
|
|
|
#include "shaders/layer.vert.h"
|
2020-12-11 11:43:17 +00:00
|
|
|
#include "shaders/equirect1.frag.h"
|
|
|
|
#include "shaders/equirect1.vert.h"
|
2020-12-02 13:20:54 +00:00
|
|
|
#include "shaders/equirect2.frag.h"
|
|
|
|
#include "shaders/equirect2.vert.h"
|
2020-10-09 16:14:17 +00:00
|
|
|
#include "shaders/mesh.frag.h"
|
|
|
|
#include "shaders/mesh.vert.h"
|
|
|
|
|
2022-04-12 19:35:39 +00:00
|
|
|
#if defined(__GNUC__)
|
2020-10-09 16:14:17 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2022-04-12 19:35:39 +00:00
|
|
|
#endif
|
2020-10-09 16:14:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Functions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VkResult
|
2021-01-14 14:13:48 +00:00
|
|
|
shader_load(struct vk_bundle *vk, const uint32_t *code, size_t size, VkShaderModule *out_module)
|
2020-10-09 16:14:17 +00:00
|
|
|
{
|
|
|
|
VkResult ret;
|
|
|
|
|
|
|
|
VkShaderModuleCreateInfo info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
|
|
|
.codeSize = size,
|
|
|
|
.pCode = code,
|
|
|
|
};
|
|
|
|
|
|
|
|
VkShaderModule module;
|
|
|
|
ret = vk->vkCreateShaderModule(vk->device, //
|
|
|
|
&info, //
|
|
|
|
NULL, //
|
|
|
|
&module); //
|
|
|
|
if (ret != VK_SUCCESS) {
|
2021-01-14 14:13:48 +00:00
|
|
|
VK_ERROR(vk, "vkCreateShaderModule failed: %s", vk_result_string(ret));
|
2020-10-09 16:14:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_module = module;
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-01-14 14:13:48 +00:00
|
|
|
#define C(c) \
|
|
|
|
do { \
|
|
|
|
VkResult ret = c; \
|
|
|
|
if (ret != VK_SUCCESS) { \
|
2022-03-27 21:10:25 +00:00
|
|
|
render_shaders_close(s, vk); \
|
2021-01-14 14:13:48 +00:00
|
|
|
return false; \
|
|
|
|
} \
|
2020-10-09 16:14:17 +00:00
|
|
|
} while (false)
|
|
|
|
|
|
|
|
bool
|
2022-03-27 21:10:25 +00:00
|
|
|
render_shaders_load(struct render_shaders *s, struct vk_bundle *vk)
|
2020-10-09 16:14:17 +00:00
|
|
|
{
|
2021-05-04 17:24:38 +00:00
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_clear_comp, // data
|
|
|
|
sizeof(shaders_clear_comp), // size
|
|
|
|
&s->clear_comp)); // out
|
|
|
|
|
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_distortion_comp, // data
|
|
|
|
sizeof(shaders_distortion_comp), // size
|
|
|
|
&s->distortion_comp)); // out
|
|
|
|
|
2020-10-09 16:14:17 +00:00
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_mesh_vert, // data
|
|
|
|
sizeof(shaders_mesh_vert), // size
|
|
|
|
&s->mesh_vert)); // out
|
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_mesh_frag, // data
|
|
|
|
sizeof(shaders_mesh_frag), // size
|
|
|
|
&s->mesh_frag)); // out
|
|
|
|
|
2020-12-11 11:43:17 +00:00
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_equirect1_vert, // data
|
|
|
|
sizeof(shaders_equirect1_vert), // size
|
|
|
|
&s->equirect1_vert)); // out
|
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_equirect1_frag, // data
|
|
|
|
sizeof(shaders_equirect1_frag), // size
|
|
|
|
&s->equirect1_frag)); // out
|
|
|
|
|
2020-12-02 13:20:54 +00:00
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_equirect2_vert, // data
|
|
|
|
sizeof(shaders_equirect2_vert), // size
|
|
|
|
&s->equirect2_vert)); // out
|
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_equirect2_frag, // data
|
|
|
|
sizeof(shaders_equirect2_frag), // size
|
|
|
|
&s->equirect2_frag)); // out
|
2020-10-09 14:33:13 +00:00
|
|
|
|
2020-10-09 16:14:17 +00:00
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_layer_vert, // data
|
|
|
|
sizeof(shaders_layer_vert), // size
|
|
|
|
&s->layer_vert)); // out
|
|
|
|
C(shader_load(vk, // vk_bundle
|
|
|
|
shaders_layer_frag, // data
|
|
|
|
sizeof(shaders_layer_frag), // size
|
|
|
|
&s->layer_frag)); // out
|
|
|
|
|
|
|
|
VK_DEBUG(vk, "Shaders loaded!");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-14 14:13:48 +00:00
|
|
|
#define D(shader) \
|
|
|
|
if (s->shader != VK_NULL_HANDLE) { \
|
|
|
|
vk->vkDestroyShaderModule(vk->device, s->shader, NULL); \
|
|
|
|
s->shader = VK_NULL_HANDLE; \
|
2020-10-09 16:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-03-27 21:10:25 +00:00
|
|
|
render_shaders_close(struct render_shaders *s, struct vk_bundle *vk)
|
2020-10-09 16:14:17 +00:00
|
|
|
{
|
2021-05-04 17:24:38 +00:00
|
|
|
D(clear_comp);
|
|
|
|
D(distortion_comp);
|
2020-10-09 16:14:17 +00:00
|
|
|
D(mesh_vert);
|
|
|
|
D(mesh_frag);
|
2020-12-11 11:43:17 +00:00
|
|
|
D(equirect1_vert);
|
|
|
|
D(equirect1_frag);
|
2020-12-02 13:20:54 +00:00
|
|
|
D(equirect2_vert);
|
|
|
|
D(equirect2_frag);
|
2020-10-09 16:14:17 +00:00
|
|
|
D(layer_vert);
|
|
|
|
D(layer_frag);
|
|
|
|
|
|
|
|
VK_DEBUG(vk, "Shaders destroyed!");
|
|
|
|
}
|