gallium: make p_winsys internal
[mesa.git] / src / gallium / drivers / nv50 / nv50_context.c
index 3c5a54bfd3803eef87c0cb948ec89c6e37009831..99776239d2bc7814eaf3f5e5a8ae6194e930d26c 100644 (file)
+/*
+ * Copyright 2008 Ben Skeggs
+ *
+ * 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 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 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.
+ */
+
 #include "draw/draw_context.h"
 #include "pipe/p_defines.h"
-#include "pipe/p_winsys.h"
-#include "pipe/p_util.h"
+#include "pipe/internal/p_winsys_screen.h"
 
 #include "nv50_context.h"
-
-static boolean
-nv50_is_format_supported(struct pipe_context *pipe, enum pipe_format format,
-                        uint type)
-{
-       return FALSE;
-}
-
-static const char *
-nv50_get_name(struct pipe_context *pipe)
-{
-       struct nv50_context *nv50 = (struct nv50_context *)pipe;
-       static char buffer[128];
-
-       snprintf(buffer, sizeof(buffer), "NV%02X", nv50->chipset);
-       return buffer;
-}
-
-static const char *
-nv50_get_vendor(struct pipe_context *pipe)
-{
-       return "nouveau";
-}
-
-static int
-nv50_get_param(struct pipe_context *pipe, int param)
-{
-       switch (param) {
-       case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
-               return 32;
-       case PIPE_CAP_NPOT_TEXTURES:
-               return 0;
-       case PIPE_CAP_TWO_SIDED_STENCIL:
-               return 1;
-       case PIPE_CAP_GLSL:
-               return 0;
-       case PIPE_CAP_S3TC:
-               return 0;
-       case PIPE_CAP_ANISOTROPIC_FILTER:
-               return 0;
-       case PIPE_CAP_POINT_SPRITE:
-               return 0;
-       case PIPE_CAP_MAX_RENDER_TARGETS:
-               return 8;
-       case PIPE_CAP_OCCLUSION_QUERY:
-               return 0;
-       case PIPE_CAP_TEXTURE_SHADOW_MAP:
-               return 0;
-       case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
-               return 13;
-       case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
-               return 10;
-       case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
-               return 13;
-       default:
-               NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
-               return 0;
-       }
-}
-
-static float
-nv50_get_paramf(struct pipe_context *pipe, int param)
-{
-       switch (param) {
-       case PIPE_CAP_MAX_LINE_WIDTH:
-       case PIPE_CAP_MAX_LINE_WIDTH_AA:
-               return 10.0;
-       case PIPE_CAP_MAX_POINT_WIDTH:
-       case PIPE_CAP_MAX_POINT_WIDTH_AA:
-               return 64.0;
-       case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
-               return 16.0;
-       case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
-               return 4.0;
-       default:
-               NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param);
-               return 0.0;
-       }
-}
+#include "nv50_screen.h"
 
 static void
-nv50_flush(struct pipe_context *pipe, unsigned flags)
+nv50_flush(struct pipe_context *pipe, unsigned flags,
+          struct pipe_fence_handle **fence)
 {
        struct nv50_context *nv50 = (struct nv50_context *)pipe;
-       struct nouveau_winsys *nvws = nv50->nvws;
        
-       if (flags & PIPE_FLUSH_WAIT) {
-               nvws->notifier_reset(nv50->sync, 0);
-               BEGIN_RING(tesla, 0x104, 1);
-               OUT_RING  (0);
-               BEGIN_RING(tesla, 0x100, 1);
-               OUT_RING  (0);
-       }
-
-       FIRE_RING();
-
-       if (flags & PIPE_FLUSH_WAIT)
-               nvws->notifier_wait(nv50->sync, 0, 0, 2000);
+       FIRE_RING(fence);
 }
 
 static void
@@ -110,84 +42,40 @@ nv50_destroy(struct pipe_context *pipe)
        struct nv50_context *nv50 = (struct nv50_context *)pipe;
 
        draw_destroy(nv50->draw);
-       free(nv50);
+       FREE(nv50);
 }
 
-static boolean
-nv50_init_hwctx(struct nv50_context *nv50, int tesla_class)
-{
-       struct nouveau_winsys *nvws = nv50->nvws;
-       int ret;
-
-       if ((ret = nvws->grobj_alloc(nvws, tesla_class, &nv50->tesla))) {
-               NOUVEAU_ERR("Error creating 3D object: %d\n", ret);
-               return FALSE;
-       }
-
-       BEGIN_RING(tesla, NV50TCL_DMA_NOTIFY, 1);
-       OUT_RING  (nv50->sync->handle);
 
-       FIRE_RING ();
-       return TRUE;
+static void
+nv50_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield)
+{
 }
 
-#define GRCLASS5097_CHIPSETS 0x00000000
-#define GRCLASS8297_CHIPSETS 0x00000010
 struct pipe_context *
-nv50_create(struct pipe_winsys *pipe_winsys, struct nouveau_winsys *nvws,
-           unsigned chipset)
+nv50_create(struct pipe_screen *pscreen, unsigned pctx_id)
 {
+       struct pipe_winsys *pipe_winsys = pscreen->winsys;
+       struct nv50_screen *screen = nv50_screen(pscreen);
        struct nv50_context *nv50;
-       int tesla_class, ret;
-
-       if ((chipset & 0xf0) != 0x50 && (chipset & 0xf0) != 0x80) {
-               NOUVEAU_ERR("Not a G8x chipset\n");
-               return NULL;
-       }
-
-       if (GRCLASS5097_CHIPSETS & (1 << (chipset & 0x0f))) {
-               tesla_class = 0x5097;
-       } else
-       if (GRCLASS8297_CHIPSETS & (1 << (chipset & 0x0f))) {
-               tesla_class = 0x8297;
-       } else {
-               NOUVEAU_ERR("Unknown G8x chipset: NV%02x\n", chipset);
-               return NULL;
-       }
 
        nv50 = CALLOC_STRUCT(nv50_context);
        if (!nv50)
                return NULL;
-       nv50->chipset = chipset;
-       nv50->nvws = nvws;
-
-       if ((ret = nvws->notifier_alloc(nvws, 1, &nv50->sync))) {
-               NOUVEAU_ERR("Error creating notifier object: %d\n", ret);
-               free(nv50);
-               return NULL;
-       }
-
-       if (!nv50_init_hwctx(nv50, tesla_class)) {
-               free(nv50);
-               return NULL;
-       }
+       nv50->screen = screen;
+       nv50->pctx_id = pctx_id;
 
        nv50->pipe.winsys = pipe_winsys;
+       nv50->pipe.screen = pscreen;
 
        nv50->pipe.destroy = nv50_destroy;
-       nv50->pipe.is_format_supported = nv50_is_format_supported;
-       nv50->pipe.get_name = nv50_get_name;
-       nv50->pipe.get_vendor = nv50_get_vendor;
-       nv50->pipe.get_param = nv50_get_param;
-       nv50->pipe.get_paramf = nv50_get_paramf;
 
+       nv50->pipe.set_edgeflags = nv50_set_edgeflags;
        nv50->pipe.draw_arrays = nv50_draw_arrays;
        nv50->pipe.draw_elements = nv50_draw_elements;
        nv50->pipe.clear = nv50_clear;
 
        nv50->pipe.flush = nv50_flush;
 
-       nv50_init_miptree_functions(nv50);
        nv50_init_surface_functions(nv50);
        nv50_init_state_functions(nv50);
        nv50_init_query_functions(nv50);