Squashed commit of the following:
[mesa.git] / src / gallium / drivers / nvfx / nvfx_screen.c
index 6cbd8b23e1f033f59443788c29faa2aec4795f18..1f6e6e34973b5df5a600c970277f5e771c6e5690 100644 (file)
@@ -1,10 +1,12 @@
 #include "pipe/p_screen.h"
 #include "pipe/p_state.h"
+#include "util/u_simple_screen.h"
 
 #include "nouveau/nouveau_screen.h"
 
 #include "nvfx_context.h"
 #include "nvfx_screen.h"
+#include "nvfx_resource.h"
 
 #define NV30TCL_CHIPSET_3X_MASK 0x00000003
 #define NV34TCL_CHIPSET_3X_MASK 0x00000010
@@ -122,7 +124,7 @@ nvfx_screen_surface_format_supported(struct pipe_screen *pscreen,
        struct nvfx_screen *screen = nvfx_screen(pscreen);
        struct pipe_surface *front = ((struct nouveau_winsys *) pscreen->winsys)->front;
 
-       if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
+       if (tex_usage & PIPE_BIND_RENDER_TARGET) {
                switch (format) {
                case PIPE_FORMAT_B8G8R8A8_UNORM:
                case PIPE_FORMAT_B5G6R5_UNORM:
@@ -131,9 +133,9 @@ nvfx_screen_surface_format_supported(struct pipe_screen *pscreen,
                        break;
                }
        } else
-       if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) {
+       if (tex_usage & PIPE_BIND_DEPTH_STENCIL) {
                switch (format) {
-               case PIPE_FORMAT_S8Z24_UNORM:
+               case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
                case PIPE_FORMAT_X8Z24_UNORM:
                        return TRUE;
                case PIPE_FORMAT_Z16_UNORM:
@@ -155,7 +157,7 @@ nvfx_screen_surface_format_supported(struct pipe_screen *pscreen,
                case PIPE_FORMAT_I8_UNORM:
                case PIPE_FORMAT_L8A8_UNORM:
                case PIPE_FORMAT_Z16_UNORM:
-               case PIPE_FORMAT_S8Z24_UNORM:
+               case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
                case PIPE_FORMAT_DXT1_RGB:
                case PIPE_FORMAT_DXT1_RGBA:
                case PIPE_FORMAT_DXT3_RGBA:
@@ -172,13 +174,6 @@ nvfx_screen_surface_format_supported(struct pipe_screen *pscreen,
        return FALSE;
 }
 
-static struct pipe_buffer *
-nvfx_surface_buffer(struct pipe_surface *surf)
-{
-       struct nvfx_miptree *mt = (struct nvfx_miptree *)surf->texture;
-
-       return mt->buffer;
-}
 
 static void
 nvfx_screen_destroy(struct pipe_screen *pscreen)
@@ -293,6 +288,36 @@ static void nv40_screen_init(struct nvfx_screen *screen, struct nouveau_stateobj
        so_data  (so, 0x00000001);
 }
 
+static void
+nvfx_screen_init_buffer_functions(struct nvfx_screen* screen)
+{
+       int vram_hack_default = 0;
+       int vram_hack;
+       // TODO: this is a bit of a guess; also add other cards that may need this hack.
+       // It may also depend on the specific card or the AGP/PCIe chipset.
+       if(screen->base.device->chipset == 0x47 /* G70 */
+               || screen->base.device->chipset == 0x49 /* G71 */
+               || screen->base.device->chipset == 0x46 /* G72 */
+               )
+               vram_hack_default = 1;
+       vram_hack = debug_get_bool_option("NOUVEAU_VTXIDX_IN_VRAM", vram_hack_default);
+
+#ifdef DEBUG
+       if(!vram_hack)
+       {
+               fprintf(stderr, "Some systems may experience graphics corruption due to randomly misplaced vertices.\n"
+                       "If this is happening, export NOUVEAU_VTXIDX_IN_VRAM=1 may reduce or eliminate the problem\n");
+       }
+       else
+       {
+               fprintf(stderr, "A performance reducing hack is being used to help avoid graphics corruption.\n"
+                       "You can try export NOUVEAU_VTXIDX_IN_VRAM=0 to disable it.\n");
+       }
+#endif
+
+       screen->vertex_buffer_flags = vram_hack ? NOUVEAU_BO_VRAM : NOUVEAU_BO_GART;
+}
+
 struct pipe_screen *
 nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
 {
@@ -350,7 +375,8 @@ nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
                return NULL;
        }
 
-       nvfx_screen_init_miptree_functions(pscreen);
+       nvfx_screen_init_resource_functions(pscreen);
+       nvfx_screen_init_buffer_functions(screen);
 
        ret = nouveau_grobj_alloc(chan, 0xbeef3097, eng3d_class, &screen->eng3d);
        if (ret) {