dri/nouveau: Split out the scratch helpers to a separate file.

This commit is contained in:
Francisco Jerez 2010-10-29 21:56:50 +02:00
parent 6daaf45359
commit f2098e0fef
9 changed files with 165 additions and 78 deletions

View file

@ -19,6 +19,7 @@ DRIVER_SOURCES = \
nouveau_bo_state.c \
nouveau_texture.c \
nouveau_surface.c \
nouveau_scratch.c \
nv04_context.c \
nv04_render.c \
nv04_state_fb.c \

View file

@ -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);
}

View file

@ -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;

View file

@ -55,19 +55,9 @@ struct nouveau_array_state {
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;
};
struct nouveau_swtnl_state {
struct nouveau_bo *vbo;
unsigned offset;
void *buf;
unsigned vertex_count;
GLenum primitive;
@ -89,7 +79,6 @@ struct nouveau_render_state {
int attr_count;
int vertex_size;
struct nouveau_scratch_state scratch;
struct nouveau_swtnl_state swtnl;
};

View file

@ -199,56 +199,6 @@ get_array_extract(struct nouveau_array_state *a,
}
}
/*
* 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.
*/
@ -337,15 +287,7 @@ 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);
}
int i;
for (i = 0; i < VERT_ATTRIB_MAX; i++)
render->map[i] = -1;

View file

@ -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]);
}

View file

@ -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

View file

@ -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) {
@ -158,8 +160,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;
}
@ -260,7 +262,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 +282,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);

View file

@ -295,7 +295,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)) {
@ -337,8 +337,8 @@ vbo_bind_vertices(struct gl_context *ctx, const struct gl_client_array **arrays,
} 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);
char *dp = nouveau_get_scratch(
ctx, n * a->stride, &a->bo, &a->offset);
/* Array in client memory, move it to
* a scratch buffer obj. */