summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/zink/zink_context.h
blob: 147f35f6d18a2ffd65ace3cf848dcc095ff1a534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * Copyright 2018 Collabora Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef ZINK_CONTEXT_H
#define ZINK_CONTEXT_H

#include "zink_pipeline.h"
#include "zink_batch.h"

#include "pipe/p_context.h"
#include "pipe/p_state.h"

#include "util/slab.h"
#include "util/list.h"

#include <vulkan/vulkan.h>

struct blitter_context;
struct primconvert_context;
struct list_head;

struct zink_blend_state;
struct zink_depth_stencil_alpha_state;
struct zink_gfx_program;
struct zink_rasterizer_state;
struct zink_resource;
struct zink_vertex_elements_state;

struct zink_sampler_view {
   struct pipe_sampler_view base;
   VkImageView image_view;
};

static inline struct zink_sampler_view *
zink_sampler_view(struct pipe_sampler_view *pview)
{
   return (struct zink_sampler_view *)pview;
}

#define ZINK_DIRTY_PROGRAM (1 << 0)

struct zink_context {
   struct pipe_context base;
   struct slab_child_pool transfer_pool;
   struct blitter_context *blitter;

   VkCommandPool cmdpool;
   struct zink_batch batches[4];
   unsigned curr_batch;

   VkQueue queue;

   struct pipe_constant_buffer ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
   struct pipe_framebuffer_state fb_state;

   struct zink_vertex_elements_state *element_state;
   struct zink_rasterizer_state *rast_state;

   struct zink_shader *gfx_stages[PIPE_SHADER_TYPES - 1];
   struct zink_gfx_pipeline_state gfx_pipeline_state;
   struct hash_table *program_cache;
   struct zink_gfx_program *curr_program;
   unsigned dirty;

   struct hash_table *render_pass_cache;
   struct hash_table *framebuffer_cache;

   struct primconvert_context *primconvert;

   struct zink_framebuffer *framebuffer;

   struct pipe_viewport_state viewport_states[PIPE_MAX_VIEWPORTS];
   VkViewport viewports[PIPE_MAX_VIEWPORTS];
   unsigned num_viewports;

   struct pipe_scissor_state scissor_states[PIPE_MAX_VIEWPORTS];
   VkRect2D scissors[PIPE_MAX_VIEWPORTS];
   unsigned num_scissors;

   struct pipe_vertex_buffer buffers[PIPE_MAX_ATTRIBS];
   uint32_t buffers_enabled_mask;

   VkSampler samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
   unsigned num_samplers[PIPE_SHADER_TYPES];
   struct pipe_sampler_view *image_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
   unsigned num_image_views[PIPE_SHADER_TYPES];

   float blend_constants[4];

   struct pipe_stencil_ref stencil_ref;

   struct list_head active_queries;
   bool queries_disabled;
};

static inline struct zink_context *
zink_context(struct pipe_context *context)
{
   return (struct zink_context *)context;
}

static inline struct zink_batch *
zink_curr_batch(struct zink_context *ctx)
{
   assert(ctx->curr_batch < ARRAY_SIZE(ctx->batches));
   return ctx->batches + ctx->curr_batch;
}

struct zink_batch *
zink_batch_rp(struct zink_context *ctx);

struct zink_batch *
zink_batch_no_rp(struct zink_context *ctx);

void
zink_resource_barrier(VkCommandBuffer cmdbuf, struct zink_resource *res,
                      VkImageAspectFlags aspect, VkImageLayout new_layout);

 void
 zink_begin_render_pass(struct zink_context *ctx,
                        struct zink_batch *batch);


VkShaderStageFlagBits
zink_shader_stage(enum pipe_shader_type type);

struct pipe_context *
zink_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);

void
zink_context_query_init(struct pipe_context *ctx);

#endif