GlistEngine
Loading...
Searching...
No Matches
gVKPipeline.h
Go to the documentation of this file.
1/*
2 * gVKPipeline.h
3 *
4 * Builds the graphics pipelines the Vulkan 2D draw path uses: one for coloured
5 * geometry (triangle, rectangle) and one for textured quads (gImage). Also owns
6 * the descriptor-set layouts and the descriptor pool textures draw from.
7 *
8 * Nothing about those layouts is written out here: the vertex attributes, the
9 * push constant range and the descriptor bindings are all reflected out of the
10 * compiled SPIR-V by gVKReflect, so the shader sources under
11 * graphics/shaders are the only place the interface is declared. Editing a
12 * shader is enough - the pipeline follows.
13 *
14 * The entry points gvkCreateGraphicsPipelines / gvkReloadGraphicsPipelines /
15 * gvkDestroyGraphicsPipelines are declared in gVKContext.h (so the context can
16 * befriend them); this header adds only what needs no access to the context.
17 */
18
19#pragma once
20
21#ifndef CORE_GVKPIPELINE_H
22#define CORE_GVKPIPELINE_H
23
24#include "gVKContext.h"
25
26#ifdef GVK_VULKAN
27
28#include "gVKReflect.h"
29#include <vector>
30
31// Newest modification time across the shader sources the 2D pipelines are built
32// from, or 0 when runtime shader compilation is unavailable. Comparing successive
33// readings is how the renderer notices an edit worth reloading for.
34long long gvkShaderSourcesTimestamp();
35void gvkDestroyPipelineCache(gVKContext& ctx);
36
37// Created on demand once gDeferredLight has supplied its internal MRT render
38// pass; the main screen pipelines are created earlier during Vulkan init.
39bool gvkCreateDeferredGeometryPipeline(gVKContext& ctx, VkRenderPass renderpass);
40void gvkDestroyDeferredGeometryPipeline(gVKContext& ctx);
41bool gvkCreateDeferredLightingPipeline(gVKContext& ctx);
42void gvkDestroyDeferredLightingPipeline(gVKContext& ctx);
43
44/*
45 * A pipeline built from a shader the application supplied rather than one of the
46 * engine's own. Everything in it is reflected out of the given SPIR-V, exactly as
47 * the built-in pipelines are, so a gShader loaded at run time gets the same
48 * treatment as mesh3d: the shader declares its interface and the layout follows.
49 *
50 * The vertex input is the one exception. It is taken from the engine's own mesh
51 * layout rather than from reflection, because the buffer the draw path binds is
52 * a gVertex array whatever the shader happens to declare. Vulkan allows a
53 * pipeline to describe attributes the shader never reads, so a shader consuming
54 * only position and texcoords still works against the full layout - what it must
55 * not do is declare an input the layout has no attribute for, which
56 * gvkBuildUserPipeline rejects.
57 */
58struct gVKUserPipeline {
59 gVKPipelineVariants variants[GVK_PIPELINE_SAMPLE_VARIANTS];
60 VkPipelineLayout layout = VK_NULL_HANDLE;
61 std::vector<VkDescriptorSetLayout> setlayouts;
62 uint32_t pushsize = 0;
63 VkShaderStageFlags pushstages = 0;
64 // What the shader declared, kept so values can be addressed by name.
65 gVKReflectedLayout reflected;
66 // True when the pipeline describes the engine's gVertex layout, so it can be
67 // drawn with mesh buffers. False means the layout came from reflection and the
68 // shader is fed by the fullscreen quad path instead.
69 bool usesmeshlayout = false;
70 // Bytes per vertex of whichever layout was chosen.
71 uint32_t vertexstride = 0;
72};
73
74// Builds one. Returns false with everything released on any failure, so a caller
75// can report the shader as unloaded and carry on.
76bool gvkBuildUserPipeline(gVKContext& ctx, const std::vector<uint32_t>& vertSpirv,
77 const std::vector<uint32_t>& fragSpirv, const char* debugName, gVKUserPipeline& out);
78
79// Releases one. Safe on an all-null instance, and leaves it that way.
80void gvkDestroyUserPipeline(gVKContext& ctx, gVKUserPipeline& pipeline);
81
82#endif /* GVK_VULKAN */
83
84#endif /* CORE_GVKPIPELINE_H */