zink: use pipe_stencil_ref instead of uint32_t-array
[mesa.git] / src / gallium / drivers / zink / zink_context.h
1 /*
2 * Copyright 2018 Collabora Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
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
13 * Software.
14 *
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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef ZINK_CONTEXT_H
25 #define ZINK_CONTEXT_H
26
27 #include "zink_pipeline.h"
28 #include "zink_batch.h"
29
30 #include "pipe/p_context.h"
31 #include "pipe/p_state.h"
32
33 #include "util/slab.h"
34
35 #include <vulkan/vulkan.h>
36
37 struct blitter_context;
38 struct primconvert_context;
39
40 struct zink_blend_state;
41 struct zink_depth_stencil_alpha_state;
42 struct zink_gfx_program;
43 struct zink_rasterizer_state;
44 struct zink_resource;
45 struct zink_vertex_elements_state;
46
47 struct zink_sampler_view {
48 struct pipe_sampler_view base;
49 VkImageView image_view;
50 };
51
52 static inline struct zink_sampler_view *
53 zink_sampler_view(struct pipe_sampler_view *pview)
54 {
55 return (struct zink_sampler_view *)pview;
56 }
57
58 #define ZINK_DIRTY_PROGRAM (1 << 0)
59
60 struct zink_context {
61 struct pipe_context base;
62 struct slab_child_pool transfer_pool;
63 struct blitter_context *blitter;
64
65 VkCommandPool cmdpool;
66 struct zink_batch batches[4];
67 unsigned curr_batch;
68
69 VkQueue queue;
70
71 struct pipe_constant_buffer ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
72 struct pipe_framebuffer_state fb_state;
73
74 struct zink_vertex_elements_state *element_state;
75 struct zink_rasterizer_state *rast_state;
76
77 struct zink_shader *gfx_stages[PIPE_SHADER_TYPES - 1];
78 struct zink_gfx_pipeline_state gfx_pipeline_state;
79 struct hash_table *program_cache;
80 struct zink_gfx_program *curr_program;
81 unsigned dirty;
82
83 struct hash_table *render_pass_cache;
84 struct hash_table *framebuffer_cache;
85
86 struct primconvert_context *primconvert;
87
88 struct zink_framebuffer *framebuffer;
89
90 VkViewport viewports[PIPE_MAX_VIEWPORTS];
91 unsigned num_viewports;
92
93 VkRect2D scissors[PIPE_MAX_VIEWPORTS];
94 unsigned num_scissors;
95
96 struct pipe_vertex_buffer buffers[PIPE_MAX_ATTRIBS];
97 uint32_t buffers_enabled_mask;
98
99 VkSampler samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
100 struct pipe_sampler_view *image_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
101
102 float blend_constants[4];
103
104 struct pipe_stencil_ref stencil_ref;
105 };
106
107 static inline struct zink_context *
108 zink_context(struct pipe_context *context)
109 {
110 return (struct zink_context *)context;
111 }
112
113 static inline struct zink_batch *
114 zink_curr_batch(struct zink_context *ctx)
115 {
116 assert(ctx->curr_batch < ARRAY_SIZE(ctx->batches));
117 return ctx->batches + ctx->curr_batch;
118 }
119
120 struct zink_batch *
121 zink_batch_rp(struct zink_context *ctx);
122
123 struct zink_batch *
124 zink_batch_no_rp(struct zink_context *ctx);
125
126 void
127 zink_resource_barrier(VkCommandBuffer cmdbuf, struct zink_resource *res,
128 VkImageAspectFlags aspect, VkImageLayout new_layout);
129
130 void
131 zink_begin_render_pass(struct zink_context *ctx,
132 struct zink_batch *batch);
133
134
135 VkShaderStageFlagBits
136 zink_shader_stage(enum pipe_shader_type type);
137
138 struct pipe_context *
139 zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
140
141 void
142 zink_context_query_init(struct pipe_context *ctx);
143
144 #endif