Commit 42642ec0 authored by Keith Whitwell's avatar Keith Whitwell

llvmpipe: convert to pipe_resources

parent 7bbcb21e
......@@ -6,7 +6,6 @@ LIBNAME = llvmpipe
DEFINES += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
C_SOURCES = \
lp_buffer.c \
lp_clear.c \
lp_context.c \
lp_draw_arrays.c \
......
......@@ -28,7 +28,6 @@ env.Depends('lp_tile_soa.c', [
llvmpipe = env.ConvenienceLibrary(
target = 'llvmpipe',
source = [
'lp_buffer.c',
'lp_clear.c',
'lp_context.c',
'lp_draw_arrays.c',
......
/**************************************************************************
*
* Copyright 2009 VMware, Inc.
* 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 VMWARE 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 "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_math.h"
#include "lp_screen.h"
#include "lp_buffer.h"
static void *
llvmpipe_buffer_map(struct pipe_screen *screen,
struct pipe_buffer *buf,
unsigned flags)
{
struct llvmpipe_buffer *llvmpipe_buf = llvmpipe_buffer(buf);
return llvmpipe_buf->data;
}
static void
llvmpipe_buffer_unmap(struct pipe_screen *screen,
struct pipe_buffer *buf)
{
}
static void
llvmpipe_buffer_destroy(struct pipe_buffer *buf)
{
struct llvmpipe_buffer *sbuf = llvmpipe_buffer(buf);
if (!sbuf->userBuffer)
align_free(sbuf->data);
FREE(sbuf);
}
static struct pipe_buffer *
llvmpipe_buffer_create(struct pipe_screen *screen,
unsigned alignment,
unsigned usage,
unsigned size)
{
struct llvmpipe_buffer *buffer = CALLOC_STRUCT(llvmpipe_buffer);
pipe_reference_init(&buffer->base.reference, 1);
buffer->base.screen = screen;
buffer->base.alignment = MAX2(alignment, 16);
buffer->base.usage = usage;
buffer->base.size = size;
buffer->data = align_malloc(size, alignment);
return &buffer->base;
}
/**
* Create buffer which wraps user-space data.
*/
static struct pipe_buffer *
llvmpipe_user_buffer_create(struct pipe_screen *screen,
void *ptr,
unsigned bytes)
{
struct llvmpipe_buffer *buffer;
buffer = CALLOC_STRUCT(llvmpipe_buffer);
if(!buffer)
return NULL;
pipe_reference_init(&buffer->base.reference, 1);
buffer->base.screen = screen;
buffer->base.size = bytes;
buffer->userBuffer = TRUE;
buffer->data = ptr;
return &buffer->base;
}
void
llvmpipe_init_screen_buffer_funcs(struct pipe_screen *screen)
{
screen->buffer_create = llvmpipe_buffer_create;
screen->user_buffer_create = llvmpipe_user_buffer_create;
screen->buffer_map = llvmpipe_buffer_map;
screen->buffer_unmap = llvmpipe_buffer_unmap;
screen->buffer_destroy = llvmpipe_buffer_destroy;
}
/**************************************************************************
*
* Copyright 2009 VMware, Inc.
* 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 VMWARE 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 LP_BUFFER_H
#define LP_BUFFER_H
#include "pipe/p_compiler.h"
#include "pipe/p_state.h"
struct llvmpipe_buffer
{
struct pipe_buffer base;
boolean userBuffer; /** Is this a user-space buffer? */
void *data;
};
/** Cast wrapper */
static INLINE struct llvmpipe_buffer *
llvmpipe_buffer( struct pipe_buffer *buf )
{
return (struct llvmpipe_buffer *)buf;
}
void
llvmpipe_init_screen_buffer_funcs(struct pipe_screen *screen);
#endif /* LP_BUFFER_H */
......@@ -77,29 +77,13 @@ static void llvmpipe_destroy( struct pipe_context *pipe )
for (i = 0; i < Elements(llvmpipe->constants); i++) {
if (llvmpipe->constants[i]) {
pipe_buffer_reference(&llvmpipe->constants[i], NULL);
pipe_resource_reference(&llvmpipe->constants[i], NULL);
}
}
align_free( llvmpipe );
}
static unsigned int
llvmpipe_is_texture_referenced( struct pipe_context *pipe,
struct pipe_texture *texture,
unsigned face, unsigned level)
{
struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
return lp_setup_is_texture_referenced(llvmpipe->setup, texture);
}
static unsigned int
llvmpipe_is_buffer_referenced( struct pipe_context *pipe,
struct pipe_buffer *buf)
{
return PIPE_UNREFERENCED;
}
struct pipe_context *
llvmpipe_create_context( struct pipe_screen *screen, void *priv )
......@@ -171,11 +155,9 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv )
llvmpipe->pipe.clear = llvmpipe_clear;
llvmpipe->pipe.flush = llvmpipe_flush;
llvmpipe->pipe.is_texture_referenced = llvmpipe_is_texture_referenced;
llvmpipe->pipe.is_buffer_referenced = llvmpipe_is_buffer_referenced;
llvmpipe_init_query_funcs( llvmpipe );
llvmpipe_init_context_texture_funcs( &llvmpipe->pipe );
llvmpipe_init_context_resource_funcs( &llvmpipe->pipe );
/*
* Create drawing context and plug our rendering stage into it.
......
......@@ -65,7 +65,7 @@ struct llvmpipe_context {
struct pipe_blend_color blend_color;
struct pipe_stencil_ref stencil_ref;
struct pipe_clip_state clip;
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;
......
......@@ -35,7 +35,6 @@
#include "pipe/p_context.h"
#include "util/u_prim.h"
#include "lp_buffer.h"
#include "lp_context.h"
#include "lp_state.h"
......@@ -58,7 +57,7 @@ llvmpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
*/
void
llvmpipe_draw_range_elements(struct pipe_context *pipe,
struct pipe_buffer *indexBuffer,
struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned min_index,
unsigned max_index,
......@@ -75,13 +74,13 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
* Map vertex buffers
*/
for (i = 0; i < lp->num_vertex_buffers; i++) {
void *buf = llvmpipe_buffer(lp->vertex_buffer[i].buffer)->data;
void *buf = llvmpipe_resource(lp->vertex_buffer[i].buffer)->data;
draw_set_mapped_vertex_buffer(draw, i, buf);
}
/* Map index buffer, if present */
if (indexBuffer) {
void *mapped_indexes = llvmpipe_buffer(indexBuffer)->data;
void *mapped_indexes = llvmpipe_resource(indexBuffer)->data;
draw_set_mapped_element_buffer_range(draw, indexSize,
min_index,
max_index,
......@@ -117,7 +116,7 @@ llvmpipe_draw_range_elements(struct pipe_context *pipe,
void
llvmpipe_draw_elements(struct pipe_context *pipe,
struct pipe_buffer *indexBuffer,
struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
......
......@@ -63,9 +63,9 @@ lp_rast_begin( struct lp_rasterizer *rast,
for (i = 0; i < rast->state.nr_cbufs; i++) {
rast->cbuf[i].map = scene->cbuf_map[i];
rast->cbuf[i].format = scene->cbuf_transfer[i]->texture->format;
rast->cbuf[i].width = scene->cbuf_transfer[i]->width;
rast->cbuf[i].height = scene->cbuf_transfer[i]->height;
rast->cbuf[i].format = scene->cbuf_transfer[i]->resource->format;
rast->cbuf[i].width = scene->cbuf_transfer[i]->box.width;
rast->cbuf[i].height = scene->cbuf_transfer[i]->box.height;
rast->cbuf[i].stride = scene->cbuf_transfer[i]->stride;
}
......@@ -73,7 +73,7 @@ lp_rast_begin( struct lp_rasterizer *rast,
rast->zsbuf.map = scene->zsbuf_map;
rast->zsbuf.stride = scene->zsbuf_transfer->stride;
rast->zsbuf.blocksize =
util_format_get_blocksize(scene->zsbuf_transfer->texture->format);
util_format_get_blocksize(scene->zsbuf_transfer->resource->format);
}
lp_scene_bin_iter_begin( scene );
......
......@@ -181,7 +181,7 @@ lp_scene_reset(struct lp_scene *scene )
struct texture_ref *ref, *next, *ref_list = &scene->textures;
for (ref = ref_list->next; ref != ref_list; ref = next) {
next = next_elem(ref);
pipe_texture_reference(&ref->texture, NULL);
pipe_resource_reference(&ref->texture, NULL);
FREE(ref);
}
make_empty_list(ref_list);
......@@ -248,12 +248,12 @@ lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y )
*/
void
lp_scene_texture_reference( struct lp_scene *scene,
struct pipe_texture *texture )
struct pipe_resource *texture )
{
struct texture_ref *ref = CALLOC_STRUCT(texture_ref);
if (ref) {
struct texture_ref *ref_list = &scene->textures;
pipe_texture_reference(&ref->texture, texture);
pipe_resource_reference(&ref->texture, texture);
insert_at_tail(ref_list, ref);
}
}
......@@ -263,8 +263,8 @@ lp_scene_texture_reference( struct lp_scene *scene,
* Does this scene have a reference to the given texture?
*/
boolean
lp_scene_is_texture_referenced( const struct lp_scene *scene,
const struct pipe_texture *texture )
lp_scene_is_resource_referenced( const struct lp_scene *scene,
const struct pipe_resource *texture )
{
const struct texture_ref *ref_list = &scene->textures;
const struct texture_ref *ref;
......
......@@ -99,7 +99,7 @@ struct data_block_list {
/** List of texture references */
struct texture_ref {
struct pipe_texture *texture;
struct pipe_resource *texture;
struct texture_ref *prev, *next; /**< linked list w/ u_simple_list.h */
};
......@@ -170,10 +170,10 @@ unsigned lp_scene_data_size( const struct lp_scene *scene );
unsigned lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y );
void lp_scene_texture_reference( struct lp_scene *scene,
struct pipe_texture *texture );
struct pipe_resource *texture );
boolean lp_scene_is_texture_referenced( const struct lp_scene *scene,
const struct pipe_texture *texture );
boolean lp_scene_is_resource_referenced( const struct lp_scene *scene,
const struct pipe_resource *texture );
/**
......
......@@ -32,7 +32,6 @@
#include "pipe/p_screen.h"
#include "lp_texture.h"
#include "lp_buffer.h"
#include "lp_fence.h"
#include "lp_jit.h"
#include "lp_screen.h"
......@@ -249,7 +248,7 @@ llvmpipe_flush_frontbuffer(struct pipe_screen *_screen,
{
struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
struct sw_winsys *winsys = screen->winsys;
struct llvmpipe_texture *texture = llvmpipe_texture(surface->texture);
struct llvmpipe_resource *texture = llvmpipe_resource(surface->texture);
assert(texture->dt);
if (texture->dt)
......@@ -302,8 +301,7 @@ llvmpipe_create_screen(struct sw_winsys *winsys)
screen->base.context_create = llvmpipe_create_context;
screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer;
llvmpipe_init_screen_texture_funcs(&screen->base);
llvmpipe_init_screen_buffer_funcs(&screen->base);
llvmpipe_init_screen_resource_funcs(&screen->base);
llvmpipe_init_screen_fence_funcs(&screen->base);
lp_jit_screen_init(screen);
......
......@@ -39,7 +39,6 @@
#include "util/u_surface.h"
#include "lp_scene.h"
#include "lp_scene_queue.h"
#include "lp_buffer.h"
#include "lp_texture.h"
#include "lp_debug.h"
#include "lp_fence.h"
......@@ -379,11 +378,11 @@ lp_setup_set_fs_functions( struct lp_setup_context *setup,
void
lp_setup_set_fs_constants(struct lp_setup_context *setup,
struct pipe_buffer *buffer)
struct pipe_resource *buffer)
{
LP_DBG(DEBUG_SETUP, "%s %p\n", __FUNCTION__, (void *) buffer);
pipe_buffer_reference(&setup->constants.current, buffer);
pipe_resource_reference(&setup->constants.current, buffer);
setup->dirty |= LP_SETUP_NEW_CONSTANTS;
}
......@@ -467,8 +466,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
struct pipe_sampler_view *view = i < num ? views[i] : NULL;
if(view) {
struct pipe_texture *tex = view->texture;
struct llvmpipe_texture *lp_tex = llvmpipe_texture(tex);
struct pipe_resource *tex = view->texture;
struct llvmpipe_resource *lp_tex = llvmpipe_resource(tex);
struct lp_jit_texture *jit_tex;
jit_tex = &setup->fs.current.jit_context.textures[i];
jit_tex->width = tex->width0;
......@@ -516,8 +515,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
* being rendered and the current scene being built.
*/
unsigned
lp_setup_is_texture_referenced( const struct lp_setup_context *setup,
const struct pipe_texture *texture )
lp_setup_is_resource_referenced( const struct lp_setup_context *setup,
const struct pipe_resource *texture )
{
unsigned i;
......@@ -532,7 +531,7 @@ lp_setup_is_texture_referenced( const struct lp_setup_context *setup,
/* check textures referenced by the scene */
for (i = 0; i < Elements(setup->scenes); i++) {
if (lp_scene_is_texture_referenced(setup->scenes[i], texture)) {
if (lp_scene_is_resource_referenced(setup->scenes[i], texture)) {
return PIPE_REFERENCED_FOR_READ;
}
}
......@@ -593,11 +592,11 @@ lp_setup_update_state( struct lp_setup_context *setup )
}
if(setup->dirty & LP_SETUP_NEW_CONSTANTS) {
struct pipe_buffer *buffer = setup->constants.current;
struct pipe_resource *buffer = setup->constants.current;
if(buffer) {
unsigned current_size = buffer->size;
const void *current_data = llvmpipe_buffer(buffer)->data;
unsigned current_size = buffer->width0;
const void *current_data = llvmpipe_resource(buffer)->data;
/* TODO: copy only the actually used constants? */
......@@ -667,7 +666,7 @@ lp_setup_destroy( struct lp_setup_context *setup )
{
reset_context( setup );
pipe_buffer_reference(&setup->constants.current, NULL);
pipe_resource_reference(&setup->constants.current, NULL);
/* free the scenes in the 'empty' queue */
while (1) {
......
......@@ -105,7 +105,7 @@ lp_setup_set_fs_functions( struct lp_setup_context *setup,
void
lp_setup_set_fs_constants(struct lp_setup_context *setup,
struct pipe_buffer *buffer);
struct pipe_resource *buffer);
void
......@@ -126,8 +126,8 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
struct pipe_sampler_view **views);
unsigned
lp_setup_is_texture_referenced( const struct lp_setup_context *setup,
const struct pipe_texture *texture );
lp_setup_is_resource_referenced( const struct lp_setup_context *setup,
const struct pipe_resource *texture );
void
lp_setup_set_flatshade_first( struct lp_setup_context *setup,
......
......@@ -115,7 +115,7 @@ struct lp_setup_context
/** fragment shader constants */
struct {
struct pipe_buffer *current;
struct pipe_resource *current;
unsigned stored_size;
const void *stored_data;
} constants;
......
......@@ -169,7 +169,7 @@ void llvmpipe_set_clip_state( struct pipe_context *,
void llvmpipe_set_constant_buffer(struct pipe_context *,
uint shader, uint index,
struct pipe_buffer *buf);
struct pipe_resource *buf);
void *llvmpipe_create_fs_state(struct pipe_context *,
const struct pipe_shader_state *);
......@@ -203,7 +203,7 @@ llvmpipe_set_vertex_sampler_views(struct pipe_context *,
struct pipe_sampler_view *
llvmpipe_create_sampler_view(struct pipe_context *pipe,
struct pipe_texture *texture,
struct pipe_resource *texture,
const struct pipe_sampler_view *templ);
void
......@@ -226,12 +226,12 @@ void llvmpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
unsigned start, unsigned count);
void llvmpipe_draw_elements(struct pipe_context *pipe,
struct pipe_buffer *indexBuffer,
struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count);
void
llvmpipe_draw_range_elements(struct pipe_context *pipe,
struct pipe_buffer *indexBuffer,
struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned min_index,
unsigned max_index,
......
......@@ -85,7 +85,6 @@
#include "gallivm/lp_bld_swizzle.h"
#include "gallivm/lp_bld_flow.h"
#include "gallivm/lp_bld_debug.h"
#include "lp_buffer.h"
#include "lp_context.h"
#include "lp_debug.h"
#include "lp_perf.h"
......@@ -1012,11 +1011,11 @@ llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
void
llvmpipe_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
struct pipe_buffer *constants)
struct pipe_resource *constants)
{
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
unsigned size = constants ? constants->size : 0;
const void *data = constants ? llvmpipe_buffer(constants)->data : NULL;
unsigned size = constants ? constants->width0 : 0;
const void *data = constants ? llvmpipe_resource(constants)->data : NULL;
assert(shader < PIPE_SHADER_TYPES);
assert(index == 0);
......@@ -1027,7 +1026,7 @@ llvmpipe_set_constant_buffer(struct pipe_context *pipe,
draw_flush(llvmpipe->draw);
/* note: reference counting */
pipe_buffer_reference(&llvmpipe->constants[shader], constants);
pipe_resource_reference(&llvmpipe->constants[shader], constants);
if(shader == PIPE_SHADER_VERTEX) {
draw_set_mapped_constant_buffer(llvmpipe->draw, PIPE_SHADER_VERTEX, 0,
......
......@@ -165,7 +165,7 @@ llvmpipe_set_vertex_sampler_views(struct pipe_context *pipe,
struct pipe_sampler_view *
llvmpipe_create_sampler_view(struct pipe_context *pipe,
struct pipe_texture *texture,
struct pipe_resource *texture,
const struct pipe_sampler_view *templ)
{
struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view);
......@@ -174,7 +174,7 @@ llvmpipe_create_sampler_view(struct pipe_context *pipe,
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
pipe_texture_reference(&view->texture, texture);
pipe_resource_reference(&view->texture, texture);
view->context = pipe;
}
......@@ -186,7 +186,7 @@ void
llvmpipe_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);
}
......
This diff is collapsed.
......@@ -43,9 +43,9 @@ struct llvmpipe_context;
struct sw_displaytarget;
struct llvmpipe_texture
struct llvmpipe_resource
{
struct pipe_texture base;
struct pipe_resource base;
unsigned long level_offset[LP_MAX_TEXTURE_2D_LEVELS];
unsigned stride[LP_MAX_TEXTURE_2D_LEVELS];
......@@ -61,6 +61,7 @@ struct llvmpipe_texture
*/
void *data;
boolean userBuffer; /** Is this a user-space buffer? */
unsigned timestamp;
};
......@@ -74,17 +75,17 @@ struct llvmpipe_transfer
/** cast wrappers */
static INLINE struct llvmpipe_texture *
llvmpipe_texture(struct pipe_texture *pt)
static INLINE struct llvmpipe_resource *
llvmpipe_resource(struct pipe_resource *pt)
{
return (struct llvmpipe_texture *) pt;
return (struct llvmpipe_resource *) pt;
}
static INLINE const struct llvmpipe_texture *
llvmpipe_texture_const(const struct pipe_texture *pt)
static INLINE const struct llvmpipe_resource *
llvmpipe_resource_const(const struct pipe_resource *pt)
{
return (const struct llvmpipe_texture *) pt;
return (const struct llvmpipe_resource *) pt;
}
......@@ -95,10 +96,7 @@ llvmpipe_transfer(struct pipe_transfer *pt)
}
extern void
llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen);
extern void
llvmpipe_init_context_texture_funcs(struct pipe_context *pipe);
void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen);
void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe);
#endif /* LP_TEXTURE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment