diff options
Diffstat (limited to 'src/mesa/drivers/dri/nouveau')
27 files changed, 889 insertions, 492 deletions
diff --git a/src/mesa/drivers/dri/nouveau/Makefile b/src/mesa/drivers/dri/nouveau/Makefile index 7be19b26fda..3b506a91ffa 100644 --- a/src/mesa/drivers/dri/nouveau/Makefile +++ b/src/mesa/drivers/dri/nouveau/Makefile @@ -19,6 +19,8 @@ DRIVER_SOURCES = \ nouveau_bo_state.c \ nouveau_texture.c \ nouveau_surface.c \ + nouveau_scratch.c \ + nouveau_array.c \ nv04_context.c \ nv04_render.c \ nv04_state_fb.c \ diff --git a/src/mesa/drivers/dri/nouveau/nouveau_array.c b/src/mesa/drivers/dri/nouveau/nouveau_array.c new file mode 100644 index 00000000000..17e6d163a02 --- /dev/null +++ b/src/mesa/drivers/dri/nouveau/nouveau_array.c @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2009-2010 Francisco Jerez. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "main/bufferobj.h" +#include "nouveau_driver.h" +#include "nouveau_array.h" +#include "nouveau_bufferobj.h" + +static void +get_array_extract(struct nouveau_array *a, extract_u_t *extract_u, + extract_f_t *extract_f) +{ +#define EXTRACT(in_t, out_t, k) \ + ({ \ + auto out_t f(struct nouveau_array *, int, int); \ + out_t f(struct nouveau_array *a, int i, int j) { \ + in_t x = ((in_t *)(a->buf + i * a->stride))[j]; \ + \ + return (out_t)x / (k); \ + }; \ + f; \ + }); + + switch (a->type) { + case GL_BYTE: + *extract_u = EXTRACT(char, unsigned, 1); + *extract_f = EXTRACT(char, float, SCHAR_MAX); + break; + case GL_UNSIGNED_BYTE: + *extract_u = EXTRACT(unsigned char, unsigned, 1); + *extract_f = EXTRACT(unsigned char, float, UCHAR_MAX); + break; + case GL_SHORT: + *extract_u = EXTRACT(short, unsigned, 1); + *extract_f = EXTRACT(short, float, SHRT_MAX); + break; + case GL_UNSIGNED_SHORT: + *extract_u = EXTRACT(unsigned short, unsigned, 1); + *extract_f = EXTRACT(unsigned short, float, USHRT_MAX); + break; + case GL_INT: + *extract_u = EXTRACT(int, unsigned, 1); + *extract_f = EXTRACT(int, float, INT_MAX); + break; + case GL_UNSIGNED_INT: + *extract_u = EXTRACT(unsigned int, unsigned, 1); + *extract_f = EXTRACT(unsigned int, float, UINT_MAX); + break; + case GL_FLOAT: + *extract_u = EXTRACT(float, unsigned, 1.0 / UINT_MAX); + *extract_f = EXTRACT(float, float, 1); + break; + default: + assert(0); + } +} + +void +nouveau_init_array(struct nouveau_array *a, int attr, int stride, + int fields, int type, struct gl_buffer_object *obj, + const void *ptr, GLboolean map) +{ + a->attr = attr; + a->stride = stride; + a->fields = fields; + a->type = type; + a->buf = NULL; + + if (obj) { + if (nouveau_bufferobj_hw(obj)) { + struct nouveau_bufferobj *nbo = + to_nouveau_bufferobj(obj); + + nouveau_bo_ref(nbo->bo, &a->bo); + a->offset = (intptr_t)ptr; + + if (map) { + nouveau_bo_map(a->bo, NOUVEAU_BO_RD); + a->buf = a->bo->map + a->offset; + } + + } else { + nouveau_bo_ref(NULL, &a->bo); + a->offset = 0; + + if (map) + a->buf = ADD_POINTERS( + nouveau_bufferobj_sys(obj), ptr); + } + } + + if (a->buf) + get_array_extract(a, &a->extract_u, &a->extract_f); +} + +void +nouveau_deinit_array(struct nouveau_array *a) +{ + if (a->bo) { + if (a->bo->map) + nouveau_bo_unmap(a->bo); + } + + a->buf = NULL; + a->fields = 0; +} + +void +nouveau_cleanup_array(struct nouveau_array *a) +{ + nouveau_deinit_array(a); + nouveau_bo_ref(NULL, &a->bo); +} diff --git a/src/mesa/drivers/dri/nouveau/nouveau_array.h b/src/mesa/drivers/dri/nouveau/nouveau_array.h new file mode 100644 index 00000000000..ad3d69b33d9 --- /dev/null +++ b/src/mesa/drivers/dri/nouveau/nouveau_array.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2009-2010 Francisco Jerez. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __NOUVEAU_ARRAY_H__ +#define __NOUVEAU_ARRAY_H__ + +struct nouveau_array; + +typedef unsigned (*extract_u_t)(struct nouveau_array *, int, int); +typedef float (*extract_f_t)(struct nouveau_array *, int, int); + +struct nouveau_array { + int attr; + int stride, fields, type; + + struct nouveau_bo *bo; + unsigned offset; + const void *buf; + + extract_u_t extract_u; + extract_f_t extract_f; +}; + +void +nouveau_init_array(struct nouveau_array *a, int attr, int stride, + int fields, int type, struct gl_buffer_object *obj, + const void *ptr, GLboolean map); + +void +nouveau_deinit_array(struct nouveau_array *a); + +void +nouveau_cleanup_array(struct nouveau_array *a); + +#endif diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bo_state.c b/src/mesa/drivers/dri/nouveau/nouveau_bo_state.c index f31772fe1d1..7eef8c1ee81 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_bo_state.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_bo_state.c @@ -126,13 +126,13 @@ void nouveau_bo_context_reset(struct nouveau_bo_context *bctx) { struct nouveau_bo_state *s = &to_nouveau_context(bctx->ctx)->bo; - int i; - - for (i = 0; i < bctx->count; i++) - nouveau_bo_ref(NULL, &bctx->marker[i].bo); + int i, n = bctx->count; - s->count -= bctx->count; + s->count -= n; bctx->count = 0; + + for (i = 0; i < n; i++) + nouveau_bo_ref(NULL, &bctx->marker[i].bo); } GLboolean diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bo_state.h b/src/mesa/drivers/dri/nouveau/nouveau_bo_state.h index 6119a8336e3..388a16a56ea 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_bo_state.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_bo_state.h @@ -29,7 +29,7 @@ enum { NOUVEAU_BO_CONTEXT_FRAMEBUFFER = 0, - NOUVEAU_BO_CONTEXT_LMA_DEPTH, + NOUVEAU_BO_CONTEXT_HIERZ, NOUVEAU_BO_CONTEXT_SURFACE, NOUVEAU_BO_CONTEXT_TEXTURE0, NOUVEAU_BO_CONTEXT_TEXTURE1, diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c index ad6e5bd805a..e60b91f64be 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c @@ -30,6 +30,23 @@ #include "main/bufferobj.h" +static inline char * +get_bufferobj_map(struct gl_buffer_object *obj, unsigned flags) +{ + struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj); + void *map = NULL; + + if (nbo->sys) { + map = nbo->sys; + } else if (nbo->bo) { + nouveau_bo_map(nbo->bo, flags); + map = nbo->bo->map; + nouveau_bo_unmap(nbo->bo); + } + + return map; +} + static struct gl_buffer_object * nouveau_bufferobj_new(struct gl_context *ctx, GLuint buffer, GLenum target) { @@ -50,6 +67,7 @@ nouveau_bufferobj_del(struct gl_context *ctx, struct gl_buffer_object *obj) struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj); nouveau_bo_ref(NULL, &nbo->bo); + FREE(nbo->sys); FREE(nbo); } @@ -64,18 +82,27 @@ nouveau_bufferobj_data(struct gl_context *ctx, GLenum target, GLsizeiptrARB size obj->Size = size; obj->Usage = usage; + /* Free previous storage */ nouveau_bo_ref(NULL, &nbo->bo); - ret = nouveau_bo_new(context_dev(ctx), - NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0, - size, &nbo->bo); - assert(!ret); - - if (data) { - nouveau_bo_map(nbo->bo, NOUVEAU_BO_WR); - memcpy(nbo->bo->map, data, size); - nouveau_bo_unmap(nbo->bo); + FREE(nbo->sys); + + if (target == GL_ELEMENT_ARRAY_BUFFER_ARB || + (size < 512 && usage == GL_DYNAMIC_DRAW_ARB) || + context_chipset(ctx) < 0x10) { + /* Heuristic: keep it in system ram */ + nbo->sys = MALLOC(size); + + } else { + /* Get a hardware BO */ + ret = nouveau_bo_new(context_dev(ctx), + NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0, + size, &nbo->bo); + assert(!ret); } + if (data) + memcpy(get_bufferobj_map(obj, NOUVEAU_BO_WR), data, size); + return GL_TRUE; } @@ -84,11 +111,7 @@ nouveau_bufferobj_subdata(struct gl_context *ctx, GLenum target, GLintptrARB off GLsizeiptrARB size, const GLvoid *data, struct gl_buffer_object *obj) { - struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj); - - nouveau_bo_map(nbo->bo, NOUVEAU_BO_WR); - memcpy(nbo->bo->map + offset, data, size); - nouveau_bo_unmap(nbo->bo); + memcpy(get_bufferobj_map(obj, NOUVEAU_BO_WR) + offset, data, size); } static void @@ -96,44 +119,48 @@ nouveau_bufferobj_get_subdata(struct gl_context *ctx, GLenum target, GLintptrARB GLsizeiptrARB size, GLvoid *data, struct gl_buffer_object *obj) { - struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj); - - nouveau_bo_map(nbo->bo, NOUVEAU_BO_RD); - memcpy(data, nbo->bo->map + offset, size); - nouveau_bo_unmap(nbo->bo); + memcpy(data, get_bufferobj_map(obj, NOUVEAU_BO_RD) + offset, size); } static void * nouveau_bufferobj_map(struct gl_context *ctx, GLenum target, GLenum access, struct gl_buffer_object *obj) { - return ctx->Driver.MapBufferRange(ctx, target, 0, obj->Size, access, + unsigned flags = 0; + + if (access == GL_READ_ONLY_ARB || + access == GL_READ_WRITE_ARB) + flags |= GL_MAP_READ_BIT; + if (access == GL_WRITE_ONLY_ARB || + access == GL_READ_WRITE_ARB) + flags |= GL_MAP_WRITE_BIT; + + return ctx->Driver.MapBufferRange(ctx, target, 0, obj->Size, flags, obj); } static void * nouveau_bufferobj_map_range(struct gl_context *ctx, GLenum target, GLintptr offset, - GLsizeiptr length, GLenum access, + GLsizeiptr length, GLbitfield access, struct gl_buffer_object *obj) { - struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj); - uint32_t flags = 0; + unsigned flags = 0; + char *map; assert(!obj->Pointer); - if (!nbo->bo) - return NULL; - - if (access == GL_READ_ONLY_ARB || - access == GL_READ_WRITE_ARB) + if (access & GL_MAP_READ_BIT) flags |= NOUVEAU_BO_RD; - if (access == GL_WRITE_ONLY_ARB || - access == GL_READ_WRITE_ARB) + if (access & GL_MAP_WRITE_BIT) flags |= NOUVEAU_BO_WR; + if (access & GL_MAP_UNSYNCHRONIZED_BIT) + flags |= NOUVEAU_BO_NOSYNC; - nouveau_bo_map_range(nbo->bo, offset, length, flags); + map = get_bufferobj_map(obj, flags); + if (!map) + return NULL; - obj->Pointer = nbo->bo->map; + obj->Pointer = map + offset; obj->Offset = offset; obj->Length = length; obj->AccessFlags = access; @@ -144,12 +171,8 @@ nouveau_bufferobj_map_range(struct gl_context *ctx, GLenum target, GLintptr offs static GLboolean nouveau_bufferobj_unmap(struct gl_context *ctx, GLenum target, struct gl_buffer_object *obj) { - struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj); - assert(obj->Pointer); - nouveau_bo_unmap(nbo->bo); - obj->Pointer = NULL; obj->Offset = 0; obj->Length = 0; diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h index acfc4cb9a90..01ef0bad0fd 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.h @@ -30,9 +30,16 @@ struct nouveau_bufferobj { struct gl_buffer_object base; struct nouveau_bo *bo; + void *sys; }; #define to_nouveau_bufferobj(x) ((struct nouveau_bufferobj *)(x)) +#define nouveau_bufferobj_hw(x) \ + (_mesa_is_bufferobj(x) ? to_nouveau_bufferobj(x)->bo : NULL) + +#define nouveau_bufferobj_sys(x) \ + (_mesa_is_bufferobj(x) ? to_nouveau_bufferobj(x)->sys : NULL) + void nouveau_bufferobj_functions_init(struct dd_function_table *functions); diff --git a/src/mesa/drivers/dri/nouveau/nouveau_class.h b/src/mesa/drivers/dri/nouveau/nouveau_class.h index d41d431f796..687b847797b 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_class.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_class.h @@ -4954,6 +4954,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NV25TCL_DMA_IN_MEMORY5 0x000001a0 #define NV25TCL_DMA_IN_MEMORY8 0x000001ac #define NV25TCL_DMA_IN_MEMORY9 0x000001b0 +#define NV25TCL_HIERZ_PITCH 0x0000022c +#define NV25TCL_HIERZ_OFFSET 0x00000230 #endif /* NOUVEAU_REG_H */ diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c index 0ace139b886..f80aaedb257 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_context.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c @@ -119,6 +119,7 @@ nouveau_context_init(struct gl_context *ctx, struct nouveau_screen *screen, nouveau_state_init(ctx); nouveau_bo_state_init(ctx); + nouveau_scratch_init(ctx); _mesa_meta_init(ctx); _swrast_CreateContext(ctx); _vbo_CreateContext(ctx); @@ -163,6 +164,7 @@ nouveau_context_deinit(struct gl_context *ctx) if (nctx->hw.chan) nouveau_channel_free(&nctx->hw.chan); + nouveau_scratch_destroy(ctx); nouveau_bo_state_destroy(ctx); _mesa_free_context_data(ctx); } @@ -325,10 +327,12 @@ nouveau_fallback(struct gl_context *ctx, enum nouveau_fallback mode) nctx->fallback = MAX2(HWTNL, mode); - if (mode < SWRAST) + if (mode < SWRAST) { nouveau_state_emit(ctx); - else + nouveau_bo_state_emit(ctx); + } else { FIRE_RING(context_chan(ctx)); + } } static void @@ -365,5 +369,6 @@ nouveau_validate_framebuffer(struct gl_context *ctx) validate_framebuffer(dri_ctx, dri_read, &dri_ctx->dri2.read_stamp); - nouveau_state_emit(ctx); + if (ctx->NewState & _NEW_BUFFERS) + _mesa_update_state(ctx); } diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.h b/src/mesa/drivers/dri/nouveau/nouveau_context.h index 23a87256728..7ebc676379e 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_context.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_context.h @@ -30,6 +30,7 @@ #include "nouveau_screen.h" #include "nouveau_state.h" #include "nouveau_bo_state.h" +#include "nouveau_scratch.h" #include "nouveau_render.h" #include "main/bitset.h" @@ -67,6 +68,7 @@ struct nouveau_context { struct nouveau_hw_state hw; struct nouveau_bo_state bo; struct nouveau_render_state render; + struct nouveau_scratch_state scratch; struct { GLboolean clear_blocked; diff --git a/src/mesa/drivers/dri/nouveau/nouveau_render.h b/src/mesa/drivers/dri/nouveau/nouveau_render.h index 81c6119fcc6..0539c377585 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_render.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_render.h @@ -28,46 +28,22 @@ #define __NOUVEAU_RENDER_H__ #include "vbo/vbo_context.h" - -struct nouveau_array_state; +#include "nouveau_array.h" typedef void (*dispatch_t)(struct gl_context *, unsigned int, int, unsigned int); -typedef unsigned (*extract_u_t)(struct nouveau_array_state *, int, int); -typedef float (*extract_f_t)(struct nouveau_array_state *, int, int); +typedef void (*emit_t)(struct gl_context *, struct nouveau_array *, const void *); struct nouveau_attr_info { int vbo_index; int imm_method; int imm_fields; - void (*emit)(struct gl_context *, struct nouveau_array_state *, const void *); -}; - -struct nouveau_array_state { - int attr; - int stride, fields, type; - - struct nouveau_bo *bo; - unsigned offset; - const void *buf; - - extract_u_t extract_u; - extract_f_t extract_f; -}; - -#define RENDER_SCRATCH_COUNT 2 -#define RENDER_SCRATCH_SIZE 2*1024*1024 - -struct nouveau_scratch_state { - struct nouveau_bo *bo[RENDER_SCRATCH_COUNT]; - - int index; - int offset; - void *buf; + emit_t emit; }; struct nouveau_swtnl_state { struct nouveau_bo *vbo; + unsigned offset; void *buf; unsigned vertex_count; GLenum primitive; @@ -79,8 +55,8 @@ struct nouveau_render_state { IMM } mode; - struct nouveau_array_state ib; - struct nouveau_array_state attrs[VERT_ATTRIB_MAX]; + struct nouveau_array ib; + struct nouveau_array attrs[VERT_ATTRIB_MAX]; /* Maps a HW VBO index or IMM emission order to an index in * the attrs array above (or -1 if unused). */ @@ -89,10 +65,16 @@ struct nouveau_render_state { int attr_count; int vertex_size; - struct nouveau_scratch_state scratch; struct nouveau_swtnl_state swtnl; }; #define to_render_state(ctx) (&to_nouveau_context(ctx)->render) +#define FOR_EACH_ATTR(render, i, attr) \ + for (i = 0; attr = (render)->map[i], i < NUM_VERTEX_ATTRS; i++) + +#define FOR_EACH_BOUND_ATTR(render, i, attr) \ + for (i = 0; attr = (render)->map[i], i < render->attr_count; i++) \ + if (attr >= 0) + #endif diff --git a/src/mesa/drivers/dri/nouveau/nouveau_render_t.c b/src/mesa/drivers/dri/nouveau/nouveau_render_t.c index dd38c14aa7c..e0cf727d11d 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_render_t.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_render_t.c @@ -100,8 +100,8 @@ /* * Select an appropriate dispatch function for the given index buffer. */ -static void -get_array_dispatch(struct nouveau_array_state *a, dispatch_t *dispatch) +static dispatch_t +get_array_dispatch(struct nouveau_array *a) { if (!a->fields) { auto void f(struct gl_context *, unsigned int, int, unsigned int); @@ -114,7 +114,7 @@ get_array_dispatch(struct nouveau_array_state *a, dispatch_t *dispatch) EMIT_VBO(L, ctx, start, delta, n); }; - *dispatch = f; + return f; } else if (a->type == GL_UNSIGNED_INT) { auto void f(struct gl_context *, unsigned int, int, unsigned int); @@ -127,7 +127,7 @@ get_array_dispatch(struct nouveau_array_state *a, dispatch_t *dispatch) EMIT_VBO(I32, ctx, start, delta, n); }; - *dispatch = f; + return f; } else { auto void f(struct gl_context *, unsigned int, int, unsigned int); @@ -141,115 +141,11 @@ get_array_dispatch(struct nouveau_array_state *a, dispatch_t *dispatch) EMIT_VBO(I16, ctx, start, delta, n & ~1); }; - *dispatch = f; + return f; } } /* - * Select appropriate element extraction functions for the given - * array. - */ -static void -get_array_extract(struct nouveau_array_state *a, - extract_u_t *extract_u, extract_f_t *extract_f) -{ -#define EXTRACT(in_t, out_t, k) \ - ({ \ - auto out_t f(struct nouveau_array_state *, int, int); \ - out_t f(struct nouveau_array_state *a, int i, int j) { \ - in_t x = ((in_t *)(a->buf + i * a->stride))[j]; \ - \ - return (out_t)x / (k); \ - }; \ - f; \ - }); - - switch (a->type) { - case GL_BYTE: - *extract_u = EXTRACT(char, unsigned, 1); - *extract_f = EXTRACT(char, float, SCHAR_MAX); - break; - case GL_UNSIGNED_BYTE: - *extract_u = EXTRACT(unsigned char, unsigned, 1); - *extract_f = EXTRACT(unsigned char, float, UCHAR_MAX); - break; - case GL_SHORT: - *extract_u = EXTRACT(short, unsigned, 1); - *extract_f = EXTRACT(short, float, SHRT_MAX); - break; - case GL_UNSIGNED_SHORT: - *extract_u = EXTRACT(unsigned short, unsigned, 1); - *extract_f = EXTRACT(unsigned short, float, USHRT_MAX); - break; - case GL_INT: - *extract_u = EXTRACT(int, unsigned, 1); - *extract_f = EXTRACT(int, float, INT_MAX); - break; - case GL_UNSIGNED_INT: - *extract_u = EXTRACT(unsigned int, unsigned, 1); - *extract_f = EXTRACT(unsigned int, float, UINT_MAX); - break; - case GL_FLOAT: - *extract_u = EXTRACT(float, unsigned, 1.0 / UINT_MAX); - *extract_f = EXTRACT(float, float, 1); - break; - - default: - assert(0); - } -} - -/* - * Returns a pointer to a chunk of <size> bytes long GART memory. <bo> - * will be updated with the buffer object the memory is located in. - * - * If <offset> is provided, it will be updated with the offset within - * <bo> of the allocated memory. Otherwise the returned memory will - * always be located right at the beginning of <bo>. - */ -static inline void * -get_scratch_vbo(struct gl_context *ctx, unsigned size, struct nouveau_bo **bo, - unsigned *offset) -{ - struct nouveau_scratch_state *scratch = &to_render_state(ctx)->scratch; - void *buf; - - if (scratch->buf && offset && - size <= RENDER_SCRATCH_SIZE - scratch->offset) { - nouveau_bo_ref(scratch->bo[scratch->index], bo); - - buf = scratch->buf + scratch->offset; - *offset = scratch->offset; - scratch->offset += size; - - } else if (size <= RENDER_SCRATCH_SIZE) { - scratch->index = (scratch->index + 1) % RENDER_SCRATCH_COUNT; - nouveau_bo_ref(scratch->bo[scratch->index], bo); - - nouveau_bo_map(*bo, NOUVEAU_BO_WR); - buf = scratch->buf = (*bo)->map; - nouveau_bo_unmap(*bo); - - if (offset) - *offset = 0; - scratch->offset = size; - - } else { - nouveau_bo_new(context_dev(ctx), - NOUVEAU_BO_MAP | NOUVEAU_BO_GART, 0, size, bo); - - nouveau_bo_map(*bo, NOUVEAU_BO_WR); - buf = (*bo)->map; - nouveau_bo_unmap(*bo); - - if (offset) - *offset = 0; - } - - return buf; -} - -/* * Returns how many vertices you can draw using <n> pushbuf dwords. */ static inline unsigned @@ -277,6 +173,11 @@ get_max_vertices(struct gl_context *ctx, const struct _mesa_index_buffer *ib, case GL_UNSIGNED_BYTE: max_out = MAX_OUT_I16; break; + + default: + assert(0); + max_out = 0; + break; } } else { max_out = MAX_OUT_L; @@ -286,76 +187,26 @@ get_max_vertices(struct gl_context *ctx, const struct _mesa_index_buffer *ib, } } -#include "nouveau_vbo_t.c" -#include "nouveau_swtnl_t.c" - static void -TAG(emit_material)(struct gl_context *ctx, struct nouveau_array_state *a, +TAG(emit_material)(struct gl_context *ctx, struct nouveau_array *a, const void *v) { - const int attr = a->attr - VERT_ATTRIB_GENERIC0; - const int state = ((int []) { - NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT, - NOUVEAU_STATE_MATERIAL_BACK_AMBIENT, - NOUVEAU_STATE_MATERIAL_FRONT_DIFFUSE, - NOUVEAU_STATE_MATERIAL_BACK_DIFFUSE, - NOUVEAU_STATE_MATERIAL_FRONT_SPECULAR, - NOUVEAU_STATE_MATERIAL_BACK_SPECULAR, - NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT, - NOUVEAU_STATE_MATERIAL_BACK_AMBIENT, - NOUVEAU_STATE_MATERIAL_FRONT_SHININESS, - NOUVEAU_STATE_MATERIAL_BACK_SHININESS - }) [attr]; + int attr = a->attr - VERT_ATTRIB_GENERIC0; + int state = ((int []) { + NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT, + NOUVEAU_STATE_MATERIAL_BACK_AMBIENT, + NOUVEAU_STATE_MATERIAL_FRONT_DIFFUSE, + NOUVEAU_STATE_MATERIAL_BACK_DIFFUSE, + NOUVEAU_STATE_MATERIAL_FRONT_SPECULAR, + NOUVEAU_STATE_MATERIAL_BACK_SPECULAR, + NOUVEAU_STATE_MATERIAL_FRONT_AMBIENT, + NOUVEAU_STATE_MATERIAL_BACK_AMBIENT, + NOUVEAU_STATE_MATERIAL_FRONT_SHININESS, + NOUVEAU_STATE_MATERIAL_BACK_SHININESS + }) [attr]; COPY_4V(ctx->Light.Material.Attrib[attr], (float *)v); _mesa_update_material(ctx, 1 << attr); context_drv(ctx)->emit[state](ctx, state); } - -static void -TAG(render_prims)(struct gl_context *ctx, const struct gl_client_array **arrays, - const struct _mesa_prim *prims, GLuint nr_prims, - const struct _mesa_index_buffer *ib, - GLboolean index_bounds_valid, - GLuint min_index, GLuint max_index) -{ - struct nouveau_context *nctx = to_nouveau_context(ctx); - - nouveau_validate_framebuffer(ctx); - - if (nctx->fallback == HWTNL) - TAG(vbo_render_prims)(ctx, arrays, prims, nr_prims, ib, - index_bounds_valid, min_index, max_index); - - if (nctx->fallback == SWTNL) - _tnl_vbo_draw_prims(ctx, arrays, prims, nr_prims, ib, - index_bounds_valid, min_index, max_index); -} - -void -TAG(render_init)(struct gl_context *ctx) -{ - struct nouveau_render_state *render = to_render_state(ctx); - struct nouveau_scratch_state *scratch = &render->scratch; - int ret, i; - - for (i = 0; i < RENDER_SCRATCH_COUNT; i++) { - ret = nouveau_bo_new(context_dev(ctx), - NOUVEAU_BO_MAP | NOUVEAU_BO_GART, - 0, RENDER_SCRATCH_SIZE, &scratch->bo[i]); - assert(!ret); - } - - for (i = 0; i < VERT_ATTRIB_MAX; i++) - render->map[i] = -1; - - TAG(swtnl_init)(ctx); - vbo_set_draw_func(ctx, TAG(render_prims)); -} - -void -TAG(render_destroy)(struct gl_context *ctx) -{ - TAG(swtnl_destroy)(ctx); -} diff --git a/src/mesa/drivers/dri/nouveau/nouveau_scratch.c b/src/mesa/drivers/dri/nouveau/nouveau_scratch.c new file mode 100644 index 00000000000..ddda67b2f14 --- /dev/null +++ b/src/mesa/drivers/dri/nouveau/nouveau_scratch.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2009-2010 Francisco Jerez. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "nouveau_driver.h" +#include "nouveau_context.h" + +/* + * Returns a pointer to a chunk of 'size' bytes long GART memory. 'bo' + * and 'offset' will point to the returned memory. + */ +void * +nouveau_get_scratch(struct gl_context *ctx, unsigned size, + struct nouveau_bo **bo, unsigned *offset) +{ + struct nouveau_scratch_state *scratch = + &to_nouveau_context(ctx)->scratch; + void *buf; + + if (scratch->buf && size <= NOUVEAU_SCRATCH_SIZE - scratch->offset) { + nouveau_bo_ref(scratch->bo[scratch->index], bo); + + buf = scratch->buf + scratch->offset; + *offset = scratch->offset; + scratch->offset += size; + + } else if (size <= NOUVEAU_SCRATCH_SIZE) { + scratch->index = (scratch->index + 1) % NOUVEAU_SCRATCH_COUNT; + nouveau_bo_ref(scratch->bo[scratch->index], bo); + + nouveau_bo_map(*bo, NOUVEAU_BO_WR); + buf = scratch->buf = (*bo)->map; + nouveau_bo_unmap(*bo); + + *offset = 0; + scratch->offset = size; + + } else { + nouveau_bo_new(context_dev(ctx), + NOUVEAU_BO_MAP | NOUVEAU_BO_GART, 0, size, bo); + + nouveau_bo_map(*bo, NOUVEAU_BO_WR); + buf = (*bo)->map; + nouveau_bo_unmap(*bo); + + *offset = 0; + } + + return buf; +} + +void +nouveau_scratch_init(struct gl_context *ctx) +{ + struct nouveau_scratch_state *scratch = + &to_nouveau_context(ctx)->scratch; + int ret, i; + + for (i = 0; i < NOUVEAU_SCRATCH_COUNT; i++) { + ret = nouveau_bo_new(context_dev(ctx), + NOUVEAU_BO_MAP | NOUVEAU_BO_GART, + 0, NOUVEAU_SCRATCH_SIZE, &scratch->bo[i]); + assert(!ret); + } +} + +void +nouveau_scratch_destroy(struct gl_context *ctx) +{ + struct nouveau_scratch_state *scratch = + &to_nouveau_context(ctx)->scratch; + int i; + + for (i = 0; i < NOUVEAU_SCRATCH_COUNT; i++) + nouveau_bo_ref(NULL, &scratch->bo[i]); +} diff --git a/src/mesa/drivers/dri/nouveau/nouveau_scratch.h b/src/mesa/drivers/dri/nouveau/nouveau_scratch.h new file mode 100644 index 00000000000..b60b33dd1ac --- /dev/null +++ b/src/mesa/drivers/dri/nouveau/nouveau_scratch.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2009-2010 Francisco Jerez. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __NOUVEAU_SCRATCH_H__ +#define __NOUVEAU_SCRATCH_H__ + +#define NOUVEAU_SCRATCH_COUNT 2 +#define NOUVEAU_SCRATCH_SIZE 3*1024*1024 + +struct nouveau_scratch_state { + struct nouveau_bo *bo[NOUVEAU_SCRATCH_COUNT]; + + int index; + int offset; + void *buf; +}; + +void * +nouveau_get_scratch(struct gl_context *ctx, unsigned size, + struct nouveau_bo **bo, unsigned *offset); + +void +nouveau_scratch_init(struct gl_context *ctx); + +void +nouveau_scratch_destroy(struct gl_context *ctx); + +#endif diff --git a/src/mesa/drivers/dri/nouveau/nouveau_state.c b/src/mesa/drivers/dri/nouveau/nouveau_state.c index 7b7ddd2f54d..1579d29efc2 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_state.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_state.c @@ -113,6 +113,12 @@ nouveau_depth_range(struct gl_context *ctx, GLclampd nearval, GLclampd farval) } static void +nouveau_read_buffer(struct gl_context *ctx, GLenum buffer) +{ + nouveau_validate_framebuffer(ctx); +} + +static void nouveau_draw_buffers(struct gl_context *ctx, GLsizei n, const GLenum *buffers) { nouveau_validate_framebuffer(ctx); @@ -512,6 +518,7 @@ nouveau_state_init(struct gl_context *ctx) ctx->Driver.DepthFunc = nouveau_depth_func; ctx->Driver.DepthMask = nouveau_depth_mask; ctx->Driver.DepthRange = nouveau_depth_range; + ctx->Driver.ReadBuffer = nouveau_read_buffer; ctx->Driver.DrawBuffers = nouveau_draw_buffers; ctx->Driver.Enable = nouveau_enable; ctx->Driver.Fogfv = nouveau_fog; diff --git a/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c b/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c index b3588e8fd39..f084f89d29e 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_swtnl_t.c @@ -28,6 +28,8 @@ #include "tnl/t_pipeline.h" #include "tnl/t_vertex.h" +#define SWTNL_VBO_SIZE 65536 + static enum tnl_attr_format swtnl_get_format(int type, int fields) { switch (type) { @@ -105,7 +107,7 @@ swtnl_choose_attrs(struct gl_context *ctx) TNLcontext *tnl = TNL_CONTEXT(ctx); struct tnl_clipspace *vtx = &tnl->clipspace; static struct tnl_attr_map map[NUM_VERTEX_ATTRS]; - int fields, i, n = 0; + int fields, attr, i, n = 0; render->mode = VBO; render->attr_count = NUM_VERTEX_ATTRS; @@ -116,7 +118,7 @@ swtnl_choose_attrs(struct gl_context *ctx) for (i = 0; i < VERT_ATTRIB_MAX; i++) { struct nouveau_attr_info *ha = &TAG(vertex_attrs)[i]; struct swtnl_attr_info *sa = &swtnl_attrs[i]; - struct nouveau_array_state *a = &render->attrs[i]; + struct nouveau_array *a = &render->attrs[i]; if (!sa->fields) continue; /* Unsupported attribute. */ @@ -141,13 +143,8 @@ swtnl_choose_attrs(struct gl_context *ctx) _tnl_install_attrs(ctx, map, n, NULL, 0); - for (i = 0; i < vtx->attr_count; i++) { - struct tnl_clipspace_attr *ta = &vtx->attr[i]; - struct nouveau_array_state *a = &render->attrs[ta->attrib]; - - a->stride = vtx->vertex_size; - a->offset = ta->vertoffset; - } + FOR_EACH_BOUND_ATTR(render, i, attr) + render->attrs[attr].stride = vtx->vertex_size; TAG(render_set_format)(ctx); } @@ -158,8 +155,8 @@ swtnl_alloc_vertices(struct gl_context *ctx) struct nouveau_swtnl_state *swtnl = &to_render_state(ctx)->swtnl; nouveau_bo_ref(NULL, &swtnl->vbo); - swtnl->buf = get_scratch_vbo(ctx, RENDER_SCRATCH_SIZE, - &swtnl->vbo, NULL); + swtnl->buf = nouveau_get_scratch(ctx, SWTNL_VBO_SIZE, &swtnl->vbo, + &swtnl->offset); swtnl->vertex_count = 0; } @@ -168,14 +165,15 @@ swtnl_bind_vertices(struct gl_context *ctx) { struct nouveau_render_state *render = to_render_state(ctx); struct nouveau_swtnl_state *swtnl = &render->swtnl; + struct tnl_clipspace *vtx = &TNL_CONTEXT(ctx)->clipspace; int i; - for (i = 0; i < render->attr_count; i++) { - int attr = render->map[i]; + for (i = 0; i < vtx->attr_count; i++) { + struct tnl_clipspace_attr *ta = &vtx->attr[i]; + struct nouveau_array *a = &render->attrs[ta->attrib]; - if (attr >= 0) - nouveau_bo_ref(swtnl->vbo, - &render->attrs[attr].bo); + nouveau_bo_ref(swtnl->vbo, &a->bo); + a->offset = swtnl->offset + ta->vertoffset; } TAG(render_bind_vertices)(ctx); @@ -185,15 +183,11 @@ static void swtnl_unbind_vertices(struct gl_context *ctx) { struct nouveau_render_state *render = to_render_state(ctx); - int i; - - for (i = 0; i < render->attr_count; i++) { - int *attr = &render->map[i]; + int i, attr; - if (*attr >= 0) { - nouveau_bo_ref(NULL, &render->attrs[*attr].bo); - *attr = -1; - } + FOR_EACH_BOUND_ATTR(render, i, attr) { + nouveau_bo_ref(NULL, &render->attrs[attr].bo); + render->map[i] = -1; } render->attr_count = 0; @@ -260,7 +254,7 @@ swtnl_reset_stipple(struct gl_context *ctx) struct nouveau_swtnl_state *swtnl = &to_render_state(ctx)->swtnl; \ int vertex_len = TNL_CONTEXT(ctx)->clipspace.vertex_size; \ \ - if (swtnl->vertex_count + (n) > swtnl->vbo->size/vertex_len \ + if (swtnl->vertex_count + (n) > SWTNL_VBO_SIZE/vertex_len \ || (swtnl->vertex_count && swtnl->primitive != p)) \ swtnl_flush_vertices(ctx); \ \ @@ -280,7 +274,7 @@ swtnl_points(struct gl_context *ctx, GLuint first, GLuint last) while (first < last) { BEGIN_PRIMITIVE(GL_POINTS, last - first); - count = MIN2(swtnl->vbo->size / vertex_len, last - first); + count = MIN2(SWTNL_VBO_SIZE / vertex_len, last - first); for (i = 0; i < count; i++) OUT_VERTEX(first + i); @@ -316,7 +310,7 @@ swtnl_quad(struct gl_context *ctx, GLuint v1, GLuint v2, GLuint v3, GLuint v4) } /* TnL initialization. */ -static void +void TAG(swtnl_init)(struct gl_context *ctx) { TNLcontext *tnl = TNL_CONTEXT(ctx); @@ -347,7 +341,7 @@ TAG(swtnl_init)(struct gl_context *ctx) swtnl_alloc_vertices(ctx); } -static void +void TAG(swtnl_destroy)(struct gl_context *ctx) { nouveau_bo_ref(NULL, &to_render_state(ctx)->swtnl.vbo); diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c index cd063702af0..060c2c5bcc0 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c @@ -79,26 +79,65 @@ nouveau_teximage_free(struct gl_context *ctx, struct gl_texture_image *ti) } static void -nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti) +nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti, + int access, int x, int y, int w, int h) { - struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface; - int ret; + struct nouveau_teximage *nti = to_nouveau_teximage(ti); + struct nouveau_surface *s = &nti->surface; + struct nouveau_surface *st = &nti->transfer.surface; if (s->bo) { - ret = nouveau_bo_map(s->bo, NOUVEAU_BO_RDWR); - assert(!ret); - - ti->Data = s->bo->map; + if (!(access & GL_MAP_READ_BIT) && + nouveau_bo_pending(s->bo)) { + /* + * Heuristic: use a bounce buffer to pipeline + * teximage transfers. + */ + st->layout = LINEAR; + st->format = s->format; + st->cpp = s->cpp; + st->width = w; + st->height = h; + st->pitch = s->pitch; + nti->transfer.x = x; + nti->transfer.y = y; + + ti->Data = nouveau_get_scratch(ctx, st->pitch * h, + &st->bo, &st->offset); + + } else { + int ret, flags = 0; + + if (access & GL_MAP_READ_BIT) + flags |= NOUVEAU_BO_RD; + if (access & GL_MAP_WRITE_BIT) + flags |= NOUVEAU_BO_WR; + + ret = nouveau_bo_map(s->bo, flags); + assert(!ret); + + ti->Data = s->bo->map + y * s->pitch + x * s->cpp; + } } } static void nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti) { - struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface; + struct nouveau_teximage *nti = to_nouveau_teximage(ti); + struct nouveau_surface *s = &nti->surface; + struct nouveau_surface *st = &nti->transfer.surface; - if (s->bo) + if (st->bo) { + context_drv(ctx)->surface_copy(ctx, s, st, nti->transfer.x, + nti->transfer.y, 0, 0, + st->width, st->height); + nouveau_surface_ref(NULL, st); + + } else if (s->bo) { nouveau_bo_unmap(s->bo); + } + ti->Data = NULL; } @@ -115,6 +154,7 @@ nouveau_choose_tex_format(struct gl_context *ctx, GLint internalFormat, case GL_RGBA12: case GL_RGBA16: case GL_RGB10_A2: + case GL_COMPRESSED_RGBA: return MESA_FORMAT_ARGB8888; case GL_RGB5_A1: return MESA_FORMAT_ARGB1555; @@ -124,6 +164,7 @@ nouveau_choose_tex_format(struct gl_context *ctx, GLint internalFormat, case GL_RGB10: case GL_RGB12: case GL_RGB16: + case GL_COMPRESSED_RGB: return MESA_FORMAT_XRGB8888; case 3: case GL_R3_G3_B2: @@ -139,6 +180,7 @@ nouveau_choose_tex_format(struct gl_context *ctx, GLint internalFormat, case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: case GL_LUMINANCE8_ALPHA8: + case GL_COMPRESSED_LUMINANCE_ALPHA: return MESA_FORMAT_ARGB8888; case 1: @@ -147,6 +189,7 @@ nouveau_choose_tex_format(struct gl_context *ctx, GLint internalFormat, case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_LUMINANCE8: + case GL_COMPRESSED_LUMINANCE: return MESA_FORMAT_L8; case GL_ALPHA: @@ -154,6 +197,7 @@ nouveau_choose_tex_format(struct gl_context *ctx, GLint internalFormat, case GL_ALPHA12: case GL_ALPHA16: case GL_ALPHA8: + case GL_COMPRESSED_ALPHA: return MESA_FORMAT_A8; case GL_INTENSITY: @@ -356,7 +400,8 @@ nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level, "glTexImage"); if (pixels) { /* Store the pixel data. */ - nouveau_teximage_map(ctx, ti); + nouveau_teximage_map(ctx, ti, GL_MAP_WRITE_BIT, + 0, 0, width, height); ret = _mesa_texstore(ctx, dims, ti->_BaseFormat, ti->TexFormat, ti->Data, @@ -443,13 +488,13 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint lev format, type, pixels, packing, "glTexSubImage"); if (pixels) { - nouveau_teximage_map(ctx, ti); + nouveau_teximage_map(ctx, ti, GL_MAP_WRITE_BIT, + xoffset, yoffset, width, height); ret = _mesa_texstore(ctx, 3, ti->_BaseFormat, ti->TexFormat, - ti->Data, xoffset, yoffset, zoffset, - s->pitch, ti->ImageOffsets, - width, height, depth, format, type, - pixels, packing); + ti->Data, 0, 0, 0, s->pitch, + ti->ImageOffsets, width, height, depth, + format, type, pixels, packing); assert(ret); nouveau_teximage_unmap(ctx, ti); @@ -508,7 +553,8 @@ nouveau_get_teximage(struct gl_context *ctx, GLenum target, GLint level, struct gl_texture_object *t, struct gl_texture_image *ti) { - nouveau_teximage_map(ctx, ti); + nouveau_teximage_map(ctx, ti, GL_MAP_READ_BIT, + 0, 0, ti->Width, ti->Height); _mesa_get_teximage(ctx, target, level, format, type, pixels, t, ti); nouveau_teximage_unmap(ctx, ti); @@ -579,8 +625,11 @@ nouveau_texture_map(struct gl_context *ctx, struct gl_texture_object *t) int i; for (i = t->BaseLevel; i < t->_MaxLevel; i++) { - if (t->Image[0][i]) - nouveau_teximage_map(ctx, t->Image[0][i]); + struct gl_texture_image *ti = t->Image[0][i]; + + if (ti) + nouveau_teximage_map(ctx, ti, GL_MAP_READ_BIT, + 0, 0, ti->Width, ti->Height); } } @@ -630,7 +679,8 @@ nouveau_generate_mipmap(struct gl_context *ctx, GLenum target, if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, t)) { struct gl_texture_image *base = t->Image[0][t->BaseLevel]; - nouveau_teximage_map(ctx, base); + nouveau_teximage_map(ctx, base, GL_MAP_READ_BIT, + 0, 0, base->Width, base->Height); _mesa_generate_mipmap(ctx, target, t); nouveau_teximage_unmap(ctx, base); diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.h b/src/mesa/drivers/dri/nouveau/nouveau_texture.h index fc170215f35..56e61c7337b 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_texture.h +++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.h @@ -30,6 +30,10 @@ struct nouveau_teximage { struct gl_texture_image base; struct nouveau_surface surface; + struct { + struct nouveau_surface surface; + int x, y; + } transfer; }; #define to_nouveau_teximage(x) ((struct nouveau_teximage *)(x)) diff --git a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c index 394f3c9b500..7a0eb9fc23d 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c @@ -31,59 +31,11 @@ #include "main/image.h" /* Arbitrary pushbuf length we can assume we can get with a single - * WAIT_RING. */ + * call to WAIT_RING. */ #define PUSHBUF_DWORDS 65536 -/* Functions to set up struct nouveau_array_state from something like - * a GL array or index buffer. */ - -static void -vbo_init_array(struct nouveau_array_state *a, int attr, int stride, - int fields, int type, struct gl_buffer_object *obj, - const void *ptr, GLboolean map) -{ - a->attr = attr; - a->stride = stride; - a->fields = fields; - a->type = type; - - if (_mesa_is_bufferobj(obj)) { - nouveau_bo_ref(to_nouveau_bufferobj(obj)->bo, &a->bo); - a->offset = (intptr_t)ptr; - - if (map) { - nouveau_bo_map(a->bo, NOUVEAU_BO_RD); - a->buf = a->bo->map + a->offset; - } else { - a->buf = NULL; - } - - } else { - nouveau_bo_ref(NULL, &a->bo); - a->offset = 0; - - if (map) - a->buf = ptr; - else - a->buf = NULL; - } - - if (a->buf) - get_array_extract(a, &a->extract_u, &a->extract_f); -} - -static void -vbo_deinit_array(struct nouveau_array_state *a) -{ - if (a->bo) { - if (a->bo->map) - nouveau_bo_unmap(a->bo); - nouveau_bo_ref(NULL, &a->bo); - } - - a->buf = NULL; - a->fields = 0; -} +/* Functions to turn GL arrays or index buffers into nouveau_array + * structures. */ static int get_array_stride(struct gl_context *ctx, const struct gl_client_array *a) @@ -102,48 +54,45 @@ vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib, const struct gl_client_array **arrays) { struct nouveau_render_state *render = to_render_state(ctx); - int i; + GLboolean imm = (render->mode == IMM); + int i, attr; if (ib) - vbo_init_array(&render->ib, 0, 0, ib->count, ib->type, - ib->obj, ib->ptr, GL_TRUE); + nouveau_init_array(&render->ib, 0, 0, ib->count, ib->type, + ib->obj, ib->ptr, GL_TRUE); - for (i = 0; i < render->attr_count; i++) { - int attr = render->map[i]; + FOR_EACH_BOUND_ATTR(render, i, attr) { + const struct gl_client_array *array = arrays[attr]; - if (attr >= 0) { - const struct gl_client_array *array = arrays[attr]; - - vbo_init_array(&render->attrs[attr], attr, - get_array_stride(ctx, array), - array->Size, array->Type, - array->BufferObj, array->Ptr, - render->mode == IMM); - } + nouveau_init_array(&render->attrs[attr], attr, + get_array_stride(ctx, array), + array->Size, array->Type, + imm ? array->BufferObj : NULL, + array->Ptr, imm); } } static void vbo_deinit_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib, - const struct gl_client_array **arrays) + const struct gl_client_array **arrays) { struct nouveau_render_state *render = to_render_state(ctx); - int i; + int i, attr; if (ib) - vbo_deinit_array(&render->ib); + nouveau_cleanup_array(&render->ib); - for (i = 0; i < render->attr_count; i++) { - int *attr = &render->map[i]; + FOR_EACH_BOUND_ATTR(render, i, attr) { + struct nouveau_array *a = &render->attrs[attr]; - if (*attr >= 0) { - vbo_deinit_array(&render->attrs[*attr]); - *attr = -1; - } + if (render->mode == IMM) + nouveau_bo_ref(NULL, &a->bo); + + nouveau_deinit_array(a); + render->map[i] = -1; } render->attr_count = 0; - context_bctx(ctx, VERTEX); } /* Make some rendering decisions from the GL context. */ @@ -164,20 +113,16 @@ vbo_choose_render_mode(struct gl_context *ctx, const struct gl_client_array **ar } } } - - if (render->mode == VBO) - render->attr_count = NUM_VERTEX_ATTRS; - else - render->attr_count = 0; } static void -vbo_emit_attr(struct gl_context *ctx, const struct gl_client_array **arrays, int attr) +vbo_emit_attr(struct gl_context *ctx, const struct gl_client_array **arrays, + int attr) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_render_state *render = to_render_state(ctx); const struct gl_client_array *array = arrays[attr]; - struct nouveau_array_state *a = &render->attrs[attr]; + struct nouveau_array *a = &render->attrs[attr]; RENDER_LOCALS(ctx); if (!array->StrideB) { @@ -186,11 +131,11 @@ vbo_emit_attr(struct gl_context *ctx, const struct gl_client_array **arrays, int return; /* Constant attribute. */ - vbo_init_array(a, attr, array->StrideB, array->Size, - array->Type, array->BufferObj, array->Ptr, - GL_TRUE); + nouveau_init_array(a, attr, array->StrideB, array->Size, + array->Type, array->BufferObj, array->Ptr, + GL_TRUE); EMIT_IMM(ctx, a, 0); - vbo_deinit_array(a); + nouveau_deinit_array(a); } else { /* Varying attribute. */ @@ -199,10 +144,13 @@ vbo_emit_attr(struct gl_context *ctx, const struct gl_client_array **arrays, int if (render->mode == VBO) { render->map[info->vbo_index] = attr; render->vertex_size += array->_ElementSize; + render->attr_count = MAX2(render->attr_count, + info->vbo_index + 1); } else { render->map[render->attr_count++] = attr; render->vertex_size += 4 * info->imm_fields; } + } } @@ -216,6 +164,7 @@ vbo_choose_attrs(struct gl_context *ctx, const struct gl_client_array **arrays) /* Reset the vertex size. */ render->vertex_size = 0; + render->attr_count = 0; vbo_emit_attr(ctx, arrays, VERT_ATTRIB_COLOR0); if (ctx->Fog.ColorSumEnabled && !ctx->Light.Enabled) @@ -233,7 +182,7 @@ vbo_choose_attrs(struct gl_context *ctx, const struct gl_client_array **arrays) (ctx->Texture._GenFlags & TEXGEN_NEED_NORMALS)) vbo_emit_attr(ctx, arrays, VERT_ATTRIB_NORMAL); - if (ctx->Light.Enabled) { + if (ctx->Light.Enabled && render->mode == IMM) { vbo_emit_attr(ctx, arrays, MAT(FRONT_AMBIENT)); vbo_emit_attr(ctx, arrays, MAT(FRONT_DIFFUSE)); vbo_emit_attr(ctx, arrays, MAT(FRONT_SPECULAR)); @@ -254,17 +203,13 @@ static int get_max_client_stride(struct gl_context *ctx, const struct gl_client_array **arrays) { struct nouveau_render_state *render = to_render_state(ctx); - int i, s = 0; + int i, attr, s = 0; - for (i = 0; i < render->attr_count; i++) { - int attr = render->map[i]; + FOR_EACH_BOUND_ATTR(render, i, attr) { + const struct gl_client_array *a = arrays[attr]; - if (attr >= 0) { - const struct gl_client_array *a = arrays[attr]; - - if (!_mesa_is_bufferobj(a->BufferObj)) - s = MAX2(s, get_array_stride(ctx, a)); - } + if (!_mesa_is_bufferobj(a->BufferObj)) + s = MAX2(s, get_array_stride(ctx, a)); } return s; @@ -295,7 +240,7 @@ vbo_maybe_split(struct gl_context *ctx, const struct gl_client_array **arrays, if (render->mode == VBO && (stride = get_max_client_stride(ctx, arrays))) vert_avail = MIN2(vert_avail, - RENDER_SCRATCH_SIZE / stride); + NOUVEAU_SCRATCH_SIZE / stride); if (max_index - min_index > vert_avail || (ib && ib->count > idx_avail)) { @@ -315,42 +260,93 @@ vbo_maybe_split(struct gl_context *ctx, const struct gl_client_array **arrays, /* VBO rendering path. */ +static GLboolean +check_update_array(struct nouveau_array *a, unsigned offset, + struct nouveau_bo *bo, int *pdelta) +{ + int delta = *pdelta; + GLboolean dirty; + + if (a->bo == bo) { + if (delta < 0) + delta = ((int)offset - (int)a->offset) / a->stride; + + dirty = (delta < 0 || + offset != (a->offset + delta * a->stride)); + } else { + dirty = GL_TRUE; + } + + *pdelta = (dirty ? 0 : delta); + return dirty; +} + static void vbo_bind_vertices(struct gl_context *ctx, const struct gl_client_array **arrays, - GLint basevertex, GLuint min_index, GLuint max_index) + int base, unsigned min_index, unsigned max_index, int *pdelta) { struct nouveau_render_state *render = to_render_state(ctx); - int i; + struct nouveau_channel *chan = context_chan(ctx); + struct nouveau_bo *bo[NUM_VERTEX_ATTRS]; + unsigned offset[NUM_VERTEX_ATTRS]; + GLboolean dirty = GL_FALSE; + int i, j, attr; + RENDER_LOCALS(ctx); - for (i = 0; i < NUM_VERTEX_ATTRS; i++) { - int attr = render->map[i]; - - if (attr >= 0) { - const struct gl_client_array *array = arrays[attr]; - struct nouveau_array_state *a = &render->attrs[attr]; - unsigned delta = (basevertex + min_index) - * array->StrideB; - - if (a->bo) { - /* Array in a buffer obj. */ - a->offset = (intptr_t)array->Ptr + delta; - } else { - int j, n = max_index - min_index + 1; - char *sp = (char *)array->Ptr + delta; - char *dp = get_scratch_vbo(ctx, n * a->stride, - &a->bo, &a->offset); - - /* Array in client memory, move it to - * a scratch buffer obj. */ - for (j = 0; j < n; j++) - memcpy(dp + j * a->stride, - sp + j * array->StrideB, - a->stride); - } + *pdelta = -1; + + FOR_EACH_BOUND_ATTR(render, i, attr) { + const struct gl_client_array *array = arrays[attr]; + struct gl_buffer_object *obj = array->BufferObj; + struct nouveau_array *a = &render->attrs[attr]; + unsigned delta = (base + min_index) * array->StrideB; + + bo[i] = NULL; + + if (nouveau_bufferobj_hw(obj)) { + /* Array in a buffer obj. */ + nouveau_bo_ref(to_nouveau_bufferobj(obj)->bo, &bo[i]); + offset[i] = delta + (intptr_t)array->Ptr; + + } else { + int n = max_index - min_index + 1; + char *sp = (char *)ADD_POINTERS( + nouveau_bufferobj_sys(obj), array->Ptr) + delta; + char *dp = nouveau_get_scratch(ctx, n * a->stride, + &bo[i], &offset[i]); + + /* Array in client memory, move it to a + * scratch buffer obj. */ + for (j = 0; j < n; j++) + memcpy(dp + j * a->stride, + sp + j * array->StrideB, + a->stride); } + + dirty |= check_update_array(a, offset[i], bo[i], pdelta); + } + + *pdelta -= min_index; + + if (dirty) { + /* Buffers changed, update the attribute binding. */ + FOR_EACH_BOUND_ATTR(render, i, attr) { + struct nouveau_array *a = &render->attrs[attr]; + + nouveau_bo_ref(NULL, &a->bo); + a->offset = offset[i]; + a->bo = bo[i]; + } + + TAG(render_bind_vertices)(ctx); + + } else { + /* Just cleanup. */ + FOR_EACH_BOUND_ATTR(render, i, attr) + nouveau_bo_ref(NULL, &bo[i]); } - TAG(render_bind_vertices)(ctx); + BATCH_VALIDATE(); } static void @@ -360,12 +356,10 @@ vbo_draw_vbo(struct gl_context *ctx, const struct gl_client_array **arrays, GLuint max_index) { struct nouveau_channel *chan = context_chan(ctx); - dispatch_t dispatch; - int delta = -min_index, basevertex = 0, i; + dispatch_t dispatch = get_array_dispatch(&to_render_state(ctx)->ib); + int i, delta = 0, basevertex = 0; RENDER_LOCALS(ctx); - get_array_dispatch(&to_render_state(ctx)->ib, &dispatch); - TAG(render_set_format)(ctx); for (i = 0; i < nr_prims; i++) { @@ -374,8 +368,8 @@ vbo_draw_vbo(struct gl_context *ctx, const struct gl_client_array **arrays, if (i == 0 || basevertex != prims[i].basevertex) { basevertex = prims[i].basevertex; - vbo_bind_vertices(ctx, arrays, basevertex, - min_index, max_index); + vbo_bind_vertices(ctx, arrays, basevertex, min_index, + max_index, &delta); } if (count > get_max_vertices(ctx, ib, AVAIL_RING(chan))) @@ -390,7 +384,7 @@ vbo_draw_vbo(struct gl_context *ctx, const struct gl_client_array **arrays, /* Immediate rendering path. */ static unsigned -extract_id(struct nouveau_array_state *a, int i, int j) +extract_id(struct nouveau_array *a, int i, int j) { return j; } @@ -404,7 +398,7 @@ vbo_draw_imm(struct gl_context *ctx, const struct gl_client_array **arrays, struct nouveau_render_state *render = to_render_state(ctx); struct nouveau_channel *chan = context_chan(ctx); extract_u_t extract = ib ? render->ib.extract_u : extract_id; - int i, j, k; + int i, j, k, attr; RENDER_LOCALS(ctx); for (i = 0; i < nr_prims; i++) { @@ -421,9 +415,8 @@ vbo_draw_imm(struct gl_context *ctx, const struct gl_client_array **arrays, j = prims[i].basevertex + extract(&render->ib, 0, start); - for (k = 0; k < render->attr_count; k++) - EMIT_IMM(ctx, &render->attrs[render->map[k]], - j); + FOR_EACH_BOUND_ATTR(render, k, attr) + EMIT_IMM(ctx, &render->attrs[attr], j); } BATCH_END(); @@ -433,7 +426,8 @@ vbo_draw_imm(struct gl_context *ctx, const struct gl_client_array **arrays, /* draw_prims entry point when we're doing hw-tnl. */ static void -TAG(vbo_render_prims)(struct gl_context *ctx, const struct gl_client_array **arrays, +TAG(vbo_render_prims)(struct gl_context *ctx, + const struct gl_client_array **arrays, const struct _mesa_prim *prims, GLuint nr_prims, const struct _mesa_index_buffer *ib, GLboolean index_bounds_valid, @@ -462,3 +456,44 @@ TAG(vbo_render_prims)(struct gl_context *ctx, const struct gl_client_array **arr vbo_deinit_arrays(ctx, ib, arrays); } + +/* VBO rendering entry points. */ + +static void +TAG(vbo_check_render_prims)(struct gl_context *ctx, + const struct gl_client_array **arrays, + const struct _mesa_prim *prims, GLuint nr_prims, + const struct _mesa_index_buffer *ib, + GLboolean index_bounds_valid, + GLuint min_index, GLuint max_index) +{ + struct nouveau_context *nctx = to_nouveau_context(ctx); + + nouveau_validate_framebuffer(ctx); + + if (nctx->fallback == HWTNL) + TAG(vbo_render_prims)(ctx, arrays, prims, nr_prims, ib, + index_bounds_valid, min_index, max_index); + + if (nctx->fallback == SWTNL) + _tnl_vbo_draw_prims(ctx, arrays, prims, nr_prims, ib, + index_bounds_valid, min_index, max_index); +} + +void +TAG(vbo_init)(struct gl_context *ctx) +{ + struct nouveau_render_state *render = to_render_state(ctx); + int i; + + for (i = 0; i < VERT_ATTRIB_MAX; i++) + render->map[i] = -1; + + vbo_set_draw_func(ctx, TAG(vbo_check_render_prims)); + vbo_use_buffer_objects(ctx); +} + +void +TAG(vbo_destroy)(struct gl_context *ctx) +{ +} diff --git a/src/mesa/drivers/dri/nouveau/nv10_context.c b/src/mesa/drivers/dri/nouveau/nv10_context.c index fdcb43b7718..de2c93ec815 100644 --- a/src/mesa/drivers/dri/nouveau/nv10_context.c +++ b/src/mesa/drivers/dri/nouveau/nv10_context.c @@ -24,6 +24,7 @@ * */ +#include "main/state.h" #include "nouveau_driver.h" #include "nouveau_context.h" #include "nouveau_fbo.h" @@ -184,6 +185,9 @@ nv10_clear(struct gl_context *ctx, GLbitfield buffers) nv17_zclear(ctx, &buffers); else nv10_zclear(ctx, &buffers); + + /* Emit the zclear state if it's dirty */ + _mesa_update_state(ctx); } nouveau_clear(ctx, buffers); @@ -407,7 +411,8 @@ nv10_context_destroy(struct gl_context *ctx) struct nouveau_context *nctx = to_nouveau_context(ctx); nv04_surface_takedown(ctx); - nv10_render_destroy(ctx); + nv10_swtnl_destroy(ctx); + nv10_vbo_destroy(ctx); nouveau_grobj_free(&nctx->hw.eng3d); @@ -463,7 +468,8 @@ nv10_context_create(struct nouveau_screen *screen, const struct gl_config *visua goto fail; nv10_hwctx_init(ctx); - nv10_render_init(ctx); + nv10_vbo_init(ctx); + nv10_swtnl_init(ctx); return ctx; diff --git a/src/mesa/drivers/dri/nouveau/nv10_driver.h b/src/mesa/drivers/dri/nouveau/nv10_driver.h index dec3d64e7d2..6fdc4641623 100644 --- a/src/mesa/drivers/dri/nouveau/nv10_driver.h +++ b/src/mesa/drivers/dri/nouveau/nv10_driver.h @@ -45,10 +45,16 @@ nv10_transform_depth(struct gl_context *ctx, float z); /* nv10_render.c */ void -nv10_render_init(struct gl_context *ctx); +nv10_vbo_init(struct gl_context *ctx); void -nv10_render_destroy(struct gl_context *ctx); +nv10_vbo_destroy(struct gl_context *ctx); + +void +nv10_swtnl_init(struct gl_context *ctx); + +void +nv10_swtnl_destroy(struct gl_context *ctx); /* nv10_state_fb.c */ void diff --git a/src/mesa/drivers/dri/nouveau/nv10_render.c b/src/mesa/drivers/dri/nouveau/nv10_render.c index a03ace35366..7115739b5aa 100644 --- a/src/mesa/drivers/dri/nouveau/nv10_render.c +++ b/src/mesa/drivers/dri/nouveau/nv10_render.c @@ -32,7 +32,7 @@ #define NUM_VERTEX_ATTRS 8 static void -nv10_emit_material(struct gl_context *ctx, struct nouveau_array_state *a, +nv10_emit_material(struct gl_context *ctx, struct nouveau_array *a, const void *v); /* Vertex attribute format. */ @@ -111,13 +111,11 @@ nv10_render_set_format(struct gl_context *ctx) struct nouveau_render_state *render = to_render_state(ctx); struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); - int i, hw_format; - - for (i = 0; i < NUM_VERTEX_ATTRS; i++) { - int attr = render->map[i]; + int i, attr, hw_format; + FOR_EACH_ATTR(render, i, attr) { if (attr >= 0) { - struct nouveau_array_state *a = &render->attrs[attr]; + struct nouveau_array *a = &render->attrs[attr]; hw_format = a->stride << 8 | a->fields << 4 | @@ -140,31 +138,27 @@ nv10_render_bind_vertices(struct gl_context *ctx) { struct nouveau_render_state *render = to_render_state(ctx); struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX); - struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); - int i; + int i, attr; - for (i = 0; i < NUM_VERTEX_ATTRS; i++) { - int attr = render->map[i]; - - if (attr >= 0) { - struct nouveau_array_state *a = &render->attrs[attr]; + FOR_EACH_BOUND_ATTR(render, i, attr) { + struct nouveau_array *a = &render->attrs[attr]; - nouveau_bo_markl(bctx, celsius, - NV10TCL_VTXBUF_ADDRESS(i), - a->bo, a->offset, - NOUVEAU_BO_GART | NOUVEAU_BO_RD); - } + nouveau_bo_markl(bctx, celsius, + NV10TCL_VTXBUF_ADDRESS(i), + a->bo, a->offset, + NOUVEAU_BO_GART | NOUVEAU_BO_RD); } - - BEGIN_RING(chan, celsius, NV10TCL_VERTEX_ARRAY_VALIDATE, 1); - OUT_RING(chan, 0); } /* Vertex array rendering defs. */ #define RENDER_LOCALS(ctx) \ struct nouveau_grobj *celsius = context_eng3d(ctx) +#define BATCH_VALIDATE() \ + BEGIN_RING(chan, celsius, NV10TCL_VERTEX_ARRAY_VALIDATE, 1); \ + OUT_RING(chan, 0) + #define BATCH_BEGIN(prim) \ BEGIN_RING(chan, celsius, NV10TCL_VERTEX_BUFFER_BEGIN_END, 1); \ OUT_RING(chan, prim) @@ -199,3 +193,5 @@ nv10_render_bind_vertices(struct gl_context *ctx) #define TAG(x) nv10_##x #include "nouveau_render_t.c" +#include "nouveau_vbo_t.c" +#include "nouveau_swtnl_t.c" diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_fb.c b/src/mesa/drivers/dri/nouveau/nv10_state_fb.c index d87fe96b1c0..0fda9faf49b 100644 --- a/src/mesa/drivers/dri/nouveau/nv10_state_fb.c +++ b/src/mesa/drivers/dri/nouveau/nv10_state_fb.c @@ -51,11 +51,11 @@ get_rt_format(gl_format format) } static void -setup_lma_buffer(struct gl_context *ctx) +setup_hierz_buffer(struct gl_context *ctx) { struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *celsius = context_eng3d(ctx); - struct nouveau_bo_context *bctx = context_bctx(ctx, LMA_DEPTH); + struct nouveau_bo_context *bctx = context_bctx(ctx, HIERZ); struct gl_framebuffer *fb = ctx->DrawBuffer; struct nouveau_framebuffer *nfb = to_nouveau_framebuffer(fb); unsigned pitch = align(fb->Width, 128), @@ -135,7 +135,7 @@ nv10_emit_framebuffer(struct gl_context *ctx, int emit) s->bo, 0, bo_flags); if (context_chipset(ctx) >= 0x17) { - setup_lma_buffer(ctx); + setup_hierz_buffer(ctx); context_dirty(ctx, ZCLEAR); } } diff --git a/src/mesa/drivers/dri/nouveau/nv20_context.c b/src/mesa/drivers/dri/nouveau/nv20_context.c index c6111a2a9a0..89200fb70da 100644 --- a/src/mesa/drivers/dri/nouveau/nv20_context.c +++ b/src/mesa/drivers/dri/nouveau/nv20_context.c @@ -26,6 +26,8 @@ #include "nouveau_driver.h" #include "nouveau_context.h" +#include "nouveau_fbo.h" +#include "nouveau_util.h" #include "nouveau_class.h" #include "nv04_driver.h" #include "nv10_driver.h" @@ -40,6 +42,57 @@ static const struct dri_extension nv20_extensions[] = { }; static void +nv20_clear(struct gl_context *ctx, GLbitfield buffers) +{ + struct nouveau_channel *chan = context_chan(ctx); + struct nouveau_grobj *kelvin = context_eng3d(ctx); + struct gl_framebuffer *fb = ctx->DrawBuffer; + uint32_t clear = 0; + + nouveau_validate_framebuffer(ctx); + + if (buffers & BUFFER_BITS_COLOR) { + struct nouveau_surface *s = &to_nouveau_renderbuffer( + fb->_ColorDrawBuffers[0])->surface; + + if (ctx->Color.ColorMask[0][RCOMP]) + clear |= NV20TCL_CLEAR_BUFFERS_COLOR_R; + if (ctx->Color.ColorMask[0][GCOMP]) + clear |= NV20TCL_CLEAR_BUFFERS_COLOR_G; + if (ctx->Color.ColorMask[0][BCOMP]) + clear |= NV20TCL_CLEAR_BUFFERS_COLOR_B; + if (ctx->Color.ColorMask[0][ACOMP]) + clear |= NV20TCL_CLEAR_BUFFERS_COLOR_A; + + BEGIN_RING(chan, kelvin, NV20TCL_CLEAR_VALUE, 1); + OUT_RING(chan, pack_rgba_f(s->format, ctx->Color.ClearColor)); + + buffers &= ~BUFFER_BITS_COLOR; + } + + if (buffers & (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)) { + struct nouveau_surface *s = &to_nouveau_renderbuffer( + fb->_DepthBuffer->Wrapped)->surface; + + if (buffers & BUFFER_BIT_DEPTH && ctx->Depth.Mask) + clear |= NV20TCL_CLEAR_BUFFERS_DEPTH; + if (buffers & BUFFER_BIT_STENCIL && ctx->Stencil.WriteMask[0]) + clear |= NV20TCL_CLEAR_BUFFERS_STENCIL; + + BEGIN_RING(chan, kelvin, NV20TCL_CLEAR_DEPTH_VALUE, 1); + OUT_RING(chan, pack_zs_f(s->format, ctx->Depth.Clear, + ctx->Stencil.Clear)); + + buffers &= ~(BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL); + } + + BEGIN_RING(chan, kelvin, NV20TCL_CLEAR_BUFFERS, 1); + OUT_RING(chan, clear); + + nouveau_clear(ctx, buffers); +} + +static void nv20_hwctx_init(struct gl_context *ctx) { struct nouveau_channel *chan = context_chan(ctx); @@ -134,10 +187,6 @@ nv20_hwctx_init(struct gl_context *ctx) OUT_RING (chan, 2); if (context_chipset(ctx) >= 0x25) { - BEGIN_RING(chan, kelvin, 0x022c, 2); - OUT_RING (chan, 0x280); - OUT_RING (chan, 0x07d28000); - BEGIN_RING(chan, kelvin, 0x1da4, 1); OUT_RING (chan, 0); } @@ -376,7 +425,8 @@ nv20_context_destroy(struct gl_context *ctx) struct nouveau_context *nctx = to_nouveau_context(ctx); nv04_surface_takedown(ctx); - nv20_render_destroy(ctx); + nv20_swtnl_destroy(ctx); + nv20_vbo_destroy(ctx); nouveau_grobj_free(&nctx->hw.eng3d); @@ -410,6 +460,7 @@ nv20_context_create(struct nouveau_screen *screen, const struct gl_config *visua ctx->Const.MaxTextureUnits = NV20_TEXTURE_UNITS; ctx->Const.MaxTextureMaxAnisotropy = 8; ctx->Const.MaxTextureLodBias = 15; + ctx->Driver.Clear = nv20_clear; /* 2D engine. */ ret = nv04_surface_init(ctx); @@ -428,7 +479,8 @@ nv20_context_create(struct nouveau_screen *screen, const struct gl_config *visua goto fail; nv20_hwctx_init(ctx); - nv20_render_init(ctx); + nv20_vbo_init(ctx); + nv20_swtnl_init(ctx); return ctx; diff --git a/src/mesa/drivers/dri/nouveau/nv20_driver.h b/src/mesa/drivers/dri/nouveau/nv20_driver.h index 7fbe6ccfa68..f2a6097b937 100644 --- a/src/mesa/drivers/dri/nouveau/nv20_driver.h +++ b/src/mesa/drivers/dri/nouveau/nv20_driver.h @@ -39,10 +39,16 @@ extern const struct nouveau_driver nv20_driver; /* nv20_render.c */ void -nv20_render_init(struct gl_context *ctx); +nv20_vbo_init(struct gl_context *ctx); void -nv20_render_destroy(struct gl_context *ctx); +nv20_vbo_destroy(struct gl_context *ctx); + +void +nv20_swtnl_init(struct gl_context *ctx); + +void +nv20_swtnl_destroy(struct gl_context *ctx); /* nv20_state_fb.c */ void diff --git a/src/mesa/drivers/dri/nouveau/nv20_render.c b/src/mesa/drivers/dri/nouveau/nv20_render.c index 6b668544627..dbdb85da203 100644 --- a/src/mesa/drivers/dri/nouveau/nv20_render.c +++ b/src/mesa/drivers/dri/nouveau/nv20_render.c @@ -32,7 +32,7 @@ #define NUM_VERTEX_ATTRS 16 static void -nv20_emit_material(struct gl_context *ctx, struct nouveau_array_state *a, +nv20_emit_material(struct gl_context *ctx, struct nouveau_array *a, const void *v); /* Vertex attribute format. */ @@ -135,13 +135,11 @@ nv20_render_set_format(struct gl_context *ctx) struct nouveau_render_state *render = to_render_state(ctx); struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); - int i, hw_format; - - for (i = 0; i < NUM_VERTEX_ATTRS; i++) { - int attr = render->map[i]; + int i, attr, hw_format; + FOR_EACH_ATTR(render, i, attr) { if (attr >= 0) { - struct nouveau_array_state *a = &render->attrs[attr]; + struct nouveau_array *a = &render->attrs[attr]; hw_format = a->stride << 8 | a->fields << 4 | @@ -162,33 +160,29 @@ nv20_render_bind_vertices(struct gl_context *ctx) { struct nouveau_render_state *render = to_render_state(ctx); struct nouveau_bo_context *bctx = context_bctx(ctx, VERTEX); - struct nouveau_channel *chan = context_chan(ctx); struct nouveau_grobj *kelvin = context_eng3d(ctx); - int i; + int i, attr; - for (i = 0; i < NUM_VERTEX_ATTRS; i++) { - int attr = render->map[i]; + FOR_EACH_BOUND_ATTR(render, i, attr) { + struct nouveau_array *a = &render->attrs[attr]; - if (attr >= 0) { - struct nouveau_array_state *a = &render->attrs[attr]; - - nouveau_bo_mark(bctx, kelvin, - NV20TCL_VTXBUF_ADDRESS(i), - a->bo, a->offset, 0, - 0, NV20TCL_VTXBUF_ADDRESS_DMA1, - NOUVEAU_BO_LOW | NOUVEAU_BO_OR | - NOUVEAU_BO_GART | NOUVEAU_BO_RD); - } + nouveau_bo_mark(bctx, kelvin, + NV20TCL_VTXBUF_ADDRESS(i), + a->bo, a->offset, 0, + 0, NV20TCL_VTXBUF_ADDRESS_DMA1, + NOUVEAU_BO_LOW | NOUVEAU_BO_OR | + NOUVEAU_BO_GART | NOUVEAU_BO_RD); } - - BEGIN_RING(chan, kelvin, NV20TCL_VTX_CACHE_INVALIDATE, 1); - OUT_RING(chan, 0); } /* Vertex array rendering defs. */ #define RENDER_LOCALS(ctx) \ struct nouveau_grobj *kelvin = context_eng3d(ctx) +#define BATCH_VALIDATE() \ + BEGIN_RING(chan, kelvin, NV20TCL_VTX_CACHE_INVALIDATE, 1); \ + OUT_RING(chan, 0) + #define BATCH_BEGIN(prim) \ BEGIN_RING(chan, kelvin, NV20TCL_VERTEX_BEGIN_END, 1); \ OUT_RING(chan, prim) @@ -223,3 +217,5 @@ nv20_render_bind_vertices(struct gl_context *ctx) #define TAG(x) nv20_##x #include "nouveau_render_t.c" +#include "nouveau_vbo_t.c" +#include "nouveau_swtnl_t.c" diff --git a/src/mesa/drivers/dri/nouveau/nv20_state_fb.c b/src/mesa/drivers/dri/nouveau/nv20_state_fb.c index 7822ca2a098..854392f9ff3 100644 --- a/src/mesa/drivers/dri/nouveau/nv20_state_fb.c +++ b/src/mesa/drivers/dri/nouveau/nv20_state_fb.c @@ -51,6 +51,31 @@ get_rt_format(gl_format format) } } +static void +setup_hierz_buffer(struct gl_context *ctx) +{ + struct nouveau_channel *chan = context_chan(ctx); + struct nouveau_grobj *kelvin = context_eng3d(ctx); + struct nouveau_bo_context *bctx = context_bctx(ctx, HIERZ); + struct gl_framebuffer *fb = ctx->DrawBuffer; + struct nouveau_framebuffer *nfb = to_nouveau_framebuffer(fb); + unsigned pitch = align(fb->Width, 128), + height = align(fb->Height, 2), + size = pitch * height; + + if (!nfb->hierz.bo || nfb->hierz.bo->size != size) { + nouveau_bo_ref(NULL, &nfb->hierz.bo); + nouveau_bo_new(context_dev(ctx), NOUVEAU_BO_VRAM, 0, size, + &nfb->hierz.bo); + } + + BEGIN_RING(chan, kelvin, NV25TCL_HIERZ_PITCH, 1); + OUT_RING(chan, pitch); + + nouveau_bo_markl(bctx, kelvin, NV25TCL_HIERZ_OFFSET, nfb->hierz.bo, + 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR); +} + void nv20_emit_framebuffer(struct gl_context *ctx, int emit) { @@ -88,6 +113,9 @@ nv20_emit_framebuffer(struct gl_context *ctx, int emit) nouveau_bo_markl(bctx, kelvin, NV20TCL_ZETA_OFFSET, s->bo, 0, bo_flags); + + if (context_chipset(ctx) >= 0x25) + setup_hierz_buffer(ctx); } else { rt_format |= get_rt_format(MESA_FORMAT_Z24_S8); zeta_pitch = rt_pitch; |