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