Commit 0251612d authored by Keith Whitwell's avatar Keith Whitwell

i915: compiling with pipe_resources

parent 9a023586
......@@ -98,7 +98,7 @@ EGL_DRIVERS_DIRS = glx
# Gallium directories and
GALLIUM_DIRS = auxiliary drivers state_trackers
GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
GALLIUM_DRIVERS_DIRS = softpipe trace identity # svga i915 i965 r300
GALLIUM_DRIVERS_DIRS = softpipe trace identity i915 #svga i965 r300
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
GALLIUM_WINSYS_DIRS = null xlib drm
GALLIUM_TARGET_DIRS = libgl-xlib
......
......@@ -128,6 +128,7 @@ C_SOURCES = \
util/u_texture.c \
util/u_tile.c \
util/u_transfer.c \
util/u_resource.c \
util/u_upload_mgr.c \
target-helpers/wrap_screen.c
# Disabling until pipe-video branch gets merged in
......
#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_transfer.h"
static INLINE struct u_resource *
u_resource( struct pipe_resource *res )
{
return (struct u_resource *)res;
}
boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
struct pipe_resource *resource,
struct winsys_handle *handle)
{
struct u_resource *ur = u_resource(resource);
return ur->vtbl->resource_get_handle(screen, resource, handle);
}
void u_resource_destroy_vtbl(struct pipe_screen *screen,
struct pipe_resource *resource)
{
struct u_resource *ur = u_resource(resource);
ur->vtbl->resource_destroy(screen, resource);
}
struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box)
{
struct u_resource *ur = u_resource(resource);
return ur->vtbl->get_transfer(context, resource, sr, usage, box);
}
void u_transfer_destroy_vtbl(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
struct u_resource *ur = u_resource(transfer->resource);
ur->vtbl->transfer_destroy(pipe, transfer);
}
void *u_transfer_map_vtbl( struct pipe_context *pipe,
struct pipe_transfer *transfer )
{
struct u_resource *ur = u_resource(transfer->resource);
return ur->vtbl->transfer_map(pipe, transfer);
}
void u_transfer_flush_region_vtbl( struct pipe_context *pipe,
struct pipe_transfer *transfer,
const struct pipe_box *box)
{
struct u_resource *ur = u_resource(transfer->resource);
ur->vtbl->transfer_flush_region(pipe, transfer, box);
}
void u_transfer_unmap_vtbl( struct pipe_context *pipe,
struct pipe_transfer *transfer )
{
struct u_resource *ur = u_resource(transfer->resource);
ur->vtbl->transfer_unmap(pipe, transfer);
}
void u_transfer_inline_write_vtbl( struct pipe_context *pipe,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned slice_stride)
{
struct u_resource *ur = u_resource(resource);
ur->vtbl->transfer_inline_write(pipe,
resource,
sr,
usage,
box,
data,
stride,
slice_stride);
}
......@@ -2,18 +2,19 @@
#include "util/u_rect.h"
#include "util/u_inlines.h"
#include "util/u_transfer.h"
#include "util/u_memory.h"
/* One-shot transfer operation with data supplied in a user
* pointer. XXX: strides??
*/
void u_transfer_inline_write( struct pipe_context *pipe,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned slice_stride)
void u_default_transfer_inline_write( struct pipe_context *pipe,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned slice_stride)
{
struct pipe_transfer *transfer = NULL;
uint8_t *map = NULL;
......@@ -54,10 +55,39 @@ out:
void u_transfer_flush_region_noop( struct pipe_context *pipe,
struct pipe_transfer *transfer,
const struct pipe_box *box)
void u_default_transfer_flush_region( struct pipe_context *pipe,
struct pipe_transfer *transfer,
const struct pipe_box *box)
{
/* This is a no-op implementation, nothing to do.
*/
}
struct pipe_transfer * u_default_get_transfer(struct pipe_context *context,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box)
{
struct pipe_transfer *transfer = CALLOC_STRUCT(pipe_transfer);
if (transfer == NULL)
return NULL;
transfer->resource = resource;
transfer->sr = sr;
transfer->usage = usage;
transfer->box = *box;
return transfer;
}
void u_default_transfer_unmap( struct pipe_context *pipe,
struct pipe_transfer *transfer )
{
}
void u_default_transfer_destroy(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
FREE(transfer);
}
......@@ -10,7 +10,7 @@
struct pipe_context;
void u_transfer_inline_write( struct pipe_context *pipe,
void u_default_transfer_inline_write( struct pipe_context *pipe,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
......@@ -19,7 +19,112 @@ void u_transfer_inline_write( struct pipe_context *pipe,
unsigned stride,
unsigned slice_stride);
void u_transfer_flush_region_noop( struct pipe_context *pipe,
struct pipe_transfer *transfer,
const struct pipe_box *box);
void u_default_transfer_flush_region( struct pipe_context *pipe,
struct pipe_transfer *transfer,
const struct pipe_box *box);
struct pipe_transfer * u_default_get_transfer(struct pipe_context *context,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box);
void u_default_transfer_unmap( struct pipe_context *pipe,
struct pipe_transfer *transfer );
void u_default_transfer_destroy(struct pipe_context *pipe,
struct pipe_transfer *transfer);
/* Useful helper to allow >1 implementation of resource functionality
* to exist in a single driver. This is intended to be transitionary!
*/
struct u_resource_vtbl {
boolean (*resource_get_handle)(struct pipe_screen *,
struct pipe_resource *tex,
struct winsys_handle *handle);
void (*resource_destroy)(struct pipe_screen *,
struct pipe_resource *pt);
struct pipe_transfer *(*get_transfer)(struct pipe_context *,
struct pipe_resource *resource,
struct pipe_subresource,
enum pipe_transfer_usage,
const struct pipe_box *);
void (*transfer_destroy)(struct pipe_context *,
struct pipe_transfer *);
void *(*transfer_map)( struct pipe_context *,
struct pipe_transfer *transfer );
void (*transfer_flush_region)( struct pipe_context *,
struct pipe_transfer *transfer,
const struct pipe_box *);
void (*transfer_unmap)( struct pipe_context *,
struct pipe_transfer *transfer );
void (*transfer_inline_write)( struct pipe_context *pipe,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned slice_stride);
};
struct u_resource {
struct pipe_resource b;
struct u_resource_vtbl *vtbl;
};
boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
struct pipe_resource *resource,
struct winsys_handle *handle);
void u_resource_destroy_vtbl(struct pipe_screen *screen,
struct pipe_resource *resource);
struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box);
void u_transfer_destroy_vtbl(struct pipe_context *pipe,
struct pipe_transfer *transfer);
void *u_transfer_map_vtbl( struct pipe_context *pipe,
struct pipe_transfer *transfer );
void u_transfer_flush_region_vtbl( struct pipe_context *pipe,
struct pipe_transfer *transfer,
const struct pipe_box *box);
void u_transfer_unmap_vtbl( struct pipe_context *rm_ctx,
struct pipe_transfer *transfer );
void u_transfer_inline_write_vtbl( struct pipe_context *rm_ctx,
struct pipe_resource *resource,
struct pipe_subresource sr,
enum pipe_transfer_usage usage,
const struct pipe_box *box,
const void *data,
unsigned stride,
unsigned slice_stride);
#endif
......@@ -5,7 +5,6 @@ LIBNAME = i915
C_SOURCES = \
i915_blit.c \
i915_buffer.c \
i915_clear.c \
i915_flush.c \
i915_context.c \
......@@ -20,7 +19,9 @@ C_SOURCES = \
i915_screen.c \
i915_prim_emit.c \
i915_prim_vbuf.c \
i915_texture.c \
i915_resource.c \
i915_resource_texture.c \
i915_resource_buffer.c \
i915_fpc_emit.c \
i915_fpc_translate.c \
i915_surface.c
......
/**************************************************************************
*
* Copyright © 2009 Jakob Bornecrantz
*
* 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 AUTHORS OR COPYRIGHT HOLDERS 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 I915_BUFFER_H
#define I915_BUFFER_H
void i915_init_screen_buffer_functions(struct i915_screen *screen);
#endif
......@@ -28,7 +28,9 @@
#include "i915_context.h"
#include "i915_state.h"
#include "i915_screen.h"
#include "i915_surface.h"
#include "i915_batch.h"
#include "i915_resource.h"
#include "draw/draw_context.h"
#include "pipe/p_defines.h"
......@@ -44,7 +46,7 @@
static void
i915_draw_range_elements(struct pipe_context *pipe,
struct pipe_buffer *indexBuffer,
struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned min_index,
unsigned max_index,
......@@ -61,8 +63,7 @@ i915_draw_range_elements(struct pipe_context *pipe,
* Map vertex buffers
*/
for (i = 0; i < i915->num_vertex_buffers; i++) {
void *buf = pipe_buffer_map(pipe->screen, i915->vertex_buffer[i].buffer,
PIPE_BUFFER_USAGE_CPU_READ);
void *buf = i915_buffer(i915->vertex_buffer[i].buffer)->data;
draw_set_mapped_vertex_buffer(draw, i, buf);
}
......@@ -70,8 +71,7 @@ i915_draw_range_elements(struct pipe_context *pipe,
* Map index buffer, if present
*/
if (indexBuffer) {
void *mapped_indexes = pipe_buffer_map(pipe->screen, indexBuffer,
PIPE_BUFFER_USAGE_CPU_READ);
void *mapped_indexes = i915_buffer(indexBuffer)->data;
draw_set_mapped_element_buffer_range(draw, indexSize,
min_index,
max_index,
......@@ -95,19 +95,17 @@ i915_draw_range_elements(struct pipe_context *pipe,
* unmap vertex/index buffers
*/
for (i = 0; i < i915->num_vertex_buffers; i++) {
pipe_buffer_unmap(pipe->screen, i915->vertex_buffer[i].buffer);
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
if (indexBuffer) {
pipe_buffer_unmap(pipe->screen, indexBuffer);
draw_set_mapped_element_buffer_range(draw, 0, start, start + count - 1, NULL);
draw_set_mapped_element_buffer(draw, 0, NULL);
}
}
static void
i915_draw_elements(struct pipe_context *pipe,
struct pipe_buffer *indexBuffer,
struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned prim, unsigned start, unsigned count)
{
......@@ -131,8 +129,8 @@ i915_draw_arrays(struct pipe_context *pipe,
static unsigned int
i915_is_texture_referenced(struct pipe_context *pipe,
struct pipe_texture *texture,
i915_is_resource_referenced(struct pipe_context *pipe,
struct pipe_resource *texture,
unsigned face, unsigned level)
{
/**
......@@ -146,16 +144,6 @@ i915_is_texture_referenced(struct pipe_context *pipe,
#endif
}
static unsigned int
i915_is_buffer_referenced(struct pipe_context *pipe,
struct pipe_buffer *buf)
{
/*
* Since we never expose hardware buffers to the state tracker
* they can never be referenced, so this isn't a lie
*/
return 0;
}
/*
......@@ -204,8 +192,7 @@ i915_create_context(struct pipe_screen *screen, void *priv)
i915->base.draw_elements = i915_draw_elements;
i915->base.draw_range_elements = i915_draw_range_elements;
i915->base.is_texture_referenced = i915_is_texture_referenced;
i915->base.is_buffer_referenced = i915_is_buffer_referenced;
i915->base.is_resource_referenced = i915_is_resource_referenced;
/*
* Create drawing context and plug our rendering stage into it.
......@@ -221,7 +208,7 @@ i915_create_context(struct pipe_screen *screen, void *priv)
i915_init_surface_functions(i915);
i915_init_state_functions(i915);
i915_init_flush_functions(i915);
i915_init_texture_functions(i915);
i915_init_resource_functions(i915);
draw_install_aaline_stage(i915->draw, &i915->base);
draw_install_aapoint_stage(i915->draw, &i915->base);
......
......@@ -192,35 +192,6 @@ struct i915_velems_state {
struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
};
#define I915_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */
#define I915_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */
struct i915_texture {
struct pipe_texture base;
/* Derived from the above:
*/
unsigned stride;
unsigned depth_stride; /* per-image on i945? */
unsigned total_nblocksy;
unsigned sw_tiled; /**< tiled with software flags */
unsigned hw_tiled; /**< tiled with hardware fences */
unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS];
/* Explicitly store the offset of each image for each cube face or
* depth value. Pretty much have to accept that hardware formats
* are going to be so diverse that there is no unified way to
* compute the offsets of depth/cube images within a mipmap level,
* so have to store them as a lookup table:
*/
unsigned *image_offset[I915_MAX_TEXTURE_2D_LEVELS]; /**< array [depth] of offsets */
/* The data is held here:
*/
struct intel_buffer *buffer;
};
struct i915_context
{
......@@ -243,7 +214,7 @@ struct i915_context
struct pipe_stencil_ref stencil_ref;
struct pipe_clip_state clip;
/* XXX unneded */
struct pipe_buffer *constants[PIPE_SHADER_TYPES];
struct pipe_resource *constants[PIPE_SHADER_TYPES];
struct pipe_framebuffer_state framebuffer;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
......@@ -333,10 +304,8 @@ void i915_clear( struct pipe_context *pipe, unsigned buffers, const float *rgba,
/***********************************************************************
* i915_surface.c:
*
*/
void i915_init_surface_functions( struct i915_context *i915 );
void i915_init_state_functions( struct i915_context *i915 );
void i915_init_flush_functions( struct i915_context *i915 );
void i915_init_string_functions( struct i915_context *i915 );
......@@ -349,10 +318,6 @@ struct pipe_context *i915_create_context(struct pipe_screen *screen,
void *priv);
/***********************************************************************
* i915_texture.c
*/
void i915_init_texture_functions(struct i915_context *i915 );
/***********************************************************************
......
#include "util/u_debug.h"
#include "i915_resource.h"
#include "i915_context.h"
#include "i915_screen.h"
static struct pipe_resource *
i915_resource_create(struct pipe_screen *screen,
const struct pipe_resource *template)
{
if (template->target == PIPE_BUFFER)
return i915_buffer_create(screen, template);
else
return i915_texture_create(screen, template);
}
static struct pipe_resource *
i915_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 i915_texture_from_handle(screen, template, whandle);
}
void
i915_init_resource_functions(struct i915_context *i915 )
{
i915->base.get_transfer = u_get_transfer_vtbl;
i915->base.transfer_map = u_transfer_map_vtbl;
i915->base.transfer_flush_region = u_transfer_flush_region_vtbl;
i915->base.transfer_unmap = u_transfer_unmap_vtbl;
i915->base.transfer_destroy = u_transfer_destroy_vtbl;
i915->base.transfer_inline_write = u_transfer_inline_write_vtbl;
}
void
i915_init_screen_resource_functions(struct i915_screen *is)
{
is->base.resource_create = i915_resource_create;
is->base.resource_from_handle = i915_resource_from_handle;
is->base.resource_get_handle = u_resource_get_handle_vtbl;
is->base.resource_destroy = u_resource_destroy_vtbl;
}
/**************************************************************************
*
* 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 I915_RESOURCE_H
#define I915_RESOURCE_H
struct i915_screen;
#include "util/u_transfer.h"
#include "util/u_debug.h"
struct i915_context;
struct i915_screen;
struct i915_buffer {
struct u_resource b;
uint8_t *data;
boolean free_on_destroy;
};
#define I915_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */
#define I915_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */
struct i915_texture {
struct u_resource b;
unsigned stride;
unsigned depth_stride; /* per-image on i945? */
unsigned total_nblocksy;
unsigned sw_tiled; /**< tiled with software flags */
unsigned hw_tiled; /**< tiled with hardware fences */
unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS];
/* Explicitly store the offset of each image for each cube face or
* depth value.
*/
unsigned *image_offset[I915_MAX_TEXTURE_2D_LEVELS]; /**< array [depth] of offsets */
/* The data is held here:
*/
struct intel_buffer *buffer;
};
void i915_init_screen_resource_functions(struct i915_screen *is);
void i915_init_resource_functions(struct i915_context *i915 );
extern struct u_resource_vtbl i915_buffer_vtbl;
extern struct u_resource_vtbl i915_texture_vtbl;
static INLINE struct i915_texture *i915_texture( struct pipe_resource *resource )
{
struct i915_texture *tex = (struct i915_texture *)resource;
assert(tex->b.vtbl == &i915_texture_vtbl);
return tex;
}
static INLINE struct i915_buffer *i915_buffer( struct pipe_resource *resource )
{
struct i915_buffer *tex = (struct i915_buffer *)resource;
assert(tex->b.vtbl == &i915_buffer_vtbl);
return tex;
}
struct pipe_resource *
i915_texture_create(struct pipe_screen *screen,
const struct pipe_resource *template);
struct pipe_resource *
i915_texture_from_handle(struct pipe_screen * screen,
const struct pipe_resource *template,
struct winsys_handle *whandle);
struct pipe_resource *
i915_user_buffer_create(struct pipe_screen *screen,
void *ptr,
unsigned bytes,
unsigned usage);
struct pipe_resource *
i915_buffer_create(struct pipe_screen *screen,
const struct pipe_resource *template);
#endif /* I915_RESOURCE_H */
/**************************************************************************
*
* Copyright 2006 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.
*
**************************************************************************/
/*
* Authors:
* Keith Whitwell <keith@tungstengraphics.com>
* Michel Dänzer <michel@tungstengraphics.com>
*/
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"