Commit 8a5b86d7 authored by Keith Whitwell's avatar Keith Whitwell

brw: compiles with pipe_resource

parent 563ca458
......@@ -46,7 +46,6 @@ C_SOURCES = \
brw_structs_dump.c \
brw_swtnl.c \
brw_urb.c \
brw_util.c \
brw_vs.c \
brw_vs_emit.c \
brw_vs_state.c \
......@@ -63,9 +62,9 @@ C_SOURCES = \
brw_wm_state.c \
brw_wm_surface_state.c \
brw_screen.c \
brw_screen_buffers.c \
brw_screen_tex_layout.c \
brw_screen_texture.c \
brw_resource_buffer.c \
brw_resource_texture.c \
brw_resource_texture_layout.c \
brw_screen_surface.c \
brw_batchbuffer.c \
brw_winsys_debug.c \
......
......@@ -53,7 +53,6 @@ i965 = env.ConvenienceLibrary(
'brw_state_upload.c',
'brw_swtnl.c',
'brw_urb.c',
'brw_util.c',
'brw_vs.c',
'brw_vs_emit.c',
'brw_vs_state.c',
......
......@@ -561,8 +561,8 @@ struct brw_context
struct pipe_stencil_ref stencil_ref;
struct pipe_framebuffer_state fb;
struct pipe_clip_state ucp;
struct pipe_buffer *vertex_constants;
struct pipe_buffer *fragment_constants;
struct pipe_resource *vertex_constants;
struct pipe_resource *fragment_constants;
struct brw_blend_constant_color bcc;
struct brw_cc1 cc1_stencil_ref;
......@@ -574,7 +574,7 @@ struct brw_context
*
* Updates are signaled by PIPE_NEW_INDEX_BUFFER.
*/
struct pipe_buffer *index_buffer;
struct pipe_resource *index_buffer;
unsigned index_size;
/* Updates are signalled by PIPE_NEW_INDEX_RANGE:
......
......@@ -160,7 +160,6 @@ static GLfloat fixed_plane[6][4] = {
*/
static enum pipe_error prepare_curbe_buffer(struct brw_context *brw)
{
struct pipe_screen *screen = brw->base.screen;
const GLuint sz = brw->curbe.total_size;
const GLuint bufsz = sz * 16 * sizeof(GLfloat);
enum pipe_error ret;
......@@ -196,15 +195,11 @@ static enum pipe_error prepare_curbe_buffer(struct brw_context *brw)
nr_const = fs->info.file_max[TGSI_FILE_CONSTANT] + 1;
/* nr_const = brw->wm.prog_data->nr_params; */
if (nr_const) {
const GLfloat *value = screen->buffer_map( screen,
brw->curr.fragment_constants,
PIPE_BUFFER_USAGE_CPU_READ);
memcpy(&buf[offset], value,
nr_const * 4 * sizeof(float));
screen->buffer_unmap( screen,
brw->curr.fragment_constants );
pipe_buffer_read( &brw->base,
brw->curr.fragment_constants,
0,
nr_const * 4 * sizeof(float),
&buf[offset]);
}
}
......@@ -258,15 +253,14 @@ static enum pipe_error prepare_curbe_buffer(struct brw_context *brw)
* buffer objects. If we want to keep on putting them into the
* curbe, makes sense to treat constbuf's specially with malloc.
*/
const GLfloat *value = screen->buffer_map( screen,
brw->curr.vertex_constants,
PIPE_BUFFER_USAGE_CPU_READ);
/* XXX: what if user's constant buffer is too small?
*/
memcpy(&buf[offset], value, nr_const * 4 * sizeof(float));
screen->buffer_unmap( screen, brw->curr.vertex_constants );
pipe_buffer_read(&brw->base,
brw->curr.vertex_constants,
0,
nr_const * 4 * sizeof(float),
&buf[offset]);
}
}
......
......@@ -142,7 +142,7 @@ static int brw_emit_prim(struct brw_context *brw,
*/
static int
try_draw_range_elements(struct brw_context *brw,
struct pipe_buffer *index_buffer,
struct pipe_resource *index_buffer,
unsigned hw_prim,
unsigned start, unsigned count)
{
......@@ -178,7 +178,7 @@ try_draw_range_elements(struct brw_context *brw,
static void
brw_draw_range_elements(struct pipe_context *pipe,
struct pipe_buffer *index_buffer,
struct pipe_resource *index_buffer,
unsigned index_size,
unsigned min_index,
unsigned max_index,
......@@ -201,7 +201,7 @@ brw_draw_range_elements(struct pipe_context *pipe,
*/
if (brw->curr.index_buffer != index_buffer ||
brw->curr.index_size != index_size) {
pipe_buffer_reference( &brw->curr.index_buffer, index_buffer );
pipe_resource_reference( &brw->curr.index_buffer, index_buffer );
brw->curr.index_size = index_size;
brw->state.dirty.mesa |= PIPE_NEW_INDEX_BUFFER;
}
......@@ -232,7 +232,7 @@ brw_draw_range_elements(struct pipe_context *pipe,
static void
brw_draw_elements(struct pipe_context *pipe,
struct pipe_buffer *index_buffer,
struct pipe_resource *index_buffer,
unsigned index_size,
unsigned mode,
unsigned start, unsigned count)
......@@ -263,14 +263,14 @@ boolean brw_draw_init( struct brw_context *brw )
/* Create helpers for uploading data in user buffers:
*/
brw->vb.upload_vertex = u_upload_create( brw->base.screen,
brw->vb.upload_vertex = u_upload_create( &brw->base,
128 * 1024,
64,
PIPE_BUFFER_USAGE_VERTEX );
if (brw->vb.upload_vertex == NULL)
return FALSE;
brw->vb.upload_index = u_upload_create( brw->base.screen,
brw->vb.upload_index = u_upload_create( &brw->base,
32 * 1024,
64,
PIPE_BUFFER_USAGE_INDEX );
......
......@@ -38,6 +38,7 @@
#include "brw_screen.h"
#include "brw_batchbuffer.h"
#include "brw_debug.h"
#include "brw_resource.h"
......@@ -67,7 +68,7 @@ static int brw_prepare_vertices(struct brw_context *brw)
for (i = 0; i < brw->curr.num_vertex_buffers; i++) {
struct pipe_vertex_buffer *vb = &brw->curr.vertex_buffer[i];
struct brw_winsys_buffer *bo;
struct pipe_buffer *upload_buf = NULL;
struct pipe_resource *upload_buf = NULL;
unsigned offset;
if (BRW_DEBUG & DEBUG_VERTS)
......@@ -75,7 +76,7 @@ static int brw_prepare_vertices(struct brw_context *brw)
__FUNCTION__, i,
brw_buffer_is_user_buffer(vb->buffer),
vb->buffer_offset,
vb->buffer->size,
vb->buffer->width0,
vb->stride);
if (brw_buffer_is_user_buffer(vb->buffer)) {
......@@ -85,8 +86,8 @@ static int brw_prepare_vertices(struct brw_context *brw)
* add support for >1 constant buffer) instead.
*/
unsigned size = (vb->stride == 0 ?
vb->buffer->size - vb->buffer_offset :
MAX2(vb->buffer->size - vb->buffer_offset,
vb->buffer->width0 - vb->buffer_offset :
MAX2(vb->buffer->width0 - vb->buffer_offset,
vb->stride * (max_index + 1 - min_index)));
ret = u_upload_buffer( brw->vb.upload_vertex,
......@@ -123,7 +124,7 @@ static int brw_prepare_vertices(struct brw_context *brw)
/* Don't need to retain this reference. We have a reference on
* the underlying winsys buffer:
*/
pipe_buffer_reference( &upload_buf, NULL );
pipe_resource_reference( &upload_buf, NULL );
}
brw->vb.nr_vb = i;
......@@ -226,8 +227,8 @@ const struct brw_tracked_state brw_vertices = {
static int brw_prepare_indices(struct brw_context *brw)
{
struct pipe_buffer *index_buffer = brw->curr.index_buffer;
struct pipe_buffer *upload_buf = NULL;
struct pipe_resource *index_buffer = brw->curr.index_buffer;
struct pipe_resource *upload_buf = NULL;
struct brw_winsys_buffer *bo = NULL;
GLuint offset;
GLuint index_size;
......@@ -241,9 +242,9 @@ static int brw_prepare_indices(struct brw_context *brw)
debug_printf("%s: index_size:%d index_buffer->size:%d\n",
__FUNCTION__,
brw->curr.index_size,
brw->curr.index_buffer->size);
brw->curr.index_buffer->width0);
ib_size = index_buffer->size;
ib_size = index_buffer->width0;
index_size = brw->curr.index_size;
/* Turn userbuffer into a proper hardware buffer?
......@@ -297,7 +298,7 @@ static int brw_prepare_indices(struct brw_context *brw)
brw->state.dirty.brw |= BRW_NEW_INDEX_BUFFER;
}
pipe_buffer_reference( &upload_buf, NULL );
pipe_resource_reference( &upload_buf, NULL );
brw_add_validated_bo(brw, brw->ib.bo);
return 0;
}
......
#include "util/u_upload_mgr.h"
#include "brw_context.h"
#include "brw_screen.h"
#include "brw_batchbuffer.h"
#include "util/u_upload_mgr.h"
/* All batchbuffer flushes must go through this function.
......@@ -46,35 +47,9 @@ brw_flush( struct pipe_context *pipe,
*fence = NULL;
}
static unsigned brw_is_buffer_referenced(struct pipe_context *pipe,
struct pipe_buffer *buffer)
{
struct brw_context *brw = brw_context(pipe);
struct brw_screen *bscreen = brw_screen(brw->base.screen);
return brw_is_buffer_referenced_by_bo( bscreen,
buffer,
brw->batch->buf );
}
static unsigned brw_is_texture_referenced(struct pipe_context *pipe,
struct pipe_resource *texture,
unsigned face,
unsigned level)
{
struct brw_context *brw = brw_context(pipe);
struct brw_screen *bscreen = brw_screen(brw->base.screen);
return brw_is_texture_referenced_by_bo( bscreen,
texture, face, level,
brw->batch->buf );
}
void brw_pipe_flush_init( struct brw_context *brw )
{
brw->base.flush = brw_flush;
brw->base.is_buffer_referenced = brw_is_buffer_referenced;
brw->base.is_texture_referenced = brw_is_texture_referenced;
}
......
......@@ -235,7 +235,7 @@ static void
brw_sampler_view_destroy(struct pipe_context *pipe,
struct pipe_sampler_view *view)
{
pipe_texture_reference(&view->texture, NULL);
pipe_resource_reference(&view->texture, NULL);
FREE(view);
}
......
......@@ -262,20 +262,20 @@ static void brw_delete_vs_state( struct pipe_context *pipe, void *prog )
static void brw_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
struct pipe_buffer *buf)
struct pipe_resource *buf)
{
struct brw_context *brw = brw_context(pipe);
assert(index == 0);
if (shader == PIPE_SHADER_FRAGMENT) {
pipe_buffer_reference( &brw->curr.fragment_constants,
pipe_resource_reference( &brw->curr.fragment_constants,
buf );
brw->state.dirty.mesa |= PIPE_NEW_FRAGMENT_CONSTANTS;
}
else {
pipe_buffer_reference( &brw->curr.vertex_constants,
pipe_resource_reference( &brw->curr.vertex_constants,
buf );
brw->state.dirty.mesa |= PIPE_NEW_VERTEX_CONSTANTS;
......@@ -298,6 +298,6 @@ void brw_pipe_shader_init( struct brw_context *brw )
void brw_pipe_shader_cleanup( struct brw_context *brw )
{
pipe_buffer_reference( &brw->curr.fragment_constants, NULL );
pipe_buffer_reference( &brw->curr.vertex_constants, NULL );
pipe_resource_reference( &brw->curr.fragment_constants, NULL );
pipe_resource_reference( &brw->curr.vertex_constants, NULL );
}
......@@ -259,11 +259,11 @@ static void brw_set_vertex_buffers(struct pipe_context *pipe,
/* Adjust refcounts */
for (i = 0; i < count; i++)
pipe_buffer_reference(&brw->curr.vertex_buffer[i].buffer,
pipe_resource_reference(&brw->curr.vertex_buffer[i].buffer,
buffers[i].buffer);
for ( ; i < brw->curr.num_vertex_buffers; i++)
pipe_buffer_reference(&brw->curr.vertex_buffer[i].buffer,
pipe_resource_reference(&brw->curr.vertex_buffer[i].buffer,
NULL);
/* Copy remaining data */
......
#include "util/u_debug.h"
#include "brw_resource.h"
#include "brw_context.h"
#include "brw_screen.h"
static struct pipe_resource *
brw_resource_create(struct pipe_screen *screen,
const struct pipe_resource *template)
{
if (template->target == PIPE_BUFFER)
return brw_buffer_create(screen, template);
else
return brw_resource_create(screen, template);
}
static struct pipe_resource *
brw_resource_from_handle(struct pipe_screen * screen,
const struct pipe_resource *template,
struct winsys_handle *whandle)
{
if (template->target == PIPE_BUFFER)
return NULL;
else
return brw_resource_from_handle(screen, template, whandle);
}
void
brw_init_resource_functions(struct brw_context *brw )
{
brw->base.get_transfer = u_get_transfer_vtbl;
brw->base.transfer_map = u_transfer_map_vtbl;
brw->base.transfer_flush_region = u_transfer_flush_region_vtbl;
brw->base.transfer_unmap = u_transfer_unmap_vtbl;
brw->base.transfer_destroy = u_transfer_destroy_vtbl;
brw->base.transfer_inline_write = u_transfer_inline_write_vtbl;
}
void
brw_init_screen_resource_functions(struct brw_screen *is)
{
is->base.resource_create = brw_resource_create;
is->base.resource_from_handle = brw_resource_from_handle;
is->base.resource_get_handle = u_resource_get_handle_vtbl;
is->base.resource_destroy = u_resource_destroy_vtbl;
is->base.user_buffer_create = brw_user_buffer_create;
}
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* 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, sub license, 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 NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS 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 BRW_RESOURCE_H
#define BRW_RESOURCE_H
struct brw_screen;
#include "util/u_transfer.h"
#include "util/u_debug.h"
#include "brw_screen.h" /* for brw_surface */
struct brw_context;
struct brw_screen;
struct brw_buffer {
struct u_resource b;
/* One of either bo or user_buffer will be non-null, depending on
* whether this is a hardware or user buffer.
*/
struct brw_winsys_buffer *bo;
void *user_buffer;
/* Mapped pointer??
*/
void *ptr;
};
#define BRW_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */
#define BRW_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */
struct brw_texture {
struct u_resource b;
struct brw_winsys_buffer *bo;
struct brw_surface_state ss;
unsigned *image_offset[BRW_MAX_TEXTURE_2D_LEVELS];
unsigned nr_images[BRW_MAX_TEXTURE_2D_LEVELS];
unsigned level_offset[BRW_MAX_TEXTURE_2D_LEVELS];
boolean compressed;
unsigned brw_target;
unsigned pitch;
unsigned tiling;
unsigned cpp;
unsigned total_height;
struct brw_surface views[2];
};
void brw_init_screen_resource_functions(struct brw_screen *is);
void brw_init_resource_functions(struct brw_context *brw );
extern struct u_resource_vtbl brw_buffer_vtbl;
extern struct u_resource_vtbl brw_texture_vtbl;
static INLINE struct brw_texture *brw_texture( struct pipe_resource *resource )
{
struct brw_texture *tex = (struct brw_texture *)resource;
assert(tex->b.vtbl == &brw_texture_vtbl);
return tex;
}
static INLINE struct brw_buffer *brw_buffer( struct pipe_resource *resource )
{
struct brw_buffer *tex = (struct brw_buffer *)resource;
assert(tex->b.vtbl == &brw_buffer_vtbl);
return tex;
}
struct pipe_resource *
brw_texture_create(struct pipe_screen *screen,
const struct pipe_resource *template);
struct pipe_resource *
brw_texture_from_handle(struct pipe_screen * screen,
const struct pipe_resource *template,
struct winsys_handle *whandle);
struct pipe_resource *
brw_user_buffer_create(struct pipe_screen *screen,
void *ptr,
unsigned bytes,
unsigned usage);
struct pipe_resource *
brw_buffer_create(struct pipe_screen *screen,
const struct pipe_resource *template);
/*
boolean
brw_is_format_supported( struct pipe_screen *screen,
enum pipe_format format,
enum pipe_texture_target target,
unsigned tex_usage,
unsigned geom_flags );
*/
/* Pipe buffer helpers
*/
static INLINE boolean
brw_buffer_is_user_buffer( const struct pipe_resource *buf )
{
return ((const struct brw_buffer *)buf)->user_buffer != NULL;
}
/***********************************************************************
* Internal functions
*/
GLboolean brw_texture_layout(struct brw_screen *brw_screen,
struct brw_texture *tex );
void brw_update_texture( struct brw_screen *brw_screen,
struct brw_texture *tex );
#endif /* BRW_RESOURCE_H */
......@@ -6,65 +6,68 @@
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "brw_screen.h"
#include "brw_resource.h"
#include "brw_context.h"
#include "brw_batchbuffer.h"
#include "brw_winsys.h"
static boolean
brw_buffer_get_handle(struct pipe_screen *screen,
struct pipe_resource *resource,
struct winsys_handle *handle)
{
return FALSE;
}
static void *
brw_buffer_map_range( struct pipe_screen *screen,
struct pipe_buffer *buffer,
unsigned offset,
unsigned length,
unsigned usage )
static void
brw_buffer_destroy(struct pipe_screen *screen,
struct pipe_resource *resource)
{
struct brw_screen *bscreen = brw_screen(screen);
struct brw_winsys_screen *sws = bscreen->sws;
struct brw_buffer *buf = brw_buffer( buffer );
struct brw_buffer *buf = brw_buffer( resource );
if (buf->user_buffer)
return buf->user_buffer;
return sws->bo_map( buf->bo,
BRW_DATA_OTHER,
offset,
length,
(usage & PIPE_BUFFER_USAGE_CPU_WRITE) ? TRUE : FALSE,
(usage & PIPE_BUFFER_USAGE_DISCARD) ? TRUE : FALSE,
(usage & PIPE_BUFFER_USAGE_FLUSH_EXPLICIT) ? TRUE : FALSE);
bo_reference(&buf->bo, NULL);
FREE(buf);
}
static void *
brw_buffer_map( struct pipe_screen *screen,
struct pipe_buffer *buffer,
unsigned usage )
brw_buffer_transfer_map( struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
struct brw_screen *bscreen = brw_screen(screen);
struct brw_screen *bscreen = brw_screen(pipe->screen);
struct brw_winsys_screen *sws = bscreen->sws;
struct brw_buffer *buf = brw_buffer( buffer );
struct brw_buffer *buf = brw_buffer(transfer->resource);
unsigned offset = transfer->box.x;
unsigned length = transfer->box.width;
unsigned usage = transfer->usage;
uint8_t *map;
if (buf->user_buffer)
return buf->user_buffer;
return sws->bo_map( buf->bo,
BRW_DATA_OTHER,
0,
buf->base.size,
(usage & PIPE_BUFFER_USAGE_CPU_WRITE) ? TRUE : FALSE,
FALSE,
FALSE);
map = buf->user_buffer;
else
map = sws->bo_map( buf->bo,
BRW_DATA_OTHER,
offset,
length,
(usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE,
(usage & PIPE_TRANSFER_DISCARD) ? TRUE : FALSE,
(usage & PIPE_TRANSFER_FLUSH_EXPLICIT) ? TRUE : FALSE);
return map + offset;
}
static void
brw_buffer_flush_mapped_range( struct pipe_screen *screen,
struct pipe_buffer *buffer,
unsigned offset,
unsigned length )
static void
brw_buffer_transfer_flush_region( struct pipe_context *pipe,
struct pipe_transfer *transfer,
const struct pipe_box *box)
{
struct brw_screen *bscreen = brw_screen(screen);
struct brw_screen *bscreen = brw_screen(pipe->screen);
struct brw_winsys_screen *sws = bscreen->sws;
struct brw_buffer *buf = brw_buffer( buffer );
struct brw_buffer *buf = brw_buffer(transfer->resource);
unsigned offset = box->x;
unsigned length = box->width;
if (buf->user_buffer)
return;
......@@ -75,35 +78,55 @@ brw_buffer_flush_mapped_range( struct pipe_screen *screen,
}
static void
brw_buffer_unmap( struct pipe_screen *screen,
struct pipe_buffer *buffer )
static void
brw_buffer_transfer_unmap( struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
struct brw_screen *bscreen = brw_screen(screen);
struct brw_screen *bscreen = brw_screen(pipe->screen);
struct brw_winsys_screen *sws = bscreen->sws;
struct brw_buffer *buf = brw_buffer( buffer );
struct brw_buffer *buf = brw_buffer( transfer->resource );
if (buf->bo)
sws->bo_unmap(buf->bo);
}
static void
brw_buffer_destroy( struct pipe_buffer *buffer )
static unsigned brw_buffer_is_referenced( struct pipe_context *pipe,
struct pipe_resource *resource,
unsigned face,