2 * Copyright 2018 Collabora Ltd.
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:
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 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.
24 #ifndef ZINK_CONTEXT_H
25 #define ZINK_CONTEXT_H
27 #include "zink_pipeline.h"
28 #include "zink_batch.h"
30 #include "pipe/p_context.h"
31 #include "pipe/p_state.h"
33 #include "util/slab.h"
34 #include "util/list.h"
36 #include <vulkan/vulkan.h>
38 struct blitter_context
;
39 struct primconvert_context
;
42 struct zink_blend_state
;
43 struct zink_depth_stencil_alpha_state
;
44 struct zink_gfx_program
;
45 struct zink_rasterizer_state
;
47 struct zink_vertex_elements_state
;
49 struct zink_sampler_view
{
50 struct pipe_sampler_view base
;
51 VkImageView image_view
;
54 static inline struct zink_sampler_view
*
55 zink_sampler_view(struct pipe_sampler_view
*pview
)
57 return (struct zink_sampler_view
*)pview
;
60 struct zink_so_target
{
61 struct pipe_stream_output_target base
;
62 struct pipe_resource
*counter_buffer
;
63 VkDeviceSize counter_buffer_offset
;
65 bool counter_buffer_valid
;
68 static inline struct zink_so_target
*
69 zink_so_target(struct pipe_stream_output_target
*so_target
)
71 return (struct zink_so_target
*)so_target
;
75 struct pipe_context base
;
76 struct slab_child_pool transfer_pool
;
77 struct blitter_context
*blitter
;
79 VkCommandPool cmdpool
;
80 struct zink_batch batches
[4];
85 struct pipe_constant_buffer ubos
[PIPE_SHADER_TYPES
][PIPE_MAX_CONSTANT_BUFFERS
];
86 struct pipe_framebuffer_state fb_state
;
88 struct zink_vertex_elements_state
*element_state
;
89 struct zink_rasterizer_state
*rast_state
;
91 struct zink_shader
*gfx_stages
[PIPE_SHADER_TYPES
- 1];
92 struct zink_gfx_pipeline_state gfx_pipeline_state
;
93 struct hash_table
*program_cache
;
94 struct zink_gfx_program
*curr_program
;
96 unsigned dirty_program
: 1;
98 struct hash_table
*render_pass_cache
;
100 struct primconvert_context
*primconvert
;
102 struct zink_framebuffer
*framebuffer
;
104 struct pipe_viewport_state viewport_states
[PIPE_MAX_VIEWPORTS
];
105 struct pipe_scissor_state scissor_states
[PIPE_MAX_VIEWPORTS
];
106 VkViewport viewports
[PIPE_MAX_VIEWPORTS
];
107 VkRect2D scissors
[PIPE_MAX_VIEWPORTS
];
108 unsigned num_viewports
;
110 struct pipe_vertex_buffer buffers
[PIPE_MAX_ATTRIBS
];
111 uint32_t buffers_enabled_mask
;
113 void *sampler_states
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
114 VkSampler samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
115 unsigned num_samplers
[PIPE_SHADER_TYPES
];
116 struct pipe_sampler_view
*image_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_SAMPLER_VIEWS
];
117 unsigned num_image_views
[PIPE_SHADER_TYPES
];
120 float blend_constants
[4];
122 struct pipe_stencil_ref stencil_ref
;
124 struct list_head suspended_queries
;
125 bool queries_disabled
;
127 struct pipe_resource
*dummy_buffer
;
128 struct pipe_resource
*null_buffers
[5]; /* used to create zink_framebuffer->null_surface, one buffer per samplecount */
130 uint32_t num_so_targets
;
131 struct pipe_stream_output_target
*so_targets
[PIPE_MAX_SO_OUTPUTS
];
132 bool dirty_so_targets
;
136 static inline struct zink_context
*
137 zink_context(struct pipe_context
*context
)
139 return (struct zink_context
*)context
;
142 static inline struct zink_batch
*
143 zink_curr_batch(struct zink_context
*ctx
)
145 assert(ctx
->curr_batch
< ARRAY_SIZE(ctx
->batches
));
146 return ctx
->batches
+ ctx
->curr_batch
;
150 zink_batch_rp(struct zink_context
*ctx
);
153 zink_batch_no_rp(struct zink_context
*ctx
);
156 zink_resource_barrier(VkCommandBuffer cmdbuf
, struct zink_resource
*res
,
157 VkImageAspectFlags aspect
, VkImageLayout new_layout
);
160 zink_begin_render_pass(struct zink_context
*ctx
,
161 struct zink_batch
*batch
);
164 VkShaderStageFlagBits
165 zink_shader_stage(enum pipe_shader_type type
);
167 struct pipe_context
*
168 zink_context_create(struct pipe_screen
*pscreen
, void *priv
, unsigned flags
);
171 zink_context_query_init(struct pipe_context
*ctx
);
174 zink_blit(struct pipe_context
*pctx
,
175 const struct pipe_blit_info
*info
);
178 zink_draw_vbo(struct pipe_context
*pctx
,
179 const struct pipe_draw_info
*dinfo
);