• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 Francisco Jerez.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial
15  * portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26 
27 #ifndef __NOUVEAU_CONTEXT_H__
28 #define __NOUVEAU_CONTEXT_H__
29 
30 #include "nouveau_screen.h"
31 #include "nouveau_state.h"
32 #include "nouveau_scratch.h"
33 #include "nouveau_render.h"
34 
35 #include "util/bitset.h"
36 
37 enum nouveau_fallback {
38 	HWTNL = 0,
39 	SWTNL,
40 	SWRAST,
41 };
42 
43 #define BUFCTX_FB      0
44 #define BUFCTX_VTX     1
45 #define BUFCTX_TEX(i) (2 + (i))
46 
47 struct nouveau_hw_state {
48 	struct nouveau_object *chan;
49 	struct nouveau_client *client;
50 	struct nouveau_pushbuf *pushbuf;
51 	struct nouveau_bufctx *bufctx;
52 
53 	struct nouveau_object *null;
54 	struct nouveau_object *ntfy;
55 	struct nouveau_object *eng3d;
56 	struct nouveau_object *eng3dm;
57 	struct nouveau_object *surf3d;
58 	struct nouveau_object *m2mf;
59 	struct nouveau_object *surf2d;
60 	struct nouveau_object *rop;
61 	struct nouveau_object *patt;
62 	struct nouveau_object *rect;
63 	struct nouveau_object *swzsurf;
64 	struct nouveau_object *sifm;
65 };
66 
67 struct nouveau_context {
68 	struct gl_context base;
69 	__DRIcontext *dri_context;
70 	struct nouveau_screen *screen;
71 
72 	BITSET_DECLARE(dirty, MAX_NOUVEAU_STATE);
73 	enum nouveau_fallback fallback;
74 
75 	struct nouveau_bo *fence;
76 
77 	struct nouveau_hw_state hw;
78 	struct nouveau_render_state render;
79 	struct nouveau_scratch_state scratch;
80 
81 	struct {
82 		GLboolean clear_blocked;
83 		int clear_seq;
84 	} hierz;
85 };
86 
87 #define to_nouveau_context(ctx)	((struct nouveau_context *)(ctx))
88 
89 #define context_dev(ctx) \
90 	(to_nouveau_context(ctx)->screen->device)
91 #define context_chipset(ctx) \
92 	(context_dev(ctx)->chipset)
93 #define context_chan(ctx) \
94 	(to_nouveau_context(ctx)->hw.chan)
95 #define context_client(ctx) \
96 	(to_nouveau_context(ctx)->hw.client)
97 #define context_push(ctx) \
98 	(to_nouveau_context(ctx)->hw.pushbuf)
99 #define context_eng3d(ctx) \
100 	(to_nouveau_context(ctx)->hw.eng3d)
101 #define context_drv(ctx) \
102 	(to_nouveau_context(ctx)->screen->driver)
103 #define context_dirty(ctx, s) \
104 	BITSET_SET(to_nouveau_context(ctx)->dirty, NOUVEAU_STATE_##s)
105 #define context_dirty_i(ctx, s, i) \
106 	BITSET_SET(to_nouveau_context(ctx)->dirty, NOUVEAU_STATE_##s##0 + i)
107 #define context_emit(ctx, s) \
108 	context_drv(ctx)->emit[NOUVEAU_STATE_##s](ctx, NOUVEAU_STATE_##s)
109 
110 GLboolean
111 nouveau_context_create(gl_api api,
112 		       const struct gl_config *visual, __DRIcontext *dri_ctx,
113 		       const struct __DriverContextConfig *ctx_config,
114 		       unsigned *error, void *share_ctx);
115 
116 GLboolean
117 nouveau_context_init(struct gl_context *ctx, gl_api api,
118 		     struct nouveau_screen *screen,
119 		     const struct gl_config *visual, struct gl_context *share_ctx);
120 
121 void
122 nouveau_context_deinit(struct gl_context *ctx);
123 
124 void
125 nouveau_context_destroy(__DRIcontext *dri_ctx);
126 
127 void
128 nouveau_update_renderbuffers(__DRIcontext *dri_ctx, __DRIdrawable *draw);
129 
130 GLboolean
131 nouveau_context_make_current(__DRIcontext *dri_ctx, __DRIdrawable *ddraw,
132 			     __DRIdrawable *rdraw);
133 
134 GLboolean
135 nouveau_context_unbind(__DRIcontext *dri_ctx);
136 
137 void
138 nouveau_fallback(struct gl_context *ctx, enum nouveau_fallback mode);
139 
140 void
141 nouveau_validate_framebuffer(struct gl_context *ctx);
142 
143 #endif
144 
145