swr: [rasterizer core] only use Viewport/Scissors during SwrDraw* operations
[mesa.git] / src / gallium / drivers / swr / swr_context.h
1 /****************************************************************************
2 * Copyright (C) 2015 Intel Corporation. All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 ***************************************************************************/
23
24 #ifndef SWR_CONTEXT_H
25 #define SWR_CONTEXT_H
26
27 #include "pipe/p_context.h"
28 #include "pipe/p_state.h"
29 #include "util/u_blitter.h"
30 #include "jit_api.h"
31 #include "swr_state.h"
32 #include <unordered_map>
33
34 #define SWR_NEW_BLEND (1 << 0)
35 #define SWR_NEW_RASTERIZER (1 << 1)
36 #define SWR_NEW_DEPTH_STENCIL_ALPHA (1 << 2)
37 #define SWR_NEW_SAMPLER (1 << 3)
38 #define SWR_NEW_SAMPLER_VIEW (1 << 4)
39 #define SWR_NEW_VS (1 << 5)
40 #define SWR_NEW_FS (1 << 6)
41 #define SWR_NEW_VSCONSTANTS (1 << 7)
42 #define SWR_NEW_FSCONSTANTS (1 << 8)
43 #define SWR_NEW_VERTEX (1 << 9)
44 #define SWR_NEW_STIPPLE (1 << 10)
45 #define SWR_NEW_SCISSOR (1 << 11)
46 #define SWR_NEW_VIEWPORT (1 << 12)
47 #define SWR_NEW_FRAMEBUFFER (1 << 13)
48 #define SWR_NEW_CLIP (1 << 14)
49 #define SWR_NEW_SO (1 << 15)
50 #define SWR_NEW_ALL 0x0000ffff
51
52 namespace std
53 {
54 template <> struct hash<BLEND_COMPILE_STATE> {
55 std::size_t operator()(const BLEND_COMPILE_STATE &k) const
56 {
57 return util_hash_crc32(&k, sizeof(k));
58 }
59 };
60 };
61
62 struct swr_jit_texture {
63 uint32_t width; // same as number of elements
64 uint32_t height;
65 uint32_t depth; // doubles as array size
66 uint32_t first_level;
67 uint32_t last_level;
68 const uint8_t *base_ptr;
69 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
70 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
71 uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
72 };
73
74 struct swr_jit_sampler {
75 float min_lod;
76 float max_lod;
77 float lod_bias;
78 float border_color[4];
79 };
80
81 struct swr_draw_context {
82 const float *constantVS[PIPE_MAX_CONSTANT_BUFFERS];
83 uint32_t num_constantsVS[PIPE_MAX_CONSTANT_BUFFERS];
84 const float *constantFS[PIPE_MAX_CONSTANT_BUFFERS];
85 uint32_t num_constantsFS[PIPE_MAX_CONSTANT_BUFFERS];
86
87 swr_jit_texture texturesVS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
88 swr_jit_sampler samplersVS[PIPE_MAX_SAMPLERS];
89 swr_jit_texture texturesFS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
90 swr_jit_sampler samplersFS[PIPE_MAX_SAMPLERS];
91
92 float userClipPlanes[PIPE_MAX_CLIP_PLANES][4];
93
94 SWR_SURFACE_STATE renderTargets[SWR_NUM_ATTACHMENTS];
95 void *swr_ctx;
96 };
97
98 /* gen_llvm_types FINI */
99
100 struct swr_context {
101 struct pipe_context pipe; /**< base class */
102
103 HANDLE swrContext;
104
105 /** Constant state objects */
106 struct swr_blend_state *blend;
107 struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
108 struct pipe_depth_stencil_alpha_state *depth_stencil;
109 struct pipe_rasterizer_state *rasterizer;
110
111 struct swr_vertex_shader *vs;
112 struct swr_fragment_shader *fs;
113 struct swr_vertex_element_state *velems;
114
115 /** Other rendering state */
116 struct pipe_blend_color blend_color;
117 struct pipe_stencil_ref stencil_ref;
118 struct pipe_clip_state clip;
119 struct pipe_constant_buffer
120 constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
121 struct pipe_framebuffer_state framebuffer;
122 struct pipe_poly_stipple poly_stipple;
123 struct pipe_scissor_state scissor;
124 SWR_RECT swr_scissor;
125 struct pipe_sampler_view *
126 sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
127
128 struct pipe_viewport_state viewport;
129 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
130 struct pipe_index_buffer index_buffer;
131
132 struct blitter_context *blitter;
133
134 /** Conditional query object and mode */
135 struct pipe_query *render_cond_query;
136 uint render_cond_mode;
137 boolean render_cond_cond;
138 unsigned active_queries;
139
140 unsigned num_vertex_buffers;
141 unsigned num_samplers[PIPE_SHADER_TYPES];
142 unsigned num_sampler_views[PIPE_SHADER_TYPES];
143
144 unsigned sample_mask;
145
146 // streamout
147 pipe_stream_output_target *so_targets[MAX_SO_STREAMS];
148 uint32_t num_so_targets;
149
150 /* Temp storage for user_buffer constants */
151 struct swr_scratch_buffers *scratch;
152
153 // blend jit functions
154 std::unordered_map<BLEND_COMPILE_STATE, PFN_BLEND_JIT_FUNC> *blendJIT;
155
156 /* Derived SWR API DrawState */
157 struct swr_derived_state derived;
158
159 /* SWR private state - draw context */
160 struct swr_draw_context swrDC;
161
162 SWR_STATS stats;
163 SWR_STATS_FE statsFE;
164
165 unsigned dirty; /**< Mask of SWR_NEW_x flags */
166 };
167
168 static INLINE struct swr_context *
169 swr_context(struct pipe_context *pipe)
170 {
171 return (struct swr_context *)pipe;
172 }
173
174 static INLINE void
175 swr_update_draw_context(struct swr_context *ctx)
176 {
177 swr_draw_context *pDC =
178 (swr_draw_context *)SwrGetPrivateContextState(ctx->swrContext);
179 ctx->swrDC.swr_ctx = ctx;
180 memcpy(pDC, &ctx->swrDC, sizeof(swr_draw_context));
181 }
182
183 struct pipe_context *swr_create_context(struct pipe_screen *, void *priv, unsigned flags);
184
185 void swr_state_init(struct pipe_context *pipe);
186
187 void swr_clear_init(struct pipe_context *pipe);
188
189 void swr_draw_init(struct pipe_context *pipe);
190
191 void swr_finish(struct pipe_context *pipe);
192 #endif