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