aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/swr/swr_context.h
blob: 73a8e8ddda174409ede25555a9dd60d7c24288ca (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/****************************************************************************
 * Copyright (C) 2015 Intel Corporation.   All Rights Reserved.
 *
 * 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
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS 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 SWR_CONTEXT_H
#define SWR_CONTEXT_H

#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "util/u_blitter.h"
#include "jit_api.h"
#include "swr_state.h"
#include <unordered_map>

#define SWR_NEW_BLEND (1 << 0)
#define SWR_NEW_RASTERIZER (1 << 1)
#define SWR_NEW_DEPTH_STENCIL_ALPHA (1 << 2)
#define SWR_NEW_SAMPLER (1 << 3)
#define SWR_NEW_SAMPLER_VIEW (1 << 4)
#define SWR_NEW_VS (1 << 5)
#define SWR_NEW_FS (1 << 6)
#define SWR_NEW_VSCONSTANTS (1 << 7)
#define SWR_NEW_FSCONSTANTS (1 << 8)
#define SWR_NEW_VERTEX (1 << 9)
#define SWR_NEW_STIPPLE (1 << 10)
#define SWR_NEW_SCISSOR (1 << 11)
#define SWR_NEW_VIEWPORT (1 << 12)
#define SWR_NEW_FRAMEBUFFER (1 << 13)
#define SWR_NEW_CLIP (1 << 14)
#define SWR_NEW_SO (1 << 15)
#define SWR_NEW_ALL 0x0000ffff

namespace std
{
template <> struct hash<BLEND_COMPILE_STATE> {
   std::size_t operator()(const BLEND_COMPILE_STATE &k) const
   {
      return util_hash_crc32(&k, sizeof(k));
   }
};
};

struct swr_jit_texture {
   uint32_t width; // same as number of elements
   uint32_t height;
   uint32_t depth; // doubles as array size
   uint32_t first_level;
   uint32_t last_level;
   const void *base_ptr;
   uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
   uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
   uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS];
};

struct swr_jit_sampler {
   float min_lod;
   float max_lod;
   float lod_bias;
   float border_color[4];
};

struct swr_draw_context {
   const float *constantVS[PIPE_MAX_CONSTANT_BUFFERS];
   unsigned num_constantsVS[PIPE_MAX_CONSTANT_BUFFERS];
   const float *constantFS[PIPE_MAX_CONSTANT_BUFFERS];
   unsigned num_constantsFS[PIPE_MAX_CONSTANT_BUFFERS];

   swr_jit_texture texturesVS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
   swr_jit_sampler samplersVS[PIPE_MAX_SAMPLERS];
   swr_jit_texture texturesFS[PIPE_MAX_SHADER_SAMPLER_VIEWS];
   swr_jit_sampler samplersFS[PIPE_MAX_SAMPLERS];

   SWR_SURFACE_STATE renderTargets[SWR_NUM_ATTACHMENTS];
};

struct swr_context {
   struct pipe_context pipe; /**< base class */

   HANDLE swrContext;

   /** Constant state objects */
   struct swr_blend_state *blend;
   struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
   struct pipe_depth_stencil_alpha_state *depth_stencil;
   struct pipe_rasterizer_state *rasterizer;

   struct swr_vertex_shader *vs;
   struct swr_fragment_shader *fs;
   struct swr_vertex_element_state *velems;

   /** Other rendering state */
   struct pipe_blend_color blend_color;
   struct pipe_stencil_ref stencil_ref;
   struct pipe_clip_state clip;
   struct pipe_constant_buffer
      constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
   struct pipe_framebuffer_state framebuffer;
   struct pipe_poly_stipple poly_stipple;
   struct pipe_scissor_state scissor;
   struct pipe_sampler_view *
      sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];

   struct pipe_viewport_state viewport;
   struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
   struct pipe_index_buffer index_buffer;

   struct blitter_context *blitter;

   /** Conditional query object and mode */
   struct pipe_query *render_cond_query;
   uint render_cond_mode;
   boolean render_cond_cond;
   unsigned active_queries;

   unsigned num_vertex_buffers;
   unsigned num_samplers[PIPE_SHADER_TYPES];
   unsigned num_sampler_views[PIPE_SHADER_TYPES];

   unsigned sample_mask;

   // streamout
   pipe_stream_output_target *so_targets[MAX_SO_STREAMS];
   uint32_t num_so_targets;

   /* Temp storage for user_buffer constants */
   struct swr_scratch_buffers *scratch;

   // blend jit functions
   std::unordered_map<BLEND_COMPILE_STATE, PFN_BLEND_JIT_FUNC> *blendJIT;

   /* Derived SWR API DrawState */
   struct swr_derived_state derived;

   /* SWR private state - draw context */
   struct swr_draw_context swrDC;

   unsigned dirty; /**< Mask of SWR_NEW_x flags */
};

static INLINE struct swr_context *
swr_context(struct pipe_context *pipe)
{
   return (struct swr_context *)pipe;
}

static INLINE void
swr_update_draw_context(struct swr_context *ctx)
{
   swr_draw_context *pDC =
      (swr_draw_context *)SwrGetPrivateContextState(ctx->swrContext);
   memcpy(pDC, &ctx->swrDC, sizeof(swr_draw_context));
}

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

void swr_state_init(struct pipe_context *pipe);

void swr_clear_init(struct pipe_context *pipe);

void swr_draw_init(struct pipe_context *pipe);

void swr_finish(struct pipe_context *pipe);
#endif