2
* Copyright © 2022 Imagination Technologies Ltd.
4
* Permission is hereby granted, free of charge, to any person obtaining a copy
5
* of this software and associated documentation files (the "Software"), to deal
6
* in the Software without restriction, including without limitation the rights
7
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
* copies of the Software, and to permit persons to whom the Software is
9
* furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
#include <vulkan/vulkan.h>
28
#include "compiler/shader_enums.h"
30
#include "nir/nir_builder.h"
31
#include "pvr_private.h"
32
#include "pvr_shader.h"
33
#include "rogue/rogue.h"
34
#include "rogue/rogue_shader.h"
35
#include "spirv/nir_spirv.h"
36
#include "vk_format.h"
37
#include "vk_shader_module.h"
43
* \brief Contains top-level functions to compile SPIR-V -> NIR -> Rogue, and
44
* interfaces with the compiler.
48
* \brief Converts a SPIR-V shader to NIR.
50
* \param[in] ctx Shared multi-stage build context.
51
* \param[in] stage Shader stage.
52
* \param[in] create_info Shader creation info from Vulkan pipeline.
53
* \return A nir_shader* if successful, or NULL if unsuccessful.
55
nir_shader *pvr_spirv_to_nir(struct rogue_build_ctx *ctx,
56
gl_shader_stage stage,
57
const VkPipelineShaderStageCreateInfo *create_info)
59
VK_FROM_HANDLE(vk_shader_module, module, create_info->module);
60
struct nir_spirv_specialization *spec;
61
unsigned num_spec = 0;
65
vk_spec_info_to_nir_spirv(create_info->pSpecializationInfo, &num_spec);
67
nir = rogue_spirv_to_nir(ctx,
70
module->size / sizeof(uint32_t),
71
(uint32_t *)module->data,
81
* \brief Converts a NIR shader to Rogue.
83
* \param[in] ctx Shared multi-stage build context.
84
* \param[in] nir NIR shader.
85
* \return A rogue_shader* if successful, or NULL if unsuccessful.
87
struct rogue_shader *pvr_nir_to_rogue(struct rogue_build_ctx *ctx,
90
return rogue_nir_to_rogue(ctx, nir);
94
* \brief Converts a Rogue shader to binary.
96
* \param[in] ctx Shared multi-stage build context.
97
* \param[in] shader Rogue shader.
98
* \return A rogue_shader_binary* if successful, or NULL if unsuccessful.
100
struct rogue_shader_binary *pvr_rogue_to_binary(struct rogue_build_ctx *ctx,
101
struct rogue_shader *shader)
103
return rogue_to_binary(ctx, shader);