zink: use ZINK_SHADER_COUNT instead of PIPE_SHADER_TYPES - 1 everywhere
[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 #include "util/list.h"
35
36 #include <vulkan/vulkan.h>
37
38 struct blitter_context;
39 struct primconvert_context;
40 struct list_head;
41
42 struct zink_blend_state;
43 struct zink_depth_stencil_alpha_state;
44 struct zink_gfx_program;
45 struct zink_rasterizer_state;
46 struct zink_resource;
47 struct zink_vertex_elements_state;
48
49 struct zink_sampler_view {
50 struct pipe_sampler_view base;
51 VkImageView image_view;
52 };
53
54 static inline struct zink_sampler_view *
55 zink_sampler_view(struct pipe_sampler_view *pview)
56 {
57 return (struct zink_sampler_view *)pview;
58 }
59
60 struct zink_so_target {
61 struct pipe_stream_output_target base;
62 struct pipe_resource *counter_buffer;
63 VkDeviceSize counter_buffer_offset;
64 uint32_t stride;
65 bool counter_buffer_valid;
66 };
67
68 static inline struct zink_so_target *
69 zink_so_target(struct pipe_stream_output_target *so_target)
70 {
71 return (struct zink_so_target *)so_target;
72 }
73
74 #define ZINK_SHADER_COUNT (PIPE_SHADER_TYPES - 1)
75
76 struct zink_context {
77 struct pipe_context base;
78 struct slab_child_pool transfer_pool;
79 struct blitter_context *blitter;
80
81 VkCommandPool cmdpool;
82 struct zink_batch batches[4];
83 unsigned curr_batch;
84
85 VkQueue queue;
86
87 struct pipe_constant_buffer ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
88 struct pipe_framebuffer_state fb_state;
89
90 struct zink_vertex_elements_state *element_state;
91 struct zink_rasterizer_state *rast_state;
92
93 struct zink_shader *gfx_stages[ZINK_SHADER_COUNT];
94 struct zink_gfx_pipeline_state gfx_pipeline_state;
95 struct hash_table *program_cache;
96 struct zink_gfx_program *curr_program;
97
98 unsigned dirty_program : 1;
99
100 struct hash_table *render_pass_cache;
101
102 struct primconvert_context *primconvert;
103
104 struct zink_framebuffer *framebuffer;
105
106 struct pipe_viewport_state viewport_states[PIPE_MAX_VIEWPORTS];
107 struct pipe_scissor_state scissor_states[PIPE_MAX_VIEWPORTS];
108 VkViewport viewports[PIPE_MAX_VIEWPORTS];
109 VkRect2D scissors[PIPE_MAX_VIEWPORTS];
110 unsigned num_viewports;
111
112 struct pipe_vertex_buffer buffers[PIPE_MAX_ATTRIBS];
113 uint32_t buffers_enabled_mask;
114
115 void *sampler_states[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
116 VkSampler samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
117 unsigned num_samplers[PIPE_SHADER_TYPES];
118 struct pipe_sampler_view *image_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
119 unsigned num_image_views[PIPE_SHADER_TYPES];
120
121 float line_width;
122 float blend_constants[4];
123
124 struct pipe_stencil_ref stencil_ref;
125
126 struct list_head suspended_queries;
127 bool queries_disabled;
128
129 struct pipe_resource *dummy_buffer;
130 struct pipe_resource *null_buffers[5]; /* used to create zink_framebuffer->null_surface, one buffer per samplecount */
131
132 uint32_t num_so_targets;
133 struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_OUTPUTS];
134 bool dirty_so_targets;
135 bool xfb_barrier;
136 };
137
138 static inline struct zink_context *
139 zink_context(struct pipe_context *context)
140 {
141 return (struct zink_context *)context;
142 }
143
144 static inline struct zink_batch *
145 zink_curr_batch(struct zink_context *ctx)
146 {
147 assert(ctx->curr_batch < ARRAY_SIZE(ctx->batches));
148 return ctx->batches + ctx->curr_batch;
149 }
150
151 struct zink_batch *
152 zink_batch_rp(struct zink_context *ctx);
153
154 struct zink_batch *
155 zink_batch_no_rp(struct zink_context *ctx);
156
157 void
158 zink_resource_barrier(VkCommandBuffer cmdbuf, struct zink_resource *res,
159 VkImageAspectFlags aspect, VkImageLayout new_layout);
160
161 void
162 zink_begin_render_pass(struct zink_context *ctx,
163 struct zink_batch *batch);
164
165
166 VkShaderStageFlagBits
167 zink_shader_stage(enum pipe_shader_type type);
168
169 struct pipe_context *
170 zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
171
172 void
173 zink_context_query_init(struct pipe_context *ctx);
174
175 void
176 zink_blit(struct pipe_context *pctx,
177 const struct pipe_blit_info *info);
178
179 void
180 zink_draw_vbo(struct pipe_context *pctx,
181 const struct pipe_draw_info *dinfo);
182
183 #endif