svga_screen.c revision 686215d9e5c87ace953b11559ec8ca24f5a3b4e4
1603c4be006d8c53905d736bf1f19a49f5ce98276Alexey Samsonov/**********************************************************
27ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * Copyright 2008-2009 VMware, Inc.  All rights reserved.
37ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany *
47ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * Permission is hereby granted, free of charge, to any person
57ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * obtaining a copy of this software and associated documentation
67ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * files (the "Software"), to deal in the Software without
77ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * restriction, including without limitation the rights to use, copy,
87ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * modify, merge, publish, distribute, sublicense, and/or sell copies
97ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * of the Software, and to permit persons to whom the Software is
107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * furnished to do so, subject to the following conditions:
117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany *
127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * The above copyright notice and this permission notice shall be
137ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * included in all copies or substantial portions of the Software.
147ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany *
15fce5bd4cc29fddb5e8f0cb9c12df7c10187a991dDmitry Vyukov * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
160969bcf2c936126b1f6e636b978aade8fc207437Alexey Samsonov * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1716e0075746b21ed866ec3be21ef0d1e46f0efed5Kostya Serebryany * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1947b1634df012507799eb39aa17d4022d748ba67bAlexey Samsonov * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
208cc1f81b2cc1fa0d4cda4f4635d955aed04c09c8Alexey Samsonov * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
217ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
227ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany * SOFTWARE.
237ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany *
247ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany **********************************************************/
257ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
26a38e40fde45acccb124f7419ecbe21ef6cfd306bDmitry Vyukov#include "util/u_memory.h"
27cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar#include "util/u_inlines.h"
287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "util/u_string.h"
296a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#include "util/u_math.h"
306a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
316a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#include "svga_winsys.h"
326a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#include "svga_context.h"
336a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#include "svga_screen.h"
346a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#include "svga_resource_texture.h"
356a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#include "svga_resource.h"
366a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#include "svga_debug.h"
376a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#include "svga_surface.h"
386a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
39adfb65039646774f0f063b538f8fb0aec021f42bDmitry Vyukov#include "svga3d_shaderdefs.h"
407ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
417ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
42adfb65039646774f0f063b538f8fb0aec021f42bDmitry Vyukov#ifdef DEBUG
437ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyint SVGA_DEBUG = 0;
447ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
457ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystatic const struct debug_named_value svga_debug_flags[] = {
467ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   { "dma",      DEBUG_DMA },
473d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar   { "tgsi",     DEBUG_TGSI },
480a4c906dbc8f150657ddd4f19a7192b779f1d605Alexey Samsonov   { "pipe",     DEBUG_PIPE },
49b78caa645f70eff2f037f1f8bb43ca9129dbd8d9Dmitry Vyukov   { "state",    DEBUG_STATE },
500a4c906dbc8f150657ddd4f19a7192b779f1d605Alexey Samsonov   { "screen",   DEBUG_SCREEN },
512d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   { "tex",      DEBUG_TEX },
527ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   { "swtnl",    DEBUG_SWTNL },
5322881ec8c8a3c01f9b993b186040444b0b5caa50Dmitry Vyukov   { "const",    DEBUG_CONSTS },
546a135be19fa0cc594fd61f9caf3c0be2b7f1466eDmitry Vyukov   { "viewport", DEBUG_VIEWPORT },
556a135be19fa0cc594fd61f9caf3c0be2b7f1466eDmitry Vyukov   { "views",    DEBUG_VIEWS },
562d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   { "perf",     DEBUG_PERF },
576a135be19fa0cc594fd61f9caf3c0be2b7f1466eDmitry Vyukov   { "flush",    DEBUG_FLUSH },
583d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar   { "sync",     DEBUG_SYNC },
593d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar   { "cache",    DEBUG_CACHE },
6022881ec8c8a3c01f9b993b186040444b0b5caa50Dmitry Vyukov   {NULL, 0}
6122881ec8c8a3c01f9b993b186040444b0b5caa50Dmitry Vyukov};
623d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar#endif
633d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar
646a135be19fa0cc594fd61f9caf3c0be2b7f1466eDmitry Vyukovstatic const char *
6522881ec8c8a3c01f9b993b186040444b0b5caa50Dmitry Vyukovsvga_get_vendor( struct pipe_screen *pscreen )
662bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov{
672bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov   return "VMware, Inc.";
682bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov}
692bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov
70cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar
71cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainarstatic const char *
72cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainarsvga_get_name( struct pipe_screen *pscreen )
7386277eb844c4983c81de62d7c050e92fe7155788Stephen Hines{
74cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar#ifdef DEBUG
75cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar   /* Only return internal details in the DEBUG version:
7686277eb844c4983c81de62d7c050e92fe7155788Stephen Hines    */
7786277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   return "SVGA3D; build: DEBUG; mutex: " PIPE_ATOMIC;
7886277eb844c4983c81de62d7c050e92fe7155788Stephen Hines#else
7986277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   return "SVGA3D; build: RELEASE; ";
8086277eb844c4983c81de62d7c050e92fe7155788Stephen Hines#endif
8186277eb844c4983c81de62d7c050e92fe7155788Stephen Hines}
8286277eb844c4983c81de62d7c050e92fe7155788Stephen Hines
8386277eb844c4983c81de62d7c050e92fe7155788Stephen Hines
8486277eb844c4983c81de62d7c050e92fe7155788Stephen Hines
859743d74426ae43898e4da55e591b09be18f8aa6eDmitry Vyukov
862bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonovstatic float
872bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonovsvga_get_paramf(struct pipe_screen *screen, enum pipe_cap param)
882bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov{
8986277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   struct svga_screen *svgascreen = svga_screen(screen);
902bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov   struct svga_winsys_screen *sws = svgascreen->sws;
912bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov   SVGA3dDevCapResult result;
922bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov
932bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov   switch (param) {
942bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov   case PIPE_CAP_MAX_LINE_WIDTH:
957ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      /* fall-through */
967ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   case PIPE_CAP_MAX_LINE_WIDTH_AA:
977ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      return 7.0;
987ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
997ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   case PIPE_CAP_MAX_POINT_WIDTH:
1002bbd8bec77c2fdb41c5f5b6cb0d83d22bc576650Alexey Samsonov      /* fall-through */
1012d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   case PIPE_CAP_MAX_POINT_WIDTH_AA:
1023d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar      /* Keep this to a reasonable size to avoid failures in
1037ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany       * conform/pntaa.c:
104158c6ac3bb46753db217f9c2c73485811a3a1890Dmitry Vyukov       */
1053d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar      return SVGA_MAX_POINTSIZE;
1060a05e5fa28a7424f8146549057c53b4590f3a251Alexey Samsonov
1077ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
1087ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      if(!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_ANISOTROPY, &result))
1097ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany         return 4.0;
110ff35f1d82b4f145b3477ef27a7a2e7b63c486988Dmitry Vyukov      return result.u;
1112d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
1127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
1137ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      return 16.0;
1147ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1157ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
1167ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      return 16;
117dc563c0efbba5aec49b20a4d74e020feb75d7e8aDmitry Vyukov   case PIPE_CAP_MAX_COMBINED_SAMPLERS:
1182d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return 16;
1192d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   case PIPE_CAP_NPOT_TEXTURES:
12086277eb844c4983c81de62d7c050e92fe7155788Stephen Hines      return 1;
1218b30c254a63a7421dd81d13dee086a54c4ca134bDmitry Vyukov   case PIPE_CAP_TWO_SIDED_STENCIL:
1228b30c254a63a7421dd81d13dee086a54c4ca134bDmitry Vyukov      return 1;
1237ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   case PIPE_CAP_GLSL:
124ff35f1d82b4f145b3477ef27a7a2e7b63c486988Dmitry Vyukov      return svgascreen->use_ps30 && svgascreen->use_vs30;
1257ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   case PIPE_CAP_ANISOTROPIC_FILTER:
1267ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      return 1;
1277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   case PIPE_CAP_POINT_SPRITE:
1282d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return 1;
12986277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   case PIPE_CAP_MAX_RENDER_TARGETS:
1302d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      if(!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_RENDER_TARGETS, &result))
1312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines         return 1;
1322d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      if(!result.u)
1337ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany         return 1;
1347ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      return MIN2(result.u, PIPE_MAX_COLOR_BUFS);
13586277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   case PIPE_CAP_OCCLUSION_QUERY:
136a38e40fde45acccb124f7419ecbe21ef6cfd306bDmitry Vyukov      return 1;
1374bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov   case PIPE_CAP_TEXTURE_SHADOW_MAP:
1384bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov      return 1;
1394bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov
140a38e40fde45acccb124f7419ecbe21ef6cfd306bDmitry Vyukov   case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
1416a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      {
142259f7063e3e4c4b94dded1e90ab0a943d0fa737bPirama Arumuga Nainar         unsigned levels = SVGA_MAX_TEXTURE_LEVELS;
1434bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov         if (sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_WIDTH, &result))
1444bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov            levels = MIN2(util_logbase2(result.u) + 1, levels);
1454bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov         else
1462d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines            levels = 12 /* 2048x2048 */;
1472d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines         if (sws->get_cap(sws, SVGA3D_DEVCAP_MAX_TEXTURE_HEIGHT, &result))
1482d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines            levels = MIN2(util_logbase2(result.u) + 1, levels);
1492d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines         else
1502d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines            levels = 12 /* 2048x2048 */;
151f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov         return levels;
1524bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov      }
1534bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov
1544bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov   case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
1556a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VOLUME_EXTENT, &result))
1566a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines         return 8;  /* max 128x128x128 */
1576a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return MIN2(util_logbase2(result.u) + 1, SVGA_MAX_TEXTURE_LEVELS);
1586a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
1599578a3ecfc35a264ede1135033398e2a77a6cad6Peter Collingbourne   case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
16086277eb844c4983c81de62d7c050e92fe7155788Stephen Hines      /*
16186277eb844c4983c81de62d7c050e92fe7155788Stephen Hines       * No mechanism to query the host, and at least limited to 2048x2048 on
162259f7063e3e4c4b94dded1e90ab0a943d0fa737bPirama Arumuga Nainar       * certain hardware.
163259f7063e3e4c4b94dded1e90ab0a943d0fa737bPirama Arumuga Nainar       */
1646a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return MIN2(screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
1656a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines                  12.0 /* 2048x2048 */);
1666a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
167259f7063e3e4c4b94dded1e90ab0a943d0fa737bPirama Arumuga Nainar   case PIPE_CAP_TEXTURE_MIRROR_REPEAT: /* req. for GL 1.4 */
1686a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return 1;
1694bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov
1704bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov   case PIPE_CAP_BLEND_EQUATION_SEPARATE: /* req. for GL 1.5 */
1714bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov      return 1;
1724bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov
17392b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
1742d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
1752d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return 1;
1762d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
1772d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
1784bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov      return 0;
17926127735454fddae3495794f38189d57dde6510fDmitry Vyukov
180a38e40fde45acccb124f7419ecbe21ef6cfd306bDmitry Vyukov   /*
18192b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov    * Fragment shader limits
182f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov    */
1836d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
1844bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov   case PIPE_CAP_MAX_FS_INSTRUCTIONS:
1854bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov   case PIPE_CAP_MAX_FS_ALU_INSTRUCTIONS:
1864bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov   case PIPE_CAP_MAX_FS_TEX_INSTRUCTIONS:
1874bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov   case PIPE_CAP_MAX_FS_TEX_INDIRECTIONS:
1886a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return svgascreen->use_ps30 ? 512 : 96;
1896d1862363c88c183b0ed7740fca876342cf0474bStephen Hines   case PIPE_CAP_MAX_FS_CONTROL_FLOW_DEPTH:
19092b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov      return SVGA3D_MAX_NESTING_LEVEL;
19192b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov   case PIPE_CAP_MAX_FS_INPUTS:
1926d1862363c88c183b0ed7740fca876342cf0474bStephen Hines      return 10;
1936d1862363c88c183b0ed7740fca876342cf0474bStephen Hines   case PIPE_CAP_MAX_FS_CONSTS:
1946d1862363c88c183b0ed7740fca876342cf0474bStephen Hines      return svgascreen->use_vs30 ? 224 : 16;
19592b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov   case PIPE_CAP_MAX_FS_TEMPS:
1966d1862363c88c183b0ed7740fca876342cf0474bStephen Hines      if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_FRAGMENT_SHADER_TEMPS, &result))
19792b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov         return svgascreen->use_ps30 ? 32 : 12;
19892b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov      return result.u;
1996d1862363c88c183b0ed7740fca876342cf0474bStephen Hines   case PIPE_CAP_MAX_FS_ADDRS:
20092b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov      return svgascreen->use_ps30 ? 1 : 0;
20192b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov   case PIPE_CAP_MAX_FS_PREDS:
20292b54796149a8b5995fa49c43f43b709b83c5644Dmitry Vyukov      return svgascreen->use_ps30 ? 1 : 0;
2034bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov
204a38e40fde45acccb124f7419ecbe21ef6cfd306bDmitry Vyukov   /*
2054bebe7bab966c82f0a8952f797ed3d490624dc62Dmitry Vyukov    * Vertex shader limits
206a38e40fde45acccb124f7419ecbe21ef6cfd306bDmitry Vyukov    */
207a38e40fde45acccb124f7419ecbe21ef6cfd306bDmitry Vyukov   case PIPE_CAP_MAX_VS_INSTRUCTIONS:
208f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov   case PIPE_CAP_MAX_VS_ALU_INSTRUCTIONS:
209f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov      if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_INSTRUCTIONS, &result))
210f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov         return svgascreen->use_vs30 ? 512 : 256;
211f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov      return result.u;
212f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov   case PIPE_CAP_MAX_VS_TEX_INSTRUCTIONS:
213f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov   case PIPE_CAP_MAX_VS_TEX_INDIRECTIONS:
2147ed46ff7af911da0dd2067734d1408c6986c6657Alexey Samsonov      /* XXX: until we have vertex texture support */
215f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov      return 0;
216f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov   case PIPE_CAP_MAX_VS_CONTROL_FLOW_DEPTH:
217f63dde3594da0dba4c8039f0cb3a4196a76f1affDmitry Vyukov      return SVGA3D_MAX_NESTING_LEVEL;
218a38e40fde45acccb124f7419ecbe21ef6cfd306bDmitry Vyukov   case PIPE_CAP_MAX_VS_INPUTS:
21926127735454fddae3495794f38189d57dde6510fDmitry Vyukov      return 16;
22026127735454fddae3495794f38189d57dde6510fDmitry Vyukov   case PIPE_CAP_MAX_VS_CONSTS:
22126127735454fddae3495794f38189d57dde6510fDmitry Vyukov      return 256;
2222d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   case PIPE_CAP_MAX_VS_TEMPS:
2232d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      if (!sws->get_cap(sws, SVGA3D_DEVCAP_MAX_VERTEX_SHADER_TEMPS, &result))
2242d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines         return svgascreen->use_vs30 ? 32 : 12;
2252d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return result.u;
22686277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   case PIPE_CAP_MAX_VS_ADDRS:
2272d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return svgascreen->use_vs30 ? 1 : 0;
2282d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   case PIPE_CAP_MAX_VS_PREDS:
2292d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return svgascreen->use_vs30 ? 1 : 0;
2302d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
2312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   default:
2322d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return 0;
23386277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   }
2342d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines}
2357ac33ac529ff93a57419f5ddf71b1fde68428577Dmitry Vyukov
2367ac33ac529ff93a57419f5ddf71b1fde68428577Dmitry Vyukov
2377ac33ac529ff93a57419f5ddf71b1fde68428577Dmitry Vyukov/* This is a fairly pointless interface
2387ac33ac529ff93a57419f5ddf71b1fde68428577Dmitry Vyukov */
2397ac33ac529ff93a57419f5ddf71b1fde68428577Dmitry Vyukovstatic int
2407ac33ac529ff93a57419f5ddf71b1fde68428577Dmitry Vyukovsvga_get_param(struct pipe_screen *screen, enum pipe_cap param)
241a05fcc1e3e045097f2f1a20798cbe038bbb1d6a9Dmitry Vyukov{
2422d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   return (int) svga_get_paramf( screen, param );
2432d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines}
2442d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
245cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar
2466a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hinesstatic INLINE SVGA3dDevCapIndex
2476a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hinessvga_translate_format_cap(enum pipe_format format)
2486a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines{
2496a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   switch(format) {
2506a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
2516a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   case PIPE_FORMAT_B8G8R8A8_UNORM:
2526a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8;
2536a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   case PIPE_FORMAT_B8G8R8X8_UNORM:
2546a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8;
2556a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
2566a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   case PIPE_FORMAT_B5G6R5_UNORM:
257cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar      return SVGA3D_DEVCAP_SURFACEFMT_R5G6B5;
2586a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   case PIPE_FORMAT_B5G5R5A1_UNORM:
2596a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5;
2606a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   case PIPE_FORMAT_B4G4R4A4_UNORM:
2616a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4;
2626a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
2636a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   case PIPE_FORMAT_Z16_UNORM:
2646a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return SVGA3D_DEVCAP_SURFACEFMT_Z_D16;
2656a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
2666a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8;
267cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar   case PIPE_FORMAT_X8Z24_UNORM:
2686a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8;
2696a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
2706a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   case PIPE_FORMAT_A8_UNORM:
2716a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      return SVGA3D_DEVCAP_SURFACEFMT_ALPHA8;
272a05fcc1e3e045097f2f1a20798cbe038bbb1d6a9Dmitry Vyukov   case PIPE_FORMAT_L8_UNORM:
273a05fcc1e3e045097f2f1a20798cbe038bbb1d6a9Dmitry Vyukov      return SVGA3D_DEVCAP_SURFACEFMT_LUMINANCE8;
274cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar
275dae1251f196f9694d428a04f14987b06112ae52cDmitry Vyukov   case PIPE_FORMAT_DXT1_RGB:
2763d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar   case PIPE_FORMAT_DXT1_RGBA:
2773d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar      return SVGA3D_DEVCAP_SURFACEFMT_DXT1;
2782d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   case PIPE_FORMAT_DXT3_RGBA:
279cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar      return SVGA3D_DEVCAP_SURFACEFMT_DXT3;
28001a7ce809bf7cc627d73c045c70bcca9891f632cDmitry Vyukov   case PIPE_FORMAT_DXT5_RGBA:
28101a7ce809bf7cc627d73c045c70bcca9891f632cDmitry Vyukov      return SVGA3D_DEVCAP_SURFACEFMT_DXT5;
28201a7ce809bf7cc627d73c045c70bcca9891f632cDmitry Vyukov
2836535c31c66569df262791f0b56852c496977c977Dmitry Vyukov   default:
2846535c31c66569df262791f0b56852c496977c977Dmitry Vyukov      return SVGA3D_DEVCAP_MAX;
2856535c31c66569df262791f0b56852c496977c977Dmitry Vyukov   }
2866535c31c66569df262791f0b56852c496977c977Dmitry Vyukov}
2876d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
2883d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar
2893d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainarstatic boolean
2906d1862363c88c183b0ed7740fca876342cf0474bStephen Hinessvga_is_format_supported( struct pipe_screen *screen,
2916d1862363c88c183b0ed7740fca876342cf0474bStephen Hines                          enum pipe_format format,
2926d1862363c88c183b0ed7740fca876342cf0474bStephen Hines                          enum pipe_texture_target target,
2936d1862363c88c183b0ed7740fca876342cf0474bStephen Hines                          unsigned tex_usage,
2946d1862363c88c183b0ed7740fca876342cf0474bStephen Hines                          unsigned geom_flags )
2956d1862363c88c183b0ed7740fca876342cf0474bStephen Hines{
2966d1862363c88c183b0ed7740fca876342cf0474bStephen Hines   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
29786277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   SVGA3dDevCapIndex index;
29886277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   SVGA3dDevCapResult result;
2996d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
3006d1862363c88c183b0ed7740fca876342cf0474bStephen Hines   assert(tex_usage);
3016d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
3026d1862363c88c183b0ed7740fca876342cf0474bStephen Hines   /* Override host capabilities */
3036d1862363c88c183b0ed7740fca876342cf0474bStephen Hines   if (tex_usage & PIPE_BIND_RENDER_TARGET) {
3046d1862363c88c183b0ed7740fca876342cf0474bStephen Hines      switch(format) {
3056d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
3066d1862363c88c183b0ed7740fca876342cf0474bStephen Hines      /* Often unsupported/problematic. This means we end up with the same
3076d1862363c88c183b0ed7740fca876342cf0474bStephen Hines       * visuals for all virtual hardware implementations.
3087ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany       */
3097ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      case PIPE_FORMAT_B4G4R4A4_UNORM:
3107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      case PIPE_FORMAT_B5G5R5A1_UNORM:
3117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany         return FALSE;
3127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
3137ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      /* Simulate ability to render into compressed textures */
3142d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      case PIPE_FORMAT_DXT1_RGB:
3152d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      case PIPE_FORMAT_DXT1_RGBA:
316859778a4e2dffa4024fa3e13b105fd62eca44b1cKostya Serebryany      case PIPE_FORMAT_DXT3_RGBA:
317591616d323d73b7ea7cd8fea4eec46cedccda27eAlexey Samsonov      case PIPE_FORMAT_DXT5_RGBA:
318591616d323d73b7ea7cd8fea4eec46cedccda27eAlexey Samsonov         return TRUE;
319591616d323d73b7ea7cd8fea4eec46cedccda27eAlexey Samsonov
3206d1862363c88c183b0ed7740fca876342cf0474bStephen Hines      default:
3216d1862363c88c183b0ed7740fca876342cf0474bStephen Hines         break;
322cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar      }
3233d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar   }
3243d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar
32586277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   /* Try to query the host */
3263d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar   index = svga_translate_format_cap(format);
3273d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar   if( index < SVGA3D_DEVCAP_MAX &&
3283d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar       sws->get_cap(sws, index, &result) )
3292e87051d136db3150a3ca322d8862f92b0a684bbDmitry Vyukov   {
3303d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar      SVGA3dSurfaceFormatCaps mask;
331bbbb20b7212155ebc5b5b4ee1c68c987dcf30320Dmitry Vyukov
3327ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      mask.value = 0;
3336d1862363c88c183b0ed7740fca876342cf0474bStephen Hines      if (tex_usage & PIPE_BIND_RENDER_TARGET)
3346d1862363c88c183b0ed7740fca876342cf0474bStephen Hines         mask.offscreenRenderTarget = 1;
3357ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      if (tex_usage & PIPE_BIND_DEPTH_STENCIL)
3367ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany         mask.zStencil = 1;
33786277eb844c4983c81de62d7c050e92fe7155788Stephen Hines      if (tex_usage & PIPE_BIND_SAMPLER_VIEW)
3387ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany         mask.texture = 1;
339a05fcc1e3e045097f2f1a20798cbe038bbb1d6a9Dmitry Vyukov
340b1fe3021eca0843e37878d224ee7f32e32f40d99Alexey Samsonov      if ((result.u & mask.value) == mask.value)
3416d1862363c88c183b0ed7740fca876342cf0474bStephen Hines         return TRUE;
3427ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      else
34386277eb844c4983c81de62d7c050e92fe7155788Stephen Hines         return FALSE;
3444af0f21c0c98950df1136dbec8824a029ed5bb8eDmitry Vyukov   }
3456d1862363c88c183b0ed7740fca876342cf0474bStephen Hines
34686277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   /* Use our translate functions directly rather than relying on a
34786277eb844c4983c81de62d7c050e92fe7155788Stephen Hines    * duplicated list of supported formats which is prone to getting
34886277eb844c4983c81de62d7c050e92fe7155788Stephen Hines    * out of sync:
34986277eb844c4983c81de62d7c050e92fe7155788Stephen Hines    */
3502d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   if(tex_usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL))
3512d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return svga_translate_format_render(format) != SVGA3D_FORMAT_INVALID;
3522d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   else
35386277eb844c4983c81de62d7c050e92fe7155788Stephen Hines      return svga_translate_format(format) != SVGA3D_FORMAT_INVALID;
3546d1862363c88c183b0ed7740fca876342cf0474bStephen Hines}
3552d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
3568cc1f81b2cc1fa0d4cda4f4635d955aed04c09c8Alexey Samsonov
3576d1862363c88c183b0ed7740fca876342cf0474bStephen Hinesstatic void
3586d1862363c88c183b0ed7740fca876342cf0474bStephen Hinessvga_fence_reference(struct pipe_screen *screen,
3597ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                     struct pipe_fence_handle **ptr,
3607ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                     struct pipe_fence_handle *fence)
3617ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany{
3627ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
3630b694fcab9b2f33bdd6691cbea4e80a5c27191b1Peter Collingbourne   sws->fence_reference(sws, ptr, fence);
364cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar}
365cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar
366cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar
3677ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystatic int
3687ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanysvga_fence_signalled(struct pipe_screen *screen,
369adfb65039646774f0f063b538f8fb0aec021f42bDmitry Vyukov                     struct pipe_fence_handle *fence,
370b1fe3021eca0843e37878d224ee7f32e32f40d99Alexey Samsonov                     unsigned flag)
371adfb65039646774f0f063b538f8fb0aec021f42bDmitry Vyukov{
3720b694fcab9b2f33bdd6691cbea4e80a5c27191b1Peter Collingbourne   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
373ba5e99668e3030cc5bab357a04271a1bdbac209cAlexey Samsonov   return sws->fence_signalled(sws, fence, flag);
3747ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}
3752d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
3762d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
3777ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystatic int
3787ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanysvga_fence_finish(struct pipe_screen *screen,
3797ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                  struct pipe_fence_handle *fence,
3807ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                  unsigned flag)
3817ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany{
38254e0a9a391616bbd2a4f0fd2d01076291274cb98Dmitry Vyukov   struct svga_winsys_screen *sws = svga_screen(screen)->sws;
38354e0a9a391616bbd2a4f0fd2d01076291274cb98Dmitry Vyukov
38454e0a9a391616bbd2a4f0fd2d01076291274cb98Dmitry Vyukov   SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n",
385d0a51c02157e8293ea365ad0d429ef8e73d115deDmitry Vyukov            __FUNCTION__, fence);
386d0a51c02157e8293ea365ad0d429ef8e73d115deDmitry Vyukov
3877ed46ff7af911da0dd2067734d1408c6986c6657Alexey Samsonov   return sws->fence_finish(sws, fence, flag);
3887ed46ff7af911da0dd2067734d1408c6986c6657Alexey Samsonov}
389d0a51c02157e8293ea365ad0d429ef8e73d115deDmitry Vyukov
390d0a51c02157e8293ea365ad0d429ef8e73d115deDmitry Vyukov
39186277eb844c4983c81de62d7c050e92fe7155788Stephen Hinesstatic void
39286277eb844c4983c81de62d7c050e92fe7155788Stephen Hinessvga_destroy_screen( struct pipe_screen *screen )
393bdd844cb41718c27ef727a99a236191bc29a3df8Dmitry Vyukov{
394bdd844cb41718c27ef727a99a236191bc29a3df8Dmitry Vyukov   struct svga_screen *svgascreen = svga_screen(screen);
3957ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
3967ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   svga_screen_cache_cleanup(svgascreen);
3977ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
3987ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   pipe_mutex_destroy(svgascreen->swc_mutex);
39986277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   pipe_mutex_destroy(svgascreen->tex_mutex);
400b1fe3021eca0843e37878d224ee7f32e32f40d99Alexey Samsonov
401b3b21231dd9dfeb34f5f302c879f2d11b6312080Dmitry Vyukov   svgascreen->sws->destroy(svgascreen->sws);
402b1fe3021eca0843e37878d224ee7f32e32f40d99Alexey Samsonov
403b3b21231dd9dfeb34f5f302c879f2d11b6312080Dmitry Vyukov   FREE(svgascreen);
4047ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}
4057ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
4067ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
4077ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany/**
408b1fe3021eca0843e37878d224ee7f32e32f40d99Alexey Samsonov * Create a new svga_screen object
4097ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany */
4107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanystruct pipe_screen *
4117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanysvga_screen_create(struct svga_winsys_screen *sws)
4126d1862363c88c183b0ed7740fca876342cf0474bStephen Hines{
413f754eb501d6bd163fff6747716b7703fe45be4b8Dmitry Vyukov   struct svga_screen *svgascreen;
41486277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   struct pipe_screen *screen;
4150fd908cf5a555483633e2d9703932bde18009682Dmitry Vyukov   SVGA3dDevCapResult result;
4160fd908cf5a555483633e2d9703932bde18009682Dmitry Vyukov
4170fd908cf5a555483633e2d9703932bde18009682Dmitry Vyukov#ifdef DEBUG
418f754eb501d6bd163fff6747716b7703fe45be4b8Dmitry Vyukov   SVGA_DEBUG = debug_get_flags_option("SVGA_DEBUG", svga_debug_flags, 0 );
41922881ec8c8a3c01f9b993b186040444b0b5caa50Dmitry Vyukov#endif
42022881ec8c8a3c01f9b993b186040444b0b5caa50Dmitry Vyukov
42186277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   svgascreen = CALLOC_STRUCT(svga_screen);
42208adb1815b4958df88f904b9780a055b0d387294Dmitry Vyukov   if (!svgascreen)
4237ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      goto error1;
42486277eb844c4983c81de62d7c050e92fe7155788Stephen Hines
42586277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   svgascreen->debug.force_level_surface_view =
4263d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar      debug_get_bool_option("SVGA_FORCE_LEVEL_SURFACE_VIEW", FALSE);
4277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany   svgascreen->debug.force_surface_view =
4287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany      debug_get_bool_option("SVGA_FORCE_SURFACE_VIEW", FALSE);
42986277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   svgascreen->debug.force_sampler_view =
4302d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      debug_get_bool_option("SVGA_FORCE_SAMPLER_VIEW", FALSE);
4312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   svgascreen->debug.no_surface_view =
4322d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      debug_get_bool_option("SVGA_NO_SURFACE_VIEW", FALSE);
4332d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   svgascreen->debug.no_sampler_view =
4342d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      debug_get_bool_option("SVGA_NO_SAMPLER_VIEW", FALSE);
4352d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
4362d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen = &svgascreen->screen;
4372d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
4382d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->destroy = svga_destroy_screen;
4392d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->get_name = svga_get_name;
4402d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->get_vendor = svga_get_vendor;
4412d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->get_param = svga_get_param;
4422d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->get_paramf = svga_get_paramf;
4432d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->is_format_supported = svga_is_format_supported;
4442d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->context_create = svga_context_create;
4452d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->fence_reference = svga_fence_reference;
4462d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->fence_signalled = svga_fence_signalled;
4472d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   screen->fence_finish = svga_fence_finish;
4482d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   svgascreen->sws = sws;
44986277eb844c4983c81de62d7c050e92fe7155788Stephen Hines
4502d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   svga_screen_init_surface_functions(screen);
4512d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   svga_init_screen_resource_functions(svgascreen);
4522d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
4532d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   svgascreen->use_ps30 =
4542d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      sws->get_cap(sws, SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION, &result) &&
4552d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      result.u >= SVGA3DPSVERSION_30 ? TRUE : FALSE;
4562d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
4572d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines   svgascreen->use_vs30 =
4582d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      sws->get_cap(sws, SVGA3D_DEVCAP_VERTEX_SHADER_VERSION, &result) &&
4592d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      result.u >= SVGA3DVSVERSION_30 ? TRUE : FALSE;
4602d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
4612d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#if 1
46286277eb844c4983c81de62d7c050e92fe7155788Stephen Hines   /* Shader model 2.0 is unsupported at the moment. */
4636a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   if(!svgascreen->use_ps30 || !svgascreen->use_vs30)
4646a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      goto error2;
4656a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#else
4666a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   if(debug_get_bool_option("SVGA_NO_SM30", FALSE))
4676a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines      svgascreen->use_vs30 = svgascreen->use_ps30 = FALSE;
4686a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines#endif
4696a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
4706a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   pipe_mutex_init(svgascreen->tex_mutex);
4716a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   pipe_mutex_init(svgascreen->swc_mutex);
4726a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
4736a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   svga_screen_cache_init(svgascreen);
4746a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines
4756a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   return screen;
4766a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hineserror2:
477848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov   FREE(svgascreen);
4787c9150579ed0278492f51cc8434b1d63a44b9bd1Pirama Arumuga Nainarerror1:
479848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov   return NULL;
4806a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines}
48186277eb844c4983c81de62d7c050e92fe7155788Stephen Hines
4826a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hinesstruct svga_winsys_screen *
4836a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hinessvga_winsys_screen(struct pipe_screen *screen)
4846a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines{
4856a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   return svga_screen(screen)->sws;
4866a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines}
487848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov
488848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov#ifdef DEBUG
489848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukovstruct svga_screen *
4906d1862363c88c183b0ed7740fca876342cf0474bStephen Hinessvga_screen(struct pipe_screen *screen)
4916d1862363c88c183b0ed7740fca876342cf0474bStephen Hines{
4926a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines   assert(screen);
493848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov   assert(screen->destroy == svga_destroy_screen);
494848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov   return (struct svga_screen *)screen;
495848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov}
496848531192777acecf79747dc7c1ffeedf5c1da9fDmitry Vyukov#endif
497b78caa645f70eff2f037f1f8bb43ca9129dbd8d9Dmitry Vyukov