Merge remote branch 'main/master' into radeon-rewrite
[mesa.git] / src / gallium / state_trackers / g3dvl / vl_context.c
1 #define VL_INTERNAL
2 #include "vl_context.h"
3 #include <assert.h>
4 #include <pipe/p_context.h>
5 #include <pipe/p_state.h>
6 #include <util/u_memory.h>
7 #include "vl_render.h"
8 #include "vl_r16snorm_mc_buf.h"
9 #include "vl_csc.h"
10 #include "vl_basic_csc.h"
11
12 static int vlInitCommon(struct vlContext *context)
13 {
14 struct pipe_context *pipe;
15 struct pipe_rasterizer_state rast;
16 struct pipe_blend_state blend;
17 struct pipe_depth_stencil_alpha_state dsa;
18 unsigned int i;
19
20 assert(context);
21
22 pipe = context->pipe;
23
24 rast.flatshade = 1;
25 rast.flatshade_first = 0;
26 rast.light_twoside = 0;
27 rast.front_winding = PIPE_WINDING_CCW;
28 rast.cull_mode = PIPE_WINDING_CW;
29 rast.fill_cw = PIPE_POLYGON_MODE_FILL;
30 rast.fill_ccw = PIPE_POLYGON_MODE_FILL;
31 rast.offset_cw = 0;
32 rast.offset_ccw = 0;
33 rast.scissor = 0;
34 rast.poly_smooth = 0;
35 rast.poly_stipple_enable = 0;
36 rast.point_sprite = 0;
37 rast.point_size_per_vertex = 0;
38 rast.multisample = 0;
39 rast.line_smooth = 0;
40 rast.line_stipple_enable = 0;
41 rast.line_stipple_factor = 0;
42 rast.line_stipple_pattern = 0;
43 rast.line_last_pixel = 0;
44 rast.bypass_vs_clip_and_viewport = 0;
45 rast.origin_lower_left = 0;
46 rast.line_width = 1;
47 rast.point_smooth = 0;
48 rast.point_size = 1;
49 rast.offset_units = 1;
50 rast.offset_scale = 1;
51 /*rast.sprite_coord_mode[i] = ;*/
52 context->raster = pipe->create_rasterizer_state(pipe, &rast);
53 pipe->bind_rasterizer_state(pipe, context->raster);
54
55 blend.blend_enable = 0;
56 blend.rgb_func = PIPE_BLEND_ADD;
57 blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
58 blend.rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
59 blend.alpha_func = PIPE_BLEND_ADD;
60 blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
61 blend.alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
62 blend.logicop_enable = 0;
63 blend.logicop_func = PIPE_LOGICOP_CLEAR;
64 /* Needed to allow color writes to FB, even if blending disabled */
65 blend.colormask = PIPE_MASK_RGBA;
66 blend.dither = 0;
67 context->blend = pipe->create_blend_state(pipe, &blend);
68 pipe->bind_blend_state(pipe, context->blend);
69
70 dsa.depth.enabled = 0;
71 dsa.depth.writemask = 0;
72 dsa.depth.func = PIPE_FUNC_ALWAYS;
73 dsa.depth.occlusion_count = 0;
74 for (i = 0; i < 2; ++i)
75 {
76 dsa.stencil[i].enabled = 0;
77 dsa.stencil[i].func = PIPE_FUNC_ALWAYS;
78 dsa.stencil[i].fail_op = PIPE_STENCIL_OP_KEEP;
79 dsa.stencil[i].zpass_op = PIPE_STENCIL_OP_KEEP;
80 dsa.stencil[i].zfail_op = PIPE_STENCIL_OP_KEEP;
81 dsa.stencil[i].ref_value = 0;
82 dsa.stencil[i].valuemask = 0;
83 dsa.stencil[i].writemask = 0;
84 }
85 dsa.alpha.enabled = 0;
86 dsa.alpha.func = PIPE_FUNC_ALWAYS;
87 dsa.alpha.ref_value = 0;
88 context->dsa = pipe->create_depth_stencil_alpha_state(pipe, &dsa);
89 pipe->bind_depth_stencil_alpha_state(pipe, context->dsa);
90
91 return 0;
92 }
93
94 int vlCreateContext
95 (
96 struct vlScreen *screen,
97 struct pipe_context *pipe,
98 unsigned int picture_width,
99 unsigned int picture_height,
100 enum vlFormat picture_format,
101 enum vlProfile profile,
102 enum vlEntryPoint entry_point,
103 struct vlContext **context
104 )
105 {
106 struct vlContext *ctx;
107
108 assert(screen);
109 assert(context);
110 assert(pipe);
111
112 ctx = CALLOC_STRUCT(vlContext);
113
114 if (!ctx)
115 return 1;
116
117 ctx->screen = screen;
118 ctx->pipe = pipe;
119 ctx->picture_width = picture_width;
120 ctx->picture_height = picture_height;
121 ctx->picture_format = picture_format;
122 ctx->profile = profile;
123 ctx->entry_point = entry_point;
124
125 vlInitCommon(ctx);
126
127 vlCreateR16SNormBufferedMC(pipe, picture_width, picture_height, picture_format, &ctx->render);
128 vlCreateBasicCSC(pipe, &ctx->csc);
129
130 *context = ctx;
131
132 return 0;
133 }
134
135 int vlDestroyContext
136 (
137 struct vlContext *context
138 )
139 {
140 assert(context);
141
142 /* XXX: Must unbind shaders before we can delete them for some reason */
143 context->pipe->bind_vs_state(context->pipe, NULL);
144 context->pipe->bind_fs_state(context->pipe, NULL);
145
146 context->render->vlDestroy(context->render);
147 context->csc->vlDestroy(context->csc);
148
149 context->pipe->delete_blend_state(context->pipe, context->blend);
150 context->pipe->delete_rasterizer_state(context->pipe, context->raster);
151 context->pipe->delete_depth_stencil_alpha_state(context->pipe, context->dsa);
152
153 FREE(context);
154
155 return 0;
156 }
157
158 struct vlScreen* vlContextGetScreen
159 (
160 struct vlContext *context
161 )
162 {
163 assert(context);
164
165 return context->screen;
166 }
167
168 struct pipe_context* vlGetPipeContext
169 (
170 struct vlContext *context
171 )
172 {
173 assert(context);
174
175 return context->pipe;
176 }
177
178 unsigned int vlGetPictureWidth
179 (
180 struct vlContext *context
181 )
182 {
183 assert(context);
184
185 return context->picture_width;
186 }
187
188 unsigned int vlGetPictureHeight
189 (
190 struct vlContext *context
191 )
192 {
193 assert(context);
194
195 return context->picture_height;
196 }
197
198 enum vlFormat vlGetPictureFormat
199 (
200 struct vlContext *context
201 )
202 {
203 assert(context);
204
205 return context->picture_format;
206 }