Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Jerome Glisse <glisse@freedesktop.org> |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 8 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 9 | * the Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 21 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
Marek Olšák | 330b6c8 | 2012-03-05 15:17:00 +0100 | [diff] [blame] | 23 | #include "r600_pipe.h" |
| 24 | #include "r600_public.h" |
| 25 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 26 | #include <errno.h> |
Marek Olšák | 330b6c8 | 2012-03-05 15:17:00 +0100 | [diff] [blame] | 27 | #include "pipe/p_shader_tokens.h" |
Kai Wasserbäch | 8fb7f1a | 2011-08-27 17:51:51 +0200 | [diff] [blame] | 28 | #include "util/u_blitter.h" |
Kai Wasserbäch | 8fb7f1a | 2011-08-27 17:51:51 +0200 | [diff] [blame] | 29 | #include "util/u_format_s3tc.h" |
Marek Olšák | f71f5ed | 2012-02-24 02:08:32 +0100 | [diff] [blame] | 30 | #include "util/u_simple_shaders.h" |
Marek Olšák | 428855e | 2012-04-11 16:00:09 +0200 | [diff] [blame] | 31 | #include "util/u_upload_mgr.h" |
Kai Wasserbäch | 8fb7f1a | 2011-08-27 17:51:51 +0200 | [diff] [blame] | 32 | #include "vl/vl_decoder.h" |
| 33 | #include "vl/vl_video_buffer.h" |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 34 | #include "os/os_time.h" |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * pipe_context |
| 38 | */ |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 39 | static struct r600_fence *r600_create_fence(struct r600_context *rctx) |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 40 | { |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 41 | struct r600_screen *rscreen = rctx->screen; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 42 | struct r600_fence *fence = NULL; |
| 43 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 44 | pipe_mutex_lock(rscreen->fences.mutex); |
| 45 | |
| 46 | if (!rscreen->fences.bo) { |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 47 | /* Create the shared buffer object */ |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 48 | rscreen->fences.bo = (struct r600_resource*) |
| 49 | pipe_buffer_create(&rscreen->screen, PIPE_BIND_CUSTOM, |
Marek Olšák | 6101b6d | 2011-09-11 22:24:38 +0200 | [diff] [blame] | 50 | PIPE_USAGE_STAGING, 4096); |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 51 | if (!rscreen->fences.bo) { |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 52 | R600_ERR("r600: failed to create bo for fence objects\n"); |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 53 | goto out; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 54 | } |
Marek Olšák | 0a61202 | 2012-04-26 12:02:31 +0200 | [diff] [blame] | 55 | rscreen->fences.data = rctx->ws->buffer_map(rscreen->fences.bo->cs_buf, |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 56 | rctx->cs, |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 57 | PIPE_TRANSFER_READ_WRITE); |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 58 | } |
| 59 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 60 | if (!LIST_IS_EMPTY(&rscreen->fences.pool)) { |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 61 | struct r600_fence *entry; |
| 62 | |
| 63 | /* Try to find a freed fence that has been signalled */ |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 64 | LIST_FOR_EACH_ENTRY(entry, &rscreen->fences.pool, head) { |
| 65 | if (rscreen->fences.data[entry->index] != 0) { |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 66 | LIST_DELINIT(&entry->head); |
| 67 | fence = entry; |
| 68 | break; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | if (!fence) { |
| 74 | /* Allocate a new fence */ |
| 75 | struct r600_fence_block *block; |
| 76 | unsigned index; |
| 77 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 78 | if ((rscreen->fences.next_index + 1) >= 1024) { |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 79 | R600_ERR("r600: too many concurrent fences\n"); |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 80 | goto out; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 83 | index = rscreen->fences.next_index++; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 84 | |
| 85 | if (!(index % FENCE_BLOCK_SIZE)) { |
| 86 | /* Allocate a new block */ |
| 87 | block = CALLOC_STRUCT(r600_fence_block); |
| 88 | if (block == NULL) |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 89 | goto out; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 90 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 91 | LIST_ADD(&block->head, &rscreen->fences.blocks); |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 92 | } else { |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 93 | block = LIST_ENTRY(struct r600_fence_block, rscreen->fences.blocks.next, head); |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | fence = &block->fences[index % FENCE_BLOCK_SIZE]; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 97 | fence->index = index; |
| 98 | } |
| 99 | |
| 100 | pipe_reference_init(&fence->reference, 1); |
| 101 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 102 | rscreen->fences.data[fence->index] = 0; |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 103 | r600_context_emit_fence(rctx, rscreen->fences.bo, fence->index, 1); |
Simon Farnsworth | 8cd03b9 | 2012-02-14 12:06:20 +0000 | [diff] [blame] | 104 | |
| 105 | /* Create a dummy BO so that fence_finish without a timeout can sleep waiting for completion */ |
| 106 | fence->sleep_bo = (struct r600_resource*) |
| 107 | pipe_buffer_create(&rctx->screen->screen, PIPE_BIND_CUSTOM, |
| 108 | PIPE_USAGE_STAGING, 1); |
| 109 | /* Add the fence as a dummy relocation. */ |
| 110 | r600_context_bo_reloc(rctx, fence->sleep_bo, RADEON_USAGE_READWRITE); |
| 111 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 112 | out: |
| 113 | pipe_mutex_unlock(rscreen->fences.mutex); |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 114 | return fence; |
| 115 | } |
| 116 | |
Marek Olšák | e2e1dc9 | 2011-08-04 03:38:20 +0200 | [diff] [blame] | 117 | |
Marek Olšák | c79e9f0 | 2011-08-04 07:05:07 +0200 | [diff] [blame] | 118 | void r600_flush(struct pipe_context *ctx, struct pipe_fence_handle **fence, |
| 119 | unsigned flags) |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 120 | { |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 121 | struct r600_context *rctx = (struct r600_context *)ctx; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 122 | struct r600_fence **rfence = (struct r600_fence**)fence; |
Marek Olšák | 578b211 | 2011-11-10 15:50:06 +0100 | [diff] [blame] | 123 | struct pipe_query *render_cond = NULL; |
| 124 | unsigned render_cond_mode = 0; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 125 | |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 126 | if (rfence) |
| 127 | *rfence = r600_create_fence(rctx); |
| 128 | |
Marek Olšák | 578b211 | 2011-11-10 15:50:06 +0100 | [diff] [blame] | 129 | /* Disable render condition. */ |
| 130 | if (rctx->current_render_cond) { |
| 131 | render_cond = rctx->current_render_cond; |
| 132 | render_cond_mode = rctx->current_render_cond_mode; |
| 133 | ctx->render_condition(ctx, NULL, 0); |
| 134 | } |
| 135 | |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 136 | r600_context_flush(rctx, flags); |
Marek Olšák | 578b211 | 2011-11-10 15:50:06 +0100 | [diff] [blame] | 137 | |
| 138 | /* Re-enable render condition. */ |
| 139 | if (render_cond) { |
| 140 | ctx->render_condition(ctx, render_cond, render_cond_mode); |
| 141 | } |
Marek Olšák | e2e1dc9 | 2011-08-04 03:38:20 +0200 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void r600_flush_from_st(struct pipe_context *ctx, |
| 145 | struct pipe_fence_handle **fence) |
| 146 | { |
| 147 | r600_flush(ctx, fence, 0); |
| 148 | } |
| 149 | |
| 150 | static void r600_flush_from_winsys(void *ctx, unsigned flags) |
| 151 | { |
| 152 | r600_flush((struct pipe_context*)ctx, NULL, flags); |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static void r600_destroy_context(struct pipe_context *context) |
| 156 | { |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 157 | struct r600_context *rctx = (struct r600_context *)context; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 158 | |
Marek Olšák | 7835401 | 2012-08-26 22:38:35 +0200 | [diff] [blame^] | 159 | pipe_resource_reference((struct pipe_resource**)&rctx->dummy_cmask, NULL); |
| 160 | pipe_resource_reference((struct pipe_resource**)&rctx->dummy_fmask, NULL); |
| 161 | |
Vadim Girlin | 8d1a9a9 | 2012-08-21 15:39:25 +0400 | [diff] [blame] | 162 | if (rctx->no_blend) { |
| 163 | rctx->context.delete_blend_state(&rctx->context, rctx->no_blend); |
| 164 | } |
Marek Olšák | f71f5ed | 2012-02-24 02:08:32 +0100 | [diff] [blame] | 165 | if (rctx->dummy_pixel_shader) { |
| 166 | rctx->context.delete_fs_state(&rctx->context, rctx->dummy_pixel_shader); |
| 167 | } |
Marek Olšák | 6a94c9d | 2012-02-21 18:30:18 +0100 | [diff] [blame] | 168 | if (rctx->custom_dsa_flush) { |
| 169 | rctx->context.delete_depth_stencil_alpha_state(&rctx->context, rctx->custom_dsa_flush); |
| 170 | } |
Marek Olšák | 0f86915 | 2012-08-09 17:21:10 +0200 | [diff] [blame] | 171 | if (rctx->custom_blend_resolve) { |
| 172 | rctx->context.delete_blend_state(&rctx->context, rctx->custom_blend_resolve); |
| 173 | } |
Marek Olšák | a3d9d7e | 2012-08-12 20:06:33 +0200 | [diff] [blame] | 174 | if (rctx->custom_blend_decompress) { |
| 175 | rctx->context.delete_blend_state(&rctx->context, rctx->custom_blend_decompress); |
| 176 | } |
Henri Verbeet | 09eff39 | 2011-04-07 22:21:20 +0200 | [diff] [blame] | 177 | util_unreference_framebuffer_state(&rctx->framebuffer); |
Tilman Sauerbeck | ecb1b8b | 2010-10-31 12:16:03 +0100 | [diff] [blame] | 178 | |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 179 | r600_context_fini(rctx); |
José Fonseca | 01b39b0 | 2010-11-03 20:22:28 +0000 | [diff] [blame] | 180 | |
Marek Olšák | 6a94c9d | 2012-02-21 18:30:18 +0100 | [diff] [blame] | 181 | if (rctx->blitter) { |
| 182 | util_blitter_destroy(rctx->blitter); |
| 183 | } |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 184 | for (int i = 0; i < R600_PIPE_NSTATES; i++) { |
| 185 | free(rctx->states[i]); |
| 186 | } |
| 187 | |
Marek Olšák | 428855e | 2012-04-11 16:00:09 +0200 | [diff] [blame] | 188 | if (rctx->uploader) { |
| 189 | u_upload_destroy(rctx->uploader); |
| 190 | } |
Marek Olšák | f0b202e | 2011-02-08 17:30:39 +0100 | [diff] [blame] | 191 | util_slab_destroy(&rctx->pool_transfers); |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 192 | |
Marek Olšák | e363dd5 | 2012-03-05 16:20:05 +0100 | [diff] [blame] | 193 | r600_release_command_buffer(&rctx->start_cs_cmd); |
Marek Olšák | 9670e72 | 2012-02-21 18:08:32 +0100 | [diff] [blame] | 194 | |
Marek Olšák | 6a94c9d | 2012-02-21 18:30:18 +0100 | [diff] [blame] | 195 | if (rctx->cs) { |
| 196 | rctx->ws->cs_destroy(rctx->cs); |
| 197 | } |
Marek Olšák | 9670e72 | 2012-02-21 18:08:32 +0100 | [diff] [blame] | 198 | |
| 199 | FREE(rctx->range); |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 200 | FREE(rctx); |
| 201 | } |
| 202 | |
Dave Airlie | dbcd652 | 2010-09-30 09:07:07 +1000 | [diff] [blame] | 203 | static struct pipe_context *r600_create_context(struct pipe_screen *screen, void *priv) |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 204 | { |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 205 | struct r600_context *rctx = CALLOC_STRUCT(r600_context); |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 206 | struct r600_screen* rscreen = (struct r600_screen *)screen; |
Vadim Girlin | 8d1a9a9 | 2012-08-21 15:39:25 +0400 | [diff] [blame] | 207 | struct pipe_blend_state no_blend = {}; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 208 | |
| 209 | if (rctx == NULL) |
| 210 | return NULL; |
Marek Olšák | f0b202e | 2011-02-08 17:30:39 +0100 | [diff] [blame] | 211 | |
Marek Olšák | 6a94c9d | 2012-02-21 18:30:18 +0100 | [diff] [blame] | 212 | util_slab_create(&rctx->pool_transfers, |
Marek Olšák | 99c65ba | 2012-02-26 20:37:43 +0100 | [diff] [blame] | 213 | sizeof(struct r600_transfer), 64, |
Marek Olšák | 6a94c9d | 2012-02-21 18:30:18 +0100 | [diff] [blame] | 214 | UTIL_SLAB_SINGLETHREADED); |
| 215 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 216 | rctx->context.screen = screen; |
| 217 | rctx->context.priv = priv; |
| 218 | rctx->context.destroy = r600_destroy_context; |
Marek Olšák | e2e1dc9 | 2011-08-04 03:38:20 +0200 | [diff] [blame] | 219 | rctx->context.flush = r600_flush_from_st; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 220 | |
| 221 | /* Easy accessing of screen/winsys. */ |
| 222 | rctx->screen = rscreen; |
Marek Olšák | 6101b6d | 2011-09-11 22:24:38 +0200 | [diff] [blame] | 223 | rctx->ws = rscreen->ws; |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 224 | rctx->family = rscreen->family; |
| 225 | rctx->chip_class = rscreen->chip_class; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 226 | |
Marek Olšák | e280984 | 2012-02-02 14:01:12 +0100 | [diff] [blame] | 227 | LIST_INITHEAD(&rctx->dirty_states); |
Marek Olšák | 09ec30f | 2012-02-23 23:22:35 +0100 | [diff] [blame] | 228 | LIST_INITHEAD(&rctx->active_timer_queries); |
| 229 | LIST_INITHEAD(&rctx->active_nontimer_queries); |
Marek Olšák | 9670e72 | 2012-02-21 18:08:32 +0100 | [diff] [blame] | 230 | LIST_INITHEAD(&rctx->dirty); |
Marek Olšák | 9670e72 | 2012-02-21 18:08:32 +0100 | [diff] [blame] | 231 | LIST_INITHEAD(&rctx->enable_list); |
| 232 | |
| 233 | rctx->range = CALLOC(NUM_RANGES, sizeof(struct r600_range)); |
Marek Olšák | 04d2828 | 2012-02-21 19:03:14 +0100 | [diff] [blame] | 234 | if (!rctx->range) |
| 235 | goto fail; |
Marek Olšák | e280984 | 2012-02-02 14:01:12 +0100 | [diff] [blame] | 236 | |
Dave Airlie | dbcd652 | 2010-09-30 09:07:07 +1000 | [diff] [blame] | 237 | r600_init_blit_functions(rctx); |
Jerome Glisse | 6abd777 | 2010-09-29 15:39:40 -0400 | [diff] [blame] | 238 | r600_init_query_functions(rctx); |
Dave Airlie | dbcd652 | 2010-09-30 09:07:07 +1000 | [diff] [blame] | 239 | r600_init_context_resource_functions(rctx); |
Roland Scheidegger | 4c70014 | 2010-12-02 04:33:43 +0100 | [diff] [blame] | 240 | r600_init_surface_functions(rctx); |
Marek Olšák | 2d7738e | 2011-01-28 22:17:41 +0100 | [diff] [blame] | 241 | rctx->context.draw_vbo = r600_draw_vbo; |
Christian König | ea78480 | 2011-07-08 19:22:43 +0200 | [diff] [blame] | 242 | |
| 243 | rctx->context.create_video_decoder = vl_create_decoder; |
Christian König | 4e837f5 | 2011-07-08 16:56:11 +0200 | [diff] [blame] | 244 | rctx->context.create_video_buffer = vl_video_buffer_create; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 245 | |
Marek Olšák | 0813e58 | 2012-01-30 06:21:07 +0100 | [diff] [blame] | 246 | r600_init_common_atoms(rctx); |
| 247 | |
Henri Verbeet | b3b946b | 2011-07-09 17:18:59 +0200 | [diff] [blame] | 248 | switch (rctx->chip_class) { |
| 249 | case R600: |
| 250 | case R700: |
Dave Airlie | dbcd652 | 2010-09-30 09:07:07 +1000 | [diff] [blame] | 251 | r600_init_state_functions(rctx); |
Marek Olšák | f126253 | 2012-01-31 10:50:51 +0100 | [diff] [blame] | 252 | r600_init_atom_start_cs(rctx); |
Marek Olšák | 04d2828 | 2012-02-21 19:03:14 +0100 | [diff] [blame] | 253 | if (r600_context_init(rctx)) |
| 254 | goto fail; |
Henri Verbeet | b3b946b | 2011-07-09 17:18:59 +0200 | [diff] [blame] | 255 | rctx->custom_dsa_flush = r600_create_db_flush_dsa(rctx); |
Marek Olšák | 7835401 | 2012-08-26 22:38:35 +0200 | [diff] [blame^] | 256 | rctx->custom_blend_resolve = rctx->chip_class == R700 ? r700_create_resolve_blend(rctx) |
| 257 | : r600_create_resolve_blend(rctx); |
Marek Olšák | 8698a3b | 2012-08-02 22:31:22 +0200 | [diff] [blame] | 258 | rctx->custom_blend_decompress = r600_create_decompress_blend(rctx); |
Marek Olšák | bc95152 | 2012-03-31 23:44:31 +0200 | [diff] [blame] | 259 | rctx->has_vertex_cache = !(rctx->family == CHIP_RV610 || |
| 260 | rctx->family == CHIP_RV620 || |
| 261 | rctx->family == CHIP_RS780 || |
| 262 | rctx->family == CHIP_RS880 || |
| 263 | rctx->family == CHIP_RV710); |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 264 | break; |
Henri Verbeet | b3b946b | 2011-07-09 17:18:59 +0200 | [diff] [blame] | 265 | case EVERGREEN: |
| 266 | case CAYMAN: |
Dave Airlie | dbcd652 | 2010-09-30 09:07:07 +1000 | [diff] [blame] | 267 | evergreen_init_state_functions(rctx); |
Marek Olšák | f126253 | 2012-01-31 10:50:51 +0100 | [diff] [blame] | 268 | evergreen_init_atom_start_cs(rctx); |
Tom Stellard | 5016fe2 | 2012-06-25 17:56:01 +0000 | [diff] [blame] | 269 | evergreen_init_atom_start_compute_cs(rctx); |
Marek Olšák | 04d2828 | 2012-02-21 19:03:14 +0100 | [diff] [blame] | 270 | if (evergreen_context_init(rctx)) |
| 271 | goto fail; |
Henri Verbeet | b3b946b | 2011-07-09 17:18:59 +0200 | [diff] [blame] | 272 | rctx->custom_dsa_flush = evergreen_create_db_flush_dsa(rctx); |
Marek Olšák | 0f86915 | 2012-08-09 17:21:10 +0200 | [diff] [blame] | 273 | rctx->custom_blend_resolve = evergreen_create_resolve_blend(rctx); |
Marek Olšák | a3d9d7e | 2012-08-12 20:06:33 +0200 | [diff] [blame] | 274 | rctx->custom_blend_decompress = evergreen_create_decompress_blend(rctx); |
Marek Olšák | bc95152 | 2012-03-31 23:44:31 +0200 | [diff] [blame] | 275 | rctx->has_vertex_cache = !(rctx->family == CHIP_CEDAR || |
| 276 | rctx->family == CHIP_PALM || |
| 277 | rctx->family == CHIP_SUMO || |
| 278 | rctx->family == CHIP_SUMO2 || |
| 279 | rctx->family == CHIP_CAICOS || |
| 280 | rctx->family == CHIP_CAYMAN || |
| 281 | rctx->family == CHIP_ARUBA); |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 282 | break; |
| 283 | default: |
Henri Verbeet | b3b946b | 2011-07-09 17:18:59 +0200 | [diff] [blame] | 284 | R600_ERR("Unsupported chip class %d.\n", rctx->chip_class); |
Marek Olšák | 04d2828 | 2012-02-21 19:03:14 +0100 | [diff] [blame] | 285 | goto fail; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 286 | } |
| 287 | |
Marek Olšák | 9670e72 | 2012-02-21 18:08:32 +0100 | [diff] [blame] | 288 | rctx->cs = rctx->ws->cs_create(rctx->ws); |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 289 | rctx->ws->cs_set_flush_callback(rctx->cs, r600_flush_from_winsys, rctx); |
Marek Olšák | e363dd5 | 2012-03-05 16:20:05 +0100 | [diff] [blame] | 290 | r600_emit_atom(rctx, &rctx->start_cs_cmd.atom); |
Marek Olšák | e2e1dc9 | 2011-08-04 03:38:20 +0200 | [diff] [blame] | 291 | |
Marek Olšák | 428855e | 2012-04-11 16:00:09 +0200 | [diff] [blame] | 292 | rctx->uploader = u_upload_create(&rctx->context, 1024 * 1024, 256, |
| 293 | PIPE_BIND_INDEX_BUFFER | |
| 294 | PIPE_BIND_CONSTANT_BUFFER); |
| 295 | if (!rctx->uploader) |
| 296 | goto fail; |
| 297 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 298 | rctx->blitter = util_blitter_create(&rctx->context); |
Marek Olšák | 04d2828 | 2012-02-21 19:03:14 +0100 | [diff] [blame] | 299 | if (rctx->blitter == NULL) |
| 300 | goto fail; |
Marek Olšák | 187d7fb | 2012-08-24 05:57:22 +0200 | [diff] [blame] | 301 | rctx->blitter->draw_rectangle = r600_draw_rectangle; |
Dave Airlie | d59498b | 2010-10-13 15:22:04 +1000 | [diff] [blame] | 302 | |
Marek Olšák | e4340c1 | 2012-01-29 23:25:42 +0100 | [diff] [blame] | 303 | r600_get_backend_mask(rctx); /* this emits commands and must be last */ |
Marek Olšák | bbad510 | 2011-10-28 22:31:34 +0200 | [diff] [blame] | 304 | |
Marek Olšák | aacd653 | 2012-02-26 13:17:53 +0100 | [diff] [blame] | 305 | if (rctx->chip_class == R600) |
| 306 | r600_set_max_scissor(rctx); |
| 307 | |
Marek Olšák | f71f5ed | 2012-02-24 02:08:32 +0100 | [diff] [blame] | 308 | rctx->dummy_pixel_shader = |
| 309 | util_make_fragment_cloneinput_shader(&rctx->context, 0, |
| 310 | TGSI_SEMANTIC_GENERIC, |
| 311 | TGSI_INTERPOLATE_CONSTANT); |
| 312 | rctx->context.bind_fs_state(&rctx->context, rctx->dummy_pixel_shader); |
| 313 | |
Vadim Girlin | 8d1a9a9 | 2012-08-21 15:39:25 +0400 | [diff] [blame] | 314 | no_blend.rt[0].colormask = 0xF; |
| 315 | rctx->no_blend = rctx->context.create_blend_state(&rctx->context, &no_blend); |
| 316 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 317 | return &rctx->context; |
Marek Olšák | 04d2828 | 2012-02-21 19:03:14 +0100 | [diff] [blame] | 318 | |
| 319 | fail: |
| 320 | r600_destroy_context(&rctx->context); |
| 321 | return NULL; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* |
| 325 | * pipe_screen |
| 326 | */ |
| 327 | static const char* r600_get_vendor(struct pipe_screen* pscreen) |
| 328 | { |
| 329 | return "X.Org"; |
| 330 | } |
| 331 | |
Dave Airlie | 4378c17 | 2010-09-30 09:17:20 +1000 | [diff] [blame] | 332 | static const char *r600_get_family_name(enum radeon_family family) |
| 333 | { |
| 334 | switch(family) { |
Henri Verbeet | 9f06411 | 2010-11-07 18:40:12 +0100 | [diff] [blame] | 335 | case CHIP_R600: return "AMD R600"; |
| 336 | case CHIP_RV610: return "AMD RV610"; |
| 337 | case CHIP_RV630: return "AMD RV630"; |
| 338 | case CHIP_RV670: return "AMD RV670"; |
| 339 | case CHIP_RV620: return "AMD RV620"; |
| 340 | case CHIP_RV635: return "AMD RV635"; |
| 341 | case CHIP_RS780: return "AMD RS780"; |
| 342 | case CHIP_RS880: return "AMD RS880"; |
| 343 | case CHIP_RV770: return "AMD RV770"; |
| 344 | case CHIP_RV730: return "AMD RV730"; |
| 345 | case CHIP_RV710: return "AMD RV710"; |
| 346 | case CHIP_RV740: return "AMD RV740"; |
| 347 | case CHIP_CEDAR: return "AMD CEDAR"; |
| 348 | case CHIP_REDWOOD: return "AMD REDWOOD"; |
| 349 | case CHIP_JUNIPER: return "AMD JUNIPER"; |
| 350 | case CHIP_CYPRESS: return "AMD CYPRESS"; |
| 351 | case CHIP_HEMLOCK: return "AMD HEMLOCK"; |
Alex Deucher | 0e4c5f6 | 2010-11-22 17:47:24 -0500 | [diff] [blame] | 352 | case CHIP_PALM: return "AMD PALM"; |
Alex Deucher | 414cd5d | 2011-04-04 12:06:11 -0400 | [diff] [blame] | 353 | case CHIP_SUMO: return "AMD SUMO"; |
| 354 | case CHIP_SUMO2: return "AMD SUMO2"; |
Alex Deucher | f54366b | 2011-01-06 18:05:16 -0500 | [diff] [blame] | 355 | case CHIP_BARTS: return "AMD BARTS"; |
| 356 | case CHIP_TURKS: return "AMD TURKS"; |
| 357 | case CHIP_CAICOS: return "AMD CAICOS"; |
Dave Airlie | 7779f6d | 2011-03-10 12:54:13 +1000 | [diff] [blame] | 358 | case CHIP_CAYMAN: return "AMD CAYMAN"; |
Alex Deucher | b4082f4 | 2012-03-20 19:43:59 -0400 | [diff] [blame] | 359 | case CHIP_ARUBA: return "AMD ARUBA"; |
Henri Verbeet | 9f06411 | 2010-11-07 18:40:12 +0100 | [diff] [blame] | 360 | default: return "AMD unknown"; |
Dave Airlie | 4378c17 | 2010-09-30 09:17:20 +1000 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 364 | static const char* r600_get_name(struct pipe_screen* pscreen) |
| 365 | { |
| 366 | struct r600_screen *rscreen = (struct r600_screen *)pscreen; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 367 | |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 368 | return r600_get_family_name(rscreen->family); |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param) |
| 372 | { |
Alex Deucher | fae7cb8 | 2010-12-02 16:09:22 -0500 | [diff] [blame] | 373 | struct r600_screen *rscreen = (struct r600_screen *)pscreen; |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 374 | enum radeon_family family = rscreen->family; |
Alex Deucher | fae7cb8 | 2010-12-02 16:09:22 -0500 | [diff] [blame] | 375 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 376 | switch (param) { |
| 377 | /* Supported features (boolean caps). */ |
| 378 | case PIPE_CAP_NPOT_TEXTURES: |
| 379 | case PIPE_CAP_TWO_SIDED_STENCIL: |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 380 | case PIPE_CAP_ANISOTROPIC_FILTER: |
| 381 | case PIPE_CAP_POINT_SPRITE: |
| 382 | case PIPE_CAP_OCCLUSION_QUERY: |
| 383 | case PIPE_CAP_TEXTURE_SHADOW_MAP: |
| 384 | case PIPE_CAP_TEXTURE_MIRROR_CLAMP: |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 385 | case PIPE_CAP_BLEND_EQUATION_SEPARATE: |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 386 | case PIPE_CAP_TEXTURE_SWIZZLE: |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 387 | case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: |
Marek Olšák | dc4c821 | 2012-01-10 00:19:00 +0100 | [diff] [blame] | 388 | case PIPE_CAP_DEPTH_CLIP_DISABLE: |
Dave Airlie | 39d1feb | 2010-10-06 10:14:33 +1000 | [diff] [blame] | 389 | case PIPE_CAP_SHADER_STENCIL_EXPORT: |
Marek Olšák | 95c7881 | 2011-03-05 16:06:10 +0100 | [diff] [blame] | 390 | case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: |
Marek Olšák | 4a7f013 | 2011-03-29 18:18:05 +0200 | [diff] [blame] | 391 | case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: |
Marek Olšák | 93754d8 | 2011-05-03 11:54:40 +0200 | [diff] [blame] | 392 | case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: |
| 393 | case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: |
Dave Airlie | 13c9a85 | 2011-06-15 15:15:41 +1000 | [diff] [blame] | 394 | case PIPE_CAP_SM3: |
Marek Olšák | badf033 | 2011-06-19 23:41:02 +0200 | [diff] [blame] | 395 | case PIPE_CAP_SEAMLESS_CUBE_MAP: |
Marek Olšák | 01680ce | 2011-08-16 09:47:16 +0200 | [diff] [blame] | 396 | case PIPE_CAP_PRIMITIVE_RESTART: |
Marek Olšák | 3d13b08 | 2011-09-27 23:08:04 +0200 | [diff] [blame] | 397 | case PIPE_CAP_CONDITIONAL_RENDER: |
Marek Olšák | ba89086 | 2011-09-27 23:18:17 +0200 | [diff] [blame] | 398 | case PIPE_CAP_TEXTURE_BARRIER: |
Marek Olšák | bc1c836 | 2012-01-23 03:11:17 +0100 | [diff] [blame] | 399 | case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: |
Marek Olšák | b0b8121 | 2012-02-16 14:45:35 +0100 | [diff] [blame] | 400 | case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION: |
Marek Olšák | 7f1cbf1 | 2012-03-08 12:20:01 +0100 | [diff] [blame] | 401 | case PIPE_CAP_TGSI_INSTANCEID: |
Marek Olšák | 7fe3631 | 2012-04-10 05:14:26 +0200 | [diff] [blame] | 402 | case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY: |
| 403 | case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY: |
| 404 | case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY: |
Marek Olšák | 437ab1d | 2012-04-24 15:19:31 +0200 | [diff] [blame] | 405 | case PIPE_CAP_USER_INDEX_BUFFERS: |
| 406 | case PIPE_CAP_USER_CONSTANT_BUFFERS: |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 407 | case PIPE_CAP_COMPUTE: |
Fredrik Höglund | af37212 | 2012-06-18 22:50:02 +0200 | [diff] [blame] | 408 | case PIPE_CAP_START_INSTANCE: |
Marek Olšák | 9d699cd | 2012-07-15 03:38:42 +0200 | [diff] [blame] | 409 | case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS: |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 410 | return 1; |
Marek Olšák | 93754d8 | 2011-05-03 11:54:40 +0200 | [diff] [blame] | 411 | |
Marek Olšák | 1b749dc | 2012-04-24 17:31:17 +0200 | [diff] [blame] | 412 | case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT: |
| 413 | return 256; |
| 414 | |
Marek Olšák | 171be75 | 2012-01-24 22:23:01 +0100 | [diff] [blame] | 415 | case PIPE_CAP_GLSL_FEATURE_LEVEL: |
Marek Olšák | 15ca9d1 | 2012-07-14 22:28:26 +0200 | [diff] [blame] | 416 | return 130; |
Marek Olšák | 171be75 | 2012-01-24 22:23:01 +0100 | [diff] [blame] | 417 | |
Marek Olšák | 93754d8 | 2011-05-03 11:54:40 +0200 | [diff] [blame] | 418 | /* Supported except the original R600. */ |
Alex Deucher | d6fea4a | 2011-03-14 17:47:21 -0400 | [diff] [blame] | 419 | case PIPE_CAP_INDEP_BLEND_ENABLE: |
Dave Airlie | de48199 | 2011-04-25 06:55:09 +1000 | [diff] [blame] | 420 | case PIPE_CAP_INDEP_BLEND_FUNC: |
Alex Deucher | d6fea4a | 2011-03-14 17:47:21 -0400 | [diff] [blame] | 421 | /* R600 doesn't support per-MRT blends */ |
Marek Olšák | 93754d8 | 2011-05-03 11:54:40 +0200 | [diff] [blame] | 422 | return family == CHIP_R600 ? 0 : 1; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 423 | |
Marek Olšák | d931b0d | 2011-05-02 02:38:20 +0200 | [diff] [blame] | 424 | /* Supported on Evergreen. */ |
Marek Olšák | d931b0d | 2011-05-02 02:38:20 +0200 | [diff] [blame] | 425 | case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE: |
| 426 | return family >= CHIP_CEDAR ? 1 : 0; |
Marek Olšák | fc8e30e | 2011-04-17 01:57:13 +0200 | [diff] [blame] | 427 | |
Marek Olšák | 93754d8 | 2011-05-03 11:54:40 +0200 | [diff] [blame] | 428 | /* Unsupported features. */ |
Marek Olšák | 93754d8 | 2011-05-03 11:54:40 +0200 | [diff] [blame] | 429 | case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: |
| 430 | case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: |
Marek Olšák | 034e63b | 2011-11-22 20:48:23 +0100 | [diff] [blame] | 431 | case PIPE_CAP_SCALED_RESOLVE: |
Marek Olšák | a3bfbcc | 2011-12-17 15:13:23 +0100 | [diff] [blame] | 432 | case PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS: |
| 433 | case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS: |
Marek Olšák | bc1c836 | 2012-01-23 03:11:17 +0100 | [diff] [blame] | 434 | case PIPE_CAP_FRAGMENT_COLOR_CLAMPED: |
| 435 | case PIPE_CAP_VERTEX_COLOR_CLAMPED: |
Marek Olšák | 7fe3631 | 2012-04-10 05:14:26 +0200 | [diff] [blame] | 436 | case PIPE_CAP_USER_VERTEX_BUFFERS: |
Marek Olšák | 93754d8 | 2011-05-03 11:54:40 +0200 | [diff] [blame] | 437 | return 0; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 438 | |
Marek Olšák | 543b233 | 2011-11-08 21:58:27 +0100 | [diff] [blame] | 439 | /* Stream output. */ |
| 440 | case PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS: |
Marek Olšák | 6e7756d | 2012-06-17 17:54:38 +0200 | [diff] [blame] | 441 | return rscreen->has_streamout ? 4 : 0; |
Marek Olšák | 15146fd | 2012-01-25 03:23:27 +0100 | [diff] [blame] | 442 | case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME: |
Marek Olšák | 6e7756d | 2012-06-17 17:54:38 +0200 | [diff] [blame] | 443 | return rscreen->has_streamout ? 1 : 0; |
Marek Olšák | 543b233 | 2011-11-08 21:58:27 +0100 | [diff] [blame] | 444 | case PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS: |
| 445 | case PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS: |
| 446 | return 16*4; |
| 447 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 448 | /* Texturing. */ |
| 449 | case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: |
| 450 | case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: |
| 451 | case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: |
Alex Deucher | fae7cb8 | 2010-12-02 16:09:22 -0500 | [diff] [blame] | 452 | if (family >= CHIP_CEDAR) |
| 453 | return 15; |
| 454 | else |
| 455 | return 14; |
Marek Olšák | b37931f | 2011-09-04 04:41:52 +0200 | [diff] [blame] | 456 | case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: |
Marek Olšák | 1a532ca | 2011-09-11 16:35:10 +0200 | [diff] [blame] | 457 | return rscreen->info.drm_minor >= 9 ? |
Marek Olšák | b37931f | 2011-09-04 04:41:52 +0200 | [diff] [blame] | 458 | (family >= CHIP_CEDAR ? 16384 : 8192) : 0; |
Marek Olšák | 320adb9 | 2011-05-03 11:54:07 +0200 | [diff] [blame] | 459 | case PIPE_CAP_MAX_COMBINED_SAMPLERS: |
| 460 | return 32; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 461 | |
| 462 | /* Render targets. */ |
| 463 | case PIPE_CAP_MAX_RENDER_TARGETS: |
Marek Olšák | 370c8b5 | 2012-02-24 16:36:05 +0100 | [diff] [blame] | 464 | /* XXX some r6xx are buggy and can only do 4 */ |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 465 | return 8; |
| 466 | |
Mathias Fröhlich | 90c2fd8 | 2011-01-23 22:35:13 +0100 | [diff] [blame] | 467 | /* Timer queries, present when the clock frequency is non zero. */ |
| 468 | case PIPE_CAP_TIMER_QUERY: |
Marek Olšák | 1a532ca | 2011-09-11 16:35:10 +0200 | [diff] [blame] | 469 | return rscreen->info.r600_clock_crystal_freq != 0; |
Marek Olšák | 44f14eb | 2012-07-05 20:06:41 +0200 | [diff] [blame] | 470 | case PIPE_CAP_QUERY_TIMESTAMP: |
| 471 | return rscreen->info.drm_minor >= 20 && |
| 472 | rscreen->info.r600_clock_crystal_freq != 0; |
Mathias Fröhlich | 90c2fd8 | 2011-01-23 22:35:13 +0100 | [diff] [blame] | 473 | |
Dave Airlie | 0b66610 | 2011-08-29 14:35:16 +0100 | [diff] [blame] | 474 | case PIPE_CAP_MIN_TEXEL_OFFSET: |
| 475 | return -8; |
| 476 | |
| 477 | case PIPE_CAP_MAX_TEXEL_OFFSET: |
| 478 | return 7; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 479 | } |
Marek Olšák | 4ac250c | 2011-11-22 20:44:14 +0100 | [diff] [blame] | 480 | return 0; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Marek Olšák | bb71f92 | 2011-11-19 22:38:22 +0100 | [diff] [blame] | 483 | static float r600_get_paramf(struct pipe_screen* pscreen, |
| 484 | enum pipe_capf param) |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 485 | { |
Alex Deucher | fae7cb8 | 2010-12-02 16:09:22 -0500 | [diff] [blame] | 486 | struct r600_screen *rscreen = (struct r600_screen *)pscreen; |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 487 | enum radeon_family family = rscreen->family; |
Alex Deucher | fae7cb8 | 2010-12-02 16:09:22 -0500 | [diff] [blame] | 488 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 489 | switch (param) { |
Marek Olšák | bb71f92 | 2011-11-19 22:38:22 +0100 | [diff] [blame] | 490 | case PIPE_CAPF_MAX_LINE_WIDTH: |
| 491 | case PIPE_CAPF_MAX_LINE_WIDTH_AA: |
| 492 | case PIPE_CAPF_MAX_POINT_WIDTH: |
| 493 | case PIPE_CAPF_MAX_POINT_WIDTH_AA: |
Alex Deucher | fae7cb8 | 2010-12-02 16:09:22 -0500 | [diff] [blame] | 494 | if (family >= CHIP_CEDAR) |
| 495 | return 16384.0f; |
| 496 | else |
| 497 | return 8192.0f; |
Marek Olšák | bb71f92 | 2011-11-19 22:38:22 +0100 | [diff] [blame] | 498 | case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY: |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 499 | return 16.0f; |
Marek Olšák | bb71f92 | 2011-11-19 22:38:22 +0100 | [diff] [blame] | 500 | case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS: |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 501 | return 16.0f; |
Marek Olšák | 034e63b | 2011-11-22 20:48:23 +0100 | [diff] [blame] | 502 | case PIPE_CAPF_GUARD_BAND_LEFT: |
| 503 | case PIPE_CAPF_GUARD_BAND_TOP: |
| 504 | case PIPE_CAPF_GUARD_BAND_RIGHT: |
| 505 | case PIPE_CAPF_GUARD_BAND_BOTTOM: |
| 506 | return 0.0f; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 507 | } |
Marek Olšák | 4ac250c | 2011-11-22 20:44:14 +0100 | [diff] [blame] | 508 | return 0.0f; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static int r600_get_shader_param(struct pipe_screen* pscreen, unsigned shader, enum pipe_shader_cap param) |
| 512 | { |
| 513 | switch(shader) |
| 514 | { |
| 515 | case PIPE_SHADER_FRAGMENT: |
| 516 | case PIPE_SHADER_VERTEX: |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 517 | case PIPE_SHADER_COMPUTE: |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 518 | break; |
| 519 | case PIPE_SHADER_GEOMETRY: |
Marek Olšák | 370c8b5 | 2012-02-24 16:36:05 +0100 | [diff] [blame] | 520 | /* XXX: support and enable geometry programs */ |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 521 | return 0; |
| 522 | default: |
Marek Olšák | 370c8b5 | 2012-02-24 16:36:05 +0100 | [diff] [blame] | 523 | /* XXX: support tessellation on Evergreen */ |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 524 | return 0; |
| 525 | } |
| 526 | |
Marek Olšák | 370c8b5 | 2012-02-24 16:36:05 +0100 | [diff] [blame] | 527 | /* XXX: all these should be fixed, since r600 surely supports much more! */ |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 528 | switch (param) { |
| 529 | case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: |
| 530 | case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: |
| 531 | case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: |
| 532 | case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: |
| 533 | return 16384; |
| 534 | case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: |
Marek Olšák | 370c8b5 | 2012-02-24 16:36:05 +0100 | [diff] [blame] | 535 | return 8; /* XXX */ |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 536 | case PIPE_SHADER_CAP_MAX_INPUTS: |
| 537 | if(shader == PIPE_SHADER_FRAGMENT) |
Marek Olšák | 1e5cef9 | 2011-06-23 15:55:41 +0200 | [diff] [blame] | 538 | return 34; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 539 | else |
Marek Olšák | 1e5cef9 | 2011-06-23 15:55:41 +0200 | [diff] [blame] | 540 | return 32; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 541 | case PIPE_SHADER_CAP_MAX_TEMPS: |
Henri Verbeet | b2a98c3 | 2011-04-25 13:28:55 +0200 | [diff] [blame] | 542 | return 256; /* Max native temporaries. */ |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 543 | case PIPE_SHADER_CAP_MAX_ADDRS: |
Marek Olšák | 370c8b5 | 2012-02-24 16:36:05 +0100 | [diff] [blame] | 544 | /* XXX Isn't this equal to TEMPS? */ |
Henri Verbeet | b2a98c3 | 2011-04-25 13:28:55 +0200 | [diff] [blame] | 545 | return 1; /* Max native address registers */ |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 546 | case PIPE_SHADER_CAP_MAX_CONSTS: |
Henri Verbeet | eac5029 | 2011-03-07 21:15:03 +0100 | [diff] [blame] | 547 | return R600_MAX_CONST_BUFFER_SIZE; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 548 | case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: |
Vadim Girlin | 54e8dca | 2012-01-21 01:37:48 +0400 | [diff] [blame] | 549 | return R600_MAX_CONST_BUFFERS-1; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 550 | case PIPE_SHADER_CAP_MAX_PREDS: |
Marek Olšák | 370c8b5 | 2012-02-24 16:36:05 +0100 | [diff] [blame] | 551 | return 0; /* nothing uses this */ |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 552 | case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: |
| 553 | return 1; |
Marek Olšák | 5c7127c | 2010-11-12 03:07:05 +0100 | [diff] [blame] | 554 | case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: |
| 555 | case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: |
| 556 | case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: |
| 557 | case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: |
| 558 | return 1; |
Marek Olšák | 9aa089e | 2010-11-14 15:34:59 +0100 | [diff] [blame] | 559 | case PIPE_SHADER_CAP_SUBROUTINES: |
| 560 | return 0; |
Bryan Cain | 17b695e | 2011-05-05 21:10:28 -0500 | [diff] [blame] | 561 | case PIPE_SHADER_CAP_INTEGERS: |
Marek Olšák | 15ca9d1 | 2012-07-14 22:28:26 +0200 | [diff] [blame] | 562 | return 1; |
Marek Olšák | f5bfe54 | 2011-09-27 22:22:06 +0200 | [diff] [blame] | 563 | case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: |
| 564 | return 16; |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 565 | case PIPE_SHADER_CAP_PREFERRED_IR: |
| 566 | if (shader == PIPE_SHADER_COMPUTE) { |
| 567 | return PIPE_SHADER_IR_LLVM; |
| 568 | } else { |
| 569 | return PIPE_SHADER_IR_TGSI; |
| 570 | } |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 571 | } |
Marek Olšák | 4ac250c | 2011-11-22 20:44:14 +0100 | [diff] [blame] | 572 | return 0; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Christian König | f265a19 | 2011-07-07 22:51:45 +0200 | [diff] [blame] | 575 | static int r600_get_video_param(struct pipe_screen *screen, |
| 576 | enum pipe_video_profile profile, |
| 577 | enum pipe_video_cap param) |
| 578 | { |
| 579 | switch (param) { |
Christian König | efc7fda | 2011-07-12 00:12:12 +0200 | [diff] [blame] | 580 | case PIPE_VIDEO_CAP_SUPPORTED: |
| 581 | return vl_profile_supported(screen, profile); |
Christian König | f265a19 | 2011-07-07 22:51:45 +0200 | [diff] [blame] | 582 | case PIPE_VIDEO_CAP_NPOT_TEXTURES: |
| 583 | return 1; |
Christian König | efc7fda | 2011-07-12 00:12:12 +0200 | [diff] [blame] | 584 | case PIPE_VIDEO_CAP_MAX_WIDTH: |
| 585 | case PIPE_VIDEO_CAP_MAX_HEIGHT: |
| 586 | return vl_video_buffer_max_size(screen); |
Christian König | 9d9afcb | 2012-01-10 14:03:28 +0100 | [diff] [blame] | 587 | case PIPE_VIDEO_CAP_PREFERED_FORMAT: |
| 588 | return PIPE_FORMAT_NV12; |
Christian König | f3f03c6 | 2012-02-01 23:38:45 +0100 | [diff] [blame] | 589 | case PIPE_VIDEO_CAP_PREFERS_INTERLACED: |
| 590 | return false; |
| 591 | case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED: |
| 592 | return false; |
| 593 | case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE: |
| 594 | return true; |
Christian König | f265a19 | 2011-07-07 22:51:45 +0200 | [diff] [blame] | 595 | default: |
| 596 | return 0; |
| 597 | } |
| 598 | } |
| 599 | |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 600 | static int r600_get_compute_param(struct pipe_screen *screen, |
| 601 | enum pipe_compute_cap param, |
| 602 | void *ret) |
| 603 | { |
| 604 | //TODO: select these params by asic |
| 605 | switch (param) { |
| 606 | case PIPE_COMPUTE_CAP_IR_TARGET: |
| 607 | if (ret) { |
| 608 | strcpy(ret, "r600--"); |
| 609 | } |
| 610 | return 7 * sizeof(char); |
| 611 | |
| 612 | case PIPE_COMPUTE_CAP_GRID_DIMENSION: |
| 613 | if (ret) { |
| 614 | uint64_t * grid_dimension = ret; |
| 615 | grid_dimension[0] = 3; |
| 616 | } |
| 617 | return 1 * sizeof(uint64_t); |
| 618 | |
| 619 | case PIPE_COMPUTE_CAP_MAX_GRID_SIZE: |
| 620 | if (ret) { |
| 621 | uint64_t * grid_size = ret; |
| 622 | grid_size[0] = 65535; |
| 623 | grid_size[1] = 65535; |
| 624 | grid_size[2] = 1; |
| 625 | } |
| 626 | return 3 * sizeof(uint64_t) ; |
| 627 | |
| 628 | case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE: |
| 629 | if (ret) { |
| 630 | uint64_t * block_size = ret; |
| 631 | block_size[0] = 256; |
| 632 | block_size[1] = 256; |
| 633 | block_size[2] = 256; |
| 634 | } |
| 635 | return 3 * sizeof(uint64_t); |
| 636 | |
| 637 | case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK: |
| 638 | if (ret) { |
| 639 | uint64_t * max_threads_per_block = ret; |
| 640 | *max_threads_per_block = 256; |
| 641 | } |
| 642 | return sizeof(uint64_t); |
| 643 | |
| 644 | case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE: |
| 645 | if (ret) { |
| 646 | uint64_t * max_global_size = ret; |
Tom Stellard | c0f7fe7 | 2012-07-11 16:18:22 +0000 | [diff] [blame] | 647 | /* XXX: This is 64kb for now until we get the |
| 648 | * compute memory pool working correctly. |
| 649 | */ |
| 650 | *max_global_size = 1024 * 16 * 4; |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 651 | } |
| 652 | return sizeof(uint64_t); |
| 653 | |
| 654 | case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE: |
| 655 | if (ret) { |
| 656 | uint64_t * max_input_size = ret; |
| 657 | *max_input_size = 1024; |
| 658 | } |
| 659 | return sizeof(uint64_t); |
| 660 | |
| 661 | case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE: |
| 662 | if (ret) { |
| 663 | uint64_t * max_local_size = ret; |
| 664 | /* XXX: This is what the proprietary driver reports, we |
| 665 | * may want to use a different value. */ |
| 666 | *max_local_size = 32768; |
| 667 | } |
| 668 | return sizeof(uint64_t); |
| 669 | |
| 670 | default: |
| 671 | fprintf(stderr, "unknown PIPE_COMPUTE_CAP %d\n", param); |
| 672 | return 0; |
| 673 | } |
| 674 | } |
| 675 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 676 | static void r600_destroy_screen(struct pipe_screen* pscreen) |
| 677 | { |
| 678 | struct r600_screen *rscreen = (struct r600_screen *)pscreen; |
| 679 | |
| 680 | if (rscreen == NULL) |
| 681 | return; |
Tilman Sauerbeck | 52ba68d | 2010-10-31 15:51:55 +0100 | [diff] [blame] | 682 | |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 683 | if (rscreen->global_pool) { |
| 684 | compute_memory_pool_delete(rscreen->global_pool); |
| 685 | } |
| 686 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 687 | if (rscreen->fences.bo) { |
| 688 | struct r600_fence_block *entry, *tmp; |
| 689 | |
| 690 | LIST_FOR_EACH_ENTRY_SAFE(entry, tmp, &rscreen->fences.blocks, head) { |
| 691 | LIST_DEL(&entry->head); |
| 692 | FREE(entry); |
| 693 | } |
| 694 | |
Marek Olšák | 0a61202 | 2012-04-26 12:02:31 +0200 | [diff] [blame] | 695 | rscreen->ws->buffer_unmap(rscreen->fences.bo->cs_buf); |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 696 | pipe_resource_reference((struct pipe_resource**)&rscreen->fences.bo, NULL); |
| 697 | } |
| 698 | pipe_mutex_destroy(rscreen->fences.mutex); |
| 699 | |
Marek Olšák | 2ce783d | 2011-08-02 20:25:13 +0200 | [diff] [blame] | 700 | rscreen->ws->destroy(rscreen->ws); |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 701 | FREE(rscreen); |
| 702 | } |
| 703 | |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 704 | static void r600_fence_reference(struct pipe_screen *pscreen, |
| 705 | struct pipe_fence_handle **ptr, |
| 706 | struct pipe_fence_handle *fence) |
| 707 | { |
| 708 | struct r600_fence **oldf = (struct r600_fence**)ptr; |
| 709 | struct r600_fence *newf = (struct r600_fence*)fence; |
| 710 | |
| 711 | if (pipe_reference(&(*oldf)->reference, &newf->reference)) { |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 712 | struct r600_screen *rscreen = (struct r600_screen *)pscreen; |
| 713 | pipe_mutex_lock(rscreen->fences.mutex); |
Simon Farnsworth | 8cd03b9 | 2012-02-14 12:06:20 +0000 | [diff] [blame] | 714 | pipe_resource_reference((struct pipe_resource**)&(*oldf)->sleep_bo, NULL); |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 715 | LIST_ADDTAIL(&(*oldf)->head, &rscreen->fences.pool); |
| 716 | pipe_mutex_unlock(rscreen->fences.mutex); |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | *ptr = fence; |
| 720 | } |
| 721 | |
| 722 | static boolean r600_fence_signalled(struct pipe_screen *pscreen, |
| 723 | struct pipe_fence_handle *fence) |
| 724 | { |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 725 | struct r600_screen *rscreen = (struct r600_screen *)pscreen; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 726 | struct r600_fence *rfence = (struct r600_fence*)fence; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 727 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 728 | return rscreen->fences.data[rfence->index]; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | static boolean r600_fence_finish(struct pipe_screen *pscreen, |
| 732 | struct pipe_fence_handle *fence, |
| 733 | uint64_t timeout) |
| 734 | { |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 735 | struct r600_screen *rscreen = (struct r600_screen *)pscreen; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 736 | struct r600_fence *rfence = (struct r600_fence*)fence; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 737 | int64_t start_time = 0; |
| 738 | unsigned spins = 0; |
| 739 | |
| 740 | if (timeout != PIPE_TIMEOUT_INFINITE) { |
| 741 | start_time = os_time_get(); |
| 742 | |
| 743 | /* Convert to microseconds. */ |
| 744 | timeout /= 1000; |
| 745 | } |
| 746 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 747 | while (rscreen->fences.data[rfence->index] == 0) { |
Simon Farnsworth | 8cd03b9 | 2012-02-14 12:06:20 +0000 | [diff] [blame] | 748 | /* Special-case infinite timeout - wait for the dummy BO to become idle */ |
| 749 | if (timeout == PIPE_TIMEOUT_INFINITE) { |
| 750 | rscreen->ws->buffer_wait(rfence->sleep_bo->buf, RADEON_USAGE_READWRITE); |
| 751 | break; |
| 752 | } |
| 753 | |
| 754 | /* The dummy BO will be busy until the CS including the fence has completed, or |
| 755 | * the GPU is reset. Don't bother continuing to spin when the BO is idle. */ |
| 756 | if (!rscreen->ws->buffer_is_busy(rfence->sleep_bo->buf, RADEON_USAGE_READWRITE)) |
| 757 | break; |
| 758 | |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 759 | if (++spins % 256) |
| 760 | continue; |
| 761 | #ifdef PIPE_OS_UNIX |
| 762 | sched_yield(); |
| 763 | #else |
| 764 | os_time_sleep(10); |
| 765 | #endif |
| 766 | if (timeout != PIPE_TIMEOUT_INFINITE && |
| 767 | os_time_get() - start_time >= timeout) { |
Simon Farnsworth | 8cd03b9 | 2012-02-14 12:06:20 +0000 | [diff] [blame] | 768 | break; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
Simon Farnsworth | 8cd03b9 | 2012-02-14 12:06:20 +0000 | [diff] [blame] | 772 | return rscreen->fences.data[rfence->index] != 0; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 773 | } |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 774 | |
Marek Olšák | 3603d15 | 2011-09-11 14:53:07 +0200 | [diff] [blame] | 775 | static int r600_interpret_tiling(struct r600_screen *rscreen, uint32_t tiling_config) |
| 776 | { |
| 777 | switch ((tiling_config & 0xe) >> 1) { |
| 778 | case 0: |
| 779 | rscreen->tiling_info.num_channels = 1; |
| 780 | break; |
| 781 | case 1: |
| 782 | rscreen->tiling_info.num_channels = 2; |
| 783 | break; |
| 784 | case 2: |
| 785 | rscreen->tiling_info.num_channels = 4; |
| 786 | break; |
| 787 | case 3: |
| 788 | rscreen->tiling_info.num_channels = 8; |
| 789 | break; |
| 790 | default: |
| 791 | return -EINVAL; |
| 792 | } |
| 793 | |
| 794 | switch ((tiling_config & 0x30) >> 4) { |
| 795 | case 0: |
| 796 | rscreen->tiling_info.num_banks = 4; |
| 797 | break; |
| 798 | case 1: |
| 799 | rscreen->tiling_info.num_banks = 8; |
| 800 | break; |
| 801 | default: |
| 802 | return -EINVAL; |
| 803 | |
| 804 | } |
| 805 | switch ((tiling_config & 0xc0) >> 6) { |
| 806 | case 0: |
| 807 | rscreen->tiling_info.group_bytes = 256; |
| 808 | break; |
| 809 | case 1: |
| 810 | rscreen->tiling_info.group_bytes = 512; |
| 811 | break; |
| 812 | default: |
| 813 | return -EINVAL; |
| 814 | } |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | static int evergreen_interpret_tiling(struct r600_screen *rscreen, uint32_t tiling_config) |
| 819 | { |
| 820 | switch (tiling_config & 0xf) { |
| 821 | case 0: |
| 822 | rscreen->tiling_info.num_channels = 1; |
| 823 | break; |
| 824 | case 1: |
| 825 | rscreen->tiling_info.num_channels = 2; |
| 826 | break; |
| 827 | case 2: |
| 828 | rscreen->tiling_info.num_channels = 4; |
| 829 | break; |
| 830 | case 3: |
| 831 | rscreen->tiling_info.num_channels = 8; |
| 832 | break; |
| 833 | default: |
| 834 | return -EINVAL; |
| 835 | } |
| 836 | |
| 837 | switch ((tiling_config & 0xf0) >> 4) { |
| 838 | case 0: |
| 839 | rscreen->tiling_info.num_banks = 4; |
| 840 | break; |
| 841 | case 1: |
| 842 | rscreen->tiling_info.num_banks = 8; |
| 843 | break; |
| 844 | case 2: |
| 845 | rscreen->tiling_info.num_banks = 16; |
| 846 | break; |
| 847 | default: |
| 848 | return -EINVAL; |
| 849 | } |
| 850 | |
| 851 | switch ((tiling_config & 0xf00) >> 8) { |
| 852 | case 0: |
| 853 | rscreen->tiling_info.group_bytes = 256; |
| 854 | break; |
| 855 | case 1: |
| 856 | rscreen->tiling_info.group_bytes = 512; |
| 857 | break; |
| 858 | default: |
| 859 | return -EINVAL; |
| 860 | } |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | static int r600_init_tiling(struct r600_screen *rscreen) |
| 865 | { |
| 866 | uint32_t tiling_config = rscreen->info.r600_tiling_config; |
| 867 | |
| 868 | /* set default group bytes, overridden by tiling info ioctl */ |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 869 | if (rscreen->chip_class <= R700) { |
Marek Olšák | 3603d15 | 2011-09-11 14:53:07 +0200 | [diff] [blame] | 870 | rscreen->tiling_info.group_bytes = 256; |
| 871 | } else { |
| 872 | rscreen->tiling_info.group_bytes = 512; |
| 873 | } |
| 874 | |
| 875 | if (!tiling_config) |
| 876 | return 0; |
| 877 | |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 878 | if (rscreen->chip_class <= R700) { |
Marek Olšák | 3603d15 | 2011-09-11 14:53:07 +0200 | [diff] [blame] | 879 | return r600_interpret_tiling(rscreen, tiling_config); |
| 880 | } else { |
| 881 | return evergreen_interpret_tiling(rscreen, tiling_config); |
| 882 | } |
| 883 | } |
| 884 | |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 885 | static unsigned radeon_family_from_device(unsigned device) |
| 886 | { |
| 887 | switch (device) { |
| 888 | #define CHIPSET(pciid, name, family) case pciid: return CHIP_##family; |
| 889 | #include "pci_ids/r600_pci_ids.h" |
| 890 | #undef CHIPSET |
| 891 | default: |
| 892 | return CHIP_UNKNOWN; |
| 893 | } |
| 894 | } |
| 895 | |
Marek Olšák | 44f14eb | 2012-07-05 20:06:41 +0200 | [diff] [blame] | 896 | static uint64_t r600_get_timestamp(struct pipe_screen *screen) |
| 897 | { |
| 898 | struct r600_screen *rscreen = (struct r600_screen*)screen; |
| 899 | |
| 900 | return 1000000 * rscreen->ws->query_timestamp(rscreen->ws) / |
| 901 | rscreen->info.r600_clock_crystal_freq; |
| 902 | } |
| 903 | |
Marek Olšák | 2ce783d | 2011-08-02 20:25:13 +0200 | [diff] [blame] | 904 | struct pipe_screen *r600_screen_create(struct radeon_winsys *ws) |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 905 | { |
Marek Olšák | 90ce3cd | 2011-09-17 14:10:20 +0200 | [diff] [blame] | 906 | struct r600_screen *rscreen = CALLOC_STRUCT(r600_screen); |
Dave Airlie | e6aad9b | 2012-04-22 08:09:05 +0100 | [diff] [blame] | 907 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 908 | if (rscreen == NULL) { |
| 909 | return NULL; |
| 910 | } |
| 911 | |
Marek Olšák | 2ce783d | 2011-08-02 20:25:13 +0200 | [diff] [blame] | 912 | rscreen->ws = ws; |
Marek Olšák | 3603d15 | 2011-09-11 14:53:07 +0200 | [diff] [blame] | 913 | ws->query_info(ws, &rscreen->info); |
| 914 | |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 915 | rscreen->family = radeon_family_from_device(rscreen->info.pci_id); |
| 916 | if (rscreen->family == CHIP_UNKNOWN) { |
| 917 | fprintf(stderr, "r600: Unknown chipset 0x%04X\n", rscreen->info.pci_id); |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 918 | FREE(rscreen); |
| 919 | return NULL; |
| 920 | } |
| 921 | |
| 922 | /* setup class */ |
Alex Deucher | b4082f4 | 2012-03-20 19:43:59 -0400 | [diff] [blame] | 923 | if (rscreen->family >= CHIP_CAYMAN) { |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 924 | rscreen->chip_class = CAYMAN; |
| 925 | } else if (rscreen->family >= CHIP_CEDAR) { |
| 926 | rscreen->chip_class = EVERGREEN; |
| 927 | } else if (rscreen->family >= CHIP_RV770) { |
| 928 | rscreen->chip_class = R700; |
| 929 | } else { |
| 930 | rscreen->chip_class = R600; |
| 931 | } |
| 932 | |
Marek Olšák | 6e7756d | 2012-06-17 17:54:38 +0200 | [diff] [blame] | 933 | /* Figure out streamout kernel support. */ |
| 934 | switch (rscreen->chip_class) { |
| 935 | case R600: |
| 936 | case EVERGREEN: |
Jerome Glisse | 1ffac44 | 2012-07-24 15:05:43 -0400 | [diff] [blame] | 937 | rscreen->has_streamout = rscreen->info.drm_minor >= 14; |
Marek Olšák | 6e7756d | 2012-06-17 17:54:38 +0200 | [diff] [blame] | 938 | break; |
| 939 | case R700: |
| 940 | rscreen->has_streamout = rscreen->info.drm_minor >= 17; |
| 941 | break; |
| 942 | /* TODO: Cayman */ |
| 943 | default: |
| 944 | rscreen->has_streamout = debug_get_bool_option("R600_STREAMOUT", FALSE); |
Marek Olšák | 393d741 | 2012-03-27 21:00:49 +0200 | [diff] [blame] | 945 | } |
| 946 | |
Marek Olšák | 3603d15 | 2011-09-11 14:53:07 +0200 | [diff] [blame] | 947 | if (r600_init_tiling(rscreen)) { |
Marek Olšák | 3603d15 | 2011-09-11 14:53:07 +0200 | [diff] [blame] | 948 | FREE(rscreen); |
| 949 | return NULL; |
| 950 | } |
| 951 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 952 | rscreen->screen.destroy = r600_destroy_screen; |
| 953 | rscreen->screen.get_name = r600_get_name; |
| 954 | rscreen->screen.get_vendor = r600_get_vendor; |
| 955 | rscreen->screen.get_param = r600_get_param; |
| 956 | rscreen->screen.get_shader_param = r600_get_shader_param; |
| 957 | rscreen->screen.get_paramf = r600_get_paramf; |
Christian König | f265a19 | 2011-07-07 22:51:45 +0200 | [diff] [blame] | 958 | rscreen->screen.get_video_param = r600_get_video_param; |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 959 | rscreen->screen.get_compute_param = r600_get_compute_param; |
Marek Olšák | 44f14eb | 2012-07-05 20:06:41 +0200 | [diff] [blame] | 960 | rscreen->screen.get_timestamp = r600_get_timestamp; |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 961 | |
Marek Olšák | 518557d | 2011-09-17 13:56:09 +0200 | [diff] [blame] | 962 | if (rscreen->chip_class >= EVERGREEN) { |
Henri Verbeet | 18cdb9c | 2011-07-05 01:58:46 +0200 | [diff] [blame] | 963 | rscreen->screen.is_format_supported = evergreen_is_format_supported; |
| 964 | } else { |
| 965 | rscreen->screen.is_format_supported = r600_is_format_supported; |
| 966 | } |
Christian König | 7eca769 | 2011-07-08 11:20:39 +0200 | [diff] [blame] | 967 | rscreen->screen.is_video_format_supported = vl_video_buffer_is_format_supported; |
Dave Airlie | dbcd652 | 2010-09-30 09:07:07 +1000 | [diff] [blame] | 968 | rscreen->screen.context_create = r600_create_context; |
Fredrik Höglund | 948e1eb | 2011-03-29 19:43:59 +0200 | [diff] [blame] | 969 | rscreen->screen.fence_reference = r600_fence_reference; |
| 970 | rscreen->screen.fence_signalled = r600_fence_signalled; |
| 971 | rscreen->screen.fence_finish = r600_fence_finish; |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 972 | r600_init_screen_resource_functions(&rscreen->screen); |
| 973 | |
Dave Airlie | 8e04379 | 2011-02-11 13:42:52 +1000 | [diff] [blame] | 974 | util_format_s3tc_init(); |
Dave Airlie | 7b3fa03 | 2010-10-08 11:56:43 +1000 | [diff] [blame] | 975 | |
Michel Dänzer | 7dd2d29 | 2011-12-30 10:45:31 +0100 | [diff] [blame] | 976 | rscreen->fences.bo = NULL; |
| 977 | rscreen->fences.data = NULL; |
| 978 | rscreen->fences.next_index = 0; |
| 979 | LIST_INITHEAD(&rscreen->fences.pool); |
| 980 | LIST_INITHEAD(&rscreen->fences.blocks); |
| 981 | pipe_mutex_init(rscreen->fences.mutex); |
| 982 | |
Tom Stellard | c0f7fe7 | 2012-07-11 16:18:22 +0000 | [diff] [blame] | 983 | rscreen->global_pool = compute_memory_pool_new(rscreen); |
Adam Rak | 6a829a1 | 2011-11-30 22:20:41 +0100 | [diff] [blame] | 984 | |
Jerome Glisse | 1235bec | 2010-09-29 15:05:19 -0400 | [diff] [blame] | 985 | return &rscreen->screen; |
| 986 | } |