Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 21 | * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
| 28 | |
Brian Paul | 4f25420 | 2008-08-24 17:48:55 -0600 | [diff] [blame] | 29 | #include "util/u_memory.h" |
Zack Rusin | 969c728 | 2009-01-31 15:14:38 -0500 | [diff] [blame] | 30 | #include "util/u_simple_screen.h" |
Zack Rusin | adfbba4 | 2009-01-30 15:56:00 -0500 | [diff] [blame] | 31 | #include "pipe/internal/p_winsys_screen.h" |
José Fonseca | 34cc7f5 | 2008-09-04 09:34:04 +0900 | [diff] [blame] | 32 | #include "pipe/p_inlines.h" |
José Fonseca | 5b8fa51 | 2008-04-14 23:55:36 +0900 | [diff] [blame] | 33 | #include "util/u_string.h" |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 34 | |
| 35 | #include "i915_reg.h" |
José Fonseca | f81b7a6 | 2008-02-27 15:59:09 +0900 | [diff] [blame] | 36 | #include "i915_context.h" |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 37 | #include "i915_screen.h" |
| 38 | #include "i915_texture.h" |
Jakob Bornecrantz | c92dc32 | 2009-02-24 23:55:03 +0100 | [diff] [blame] | 39 | #include "i915_winsys.h" |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 40 | |
| 41 | |
| 42 | static const char * |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 43 | i915_get_vendor(struct pipe_screen *screen) |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 44 | { |
| 45 | return "Tungsten Graphics, Inc."; |
| 46 | } |
| 47 | |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 48 | static const char * |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 49 | i915_get_name(struct pipe_screen *screen) |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 50 | { |
| 51 | static char buffer[128]; |
| 52 | const char *chipset; |
| 53 | |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 54 | switch (i915_screen(screen)->pci_id) { |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 55 | case PCI_CHIP_I915_G: |
| 56 | chipset = "915G"; |
| 57 | break; |
| 58 | case PCI_CHIP_I915_GM: |
| 59 | chipset = "915GM"; |
| 60 | break; |
| 61 | case PCI_CHIP_I945_G: |
| 62 | chipset = "945G"; |
| 63 | break; |
| 64 | case PCI_CHIP_I945_GM: |
| 65 | chipset = "945GM"; |
| 66 | break; |
| 67 | case PCI_CHIP_I945_GME: |
| 68 | chipset = "945GME"; |
| 69 | break; |
| 70 | case PCI_CHIP_G33_G: |
| 71 | chipset = "G33"; |
| 72 | break; |
| 73 | case PCI_CHIP_Q35_G: |
| 74 | chipset = "Q35"; |
| 75 | break; |
| 76 | case PCI_CHIP_Q33_G: |
| 77 | chipset = "Q33"; |
| 78 | break; |
| 79 | default: |
| 80 | chipset = "unknown"; |
| 81 | break; |
| 82 | } |
| 83 | |
José Fonseca | 5b8fa51 | 2008-04-14 23:55:36 +0900 | [diff] [blame] | 84 | util_snprintf(buffer, sizeof(buffer), "i915 (chipset: %s)", chipset); |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 85 | return buffer; |
| 86 | } |
| 87 | |
Brian | 17188e4 | 2008-02-27 10:15:37 -0700 | [diff] [blame] | 88 | static int |
| 89 | i915_get_param(struct pipe_screen *screen, int param) |
| 90 | { |
| 91 | switch (param) { |
| 92 | case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: |
| 93 | return 8; |
| 94 | case PIPE_CAP_NPOT_TEXTURES: |
| 95 | return 1; |
| 96 | case PIPE_CAP_TWO_SIDED_STENCIL: |
| 97 | return 1; |
| 98 | case PIPE_CAP_GLSL: |
| 99 | return 0; |
| 100 | case PIPE_CAP_S3TC: |
| 101 | return 0; |
| 102 | case PIPE_CAP_ANISOTROPIC_FILTER: |
| 103 | return 0; |
| 104 | case PIPE_CAP_POINT_SPRITE: |
| 105 | return 0; |
| 106 | case PIPE_CAP_MAX_RENDER_TARGETS: |
| 107 | return 1; |
| 108 | case PIPE_CAP_OCCLUSION_QUERY: |
| 109 | return 0; |
| 110 | case PIPE_CAP_TEXTURE_SHADOW_MAP: |
| 111 | return 1; |
| 112 | case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: |
| 113 | return 11; /* max 1024x1024 */ |
| 114 | case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: |
| 115 | return 8; /* max 128x128x128 */ |
| 116 | case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: |
| 117 | return 11; /* max 1024x1024 */ |
| 118 | default: |
| 119 | return 0; |
| 120 | } |
| 121 | } |
| 122 | |
Brian | 17188e4 | 2008-02-27 10:15:37 -0700 | [diff] [blame] | 123 | static float |
| 124 | i915_get_paramf(struct pipe_screen *screen, int param) |
| 125 | { |
| 126 | switch (param) { |
| 127 | case PIPE_CAP_MAX_LINE_WIDTH: |
| 128 | /* fall-through */ |
| 129 | case PIPE_CAP_MAX_LINE_WIDTH_AA: |
| 130 | return 7.5; |
| 131 | |
| 132 | case PIPE_CAP_MAX_POINT_WIDTH: |
| 133 | /* fall-through */ |
| 134 | case PIPE_CAP_MAX_POINT_WIDTH_AA: |
| 135 | return 255.0; |
| 136 | |
| 137 | case PIPE_CAP_MAX_TEXTURE_ANISOTROPY: |
| 138 | return 4.0; |
| 139 | |
| 140 | case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: |
| 141 | return 16.0; |
| 142 | |
| 143 | default: |
| 144 | return 0; |
| 145 | } |
| 146 | } |
| 147 | |
Brian | 364f8ca | 2008-02-27 13:58:06 -0700 | [diff] [blame] | 148 | static boolean |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 149 | i915_is_format_supported(struct pipe_screen *screen, |
| 150 | enum pipe_format format, |
| 151 | enum pipe_texture_target target, |
| 152 | unsigned tex_usage, |
| 153 | unsigned geom_flags) |
Brian | 364f8ca | 2008-02-27 13:58:06 -0700 | [diff] [blame] | 154 | { |
| 155 | static const enum pipe_format tex_supported[] = { |
| 156 | PIPE_FORMAT_R8G8B8A8_UNORM, |
| 157 | PIPE_FORMAT_A8R8G8B8_UNORM, |
| 158 | PIPE_FORMAT_R5G6B5_UNORM, |
Brian Paul | 54f94a7 | 2008-04-30 16:50:17 -0600 | [diff] [blame] | 159 | PIPE_FORMAT_L8_UNORM, |
| 160 | PIPE_FORMAT_A8_UNORM, |
| 161 | PIPE_FORMAT_I8_UNORM, |
| 162 | PIPE_FORMAT_A8L8_UNORM, |
Brian | 364f8ca | 2008-02-27 13:58:06 -0700 | [diff] [blame] | 163 | PIPE_FORMAT_YCBCR, |
| 164 | PIPE_FORMAT_YCBCR_REV, |
| 165 | PIPE_FORMAT_S8Z24_UNORM, |
| 166 | PIPE_FORMAT_NONE /* list terminator */ |
| 167 | }; |
| 168 | static const enum pipe_format surface_supported[] = { |
| 169 | PIPE_FORMAT_A8R8G8B8_UNORM, |
| 170 | PIPE_FORMAT_R5G6B5_UNORM, |
| 171 | PIPE_FORMAT_S8Z24_UNORM, |
Brian | 364f8ca | 2008-02-27 13:58:06 -0700 | [diff] [blame] | 172 | PIPE_FORMAT_NONE /* list terminator */ |
| 173 | }; |
| 174 | const enum pipe_format *list; |
| 175 | uint i; |
| 176 | |
José Fonseca | 8aafc03 | 2008-07-19 12:04:37 +0900 | [diff] [blame] | 177 | if(tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) |
Brian | 364f8ca | 2008-02-27 13:58:06 -0700 | [diff] [blame] | 178 | list = surface_supported; |
José Fonseca | 8aafc03 | 2008-07-19 12:04:37 +0900 | [diff] [blame] | 179 | else |
| 180 | list = tex_supported; |
Brian | 364f8ca | 2008-02-27 13:58:06 -0700 | [diff] [blame] | 181 | |
| 182 | for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) { |
| 183 | if (list[i] == format) |
| 184 | return TRUE; |
| 185 | } |
| 186 | |
| 187 | return FALSE; |
| 188 | } |
| 189 | |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 190 | static void |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 191 | i915_destroy_screen(struct pipe_screen *screen) |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 192 | { |
José Fonseca | 9dcb956 | 2008-08-08 12:23:21 +0100 | [diff] [blame] | 193 | struct pipe_winsys *winsys = screen->winsys; |
| 194 | |
| 195 | if(winsys->destroy) |
| 196 | winsys->destroy(winsys); |
| 197 | |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 198 | FREE(screen); |
| 199 | } |
| 200 | |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 201 | static struct pipe_transfer* |
| 202 | i915_get_tex_transfer(struct pipe_screen *screen, |
| 203 | struct pipe_texture *texture, |
| 204 | unsigned face, unsigned level, unsigned zslice, |
| 205 | enum pipe_transfer_usage usage, unsigned x, unsigned y, |
| 206 | unsigned w, unsigned h) |
Keith Whitwell | c9ed86a | 2008-05-01 11:07:21 +0100 | [diff] [blame] | 207 | { |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 208 | struct i915_texture *tex = (struct i915_texture *)texture; |
| 209 | struct i915_transfer *trans; |
| 210 | unsigned offset; /* in bytes */ |
| 211 | |
| 212 | if (texture->target == PIPE_TEXTURE_CUBE) { |
| 213 | offset = tex->image_offset[level][face]; |
| 214 | } |
| 215 | else if (texture->target == PIPE_TEXTURE_3D) { |
| 216 | offset = tex->image_offset[level][zslice]; |
| 217 | } |
| 218 | else { |
| 219 | offset = tex->image_offset[level][0]; |
| 220 | assert(face == 0); |
| 221 | assert(zslice == 0); |
| 222 | } |
| 223 | |
| 224 | trans = CALLOC_STRUCT(i915_transfer); |
| 225 | if (trans) { |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 226 | pipe_texture_reference(&trans->base.texture, texture); |
| 227 | trans->base.format = trans->base.format; |
Jakob Bornecrantz | 7de5e60 | 2009-08-08 03:20:24 +0200 | [diff] [blame] | 228 | trans->base.x = x; |
| 229 | trans->base.y = y; |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 230 | trans->base.width = w; |
| 231 | trans->base.height = h; |
| 232 | trans->base.block = texture->block; |
| 233 | trans->base.nblocksx = texture->nblocksx[level]; |
| 234 | trans->base.nblocksy = texture->nblocksy[level]; |
| 235 | trans->base.stride = tex->stride; |
| 236 | trans->offset = offset; |
| 237 | trans->base.usage = usage; |
| 238 | } |
| 239 | return &trans->base; |
| 240 | } |
| 241 | |
| 242 | static void |
Michel Dänzer | 5e27cd4 | 2009-03-04 11:58:48 +0100 | [diff] [blame] | 243 | i915_tex_transfer_destroy(struct pipe_transfer *trans) |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 244 | { |
Michel Dänzer | 5e27cd4 | 2009-03-04 11:58:48 +0100 | [diff] [blame] | 245 | pipe_texture_reference(&trans->texture, NULL); |
| 246 | FREE(trans); |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static void * |
| 250 | i915_transfer_map( struct pipe_screen *screen, |
| 251 | struct pipe_transfer *transfer ) |
| 252 | { |
| 253 | struct i915_texture *tex = (struct i915_texture *)transfer->texture; |
| 254 | char *map; |
| 255 | unsigned flags = 0; |
| 256 | |
| 257 | if (transfer->usage != PIPE_TRANSFER_WRITE) |
| 258 | flags |= PIPE_BUFFER_USAGE_CPU_READ; |
| 259 | |
| 260 | if (transfer->usage != PIPE_TRANSFER_READ) |
| 261 | flags |= PIPE_BUFFER_USAGE_CPU_WRITE; |
| 262 | |
| 263 | map = pipe_buffer_map( screen, tex->buffer, flags ); |
Keith Whitwell | c9ed86a | 2008-05-01 11:07:21 +0100 | [diff] [blame] | 264 | if (map == NULL) |
| 265 | return NULL; |
| 266 | |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 267 | if (transfer->texture && |
Keith Whitwell | c9ed86a | 2008-05-01 11:07:21 +0100 | [diff] [blame] | 268 | (flags & PIPE_BUFFER_USAGE_CPU_WRITE)) |
| 269 | { |
| 270 | /* Do something to notify contexts of a texture change. |
| 271 | */ |
| 272 | /* i915_screen(screen)->timestamp++; */ |
| 273 | } |
| 274 | |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 275 | return map + i915_transfer(transfer)->offset + |
| 276 | transfer->y / transfer->block.height * transfer->stride + |
| 277 | transfer->x / transfer->block.width * transfer->block.size; |
Keith Whitwell | c9ed86a | 2008-05-01 11:07:21 +0100 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | static void |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 281 | i915_transfer_unmap(struct pipe_screen *screen, |
| 282 | struct pipe_transfer *transfer) |
Keith Whitwell | c9ed86a | 2008-05-01 11:07:21 +0100 | [diff] [blame] | 283 | { |
Michel Dänzer | b89aa1d | 2009-02-18 13:14:02 +0100 | [diff] [blame] | 284 | struct i915_texture *tex = (struct i915_texture *)transfer->texture; |
Zack Rusin | 5069bfe | 2009-02-02 23:47:16 -0500 | [diff] [blame] | 285 | pipe_buffer_unmap( screen, tex->buffer ); |
Keith Whitwell | c9ed86a | 2008-05-01 11:07:21 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 288 | /** |
| 289 | * Create a new i915_screen object |
| 290 | */ |
| 291 | struct pipe_screen * |
| 292 | i915_create_screen(struct pipe_winsys *winsys, uint pci_id) |
| 293 | { |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 294 | struct i915_screen *is = CALLOC_STRUCT(i915_screen); |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 295 | |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 296 | if (!is) |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 297 | return NULL; |
| 298 | |
| 299 | switch (pci_id) { |
| 300 | case PCI_CHIP_I915_G: |
| 301 | case PCI_CHIP_I915_GM: |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 302 | is->is_i945 = FALSE; |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 303 | break; |
| 304 | |
| 305 | case PCI_CHIP_I945_G: |
| 306 | case PCI_CHIP_I945_GM: |
| 307 | case PCI_CHIP_I945_GME: |
| 308 | case PCI_CHIP_G33_G: |
| 309 | case PCI_CHIP_Q33_G: |
| 310 | case PCI_CHIP_Q35_G: |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 311 | is->is_i945 = TRUE; |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 312 | break; |
| 313 | |
| 314 | default: |
José Fonseca | baab98a | 2008-03-31 09:02:08 +0900 | [diff] [blame] | 315 | debug_printf("%s: unknown pci id 0x%x, cannot create screen\n", |
| 316 | __FUNCTION__, pci_id); |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 317 | return NULL; |
| 318 | } |
| 319 | |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 320 | is->pci_id = pci_id; |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 321 | |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 322 | is->base.winsys = winsys; |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 323 | |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 324 | is->base.destroy = i915_destroy_screen; |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 325 | |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 326 | is->base.get_name = i915_get_name; |
| 327 | is->base.get_vendor = i915_get_vendor; |
| 328 | is->base.get_param = i915_get_param; |
| 329 | is->base.get_paramf = i915_get_paramf; |
| 330 | is->base.is_format_supported = i915_is_format_supported; |
| 331 | is->base.get_tex_transfer = i915_get_tex_transfer; |
| 332 | is->base.tex_transfer_destroy = i915_tex_transfer_destroy; |
| 333 | is->base.transfer_map = i915_transfer_map; |
| 334 | is->base.transfer_unmap = i915_transfer_unmap; |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 335 | |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 336 | i915_init_screen_texture_functions(is); |
| 337 | u_simple_screen_init(&is->base); |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 338 | |
Jakob Bornecrantz | 1bb3a2c | 2009-08-30 21:10:36 +0100 | [diff] [blame^] | 339 | return &is->base; |
Brian | aa59a93 | 2008-02-26 20:15:14 -0700 | [diff] [blame] | 340 | } |