# Gallium directories and
GALLIUM_DIRS = auxiliary drivers state_trackers
GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a
-GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity
+GALLIUM_DRIVERS_DIRS = softpipe trace identity i915 i965 svga r300 nvfx nv50 failover
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
GALLIUM_WINSYS_DIRS = sw sw/xlib
GALLIUM_TARGET_DIRS = libgl-xlib
CONFIG_NAME = linux-debug
OPT_FLAGS = -g
-CFLAGS += -pedantic
+#CFLAGS += -pedantic
DEFINES += -DDEBUG -DDEBUG_MATH
util/u_surface.c \
util/u_texture.c \
util/u_tile.c \
- util/u_timed_winsys.c \
+ util/u_transfer.c \
+ util/u_resource.c \
util/u_upload_mgr.c \
- util/u_simple_screen.c \
target-helpers/wrap_screen.c
# Disabling until pipe-video branch gets merged in
'util/u_math.c',
'util/u_mm.c',
'util/u_rect.c',
+ 'util/u_resource.c',
'util/u_ringbuffer.c',
'util/u_sampler.c',
'util/u_simple_shaders.c',
'util/u_surface.c',
'util/u_texture.c',
'util/u_tile.c',
- 'util/u_timed_winsys.c',
+ 'util/u_transfer.c',
'util/u_upload_mgr.c',
- 'util/u_simple_screen.c',
# Disabling until pipe-video branch gets merged in
#'vl/vl_bitstream_parser.c',
#'vl/vl_mpeg12_mc_renderer.c',
uint pos_slot;
void *sampler_cso;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_sampler_view *sampler_view;
uint num_samplers;
uint num_sampler_views;
{
struct pipe_context *pipe = aaline->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture texTemp;
+ struct pipe_resource texTemp;
struct pipe_sampler_view viewTempl;
uint level;
texTemp.height0 = 1 << MAX_TEXTURE_LEVEL;
texTemp.depth0 = 1;
- aaline->texture = screen->texture_create(screen, &texTemp);
+ aaline->texture = screen->resource_create(screen, &texTemp);
if (!aaline->texture)
return FALSE;
*/
for (level = 0; level <= MAX_TEXTURE_LEVEL; level++) {
struct pipe_transfer *transfer;
+ struct pipe_box box;
const uint size = u_minify(aaline->texture->width0, level);
ubyte *data;
uint i, j;
assert(aaline->texture->width0 == aaline->texture->height0);
+ u_box_origin_2d( size, size, &box );
+
/* This texture is new, no need to flush.
*/
- transfer = pipe->get_tex_transfer(pipe, aaline->texture, 0, level, 0,
- PIPE_TRANSFER_WRITE, 0, 0, size, size);
+ transfer = pipe->get_transfer(pipe,
+ aaline->texture,
+ u_subresource(0, level),
+ PIPE_TRANSFER_WRITE,
+ &box);
+
data = pipe->transfer_map(pipe, transfer);
if (data == NULL)
return FALSE;
/* unmap */
pipe->transfer_unmap(pipe, transfer);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
return TRUE;
}
aaline->pipe->delete_sampler_state(aaline->pipe, aaline->sampler_cso);
if (aaline->texture)
- pipe_texture_reference(&aaline->texture, NULL);
+ pipe_resource_reference(&aaline->texture, NULL);
if (aaline->sampler_view) {
pipe_sampler_view_reference(&aaline->sampler_view, NULL);
struct draw_stage stage;
void *sampler_cso;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_sampler_view *sampler_view;
uint num_samplers;
uint num_sampler_views;
*/
pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL );
- transfer = pipe->get_tex_transfer(pipe, pstip->texture, 0, 0, 0,
- PIPE_TRANSFER_WRITE, 0, 0, 32, 32);
+ transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0, 0,
+ PIPE_TRANSFER_WRITE, 0, 0, 32, 32);
data = pipe->transfer_map(pipe, transfer);
/*
/* unmap */
pipe->transfer_unmap(pipe, transfer);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
{
struct pipe_context *pipe = pstip->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture texTemp;
+ struct pipe_resource texTemp;
struct pipe_sampler_view viewTempl;
memset(&texTemp, 0, sizeof(texTemp));
texTemp.height0 = 32;
texTemp.depth0 = 1;
- pstip->texture = screen->texture_create(screen, &texTemp);
+ pstip->texture = screen->resource_create(screen, &texTemp);
if (pstip->texture == NULL)
return FALSE;
pstip->pipe->delete_sampler_state(pstip->pipe, pstip->sampler_cso);
- pipe_texture_reference(&pstip->texture, NULL);
+ pipe_resource_reference(&pstip->texture, NULL);
if (pstip->sampler_view) {
pipe_sampler_view_reference(&pstip->sampler_view, NULL);
*/
void
lp_sampler_static_state(struct lp_sampler_static_state *state,
- const struct pipe_texture *texture,
+ const struct pipe_resource *texture,
const struct pipe_sampler_state *sampler)
{
memset(state, 0, sizeof *state);
#include "gallivm/lp_bld.h"
-struct pipe_texture;
+struct pipe_resource;
struct pipe_sampler_state;
struct util_format_description;
struct lp_type;
/**
* Sampler static state.
*
- * These are the bits of state from pipe_texture and pipe_sampler_state that
+ * These are the bits of state from pipe_resource and pipe_sampler_state that
* are embedded in the generated code.
*/
struct lp_sampler_static_state
/**
* Sampler dynamic state.
*
- * These are the bits of state from pipe_texture and pipe_sampler_state that
+ * These are the bits of state from pipe_resource and pipe_sampler_state that
* are computed in runtime.
*
* There are obtained through callbacks, as we don't want to tie the texture
*/
void
lp_sampler_static_state(struct lp_sampler_static_state *state,
- const struct pipe_texture *texture,
+ const struct pipe_resource *texture,
const struct pipe_sampler_state *sampler);
#include "util/u_debug.h"
#include "util/u_inlines.h"
#include "pipe/p_defines.h"
-#include "pipe/p_state.h"
#ifdef __cplusplus
struct pb_vtbl;
struct pb_validate;
+struct pipe_fence_handle;
+#define PB_USAGE_CPU_READ (1 << 0)
+#define PB_USAGE_CPU_WRITE (1 << 1)
+#define PB_USAGE_GPU_READ (1 << 2)
+#define PB_USAGE_GPU_WRITE (1 << 3)
+#define PB_USAGE_UNSYNCHRONIZED (1 << 10)
+#define PB_USAGE_DONTBLOCK (1 << 9)
+
+#define PB_USAGE_CPU_READ_WRITE \
+ ( PB_USAGE_CPU_READ | PB_USAGE_CPU_WRITE )
+#define PB_USAGE_GPU_READ_WRITE \
+ ( PB_USAGE_GPU_READ | PB_USAGE_GPU_WRITE )
+#define PB_USAGE_WRITE \
+ ( PB_USAGE_CPU_WRITE | PB_USAGE_GPU_WRITE )
+
/**
* Buffer description.
*
*/
struct pb_buffer
{
- struct pipe_buffer base;
+ /* This used to be a pipe_buffer struct:
+ */
+ struct {
+ struct pipe_reference reference;
+ unsigned size;
+ unsigned alignment;
+ unsigned usage;
+ } base;
/**
* Pointer to the virtual function table.
/**
* Map the entire data store of a buffer object into the client's address.
- * flags is bitmask of PIPE_BUFFER_FLAG_READ/WRITE.
+ * flags is bitmask of PB_USAGE_CPU_READ/WRITE.
*/
void *(*map)( struct pb_buffer *buf,
unsigned flags );
};
-static INLINE struct pipe_buffer *
-pb_pipe_buffer( struct pb_buffer *pbuf )
-{
- assert(pbuf);
- return &pbuf->base;
-}
-
-
-static INLINE struct pb_buffer *
-pb_buffer( struct pipe_buffer *buf )
-{
- assert(buf);
- /* Could add a magic cookie check on debug builds.
- */
- return (struct pb_buffer *)buf;
-}
-
/* Accessor functions for pb->vtbl:
*/
void *data;
/**
- * A bitmask of PIPE_BUFFER_USAGE_CPU/GPU_READ/WRITE describing the current
+ * A bitmask of PB_USAGE_CPU/GPU_READ/WRITE describing the current
* buffer usage.
*/
unsigned flags;
struct fenced_buffer *fenced_buf)
{
assert(pipe_is_referenced(&fenced_buf->base.base.reference));
- assert(fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE);
+ assert(fenced_buf->flags & PB_USAGE_GPU_READ_WRITE);
assert(fenced_buf->fence);
p_atomic_inc(&fenced_buf->base.base.reference.count);
assert(fenced_buf->mgr == fenced_mgr);
ops->fence_reference(ops, &fenced_buf->fence, NULL);
- fenced_buf->flags &= ~PIPE_BUFFER_USAGE_GPU_READ_WRITE;
+ fenced_buf->flags &= ~PB_USAGE_GPU_READ_WRITE;
assert(fenced_buf->head.prev);
assert(fenced_buf->head.next);
assert(!destroyed);
- fenced_buf->flags &= ~PIPE_BUFFER_USAGE_GPU_READ_WRITE;
+ fenced_buf->flags &= ~PB_USAGE_GPU_READ_WRITE;
ret = PIPE_OK;
}
assert(fenced_buf->data);
assert(fenced_buf->buffer);
- map = pb_map(fenced_buf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE);
+ map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_WRITE);
if(!map)
return PIPE_ERROR;
assert(fenced_buf->data);
assert(fenced_buf->buffer);
- map = pb_map(fenced_buf->buffer, PIPE_BUFFER_USAGE_CPU_READ);
+ map = pb_map(fenced_buf->buffer, PB_USAGE_CPU_READ);
if(!map)
return PIPE_ERROR;
pipe_mutex_lock(fenced_mgr->mutex);
- assert(!(flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE));
+ assert(!(flags & PB_USAGE_GPU_READ_WRITE));
/*
* Serialize writes.
*/
- while((fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_WRITE) ||
- ((fenced_buf->flags & PIPE_BUFFER_USAGE_GPU_READ) &&
- (flags & PIPE_BUFFER_USAGE_CPU_WRITE))) {
+ while((fenced_buf->flags & PB_USAGE_GPU_WRITE) ||
+ ((fenced_buf->flags & PB_USAGE_GPU_READ) &&
+ (flags & PB_USAGE_CPU_WRITE))) {
/*
* Don't wait for the GPU to finish accessing it, if blocking is forbidden.
*/
- if((flags & PIPE_BUFFER_USAGE_DONTBLOCK) &&
+ if((flags & PB_USAGE_DONTBLOCK) &&
ops->fence_signalled(ops, fenced_buf->fence, 0) != 0) {
goto done;
}
- if (flags & PIPE_BUFFER_USAGE_UNSYNCHRONIZED) {
+ if (flags & PB_USAGE_UNSYNCHRONIZED) {
break;
}
if(map) {
++fenced_buf->mapcount;
- fenced_buf->flags |= flags & PIPE_BUFFER_USAGE_CPU_READ_WRITE;
+ fenced_buf->flags |= flags & PB_USAGE_CPU_READ_WRITE;
}
done:
pb_unmap(fenced_buf->buffer);
--fenced_buf->mapcount;
if(!fenced_buf->mapcount)
- fenced_buf->flags &= ~PIPE_BUFFER_USAGE_CPU_READ_WRITE;
+ fenced_buf->flags &= ~PB_USAGE_CPU_READ_WRITE;
}
pipe_mutex_unlock(fenced_mgr->mutex);
goto done;
}
- assert(flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE);
- assert(!(flags & ~PIPE_BUFFER_USAGE_GPU_READ_WRITE));
- flags &= PIPE_BUFFER_USAGE_GPU_READ_WRITE;
+ assert(flags & PB_USAGE_GPU_READ_WRITE);
+ assert(!(flags & ~PB_USAGE_GPU_READ_WRITE));
+ flags &= PB_USAGE_GPU_READ_WRITE;
/* Buffer cannot be validated in two different lists */
if(fenced_buf->vl && fenced_buf->vl != vl) {
#endif
-struct pipe_buffer;
struct pipe_fence_handle;
return NULL;
pipe_reference_init(&buf->base.base.reference, 1);
- buf->base.base.alignment = desc->alignment;
buf->base.base.usage = desc->usage;
buf->base.base.size = size;
+ buf->base.base.alignment = desc->alignment;
buf->base.vtbl = &malloc_buffer_vtbl;
buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment);
struct pb_desc;
-struct pipe_buffer;
/**
if(!pb_check_usage(desc->usage, buf->base.base.usage))
return FALSE;
- map = pb_map(buf->buffer, PIPE_BUFFER_USAGE_DONTBLOCK);
+ map = pb_map(buf->buffer, PB_USAGE_DONTBLOCK);
if (!map) {
return FALSE;
}
{
uint8_t *map;
- map = pb_map(buf->buffer, PIPE_BUFFER_USAGE_CPU_WRITE);
+ map = pb_map(buf->buffer, PB_USAGE_CPU_WRITE);
assert(map);
if(map) {
fill_random_pattern(map, buf->underflow_size);
uint8_t *map;
map = pb_map(buf->buffer,
- PIPE_BUFFER_USAGE_CPU_READ |
- PIPE_BUFFER_USAGE_UNSYNCHRONIZED);
+ PB_USAGE_CPU_READ |
+ PB_USAGE_UNSYNCHRONIZED);
assert(map);
if(map) {
boolean underflow, overflow;
real_size = mgr->underflow_size + size + mgr->overflow_size;
real_desc = *desc;
- real_desc.usage |= PIPE_BUFFER_USAGE_CPU_WRITE;
- real_desc.usage |= PIPE_BUFFER_USAGE_CPU_READ;
+ real_desc.usage |= PB_USAGE_CPU_WRITE;
+ real_desc.usage |= PB_USAGE_CPU_READ;
buf->buffer = mgr->provider->create_buffer(mgr->provider,
real_size,
mm->buffer = buffer;
mm->map = pb_map(mm->buffer,
- PIPE_BUFFER_USAGE_CPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE);
+ PB_USAGE_CPU_READ |
+ PB_USAGE_CPU_WRITE);
if(!mm->map)
goto failure;
if(!buf->buffer)
return PIPE_ERROR_OUT_OF_MEMORY;
- map = pb_map(buf->buffer, PIPE_BUFFER_USAGE_CPU_READ);
+ map = pb_map(buf->buffer, PB_USAGE_CPU_READ);
if(!map) {
pb_reference(&buf->buffer, NULL);
return PIPE_ERROR;
goto failure;
pool->map = pb_map(pool->buffer,
- PIPE_BUFFER_USAGE_CPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE);
+ PB_USAGE_CPU_READ |
+ PB_USAGE_CPU_WRITE);
if(!pool->map)
goto failure;
/* Note down the slab virtual address. All mappings are accessed directly
* through this address so it is required that the buffer is pinned. */
slab->virtual = pb_map(slab->bo,
- PIPE_BUFFER_USAGE_CPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE);
+ PB_USAGE_CPU_READ |
+ PB_USAGE_CPU_WRITE);
if(!slab->virtual) {
ret = PIPE_ERROR_OUT_OF_MEMORY;
goto out_err1;
if(!buf)
return PIPE_ERROR;
- assert(flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE);
- assert(!(flags & ~PIPE_BUFFER_USAGE_GPU_READ_WRITE));
- flags &= PIPE_BUFFER_USAGE_GPU_READ_WRITE;
+ assert(flags & PB_USAGE_GPU_READ_WRITE);
+ assert(!(flags & ~PB_USAGE_GPU_READ_WRITE));
+ flags &= PB_USAGE_GPU_READ_WRITE;
/* We only need to store one reference for each buffer, so avoid storing
* consecutive references for the same buffer. It might not be the most
void *vs;
void *fs[TGSI_WRITEMASK_XYZW + 1];
- struct pipe_buffer *vbuf; /**< quad vertices */
+ struct pipe_resource *vbuf; /**< quad vertices */
unsigned vbuf_slot;
float vertices[4][2][4]; /**< vertex/texcoords for quad */
if (ctx->fs[i])
pipe->delete_fs_state(pipe, ctx->fs[i]);
- pipe_buffer_reference(&ctx->vbuf, NULL);
+ pipe_resource_reference(&ctx->vbuf, NULL);
FREE(ctx);
}
if (!ctx->vbuf) {
ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
- 32,
- PIPE_BUFFER_USAGE_VERTEX,
+ PIPE_BIND_VERTEX_BUFFER,
max_slots * sizeof ctx->vertices);
}
offset = get_next_slot( ctx );
- pipe_buffer_write_nooverlap(ctx->pipe->screen, ctx->vbuf,
+ pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf,
offset, sizeof(ctx->vertices), ctx->vertices);
return offset;
filter == PIPE_TEX_MIPFILTER_LINEAR);
assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0));
+ PIPE_BIND_SAMPLER_VIEW, 0));
assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
+ PIPE_BIND_RENDER_TARGET, 0));
/* do the regions overlap? */
overlap = util_same_surface(src, dst) &&
}
assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
+ PIPE_BIND_RENDER_TARGET, 0));
/* Create a temporary texture when src and dest alias or when src
* is anything other than a single-level 2d texture.
src->texture->target != PIPE_TEXTURE_2D ||
src->texture->last_level != 0)
{
- struct pipe_texture texTemp;
- struct pipe_texture *tex;
+ struct pipe_resource texTemp;
+ struct pipe_resource *tex;
struct pipe_sampler_view sv_templ;
struct pipe_surface *texSurf;
const int srcLeft = MIN2(srcX0, srcX1);
texTemp.height0 = srcH;
texTemp.depth0 = 1;
- tex = screen->texture_create(screen, &texTemp);
+ tex = screen->resource_create(screen, &texTemp);
if (!tex)
return;
sampler_view = ctx->pipe->create_sampler_view(ctx->pipe, tex, &sv_templ);
if (!sampler_view) {
- pipe_texture_reference(&tex, NULL);
+ pipe_resource_reference(&tex, NULL);
return;
}
texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
/* load temp texture */
if (pipe->surface_copy) {
t0 = 0.0f;
t1 = 1.0f;
- pipe_texture_reference(&tex, NULL);
+ pipe_resource_reference(&tex, NULL);
}
else {
pipe_sampler_view_reference(&sampler_view, src_sampler_view);
*/
void util_blit_flush( struct blit_state *ctx )
{
- pipe_buffer_reference(&ctx->vbuf, NULL);
+ pipe_resource_reference(&ctx->vbuf, NULL);
ctx->vbuf_slot = 0;
}
struct pipe_framebuffer_state fb;
float s0, t0, s1, t1;
unsigned offset;
- struct pipe_texture *tex = src_sampler_view->texture;
+ struct pipe_resource *tex = src_sampler_view->texture;
assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
filter == PIPE_TEX_MIPFILTER_LINEAR);
assert(ctx->pipe->screen->is_format_supported(ctx->pipe->screen, dst->format,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET,
+ PIPE_BIND_RENDER_TARGET,
0));
/* save state (restored below) */
struct pipe_context;
struct pipe_surface;
-struct pipe_texture;
+struct pipe_resource;
struct cso_context;
struct blitter_context blitter;
struct pipe_context *pipe; /**< pipe context */
- struct pipe_buffer *vbuf; /**< quad */
+ struct pipe_resource *vbuf; /**< quad */
float vertices[4][2][4]; /**< {pos, color} or {pos, texcoord} */
/* create the vertex buffer */
ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
- 32,
- PIPE_BUFFER_USAGE_VERTEX,
+ PIPE_BIND_VERTEX_BUFFER,
sizeof(ctx->vertices));
return &ctx->blitter;
pipe_sampler_view_reference(&ctx->sampler_view, NULL);
}
- pipe_buffer_reference(&ctx->vbuf, NULL);
+ pipe_resource_reference(&ctx->vbuf, NULL);
FREE(ctx);
}
struct pipe_context *pipe = ctx->pipe;
/* write vertices and draw them */
- pipe_buffer_write(pipe->screen, ctx->vbuf,
+ pipe_buffer_write(pipe, ctx->vbuf,
0, sizeof(ctx->vertices), ctx->vertices);
util_draw_vertex_buffer(pipe, ctx->vbuf, 0, PIPE_PRIM_TRIANGLE_FAN,
struct pipe_context *pipe = ctx->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture texTemp;
- struct pipe_texture *texture;
+ struct pipe_resource texTemp;
+ struct pipe_resource *texture;
struct pipe_surface *tex_surf;
/* check whether the states are properly saved */
texTemp.height0 = height;
texTemp.depth0 = 1;
- texture = screen->texture_create(screen, &texTemp);
+ texture = screen->resource_create(screen, &texTemp);
if (!texture)
return;
tex_surf = screen->get_tex_surface(screen, texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION);
/* blit from the src to the temp */
util_blitter_do_copy(blitter, tex_surf, 0, 0,
width, height,
FALSE);
pipe_surface_reference(&tex_surf, NULL);
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&texture, NULL);
blitter_restore_CSOs(ctx);
}
is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0;
is_stencil = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 1) != 0;
- dst_tex_usage = is_depth || is_stencil ? PIPE_TEXTURE_USAGE_DEPTH_STENCIL :
- PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ dst_tex_usage = is_depth || is_stencil ? PIPE_BIND_DEPTH_STENCIL :
+ PIPE_BIND_RENDER_TARGET;
/* check if we can sample from and render to the surfaces */
/* (assuming copying a stencil buffer is not possible) */
!screen->is_format_supported(screen, dst->format, dst->texture->target,
dst_tex_usage, 0) ||
!screen->is_format_supported(screen, src->format, src->texture->target,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
util_surface_copy(pipe, FALSE, dst, dstx, dsty, src, srcx, srcy,
width, height);
return;
/* check if we can render to the surface */
if (util_format_is_depth_or_stencil(dst->format) || /* unlikely, but you never know */
!screen->is_format_supported(screen, dst->format, dst->texture->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ PIPE_BIND_RENDER_TARGET, 0)) {
util_surface_fill(pipe, dst, dstx, dsty, width, height, value);
return;
}
--- /dev/null
+#ifndef UTIL_BOX_INLINES_H
+#define UTIL_BOX_INLINES_H
+
+#include "pipe/p_state.h"
+
+static INLINE
+void u_box_1d( unsigned x,
+ unsigned w,
+ struct pipe_box *box )
+{
+ box->x = x;
+ box->y = 0;
+ box->z = 0;
+ box->width = w;
+ box->height = 1;
+ box->depth = 1;
+}
+
+static INLINE
+void u_box_2d( unsigned x,
+ unsigned y,
+ unsigned w,
+ unsigned h,
+ struct pipe_box *box )
+{
+ box->x = x;
+ box->y = y;
+ box->z = 0;
+ box->width = w;
+ box->height = h;
+ box->depth = 1;
+}
+
+static INLINE
+void u_box_origin_2d( unsigned w,
+ unsigned h,
+ struct pipe_box *box )
+{
+ box->x = 0;
+ box->y = 0;
+ box->z = 0;
+ box->width = w;
+ box->height = h;
+ box->depth = 1;
+}
+
+static INLINE
+void u_box_2d_zslice( unsigned x,
+ unsigned y,
+ unsigned z,
+ unsigned w,
+ unsigned h,
+ struct pipe_box *box )
+{
+ box->x = x;
+ box->y = y;
+ box->z = z;
+ box->width = w;
+ box->height = h;
+ box->depth = 1;
+}
+
+static INLINE
+struct pipe_subresource u_subresource( unsigned face,
+ unsigned level )
+{
+ struct pipe_subresource subresource;
+ subresource.face = face;
+ subresource.level = level;
+ return subresource;
+}
+
+#endif
const char *prefix,
struct pipe_surface *surface)
{
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_transfer *transfer;
void *data;
*/
texture = surface->texture;
- transfer = pipe->get_tex_transfer(pipe, texture, surface->face,
+ transfer = pipe_get_transfer(pipe, texture, surface->face,
surface->level, surface->zslice,
PIPE_TRANSFER_READ, 0, 0, surface->width,
surface->height);
debug_dump_image(prefix,
texture->format,
util_format_get_blocksize(texture->format),
- util_format_get_nblocksx(texture->format, transfer->width),
- util_format_get_nblocksy(texture->format, transfer->height),
+ util_format_get_nblocksx(texture->format, surface->width),
+ util_format_get_nblocksy(texture->format, surface->height),
transfer->stride,
data);
pipe->transfer_unmap(pipe, transfer);
error:
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
void debug_dump_texture(struct pipe_context *pipe,
const char *prefix,
- struct pipe_texture *texture)
+ struct pipe_resource *texture)
{
struct pipe_surface *surface;
struct pipe_screen *screen;
/* XXX for now, just dump image for face=0, level=0 */
surface = screen->get_tex_surface(screen, texture, 0, 0, 0,
- PIPE_TEXTURE_USAGE_SAMPLER);
+ PIPE_BIND_SAMPLER_VIEW);
if (surface) {
debug_dump_surface(pipe, prefix, surface);
screen->tex_surface_destroy(surface);
{
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
struct pipe_transfer *transfer;
- struct pipe_texture *texture = surface->texture;
+ struct pipe_resource *texture = surface->texture;
- transfer = pipe->get_tex_transfer(pipe, texture, surface->face,
- surface->level, surface->zslice,
- PIPE_TRANSFER_READ, 0, 0, surface->width,
- surface->height);
+ transfer = pipe_get_transfer(pipe, texture, surface->face,
+ surface->level, surface->zslice,
+ PIPE_TRANSFER_READ, 0, 0, surface->width,
+ surface->height);
debug_dump_transfer_bmp(pipe, filename, transfer);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
#endif
}
if (!transfer)
goto error1;
- rgba = MALLOC(transfer->width*transfer->height*4*sizeof(float));
+ rgba = MALLOC(transfer->box.width *
+ transfer->box.height *
+ transfer->box.depth *
+ 4*sizeof(float));
if(!rgba)
goto error1;
pipe_get_tile_rgba(pipe, transfer, 0, 0,
- transfer->width, transfer->height,
+ transfer->box.width, transfer->box.height,
rgba);
debug_dump_float_rgba_bmp(filename,
- transfer->width, transfer->height,
- rgba, transfer->width);
+ transfer->box.width, transfer->box.height,
+ rgba, transfer->box.width);
FREE(rgba);
error1:
struct pipe_context;
struct pipe_surface;
struct pipe_transfer;
-struct pipe_texture;
+struct pipe_resource;
void debug_dump_image(const char *prefix,
unsigned format, unsigned cpp,
struct pipe_surface *surface);
void debug_dump_texture(struct pipe_context *pipe,
const char *prefix,
- struct pipe_texture *texture);
+ struct pipe_resource *texture);
void debug_dump_surface_bmp(struct pipe_context *pipe,
const char *filename,
struct pipe_surface *surface);
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "util/u_draw_quad.h"
+#include "util/u_memory.h"
/**
*/
void
util_draw_vertex_buffer(struct pipe_context *pipe,
- struct pipe_buffer *vbuf,
+ struct pipe_resource *vbuf,
uint offset,
uint prim_type,
uint num_verts,
/**
* Draw screen-aligned textured quad.
- * Note: this function allocs/destroys a vertex buffer and isn't especially
- * efficient.
+ * Note: this isn't especially efficient.
*/
void
util_draw_texquad(struct pipe_context *pipe,
float x0, float y0, float x1, float y1, float z)
{
- struct pipe_buffer *vbuf;
- uint numAttribs = 2, vertexBytes, i, j;
-
- vertexBytes = 4 * (4 * numAttribs * sizeof(float));
-
- /* XXX create one-time */
- vbuf = pipe_buffer_create(pipe->screen, 32,
- PIPE_BUFFER_USAGE_VERTEX, vertexBytes);
- if (vbuf) {
- float *v = (float *) pipe_buffer_map(pipe->screen, vbuf,
- PIPE_BUFFER_USAGE_CPU_WRITE);
- if (v) {
- /*
- * Load vertex buffer
- */
- for (i = j = 0; i < 4; i++) {
- v[j + 2] = z; /* z */
- v[j + 3] = 1.0; /* w */
- v[j + 6] = 0.0; /* r */
- v[j + 7] = 1.0; /* q */
- j += 8;
- }
-
- v[0] = x0;
- v[1] = y0;
- v[4] = 0.0; /*s*/
- v[5] = 0.0; /*t*/
-
- v[8] = x1;
- v[9] = y0;
- v[12] = 1.0;
- v[13] = 0.0;
-
- v[16] = x1;
- v[17] = y1;
- v[20] = 1.0;
- v[21] = 1.0;
-
- v[24] = x0;
- v[25] = y1;
- v[28] = 0.0;
- v[29] = 1.0;
-
- pipe_buffer_unmap(pipe->screen, vbuf);
- util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2);
- }
-
- pipe_buffer_reference(&vbuf, NULL);
+ uint numAttribs = 2, i, j;
+ uint vertexBytes = 4 * (4 * numAttribs * sizeof(float));
+ struct pipe_resource *vbuf = NULL;
+ uint *v = NULL;
+
+ v = MALLOC(vertexBytes);
+ if (v == NULL)
+ goto out;
+
+ /*
+ * Load vertex buffer
+ */
+ for (i = j = 0; i < 4; i++) {
+ v[j + 2] = z; /* z */
+ v[j + 3] = 1.0; /* w */
+ v[j + 6] = 0.0; /* r */
+ v[j + 7] = 1.0; /* q */
+ j += 8;
}
+
+ v[0] = x0;
+ v[1] = y0;
+ v[4] = 0.0; /*s*/
+ v[5] = 0.0; /*t*/
+
+ v[8] = x1;
+ v[9] = y0;
+ v[12] = 1.0;
+ v[13] = 0.0;
+
+ v[16] = x1;
+ v[17] = y1;
+ v[20] = 1.0;
+ v[21] = 1.0;
+
+ v[24] = x0;
+ v[25] = y1;
+ v[28] = 0.0;
+ v[29] = 1.0;
+
+ vbuf = pipe_user_buffer_create(pipe->screen, v, vertexBytes,
+ PIPE_BIND_VERTEX_BUFFER);
+ if (!vbuf)
+ goto out;
+
+ util_draw_vertex_buffer(pipe, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2);
+
+out:
+ if (vbuf)
+ pipe_resource_reference(&vbuf, NULL);
+
+ if (v)
+ FREE(v);
}
extern "C" {
#endif
-struct pipe_buffer;
+struct pipe_resource;
extern void
util_draw_vertex_buffer(struct pipe_context *pipe,
- struct pipe_buffer *vbuf, uint offset,
+ struct pipe_resource *vbuf, uint offset,
uint num_attribs, uint num_verts, uint prim_type);
void
util_dump_template(struct os_stream *stream,
- const struct pipe_texture *templat);
+ const struct pipe_resource *templat);
void
util_dump_rasterizer_state(struct os_stream *stream,
void
-util_dump_template(struct os_stream *stream, const struct pipe_texture *templat)
+util_dump_template(struct os_stream *stream, const struct pipe_resource *templat)
{
if(!templat) {
util_dump_null(stream);
return;
}
- util_dump_struct_begin(stream, "pipe_texture");
+ util_dump_struct_begin(stream, "pipe_resource");
util_dump_member(stream, int, templat, target);
util_dump_member(stream, format, templat, format);
util_dump_member_end(stream);
util_dump_member(stream, uint, templat, last_level);
- util_dump_member(stream, uint, templat, tex_usage);
+ util_dump_member(stream, uint, templat, _usage);
+ util_dump_member(stream, uint, templat, bind);
+ util_dump_member(stream, uint, templat, flags);
util_dump_struct_end(stream);
}
util_dump_struct_begin(stream, "pipe_transfer");
- util_dump_member(stream, uint, state, width);
- util_dump_member(stream, uint, state, height);
+ util_dump_member(stream, ptr, state, resource);
+// util_dump_member(stream, uint, state, box);
util_dump_member(stream, uint, state, stride);
- util_dump_member(stream, uint, state, usage);
+ util_dump_member(stream, uint, state, slice_stride);
- util_dump_member(stream, ptr, state, texture);
- util_dump_member(stream, uint, state, face);
- util_dump_member(stream, uint, state, level);
- util_dump_member(stream, uint, state, zslice);
+// util_dump_member(stream, ptr, state, data);
util_dump_struct_end(stream);
}
void *vs;
void *fs2d, *fsCube;
- struct pipe_buffer *vbuf; /**< quad vertices */
+ struct pipe_resource *vbuf; /**< quad vertices */
unsigned vbuf_slot;
float vertices[4][2][4]; /**< vertex/texcoords for quad */
static void
make_1d_mipmap(struct gen_mipmap_state *ctx,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_transfer *srcTrans, *dstTrans;
void *srcMap, *dstMap;
- srcTrans = pipe->get_tex_transfer(pipe, pt, face, srcLevel, zslice,
+ srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice,
PIPE_TRANSFER_READ, 0, 0,
u_minify(pt->width0, srcLevel),
u_minify(pt->height0, srcLevel));
- dstTrans = pipe->get_tex_transfer(pipe, pt, face, dstLevel, zslice,
+ dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice,
PIPE_TRANSFER_WRITE, 0, 0,
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
reduce_1d(pt->format,
- srcTrans->width, srcMap,
- dstTrans->width, dstMap);
+ srcTrans->box.width, srcMap,
+ dstTrans->box.width, dstMap);
pipe->transfer_unmap(pipe, srcTrans);
pipe->transfer_unmap(pipe, dstTrans);
- pipe->tex_transfer_destroy(pipe, srcTrans);
- pipe->tex_transfer_destroy(pipe, dstTrans);
+ pipe->transfer_destroy(pipe, srcTrans);
+ pipe->transfer_destroy(pipe, dstTrans);
}
}
static void
make_2d_mipmap(struct gen_mipmap_state *ctx,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_transfer *srcTrans, *dstTrans;
ubyte *srcMap, *dstMap;
- srcTrans = pipe->get_tex_transfer(pipe, pt, face, srcLevel, zslice,
- PIPE_TRANSFER_READ, 0, 0,
- u_minify(pt->width0, srcLevel),
- u_minify(pt->height0, srcLevel));
- dstTrans = pipe->get_tex_transfer(pipe, pt, face, dstLevel, zslice,
- PIPE_TRANSFER_WRITE, 0, 0,
- u_minify(pt->width0, dstLevel),
- u_minify(pt->height0, dstLevel));
+ srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice,
+ PIPE_TRANSFER_READ, 0, 0,
+ u_minify(pt->width0, srcLevel),
+ u_minify(pt->height0, srcLevel));
+ dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice,
+ PIPE_TRANSFER_WRITE, 0, 0,
+ u_minify(pt->width0, dstLevel),
+ u_minify(pt->height0, dstLevel));
srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
reduce_2d(pt->format,
- srcTrans->width, srcTrans->height,
+ srcTrans->box.width, srcTrans->box.height,
srcTrans->stride, srcMap,
- dstTrans->width, dstTrans->height,
+ dstTrans->box.width, dstTrans->box.height,
dstTrans->stride, dstMap);
pipe->transfer_unmap(pipe, srcTrans);
pipe->transfer_unmap(pipe, dstTrans);
- pipe->tex_transfer_destroy(pipe, srcTrans);
- pipe->tex_transfer_destroy(pipe, dstTrans);
+ pipe->transfer_destroy(pipe, srcTrans);
+ pipe->transfer_destroy(pipe, dstTrans);
}
}
static void
make_3d_mipmap(struct gen_mipmap_state *ctx,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
{
#if 0
struct pipe_transfer *srcTrans, *dstTrans;
ubyte *srcMap, *dstMap;
- srcTrans = pipe->get_tex_transfer(pipe, pt, face, srcLevel, zslice,
+ srcTrans = pipe->get_transfer(pipe, pt, face, srcLevel, zslice,
PIPE_TRANSFER_READ, 0, 0,
u_minify(pt->width0, srcLevel),
u_minify(pt->height0, srcLevel));
- dstTrans = pipe->get_tex_transfer(pipe, pt, face, dstLevel, zslice,
+ dstTrans = pipe->get_transfer(pipe, pt, face, dstLevel, zslice,
PIPE_TRANSFER_WRITE, 0, 0,
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
pipe->transfer_unmap(pipe, srcTrans);
pipe->transfer_unmap(pipe, dstTrans);
- pipe->tex_transfer_destroy(pipe, srcTrans);
- pipe->tex_transfer_destroy(pipe, dstTrans);
+ pipe->transfer_destroy(pipe, srcTrans);
+ pipe->transfer_destroy(pipe, dstTrans);
}
#else
(void) reduce_3d;
static void
fallback_gen_mipmap(struct gen_mipmap_state *ctx,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
{
switch (pt->target) {
if (!ctx->vbuf) {
ctx->vbuf = pipe_buffer_create(ctx->pipe->screen,
- 32,
- PIPE_BUFFER_USAGE_VERTEX,
+ PIPE_BIND_VERTEX_BUFFER,
max_slots * sizeof ctx->vertices);
}
offset = get_next_slot( ctx );
- pipe_buffer_write_nooverlap(ctx->pipe->screen, ctx->vbuf,
+ pipe_buffer_write_nooverlap(ctx->pipe, ctx->vbuf,
offset, sizeof(ctx->vertices), ctx->vertices);
return offset;
pipe->delete_fs_state(pipe, ctx->fs2d);
pipe->delete_fs_state(pipe, ctx->fsCube);
- pipe_buffer_reference(&ctx->vbuf, NULL);
+ pipe_resource_reference(&ctx->vbuf, NULL);
FREE(ctx);
}
*/
void util_gen_mipmap_flush( struct gen_mipmap_state *ctx )
{
- pipe_buffer_reference(&ctx->vbuf, NULL);
+ pipe_resource_reference(&ctx->vbuf, NULL);
ctx->vbuf_slot = 0;
}
struct pipe_context *pipe = ctx->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_framebuffer_state fb;
- struct pipe_texture *pt = psv->texture;
+ struct pipe_resource *pt = psv->texture;
void *fs = (pt->target == PIPE_TEXTURE_CUBE) ? ctx->fsCube : ctx->fs2d;
uint dstLevel;
uint zslice = 0;
/* check if we can render in the texture's format */
if (!screen->is_format_supported(screen, psv->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ PIPE_BIND_RENDER_TARGET, 0)) {
fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel);
return;
}
struct pipe_surface *surf =
screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET);
/*
* Setup framebuffer / dest surface
struct pipe_context;
-struct pipe_texture;
+struct pipe_resource;
struct cso_context;
struct gen_mipmap_state;
#include "pipe/p_screen.h"
#include "util/u_debug.h"
#include "util/u_atomic.h"
+#include "util/u_box.h"
#ifdef __cplusplus
return destroy;
}
-static INLINE void
-pipe_buffer_reference(struct pipe_buffer **ptr, struct pipe_buffer *buf)
-{
- struct pipe_buffer *old_buf;
-
- assert(ptr);
- old_buf = *ptr;
-
- if (pipe_reference(&(*ptr)->reference, &buf->reference))
- old_buf->screen->buffer_destroy(old_buf);
- *ptr = buf;
-}
static INLINE void
pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
*ptr = surf;
}
+
static INLINE void
-pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex)
+pipe_resource_reference(struct pipe_resource **ptr, struct pipe_resource *tex)
{
- struct pipe_texture *old_tex = *ptr;
+ struct pipe_resource *old_tex = *ptr;
if (pipe_reference(&(*ptr)->reference, &tex->reference))
- old_tex->screen->texture_destroy(old_tex);
+ old_tex->screen->resource_destroy(old_tex->screen, old_tex);
*ptr = tex;
}
+
static INLINE void
pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_view *view)
{
* Convenience wrappers for screen buffer functions.
*/
-static INLINE struct pipe_buffer *
+static INLINE struct pipe_resource *
pipe_buffer_create( struct pipe_screen *screen,
- unsigned alignment, unsigned usage, unsigned size )
+ unsigned bind,
+ unsigned size )
{
- return screen->buffer_create(screen, alignment, usage, size);
+ struct pipe_resource buffer;
+ memset(&buffer, 0, sizeof buffer);
+ buffer.target = PIPE_BUFFER;
+ buffer.format = PIPE_FORMAT_R8_UNORM; /* want TYPELESS or similar */
+ buffer.bind = bind;
+ buffer._usage = PIPE_USAGE_DEFAULT;
+ buffer.flags = 0;
+ buffer.width0 = size;
+ buffer.height0 = 1;
+ buffer.depth0 = 1;
+ return screen->resource_create(screen, &buffer);
}
-static INLINE struct pipe_buffer *
-pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size )
+
+static INLINE struct pipe_resource *
+pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size,
+ unsigned usage )
{
- return screen->user_buffer_create(screen, ptr, size);
+ return screen->user_buffer_create(screen, ptr, size, usage);
}
static INLINE void *
-pipe_buffer_map(struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned usage)
+pipe_buffer_map_range(struct pipe_context *pipe,
+ struct pipe_resource *buffer,
+ unsigned offset,
+ unsigned length,
+ unsigned usage,
+ struct pipe_transfer **transfer)
{
- if(screen->buffer_map_range) {
- unsigned offset = 0;
- unsigned length = buf->size;
- return screen->buffer_map_range(screen, buf, offset, length, usage);
+ struct pipe_box box;
+ void *map;
+
+ assert(offset < buffer->width0);
+ assert(offset + length <= buffer->width0);
+ assert(length);
+
+ u_box_1d(offset, length, &box);
+
+ *transfer = pipe->get_transfer( pipe,
+ buffer,
+ u_subresource(0, 0),
+ usage,
+ &box);
+
+ if (*transfer == NULL)
+ return NULL;
+
+ map = pipe->transfer_map( pipe, *transfer );
+ if (map == NULL) {
+ pipe->transfer_destroy( pipe, *transfer );
+ return NULL;
}
- else
- return screen->buffer_map(screen, buf, usage);
+
+ /* Match old screen->buffer_map_range() behaviour, return pointer
+ * to where the beginning of the buffer would be:
+ */
+ return (void *)((char *)map - offset);
}
-static INLINE void
-pipe_buffer_unmap(struct pipe_screen *screen,
- struct pipe_buffer *buf)
+
+static INLINE void *
+pipe_buffer_map(struct pipe_context *pipe,
+ struct pipe_resource *buffer,
+ unsigned usage,
+ struct pipe_transfer **transfer)
{
- screen->buffer_unmap(screen, buf);
+ return pipe_buffer_map_range(pipe, buffer, 0, buffer->width0, usage, transfer);
}
-static INLINE void *
-pipe_buffer_map_range(struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned offset,
- unsigned length,
- unsigned usage)
+
+static INLINE void
+pipe_buffer_unmap(struct pipe_context *pipe,
+ struct pipe_resource *buf,
+ struct pipe_transfer *transfer)
{
- assert(offset < buf->size);
- assert(offset + length <= buf->size);
- assert(length);
- if(screen->buffer_map_range)
- return screen->buffer_map_range(screen, buf, offset, length, usage);
- else
- return screen->buffer_map(screen, buf, usage);
+ if (transfer) {
+ pipe->transfer_unmap(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
+ }
}
static INLINE void
-pipe_buffer_flush_mapped_range(struct pipe_screen *screen,
- struct pipe_buffer *buf,
+pipe_buffer_flush_mapped_range(struct pipe_context *pipe,
+ struct pipe_transfer *transfer,
unsigned offset,
unsigned length)
{
- assert(offset < buf->size);
- assert(offset + length <= buf->size);
+ struct pipe_box box;
+ int transfer_offset;
+
assert(length);
- if(screen->buffer_flush_mapped_range)
- screen->buffer_flush_mapped_range(screen, buf, offset, length);
+ assert(transfer->box.x <= offset);
+ assert(offset + length <= transfer->box.x + transfer->box.width);
+
+ /* Match old screen->buffer_flush_mapped_range() behaviour, where
+ * offset parameter is relative to the start of the buffer, not the
+ * mapped range.
+ */
+ transfer_offset = offset - transfer->box.x;
+
+ u_box_1d(transfer_offset, length, &box);
+
+ pipe->transfer_flush_region(pipe, transfer, &box);
}
static INLINE void
-pipe_buffer_write(struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned offset, unsigned size,
+pipe_buffer_write(struct pipe_context *pipe,
+ struct pipe_resource *buf,
+ unsigned offset,
+ unsigned size,
const void *data)
{
- void *map;
-
- assert(offset < buf->size);
- assert(offset + size <= buf->size);
- assert(size);
-
- map = pipe_buffer_map_range(screen, buf, offset, size,
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
- PIPE_BUFFER_USAGE_DISCARD);
- assert(map);
- if(map) {
- memcpy((uint8_t *)map + offset, data, size);
- pipe_buffer_flush_mapped_range(screen, buf, offset, size);
- pipe_buffer_unmap(screen, buf);
- }
+ struct pipe_box box;
+
+ u_box_1d(offset, size, &box);
+
+ pipe->transfer_inline_write( pipe,
+ buf,
+ u_subresource(0,0),
+ PIPE_TRANSFER_WRITE,
+ &box,
+ data,
+ size,
+ 0);
}
/**
* been written before.
*/
static INLINE void
-pipe_buffer_write_nooverlap(struct pipe_screen *screen,
- struct pipe_buffer *buf,
+pipe_buffer_write_nooverlap(struct pipe_context *pipe,
+ struct pipe_resource *buf,
unsigned offset, unsigned size,
const void *data)
{
- void *map;
-
- assert(offset < buf->size);
- assert(offset + size <= buf->size);
- assert(size);
-
- map = pipe_buffer_map_range(screen, buf, offset, size,
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
- PIPE_BUFFER_USAGE_DISCARD |
- PIPE_BUFFER_USAGE_UNSYNCHRONIZED);
- assert(map);
- if(map) {
- memcpy((uint8_t *)map + offset, data, size);
- pipe_buffer_flush_mapped_range(screen, buf, offset, size);
- pipe_buffer_unmap(screen, buf);
- }
+ struct pipe_box box;
+
+ u_box_1d(offset, size, &box);
+
+ pipe->transfer_inline_write(pipe,
+ buf,
+ u_subresource(0,0),
+ (PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_NOOVERWRITE),
+ &box,
+ data,
+ 0, 0);
}
static INLINE void
-pipe_buffer_read(struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned offset, unsigned size,
+pipe_buffer_read(struct pipe_context *pipe,
+ struct pipe_resource *buf,
+ unsigned offset,
+ unsigned size,
void *data)
{
- void *map;
-
- assert(offset < buf->size);
- assert(offset + size <= buf->size);
- assert(size);
-
- map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_READ);
- assert(map);
- if(map) {
- memcpy(data, (const uint8_t *)map + offset, size);
- pipe_buffer_unmap(screen, buf);
- }
+ struct pipe_transfer *src_transfer;
+ ubyte *map;
+
+ map = (ubyte *) pipe_buffer_map_range(pipe,
+ buf,
+ offset, size,
+ PIPE_TRANSFER_READ,
+ &src_transfer);
+
+ if (map)
+ memcpy(data, map + offset, size);
+
+ pipe_buffer_unmap(pipe, buf, src_transfer);
+}
+
+static INLINE struct pipe_transfer *
+pipe_get_transfer( struct pipe_context *context,
+ struct pipe_resource *resource,
+ unsigned face, unsigned level,
+ unsigned zslice,
+ enum pipe_transfer_usage usage,
+ unsigned x, unsigned y,
+ unsigned w, unsigned h)
+{
+ struct pipe_box box;
+ u_box_2d_zslice( x, y, zslice, w, h, &box );
+ return context->get_transfer( context,
+ resource,
+ u_subresource(face, level),
+ usage,
+ &box );
}
static INLINE void *
pipe_transfer_map( struct pipe_context *context,
- struct pipe_transfer *transf )
+ struct pipe_transfer *transfer )
{
- return context->transfer_map(context, transf);
+ return context->transfer_map( context, transfer );
}
static INLINE void
pipe_transfer_unmap( struct pipe_context *context,
- struct pipe_transfer *transf )
+ struct pipe_transfer *transfer )
{
- context->transfer_unmap(context, transf);
+ context->transfer_unmap( context, transfer );
}
+
static INLINE void
-pipe_transfer_destroy( struct pipe_context *context,
- struct pipe_transfer *transfer )
+pipe_transfer_destroy( struct pipe_context *context,
+ struct pipe_transfer *transfer )
{
- context->tex_transfer_destroy(context, transfer);
+ context->transfer_destroy(context, transfer);
}
-static INLINE unsigned
-pipe_transfer_buffer_flags( struct pipe_transfer *transf )
-{
- switch (transf->usage & PIPE_TRANSFER_READ_WRITE) {
- case PIPE_TRANSFER_READ_WRITE:
- return PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE;
- case PIPE_TRANSFER_READ:
- return PIPE_BUFFER_USAGE_CPU_READ;
- case PIPE_TRANSFER_WRITE:
- return PIPE_BUFFER_USAGE_CPU_WRITE;
- default:
- debug_assert(0);
- return 0;
- }
-}
#ifdef __cplusplus
}
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
#include "util/u_format.h"
+#include "util/u_inlines.h"
#include "util/u_rect.h"
src_format = src->texture->format;
dst_format = dst->texture->format;
- src_trans = pipe->get_tex_transfer(pipe,
- src->texture,
- src->face,
- src->level,
- src->zslice,
- PIPE_TRANSFER_READ,
- src_x, src_y, w, h);
-
- dst_trans = pipe->get_tex_transfer(pipe,
- dst->texture,
- dst->face,
- dst->level,
- dst->zslice,
- PIPE_TRANSFER_WRITE,
- dst_x, dst_y, w, h);
+ src_trans = pipe_get_transfer(pipe,
+ src->texture,
+ src->face,
+ src->level,
+ src->zslice,
+ PIPE_TRANSFER_READ,
+ src_x, src_y, w, h);
+
+ dst_trans = pipe_get_transfer(pipe,
+ dst->texture,
+ dst->face,
+ dst->level,
+ dst->zslice,
+ PIPE_TRANSFER_WRITE,
+ dst_x, dst_y, w, h);
assert(util_format_get_blocksize(dst_format) == util_format_get_blocksize(src_format));
assert(util_format_get_blockwidth(dst_format) == util_format_get_blockwidth(src_format));
pipe->transfer_unmap(pipe, src_trans);
pipe->transfer_unmap(pipe, dst_trans);
- pipe->tex_transfer_destroy(pipe, src_trans);
- pipe->tex_transfer_destroy(pipe, dst_trans);
+ pipe->transfer_destroy(pipe, src_trans);
+ pipe->transfer_destroy(pipe, dst_trans);
}
assert(dst->texture);
if (!dst->texture)
return;
- dst_trans = pipe->get_tex_transfer(pipe,
- dst->texture,
- dst->face,
- dst->level,
- dst->zslice,
- PIPE_TRANSFER_WRITE,
- dstx, dsty, width, height);
+ dst_trans = pipe_get_transfer(pipe,
+ dst->texture,
+ dst->face,
+ dst->level,
+ dst->zslice,
+ PIPE_TRANSFER_WRITE,
+ dstx, dsty, width, height);
dst_map = pipe->transfer_map(pipe, dst_trans);
if (dst_map) {
assert(dst_trans->stride > 0);
- switch (util_format_get_blocksize(dst_trans->texture->format)) {
+ switch (util_format_get_blocksize(dst->texture->format)) {
case 1:
case 2:
case 4:
- util_fill_rect(dst_map, dst_trans->texture->format, dst_trans->stride,
+ util_fill_rect(dst_map, dst->texture->format,
+ dst_trans->stride,
0, 0, width, height, value);
break;
case 8:
- {
- /* expand the 4-byte clear value to an 8-byte value */
- ushort *row = (ushort *) dst_map;
- ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff);
- ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff);
- ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff);
- ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff);
- unsigned i, j;
- val0 = (val0 << 8) | val0;
- val1 = (val1 << 8) | val1;
- val2 = (val2 << 8) | val2;
- val3 = (val3 << 8) | val3;
- for (i = 0; i < height; i++) {
- for (j = 0; j < width; j++) {
- row[j*4+0] = val0;
- row[j*4+1] = val1;
- row[j*4+2] = val2;
- row[j*4+3] = val3;
- }
- row += dst_trans->stride/2;
- }
- }
- break;
+ {
+ /* expand the 4-byte clear value to an 8-byte value */
+ ushort *row = (ushort *) dst_map;
+ ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff);
+ ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff);
+ ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff);
+ ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff);
+ unsigned i, j;
+ val0 = (val0 << 8) | val0;
+ val1 = (val1 << 8) | val1;
+ val2 = (val2 << 8) | val2;
+ val3 = (val3 << 8) | val3;
+ for (i = 0; i < height; i++) {
+ for (j = 0; j < width; j++) {
+ row[j*4+0] = val0;
+ row[j*4+1] = val1;
+ row[j*4+2] = val2;
+ row[j*4+3] = val3;
+ }
+ row += dst_trans->stride/2;
+ }
+ }
+ break;
default:
assert(0);
break;
}
pipe->transfer_unmap(pipe, dst_trans);
- pipe->tex_transfer_destroy(pipe, dst_trans);
+ pipe->transfer_destroy(pipe, dst_trans);
}
--- /dev/null
+
+
+#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);
+}
+
+unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned face, unsigned level)
+{
+ struct u_resource *ur = u_resource(resource);
+ return ur->vtbl->is_resource_referenced(pipe, resource, face, level);
+}
+
+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,
+ unsigned 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);
+}
+
+
+
+
static void
default_template(struct pipe_sampler_view *view,
- const struct pipe_texture *texture,
+ const struct pipe_resource *texture,
enum pipe_format format,
unsigned expand_green_blue)
{
void
u_sampler_view_default_template(struct pipe_sampler_view *view,
- const struct pipe_texture *texture,
+ const struct pipe_resource *texture,
enum pipe_format format)
{
/* Expand to (0, 0, 0, 1) */
void
u_sampler_view_default_dx9_template(struct pipe_sampler_view *view,
- const struct pipe_texture *texture,
+ const struct pipe_resource *texture,
enum pipe_format format)
{
/* Expand to (1, 1, 1, 1) */
void
u_sampler_view_default_template(struct pipe_sampler_view *view,
- const struct pipe_texture *texture,
+ const struct pipe_resource *texture,
enum pipe_format format);
void
u_sampler_view_default_dx9_template(struct pipe_sampler_view *view,
- const struct pipe_texture *texture,
+ const struct pipe_resource *texture,
enum pipe_format format);
+++ /dev/null
-/**************************************************************************
- *
- * 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 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.
- *
- **************************************************************************/
-
-#include "u_simple_screen.h"
-
-#include "pipe/p_screen.h"
-#include "pipe/p_state.h"
-#include "util/u_simple_screen.h"
-
-
-static struct pipe_buffer *
-pass_buffer_create(struct pipe_screen *screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct pipe_buffer *buffer =
- screen->winsys->buffer_create(screen->winsys, alignment, usage, size);
-
- buffer->screen = screen;
-
- return buffer;
-}
-
-static struct pipe_buffer *
-pass_user_buffer_create(struct pipe_screen *screen,
- void *ptr,
- unsigned bytes)
-{
- struct pipe_buffer *buffer =
- screen->winsys->user_buffer_create(screen->winsys, ptr, bytes);
-
- buffer->screen = screen;
-
- return buffer;
-}
-
-
-
-static void *
-pass_buffer_map(struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned usage)
-{
- return screen->winsys->buffer_map(screen->winsys, buf, usage);
-}
-
-static void
-pass_buffer_unmap(struct pipe_screen *screen,
- struct pipe_buffer *buf)
-{
- screen->winsys->buffer_unmap(screen->winsys, buf);
-}
-
-static void
-pass_buffer_destroy(struct pipe_buffer *buf)
-{
- buf->screen->winsys->buffer_destroy(buf);
-}
-
-
-static void
-pass_flush_frontbuffer(struct pipe_screen *screen,
- struct pipe_surface *surf,
- void *context_private)
-{
- screen->winsys->flush_frontbuffer(screen->winsys, surf, context_private);
-}
-
-static void
-pass_fence_reference(struct pipe_screen *screen,
- struct pipe_fence_handle **ptr,
- struct pipe_fence_handle *fence)
-{
- screen->winsys->fence_reference(screen->winsys, ptr, fence);
-}
-
-static int
-pass_fence_signalled(struct pipe_screen *screen,
- struct pipe_fence_handle *fence,
- unsigned flag)
-{
- return screen->winsys->fence_signalled(screen->winsys, fence, flag);
-}
-
-static int
-pass_fence_finish(struct pipe_screen *screen,
- struct pipe_fence_handle *fence,
- unsigned flag)
-{
- return screen->winsys->fence_finish(screen->winsys, fence, flag);
-}
-
-void
-u_simple_screen_init(struct pipe_screen *screen)
-{
- screen->buffer_create = pass_buffer_create;
- screen->user_buffer_create = pass_user_buffer_create;
-
- screen->buffer_map = pass_buffer_map;
- screen->buffer_unmap = pass_buffer_unmap;
- screen->buffer_destroy = pass_buffer_destroy;
- screen->flush_frontbuffer = pass_flush_frontbuffer;
- screen->fence_reference = pass_fence_reference;
- screen->fence_signalled = pass_fence_signalled;
- screen->fence_finish = pass_fence_finish;
-}
-
-const char *
-u_simple_screen_winsys_name(struct pipe_screen *screen)
-{
- return screen->winsys->get_name(screen->winsys);
-}
struct pipe_screen;
struct pipe_fence_handle;
struct pipe_surface;
-struct pipe_buffer;
+struct pipe_resource;
/**
* Gallium3D drivers are (meant to be!) independent of both GL and the
* window systems must then implement that interface (rather than the
* other way around...).
*
- * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
- * usage argument is only an optimization hint, not a guarantee, therefore
- * proper behavior must be observed in all circumstances.
+ * usage is a bitmask of PIPE_BIND_*.
+ * All possible usages must be present.
*
* alignment indicates the client's alignment requirements, eg for
* SSE instructions.
*/
- struct pipe_buffer *(*buffer_create)( struct pipe_winsys *ws,
+ struct pipe_resource *(*buffer_create)( struct pipe_winsys *ws,
unsigned alignment,
unsigned usage,
unsigned size );
* Note that ptr may be accessed at any time upto the time when the
* buffer is destroyed, so the data must not be freed before then.
*/
- struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *ws,
+ struct pipe_resource *(*user_buffer_create)(struct pipe_winsys *ws,
void *ptr,
unsigned bytes);
* display targets) must be allocated with special characteristics, memory
* pools, or obtained directly from the windowing system.
*
- * This callback is invoked by the pipe_screenwhen creating a texture marked
- * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
+ * This callback is invoked by the pipe_screen when creating a texture marked
+ * with the PIPE_BIND_DISPLAY_TARGET flag to get the underlying
* buffer storage.
*/
- struct pipe_buffer *(*surface_buffer_create)(struct pipe_winsys *ws,
+ struct pipe_resource *(*surface_buffer_create)(struct pipe_winsys *ws,
unsigned width, unsigned height,
enum pipe_format format,
unsigned usage,
* flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
*/
void *(*buffer_map)( struct pipe_winsys *ws,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned usage );
void (*buffer_unmap)( struct pipe_winsys *ws,
- struct pipe_buffer *buf );
+ struct pipe_resource *buf );
- void (*buffer_destroy)( struct pipe_buffer *buf );
+ void (*buffer_destroy)( struct pipe_resource *buf );
/** Set ptr = fence, with reference counting */
boolean
util_create_rgba_surface(struct pipe_screen *screen,
uint width, uint height,
- struct pipe_texture **textureOut,
+ uint bind,
+ struct pipe_resource **textureOut,
struct pipe_surface **surfaceOut)
{
static const enum pipe_format rgbaFormats[] = {
PIPE_FORMAT_NONE
};
const uint target = PIPE_TEXTURE_2D;
- const uint usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
enum pipe_format format = PIPE_FORMAT_NONE;
- struct pipe_texture templ;
+ struct pipe_resource templ;
uint i;
/* Choose surface format */
for (i = 0; rgbaFormats[i]; i++) {
if (screen->is_format_supported(screen, rgbaFormats[i],
- target, usage, 0)) {
+ target, bind, 0)) {
format = rgbaFormats[i];
break;
}
templ.width0 = width;
templ.height0 = height;
templ.depth0 = 1;
- templ.tex_usage = usage;
+ templ.bind = bind;
- *textureOut = screen->texture_create(screen, &templ);
+ *textureOut = screen->resource_create(screen, &templ);
if (!*textureOut)
return FALSE;
/* create surface / view into texture */
- *surfaceOut = screen->get_tex_surface(screen, *textureOut, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+ *surfaceOut = screen->get_tex_surface(screen,
+ *textureOut,
+ 0, 0, 0,
+ bind);
if (!*surfaceOut) {
- pipe_texture_reference(textureOut, NULL);
+ pipe_resource_reference(textureOut, NULL);
return FALSE;
}
* Release the surface and texture from util_create_rgba_surface().
*/
void
-util_destroy_rgba_surface(struct pipe_texture *texture,
+util_destroy_rgba_surface(struct pipe_resource *texture,
struct pipe_surface *surface)
{
pipe_surface_reference(&surface, NULL);
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&texture, NULL);
}
extern boolean
util_create_rgba_surface(struct pipe_screen *screen,
- uint width, uint height,
- struct pipe_texture **textureOut,
+ uint width, uint height, uint bind,
+ struct pipe_resource **textureOut,
struct pipe_surface **surfaceOut);
extern void
-util_destroy_rgba_surface(struct pipe_texture *texture,
+util_destroy_rgba_surface(struct pipe_resource *texture,
struct pipe_surface *surface);
const void *src;
if (dst_stride == 0)
- dst_stride = util_format_get_stride(pt->texture->format, w);
+ dst_stride = util_format_get_stride(pt->resource->format, w);
- if (pipe_clip_tile(x, y, &w, &h, pt))
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
return;
src = pipe->transfer_map(pipe, pt);
if(!src)
return;
- util_copy_rect(dst, pt->texture->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y);
+ util_copy_rect(dst, pt->resource->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y);
pipe->transfer_unmap(pipe, pt);
}
const void *src, int src_stride)
{
void *dst;
- enum pipe_format format = pt->texture->format;
+ enum pipe_format format = pt->resource->format;
if (src_stride == 0)
src_stride = util_format_get_stride(format, w);
- if (pipe_clip_tile(x, y, &w, &h, pt))
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
return;
dst = pipe->transfer_map(pipe, pt);
{
unsigned dst_stride = w * 4;
void *packed;
- enum pipe_format format = pt->texture->format;
+ enum pipe_format format = pt->resource->format;
- if (pipe_clip_tile(x, y, &w, &h, pt))
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
return;
packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
uint iy;
float rgba01[6];
- if (pipe_clip_tile(x, y, &w, &h, pt)) {
+ if (u_clip_tile(x, y, &w, &h, &pt->box)) {
return;
}
{
unsigned src_stride = w * 4;
void *packed;
- enum pipe_format format = pt->texture->format;
+ enum pipe_format format = pt->resource->format;
- if (pipe_clip_tile(x, y, &w, &h, pt))
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
return;
packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
ubyte *map;
uint *pDest = z;
uint i, j;
- enum pipe_format format = pt->texture->format;
+ enum pipe_format format = pt->resource->format;
- if (pipe_clip_tile(x, y, &w, &h, pt))
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
return;
map = (ubyte *)pipe->transfer_map(pipe, pt);
const uint *ptrc = zSrc;
ubyte *map;
uint i, j;
- enum pipe_format format = pt->texture->format;
+ enum pipe_format format = pt->resource->format;
- if (pipe_clip_tile(x, y, &w, &h, pt))
+ if (u_clip_tile(x, y, &w, &h, &pt->box))
return;
map = (ubyte *)pipe->transfer_map(pipe, pt);
case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
{
uint *pDest = (uint *) (map + y * pt->stride + x*4);
- assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
+ //assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
/* convert 32-bit Z to 24-bit Z, preserve stencil */
case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
{
uint *pDest = (uint *) (map + y * pt->stride + x*4);
- assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
+ //assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
/* convert 32-bit Z to 24-bit Z, preserve stencil */
struct pipe_transfer;
-
/**
* Clip tile against transfer dims.
+ *
+ * XXX: this only clips width and height!
+ *
* \return TRUE if tile is totally clipped, FALSE otherwise
*/
static INLINE boolean
-pipe_clip_tile(uint x, uint y, uint *w, uint *h, const struct pipe_transfer *pt)
+u_clip_tile(uint x, uint y, uint *w, uint *h, const struct pipe_box *box)
{
- if (x >= pt->width)
+ if (x >= box->width)
return TRUE;
- if (y >= pt->height)
+ if (y >= box->height)
return TRUE;
- if (x + *w > pt->width)
- *w = pt->width - x;
- if (y + *h > pt->height)
- *h = pt->height - y;
+ if (x + *w > box->width)
+ *w = box->width - x;
+ if (y + *h > box->height)
+ *h = box->height - y;
return FALSE;
}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
- * 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 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
- * THE COPYRIGHT HOLDERS, AUTHORS 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- *
- **************************************************************************/
-/*
- * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
- */
-
-#include "pipe/p_state.h"
-#include "util/u_simple_screen.h"
-#include "u_timed_winsys.h"
-#include "util/u_memory.h"
-#include "os/os_time.h"
-
-
-struct timed_winsys {
- struct pipe_winsys base;
- struct pipe_winsys *backend;
- uint64_t last_dump;
- struct {
- const char *name_key;
- double total;
- unsigned calls;
- } funcs[13];
-};
-
-
-static struct timed_winsys *timed_winsys( struct pipe_winsys *winsys )
-{
- return (struct timed_winsys *)winsys;
-}
-
-
-static void time_display( struct pipe_winsys *winsys )
-{
- struct timed_winsys *tws = timed_winsys(winsys);
- unsigned i;
- double overall = 0;
-
- for (i = 0; i < Elements(tws->funcs); i++) {
- if (tws->funcs[i].name_key) {
- debug_printf("*** %-25s %5.3fms (%d calls, avg %.3fms)\n",
- tws->funcs[i].name_key,
- tws->funcs[i].total,
- tws->funcs[i].calls,
- tws->funcs[i].total / tws->funcs[i].calls);
- overall += tws->funcs[i].total;
- tws->funcs[i].calls = 0;
- tws->funcs[i].total = 0;
- }
- }
-
- debug_printf("*** %-25s %5.3fms\n",
- "OVERALL WINSYS",
- overall);
-}
-
-static void time_finish( struct pipe_winsys *winsys,
- long long startval,
- unsigned idx,
- const char *name )
-{
- struct timed_winsys *tws = timed_winsys(winsys);
- int64_t endval = os_time_get();
- double elapsed = (endval - startval)/1000.0;
-
- if (endval - startval > 1000LL)
- debug_printf("*** %s %.3f\n", name, elapsed );
-
- assert( tws->funcs[idx].name_key == name ||
- tws->funcs[idx].name_key == NULL);
-
- tws->funcs[idx].name_key = name;
- tws->funcs[idx].total += elapsed;
- tws->funcs[idx].calls++;
-
- if (endval - tws->last_dump > 10LL * 1000LL * 1000LL) {
- time_display( winsys );
- tws->last_dump = endval;
- }
-}
-
-
-/* Pipe has no concept of pools, but the psb driver passes a flag that
- * can be mapped onto pools in the backend.
- */
-static struct pipe_buffer *
-timed_buffer_create(struct pipe_winsys *winsys,
- unsigned alignment,
- unsigned usage,
- unsigned size )
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- struct pipe_buffer *buf =
- backend->buffer_create( backend, alignment, usage, size );
-
- time_finish(winsys, start, 0, __FUNCTION__);
-
- return buf;
-}
-
-
-
-
-static struct pipe_buffer *
-timed_user_buffer_create(struct pipe_winsys *winsys,
- void *data,
- unsigned bytes)
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- struct pipe_buffer *buf = backend->user_buffer_create( backend, data, bytes );
-
- time_finish(winsys, start, 1, __FUNCTION__);
-
- return buf;
-}
-
-
-static void *
-timed_buffer_map(struct pipe_winsys *winsys,
- struct pipe_buffer *buf,
- unsigned flags)
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- void *map = backend->buffer_map( backend, buf, flags );
-
- time_finish(winsys, start, 2, __FUNCTION__);
-
- return map;
-}
-
-
-static void
-timed_buffer_unmap(struct pipe_winsys *winsys,
- struct pipe_buffer *buf)
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- backend->buffer_unmap( backend, buf );
-
- time_finish(winsys, start, 3, __FUNCTION__);
-}
-
-
-static void
-timed_buffer_destroy(struct pipe_buffer *buf)
-{
- struct pipe_winsys *winsys = buf->screen->winsys;
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- backend->buffer_destroy( buf );
-
- time_finish(winsys, start, 4, __FUNCTION__);
-}
-
-
-static void
-timed_flush_frontbuffer( struct pipe_winsys *winsys,
- struct pipe_surface *surf,
- void *context_private)
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- backend->flush_frontbuffer( backend, surf, context_private );
-
- time_finish(winsys, start, 5, __FUNCTION__);
-}
-
-
-
-
-static struct pipe_buffer *
-timed_surface_buffer_create(struct pipe_winsys *winsys,
- unsigned width, unsigned height,
- enum pipe_format format,
- unsigned usage,
- unsigned tex_usage,
- unsigned *stride)
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- struct pipe_buffer *ret = backend->surface_buffer_create( backend, width, height,
- format, usage, tex_usage, stride );
-
- time_finish(winsys, start, 7, __FUNCTION__);
-
- return ret;
-}
-
-
-static const char *
-timed_get_name( struct pipe_winsys *winsys )
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- const char *ret = backend->get_name( backend );
-
- time_finish(winsys, start, 9, __FUNCTION__);
-
- return ret;
-}
-
-static void
-timed_fence_reference(struct pipe_winsys *winsys,
- struct pipe_fence_handle **ptr,
- struct pipe_fence_handle *fence)
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- backend->fence_reference( backend, ptr, fence );
-
- time_finish(winsys, start, 10, __FUNCTION__);
-}
-
-
-static int
-timed_fence_signalled( struct pipe_winsys *winsys,
- struct pipe_fence_handle *fence,
- unsigned flag )
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- int ret = backend->fence_signalled( backend, fence, flag );
-
- time_finish(winsys, start, 11, __FUNCTION__);
-
- return ret;
-}
-
-static int
-timed_fence_finish( struct pipe_winsys *winsys,
- struct pipe_fence_handle *fence,
- unsigned flag )
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- int64_t start = os_time_get();
-
- int ret = backend->fence_finish( backend, fence, flag );
-
- time_finish(winsys, start, 12, __FUNCTION__);
-
- return ret;
-}
-
-static void
-timed_winsys_destroy( struct pipe_winsys *winsys )
-{
- struct pipe_winsys *backend = timed_winsys(winsys)->backend;
- backend->destroy( backend );
- FREE(winsys);
-}
-
-
-
-struct pipe_winsys *u_timed_winsys_create( struct pipe_winsys *backend )
-{
- struct timed_winsys *ws = CALLOC_STRUCT(timed_winsys);
-
- ws->base.user_buffer_create = timed_user_buffer_create;
- ws->base.buffer_map = timed_buffer_map;
- ws->base.buffer_unmap = timed_buffer_unmap;
- ws->base.buffer_destroy = timed_buffer_destroy;
- ws->base.buffer_create = timed_buffer_create;
- ws->base.surface_buffer_create = timed_surface_buffer_create;
- ws->base.flush_frontbuffer = timed_flush_frontbuffer;
- ws->base.get_name = timed_get_name;
- ws->base.fence_reference = timed_fence_reference;
- ws->base.fence_signalled = timed_fence_signalled;
- ws->base.fence_finish = timed_fence_finish;
- ws->base.destroy = timed_winsys_destroy;
-
- ws->backend = backend;
-
- return &ws->base;
-}
-
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
- * 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 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
- * THE COPYRIGHT HOLDERS, AUTHORS 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- *
- **************************************************************************/
-/*
- * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
- */
-
-
-#ifndef U_TIMED_WINSYS_H
-#define U_TIMED_WINSYS_H
-
-
-struct pipe_winsys;
-struct pipe_winsys *u_timed_winsys_create( struct pipe_winsys *backend );
-
-
-#endif
--- /dev/null
+#include "pipe/p_context.h"
+#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_default_transfer_inline_write( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned slice_stride)
+{
+ struct pipe_transfer *transfer = NULL;
+ uint8_t *map = NULL;
+
+ transfer = pipe->get_transfer(pipe,
+ resource,
+ sr,
+ usage,
+ box );
+ if (transfer == NULL)
+ goto out;
+
+ map = pipe_transfer_map(pipe, transfer);
+ if (map == NULL)
+ goto out;
+
+ assert(box->depth == 1); /* XXX: fix me */
+
+ util_copy_rect(map,
+ resource->format,
+ transfer->stride, /* bytes? */
+ 0, 0,
+ box->width,
+ box->height,
+ data,
+ box->width, /* bytes? texels? */
+ 0, 0);
+
+out:
+ if (map)
+ pipe_transfer_unmap(pipe, transfer);
+
+ if (transfer)
+ pipe_transfer_destroy(pipe, transfer);
+}
+
+
+boolean u_default_resource_get_handle(struct pipe_screen *screen,
+ struct pipe_resource *resource,
+ struct winsys_handle *handle)
+{
+ return FALSE;
+}
+
+
+
+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.
+ */
+}
+
+unsigned u_default_is_resource_referenced( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned face, unsigned level)
+{
+ return 0;
+}
+
+struct pipe_transfer * u_default_get_transfer(struct pipe_context *context,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned 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;
+
+ /* Note strides are zero, this is ok for buffers, but not for
+ * textures 2d & higher at least.
+ */
+ 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);
+}
+
--- /dev/null
+
+#ifndef U_TRANSFER_H
+#define U_TRANSFER_H
+
+/* Fallback implementations for inline read/writes which just go back
+ * to the regular transfer behaviour.
+ */
+#include "pipe/p_state.h"
+
+struct pipe_context;
+
+boolean u_default_resource_get_handle(struct pipe_screen *screen,
+ struct pipe_resource *resource,
+ struct winsys_handle *handle);
+
+void u_default_transfer_inline_write( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned slice_stride);
+
+void u_default_transfer_flush_region( struct pipe_context *pipe,
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box);
+
+unsigned u_default_is_resource_referenced( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned face, unsigned level);
+
+struct pipe_transfer * u_default_get_transfer(struct pipe_context *context,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned 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);
+
+ unsigned (*is_resource_referenced)(struct pipe_context *pipe,
+ struct pipe_resource *texture,
+ unsigned face, unsigned level);
+
+ struct pipe_transfer *(*get_transfer)(struct pipe_context *,
+ struct pipe_resource *resource,
+ struct pipe_subresource,
+ unsigned 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,
+ unsigned 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);
+
+unsigned u_is_resource_referenced_vtbl( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned face, unsigned level);
+
+struct pipe_transfer *u_get_transfer_vtbl(struct pipe_context *context,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned 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,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned slice_stride);
+
+
+
+
+
+
+
+
+#endif
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
-#include "pipe/p_screen.h"
+#include "pipe/p_context.h"
#include "util/u_memory.h"
#include "util/u_math.h"
struct u_upload_mgr {
- struct pipe_screen *screen;
+ struct pipe_context *pipe;
unsigned default_size;
unsigned alignment;
/* The active buffer:
*/
- struct pipe_buffer *buffer;
+ struct pipe_resource *buffer;
unsigned size;
unsigned offset;
};
-struct u_upload_mgr *u_upload_create( struct pipe_screen *screen,
+struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
unsigned default_size,
unsigned alignment,
unsigned usage )
{
struct u_upload_mgr *upload = CALLOC_STRUCT( u_upload_mgr );
+ upload->pipe = pipe;
upload->default_size = default_size;
- upload->screen = screen;
upload->alignment = alignment;
upload->usage = usage;
upload->buffer = NULL;
return upload;
}
-
+/* Slightly specialized version of buffer_write designed to maximize
+ * chances of the driver consolidating successive writes into a single
+ * upload.
+ *
+ * dirty_size may be slightly greater than size to cope with
+ * alignment. We don't want to leave holes between succesively mapped
+ * regions as that may prevent the driver from consolidating uploads.
+ *
+ * Note that the 'data' pointer has probably come from the application
+ * and we cannot read even a byte past its end without risking
+ * segfaults, or at least complaints from valgrind..
+ */
static INLINE enum pipe_error
-my_buffer_write(struct pipe_screen *screen,
- struct pipe_buffer *buf,
+my_buffer_write(struct pipe_context *pipe,
+ struct pipe_resource *buf,
unsigned offset, unsigned size, unsigned dirty_size,
const void *data)
{
+ struct pipe_transfer *transfer = NULL;
uint8_t *map;
- assert(offset < buf->size);
- assert(offset + size <= buf->size);
+ assert(offset < buf->width0);
+ assert(offset + size <= buf->width0);
assert(dirty_size >= size);
assert(size);
- map = pipe_buffer_map_range(screen, buf, offset, size,
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
- PIPE_BUFFER_USAGE_DISCARD |
- PIPE_BUFFER_USAGE_UNSYNCHRONIZED);
+ map = pipe_buffer_map_range(pipe, buf, offset, dirty_size,
+ PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_FLUSH_EXPLICIT |
+ PIPE_TRANSFER_DISCARD |
+ PIPE_TRANSFER_UNSYNCHRONIZED,
+ &transfer);
if (map == NULL)
return PIPE_ERROR_OUT_OF_MEMORY;
memcpy(map + offset, data, size);
- pipe_buffer_flush_mapped_range(screen, buf, offset, dirty_size);
- pipe_buffer_unmap(screen, buf);
+ pipe_buffer_flush_mapped_range(pipe, transfer, offset, dirty_size);
+ pipe_buffer_unmap(pipe, buf, transfer);
return PIPE_OK;
}
*/
void u_upload_flush( struct u_upload_mgr *upload )
{
- pipe_buffer_reference( &upload->buffer, NULL );
+ pipe_resource_reference( &upload->buffer, NULL );
upload->size = 0;
}
*/
size = align(MAX2(upload->default_size, min_size), 4096);
- upload->buffer = pipe_buffer_create( upload->screen,
- upload->alignment,
- upload->usage | PIPE_BUFFER_USAGE_CPU_WRITE,
+ upload->buffer = pipe_buffer_create( upload->pipe->screen,
+ upload->usage,
size );
if (upload->buffer == NULL)
goto fail;
fail:
if (upload->buffer)
- pipe_buffer_reference( &upload->buffer, NULL );
+ pipe_resource_reference( &upload->buffer, NULL );
return PIPE_ERROR_OUT_OF_MEMORY;
}
unsigned size,
const void *data,
unsigned *out_offset,
- struct pipe_buffer **outbuf )
+ struct pipe_resource **outbuf )
{
unsigned alloc_size = align( size, upload->alignment );
enum pipe_error ret = PIPE_OK;
/* Copy the data, using map_range if available:
*/
- ret = my_buffer_write( upload->screen,
+ ret = my_buffer_write( upload->pipe,
upload->buffer,
upload->offset,
size,
/* Emit the return values:
*/
- pipe_buffer_reference( outbuf, upload->buffer );
+ pipe_resource_reference( outbuf, upload->buffer );
*out_offset = upload->offset;
upload->offset += alloc_size;
return PIPE_OK;
enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
unsigned offset,
unsigned size,
- struct pipe_buffer *inbuf,
+ struct pipe_resource *inbuf,
unsigned *out_offset,
- struct pipe_buffer **outbuf )
+ struct pipe_resource **outbuf )
{
enum pipe_error ret = PIPE_OK;
+ struct pipe_transfer *transfer = NULL;
const char *map = NULL;
- map = (const char *)pipe_buffer_map(
- upload->screen, inbuf, PIPE_BUFFER_USAGE_CPU_READ );
+ map = (const char *)pipe_buffer_map(upload->pipe,
+ inbuf,
+ PIPE_TRANSFER_READ,
+ &transfer);
if (map == NULL) {
ret = PIPE_ERROR_OUT_OF_MEMORY;
done:
if (map)
- pipe_buffer_unmap( upload->screen, inbuf );
+ pipe_buffer_unmap( upload->pipe, inbuf, transfer );
return ret;
}
#include "pipe/p_defines.h"
struct pipe_screen;
-struct pipe_buffer;
+struct pipe_resource;
struct u_upload_mgr;
-struct u_upload_mgr *u_upload_create( struct pipe_screen *screen,
+struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
unsigned default_size,
unsigned alignment,
unsigned usage );
unsigned size,
const void *data,
unsigned *out_offset,
- struct pipe_buffer **outbuf );
+ struct pipe_resource **outbuf );
enum pipe_error u_upload_buffer( struct u_upload_mgr *upload,
unsigned offset,
unsigned size,
- struct pipe_buffer *inbuf,
+ struct pipe_resource *inbuf,
unsigned *out_offset,
- struct pipe_buffer **outbuf );
+ struct pipe_resource **outbuf );
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include "vl_bitstream_parser.h"
-#include <assert.h>
-#include <limits.h>
-#include <util/u_memory.h>
-
-static unsigned
-grab_bits(unsigned cursor, unsigned how_many_bits, unsigned bitstream_elt)
-{
- unsigned excess_bits = sizeof(unsigned) * CHAR_BIT - how_many_bits - cursor;
-
- assert(cursor < sizeof(unsigned) * CHAR_BIT);
- assert(how_many_bits > 0 && how_many_bits <= sizeof(unsigned) * CHAR_BIT);
- assert(cursor + how_many_bits <= sizeof(unsigned) * CHAR_BIT);
-
- return (bitstream_elt << excess_bits) >> (excess_bits + cursor);
-}
-
-static unsigned
-show_bits(unsigned cursor, unsigned how_many_bits, const unsigned *bitstream)
-{
- unsigned cur_int = cursor / (sizeof(unsigned) * CHAR_BIT);
- unsigned cur_bit = cursor % (sizeof(unsigned) * CHAR_BIT);
-
- assert(bitstream);
-
- if (cur_bit + how_many_bits > sizeof(unsigned) * CHAR_BIT) {
- unsigned lower = grab_bits(cur_bit, sizeof(unsigned) * CHAR_BIT - cur_bit,
- bitstream[cur_int]);
- unsigned upper = grab_bits(0, cur_bit + how_many_bits - sizeof(unsigned) * CHAR_BIT,
- bitstream[cur_int + 1]);
- return lower | upper << (sizeof(unsigned) * CHAR_BIT - cur_bit);
- }
- else
- return grab_bits(cur_bit, how_many_bits, bitstream[cur_int]);
-}
-
-bool vl_bitstream_parser_init(struct vl_bitstream_parser *parser,
- unsigned num_bitstreams,
- const void **bitstreams,
- const unsigned *sizes)
-{
- assert(parser);
- assert(num_bitstreams);
- assert(bitstreams);
- assert(sizes);
-
- parser->num_bitstreams = num_bitstreams;
- parser->bitstreams = (const unsigned**)bitstreams;
- parser->sizes = sizes;
- parser->cur_bitstream = 0;
- parser->cursor = 0;
-
- return true;
-}
-
-void vl_bitstream_parser_cleanup(struct vl_bitstream_parser *parser)
-{
- assert(parser);
-}
-
-unsigned
-vl_bitstream_parser_get_bits(struct vl_bitstream_parser *parser,
- unsigned how_many_bits)
-{
- unsigned bits;
-
- assert(parser);
-
- bits = vl_bitstream_parser_show_bits(parser, how_many_bits);
-
- vl_bitstream_parser_forward(parser, how_many_bits);
-
- return bits;
-}
-
-unsigned
-vl_bitstream_parser_show_bits(struct vl_bitstream_parser *parser,
- unsigned how_many_bits)
-{
- unsigned bits = 0;
- unsigned shift = 0;
- unsigned cursor;
- unsigned cur_bitstream;
-
- assert(parser);
-
- cursor = parser->cursor;
- cur_bitstream = parser->cur_bitstream;
-
- while (1) {
- unsigned bits_left = parser->sizes[cur_bitstream] * CHAR_BIT - cursor;
- unsigned bits_to_show = how_many_bits > bits_left ? bits_left : how_many_bits;
-
- bits |= show_bits(cursor, bits_to_show,
- parser->bitstreams[cur_bitstream]) << shift;
-
- if (how_many_bits > bits_to_show) {
- how_many_bits -= bits_to_show;
- cursor = 0;
- ++cur_bitstream;
- shift += bits_to_show;
- }
- else
- break;
- }
-
- return bits;
-}
-
-void vl_bitstream_parser_forward(struct vl_bitstream_parser *parser,
- unsigned how_many_bits)
-{
- assert(parser);
- assert(how_many_bits);
-
- parser->cursor += how_many_bits;
-
- while (parser->cursor > parser->sizes[parser->cur_bitstream] * CHAR_BIT) {
- parser->cursor -= parser->sizes[parser->cur_bitstream++] * CHAR_BIT;
- assert(parser->cur_bitstream < parser->num_bitstreams);
- }
-}
-
-void vl_bitstream_parser_rewind(struct vl_bitstream_parser *parser,
- unsigned how_many_bits)
-{
- signed c;
-
- assert(parser);
- assert(how_many_bits);
-
- c = parser->cursor - how_many_bits;
-
- while (c < 0) {
- c += parser->sizes[parser->cur_bitstream--] * CHAR_BIT;
- assert(parser->cur_bitstream < parser->num_bitstreams);
- }
-
- parser->cursor = (unsigned)c;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 vl_bitstream_parser_h
-#define vl_bitstream_parser_h
-
-#include "pipe/p_compiler.h"
-
-struct vl_bitstream_parser
-{
- unsigned num_bitstreams;
- const unsigned **bitstreams;
- const unsigned *sizes;
- unsigned cur_bitstream;
- unsigned cursor;
-};
-
-bool vl_bitstream_parser_init(struct vl_bitstream_parser *parser,
- unsigned num_bitstreams,
- const void **bitstreams,
- const unsigned *sizes);
-
-void vl_bitstream_parser_cleanup(struct vl_bitstream_parser *parser);
-
-unsigned
-vl_bitstream_parser_get_bits(struct vl_bitstream_parser *parser,
- unsigned how_many_bits);
-
-unsigned
-vl_bitstream_parser_show_bits(struct vl_bitstream_parser *parser,
- unsigned how_many_bits);
-
-void vl_bitstream_parser_forward(struct vl_bitstream_parser *parser,
- unsigned how_many_bits);
-
-void vl_bitstream_parser_rewind(struct vl_bitstream_parser *parser,
- unsigned how_many_bits);
-
-#endif /* vl_bitstream_parser_h */
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include "vl_compositor.h"
-#include <assert.h>
-#include <pipe/p_context.h>
-#include <util/u_inlines.h>
-#include <tgsi/tgsi_parse.h>
-#include <tgsi/tgsi_build.h>
-#include <util/u_memory.h>
-#include "vl_csc.h"
-#include "vl_shader_build.h"
-
-struct vertex2f
-{
- float x, y;
-};
-
-struct vertex4f
-{
- float x, y, z, w;
-};
-
-struct vertex_shader_consts
-{
- struct vertex4f dst_scale;
- struct vertex4f dst_trans;
- struct vertex4f src_scale;
- struct vertex4f src_trans;
-};
-
-struct fragment_shader_consts
-{
- float matrix[16];
-};
-
-/*
- * Represents 2 triangles in a strip in normalized coords.
- * Used to render the surface onto the frame buffer.
- */
-static const struct vertex2f surface_verts[4] =
-{
- {0.0f, 0.0f},
- {0.0f, 1.0f},
- {1.0f, 0.0f},
- {1.0f, 1.0f}
-};
-
-/*
- * Represents texcoords for the above. We can use the position values directly.
- * TODO: Duplicate these in the shader, no need to create a buffer.
- */
-static const struct vertex2f *surface_texcoords = surface_verts;
-
-static void
-create_vert_shader(struct vl_compositor *c)
-{
- const unsigned max_tokens = 50;
-
- struct pipe_shader_state vs;
- struct tgsi_token *tokens;
- struct tgsi_header *header;
-
- struct tgsi_full_declaration decl;
- struct tgsi_full_instruction inst;
-
- unsigned ti;
-
- unsigned i;
-
- assert(c);
-
- tokens = (struct tgsi_token*)MALLOC(max_tokens * sizeof(struct tgsi_token));
- header = (struct tgsi_header*)&tokens[0];
- *header = tgsi_build_header();
- *(struct tgsi_processor*)&tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header);
-
- ti = 2;
-
- /*
- * decl i0 ; Vertex pos
- * decl i1 ; Vertex texcoords
- */
- for (i = 0; i < 2; i++) {
- decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * decl c0 ; Scaling vector to scale vertex pos rect to destination size
- * decl c1 ; Translation vector to move vertex pos rect into position
- * decl c2 ; Scaling vector to scale texcoord rect to source size
- * decl c3 ; Translation vector to move texcoord rect into position
- */
- decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 3);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /*
- * decl o0 ; Vertex pos
- * decl o1 ; Vertex texcoords
- */
- for (i = 0; i < 2; i++) {
- decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /* decl t0, t1 */
- decl = vl_decl_temps(0, 1);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /*
- * mad o0, i0, c0, c1 ; Scale and translate unit output rect to destination size and pos
- * mad o1, i1, c2, c3 ; Scale and translate unit texcoord rect to source size and pos
- */
- for (i = 0; i < 2; ++i) {
- inst = vl_inst4(TGSI_OPCODE_MAD, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i, TGSI_FILE_CONSTANT, i * 2, TGSI_FILE_CONSTANT, i * 2 + 1);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* end */
- inst = vl_end();
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- assert(ti <= max_tokens);
-
- vs.tokens = tokens;
- c->vertex_shader = c->pipe->create_vs_state(c->pipe, &vs);
- FREE(tokens);
-}
-
-static void
-create_frag_shader(struct vl_compositor *c)
-{
- const unsigned max_tokens = 50;
-
- struct pipe_shader_state fs;
- struct tgsi_token *tokens;
- struct tgsi_header *header;
-
- struct tgsi_full_declaration decl;
- struct tgsi_full_instruction inst;
-
- unsigned ti;
-
- unsigned i;
-
- assert(c);
-
- tokens = (struct tgsi_token*)MALLOC(max_tokens * sizeof(struct tgsi_token));
- header = (struct tgsi_header*)&tokens[0];
- *header = tgsi_build_header();
- *(struct tgsi_processor*)&tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header);
-
- ti = 2;
-
- /* decl i0 ; Texcoords for s0 */
- decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, 1, 0, 0, TGSI_INTERPOLATE_LINEAR);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /*
- * decl c0-c3 ; CSC matrix c0-c3
- */
- decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 3);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl o0 ; Fragment color */
- decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl t0 */
- decl = vl_decl_temps(0, 0);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl s0 ; Sampler for tex containing picture to display */
- decl = vl_decl_samplers(0, 0);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* tex2d t0, i0, s0 ; Read src pixel */
- inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_INPUT, 0, TGSI_FILE_SAMPLER, 0);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /*
- * dp4 o0.x, t0, c0 ; Multiply pixel by the color conversion matrix
- * dp4 o0.y, t0, c1
- * dp4 o0.z, t0, c2
- * dp4 o0.w, t0, c3
- */
- for (i = 0; i < 4; ++i) {
- inst = vl_inst3(TGSI_OPCODE_DP4, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, i);
- inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X << i;
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* end */
- inst = vl_end();
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- assert(ti <= max_tokens);
-
- fs.tokens = tokens;
- c->fragment_shader = c->pipe->create_fs_state(c->pipe, &fs);
- FREE(tokens);
-}
-
-static bool
-init_pipe_state(struct vl_compositor *c)
-{
- struct pipe_sampler_state sampler;
- struct pipe_vertex_element vertex_elems[2];
-
- assert(c);
-
- c->fb_state.nr_cbufs = 1;
- c->fb_state.zsbuf = NULL;
-
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR;
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
- sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
- sampler.compare_mode = PIPE_TEX_COMPARE_NONE;
- sampler.compare_func = PIPE_FUNC_ALWAYS;
- sampler.normalized_coords = 1;
- /*sampler.lod_bias = ;*/
- /*sampler.min_lod = ;*/
- /*sampler.max_lod = ;*/
- /*sampler.border_color[i] = ;*/
- /*sampler.max_anisotropy = ;*/
- c->sampler = c->pipe->create_sampler_state(c->pipe, &sampler);
-
- vertex_elems[0].src_offset = 0;
- vertex_elems[0].instance_divisor = 0;
- vertex_elems[0].vertex_buffer_index = 0;
- vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT;
- vertex_elems[1].src_offset = 0;
- vertex_elems[1].instance_divisor = 0;
- vertex_elems[1].vertex_buffer_index = 1;
- vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
- c->vertex_elems = c->pipe->create_vertex_elements_state(c->pipe, 2, vertex_elems);
-
-
- return true;
-}
-
-static void cleanup_pipe_state(struct vl_compositor *c)
-{
- assert(c);
-
- c->pipe->delete_sampler_state(c->pipe, c->sampler);
- c->pipe->delete_vertex_elements_state(c->pipe, c->vertex_elems);
-}
-
-static bool
-init_shaders(struct vl_compositor *c)
-{
- assert(c);
-
- create_vert_shader(c);
- create_frag_shader(c);
-
- return true;
-}
-
-static void cleanup_shaders(struct vl_compositor *c)
-{
- assert(c);
-
- c->pipe->delete_vs_state(c->pipe, c->vertex_shader);
- c->pipe->delete_fs_state(c->pipe, c->fragment_shader);
-}
-
-static bool
-init_buffers(struct vl_compositor *c)
-{
- struct fragment_shader_consts fsc;
-
- assert(c);
-
- /*
- * Create our vertex buffer and vertex buffer element
- * VB contains 4 vertices that render a quad covering the entire window
- * to display a rendered surface
- * Quad is rendered as a tri strip
- */
- c->vertex_bufs[0].stride = sizeof(struct vertex2f);
- c->vertex_bufs[0].max_index = 3;
- c->vertex_bufs[0].buffer_offset = 0;
- c->vertex_bufs[0].buffer = pipe_buffer_create
- (
- c->pipe->screen,
- 1,
- PIPE_BUFFER_USAGE_VERTEX,
- sizeof(struct vertex2f) * 4
- );
-
- memcpy
- (
- pipe_buffer_map(c->pipe->screen, c->vertex_bufs[0].buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
- surface_verts,
- sizeof(struct vertex2f) * 4
- );
-
- pipe_buffer_unmap(c->pipe->screen, c->vertex_bufs[0].buffer);
-
- /*
- * Create our texcoord buffer and texcoord buffer element
- * Texcoord buffer contains the TCs for mapping the rendered surface to the 4 vertices
- */
- c->vertex_bufs[1].stride = sizeof(struct vertex2f);
- c->vertex_bufs[1].max_index = 3;
- c->vertex_bufs[1].buffer_offset = 0;
- c->vertex_bufs[1].buffer = pipe_buffer_create
- (
- c->pipe->screen,
- 1,
- PIPE_BUFFER_USAGE_VERTEX,
- sizeof(struct vertex2f) * 4
- );
-
- memcpy
- (
- pipe_buffer_map(c->pipe->screen, c->vertex_bufs[1].buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
- surface_texcoords,
- sizeof(struct vertex2f) * 4
- );
-
- pipe_buffer_unmap(c->pipe->screen, c->vertex_bufs[1].buffer);
-
- /*
- * Create our vertex shader's constant buffer
- * Const buffer contains scaling and translation vectors
- */
- c->vs_const_buf = pipe_buffer_create
- (
- c->pipe->screen,
- 1,
- PIPE_BUFFER_USAGE_CONSTANT | PIPE_BUFFER_USAGE_DISCARD,
- sizeof(struct vertex_shader_consts)
- );
-
- /*
- * Create our fragment shader's constant buffer
- * Const buffer contains the color conversion matrix and bias vectors
- */
- c->fs_const_buf = pipe_buffer_create
- (
- c->pipe->screen,
- 1,
- PIPE_BUFFER_USAGE_CONSTANT,
- sizeof(struct fragment_shader_consts)
- );
-
- vl_csc_get_matrix(VL_CSC_COLOR_STANDARD_IDENTITY, NULL, true, fsc.matrix);
-
- vl_compositor_set_csc_matrix(c, fsc.matrix);
-
- return true;
-}
-
-static void
-cleanup_buffers(struct vl_compositor *c)
-{
- unsigned i;
-
- assert(c);
-
- for (i = 0; i < 2; ++i)
- pipe_buffer_reference(&c->vertex_bufs[i].buffer, NULL);
-
- pipe_buffer_reference(&c->vs_const_buf, NULL);
- pipe_buffer_reference(&c->fs_const_buf, NULL);
-}
-
-bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe)
-{
- assert(compositor);
-
- memset(compositor, 0, sizeof(struct vl_compositor));
-
- compositor->pipe = pipe;
-
- if (!init_pipe_state(compositor))
- return false;
- if (!init_shaders(compositor)) {
- cleanup_pipe_state(compositor);
- return false;
- }
- if (!init_buffers(compositor)) {
- cleanup_shaders(compositor);
- cleanup_pipe_state(compositor);
- return false;
- }
-
- return true;
-}
-
-void vl_compositor_cleanup(struct vl_compositor *compositor)
-{
- assert(compositor);
-
- cleanup_buffers(compositor);
- cleanup_shaders(compositor);
- cleanup_pipe_state(compositor);
-}
-
-void vl_compositor_render(struct vl_compositor *compositor,
- /*struct pipe_texture *backround,
- struct pipe_video_rect *backround_area,*/
- struct pipe_texture *src_surface,
- enum pipe_mpeg12_picture_type picture_type,
- /*unsigned num_past_surfaces,
- struct pipe_texture *past_surfaces,
- unsigned num_future_surfaces,
- struct pipe_texture *future_surfaces,*/
- struct pipe_video_rect *src_area,
- struct pipe_texture *dst_surface,
- struct pipe_video_rect *dst_area,
- /*unsigned num_layers,
- struct pipe_texture *layers,
- struct pipe_video_rect *layer_src_areas,
- struct pipe_video_rect *layer_dst_areas*/
- struct pipe_fence_handle **fence)
-{
- struct vertex_shader_consts *vs_consts;
-
- assert(compositor);
- assert(src_surface);
- assert(src_area);
- assert(dst_surface);
- assert(dst_area);
- assert(picture_type == PIPE_MPEG12_PICTURE_TYPE_FRAME);
-
- compositor->fb_state.width = dst_surface->width0;
- compositor->fb_state.height = dst_surface->height0;
- compositor->fb_state.cbufs[0] = compositor->pipe->screen->get_tex_surface
- (
- compositor->pipe->screen,
- dst_surface,
- 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE
- );
-
- compositor->viewport.scale[0] = compositor->fb_state.width;
- compositor->viewport.scale[1] = compositor->fb_state.height;
- compositor->viewport.scale[2] = 1;
- compositor->viewport.scale[3] = 1;
- compositor->viewport.translate[0] = 0;
- compositor->viewport.translate[1] = 0;
- compositor->viewport.translate[2] = 0;
- compositor->viewport.translate[3] = 0;
-
- compositor->scissor.maxx = compositor->fb_state.width;
- compositor->scissor.maxy = compositor->fb_state.height;
-
- compositor->pipe->set_framebuffer_state(compositor->pipe, &compositor->fb_state);
- compositor->pipe->set_viewport_state(compositor->pipe, &compositor->viewport);
- compositor->pipe->set_scissor_state(compositor->pipe, &compositor->scissor);
- compositor->pipe->bind_fragment_sampler_states(compositor->pipe, 1, &compositor->sampler);
- compositor->pipe->set_fragment_sampler_textures(compositor->pipe, 1, &src_surface);
- compositor->pipe->bind_vs_state(compositor->pipe, compositor->vertex_shader);
- compositor->pipe->bind_fs_state(compositor->pipe, compositor->fragment_shader);
- compositor->pipe->set_vertex_buffers(compositor->pipe, 2, compositor->vertex_bufs);
- compositor->pipe->bind_vertex_elements_state(compositor->pipe, compositor->vertex_elems);
- compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_VERTEX, 0, compositor->vs_const_buf);
- compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_FRAGMENT, 0, compositor->fs_const_buf);
-
- vs_consts = pipe_buffer_map
- (
- compositor->pipe->screen,
- compositor->vs_const_buf,
- PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
- );
-
- vs_consts->dst_scale.x = dst_area->w / (float)compositor->fb_state.cbufs[0]->width;
- vs_consts->dst_scale.y = dst_area->h / (float)compositor->fb_state.cbufs[0]->height;
- vs_consts->dst_scale.z = 1;
- vs_consts->dst_scale.w = 1;
- vs_consts->dst_trans.x = dst_area->x / (float)compositor->fb_state.cbufs[0]->width;
- vs_consts->dst_trans.y = dst_area->y / (float)compositor->fb_state.cbufs[0]->height;
- vs_consts->dst_trans.z = 0;
- vs_consts->dst_trans.w = 0;
-
- vs_consts->src_scale.x = src_area->w / (float)src_surface->width0;
- vs_consts->src_scale.y = src_area->h / (float)src_surface->height0;
- vs_consts->src_scale.z = 1;
- vs_consts->src_scale.w = 1;
- vs_consts->src_trans.x = src_area->x / (float)src_surface->width0;
- vs_consts->src_trans.y = src_area->y / (float)src_surface->height0;
- vs_consts->src_trans.z = 0;
- vs_consts->src_trans.w = 0;
-
- pipe_buffer_unmap(compositor->pipe->screen, compositor->vs_const_buf);
-
- compositor->pipe->draw_arrays(compositor->pipe, PIPE_PRIM_TRIANGLE_STRIP, 0, 4);
- compositor->pipe->flush(compositor->pipe, PIPE_FLUSH_RENDER_CACHE, fence);
-
- pipe_surface_reference(&compositor->fb_state.cbufs[0], NULL);
-}
-
-void vl_compositor_set_csc_matrix(struct vl_compositor *compositor, const float *mat)
-{
- assert(compositor);
-
- memcpy
- (
- pipe_buffer_map(compositor->pipe->screen, compositor->fs_const_buf, PIPE_BUFFER_USAGE_CPU_WRITE),
- mat,
- sizeof(struct fragment_shader_consts)
- );
-
- pipe_buffer_unmap(compositor->pipe->screen, compositor->fs_const_buf);
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 vl_compositor_h
-#define vl_compositor_h
-
-#include <pipe/p_compiler.h>
-#include <pipe/p_state.h>
-#include <pipe/p_video_state.h>
-
-struct pipe_context;
-struct pipe_texture;
-
-struct vl_compositor
-{
- struct pipe_context *pipe;
-
- struct pipe_framebuffer_state fb_state;
- void *sampler;
- void *vertex_shader;
- void *fragment_shader;
- void *vertex_elems;
- struct pipe_viewport_state viewport;
- struct pipe_scissor_state scissor;
- struct pipe_vertex_buffer vertex_bufs[2];
- struct pipe_buffer *vs_const_buf, *fs_const_buf;
-};
-
-bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe);
-
-void vl_compositor_cleanup(struct vl_compositor *compositor);
-
-void vl_compositor_render(struct vl_compositor *compositor,
- /*struct pipe_texture *backround,
- struct pipe_video_rect *backround_area,*/
- struct pipe_texture *src_surface,
- enum pipe_mpeg12_picture_type picture_type,
- /*unsigned num_past_surfaces,
- struct pipe_texture *past_surfaces,
- unsigned num_future_surfaces,
- struct pipe_texture *future_surfaces,*/
- struct pipe_video_rect *src_area,
- struct pipe_texture *dst_surface,
- struct pipe_video_rect *dst_area,
- /*unsigned num_layers,
- struct pipe_texture *layers,
- struct pipe_video_rect *layer_src_areas,
- struct pipe_video_rect *layer_dst_areas,*/
- struct pipe_fence_handle **fence);
-
-void vl_compositor_set_csc_matrix(struct vl_compositor *compositor, const float *mat);
-
-#endif /* vl_compositor_h */
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include "vl_csc.h"
-#include <util/u_math.h>
-#include <util/u_debug.h>
-
-/*
- * Color space conversion formulas
- *
- * To convert YCbCr to RGB,
- * vec4 ycbcr, rgb
- * mat44 csc
- * rgb = csc * ycbcr
- *
- * To calculate the color space conversion matrix csc with ProcAmp adjustments,
- * mat44 csc, cstd, procamp, bias
- * csc = cstd * (procamp * bias)
- *
- * Where cstd is a matrix corresponding to one of the color standards (BT.601, BT.709, etc)
- * adjusted for the kind of YCbCr -> RGB mapping wanted (1:1, full),
- * bias is a matrix corresponding to the kind of YCbCr -> RGB mapping wanted (1:1, full)
- *
- * To calculate procamp,
- * mat44 procamp, hue, saturation, brightness, contrast
- * procamp = brightness * (saturation * (contrast * hue))
- * Alternatively,
- * procamp = saturation * (brightness * (contrast * hue))
- *
- * contrast
- * [ c, 0, 0, 0]
- * [ 0, c, 0, 0]
- * [ 0, 0, c, 0]
- * [ 0, 0, 0, 1]
- *
- * brightness
- * [ 1, 0, 0, b]
- * [ 0, 1, 0, 0]
- * [ 0, 0, 1, 0]
- * [ 0, 0, 0, 1]
- *
- * saturation
- * [ 1, 0, 0, 0]
- * [ 0, s, 0, 0]
- * [ 0, 0, s, 0]
- * [ 0, 0, 0, 1]
- *
- * hue
- * [ 1, 0, 0, 0]
- * [ 0, cos(h), sin(h), 0]
- * [ 0, -sin(h), cos(h), 0]
- * [ 0, 0, 0, 1]
- *
- * procamp
- * [ c, 0, 0, b]
- * [ 0, c*s*cos(h), c*s*sin(h), 0]
- * [ 0, -c*s*sin(h), c*s*cos(h), 0]
- * [ 0, 0, 0, 1]
- *
- * bias
- * [ 1, 0, 0, ybias]
- * [ 0, 1, 0, cbbias]
- * [ 0, 0, 1, crbias]
- * [ 0, 0, 0, 1]
- *
- * csc
- * [ c*cstd[ 0], c*cstd[ 1]*s*cos(h) - c*cstd[ 2]*s*sin(h), c*cstd[ 2]*s*cos(h) + c*cstd[ 1]*s*sin(h), cstd[ 3] + cstd[ 0]*(b + c*ybias) + cstd[ 1]*(c*cbbias*s*cos(h) + c*crbias*s*sin(h)) + cstd[ 2]*(c*crbias*s*cos(h) - c*cbbias*s*sin(h))]
- * [ c*cstd[ 4], c*cstd[ 5]*s*cos(h) - c*cstd[ 6]*s*sin(h), c*cstd[ 6]*s*cos(h) + c*cstd[ 5]*s*sin(h), cstd[ 7] + cstd[ 4]*(b + c*ybias) + cstd[ 5]*(c*cbbias*s*cos(h) + c*crbias*s*sin(h)) + cstd[ 6]*(c*crbias*s*cos(h) - c*cbbias*s*sin(h))]
- * [ c*cstd[ 8], c*cstd[ 9]*s*cos(h) - c*cstd[10]*s*sin(h), c*cstd[10]*s*cos(h) + c*cstd[ 9]*s*sin(h), cstd[11] + cstd[ 8]*(b + c*ybias) + cstd[ 9]*(c*cbbias*s*cos(h) + c*crbias*s*sin(h)) + cstd[10]*(c*crbias*s*cos(h) - c*cbbias*s*sin(h))]
- * [ c*cstd[12], c*cstd[13]*s*cos(h) - c*cstd[14]*s*sin(h), c*cstd[14]*s*cos(h) + c*cstd[13]*s*sin(h), cstd[15] + cstd[12]*(b + c*ybias) + cstd[13]*(c*cbbias*s*cos(h) + c*crbias*s*sin(h)) + cstd[14]*(c*crbias*s*cos(h) - c*cbbias*s*sin(h))]
- */
-
-/*
- * Converts ITU-R BT.601 YCbCr pixels to RGB pixels where:
- * Y is in [16,235], Cb and Cr are in [16,240]
- * R, G, and B are in [16,235]
- */
-static const float bt_601[16] =
-{
- 1.0f, 0.0f, 1.371f, 0.0f,
- 1.0f, -0.336f, -0.698f, 0.0f,
- 1.0f, 1.732f, 0.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
-};
-
-/*
- * Converts ITU-R BT.601 YCbCr pixels to RGB pixels where:
- * Y is in [16,235], Cb and Cr are in [16,240]
- * R, G, and B are in [0,255]
- */
-static const float bt_601_full[16] =
-{
- 1.164f, 0.0f, 1.596f, 0.0f,
- 1.164f, -0.391f, -0.813f, 0.0f,
- 1.164f, 2.018f, 0.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
-};
-
-/*
- * Converts ITU-R BT.709 YCbCr pixels to RGB pixels where:
- * Y is in [16,235], Cb and Cr are in [16,240]
- * R, G, and B are in [16,235]
- */
-static const float bt_709[16] =
-{
- 1.0f, 0.0f, 1.540f, 0.0f,
- 1.0f, -0.183f, -0.459f, 0.0f,
- 1.0f, 1.816f, 0.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
-};
-
-/*
- * Converts ITU-R BT.709 YCbCr pixels to RGB pixels where:
- * Y is in [16,235], Cb and Cr are in [16,240]
- * R, G, and B are in [0,255]
- */
-static const float bt_709_full[16] =
-{
- 1.164f, 0.0f, 1.793f, 0.0f,
- 1.164f, -0.213f, -0.534f, 0.0f,
- 1.164f, 2.115f, 0.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
-};
-
-static const float identity[16] =
-{
- 1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
-};
-
-void vl_csc_get_matrix(enum VL_CSC_COLOR_STANDARD cs,
- struct vl_procamp *procamp,
- bool full_range,
- float *matrix)
-{
- float ybias = full_range ? -16.0f/255.0f : 0.0f;
- float cbbias = -128.0f/255.0f;
- float crbias = -128.0f/255.0f;
- float c = procamp ? procamp->contrast : 1.0f;
- float s = procamp ? procamp->saturation : 1.0f;
- float b = procamp ? procamp->brightness : 0.0f;
- float h = procamp ? procamp->hue : 0.0f;
- const float *cstd;
-
- assert(matrix);
-
- switch (cs) {
- case VL_CSC_COLOR_STANDARD_BT_601:
- cstd = full_range ? &bt_601_full[0] : &bt_601[0];
- break;
- case VL_CSC_COLOR_STANDARD_BT_709:
- cstd = full_range ? &bt_709_full[0] : &bt_709[0];
- break;
- case VL_CSC_COLOR_STANDARD_IDENTITY:
- default:
- assert(cs == VL_CSC_COLOR_STANDARD_IDENTITY);
- memcpy(matrix, &identity[0], sizeof(float) * 16);
- return;
- }
-
- matrix[ 0] = c*cstd[ 0];
- matrix[ 1] = c*cstd[ 1]*s*cosf(h) - c*cstd[ 2]*s*sinf(h);
- matrix[ 2] = c*cstd[ 2]*s*cosf(h) + c*cstd[ 1]*s*sinf(h);
- matrix[ 3] = cstd[ 3] + cstd[ 0]*(b + c*ybias) + cstd[ 1]*(c*cbbias*s*cosf(h) + c*crbias*s*sinf(h)) + cstd[ 2]*(c*crbias*s*cosf(h) - c*cbbias*s*sinf(h));
-
- matrix[ 4] = c*cstd[ 4];
- matrix[ 5] = c*cstd[ 5]*s*cosf(h) - c*cstd[ 6]*s*sinf(h);
- matrix[ 6] = c*cstd[ 6]*s*cosf(h) + c*cstd[ 5]*s*sinf(h);
- matrix[ 7] = cstd[ 7] + cstd[ 4]*(b + c*ybias) + cstd[ 5]*(c*cbbias*s*cosf(h) + c*crbias*s*sinf(h)) + cstd[ 6]*(c*crbias*s*cosf(h) - c*cbbias*s*sinf(h));
-
- matrix[ 8] = c*cstd[ 8];
- matrix[ 9] = c*cstd[ 9]*s*cosf(h) - c*cstd[10]*s*sinf(h);
- matrix[10] = c*cstd[10]*s*cosf(h) + c*cstd[ 9]*s*sinf(h);
- matrix[11] = cstd[11] + cstd[ 8]*(b + c*ybias) + cstd[ 9]*(c*cbbias*s*cosf(h) + c*crbias*s*sinf(h)) + cstd[10]*(c*crbias*s*cosf(h) - c*cbbias*s*sinf(h));
-
- matrix[12] = c*cstd[12];
- matrix[13] = c*cstd[13]*s*cos(h) - c*cstd[14]*s*sin(h);
- matrix[14] = c*cstd[14]*s*cos(h) + c*cstd[13]*s*sin(h);
- matrix[15] = cstd[15] + cstd[12]*(b + c*ybias) + cstd[13]*(c*cbbias*s*cos(h) + c*crbias*s*sin(h)) + cstd[14]*(c*crbias*s*cos(h) - c*cbbias*s*sin(h));
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 vl_csc_h
-#define vl_csc_h
-
-#include <pipe/p_compiler.h>
-
-struct vl_procamp
-{
- float brightness;
- float contrast;
- float saturation;
- float hue;
-};
-
-enum VL_CSC_COLOR_STANDARD
-{
- VL_CSC_COLOR_STANDARD_IDENTITY,
- VL_CSC_COLOR_STANDARD_BT_601,
- VL_CSC_COLOR_STANDARD_BT_709
-};
-
-void vl_csc_get_matrix(enum VL_CSC_COLOR_STANDARD cs,
- struct vl_procamp *procamp,
- bool full_range,
- float *matrix);
-
-#endif /* vl_csc_h */
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include "vl_mpeg12_mc_renderer.h"
-#include <assert.h>
-#include <pipe/p_context.h>
-#include <util/u_inlines.h>
-#include <util/u_format.h>
-#include <util/u_math.h>
-#include <util/u_memory.h>
-#include <tgsi/tgsi_parse.h>
-#include <tgsi/tgsi_build.h>
-#include "vl_shader_build.h"
-
-#define DEFAULT_BUF_ALIGNMENT 1
-#define MACROBLOCK_WIDTH 16
-#define MACROBLOCK_HEIGHT 16
-#define BLOCK_WIDTH 8
-#define BLOCK_HEIGHT 8
-#define ZERO_BLOCK_NIL -1.0f
-#define ZERO_BLOCK_IS_NIL(zb) ((zb).x < 0.0f)
-
-struct vertex2f
-{
- float x, y;
-};
-
-struct vertex4f
-{
- float x, y, z, w;
-};
-
-struct vertex_shader_consts
-{
- struct vertex4f denorm;
-};
-
-struct fragment_shader_consts
-{
- struct vertex4f multiplier;
- struct vertex4f div;
-};
-
-/*
- * Muliplier renormalizes block samples from 16 bits to 12 bits.
- * Divider is used when calculating Y % 2 for choosing top or bottom
- * field for P or B macroblocks.
- * TODO: Use immediates.
- */
-static const struct fragment_shader_consts fs_consts = {
- {32767.0f / 255.0f, 32767.0f / 255.0f, 32767.0f / 255.0f, 0.0f},
- {0.5f, 2.0f, 0.0f, 0.0f}
-};
-
-struct vert_stream_0
-{
- struct vertex2f pos;
- struct vertex2f luma_tc;
- struct vertex2f cb_tc;
- struct vertex2f cr_tc;
-};
-
-enum MACROBLOCK_TYPE
-{
- MACROBLOCK_TYPE_INTRA,
- MACROBLOCK_TYPE_FWD_FRAME_PRED,
- MACROBLOCK_TYPE_FWD_FIELD_PRED,
- MACROBLOCK_TYPE_BKWD_FRAME_PRED,
- MACROBLOCK_TYPE_BKWD_FIELD_PRED,
- MACROBLOCK_TYPE_BI_FRAME_PRED,
- MACROBLOCK_TYPE_BI_FIELD_PRED,
-
- NUM_MACROBLOCK_TYPES
-};
-
-static void
-create_intra_vert_shader(struct vl_mpeg12_mc_renderer *r)
-{
- const unsigned max_tokens = 50;
-
- struct pipe_shader_state vs;
- struct tgsi_token *tokens;
- struct tgsi_header *header;
-
- struct tgsi_full_declaration decl;
- struct tgsi_full_instruction inst;
-
- unsigned ti;
-
- unsigned i;
-
- assert(r);
-
- tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
- header = (struct tgsi_header *) &tokens[0];
- *header = tgsi_build_header();
- *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header);
-
- ti = 2;
-
- /*
- * decl i0 ; Vertex pos
- * decl i1 ; Luma texcoords
- * decl i2 ; Chroma Cb texcoords
- * decl i3 ; Chroma Cr texcoords
- */
- for (i = 0; i < 4; i++) {
- decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * decl o0 ; Vertex pos
- * decl o1 ; Luma texcoords
- * decl o2 ; Chroma Cb texcoords
- * decl o3 ; Chroma Cr texcoords
- */
- for (i = 0; i < 4; i++) {
- decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * mov o0, i0 ; Move input vertex pos to output
- * mov o1, i1 ; Move input luma texcoords to output
- * mov o2, i2 ; Move input chroma Cb texcoords to output
- * mov o3, i3 ; Move input chroma Cr texcoords to output
- */
- for (i = 0; i < 4; ++i) {
- inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* end */
- inst = vl_end();
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- assert(ti <= max_tokens);
-
- vs.tokens = tokens;
- r->i_vs = r->pipe->create_vs_state(r->pipe, &vs);
- free(tokens);
-}
-
-static void
-create_intra_frag_shader(struct vl_mpeg12_mc_renderer *r)
-{
- const unsigned max_tokens = 100;
-
- struct pipe_shader_state fs;
- struct tgsi_token *tokens;
- struct tgsi_header *header;
-
- struct tgsi_full_declaration decl;
- struct tgsi_full_instruction inst;
-
- unsigned ti;
-
- unsigned i;
-
- assert(r);
-
- tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
- header = (struct tgsi_header *) &tokens[0];
- *header = tgsi_build_header();
- *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header);
-
- ti = 2;
-
- /*
- * decl i0 ; Luma texcoords
- * decl i1 ; Chroma Cb texcoords
- * decl i2 ; Chroma Cr texcoords
- */
- for (i = 0; i < 3; ++i) {
- decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /* decl c0 ; Scaling factor, rescales 16-bit snorm to 9-bit snorm */
- decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 0);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl o0 ; Fragment color */
- decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl t0, t1 */
- decl = vl_decl_temps(0, 1);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /*
- * decl s0 ; Sampler for luma texture
- * decl s1 ; Sampler for chroma Cb texture
- * decl s2 ; Sampler for chroma Cr texture
- */
- for (i = 0; i < 3; ++i) {
- decl = vl_decl_samplers(i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * tex2d t1, i0, s0 ; Read texel from luma texture
- * mov t0.x, t1.x ; Move luma sample into .x component
- * tex2d t1, i1, s1 ; Read texel from chroma Cb texture
- * mov t0.y, t1.x ; Move Cb sample into .y component
- * tex2d t1, i2, s2 ; Read texel from chroma Cr texture
- * mov t0.z, t1.x ; Move Cr sample into .z component
- */
- for (i = 0; i < 3; ++i) {
- inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
- inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
- inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X << i;
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* mul o0, t0, c0 ; Rescale texel to correct range */
- inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /* end */
- inst = vl_end();
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- assert(ti <= max_tokens);
-
- fs.tokens = tokens;
- r->i_fs = r->pipe->create_fs_state(r->pipe, &fs);
- free(tokens);
-}
-
-static void
-create_frame_pred_vert_shader(struct vl_mpeg12_mc_renderer *r)
-{
- const unsigned max_tokens = 100;
-
- struct pipe_shader_state vs;
- struct tgsi_token *tokens;
- struct tgsi_header *header;
-
- struct tgsi_full_declaration decl;
- struct tgsi_full_instruction inst;
-
- unsigned ti;
-
- unsigned i;
-
- assert(r);
-
- tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
- header = (struct tgsi_header *) &tokens[0];
- *header = tgsi_build_header();
- *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header);
-
- ti = 2;
-
- /*
- * decl i0 ; Vertex pos
- * decl i1 ; Luma texcoords
- * decl i2 ; Chroma Cb texcoords
- * decl i3 ; Chroma Cr texcoords
- * decl i4 ; Ref surface top field texcoords
- * decl i5 ; Ref surface bottom field texcoords (unused, packed in the same stream)
- */
- for (i = 0; i < 6; i++) {
- decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * decl o0 ; Vertex pos
- * decl o1 ; Luma texcoords
- * decl o2 ; Chroma Cb texcoords
- * decl o3 ; Chroma Cr texcoords
- * decl o4 ; Ref macroblock texcoords
- */
- for (i = 0; i < 5; i++) {
- decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * mov o0, i0 ; Move input vertex pos to output
- * mov o1, i1 ; Move input luma texcoords to output
- * mov o2, i2 ; Move input chroma Cb texcoords to output
- * mov o3, i3 ; Move input chroma Cr texcoords to output
- */
- for (i = 0; i < 4; ++i) {
- inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* add o4, i0, i4 ; Translate vertex pos by motion vec to form ref macroblock texcoords */
- inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 4, TGSI_FILE_INPUT, 0, TGSI_FILE_INPUT, 4);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /* end */
- inst = vl_end();
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- assert(ti <= max_tokens);
-
- vs.tokens = tokens;
- r->p_vs[0] = r->pipe->create_vs_state(r->pipe, &vs);
- free(tokens);
-}
-
-#if 0
-static void
-create_field_pred_vert_shader(struct vl_mpeg12_mc_renderer *r)
-{
- assert(false);
-}
-#endif
-
-static void
-create_frame_pred_frag_shader(struct vl_mpeg12_mc_renderer *r)
-{
- const unsigned max_tokens = 100;
-
- struct pipe_shader_state fs;
- struct tgsi_token *tokens;
- struct tgsi_header *header;
-
- struct tgsi_full_declaration decl;
- struct tgsi_full_instruction inst;
-
- unsigned ti;
-
- unsigned i;
-
- assert(r);
-
- tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
- header = (struct tgsi_header *) &tokens[0];
- *header = tgsi_build_header();
- *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header);
-
- ti = 2;
-
- /*
- * decl i0 ; Luma texcoords
- * decl i1 ; Chroma Cb texcoords
- * decl i2 ; Chroma Cr texcoords
- * decl i3 ; Ref macroblock texcoords
- */
- for (i = 0; i < 4; ++i) {
- decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /* decl c0 ; Scaling factor, rescales 16-bit snorm to 9-bit snorm */
- decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 0);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl o0 ; Fragment color */
- decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl t0, t1 */
- decl = vl_decl_temps(0, 1);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /*
- * decl s0 ; Sampler for luma texture
- * decl s1 ; Sampler for chroma Cb texture
- * decl s2 ; Sampler for chroma Cr texture
- * decl s3 ; Sampler for ref surface texture
- */
- for (i = 0; i < 4; ++i) {
- decl = vl_decl_samplers(i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * tex2d t1, i0, s0 ; Read texel from luma texture
- * mov t0.x, t1.x ; Move luma sample into .x component
- * tex2d t1, i1, s1 ; Read texel from chroma Cb texture
- * mov t0.y, t1.x ; Move Cb sample into .y component
- * tex2d t1, i2, s2 ; Read texel from chroma Cr texture
- * mov t0.z, t1.x ; Move Cr sample into .z component
- */
- for (i = 0; i < 3; ++i) {
- inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
- inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
- inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X << i;
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* mul t0, t0, c0 ; Rescale texel to correct range */
- inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /* tex2d t1, i3, s3 ; Read texel from ref macroblock */
- inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, 3, TGSI_FILE_SAMPLER, 3);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /* add o0, t0, t1 ; Add ref and differential to form final output */
- inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /* end */
- inst = vl_end();
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- assert(ti <= max_tokens);
-
- fs.tokens = tokens;
- r->p_fs[0] = r->pipe->create_fs_state(r->pipe, &fs);
- free(tokens);
-}
-
-#if 0
-static void
-create_field_pred_frag_shader(struct vl_mpeg12_mc_renderer *r)
-{
- assert(false);
-}
-#endif
-
-static void
-create_frame_bi_pred_vert_shader(struct vl_mpeg12_mc_renderer *r)
-{
- const unsigned max_tokens = 100;
-
- struct pipe_shader_state vs;
- struct tgsi_token *tokens;
- struct tgsi_header *header;
-
- struct tgsi_full_declaration decl;
- struct tgsi_full_instruction inst;
-
- unsigned ti;
-
- unsigned i;
-
- assert(r);
-
- tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
- header = (struct tgsi_header *) &tokens[0];
- *header = tgsi_build_header();
- *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header);
-
- ti = 2;
-
- /*
- * decl i0 ; Vertex pos
- * decl i1 ; Luma texcoords
- * decl i2 ; Chroma Cb texcoords
- * decl i3 ; Chroma Cr texcoords
- * decl i4 ; First ref macroblock top field texcoords
- * decl i5 ; First ref macroblock bottom field texcoords (unused, packed in the same stream)
- * decl i6 ; Second ref macroblock top field texcoords
- * decl i7 ; Second ref macroblock bottom field texcoords (unused, packed in the same stream)
- */
- for (i = 0; i < 8; i++) {
- decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * decl o0 ; Vertex pos
- * decl o1 ; Luma texcoords
- * decl o2 ; Chroma Cb texcoords
- * decl o3 ; Chroma Cr texcoords
- * decl o4 ; First ref macroblock texcoords
- * decl o5 ; Second ref macroblock texcoords
- */
- for (i = 0; i < 6; i++) {
- decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * mov o0, i0 ; Move input vertex pos to output
- * mov o1, i1 ; Move input luma texcoords to output
- * mov o2, i2 ; Move input chroma Cb texcoords to output
- * mov o3, i3 ; Move input chroma Cr texcoords to output
- */
- for (i = 0; i < 4; ++i) {
- inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * add o4, i0, i4 ; Translate vertex pos by motion vec to form first ref macroblock texcoords
- * add o5, i0, i6 ; Translate vertex pos by motion vec to form second ref macroblock texcoords
- */
- for (i = 0; i < 2; ++i) {
- inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, i + 4, TGSI_FILE_INPUT, 0, TGSI_FILE_INPUT, (i + 2) * 2);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* end */
- inst = vl_end();
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- assert(ti <= max_tokens);
-
- vs.tokens = tokens;
- r->b_vs[0] = r->pipe->create_vs_state(r->pipe, &vs);
- free(tokens);
-}
-
-#if 0
-static void
-create_field_bi_pred_vert_shader(struct vl_mpeg12_mc_renderer *r)
-{
- assert(false);
-}
-#endif
-
-static void
-create_frame_bi_pred_frag_shader(struct vl_mpeg12_mc_renderer *r)
-{
- const unsigned max_tokens = 100;
-
- struct pipe_shader_state fs;
- struct tgsi_token *tokens;
- struct tgsi_header *header;
-
- struct tgsi_full_declaration decl;
- struct tgsi_full_instruction inst;
-
- unsigned ti;
-
- unsigned i;
-
- assert(r);
-
- tokens = (struct tgsi_token *) malloc(max_tokens * sizeof(struct tgsi_token));
- header = (struct tgsi_header *) &tokens[0];
- *header = tgsi_build_header();
- *(struct tgsi_processor *) &tokens[1] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header);
-
- ti = 2;
-
- /*
- * decl i0 ; Luma texcoords
- * decl i1 ; Chroma Cb texcoords
- * decl i2 ; Chroma Cr texcoords
- * decl i3 ; First ref macroblock texcoords
- * decl i4 ; Second ref macroblock texcoords
- */
- for (i = 0; i < 5; ++i) {
- decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * decl c0 ; Scaling factor, rescales 16-bit snorm to 9-bit snorm
- * decl c1 ; Constant 1/2 in .x channel to use as weight to blend past and future texels
- */
- decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 1);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl o0 ; Fragment color */
- decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /* decl t0-t2 */
- decl = vl_decl_temps(0, 2);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
-
- /*
- * decl s0 ; Sampler for luma texture
- * decl s1 ; Sampler for chroma Cb texture
- * decl s2 ; Sampler for chroma Cr texture
- * decl s3 ; Sampler for first ref surface texture
- * decl s4 ; Sampler for second ref surface texture
- */
- for (i = 0; i < 5; ++i) {
- decl = vl_decl_samplers(i, i);
- ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
- }
-
- /*
- * tex2d t1, i0, s0 ; Read texel from luma texture
- * mov t0.x, t1.x ; Move luma sample into .x component
- * tex2d t1, i1, s1 ; Read texel from chroma Cb texture
- * mov t0.y, t1.x ; Move Cb sample into .y component
- * tex2d t1, i2, s2 ; Read texel from chroma Cr texture
- * mov t0.z, t1.x ; Move Cr sample into .z component
- */
- for (i = 0; i < 3; ++i) {
- inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
- inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
- inst.Dst[0].Register.WriteMask = TGSI_WRITEMASK_X << i;
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* mul t0, t0, c0 ; Rescale texel to correct range */
- inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /*
- * tex2d t1, i3, s3 ; Read texel from first ref macroblock
- * tex2d t2, i4, s4 ; Read texel from second ref macroblock
- */
- for (i = 0; i < 2; ++i) {
- inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, i + 1, TGSI_FILE_INPUT, i + 3, TGSI_FILE_SAMPLER, i + 3);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- }
-
- /* lerp t1, c1.x, t1, t2 ; Blend past and future texels */
- inst = vl_inst4(TGSI_OPCODE_LRP, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_CONSTANT, 1, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_TEMPORARY, 2);
- inst.Src[0].Register.SwizzleX = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleY = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleZ = TGSI_SWIZZLE_X;
- inst.Src[0].Register.SwizzleW = TGSI_SWIZZLE_X;
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /* add o0, t0, t1 ; Add past/future ref and differential to form final output */
- inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1);
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- /* end */
- inst = vl_end();
- ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
-
- assert(ti <= max_tokens);
-
- fs.tokens = tokens;
- r->b_fs[0] = r->pipe->create_fs_state(r->pipe, &fs);
- free(tokens);
-}
-
-#if 0
-static void
-create_field_bi_pred_frag_shader(struct vl_mpeg12_mc_renderer *r)
-{
- assert(false);
-}
-#endif
-
-static void
-xfer_buffers_map(struct vl_mpeg12_mc_renderer *r)
-{
- unsigned i;
-
- assert(r);
-
- for (i = 0; i < 3; ++i) {
- r->tex_transfer[i] = r->pipe->get_tex_transfer
- (
- r->pipe, r->textures.all[i],
- 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0,
- r->textures.all[i]->width0, r->textures.all[i]->height0
- );
-
- r->texels[i] = r->pipe->transfer_map(r->pipe, r->tex_transfer[i]);
- }
-}
-
-static void
-xfer_buffers_unmap(struct vl_mpeg12_mc_renderer *r)
-{
- unsigned i;
-
- assert(r);
-
- for (i = 0; i < 3; ++i) {
- r->pipe->transfer_unmap(r->pipe, r->tex_transfer[i]);
- r->pipe->tex_transfer_destroy(r->pipe, r->tex_transfer[i]);
- }
-}
-
-static bool
-init_pipe_state(struct vl_mpeg12_mc_renderer *r)
-{
- struct pipe_sampler_state sampler;
- struct pipe_vertex_element vertex_elems[8];
- unsigned filters[5];
- unsigned i;
-
- assert(r);
-
- r->viewport.scale[0] = r->pot_buffers ?
- util_next_power_of_two(r->picture_width) : r->picture_width;
- r->viewport.scale[1] = r->pot_buffers ?
- util_next_power_of_two(r->picture_height) : r->picture_height;
- r->viewport.scale[2] = 1;
- r->viewport.scale[3] = 1;
- r->viewport.translate[0] = 0;
- r->viewport.translate[1] = 0;
- r->viewport.translate[2] = 0;
- r->viewport.translate[3] = 0;
-
- r->scissor.maxx = r->pot_buffers ?
- util_next_power_of_two(r->picture_width) : r->picture_width;
- r->scissor.maxy = r->pot_buffers ?
- util_next_power_of_two(r->picture_height) : r->picture_height;
-
- r->fb_state.width = r->pot_buffers ?
- util_next_power_of_two(r->picture_width) : r->picture_width;
- r->fb_state.height = r->pot_buffers ?
- util_next_power_of_two(r->picture_height) : r->picture_height;
- r->fb_state.nr_cbufs = 1;
- r->fb_state.zsbuf = NULL;
-
- /* Luma filter */
- filters[0] = PIPE_TEX_FILTER_NEAREST;
- /* Chroma filters */
- if (r->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444 ||
- r->eb_handling == VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE) {
- filters[1] = PIPE_TEX_FILTER_NEAREST;
- filters[2] = PIPE_TEX_FILTER_NEAREST;
- }
- else {
- filters[1] = PIPE_TEX_FILTER_LINEAR;
- filters[2] = PIPE_TEX_FILTER_LINEAR;
- }
- /* Fwd, bkwd ref filters */
- filters[3] = PIPE_TEX_FILTER_LINEAR;
- filters[4] = PIPE_TEX_FILTER_LINEAR;
-
- for (i = 0; i < 5; ++i) {
- sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
- sampler.min_img_filter = filters[i];
- sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
- sampler.mag_img_filter = filters[i];
- sampler.compare_mode = PIPE_TEX_COMPARE_NONE;
- sampler.compare_func = PIPE_FUNC_ALWAYS;
- sampler.normalized_coords = 1;
- /*sampler.shadow_ambient = ; */
- /*sampler.lod_bias = ; */
- sampler.min_lod = 0;
- /*sampler.max_lod = ; */
- /*sampler.border_color[i] = ; */
- /*sampler.max_anisotropy = ; */
- r->samplers.all[i] = r->pipe->create_sampler_state(r->pipe, &sampler);
- }
-
- /* Position element */
- vertex_elems[0].src_offset = 0;
- vertex_elems[0].instance_divisor = 0;
- vertex_elems[0].vertex_buffer_index = 0;
- vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT;
-
- /* Luma, texcoord element */
- vertex_elems[1].src_offset = sizeof(struct vertex2f);
- vertex_elems[1].instance_divisor = 0;
- vertex_elems[1].vertex_buffer_index = 0;
- vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
-
- /* Chroma Cr texcoord element */
- vertex_elems[2].src_offset = sizeof(struct vertex2f) * 2;
- vertex_elems[2].instance_divisor = 0;
- vertex_elems[2].vertex_buffer_index = 0;
- vertex_elems[2].src_format = PIPE_FORMAT_R32G32_FLOAT;
-
- /* Chroma Cb texcoord element */
- vertex_elems[3].src_offset = sizeof(struct vertex2f) * 3;
- vertex_elems[3].instance_divisor = 0;
- vertex_elems[3].vertex_buffer_index = 0;
- vertex_elems[3].src_format = PIPE_FORMAT_R32G32_FLOAT;
-
- /* First ref surface top field texcoord element */
- vertex_elems[4].src_offset = 0;
- vertex_elems[4].instance_divisor = 0;
- vertex_elems[4].vertex_buffer_index = 1;
- vertex_elems[4].src_format = PIPE_FORMAT_R32G32_FLOAT;
-
- /* First ref surface bottom field texcoord element */
- vertex_elems[5].src_offset = sizeof(struct vertex2f);
- vertex_elems[5].instance_divisor = 0;
- vertex_elems[5].vertex_buffer_index = 1;
- vertex_elems[5].src_format = PIPE_FORMAT_R32G32_FLOAT;
-
- /* Second ref surface top field texcoord element */
- vertex_elems[6].src_offset = 0;
- vertex_elems[6].instance_divisor = 0;
- vertex_elems[6].vertex_buffer_index = 2;
- vertex_elems[6].src_format = PIPE_FORMAT_R32G32_FLOAT;
-
- /* Second ref surface bottom field texcoord element */
- vertex_elems[7].src_offset = sizeof(struct vertex2f);
- vertex_elems[7].instance_divisor = 0;
- vertex_elems[7].vertex_buffer_index = 2;
- vertex_elems[7].src_format = PIPE_FORMAT_R32G32_FLOAT;
-
- /* need versions with 4,6 and 8 vertex elems */
- r->vertex_elems[0] = r->pipe->create_vertex_elements_state(r->pipe, 4, vertex_elems);
- r->vertex_elems[1] = r->pipe->create_vertex_elements_state(r->pipe, 6, vertex_elems);
- r->vertex_elems[2] = r->pipe->create_vertex_elements_state(r->pipe, 8, vertex_elems);
-
- return true;
-}
-
-static void
-cleanup_pipe_state(struct vl_mpeg12_mc_renderer *r)
-{
- unsigned i;
-
- assert(r);
-
- for (i = 0; i < 5; ++i)
- r->pipe->delete_sampler_state(r->pipe, r->samplers.all[i]);
- for (i = 0; i < 3; i++)
- r->pipe->delete_vertex_elements_state(r->pipe, r->vertex_elems[i]);
-}
-
-static bool
-init_shaders(struct vl_mpeg12_mc_renderer *r)
-{
- assert(r);
-
- create_intra_vert_shader(r);
- create_intra_frag_shader(r);
- create_frame_pred_vert_shader(r);
- create_frame_pred_frag_shader(r);
- create_frame_bi_pred_vert_shader(r);
- create_frame_bi_pred_frag_shader(r);
-
- return true;
-}
-
-static void
-cleanup_shaders(struct vl_mpeg12_mc_renderer *r)
-{
- assert(r);
-
- r->pipe->delete_vs_state(r->pipe, r->i_vs);
- r->pipe->delete_fs_state(r->pipe, r->i_fs);
- r->pipe->delete_vs_state(r->pipe, r->p_vs[0]);
- r->pipe->delete_fs_state(r->pipe, r->p_fs[0]);
- r->pipe->delete_vs_state(r->pipe, r->b_vs[0]);
- r->pipe->delete_fs_state(r->pipe, r->b_fs[0]);
-}
-
-static bool
-init_buffers(struct vl_mpeg12_mc_renderer *r)
-{
- struct pipe_texture template;
-
- const unsigned mbw =
- align(r->picture_width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH;
- const unsigned mbh =
- align(r->picture_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT;
-
- unsigned i;
-
- assert(r);
-
- r->macroblocks_per_batch =
- mbw * (r->bufmode == VL_MPEG12_MC_RENDERER_BUFFER_PICTURE ? mbh : 1);
- r->num_macroblocks = 0;
- r->macroblock_buf = MALLOC(r->macroblocks_per_batch * sizeof(struct pipe_mpeg12_macroblock));
-
- memset(&template, 0, sizeof(struct pipe_texture));
- template.target = PIPE_TEXTURE_2D;
- /* TODO: Accomodate HW that can't do this and also for cases when this isn't precise enough */
- template.format = PIPE_FORMAT_R16_SNORM;
- template.last_level = 0;
- template.width0 = r->pot_buffers ?
- util_next_power_of_two(r->picture_width) : r->picture_width;
- template.height0 = r->pot_buffers ?
- util_next_power_of_two(r->picture_height) : r->picture_height;
- template.depth0 = 1;
- template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_DYNAMIC;
-
- r->textures.individual.y = r->pipe->screen->texture_create(r->pipe->screen, &template);
-
- if (r->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
- template.width0 = r->pot_buffers ?
- util_next_power_of_two(r->picture_width / 2) :
- r->picture_width / 2;
- template.height0 = r->pot_buffers ?
- util_next_power_of_two(r->picture_height / 2) :
- r->picture_height / 2;
- }
- else if (r->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422)
- template.height0 = r->pot_buffers ?
- util_next_power_of_two(r->picture_height / 2) :
- r->picture_height / 2;
-
- r->textures.individual.cb =
- r->pipe->screen->texture_create(r->pipe->screen, &template);
- r->textures.individual.cr =
- r->pipe->screen->texture_create(r->pipe->screen, &template);
-
- r->vertex_bufs.individual.ycbcr.stride = sizeof(struct vertex2f) * 4;
- r->vertex_bufs.individual.ycbcr.max_index = 24 * r->macroblocks_per_batch - 1;
- r->vertex_bufs.individual.ycbcr.buffer_offset = 0;
- r->vertex_bufs.individual.ycbcr.buffer = pipe_buffer_create
- (
- r->pipe->screen,
- DEFAULT_BUF_ALIGNMENT,
- PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_DISCARD,
- sizeof(struct vertex2f) * 4 * 24 * r->macroblocks_per_batch
- );
-
- for (i = 1; i < 3; ++i) {
- r->vertex_bufs.all[i].stride = sizeof(struct vertex2f) * 2;
- r->vertex_bufs.all[i].max_index = 24 * r->macroblocks_per_batch - 1;
- r->vertex_bufs.all[i].buffer_offset = 0;
- r->vertex_bufs.all[i].buffer = pipe_buffer_create
- (
- r->pipe->screen,
- DEFAULT_BUF_ALIGNMENT,
- PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_DISCARD,
- sizeof(struct vertex2f) * 2 * 24 * r->macroblocks_per_batch
- );
- }
-
- r->vs_const_buf = pipe_buffer_create
- (
- r->pipe->screen,
- DEFAULT_BUF_ALIGNMENT,
- PIPE_BUFFER_USAGE_CONSTANT | PIPE_BUFFER_USAGE_DISCARD,
- sizeof(struct vertex_shader_consts)
- );
-
- r->fs_const_buf = pipe_buffer_create
- (
- r->pipe->screen,
- DEFAULT_BUF_ALIGNMENT,
- PIPE_BUFFER_USAGE_CONSTANT, sizeof(struct fragment_shader_consts)
- );
-
- memcpy
- (
- pipe_buffer_map(r->pipe->screen, r->fs_const_buf, PIPE_BUFFER_USAGE_CPU_WRITE),
- &fs_consts, sizeof(struct fragment_shader_consts)
- );
-
- pipe_buffer_unmap(r->pipe->screen, r->fs_const_buf);
-
- return true;
-}
-
-static void
-cleanup_buffers(struct vl_mpeg12_mc_renderer *r)
-{
- unsigned i;
-
- assert(r);
-
- pipe_buffer_reference(&r->vs_const_buf, NULL);
- pipe_buffer_reference(&r->fs_const_buf, NULL);
-
- for (i = 0; i < 3; ++i)
- pipe_buffer_reference(&r->vertex_bufs.all[i].buffer, NULL);
-
- for (i = 0; i < 3; ++i)
- pipe_texture_reference(&r->textures.all[i], NULL);
-
- FREE(r->macroblock_buf);
-}
-
-static enum MACROBLOCK_TYPE
-get_macroblock_type(struct pipe_mpeg12_macroblock *mb)
-{
- assert(mb);
-
- switch (mb->mb_type) {
- case PIPE_MPEG12_MACROBLOCK_TYPE_INTRA:
- return MACROBLOCK_TYPE_INTRA;
- case PIPE_MPEG12_MACROBLOCK_TYPE_FWD:
- return mb->mo_type == PIPE_MPEG12_MOTION_TYPE_FRAME ?
- MACROBLOCK_TYPE_FWD_FRAME_PRED : MACROBLOCK_TYPE_FWD_FIELD_PRED;
- case PIPE_MPEG12_MACROBLOCK_TYPE_BKWD:
- return mb->mo_type == PIPE_MPEG12_MOTION_TYPE_FRAME ?
- MACROBLOCK_TYPE_BKWD_FRAME_PRED : MACROBLOCK_TYPE_BKWD_FIELD_PRED;
- case PIPE_MPEG12_MACROBLOCK_TYPE_BI:
- return mb->mo_type == PIPE_MPEG12_MOTION_TYPE_FRAME ?
- MACROBLOCK_TYPE_BI_FRAME_PRED : MACROBLOCK_TYPE_BI_FIELD_PRED;
- default:
- assert(0);
- }
-
- /* Unreachable */
- return -1;
-}
-
-/* XXX: One of these days this will have to be killed with fire */
-#define SET_BLOCK(vb, cbp, mbx, mby, unitx, unity, ofsx, ofsy, hx, hy, lm, cbm, crm, use_zb, zb) \
- do { \
- (vb)[0].pos.x = (mbx) * (unitx) + (ofsx); (vb)[0].pos.y = (mby) * (unity) + (ofsy); \
- (vb)[1].pos.x = (mbx) * (unitx) + (ofsx); (vb)[1].pos.y = (mby) * (unity) + (ofsy) + (hy); \
- (vb)[2].pos.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[2].pos.y = (mby) * (unity) + (ofsy); \
- (vb)[3].pos.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[3].pos.y = (mby) * (unity) + (ofsy); \
- (vb)[4].pos.x = (mbx) * (unitx) + (ofsx); (vb)[4].pos.y = (mby) * (unity) + (ofsy) + (hy); \
- (vb)[5].pos.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[5].pos.y = (mby) * (unity) + (ofsy) + (hy); \
- \
- if (!use_zb || (cbp) & (lm)) \
- { \
- (vb)[0].luma_tc.x = (mbx) * (unitx) + (ofsx); (vb)[0].luma_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[1].luma_tc.x = (mbx) * (unitx) + (ofsx); (vb)[1].luma_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- (vb)[2].luma_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[2].luma_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[3].luma_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[3].luma_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[4].luma_tc.x = (mbx) * (unitx) + (ofsx); (vb)[4].luma_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- (vb)[5].luma_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[5].luma_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- } \
- else \
- { \
- (vb)[0].luma_tc.x = (zb)[0].x; (vb)[0].luma_tc.y = (zb)[0].y; \
- (vb)[1].luma_tc.x = (zb)[0].x; (vb)[1].luma_tc.y = (zb)[0].y + (hy); \
- (vb)[2].luma_tc.x = (zb)[0].x + (hx); (vb)[2].luma_tc.y = (zb)[0].y; \
- (vb)[3].luma_tc.x = (zb)[0].x + (hx); (vb)[3].luma_tc.y = (zb)[0].y; \
- (vb)[4].luma_tc.x = (zb)[0].x; (vb)[4].luma_tc.y = (zb)[0].y + (hy); \
- (vb)[5].luma_tc.x = (zb)[0].x + (hx); (vb)[5].luma_tc.y = (zb)[0].y + (hy); \
- } \
- \
- if (!use_zb || (cbp) & (cbm)) \
- { \
- (vb)[0].cb_tc.x = (mbx) * (unitx) + (ofsx); (vb)[0].cb_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[1].cb_tc.x = (mbx) * (unitx) + (ofsx); (vb)[1].cb_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- (vb)[2].cb_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[2].cb_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[3].cb_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[3].cb_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[4].cb_tc.x = (mbx) * (unitx) + (ofsx); (vb)[4].cb_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- (vb)[5].cb_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[5].cb_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- } \
- else \
- { \
- (vb)[0].cb_tc.x = (zb)[1].x; (vb)[0].cb_tc.y = (zb)[1].y; \
- (vb)[1].cb_tc.x = (zb)[1].x; (vb)[1].cb_tc.y = (zb)[1].y + (hy); \
- (vb)[2].cb_tc.x = (zb)[1].x + (hx); (vb)[2].cb_tc.y = (zb)[1].y; \
- (vb)[3].cb_tc.x = (zb)[1].x + (hx); (vb)[3].cb_tc.y = (zb)[1].y; \
- (vb)[4].cb_tc.x = (zb)[1].x; (vb)[4].cb_tc.y = (zb)[1].y + (hy); \
- (vb)[5].cb_tc.x = (zb)[1].x + (hx); (vb)[5].cb_tc.y = (zb)[1].y + (hy); \
- } \
- \
- if (!use_zb || (cbp) & (crm)) \
- { \
- (vb)[0].cr_tc.x = (mbx) * (unitx) + (ofsx); (vb)[0].cr_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[1].cr_tc.x = (mbx) * (unitx) + (ofsx); (vb)[1].cr_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- (vb)[2].cr_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[2].cr_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[3].cr_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[3].cr_tc.y = (mby) * (unity) + (ofsy); \
- (vb)[4].cr_tc.x = (mbx) * (unitx) + (ofsx); (vb)[4].cr_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- (vb)[5].cr_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[5].cr_tc.y = (mby) * (unity) + (ofsy) + (hy); \
- } \
- else \
- { \
- (vb)[0].cr_tc.x = (zb)[2].x; (vb)[0].cr_tc.y = (zb)[2].y; \
- (vb)[1].cr_tc.x = (zb)[2].x; (vb)[1].cr_tc.y = (zb)[2].y + (hy); \
- (vb)[2].cr_tc.x = (zb)[2].x + (hx); (vb)[2].cr_tc.y = (zb)[2].y; \
- (vb)[3].cr_tc.x = (zb)[2].x + (hx); (vb)[3].cr_tc.y = (zb)[2].y; \
- (vb)[4].cr_tc.x = (zb)[2].x; (vb)[4].cr_tc.y = (zb)[2].y + (hy); \
- (vb)[5].cr_tc.x = (zb)[2].x + (hx); (vb)[5].cr_tc.y = (zb)[2].y + (hy); \
- } \
- } while (0)
-
-static void
-gen_macroblock_verts(struct vl_mpeg12_mc_renderer *r,
- struct pipe_mpeg12_macroblock *mb, unsigned pos,
- struct vert_stream_0 *ycbcr_vb, struct vertex2f **ref_vb)
-{
- struct vertex2f mo_vec[2];
-
- unsigned i;
-
- assert(r);
- assert(mb);
- assert(ycbcr_vb);
- assert(pos < r->macroblocks_per_batch);
-
- mo_vec[1].x = 0;
- mo_vec[1].y = 0;
-
- switch (mb->mb_type) {
- case PIPE_MPEG12_MACROBLOCK_TYPE_BI:
- {
- struct vertex2f *vb;
-
- assert(ref_vb && ref_vb[1]);
-
- vb = ref_vb[1] + pos * 2 * 24;
-
- mo_vec[0].x = mb->pmv[0][1][0] * 0.5f * r->surface_tex_inv_size.x;
- mo_vec[0].y = mb->pmv[0][1][1] * 0.5f * r->surface_tex_inv_size.y;
-
- if (mb->mo_type == PIPE_MPEG12_MOTION_TYPE_FRAME) {
- for (i = 0; i < 24 * 2; i += 2) {
- vb[i].x = mo_vec[0].x;
- vb[i].y = mo_vec[0].y;
- }
- }
- else {
- mo_vec[1].x = mb->pmv[1][1][0] * 0.5f * r->surface_tex_inv_size.x;
- mo_vec[1].y = mb->pmv[1][1][1] * 0.5f * r->surface_tex_inv_size.y;
-
- for (i = 0; i < 24 * 2; i += 2) {
- vb[i].x = mo_vec[0].x;
- vb[i].y = mo_vec[0].y;
- vb[i + 1].x = mo_vec[1].x;
- vb[i + 1].y = mo_vec[1].y;
- }
- }
-
- /* fall-through */
- }
- case PIPE_MPEG12_MACROBLOCK_TYPE_FWD:
- case PIPE_MPEG12_MACROBLOCK_TYPE_BKWD:
- {
- struct vertex2f *vb;
-
- assert(ref_vb && ref_vb[0]);
-
- vb = ref_vb[0] + pos * 2 * 24;
-
- if (mb->mb_type == PIPE_MPEG12_MACROBLOCK_TYPE_BKWD) {
- mo_vec[0].x = mb->pmv[0][1][0] * 0.5f * r->surface_tex_inv_size.x;
- mo_vec[0].y = mb->pmv[0][1][1] * 0.5f * r->surface_tex_inv_size.y;
-
- if (mb->mo_type == PIPE_MPEG12_MOTION_TYPE_FIELD) {
- mo_vec[1].x = mb->pmv[1][1][0] * 0.5f * r->surface_tex_inv_size.x;
- mo_vec[1].y = mb->pmv[1][1][1] * 0.5f * r->surface_tex_inv_size.y;
- }
- }
- else {
- mo_vec[0].x = mb->pmv[0][0][0] * 0.5f * r->surface_tex_inv_size.x;
- mo_vec[0].y = mb->pmv[0][0][1] * 0.5f * r->surface_tex_inv_size.y;
-
- if (mb->mo_type == PIPE_MPEG12_MOTION_TYPE_FIELD) {
- mo_vec[1].x = mb->pmv[1][0][0] * 0.5f * r->surface_tex_inv_size.x;
- mo_vec[1].y = mb->pmv[1][0][1] * 0.5f * r->surface_tex_inv_size.y;
- }
- }
-
- if (mb->mb_type == PIPE_MPEG12_MOTION_TYPE_FRAME) {
- for (i = 0; i < 24 * 2; i += 2) {
- vb[i].x = mo_vec[0].x;
- vb[i].y = mo_vec[0].y;
- }
- }
- else {
- for (i = 0; i < 24 * 2; i += 2) {
- vb[i].x = mo_vec[0].x;
- vb[i].y = mo_vec[0].y;
- vb[i + 1].x = mo_vec[1].x;
- vb[i + 1].y = mo_vec[1].y;
- }
- }
-
- /* fall-through */
- }
- case PIPE_MPEG12_MACROBLOCK_TYPE_INTRA:
- {
- const struct vertex2f unit =
- {
- r->surface_tex_inv_size.x * MACROBLOCK_WIDTH,
- r->surface_tex_inv_size.y * MACROBLOCK_HEIGHT
- };
- const struct vertex2f half =
- {
- r->surface_tex_inv_size.x * (MACROBLOCK_WIDTH / 2),
- r->surface_tex_inv_size.y * (MACROBLOCK_HEIGHT / 2)
- };
- const bool use_zb = r->eb_handling == VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE;
-
- struct vert_stream_0 *vb = ycbcr_vb + pos * 24;
-
- SET_BLOCK(vb, mb->cbp, mb->mbx, mb->mby,
- unit.x, unit.y, 0, 0, half.x, half.y,
- 32, 2, 1, use_zb, r->zero_block);
-
- SET_BLOCK(vb + 6, mb->cbp, mb->mbx, mb->mby,
- unit.x, unit.y, half.x, 0, half.x, half.y,
- 16, 2, 1, use_zb, r->zero_block);
-
- SET_BLOCK(vb + 12, mb->cbp, mb->mbx, mb->mby,
- unit.x, unit.y, 0, half.y, half.x, half.y,
- 8, 2, 1, use_zb, r->zero_block);
-
- SET_BLOCK(vb + 18, mb->cbp, mb->mbx, mb->mby,
- unit.x, unit.y, half.x, half.y, half.x, half.y,
- 4, 2, 1, use_zb, r->zero_block);
-
- break;
- }
- default:
- assert(0);
- }
-}
-
-static void
-gen_macroblock_stream(struct vl_mpeg12_mc_renderer *r,
- unsigned *num_macroblocks)
-{
- unsigned offset[NUM_MACROBLOCK_TYPES];
- struct vert_stream_0 *ycbcr_vb;
- struct vertex2f *ref_vb[2];
- unsigned i;
-
- assert(r);
- assert(num_macroblocks);
-
- for (i = 0; i < r->num_macroblocks; ++i) {
- enum MACROBLOCK_TYPE mb_type = get_macroblock_type(&r->macroblock_buf[i]);
- ++num_macroblocks[mb_type];
- }
-
- offset[0] = 0;
-
- for (i = 1; i < NUM_MACROBLOCK_TYPES; ++i)
- offset[i] = offset[i - 1] + num_macroblocks[i - 1];
-
- ycbcr_vb = (struct vert_stream_0 *)pipe_buffer_map
- (
- r->pipe->screen,
- r->vertex_bufs.individual.ycbcr.buffer,
- PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
- );
-
- for (i = 0; i < 2; ++i)
- ref_vb[i] = (struct vertex2f *)pipe_buffer_map
- (
- r->pipe->screen,
- r->vertex_bufs.individual.ref[i].buffer,
- PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
- );
-
- for (i = 0; i < r->num_macroblocks; ++i) {
- enum MACROBLOCK_TYPE mb_type = get_macroblock_type(&r->macroblock_buf[i]);
-
- gen_macroblock_verts(r, &r->macroblock_buf[i], offset[mb_type],
- ycbcr_vb, ref_vb);
-
- ++offset[mb_type];
- }
-
- pipe_buffer_unmap(r->pipe->screen, r->vertex_bufs.individual.ycbcr.buffer);
- for (i = 0; i < 2; ++i)
- pipe_buffer_unmap(r->pipe->screen, r->vertex_bufs.individual.ref[i].buffer);
-}
-
-static void
-flush(struct vl_mpeg12_mc_renderer *r)
-{
- unsigned num_macroblocks[NUM_MACROBLOCK_TYPES] = { 0 };
- unsigned vb_start = 0;
- struct vertex_shader_consts *vs_consts;
- unsigned i;
-
- assert(r);
- assert(r->num_macroblocks == r->macroblocks_per_batch);
-
- gen_macroblock_stream(r, num_macroblocks);
-
- r->fb_state.cbufs[0] = r->pipe->screen->get_tex_surface
- (
- r->pipe->screen, r->surface,
- 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
- );
-
- r->pipe->set_framebuffer_state(r->pipe, &r->fb_state);
- r->pipe->set_viewport_state(r->pipe, &r->viewport);
- r->pipe->set_scissor_state(r->pipe, &r->scissor);
-
- vs_consts = pipe_buffer_map
- (
- r->pipe->screen, r->vs_const_buf,
- PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
- );
-
- vs_consts->denorm.x = r->surface->width0;
- vs_consts->denorm.y = r->surface->height0;
-
- pipe_buffer_unmap(r->pipe->screen, r->vs_const_buf);
-
- r->pipe->set_constant_buffer(r->pipe, PIPE_SHADER_VERTEX, 0,
- r->vs_const_buf);
- r->pipe->set_constant_buffer(r->pipe, PIPE_SHADER_FRAGMENT, 0,
- r->fs_const_buf);
-
- if (num_macroblocks[MACROBLOCK_TYPE_INTRA] > 0) {
- r->pipe->set_vertex_buffers(r->pipe, 1, r->vertex_bufs.all);
- r->pipe->bind_vertex_elements_state(r->pipe, r->vertex_elems[0]);
- r->pipe->set_fragment_sampler_textures(r->pipe, 3, r->textures.all);
- r->pipe->bind_fragment_sampler_states(r->pipe, 3, r->samplers.all);
- r->pipe->bind_vs_state(r->pipe, r->i_vs);
- r->pipe->bind_fs_state(r->pipe, r->i_fs);
-
- r->pipe->draw_arrays(r->pipe, PIPE_PRIM_TRIANGLES, vb_start,
- num_macroblocks[MACROBLOCK_TYPE_INTRA] * 24);
- vb_start += num_macroblocks[MACROBLOCK_TYPE_INTRA] * 24;
- }
-
- if (num_macroblocks[MACROBLOCK_TYPE_FWD_FRAME_PRED] > 0) {
- r->pipe->set_vertex_buffers(r->pipe, 2, r->vertex_bufs.all);
- r->pipe->bind_vertex_elements_state(r->pipe, r->vertex_elems[1]);
- r->textures.individual.ref[0] = r->past;
- r->pipe->set_fragment_sampler_textures(r->pipe, 4, r->textures.all);
- r->pipe->bind_fragment_sampler_states(r->pipe, 4, r->samplers.all);
- r->pipe->bind_vs_state(r->pipe, r->p_vs[0]);
- r->pipe->bind_fs_state(r->pipe, r->p_fs[0]);
-
- r->pipe->draw_arrays(r->pipe, PIPE_PRIM_TRIANGLES, vb_start,
- num_macroblocks[MACROBLOCK_TYPE_FWD_FRAME_PRED] * 24);
- vb_start += num_macroblocks[MACROBLOCK_TYPE_FWD_FRAME_PRED] * 24;
- }
-
- if (false /*num_macroblocks[MACROBLOCK_TYPE_FWD_FIELD_PRED] > 0 */ ) {
- r->pipe->set_vertex_buffers(r->pipe, 2, r->vertex_bufs.all);
- r->pipe->bind_vertex_elements_state(r->pipe, r->vertex_elems[1]);
- r->textures.individual.ref[0] = r->past;
- r->pipe->set_fragment_sampler_textures(r->pipe, 4, r->textures.all);
- r->pipe->bind_fragment_sampler_states(r->pipe, 4, r->samplers.all);
- r->pipe->bind_vs_state(r->pipe, r->p_vs[1]);
- r->pipe->bind_fs_state(r->pipe, r->p_fs[1]);
-
- r->pipe->draw_arrays(r->pipe, PIPE_PRIM_TRIANGLES, vb_start,
- num_macroblocks[MACROBLOCK_TYPE_FWD_FIELD_PRED] * 24);
- vb_start += num_macroblocks[MACROBLOCK_TYPE_FWD_FIELD_PRED] * 24;
- }
-
- if (num_macroblocks[MACROBLOCK_TYPE_BKWD_FRAME_PRED] > 0) {
- r->pipe->set_vertex_buffers(r->pipe, 2, r->vertex_bufs.all);
- r->pipe->bind_vertex_elements_state(r->pipe, r->vertex_elems[1]);
- r->textures.individual.ref[0] = r->future;
- r->pipe->set_fragment_sampler_textures(r->pipe, 4, r->textures.all);
- r->pipe->bind_fragment_sampler_states(r->pipe, 4, r->samplers.all);
- r->pipe->bind_vs_state(r->pipe, r->p_vs[0]);
- r->pipe->bind_fs_state(r->pipe, r->p_fs[0]);
-
- r->pipe->draw_arrays(r->pipe, PIPE_PRIM_TRIANGLES, vb_start,
- num_macroblocks[MACROBLOCK_TYPE_BKWD_FRAME_PRED] * 24);
- vb_start += num_macroblocks[MACROBLOCK_TYPE_BKWD_FRAME_PRED] * 24;
- }
-
- if (false /*num_macroblocks[MACROBLOCK_TYPE_BKWD_FIELD_PRED] > 0 */ ) {
- r->pipe->set_vertex_buffers(r->pipe, 2, r->vertex_bufs.all);
- r->pipe->bind_vertex_elements_state(r->pipe, r->vertex_elems[1]);
- r->textures.individual.ref[0] = r->future;
- r->pipe->set_fragment_sampler_textures(r->pipe, 4, r->textures.all);
- r->pipe->bind_fragment_sampler_states(r->pipe, 4, r->samplers.all);
- r->pipe->bind_vs_state(r->pipe, r->p_vs[1]);
- r->pipe->bind_fs_state(r->pipe, r->p_fs[1]);
-
- r->pipe->draw_arrays(r->pipe, PIPE_PRIM_TRIANGLES, vb_start,
- num_macroblocks[MACROBLOCK_TYPE_BKWD_FIELD_PRED] * 24);
- vb_start += num_macroblocks[MACROBLOCK_TYPE_BKWD_FIELD_PRED] * 24;
- }
-
- if (num_macroblocks[MACROBLOCK_TYPE_BI_FRAME_PRED] > 0) {
- r->pipe->set_vertex_buffers(r->pipe, 3, r->vertex_bufs.all);
- r->pipe->bind_vertex_elements_state(r->pipe, r->vertex_elems[2]);
- r->textures.individual.ref[0] = r->past;
- r->textures.individual.ref[1] = r->future;
- r->pipe->set_fragment_sampler_textures(r->pipe, 5, r->textures.all);
- r->pipe->bind_fragment_sampler_states(r->pipe, 5, r->samplers.all);
- r->pipe->bind_vs_state(r->pipe, r->b_vs[0]);
- r->pipe->bind_fs_state(r->pipe, r->b_fs[0]);
-
- r->pipe->draw_arrays(r->pipe, PIPE_PRIM_TRIANGLES, vb_start,
- num_macroblocks[MACROBLOCK_TYPE_BI_FRAME_PRED] * 24);
- vb_start += num_macroblocks[MACROBLOCK_TYPE_BI_FRAME_PRED] * 24;
- }
-
- if (false /*num_macroblocks[MACROBLOCK_TYPE_BI_FIELD_PRED] > 0 */ ) {
- r->pipe->set_vertex_buffers(r->pipe, 3, r->vertex_bufs.all);
- r->pipe->bind_vertex_elements_state(r->pipe, r->vertex_elems[2]);
- r->textures.individual.ref[0] = r->past;
- r->textures.individual.ref[1] = r->future;
- r->pipe->set_fragment_sampler_textures(r->pipe, 5, r->textures.all);
- r->pipe->bind_fragment_sampler_states(r->pipe, 5, r->samplers.all);
- r->pipe->bind_vs_state(r->pipe, r->b_vs[1]);
- r->pipe->bind_fs_state(r->pipe, r->b_fs[1]);
-
- r->pipe->draw_arrays(r->pipe, PIPE_PRIM_TRIANGLES, vb_start,
- num_macroblocks[MACROBLOCK_TYPE_BI_FIELD_PRED] * 24);
- vb_start += num_macroblocks[MACROBLOCK_TYPE_BI_FIELD_PRED] * 24;
- }
-
- r->pipe->flush(r->pipe, PIPE_FLUSH_RENDER_CACHE, r->fence);
- pipe_surface_reference(&r->fb_state.cbufs[0], NULL);
-
- if (r->eb_handling == VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE)
- for (i = 0; i < 3; ++i)
- r->zero_block[i].x = ZERO_BLOCK_NIL;
-
- r->num_macroblocks = 0;
-}
-
-static void
-grab_frame_coded_block(short *src, short *dst, unsigned dst_pitch)
-{
- unsigned y;
-
- assert(src);
- assert(dst);
-
- for (y = 0; y < BLOCK_HEIGHT; ++y)
- memcpy(dst + y * dst_pitch, src + y * BLOCK_WIDTH, BLOCK_WIDTH * 2);
-}
-
-static void
-grab_field_coded_block(short *src, short *dst, unsigned dst_pitch)
-{
- unsigned y;
-
- assert(src);
- assert(dst);
-
- for (y = 0; y < BLOCK_HEIGHT; ++y)
- memcpy(dst + y * dst_pitch * 2, src + y * BLOCK_WIDTH, BLOCK_WIDTH * 2);
-}
-
-static void
-fill_zero_block(short *dst, unsigned dst_pitch)
-{
- unsigned y;
-
- assert(dst);
-
- for (y = 0; y < BLOCK_HEIGHT; ++y)
- memset(dst + y * dst_pitch, 0, BLOCK_WIDTH * 2);
-}
-
-static void
-grab_blocks(struct vl_mpeg12_mc_renderer *r, unsigned mbx, unsigned mby,
- enum pipe_mpeg12_dct_type dct_type, unsigned cbp, short *blocks)
-{
- unsigned tex_pitch;
- short *texels;
- unsigned tb = 0, sb = 0;
- unsigned mbpx = mbx * MACROBLOCK_WIDTH, mbpy = mby * MACROBLOCK_HEIGHT;
- unsigned x, y;
-
- assert(r);
- assert(blocks);
-
- tex_pitch = r->tex_transfer[0]->stride / util_format_get_blocksize(r->tex_transfer[0]->texture->format);
- texels = r->texels[0] + mbpy * tex_pitch + mbpx;
-
- for (y = 0; y < 2; ++y) {
- for (x = 0; x < 2; ++x, ++tb) {
- if ((cbp >> (5 - tb)) & 1) {
- if (dct_type == PIPE_MPEG12_DCT_TYPE_FRAME) {
- grab_frame_coded_block(blocks + sb * BLOCK_WIDTH * BLOCK_HEIGHT,
- texels + y * tex_pitch * BLOCK_WIDTH +
- x * BLOCK_WIDTH, tex_pitch);
- }
- else {
- grab_field_coded_block(blocks + sb * BLOCK_WIDTH * BLOCK_HEIGHT,
- texels + y * tex_pitch + x * BLOCK_WIDTH,
- tex_pitch);
- }
-
- ++sb;
- }
- else if (r->eb_handling != VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_NONE) {
- if (r->eb_handling == VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ALL ||
- ZERO_BLOCK_IS_NIL(r->zero_block[0])) {
- fill_zero_block(texels + y * tex_pitch * BLOCK_WIDTH + x * BLOCK_WIDTH, tex_pitch);
- if (r->eb_handling == VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE) {
- r->zero_block[0].x = (mbpx + x * 8) * r->surface_tex_inv_size.x;
- r->zero_block[0].y = (mbpy + y * 8) * r->surface_tex_inv_size.y;
- }
- }
- }
- }
- }
-
- /* TODO: Implement 422, 444 */
- assert(r->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
-
- mbpx /= 2;
- mbpy /= 2;
-
- for (tb = 0; tb < 2; ++tb) {
- tex_pitch = r->tex_transfer[tb + 1]->stride / util_format_get_blocksize(r->tex_transfer[tb + 1]->texture->format);
- texels = r->texels[tb + 1] + mbpy * tex_pitch + mbpx;
-
- if ((cbp >> (1 - tb)) & 1) {
- grab_frame_coded_block(blocks + sb * BLOCK_WIDTH * BLOCK_HEIGHT, texels, tex_pitch);
- ++sb;
- }
- else if (r->eb_handling != VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_NONE) {
- if (r->eb_handling == VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ALL ||
- ZERO_BLOCK_IS_NIL(r->zero_block[tb + 1])) {
- fill_zero_block(texels, tex_pitch);
- if (r->eb_handling == VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE) {
- r->zero_block[tb + 1].x = (mbpx << 1) * r->surface_tex_inv_size.x;
- r->zero_block[tb + 1].y = (mbpy << 1) * r->surface_tex_inv_size.y;
- }
- }
- }
- }
-}
-
-static void
-grab_macroblock(struct vl_mpeg12_mc_renderer *r,
- struct pipe_mpeg12_macroblock *mb)
-{
- assert(r);
- assert(mb);
- assert(r->num_macroblocks < r->macroblocks_per_batch);
-
- memcpy(&r->macroblock_buf[r->num_macroblocks], mb,
- sizeof(struct pipe_mpeg12_macroblock));
-
- grab_blocks(r, mb->mbx, mb->mby, mb->dct_type, mb->cbp, mb->blocks);
-
- ++r->num_macroblocks;
-}
-
-bool
-vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
- struct pipe_context *pipe,
- unsigned picture_width,
- unsigned picture_height,
- enum pipe_video_chroma_format chroma_format,
- enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode,
- enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK eb_handling,
- bool pot_buffers)
-{
- unsigned i;
-
- assert(renderer);
- assert(pipe);
- /* TODO: Implement other policies */
- assert(bufmode == VL_MPEG12_MC_RENDERER_BUFFER_PICTURE);
- /* TODO: Implement this */
- /* XXX: XFER_ALL sampling issue at block edges when using bilinear filtering */
- assert(eb_handling != VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_NONE);
- /* TODO: Non-pot buffers untested, probably doesn't work without changes to texcoord generation, vert shader, etc */
- assert(pot_buffers);
-
- memset(renderer, 0, sizeof(struct vl_mpeg12_mc_renderer));
-
- renderer->pipe = pipe;
- renderer->picture_width = picture_width;
- renderer->picture_height = picture_height;
- renderer->chroma_format = chroma_format;
- renderer->bufmode = bufmode;
- renderer->eb_handling = eb_handling;
- renderer->pot_buffers = pot_buffers;
-
- if (!init_pipe_state(renderer))
- return false;
- if (!init_shaders(renderer)) {
- cleanup_pipe_state(renderer);
- return false;
- }
- if (!init_buffers(renderer)) {
- cleanup_shaders(renderer);
- cleanup_pipe_state(renderer);
- return false;
- }
-
- renderer->surface = NULL;
- renderer->past = NULL;
- renderer->future = NULL;
- for (i = 0; i < 3; ++i)
- renderer->zero_block[i].x = ZERO_BLOCK_NIL;
- renderer->num_macroblocks = 0;
-
- xfer_buffers_map(renderer);
-
- return true;
-}
-
-void
-vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer)
-{
- assert(renderer);
-
- xfer_buffers_unmap(renderer);
-
- cleanup_pipe_state(renderer);
- cleanup_shaders(renderer);
- cleanup_buffers(renderer);
-}
-
-void
-vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer
- *renderer,
- struct pipe_texture *surface,
- struct pipe_texture *past,
- struct pipe_texture *future,
- unsigned num_macroblocks,
- struct pipe_mpeg12_macroblock
- *mpeg12_macroblocks,
- struct pipe_fence_handle **fence)
-{
- bool new_surface = false;
-
- assert(renderer);
- assert(surface);
- assert(num_macroblocks);
- assert(mpeg12_macroblocks);
-
- if (renderer->surface) {
- if (surface != renderer->surface) {
- if (renderer->num_macroblocks > 0) {
- xfer_buffers_unmap(renderer);
- flush(renderer);
- }
-
- new_surface = true;
- }
-
- /* If the surface we're rendering hasn't changed the ref frames shouldn't change. */
- assert(surface != renderer->surface || renderer->past == past);
- assert(surface != renderer->surface || renderer->future == future);
- }
- else
- new_surface = true;
-
- if (new_surface) {
- renderer->surface = surface;
- renderer->past = past;
- renderer->future = future;
- renderer->fence = fence;
- renderer->surface_tex_inv_size.x = 1.0f / surface->width0;
- renderer->surface_tex_inv_size.y = 1.0f / surface->height0;
- }
-
- while (num_macroblocks) {
- unsigned left_in_batch = renderer->macroblocks_per_batch - renderer->num_macroblocks;
- unsigned num_to_submit = MIN2(num_macroblocks, left_in_batch);
- unsigned i;
-
- for (i = 0; i < num_to_submit; ++i) {
- assert(mpeg12_macroblocks[i].base.codec == PIPE_VIDEO_CODEC_MPEG12);
- grab_macroblock(renderer, &mpeg12_macroblocks[i]);
- }
-
- num_macroblocks -= num_to_submit;
-
- if (renderer->num_macroblocks == renderer->macroblocks_per_batch) {
- xfer_buffers_unmap(renderer);
- flush(renderer);
- xfer_buffers_map(renderer);
- /* Next time we get this surface it may have new ref frames */
- renderer->surface = NULL;
- }
- }
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 vl_mpeg12_mc_renderer_h
-#define vl_mpeg12_mc_renderer_h
-
-#include <pipe/p_compiler.h>
-#include <pipe/p_state.h>
-#include <pipe/p_video_state.h>
-
-struct pipe_context;
-struct pipe_video_surface;
-struct pipe_macroblock;
-
-/* A slice is video-width (rounded up to a multiple of macroblock width) x macroblock height */
-enum VL_MPEG12_MC_RENDERER_BUFFER_MODE
-{
- VL_MPEG12_MC_RENDERER_BUFFER_SLICE, /* Saves memory at the cost of smaller batches */
- VL_MPEG12_MC_RENDERER_BUFFER_PICTURE /* Larger batches, more memory */
-};
-
-enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK
-{
- VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ALL, /* Waste of memory bandwidth */
- VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE, /* Can only do point-filtering when interpolating subsampled chroma channels */
- VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_NONE /* Needs conditional texel fetch! */
-};
-
-struct vl_mpeg12_mc_renderer
-{
- struct pipe_context *pipe;
- unsigned picture_width;
- unsigned picture_height;
- enum pipe_video_chroma_format chroma_format;
- enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode;
- enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK eb_handling;
- bool pot_buffers;
- unsigned macroblocks_per_batch;
-
- struct pipe_viewport_state viewport;
- struct pipe_scissor_state scissor;
- struct pipe_buffer *vs_const_buf;
- struct pipe_buffer *fs_const_buf;
- struct pipe_framebuffer_state fb_state;
- void *vertex_elems[3];
-
- union
- {
- void *all[5];
- struct { void *y, *cb, *cr, *ref[2]; } individual;
- } samplers;
-
- void *i_vs, *p_vs[2], *b_vs[2];
- void *i_fs, *p_fs[2], *b_fs[2];
-
- union
- {
- struct pipe_texture *all[5];
- struct { struct pipe_texture *y, *cb, *cr, *ref[2]; } individual;
- } textures;
-
- union
- {
- struct pipe_vertex_buffer all[3];
- struct { struct pipe_vertex_buffer ycbcr, ref[2]; } individual;
- } vertex_bufs;
-
- struct pipe_texture *surface, *past, *future;
- struct pipe_fence_handle **fence;
- unsigned num_macroblocks;
- struct pipe_mpeg12_macroblock *macroblock_buf;
- struct pipe_transfer *tex_transfer[3];
- short *texels[3];
- struct { float x, y; } surface_tex_inv_size;
- struct { float x, y; } zero_block[3];
-};
-
-bool vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
- struct pipe_context *pipe,
- unsigned picture_width,
- unsigned picture_height,
- enum pipe_video_chroma_format chroma_format,
- enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode,
- enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK eb_handling,
- bool pot_buffers);
-
-void vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer);
-
-void vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer *renderer,
- struct pipe_texture *surface,
- struct pipe_texture *past,
- struct pipe_texture *future,
- unsigned num_macroblocks,
- struct pipe_mpeg12_macroblock *mpeg12_macroblocks,
- struct pipe_fence_handle **fence);
-
-#endif /* vl_mpeg12_mc_renderer_h */
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include "vl_shader_build.h"
-#include <assert.h>
-#include <tgsi/tgsi_parse.h>
-#include <tgsi/tgsi_build.h>
-
-struct tgsi_full_declaration vl_decl_input(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
-{
- struct tgsi_full_declaration decl = tgsi_default_full_declaration();
-
- decl.Declaration.File = TGSI_FILE_INPUT;
- decl.Declaration.Semantic = 1;
- decl.Semantic.Name = name;
- decl.Semantic.Index = index;
- decl.Range.First = first;
- decl.Range.Last = last;
-
- return decl;
-}
-
-struct tgsi_full_declaration vl_decl_interpolated_input
-(
- unsigned int name,
- unsigned int index,
- unsigned int first,
- unsigned int last,
- int interpolation
-)
-{
- struct tgsi_full_declaration decl = tgsi_default_full_declaration();
-
- assert
- (
- interpolation == TGSI_INTERPOLATE_CONSTANT ||
- interpolation == TGSI_INTERPOLATE_LINEAR ||
- interpolation == TGSI_INTERPOLATE_PERSPECTIVE
- );
-
- decl.Declaration.File = TGSI_FILE_INPUT;
- decl.Declaration.Semantic = 1;
- decl.Semantic.Name = name;
- decl.Semantic.Index = index;
- decl.Declaration.Interpolate = interpolation;;
- decl.Range.First = first;
- decl.Range.Last = last;
-
- return decl;
-}
-
-struct tgsi_full_declaration vl_decl_constants(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
-{
- struct tgsi_full_declaration decl = tgsi_default_full_declaration();
-
- decl.Declaration.File = TGSI_FILE_CONSTANT;
- decl.Declaration.Semantic = 1;
- decl.Semantic.Name = name;
- decl.Semantic.Index = index;
- decl.Range.First = first;
- decl.Range.Last = last;
-
- return decl;
-}
-
-struct tgsi_full_declaration vl_decl_output(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
-{
- struct tgsi_full_declaration decl = tgsi_default_full_declaration();
-
- decl.Declaration.File = TGSI_FILE_OUTPUT;
- decl.Declaration.Semantic = 1;
- decl.Semantic.Name = name;
- decl.Semantic.Index = index;
- decl.Range.First = first;
- decl.Range.Last = last;
-
- return decl;
-}
-
-struct tgsi_full_declaration vl_decl_temps(unsigned int first, unsigned int last)
-{
- struct tgsi_full_declaration decl = tgsi_default_full_declaration();
-
- decl = tgsi_default_full_declaration();
- decl.Declaration.File = TGSI_FILE_TEMPORARY;
- decl.Range.First = first;
- decl.Range.Last = last;
-
- return decl;
-}
-
-struct tgsi_full_declaration vl_decl_samplers(unsigned int first, unsigned int last)
-{
- struct tgsi_full_declaration decl = tgsi_default_full_declaration();
-
- decl = tgsi_default_full_declaration();
- decl.Declaration.File = TGSI_FILE_SAMPLER;
- decl.Range.First = first;
- decl.Range.Last = last;
-
- return decl;
-}
-
-struct tgsi_full_instruction vl_inst2
-(
- int opcode,
- enum tgsi_file_type dst_file,
- unsigned int dst_index,
- enum tgsi_file_type src_file,
- unsigned int src_index
-)
-{
- struct tgsi_full_instruction inst = tgsi_default_full_instruction();
-
- inst.Instruction.Opcode = opcode;
- inst.Instruction.NumDstRegs = 1;
- inst.Dst[0].Register.File = dst_file;
- inst.Dst[0].Register.Index = dst_index;
- inst.Instruction.NumSrcRegs = 1;
- inst.Src[0].Register.File = src_file;
- inst.Src[0].Register.Index = src_index;
-
- return inst;
-}
-
-struct tgsi_full_instruction vl_inst3
-(
- int opcode,
- enum tgsi_file_type dst_file,
- unsigned int dst_index,
- enum tgsi_file_type src1_file,
- unsigned int src1_index,
- enum tgsi_file_type src2_file,
- unsigned int src2_index
-)
-{
- struct tgsi_full_instruction inst = tgsi_default_full_instruction();
-
- inst.Instruction.Opcode = opcode;
- inst.Instruction.NumDstRegs = 1;
- inst.Dst[0].Register.File = dst_file;
- inst.Dst[0].Register.Index = dst_index;
- inst.Instruction.NumSrcRegs = 2;
- inst.Src[0].Register.File = src1_file;
- inst.Src[0].Register.Index = src1_index;
- inst.Src[1].Register.File = src2_file;
- inst.Src[1].Register.Index = src2_index;
-
- return inst;
-}
-
-struct tgsi_full_instruction vl_tex
-(
- int tex,
- enum tgsi_file_type dst_file,
- unsigned int dst_index,
- enum tgsi_file_type src1_file,
- unsigned int src1_index,
- enum tgsi_file_type src2_file,
- unsigned int src2_index
-)
-{
- struct tgsi_full_instruction inst = tgsi_default_full_instruction();
-
- inst.Instruction.Opcode = TGSI_OPCODE_TEX;
- inst.Instruction.NumDstRegs = 1;
- inst.Dst[0].Register.File = dst_file;
- inst.Dst[0].Register.Index = dst_index;
- inst.Instruction.NumSrcRegs = 2;
- inst.Instruction.Texture = 1;
- inst.Texture.Texture = tex;
- inst.Src[0].Register.File = src1_file;
- inst.Src[0].Register.Index = src1_index;
- inst.Src[1].Register.File = src2_file;
- inst.Src[1].Register.Index = src2_index;
-
- return inst;
-}
-
-struct tgsi_full_instruction vl_inst4
-(
- int opcode,
- enum tgsi_file_type dst_file,
- unsigned int dst_index,
- enum tgsi_file_type src1_file,
- unsigned int src1_index,
- enum tgsi_file_type src2_file,
- unsigned int src2_index,
- enum tgsi_file_type src3_file,
- unsigned int src3_index
-)
-{
- struct tgsi_full_instruction inst = tgsi_default_full_instruction();
-
- inst.Instruction.Opcode = opcode;
- inst.Instruction.NumDstRegs = 1;
- inst.Dst[0].Register.File = dst_file;
- inst.Dst[0].Register.Index = dst_index;
- inst.Instruction.NumSrcRegs = 3;
- inst.Src[0].Register.File = src1_file;
- inst.Src[0].Register.Index = src1_index;
- inst.Src[1].Register.File = src2_file;
- inst.Src[1].Register.Index = src2_index;
- inst.Src[2].Register.File = src3_file;
- inst.Src[2].Register.Index = src3_index;
-
- return inst;
-}
-
-struct tgsi_full_instruction vl_end(void)
-{
- struct tgsi_full_instruction inst = tgsi_default_full_instruction();
-
- inst.Instruction.Opcode = TGSI_OPCODE_END;
- inst.Instruction.NumDstRegs = 0;
- inst.Instruction.NumSrcRegs = 0;
-
- return inst;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 vl_shader_build_h
-#define vl_shader_build_h
-
-#include <pipe/p_shader_tokens.h>
-
-struct tgsi_full_declaration vl_decl_input(unsigned int name, unsigned int index, unsigned int first, unsigned int last);
-struct tgsi_full_declaration vl_decl_interpolated_input
-(
- unsigned int name,
- unsigned int index,
- unsigned int first,
- unsigned int last,
- int interpolation
-);
-struct tgsi_full_declaration vl_decl_constants(unsigned int name, unsigned int index, unsigned int first, unsigned int last);
-struct tgsi_full_declaration vl_decl_output(unsigned int name, unsigned int index, unsigned int first, unsigned int last);
-struct tgsi_full_declaration vl_decl_temps(unsigned int first, unsigned int last);
-struct tgsi_full_declaration vl_decl_samplers(unsigned int first, unsigned int last);
-struct tgsi_full_instruction vl_inst2
-(
- int opcode,
- enum tgsi_file_type dst_file,
- unsigned int dst_index,
- enum tgsi_file_type src_file,
- unsigned int src_index
-);
-struct tgsi_full_instruction vl_inst3
-(
- int opcode,
- enum tgsi_file_type dst_file,
- unsigned int dst_index,
- enum tgsi_file_type src1_file,
- unsigned int src1_index,
- enum tgsi_file_type src2_file,
- unsigned int src2_index
-);
-struct tgsi_full_instruction vl_tex
-(
- int tex,
- enum tgsi_file_type dst_file,
- unsigned int dst_index,
- enum tgsi_file_type src1_file,
- unsigned int src1_index,
- enum tgsi_file_type src2_file,
- unsigned int src2_index
-);
-struct tgsi_full_instruction vl_inst4
-(
- int opcode,
- enum tgsi_file_type dst_file,
- unsigned int dst_index,
- enum tgsi_file_type src1_file,
- unsigned int src1_index,
- enum tgsi_file_type src2_file,
- unsigned int src2_index,
- enum tgsi_file_type src3_file,
- unsigned int src3_index
-);
-struct tgsi_full_instruction vl_end(void);
-
-#endif
Resource Busy Queries
^^^^^^^^^^^^^^^^^^^^^
-``is_texture_referenced``
-
-``is_buffer_referenced``
+``is_resource_referenced``
for a driver to batch multiple blits with the same source and
destination.
+
+Transfers
+^^^^^^^^^
+
+These methods are used to get data to/from a resource.
+
+``get_transfer`` creates a transfer object.
+
+``transfer_destroy`` destroys the transfer object. May cause
+data to be written to the resource at this point.
+
+``transfer_map`` creates a memory mapping for the transfer object.
+The returned map points to the start of the mapped range according to
+the box region, not the beginning of the resource.
+
+.. _transfer_flush_region:
+``transfer_flush_region`` If a transfer was created with TRANFER_FLUSH_EXPLICIT,
+only the region specified is guaranteed to be written to. This is relative to
+the mapped range, not the beginning of the resource.
+
+``transfer_unmap`` remove the memory mapping for the transfer object.
+Any pointers into the map should be considered invalid and discarded.
+
+``transfer_inline_write`` performs a simplified transfer for simple writes.
+Basically get_transfer, transfer_map, data write, transfer_unmap, and
+transfer_destroy all in one.
+
+.. _pipe_transfer:
+
+PIPE_TRANSFER
+^^^^^^^^^^^^^
+
+These flags control the behavior of a transfer object.
+
+* ``READ``: resource contents are read at transfer create time.
+* ``WRITE``: resource contents will be written back at transfer destroy time.
+* ``MAP_DIRECTLY``: a transfer should directly map the resource. May return
+ NULL if not supported.
+* ``DISCARD``: The memory within the mapped region is discarded.
+ Cannot be used with ``READ``.
+* ``DONTBLOCK``: Fail if the resource cannot be mapped immediately.
+* ``UNSYNCHRONIZED``: Do not synchronize pending operations on the resource
+ when mapping. The interaction of any writes to the map and any
+ operations pending on the resource are undefined. Cannot be used with
+ ``READ``.
+* ``FLUSH_EXPLICIT``: Written ranges will be notified later with
+ :ref:`transfer_flush_region`. Cannot be used with
+ ``READ``.
file is still supported. In that case, the constbuf index is assumed
to be 0.
-.. _pipe_buffer_usage:
+.. _pipe_bind:
-PIPE_BUFFER_USAGE
-^^^^^^^^^^^^^^^^^
+PIPE_BIND
+^^^^^^^^^
-These flags control buffer creation. Buffers may only have one role, so
-care should be taken to not allocate a buffer with the wrong usage.
-
-* ``PIXEL``: This is the flag to use for all textures.
-* ``VERTEX``: A vertex buffer.
-* ``INDEX``: An element buffer.
-* ``CONSTANT``: A buffer of shader constants.
-
-Buffers are inevitably abstracting the pipe's underlying memory management,
-so many of their usage flags can be used to direct the way the buffer is
-handled.
-
-* ``CPU_READ``, ``CPU_WRITE``: Whether the user will map and, in the case of
- the latter, write to, the buffer. The convenience flag ``CPU_READ_WRITE`` is
- available to signify a read/write buffer.
-* ``GPU_READ``, ``GPU_WRITE``: Whether the driver will internally need to
- read from or write to the buffer. The latter will only happen if the buffer
- is made into a render target.
-* ``DISCARD``: When set on a map, the contents of the map will be discarded
- beforehand. Cannot be used with ``CPU_READ``.
-* ``DONTBLOCK``: When set on a map, the map will fail if the buffer cannot be
- mapped immediately.
-* ``UNSYNCHRONIZED``: When set on a map, any outstanding operations on the
- buffer will be ignored. The interaction of any writes to the map and any
- operations pending with the buffer are undefined. Cannot be used with
- ``CPU_READ``.
-* ``FLUSH_EXPLICIT``: When set on a map, written ranges of the map require
- explicit flushes using :ref:`buffer_flush_mapped_range`. Requires
- ``CPU_WRITE``.
-
-.. _pipe_texture_usage:
-
-PIPE_TEXTURE_USAGE
-^^^^^^^^^^^^^^^^^^
-
-These flags determine the possible roles a texture may be used for during its
-lifetime. Texture usage flags are cumulative and may be combined to create a
-texture that can be used as multiple things.
+These flags control resource creation. Resources may be used in different roles
+during their lifecycle. Bind flags are cumulative and may be combined to create
+a resource which can be used as multiple things.
+Depending on the pipe driver's memory management, depending on these bind flags
+resources might be created and handled quite differently.
* ``RENDER_TARGET``: A color buffer or pixel buffer which will be rendered to.
* ``DISPLAY_TARGET``: A sharable buffer that can be given to another process.
-* ``PRIMARY``: A front color buffer or scanout buffer.
* ``DEPTH_STENCIL``: A depth (Z) buffer or stencil buffer. Gallium does
not explicitly provide for stencil-only buffers, so any stencil buffer
validated here is implicitly also a depth buffer.
-* ``SAMPLER``: A texture that may be sampled from in a fragment or vertex
+* ``SAMPLER_VIEW``: A texture that may be sampled from in a fragment or vertex
shader.
-* ``DYNAMIC``: A texture that will be mapped frequently.
+* ``VERTEX_BUFFER``: A vertex buffer.
+* ``INDEX_BUFFER``: An element buffer.
+* ``CONSTANT_BUFFER``: A buffer of shader constants.
+* ``BLIT_SOURCE``: A blit source, as given to surface_copy.
+* ``BLIT_DESTINATION``: A blit destination, as given to surface_copy and surface_fill.
+* ``TRANSFER_WRITE``: A transfer object which will be written to.
+* ``TRANSFER_READ``: A transfer object which will be read from.
+* ``CUSTOM``:
+* ``SCANOUT``: A front color buffer or scanout buffer.
+* ``SHARED``:
+
+.. _pipe_usage:
+
+PIPE_USAGE
+^^^^^^^^^^
+
+The PIPE_USAGE enums are hints about the expected lifecycle of a resource.
+* ``DEFAULT``: Expect many uploads to the resource, intermixed with draws.
+* ``DYNAMIC``: Expect many uploads to the resource, intermixed with draws.
+* ``STATIC``: Same as immutable (?)
+* ``IMMUTABLE``: Resource will not be changed after first upload.
+* ``STREAM``: Upload will be followed by draw, followed by upload, ...
+
PIPE_TEXTURE_GEOM
See if a format can be used in a specific manner.
-**usage** is a bitmask of :ref:`PIPE_TEXTURE_USAGE` flags.
+**tex_usage** is a bitmask of :ref:`PIPE_BIND` flags.
Returns TRUE if all usages can be satisfied.
-.. note::
-
- ``PIPE_TEXTURE_USAGE_DYNAMIC`` is not a valid usage.
-.. _texture_create:
+.. _resource_create:
-texture_create
+resource_create
^^^^^^^^^^^^^^
-Given a template of texture setup, create a buffer and texture.
+Given a template of texture setup, create a resource.
+The way a resource may be used is specifed by bind flags, :ref:`pipe_bind`.
+and hints are used to indicate to the driver what access pattern might be
+likely, :ref:`pipe_usage`.
-texture_blanket
+resource_destroy
^^^^^^^^^^^^^^^
-Like :ref:`texture_create`, but use a supplied buffer instead of creating a
-new one.
-
-texture_destroy
-^^^^^^^^^^^^^^^
-
-Destroy a texture. The buffer backing the texture is destroyed if it has no
-more references.
-
-buffer_map
-^^^^^^^^^^
-
-Map a buffer into memory.
-
-**usage** is a bitmask of :ref:`PIPE_BUFFER_USAGE` flags.
-
-Returns a pointer to the map, or NULL if the mapping failed.
-
-buffer_map_range
-^^^^^^^^^^^^^^^^
-
-Map a range of a buffer into memory.
-
-The returned map is always relative to the beginning of the buffer, not the
-beginning of the mapped range.
-
-.. _buffer_flush_mapped_range:
-
-buffer_flush_mapped_range
-^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Flush a range of mapped memory into a buffer.
-
-The buffer must have been mapped with ``PIPE_BUFFER_USAGE_FLUSH_EXPLICIT``.
-
-**usage** is a bitmask of :ref:`PIPE_BUFFER_USAGE` flags.
-
-buffer_unmap
-^^^^^^^^^^^^
-
-Unmap a buffer from memory.
+Destroy a resource. A resource is destroyed if it has no more references.
-Any pointers into the map should be considered invalid and discarded.
SOURCES = \
cell_batch.c \
- cell_buffer.c \
cell_clear.c \
cell_context.c \
cell_draw_arrays.c \
+++ /dev/null
-/**************************************************************************
- *
- * 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 "cell_screen.h"
-#include "cell_buffer.h"
-
-
-static void *
-cell_buffer_map(struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned flags)
-{
- struct cell_buffer *cell_buf = cell_buffer(buf);
- return cell_buf->data;
-}
-
-
-static void
-cell_buffer_unmap(struct pipe_screen *screen,
- struct pipe_buffer *buf)
-{
-}
-
-
-static void
-cell_buffer_destroy(struct pipe_buffer *buf)
-{
- struct cell_buffer *sbuf = cell_buffer(buf);
-
- if (!sbuf->userBuffer)
- align_free(sbuf->data);
-
- FREE(sbuf);
-}
-
-
-static struct pipe_buffer *
-cell_buffer_create(struct pipe_screen *screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct cell_buffer *buffer = CALLOC_STRUCT(cell_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 *
-cell_user_buffer_create(struct pipe_screen *screen,
- void *ptr,
- unsigned bytes)
-{
- struct cell_buffer *buffer;
-
- buffer = CALLOC_STRUCT(cell_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
-cell_init_screen_buffer_funcs(struct pipe_screen *screen)
-{
- screen->buffer_create = cell_buffer_create;
- screen->user_buffer_create = cell_user_buffer_create;
- screen->buffer_map = cell_buffer_map;
- screen->buffer_unmap = cell_buffer_unmap;
- screen->buffer_destroy = cell_buffer_destroy;
-}
+++ /dev/null
-/**************************************************************************
- *
- * 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 SP_BUFFER_H
-#define SP_BUFFER_H
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_state.h"
-
-
-struct cell_buffer
-{
- struct pipe_buffer base;
- boolean userBuffer; /** Is this a user-space buffer? */
- void *data;
-};
-
-
-/** Cast wrapper */
-static INLINE struct cell_buffer *
-cell_buffer( struct pipe_buffer *buf )
-{
- return (struct cell_buffer *)buf;
-}
-
-
-void
-cell_init_screen_buffer_funcs(struct pipe_screen *screen);
-
-
-#endif /* SP_BUFFER_H */
};
static unsigned int
-cell_is_texture_referenced( struct pipe_context *pipe,
- struct pipe_texture *texture,
+cell_is_resource_referenced( struct pipe_context *pipe,
+ struct pipe_resource *texture,
unsigned face, unsigned level)
{
/**
return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
}
-static unsigned int
-cell_is_buffer_referenced( struct pipe_context *pipe,
- struct pipe_buffer *buf)
-{
- /**
- * FIXME: Optimize.
- */
-
- return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
-}
struct pipe_context *
cell_create_context(struct pipe_screen *screen,
cell->pipe.clear = cell_clear;
cell->pipe.flush = cell_flush;
- cell->pipe.is_texture_referenced = cell_is_texture_referenced;
- cell->pipe.is_buffer_referenced = cell_is_buffer_referenced;
+ cell->pipe.is_resource_referenced = cell_is_resource_referenced;
#if 0
cell->pipe.begin_query = cell_begin_query;
struct pipe_blend_color blend_color;
struct pipe_stencil_ref stencil_ref;
struct pipe_clip_state clip;
- struct pipe_buffer *constants[2];
+ struct pipe_resource *constants[2];
struct pipe_framebuffer_state framebuffer;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
- struct cell_texture *texture[PIPE_MAX_SAMPLERS];
+ struct cell_resource *texture[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
uint num_textures;
struct pipe_viewport_state viewport;
#include "cell_draw_arrays.h"
#include "cell_state.h"
#include "cell_flush.h"
-#include "cell_buffer.h"
+#include "cell_texture.h"
#include "draw/draw_context.h"
*/
static void
cell_draw_range_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned min_index,
unsigned max_index,
* Map vertex buffers
*/
for (i = 0; i < cell->num_vertex_buffers; i++) {
- void *buf = cell_buffer(cell->vertex_buffer[i].buffer)->data;
+ void *buf = cell_resource(cell->vertex_buffer[i].buffer)->data;
draw_set_mapped_vertex_buffer(draw, i, buf);
}
/* Map index buffer, if present */
if (indexBuffer) {
- void *mapped_indexes = cell_buffer(indexBuffer)->data;
+ void *mapped_indexes = cell_resource(indexBuffer)->data;
draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
}
else {
static void
cell_draw_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
struct cell_buffer_node
{
- struct pipe_buffer *buffer;
+ struct pipe_resource *buffer;
struct cell_buffer_node *next;
};
static void
cell_add_buffer_to_list(struct cell_context *cell,
struct cell_buffer_list *list,
- struct pipe_buffer *buffer)
+ struct pipe_resource *buffer)
{
struct cell_buffer_node *node = CALLOC_STRUCT(cell_buffer_node);
/* create new list node which references the buffer, insert at head */
if (node) {
- pipe_buffer_reference(&node->buffer, buffer);
+ pipe_resource_reference(&node->buffer, buffer);
node->next = list->head;
list->head = node;
}
if (node->buffer->reference.count == 1)
printf(" Delete!\n");
#endif
- pipe_buffer_reference(&node->buffer, NULL);
+ pipe_resource_reference(&node->buffer, NULL);
FREE(node);
node = next;
}
uint i;
for (i = 0; i < cell->num_textures; i++) {
- struct cell_texture *ct = cell->texture[i];
+ struct cell_resource *ct = cell->texture[i];
if (ct) {
#if 0
printf("Adding texture %p buffer %p to list\n",
struct pipe_sampler_view *old_view = cell->fragment_sampler_views[i];
if (old_view != new_view) {
- struct pipe_texture *new_tex = new_view ? new_view->texture : NULL;
+ struct pipe_resource *new_tex = new_view ? new_view->texture : NULL;
pipe_sampler_view_reference(&cell->fragment_sampler_views[i],
views[i]);
- pipe_texture_reference((struct pipe_texture **) &cell->texture[i],
- (struct pipe_texture *) new_tex);
+ pipe_resource_reference((struct pipe_resource **) &cell->texture[i],
+ (struct pipe_resource *) new_tex);
changed |= (1 << i);
}
static struct pipe_sampler_view *
cell_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);
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
- pipe_texture_reference(&view->texture, texture);
+ pipe_resource_reference(&view->texture, texture);
view->context = pipe;
}
cell_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);
}
for (i = 0; i < 1; i++) {
struct pipe_surface *ps = cell->framebuffer.cbufs[i];
if (ps) {
- struct cell_texture *ct = cell_texture(ps->texture);
+ struct cell_resource *ct = cell_resource(ps->texture);
#if 0
cell->cbuf_map[i] = screen->buffer_map(screen,
ct->buffer,
{
struct pipe_surface *ps = cell->framebuffer.zsbuf;
if (ps) {
- struct cell_texture *ct = cell_texture(ps->texture);
+ struct cell_resource *ct = cell_resource(ps->texture);
#if 0
cell->zsbuf_map = screen->buffer_map(screen,
ct->buffer,
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
struct pipe_surface *ps = cell->framebuffer.cbufs[i];
if (ps && cell->cbuf_map[i]) {
- /*struct cell_texture *ct = cell_texture(ps->texture);*/
+ /*struct cell_resource *ct = cell_resource(ps->texture);*/
assert(ps->texture);
/*assert(ct->buffer);*/
{
struct pipe_surface *ps = cell->framebuffer.zsbuf;
if (ps && cell->zsbuf_map) {
- /*struct cell_texture *ct = cell_texture(ps->texture);*/
+ /*struct cell_resource *ct = cell_resource(ps->texture);*/
/*screen->buffer_unmap(screen, ct->buffer);*/
cell->zsbuf_map = NULL;
}
#include "cell_context.h"
#include "cell_screen.h"
#include "cell_texture.h"
-#include "cell_buffer.h"
#include "cell_public.h"
#include "state_tracker/sw_winsys.h"
unsigned tex_usage,
unsigned geom_flags )
{
-
struct sw_winsys *winsys = cell_screen(screen)->winsys;
- if (tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED)) {
+ if (tex_usage & (PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED)) {
if (!winsys->is_displaytarget_format_supported(winsys, tex_usage, format))
return FALSE;
}
screen->base.context_create = cell_create_context;
cell_init_screen_texture_funcs(&screen->base);
- cell_init_screen_buffer_funcs(&screen->base);
return &screen->base;
}
if (cell->dirty & (CELL_NEW_FS_CONSTANTS)) {
const uint shader = PIPE_SHADER_FRAGMENT;
- const uint num_const = cell->constants[shader]->size / sizeof(float);
+ const uint num_const = cell->constants[shader]->width0 / sizeof(float);
uint i, j;
float *buf = cell_batch_alloc16(cell, ROUNDUP16(32 + num_const * sizeof(float)));
uint32_t *ibuf = (uint32_t *) buf;
texture->opcode[0] = CELL_CMD_STATE_TEXTURE;
texture->unit = i;
if (cell->texture[i]) {
- struct cell_texture *ct = cell->texture[i];
+ struct cell_resource *ct = cell->texture[i];
uint level;
for (level = 0; level < CELL_MAX_TEXTURE_LEVELS; level++) {
texture->start[level] = (ct->mapped +
#include "cell_context.h"
#include "cell_state.h"
#include "cell_gen_fp.h"
-#include "cell_buffer.h"
+#include "cell_texture.h"
/** cast wrapper */
static void
cell_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
- struct pipe_buffer *constants)
+ struct pipe_resource *constants)
{
struct cell_context *cell = cell_context(pipe);
- unsigned size = constants ? constants->size : 0;
- const void *data = constants ? cell_buffer(constants)->data : NULL;
+ unsigned size = constants ? constants->width0 : 0;
+ const void *data = constants ? cell_resource(constants)->data : NULL;
assert(shader < PIPE_SHADER_TYPES);
assert(index == 0);
draw_flush(cell->draw);
/* note: reference counting */
- pipe_buffer_reference(&cell->constants[shader], constants);
+ pipe_resource_reference(&cell->constants[shader], constants);
if(shader == PIPE_SHADER_VERTEX) {
draw_set_mapped_constant_buffer(cell->draw, PIPE_SHADER_VERTEX, 0,
#include "cell_context.h"
#include "cell_screen.h"
#include "cell_state.h"
-#include "cell_texture.h"
+#include "cell_resource.h"
#include "state_tracker/sw_winsys.h"
static boolean
-cell_texture_layout(struct pipe_screen *screen,
- struct cell_texture *ct)
+cell_resource_layout(struct pipe_screen *screen,
+ struct cell_resource *ct)
{
- struct pipe_texture *pt = &ct->base;
+ struct pipe_resource *pt = &ct->base;
unsigned level;
unsigned width = pt->width0;
unsigned height = pt->height0;
*/
static boolean
cell_displaytarget_layout(struct pipe_screen *screen,
- struct cell_texture * ct)
+ struct cell_resource * ct)
{
struct sw_winsys *winsys = cell_screen(screen)->winsys;
/* Round up the surface size to a multiple of the tile size?
*/
ct->dt = winsys->displaytarget_create(winsys,
- ct->base.tex_usage,
+ ct->base.bind,
ct->base.format,
ct->base.width0,
ct->base.height0,
return ct->dt != NULL;
}
-static struct pipe_texture *
-cell_texture_create(struct pipe_screen *screen,
- const struct pipe_texture *templat)
+static struct pipe_resource *
+cell_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *templat)
{
- struct cell_texture *ct = CALLOC_STRUCT(cell_texture);
+ struct cell_resource *ct = CALLOC_STRUCT(cell_resource);
if (!ct)
return NULL;
/* Create both a displaytarget (linear) and regular texture
* (twiddled). Convert twiddled->linear at flush_frontbuffer time.
*/
- if (ct->base.tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED)) {
+ if (ct->base.bind & (PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED)) {
if (!cell_displaytarget_layout(screen, ct))
goto fail;
}
- if (!cell_texture_layout(screen, ct))
+ if (!cell_resource_layout(screen, ct))
goto fail;
return &ct->base;
static void
-cell_texture_destroy(struct pipe_texture *pt)
+cell_resource_destroy(struct pipe_resource *pt)
{
struct cell_screen *screen = cell_screen(pt->screen);
struct sw_winsys *winsys = screen->winsys;
- struct cell_texture *ct = cell_texture(pt);
+ struct cell_resource *ct = cell_resource(pt);
if (ct->dt) {
/* display target */
winsys->displaytarget_destroy(winsys, ct->dt);
}
-
- align_free(ct->data);
+ else if (!ct->userBuffer) {
+ align_free(ct->data);
+ }
FREE(ct);
}
static struct pipe_surface *
cell_get_tex_surface(struct pipe_screen *screen,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
unsigned face, unsigned level, unsigned zslice,
unsigned usage)
{
- struct cell_texture *ct = cell_texture(pt);
+ struct cell_resource *ct = cell_resource(pt);
struct pipe_surface *ps;
ps = CALLOC_STRUCT(pipe_surface);
if (ps) {
pipe_reference_init(&ps->reference, 1);
- pipe_texture_reference(&ps->texture, pt);
+ pipe_resource_reference(&ps->texture, pt);
ps->format = pt->format;
ps->width = u_minify(pt->width0, level);
ps->height = u_minify(pt->height0, level);
static void
cell_tex_surface_destroy(struct pipe_surface *surf)
{
- pipe_texture_reference(&surf->texture, NULL);
+ pipe_resource_reference(&surf->texture, NULL);
FREE(surf);
}
* back out for glGetTexImage).
*/
static struct pipe_transfer *
-cell_get_tex_transfer(struct pipe_context *ctx,
- struct pipe_texture *texture,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
+cell_get_transfer(struct pipe_context *ctx,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
{
- struct cell_texture *ct = cell_texture(texture);
+ struct cell_resource *ct = cell_resource(resource);
struct cell_transfer *ctrans;
+ enum pipe_format *format = resource->format;
+
+ assert(resource);
+ assert(level <= resource->last_level);
- assert(texture);
- assert(level <= texture->last_level);
+ /* make sure the requested region is in the image bounds */
+ assert(box->x + box->width <= u_minify(resource->width0, sr.level));
+ assert(box->y + box->height <= u_minify(resource->height0, sr.level));
+ assert(box->z + box->depth <= u_minify(resource->depth0, sr.level));
ctrans = CALLOC_STRUCT(cell_transfer);
if (ctrans) {
struct pipe_transfer *pt = &ctrans->base;
- pipe_texture_reference(&pt->texture, texture);
- pt->x = x;
- pt->y = y;
- pt->width = w;
- pt->height = h;
- pt->stride = ct->stride[level];
+ pipe_resource_reference(&pt->resource, resource);
+ pt->sr = sr;
pt->usage = usage;
- pt->face = face;
- pt->level = level;
- pt->zslice = zslice;
+ pt->box = *box;
+ pt->stride = ct->stride[sr.level];
- ctrans->offset = ct->level_offset[level];
+ ctrans->offset = ct->level_offset[sr.level];
- if (texture->target == PIPE_TEXTURE_CUBE) {
- unsigned h_tile = align(u_minify(texture->height0, level), TILE_SIZE);
- ctrans->offset += face * util_format_get_nblocksy(texture->format, h_tile) * pt->stride;
+ if (resource->target == PIPE_TEXTURE_CUBE) {
+ unsigned h_tile = align(u_minify(resource->height0, sr.level), TILE_SIZE);
+ ctrans->offset += sr.face * util_format_get_nblocksy(format, h_tile) * pt->stride;
}
- else if (texture->target == PIPE_TEXTURE_3D) {
- unsigned h_tile = align(u_minify(texture->height0, level), TILE_SIZE);
- ctrans->offset += zslice * util_format_get_nblocksy(texture->format, h_tile) * pt->stride;
+ else if (resource->target == PIPE_TEXTURE_3D) {
+ unsigned h_tile = align(u_minify(resource->height0, sr.level), TILE_SIZE);
+ ctrans->offset += box->z * util_format_get_nblocksy(format, h_tile) * pt->stride;
}
else {
- assert(face == 0);
- assert(zslice == 0);
+ assert(sr.face == 0);
+ assert(box->z == 0);
}
+
return pt;
}
return NULL;
static void
-cell_tex_transfer_destroy(struct pipe_context *ctx, struct pipe_transfer *t)
+cell_transfer_destroy(struct pipe_context *ctx, struct pipe_transfer *t)
{
struct cell_transfer *transfer = cell_transfer(t);
/* Effectively do the texture_update work here - if texture images
* needed post-processing to put them into hardware layout, this is
* where it would happen. For cell, nothing to do.
*/
- assert (transfer->base.texture);
- pipe_texture_reference(&transfer->base.texture, NULL);
+ assert (transfer->base.resource);
+ pipe_resource_reference(&transfer->base.resource, NULL);
FREE(transfer);
}
cell_transfer_map(struct pipe_context *ctx, struct pipe_transfer *transfer)
{
struct cell_transfer *ctrans = cell_transfer(transfer);
- struct pipe_texture *pt = transfer->texture;
- struct cell_texture *ct = cell_texture(pt);
- const uint level = ctrans->base.level;
- const uint texWidth = u_minify(pt->width0, level);
- const uint texHeight = u_minify(pt->height0, level);
- const uint stride = ct->stride[level];
- unsigned size;
+ struct pipe_resource *pt = transfer->resource;
+ struct cell_resource *ct = cell_resource(pt);
- assert(transfer->texture);
+ assert(transfer->resource);
if (ct->mapped == NULL) {
ct->mapped = ct->data;
}
- /*
- * Create a buffer of ordinary memory for the linear texture.
- * This is the memory that the user will read/write.
+
+ /* Better test would be resource->is_linear
*/
- size = util_format_get_stride(pt->format, align(texWidth, TILE_SIZE)) *
- util_format_get_nblocksy(pt->format, align(texHeight, TILE_SIZE));
-
- ctrans->map = align_malloc(size, 16);
- if (!ctrans->map)
- return NULL; /* out of memory */
-
- if (transfer->usage & PIPE_TRANSFER_READ) {
- /* need to untwiddle the texture to make a linear version */
- const uint bpp = util_format_get_blocksize(ct->base.format);
- if (bpp == 4) {
- const uint *src = (uint *) (ct->mapped + ctrans->offset);
- uint *dst = ctrans->map;
- untwiddle_image_uint(texWidth, texHeight, TILE_SIZE,
- dst, stride, src);
- }
- else {
- // xxx fix
+ if (transfer->resource->target != PIPE_BUFFER) {
+ const uint level = ctrans->base.sr.level;
+ const uint texWidth = u_minify(pt->width0, level);
+ const uint texHeight = u_minify(pt->height0, level);
+ unsigned size;
+
+
+ /*
+ * Create a buffer of ordinary memory for the linear texture.
+ * This is the memory that the user will read/write.
+ */
+ size = (util_format_get_stride(pt->format, align(texWidth, TILE_SIZE)) *
+ util_format_get_nblocksy(pt->format, align(texHeight, TILE_SIZE)));
+
+ ctrans->map = align_malloc(size, 16);
+ if (!ctrans->map)
+ return NULL; /* out of memory */
+
+ if (transfer->usage & PIPE_TRANSFER_READ) {
+ /* Textures always stored twiddled, need to untwiddle the
+ * texture to make a linear version.
+ */
+ const uint bpp = util_format_get_blocksize(ct->base.format);
+ if (bpp == 4) {
+ const uint *src = (uint *) (ct->mapped + ctrans->offset);
+ uint *dst = ctrans->map;
+ untwiddle_image_uint(texWidth, texHeight, TILE_SIZE,
+ dst, transfer->stride, src);
+ }
+ else {
+ // xxx fix
+ }
}
}
+ else {
+ unsigned stride = transfer->stride;
+ enum pipe_format format = pt->format;
+ unsigned blocksize = util_format_get_blocksize(format);
+
+ ctrans->map = (ct->mapped +
+ ctrans->offset +
+ ctrans->base.box.y / util_format_get_blockheight(format) * stride +
+ ctrans->base.box.x / util_format_get_blockwidth(format) * blocksize);
+ }
+
return ctrans->map;
}
struct pipe_transfer *transfer)
{
struct cell_transfer *ctrans = cell_transfer(transfer);
- struct pipe_texture *pt = transfer->texture;
- struct cell_texture *ct = cell_texture(pt);
- const uint level = ctrans->base.level;
+ struct pipe_resource *pt = transfer->resource;
+ struct cell_resource *ct = cell_resource(pt);
+ const uint level = ctrans->base.sr.level;
const uint texWidth = u_minify(pt->width0, level);
const uint texHeight = u_minify(pt->height0, level);
const uint stride = ct->stride[level];
return;
}
- if (transfer->usage & PIPE_TRANSFER_WRITE) {
- /* The user wrote new texture data into the mapped buffer.
- * We need to convert the new linear data into the twiddled/tiled format.
- */
- const uint bpp = util_format_get_blocksize(ct->base.format);
- if (bpp == 4) {
- const uint *src = ctrans->map;
- uint *dst = (uint *) (ct->mapped + ctrans->offset);
- twiddle_image_uint(texWidth, texHeight, TILE_SIZE, dst, stride, src);
- }
- else {
- // xxx fix
+ if (pt->target != PIPE_BUFFER) {
+ if (transfer->usage & PIPE_TRANSFER_WRITE) {
+ /* The user wrote new texture data into the mapped buffer.
+ * We need to convert the new linear data into the twiddled/tiled format.
+ */
+ const uint bpp = util_format_get_blocksize(ct->base.format);
+ if (bpp == 4) {
+ const uint *src = ctrans->map;
+ uint *dst = (uint *) (ct->mapped + ctrans->offset);
+ twiddle_image_uint(texWidth, texHeight, TILE_SIZE, dst, stride, src);
+ }
+ else {
+ // xxx fix
+ }
}
+
+ align_free(ctrans->map);
+ }
+ else {
+ /* nothing to do */
}
- align_free(ctrans->map);
ctrans->map = NULL;
}
{
struct cell_screen *screen = cell_screen(_screen);
struct sw_winsys *winsys = screen->winsys;
- struct cell_texture *ct = cell_texture(surface->texture);
+ struct cell_resource *ct = cell_resource(surface->texture);
if (!ct->dt)
return;
*/
{
unsigned *map = winsys->displaytarget_map(winsys, ct->dt,
- (PIPE_BUFFER_USAGE_CPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE));
+ (PIPE_TRANSFER_READ |
+ PIPE_TRANSFER_WRITE));
unsigned *src = (unsigned *)(ct->data + ct->level_offset[surface->level]);
untwiddle_image_uint(surface->width,
}
+
+/**
+ * Create buffer which wraps user-space data.
+ */
+static struct pipe_resource *
+cell_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind_flags)
+{
+ struct cell_resource *buffer;
+
+ buffer = CALLOC_STRUCT(cell_resource);
+ if(!buffer)
+ return NULL;
+
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->base.screen = screen;
+ buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */
+ buffer->base.bind = PIPE_BIND_TRANSFER_READ | bind_flags;
+ buffer->base._usage = PIPE_USAGE_IMMUTABLE;
+ buffer->base.flags = 0;
+ buffer->base.width0 = bytes;
+ buffer->base.height0 = 1;
+ buffer->base.depth0 = 1;
+ buffer->userBuffer = TRUE;
+ buffer->data = ptr;
+
+ return &buffer->base;
+}
+
+
+
+
void
cell_init_screen_texture_funcs(struct pipe_screen *screen)
{
- screen->texture_create = cell_texture_create;
- screen->texture_destroy = cell_texture_destroy;
+ screen->resource_create = cell_resource_create;
+ screen->resource_destroy = cell_resource_destroy;
+ screen->resource_from_handle = cell_resource_from_handle;
+ screen->resource_get_handle = cell_resource_get_handle;
+ screen->user_buffer_create = cell_user_buffer_create;
screen->get_tex_surface = cell_get_tex_surface;
screen->tex_surface_destroy = cell_tex_surface_destroy;
}
void
-cell_init_texture_transfer_funcs(struct cell_context *cell)
+cell_init_transfer_funcs(struct cell_context *cell)
{
- cell->pipe.get_tex_transfer = cell_get_tex_transfer;
- cell->pipe.tex_transfer_destroy = cell_tex_transfer_destroy;
+ cell->pipe.get_transfer = cell_get_transfer;
+ cell->pipe.transfer_destroy = cell_transfer_destroy;
cell->pipe.transfer_map = cell_transfer_map;
cell->pipe.transfer_unmap = cell_transfer_unmap;
+
+ cell->pipe.transfer_flush_region = u_default_transfer_flush_region;
+ cell->pipe.transfer_inline_write = u_default_transfer_inline_write;
}
#include "cell/common.h"
struct cell_context;
-struct pipe_texture;
+struct pipe_resource;
/**
- * Subclass of pipe_texture
+ * Subclass of pipe_resource
*/
-struct cell_texture
+struct cell_resource
{
- struct pipe_texture base;
+ struct pipe_resource base;
unsigned long level_offset[CELL_MAX_TEXTURE_LEVELS];
unsigned long stride[CELL_MAX_TEXTURE_LEVELS];
/**
- * Display target, for textures with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET
+ * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET
* usage.
*/
struct sw_displaytarget *dt;
* Malloc'ed data for regular textures, or a mapping to dt above.
*/
void *data;
+ boolean userBuffer;
/* Size of the linear buffer??
*/
/** cast wrapper */
-static INLINE struct cell_texture *
-cell_texture(struct pipe_texture *pt)
+static INLINE struct cell_resource *
+cell_resource(struct pipe_resource *pt)
{
- return (struct cell_texture *) pt;
+ return (struct cell_resource *) pt;
}
struct spu_sampler
{
const struct pipe_sampler_state *state;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
/** Get samples for four fragments in a quad */
void (*get_samples)(struct spu_sampler *sampler,
const float s[QUAD_SIZE],
static void failover_draw_elements( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexResource,
unsigned indexSize,
unsigned prim,
unsigned start,
*/
if (failover->mode == FO_HW) {
failover->hw->draw_elements( failover->hw,
- indexBuffer,
+ indexResource,
indexSize,
prim,
start,
}
failover->sw->draw_elements( failover->sw,
- indexBuffer,
+ indexResource,
indexSize,
prim,
start,
}
static unsigned int
-failover_is_texture_referenced( struct pipe_context *_pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level)
+failover_is_resource_referenced( struct pipe_context *_pipe,
+ struct pipe_resource *resource,
+ unsigned face, unsigned level)
{
struct failover_context *failover = failover_context( _pipe );
struct pipe_context *pipe = (failover->mode == FO_HW) ?
failover->hw : failover->sw;
- return pipe->is_texture_referenced(pipe, texture, face, level);
-}
-
-static unsigned int
-failover_is_buffer_referenced( struct pipe_context *_pipe,
- struct pipe_buffer *buf)
-{
- struct failover_context *failover = failover_context( _pipe );
- struct pipe_context *pipe = (failover->mode == FO_HW) ?
- failover->hw : failover->sw;
-
- return pipe->is_buffer_referenced(pipe, buf);
+ return pipe->is_resource_referenced(pipe, resource, face, level);
}
struct pipe_context *failover_create( struct pipe_context *hw,
#endif
failover->pipe.flush = hw->flush;
- failover->pipe.is_texture_referenced = failover_is_texture_referenced;
- failover->pipe.is_buffer_referenced = failover_is_buffer_referenced;
+ failover->pipe.is_resource_referenced = failover_is_resource_referenced;
failover->dirty = 0;
void
failover_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
- struct pipe_buffer *buf);
+ struct pipe_resource *resource);
#endif /* FO_CONTEXT_H */
static struct pipe_sampler_view *
failover_create_sampler_view(struct pipe_context *pipe,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
const struct pipe_sampler_view *templ)
{
struct fo_sampler_view *view = malloc(sizeof(struct fo_sampler_view));
view->base = *templ;
view->base.reference.count = 1;
view->base.texture = NULL;
- pipe_texture_reference(&view->base.texture, texture);
+ pipe_resource_reference(&view->base.texture, texture);
view->base.context = pipe;
return &view->base;
failover->sw->sampler_view_destroy(failover->sw, fo_view->sw);
failover->hw->sampler_view_destroy(failover->hw, fo_view->hw);
- pipe_texture_reference(&fo_view->base.texture, NULL);
+ pipe_resource_reference(&fo_view->base.texture, NULL);
free(fo_view);
}
void
failover_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
- struct pipe_buffer *buf)
+ struct pipe_resource *res)
{
struct failover_context *failover = failover_context(pipe);
assert(shader < PIPE_SHADER_TYPES);
assert(index == 0);
- failover->sw->set_constant_buffer(failover->sw, shader, index, buf);
- failover->hw->set_constant_buffer(failover->hw, shader, index, buf);
+ failover->sw->set_constant_buffer(failover->sw, shader, index, res);
+ failover->hw->set_constant_buffer(failover->hw, shader, index, res);
}
C_SOURCES = \
i915_blit.c \
- i915_buffer.c \
i915_clear.c \
i915_flush.c \
i915_context.c \
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
target = 'i915',
source = [
'i915_blit.c',
- 'i915_buffer.c',
+ 'i915_resource_buffer.c',
'i915_clear.c',
'i915_context.c',
'i915_debug.c',
'i915_state_immediate.c',
'i915_state_sampler.c',
'i915_surface.c',
- 'i915_texture.c',
+ 'i915_resource.c',
+ 'i915_resource_texture.c',
])
Export('i915')
+++ /dev/null
-/**************************************************************************
- *
- * 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.
- *
- **************************************************************************/
-
-#include "util/u_inlines.h"
-#include "util/u_memory.h"
-#include "i915_screen.h"
-#include "i915_buffer.h"
-
-struct i915_winsys_buffer;
-
-struct i915_buffer
-{
- struct pipe_buffer base;
-
- struct i915_winsys_buffer *ibuf; /** hw buffer */
-
- void *data; /**< user and malloc data */
- boolean own; /**< we own the data incase of malloc */
-};
-
-static INLINE struct i915_buffer *
-i915_buffer(struct pipe_buffer *buffer)
-{
- return (struct i915_buffer *)buffer;
-}
-
-static struct pipe_buffer *
-i915_buffer_create(struct pipe_screen *screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer);
-
- if (!buf)
- return NULL;
-
- pipe_reference_init(&buf->base.reference, 1);
- buf->base.alignment = alignment;
- buf->base.screen = screen;
- buf->base.usage = usage;
- buf->base.size = size;
- buf->data = MALLOC(size);
- buf->own = TRUE;
-
- if (!buf->data)
- goto err;
-
- return &buf->base;
-
-err:
- FREE(buf);
- return NULL;
-}
-
-static struct pipe_buffer *
-i915_user_buffer_create(struct pipe_screen *screen,
- void *ptr,
- unsigned bytes)
-{
- struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer);
-
- if (!buf)
- return NULL;
-
- pipe_reference_init(&buf->base.reference, 1);
- buf->base.alignment = 0;
- buf->base.screen = screen;
- buf->base.usage = 0;
- buf->base.size = bytes;
- buf->data = ptr;
- buf->own = FALSE;
-
- return &buf->base;
-}
-
-static void *
-i915_buffer_map(struct pipe_screen *screen,
- struct pipe_buffer *buffer,
- unsigned usage)
-{
- struct i915_buffer *buf = i915_buffer(buffer);
- assert(!buf->ibuf);
- return buf->data;
-}
-
-static void
-i915_buffer_unmap(struct pipe_screen *screen,
- struct pipe_buffer *buffer)
-{
- struct i915_buffer *buf = i915_buffer(buffer);
- assert(!buf->ibuf);
- (void) buf;
-}
-
-static void
-i915_buffer_destroy(struct pipe_buffer *buffer)
-{
- struct i915_buffer *buf = i915_buffer(buffer);
- assert(!buf->ibuf);
-
- if (buf->own)
- FREE(buf->data);
- FREE(buf);
-}
-
-void i915_init_screen_buffer_functions(struct i915_screen *screen)
-{
- screen->base.buffer_create = i915_buffer_create;
- screen->base.user_buffer_create = i915_user_buffer_create;
- screen->base.buffer_map = i915_buffer_map;
- screen->base.buffer_map_range = NULL;
- screen->base.buffer_flush_mapped_range = NULL;
- screen->base.buffer_unmap = i915_buffer_unmap;
- screen->base.buffer_destroy = i915_buffer_destroy;
-}
+++ /dev/null
-/**************************************************************************
- *
- * 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
#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"
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,
* 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);
}
* 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,
* 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)
{
}
-/*
- * Is referenced functions
- */
-
-
-static unsigned int
-i915_is_texture_referenced(struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level)
-{
- /**
- * FIXME: Return the corrent result. We can't alays return referenced
- * since it causes a double flush within the vbo module.
- */
-#if 0
- return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
-#else
- return 0;
-#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;
-}
/*
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;
-
/*
* Create drawing context and plug our rendering stage into it.
*/
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);
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 i915_winsys_buffer *buffer;
-};
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;
/***********************************************************************
- * 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 );
void *priv);
-/***********************************************************************
- * i915_texture.c
- */
-void i915_init_texture_functions(struct i915_context *i915 );
/***********************************************************************
--- /dev/null
+#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.is_resource_referenced = u_default_is_resource_referenced;
+ 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;
+ is->base.user_buffer_create = i915_user_buffer_create;
+}
--- /dev/null
+/**************************************************************************
+ *
+ * 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 i915_winsys_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 */
--- /dev/null
+/**************************************************************************
+ *
+ * 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"
+
+#include "i915_context.h"
+#include "i915_resource.h"
+#include "i915_screen.h"
+
+
+
+static boolean
+i915_buffer_get_handle(struct pipe_screen *screen,
+ struct pipe_resource *resource,
+ struct winsys_handle *handle)
+{
+ return FALSE;
+}
+
+static void
+i915_buffer_destroy(struct pipe_screen *screen,
+ struct pipe_resource *resource)
+{
+ struct i915_buffer *buffer = i915_buffer(resource);
+ if (buffer->free_on_destroy)
+ align_free(buffer->data);
+ FREE(buffer);
+}
+
+
+static void *
+i915_buffer_transfer_map( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ struct i915_buffer *buffer = i915_buffer(transfer->resource);
+ return buffer->data + transfer->box.x;
+}
+
+
+static void
+i915_buffer_transfer_inline_write( struct pipe_context *rm_ctx,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned slice_stride)
+{
+ struct i915_buffer *buffer = i915_buffer(resource);
+
+ memcpy(buffer->data + box->x,
+ data,
+ box->width);
+}
+
+
+struct u_resource_vtbl i915_buffer_vtbl =
+{
+ i915_buffer_get_handle, /* get_handle */
+ i915_buffer_destroy, /* resource_destroy */
+ NULL, /* is_resource_referenced */
+ u_default_get_transfer, /* get_transfer */
+ u_default_transfer_destroy, /* transfer_destroy */
+ i915_buffer_transfer_map, /* transfer_map */
+ u_default_transfer_flush_region, /* transfer_flush_region */
+ u_default_transfer_unmap, /* transfer_unmap */
+ i915_buffer_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+struct pipe_resource *
+i915_buffer_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer);
+
+ if (!buf)
+ return NULL;
+
+ buf->b.b = *template;
+ buf->b.vtbl = &i915_buffer_vtbl;
+ pipe_reference_init(&buf->b.b.reference, 1);
+ buf->b.b.screen = screen;
+
+ buf->data = MALLOC(template->width0);
+ buf->free_on_destroy = TRUE;
+
+ if (!buf->data)
+ goto err;
+
+ return &buf->b.b;
+
+err:
+ FREE(buf);
+ return NULL;
+}
+
+
+
+struct pipe_resource *
+i915_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind)
+{
+ struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer);
+
+ if (!buf)
+ return NULL;
+
+ pipe_reference_init(&buf->b.b.reference, 1);
+ buf->b.vtbl = &i915_buffer_vtbl;
+ buf->b.b.screen = screen;
+ buf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */
+ buf->b.b._usage = PIPE_USAGE_IMMUTABLE;
+ buf->b.b.bind = bind;
+ buf->b.b.flags = 0;
+ buf->b.b.width0 = bytes;
+ buf->b.b.height0 = 1;
+ buf->b.b.depth0 = 1;
+
+ buf->data = ptr;
+ buf->free_on_destroy = FALSE;
+
+ return &buf->b.b;
+}
--- /dev/null
+/**************************************************************************
+ *
+ * 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_state.h"
+#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"
+
+#include "i915_context.h"
+#include "i915_resource.h"
+#include "i915_screen.h"
+#include "i915_winsys.h"
+
+
+/*
+ * Helper function and arrays
+ */
+
+
+/**
+ * Initial offset for Cube map.
+ */
+static const int initial_offsets[6][2] = {
+ {0, 0},
+ {0, 2},
+ {1, 0},
+ {1, 2},
+ {1, 1},
+ {1, 3}
+};
+
+/**
+ * Step offsets for Cube map.
+ */
+static const int step_offsets[6][2] = {
+ {0, 2},
+ {0, 2},
+ {-1, 2},
+ {-1, 2},
+ {-1, 1},
+ {-1, 1}
+};
+
+/* XXX really need twice the size if x is already pot?
+ Otherwise just use util_next_power_of_two?
+*/
+static unsigned
+power_of_two(unsigned x)
+{
+ unsigned value = 1;
+ while (value < x)
+ value = value << 1;
+ return value;
+}
+
+/*
+ * More advanced helper funcs
+ */
+
+
+static void
+i915_texture_set_level_info(struct i915_texture *tex,
+ unsigned level,
+ unsigned nr_images,
+ unsigned w, unsigned h, unsigned d)
+{
+ assert(level < Elements(tex->nr_images));
+
+ tex->nr_images[level] = nr_images;
+
+ /*
+ DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
+ level, w, h, d, x, y, tex->level_offset[level]);
+ */
+
+ /* Not sure when this would happen, but anyway:
+ */
+ if (tex->image_offset[level]) {
+ FREE(tex->image_offset[level]);
+ tex->image_offset[level] = NULL;
+ }
+
+ assert(nr_images);
+ assert(!tex->image_offset[level]);
+
+ tex->image_offset[level] = (unsigned *) MALLOC(nr_images * sizeof(unsigned));
+ tex->image_offset[level][0] = 0;
+}
+
+static void
+i915_texture_set_image_offset(struct i915_texture *tex,
+ unsigned level, unsigned img, unsigned x, unsigned y)
+{
+ if (img == 0 && level == 0)
+ assert(x == 0 && y == 0);
+
+ assert(img < tex->nr_images[level]);
+
+ tex->image_offset[level][img] = y * tex->stride + x * util_format_get_blocksize(tex->b.b.format);
+
+ /*
+ printf("%s level %d img %d pos %d,%d image_offset %x\n",
+ __FUNCTION__, level, img, x, y, tex->image_offset[level][img]);
+ */
+}
+
+
+/*
+ * i915 layout functions, some used by i945
+ */
+
+
+/**
+ * Special case to deal with scanout textures.
+ */
+static boolean
+i915_scanout_layout(struct i915_texture *tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+
+ if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4)
+ return FALSE;
+
+ i915_texture_set_level_info(tex, 0, 1,
+ pt->width0,
+ pt->height0,
+ 1);
+ i915_texture_set_image_offset(tex, 0, 0, 0, 0);
+
+ if (pt->width0 >= 240) {
+ tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0));
+ tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8);
+ tex->hw_tiled = I915_TILE_X;
+ } else if (pt->width0 == 64 && pt->height0 == 64) {
+ tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0));
+ tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8);
+ } else {
+ return FALSE;
+ }
+
+ debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
+ pt->width0, pt->height0, util_format_get_blocksize(pt->format),
+ tex->stride, tex->total_nblocksy, tex->stride * tex->total_nblocksy);
+
+ return TRUE;
+}
+
+/**
+ * Special case to deal with shared textures.
+ */
+static boolean
+i915_display_target_layout(struct i915_texture *tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+
+ if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4)
+ return FALSE;
+
+ /* fallback to normal textures for small textures */
+ if (pt->width0 < 240)
+ return FALSE;
+
+ i915_texture_set_level_info(tex, 0, 1,
+ pt->width0,
+ pt->height0,
+ 1);
+ i915_texture_set_image_offset(tex, 0, 0, 0, 0);
+
+ tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0));
+ tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8);
+ tex->hw_tiled = I915_TILE_X;
+
+ debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
+ pt->width0, pt->height0, util_format_get_blocksize(pt->format),
+ tex->stride, tex->total_nblocksy, tex->stride * tex->total_nblocksy);
+
+ return TRUE;
+}
+
+static void
+i915_texture_layout_2d(struct i915_texture *tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+ unsigned level;
+ unsigned width = pt->width0;
+ unsigned height = pt->height0;
+ unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->width0);
+
+ /* used for scanouts that need special layouts */
+ if (pt->bind & PIPE_BIND_SCANOUT)
+ if (i915_scanout_layout(tex))
+ return;
+
+ /* shared buffers needs to be compatible with X servers
+ *
+ * XXX: need a better name than shared for this if it is to be part
+ * of core gallium, and probably move the flag to resource.flags,
+ * rather than bindings.
+ */
+ if (pt->bind & PIPE_BIND_SHARED)
+ if (i915_display_target_layout(tex))
+ return;
+
+ tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4);
+ tex->total_nblocksy = 0;
+
+ for (level = 0; level <= pt->last_level; level++) {
+ i915_texture_set_level_info(tex, level, 1, width, height, 1);
+ i915_texture_set_image_offset(tex, level, 0, 0, tex->total_nblocksy);
+
+ nblocksy = align(MAX2(2, nblocksy), 2);
+
+ tex->total_nblocksy += nblocksy;
+
+ width = u_minify(width, 1);
+ height = u_minify(height, 1);
+ nblocksy = util_format_get_nblocksy(pt->format, height);
+ }
+}
+
+static void
+i915_texture_layout_3d(struct i915_texture *tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+ unsigned level;
+
+ unsigned width = pt->width0;
+ unsigned height = pt->height0;
+ unsigned depth = pt->depth0;
+ unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->height0);
+ unsigned stack_nblocksy = 0;
+
+ /* Calculate the size of a single slice.
+ */
+ tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4);
+
+ /* XXX: hardware expects/requires 9 levels at minimum.
+ */
+ for (level = 0; level <= MAX2(8, pt->last_level); level++) {
+ i915_texture_set_level_info(tex, level, depth, width, height, depth);
+
+ stack_nblocksy += MAX2(2, nblocksy);
+
+ width = u_minify(width, 1);
+ height = u_minify(height, 1);
+ nblocksy = util_format_get_nblocksy(pt->format, height);
+ }
+
+ /* Fixup depth image_offsets:
+ */
+ for (level = 0; level <= pt->last_level; level++) {
+ unsigned i;
+ for (i = 0; i < depth; i++)
+ i915_texture_set_image_offset(tex, level, i, 0, i * stack_nblocksy);
+
+ depth = u_minify(depth, 1);
+ }
+
+ /* Multiply slice size by texture depth for total size. It's
+ * remarkable how wasteful of memory the i915 texture layouts
+ * are. They are largely fixed in the i945.
+ */
+ tex->total_nblocksy = stack_nblocksy * pt->depth0;
+}
+
+static void
+i915_texture_layout_cube(struct i915_texture *tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+ unsigned width = pt->width0, height = pt->height0;
+ const unsigned nblocks = util_format_get_nblocksx(pt->format, pt->width0);
+ unsigned level;
+ unsigned face;
+
+ assert(width == height); /* cubemap images are square */
+
+ /* double pitch for cube layouts */
+ tex->stride = align(nblocks * util_format_get_blocksize(pt->format) * 2, 4);
+ tex->total_nblocksy = nblocks * 4;
+
+ for (level = 0; level <= pt->last_level; level++) {
+ i915_texture_set_level_info(tex, level, 6, width, height, 1);
+ width /= 2;
+ height /= 2;
+ }
+
+ for (face = 0; face < 6; face++) {
+ unsigned x = initial_offsets[face][0] * nblocks;
+ unsigned y = initial_offsets[face][1] * nblocks;
+ unsigned d = nblocks;
+
+ for (level = 0; level <= pt->last_level; level++) {
+ i915_texture_set_image_offset(tex, level, face, x, y);
+ d >>= 1;
+ x += step_offsets[face][0] * d;
+ y += step_offsets[face][1] * d;
+ }
+ }
+}
+
+static boolean
+i915_texture_layout(struct i915_texture * tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+
+ switch (pt->target) {
+ case PIPE_TEXTURE_1D:
+ case PIPE_TEXTURE_2D:
+ i915_texture_layout_2d(tex);
+ break;
+ case PIPE_TEXTURE_3D:
+ i915_texture_layout_3d(tex);
+ break;
+ case PIPE_TEXTURE_CUBE:
+ i915_texture_layout_cube(tex);
+ break;
+ default:
+ assert(0);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * i945 layout functions
+ */
+
+
+static void
+i945_texture_layout_2d(struct i915_texture *tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+ const int align_x = 2, align_y = 4;
+ unsigned level;
+ unsigned x = 0;
+ unsigned y = 0;
+ unsigned width = pt->width0;
+ unsigned height = pt->height0;
+ unsigned nblocksx = util_format_get_nblocksx(pt->format, pt->width0);
+ unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->height0);
+
+ /* used for scanouts that need special layouts */
+ if (tex->b.b.bind & PIPE_BIND_SCANOUT)
+ if (i915_scanout_layout(tex))
+ return;
+
+ /* shared buffers needs to be compatible with X servers */
+ if (tex->b.b.bind & PIPE_BIND_SHARED)
+ if (i915_display_target_layout(tex))
+ return;
+
+ tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4);
+
+ /* May need to adjust pitch to accomodate the placement of
+ * the 2nd mipmap level. This occurs when the alignment
+ * constraints of mipmap placement push the right edge of the
+ * 2nd mipmap level out past the width of its parent.
+ */
+ if (pt->last_level > 0) {
+ unsigned mip1_nblocksx
+ = align(util_format_get_nblocksx(pt->format, u_minify(width, 1)), align_x)
+ + util_format_get_nblocksx(pt->format, u_minify(width, 2));
+
+ if (mip1_nblocksx > nblocksx)
+ tex->stride = mip1_nblocksx * util_format_get_blocksize(pt->format);
+ }
+
+ /* Pitch must be a whole number of dwords
+ */
+ tex->stride = align(tex->stride, 64);
+ tex->total_nblocksy = 0;
+
+ for (level = 0; level <= pt->last_level; level++) {
+ i915_texture_set_level_info(tex, level, 1, width, height, 1);
+ i915_texture_set_image_offset(tex, level, 0, x, y);
+
+ nblocksy = align(nblocksy, align_y);
+
+ /* Because the images are packed better, the final offset
+ * might not be the maximal one:
+ */
+ tex->total_nblocksy = MAX2(tex->total_nblocksy, y + nblocksy);
+
+ /* Layout_below: step right after second mipmap level.
+ */
+ if (level == 1) {
+ x += align(nblocksx, align_x);
+ }
+ else {
+ y += nblocksy;
+ }
+
+ width = u_minify(width, 1);
+ height = u_minify(height, 1);
+ nblocksx = util_format_get_nblocksx(pt->format, width);
+ nblocksy = util_format_get_nblocksy(pt->format, height);
+ }
+}
+
+static void
+i945_texture_layout_3d(struct i915_texture *tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+ unsigned width = pt->width0;
+ unsigned height = pt->height0;
+ unsigned depth = pt->depth0;
+ unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->width0);
+ unsigned pack_x_pitch, pack_x_nr;
+ unsigned pack_y_pitch;
+ unsigned level;
+
+ tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4);
+ tex->total_nblocksy = 0;
+
+ pack_y_pitch = MAX2(nblocksy, 2);
+ pack_x_pitch = tex->stride / util_format_get_blocksize(pt->format);
+ pack_x_nr = 1;
+
+ for (level = 0; level <= pt->last_level; level++) {
+ int x = 0;
+ int y = 0;
+ unsigned q, j;
+
+ i915_texture_set_level_info(tex, level, depth, width, height, depth);
+
+ for (q = 0; q < depth;) {
+ for (j = 0; j < pack_x_nr && q < depth; j++, q++) {
+ i915_texture_set_image_offset(tex, level, q, x, y + tex->total_nblocksy);
+ x += pack_x_pitch;
+ }
+
+ x = 0;
+ y += pack_y_pitch;
+ }
+
+ tex->total_nblocksy += y;
+
+ if (pack_x_pitch > 4) {
+ pack_x_pitch >>= 1;
+ pack_x_nr <<= 1;
+ assert(pack_x_pitch * pack_x_nr * util_format_get_blocksize(pt->format) <= tex->stride);
+ }
+
+ if (pack_y_pitch > 2) {
+ pack_y_pitch >>= 1;
+ }
+
+ width = u_minify(width, 1);
+ height = u_minify(height, 1);
+ depth = u_minify(depth, 1);
+ nblocksy = util_format_get_nblocksy(pt->format, height);
+ }
+}
+
+static void
+i945_texture_layout_cube(struct i915_texture *tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+ unsigned level;
+
+ const unsigned nblocks = util_format_get_nblocksx(pt->format, pt->width0);
+ unsigned face;
+ unsigned width = pt->width0;
+ unsigned height = pt->height0;
+
+ /*
+ printf("%s %i, %i\n", __FUNCTION__, pt->width0, pt->height0);
+ */
+
+ assert(width == height); /* cubemap images are square */
+
+ /*
+ * XXX Should only be used for compressed formats. But lets
+ * keep this code active just in case.
+ *
+ * Depending on the size of the largest images, pitch can be
+ * determined either by the old-style packing of cubemap faces,
+ * or the final row of 4x4, 2x2 and 1x1 faces below this.
+ */
+ if (nblocks > 32)
+ tex->stride = align(nblocks * util_format_get_blocksize(pt->format) * 2, 4);
+ else
+ tex->stride = 14 * 8 * util_format_get_blocksize(pt->format);
+
+ tex->total_nblocksy = nblocks * 4;
+
+ /* Set all the levels to effectively occupy the whole rectangular region.
+ */
+ for (level = 0; level <= pt->last_level; level++) {
+ i915_texture_set_level_info(tex, level, 6, width, height, 1);
+ width /= 2;
+ height /= 2;
+ }
+
+ for (face = 0; face < 6; face++) {
+ unsigned x = initial_offsets[face][0] * nblocks;
+ unsigned y = initial_offsets[face][1] * nblocks;
+ unsigned d = nblocks;
+
+#if 0 /* Fix and enable this code for compressed formats */
+ if (nblocks == 4 && face >= 4) {
+ y = tex->total_height - 4;
+ x = (face - 4) * 8;
+ }
+ else if (nblocks < 4 && (face > 0)) {
+ y = tex->total_height - 4;
+ x = face * 8;
+ }
+#endif
+
+ for (level = 0; level <= pt->last_level; level++) {
+ i915_texture_set_image_offset(tex, level, face, x, y);
+
+ d >>= 1;
+
+#if 0 /* Fix and enable this code for compressed formats */
+ switch (d) {
+ case 4:
+ switch (face) {
+ case PIPE_TEX_FACE_POS_X:
+ case PIPE_TEX_FACE_NEG_X:
+ x += step_offsets[face][0] * d;
+ y += step_offsets[face][1] * d;
+ break;
+ case PIPE_TEX_FACE_POS_Y:
+ case PIPE_TEX_FACE_NEG_Y:
+ y += 12;
+ x -= 8;
+ break;
+ case PIPE_TEX_FACE_POS_Z:
+ case PIPE_TEX_FACE_NEG_Z:
+ y = tex->total_height - 4;
+ x = (face - 4) * 8;
+ break;
+ }
+ case 2:
+ y = tex->total_height - 4;
+ x = 16 + face * 8;
+ break;
+
+ case 1:
+ x += 48;
+ break;
+ default:
+#endif
+ x += step_offsets[face][0] * d;
+ y += step_offsets[face][1] * d;
+#if 0
+ break;
+ }
+#endif
+ }
+ }
+}
+
+static boolean
+i945_texture_layout(struct i915_texture * tex)
+{
+ struct pipe_resource *pt = &tex->b.b;
+
+ switch (pt->target) {
+ case PIPE_TEXTURE_1D:
+ case PIPE_TEXTURE_2D:
+ i945_texture_layout_2d(tex);
+ break;
+ case PIPE_TEXTURE_3D:
+ i945_texture_layout_3d(tex);
+ break;
+ case PIPE_TEXTURE_CUBE:
+ i945_texture_layout_cube(tex);
+ break;
+ default:
+ assert(0);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+
+/*
+ * Screen texture functions
+ */
+
+
+
+static boolean
+i915_texture_get_handle(struct pipe_screen * screen,
+ struct pipe_resource *texture,
+ struct winsys_handle *whandle)
+{
+ struct i915_screen *is = i915_screen(screen);
+ struct i915_texture *tex = i915_texture(texture);
+ struct i915_winsys *iws = is->iws;
+
+ return iws->buffer_get_handle(iws, tex->buffer, whandle, tex->stride);
+}
+
+
+static void
+i915_texture_destroy(struct pipe_screen *screen,
+ struct pipe_resource *pt)
+{
+ struct i915_texture *tex = i915_texture(pt);
+ struct i915_winsys *iws = i915_screen(screen)->iws;
+ uint i;
+
+ /*
+ DBG("%s deleting %p\n", __FUNCTION__, (void *) tex);
+ */
+
+ iws->buffer_destroy(iws, tex->buffer);
+
+ for (i = 0; i < Elements(tex->image_offset); i++)
+ if (tex->image_offset[i])
+ FREE(tex->image_offset[i]);
+
+ FREE(tex);
+}
+
+static struct pipe_transfer *
+i915_texture_get_transfer(struct pipe_context *context,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
+{
+ struct i915_texture *tex = i915_texture(resource);
+ 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;
+ transfer->stride = tex->stride;
+
+ return transfer;
+}
+
+
+static void *
+i915_texture_transfer_map(struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
+{
+ struct pipe_resource *resource = transfer->resource;
+ struct i915_texture *tex = i915_texture(resource);
+ struct i915_winsys *iws = i915_screen(pipe->screen)->iws;
+ struct pipe_subresource sr = transfer->sr;
+ struct pipe_box *box = &transfer->box;
+ enum pipe_format format = resource->format;
+ unsigned offset;
+ char *map;
+
+ if (resource->target == PIPE_TEXTURE_CUBE) {
+ offset = tex->image_offset[sr.level][sr.face];
+ }
+ else if (resource->target == PIPE_TEXTURE_3D) {
+ offset = tex->image_offset[sr.level][box->z];
+ }
+ else {
+ offset = tex->image_offset[sr.level][0];
+ assert(sr.face == 0);
+ assert(box->z == 0);
+ }
+
+ map = iws->buffer_map(iws,
+ tex->buffer,
+ (transfer->usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE);
+ if (map == NULL)
+ return NULL;
+
+ return map + offset +
+ box->y / util_format_get_blockheight(format) * transfer->stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+}
+
+static void
+i915_texture_transfer_unmap(struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
+{
+ struct i915_texture *tex = i915_texture(transfer->resource);
+ struct i915_winsys *iws = i915_screen(tex->b.b.screen)->iws;
+ iws->buffer_unmap(iws, tex->buffer);
+}
+
+
+
+struct u_resource_vtbl i915_texture_vtbl =
+{
+ i915_texture_get_handle, /* get_handle */
+ i915_texture_destroy, /* resource_destroy */
+ NULL, /* is_resource_referenced */
+ i915_texture_get_transfer, /* get_transfer */
+ u_default_transfer_destroy, /* transfer_destroy */
+ i915_texture_transfer_map, /* transfer_map */
+ u_default_transfer_flush_region, /* transfer_flush_region */
+ i915_texture_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+
+struct pipe_resource *
+i915_texture_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ struct i915_screen *is = i915_screen(screen);
+ struct i915_winsys *iws = is->iws;
+ struct i915_texture *tex = CALLOC_STRUCT(i915_texture);
+ size_t tex_size;
+ unsigned buf_usage = 0;
+
+ if (!tex)
+ return NULL;
+
+ tex->b.b = *template;
+ tex->b.vtbl = &i915_texture_vtbl;
+ pipe_reference_init(&tex->b.b.reference, 1);
+ tex->b.b.screen = screen;
+
+ if (is->is_i945) {
+ if (!i945_texture_layout(tex))
+ goto fail;
+ } else {
+ if (!i915_texture_layout(tex))
+ goto fail;
+ }
+
+ tex_size = tex->stride * tex->total_nblocksy;
+
+ /* for scanouts and cursors, cursors arn't scanouts */
+
+ /* XXX: use a custom flag for cursors, don't rely on magically
+ * guessing that this is Xorg asking for a cursor
+ */
+ if ((template->bind & PIPE_BIND_SCANOUT) && template->width0 != 64)
+ buf_usage = I915_NEW_SCANOUT;
+ else
+ buf_usage = I915_NEW_TEXTURE;
+
+ tex->buffer = iws->buffer_create(iws, tex_size, 64, buf_usage);
+ if (!tex->buffer)
+ goto fail;
+
+ /* setup any hw fences */
+ if (tex->hw_tiled) {
+ assert(tex->sw_tiled == I915_TILE_NONE);
+ iws->buffer_set_fence_reg(iws, tex->buffer, tex->stride, tex->hw_tiled);
+ }
+
+
+#if 0
+ void *ptr = ws->buffer_map(ws, tex->buffer,
+ PIPE_BUFFER_USAGE_CPU_WRITE);
+ memset(ptr, 0x80, tex_size);
+ ws->buffer_unmap(ws, tex->buffer);
+#endif
+
+ return &tex->b.b;
+
+fail:
+ FREE(tex);
+ return NULL;
+}
+
+struct pipe_resource *
+i915_texture_from_handle(struct pipe_screen * screen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle)
+{
+ struct i915_screen *is = i915_screen(screen);
+ struct i915_texture *tex;
+ struct i915_winsys *iws = is->iws;
+ struct i915_winsys_buffer *buffer;
+ unsigned stride;
+
+ assert(screen);
+
+ buffer = iws->buffer_from_handle(iws, whandle, &stride);
+
+ /* Only supports one type */
+ if (template->target != PIPE_TEXTURE_2D ||
+ template->last_level != 0 ||
+ template->depth0 != 1) {
+ return NULL;
+ }
+
+ tex = CALLOC_STRUCT(i915_texture);
+ if (!tex)
+ return NULL;
+
+ tex->b.b = *template;
+ tex->b.vtbl = &i915_texture_vtbl;
+ pipe_reference_init(&tex->b.b.reference, 1);
+ tex->b.b.screen = screen;
+
+ tex->stride = stride;
+
+ i915_texture_set_level_info(tex, 0, 1, template->width0, template->height0, 1);
+ i915_texture_set_image_offset(tex, 0, 0, 0, 0);
+
+ tex->buffer = buffer;
+
+ return &tex->b.b;
+}
+
#include "i915_reg.h"
#include "i915_context.h"
#include "i915_screen.h"
-#include "i915_buffer.h"
-#include "i915_texture.h"
+#include "i915_surface.h"
+#include "i915_resource.h"
#include "i915_winsys.h"
const enum pipe_format *list;
uint i;
- if(tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
+ if(tex_usage & PIPE_BIND_RENDER_TARGET)
list = surface_supported;
else
list = tex_supported;
is->base.fence_signalled = i915_fence_signalled;
is->base.fence_finish = i915_fence_finish;
- i915_init_screen_texture_functions(is);
- i915_init_screen_buffer_functions(is);
+ i915_init_screen_resource_functions(is);
+ i915_init_screen_surface_functions(is);
return &is->base;
}
#include "i915_reg.h"
#include "i915_state_inlines.h"
#include "i915_fpc.h"
+#include "i915_resource.h"
/* The i915 (and related graphics cores) do not support GL_CLAMP. The
* Intel drivers for "other operating systems" implement GL_CLAMP as
static void i915_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
- struct pipe_buffer *buf)
+ struct pipe_resource *buf)
{
struct i915_context *i915 = i915_context(pipe);
- struct pipe_screen *screen = pipe->screen;
+ struct i915_buffer *ir = i915_buffer(buf);
draw_flush(i915->draw);
assert(shader < PIPE_SHADER_TYPES);
* N constants, leaving any extras from shader translation alone.
*/
if (buf) {
- void *mapped;
- if (buf->size &&
- (mapped = pipe_buffer_map(screen, buf,
- PIPE_BUFFER_USAGE_CPU_READ))) {
- memcpy(i915->current.constants[shader], mapped, buf->size);
- pipe_buffer_unmap(screen, buf);
- i915->current.num_user_constants[shader]
- = buf->size / (4 * sizeof(float));
- }
- else {
- i915->current.num_user_constants[shader] = 0;
- }
+ memcpy(i915->current.constants[shader], ir->data, ir->b.b.width0);
+ i915->current.num_user_constants[shader] = (ir->b.b.width0 /
+ 4 * sizeof(float));
}
+ else {
+ i915->current.num_user_constants[shader] = 0;
+ }
+
i915->dirty |= I915_NEW_CONSTANTS;
}
static struct pipe_sampler_view *
i915_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);
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
- pipe_texture_reference(&view->texture, texture);
+ pipe_resource_reference(&view->texture, texture);
view->context = pipe;
}
i915_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);
}
#include "i915_context.h"
#include "i915_batch.h"
#include "i915_reg.h"
+#include "i915_resource.h"
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
if (cbuf_surface) {
unsigned ctile = BUF_3D_USE_FENCE;
- struct i915_texture *tex = (struct i915_texture *)
- cbuf_surface->texture;
+ struct i915_texture *tex = i915_texture(cbuf_surface->texture);
assert(tex);
if (tex && tex->sw_tiled) {
*/
if (depth_surface) {
unsigned ztile = BUF_3D_USE_FENCE;
- struct i915_texture *tex = (struct i915_texture *)
- depth_surface->texture;
+ struct i915_texture *tex = i915_texture(depth_surface->texture);
assert(tex);
if (tex && tex->sw_tiled) {
OUT_BATCH(enabled);
for (unit = 0; unit < I915_TEX_UNITS; unit++) {
if (enabled & (1 << unit)) {
- struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture;
+ struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture);
struct i915_winsys_buffer *buf = texture->buffer;
uint offset = 0;
assert(buf);
#include "i915_context.h"
#include "i915_reg.h"
#include "i915_state.h"
+#include "i915_resource.h"
/*
const struct i915_texture *tex,
unsigned state[3] )
{
- const struct pipe_texture *pt = &tex->base;
+ const struct pipe_resource *pt = &tex->b.b;
unsigned minlod, lastlod;
/* Need to do this after updating the maps, which call the
/* determine unit enable/disable by looking for a bound texture */
/* could also examine the fragment program? */
if (i915->fragment_sampler_views[unit]) {
- struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture;
+ struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture);
update_sampler( i915,
unit,
const struct i915_sampler_state *sampler,
uint state[6])
{
- const struct pipe_texture *pt = &tex->base;
+ const struct pipe_resource *pt = &tex->b.b;
uint format, pitch;
const uint width = pt->width0, height = pt->height0, depth = pt->depth0;
const uint num_levels = pt->last_level;
/* determine unit enable/disable by looking for a bound texture */
/* could also examine the fragment program? */
if (i915->fragment_sampler_views[unit]) {
- struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture;
+ struct i915_texture *texture = i915_texture(i915->fragment_sampler_views[unit]->texture);
i915_update_texture( i915,
unit,
*
**************************************************************************/
-#include "i915_context.h"
+#include "i915_surface.h"
+#include "i915_resource.h"
#include "i915_blit.h"
+#include "i915_screen.h"
#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "util/u_math.h"
#include "util/u_format.h"
+#include "util/u_memory.h"
/* Assumes all values are within bounds -- no checking at this level -
struct pipe_surface *src,
unsigned srcx, unsigned srcy, unsigned width, unsigned height)
{
- struct i915_texture *dst_tex = (struct i915_texture *)dst->texture;
- struct i915_texture *src_tex = (struct i915_texture *)src->texture;
- struct pipe_texture *dpt = &dst_tex->base;
- struct pipe_texture *spt = &src_tex->base;
+ struct i915_texture *dst_tex = i915_texture(dst->texture);
+ struct i915_texture *src_tex = i915_texture(src->texture);
+ struct pipe_resource *dpt = &dst_tex->b.b;
+ struct pipe_resource *spt = &src_tex->b.b;
assert( dst != src );
assert( util_format_get_blocksize(dpt->format) == util_format_get_blocksize(spt->format) );
unsigned dstx, unsigned dsty,
unsigned width, unsigned height, unsigned value)
{
- struct i915_texture *tex = (struct i915_texture *)dst->texture;
- struct pipe_texture *pt = &tex->base;
+ struct i915_texture *tex = i915_texture(dst->texture);
+ struct pipe_resource *pt = &tex->b.b;
assert(util_format_get_blockwidth(pt->format) == 1);
assert(util_format_get_blockheight(pt->format) == 1);
}
+/*
+ * Screen surface functions
+ */
+
+
+static struct pipe_surface *
+i915_get_tex_surface(struct pipe_screen *screen,
+ struct pipe_resource *pt,
+ unsigned face, unsigned level, unsigned zslice,
+ unsigned flags)
+{
+ struct i915_texture *tex = i915_texture(pt);
+ struct pipe_surface *ps;
+ unsigned offset; /* in bytes */
+
+ if (pt->target == PIPE_TEXTURE_CUBE) {
+ offset = tex->image_offset[level][face];
+ }
+ else if (pt->target == PIPE_TEXTURE_3D) {
+ offset = tex->image_offset[level][zslice];
+ }
+ else {
+ offset = tex->image_offset[level][0];
+ assert(face == 0);
+ assert(zslice == 0);
+ }
+
+ ps = CALLOC_STRUCT(pipe_surface);
+ if (ps) {
+ pipe_reference_init(&ps->reference, 1);
+ pipe_resource_reference(&ps->texture, pt);
+ ps->format = pt->format;
+ ps->width = u_minify(pt->width0, level);
+ ps->height = u_minify(pt->height0, level);
+ ps->offset = offset;
+ ps->usage = flags;
+ }
+ return ps;
+}
+
+static void
+i915_tex_surface_destroy(struct pipe_surface *surf)
+{
+ pipe_resource_reference(&surf->texture, NULL);
+ FREE(surf);
+}
+
+
+/* Probably going to make blits work on textures rather than surfaces.
+ */
void
i915_init_surface_functions(struct i915_context *i915)
{
i915->base.surface_copy = i915_surface_copy;
i915->base.surface_fill = i915_surface_fill;
}
+
+/* No good reason for these to be in the screen.
+ */
+void
+i915_init_screen_surface_functions(struct i915_screen *is)
+{
+ is->base.get_tex_surface = i915_get_tex_surface;
+ is->base.tex_surface_destroy = i915_tex_surface_destroy;
+}
--- /dev/null
+/**************************************************************************
+ *
+ * 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_SURFACE_H
+#define I915_SURFACE_H
+
+struct i915_context;
+struct i915_screen;
+
+void i915_init_surface_functions( struct i915_context *i915 );
+void i915_init_screen_surface_functions( struct i915_screen *is );
+
+
+#endif /* I915_SCREEN_H */
+++ /dev/null
-/**************************************************************************
- *
- * 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_state.h"
-#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"
-
-#include "i915_context.h"
-#include "i915_texture.h"
-#include "i915_screen.h"
-#include "i915_winsys.h"
-
-
-/*
- * Helper function and arrays
- */
-
-
-/**
- * Initial offset for Cube map.
- */
-static const int initial_offsets[6][2] = {
- {0, 0},
- {0, 2},
- {1, 0},
- {1, 2},
- {1, 1},
- {1, 3}
-};
-
-/**
- * Step offsets for Cube map.
- */
-static const int step_offsets[6][2] = {
- {0, 2},
- {0, 2},
- {-1, 2},
- {-1, 2},
- {-1, 1},
- {-1, 1}
-};
-
-/* XXX really need twice the size if x is already pot?
- Otherwise just use util_next_power_of_two?
-*/
-static unsigned
-power_of_two(unsigned x)
-{
- unsigned value = 1;
- while (value < x)
- value = value << 1;
- return value;
-}
-
-/*
- * More advanced helper funcs
- */
-
-
-static void
-i915_miptree_set_level_info(struct i915_texture *tex,
- unsigned level,
- unsigned nr_images,
- unsigned w, unsigned h, unsigned d)
-{
- assert(level < Elements(tex->nr_images));
-
- tex->nr_images[level] = nr_images;
-
- /*
- DBG("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
- level, w, h, d, x, y, tex->level_offset[level]);
- */
-
- /* Not sure when this would happen, but anyway:
- */
- if (tex->image_offset[level]) {
- FREE(tex->image_offset[level]);
- tex->image_offset[level] = NULL;
- }
-
- assert(nr_images);
- assert(!tex->image_offset[level]);
-
- tex->image_offset[level] = (unsigned *) MALLOC(nr_images * sizeof(unsigned));
- tex->image_offset[level][0] = 0;
-}
-
-static void
-i915_miptree_set_image_offset(struct i915_texture *tex,
- unsigned level, unsigned img, unsigned x, unsigned y)
-{
- if (img == 0 && level == 0)
- assert(x == 0 && y == 0);
-
- assert(img < tex->nr_images[level]);
-
- tex->image_offset[level][img] = y * tex->stride + x * util_format_get_blocksize(tex->base.format);
-
- /*
- printf("%s level %d img %d pos %d,%d image_offset %x\n",
- __FUNCTION__, level, img, x, y, tex->image_offset[level][img]);
- */
-}
-
-
-/*
- * i915 layout functions, some used by i945
- */
-
-
-/**
- * Special case to deal with scanout textures.
- */
-static boolean
-i915_scanout_layout(struct i915_texture *tex)
-{
- struct pipe_texture *pt = &tex->base;
-
- if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4)
- return FALSE;
-
- i915_miptree_set_level_info(tex, 0, 1,
- pt->width0,
- pt->height0,
- 1);
- i915_miptree_set_image_offset(tex, 0, 0, 0, 0);
-
- if (pt->width0 >= 240) {
- tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0));
- tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8);
- tex->hw_tiled = I915_TILE_X;
- } else if (pt->width0 == 64 && pt->height0 == 64) {
- tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0));
- tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8);
- } else {
- return FALSE;
- }
-
- debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
- pt->width0, pt->height0, util_format_get_blocksize(pt->format),
- tex->stride, tex->total_nblocksy, tex->stride * tex->total_nblocksy);
-
- return TRUE;
-}
-
-/**
- * Special case to deal with shared textures.
- */
-static boolean
-i915_display_target_layout(struct i915_texture *tex)
-{
- struct pipe_texture *pt = &tex->base;
-
- if (pt->last_level > 0 || util_format_get_blocksize(pt->format) != 4)
- return FALSE;
-
- /* fallback to normal textures for small textures */
- if (pt->width0 < 240)
- return FALSE;
-
- i915_miptree_set_level_info(tex, 0, 1,
- pt->width0,
- pt->height0,
- 1);
- i915_miptree_set_image_offset(tex, 0, 0, 0, 0);
-
- tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0));
- tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8);
- tex->hw_tiled = I915_TILE_X;
-
- debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
- pt->width0, pt->height0, util_format_get_blocksize(pt->format),
- tex->stride, tex->total_nblocksy, tex->stride * tex->total_nblocksy);
-
- return TRUE;
-}
-
-static void
-i915_miptree_layout_2d(struct i915_texture *tex)
-{
- struct pipe_texture *pt = &tex->base;
- unsigned level;
- unsigned width = pt->width0;
- unsigned height = pt->height0;
- unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->width0);
-
- /* used for scanouts that need special layouts */
- if (pt->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT)
- if (i915_scanout_layout(tex))
- return;
-
- /* shared buffers needs to be compatible with X servers */
- if (pt->tex_usage & PIPE_TEXTURE_USAGE_SHARED)
- if (i915_display_target_layout(tex))
- return;
-
- tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4);
- tex->total_nblocksy = 0;
-
- for (level = 0; level <= pt->last_level; level++) {
- i915_miptree_set_level_info(tex, level, 1, width, height, 1);
- i915_miptree_set_image_offset(tex, level, 0, 0, tex->total_nblocksy);
-
- nblocksy = align(MAX2(2, nblocksy), 2);
-
- tex->total_nblocksy += nblocksy;
-
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- nblocksy = util_format_get_nblocksy(pt->format, height);
- }
-}
-
-static void
-i915_miptree_layout_3d(struct i915_texture *tex)
-{
- struct pipe_texture *pt = &tex->base;
- unsigned level;
-
- unsigned width = pt->width0;
- unsigned height = pt->height0;
- unsigned depth = pt->depth0;
- unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->height0);
- unsigned stack_nblocksy = 0;
-
- /* Calculate the size of a single slice.
- */
- tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4);
-
- /* XXX: hardware expects/requires 9 levels at minimum.
- */
- for (level = 0; level <= MAX2(8, pt->last_level); level++) {
- i915_miptree_set_level_info(tex, level, depth, width, height, depth);
-
- stack_nblocksy += MAX2(2, nblocksy);
-
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- nblocksy = util_format_get_nblocksy(pt->format, height);
- }
-
- /* Fixup depth image_offsets:
- */
- for (level = 0; level <= pt->last_level; level++) {
- unsigned i;
- for (i = 0; i < depth; i++)
- i915_miptree_set_image_offset(tex, level, i, 0, i * stack_nblocksy);
-
- depth = u_minify(depth, 1);
- }
-
- /* Multiply slice size by texture depth for total size. It's
- * remarkable how wasteful of memory the i915 texture layouts
- * are. They are largely fixed in the i945.
- */
- tex->total_nblocksy = stack_nblocksy * pt->depth0;
-}
-
-static void
-i915_miptree_layout_cube(struct i915_texture *tex)
-{
- struct pipe_texture *pt = &tex->base;
- unsigned width = pt->width0, height = pt->height0;
- const unsigned nblocks = util_format_get_nblocksx(pt->format, pt->width0);
- unsigned level;
- unsigned face;
-
- assert(width == height); /* cubemap images are square */
-
- /* double pitch for cube layouts */
- tex->stride = align(nblocks * util_format_get_blocksize(pt->format) * 2, 4);
- tex->total_nblocksy = nblocks * 4;
-
- for (level = 0; level <= pt->last_level; level++) {
- i915_miptree_set_level_info(tex, level, 6, width, height, 1);
- width /= 2;
- height /= 2;
- }
-
- for (face = 0; face < 6; face++) {
- unsigned x = initial_offsets[face][0] * nblocks;
- unsigned y = initial_offsets[face][1] * nblocks;
- unsigned d = nblocks;
-
- for (level = 0; level <= pt->last_level; level++) {
- i915_miptree_set_image_offset(tex, level, face, x, y);
- d >>= 1;
- x += step_offsets[face][0] * d;
- y += step_offsets[face][1] * d;
- }
- }
-}
-
-static boolean
-i915_miptree_layout(struct i915_texture * tex)
-{
- struct pipe_texture *pt = &tex->base;
-
- switch (pt->target) {
- case PIPE_TEXTURE_1D:
- case PIPE_TEXTURE_2D:
- i915_miptree_layout_2d(tex);
- break;
- case PIPE_TEXTURE_3D:
- i915_miptree_layout_3d(tex);
- break;
- case PIPE_TEXTURE_CUBE:
- i915_miptree_layout_cube(tex);
- break;
- default:
- assert(0);
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/*
- * i945 layout functions
- */
-
-
-static void
-i945_miptree_layout_2d(struct i915_texture *tex)
-{
- struct pipe_texture *pt = &tex->base;
- const int align_x = 2, align_y = 4;
- unsigned level;
- unsigned x = 0;
- unsigned y = 0;
- unsigned width = pt->width0;
- unsigned height = pt->height0;
- unsigned nblocksx = util_format_get_nblocksx(pt->format, pt->width0);
- unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->height0);
-
- /* used for scanouts that need special layouts */
- if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_SCANOUT)
- if (i915_scanout_layout(tex))
- return;
-
- /* shared buffers needs to be compatible with X servers */
- if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_SHARED)
- if (i915_display_target_layout(tex))
- return;
-
- tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4);
-
- /* May need to adjust pitch to accomodate the placement of
- * the 2nd mipmap level. This occurs when the alignment
- * constraints of mipmap placement push the right edge of the
- * 2nd mipmap level out past the width of its parent.
- */
- if (pt->last_level > 0) {
- unsigned mip1_nblocksx
- = align(util_format_get_nblocksx(pt->format, u_minify(width, 1)), align_x)
- + util_format_get_nblocksx(pt->format, u_minify(width, 2));
-
- if (mip1_nblocksx > nblocksx)
- tex->stride = mip1_nblocksx * util_format_get_blocksize(pt->format);
- }
-
- /* Pitch must be a whole number of dwords
- */
- tex->stride = align(tex->stride, 64);
- tex->total_nblocksy = 0;
-
- for (level = 0; level <= pt->last_level; level++) {
- i915_miptree_set_level_info(tex, level, 1, width, height, 1);
- i915_miptree_set_image_offset(tex, level, 0, x, y);
-
- nblocksy = align(nblocksy, align_y);
-
- /* Because the images are packed better, the final offset
- * might not be the maximal one:
- */
- tex->total_nblocksy = MAX2(tex->total_nblocksy, y + nblocksy);
-
- /* Layout_below: step right after second mipmap level.
- */
- if (level == 1) {
- x += align(nblocksx, align_x);
- }
- else {
- y += nblocksy;
- }
-
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- nblocksx = util_format_get_nblocksx(pt->format, width);
- nblocksy = util_format_get_nblocksy(pt->format, height);
- }
-}
-
-static void
-i945_miptree_layout_3d(struct i915_texture *tex)
-{
- struct pipe_texture *pt = &tex->base;
- unsigned width = pt->width0;
- unsigned height = pt->height0;
- unsigned depth = pt->depth0;
- unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->width0);
- unsigned pack_x_pitch, pack_x_nr;
- unsigned pack_y_pitch;
- unsigned level;
-
- tex->stride = align(util_format_get_stride(pt->format, pt->width0), 4);
- tex->total_nblocksy = 0;
-
- pack_y_pitch = MAX2(nblocksy, 2);
- pack_x_pitch = tex->stride / util_format_get_blocksize(pt->format);
- pack_x_nr = 1;
-
- for (level = 0; level <= pt->last_level; level++) {
- int x = 0;
- int y = 0;
- unsigned q, j;
-
- i915_miptree_set_level_info(tex, level, depth, width, height, depth);
-
- for (q = 0; q < depth;) {
- for (j = 0; j < pack_x_nr && q < depth; j++, q++) {
- i915_miptree_set_image_offset(tex, level, q, x, y + tex->total_nblocksy);
- x += pack_x_pitch;
- }
-
- x = 0;
- y += pack_y_pitch;
- }
-
- tex->total_nblocksy += y;
-
- if (pack_x_pitch > 4) {
- pack_x_pitch >>= 1;
- pack_x_nr <<= 1;
- assert(pack_x_pitch * pack_x_nr * util_format_get_blocksize(pt->format) <= tex->stride);
- }
-
- if (pack_y_pitch > 2) {
- pack_y_pitch >>= 1;
- }
-
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- depth = u_minify(depth, 1);
- nblocksy = util_format_get_nblocksy(pt->format, height);
- }
-}
-
-static void
-i945_miptree_layout_cube(struct i915_texture *tex)
-{
- struct pipe_texture *pt = &tex->base;
- unsigned level;
-
- const unsigned nblocks = util_format_get_nblocksx(pt->format, pt->width0);
- unsigned face;
- unsigned width = pt->width0;
- unsigned height = pt->height0;
-
- /*
- printf("%s %i, %i\n", __FUNCTION__, pt->width0, pt->height0);
- */
-
- assert(width == height); /* cubemap images are square */
-
- /*
- * XXX Should only be used for compressed formats. But lets
- * keep this code active just in case.
- *
- * Depending on the size of the largest images, pitch can be
- * determined either by the old-style packing of cubemap faces,
- * or the final row of 4x4, 2x2 and 1x1 faces below this.
- */
- if (nblocks > 32)
- tex->stride = align(nblocks * util_format_get_blocksize(pt->format) * 2, 4);
- else
- tex->stride = 14 * 8 * util_format_get_blocksize(pt->format);
-
- tex->total_nblocksy = nblocks * 4;
-
- /* Set all the levels to effectively occupy the whole rectangular region.
- */
- for (level = 0; level <= pt->last_level; level++) {
- i915_miptree_set_level_info(tex, level, 6, width, height, 1);
- width /= 2;
- height /= 2;
- }
-
- for (face = 0; face < 6; face++) {
- unsigned x = initial_offsets[face][0] * nblocks;
- unsigned y = initial_offsets[face][1] * nblocks;
- unsigned d = nblocks;
-
-#if 0 /* Fix and enable this code for compressed formats */
- if (nblocks == 4 && face >= 4) {
- y = tex->total_height - 4;
- x = (face - 4) * 8;
- }
- else if (nblocks < 4 && (face > 0)) {
- y = tex->total_height - 4;
- x = face * 8;
- }
-#endif
-
- for (level = 0; level <= pt->last_level; level++) {
- i915_miptree_set_image_offset(tex, level, face, x, y);
-
- d >>= 1;
-
-#if 0 /* Fix and enable this code for compressed formats */
- switch (d) {
- case 4:
- switch (face) {
- case PIPE_TEX_FACE_POS_X:
- case PIPE_TEX_FACE_NEG_X:
- x += step_offsets[face][0] * d;
- y += step_offsets[face][1] * d;
- break;
- case PIPE_TEX_FACE_POS_Y:
- case PIPE_TEX_FACE_NEG_Y:
- y += 12;
- x -= 8;
- break;
- case PIPE_TEX_FACE_POS_Z:
- case PIPE_TEX_FACE_NEG_Z:
- y = tex->total_height - 4;
- x = (face - 4) * 8;
- break;
- }
- case 2:
- y = tex->total_height - 4;
- x = 16 + face * 8;
- break;
-
- case 1:
- x += 48;
- break;
- default:
-#endif
- x += step_offsets[face][0] * d;
- y += step_offsets[face][1] * d;
-#if 0
- break;
- }
-#endif
- }
- }
-}
-
-static boolean
-i945_miptree_layout(struct i915_texture * tex)
-{
- struct pipe_texture *pt = &tex->base;
-
- switch (pt->target) {
- case PIPE_TEXTURE_1D:
- case PIPE_TEXTURE_2D:
- i945_miptree_layout_2d(tex);
- break;
- case PIPE_TEXTURE_3D:
- i945_miptree_layout_3d(tex);
- break;
- case PIPE_TEXTURE_CUBE:
- i945_miptree_layout_cube(tex);
- break;
- default:
- assert(0);
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/*
- * Screen texture functions
- */
-
-
-static struct pipe_texture *
-i915_texture_create(struct pipe_screen *screen,
- const struct pipe_texture *templat)
-{
- struct i915_screen *is = i915_screen(screen);
- struct i915_winsys *iws = is->iws;
- struct i915_texture *tex = CALLOC_STRUCT(i915_texture);
- size_t tex_size;
- unsigned buf_usage = 0;
-
- if (!tex)
- return NULL;
-
- tex->base = *templat;
- pipe_reference_init(&tex->base.reference, 1);
- tex->base.screen = screen;
-
- if (is->is_i945) {
- if (!i945_miptree_layout(tex))
- goto fail;
- } else {
- if (!i915_miptree_layout(tex))
- goto fail;
- }
-
- tex_size = tex->stride * tex->total_nblocksy;
-
-
-
- /* for scanouts and cursors, cursors arn't scanouts */
- if (templat->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT && templat->width0 != 64)
- buf_usage = I915_NEW_SCANOUT;
- else
- buf_usage = I915_NEW_TEXTURE;
-
- tex->buffer = iws->buffer_create(iws, tex_size, 64, buf_usage);
- if (!tex->buffer)
- goto fail;
-
- /* setup any hw fences */
- if (tex->hw_tiled) {
- assert(tex->sw_tiled == I915_TILE_NONE);
- iws->buffer_set_fence_reg(iws, tex->buffer, tex->stride, tex->hw_tiled);
- }
-
-
-#if 0
- void *ptr = ws->buffer_map(ws, tex->buffer,
- PIPE_BUFFER_USAGE_CPU_WRITE);
- memset(ptr, 0x80, tex_size);
- ws->buffer_unmap(ws, tex->buffer);
-#endif
-
- return &tex->base;
-
-fail:
- FREE(tex);
- return NULL;
-}
-
-static struct pipe_texture *
-i915_texture_from_handle(struct pipe_screen * screen,
- const struct pipe_texture *templat,
- struct winsys_handle *whandle)
-{
- struct i915_screen *is = i915_screen(screen);
- struct i915_texture *tex;
- struct i915_winsys *iws = is->iws;
- struct i915_winsys_buffer *buffer;
- unsigned stride;
-
- assert(screen);
-
- buffer = iws->buffer_from_handle(iws, whandle, &stride);
-
- /* Only supports one type */
- if (templat->target != PIPE_TEXTURE_2D ||
- templat->last_level != 0 ||
- templat->depth0 != 1) {
- return NULL;
- }
-
- tex = CALLOC_STRUCT(i915_texture);
- if (!tex)
- return NULL;
-
- tex->base = *templat;
- pipe_reference_init(&tex->base.reference, 1);
- tex->base.screen = screen;
-
- tex->stride = stride;
-
- i915_miptree_set_level_info(tex, 0, 1, templat->width0, templat->height0, 1);
- i915_miptree_set_image_offset(tex, 0, 0, 0, 0);
-
- tex->buffer = buffer;
-
- return &tex->base;
-}
-
-static boolean
-i915_texture_get_handle(struct pipe_screen * screen,
- struct pipe_texture *texture,
- struct winsys_handle *whandle)
-{
- struct i915_screen *is = i915_screen(screen);
- struct i915_texture *tex = (struct i915_texture *)texture;
- struct i915_winsys *iws = is->iws;
-
- return iws->buffer_get_handle(iws, tex->buffer, whandle, tex->stride);
-}
-
-
-static void
-i915_texture_destroy(struct pipe_texture *pt)
-{
- struct i915_texture *tex = (struct i915_texture *)pt;
- struct i915_winsys *iws = i915_screen(pt->screen)->iws;
- uint i;
-
- /*
- DBG("%s deleting %p\n", __FUNCTION__, (void *) tex);
- */
-
- iws->buffer_destroy(iws, tex->buffer);
-
- for (i = 0; i < Elements(tex->image_offset); i++)
- if (tex->image_offset[i])
- FREE(tex->image_offset[i]);
-
- FREE(tex);
-}
-
-
-/*
- * Screen surface functions
- */
-
-
-static struct pipe_surface *
-i915_get_tex_surface(struct pipe_screen *screen,
- struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- unsigned flags)
-{
- struct i915_texture *tex = (struct i915_texture *)pt;
- struct pipe_surface *ps;
- unsigned offset; /* in bytes */
-
- if (pt->target == PIPE_TEXTURE_CUBE) {
- offset = tex->image_offset[level][face];
- }
- else if (pt->target == PIPE_TEXTURE_3D) {
- offset = tex->image_offset[level][zslice];
- }
- else {
- offset = tex->image_offset[level][0];
- assert(face == 0);
- assert(zslice == 0);
- }
-
- ps = CALLOC_STRUCT(pipe_surface);
- if (ps) {
- pipe_reference_init(&ps->reference, 1);
- pipe_texture_reference(&ps->texture, pt);
- ps->format = pt->format;
- ps->width = u_minify(pt->width0, level);
- ps->height = u_minify(pt->height0, level);
- ps->offset = offset;
- ps->usage = flags;
- }
- return ps;
-}
-
-static void
-i915_tex_surface_destroy(struct pipe_surface *surf)
-{
- pipe_texture_reference(&surf->texture, NULL);
- FREE(surf);
-}
-
-
-/*
- * Texture transfer functions
- */
-
-
-static struct pipe_transfer *
-i915_get_tex_transfer(struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage, unsigned x, unsigned y,
- unsigned w, unsigned h)
-{
- struct i915_texture *tex = (struct i915_texture *)texture;
- struct i915_transfer *trans;
- unsigned offset; /* in bytes */
-
- if (texture->target == PIPE_TEXTURE_CUBE) {
- offset = tex->image_offset[level][face];
- }
- else if (texture->target == PIPE_TEXTURE_3D) {
- offset = tex->image_offset[level][zslice];
- }
- else {
- offset = tex->image_offset[level][0];
- assert(face == 0);
- assert(zslice == 0);
- }
-
- trans = CALLOC_STRUCT(i915_transfer);
- if (trans) {
- pipe_texture_reference(&trans->base.texture, texture);
- trans->base.x = x;
- trans->base.y = y;
- trans->base.width = w;
- trans->base.height = h;
- trans->base.stride = tex->stride;
- trans->offset = offset;
- trans->base.usage = usage;
- }
- return &trans->base;
-}
-
-static void *
-i915_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct i915_texture *tex = (struct i915_texture *)transfer->texture;
- struct i915_winsys *iws = i915_screen(tex->base.screen)->iws;
- char *map;
- boolean write = FALSE;
- enum pipe_format format = tex->base.format;
-
- if (transfer->usage & PIPE_TRANSFER_WRITE)
- write = TRUE;
-
- map = iws->buffer_map(iws, tex->buffer, write);
- if (map == NULL)
- return NULL;
-
- return map + i915_transfer(transfer)->offset +
- transfer->y / util_format_get_blockheight(format) * transfer->stride +
- transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
-}
-
-static void
-i915_transfer_unmap(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct i915_texture *tex = (struct i915_texture *)transfer->texture;
- struct i915_winsys *iws = i915_screen(tex->base.screen)->iws;
- iws->buffer_unmap(iws, tex->buffer);
-}
-
-static void
-i915_tex_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *trans)
-{
- pipe_texture_reference(&trans->texture, NULL);
- FREE(trans);
-}
-
-
-/*
- * Other texture functions
- */
-
-void
-i915_init_texture_functions(struct i915_context *i915 )
-{
- i915->base.get_tex_transfer = i915_get_tex_transfer;
- i915->base.transfer_map = i915_transfer_map;
- i915->base.transfer_unmap = i915_transfer_unmap;
- i915->base.tex_transfer_destroy = i915_tex_transfer_destroy;
-}
-
-void
-i915_init_screen_texture_functions(struct i915_screen *is)
-{
- is->base.texture_create = i915_texture_create;
- is->base.texture_from_handle = i915_texture_from_handle;
- is->base.texture_get_handle = i915_texture_get_handle;
- is->base.texture_destroy = i915_texture_destroy;
- is->base.get_tex_surface = i915_get_tex_surface;
- is->base.tex_surface_destroy = i915_tex_surface_destroy;
-}
+++ /dev/null
-/**************************************************************************
- *
- * 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_TEXTURE_H
-#define I915_TEXTURE_H
-
-struct i915_screen;
-
-extern void
-i915_init_screen_texture_functions(struct i915_screen *is);
-
-#endif /* I915_TEXTURE_H */
struct i915_winsys;
struct i915_winsys_buffer;
struct i915_winsys_batchbuffer;
-struct pipe_texture;
+struct pipe_resource;
struct pipe_fence_handle;
struct winsys_handle;
/**
* Creates a buffer from a handle.
- * Used to implement pipe_screen::texture_from_handle.
+ * Used to implement pipe_screen::resource_from_handle.
* Also provides the stride information needed for the
* texture via the stride argument.
*/
unsigned *stride);
/**
- * Used to implement pipe_screen::texture_get_handle.
+ * Used to implement pipe_screen::resource_get_handle.
* The winsys might need the stride information.
*/
boolean (*buffer_get_handle)(struct i915_winsys *iws,
brw_pipe_vertex.c \
brw_pipe_clear.c \
brw_pipe_rast.c \
+ brw_resource.c \
brw_sf.c \
brw_sf_emit.c \
brw_sf_state.c \
brw_structs_dump.c \
brw_swtnl.c \
brw_urb.c \
- brw_util.c \
brw_vs.c \
brw_vs_emit.c \
brw_vs_state.c \
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 \
'brw_pipe_sampler.c',
'brw_pipe_shader.c',
'brw_pipe_vertex.c',
- 'brw_screen_buffers.c',
+ 'brw_resource.c',
+ 'brw_resource_buffer.c',
+ 'brw_resource_texture.c',
+ 'brw_resource_texture_layout.c',
'brw_screen.c',
'brw_screen_surface.c',
- 'brw_screen_tex_layout.c',
- 'brw_screen_texture.c',
'brw_structs_dump.c',
'brw_sf.c',
'brw_sf_emit.c',
'brw_state_upload.c',
'brw_swtnl.c',
'brw_urb.c',
- 'brw_util.c',
'brw_vs.c',
'brw_vs_emit.c',
'brw_vs_state.c',
#include "brw_state.h"
#include "brw_batchbuffer.h"
#include "brw_winsys.h"
+#include "brw_resource.h"
#include "brw_screen.h"
brw->sws = brw_screen(screen)->sws;
brw->chipset = brw_screen(screen)->chipset;
- brw_tex_init( brw );
+ brw_init_resource_functions( brw );
brw_pipe_blend_init( brw );
brw_pipe_depth_stencil_init( brw );
brw_pipe_framebuffer_init( brw );
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;
*
* 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:
*/
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;
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]);
}
}
* 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]);
}
}
*/
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)
{
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,
*/
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;
}
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)
/* 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 );
+ PIPE_BIND_VERTEX_BUFFER );
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 );
+ PIPE_BIND_INDEX_BUFFER );
if (brw->vb.upload_index == NULL)
return FALSE;
#include "brw_screen.h"
#include "brw_batchbuffer.h"
#include "brw_debug.h"
+#include "brw_resource.h"
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)
__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)) {
* 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,
/* 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;
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;
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?
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.
*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_texture *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;
}
static struct pipe_sampler_view *
brw_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);
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
- pipe_texture_reference(&view->texture, texture);
+ pipe_resource_reference(&view->texture, texture);
view->context = pipe;
}
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);
}
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;
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 );
}
/* 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 */
--- /dev/null
+#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_texture_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;
+}
--- /dev/null
+/**************************************************************************
+ *
+ * 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 */
--- /dev/null
+
+#include "util/u_memory.h"
+#include "util/u_math.h"
+
+#include "pipe/p_state.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.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_destroy(struct pipe_screen *screen,
+ struct pipe_resource *resource)
+{
+ struct brw_buffer *buf = brw_buffer( resource );
+
+ bo_reference(&buf->bo, NULL);
+ FREE(buf);
+}
+
+
+static void *
+brw_buffer_transfer_map( struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
+{
+ struct brw_screen *bscreen = brw_screen(pipe->screen);
+ struct brw_winsys_screen *sws = bscreen->sws;
+ 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)
+ 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_transfer_flush_region( struct pipe_context *pipe,
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box)
+{
+ struct brw_screen *bscreen = brw_screen(pipe->screen);
+ struct brw_winsys_screen *sws = bscreen->sws;
+ struct brw_buffer *buf = brw_buffer(transfer->resource);
+ unsigned offset = box->x;
+ unsigned length = box->width;
+
+ if (buf->user_buffer)
+ return;
+
+ sws->bo_flush_range( buf->bo,
+ offset,
+ length );
+}
+
+
+static void
+brw_buffer_transfer_unmap( struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
+{
+ struct brw_screen *bscreen = brw_screen(pipe->screen);
+ struct brw_winsys_screen *sws = bscreen->sws;
+ struct brw_buffer *buf = brw_buffer( transfer->resource );
+
+ if (buf->bo)
+ sws->bo_unmap(buf->bo);
+}
+
+
+static unsigned brw_buffer_is_referenced( struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned face,
+ unsigned level)
+{
+ struct brw_context *brw = brw_context(pipe);
+ struct brw_winsys_buffer *batch_bo = brw->batch->buf;
+ struct brw_buffer *buf = brw_buffer(resource);
+
+ if (buf->bo == NULL)
+ return PIPE_UNREFERENCED;
+
+ if (!brw_screen(pipe->screen)->sws->bo_references( batch_bo, buf->bo ))
+ return PIPE_UNREFERENCED;
+
+ return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
+}
+
+
+struct u_resource_vtbl brw_buffer_vtbl =
+{
+ brw_buffer_get_handle, /* get_handle */
+ brw_buffer_destroy, /* resource_destroy */
+ brw_buffer_is_referenced, /* is_resource_referenced */
+ u_default_get_transfer, /* get_transfer */
+ u_default_transfer_destroy, /* transfer_destroy */
+ brw_buffer_transfer_map, /* transfer_map */
+ brw_buffer_transfer_flush_region, /* transfer_flush_region */
+ brw_buffer_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+struct pipe_resource *
+brw_buffer_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ struct brw_screen *bscreen = brw_screen(screen);
+ struct brw_winsys_screen *sws = bscreen->sws;
+ struct brw_buffer *buf;
+ unsigned buffer_type;
+ enum pipe_error ret;
+
+ buf = CALLOC_STRUCT(brw_buffer);
+ if (!buf)
+ return NULL;
+
+ buf->b.b = *template;
+ buf->b.vtbl = &brw_buffer_vtbl;
+ pipe_reference_init(&buf->b.b.reference, 1);
+ buf->b.b.screen = screen;
+
+ switch (template->bind & (PIPE_BIND_VERTEX_BUFFER |
+ PIPE_BIND_INDEX_BUFFER |
+ PIPE_BIND_CONSTANT_BUFFER))
+ {
+ case PIPE_BIND_VERTEX_BUFFER:
+ case PIPE_BIND_INDEX_BUFFER:
+ case (PIPE_BIND_VERTEX_BUFFER|PIPE_BIND_INDEX_BUFFER):
+ buffer_type = BRW_BUFFER_TYPE_VERTEX;
+ break;
+
+ case PIPE_BIND_CONSTANT_BUFFER:
+ buffer_type = BRW_BUFFER_TYPE_SHADER_CONSTANTS;
+ break;
+
+ default:
+ buffer_type = BRW_BUFFER_TYPE_GENERIC;
+ break;
+ }
+
+ ret = sws->bo_alloc( sws, buffer_type,
+ template->width0,
+ 64, /* alignment */
+ &buf->bo );
+ if (ret != PIPE_OK)
+ return NULL;
+
+ return &buf->b.b;
+}
+
+
+struct pipe_resource *
+brw_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind)
+{
+ struct brw_buffer *buf;
+
+ buf = CALLOC_STRUCT(brw_buffer);
+ if (!buf)
+ return NULL;
+
+ pipe_reference_init(&buf->b.b.reference, 1);
+ buf->b.vtbl = &brw_buffer_vtbl;
+ buf->b.b.screen = screen;
+ buf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */
+ buf->b.b._usage = PIPE_USAGE_IMMUTABLE;
+ buf->b.b.bind = bind;
+ buf->b.b.width0 = bytes;
+ buf->b.b.height0 = 1;
+ buf->b.b.depth0 = 1;
+
+ buf->user_buffer = ptr;
+
+ return &buf->b.b;
+}
--- /dev/null
+/*
+ Copyright (C) Intel Corp. 2006. All Rights Reserved.
+ Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ develop this 3D driver.
+
+ 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.
+
+ **********************************************************************/
+ /*
+ * Authors:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "util/u_memory.h"
+#include "util/u_simple_list.h"
+#include "util/u_format.h"
+
+#include "brw_screen.h"
+#include "brw_defines.h"
+#include "brw_structs.h"
+#include "brw_winsys.h"
+#include "brw_batchbuffer.h"
+#include "brw_context.h"
+#include "brw_resource.h"
+
+
+/**
+ * Subclass of pipe_transfer
+ */
+struct brw_transfer
+{
+ struct pipe_transfer base;
+
+ unsigned offset;
+};
+
+static INLINE struct brw_transfer *
+brw_transfer(struct pipe_transfer *transfer)
+{
+ return (struct brw_transfer *)transfer;
+}
+
+
+static GLuint translate_tex_target( unsigned target )
+{
+ switch (target) {
+ case PIPE_TEXTURE_1D:
+ return BRW_SURFACE_1D;
+
+ case PIPE_TEXTURE_2D:
+ return BRW_SURFACE_2D;
+
+ case PIPE_TEXTURE_3D:
+ return BRW_SURFACE_3D;
+
+ case PIPE_TEXTURE_CUBE:
+ return BRW_SURFACE_CUBE;
+
+ default:
+ assert(0);
+ return BRW_SURFACE_1D;
+ }
+}
+
+
+static GLuint translate_tex_format( enum pipe_format pf )
+{
+ switch( pf ) {
+ case PIPE_FORMAT_L8_UNORM:
+ return BRW_SURFACEFORMAT_L8_UNORM;
+
+ case PIPE_FORMAT_I8_UNORM:
+ return BRW_SURFACEFORMAT_I8_UNORM;
+
+ case PIPE_FORMAT_A8_UNORM:
+ return BRW_SURFACEFORMAT_A8_UNORM;
+
+ case PIPE_FORMAT_L16_UNORM:
+ return BRW_SURFACEFORMAT_L16_UNORM;
+
+ /* XXX: Add these to gallium
+ case PIPE_FORMAT_I16_UNORM:
+ return BRW_SURFACEFORMAT_I16_UNORM;
+
+ case PIPE_FORMAT_A16_UNORM:
+ return BRW_SURFACEFORMAT_A16_UNORM;
+ */
+
+ case PIPE_FORMAT_L8A8_UNORM:
+ return BRW_SURFACEFORMAT_L8A8_UNORM;
+
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ return BRW_SURFACEFORMAT_B5G6R5_UNORM;
+
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ return BRW_SURFACEFORMAT_B5G5R5A1_UNORM;
+
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ return BRW_SURFACEFORMAT_B4G4R4A4_UNORM;
+
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ return BRW_SURFACEFORMAT_R8G8B8X8_UNORM;
+
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ return BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
+
+ /*
+ * Video formats
+ */
+
+ case PIPE_FORMAT_YUYV:
+ return BRW_SURFACEFORMAT_YCRCB_NORMAL;
+
+ case PIPE_FORMAT_UYVY:
+ return BRW_SURFACEFORMAT_YCRCB_SWAPUVY;
+
+ /*
+ * Compressed formats.
+ */
+ /* XXX: Add FXT to gallium?
+ case PIPE_FORMAT_FXT1_RGBA:
+ return BRW_SURFACEFORMAT_FXT1;
+ */
+
+ case PIPE_FORMAT_DXT1_RGB:
+ return BRW_SURFACEFORMAT_DXT1_RGB;
+
+ case PIPE_FORMAT_DXT1_RGBA:
+ return BRW_SURFACEFORMAT_BC1_UNORM;
+
+ case PIPE_FORMAT_DXT3_RGBA:
+ return BRW_SURFACEFORMAT_BC2_UNORM;
+
+ case PIPE_FORMAT_DXT5_RGBA:
+ return BRW_SURFACEFORMAT_BC3_UNORM;
+
+ /*
+ * sRGB formats
+ */
+
+ case PIPE_FORMAT_A8B8G8R8_SRGB:
+ return BRW_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB;
+
+ case PIPE_FORMAT_L8A8_SRGB:
+ return BRW_SURFACEFORMAT_L8A8_UNORM_SRGB;
+
+ case PIPE_FORMAT_L8_SRGB:
+ return BRW_SURFACEFORMAT_L8_UNORM_SRGB;
+
+ case PIPE_FORMAT_DXT1_SRGB:
+ return BRW_SURFACEFORMAT_BC1_UNORM_SRGB;
+
+ /*
+ * Depth formats
+ */
+
+ case PIPE_FORMAT_Z16_UNORM:
+ return BRW_SURFACEFORMAT_I16_UNORM;
+
+ case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
+ case PIPE_FORMAT_Z24X8_UNORM:
+ return BRW_SURFACEFORMAT_I24X8_UNORM;
+
+ case PIPE_FORMAT_Z32_FLOAT:
+ return BRW_SURFACEFORMAT_I32_FLOAT;
+
+ /* XXX: presumably for bump mapping. Add this to mesa state
+ * tracker?
+ *
+ * XXX: Add flipped versions of these formats to Gallium.
+ */
+ case PIPE_FORMAT_R8G8_SNORM:
+ return BRW_SURFACEFORMAT_R8G8_SNORM;
+
+ case PIPE_FORMAT_R8G8B8A8_SNORM:
+ return BRW_SURFACEFORMAT_R8G8B8A8_SNORM;
+
+ default:
+ return BRW_SURFACEFORMAT_INVALID;
+ }
+}
+
+
+static boolean
+brw_texture_get_handle(struct pipe_screen *screen,
+ struct pipe_resource *texture,
+ struct winsys_handle *whandle)
+{
+ struct brw_screen *bscreen = brw_screen(screen);
+ struct brw_texture *tex = brw_texture(texture);
+ unsigned stride;
+
+ stride = tex->pitch * tex->cpp;
+
+ return bscreen->sws->bo_get_handle(tex->bo, whandle, stride);
+}
+
+
+
+static void brw_texture_destroy(struct pipe_screen *screen,
+ struct pipe_resource *pt)
+{
+ struct brw_texture *tex = brw_texture(pt);
+ bo_reference(&tex->bo, NULL);
+ FREE(pt);
+}
+
+
+
+
+static unsigned brw_texture_is_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(pipe->screen);
+ struct brw_winsys_buffer *batch_bo = brw->batch->buf;
+ struct brw_texture *tex = brw_texture(texture);
+ struct brw_surface *surf;
+ int i;
+
+ /* XXX: this is subject to false positives if the underlying
+ * texture BO is referenced, we can't tell whether the sub-region
+ * we care about participates in that.
+ */
+ if (bscreen->sws->bo_references( batch_bo, tex->bo ))
+ return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
+
+ /* Find any view on this texture for this face/level and see if it
+ * is referenced:
+ */
+ for (i = 0; i < 2; i++) {
+ foreach (surf, &tex->views[i]) {
+ if (surf->bo == tex->bo)
+ continue;
+
+ if (surf->id.bits.face != face ||
+ surf->id.bits.level != level)
+ continue;
+
+ if (bscreen->sws->bo_references( batch_bo, surf->bo))
+ return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
+ }
+ }
+
+ return PIPE_UNREFERENCED;
+}
+
+
+/*
+ * Transfer functions
+ */
+
+
+static struct pipe_transfer *
+brw_texture_get_transfer(struct pipe_context *context,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
+{
+ struct brw_texture *tex = brw_texture(resource);
+ 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;
+ transfer->stride = tex->pitch * tex->cpp;
+
+ return transfer;
+}
+
+
+static void *
+brw_texture_transfer_map(struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
+{
+ struct pipe_resource *resource = transfer->resource;
+ struct brw_texture *tex = brw_texture(transfer->resource);
+ struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws;
+ struct pipe_subresource sr = transfer->sr;
+ struct pipe_box *box = &transfer->box;
+ enum pipe_format format = resource->format;
+ unsigned usage = transfer->usage;
+ unsigned offset;
+ char *map;
+
+ if (resource->target == PIPE_TEXTURE_CUBE) {
+ offset = tex->image_offset[sr.level][sr.face];
+ }
+ else if (resource->target == PIPE_TEXTURE_3D) {
+ offset = tex->image_offset[sr.level][box->z];
+ }
+ else {
+ offset = tex->image_offset[sr.level][0];
+ assert(sr.face == 0);
+ assert(box->z == 0);
+ }
+
+ map = sws->bo_map(tex->bo,
+ BRW_DATA_OTHER,
+ 0,
+ tex->bo->size,
+ (usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE,
+ (usage & 0) ? TRUE : FALSE,
+ (usage & 0) ? TRUE : FALSE);
+
+ if (!map)
+ return NULL;
+
+ return map + offset +
+ box->y / util_format_get_blockheight(format) * transfer->stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+}
+
+static void
+brw_texture_transfer_unmap(struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
+{
+ struct brw_texture *tex = brw_texture(transfer->resource);
+ struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws;
+
+ sws->bo_unmap(tex->bo);
+}
+
+
+
+
+
+struct u_resource_vtbl brw_texture_vtbl =
+{
+ brw_texture_get_handle, /* get_handle */
+ brw_texture_destroy, /* resource_destroy */
+ brw_texture_is_referenced, /* is_resource_referenced */
+ brw_texture_get_transfer, /* get_transfer */
+ u_default_transfer_destroy, /* transfer_destroy */
+ brw_texture_transfer_map, /* transfer_map */
+ u_default_transfer_flush_region, /* transfer_flush_region */
+ brw_texture_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+
+
+struct pipe_resource *
+brw_texture_create( struct pipe_screen *screen,
+ const struct pipe_resource *template )
+{
+ struct brw_screen *bscreen = brw_screen(screen);
+ struct brw_texture *tex;
+ enum brw_buffer_type buffer_type;
+ enum pipe_error ret;
+ GLuint format;
+
+ tex = CALLOC_STRUCT(brw_texture);
+ if (tex == NULL)
+ return NULL;
+
+ tex->b.b = *template;
+ tex->b.vtbl = &brw_texture_vtbl;
+ pipe_reference_init(&tex->b.b.reference, 1);
+ tex->b.b.screen = screen;
+
+ /* XXX: compressed textures need special treatment here
+ */
+ tex->cpp = util_format_get_blocksize(tex->b.b.format);
+ tex->compressed = util_format_is_s3tc(tex->b.b.format);
+
+ make_empty_list(&tex->views[0]);
+ make_empty_list(&tex->views[1]);
+
+ /* XXX: No tiling with compressed textures??
+ */
+ if (tex->compressed == 0 &&
+ !bscreen->no_tiling)
+ {
+ if (bscreen->chipset.is_965 &&
+ util_format_is_depth_or_stencil(template->format))
+ tex->tiling = BRW_TILING_Y;
+ else
+ tex->tiling = BRW_TILING_X;
+ }
+ else {
+ tex->tiling = BRW_TILING_NONE;
+ }
+
+
+ if (!brw_texture_layout( bscreen, tex ))
+ goto fail;
+
+
+ if (template->bind & (PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED)) {
+ buffer_type = BRW_BUFFER_TYPE_SCANOUT;
+ }
+ else {
+ buffer_type = BRW_BUFFER_TYPE_TEXTURE;
+ }
+
+ ret = bscreen->sws->bo_alloc( bscreen->sws,
+ buffer_type,
+ tex->pitch * tex->total_height * tex->cpp,
+ 64,
+ &tex->bo );
+ if (ret)
+ goto fail;
+
+ tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW;
+ tex->ss.ss0.surface_type = translate_tex_target(tex->b.b.target);
+
+ format = translate_tex_format(tex->b.b.format);
+ assert(format != BRW_SURFACEFORMAT_INVALID);
+ tex->ss.ss0.surface_format = format;
+
+ /* This is ok for all textures with channel width 8bit or less:
+ */
+/* tex->ss.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */
+
+
+ /* XXX: what happens when tex->bo->offset changes???
+ */
+ tex->ss.ss1.base_addr = 0; /* reloc */
+ tex->ss.ss2.mip_count = tex->b.b.last_level;
+ tex->ss.ss2.width = tex->b.b.width0 - 1;
+ tex->ss.ss2.height = tex->b.b.height0 - 1;
+
+ switch (tex->tiling) {
+ case BRW_TILING_NONE:
+ tex->ss.ss3.tiled_surface = 0;
+ tex->ss.ss3.tile_walk = 0;
+ break;
+ case BRW_TILING_X:
+ tex->ss.ss3.tiled_surface = 1;
+ tex->ss.ss3.tile_walk = BRW_TILEWALK_XMAJOR;
+ break;
+ case BRW_TILING_Y:
+ tex->ss.ss3.tiled_surface = 1;
+ tex->ss.ss3.tile_walk = BRW_TILEWALK_YMAJOR;
+ break;
+ }
+
+ tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1;
+ tex->ss.ss3.depth = tex->b.b.depth0 - 1;
+
+ tex->ss.ss4.min_lod = 0;
+
+ if (tex->b.b.target == PIPE_TEXTURE_CUBE) {
+ tex->ss.ss0.cube_pos_x = 1;
+ tex->ss.ss0.cube_pos_y = 1;
+ tex->ss.ss0.cube_pos_z = 1;
+ tex->ss.ss0.cube_neg_x = 1;
+ tex->ss.ss0.cube_neg_y = 1;
+ tex->ss.ss0.cube_neg_z = 1;
+ }
+
+ return &tex->b.b;
+
+fail:
+ bo_reference(&tex->bo, NULL);
+ FREE(tex);
+ return NULL;
+}
+
+
+struct pipe_resource *
+brw_texture_from_handle(struct pipe_screen *screen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle)
+{
+ struct brw_screen *bscreen = brw_screen(screen);
+ struct brw_texture *tex;
+ struct brw_winsys_buffer *buffer;
+ unsigned tiling;
+ unsigned pitch;
+ GLuint format;
+
+ if (template->target != PIPE_TEXTURE_2D ||
+ template->last_level != 0 ||
+ template->depth0 != 1)
+ return NULL;
+
+ if (util_format_is_s3tc(template->format))
+ return NULL;
+
+ tex = CALLOC_STRUCT(brw_texture);
+ if (!tex)
+ return NULL;
+
+ if (bscreen->sws->bo_from_handle(bscreen->sws, whandle, &pitch, &tiling, &buffer) != PIPE_OK)
+ goto fail;
+
+ tex->b.b = *template;
+ tex->b.vtbl = &brw_texture_vtbl;
+ pipe_reference_init(&tex->b.b.reference, 1);
+ tex->b.b.screen = screen;
+
+ /* XXX: cpp vs. blocksize
+ */
+ tex->cpp = util_format_get_blocksize(tex->b.b.format);
+ tex->tiling = tiling;
+
+ make_empty_list(&tex->views[0]);
+ make_empty_list(&tex->views[1]);
+
+ if (!brw_texture_layout(bscreen, tex))
+ goto fail;
+
+ /* XXX Maybe some more checks? */
+ if ((pitch / tex->cpp) < tex->pitch)
+ goto fail;
+
+ tex->pitch = pitch / tex->cpp;
+
+ tex->bo = buffer;
+
+ /* fix this warning */
+#if 0
+ if (tex->size > buffer->size)
+ goto fail;
+#endif
+
+ tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW;
+ tex->ss.ss0.surface_type = translate_tex_target(tex->b.b.target);
+
+ format = translate_tex_format(tex->b.b.format);
+ assert(format != BRW_SURFACEFORMAT_INVALID);
+ tex->ss.ss0.surface_format = format;
+ assert(tex->ss.ss0.surface_format != BRW_SURFACEFORMAT_INVALID);
+
+ /* This is ok for all textures with channel width 8bit or less:
+ */
+/* tex->ss.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */
+
+
+ /* XXX: what happens when tex->bo->offset changes???
+ */
+ tex->ss.ss1.base_addr = 0; /* reloc */
+ tex->ss.ss2.mip_count = tex->b.b.last_level;
+ tex->ss.ss2.width = tex->b.b.width0 - 1;
+ tex->ss.ss2.height = tex->b.b.height0 - 1;
+
+ switch (tex->tiling) {
+ case BRW_TILING_NONE:
+ tex->ss.ss3.tiled_surface = 0;
+ tex->ss.ss3.tile_walk = 0;
+ break;
+ case BRW_TILING_X:
+ tex->ss.ss3.tiled_surface = 1;
+ tex->ss.ss3.tile_walk = BRW_TILEWALK_XMAJOR;
+ break;
+ case BRW_TILING_Y:
+ tex->ss.ss3.tiled_surface = 1;
+ tex->ss.ss3.tile_walk = BRW_TILEWALK_YMAJOR;
+ break;
+ }
+
+ tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1;
+ tex->ss.ss3.depth = tex->b.b.depth0 - 1;
+
+ tex->ss.ss4.min_lod = 0;
+
+ return &tex->b.b;
+
+fail:
+ FREE(tex);
+ return NULL;
+}
+
+
+#if 0
+boolean brw_is_format_supported( struct pipe_screen *screen,
+ enum pipe_format format,
+ enum pipe_texture_target target,
+ unsigned tex_usage,
+ unsigned geom_flags )
+{
+ return translate_tex_format(format) != BRW_SURFACEFORMAT_INVALID;
+}
+#endif
--- /dev/null
+/*
+ Copyright (C) Intel Corp. 2006. All Rights Reserved.
+ Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ develop this 3D driver.
+
+ 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 "pipe/p_format.h"
+
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+#include "brw_resource.h"
+#include "brw_debug.h"
+#include "brw_winsys.h"
+
+/* Code to layout images in a mipmap tree for i965.
+ */
+
+static int
+brw_tex_pitch_align (struct brw_texture *tex,
+ int pitch)
+{
+ if (!tex->compressed) {
+ int pitch_align;
+
+ switch (tex->tiling) {
+ case BRW_TILING_X:
+ pitch_align = 512;
+ break;
+ case BRW_TILING_Y:
+ pitch_align = 128;
+ break;
+ default:
+ /* XXX: Untiled pitch alignment of 64 bytes for now to allow
+ * render-to-texture to work in all cases. This should
+ * probably be replaced at some point by some scheme to only
+ * do this when really necessary, for example standalone
+ * render target views.
+ */
+ pitch_align = 64;
+ break;
+ }
+
+ pitch = align(pitch * tex->cpp, pitch_align);
+ pitch /= tex->cpp;
+ }
+
+ return pitch;
+}
+
+
+static void
+brw_tex_alignment_unit(enum pipe_format pf,
+ GLuint *w, GLuint *h)
+{
+ switch (pf) {
+ case PIPE_FORMAT_DXT1_RGB:
+ case PIPE_FORMAT_DXT1_RGBA:
+ case PIPE_FORMAT_DXT3_RGBA:
+ case PIPE_FORMAT_DXT5_RGBA:
+ case PIPE_FORMAT_DXT1_SRGB:
+ case PIPE_FORMAT_DXT1_SRGBA:
+ case PIPE_FORMAT_DXT3_SRGBA:
+ case PIPE_FORMAT_DXT5_SRGBA:
+ *w = 4;
+ *h = 4;
+ break;
+
+ default:
+ *w = 4;
+ *h = 2;
+ break;
+ }
+}
+
+
+static void
+brw_tex_set_level_info(struct brw_texture *tex,
+ GLuint level,
+ GLuint nr_images,
+ GLuint x, GLuint y,
+ GLuint w, GLuint h, GLuint d)
+{
+
+ if (BRW_DEBUG & DEBUG_TEXTURE)
+ debug_printf("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
+ level, w, h, d, x, y, tex->level_offset[level]);
+
+ assert(tex->image_offset[level] == NULL);
+ assert(nr_images >= 1);
+
+ tex->level_offset[level] = (x + y * tex->pitch) * tex->cpp;
+ tex->nr_images[level] = nr_images;
+
+ tex->image_offset[level] = MALLOC(nr_images * sizeof(GLuint));
+ tex->image_offset[level][0] = 0;
+}
+
+
+static void
+brw_tex_set_image_offset(struct brw_texture *tex,
+ GLuint level, GLuint img,
+ GLuint x, GLuint y,
+ GLuint offset)
+{
+ assert((x == 0 && y == 0) || img != 0 || level != 0);
+ assert(img < tex->nr_images[level]);
+
+ if (BRW_DEBUG & DEBUG_TEXTURE)
+ debug_printf("%s level %d img %d pos %d,%d image_offset %x\n",
+ __FUNCTION__, level, img, x, y,
+ tex->image_offset[level][img]);
+
+ tex->image_offset[level][img] = (x + y * tex->pitch) * tex->cpp + offset;
+}
+
+
+
+static void brw_layout_2d( struct brw_texture *tex )
+{
+ GLuint align_h = 2, align_w = 4;
+ GLuint level;
+ GLuint x = 0;
+ GLuint y = 0;
+ GLuint width = tex->b.b.width0;
+ GLuint height = tex->b.b.height0;
+
+ tex->pitch = tex->b.b.width0;
+ brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h);
+
+ if (tex->compressed) {
+ tex->pitch = align(tex->b.b.width0, align_w);
+ }
+
+ /* May need to adjust pitch to accomodate the placement of
+ * the 2nd mipmap. This occurs when the alignment
+ * constraints of mipmap placement push the right edge of the
+ * 2nd mipmap out past the width of its parent.
+ */
+ if (tex->b.b.last_level > 0) {
+ GLuint mip1_width;
+
+ if (tex->compressed) {
+ mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) +
+ align(u_minify(tex->b.b.width0, 2), align_w));
+ } else {
+ mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) +
+ u_minify(tex->b.b.width0, 2));
+ }
+
+ if (mip1_width > tex->pitch) {
+ tex->pitch = mip1_width;
+ }
+ }
+
+ /* Pitch must be a whole number of dwords, even though we
+ * express it in texels.
+ */
+ tex->pitch = brw_tex_pitch_align (tex, tex->pitch);
+ tex->total_height = 0;
+
+ for ( level = 0 ; level <= tex->b.b.last_level ; level++ ) {
+ GLuint img_height;
+
+ brw_tex_set_level_info(tex, level, 1, x, y, width, height, 1);
+
+ if (tex->compressed)
+ img_height = MAX2(1, height/4);
+ else
+ img_height = align(height, align_h);
+
+
+ /* Because the images are packed better, the final offset
+ * might not be the maximal one:
+ */
+ tex->total_height = MAX2(tex->total_height, y + img_height);
+
+ /* Layout_below: step right after second mipmap.
+ */
+ if (level == 1) {
+ x += align(width, align_w);
+ }
+ else {
+ y += img_height;
+ }
+
+ width = u_minify(width, 1);
+ height = u_minify(height, 1);
+ }
+}
+
+
+static boolean
+brw_layout_cubemap_idgng( struct brw_texture *tex )
+{
+ GLuint align_h = 2, align_w = 4;
+ GLuint level;
+ GLuint x = 0;
+ GLuint y = 0;
+ GLuint width = tex->b.b.width0;
+ GLuint height = tex->b.b.height0;
+ GLuint qpitch = 0;
+ GLuint y_pitch = 0;
+
+ tex->pitch = tex->b.b.width0;
+ brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h);
+ y_pitch = align(height, align_h);
+
+ if (tex->compressed) {
+ tex->pitch = align(tex->b.b.width0, align_w);
+ }
+
+ if (tex->b.b.last_level != 0) {
+ GLuint mip1_width;
+
+ if (tex->compressed) {
+ mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) +
+ align(u_minify(tex->b.b.width0, 2), align_w));
+ } else {
+ mip1_width = (align(u_minify(tex->b.b.width0, 1), align_w) +
+ u_minify(tex->b.b.width0, 2));
+ }
+
+ if (mip1_width > tex->pitch) {
+ tex->pitch = mip1_width;
+ }
+ }
+
+ tex->pitch = brw_tex_pitch_align(tex, tex->pitch);
+
+ if (tex->compressed) {
+ qpitch = ((y_pitch +
+ align(u_minify(y_pitch, 1), align_h) +
+ 11 * align_h) / 4) * tex->pitch * tex->cpp;
+
+ tex->total_height = ((y_pitch +
+ align(u_minify(y_pitch, 1), align_h) +
+ 11 * align_h) / 4) * 6;
+ } else {
+ qpitch = (y_pitch +
+ align(u_minify(y_pitch, 1), align_h) +
+ 11 * align_h) * tex->pitch * tex->cpp;
+
+ tex->total_height = (y_pitch +
+ align(u_minify(y_pitch, 1), align_h) +
+ 11 * align_h) * 6;
+ }
+
+ for (level = 0; level <= tex->b.b.last_level; level++) {
+ GLuint img_height;
+ GLuint nr_images = 6;
+ GLuint q = 0;
+
+ brw_tex_set_level_info(tex, level, nr_images, x, y, width, height, 1);
+
+ for (q = 0; q < nr_images; q++)
+ brw_tex_set_image_offset(tex, level, q, x, y, q * qpitch);
+
+ if (tex->compressed)
+ img_height = MAX2(1, height/4);
+ else
+ img_height = align(height, align_h);
+
+ if (level == 1) {
+ x += align(width, align_w);
+ }
+ else {
+ y += img_height;
+ }
+
+ width = u_minify(width, 1);
+ height = u_minify(height, 1);
+ }
+
+ return TRUE;
+}
+
+
+static boolean
+brw_layout_3d_cube( struct brw_texture *tex )
+{
+ GLuint width = tex->b.b.width0;
+ GLuint height = tex->b.b.height0;
+ GLuint depth = tex->b.b.depth0;
+ GLuint pack_x_pitch, pack_x_nr;
+ GLuint pack_y_pitch;
+ GLuint level;
+ GLuint align_h = 2;
+ GLuint align_w = 4;
+
+ tex->total_height = 0;
+ brw_tex_alignment_unit(tex->b.b.format, &align_w, &align_h);
+
+ if (tex->compressed) {
+ tex->pitch = align(width, align_w);
+ pack_y_pitch = (height + 3) / 4;
+ } else {
+ tex->pitch = brw_tex_pitch_align(tex, tex->b.b.width0);
+ pack_y_pitch = align(tex->b.b.height0, align_h);
+ }
+
+ pack_x_pitch = width;
+ pack_x_nr = 1;
+
+ for (level = 0 ; level <= tex->b.b.last_level ; level++) {
+ GLuint nr_images = tex->b.b.target == PIPE_TEXTURE_3D ? depth : 6;
+ GLint x = 0;
+ GLint y = 0;
+ GLint q, j;
+
+ brw_tex_set_level_info(tex, level, nr_images,
+ 0, tex->total_height,
+ width, height, depth);
+
+ for (q = 0; q < nr_images;) {
+ for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) {
+ brw_tex_set_image_offset(tex, level, q, x, y, 0);
+ x += pack_x_pitch;
+ }
+
+ x = 0;
+ y += pack_y_pitch;
+ }
+
+
+ tex->total_height += y;
+ width = u_minify(width, 1);
+ height = u_minify(height, 1);
+ depth = u_minify(depth, 1);
+
+ if (tex->compressed) {
+ pack_y_pitch = (height + 3) / 4;
+
+ if (pack_x_pitch > align(width, align_w)) {
+ pack_x_pitch = align(width, align_w);
+ pack_x_nr <<= 1;
+ }
+ } else {
+ if (pack_x_pitch > 4) {
+ pack_x_pitch >>= 1;
+ pack_x_nr <<= 1;
+ assert(pack_x_pitch * pack_x_nr <= tex->pitch);
+ }
+
+ if (pack_y_pitch > 2) {
+ pack_y_pitch >>= 1;
+ pack_y_pitch = align(pack_y_pitch, align_h);
+ }
+ }
+ }
+
+ /* The 965's sampler lays cachelines out according to how accesses
+ * in the texture surfaces run, so they may be "vertical" through
+ * memory. As a result, the docs say in Surface Padding Requirements:
+ * Sampling Engine Surfaces that two extra rows of padding are required.
+ */
+ if (tex->b.b.target == PIPE_TEXTURE_CUBE)
+ tex->total_height += 2;
+
+ return TRUE;
+}
+
+
+
+GLboolean brw_texture_layout(struct brw_screen *brw_screen,
+ struct brw_texture *tex )
+{
+ switch (tex->b.b.target) {
+ case PIPE_TEXTURE_CUBE:
+ if (brw_screen->chipset.is_igdng)
+ brw_layout_cubemap_idgng( tex );
+ else
+ brw_layout_3d_cube( tex );
+ break;
+
+ case PIPE_TEXTURE_3D:
+ brw_layout_3d_cube( tex );
+ break;
+
+ default:
+ brw_layout_2d( tex );
+ break;
+ }
+
+ if (BRW_DEBUG & DEBUG_TEXTURE)
+ debug_printf("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
+ tex->pitch,
+ tex->total_height,
+ tex->cpp,
+ tex->pitch * tex->total_height * tex->cpp );
+
+ return GL_TRUE;
+}
#include "brw_screen.h"
#include "brw_winsys.h"
#include "brw_debug.h"
+#include "brw_resource.h"
#ifdef DEBUG
static const struct debug_named_value debug_names[] = {
const enum pipe_format *list;
uint i;
- if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL)
+ if (tex_usage & PIPE_BIND_DEPTH_STENCIL)
list = depth_supported;
- else if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
+ else if (tex_usage & PIPE_BIND_RENDER_TARGET)
list = render_supported;
else
list = tex_supported;
bscreen->base.fence_signalled = brw_fence_signalled;
bscreen->base.fence_finish = brw_fence_finish;
- brw_screen_tex_init(bscreen);
+ brw_init_screen_resource_functions(bscreen);
brw_screen_tex_surface_init(bscreen);
- brw_screen_buffer_init(bscreen);
bscreen->no_tiling = debug_get_option("BRW_NO_TILING", FALSE) != NULL;
boolean no_tiling;
};
-/**
- * Subclass of pipe_transfer
- */
-struct brw_transfer
-{
- struct pipe_transfer base;
-
- unsigned offset;
-};
-
-struct brw_buffer
-{
- struct pipe_buffer base;
-
- /* 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;
-};
union brw_surface_id {
};
-#define BRW_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */
-#define BRW_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */
-
-
-struct brw_texture
-{
- struct pipe_texture base;
- 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];
-};
-
-
/*
* Cast wrappers
return (struct brw_screen *) pscreen;
}
-static INLINE struct brw_transfer *
-brw_transfer(struct pipe_transfer *transfer)
-{
- return (struct brw_transfer *)transfer;
-}
static INLINE struct brw_surface *
brw_surface(struct pipe_surface *surface)
return (struct brw_surface *)surface;
}
-static INLINE struct brw_buffer *
-brw_buffer(struct pipe_buffer *buffer)
-{
- return (struct brw_buffer *)buffer;
-}
-
-static INLINE struct brw_texture *
-brw_texture(struct pipe_texture *texture)
-{
- return (struct brw_texture *)texture;
-}
-
-
-/* Pipe buffer helpers
- */
-static INLINE boolean
-brw_buffer_is_user_buffer( const struct pipe_buffer *buf )
-{
- return ((const struct brw_buffer *)buf)->user_buffer != NULL;
-}
-
unsigned
brw_surface_pitch( const struct pipe_surface *surface );
-/***********************************************************************
- * 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 );
-
-
-/* brw_screen_texture.h
- */
-struct brw_context;
-void brw_tex_init( struct brw_context *brw );
-void brw_screen_tex_init( struct brw_screen *brw_screen );
void brw_screen_tex_surface_init( struct brw_screen *brw_screen );
-void brw_screen_buffer_init(struct brw_screen *brw_screen);
-
-
-boolean brw_is_texture_referenced_by_bo( struct brw_screen *brw_screen,
- struct pipe_texture *texture,
- unsigned face,
- unsigned level,
- struct brw_winsys_buffer *bo );
-
-boolean brw_is_buffer_referenced_by_bo( struct brw_screen *brw_screen,
- struct pipe_buffer *buffer,
- struct brw_winsys_buffer *bo );
-
-
#endif /* BRW_SCREEN_H */
+++ /dev/null
-
-#include "util/u_memory.h"
-#include "util/u_math.h"
-
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-
-#include "brw_screen.h"
-#include "brw_winsys.h"
-
-
-
-static void *
-brw_buffer_map_range( struct pipe_screen *screen,
- struct pipe_buffer *buffer,
- unsigned offset,
- unsigned length,
- unsigned usage )
-{
- struct brw_screen *bscreen = brw_screen(screen);
- struct brw_winsys_screen *sws = bscreen->sws;
- struct brw_buffer *buf = brw_buffer( buffer );
-
- 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);
-}
-
-static void *
-brw_buffer_map( struct pipe_screen *screen,
- struct pipe_buffer *buffer,
- unsigned usage )
-{
- struct brw_screen *bscreen = brw_screen(screen);
- struct brw_winsys_screen *sws = bscreen->sws;
- struct brw_buffer *buf = brw_buffer( buffer );
-
- 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);
-}
-
-
-static void
-brw_buffer_flush_mapped_range( struct pipe_screen *screen,
- struct pipe_buffer *buffer,
- unsigned offset,
- unsigned length )
-{
- struct brw_screen *bscreen = brw_screen(screen);
- struct brw_winsys_screen *sws = bscreen->sws;
- struct brw_buffer *buf = brw_buffer( buffer );
-
- if (buf->user_buffer)
- return;
-
- sws->bo_flush_range( buf->bo,
- offset,
- length );
-}
-
-
-static void
-brw_buffer_unmap( struct pipe_screen *screen,
- struct pipe_buffer *buffer )
-{
- struct brw_screen *bscreen = brw_screen(screen);
- struct brw_winsys_screen *sws = bscreen->sws;
- struct brw_buffer *buf = brw_buffer( buffer );
-
- if (buf->bo)
- sws->bo_unmap(buf->bo);
-}
-
-static void
-brw_buffer_destroy( struct pipe_buffer *buffer )
-{
- struct brw_buffer *buf = brw_buffer( buffer );
-
- assert(!p_atomic_read(&buffer->reference.count));
-
- bo_reference(&buf->bo, NULL);
- FREE(buf);
-}
-
-
-static struct pipe_buffer *
-brw_buffer_create(struct pipe_screen *screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct brw_screen *bscreen = brw_screen(screen);
- struct brw_winsys_screen *sws = bscreen->sws;
- struct brw_buffer *buf;
- unsigned buffer_type;
- enum pipe_error ret;
-
- buf = CALLOC_STRUCT(brw_buffer);
- if (!buf)
- return NULL;
-
- pipe_reference_init(&buf->base.reference, 1);
- buf->base.screen = screen;
- buf->base.alignment = alignment;
- buf->base.usage = usage;
- buf->base.size = size;
-
- switch (usage & (PIPE_BUFFER_USAGE_VERTEX |
- PIPE_BUFFER_USAGE_INDEX |
- PIPE_BUFFER_USAGE_PIXEL |
- PIPE_BUFFER_USAGE_CONSTANT))
- {
- case PIPE_BUFFER_USAGE_VERTEX:
- case PIPE_BUFFER_USAGE_INDEX:
- case (PIPE_BUFFER_USAGE_VERTEX|PIPE_BUFFER_USAGE_INDEX):
- buffer_type = BRW_BUFFER_TYPE_VERTEX;
- break;
-
- case PIPE_BUFFER_USAGE_PIXEL:
- buffer_type = BRW_BUFFER_TYPE_PIXEL;
- break;
-
- case PIPE_BUFFER_USAGE_CONSTANT:
- buffer_type = BRW_BUFFER_TYPE_SHADER_CONSTANTS;
- break;
-
- default:
- buffer_type = BRW_BUFFER_TYPE_GENERIC;
- break;
- }
-
- ret = sws->bo_alloc( sws, buffer_type,
- size, alignment,
- &buf->bo );
- if (ret != PIPE_OK)
- return NULL;
-
- return &buf->base;
-}
-
-
-static struct pipe_buffer *
-brw_user_buffer_create(struct pipe_screen *screen,
- void *ptr,
- unsigned bytes)
-{
- struct brw_buffer *buf;
-
- buf = CALLOC_STRUCT(brw_buffer);
- if (!buf)
- return NULL;
-
- buf->user_buffer = ptr;
-
- pipe_reference_init(&buf->base.reference, 1);
- buf->base.screen = screen;
- buf->base.alignment = 1;
- buf->base.usage = 0;
- buf->base.size = bytes;
-
- return &buf->base;
-}
-
-
-boolean brw_is_buffer_referenced_by_bo( struct brw_screen *brw_screen,
- struct pipe_buffer *buffer,
- struct brw_winsys_buffer *bo )
-{
- struct brw_buffer *buf = brw_buffer(buffer);
- if (buf->bo == NULL)
- return FALSE;
-
- return brw_screen->sws->bo_references( bo, buf->bo );
-}
-
-
-void brw_screen_buffer_init(struct brw_screen *brw_screen)
-{
- brw_screen->base.buffer_create = brw_buffer_create;
- brw_screen->base.user_buffer_create = brw_user_buffer_create;
- brw_screen->base.buffer_map = brw_buffer_map;
- brw_screen->base.buffer_map_range = brw_buffer_map_range;
- brw_screen->base.buffer_flush_mapped_range = brw_buffer_flush_mapped_range;
- brw_screen->base.buffer_unmap = brw_buffer_unmap;
- brw_screen->base.buffer_destroy = brw_buffer_destroy;
-}
#include "pipe/p_screen.h"
#include "brw_screen.h"
#include "brw_defines.h"
+#include "brw_resource.h"
#include "brw_winsys.h"
enum {
*/
assert(id.bits.zslice == 0);
- surface->base.format = tex->base.format;
- surface->base.width = u_minify(tex->base.width0, id.bits.level);
- surface->base.height = u_minify(tex->base.height0, id.bits.level);
+ surface->base.format = tex->b.b.format;
+ surface->base.width = u_minify(tex->b.b.width0, id.bits.level);
+ surface->base.height = u_minify(tex->b.b.height0, id.bits.level);
surface->base.offset = tex->image_offset[id.bits.level][id.bits.face];
surface->base.usage = usage;
surface->base.zslice = id.bits.zslice;
surface->tiling = tex->tiling;
bo_reference( &surface->bo, tex->bo );
- pipe_texture_reference( &surface->base.texture, &tex->base );
+ pipe_resource_reference( &surface->base.texture, &tex->b.b );
surface->ss.ss0.surface_format = tex->ss.ss0.surface_format;
surface->ss.ss0.surface_type = BRW_SURFACE_2D;
/* Get a surface which is view into a texture
*/
static struct pipe_surface *brw_get_tex_surface(struct pipe_screen *screen,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
unsigned face, unsigned level,
unsigned zslice,
unsigned usage )
*/
remove_from_list(surface);
bo_reference(&surface->bo, NULL);
- pipe_texture_reference( &surface->base.texture, NULL );
+ pipe_resource_reference( &surface->base.texture, NULL );
FREE(surface);
+++ /dev/null
-/*
- Copyright (C) Intel Corp. 2006. All Rights Reserved.
- Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
- develop this 3D driver.
-
- 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 "pipe/p_format.h"
-
-#include "util/u_math.h"
-#include "util/u_memory.h"
-
-#include "brw_screen.h"
-#include "brw_debug.h"
-#include "brw_winsys.h"
-
-/* Code to layout images in a mipmap tree for i965.
- */
-
-static int
-brw_tex_pitch_align (struct brw_texture *tex,
- int pitch)
-{
- if (!tex->compressed) {
- int pitch_align;
-
- switch (tex->tiling) {
- case BRW_TILING_X:
- pitch_align = 512;
- break;
- case BRW_TILING_Y:
- pitch_align = 128;
- break;
- default:
- /* XXX: Untiled pitch alignment of 64 bytes for now to allow
- * render-to-texture to work in all cases. This should
- * probably be replaced at some point by some scheme to only
- * do this when really necessary, for example standalone
- * render target views.
- */
- pitch_align = 64;
- break;
- }
-
- pitch = align(pitch * tex->cpp, pitch_align);
- pitch /= tex->cpp;
- }
-
- return pitch;
-}
-
-
-static void
-brw_tex_alignment_unit(enum pipe_format pf,
- GLuint *w, GLuint *h)
-{
- switch (pf) {
- case PIPE_FORMAT_DXT1_RGB:
- case PIPE_FORMAT_DXT1_RGBA:
- case PIPE_FORMAT_DXT3_RGBA:
- case PIPE_FORMAT_DXT5_RGBA:
- case PIPE_FORMAT_DXT1_SRGB:
- case PIPE_FORMAT_DXT1_SRGBA:
- case PIPE_FORMAT_DXT3_SRGBA:
- case PIPE_FORMAT_DXT5_SRGBA:
- *w = 4;
- *h = 4;
- break;
-
- default:
- *w = 4;
- *h = 2;
- break;
- }
-}
-
-
-static void
-brw_tex_set_level_info(struct brw_texture *tex,
- GLuint level,
- GLuint nr_images,
- GLuint x, GLuint y,
- GLuint w, GLuint h, GLuint d)
-{
-
- if (BRW_DEBUG & DEBUG_TEXTURE)
- debug_printf("%s level %d size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__,
- level, w, h, d, x, y, tex->level_offset[level]);
-
- assert(tex->image_offset[level] == NULL);
- assert(nr_images >= 1);
-
- tex->level_offset[level] = (x + y * tex->pitch) * tex->cpp;
- tex->nr_images[level] = nr_images;
-
- tex->image_offset[level] = MALLOC(nr_images * sizeof(GLuint));
- tex->image_offset[level][0] = 0;
-}
-
-
-static void
-brw_tex_set_image_offset(struct brw_texture *tex,
- GLuint level, GLuint img,
- GLuint x, GLuint y,
- GLuint offset)
-{
- assert((x == 0 && y == 0) || img != 0 || level != 0);
- assert(img < tex->nr_images[level]);
-
- if (BRW_DEBUG & DEBUG_TEXTURE)
- debug_printf("%s level %d img %d pos %d,%d image_offset %x\n",
- __FUNCTION__, level, img, x, y,
- tex->image_offset[level][img]);
-
- tex->image_offset[level][img] = (x + y * tex->pitch) * tex->cpp + offset;
-}
-
-
-
-static void brw_layout_2d( struct brw_texture *tex )
-{
- GLuint align_h = 2, align_w = 4;
- GLuint level;
- GLuint x = 0;
- GLuint y = 0;
- GLuint width = tex->base.width0;
- GLuint height = tex->base.height0;
-
- tex->pitch = tex->base.width0;
- brw_tex_alignment_unit(tex->base.format, &align_w, &align_h);
-
- if (tex->compressed) {
- tex->pitch = align(tex->base.width0, align_w);
- }
-
- /* May need to adjust pitch to accomodate the placement of
- * the 2nd mipmap. This occurs when the alignment
- * constraints of mipmap placement push the right edge of the
- * 2nd mipmap out past the width of its parent.
- */
- if (tex->base.last_level > 0) {
- GLuint mip1_width;
-
- if (tex->compressed) {
- mip1_width = (align(u_minify(tex->base.width0, 1), align_w) +
- align(u_minify(tex->base.width0, 2), align_w));
- } else {
- mip1_width = (align(u_minify(tex->base.width0, 1), align_w) +
- u_minify(tex->base.width0, 2));
- }
-
- if (mip1_width > tex->pitch) {
- tex->pitch = mip1_width;
- }
- }
-
- /* Pitch must be a whole number of dwords, even though we
- * express it in texels.
- */
- tex->pitch = brw_tex_pitch_align (tex, tex->pitch);
- tex->total_height = 0;
-
- for ( level = 0 ; level <= tex->base.last_level ; level++ ) {
- GLuint img_height;
-
- brw_tex_set_level_info(tex, level, 1, x, y, width, height, 1);
-
- if (tex->compressed)
- img_height = MAX2(1, height/4);
- else
- img_height = align(height, align_h);
-
-
- /* Because the images are packed better, the final offset
- * might not be the maximal one:
- */
- tex->total_height = MAX2(tex->total_height, y + img_height);
-
- /* Layout_below: step right after second mipmap.
- */
- if (level == 1) {
- x += align(width, align_w);
- }
- else {
- y += img_height;
- }
-
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- }
-}
-
-
-static boolean
-brw_layout_cubemap_idgng( struct brw_texture *tex )
-{
- GLuint align_h = 2, align_w = 4;
- GLuint level;
- GLuint x = 0;
- GLuint y = 0;
- GLuint width = tex->base.width0;
- GLuint height = tex->base.height0;
- GLuint qpitch = 0;
- GLuint y_pitch = 0;
-
- tex->pitch = tex->base.width0;
- brw_tex_alignment_unit(tex->base.format, &align_w, &align_h);
- y_pitch = align(height, align_h);
-
- if (tex->compressed) {
- tex->pitch = align(tex->base.width0, align_w);
- }
-
- if (tex->base.last_level != 0) {
- GLuint mip1_width;
-
- if (tex->compressed) {
- mip1_width = (align(u_minify(tex->base.width0, 1), align_w) +
- align(u_minify(tex->base.width0, 2), align_w));
- } else {
- mip1_width = (align(u_minify(tex->base.width0, 1), align_w) +
- u_minify(tex->base.width0, 2));
- }
-
- if (mip1_width > tex->pitch) {
- tex->pitch = mip1_width;
- }
- }
-
- tex->pitch = brw_tex_pitch_align(tex, tex->pitch);
-
- if (tex->compressed) {
- qpitch = ((y_pitch +
- align(u_minify(y_pitch, 1), align_h) +
- 11 * align_h) / 4) * tex->pitch * tex->cpp;
-
- tex->total_height = ((y_pitch +
- align(u_minify(y_pitch, 1), align_h) +
- 11 * align_h) / 4) * 6;
- } else {
- qpitch = (y_pitch +
- align(u_minify(y_pitch, 1), align_h) +
- 11 * align_h) * tex->pitch * tex->cpp;
-
- tex->total_height = (y_pitch +
- align(u_minify(y_pitch, 1), align_h) +
- 11 * align_h) * 6;
- }
-
- for (level = 0; level <= tex->base.last_level; level++) {
- GLuint img_height;
- GLuint nr_images = 6;
- GLuint q = 0;
-
- brw_tex_set_level_info(tex, level, nr_images, x, y, width, height, 1);
-
- for (q = 0; q < nr_images; q++)
- brw_tex_set_image_offset(tex, level, q, x, y, q * qpitch);
-
- if (tex->compressed)
- img_height = MAX2(1, height/4);
- else
- img_height = align(height, align_h);
-
- if (level == 1) {
- x += align(width, align_w);
- }
- else {
- y += img_height;
- }
-
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- }
-
- return TRUE;
-}
-
-
-static boolean
-brw_layout_3d_cube( struct brw_texture *tex )
-{
- GLuint width = tex->base.width0;
- GLuint height = tex->base.height0;
- GLuint depth = tex->base.depth0;
- GLuint pack_x_pitch, pack_x_nr;
- GLuint pack_y_pitch;
- GLuint level;
- GLuint align_h = 2;
- GLuint align_w = 4;
-
- tex->total_height = 0;
- brw_tex_alignment_unit(tex->base.format, &align_w, &align_h);
-
- if (tex->compressed) {
- tex->pitch = align(width, align_w);
- pack_y_pitch = (height + 3) / 4;
- } else {
- tex->pitch = brw_tex_pitch_align(tex, tex->base.width0);
- pack_y_pitch = align(tex->base.height0, align_h);
- }
-
- pack_x_pitch = width;
- pack_x_nr = 1;
-
- for (level = 0 ; level <= tex->base.last_level ; level++) {
- GLuint nr_images = tex->base.target == PIPE_TEXTURE_3D ? depth : 6;
- GLint x = 0;
- GLint y = 0;
- GLint q, j;
-
- brw_tex_set_level_info(tex, level, nr_images,
- 0, tex->total_height,
- width, height, depth);
-
- for (q = 0; q < nr_images;) {
- for (j = 0; j < pack_x_nr && q < nr_images; j++, q++) {
- brw_tex_set_image_offset(tex, level, q, x, y, 0);
- x += pack_x_pitch;
- }
-
- x = 0;
- y += pack_y_pitch;
- }
-
-
- tex->total_height += y;
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- depth = u_minify(depth, 1);
-
- if (tex->compressed) {
- pack_y_pitch = (height + 3) / 4;
-
- if (pack_x_pitch > align(width, align_w)) {
- pack_x_pitch = align(width, align_w);
- pack_x_nr <<= 1;
- }
- } else {
- if (pack_x_pitch > 4) {
- pack_x_pitch >>= 1;
- pack_x_nr <<= 1;
- assert(pack_x_pitch * pack_x_nr <= tex->pitch);
- }
-
- if (pack_y_pitch > 2) {
- pack_y_pitch >>= 1;
- pack_y_pitch = align(pack_y_pitch, align_h);
- }
- }
- }
-
- /* The 965's sampler lays cachelines out according to how accesses
- * in the texture surfaces run, so they may be "vertical" through
- * memory. As a result, the docs say in Surface Padding Requirements:
- * Sampling Engine Surfaces that two extra rows of padding are required.
- */
- if (tex->base.target == PIPE_TEXTURE_CUBE)
- tex->total_height += 2;
-
- return TRUE;
-}
-
-
-
-GLboolean brw_texture_layout(struct brw_screen *brw_screen,
- struct brw_texture *tex )
-{
- switch (tex->base.target) {
- case PIPE_TEXTURE_CUBE:
- if (brw_screen->chipset.is_igdng)
- brw_layout_cubemap_idgng( tex );
- else
- brw_layout_3d_cube( tex );
- break;
-
- case PIPE_TEXTURE_3D:
- brw_layout_3d_cube( tex );
- break;
-
- default:
- brw_layout_2d( tex );
- break;
- }
-
- if (BRW_DEBUG & DEBUG_TEXTURE)
- debug_printf("%s: %dx%dx%d - sz 0x%x\n", __FUNCTION__,
- tex->pitch,
- tex->total_height,
- tex->cpp,
- tex->pitch * tex->total_height * tex->cpp );
-
- return GL_TRUE;
-}
+++ /dev/null
-/*
- Copyright (C) Intel Corp. 2006. All Rights Reserved.
- Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
- develop this 3D driver.
-
- 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.
-
- **********************************************************************/
- /*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-#include "util/u_memory.h"
-#include "util/u_simple_list.h"
-#include "util/u_format.h"
-
-#include "brw_screen.h"
-#include "brw_defines.h"
-#include "brw_structs.h"
-#include "brw_winsys.h"
-#include "brw_context.h"
-
-
-
-
-static GLuint translate_tex_target( unsigned target )
-{
- switch (target) {
- case PIPE_TEXTURE_1D:
- return BRW_SURFACE_1D;
-
- case PIPE_TEXTURE_2D:
- return BRW_SURFACE_2D;
-
- case PIPE_TEXTURE_3D:
- return BRW_SURFACE_3D;
-
- case PIPE_TEXTURE_CUBE:
- return BRW_SURFACE_CUBE;
-
- default:
- assert(0);
- return BRW_SURFACE_1D;
- }
-}
-
-
-static GLuint translate_tex_format( enum pipe_format pf )
-{
- switch( pf ) {
- case PIPE_FORMAT_L8_UNORM:
- return BRW_SURFACEFORMAT_L8_UNORM;
-
- case PIPE_FORMAT_I8_UNORM:
- return BRW_SURFACEFORMAT_I8_UNORM;
-
- case PIPE_FORMAT_A8_UNORM:
- return BRW_SURFACEFORMAT_A8_UNORM;
-
- case PIPE_FORMAT_L16_UNORM:
- return BRW_SURFACEFORMAT_L16_UNORM;
-
- /* XXX: Add these to gallium
- case PIPE_FORMAT_I16_UNORM:
- return BRW_SURFACEFORMAT_I16_UNORM;
-
- case PIPE_FORMAT_A16_UNORM:
- return BRW_SURFACEFORMAT_A16_UNORM;
- */
-
- case PIPE_FORMAT_L8A8_UNORM:
- return BRW_SURFACEFORMAT_L8A8_UNORM;
-
- case PIPE_FORMAT_B5G6R5_UNORM:
- return BRW_SURFACEFORMAT_B5G6R5_UNORM;
-
- case PIPE_FORMAT_B5G5R5A1_UNORM:
- return BRW_SURFACEFORMAT_B5G5R5A1_UNORM;
-
- case PIPE_FORMAT_B4G4R4A4_UNORM:
- return BRW_SURFACEFORMAT_B4G4R4A4_UNORM;
-
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- return BRW_SURFACEFORMAT_R8G8B8X8_UNORM;
-
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- return BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
-
- /*
- * Video formats
- */
-
- case PIPE_FORMAT_YUYV:
- return BRW_SURFACEFORMAT_YCRCB_NORMAL;
-
- case PIPE_FORMAT_UYVY:
- return BRW_SURFACEFORMAT_YCRCB_SWAPUVY;
-
- /*
- * Compressed formats.
- */
- /* XXX: Add FXT to gallium?
- case PIPE_FORMAT_FXT1_RGBA:
- return BRW_SURFACEFORMAT_FXT1;
- */
-
- case PIPE_FORMAT_DXT1_RGB:
- return BRW_SURFACEFORMAT_DXT1_RGB;
-
- case PIPE_FORMAT_DXT1_RGBA:
- return BRW_SURFACEFORMAT_BC1_UNORM;
-
- case PIPE_FORMAT_DXT3_RGBA:
- return BRW_SURFACEFORMAT_BC2_UNORM;
-
- case PIPE_FORMAT_DXT5_RGBA:
- return BRW_SURFACEFORMAT_BC3_UNORM;
-
- /*
- * sRGB formats
- */
-
- case PIPE_FORMAT_A8B8G8R8_SRGB:
- return BRW_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB;
-
- case PIPE_FORMAT_L8A8_SRGB:
- return BRW_SURFACEFORMAT_L8A8_UNORM_SRGB;
-
- case PIPE_FORMAT_L8_SRGB:
- return BRW_SURFACEFORMAT_L8_UNORM_SRGB;
-
- case PIPE_FORMAT_DXT1_SRGB:
- return BRW_SURFACEFORMAT_BC1_UNORM_SRGB;
-
- /*
- * Depth formats
- */
-
- case PIPE_FORMAT_Z16_UNORM:
- return BRW_SURFACEFORMAT_I16_UNORM;
-
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- case PIPE_FORMAT_Z24X8_UNORM:
- return BRW_SURFACEFORMAT_I24X8_UNORM;
-
- case PIPE_FORMAT_Z32_FLOAT:
- return BRW_SURFACEFORMAT_I32_FLOAT;
-
- /* XXX: presumably for bump mapping. Add this to mesa state
- * tracker?
- *
- * XXX: Add flipped versions of these formats to Gallium.
- */
- case PIPE_FORMAT_R8G8_SNORM:
- return BRW_SURFACEFORMAT_R8G8_SNORM;
-
- case PIPE_FORMAT_R8G8B8A8_SNORM:
- return BRW_SURFACEFORMAT_R8G8B8A8_SNORM;
-
- default:
- return BRW_SURFACEFORMAT_INVALID;
- }
-}
-
-
-
-
-
-static struct pipe_texture *brw_texture_create( struct pipe_screen *screen,
- const struct pipe_texture *templ )
-
-{
- struct brw_screen *bscreen = brw_screen(screen);
- struct brw_texture *tex;
- enum brw_buffer_type buffer_type;
- enum pipe_error ret;
- GLuint format;
-
- tex = CALLOC_STRUCT(brw_texture);
- if (tex == NULL)
- return NULL;
-
- memcpy(&tex->base, templ, sizeof *templ);
- pipe_reference_init(&tex->base.reference, 1);
- tex->base.screen = screen;
-
- /* XXX: compressed textures need special treatment here
- */
- tex->cpp = util_format_get_blocksize(tex->base.format);
- tex->compressed = util_format_is_s3tc(tex->base.format);
-
- make_empty_list(&tex->views[0]);
- make_empty_list(&tex->views[1]);
-
- /* XXX: No tiling with compressed textures??
- */
- if (tex->compressed == 0 &&
- !bscreen->no_tiling)
- {
- if (bscreen->chipset.is_965 &&
- util_format_is_depth_or_stencil(templ->format))
- tex->tiling = BRW_TILING_Y;
- else
- tex->tiling = BRW_TILING_X;
- }
- else {
- tex->tiling = BRW_TILING_NONE;
- }
-
-
-
-
- if (!brw_texture_layout( bscreen, tex ))
- goto fail;
-
-
- if (templ->tex_usage & (PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED)) {
- buffer_type = BRW_BUFFER_TYPE_SCANOUT;
- }
- else {
- buffer_type = BRW_BUFFER_TYPE_TEXTURE;
- }
-
- ret = bscreen->sws->bo_alloc( bscreen->sws,
- buffer_type,
- tex->pitch * tex->total_height * tex->cpp,
- 64,
- &tex->bo );
- if (ret)
- goto fail;
-
- tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW;
- tex->ss.ss0.surface_type = translate_tex_target(tex->base.target);
-
- format = translate_tex_format(tex->base.format);
- assert(format != BRW_SURFACEFORMAT_INVALID);
- tex->ss.ss0.surface_format = format;
-
- /* This is ok for all textures with channel width 8bit or less:
- */
-/* tex->ss.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */
-
-
- /* XXX: what happens when tex->bo->offset changes???
- */
- tex->ss.ss1.base_addr = 0; /* reloc */
- tex->ss.ss2.mip_count = tex->base.last_level;
- tex->ss.ss2.width = tex->base.width0 - 1;
- tex->ss.ss2.height = tex->base.height0 - 1;
-
- switch (tex->tiling) {
- case BRW_TILING_NONE:
- tex->ss.ss3.tiled_surface = 0;
- tex->ss.ss3.tile_walk = 0;
- break;
- case BRW_TILING_X:
- tex->ss.ss3.tiled_surface = 1;
- tex->ss.ss3.tile_walk = BRW_TILEWALK_XMAJOR;
- break;
- case BRW_TILING_Y:
- tex->ss.ss3.tiled_surface = 1;
- tex->ss.ss3.tile_walk = BRW_TILEWALK_YMAJOR;
- break;
- }
-
- tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1;
- tex->ss.ss3.depth = tex->base.depth0 - 1;
-
- tex->ss.ss4.min_lod = 0;
-
- if (tex->base.target == PIPE_TEXTURE_CUBE) {
- tex->ss.ss0.cube_pos_x = 1;
- tex->ss.ss0.cube_pos_y = 1;
- tex->ss.ss0.cube_pos_z = 1;
- tex->ss.ss0.cube_neg_x = 1;
- tex->ss.ss0.cube_neg_y = 1;
- tex->ss.ss0.cube_neg_z = 1;
- }
-
- return &tex->base;
-
-fail:
- bo_reference(&tex->bo, NULL);
- FREE(tex);
- return NULL;
-}
-
-static struct pipe_texture *
-brw_texture_from_handle(struct pipe_screen *screen,
- const struct pipe_texture *templ,
- struct winsys_handle *whandle)
-{
- struct brw_screen *bscreen = brw_screen(screen);
- struct brw_texture *tex;
- struct brw_winsys_buffer *buffer;
- unsigned tiling;
- unsigned pitch;
- GLuint format;
-
- if (templ->target != PIPE_TEXTURE_2D ||
- templ->last_level != 0 ||
- templ->depth0 != 1)
- return NULL;
-
- if (util_format_is_s3tc(templ->format))
- return NULL;
-
- tex = CALLOC_STRUCT(brw_texture);
- if (!tex)
- return NULL;
-
- if (bscreen->sws->bo_from_handle(bscreen->sws, whandle, &pitch, &tiling, &buffer) != PIPE_OK)
- goto fail;
-
- memcpy(&tex->base, templ, sizeof *templ);
- pipe_reference_init(&tex->base.reference, 1);
- tex->base.screen = screen;
-
- /* XXX: cpp vs. blocksize
- */
- tex->cpp = util_format_get_blocksize(tex->base.format);
- tex->tiling = tiling;
-
- make_empty_list(&tex->views[0]);
- make_empty_list(&tex->views[1]);
-
- if (!brw_texture_layout(bscreen, tex))
- goto fail;
-
- /* XXX Maybe some more checks? */
- if ((pitch / tex->cpp) < tex->pitch)
- goto fail;
-
- tex->pitch = pitch / tex->cpp;
-
- tex->bo = buffer;
-
- /* fix this warning */
-#if 0
- if (tex->size > buffer->size)
- goto fail;
-#endif
-
- tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW;
- tex->ss.ss0.surface_type = translate_tex_target(tex->base.target);
-
- format = translate_tex_format(tex->base.format);
- assert(format != BRW_SURFACEFORMAT_INVALID);
- tex->ss.ss0.surface_format = format;
-
- /* This is ok for all textures with channel width 8bit or less:
- */
-/* tex->ss.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */
-
-
- /* XXX: what happens when tex->bo->offset changes???
- */
- tex->ss.ss1.base_addr = 0; /* reloc */
- tex->ss.ss2.mip_count = tex->base.last_level;
- tex->ss.ss2.width = tex->base.width0 - 1;
- tex->ss.ss2.height = tex->base.height0 - 1;
-
- switch (tex->tiling) {
- case BRW_TILING_NONE:
- tex->ss.ss3.tiled_surface = 0;
- tex->ss.ss3.tile_walk = 0;
- break;
- case BRW_TILING_X:
- tex->ss.ss3.tiled_surface = 1;
- tex->ss.ss3.tile_walk = BRW_TILEWALK_XMAJOR;
- break;
- case BRW_TILING_Y:
- tex->ss.ss3.tiled_surface = 1;
- tex->ss.ss3.tile_walk = BRW_TILEWALK_YMAJOR;
- break;
- }
-
- tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1;
- tex->ss.ss3.depth = tex->base.depth0 - 1;
-
- tex->ss.ss4.min_lod = 0;
-
- return &tex->base;
-
-fail:
- FREE(tex);
- return NULL;
-}
-
-static boolean
-brw_texture_get_handle(struct pipe_screen *screen,
- struct pipe_texture *texture,
- struct winsys_handle *whandle)
-{
- struct brw_screen *bscreen = brw_screen(screen);
- struct brw_texture *tex = brw_texture(texture);
- unsigned stride;
-
- stride = tex->pitch * tex->cpp;
-
- return bscreen->sws->bo_get_handle(tex->bo, whandle, stride);
-}
-
-
-
-static void brw_texture_destroy(struct pipe_texture *pt)
-{
- struct brw_texture *tex = brw_texture(pt);
- bo_reference(&tex->bo, NULL);
- FREE(pt);
-}
-
-
-static boolean brw_is_format_supported( struct pipe_screen *screen,
- enum pipe_format format,
- enum pipe_texture_target target,
- unsigned tex_usage,
- unsigned geom_flags )
-{
- return translate_tex_format(format) != BRW_SURFACEFORMAT_INVALID;
-}
-
-
-boolean brw_is_texture_referenced_by_bo( struct brw_screen *brw_screen,
- struct pipe_texture *texture,
- unsigned face,
- unsigned level,
- struct brw_winsys_buffer *bo )
-{
- struct brw_texture *tex = brw_texture(texture);
- struct brw_surface *surf;
- int i;
-
- /* XXX: this is subject to false positives if the underlying
- * texture BO is referenced, we can't tell whether the sub-region
- * we care about participates in that.
- */
- if (brw_screen->sws->bo_references( bo, tex->bo ))
- return TRUE;
-
- /* Find any view on this texture for this face/level and see if it
- * is referenced:
- */
- for (i = 0; i < 2; i++) {
- foreach (surf, &tex->views[i]) {
- if (surf->bo == tex->bo)
- continue;
-
- if (surf->id.bits.face != face ||
- surf->id.bits.level != level)
- continue;
-
- if (brw_screen->sws->bo_references( bo, surf->bo))
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
-/*
- * Transfer functions
- */
-
-static struct pipe_transfer*
-brw_get_tex_transfer(struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage, unsigned x, unsigned y,
- unsigned w, unsigned h)
-{
- struct brw_texture *tex = brw_texture(texture);
- struct brw_transfer *trans;
- unsigned offset; /* in bytes */
-
- if (texture->target == PIPE_TEXTURE_CUBE) {
- offset = tex->image_offset[level][face];
- } else if (texture->target == PIPE_TEXTURE_3D) {
- offset = tex->image_offset[level][zslice];
- } else {
- offset = tex->image_offset[level][0];
- assert(face == 0);
- assert(zslice == 0);
- }
-
- trans = CALLOC_STRUCT(brw_transfer);
- if (trans) {
- pipe_texture_reference(&trans->base.texture, texture);
- trans->base.x = x;
- trans->base.y = y;
- trans->base.width = w;
- trans->base.height = h;
- trans->base.stride = tex->pitch * tex->cpp;
- trans->offset = offset;
- trans->base.usage = usage;
- }
- return &trans->base;
-}
-
-static void *
-brw_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct brw_texture *tex = brw_texture(transfer->texture);
- struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws;
- char *map;
- unsigned usage = transfer->usage;
-
- map = sws->bo_map(tex->bo,
- BRW_DATA_OTHER,
- 0,
- tex->bo->size,
- (usage & PIPE_TRANSFER_WRITE) ? TRUE : FALSE,
- (usage & 0) ? TRUE : FALSE,
- (usage & 0) ? TRUE : FALSE);
-
- if (!map)
- return NULL;
-
- /* XXX: blocksize and compressed textures
- */
- return map + brw_transfer(transfer)->offset +
- transfer->y /* / transfer->block.height */ * transfer->stride +
- transfer->x /* / transfer->block.width */ * brw_texture(transfer->texture)->cpp;
-}
-
-static void
-brw_transfer_unmap(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct brw_texture *tex = brw_texture(transfer->texture);
- struct brw_winsys_screen *sws = brw_screen(pipe->screen)->sws;
-
- sws->bo_unmap(tex->bo);
-}
-
-static void
-brw_tex_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *trans)
-{
- pipe_texture_reference(&trans->texture, NULL);
- FREE(trans);
-}
-
-
-void brw_tex_init( struct brw_context *brw )
-{
- brw->base.get_tex_transfer = brw_get_tex_transfer;
- brw->base.transfer_map = brw_transfer_map;
- brw->base.transfer_unmap = brw_transfer_unmap;
- brw->base.tex_transfer_destroy = brw_tex_transfer_destroy;
-}
-
-void brw_screen_tex_init( struct brw_screen *brw_screen )
-{
- brw_screen->base.is_format_supported = brw_is_format_supported;
- brw_screen->base.texture_create = brw_texture_create;
- brw_screen->base.texture_from_handle = brw_texture_from_handle;
- brw_screen->base.texture_get_handle = brw_texture_get_handle;
- brw_screen->base.texture_destroy = brw_texture_destroy;
-}
+++ /dev/null
-/*
- Copyright (C) Intel Corp. 2006. All Rights Reserved.
- Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
- develop this 3D driver.
-
- 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.
-
- **********************************************************************/
- /*
- * Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
- */
-
-
-
-
-
-
GLuint surf)
{
struct brw_surface_key key;
- struct pipe_buffer *cb = brw->curr.vs_constants;
+ struct pipe_resource *cb = brw->curr.vs_constants;
enum pipe_error ret;
assert(surf == 0);
#include "brw_wm.h"
#include "brw_state.h"
#include "brw_debug.h"
+#include "brw_resource.h"
#include "brw_pipe_rast.h"
for (i = 0; i < brw->curr.num_fragment_sampler_views; i++) {
const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture);
- if (tex->base.format == PIPE_FORMAT_UYVY)
+ if (tex->b.b.format == PIPE_FORMAT_UYVY)
key->yuvtex_mask |= 1 << i;
- if (tex->base.format == PIPE_FORMAT_YUYV)
+ if (tex->b.b.format == PIPE_FORMAT_YUYV)
key->yuvtex_swap_mask |= 1 << i;
/* XXX: shadow texture
{
struct brw_surface_key key;
struct brw_fragment_shader *fp = brw->curr.fragment_shader;
- struct pipe_buffer *cbuf = brw->curr.fragment_constants;
+ struct pipe_resource *cbuf = brw->curr.fragment_constants;
int pitch = cbuf->size / (4 * sizeof(float));
enum pipe_error ret;
#include "brw_context.h"
#include "brw_state.h"
#include "brw_defines.h"
-#include "brw_screen.h"
+#include "brw_resource.h"
/* Samplers aren't strictly wm state from the hardware's perspective,
/* Cube-maps on 965 and later must use the same wrap mode for all 3
* coordinate dimensions. Futher, only CUBE and CLAMP are valid.
*/
- if (tex->base.target == PIPE_TEXTURE_CUBE) {
+ if (tex->b.b.target == PIPE_TEXTURE_CUBE) {
if (FALSE &&
(sampler->ss0.min_filter != BRW_MAPFILTER_NEAREST ||
sampler->ss0.mag_filter != BRW_MAPFILTER_NEAREST)) {
entry->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
entry->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
}
- } else if (tex->base.target == PIPE_TEXTURE_1D) {
+ } else if (tex->b.b.target == PIPE_TEXTURE_1D) {
/* There's a bug in 1D texture sampling - it actually pays
* attention to the wrap_t value, though it should not.
* Override the wrap_t value here to GL_REPEAT to keep
sampler->border_color[0]
};
- if (util_format_is_depth_or_stencil(tex->base.format)) {
+ if (util_format_is_depth_or_stencil(tex->b.b.format)) {
bc = bordercolor;
}
else {
#include "brw_batchbuffer.h"
#include "brw_context.h"
#include "brw_state.h"
-#include "brw_screen.h"
+#include "brw_resource.h"
#include "pipe/p_context.h"
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "id_context.h"
#include "id_objects.h"
static void
identity_draw_elements(struct pipe_context *_pipe,
- struct pipe_buffer *_indexBuffer,
+ struct pipe_resource *_indexResource,
unsigned indexSize,
unsigned prim,
unsigned start,
unsigned count)
{
struct identity_context *id_pipe = identity_context(_pipe);
- struct identity_buffer *id_buffer = identity_buffer(_indexBuffer);
+ struct identity_resource *id_resource = identity_resource(_indexResource);
struct pipe_context *pipe = id_pipe->pipe;
- struct pipe_buffer *indexBuffer = id_buffer->buffer;
+ struct pipe_resource *indexResource = id_resource->resource;
pipe->draw_elements(pipe,
- indexBuffer,
+ indexResource,
indexSize,
prim,
start,
static void
identity_draw_range_elements(struct pipe_context *_pipe,
- struct pipe_buffer *_indexBuffer,
+ struct pipe_resource *_indexResource,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
unsigned count)
{
struct identity_context *id_pipe = identity_context(_pipe);
- struct identity_buffer *id_buffer = identity_buffer(_indexBuffer);
+ struct identity_resource *id_resource = identity_resource(_indexResource);
struct pipe_context *pipe = id_pipe->pipe;
- struct pipe_buffer *indexBuffer = id_buffer->buffer;
+ struct pipe_resource *indexResource = id_resource->resource;
pipe->draw_range_elements(pipe,
- indexBuffer,
+ indexResource,
indexSize,
minIndex,
maxIndex,
identity_set_constant_buffer(struct pipe_context *_pipe,
uint shader,
uint index,
- struct pipe_buffer *_buffer)
+ struct pipe_resource *_resource)
{
struct identity_context *id_pipe = identity_context(_pipe);
struct pipe_context *pipe = id_pipe->pipe;
- struct pipe_buffer *unwrapped_buffer;
- struct pipe_buffer *buffer = NULL;
+ struct pipe_resource *unwrapped_resource;
+ struct pipe_resource *resource = NULL;
/* XXX hmm? unwrap the input state */
- if (_buffer) {
- unwrapped_buffer = identity_buffer_unwrap(_buffer);
- buffer = unwrapped_buffer;
+ if (_resource) {
+ unwrapped_resource = identity_resource_unwrap(_resource);
+ resource = unwrapped_resource;
}
pipe->set_constant_buffer(pipe,
shader,
index,
- buffer);
+ resource);
}
static void
if (num_buffers) {
memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
for (i = 0; i < num_buffers; i++)
- unwrapped_buffers[i].buffer = identity_buffer_unwrap(_buffers[i].buffer);
+ unwrapped_buffers[i].buffer = identity_resource_unwrap(_buffers[i].buffer);
buffers = unwrapped_buffers;
}
}
static unsigned int
-identity_is_texture_referenced(struct pipe_context *_pipe,
- struct pipe_texture *_texture,
+identity_is_resource_referenced(struct pipe_context *_pipe,
+ struct pipe_resource *_resource,
unsigned face,
unsigned level)
{
struct identity_context *id_pipe = identity_context(_pipe);
- struct identity_texture *id_texture = identity_texture(_texture);
+ struct identity_resource *id_resource = identity_resource(_resource);
struct pipe_context *pipe = id_pipe->pipe;
- struct pipe_texture *texture = id_texture->texture;
+ struct pipe_resource *texture = id_resource->resource;
- return pipe->is_texture_referenced(pipe,
+ return pipe->is_resource_referenced(pipe,
texture,
face,
level);
}
-static unsigned int
-identity_is_buffer_referenced(struct pipe_context *_pipe,
- struct pipe_buffer *_buffer)
-{
- struct identity_context *id_pipe = identity_context(_pipe);
- struct identity_buffer *id_buffer = identity_buffer(_buffer);
- struct pipe_context *pipe = id_pipe->pipe;
- struct pipe_buffer *buffer = id_buffer->buffer;
-
- return pipe->is_buffer_referenced(pipe,
- buffer);
-}
-
static struct pipe_sampler_view *
identity_create_sampler_view(struct pipe_context *pipe,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
const struct pipe_sampler_view *templ)
{
struct identity_context *id_pipe = identity_context(pipe);
- struct identity_texture *id_texture = identity_texture(texture);
+ struct identity_resource *id_resource = identity_resource(texture);
struct pipe_context *pipe_unwrapped = id_pipe->pipe;
- struct pipe_texture *texture_unwrapped = id_texture->texture;
+ struct pipe_resource *texture_unwrapped = id_resource->resource;
struct identity_sampler_view *view = malloc(sizeof(struct identity_sampler_view));
view->sampler_view = pipe_unwrapped->create_sampler_view(pipe_unwrapped,
view->base = *templ;
view->base.reference.count = 1;
view->base.texture = NULL;
- pipe_texture_reference(&view->base.texture, texture);
+ pipe_resource_reference(&view->base.texture, texture);
view->base.context = pipe;
return &view->base;
pipe_unwrapped->sampler_view_destroy(pipe_unwrapped,
view_unwrapped);
- pipe_texture_reference(&view->texture, NULL);
+ pipe_resource_reference(&view->texture, NULL);
free(view);
}
-
static struct pipe_transfer *
-identity_context_get_tex_transfer(struct pipe_context *_context,
- struct pipe_texture *_texture,
- unsigned face,
- unsigned level,
- unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x,
- unsigned y,
- unsigned w,
- unsigned h)
+identity_context_get_transfer(struct pipe_context *_context,
+ struct pipe_resource *_resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
{
struct identity_context *id_context = identity_context(_context);
- struct identity_texture *id_texture = identity_texture(_texture);
+ struct identity_resource *id_resource = identity_resource(_resource);
struct pipe_context *context = id_context->pipe;
- struct pipe_texture *texture = id_texture->texture;
+ struct pipe_resource *texture = id_resource->resource;
struct pipe_transfer *result;
- result = context->get_tex_transfer(context,
- texture,
- face,
- level,
- zslice,
- usage,
- x,
- y,
- w,
- h);
+ result = context->get_transfer(context,
+ texture,
+ sr,
+ usage,
+ box);
if (result)
- return identity_transfer_create(id_context, id_texture, result);
+ return identity_transfer_create(id_context, id_resource, result);
return NULL;
}
static void
-identity_context_tex_transfer_destroy(struct pipe_context *_pipe,
+identity_context_transfer_destroy(struct pipe_context *_pipe,
struct pipe_transfer *_transfer)
{
identity_transfer_destroy(identity_context(_pipe),
transfer);
}
+
+
+static void
+identity_context_transfer_flush_region( struct pipe_context *_context,
+ struct pipe_transfer *_transfer,
+ const struct pipe_box *box)
+{
+ struct identity_context *id_context = identity_context(_context);
+ struct identity_transfer *id_transfer = identity_transfer(_transfer);
+ struct pipe_context *context = id_context->pipe;
+ struct pipe_transfer *transfer = id_transfer->transfer;
+
+ context->transfer_flush_region(context,
+ transfer,
+ box);
+}
+
+
static void
identity_context_transfer_unmap(struct pipe_context *_context,
struct pipe_transfer *_transfer)
transfer);
}
+
+static void
+identity_context_transfer_inline_write( struct pipe_context *_context,
+ struct pipe_resource *_resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned slice_stride)
+{
+ struct identity_context *id_context = identity_context(_context);
+ struct identity_resource *id_resource = identity_resource(_resource);
+ struct pipe_context *context = id_context->pipe;
+ struct pipe_resource *texture = id_resource->resource;
+
+ context->transfer_inline_write(context,
+ texture,
+ sr,
+ usage,
+ box,
+ data,
+ stride,
+ slice_stride);
+}
+
+
struct pipe_context *
identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
{
id_pipe->base.surface_fill = identity_surface_fill;
id_pipe->base.clear = identity_clear;
id_pipe->base.flush = identity_flush;
- id_pipe->base.is_texture_referenced = identity_is_texture_referenced;
- id_pipe->base.is_buffer_referenced = identity_is_buffer_referenced;
+ id_pipe->base.is_resource_referenced = identity_is_resource_referenced;
id_pipe->base.create_sampler_view = identity_create_sampler_view;
id_pipe->base.sampler_view_destroy = identity_sampler_view_destroy;
- id_pipe->base.get_tex_transfer = identity_context_get_tex_transfer;
- id_pipe->base.tex_transfer_destroy = identity_context_tex_transfer_destroy;
+ id_pipe->base.get_transfer = identity_context_get_transfer;
+ id_pipe->base.transfer_destroy = identity_context_transfer_destroy;
id_pipe->base.transfer_map = identity_context_transfer_map;
id_pipe->base.transfer_unmap = identity_context_transfer_unmap;
+ id_pipe->base.transfer_flush_region = identity_context_transfer_flush_region;
+ id_pipe->base.transfer_inline_write = identity_context_transfer_inline_write;
id_pipe->pipe = pipe;
#include "id_objects.h"
#include "id_context.h"
-struct pipe_buffer *
-identity_buffer_create(struct identity_screen *id_screen,
- struct pipe_buffer *buffer)
-{
- struct identity_buffer *id_buffer;
-
- if(!buffer)
- goto error;
-
- assert(buffer->screen == id_screen->screen);
-
- id_buffer = CALLOC_STRUCT(identity_buffer);
- if(!id_buffer)
- goto error;
-
- memcpy(&id_buffer->base, buffer, sizeof(struct pipe_buffer));
-
- pipe_reference_init(&id_buffer->base.reference, 1);
- id_buffer->base.screen = &id_screen->base;
- id_buffer->buffer = buffer;
-
- return &id_buffer->base;
-
-error:
- pipe_buffer_reference(&buffer, NULL);
- return NULL;
-}
-
-void
-identity_buffer_destroy(struct identity_buffer *id_buffer)
-{
- pipe_buffer_reference(&id_buffer->buffer, NULL);
- FREE(id_buffer);
-}
-struct pipe_texture *
-identity_texture_create(struct identity_screen *id_screen,
- struct pipe_texture *texture)
+struct pipe_resource *
+identity_resource_create(struct identity_screen *id_screen,
+ struct pipe_resource *resource)
{
- struct identity_texture *id_texture;
+ struct identity_resource *id_resource;
- if(!texture)
+ if(!resource)
goto error;
- assert(texture->screen == id_screen->screen);
+ assert(resource->screen == id_screen->screen);
- id_texture = CALLOC_STRUCT(identity_texture);
- if(!id_texture)
+ id_resource = CALLOC_STRUCT(identity_resource);
+ if(!id_resource)
goto error;
- memcpy(&id_texture->base, texture, sizeof(struct pipe_texture));
+ memcpy(&id_resource->base, resource, sizeof(struct pipe_resource));
- pipe_reference_init(&id_texture->base.reference, 1);
- id_texture->base.screen = &id_screen->base;
- id_texture->texture = texture;
+ pipe_reference_init(&id_resource->base.reference, 1);
+ id_resource->base.screen = &id_screen->base;
+ id_resource->resource = resource;
- return &id_texture->base;
+ return &id_resource->base;
error:
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&resource, NULL);
return NULL;
}
void
-identity_texture_destroy(struct identity_texture *id_texture)
+identity_resource_destroy(struct identity_resource *id_resource)
{
- pipe_texture_reference(&id_texture->texture, NULL);
- FREE(id_texture);
+ pipe_resource_reference(&id_resource->resource, NULL);
+ FREE(id_resource);
}
struct pipe_surface *
-identity_surface_create(struct identity_texture *id_texture,
+identity_surface_create(struct identity_resource *id_resource,
struct pipe_surface *surface)
{
struct identity_surface *id_surface;
if(!surface)
goto error;
- assert(surface->texture == id_texture->texture);
+ assert(surface->texture == id_resource->resource);
id_surface = CALLOC_STRUCT(identity_surface);
if(!id_surface)
pipe_reference_init(&id_surface->base.reference, 1);
id_surface->base.texture = NULL;
- pipe_texture_reference(&id_surface->base.texture, &id_texture->base);
+ pipe_resource_reference(&id_surface->base.texture, &id_resource->base);
id_surface->surface = surface;
return &id_surface->base;
void
identity_surface_destroy(struct identity_surface *id_surface)
{
- pipe_texture_reference(&id_surface->base.texture, NULL);
+ pipe_resource_reference(&id_surface->base.texture, NULL);
pipe_surface_reference(&id_surface->surface, NULL);
FREE(id_surface);
}
struct pipe_transfer *
identity_transfer_create(struct identity_context *id_context,
- struct identity_texture *id_texture,
+ struct identity_resource *id_resource,
struct pipe_transfer *transfer)
{
struct identity_transfer *id_transfer;
if(!transfer)
goto error;
- assert(transfer->texture == id_texture->texture);
+ assert(transfer->resource == id_resource->resource);
id_transfer = CALLOC_STRUCT(identity_transfer);
if(!id_transfer)
memcpy(&id_transfer->base, transfer, sizeof(struct pipe_transfer));
- id_transfer->base.texture = NULL;
+ id_transfer->base.resource = NULL;
id_transfer->transfer = transfer;
- pipe_texture_reference(&id_transfer->base.texture, &id_texture->base);
- assert(id_transfer->base.texture == &id_texture->base);
+ pipe_resource_reference(&id_transfer->base.resource, &id_resource->base);
+ assert(id_transfer->base.resource == &id_resource->base);
return &id_transfer->base;
error:
- id_context->pipe->tex_transfer_destroy(id_context->pipe, transfer);
+ id_context->pipe->transfer_destroy(id_context->pipe, transfer);
return NULL;
}
identity_transfer_destroy(struct identity_context *id_context,
struct identity_transfer *id_transfer)
{
- pipe_texture_reference(&id_transfer->base.texture, NULL);
- id_context->pipe->tex_transfer_destroy(id_context->pipe,
- id_transfer->transfer);
+ pipe_resource_reference(&id_transfer->base.resource, NULL);
+ id_context->pipe->transfer_destroy(id_context->pipe,
+ id_transfer->transfer);
FREE(id_transfer);
}
-struct pipe_video_surface *
-identity_video_surface_create(struct identity_screen *id_screen,
- struct pipe_video_surface *video_surface)
-{
- struct identity_video_surface *id_video_surface;
-
- if (!video_surface) {
- goto error;
- }
-
- assert(video_surface->screen == id_screen->screen);
-
- id_video_surface = CALLOC_STRUCT(identity_video_surface);
- if (!id_video_surface) {
- goto error;
- }
-
- memcpy(&id_video_surface->base,
- video_surface,
- sizeof(struct pipe_video_surface));
-
- pipe_reference_init(&id_video_surface->base.reference, 1);
- id_video_surface->base.screen = &id_screen->base;
- id_video_surface->video_surface = video_surface;
-
- return &id_video_surface->base;
-
-error:
- pipe_video_surface_reference(&video_surface, NULL);
- return NULL;
-}
-
-void
-identity_video_surface_destroy(struct identity_video_surface *id_video_surface)
-{
- pipe_video_surface_reference(&id_video_surface->video_surface, NULL);
- FREE(id_video_surface);
-}
#include "pipe/p_compiler.h"
#include "pipe/p_state.h"
-#include "pipe/p_video_state.h"
#include "id_screen.h"
struct identity_context;
-struct identity_buffer
-{
- struct pipe_buffer base;
-
- struct pipe_buffer *buffer;
-};
-
-struct identity_texture
+struct identity_resource
{
- struct pipe_texture base;
+ struct pipe_resource base;
- struct pipe_texture *texture;
+ struct pipe_resource *resource;
};
};
-struct identity_video_surface
-{
- struct pipe_video_surface base;
-
- struct pipe_video_surface *video_surface;
-};
-
-
-static INLINE struct identity_buffer *
-identity_buffer(struct pipe_buffer *_buffer)
+static INLINE struct identity_resource *
+identity_resource(struct pipe_resource *_resource)
{
- if(!_buffer)
+ if(!_resource)
return NULL;
- (void)identity_screen(_buffer->screen);
- return (struct identity_buffer *)_buffer;
-}
-
-static INLINE struct identity_texture *
-identity_texture(struct pipe_texture *_texture)
-{
- if(!_texture)
- return NULL;
- (void)identity_screen(_texture->screen);
- return (struct identity_texture *)_texture;
+ (void)identity_screen(_resource->screen);
+ return (struct identity_resource *)_resource;
}
static INLINE struct identity_sampler_view *
{
if(!_surface)
return NULL;
- (void)identity_texture(_surface->texture);
+ (void)identity_resource(_surface->texture);
return (struct identity_surface *)_surface;
}
{
if(!_transfer)
return NULL;
- (void)identity_texture(_transfer->texture);
+ (void)identity_resource(_transfer->resource);
return (struct identity_transfer *)_transfer;
}
-static INLINE struct identity_video_surface *
-identity_video_surface(struct pipe_video_surface *_video_surface)
-{
- if (!_video_surface) {
- return NULL;
- }
- (void)identity_screen(_video_surface->screen);
- return (struct identity_video_surface *)_video_surface;
-}
-
-static INLINE struct pipe_buffer *
-identity_buffer_unwrap(struct pipe_buffer *_buffer)
-{
- if(!_buffer)
- return NULL;
- return identity_buffer(_buffer)->buffer;
-}
-
-static INLINE struct pipe_texture *
-identity_texture_unwrap(struct pipe_texture *_texture)
+static INLINE struct pipe_resource *
+identity_resource_unwrap(struct pipe_resource *_resource)
{
- if(!_texture)
+ if(!_resource)
return NULL;
- return identity_texture(_texture)->texture;
+ return identity_resource(_resource)->resource;
}
static INLINE struct pipe_sampler_view *
}
-struct pipe_buffer *
-identity_buffer_create(struct identity_screen *id_screen,
- struct pipe_buffer *buffer);
-
-void
-identity_buffer_destroy(struct identity_buffer *id_buffer);
-
-struct pipe_texture *
-identity_texture_create(struct identity_screen *id_screen,
- struct pipe_texture *texture);
+struct pipe_resource *
+identity_resource_create(struct identity_screen *id_screen,
+ struct pipe_resource *resource);
void
-identity_texture_destroy(struct identity_texture *id_texture);
+identity_resource_destroy(struct identity_resource *id_resource);
struct pipe_surface *
-identity_surface_create(struct identity_texture *id_texture,
+identity_surface_create(struct identity_resource *id_resource,
struct pipe_surface *surface);
void
struct pipe_transfer *
identity_transfer_create(struct identity_context *id_context,
- struct identity_texture *id_texture,
+ struct identity_resource *id_resource,
struct pipe_transfer *transfer);
void
identity_transfer_destroy(struct identity_context *id_context,
struct identity_transfer *id_transfer);
-struct pipe_video_surface *
-identity_video_surface_create(struct identity_screen *id_screen,
- struct pipe_video_surface *video_surface);
-
-void
-identity_video_surface_destroy(struct identity_video_surface *id_video_surface);
-
#endif /* ID_OBJECTS_H */
return NULL;
}
-static struct pipe_texture *
-identity_screen_texture_create(struct pipe_screen *_screen,
- const struct pipe_texture *templat)
+static struct pipe_resource *
+identity_screen_resource_create(struct pipe_screen *_screen,
+ const struct pipe_resource *templat)
{
struct identity_screen *id_screen = identity_screen(_screen);
struct pipe_screen *screen = id_screen->screen;
- struct pipe_texture *result;
+ struct pipe_resource *result;
- result = screen->texture_create(screen,
+ result = screen->resource_create(screen,
templat);
if (result)
- return identity_texture_create(id_screen, result);
+ return identity_resource_create(id_screen, result);
return NULL;
}
-static struct pipe_texture *
-identity_screen_texture_from_handle(struct pipe_screen *_screen,
- const struct pipe_texture *templ,
+static struct pipe_resource *
+identity_screen_resource_from_handle(struct pipe_screen *_screen,
+ const struct pipe_resource *templ,
struct winsys_handle *handle)
{
struct identity_screen *id_screen = identity_screen(_screen);
struct pipe_screen *screen = id_screen->screen;
- struct pipe_texture *result;
+ struct pipe_resource *result;
/* TODO trace call */
- result = screen->texture_from_handle(screen, templ, handle);
+ result = screen->resource_from_handle(screen, templ, handle);
- result = identity_texture_create(identity_screen(_screen), result);
+ result = identity_resource_create(identity_screen(_screen), result);
return result;
}
static boolean
-identity_screen_texture_get_handle(struct pipe_screen *_screen,
- struct pipe_texture *_texture,
+identity_screen_resource_get_handle(struct pipe_screen *_screen,
+ struct pipe_resource *_texture,
struct winsys_handle *handle)
{
struct identity_screen *id_screen = identity_screen(_screen);
- struct identity_texture *id_texture = identity_texture(_texture);
+ struct identity_resource *id_resource = identity_resource(_texture);
struct pipe_screen *screen = id_screen->screen;
- struct pipe_texture *texture = id_texture->texture;
+ struct pipe_resource *texture = id_resource->resource;
/* TODO trace call */
- return screen->texture_get_handle(screen, texture, handle);
+ return screen->resource_get_handle(screen, texture, handle);
}
static void
-identity_screen_texture_destroy(struct pipe_texture *_texture)
+identity_screen_resource_destroy(struct pipe_screen *screen,
+ struct pipe_resource *_texture)
{
- identity_texture_destroy(identity_texture(_texture));
+ identity_resource_destroy(identity_resource(_texture));
}
static struct pipe_surface *
identity_screen_get_tex_surface(struct pipe_screen *_screen,
- struct pipe_texture *_texture,
+ struct pipe_resource *_texture,
unsigned face,
unsigned level,
unsigned zslice,
unsigned usage)
{
struct identity_screen *id_screen = identity_screen(_screen);
- struct identity_texture *id_texture = identity_texture(_texture);
+ struct identity_resource *id_resource = identity_resource(_texture);
struct pipe_screen *screen = id_screen->screen;
- struct pipe_texture *texture = id_texture->texture;
+ struct pipe_resource *texture = id_resource->resource;
struct pipe_surface *result;
result = screen->get_tex_surface(screen,
usage);
if (result)
- return identity_surface_create(id_texture, result);
+ return identity_surface_create(id_resource, result);
return NULL;
}
}
-static struct pipe_buffer *
-identity_screen_buffer_create(struct pipe_screen *_screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct identity_screen *id_screen = identity_screen(_screen);
- struct pipe_screen *screen = id_screen->screen;
- struct pipe_buffer *result;
-
- result = screen->buffer_create(screen,
- alignment,
- usage,
- size);
- if (result)
- return identity_buffer_create(id_screen, result);
- return NULL;
-}
-
-static struct pipe_buffer *
+static struct pipe_resource *
identity_screen_user_buffer_create(struct pipe_screen *_screen,
void *ptr,
- unsigned bytes)
+ unsigned bytes,
+ unsigned usage)
{
struct identity_screen *id_screen = identity_screen(_screen);
struct pipe_screen *screen = id_screen->screen;
- struct pipe_buffer *result;
+ struct pipe_resource *result;
result = screen->user_buffer_create(screen,
ptr,
- bytes);
+ bytes,
+ usage);
if (result)
- return identity_buffer_create(id_screen, result);
+ return identity_resource_create(id_screen, result);
return NULL;
}
-static void *
-identity_screen_buffer_map(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer,
- unsigned usage)
-{
- struct identity_screen *id_screen = identity_screen(_screen);
- struct identity_buffer *id_buffer = identity_buffer(_buffer);
- struct pipe_screen *screen = id_screen->screen;
- struct pipe_buffer *buffer = id_buffer->buffer;
-
- return screen->buffer_map(screen,
- buffer,
- usage);
-}
-
-static void *
-identity_screen_buffer_map_range(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer,
- unsigned offset,
- unsigned length,
- unsigned usage)
-{
- struct identity_screen *id_screen = identity_screen(_screen);
- struct identity_buffer *id_buffer = identity_buffer(_buffer);
- struct pipe_screen *screen = id_screen->screen;
- struct pipe_buffer *buffer = id_buffer->buffer;
-
- return screen->buffer_map_range(screen,
- buffer,
- offset,
- length,
- usage);
-}
-
-static void
-identity_screen_buffer_flush_mapped_range(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer,
- unsigned offset,
- unsigned length)
-{
- struct identity_screen *id_screen = identity_screen(_screen);
- struct identity_buffer *id_buffer = identity_buffer(_buffer);
- struct pipe_screen *screen = id_screen->screen;
- struct pipe_buffer *buffer = id_buffer->buffer;
-
- screen->buffer_flush_mapped_range(screen,
- buffer,
- offset,
- length);
-}
-
-static void
-identity_screen_buffer_unmap(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer)
-{
- struct identity_screen *id_screen = identity_screen(_screen);
- struct identity_buffer *id_buffer = identity_buffer(_buffer);
- struct pipe_screen *screen = id_screen->screen;
- struct pipe_buffer *buffer = id_buffer->buffer;
-
- screen->buffer_unmap(screen,
- buffer);
-}
-
-static void
-identity_screen_buffer_destroy(struct pipe_buffer *_buffer)
-{
- identity_buffer_destroy(identity_buffer(_buffer));
-}
-
-static struct pipe_video_surface *
-identity_screen_video_surface_create(struct pipe_screen *_screen,
- enum pipe_video_chroma_format chroma_format,
- unsigned width,
- unsigned height)
-{
- struct identity_screen *id_screen = identity_screen(_screen);
- struct pipe_screen *screen = id_screen->screen;
- struct pipe_video_surface *result;
-
- result = screen->video_surface_create(screen,
- chroma_format,
- width,
- height);
-
- if (result) {
- return identity_video_surface_create(id_screen, result);
- }
- return NULL;
-}
-
-static void
-identity_screen_video_surface_destroy(struct pipe_video_surface *_vsfc)
-{
- identity_video_surface_destroy(identity_video_surface(_vsfc));
-}
static void
identity_screen_flush_frontbuffer(struct pipe_screen *_screen,
id_screen->base.get_paramf = identity_screen_get_paramf;
id_screen->base.is_format_supported = identity_screen_is_format_supported;
id_screen->base.context_create = identity_screen_context_create;
- id_screen->base.texture_create = identity_screen_texture_create;
- id_screen->base.texture_from_handle = identity_screen_texture_from_handle;
- id_screen->base.texture_get_handle = identity_screen_texture_get_handle;
- id_screen->base.texture_destroy = identity_screen_texture_destroy;
+ id_screen->base.resource_create = identity_screen_resource_create;
+ id_screen->base.resource_from_handle = identity_screen_resource_from_handle;
+ id_screen->base.resource_get_handle = identity_screen_resource_get_handle;
+ id_screen->base.resource_destroy = identity_screen_resource_destroy;
id_screen->base.get_tex_surface = identity_screen_get_tex_surface;
id_screen->base.tex_surface_destroy = identity_screen_tex_surface_destroy;
- id_screen->base.buffer_create = identity_screen_buffer_create;
id_screen->base.user_buffer_create = identity_screen_user_buffer_create;
- if (screen->buffer_map)
- id_screen->base.buffer_map = identity_screen_buffer_map;
- if (screen->buffer_map_range)
- id_screen->base.buffer_map_range = identity_screen_buffer_map_range;
- if (screen->buffer_flush_mapped_range)
- id_screen->base.buffer_flush_mapped_range = identity_screen_buffer_flush_mapped_range;
- if (screen->buffer_unmap)
- id_screen->base.buffer_unmap = identity_screen_buffer_unmap;
- id_screen->base.buffer_destroy = identity_screen_buffer_destroy;
- if (screen->video_surface_create) {
- id_screen->base.video_surface_create = identity_screen_video_surface_create;
- }
- if (screen->video_surface_destroy) {
- id_screen->base.video_surface_destroy = identity_screen_video_surface_destroy;
- }
id_screen->base.flush_frontbuffer = identity_screen_flush_frontbuffer;
id_screen->base.fence_reference = identity_screen_fence_reference;
id_screen->base.fence_signalled = identity_screen_fence_signalled;
DEFINES += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
C_SOURCES = \
- lp_buffer.c \
lp_clear.c \
lp_context.c \
lp_draw_arrays.c \
llvmpipe = env.ConvenienceLibrary(
target = 'llvmpipe',
source = [
- 'lp_buffer.c',
'lp_clear.c',
'lp_context.c',
'lp_draw_arrays.c',
+++ /dev/null
-/**************************************************************************
- *
- * 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;
-}
+++ /dev/null
-/**************************************************************************
- *
- * 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 */
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 )
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.
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;
#include "pipe/p_context.h"
#include "util/u_prim.h"
-#include "lp_buffer.h"
#include "lp_context.h"
#include "lp_state.h"
*/
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,
* 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,
void
llvmpipe_draw_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
*/
boolean
llvmpipe_flush_texture(struct pipe_context *pipe,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
unsigned face,
unsigned level,
unsigned flush_flags,
{
unsigned referenced;
- referenced = pipe->is_texture_referenced(pipe, texture, face, level);
+ referenced = pipe->is_resource_referenced(pipe, texture, face, level);
if ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
((referenced & PIPE_REFERENCED_FOR_READ) && !read_only)) {
boolean
llvmpipe_flush_texture(struct pipe_context *pipe,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
unsigned face,
unsigned level,
unsigned flush_flags,
rast->cbuf[i].format = cbuf->texture->format;
rast->cbuf[i].width = cbuf->width;
rast->cbuf[i].height = cbuf->height;
- rast->cbuf[i].stride = llvmpipe_texture_stride(cbuf->texture, cbuf->level);
+ rast->cbuf[i].stride = llvmpipe_resource_stride(cbuf->texture, cbuf->level);
}
if (write_zstencil) {
struct pipe_surface *zsbuf = scene->fb.zsbuf;
rast->zsbuf.map = scene->zsbuf_map;
- rast->zsbuf.stride = llvmpipe_texture_stride(zsbuf->texture, zsbuf->level);
+ rast->zsbuf.stride = llvmpipe_resource_stride(zsbuf->texture, zsbuf->level);
rast->zsbuf.blocksize =
util_format_get_blocksize(zsbuf->texture->format);
}
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);
*/
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);
}
}
* 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;
lp_scene_map_buffers( struct lp_scene *scene )
{
struct pipe_surface *cbuf, *zsbuf;
+ unsigned usage;
int i;
LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
+ /* XXX: try to improve on this:
+ */
+ usage = PIPE_TRANSFER_READ_WRITE;
/* Map all color buffers
*/
for (i = 0; i < scene->fb.nr_cbufs; i++) {
cbuf = scene->fb.cbufs[i];
if (cbuf) {
- scene->cbuf_map[i] = llvmpipe_texture_map(cbuf->texture,
- cbuf->face,
- cbuf->level,
- cbuf->zslice);
+ scene->cbuf_map[i] = llvmpipe_resource_map(cbuf->texture,
+ usage,
+ cbuf->face,
+ cbuf->level,
+ cbuf->zslice);
if (!scene->cbuf_map[i])
goto fail;
}
*/
zsbuf = scene->fb.zsbuf;
if (zsbuf) {
- scene->zsbuf_map = llvmpipe_texture_map(zsbuf->texture,
- zsbuf->face,
- zsbuf->level,
- zsbuf->zslice);
+ scene->zsbuf_map = llvmpipe_resource_map(zsbuf->texture,
+ usage,
+ zsbuf->face,
+ zsbuf->level,
+ zsbuf->zslice);
if (!scene->zsbuf_map)
goto fail;
}
for (i = 0; i < scene->fb.nr_cbufs; i++) {
if (scene->cbuf_map[i]) {
struct pipe_surface *cbuf = scene->fb.cbufs[i];
- llvmpipe_texture_unmap(cbuf->texture,
+ llvmpipe_resource_unmap(cbuf->texture,
cbuf->face,
cbuf->level,
cbuf->zslice);
if (scene->zsbuf_map) {
struct pipe_surface *zsbuf = scene->fb.zsbuf;
- llvmpipe_texture_unmap(zsbuf->texture,
+ llvmpipe_resource_unmap(zsbuf->texture,
zsbuf->face,
zsbuf->level,
zsbuf->zslice);
/** 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 */
};
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 );
/**
#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"
break;
}
- if(tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
+ if(tex_usage & PIPE_BIND_RENDER_TARGET) {
if(format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN)
return FALSE;
return FALSE;
}
- if(tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED)) {
+ if(tex_usage & (PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED)) {
if(!winsys->is_displaytarget_format_supported(winsys, tex_usage, format))
return FALSE;
}
- if(tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) {
+ if(tex_usage & PIPE_BIND_DEPTH_STENCIL) {
if(format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
return FALSE;
{
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)
util_format_s3tc_init();
- 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);
#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"
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;
}
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;
/* We're referencing the texture's internal data, so save a
* reference to it.
*/
- pipe_texture_reference(&setup->fs.current_tex[i], tex);
+ pipe_resource_reference(&setup->fs.current_tex[i], tex);
if (!lp_tex->dt) {
/* regular texture - setup array of mipmap level pointers */
struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen);
struct sw_winsys *winsys = screen->winsys;
jit_tex->data[0] = winsys->displaytarget_map(winsys, lp_tex->dt,
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ);
jit_tex->row_stride[0] = lp_tex->stride[0];
assert(jit_tex->data[0]);
}
* 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;
/* 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;
}
}
}
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? */
reset_context( setup );
for (i = 0; i < Elements(setup->fs.current_tex); i++) {
- pipe_texture_reference(&setup->fs.current_tex[i], NULL);
+ pipe_resource_reference(&setup->fs.current_tex[i], NULL);
}
- pipe_buffer_reference(&setup->constants.current, NULL);
+ pipe_resource_reference(&setup->constants.current, NULL);
/* free the scenes in the 'empty' queue */
while (1) {
unsigned src_index; /* where to find values in incoming vertices */
};
-struct pipe_texture;
+struct pipe_resource;
struct pipe_surface;
-struct pipe_buffer;
struct pipe_blend_color;
struct pipe_screen;
struct pipe_framebuffer_state;
void
lp_setup_set_fs_constants(struct lp_setup_context *setup,
- struct pipe_buffer *buffer);
+ struct pipe_resource *buffer);
void
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,
const struct lp_rast_state *stored; /**< what's in the scene */
struct lp_rast_state current; /**< currently set state */
- struct pipe_texture *current_tex[PIPE_MAX_SAMPLERS];
+ struct pipe_resource *current_tex[PIPE_MAX_SAMPLERS];
} fs;
/** fragment shader constants */
struct {
- struct pipe_buffer *current;
+ struct pipe_resource *current;
unsigned stored_size;
const void *stored_data;
} constants;
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 *);
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
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,
#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"
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);
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,
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);
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
- pipe_texture_reference(&view->texture, texture);
+ pipe_resource_reference(&view->texture, texture);
view->context = pipe;
}
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);
}
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_transfer.h"
#include "lp_context.h"
#include "lp_screen.h"
#include "lp_flush.h"
#include "lp_texture.h"
+#include "lp_setup.h"
#include "lp_tile_size.h"
#include "state_tracker/sw_winsys.h"
* Simple, maximally packed layout.
*/
static boolean
-llvmpipe_texture_layout(struct llvmpipe_screen *screen,
- struct llvmpipe_texture *lpt)
+llvmpipe_resource_layout(struct llvmpipe_screen *screen,
+ struct llvmpipe_resource *lpt)
{
- struct pipe_texture *pt = &lpt->base;
+ struct pipe_resource *pt = &lpt->base;
unsigned level;
unsigned width = pt->width0;
unsigned height = pt->height0;
static boolean
llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen,
- struct llvmpipe_texture *lpt)
+ struct llvmpipe_resource *lpt)
{
struct sw_winsys *winsys = screen->winsys;
unsigned height = align(lpt->base.height0, TILE_SIZE);
lpt->dt = winsys->displaytarget_create(winsys,
- lpt->base.tex_usage,
+ lpt->base.bind,
lpt->base.format,
width, height,
16,
}
-static struct pipe_texture *
-llvmpipe_texture_create(struct pipe_screen *_screen,
- const struct pipe_texture *templat)
+static struct pipe_resource *
+llvmpipe_resource_create(struct pipe_screen *_screen,
+ const struct pipe_resource *templat)
{
struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
- struct llvmpipe_texture *lpt = CALLOC_STRUCT(llvmpipe_texture);
+ struct llvmpipe_resource *lpt = CALLOC_STRUCT(llvmpipe_resource);
if (!lpt)
return NULL;
pipe_reference_init(&lpt->base.reference, 1);
lpt->base.screen = &screen->base;
- if (lpt->base.tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED)) {
+ if (lpt->base.bind & (PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED)) {
if (!llvmpipe_displaytarget_layout(screen, lpt))
goto fail;
}
else {
- if (!llvmpipe_texture_layout(screen, lpt))
+ if (!llvmpipe_resource_layout(screen, lpt))
goto fail;
}
-
+
return &lpt->base;
fail:
static void
-llvmpipe_texture_destroy(struct pipe_texture *pt)
+llvmpipe_resource_destroy(struct pipe_screen *pscreen,
+ struct pipe_resource *pt)
{
- struct llvmpipe_screen *screen = llvmpipe_screen(pt->screen);
- struct llvmpipe_texture *lpt = llvmpipe_texture(pt);
+ struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
+ struct llvmpipe_resource *lpt = llvmpipe_resource(pt);
if (lpt->dt) {
/* display target */
struct sw_winsys *winsys = screen->winsys;
winsys->displaytarget_destroy(winsys, lpt->dt);
}
- else {
+ else if (!lpt->userBuffer) {
/* regular texture */
align_free(lpt->data);
}
* Map a texture. Without any synchronization.
*/
void *
-llvmpipe_texture_map(struct pipe_texture *texture,
- unsigned face,
- unsigned level,
- unsigned zslice)
+llvmpipe_resource_map(struct pipe_resource *texture,
+ unsigned usage,
+ unsigned face,
+ unsigned level,
+ unsigned zslice)
{
- struct llvmpipe_texture *lpt = llvmpipe_texture(texture);
+ struct llvmpipe_resource *lpt = llvmpipe_resource(texture);
uint8_t *map;
if (lpt->dt) {
/* display target */
struct llvmpipe_screen *screen = llvmpipe_screen(texture->screen);
struct sw_winsys *winsys = screen->winsys;
- const unsigned usage = PIPE_BUFFER_USAGE_CPU_READ_WRITE;
assert(face == 0);
assert(level == 0);
/* XXX shouldn't that rather be
tex_height = align(u_minify(texture->height0, level), 2)
- to account for alignment done in llvmpipe_texture_layout ?
+ to account for alignment done in llvmpipe_resource_layout ?
*/
if (texture->target == PIPE_TEXTURE_CUBE) {
unsigned tex_height = u_minify(texture->height0, level);
* Unmap a texture. Without any synchronization.
*/
void
-llvmpipe_texture_unmap(struct pipe_texture *texture,
+llvmpipe_resource_unmap(struct pipe_resource *texture,
unsigned face,
unsigned level,
unsigned zslice)
{
- struct llvmpipe_texture *lpt = llvmpipe_texture(texture);
+ struct llvmpipe_resource *lpt = llvmpipe_resource(texture);
if (lpt->dt) {
/* display target */
}
-static struct pipe_texture *
-llvmpipe_texture_from_handle(struct pipe_screen *screen,
- const struct pipe_texture *template,
- struct winsys_handle *whandle)
+static struct pipe_resource *
+llvmpipe_resource_from_handle(struct pipe_screen *screen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle)
{
struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
- struct llvmpipe_texture *lpt = CALLOC_STRUCT(llvmpipe_texture);
+ struct llvmpipe_resource *lpt = CALLOC_STRUCT(llvmpipe_resource);
if (!lpt)
return NULL;
static boolean
-llvmpipe_texture_get_handle(struct pipe_screen *screen,
- struct pipe_texture *pt,
+llvmpipe_resource_get_handle(struct pipe_screen *screen,
+ struct pipe_resource *pt,
struct winsys_handle *whandle)
{
struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
- struct llvmpipe_texture *lpt = llvmpipe_texture(pt);
+ struct llvmpipe_resource *lpt = llvmpipe_resource(pt);
assert(lpt->dt);
if (!lpt->dt)
static struct pipe_surface *
llvmpipe_get_tex_surface(struct pipe_screen *screen,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
unsigned face, unsigned level, unsigned zslice,
unsigned usage)
{
- struct llvmpipe_texture *lpt = llvmpipe_texture(pt);
struct pipe_surface *ps;
assert(level <= pt->last_level);
ps = CALLOC_STRUCT(pipe_surface);
if (ps) {
pipe_reference_init(&ps->reference, 1);
- pipe_texture_reference(&ps->texture, pt);
+ pipe_resource_reference(&ps->texture, pt);
ps->format = pt->format;
ps->width = u_minify(pt->width0, level);
ps->height = u_minify(pt->height0, level);
ps->usage = usage;
- /* Because we are llvmpipe, anything that the state tracker
- * thought was going to be done with the GPU will actually get
- * done with the CPU. Let's adjust the flags to take that into
- * account.
- */
- if (ps->usage & PIPE_BUFFER_USAGE_GPU_WRITE) {
- /* GPU_WRITE means "render" and that can involve reads (blending) */
- ps->usage |= PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_CPU_READ;
- }
-
- if (ps->usage & PIPE_BUFFER_USAGE_GPU_READ)
- ps->usage |= PIPE_BUFFER_USAGE_CPU_READ;
-
- if (ps->usage & (PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_GPU_WRITE)) {
- /* Mark the surface as dirty. */
- lpt->timestamp++;
- llvmpipe_screen(screen)->timestamp++;
- }
-
ps->face = face;
ps->level = level;
ps->zslice = zslice;
* where it would happen. For llvmpipe, nothing to do.
*/
assert(surf->texture);
- pipe_texture_reference(&surf->texture, NULL);
+ pipe_resource_reference(&surf->texture, NULL);
FREE(surf);
}
static struct pipe_transfer *
-llvmpipe_get_tex_transfer(struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
+llvmpipe_get_transfer(struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
{
- struct llvmpipe_texture *lptex = llvmpipe_texture(texture);
+ struct llvmpipe_resource *lptex = llvmpipe_resource(resource);
struct llvmpipe_transfer *lpt;
- assert(texture);
- assert(level <= texture->last_level);
+ assert(resource);
+ assert(sr.level <= resource->last_level);
lpt = CALLOC_STRUCT(llvmpipe_transfer);
if (lpt) {
struct pipe_transfer *pt = &lpt->base;
- pipe_texture_reference(&pt->texture, texture);
- pt->x = x;
- pt->y = y;
- pt->width = align(w, TILE_SIZE);
- pt->height = align(h, TILE_SIZE);
- pt->stride = lptex->stride[level];
+ pipe_resource_reference(&pt->resource, resource);
+ pt->box = *box;
+ pt->stride = lptex->stride[sr.level];
pt->usage = usage;
- pt->face = face;
- pt->level = level;
- pt->zslice = zslice;
return pt;
}
static void
-llvmpipe_tex_transfer_destroy(struct pipe_context *pipe,
+llvmpipe_transfer_destroy(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
/* Effectively do the texture_update work here - if texture images
* needed post-processing to put them into hardware layout, this is
* where it would happen. For llvmpipe, nothing to do.
*/
- assert (transfer->texture);
- pipe_texture_reference(&transfer->texture, NULL);
+ assert (transfer->resource);
+ pipe_resource_reference(&transfer->resource, NULL);
FREE(transfer);
}
{
struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
ubyte *map;
- struct llvmpipe_texture *lpt;
+ struct llvmpipe_resource *lpt;
enum pipe_format format;
- assert(transfer->texture);
- lpt = llvmpipe_texture(transfer->texture);
+ assert(transfer->resource);
+ lpt = llvmpipe_resource(transfer->resource);
format = lpt->base.format;
/*
* context if necessary.
*/
llvmpipe_flush_texture(pipe,
- transfer->texture, transfer->face, transfer->level,
+ transfer->resource,
+ transfer->sr.face,
+ transfer->sr.level,
0, /* flush_flags */
!(transfer->usage & PIPE_TRANSFER_WRITE), /* read_only */
TRUE, /* cpu_access */
FALSE); /* do_not_flush */
- map = llvmpipe_texture_map(transfer->texture,
- transfer->face, transfer->level, transfer->zslice);
+ map = llvmpipe_resource_map(transfer->resource,
+ transfer->usage,
+ transfer->sr.face,
+ transfer->sr.level,
+ transfer->box.z);
/* May want to different things here depending on read/write nature
* of the map:
}
map +=
- transfer->y / util_format_get_blockheight(format) * transfer->stride +
- transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
+ transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
return map;
}
llvmpipe_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
- assert(transfer->texture);
+ assert(transfer->resource);
+
+ llvmpipe_resource_unmap(transfer->resource,
+ transfer->sr.face,
+ transfer->sr.level,
+ transfer->box.z);
+}
+
+static unsigned int
+llvmpipe_is_resource_referenced( struct pipe_context *pipe,
+ struct pipe_resource *presource,
+ unsigned face, unsigned level)
+{
+ struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
+
+ if (presource->target == PIPE_BUFFER)
+ return PIPE_UNREFERENCED;
+
+ return lp_setup_is_resource_referenced(llvmpipe->setup, presource);
+}
+
+
+
+/**
+ * Create buffer which wraps user-space data.
+ */
+static struct pipe_resource *
+llvmpipe_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind_flags)
+{
+ struct llvmpipe_resource *buffer;
+
+ buffer = CALLOC_STRUCT(llvmpipe_resource);
+ if(!buffer)
+ return NULL;
- llvmpipe_texture_unmap(transfer->texture,
- transfer->face, transfer->level, transfer->zslice);
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->base.screen = screen;
+ buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */
+ buffer->base.bind = bind_flags;
+ buffer->base._usage = PIPE_USAGE_IMMUTABLE;
+ buffer->base.flags = 0;
+ buffer->base.width0 = bytes;
+ buffer->base.height0 = 1;
+ buffer->base.depth0 = 1;
+ buffer->userBuffer = TRUE;
+ buffer->data = ptr;
+
+ return &buffer->base;
}
void
-llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen)
+llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen)
{
- screen->texture_create = llvmpipe_texture_create;
- screen->texture_destroy = llvmpipe_texture_destroy;
- screen->texture_from_handle = llvmpipe_texture_from_handle;
- screen->texture_get_handle = llvmpipe_texture_get_handle;
+ screen->resource_create = llvmpipe_resource_create;
+ screen->resource_destroy = llvmpipe_resource_destroy;
+ screen->resource_from_handle = llvmpipe_resource_from_handle;
+ screen->resource_get_handle = llvmpipe_resource_get_handle;
+ screen->user_buffer_create = llvmpipe_user_buffer_create;
screen->get_tex_surface = llvmpipe_get_tex_surface;
screen->tex_surface_destroy = llvmpipe_tex_surface_destroy;
void
-llvmpipe_init_context_texture_funcs(struct pipe_context *pipe)
+llvmpipe_init_context_resource_funcs(struct pipe_context *pipe)
{
- pipe->get_tex_transfer = llvmpipe_get_tex_transfer;
- pipe->tex_transfer_destroy = llvmpipe_tex_transfer_destroy;
+ pipe->get_transfer = llvmpipe_get_transfer;
+ pipe->transfer_destroy = llvmpipe_transfer_destroy;
pipe->transfer_map = llvmpipe_transfer_map;
pipe->transfer_unmap = llvmpipe_transfer_unmap;
+ pipe->is_resource_referenced = llvmpipe_is_resource_referenced;
+
+ pipe->transfer_flush_region = u_default_transfer_flush_region;
+ pipe->transfer_inline_write = u_default_transfer_inline_write;
}
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];
/**
- * Display target, for textures with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET
+ * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET
* usage.
*/
struct sw_displaytarget *dt;
*/
void *data;
+ boolean userBuffer; /** Is this a user-space buffer? */
unsigned timestamp;
};
/** 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;
}
}
+void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen);
+void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe);
+
static INLINE unsigned
-llvmpipe_texture_stride(struct pipe_texture *texture,
+llvmpipe_resource_stride(struct pipe_resource *texture,
unsigned level)
{
- struct llvmpipe_texture *lpt = llvmpipe_texture(texture);
+ struct llvmpipe_resource *lpt = llvmpipe_resource(texture);
assert(level < LP_MAX_TEXTURE_2D_LEVELS);
return lpt->stride[level];
}
void *
-llvmpipe_texture_map(struct pipe_texture *texture,
- unsigned face,
- unsigned level,
- unsigned zslice);
+llvmpipe_resource_map(struct pipe_resource *texture,
+ unsigned usage,
+ unsigned face,
+ unsigned level,
+ unsigned zslice);
void
-llvmpipe_texture_unmap(struct pipe_texture *texture,
+llvmpipe_resource_unmap(struct pipe_resource *texture,
unsigned face,
unsigned level,
unsigned zslice);
-extern void
-llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen);
-
-extern void
-llvmpipe_init_context_texture_funcs(struct pipe_context *pipe);
#endif /* LP_TEXTURE_H */
LIBNAME = nouveau
-C_SOURCES = nouveau_screen.c \
- nouveau_context.c
+LIBRARY_INCLUDES = \
+ -I$(TOP)/src/gallium/drivers/nouveau/include
+
+C_SOURCES = nouveau_screen.c
include ../../Makefile.template
+++ /dev/null
-#include "pipe/p_defines.h"
-#include "pipe/p_context.h"
-
-#include "nouveau/nouveau_screen.h"
-#include "nouveau/nouveau_context.h"
-
-#include "nouveau/nouveau_bo.h"
-
-static unsigned int
-nouveau_reference_flags(struct nouveau_bo *bo)
-{
- uint32_t bo_flags;
- int flags = 0;
-
- bo_flags = nouveau_bo_pending(bo);
- if (bo_flags & NOUVEAU_BO_RD)
- flags |= PIPE_REFERENCED_FOR_READ;
- if (bo_flags & NOUVEAU_BO_WR)
- flags |= PIPE_REFERENCED_FOR_WRITE;
-
- return flags;
-}
-
-unsigned int
-nouveau_is_texture_referenced(struct pipe_context *pipe,
- struct pipe_texture *pt,
- unsigned face, unsigned level)
-{
- struct nouveau_miptree *mt = nouveau_miptree(pt);
-
- return nouveau_reference_flags(mt->bo);
-}
-
-unsigned int
-nouveau_is_buffer_referenced(struct pipe_context *pipe, struct pipe_buffer *pb)
-{
- struct nouveau_bo *bo = nouveau_bo(pb);
-
- return nouveau_reference_flags(bo);
-}
-
+++ /dev/null
-#ifndef __NOUVEAU_CONTEXT_H__
-#define __NOUVEAU_CONTEXT_H__
-
-unsigned int
-nouveau_is_texture_referenced(struct pipe_context *, struct pipe_texture *,
- unsigned face, unsigned level);
-
-unsigned int
-nouveau_is_buffer_referenced(struct pipe_context *, struct pipe_buffer *);
-
-#endif
/* XXX this should go away */
#include "state_tracker/drm_api.h"
+#include "util/u_simple_screen.h"
static const char *
nouveau_screen_get_name(struct pipe_screen *pscreen)
return "nouveau";
}
-static struct pipe_buffer *
-nouveau_screen_bo_skel(struct pipe_screen *pscreen, struct nouveau_bo *bo,
- unsigned alignment, unsigned usage, unsigned size)
-{
- struct pipe_buffer *pb;
-
- pb = CALLOC(1, sizeof(struct pipe_buffer)+sizeof(struct nouveau_bo *));
- if (!pb) {
- nouveau_bo_ref(NULL, &bo);
- return NULL;
- }
- pipe_reference_init(&pb->reference, 1);
- pb->screen = pscreen;
- pb->alignment = alignment;
- pb->usage = usage;
- pb->size = size;
- *(struct nouveau_bo **)(pb + 1) = bo;
- return pb;
-}
-static struct pipe_buffer *
+struct nouveau_bo *
nouveau_screen_bo_new(struct pipe_screen *pscreen, unsigned alignment,
- unsigned usage, unsigned size)
+ unsigned usage, unsigned bind, unsigned size)
{
struct nouveau_device *dev = nouveau_screen(pscreen)->device;
struct nouveau_bo *bo = NULL;
uint32_t flags = NOUVEAU_BO_MAP, tile_mode = 0, tile_flags = 0;
int ret;
- if (usage & NOUVEAU_BUFFER_USAGE_TRANSFER)
- flags |= NOUVEAU_BO_GART;
- else
- if (usage & PIPE_BUFFER_USAGE_VERTEX) {
+ if (bind & PIPE_BIND_VERTEX_BUFFER) {
if (pscreen->get_param(pscreen, NOUVEAU_CAP_HW_VTXBUF))
flags |= NOUVEAU_BO_GART;
} else
- if (usage & PIPE_BUFFER_USAGE_INDEX) {
+ if (usage & PIPE_BIND_INDEX_BUFFER) {
if (pscreen->get_param(pscreen, NOUVEAU_CAP_HW_IDXBUF))
flags |= NOUVEAU_BO_GART;
}
- if (usage & PIPE_BUFFER_USAGE_PIXEL) {
- if (usage & NOUVEAU_BUFFER_USAGE_TEXTURE)
+ if (bind & (PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_DEPTH_STENCIL |
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SAMPLER_VIEW))
+ {
+ /* TODO: this may be incorrect or suboptimal */
+ if (!(bind & PIPE_BIND_SCANOUT))
flags |= NOUVEAU_BO_GART;
- if (!(usage & PIPE_BUFFER_USAGE_CPU_READ_WRITE))
+ if (usage != PIPE_USAGE_DYNAMIC)
flags |= NOUVEAU_BO_VRAM;
if (dev->chipset == 0x50 || dev->chipset >= 0x80) {
- if (usage & NOUVEAU_BUFFER_USAGE_ZETA)
+ if (bind & PIPE_BIND_DEPTH_STENCIL)
tile_flags = 0x2800;
else
tile_flags = 0x7000;
if (ret)
return NULL;
- return nouveau_screen_bo_skel(pscreen, bo, alignment, usage, size);
+ return bo;
}
-static struct pipe_buffer *
+struct nouveau_bo *
nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes)
{
struct nouveau_device *dev = nouveau_screen(pscreen)->device;
if (ret)
return NULL;
- return nouveau_screen_bo_skel(pscreen, bo, 0, 0, bytes);
+ return bo;
}
-static inline uint32_t
-nouveau_screen_map_flags(unsigned pipe)
+void *
+nouveau_screen_bo_map(struct pipe_screen *pscreen,
+ struct nouveau_bo *bo,
+ unsigned map_flags)
{
- uint32_t flags = 0;
-
- if (pipe & PIPE_BUFFER_USAGE_CPU_READ)
- flags |= NOUVEAU_BO_RD;
- if (pipe & PIPE_BUFFER_USAGE_CPU_WRITE)
- flags |= NOUVEAU_BO_WR;
- if (pipe & PIPE_BUFFER_USAGE_DISCARD)
- flags |= NOUVEAU_BO_INVAL;
- if (pipe & PIPE_BUFFER_USAGE_DONTBLOCK)
- flags |= NOUVEAU_BO_NOWAIT;
- else
- if (pipe & PIPE_BUFFER_USAGE_UNSYNCHRONIZED)
- flags |= NOUVEAU_BO_NOSYNC;
-
- return flags;
-}
-
-static void *
-nouveau_screen_bo_map(struct pipe_screen *pscreen, struct pipe_buffer *pb,
- unsigned usage)
-{
- struct nouveau_bo *bo = nouveau_bo(pb);
- struct nouveau_screen *nscreen = nouveau_screen(pscreen);
int ret;
- if (nscreen->pre_pipebuffer_map_callback) {
- ret = nscreen->pre_pipebuffer_map_callback(pscreen, pb, usage);
- if (ret) {
- debug_printf("pre_pipebuffer_map_callback failed %d\n",
- ret);
- return NULL;
- }
- }
-
- ret = nouveau_bo_map(bo, nouveau_screen_map_flags(usage));
+ ret = nouveau_bo_map(bo, map_flags);
if (ret) {
debug_printf("map failed: %d\n", ret);
return NULL;
return bo->map;
}
-static void *
-nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct pipe_buffer *pb,
- unsigned offset, unsigned length, unsigned usage)
+void *
+nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct nouveau_bo *bo,
+ unsigned offset, unsigned length, unsigned flags)
{
- struct nouveau_bo *bo = nouveau_bo(pb);
- struct nouveau_screen *nscreen = nouveau_screen(pscreen);
- uint32_t flags = nouveau_screen_map_flags(usage);
int ret;
- if (nscreen->pre_pipebuffer_map_callback) {
- ret = nscreen->pre_pipebuffer_map_callback(pscreen, pb, usage);
- if (ret) {
- debug_printf("pre_pipebuffer_map_callback failed %d\n",
- ret);
- return NULL;
- }
- }
-
ret = nouveau_bo_map_range(bo, offset, length, flags);
if (ret) {
nouveau_bo_unmap(bo);
return (char *)bo->map - offset; /* why gallium? why? */
}
-static void
-nouveau_screen_bo_map_flush(struct pipe_screen *pscreen, struct pipe_buffer *pb,
- unsigned offset, unsigned length)
+void
+nouveau_screen_bo_map_flush_range(struct pipe_screen *pscreen, struct nouveau_bo *bo,
+ unsigned offset, unsigned length)
{
- struct nouveau_bo *bo = nouveau_bo(pb);
-
nouveau_bo_map_flush(bo, offset, length);
}
-static void
-nouveau_screen_bo_unmap(struct pipe_screen *pscreen, struct pipe_buffer *pb)
+void
+nouveau_screen_bo_unmap(struct pipe_screen *pscreen, struct nouveau_bo *bo)
{
- struct nouveau_bo *bo = nouveau_bo(pb);
-
nouveau_bo_unmap(bo);
}
-static void
-nouveau_screen_bo_del(struct pipe_buffer *pb)
+void
+nouveau_screen_bo_release(struct pipe_screen *pscreen, struct nouveau_bo *bo)
{
- struct nouveau_bo *bo = nouveau_bo(pb);
-
nouveau_bo_ref(NULL, &bo);
- FREE(pb);
}
static void
}
-/*
- * Both texture_{from|get}_handle use drm api defines directly which they
- * shouldn't do. The problem is that from|get are pipe functions and as
- * such they should be defined in the pipe level. If nouveau had a propper
- * winsys interface we would have added from|get to that interface using
- * the winsys_handle struct as done with other drivers. However this code
- * calls directly into the libdrm_nouveau.so functions (nouveau_bo_*). So
- * we need to translate the handle into something they understand.
- */
-static struct pipe_texture *
-nouveau_screen_texture_from_handle(struct pipe_screen *pscreen,
- const struct pipe_texture *templ,
- struct winsys_handle *whandle)
+struct nouveau_bo *
+nouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
+ struct winsys_handle *whandle,
+ unsigned *out_stride)
{
struct nouveau_device *dev = nouveau_screen(pscreen)->device;
- struct pipe_texture *pt;
- struct pipe_buffer *pb;
+ struct nouveau_bo *bo = 0;
int ret;
-
- pb = CALLOC(1, sizeof(struct pipe_buffer) + sizeof(struct nouveau_bo*));
- if (!pb)
- return NULL;
-
- ret = nouveau_bo_handle_ref(dev, whandle->handle, (struct nouveau_bo**)(pb+1));
+
+ ret = nouveau_bo_handle_ref(dev, whandle->handle, &bo);
if (ret) {
debug_printf("%s: ref name 0x%08x failed with %d\n",
__func__, whandle->handle, ret);
- FREE(pb);
return NULL;
}
- pipe_reference_init(&pb->reference, 1);
- pb->screen = pscreen;
- pb->alignment = 0;
- pb->usage = PIPE_BUFFER_USAGE_GPU_READ_WRITE |
- PIPE_BUFFER_USAGE_CPU_READ_WRITE;
- pb->size = nouveau_bo(pb)->size;
- pt = nouveau_screen(pscreen)->texture_blanket(pscreen, templ,
- &whandle->stride, pb);
- pipe_buffer_reference(&pb, NULL);
- return pt;
+ *out_stride = whandle->stride;
+ return bo;
}
-static boolean
-nouveau_screen_texture_get_handle(struct pipe_screen *pscreen,
- struct pipe_texture *pt,
- struct winsys_handle *whandle)
-{
- struct nouveau_miptree *mt = nouveau_miptree(pt);
-
- if (!mt || !mt->bo)
- return false;
- whandle->stride = util_format_get_stride(mt->base.format, mt->base.width0);
+boolean
+nouveau_screen_bo_get_handle(struct pipe_screen *pscreen,
+ struct nouveau_bo *bo,
+ unsigned stride,
+ struct winsys_handle *whandle)
+{
+ whandle->stride = stride;
if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
- return nouveau_bo_handle_get(mt->bo, &whandle->handle) == 0;
+ return nouveau_bo_handle_get(bo, &whandle->handle) == 0;
} else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
- whandle->handle = mt->bo->handle;
+ whandle->handle = bo->handle;
return TRUE;
} else {
return FALSE;
}
}
+
+unsigned int
+nouveau_reference_flags(struct nouveau_bo *bo)
+{
+ uint32_t bo_flags;
+ int flags = 0;
+
+ bo_flags = nouveau_bo_pending(bo);
+ if (bo_flags & NOUVEAU_BO_RD)
+ flags |= PIPE_REFERENCED_FOR_READ;
+ if (bo_flags & NOUVEAU_BO_WR)
+ flags |= PIPE_REFERENCED_FOR_WRITE;
+
+ return flags;
+}
+
+
+
+
+
int
nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev)
{
pscreen->get_name = nouveau_screen_get_name;
pscreen->get_vendor = nouveau_screen_get_vendor;
- pscreen->buffer_create = nouveau_screen_bo_new;
- pscreen->user_buffer_create = nouveau_screen_bo_user;
- pscreen->buffer_map = nouveau_screen_bo_map;
- pscreen->buffer_map_range = nouveau_screen_bo_map_range;
- pscreen->buffer_flush_mapped_range = nouveau_screen_bo_map_flush;
- pscreen->buffer_unmap = nouveau_screen_bo_unmap;
- pscreen->buffer_destroy = nouveau_screen_bo_del;
-
pscreen->fence_reference = nouveau_screen_fence_ref;
pscreen->fence_signalled = nouveau_screen_fence_signalled;
pscreen->fence_finish = nouveau_screen_fence_finish;
- pscreen->texture_from_handle = nouveau_screen_texture_from_handle;
- pscreen->texture_get_handle = nouveau_screen_texture_get_handle;
-
return 0;
}
struct pipe_screen base;
struct nouveau_device *device;
struct nouveau_channel *channel;
-
- /**
- * Create a new texture object, using the given template info, but on top of
- * existing memory.
- *
- * It is assumed that the buffer data is layed out according to the expected
- * by the hardware. NULL will be returned if any inconsistency is found.
- */
- struct pipe_texture * (*texture_blanket)(struct pipe_screen *,
- const struct pipe_texture *templat,
- const unsigned *stride,
- struct pipe_buffer *buffer);
-
- int (*pre_pipebuffer_map_callback) (struct pipe_screen *pscreen,
- struct pipe_buffer *pb, unsigned usage);
};
static inline struct nouveau_screen *
return (struct nouveau_screen *)pscreen;
}
-static inline struct nouveau_bo *
-nouveau_bo(struct pipe_buffer *pb)
-{
- return pb ? *(struct nouveau_bo **)(pb + 1) : NULL;
-}
+
+
+/* Not really sure if this is needed, or whether the individual
+ * drivers are happy to talk to the bo functions themselves. In a way
+ * this is what we'd expect from a regular winsys interface.
+ */
+struct nouveau_bo *
+nouveau_screen_bo_new(struct pipe_screen *pscreen, unsigned alignment,
+ unsigned usage, unsigned bind, unsigned size);
+struct nouveau_bo *
+nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes);
+void *
+nouveau_screen_bo_map(struct pipe_screen *pscreen,
+ struct nouveau_bo *pb,
+ unsigned usage);
+void *
+nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct nouveau_bo *bo,
+ unsigned offset, unsigned length, unsigned usage);
+void
+nouveau_screen_bo_map_flush_range(struct pipe_screen *pscreen, struct nouveau_bo *bo,
+ unsigned offset, unsigned length);
+void
+nouveau_screen_bo_unmap(struct pipe_screen *pscreen, struct nouveau_bo *bo);
+void
+nouveau_screen_bo_release(struct pipe_screen *pscreen, struct nouveau_bo *bo);
+
+boolean
+nouveau_screen_bo_get_handle(struct pipe_screen *pscreen,
+ struct nouveau_bo *bo,
+ unsigned stride,
+ struct winsys_handle *whandle);
+struct nouveau_bo *
+nouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
+ struct winsys_handle *whandle,
+ unsigned *out_stride);
+
+unsigned int
+nouveau_reference_flags(struct nouveau_bo *bo);
+
+
int nouveau_screen_init(struct nouveau_screen *, struct nouveau_device *);
void nouveau_screen_fini(struct nouveau_screen *);
-struct nouveau_miptree {
- struct pipe_texture base;
- struct nouveau_bo *bo;
-};
-static inline struct nouveau_miptree *
-nouveau_miptree(struct pipe_texture *pt)
-{
- return (struct nouveau_miptree *)pt;
-}
+
#endif
unsigned p_start;
unsigned p_end;
- int repeat_first:1;
- int close_first:1;
- int edgeflag_off:1;
+ uint repeat_first:1;
+ uint close_first:1;
+ uint edgeflag_off:1;
};
static inline void
#define NOUVEAU_WINSYS_H
#include <stdint.h>
-#include "util/u_simple_screen.h"
#include "pipe/p_defines.h"
#include "nouveau/nouveau_bo.h"
#define NOUVEAU_CAP_HW_VTXBUF (0xbeef0000)
#define NOUVEAU_CAP_HW_IDXBUF (0xbeef0001)
-#define NOUVEAU_TEXTURE_USAGE_LINEAR (1 << 16)
-
-#define NOUVEAU_BUFFER_USAGE_TEXTURE (1 << 16)
-#define NOUVEAU_BUFFER_USAGE_ZETA (1 << 17)
-#define NOUVEAU_BUFFER_USAGE_TRANSFER (1 << 18)
-
-/* use along with GPU_WRITE for 2D-only writes */
-#define NOUVEAU_BUFFER_USAGE_NO_RENDER (1 << 19)
+static inline uint32_t
+nouveau_screen_transfer_flags(unsigned pipe)
+{
+ uint32_t flags = 0;
+
+ if (pipe & PIPE_TRANSFER_READ)
+ flags |= NOUVEAU_BO_RD;
+ if (pipe & PIPE_TRANSFER_WRITE)
+ flags |= NOUVEAU_BO_WR;
+ if (pipe & PIPE_TRANSFER_DISCARD)
+ flags |= NOUVEAU_BO_INVAL;
+ if (pipe & PIPE_TRANSFER_DONTBLOCK)
+ flags |= NOUVEAU_BO_NOWAIT;
+ else
+ if (pipe & PIPE_TRANSFER_UNSYNCHRONIZED)
+ flags |= NOUVEAU_BO_NOSYNC;
+
+ return flags;
+}
extern struct pipe_screen *
nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *);
LIBNAME = nv50
C_SOURCES = \
+ nv50_buffer.c \
nv50_clear.c \
nv50_context.c \
nv50_draw.c \
nv50_miptree.c \
nv50_query.c \
nv50_program.c \
+ nv50_resource.c \
nv50_screen.c \
nv50_state.c \
nv50_state_validate.c \
--- /dev/null
+
+#include "util/u_inlines.h"
+#include "util/u_memory.h"
+#include "util/u_math.h"
+
+#include "nouveau/nouveau_screen.h"
+#include "nouveau/nouveau_winsys.h"
+#include "nv50_resource.h"
+
+
+
+static void nv50_buffer_destroy(struct pipe_screen *pscreen,
+ struct pipe_resource *presource)
+{
+ struct nv50_resource *buffer = nv50_resource(presource);
+
+ nouveau_screen_bo_release(pscreen, buffer->bo);
+ FREE(buffer);
+}
+
+
+
+
+/* Utility functions for transfer create/destroy are hooked in and
+ * just record the arguments to those functions.
+ */
+static void *
+nv50_buffer_transfer_map( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ struct nv50_resource *buffer = nv50_resource(transfer->resource);
+ uint8_t *map;
+
+ map = nouveau_screen_bo_map_range( pipe->screen,
+ buffer->bo,
+ transfer->box.x,
+ transfer->box.width,
+ nouveau_screen_transfer_flags(transfer->usage) );
+ if (map == NULL)
+ return NULL;
+
+ return map + transfer->box.x;
+}
+
+
+
+static void nv50_buffer_transfer_flush_region( struct pipe_context *pipe,
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box)
+{
+ struct nv50_resource *buffer = nv50_resource(transfer->resource);
+
+ nouveau_screen_bo_map_flush_range(pipe->screen,
+ buffer->bo,
+ transfer->box.x + box->x,
+ box->width);
+}
+
+static void nv50_buffer_transfer_unmap( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ struct nv50_resource *buffer = nv50_resource(transfer->resource);
+
+ nouveau_screen_bo_unmap(pipe->screen, buffer->bo);
+}
+
+
+
+
+struct u_resource_vtbl nv50_buffer_vtbl =
+{
+ u_default_resource_get_handle, /* get_handle */
+ nv50_buffer_destroy, /* resource_destroy */
+ NULL, /* is_resource_referenced */
+ u_default_get_transfer, /* get_transfer */
+ u_default_transfer_destroy, /* transfer_destroy */
+ nv50_buffer_transfer_map, /* transfer_map */
+ nv50_buffer_transfer_flush_region, /* transfer_flush_region */
+ nv50_buffer_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+
+struct pipe_resource *
+nv50_buffer_create(struct pipe_screen *pscreen,
+ const struct pipe_resource *template)
+{
+ struct nv50_resource *buffer;
+
+ buffer = CALLOC_STRUCT(nv50_resource);
+ if (!buffer)
+ return NULL;
+
+ buffer->base = *template;
+ buffer->vtbl = &nv50_buffer_vtbl;
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->base.screen = pscreen;
+
+ buffer->bo = nouveau_screen_bo_new(pscreen,
+ 16,
+ buffer->base._usage,
+ buffer->base.bind,
+ buffer->base.width0);
+
+ if (buffer->bo == NULL)
+ goto fail;
+
+ return &buffer->base;
+
+fail:
+ FREE(buffer);
+ return NULL;
+}
+
+
+struct pipe_resource *
+nv50_user_buffer_create(struct pipe_screen *pscreen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind)
+{
+ struct nv50_resource *buffer;
+
+ buffer = CALLOC_STRUCT(nv50_resource);
+ if (!buffer)
+ return NULL;
+
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->vtbl = &nv50_buffer_vtbl;
+ buffer->base.screen = pscreen;
+ buffer->base.format = PIPE_FORMAT_R8_UNORM;
+ buffer->base._usage = PIPE_USAGE_IMMUTABLE;
+ buffer->base.bind = bind;
+ buffer->base.width0 = bytes;
+ buffer->base.height0 = 1;
+ buffer->base.depth0 = 1;
+
+ buffer->bo = nouveau_screen_bo_user(pscreen, ptr, bytes);
+ if (!buffer->bo)
+ goto fail;
+
+ return &buffer->base;
+
+fail:
+ FREE(buffer);
+ return NULL;
+}
+
#include "nv50_context.h"
#include "nv50_screen.h"
+#include "nv50_resource.h"
static void
nv50_flush(struct pipe_context *pipe, unsigned flags,
nv50->pipe.flush = nv50_flush;
- nv50->pipe.is_texture_referenced = nouveau_is_texture_referenced;
- nv50->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
-
screen->base.channel->user_private = nv50;
nv50_init_surface_functions(nv50);
nv50_init_state_functions(nv50);
nv50_init_query_functions(nv50);
- nv50_init_transfer_functions(nv50);
+ nv50_init_resource_functions(&nv50->pipe);
nv50->draw = draw_create();
assert(nv50->draw);
#include "nouveau/nouveau_winsys.h"
#include "nouveau/nouveau_gldefs.h"
#include "nouveau/nouveau_stateobj.h"
-#include "nouveau/nouveau_context.h"
#include "nv50_screen.h"
#include "nv50_program.h"
return 1 << (tile_mode >> 4);
}
-struct nv50_miptree_level {
- int *image_offset;
- unsigned pitch;
- unsigned tile_mode;
-};
-
-#define NV50_MAX_TEXTURE_LEVELS 16
-
-struct nv50_miptree {
- struct nouveau_miptree base;
-
- struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS];
- int image_nr;
- int total_size;
-};
-
-static INLINE struct nv50_miptree *
-nv50_miptree(struct pipe_texture *pt)
-{
- return (struct nv50_miptree *)pt;
-}
struct nv50_surface {
struct pipe_surface base;
struct nv50_program *vertprog;
struct nv50_program *fragprog;
struct nv50_program *geomprog;
- struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
+ struct pipe_resource *constbuf[PIPE_SHADER_TYPES];
struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS];
unsigned vtxbuf_nr;
struct nv50_vtxelt_stateobj *vtxelt;
unsigned startInstance,
unsigned instanceCount);
extern void nv50_draw_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start,
unsigned count);
extern void nv50_draw_elements_instanced(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start,
unsigned count,
/* nv50_push.c */
extern void
-nv50_push_elements_instanced(struct pipe_context *, struct pipe_buffer *,
+nv50_push_elements_instanced(struct pipe_context *, struct pipe_resource *,
unsigned idxsize, unsigned mode, unsigned start,
unsigned count, unsigned i_start,
unsigned i_count);
extern void nv50_tex_relocs(struct nv50_context *);
extern struct nouveau_stateobj *nv50_tex_validate(struct nv50_context *);
-/* nv50_transfer.c */
-extern void
-nv50_upload_sifc(struct nv50_context *nv50,
- struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc,
- unsigned dst_format, int dst_w, int dst_h, int dst_pitch,
- void *src, unsigned src_format, int src_pitch,
- int x, int y, int w, int h, int cpp);
/* nv50_context.c */
struct pipe_context *
#include "util/u_format.h"
#include "nv50_context.h"
+#include "nv50_resource.h"
+#include "nv50_transfer.h"
/* The restrictions in tile mode selection probably aren't necessary. */
static INLINE uint32_t
return (z % tile_d) * pitch_2d + (z / tile_d) * pitch_3d;
}
-static struct pipe_texture *
-nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *tmp)
+
+
+
+static void
+nv50_miptree_destroy(struct pipe_screen *pscreen,
+ struct pipe_resource *pt)
+{
+ struct nv50_miptree *mt = nv50_miptree(pt);
+ unsigned l;
+
+ for (l = 0; l <= pt->last_level; ++l)
+ FREE(mt->level[l].image_offset);
+
+ nouveau_screen_bo_release(pscreen, mt->base.bo);
+ FREE(mt);
+}
+
+static boolean
+nv50_miptree_get_handle(struct pipe_screen *pscreen,
+ struct pipe_resource *pt,
+ struct winsys_handle *whandle)
+{
+ struct nv50_miptree *mt = nv50_miptree(pt);
+ unsigned stride;
+
+
+ if (!mt || !mt->base.bo)
+ return FALSE;
+
+ stride = util_format_get_stride(mt->base.base.format,
+ mt->base.base.width0);
+
+ return nouveau_screen_bo_get_handle(pscreen,
+ mt->base.bo,
+ stride,
+ whandle);
+}
+
+
+struct u_resource_vtbl nv50_miptree_vtbl =
+{
+ nv50_miptree_get_handle, /* get_handle */
+ nv50_miptree_destroy, /* resource_destroy */
+ NULL, /* is_resource_referenced */
+ nv50_miptree_transfer_new, /* get_transfer */
+ nv50_miptree_transfer_del, /* transfer_destroy */
+ nv50_miptree_transfer_map, /* transfer_map */
+ u_default_transfer_flush_region, /* transfer_flush_region */
+ nv50_miptree_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+struct pipe_resource *
+nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_resource *tmp)
{
struct nouveau_device *dev = nouveau_screen(pscreen)->device;
struct nv50_miptree *mt = CALLOC_STRUCT(nv50_miptree);
- struct pipe_texture *pt = &mt->base.base;
+ struct pipe_resource *pt = &mt->base.base;
unsigned width = tmp->width0, height = tmp->height0;
unsigned depth = tmp->depth0, image_alignment;
uint32_t tile_flags;
tile_flags = 0x7400;
break;
default:
- if ((pt->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) &&
+ if ((pt->bind & PIPE_BIND_SCANOUT) &&
util_format_get_blocksizebits(pt->format) == 32)
tile_flags = 0x7a00;
else
return pt;
}
-static struct pipe_texture *
-nv50_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
- const unsigned *stride, struct pipe_buffer *pb)
+
+struct pipe_resource *
+nv50_miptree_from_handle(struct pipe_screen *pscreen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle)
{
- struct nouveau_bo *bo = nouveau_bo(pb);
struct nv50_miptree *mt;
+ unsigned stride;
/* Only supports 2D, non-mipmapped textures for the moment */
- if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
- pt->depth0 != 1)
+ if (template->target != PIPE_TEXTURE_2D ||
+ template->last_level != 0 ||
+ template->depth0 != 1)
return NULL;
mt = CALLOC_STRUCT(nv50_miptree);
if (!mt)
return NULL;
- mt->base.base = *pt;
+ mt->base.bo = nouveau_screen_bo_from_handle(pscreen, whandle, &stride);
+ if (mt->base.bo == NULL) {
+ FREE(mt);
+ return NULL;
+ }
+
+
+ mt->base.base = *template;
pipe_reference_init(&mt->base.base.reference, 1);
mt->base.base.screen = pscreen;
mt->image_nr = 1;
- mt->level[0].pitch = *stride;
+ mt->level[0].pitch = stride;
mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
- mt->level[0].tile_mode = bo->tile_mode;
+ mt->level[0].tile_mode = mt->base.bo->tile_mode;
- nouveau_bo_ref(bo, &mt->base.bo);
+ /* XXX: Need to adjust bo refcount??
+ */
+ /* nouveau_bo_ref(bo, &mt->base.bo); */
return &mt->base.base;
}
-static void
-nv50_miptree_destroy(struct pipe_texture *pt)
-{
- struct nv50_miptree *mt = nv50_miptree(pt);
- unsigned l;
- for (l = 0; l <= pt->last_level; ++l)
- FREE(mt->level[l].image_offset);
- nouveau_bo_ref(NULL, &mt->base.bo);
- FREE(mt);
-}
+/* Surface functions
+ */
-static struct pipe_surface *
-nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
+struct pipe_surface *
+nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_resource *pt,
unsigned face, unsigned level, unsigned zslice,
unsigned flags)
{
ps = CALLOC_STRUCT(pipe_surface);
if (!ps)
return NULL;
- pipe_texture_reference(&ps->texture, pt);
+ pipe_resource_reference(&ps->texture, pt);
ps->format = pt->format;
ps->width = u_minify(pt->width0, level);
ps->height = u_minify(pt->height0, level);
return ps;
}
-static void
+void
nv50_miptree_surface_del(struct pipe_surface *ps)
{
struct nv50_surface *s = nv50_surface(ps);
- pipe_texture_reference(&ps->texture, NULL);
+ pipe_resource_reference(&ps->texture, NULL);
FREE(s);
}
-
-void
-nv50_screen_init_miptree_functions(struct pipe_screen *pscreen)
-{
- pscreen->texture_create = nv50_miptree_create;
- pscreen->texture_destroy = nv50_miptree_destroy;
- pscreen->get_tex_surface = nv50_miptree_surface_new;
- pscreen->tex_surface_destroy = nv50_miptree_surface_del;
-
- nouveau_screen(pscreen)->texture_blanket = nv50_miptree_blanket;
-}
-
#include "tgsi/tgsi_util.h"
#include "nv50_context.h"
+#include "nv50_transfer.h"
#define NV50_SU_MAX_TEMP 127
#define NV50_SU_MAX_ADDR 4
static void
nv50_program_validate_data(struct nv50_context *nv50, struct nv50_program *p)
{
- struct pipe_screen *pscreen = nv50->pipe.screen;
+ struct pipe_context *pipe = &nv50->pipe;
+ struct pipe_transfer *transfer;
if (!p->data[0] && p->immd_nr) {
struct nouveau_resource *heap = nv50->screen->immd_heap[0];
if (p->param_nr) {
unsigned cb;
- uint32_t *map = pipe_buffer_map(pscreen,
+ uint32_t *map = pipe_buffer_map(pipe,
nv50->constbuf[p->type],
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &transfer);
switch (p->type) {
case PIPE_SHADER_GEOMETRY: cb = NV50_CB_PGP; break;
case PIPE_SHADER_FRAGMENT: cb = NV50_CB_PFP; break;
}
nv50_program_upload_data(nv50, map, 0, p->param_nr, cb);
- pipe_buffer_unmap(pscreen, nv50->constbuf[p->type]);
+ pipe_buffer_unmap(pipe, nv50->constbuf[p->type],
+ transfer);
}
}
#include "nouveau/nouveau_util.h"
#include "nv50_context.h"
+#include "nv50_resource.h"
struct push_context {
struct nv50_context *nv50;
void
nv50_push_elements_instanced(struct pipe_context *pipe,
- struct pipe_buffer *idxbuf, unsigned idxsize,
+ struct pipe_resource *idxbuf, unsigned idxsize,
unsigned mode, unsigned start, unsigned count,
unsigned i_start, unsigned i_count)
{
for (i = 0; i < nv50->vtxelt->num_elements; i++) {
struct pipe_vertex_element *ve = &nv50->vtxelt->pipe[i];
struct pipe_vertex_buffer *vb = &nv50->vtxbuf[ve->vertex_buffer_index];
- struct nouveau_bo *bo = nouveau_bo(vb->buffer);
+ struct nouveau_bo *bo = nv50_resource(vb->buffer)->bo;
unsigned size, nr_components, n;
if (!(nv50->vbo_fifo & (1 << i)))
/* map index buffer, if present */
if (idxbuf) {
- struct nouveau_bo *bo = nouveau_bo(idxbuf);
+ struct nouveau_bo *bo = nv50_resource(idxbuf)->bo;
if (nouveau_bo_map(bo, NOUVEAU_BO_RD)) {
assert(bo->map);
--- /dev/null
+
+#include "pipe/p_context.h"
+#include "nv50_resource.h"
+#include "nouveau/nouveau_screen.h"
+
+
+/* This doesn't look quite right - this query is supposed to ask
+ * whether the particular context has references to the resource in
+ * any unflushed rendering command buffer, and hence requires a
+ * pipe->flush() for serializing some modification to that resource.
+ *
+ * This seems to be answering the question of whether the resource is
+ * currently on hardware.
+ */
+static unsigned int
+nv50_resource_is_referenced(struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned face, unsigned level)
+{
+ return nouveau_reference_flags(nv50_resource(resource)->bo);
+}
+
+static struct pipe_resource *
+nv50_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ if (template->target == PIPE_BUFFER)
+ return nv50_buffer_create(screen, template);
+ else
+ return nv50_miptree_create(screen, template);
+}
+
+static struct pipe_resource *
+nv50_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 nv50_miptree_from_handle(screen, template, whandle);
+}
+
+void
+nv50_init_resource_functions(struct pipe_context *pcontext)
+{
+ pcontext->get_transfer = u_get_transfer_vtbl;
+ pcontext->transfer_map = u_transfer_map_vtbl;
+ pcontext->transfer_flush_region = u_transfer_flush_region_vtbl;
+ pcontext->transfer_unmap = u_transfer_unmap_vtbl;
+ pcontext->transfer_destroy = u_transfer_destroy_vtbl;
+ pcontext->transfer_inline_write = u_transfer_inline_write_vtbl;
+ pcontext->is_resource_referenced = nv50_resource_is_referenced;
+}
+
+void
+nv50_screen_init_resource_functions(struct pipe_screen *pscreen)
+{
+ pscreen->resource_create = nv50_resource_create;
+ pscreen->resource_from_handle = nv50_resource_from_handle;
+ pscreen->resource_get_handle = u_resource_get_handle_vtbl;
+ pscreen->resource_destroy = u_resource_destroy_vtbl;
+ pscreen->user_buffer_create = nv50_user_buffer_create;
+
+ pscreen->get_tex_surface = nv50_miptree_surface_new;
+ pscreen->tex_surface_destroy = nv50_miptree_surface_del;
+}
--- /dev/null
+
+#ifndef NV50_RESOURCE_H
+#define NV50_RESOURCE_H
+
+#include "util/u_transfer.h"
+
+struct pipe_resource;
+struct nouveau_bo;
+
+
+/* This gets further specialized into either buffer or texture
+ * structures. In the future we'll want to remove much of that
+ * distinction, but for now try to keep as close to the existing code
+ * as possible and use the vtbl struct to choose between the two
+ * underlying implementations.
+ */
+struct nv50_resource {
+ struct pipe_resource base;
+ struct u_resource_vtbl *vtbl;
+ struct nouveau_bo *bo;
+};
+
+struct nv50_miptree_level {
+ int *image_offset;
+ unsigned pitch;
+ unsigned tile_mode;
+};
+
+#define NV50_MAX_TEXTURE_LEVELS 16
+
+struct nv50_miptree {
+ struct nv50_resource base;
+
+ struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS];
+ int image_nr;
+ int total_size;
+};
+
+static INLINE struct nv50_miptree *
+nv50_miptree(struct pipe_resource *pt)
+{
+ return (struct nv50_miptree *)pt;
+}
+
+
+static INLINE
+struct nv50_resource *nv50_resource(struct pipe_resource *resource)
+{
+ return (struct nv50_resource *)resource;
+}
+
+
+void
+nv50_init_resource_functions(struct pipe_context *pcontext);
+
+void
+nv50_screen_init_resource_functions(struct pipe_screen *pscreen);
+
+/* Internal functions
+ */
+struct pipe_resource *
+nv50_miptree_create(struct pipe_screen *pscreen,
+ const struct pipe_resource *tmp);
+
+struct pipe_resource *
+nv50_miptree_from_handle(struct pipe_screen *pscreen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle);
+
+struct pipe_resource *
+nv50_buffer_create(struct pipe_screen *pscreen,
+ const struct pipe_resource *template);
+
+struct pipe_resource *
+nv50_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned usage);
+
+
+struct pipe_surface *
+nv50_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_resource *pt,
+ unsigned face, unsigned level, unsigned zslice,
+ unsigned flags);
+
+void
+nv50_miptree_surface_del(struct pipe_surface *ps);
+
+
+#endif
#include "nv50_context.h"
#include "nv50_screen.h"
+#include "nv50_resource.h"
#include "nouveau/nouveau_stateobj.h"
enum pipe_texture_target target,
unsigned tex_usage, unsigned geom_flags)
{
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
+ if (tex_usage & PIPE_BIND_RENDER_TARGET) {
switch (format) {
case PIPE_FORMAT_B8G8R8X8_UNORM:
case PIPE_FORMAT_B8G8R8A8_UNORM:
break;
}
} else
- if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) {
+ if (tex_usage & PIPE_BIND_DEPTH_STENCIL) {
switch (format) {
case PIPE_FORMAT_Z32_FLOAT:
case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
pscreen->is_format_supported = nv50_screen_is_format_supported;
pscreen->context_create = nv50_create;
- nv50_screen_init_miptree_functions(pscreen);
+ nv50_screen_init_resource_functions(pscreen);
/* DMA engine object */
ret = nouveau_grobj_alloc(chan, 0xbeef5039,
struct nouveau_resource *immd_heap[1];
struct nouveau_resource *parm_heap[PIPE_SHADER_TYPES];
- struct pipe_buffer *strm_vbuf[16];
+ struct pipe_resource *strm_vbuf[16];
struct nouveau_bo *tic;
struct nouveau_bo *tsc;
nv50_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(nv50_sampler_view(view));
}
static struct pipe_sampler_view *
nv50_create_sampler_view(struct pipe_context *pipe,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
const struct pipe_sampler_view *templ)
{
struct nv50_sampler_view *view = CALLOC_STRUCT(nv50_sampler_view);
view->pipe = *templ;
view->pipe.reference.count = 1;
view->pipe.texture = NULL;
- pipe_texture_reference(&view->pipe.texture, texture);
+ pipe_resource_reference(&view->pipe.texture, texture);
view->pipe.context = pipe;
if (!nv50_tex_construct(view)) {
static void
nv50_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
- struct pipe_buffer *buf )
+ struct pipe_resource *buf )
{
struct nv50_context *nv50 = nv50_context(pipe);
#include "util/u_format.h"
#include "nv50_context.h"
+#include "nv50_resource.h"
#include "nouveau/nouveau_stateobj.h"
static struct nouveau_stateobj *
(4 << 16) | (5 << 19) | (6 << 22) | (7 << 25));
for (i = 0; i < fb->nr_cbufs; i++) {
- struct pipe_texture *pt = fb->cbufs[i]->texture;
+ struct pipe_resource *pt = fb->cbufs[i]->texture;
struct nouveau_bo *bo = nv50_miptree(pt)->base.bo;
if (!gw) {
}
if (fb->zsbuf) {
- struct pipe_texture *pt = fb->zsbuf->texture;
+ struct pipe_resource *pt = fb->zsbuf->texture;
struct nouveau_bo *bo = nv50_miptree(pt)->base.bo;
if (!gw) {
#include <stdint.h>
#include "nouveau/nouveau_pushbuf.h"
#include "nv50_context.h"
+#include "nv50_resource.h"
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "nv50_context.h"
#include "nv50_texture.h"
+#include "nv50_resource.h"
#include "nouveau/nouveau_stateobj.h"
#include "nouveau/nouveau_reloc.h"
#include "util/u_math.h"
#include "nv50_context.h"
+#include "nv50_transfer.h"
+#include "nv50_resource.h"
struct nv50_transfer {
struct pipe_transfer base;
}
}
-static struct pipe_transfer *
-nv50_transfer_new(struct pipe_context *pcontext, struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
+struct pipe_transfer *
+nv50_miptree_transfer_new(struct pipe_context *pcontext,
+ struct pipe_resource *pt,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
{
struct pipe_screen *pscreen = pcontext->screen;
struct nouveau_device *dev = nouveau_screen(pscreen)->device;
struct nv50_miptree *mt = nv50_miptree(pt);
- struct nv50_miptree_level *lvl = &mt->level[level];
+ struct nv50_miptree_level *lvl = &mt->level[sr.level];
struct nv50_transfer *tx;
unsigned nx, ny, image = 0;
int ret;
if (pt->target == PIPE_TEXTURE_CUBE)
- image = face;
+ image = sr.face;
tx = CALLOC_STRUCT(nv50_transfer);
if (!tx)
return NULL;
- pipe_texture_reference(&tx->base.texture, pt);
- tx->nblocksx = util_format_get_nblocksx(pt->format, u_minify(pt->width0, level));
- tx->nblocksy = util_format_get_nblocksy(pt->format, u_minify(pt->height0, level));
- tx->base.width = w;
- tx->base.height = h;
+ /* Don't handle 3D transfers yet.
+ */
+ assert(box->depth == 1);
+
+
+ pipe_resource_reference(&tx->base.resource, pt);
+ tx->base.sr = sr;
+ tx->base.usage = usage;
+ tx->base.box = *box;
+ tx->nblocksx = util_format_get_nblocksx(pt->format, u_minify(pt->width0, sr.level));
+ tx->nblocksy = util_format_get_nblocksy(pt->format, u_minify(pt->height0, sr.level));
tx->base.stride = tx->nblocksx * util_format_get_blocksize(pt->format);
tx->base.usage = usage;
tx->level_pitch = lvl->pitch;
- tx->level_width = u_minify(mt->base.base.width0, level);
- tx->level_height = u_minify(mt->base.base.height0, level);
- tx->level_depth = u_minify(mt->base.base.depth0, level);
+ tx->level_width = u_minify(mt->base.base.width0, sr.level);
+ tx->level_height = u_minify(mt->base.base.height0, sr.level);
+ tx->level_depth = u_minify(mt->base.base.depth0, sr.level);
tx->level_offset = lvl->image_offset[image];
tx->level_tiling = lvl->tile_mode;
- tx->level_z = zslice;
- tx->level_x = util_format_get_nblocksx(pt->format, x);
- tx->level_y = util_format_get_nblocksy(pt->format, y);
+ tx->level_z = box->z;
+ tx->level_x = util_format_get_nblocksx(pt->format, box->x);
+ tx->level_y = util_format_get_nblocksy(pt->format, box->y);
ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0,
tx->nblocksy * tx->base.stride, &tx->bo);
if (ret) {
}
if (usage & PIPE_TRANSFER_READ) {
- nx = util_format_get_nblocksx(pt->format, tx->base.width);
- ny = util_format_get_nblocksy(pt->format, tx->base.height);
+ nx = util_format_get_nblocksx(pt->format, box->width);
+ ny = util_format_get_nblocksy(pt->format, box->height);
nv50_transfer_rect_m2mf(pscreen, mt->base.bo, tx->level_offset,
tx->level_pitch, tx->level_tiling,
- x, y, zslice,
+ box->x, box->y, box->z,
tx->nblocksx, tx->nblocksy,
tx->level_depth,
tx->bo, 0,
return &tx->base;
}
-static void
-nv50_transfer_del(struct pipe_context *pcontext, struct pipe_transfer *ptx)
+void
+nv50_miptree_transfer_del(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx)
{
struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
- struct nv50_miptree *mt = nv50_miptree(ptx->texture);
- struct pipe_texture *pt = ptx->texture;
+ struct nv50_miptree *mt = nv50_miptree(ptx->resource);
+ struct pipe_resource *pt = ptx->resource;
- unsigned nx = util_format_get_nblocksx(pt->format, tx->base.width);
- unsigned ny = util_format_get_nblocksy(pt->format, tx->base.height);
+ unsigned nx = util_format_get_nblocksx(pt->format, tx->base.box.width);
+ unsigned ny = util_format_get_nblocksy(pt->format, tx->base.box.height);
if (ptx->usage & PIPE_TRANSFER_WRITE) {
struct pipe_screen *pscreen = pcontext->screen;
}
nouveau_bo_ref(NULL, &tx->bo);
- pipe_texture_reference(&ptx->texture, NULL);
+ pipe_resource_reference(&ptx->resource, NULL);
FREE(ptx);
}
-static void *
-nv50_transfer_map(struct pipe_context *pcontext, struct pipe_transfer *ptx)
+void *
+nv50_miptree_transfer_map(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx)
{
struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
unsigned flags = 0;
return tx->bo->map;
}
-static void
-nv50_transfer_unmap(struct pipe_context *pcontext, struct pipe_transfer *ptx)
+void
+nv50_miptree_transfer_unmap(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx)
{
struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
nouveau_bo_unmap(tx->bo);
}
-void
-nv50_init_transfer_functions(struct nv50_context *nv50)
-{
- nv50->pipe.get_tex_transfer = nv50_transfer_new;
- nv50->pipe.tex_transfer_destroy = nv50_transfer_del;
- nv50->pipe.transfer_map = nv50_transfer_map;
- nv50->pipe.transfer_unmap = nv50_transfer_unmap;
-}
void
nv50_upload_sifc(struct nv50_context *nv50,
--- /dev/null
+
+#ifndef NV50_TRANSFER_H
+#define NV50_TRANSFER_H
+
+#include "pipe/p_state.h"
+
+
+struct pipe_transfer *
+nv50_miptree_transfer_new(struct pipe_context *pcontext,
+ struct pipe_resource *pt,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box);
+void
+nv50_miptree_transfer_del(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx);
+void *
+nv50_miptree_transfer_map(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx);
+void
+nv50_miptree_transfer_unmap(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx);
+
+extern void
+nv50_upload_sifc(struct nv50_context *nv50,
+ struct nouveau_bo *bo, unsigned dst_offset, unsigned reloc,
+ unsigned dst_format, int dst_w, int dst_h, int dst_pitch,
+ void *src, unsigned src_format, int src_pitch,
+ int x, int y, int w, int h, int cpp);
+
+#endif
#include "nouveau/nouveau_util.h"
#include "nv50_context.h"
+#include "nv50_resource.h"
static INLINE uint32_t
nv50_vbo_type_to_hw(enum pipe_format format)
if (a[i].divisor) {
vb = &nv50->vtxbuf[ve->vertex_buffer_index];
- a[i].bo = nouveau_bo(vb->buffer);
+ a[i].bo = nv50_resource(vb->buffer)->bo;
a[i].stride = vb->stride;
a[i].step = first % a[i].divisor;
a[i].delta = vb->buffer_offset + ve->src_offset +
static void
nv50_draw_elements_inline(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer, unsigned indexSize,
+ struct pipe_resource *indexBuffer, unsigned indexSize,
unsigned mode, unsigned start, unsigned count,
unsigned startInstance, unsigned instanceCount)
{
- struct pipe_screen *pscreen = pipe->screen;
struct nv50_context *nv50 = nv50_context(pipe);
struct nouveau_channel *chan = nv50->screen->tesla->channel;
struct nouveau_grobj *tesla = nv50->screen->tesla;
+ struct pipe_transfer *transfer;
struct instance a[16];
struct inline_ctx ctx;
struct u_split_prim s;
s.edge = inline_edgeflag;
ctx.nv50 = nv50;
- ctx.map = pipe_buffer_map(pscreen, indexBuffer, PIPE_BUFFER_USAGE_CPU_READ);
+ ctx.map = pipe_buffer_map(pipe, indexBuffer, PIPE_TRANSFER_READ, &transfer);
assert(ctx.map);
if (!ctx.map)
return;
nzi = TRUE;
}
- pipe_buffer_unmap(pscreen, indexBuffer);
+ pipe_buffer_unmap(pipe, indexBuffer, transfer);
}
void
nv50_draw_elements_instanced(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count,
unsigned startInstance, unsigned instanceCount)
instanceCount);
return;
} else
- if (!(indexBuffer->usage & PIPE_BUFFER_USAGE_INDEX) || indexSize == 1) {
+ if (!(indexBuffer->bind & PIPE_BIND_INDEX_BUFFER) || indexSize == 1) {
nv50_draw_elements_inline(pipe, indexBuffer, indexSize,
mode, start, count, startInstance,
instanceCount);
if (indexSize == 4) {
BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U32 | 0x30000, 0);
OUT_RING (chan, count);
- nouveau_pushbuf_submit(chan, nouveau_bo(indexBuffer),
+ nouveau_pushbuf_submit(chan,
+ nv50_resource(indexBuffer)->bo,
start << 2, count << 2);
} else
if (indexSize == 2) {
OUT_RING (chan, ((start & 1) << 31) | count);
BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U16 | 0x30000, 0);
OUT_RING (chan, dwords);
- nouveau_pushbuf_submit(chan, nouveau_bo(indexBuffer),
+ nouveau_pushbuf_submit(chan,
+ nv50_resource(indexBuffer)->bo,
vb_start << 1, dwords << 2);
BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U16_SETUP, 1);
OUT_RING (chan, 0);
void
nv50_draw_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer, unsigned indexSize,
+ struct pipe_resource *indexBuffer, unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
nv50_draw_elements_instanced(pipe, indexBuffer, indexSize,
{
struct nouveau_stateobj *so;
struct nouveau_grobj *tesla = nv50->screen->tesla;
- struct nouveau_bo *bo = nouveau_bo(vb->buffer);
+ struct nouveau_bo *bo = nv50_resource(vb->buffer)->bo;
float v[4];
int ret;
unsigned nr_components = util_format_get_nr_components(ve->src_format);
for (i = 0; i < nv50->vtxbuf_nr; i++) {
if (nv50->vtxbuf[i].stride &&
- !(nv50->vtxbuf[i].buffer->usage & PIPE_BUFFER_USAGE_VERTEX))
+ !(nv50->vtxbuf[i].buffer->bind & PIPE_BIND_VERTEX_BUFFER))
nv50->vbo_fifo = 0xffff;
}
struct pipe_vertex_element *ve = &nv50->vtxelt->pipe[i];
struct pipe_vertex_buffer *vb =
&nv50->vtxbuf[ve->vertex_buffer_index];
- struct nouveau_bo *bo = nouveau_bo(vb->buffer);
+ struct nouveau_bo *bo = nv50_resource(vb->buffer)->bo;
uint32_t hw = nv50->vtxelt->hw[i];
if (!vb->stride &&
/* vertex array limits */
so_method(vtxbuf, tesla, NV50TCL_VERTEX_ARRAY_LIMIT_HIGH(i), 2);
- so_reloc (vtxbuf, bo, vb->buffer->size - 1,
+ so_reloc (vtxbuf, bo, vb->buffer->width0 - 1,
NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD |
NOUVEAU_BO_HIGH, 0, 0);
- so_reloc (vtxbuf, bo, vb->buffer->size - 1,
+ so_reloc (vtxbuf, bo, vb->buffer->width0 - 1,
NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD |
NOUVEAU_BO_LOW, 0, 0);
}
C_SOURCES = \
nv04_surface_2d.c \
+ nvfx_buffer.c \
nvfx_context.c \
nvfx_clear.c \
nvfx_draw.c \
nv40_fragtex.c \
nvfx_miptree.c \
nvfx_query.c \
+ nvfx_resource.c \
nvfx_screen.c \
nvfx_state.c \
nvfx_state_blend.c \
nvfx_vbo.c \
nvfx_vertprog.c
+LIBRARY_INCLUDES = \
+ -I$(TOP)/src/gallium/drivers/nouveau/include
+
include ../../Makefile.template
struct nouveau_channel *chan = ctx->swzsurf->channel;
struct nouveau_grobj *swzsurf = ctx->swzsurf;
struct nouveau_grobj *sifm = ctx->sifm;
- struct nouveau_bo *src_bo = nouveau_bo(ctx->buf(src));
- struct nouveau_bo *dst_bo = nouveau_bo(ctx->buf(dst));
+ struct nouveau_bo *src_bo = ctx->buf(src);
+ struct nouveau_bo *dst_bo = ctx->buf(dst);
const unsigned src_pitch = ((struct nv04_surface *)src)->pitch;
/* Max width & height may not be the same on all HW, but must be POT */
const unsigned max_w = 1024;
{
struct nouveau_channel *chan = ctx->m2mf->channel;
struct nouveau_grobj *m2mf = ctx->m2mf;
- struct nouveau_bo *src_bo = nouveau_bo(ctx->buf(src));
- struct nouveau_bo *dst_bo = nouveau_bo(ctx->buf(dst));
+ struct nouveau_bo *src_bo = ctx->buf(src);
+ struct nouveau_bo *dst_bo = ctx->buf(dst);
unsigned src_pitch = ((struct nv04_surface *)src)->pitch;
unsigned dst_pitch = ((struct nv04_surface *)dst)->pitch;
unsigned dst_offset = dst->offset + dy * dst_pitch +
struct nouveau_channel *chan = ctx->surf2d->channel;
struct nouveau_grobj *surf2d = ctx->surf2d;
struct nouveau_grobj *blit = ctx->blit;
- struct nouveau_bo *src_bo = nouveau_bo(ctx->buf(src));
- struct nouveau_bo *dst_bo = nouveau_bo(ctx->buf(dst));
+ struct nouveau_bo *src_bo = ctx->buf(src);
+ struct nouveau_bo *dst_bo = ctx->buf(dst);
unsigned src_pitch = ((struct nv04_surface *)src)->pitch;
unsigned dst_pitch = ((struct nv04_surface *)dst)->pitch;
int format;
{
unsigned src_pitch = ((struct nv04_surface *)src)->pitch;
unsigned dst_pitch = ((struct nv04_surface *)dst)->pitch;
- int src_linear = src->texture->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR;
- int dst_linear = dst->texture->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR;
+ int src_linear = src->texture->flags & NVFX_RESOURCE_FLAG_LINEAR;
+ int dst_linear = dst->texture->flags & NVFX_RESOURCE_FLAG_LINEAR;
assert(src->format == dst->format);
struct nouveau_channel *chan = ctx->surf2d->channel;
struct nouveau_grobj *surf2d = ctx->surf2d;
struct nouveau_grobj *rect = ctx->rect;
- struct nouveau_bo *dst_bo = nouveau_bo(ctx->buf(dst));
+ struct nouveau_bo *dst_bo = ctx->buf(dst);
unsigned dst_pitch = ((struct nv04_surface *)dst)->pitch;
int cs2d_format, gdirect_format;
}
struct nv04_surface*
-nv04_surface_wrap_for_render(struct pipe_screen *pscreen, struct nv04_surface_2d* eng2d, struct nv04_surface* ns)
+nv04_surface_wrap_for_render(struct pipe_screen *pscreen,
+ struct nv04_surface_2d* eng2d, struct nv04_surface* ns)
{
int temp_flags;
- // printf("creating temp, flags is %i!\n", flags);
+ temp_flags = (ns->base.usage |
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION);
- if(ns->base.usage & PIPE_BUFFER_USAGE_DISCARD)
- {
- temp_flags = ns->base.usage | PIPE_BUFFER_USAGE_GPU_READ;
- ns->base.usage = PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER | PIPE_BUFFER_USAGE_DISCARD;
- }
- else
- {
- temp_flags = ns->base.usage | PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
- ns->base.usage = PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER | PIPE_BUFFER_USAGE_GPU_READ;
- }
-
- ns->base.usage = PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
+ ns->base.usage = (PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION);
- struct pipe_texture templ;
+ struct pipe_resource templ;
memset(&templ, 0, sizeof(templ));
templ.format = ns->base.texture->format;
templ.target = PIPE_TEXTURE_2D;
// TODO: this is probably wrong and we should specifically handle multisampling somehow once it is implemented
templ.nr_samples = ns->base.texture->nr_samples;
- templ.tex_usage = ns->base.texture->tex_usage | PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ templ.bind = ns->base.texture->bind | PIPE_BIND_RENDER_TARGET;
- struct pipe_texture* temp_tex = pscreen->texture_create(pscreen, &templ);
+ struct pipe_resource* temp_tex = pscreen->resource_create(pscreen, &templ);
struct nv04_surface* temp_ns = (struct nv04_surface*)pscreen->get_tex_surface(pscreen, temp_tex, 0, 0, 0, temp_flags);
temp_ns->backing = ns;
- if(ns->base.usage & PIPE_BUFFER_USAGE_GPU_READ)
- eng2d->copy(eng2d, &temp_ns->backing->base, 0, 0, &ns->base, 0, 0, ns->base.width, ns->base.height);
+ if(ns->base.usage & PIPE_BIND_BLIT_SOURCE)
+ eng2d->copy(eng2d, &temp_ns->backing->base,
+ 0, 0, &ns->base,
+ 0, 0, ns->base.width, ns->base.height);
return temp_ns;
}
struct nouveau_grobj *blit;
struct nouveau_grobj *sifm;
- struct pipe_buffer *(*buf)(struct pipe_surface *);
+ struct nouveau_bo *(*buf)(struct pipe_surface *);
void (*copy)(struct nv04_surface_2d *, struct pipe_surface *dst,
int dx, int dy, struct pipe_surface *src, int sx, int sy,
struct nv04_surface*
nv04_surface_wrap_for_render(struct pipe_screen *pscreen, struct nv04_surface_2d* eng2d, struct nv04_surface* ns);
+#define NVFX_RESOURCE_FLAG_LINEAR (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
+
#endif
#include "nvfx_context.h"
#include "nouveau/nouveau_util.h"
#include "nvfx_tex.h"
+#include "nvfx_resource.h"
void
nv30_sampler_state_init(struct pipe_context *pipe,
{
struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
struct nvfx_miptree *nv30mt = (struct nvfx_miptree *)nvfx->fragment_sampler_views[unit]->texture;
- struct pipe_texture *pt = &nv30mt->base;
- struct nouveau_bo *bo = nouveau_bo(nv30mt->buffer);
+ struct pipe_resource *pt = &nv30mt->base.base;
+ struct nouveau_bo *bo = nv30mt->base.bo;
struct nv30_texture_format *tf;
struct nouveau_stateobj *so;
uint32_t txf, txs;
#include "util/u_format.h"
#include "nvfx_context.h"
#include "nvfx_tex.h"
+#include "nvfx_resource.h"
void
nv40_sampler_state_init(struct pipe_context *pipe,
{
struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
struct nvfx_miptree *nv40mt = (struct nvfx_miptree *)nvfx->fragment_sampler_views[unit]->texture;
- struct nouveau_bo *bo = nouveau_bo(nv40mt->buffer);
- struct pipe_texture *pt = &nv40mt->base;
+ struct nouveau_bo *bo = nv40mt->base.bo;
+ struct pipe_resource *pt = &nv40mt->base.base;
struct nv40_texture_format *tf;
struct nouveau_stateobj *so;
uint32_t txf, txs, txp;
return NULL;
}
- if (!(pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)) {
+ if (!(pt->flags & NVFX_RESOURCE_FLAG_LINEAR)) {
txp = 0;
} else {
txp = nv40mt->level[0].pitch;
--- /dev/null
+
+#include "util/u_inlines.h"
+#include "util/u_memory.h"
+#include "util/u_math.h"
+
+#include "nouveau/nouveau_screen.h"
+#include "nouveau/nouveau_winsys.h"
+#include "nvfx_resource.h"
+
+
+/* Currently using separate implementations for buffers and textures,
+ * even though gallium has a unified abstraction of these objects.
+ * Eventually these should be combined, and mechanisms like transfers
+ * be adapted to work for both buffer and texture uploads.
+ */
+static void nvfx_buffer_destroy(struct pipe_screen *pscreen,
+ struct pipe_resource *presource)
+{
+ struct nvfx_resource *buffer = nvfx_resource(presource);
+
+ nouveau_screen_bo_release(pscreen, buffer->bo);
+ FREE(buffer);
+}
+
+
+
+
+/* Utility functions for transfer create/destroy are hooked in and
+ * just record the arguments to those functions.
+ */
+static void *
+nvfx_buffer_transfer_map( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ struct nvfx_resource *buffer = nvfx_resource(transfer->resource);
+ uint8_t *map;
+
+ map = nouveau_screen_bo_map_range( pipe->screen,
+ buffer->bo,
+ transfer->box.x,
+ transfer->box.width,
+ nouveau_screen_transfer_flags(transfer->usage) );
+ if (map == NULL)
+ return NULL;
+
+ return map + transfer->box.x;
+}
+
+
+
+static void nvfx_buffer_transfer_flush_region( struct pipe_context *pipe,
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box)
+{
+ struct nvfx_resource *buffer = nvfx_resource(transfer->resource);
+
+ nouveau_screen_bo_map_flush_range(pipe->screen,
+ buffer->bo,
+ transfer->box.x + box->x,
+ box->width);
+}
+
+static void nvfx_buffer_transfer_unmap( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ struct nvfx_resource *buffer = nvfx_resource(transfer->resource);
+
+ nouveau_screen_bo_unmap(pipe->screen, buffer->bo);
+}
+
+
+
+
+struct u_resource_vtbl nvfx_buffer_vtbl =
+{
+ u_default_resource_get_handle, /* get_handle */
+ nvfx_buffer_destroy, /* resource_destroy */
+ NULL, /* is_resource_referenced */
+ u_default_get_transfer, /* get_transfer */
+ u_default_transfer_destroy, /* transfer_destroy */
+ nvfx_buffer_transfer_map, /* transfer_map */
+ nvfx_buffer_transfer_flush_region, /* transfer_flush_region */
+ nvfx_buffer_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+struct pipe_resource *
+nvfx_buffer_create(struct pipe_screen *pscreen,
+ const struct pipe_resource *template)
+{
+ struct nvfx_resource *buffer;
+
+ buffer = CALLOC_STRUCT(nvfx_resource);
+ if (!buffer)
+ return NULL;
+
+ buffer->base = *template;
+ buffer->vtbl = &nvfx_buffer_vtbl;
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->base.screen = pscreen;
+
+ buffer->bo = nouveau_screen_bo_new(pscreen,
+ 16,
+ buffer->base._usage,
+ buffer->base.bind,
+ buffer->base.width0);
+
+ if (buffer->bo == NULL)
+ goto fail;
+
+ return &buffer->base;
+
+fail:
+ FREE(buffer);
+ return NULL;
+}
+
+
+struct pipe_resource *
+nvfx_user_buffer_create(struct pipe_screen *pscreen,
+ void *ptr,
+ unsigned bytes,
+ unsigned usage)
+{
+ struct nvfx_resource *buffer;
+
+ buffer = CALLOC_STRUCT(nvfx_resource);
+ if (!buffer)
+ return NULL;
+
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->vtbl = &nvfx_buffer_vtbl;
+ buffer->base.screen = pscreen;
+ buffer->base.format = PIPE_FORMAT_R8_UNORM;
+ buffer->base._usage = PIPE_USAGE_IMMUTABLE;
+ buffer->base.bind = usage;
+ buffer->base.width0 = bytes;
+ buffer->base.height0 = 1;
+ buffer->base.depth0 = 1;
+
+ buffer->bo = nouveau_screen_bo_user(pscreen, ptr, bytes);
+ if (!buffer->bo)
+ goto fail;
+
+ return &buffer->base;
+
+fail:
+ FREE(buffer);
+ return NULL;
+}
+
#include "nvfx_context.h"
#include "nvfx_screen.h"
+#include "nvfx_resource.h"
static void
nvfx_flush(struct pipe_context *pipe, unsigned flags,
nvfx->pipe.clear = nvfx_clear;
nvfx->pipe.flush = nvfx_flush;
- nvfx->pipe.is_texture_referenced = nouveau_is_texture_referenced;
- nvfx->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
-
screen->base.channel->user_private = nvfx;
screen->base.channel->flush_notify = nvfx_state_flush_notify;
nvfx_init_query_functions(nvfx);
nvfx_init_surface_functions(nvfx);
nvfx_init_state_functions(nvfx);
- nvfx_init_transfer_functions(nvfx);
+ nvfx_init_resource_functions(&nvfx->pipe);
/* Create, configure, and install fallback swtnl path */
nvfx->draw = draw_create();
#include "nouveau/nouveau_winsys.h"
#include "nouveau/nouveau_gldefs.h"
-#include "nouveau/nouveau_context.h"
#include "nouveau/nouveau_stateobj.h"
#include "nvfx_state.h"
struct pipe_clip_state clip;
struct nvfx_vertex_program *vertprog;
struct nvfx_fragment_program *fragprog;
- struct pipe_buffer *constbuf[PIPE_SHADER_TYPES];
+ struct pipe_resource *constbuf[PIPE_SHADER_TYPES];
unsigned constbuf_nr[PIPE_SHADER_TYPES];
struct nvfx_rasterizer_state *rasterizer;
struct nvfx_zsa_state *zsa;
struct pipe_stencil_ref stencil_ref;
struct pipe_viewport_state viewport;
struct pipe_framebuffer_state framebuffer;
- struct pipe_buffer *idxbuf;
+ struct pipe_resource *idxbuf;
unsigned idxbuf_format;
struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
/* nvfx_draw.c */
extern struct draw_stage *nvfx_draw_render_stage(struct nvfx_context *nvfx);
extern void nvfx_draw_elements_swtnl(struct pipe_context *pipe,
- struct pipe_buffer *idxbuf,
+ struct pipe_resource *idxbuf,
unsigned ib_size, unsigned mode,
unsigned start, unsigned count);
extern void nvfx_draw_arrays(struct pipe_context *, unsigned mode,
unsigned start, unsigned count);
extern void nvfx_draw_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start,
unsigned count);
void
nvfx_draw_elements_swtnl(struct pipe_context *pipe,
- struct pipe_buffer *idxbuf, unsigned idxbuf_size,
+ struct pipe_resource *idxbuf, unsigned idxbuf_size,
unsigned mode, unsigned start, unsigned count)
{
struct nvfx_context *nvfx = nvfx_context(pipe);
- struct pipe_screen *pscreen = pipe->screen;
+ struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
+ struct pipe_transfer *ib_transfer;
+ struct pipe_transfer *cb_transfer;
unsigned i;
void *map;
nvfx_state_emit(nvfx);
for (i = 0; i < nvfx->vtxbuf_nr; i++) {
- map = pipe_buffer_map(pscreen, nvfx->vtxbuf[i].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(pipe, nvfx->vtxbuf[i].buffer,
+ PIPE_TRANSFER_READ,
+ &vb_transfer[i]);
draw_set_mapped_vertex_buffer(nvfx->draw, i, map);
}
if (idxbuf) {
- map = pipe_buffer_map(pscreen, idxbuf,
- PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(pipe, idxbuf,
+ PIPE_TRANSFER_READ,
+ &ib_transfer);
draw_set_mapped_element_buffer(nvfx->draw, idxbuf_size, map);
} else {
draw_set_mapped_element_buffer(nvfx->draw, 0, NULL);
if (nvfx->constbuf[PIPE_SHADER_VERTEX]) {
const unsigned nr = nvfx->constbuf_nr[PIPE_SHADER_VERTEX];
- map = pipe_buffer_map(pscreen,
+ map = pipe_buffer_map(pipe,
nvfx->constbuf[PIPE_SHADER_VERTEX],
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &cb_transfer);
draw_set_mapped_constant_buffer(nvfx->draw, PIPE_SHADER_VERTEX, 0,
map, nr);
}
draw_arrays(nvfx->draw, mode, start, count);
for (i = 0; i < nvfx->vtxbuf_nr; i++)
- pipe_buffer_unmap(pscreen, nvfx->vtxbuf[i].buffer);
+ pipe_buffer_unmap(pipe, nvfx->vtxbuf[i].buffer, vb_transfer[i]);
if (idxbuf)
- pipe_buffer_unmap(pscreen, idxbuf);
+ pipe_buffer_unmap(pipe, idxbuf, ib_transfer);
if (nvfx->constbuf[PIPE_SHADER_VERTEX])
- pipe_buffer_unmap(pscreen, nvfx->constbuf[PIPE_SHADER_VERTEX]);
+ pipe_buffer_unmap(pipe, nvfx->constbuf[PIPE_SHADER_VERTEX],
+ cb_transfer);
draw_flush(nvfx->draw);
pipe->flush(pipe, 0, NULL);
#include "nvfx_context.h"
#include "nvfx_shader.h"
+#include "nvfx_resource.h"
#define MAX_CONSTS 128
#define MAX_IMM 32
nvfx_fragprog_upload(struct nvfx_context *nvfx,
struct nvfx_fragment_program *fp)
{
- struct pipe_screen *pscreen = nvfx->pipe.screen;
+ struct pipe_context *pipe = &nvfx->pipe;
const uint32_t le = 1;
- uint32_t *map;
- int i;
-
- map = pipe_buffer_map(pscreen, fp->buffer, PIPE_BUFFER_USAGE_CPU_WRITE);
#if 0
for (i = 0; i < fp->insn_len; i++) {
#endif
if ((*(const uint8_t *)&le)) {
- for (i = 0; i < fp->insn_len; i++) {
- map[i] = fp->insn[i];
- }
+ /* Can do this with an inline transfer */
+ pipe_buffer_write(pipe,
+ fp->buffer,
+ 0,
+ fp->insn_len * sizeof fp->insn[0],
+ fp->insn);
} else {
+ struct pipe_transfer *transfer;
+ uint32_t *map;
+ int i;
+
+ map = pipe_buffer_map(pipe, fp->buffer,
+ PIPE_TRANSFER_WRITE,
+ &transfer);
+
/* Weird swapping for big-endian chips */
for (i = 0; i < fp->insn_len; i++) {
map[i] = ((fp->insn[i] & 0xffff) << 16) |
((fp->insn[i] >> 16) & 0xffff);
}
- }
- pipe_buffer_unmap(pscreen, fp->buffer);
+ pipe_buffer_unmap(pipe, fp->buffer, transfer);
+ }
}
static boolean
nvfx_fragprog_validate(struct nvfx_context *nvfx)
{
+ struct pipe_context *pipe = &nvfx->pipe;
struct nvfx_fragment_program *fp = nvfx->fragprog;
- struct pipe_buffer *constbuf =
+ struct pipe_resource *constbuf =
nvfx->constbuf[PIPE_SHADER_FRAGMENT];
struct pipe_screen *pscreen = nvfx->pipe.screen;
struct nouveau_stateobj *so;
return FALSE;
}
- fp->buffer = pscreen->buffer_create(pscreen, 0x100, 0, fp->insn_len * 4);
+ fp->buffer = pipe_buffer_create(pscreen,
+ /* XXX: no alignment, maybe use a priv bind flag
+ * 0x100,
+ */
+ 0, fp->insn_len * 4);
nvfx_fragprog_upload(nvfx, fp);
so = so_new(4, 4, 1);
so_method(so, nvfx->screen->eng3d, NV34TCL_FP_ACTIVE_PROGRAM, 1);
- so_reloc (so, nouveau_bo(fp->buffer), 0, NOUVEAU_BO_VRAM |
+ so_reloc (so, nvfx_resource(fp->buffer)->bo, 0, NOUVEAU_BO_VRAM |
NOUVEAU_BO_GART | NOUVEAU_BO_RD | NOUVEAU_BO_LOW |
NOUVEAU_BO_OR, NV34TCL_FP_ACTIVE_PROGRAM_DMA0,
NV34TCL_FP_ACTIVE_PROGRAM_DMA1);
update_constants:
if (fp->nr_consts) {
+ struct pipe_transfer *transfer;
float *map;
- map = pipe_buffer_map(pscreen, constbuf,
- PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(pipe, constbuf,
+ PIPE_TRANSFER_READ,
+ &transfer);
+
+ /* XXX: probably a bad idea to be reading back data
+ * from a buffer the gpu has been using. Not really
+ * sure what this code is doing though, or how to
+ * avoid it - kw.
+ */
for (i = 0; i < fp->nr_consts; i++) {
struct nvfx_fragment_program_data *fpd = &fp->consts[i];
uint32_t *p = &fp->insn[fpd->offset];
memcpy(p, cb, 4 * sizeof(float));
new_consts = TRUE;
}
- pipe_buffer_unmap(pscreen, constbuf);
+ pipe_buffer_unmap(pipe, constbuf, transfer);
if (new_consts)
nvfx_fragprog_upload(nvfx, fp);
struct nvfx_fragment_program *fp)
{
if (fp->buffer)
- pipe_buffer_reference(&fp->buffer, NULL);
+ pipe_resource_reference(&fp->buffer, NULL);
if (fp->so)
so_ref(NULL, &fp->so);
#include "util/u_math.h"
#include "nvfx_context.h"
+#include "nvfx_resource.h"
+#include "nvfx_transfer.h"
#include "nv04_surface_2d.h"
+#include "nouveau/nouveau_util.h"
+/* Currently using separate implementations for buffers and textures,
+ * even though gallium has a unified abstraction of these objects.
+ * Eventually these should be combined, and mechanisms like transfers
+ * be adapted to work for both buffer and texture uploads.
+ */
static void
nvfx_miptree_layout(struct nvfx_miptree *mt)
{
- struct pipe_texture *pt = &mt->base;
+ struct pipe_resource *pt = &mt->base.base;
uint width = pt->width0;
uint offset = 0;
int nr_faces, l, f;
- uint wide_pitch = pt->tex_usage & (PIPE_TEXTURE_USAGE_SAMPLER |
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL |
- PIPE_TEXTURE_USAGE_RENDER_TARGET |
- PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT);
+ uint wide_pitch = pt->bind & (PIPE_BIND_SAMPLER_VIEW |
+ PIPE_BIND_DEPTH_STENCIL |
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT);
if (pt->target == PIPE_TEXTURE_CUBE) {
nr_faces = 6;
}
for (l = 0; l <= pt->last_level; l++) {
- if (wide_pitch && (pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR))
+ if (wide_pitch && (pt->flags & NVFX_RESOURCE_FLAG_LINEAR))
mt->level[l].pitch = align(util_format_get_stride(pt->format, pt->width0), 64);
else
mt->level[l].pitch = util_format_get_stride(pt->format, width);
for (l = 0; l < pt->last_level; l++) {
mt->level[l].image_offset[f] = offset;
- if (!(pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR) &&
+ if (!(pt->flags & NVFX_RESOURCE_FLAG_LINEAR) &&
u_minify(pt->width0, l + 1) > 1 && u_minify(pt->height0, l + 1) > 1)
offset += align(mt->level[l].pitch * u_minify(pt->height0, l), 64);
else
mt->total_size = offset;
}
-static struct pipe_texture *
-nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)
+static boolean
+nvfx_miptree_get_handle(struct pipe_screen *pscreen,
+ struct pipe_resource *ptexture,
+ struct winsys_handle *whandle)
+{
+ struct nvfx_miptree* mt = (struct nvfx_miptree*)ptexture;
+
+ if (!mt || !mt->base.bo)
+ return FALSE;
+
+ return nouveau_screen_bo_get_handle(pscreen,
+ mt->base.bo,
+ mt->level[0].pitch,
+ whandle);
+}
+
+
+static void
+nvfx_miptree_destroy(struct pipe_screen *screen, struct pipe_resource *pt)
+{
+ struct nvfx_miptree *mt = (struct nvfx_miptree *)pt;
+ int l;
+
+ nouveau_screen_bo_release(screen, mt->base.bo);
+
+ for (l = 0; l <= pt->last_level; l++) {
+ if (mt->level[l].image_offset)
+ FREE(mt->level[l].image_offset);
+ }
+
+ FREE(mt);
+}
+
+
+
+
+struct u_resource_vtbl nvfx_miptree_vtbl =
+{
+ nvfx_miptree_get_handle, /* get_handle */
+ nvfx_miptree_destroy, /* resource_destroy */
+ NULL, /* is_resource_referenced */
+ nvfx_miptree_transfer_new, /* get_transfer */
+ nvfx_miptree_transfer_del, /* transfer_destroy */
+ nvfx_miptree_transfer_map, /* transfer_map */
+ u_default_transfer_flush_region, /* transfer_flush_region */
+ nvfx_miptree_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+struct pipe_resource *
+nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_resource *pt)
{
struct nvfx_miptree *mt;
- unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL |
- NOUVEAU_BUFFER_USAGE_TEXTURE;
static int no_swizzle = -1;
if(no_swizzle < 0)
no_swizzle = debug_get_bool_option("NOUVEAU_NO_SWIZZLE", FALSE);
- mt = MALLOC(sizeof(struct nvfx_miptree));
+ mt = CALLOC_STRUCT(nvfx_miptree);
if (!mt)
return NULL;
- mt->base = *pt;
- pipe_reference_init(&mt->base.reference, 1);
- mt->base.screen = pscreen;
+
+ mt->base.base = *pt;
+ mt->base.vtbl = &nvfx_miptree_vtbl;
+ pipe_reference_init(&mt->base.base.reference, 1);
+ mt->base.base.screen = pscreen;
/* Swizzled textures must be POT */
if (pt->width0 & (pt->width0 - 1) ||
pt->height0 & (pt->height0 - 1))
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+ mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR;
else
- if (pt->tex_usage & (PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL))
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+ if (pt->bind & (PIPE_BIND_SCANOUT |
+ PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_DEPTH_STENCIL))
+ mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR;
else
- if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+ if (pt->_usage == PIPE_USAGE_DYNAMIC)
+ mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR;
else {
switch (pt->format) {
case PIPE_FORMAT_B5G6R5_UNORM:
are just preserving the pre-unification behavior.
The whole 2D code is going to be rewritten anyway. */
if(nvfx_screen(pscreen)->is_nv4x) {
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+ mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR;
break;
}
/* TODO: Figure out which formats can be swizzled */
case PIPE_FORMAT_R16_SNORM:
{
if (no_swizzle)
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+ mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR;
break;
}
default:
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+ mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR;
}
}
- if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
- buf_usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
-
/* apparently we can't render to swizzled surfaces smaller than 64 bytes, so make them linear.
* If the user did not ask for a render target, they can still render to it, but it will cost them an extra copy.
* This also happens for small mipmaps of large textures. */
- if (pt->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET && util_format_get_stride(pt->format, pt->width0) < 64)
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+ if (pt->bind & PIPE_BIND_RENDER_TARGET &&
+ util_format_get_stride(pt->format, pt->width0) < 64)
+ mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR;
nvfx_miptree_layout(mt);
- mt->buffer = pscreen->buffer_create(pscreen, 256, buf_usage, mt->total_size);
- if (!mt->buffer) {
+ mt->base.bo = nouveau_screen_bo_new(pscreen, 256,
+ pt->_usage, pt->bind, mt->total_size);
+ if (!mt->base.bo) {
FREE(mt);
return NULL;
}
- mt->bo = nouveau_bo(mt->buffer);
- return &mt->base;
+ return &mt->base.base;
}
-static struct pipe_texture *
-nvfx_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
- const unsigned *stride, struct pipe_buffer *pb)
+
+
+
+struct pipe_resource *
+nvfx_miptree_from_handle(struct pipe_screen *pscreen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle)
{
struct nvfx_miptree *mt;
+ unsigned stride;
/* Only supports 2D, non-mipmapped textures for the moment */
- if (pt->target != PIPE_TEXTURE_2D || pt->last_level != 0 ||
- pt->depth0 != 1)
+ if (template->target != PIPE_TEXTURE_2D ||
+ template->last_level != 0 ||
+ template->depth0 != 1)
return NULL;
mt = CALLOC_STRUCT(nvfx_miptree);
if (!mt)
return NULL;
- mt->base = *pt;
- pipe_reference_init(&mt->base.reference, 1);
- mt->base.screen = pscreen;
- mt->level[0].pitch = stride[0];
+ mt->base.bo = nouveau_screen_bo_from_handle(pscreen, whandle, &stride);
+ if (mt->base.bo == NULL) {
+ FREE(mt);
+ return NULL;
+ }
+
+ mt->base.base = *template;
+ pipe_reference_init(&mt->base.base.reference, 1);
+ mt->base.base.screen = pscreen;
+ mt->level[0].pitch = stride;
mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
/* Assume whoever created this buffer expects it to be linear for now */
- mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+ mt->base.base.flags |= NVFX_RESOURCE_FLAG_LINEAR;
- pipe_buffer_reference(&mt->buffer, pb);
- mt->bo = nouveau_bo(mt->buffer);
- return &mt->base;
+ /* XXX: Need to adjust bo refcount??
+ */
+ /* nouveau_bo_ref(bo, &mt->base.bo); */
+ return &mt->base.base;
}
-static void
-nvfx_miptree_destroy(struct pipe_texture *pt)
-{
- struct nvfx_miptree *mt = (struct nvfx_miptree *)pt;
- int l;
- pipe_buffer_reference(&mt->buffer, NULL);
- for (l = 0; l <= pt->last_level; l++) {
- if (mt->level[l].image_offset)
- FREE(mt->level[l].image_offset);
- }
- FREE(mt);
-}
-static struct pipe_surface *
-nvfx_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
+
+/* Surface helpers, not strictly required to implement the resource vtbl:
+ */
+struct pipe_surface *
+nvfx_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_resource *pt,
unsigned face, unsigned level, unsigned zslice,
unsigned flags)
{
ns = CALLOC_STRUCT(nv04_surface);
if (!ns)
return NULL;
- pipe_texture_reference(&ns->base.texture, pt);
+ pipe_resource_reference(&ns->base.texture, pt);
ns->base.format = pt->format;
ns->base.width = u_minify(pt->width0, level);
ns->base.height = u_minify(pt->height0, level);
ns->base.offset = mt->level[level].image_offset[0];
}
- /* create a linear temporary that we can render into if necessary.
- * Note that ns->pitch is always a multiple of 64 for linear surfaces and swizzled surfaces are POT, so
- * ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/
- if((ns->pitch & 63) && (ns->base.usage & (PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER)) == PIPE_BUFFER_USAGE_GPU_WRITE)
- return &nv04_surface_wrap_for_render(pscreen, ((struct nvfx_screen*)pscreen)->eng2d, ns)->base;
+ /* create a linear temporary that we can render into if
+ * necessary.
+ *
+ * Note that ns->pitch is always a multiple of 64 for linear
+ * surfaces and swizzled surfaces are POT, so ns->pitch & 63
+ * is equivalent to (ns->pitch < 64 && swizzled)
+ */
+
+ if ((ns->pitch & 63) &&
+ (ns->base.usage & PIPE_BIND_RENDER_TARGET))
+ {
+ struct nv04_surface_2d* eng2d =
+ ((struct nvfx_screen*)pscreen)->eng2d;
+
+ ns = nv04_surface_wrap_for_render(pscreen, eng2d, ns);
+ }
return &ns->base;
}
-static void
+void
nvfx_miptree_surface_del(struct pipe_surface *ps)
{
struct nv04_surface* ns = (struct nv04_surface*)ps;
if(ns->backing)
{
struct nvfx_screen* screen = (struct nvfx_screen*)ps->texture->screen;
- if(ns->backing->base.usage & PIPE_BUFFER_USAGE_GPU_WRITE)
+ if(ns->backing->base.usage & PIPE_BIND_RENDER_TARGET)
screen->eng2d->copy(screen->eng2d, &ns->backing->base, 0, 0, ps, 0, 0, ns->base.width, ns->base.height);
nvfx_miptree_surface_del(&ns->backing->base);
}
- pipe_texture_reference(&ps->texture, NULL);
+ pipe_resource_reference(&ps->texture, NULL);
FREE(ps);
}
-
-void
-nvfx_screen_init_miptree_functions(struct pipe_screen *pscreen)
-{
- pscreen->texture_create = nvfx_miptree_create;
- pscreen->texture_destroy = nvfx_miptree_destroy;
- pscreen->get_tex_surface = nvfx_miptree_surface_new;
- pscreen->tex_surface_destroy = nvfx_miptree_surface_del;
-
- nouveau_screen(pscreen)->texture_blanket = nvfx_miptree_blanket;
-}
--- /dev/null
+
+#include "pipe/p_context.h"
+#include "nvfx_resource.h"
+#include "nouveau/nouveau_screen.h"
+
+
+/* This doesn't look quite right - this query is supposed to ask
+ * whether the particular context has references to the resource in
+ * any unflushed rendering command buffer, and hence requires a
+ * pipe->flush() for serializing some modification to that resource.
+ *
+ * This seems to be answering the question of whether the resource is
+ * currently on hardware.
+ */
+static unsigned int
+nvfx_resource_is_referenced(struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ unsigned face, unsigned level)
+{
+ return nouveau_reference_flags(nvfx_resource(resource)->bo);
+}
+
+static struct pipe_resource *
+nvfx_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ if (template->target == PIPE_BUFFER)
+ return nvfx_buffer_create(screen, template);
+ else
+ return nvfx_miptree_create(screen, template);
+}
+
+static struct pipe_resource *
+nvfx_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 nvfx_miptree_from_handle(screen, template, whandle);
+}
+
+void
+nvfx_init_resource_functions(struct pipe_context *pipe)
+{
+ pipe->get_transfer = u_get_transfer_vtbl;
+ pipe->transfer_map = u_transfer_map_vtbl;
+ pipe->transfer_flush_region = u_transfer_flush_region_vtbl;
+ pipe->transfer_unmap = u_transfer_unmap_vtbl;
+ pipe->transfer_destroy = u_transfer_destroy_vtbl;
+ pipe->transfer_inline_write = u_transfer_inline_write_vtbl;
+ pipe->is_resource_referenced = nvfx_resource_is_referenced;
+}
+
+void
+nvfx_screen_init_resource_functions(struct pipe_screen *pscreen)
+{
+ pscreen->resource_create = nvfx_resource_create;
+ pscreen->resource_from_handle = nvfx_resource_from_handle;
+ pscreen->resource_get_handle = u_resource_get_handle_vtbl;
+ pscreen->resource_destroy = u_resource_destroy_vtbl;
+ pscreen->user_buffer_create = nvfx_user_buffer_create;
+
+ pscreen->get_tex_surface = nvfx_miptree_surface_new;
+ pscreen->tex_surface_destroy = nvfx_miptree_surface_del;
+}
--- /dev/null
+
+#ifndef NVFX_RESOURCE_H
+#define NVFX_RESOURCE_H
+
+#include "util/u_transfer.h"
+
+struct pipe_resource;
+struct nouveau_bo;
+
+
+/* This gets further specialized into either buffer or texture
+ * structures. In the future we'll want to remove much of that
+ * distinction, but for now try to keep as close to the existing code
+ * as possible and use the vtbl struct to choose between the two
+ * underlying implementations.
+ */
+struct nvfx_resource {
+ struct pipe_resource base;
+ struct u_resource_vtbl *vtbl;
+ struct nouveau_bo *bo;
+};
+
+#define NVFX_MAX_TEXTURE_LEVELS 16
+
+struct nvfx_miptree {
+ struct nvfx_resource base;
+ uint total_size;
+
+ struct {
+ uint pitch;
+ uint *image_offset;
+ } level[NVFX_MAX_TEXTURE_LEVELS];
+
+ unsigned image_nr;
+};
+
+static INLINE
+struct nvfx_resource *nvfx_resource(struct pipe_resource *resource)
+{
+ return (struct nvfx_resource *)resource;
+}
+
+static INLINE struct nouveau_bo *
+nvfx_surface_buffer(struct pipe_surface *surf)
+{
+ struct nvfx_resource *mt = nvfx_resource(surf->texture);
+
+ return mt->bo;
+}
+
+
+void
+nvfx_init_resource_functions(struct pipe_context *pipe);
+
+void
+nvfx_screen_init_resource_functions(struct pipe_screen *pscreen);
+
+
+/* Internal:
+ */
+
+struct pipe_resource *
+nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_resource *pt);
+
+struct pipe_resource *
+nvfx_miptree_from_handle(struct pipe_screen *pscreen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle);
+
+struct pipe_resource *
+nvfx_buffer_create(struct pipe_screen *pscreen,
+ const struct pipe_resource *template);
+
+struct pipe_resource *
+nvfx_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned usage);
+
+
+
+void
+nvfx_miptree_surface_del(struct pipe_surface *ps);
+
+struct pipe_surface *
+nvfx_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_resource *pt,
+ unsigned face, unsigned level, unsigned zslice,
+ unsigned flags);
+
+
+#endif
#include "pipe/p_screen.h"
#include "pipe/p_state.h"
+#include "util/u_simple_screen.h"
#include "nouveau/nouveau_screen.h"
#include "nvfx_context.h"
#include "nvfx_screen.h"
+#include "nvfx_resource.h"
#define NV30TCL_CHIPSET_3X_MASK 0x00000003
#define NV34TCL_CHIPSET_3X_MASK 0x00000010
struct nvfx_screen *screen = nvfx_screen(pscreen);
struct pipe_surface *front = ((struct nouveau_winsys *) pscreen->winsys)->front;
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
+ if (tex_usage & PIPE_BIND_RENDER_TARGET) {
switch (format) {
case PIPE_FORMAT_B8G8R8A8_UNORM:
case PIPE_FORMAT_B5G6R5_UNORM:
break;
}
} else
- if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) {
+ if (tex_usage & PIPE_BIND_DEPTH_STENCIL) {
switch (format) {
case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
case PIPE_FORMAT_X8Z24_UNORM:
return FALSE;
}
-static struct pipe_buffer *
-nvfx_surface_buffer(struct pipe_surface *surf)
-{
- struct nvfx_miptree *mt = (struct nvfx_miptree *)surf->texture;
-
- return mt->buffer;
-}
static void
nvfx_screen_destroy(struct pipe_screen *pscreen)
return NULL;
}
+ nvfx_screen_init_resource_functions(pscreen);
nvfx_screen_init_buffer_functions(screen);
- nvfx_screen_init_miptree_functions(pscreen);
ret = nouveau_grobj_alloc(chan, 0xbeef3097, eng3d_class, &screen->eng3d);
if (ret) {
#include "nouveau/nouveau_screen.h"
#include "nv04_surface_2d.h"
+#include "nvfx_context.h"
struct nvfx_screen {
struct nouveau_screen base;
static struct pipe_sampler_view *
nvfx_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);
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
- pipe_texture_reference(&view->texture, texture);
+ pipe_resource_reference(&view->texture, texture);
view->context = pipe;
}
nvfx_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);
}
static void
nvfx_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
- struct pipe_buffer *buf )
+ struct pipe_resource *buf )
{
struct nvfx_context *nvfx = nvfx_context(pipe);
nvfx->constbuf[shader] = buf;
- nvfx->constbuf_nr[shader] = buf->size / (4 * sizeof(float));
+ nvfx->constbuf_nr[shader] = buf->width0 / (4 * sizeof(float));
if (shader == PIPE_SHADER_VERTEX) {
nvfx->dirty |= NVFX_NEW_VERTPROG;
struct nvfx_fragment_program_data *consts;
unsigned nr_consts;
-
- struct pipe_buffer *buffer;
+
+ /* XXX: just use a nouveau_bo for this?
+ */
+ struct pipe_resource *buffer;
uint32_t fp_control;
struct nouveau_stateobj *so;
};
-#define NVFX_MAX_TEXTURE_LEVELS 16
-
-struct nvfx_miptree {
- struct pipe_texture base;
- struct nouveau_bo *bo;
-
- struct pipe_buffer *buffer;
- uint total_size;
-
- struct {
- uint pitch;
- uint *image_offset;
- } level[NVFX_MAX_TEXTURE_LEVELS];
-};
#endif
#include "nvfx_context.h"
+#include "nvfx_resource.h"
#include "nouveau/nouveau_util.h"
-static struct pipe_buffer *
-nvfx_do_surface_buffer(struct pipe_surface *surface)
-{
- struct nvfx_miptree *mt = (struct nvfx_miptree *)surface->texture;
- return mt->buffer;
-}
-#define nvfx_surface_buffer(ps) nouveau_bo(nvfx_do_surface_buffer(ps))
static boolean
nvfx_state_framebuffer_validate(struct nvfx_context *nvfx)
if (rt_enable & (NV34TCL_RT_ENABLE_COLOR0 | NV34TCL_RT_ENABLE_COLOR1 |
NV40TCL_RT_ENABLE_COLOR2 | NV40TCL_RT_ENABLE_COLOR3)) {
/* Render to at least a colour buffer */
- if (!(rt[0]->base.texture->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)) {
+ if (!(rt[0]->base.texture->flags & NVFX_RESOURCE_FLAG_LINEAR)) {
assert(!(fb->width & (fb->width - 1)) && !(fb->height & (fb->height - 1)));
for (i = 1; i < fb->nr_cbufs; i++)
- assert(!(rt[i]->base.texture->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR));
+ assert(!(rt[i]->base.texture->flags & NVFX_RESOURCE_FLAG_LINEAR));
rt_format = NV34TCL_RT_FORMAT_TYPE_SWIZZLED |
(log2i(rt[0]->base.width) << NV34TCL_RT_FORMAT_LOG2_WIDTH_SHIFT) |
depth_only = 1;
/* Render to depth buffer only */
- if (!(zeta->base.texture->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)) {
+ if (!(zeta->base.texture->flags & NVFX_RESOURCE_FLAG_LINEAR)) {
assert(!(fb->width & (fb->width - 1)) && !(fb->height & (fb->height - 1)));
rt_format = NV34TCL_RT_FORMAT_TYPE_SWIZZLED |
#include "nvfx_context.h"
#include "nvfx_screen.h"
#include "nvfx_state.h"
+#include "nvfx_resource.h"
+#include "nvfx_transfer.h"
struct nvfx_transfer {
struct pipe_transfer base;
};
static void
-nvfx_compatible_transfer_tex(struct pipe_texture *pt, unsigned width, unsigned height,
- struct pipe_texture *template)
+nvfx_compatible_transfer_tex(struct pipe_resource *pt, unsigned width, unsigned height,
+ unsigned bind,
+ struct pipe_resource *template)
{
- memset(template, 0, sizeof(struct pipe_texture));
+ memset(template, 0, sizeof(struct pipe_resource));
template->target = pt->target;
template->format = pt->format;
template->width0 = width;
template->depth0 = 1;
template->last_level = 0;
template->nr_samples = pt->nr_samples;
+ template->bind = bind;
+ template->_usage = PIPE_USAGE_DYNAMIC;
+ template->flags = NVFX_RESOURCE_FLAG_LINEAR;
+}
+
+
+static unsigned nvfx_transfer_bind_flags( unsigned transfer_usage )
+{
+ unsigned bind = 0;
+
+ if (transfer_usage & PIPE_TRANSFER_WRITE)
+ bind |= PIPE_BIND_BLIT_DESTINATION;
- template->tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC |
- NOUVEAU_TEXTURE_USAGE_LINEAR;
+ if (transfer_usage & PIPE_TRANSFER_READ)
+ bind |= PIPE_BIND_BLIT_SOURCE;
+
+ return bind;
}
-static struct pipe_transfer *
-nvfx_transfer_new(struct pipe_context *pipe, struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
+struct pipe_transfer *
+nvfx_miptree_transfer_new(struct pipe_context *pipe,
+ struct pipe_resource *pt,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
{
struct pipe_screen *pscreen = pipe->screen;
struct nvfx_miptree *mt = (struct nvfx_miptree *)pt;
struct nvfx_transfer *tx;
- struct pipe_texture tx_tex_template, *tx_tex;
+ struct pipe_resource tx_tex_template, *tx_tex;
static int no_transfer = -1;
+ unsigned bind = nvfx_transfer_bind_flags(usage);
if(no_transfer < 0)
no_transfer = debug_get_bool_option("NOUVEAU_NO_TRANSFER", TRUE/*XXX:FALSE*/);
+
tx = CALLOC_STRUCT(nvfx_transfer);
if (!tx)
return NULL;
- pipe_texture_reference(&tx->base.texture, pt);
- tx->base.x = x;
- tx->base.y = y;
- tx->base.width = w;
- tx->base.height = h;
- tx->base.stride = mt->level[level].pitch;
+ /* Don't handle 3D transfers yet.
+ */
+ assert(box->depth == 1);
+
+ pipe_resource_reference(&tx->base.resource, pt);
+ tx->base.sr = sr;
tx->base.usage = usage;
- tx->base.face = face;
- tx->base.level = level;
- tx->base.zslice = zslice;
+ tx->base.box = *box;
+ tx->base.stride = mt->level[sr.level].pitch;
/* Direct access to texture */
- if ((pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC || no_transfer) &&
- pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)
+ if ((pt->_usage == PIPE_USAGE_DYNAMIC ||
+ no_transfer) &&
+ pt->flags & NVFX_RESOURCE_FLAG_LINEAR)
{
tx->direct = true;
+
+ /* XXX: just call the internal nvfx function.
+ */
tx->surface = pscreen->get_tex_surface(pscreen, pt,
- face, level, zslice,
- pipe_transfer_buffer_flags(&tx->base));
+ sr.face, sr.level,
+ box->z,
+ bind);
return &tx->base;
}
tx->direct = false;
- nvfx_compatible_transfer_tex(pt, w, h, &tx_tex_template);
+ nvfx_compatible_transfer_tex(pt, box->width, box->height, bind, &tx_tex_template);
- tx_tex = pscreen->texture_create(pscreen, &tx_tex_template);
+ tx_tex = pscreen->resource_create(pscreen, &tx_tex_template);
if (!tx_tex)
{
FREE(tx);
tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
0, 0, 0,
- pipe_transfer_buffer_flags(&tx->base));
+ bind);
- pipe_texture_reference(&tx_tex, NULL);
+ pipe_resource_reference(&tx_tex, NULL);
if (!tx->surface)
{
struct pipe_surface *src;
src = pscreen->get_tex_surface(pscreen, pt,
- face, level, zslice,
- PIPE_BUFFER_USAGE_GPU_READ);
+ sr.face, sr.level, box->z,
+ PIPE_BIND_BLIT_SOURCE);
/* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
/* TODO: Check if SIFM can un-swizzle */
nvscreen->eng2d->copy(nvscreen->eng2d,
tx->surface, 0, 0,
- src, x, y,
- w, h);
+ src,
+ box->x, box->y,
+ box->width, box->height);
pipe_surface_reference(&src, NULL);
}
return &tx->base;
}
-static void
-nvfx_transfer_del(struct pipe_context *pipe,
- struct pipe_transfer *ptx)
+void
+nvfx_miptree_transfer_del(struct pipe_context *pipe,
+ struct pipe_transfer *ptx)
{
struct nvfx_transfer *tx = (struct nvfx_transfer *)ptx;
struct nvfx_screen *nvscreen = nvfx_screen(pscreen);
struct pipe_surface *dst;
- dst = pscreen->get_tex_surface(pscreen, ptx->texture,
- ptx->face, ptx->level, ptx->zslice,
- PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER);
+ dst = pscreen->get_tex_surface(pscreen,
+ ptx->resource,
+ ptx->sr.face,
+ ptx->sr.level,
+ ptx->box.z,
+ PIPE_BIND_BLIT_DESTINATION);
/* TODO: Check if SIFM can deal with x,y,w,h when swizzling */
nvscreen->eng2d->copy(nvscreen->eng2d,
- dst, tx->base.x, tx->base.y,
+ dst, ptx->box.x, ptx->box.y,
tx->surface, 0, 0,
- tx->base.width, tx->base.height);
+ ptx->box.width, ptx->box.height);
pipe_surface_reference(&dst, NULL);
}
pipe_surface_reference(&tx->surface, NULL);
- pipe_texture_reference(&ptx->texture, NULL);
+ pipe_resource_reference(&ptx->resource, NULL);
FREE(ptx);
}
-static void *
-nvfx_transfer_map(struct pipe_context *pipe, struct pipe_transfer *ptx)
+void *
+nvfx_miptree_transfer_map(struct pipe_context *pipe, struct pipe_transfer *ptx)
{
struct pipe_screen *pscreen = pipe->screen;
struct nvfx_transfer *tx = (struct nvfx_transfer *)ptx;
struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
struct nvfx_miptree *mt = (struct nvfx_miptree *)tx->surface->texture;
- void *map = pipe_buffer_map(pscreen, mt->buffer,
- pipe_transfer_buffer_flags(ptx));
+ uint8_t *map = nouveau_screen_bo_map(pscreen, mt->base.bo,
+ nouveau_screen_transfer_flags(ptx->usage));
if(!tx->direct)
return map + ns->base.offset;
else
- return map + ns->base.offset + ptx->y * ns->pitch + ptx->x * util_format_get_blocksize(ptx->texture->format);
+ return (map + ns->base.offset +
+ ptx->box.y * ns->pitch +
+ ptx->box.x * util_format_get_blocksize(ptx->resource->format));
}
-static void
-nvfx_transfer_unmap(struct pipe_context *pipe, struct pipe_transfer *ptx)
+void
+nvfx_miptree_transfer_unmap(struct pipe_context *pipe, struct pipe_transfer *ptx)
{
struct pipe_screen *pscreen = pipe->screen;
struct nvfx_transfer *tx = (struct nvfx_transfer *)ptx;
struct nvfx_miptree *mt = (struct nvfx_miptree *)tx->surface->texture;
- pipe_buffer_unmap(pscreen, mt->buffer);
-}
-
-void
-nvfx_init_transfer_functions(struct nvfx_context *nvfx)
-{
- nvfx->pipe.get_tex_transfer = nvfx_transfer_new;
- nvfx->pipe.tex_transfer_destroy = nvfx_transfer_del;
- nvfx->pipe.transfer_map = nvfx_transfer_map;
- nvfx->pipe.transfer_unmap = nvfx_transfer_unmap;
+ nouveau_screen_bo_unmap(pscreen, mt->base.bo);
}
--- /dev/null
+
+#ifndef NVFX_TRANSFER_H
+#define NVFX_TRANSFER_H
+
+#include "util/u_transfer.h"
+#include "pipe/p_state.h"
+
+
+struct pipe_transfer *
+nvfx_miptree_transfer_new(struct pipe_context *pcontext,
+ struct pipe_resource *pt,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box);
+void
+nvfx_miptree_transfer_del(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx);
+void *
+nvfx_miptree_transfer_map(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx);
+void
+nvfx_miptree_transfer_unmap(struct pipe_context *pcontext,
+ struct pipe_transfer *ptx);
+
+
+#endif
#include "nvfx_context.h"
#include "nvfx_state.h"
+#include "nvfx_resource.h"
#include "nouveau/nouveau_channel.h"
#include "nouveau/nouveau_pushbuf.h"
}
static boolean
-nvfx_vbo_set_idxbuf(struct nvfx_context *nvfx, struct pipe_buffer *ib,
+nvfx_vbo_set_idxbuf(struct nvfx_context *nvfx, struct pipe_resource *ib,
unsigned ib_size)
{
struct pipe_screen *pscreen = &nvfx->screen->base.base;
int attrib, struct pipe_vertex_element *ve,
struct pipe_vertex_buffer *vb)
{
- struct pipe_screen *pscreen = nvfx->pipe.screen;
+ struct pipe_context *pipe = &nvfx->pipe;
struct nouveau_grobj *eng3d = nvfx->screen->eng3d;
+ struct pipe_transfer *transfer;
unsigned type, ncomp;
- void *map;
+ uint8_t *map;
if (nvfx_vbo_format_to_hw(ve->src_format, &type, &ncomp))
return FALSE;
- map = pipe_buffer_map(pscreen, vb->buffer, PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(pipe, vb->buffer, PIPE_TRANSFER_READ, &transfer);
map += vb->buffer_offset + ve->src_offset;
switch (type) {
case NV34TCL_VTXFMT_TYPE_FLOAT:
{
- float *v = map;
+ float *v = (float *)map;
switch (ncomp) {
case 4:
so_data (so, fui(v[0]));
break;
default:
- pipe_buffer_unmap(pscreen, vb->buffer);
+ pipe_buffer_unmap(pipe, vb->buffer, transfer);
return FALSE;
}
}
break;
default:
- pipe_buffer_unmap(pscreen, vb->buffer);
+ pipe_buffer_unmap(pipe, vb->buffer, transfer);
return FALSE;
}
- pipe_buffer_unmap(pscreen, vb->buffer);
+ pipe_buffer_unmap(pipe, vb->buffer, transfer);
return TRUE;
}
static void
nvfx_draw_elements_inline(struct pipe_context *pipe,
- struct pipe_buffer *ib, unsigned ib_size,
+ struct pipe_resource *ib, unsigned ib_size,
unsigned mode, unsigned start, unsigned count)
{
struct nvfx_context *nvfx = nvfx_context(pipe);
- struct pipe_screen *pscreen = pipe->screen;
+ struct pipe_transfer *transfer;
void *map;
- map = pipe_buffer_map(pscreen, ib, PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(pipe, ib, PIPE_TRANSFER_READ, &transfer);
if (!ib) {
NOUVEAU_ERR("failed mapping ib\n");
return;
break;
}
- pipe_buffer_unmap(pscreen, ib);
+ pipe_buffer_unmap(pipe, ib, transfer);
}
static void
void
nvfx_draw_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer, unsigned indexSize,
+ struct pipe_resource *indexBuffer, unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
struct nvfx_context *nvfx = nvfx_context(pipe);
{
struct nouveau_stateobj *vtxbuf, *vtxfmt, *sattr = NULL;
struct nouveau_grobj *eng3d = nvfx->screen->eng3d;
- struct pipe_buffer *ib = nvfx->idxbuf;
+ struct pipe_resource *ib = nvfx->idxbuf;
unsigned ib_format = nvfx->idxbuf_format;
unsigned vb_flags = nvfx->screen->vertex_buffer_flags | NOUVEAU_BO_RD;
int hw;
return FALSE;
}
- so_reloc(vtxbuf, nouveau_bo(vb->buffer),
+ so_reloc(vtxbuf, nvfx_resource(vb->buffer)->bo,
vb->buffer_offset + ve->src_offset,
vb_flags | NOUVEAU_BO_LOW | NOUVEAU_BO_OR,
0, NV34TCL_VTXBUF_ADDRESS_DMA1);
}
if (ib) {
- struct nouveau_bo *bo = nouveau_bo(ib);
+ struct nouveau_bo *bo = nvfx_resource(ib)->bo;
so_method(vtxbuf, eng3d, NV34TCL_IDXBUF_ADDRESS, 2);
so_reloc (vtxbuf, bo, 0, vb_flags | NOUVEAU_BO_LOW, 0, 0);
static boolean
nvfx_vertprog_validate(struct nvfx_context *nvfx)
{
- struct pipe_screen *pscreen = nvfx->pipe.screen;
+ struct pipe_context *pipe = &nvfx->pipe;
struct nvfx_screen *screen = nvfx->screen;
struct nouveau_channel *chan = screen->base.channel;
struct nouveau_grobj *eng3d = screen->eng3d;
struct nvfx_vertex_program *vp;
- struct pipe_buffer *constbuf;
+ struct pipe_resource *constbuf;
+ struct pipe_transfer *transfer;
boolean upload_code = FALSE, upload_data = FALSE;
int i;
float *map = NULL;
if (constbuf) {
- map = pipe_buffer_map(pscreen, constbuf,
- PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(pipe, constbuf,
+ PIPE_TRANSFER_READ,
+ &transfer);
}
for (i = 0; i < vp->nr_consts; i++) {
}
if (constbuf)
- pipe_buffer_unmap(pscreen, constbuf);
+ pipe_buffer_unmap(pipe, constbuf, transfer);
}
/* Upload vtxprog */
r300_fs.c \
r300_query.c \
r300_render.c \
+ r300_resource.c \
r300_screen.c \
r300_screen_buffer.c \
r300_state.c \
if (!pipe->screen->is_format_supported(pipe->screen,
old_format, src->texture->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET |
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
switch (util_format_get_blocksize(old_format)) {
case 1:
new_format = PIPE_FORMAT_I8_UNORM;
draw_destroy(r300->draw);
/* Free the OQ BO. */
- context->screen->buffer_destroy(r300->oqbo);
+ context->screen->resource_destroy(context->screen, r300->oqbo);
/* If there are any queries pending or not destroyed, remove them now. */
foreach_s(query, temp, &r300->query_list) {
FREE(r300);
}
-static unsigned int
-r300_is_texture_referenced(struct pipe_context *context,
- struct pipe_texture *texture,
- unsigned face, unsigned level)
-{
- struct r300_context* r300 = r300_context(context);
- struct r300_texture* tex = r300_texture(texture);
-
- return r300->rws->is_buffer_referenced(r300->rws, tex->buffer);
-}
-
-static unsigned int
-r300_is_buffer_referenced(struct pipe_context *context,
- struct pipe_buffer *buf)
-{
- struct r300_context* r300 = r300_context(context);
-
- return r300_buffer_is_referenced(r300, buf);
-}
static void r300_flush_cb(void *data)
{
draw_set_viewport_state(r300->draw, &r300_viewport_identity);
}
- r300->context.is_texture_referenced = r300_is_texture_referenced;
- r300->context.is_buffer_referenced = r300_is_buffer_referenced;
-
r300_setup_atoms(r300);
/* Open up the OQ BO. */
- r300->oqbo = screen->buffer_create(screen, 4096,
- PIPE_BUFFER_USAGE_PIXEL, 4096);
+ r300->oqbo = pipe_buffer_create(screen,
+ R300_BIND_OQBO, 4096);
make_empty_list(&r300->query_list);
r300_init_flush_functions(r300);
-
r300_init_query_functions(r300);
-
- r300_init_transfer_functions(r300);
-
r300_init_state_functions(r300);
+ r300_init_resource_functions(r300);
r300->invariant_state.dirty = TRUE;
r300->blitter = util_blitter_create(&r300->context);
- r300->upload_ib = u_upload_create(screen,
+ r300->upload_ib = u_upload_create(&r300->context,
32 * 1024, 16,
- PIPE_BUFFER_USAGE_INDEX);
+ PIPE_BIND_INDEX_BUFFER);
if (r300->upload_ib == NULL)
goto no_upload_ib;
- r300->upload_vb = u_upload_create(screen,
+ r300->upload_vb = u_upload_create(&r300->context,
128 * 1024, 16,
- PIPE_BUFFER_USAGE_VERTEX);
+ PIPE_BIND_VERTEX_BUFFER);
if (r300->upload_vb == NULL)
goto no_upload_vb;
#include "pipe/p_context.h"
#include "util/u_inlines.h"
+#include "util/u_transfer.h"
#include "r300_defines.h"
#include "r300_screen.h"
struct r300_texture {
/* Parent class */
- struct pipe_texture tex;
+ struct u_resource b;
/* Offsets into the buffer. */
unsigned offset[R300_MAX_TEXTURE_LEVELS];
unsigned mode, unsigned count);
void (*emit_draw_elements)(
- struct r300_context *r300, struct pipe_buffer* indexBuffer,
+ struct r300_context *r300, struct pipe_resource* indexBuffer,
unsigned indexSize, unsigned minIndex, unsigned maxIndex,
unsigned mode, unsigned start, unsigned count);
struct blitter_context* blitter;
/* Vertex buffer for rendering. */
- struct pipe_buffer* vbo;
+ struct pipe_resource* vbo;
/* Offset into the VBO. */
size_t vbo_offset;
/* Occlusion query buffer. */
- struct pipe_buffer* oqbo;
+ struct pipe_resource* oqbo;
/* Query list. */
struct r300_query *query_current;
struct r300_query query_list;
};
/* Convenience cast wrapper. */
-static INLINE struct r300_texture* r300_texture(struct pipe_texture* tex)
+static INLINE struct r300_texture* r300_texture(struct pipe_resource* tex)
{
return (struct r300_texture*)tex;
}
/* Context initialization. */
struct draw_stage* r300_draw_stage(struct r300_context* r300);
void r300_init_state_functions(struct r300_context* r300);
-void r300_init_surface_functions(struct r300_context* r300);
-void r300_init_tex_functions( struct pipe_context *pipe );
+void r300_init_resource_functions(struct r300_context* r300);
static INLINE boolean CTX_DBG_ON(struct r300_context * ctx, unsigned flags)
{
#define R300_MAX_TEXTURE_LEVELS 13
#define R300_MAX_DRAW_VBO_SIZE (1024 * 1024)
-#define R300_TEXTURE_USAGE_TRANSFER PIPE_TEXTURE_USAGE_CUSTOM
+#define R300_RESOURCE_FLAG_TRANSFER PIPE_RESOURCE_FLAG_DRV_PRIV
/* Non-atom dirty state flags. */
#define R300_NEW_FRAGMENT_SHADER 0x00000020
struct r300_viewport_state* viewport = r300->viewport_state.state;
struct r300_textures_state* texstate = r300->textures_state.state;
static float vec[4] = { 0.0, 0.0, 0.0, 1.0 };
- struct pipe_texture *tex;
+ struct pipe_resource *tex;
switch(constant->Type) {
case RC_CONSTANT_EXTERNAL:
void r300_emit_buffer_validate(struct r300_context *r300,
boolean do_validate_vertex_buffers,
- struct pipe_buffer *index_buffer)
+ struct pipe_resource *index_buffer)
{
struct pipe_framebuffer_state* fb =
(struct pipe_framebuffer_state*)r300->fb_state.state;
struct r300_texture* tex;
struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
struct pipe_vertex_element *velem = r300->velems->velem;
- struct pipe_buffer *pbuf;
+ struct pipe_resource *pbuf;
unsigned i;
boolean invalid = FALSE;
void r300_emit_buffer_validate(struct r300_context *r300,
boolean do_validate_vertex_buffers,
- struct pipe_buffer *index_buffer);
+ struct pipe_resource *index_buffer);
#endif /* R300_EMIT_H */
static void r300_begin_query(struct pipe_context* pipe,
struct pipe_query* query)
{
- uint32_t* map;
+ uint32_t value = ~0U;
struct r300_context* r300 = r300_context(pipe);
struct r300_query* q = (struct r300_query*)query;
assert(r300->query_current == NULL);
- map = pipe->screen->buffer_map(pipe->screen, r300->oqbo,
- PIPE_BUFFER_USAGE_CPU_WRITE);
- map += q->offset / 4;
- *map = ~0U;
- pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
+ pipe_buffer_write(pipe,
+ r300->oqbo,
+ q->offset,
+ sizeof value,
+ &value);
q->flushed = FALSE;
r300->query_current = q;
struct r300_context* r300 = r300_context(pipe);
struct r300_screen* r300screen = r300->screen;
struct r300_query *q = (struct r300_query*)query;
- unsigned flags = PIPE_BUFFER_USAGE_CPU_READ;
+ struct pipe_transfer *transfer;
+ unsigned flags = PIPE_TRANSFER_READ;
uint32_t* map;
uint32_t temp = 0;
unsigned i, num_results;
if (q->flushed == FALSE)
pipe->flush(pipe, 0, NULL);
if (!wait) {
- flags |= PIPE_BUFFER_USAGE_DONTBLOCK;
+ flags |= PIPE_TRANSFER_DONTBLOCK;
}
- map = pipe->screen->buffer_map(pipe->screen, r300->oqbo, flags);
+ map = pipe_buffer_map(pipe, r300->oqbo, flags, &transfer);
if (!map)
return FALSE;
map += q->offset / 4;
temp += *map;
map++;
}
- pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
+ pipe_buffer_unmap(pipe, r300->oqbo, transfer);
if (temp == ~0U) {
/* Our results haven't been written yet... */
if (!checked[vbi]) {
vbuf = &r300->vertex_buffer[vbi];
- if (r300_buffer_is_referenced(r300, vbuf->buffer)) {
+ if (r300->context.is_resource_referenced(&r300->context,
+ vbuf->buffer,
+ 0, 0)) {
/* It's a very bad idea to map it... */
return FALSE;
}
/* Mapped vertex buffers. */
uint32_t* map[PIPE_MAX_ATTRIBS] = {0};
+ struct pipe_transfer* transfer[PIPE_MAX_ATTRIBS] = {NULL};
CS_LOCALS(r300);
/* Map the buffer. */
if (!map[vbi]) {
vbuf = &r300->vertex_buffer[vbi];
- map[vbi] = (uint32_t*)pipe_buffer_map(r300->context.screen,
+ map[vbi] = (uint32_t*)pipe_buffer_map(&r300->context,
vbuf->buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &transfer[vbi]);
map[vbi] += vbuf->buffer_offset / 4;
stride[vbi] = vbuf->stride / 4;
}
if (map[vbi]) {
vbuf = &r300->vertex_buffer[vbi];
- pipe_buffer_unmap(r300->context.screen, vbuf->buffer);
+ pipe_buffer_unmap(&r300->context, vbuf->buffer, transfer[vbi]);
map[vbi] = NULL;
}
}
}
void r500_emit_draw_elements(struct r300_context *r300,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
}
void r300_emit_draw_elements(struct r300_context *r300,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
}
static void r300_shorten_ubyte_elts(struct r300_context* r300,
- struct pipe_buffer** elts,
+ struct pipe_resource** elts,
unsigned start,
unsigned count)
{
+ struct pipe_context* context = &r300->context;
struct pipe_screen* screen = r300->context.screen;
- struct pipe_buffer* new_elts;
+ struct pipe_resource* new_elts;
unsigned char *in_map;
unsigned short *out_map;
+ struct pipe_transfer *src_transfer, *dst_transfer;
unsigned i;
- new_elts = screen->buffer_create(screen, 32,
- PIPE_BUFFER_USAGE_INDEX |
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_GPU_READ,
- 2 * count);
+ new_elts = pipe_buffer_create(screen,
+ PIPE_BIND_INDEX_BUFFER,
+ 2 * count);
- in_map = pipe_buffer_map(screen, *elts, PIPE_BUFFER_USAGE_CPU_READ);
- out_map = pipe_buffer_map(screen, new_elts, PIPE_BUFFER_USAGE_CPU_WRITE);
+ in_map = pipe_buffer_map(context, *elts, PIPE_TRANSFER_READ, &src_transfer);
+ out_map = pipe_buffer_map(context, new_elts, PIPE_TRANSFER_WRITE, &dst_transfer);
in_map += start;
out_map++;
}
- pipe_buffer_unmap(screen, *elts);
- pipe_buffer_unmap(screen, new_elts);
+ pipe_buffer_unmap(context, *elts, src_transfer);
+ pipe_buffer_unmap(context, new_elts, dst_transfer);
*elts = new_elts;
}
static void r300_align_ushort_elts(struct r300_context *r300,
- struct pipe_buffer **elts,
+ struct pipe_resource **elts,
unsigned start, unsigned count)
{
- struct pipe_screen* screen = r300->context.screen;
- struct pipe_buffer* new_elts;
+ struct pipe_context* context = &r300->context;
+ struct pipe_transfer *in_transfer = NULL;
+ struct pipe_transfer *out_transfer = NULL;
+ struct pipe_resource* new_elts;
unsigned short *in_map;
unsigned short *out_map;
- new_elts = screen->buffer_create(screen, 32,
- PIPE_BUFFER_USAGE_INDEX |
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_GPU_READ,
- 2 * count);
+ new_elts = pipe_buffer_create(context->screen,
+ PIPE_BIND_INDEX_BUFFER,
+ 2 * count);
- in_map = pipe_buffer_map(screen, *elts, PIPE_BUFFER_USAGE_CPU_READ);
- out_map = pipe_buffer_map(screen, new_elts, PIPE_BUFFER_USAGE_CPU_WRITE);
+ in_map = pipe_buffer_map(context, *elts,
+ PIPE_TRANSFER_READ, &in_transfer);
+ out_map = pipe_buffer_map(context, new_elts,
+ PIPE_TRANSFER_WRITE, &out_transfer);
memcpy(out_map, in_map+start, 2 * count);
- pipe_buffer_unmap(screen, *elts);
- pipe_buffer_unmap(screen, new_elts);
+ pipe_buffer_unmap(context, *elts, in_transfer);
+ pipe_buffer_unmap(context, new_elts, out_transfer);
*elts = new_elts;
}
/* This is the fast-path drawing & emission for HW TCL. */
void r300_draw_range_elements(struct pipe_context* pipe,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
unsigned count)
{
struct r300_context* r300 = r300_context(pipe);
- struct pipe_buffer* orgIndexBuffer = indexBuffer;
+ struct pipe_resource* orgIndexBuffer = indexBuffer;
#if defined(ENABLE_ALT_NUM_VERTS)
boolean alt_num_verts = r300->screen->caps.is_r500 &&
count > 65536;
}
if (indexBuffer != orgIndexBuffer) {
- pipe_buffer_reference( &indexBuffer, NULL );
+ pipe_resource_reference( &indexBuffer, NULL );
}
}
/* Simple helpers for context setup. Should probably be moved to util. */
void r300_draw_elements(struct pipe_context* pipe,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize, unsigned mode,
unsigned start, unsigned count)
{
unsigned count)
{
struct r300_context* r300 = r300_context(pipe);
+ struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
int i;
if (r300->skip_rendering) {
}
for (i = 0; i < r300->vertex_buffer_count; i++) {
- void* buf = pipe_buffer_map(pipe->screen,
+ void* buf = pipe_buffer_map(pipe,
r300->vertex_buffer[i].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &vb_transfer[i]);
draw_set_mapped_vertex_buffer(r300->draw, i, buf);
}
draw_arrays(r300->draw, mode, start, count);
for (i = 0; i < r300->vertex_buffer_count; i++) {
- pipe_buffer_unmap(pipe->screen, r300->vertex_buffer[i].buffer);
+ pipe_buffer_unmap(pipe, r300->vertex_buffer[i].buffer,
+ vb_transfer[i]);
draw_set_mapped_vertex_buffer(r300->draw, i, NULL);
}
}
/* SW TCL elements, using Draw. */
void r300_swtcl_draw_range_elements(struct pipe_context* pipe,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
unsigned count)
{
struct r300_context* r300 = r300_context(pipe);
+ struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
+ struct pipe_transfer *ib_transfer;
int i;
void* indices;
}
for (i = 0; i < r300->vertex_buffer_count; i++) {
- void* buf = pipe_buffer_map(pipe->screen,
+ void* buf = pipe_buffer_map(pipe,
r300->vertex_buffer[i].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &vb_transfer[i]);
draw_set_mapped_vertex_buffer(r300->draw, i, buf);
}
- indices = pipe_buffer_map(pipe->screen, indexBuffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ indices = pipe_buffer_map(pipe, indexBuffer,
+ PIPE_TRANSFER_READ, &ib_transfer);
draw_set_mapped_element_buffer_range(r300->draw, indexSize,
minIndex, maxIndex, indices);
draw_arrays(r300->draw, mode, start, count);
for (i = 0; i < r300->vertex_buffer_count; i++) {
- pipe_buffer_unmap(pipe->screen, r300->vertex_buffer[i].buffer);
+ pipe_buffer_unmap(pipe, r300->vertex_buffer[i].buffer,
+ vb_transfer[i]);
draw_set_mapped_vertex_buffer(r300->draw, i, NULL);
}
- pipe_buffer_unmap(pipe->screen, indexBuffer);
+ pipe_buffer_unmap(pipe, indexBuffer,
+ ib_transfer);
draw_set_mapped_element_buffer_range(r300->draw, 0, start,
start + count - 1, NULL);
}
unsigned hwprim;
/* VBO */
- struct pipe_buffer* vbo;
+ struct pipe_resource* vbo;
size_t vbo_size;
size_t vbo_offset;
size_t vbo_max_used;
void * vbo_ptr;
+
+ struct pipe_transfer *vbo_transfer;
};
static INLINE struct r300_render*
if (size + r300render->vbo_offset > r300render->vbo_size)
{
- pipe_buffer_reference(&r300->vbo, NULL);
+ pipe_resource_reference(&r300->vbo, NULL);
r300render->vbo = pipe_buffer_create(screen,
- 64,
- PIPE_BUFFER_USAGE_VERTEX,
+ PIPE_BIND_VERTEX_BUFFER,
R300_MAX_DRAW_VBO_SIZE);
r300render->vbo_offset = 0;
r300render->vbo_size = R300_MAX_DRAW_VBO_SIZE;
static void* r300_render_map_vertices(struct vbuf_render* render)
{
struct r300_render* r300render = r300_render(render);
- struct pipe_screen* screen = r300render->r300->context.screen;
- r300render->vbo_ptr = pipe_buffer_map(screen, r300render->vbo,
- PIPE_BUFFER_USAGE_CPU_WRITE);
+ r300render->vbo_ptr = pipe_buffer_map(&r300render->r300->context,
+ r300render->vbo,
+ PIPE_TRANSFER_WRITE,
+ &r300render->vbo_transfer);
return ((uint8_t*)r300render->vbo_ptr + r300render->vbo_offset);
}
ushort max)
{
struct r300_render* r300render = r300_render(render);
- struct pipe_screen* screen = r300render->r300->context.screen;
+ struct pipe_context* context = &r300render->r300->context;
CS_LOCALS(r300render->r300);
BEGIN_CS(2);
OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max);
r300render->vbo_max_used = MAX2(r300render->vbo_max_used,
r300render->vertex_size * (max + 1));
- pipe_buffer_unmap(screen, r300render->vbo);
+ pipe_buffer_unmap(context, r300render->vbo, r300render->vbo_transfer);
}
static void r300_render_release_vertices(struct vbuf_render* render)
unsigned count);
void r500_emit_draw_elements(struct r300_context *r300,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
unsigned count);
void r300_emit_draw_elements(struct r300_context *r300,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
unsigned count);
void r300_draw_range_elements(struct pipe_context* pipe,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
unsigned count);
void r300_draw_elements(struct pipe_context* pipe,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize, unsigned mode,
unsigned start, unsigned count);
unsigned count);
void r300_swtcl_draw_range_elements(struct pipe_context* pipe,
- struct pipe_buffer* indexBuffer,
+ struct pipe_resource* indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
--- /dev/null
+/*
+ * Copyright 2010 Red Hat Inc.
+ *
+ * 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
+ * on 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
+ * THE AUTHOR(S) AND/OR THEIR 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: Dave Airlie
+ */
+#include <stdio.h>
+
+#include "util/u_inlines.h"
+#include "util/u_format.h"
+#include "util/u_memory.h"
+#include "util/u_upload_mgr.h"
+#include "util/u_math.h"
+
+#include "r300_context.h"
+#include "r300_texture.h"
+#include "r300_transfer.h"
+#include "r300_screen.h"
+#include "r300_state_inlines.h"
+#include "r300_screen_buffer.h"
+
+#include "r300_winsys.h"
+
+
+
+
+static struct pipe_resource *
+r300_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ if (template->target == PIPE_BUFFER)
+ return r300_buffer_create(screen, template);
+ else
+ return r300_texture_create(screen, template);
+
+}
+
+static struct pipe_resource *
+r300_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 r300_texture_from_handle(screen, template, whandle);
+}
+
+
+
+void
+r300_init_resource_functions(struct r300_context *r300)
+{
+ r300->context.get_transfer = u_get_transfer_vtbl;
+ r300->context.transfer_map = u_transfer_map_vtbl;
+ r300->context.transfer_flush_region = u_transfer_flush_region_vtbl;
+ r300->context.transfer_unmap = u_transfer_unmap_vtbl;
+ r300->context.transfer_destroy = u_transfer_destroy_vtbl;
+ r300->context.transfer_inline_write = u_transfer_inline_write_vtbl;
+ r300->context.is_resource_referenced = u_is_resource_referenced_vtbl;
+}
+
+void
+r300_init_screen_resource_functions(struct r300_screen *r300screen)
+{
+ r300screen->screen.resource_create = r300_resource_create;
+ r300screen->screen.resource_from_handle = r300_resource_from_handle;
+ r300screen->screen.resource_get_handle = u_resource_get_handle_vtbl;
+ r300screen->screen.resource_destroy = u_resource_destroy_vtbl;
+ r300screen->screen.user_buffer_create = r300_user_buffer_create;
+
+ r300screen->screen.get_tex_surface = r300_get_tex_surface;
+ r300screen->screen.tex_surface_destroy = r300_tex_surface_destroy;
+}
}
/* Check sampler format support. */
- if ((usage & PIPE_TEXTURE_USAGE_SAMPLER) &&
+ if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
/* Z24 cannot be sampled from on non-r5xx. */
(is_r500 || !is_z24) &&
/* ATI1N is r5xx-only. */
/* ATI2N is supported on r4xx-r5xx. */
(is_r400 || is_r500 || !is_ati2n) &&
r300_is_sampler_format_supported(format)) {
- retval |= PIPE_TEXTURE_USAGE_SAMPLER;
+ retval |= PIPE_BIND_SAMPLER_VIEW;
}
/* Check colorbuffer format support. */
- if ((usage & (PIPE_TEXTURE_USAGE_RENDER_TARGET |
- PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED)) &&
+ if ((usage & (PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED)) &&
/* 2101010 cannot be rendered to on non-r5xx. */
(is_r500 || !is_color2101010) &&
r300_is_colorbuffer_format_supported(format)) {
retval |= usage &
- (PIPE_TEXTURE_USAGE_RENDER_TARGET |
- PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED);
+ (PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED);
}
/* Check depth-stencil format support. */
- if (usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL &&
+ if (usage & PIPE_BIND_DEPTH_STENCIL &&
r300_is_zs_format_supported(format)) {
- retval |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ retval |= PIPE_BIND_DEPTH_STENCIL;
}
return retval == usage;
r300screen->screen.fence_signalled = r300_fence_signalled;
r300screen->screen.fence_finish = r300_fence_finish;
- r300_init_screen_texture_functions(&r300screen->screen);
+ r300_init_screen_resource_functions(r300screen);
- r300_screen_init_buffer_functions(r300screen);
return &r300screen->screen;
}
void r300_init_debug(struct r300_screen* ctx);
+void r300_init_screen_resource_functions(struct r300_screen *r300screen);
+
#endif /* R300_SCREEN_H */
#include "r300_winsys.h"
-boolean r300_buffer_is_referenced(struct r300_context *r300,
- struct pipe_buffer *buf)
+static unsigned r300_buffer_is_referenced(struct pipe_context *context,
+ struct pipe_resource *buf,
+ unsigned face, unsigned level)
{
+ struct r300_context *r300 = r300_context(context);
struct r300_buffer *rbuf = r300_buffer(buf);
+
if (r300_buffer_is_user_buffer(buf))
- return FALSE;
+ return PIPE_UNREFERENCED;
+
+ if (r300->rws->is_buffer_referenced(r300->rws, rbuf->buf))
+ return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
- return r300->rws->is_buffer_referenced(r300->rws, rbuf->buf);
-
+ return PIPE_UNREFERENCED;
}
+
+/* External helper, not required to implent u_resource_vtbl:
+ */
int r300_upload_index_buffer(struct r300_context *r300,
- struct pipe_buffer **index_buffer,
+ struct pipe_resource **index_buffer,
unsigned index_size,
unsigned start,
unsigned count)
{
- struct pipe_buffer *upload_buffer = NULL;
+ struct pipe_resource *upload_buffer = NULL;
unsigned index_offset = start * index_size;
int ret = 0;
}
done:
// if (upload_buffer)
- // pipe_buffer_reference(&upload_buffer, NULL);
+ // pipe_resource_reference(&upload_buffer, NULL);
return ret;
}
+/* External helper, not required to implent u_resource_vtbl:
+ */
int r300_upload_user_buffers(struct r300_context *r300)
{
enum pipe_error ret = PIPE_OK;
for (i = 0; i < nr; i++) {
if (r300_buffer_is_user_buffer(r300->vertex_buffer[i].buffer)) {
- struct pipe_buffer *upload_buffer = NULL;
+ struct pipe_resource *upload_buffer = NULL;
unsigned offset = 0; /*r300->vertex_buffer[i].buffer_offset * 4;*/
- unsigned size = r300->vertex_buffer[i].buffer->size;
+ unsigned size = r300->vertex_buffer[i].buffer->width0;
unsigned upload_offset;
ret = u_upload_buffer(r300->upload_vb,
offset, size,
if (ret)
return ret;
- pipe_buffer_reference(&r300->vertex_buffer[i].buffer, NULL);
+ pipe_resource_reference(&r300->vertex_buffer[i].buffer, NULL);
r300->vertex_buffer[i].buffer = upload_buffer;
r300->vertex_buffer[i].buffer_offset = upload_offset;
}
}
}
-static struct pipe_buffer *r300_buffer_create(struct pipe_screen *screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct r300_screen *r300screen = r300_screen(screen);
- struct r300_buffer *rbuf;
-
- rbuf = CALLOC_STRUCT(r300_buffer);
- if (!rbuf)
- goto error1;
-
- rbuf->magic = R300_BUFFER_MAGIC;
-
- pipe_reference_init(&rbuf->base.reference, 1);
- rbuf->base.screen = screen;
- rbuf->base.alignment = alignment;
- rbuf->base.usage = usage;
- rbuf->base.size = size;
- rbuf->buf = r300_winsys_buffer_create(r300screen,
- alignment,
- usage,
- size);
-
- if (!rbuf->buf)
- goto error2;
-
- return &rbuf->base;
-error2:
- FREE(rbuf);
-error1:
- return NULL;
-}
-
-
-static struct pipe_buffer *r300_user_buffer_create(struct pipe_screen *screen,
- void *ptr,
- unsigned bytes)
+static void r300_buffer_destroy(struct pipe_screen *screen,
+ struct pipe_resource *buf)
{
- struct r300_buffer *rbuf;
-
- rbuf = CALLOC_STRUCT(r300_buffer);
- if (!rbuf)
- goto no_rbuf;
-
- rbuf->magic = R300_BUFFER_MAGIC;
-
- pipe_reference_init(&rbuf->base.reference, 1);
- rbuf->base.screen = screen;
- rbuf->base.alignment = 1;
- rbuf->base.usage = 0;
- rbuf->base.size = bytes;
-
- rbuf->user_buffer = ptr;
- return &rbuf->base;
-
-no_rbuf:
- return NULL;
-}
-
-static void r300_buffer_destroy(struct pipe_buffer *buf)
-{
- struct r300_screen *r300screen = r300_screen(buf->screen);
+ struct r300_screen *r300screen = r300_screen(screen);
struct r300_buffer *rbuf = r300_buffer(buf);
r300_winsys_buffer_destroy(r300screen, rbuf);
static void *
r300_buffer_map_range(struct pipe_screen *screen,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned offset, unsigned length,
unsigned usage )
{
if (rbuf->user_buffer)
return rbuf->user_buffer;
- if (rbuf->base.usage & PIPE_BUFFER_USAGE_CONSTANT)
+ if (rbuf->b.b.bind & PIPE_BIND_CONSTANT_BUFFER) {
goto just_map;
+ }
/* check if the mapping is to a range we already flushed */
- if (usage & PIPE_BUFFER_USAGE_DISCARD) {
+ if (usage & PIPE_TRANSFER_DISCARD) {
for (i = 0; i < rbuf->num_ranges; i++) {
if ((offset >= rbuf->ranges[i].start) &&
rbuf->num_ranges = 0;
rbuf->map = NULL;
rbuf->buf = r300_winsys_buffer_create(r300screen,
- rbuf->base.alignment,
- rbuf->base.usage,
- rbuf->base.size);
+ 16,
+ rbuf->b.b.bind, /* XXX */
+ rbuf->b.b.width0);
break;
}
}
static void
r300_buffer_flush_mapped_range( struct pipe_screen *screen,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned offset,
unsigned length )
{
if (rbuf->user_buffer)
return;
- if (rbuf->base.usage & PIPE_BUFFER_USAGE_CONSTANT)
+ if (rbuf->b.b.bind & PIPE_BIND_CONSTANT_BUFFER)
return;
/* mark the range as used */
rbuf->num_ranges++;
}
-static void *
-r300_buffer_map(struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned usage)
+
+static void
+r300_buffer_unmap(struct pipe_screen *screen,
+ struct pipe_resource *buf)
{
struct r300_screen *r300screen = r300_screen(screen);
struct r300_winsys_screen *rws = r300screen->rws;
struct r300_buffer *rbuf = r300_buffer(buf);
- void *map;
- if (rbuf->user_buffer)
- return rbuf->user_buffer;
+ if (rbuf->buf) {
+ rws->buffer_unmap(rws, rbuf->buf);
+ }
+}
- map = rws->buffer_map(rws, rbuf->buf, usage);
- return map;
+
+
+/* As a first step, keep the original code intact, implement buffer
+ * transfers in terms of the old map/unmap functions.
+ *
+ * Utility functions for transfer create/destroy are hooked in and
+ * just record the arguments to those functions.
+ */
+static void *
+r300_buffer_transfer_map( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ uint8_t *map = r300_buffer_map_range( pipe->screen,
+ transfer->resource,
+ transfer->box.x,
+ transfer->box.width,
+ transfer->usage );
+ if (map == NULL)
+ return NULL;
+
+ /* map_buffer() returned a pointer to the beginning of the buffer,
+ * but transfers are expected to return a pointer to just the
+ * region specified in the box.
+ */
+ return map + transfer->box.x;
}
-static void
-r300_buffer_unmap(struct pipe_screen *screen,
- struct pipe_buffer *buf)
+
+
+static void r300_buffer_transfer_flush_region( struct pipe_context *pipe,
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box)
+{
+ assert(box->x + box->width <= transfer->box.width);
+
+ r300_buffer_flush_mapped_range(pipe->screen,
+ transfer->resource,
+ transfer->box.x + box->x,
+ box->width);
+}
+
+static void r300_buffer_transfer_unmap( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ r300_buffer_unmap(pipe->screen,
+ transfer->resource);
+}
+
+
+
+
+struct u_resource_vtbl r300_buffer_vtbl =
+{
+ u_default_resource_get_handle, /* get_handle */
+ r300_buffer_destroy, /* resource_destroy */
+ r300_buffer_is_referenced, /* is_buffer_referenced */
+ u_default_get_transfer, /* get_transfer */
+ u_default_transfer_destroy, /* transfer_destroy */
+ r300_buffer_transfer_map, /* transfer_map */
+ r300_buffer_transfer_flush_region, /* transfer_flush_region */
+ r300_buffer_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+
+struct pipe_resource *r300_buffer_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
{
struct r300_screen *r300screen = r300_screen(screen);
- struct r300_winsys_screen *rws = r300screen->rws;
- struct r300_buffer *rbuf = r300_buffer(buf);
+ struct r300_buffer *rbuf;
+ unsigned alignment = 16;
- if (rbuf->buf) {
- rws->buffer_unmap(rws, rbuf->buf);
- }
+ rbuf = CALLOC_STRUCT(r300_buffer);
+ if (!rbuf)
+ goto error1;
+
+ rbuf->magic = R300_BUFFER_MAGIC;
+
+ rbuf->b.b = *template;
+ rbuf->b.vtbl = &r300_buffer_vtbl;
+ pipe_reference_init(&rbuf->b.b.reference, 1);
+ rbuf->b.b.screen = screen;
+
+ if (rbuf->b.b.bind & R300_BIND_OQBO)
+ alignment = 4096;
+
+ rbuf->buf = r300_winsys_buffer_create(r300screen,
+ alignment,
+ rbuf->b.b.bind,
+ rbuf->b.b.width0);
+
+ if (!rbuf->buf)
+ goto error2;
+
+ return &rbuf->b.b;
+error2:
+ FREE(rbuf);
+error1:
+ return NULL;
}
-void r300_screen_init_buffer_functions(struct r300_screen *r300screen)
+
+struct pipe_resource *r300_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind)
{
- r300screen->screen.buffer_create = r300_buffer_create;
- r300screen->screen.user_buffer_create = r300_user_buffer_create;
- r300screen->screen.buffer_map = r300_buffer_map;
- r300screen->screen.buffer_map_range = r300_buffer_map_range;
- r300screen->screen.buffer_flush_mapped_range = r300_buffer_flush_mapped_range;
- r300screen->screen.buffer_unmap = r300_buffer_unmap;
- r300screen->screen.buffer_destroy = r300_buffer_destroy;
+ struct r300_buffer *rbuf;
+
+ rbuf = CALLOC_STRUCT(r300_buffer);
+ if (!rbuf)
+ goto no_rbuf;
+
+ rbuf->magic = R300_BUFFER_MAGIC;
+
+ pipe_reference_init(&rbuf->b.b.reference, 1);
+ rbuf->b.vtbl = &r300_buffer_vtbl;
+ rbuf->b.b.screen = screen;
+ rbuf->b.b.format = PIPE_FORMAT_R8_UNORM;
+ rbuf->b.b._usage = PIPE_USAGE_IMMUTABLE;
+ rbuf->b.b.bind = bind;
+ rbuf->b.b.width0 = bytes;
+ rbuf->b.b.height0 = 1;
+ rbuf->b.b.depth0 = 1;
+
+ rbuf->user_buffer = ptr;
+ return &rbuf->b.b;
+
+no_rbuf:
+ return NULL;
}
+
#include <stdio.h>
#include "pipe/p_compiler.h"
#include "pipe/p_state.h"
+#include "util/u_transfer.h"
#include "r300_screen.h"
#include "r300_winsys.h"
struct r300_buffer
{
- struct pipe_buffer base;
+ struct u_resource b;
uint32_t magic;
};
static INLINE struct r300_buffer *
-r300_buffer(struct pipe_buffer *buffer)
+r300_buffer(struct pipe_resource *buffer)
{
if (buffer) {
assert(((struct r300_buffer *)buffer)->magic == R300_BUFFER_MAGIC);
}
static INLINE boolean
-r300_buffer_is_user_buffer(struct pipe_buffer *buffer)
+r300_buffer_is_user_buffer(struct pipe_resource *buffer)
{
return r300_buffer(buffer)->user_buffer ? true : false;
}
static INLINE boolean r300_add_buffer(struct r300_winsys_screen *rws,
- struct pipe_buffer *buffer,
+ struct pipe_resource *buffer,
int rd, int wr)
{
struct r300_buffer *buf = r300_buffer(buffer);
return rws->add_buffer(rws, tex->buffer, rd, wr);
}
-void r300_screen_init_buffer_functions(struct r300_screen *r300screen);
static INLINE void r300_buffer_write_reloc(struct r300_winsys_screen *rws,
struct r300_buffer *buf,
int r300_upload_user_buffers(struct r300_context *r300);
int r300_upload_index_buffer(struct r300_context *r300,
- struct pipe_buffer **index_buffer,
+ struct pipe_resource **index_buffer,
unsigned index_size,
unsigned start,
unsigned count);
-boolean r300_buffer_is_referenced(struct r300_context *r300,
- struct pipe_buffer *buf);
+
+struct pipe_resource *r300_buffer_create(struct pipe_screen *screen,
+ const struct pipe_resource *template);
+
+struct pipe_resource *r300_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned usage);
+
#endif
static struct pipe_sampler_view *
r300_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);
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
- pipe_texture_reference(&view->texture, texture);
+ pipe_resource_reference(&view->texture, texture);
view->context = pipe;
}
r300_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);
}
vbo = (struct pipe_vertex_buffer*)&buffers[i];
/* Reference our buffer. */
- pipe_buffer_reference(&r300->vertex_buffer[i].buffer, vbo->buffer);
+ pipe_resource_reference(&r300->vertex_buffer[i].buffer, vbo->buffer);
/* Skip NULL buffers */
if (!buffers[i].buffer) {
if (vbo->max_index == ~0) {
/* Bogus value from broken state tracker; hax it. */
vbo->max_index =
- (vbo->buffer->size - vbo->buffer_offset) / vbo->stride;
+ (vbo->buffer->width0 - vbo->buffer_offset) / vbo->stride;
}
max_index = MIN2(vbo->max_index, max_index);
for (; i < r300->vertex_buffer_count; i++) {
/* Dereference any old buffers. */
- pipe_buffer_reference(&r300->vertex_buffer[i].buffer, NULL);
+ pipe_resource_reference(&r300->vertex_buffer[i].buffer, NULL);
}
memcpy(r300->vertex_buffer, buffers,
static void r300_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
- struct pipe_buffer *buf)
+ struct pipe_resource *buf)
{
struct r300_context* r300 = r300_context(pipe);
+ struct pipe_transfer *tr;
void *mapped;
int max_size = 0;
- if (buf == NULL || buf->size == 0 ||
- (mapped = pipe_buffer_map(pipe->screen, buf, PIPE_BUFFER_USAGE_CPU_READ)) == NULL)
+ if (buf == NULL || buf->width0 == 0 ||
+ (mapped = pipe_buffer_map(pipe, buf, PIPE_TRANSFER_READ, &tr)) == NULL)
{
r300->shader_constants[shader].count = 0;
return;
}
- assert((buf->size % 4 * sizeof(float)) == 0);
+ assert((buf->width0 % 4 * sizeof(float)) == 0);
/* Check the size of the constant buffer. */
switch (shader) {
}
/* XXX Subtract immediates and RC_STATE_* variables. */
- if (buf->size > (sizeof(float) * 4 * max_size)) {
+ if (buf->width0 > (sizeof(float) * 4 * max_size)) {
fprintf(stderr, "r300: Max size of the constant buffer is "
"%i*4 floats.\n", max_size);
abort();
}
- memcpy(r300->shader_constants[shader].constants, mapped, buf->size);
- r300->shader_constants[shader].count = buf->size / (4 * sizeof(float));
- pipe_buffer_unmap(pipe->screen, buf);
+ memcpy(r300->shader_constants[shader].constants, mapped, buf->width0);
+ r300->shader_constants[shader].count = buf->width0 / (4 * sizeof(float));
+ pipe_buffer_unmap(pipe, buf, tr);
if (shader == PIPE_SHADER_VERTEX) {
if (r300->screen->caps.has_tcl) {
} else if (r300->draw) {
draw_set_mapped_constant_buffer(r300->draw, PIPE_SHADER_VERTEX,
0, r300->shader_constants[PIPE_SHADER_VERTEX].constants,
- buf->size);
+ buf->width0);
}
} else if (shader == PIPE_SHADER_FRAGMENT) {
r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
tex = r300_texture(view->texture);
sampler = state->sampler_states[i];
- assert(view->format == tex->tex.format);
+ assert(view->format == tex->b.b.format);
texstate = &state->regs[i];
memcpy(texstate->format, &tex->state, sizeof(uint32_t)*3);
R300_TXO_MICRO_TILE(tex->microtile);
/* to emulate 1D textures through 2D ones correctly */
- if (tex->tex.target == PIPE_TEXTURE_1D) {
+ if (tex->b.b.target == PIPE_TEXTURE_1D) {
texstate->filter[0] &= ~R300_TX_WRAP_T_MASK;
texstate->filter[0] |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE);
}
/* determine min/max levels */
/* the MAX_MIP level is the largest (finest) one */
max_level = MIN3(sampler->max_lod + view->first_level,
- tex->tex.last_level, view->last_level);
+ tex->b.b.last_level, view->last_level);
min_level = MIN2(sampler->min_lod + view->first_level,
max_level);
texstate->format[0] |= R300_TX_NUM_LEVELS(max_level);
#include "r300_context.h"
#include "r300_texture.h"
+#include "r300_transfer.h"
#include "r300_screen.h"
#include "r300_winsys.h"
static void r300_setup_texture_state(struct r300_screen* screen, struct r300_texture* tex)
{
struct r300_texture_format_state* state = &tex->state;
- struct pipe_texture *pt = &tex->tex;
+ struct pipe_resource *pt = &tex->b.b;
unsigned i;
boolean is_r500 = screen->caps.is_r500;
pt->width0, pt->height0, pt->last_level);
/* Set framebuffer state. */
- if (util_format_is_depth_or_stencil(tex->tex.format)) {
- for (i = 0; i <= tex->tex.last_level; i++) {
+ if (util_format_is_depth_or_stencil(tex->b.b.format)) {
+ for (i = 0; i <= tex->b.b.last_level; i++) {
tex->fb_state.depthpitch[i] =
tex->pitch[i] |
R300_DEPTHMACROTILE(tex->mip_macrotile[i]) |
R300_DEPTHMICROTILE(tex->microtile);
}
- tex->fb_state.zb_format = r300_translate_zsformat(tex->tex.format);
+ tex->fb_state.zb_format = r300_translate_zsformat(tex->b.b.format);
} else {
- for (i = 0; i <= tex->tex.last_level; i++) {
+ for (i = 0; i <= tex->b.b.last_level; i++) {
tex->fb_state.colorpitch[i] =
tex->pitch[i] |
- r300_translate_colorformat(tex->tex.format) |
+ r300_translate_colorformat(tex->b.b.format) |
R300_COLOR_TILE(tex->mip_macrotile[i]) |
R300_COLOR_MICROTILE(tex->microtile);
}
- tex->fb_state.us_out_fmt = r300_translate_out_fmt(tex->tex.format);
+ tex->fb_state.us_out_fmt = r300_translate_out_fmt(tex->b.b.format);
}
}
void r300_texture_reinterpret_format(struct pipe_screen *screen,
- struct pipe_texture *tex,
+ struct pipe_resource *tex,
enum pipe_format new_format)
{
struct r300_screen *r300screen = r300_screen(screen);
{
unsigned offset = tex->offset[level];
- switch (tex->tex.target) {
+ switch (tex->b.b.target) {
case PIPE_TEXTURE_3D:
assert(face == 0);
return offset + zslice * tex->layer_size[level];
{
unsigned pixsize, tile_size;
- pixsize = util_format_get_blocksize(tex->tex.format);
+ pixsize = util_format_get_blocksize(tex->b.b.format);
tile_size = microblock_table[util_logbase2(pixsize)][tex->microtile][dim];
if (macrotile) {
tile = r300_texture_get_tile_size(tex, dim, TRUE);
if (dim == TILE_WIDTH) {
- texdim = u_minify(tex->tex.width0, level);
+ texdim = u_minify(tex->b.b.width0, level);
} else {
- texdim = u_minify(tex->tex.height0, level);
+ texdim = u_minify(tex->b.b.height0, level);
}
/* See TX_FILTER1_n.MACRO_SWITCH. */
return tex->stride_override;
/* Check the level. */
- if (level > tex->tex.last_level) {
+ if (level > tex->b.b.last_level) {
SCREEN_DBG(screen, DBG_TEX, "%s: level (%u) > last_level (%u)\n",
- __FUNCTION__, level, tex->tex.last_level);
+ __FUNCTION__, level, tex->b.b.last_level);
return 0;
}
- width = u_minify(tex->tex.width0, level);
+ width = u_minify(tex->b.b.width0, level);
- if (r300_format_is_plain(tex->tex.format)) {
+ if (r300_format_is_plain(tex->b.b.format)) {
tile_width = r300_texture_get_tile_size(tex, TILE_WIDTH,
tex->mip_macrotile[level]);
width = align(width, tile_width);
- return util_format_get_stride(tex->tex.format, width);
+ return util_format_get_stride(tex->b.b.format, width);
} else {
- return align(util_format_get_stride(tex->tex.format, width), 32);
+ return align(util_format_get_stride(tex->b.b.format, width), 32);
}
}
{
unsigned height, tile_height;
- height = u_minify(tex->tex.height0, level);
+ height = u_minify(tex->b.b.height0, level);
- if (r300_format_is_plain(tex->tex.format)) {
+ if (r300_format_is_plain(tex->b.b.format)) {
tile_height = r300_texture_get_tile_size(tex, TILE_HEIGHT,
tex->mip_macrotile[level]);
height = align(height, tile_height);
height = util_next_power_of_two(height);
}
- return util_format_get_nblocksy(tex->tex.format, height);
+ return util_format_get_nblocksy(tex->b.b.format, height);
}
static void r300_setup_miptree(struct r300_screen* screen,
struct r300_texture* tex)
{
- struct pipe_texture* base = &tex->tex;
+ struct pipe_resource* base = &tex->b.b;
unsigned stride, size, layer_size, nblocksy, i;
boolean rv350_mode = screen->caps.family >= CHIP_FAMILY_RV350;
static void r300_setup_flags(struct r300_texture* tex)
{
- tex->uses_pitch = !util_is_power_of_two(tex->tex.width0) ||
- !util_is_power_of_two(tex->tex.height0) ||
+ tex->uses_pitch = !util_is_power_of_two(tex->b.b.width0) ||
+ !util_is_power_of_two(tex->b.b.height0) ||
tex->stride_override;
}
struct r300_texture *tex)
{
struct r300_winsys_screen *rws = (struct r300_winsys_screen *)screen->winsys;
- enum pipe_format format = tex->tex.format;
+ enum pipe_format format = tex->b.b.format;
boolean rv350_mode = r300_screen(screen)->caps.family >= CHIP_FAMILY_RV350;
if (!r300_format_is_plain(format)) {
return;
}
- if (tex->tex.width0 == 1 ||
- tex->tex.height0 == 1) {
+ if (tex->b.b.width0 == 1 ||
+ tex->b.b.height0 == 1) {
return;
}
}
}
+
+static unsigned r300_texture_is_referenced(struct pipe_context *context,
+ struct pipe_resource *texture,
+ unsigned face, unsigned level)
+{
+ struct r300_context *r300 = r300_context(context);
+ struct r300_texture *rtex = (struct r300_texture *)texture;
+
+ if (r300->rws->is_buffer_referenced(r300->rws, rtex->buffer))
+ return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
+
+ return PIPE_UNREFERENCED;
+}
+
+static void r300_texture_destroy(struct pipe_screen *screen,
+ struct pipe_resource* texture)
+{
+ struct r300_texture* tex = (struct r300_texture*)texture;
+ struct r300_winsys_screen *rws = (struct r300_winsys_screen *)texture->screen->winsys;
+
+ rws->buffer_reference(rws, &tex->buffer, NULL);
+ FREE(tex);
+}
+
+
+
+
+static boolean
+ r300_texture_get_handle(struct pipe_screen* screen,
+ struct pipe_resource *texture,
+ struct winsys_handle *whandle)
+{
+ struct r300_winsys_screen *rws = (struct r300_winsys_screen *)screen->winsys;
+ struct r300_texture* tex = (struct r300_texture*)texture;
+ unsigned stride;
+
+ if (!tex) {
+ return FALSE;
+ }
+
+ stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
+
+ rws->buffer_get_handle(rws, tex->buffer, stride, whandle);
+
+ return TRUE;
+}
+
+
+
+struct u_resource_vtbl r300_texture_vtbl =
+{
+ r300_texture_get_handle, /* get_handle */
+ r300_texture_destroy, /* resource_destroy */
+ r300_texture_is_referenced, /* is_resource_referenced */
+ r300_texture_get_transfer, /* get_transfer */
+ r300_texture_transfer_destroy, /* transfer_destroy */
+ r300_texture_transfer_map, /* transfer_map */
+ u_default_transfer_flush_region, /* transfer_flush_region */
+ r300_texture_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
/* Create a new texture. */
-static struct pipe_texture* r300_texture_create(struct pipe_screen* screen,
- const struct pipe_texture* base)
+struct pipe_resource* r300_texture_create(struct pipe_screen* screen,
+ const struct pipe_resource* base)
{
struct r300_texture* tex = CALLOC_STRUCT(r300_texture);
struct r300_screen* rscreen = r300_screen(screen);
return NULL;
}
- tex->tex = *base;
- pipe_reference_init(&tex->tex.reference, 1);
- tex->tex.screen = screen;
+ tex->b.b = *base;
+ tex->b.vtbl = &r300_texture_vtbl;
+ pipe_reference_init(&tex->b.b.reference, 1);
+ tex->b.b.screen = screen;
r300_setup_flags(tex);
- if (!(base->tex_usage & R300_TEXTURE_USAGE_TRANSFER) &&
- !(base->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT)) {
+ if (!(base->flags & R300_RESOURCE_FLAG_TRANSFER) &&
+ !(base->bind & PIPE_BIND_SCANOUT)) {
r300_setup_tiling(screen, tex);
}
r300_setup_miptree(rscreen, tex);
r300_setup_texture_state(rscreen, tex);
tex->buffer = rws->buffer_create(rws, 2048,
- PIPE_BUFFER_USAGE_PIXEL,
+ PIPE_BIND_SAMPLER_VIEW, /* XXX */
tex->size);
rws->buffer_set_tiling(rws, tex->buffer,
tex->pitch[0],
return NULL;
}
- return (struct pipe_texture*)tex;
+ return (struct pipe_resource*)tex;
}
-static void r300_texture_destroy(struct pipe_texture* texture)
-{
- struct r300_texture* tex = r300_texture(texture);
- struct r300_winsys_screen *rws = (struct r300_winsys_screen *)texture->screen->winsys;
- rws->buffer_reference(rws, &tex->buffer, NULL);
- FREE(tex);
-}
-static struct pipe_surface* r300_get_tex_surface(struct pipe_screen* screen,
- struct pipe_texture* texture,
- unsigned face,
- unsigned level,
- unsigned zslice,
- unsigned flags)
+/* Not required to implement u_resource_vtbl, consider moving to another file:
+ */
+struct pipe_surface* r300_get_tex_surface(struct pipe_screen* screen,
+ struct pipe_resource* texture,
+ unsigned face,
+ unsigned level,
+ unsigned zslice,
+ unsigned flags)
{
struct r300_texture* tex = r300_texture(texture);
struct pipe_surface* surface = CALLOC_STRUCT(pipe_surface);
if (surface) {
pipe_reference_init(&surface->reference, 1);
- pipe_texture_reference(&surface->texture, texture);
+ pipe_resource_reference(&surface->texture, texture);
surface->format = texture->format;
surface->width = u_minify(texture->width0, level);
surface->height = u_minify(texture->height0, level);
return surface;
}
-static void r300_tex_surface_destroy(struct pipe_surface* s)
+/* Not required to implement u_resource_vtbl, consider moving to another file:
+ */
+void r300_tex_surface_destroy(struct pipe_surface* s)
{
- pipe_texture_reference(&s->texture, NULL);
+ pipe_resource_reference(&s->texture, NULL);
FREE(s);
}
-
-static struct pipe_texture*
- r300_texture_from_handle(struct pipe_screen* screen,
- const struct pipe_texture* base,
- struct winsys_handle *whandle)
+struct pipe_resource*
+r300_texture_from_handle(struct pipe_screen* screen,
+ const struct pipe_resource* base,
+ struct winsys_handle *whandle)
{
struct r300_winsys_screen *rws = (struct r300_winsys_screen*)screen->winsys;
struct r300_screen* rscreen = r300_screen(screen);
return NULL;
}
- tex->tex = *base;
- pipe_reference_init(&tex->tex.reference, 1);
- tex->tex.screen = screen;
+ tex->b.b = *base;
+ tex->b.vtbl = &r300_texture_vtbl;
+ pipe_reference_init(&tex->b.b.reference, 1);
+ tex->b.b.screen = screen;
tex->stride_override = stride;
tex->microtile,
tex->macrotile);
}
- return (struct pipe_texture*)tex;
-}
-
-static boolean
- r300_texture_get_handle(struct pipe_screen* screen,
- struct pipe_texture *texture,
- struct winsys_handle *whandle)
-{
- struct r300_winsys_screen *rws = (struct r300_winsys_screen *)screen->winsys;
- struct r300_texture* tex = r300_texture(texture);
- unsigned stride;
-
- if (!tex) {
- return FALSE;
- }
-
- stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
-
- rws->buffer_get_handle(rws, tex->buffer, stride, whandle);
-
- return TRUE;
+ return (struct pipe_resource*)tex;
}
-static struct pipe_video_surface *
-r300_video_surface_create(struct pipe_screen *screen,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
-{
- struct r300_video_surface *r300_vsfc;
- struct pipe_texture base;
-
- assert(screen);
- assert(width && height);
-
- r300_vsfc = CALLOC_STRUCT(r300_video_surface);
- if (!r300_vsfc)
- return NULL;
-
- pipe_reference_init(&r300_vsfc->base.reference, 1);
- r300_vsfc->base.screen = screen;
- r300_vsfc->base.chroma_format = chroma_format;
- r300_vsfc->base.width = width;
- r300_vsfc->base.height = height;
-
- memset(&base, 0, sizeof(struct pipe_texture));
- base.target = PIPE_TEXTURE_2D;
- base.format = PIPE_FORMAT_B8G8R8X8_UNORM;
- base.last_level = 0;
- base.width0 = util_next_power_of_two(width);
- base.height0 = util_next_power_of_two(height);
- base.depth0 = 1;
- base.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER |
- PIPE_TEXTURE_USAGE_RENDER_TARGET;
-
- r300_vsfc->tex = screen->texture_create(screen, &base);
- if (!r300_vsfc->tex)
- {
- FREE(r300_vsfc);
- return NULL;
- }
-
- return &r300_vsfc->base;
-}
-
-static void r300_video_surface_destroy(struct pipe_video_surface *vsfc)
-{
- struct r300_video_surface *r300_vsfc = r300_video_surface(vsfc);
- pipe_texture_reference(&r300_vsfc->tex, NULL);
- FREE(r300_vsfc);
-}
-
-void r300_init_screen_texture_functions(struct pipe_screen* screen)
-{
- screen->texture_create = r300_texture_create;
- screen->texture_from_handle = r300_texture_from_handle;
- screen->texture_get_handle = r300_texture_get_handle;
- screen->texture_destroy = r300_texture_destroy;
- screen->get_tex_surface = r300_get_tex_surface;
- screen->tex_surface_destroy = r300_tex_surface_destroy;
-
- screen->video_surface_create = r300_video_surface_create;
- screen->video_surface_destroy= r300_video_surface_destroy;
-}
-
-boolean r300_get_texture_buffer(struct pipe_screen* screen,
- struct pipe_texture* texture,
- struct r300_winsys_buffer** buffer,
- unsigned* stride)
-{
- struct r300_texture* tex = r300_texture(texture);
- struct r300_winsys_screen *rws = (struct r300_winsys_screen *)screen->winsys;
- struct r300_winsys_buffer *buf;
-
- if (!tex) {
- return FALSE;
- }
-
- rws->buffer_reference(rws, &buf, tex->buffer);
-
- if (stride) {
- *stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
- }
-
- *buffer = buf;
- return TRUE;
-}
#ifndef R300_TEXTURE_H
#define R300_TEXTURE_H
-#include "pipe/p_video_state.h"
#include "util/u_format.h"
#include "r300_reg.h"
struct r300_texture;
-void r300_init_screen_texture_functions(struct pipe_screen* screen);
-
unsigned r300_texture_get_stride(struct r300_screen* screen,
struct r300_texture* tex, unsigned level);
unsigned zslice, unsigned face);
void r300_texture_reinterpret_format(struct pipe_screen *screen,
- struct pipe_texture *tex,
+ struct pipe_resource *tex,
enum pipe_format new_format);
boolean r300_is_colorbuffer_format_supported(enum pipe_format format);
boolean r300_is_sampler_format_supported(enum pipe_format format);
-struct r300_video_surface
-{
- struct pipe_video_surface base;
- struct pipe_texture *tex;
-};
-
-static INLINE struct r300_video_surface *
-r300_video_surface(struct pipe_video_surface *pvs)
-{
- return (struct r300_video_surface *)pvs;
-}
-
-/* Used internally for texture_is_referenced()
- */
-boolean r300_get_texture_buffer(struct pipe_screen* screen,
- struct pipe_texture *texture,
- struct r300_winsys_buffer** buffer,
- unsigned* stride);
+
+struct pipe_resource*
+r300_texture_from_handle(struct pipe_screen* screen,
+ const struct pipe_resource* base,
+ struct winsys_handle *whandle);
+
+struct pipe_resource*
+r300_texture_create(struct pipe_screen* screen,
+ const struct pipe_resource* template);
+
+
+struct pipe_surface* r300_get_tex_surface(struct pipe_screen* screen,
+ struct pipe_resource* texture,
+ unsigned face,
+ unsigned level,
+ unsigned zslice,
+ unsigned flags);
+
+void r300_tex_surface_destroy(struct pipe_surface* s);
#endif /* R300_TEXTURE_H */
/* Pipe context. */
struct pipe_context *ctx;
- /* Parameters of get_tex_transfer. */
- unsigned x, y, level, zslice, face;
-
/* Offset from start of buffer. */
unsigned offset;
struct r300_texture *detiled_texture;
/* Transfer and format flags. */
- unsigned buffer_usage, render_target_usage;
+ unsigned render_target_usage;
};
/* Convenience cast wrapper. */
{
struct pipe_screen *screen = ctx->screen;
struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer;
- struct pipe_texture *tex = transfer->texture;
+ struct pipe_resource *tex = transfer->resource;
struct pipe_surface *src, *dst;
- src = screen->get_tex_surface(screen, tex, r300transfer->face,
- r300transfer->level, r300transfer->zslice,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_PIXEL);
+ src = screen->get_tex_surface(screen, tex,
+ transfer->sr.face,
+ transfer->sr.level,
+ transfer->box.z,
+ PIPE_BIND_BLIT_SOURCE);
- dst = screen->get_tex_surface(screen, &r300transfer->detiled_texture->tex,
+ dst = screen->get_tex_surface(screen, &r300transfer->detiled_texture->b.b,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE |
- PIPE_BUFFER_USAGE_PIXEL |
- r300transfer->buffer_usage);
+ PIPE_BIND_BLIT_DESTINATION);
- ctx->surface_copy(ctx, dst, 0, 0, src, r300transfer->x, r300transfer->y,
- transfer->width, transfer->height);
+ ctx->surface_copy(ctx, dst, 0, 0, src,
+ transfer->box.x, transfer->box.y,
+ transfer->box.width, transfer->box.height);
pipe_surface_reference(&src, NULL);
pipe_surface_reference(&dst, NULL);
{
struct pipe_screen *screen = ctx->screen;
struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer;
- struct pipe_texture *tex = transfer->texture;
+ struct pipe_resource *tex = transfer->resource;
struct pipe_surface *src, *dst;
- src = screen->get_tex_surface(screen, &r300transfer->detiled_texture->tex,
+ src = screen->get_tex_surface(screen, &r300transfer->detiled_texture->b.b,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_PIXEL);
+ PIPE_BIND_BLIT_SOURCE);
- dst = screen->get_tex_surface(screen, tex, r300transfer->face,
- r300transfer->level, r300transfer->zslice,
- PIPE_BUFFER_USAGE_GPU_WRITE |
- PIPE_BUFFER_USAGE_PIXEL);
+ dst = screen->get_tex_surface(screen, tex,
+ transfer->sr.face,
+ transfer->sr.level,
+ transfer->box.z,
+ PIPE_BIND_BLIT_DESTINATION);
/* XXX this flush prevents the following DRM error from occuring:
* [drm:radeon_cs_ioctl] *ERROR* Failed to parse relocation !
* Reproducible with perf/copytex. */
ctx->flush(ctx, 0, NULL);
- ctx->surface_copy(ctx, dst, r300transfer->x, r300transfer->y, src, 0, 0,
- transfer->width, transfer->height);
+ ctx->surface_copy(ctx, dst,
+ transfer->box.x, transfer->box.y,
+ src, 0, 0,
+ transfer->box.width, transfer->box.height);
/* XXX this flush fixes a few piglit tests (e.g. glean/pixelFormats). */
ctx->flush(ctx, 0, NULL);
pipe_surface_reference(&dst, NULL);
}
-static struct pipe_transfer*
-r300_get_tex_transfer(struct pipe_context *ctx,
- struct pipe_texture *texture,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage, unsigned x, unsigned y,
- unsigned w, unsigned h)
+struct pipe_transfer*
+r300_texture_get_transfer(struct pipe_context *ctx,
+ struct pipe_resource *texture,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
{
struct r300_texture *tex = r300_texture(texture);
struct r300_screen *r300screen = r300_screen(ctx->screen);
struct r300_transfer *trans;
- struct pipe_texture base;
+ struct pipe_resource base;
trans = CALLOC_STRUCT(r300_transfer);
if (trans) {
/* Initialize the transfer object. */
- pipe_texture_reference(&trans->transfer.texture, texture);
+ pipe_resource_reference(&trans->transfer.resource, texture);
+ trans->transfer.sr = sr;
trans->transfer.usage = usage;
- trans->transfer.width = w;
- trans->transfer.height = h;
+ trans->transfer.box = *box;
trans->ctx = ctx;
- trans->x = x;
- trans->y = y;
- trans->level = level;
- trans->zslice = zslice;
- trans->face = face;
/* If the texture is tiled, we must create a temporary detiled texture
* for this transfer. */
if (tex->microtile || tex->macrotile) {
- trans->buffer_usage = pipe_transfer_buffer_flags(&trans->transfer);
trans->render_target_usage =
util_format_is_depth_or_stencil(texture->format) ?
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL :
- PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ PIPE_BIND_DEPTH_STENCIL :
+ PIPE_BIND_RENDER_TARGET;
base.target = PIPE_TEXTURE_2D;
base.format = texture->format;
- base.width0 = w;
- base.height0 = h;
+ base.width0 = box->width;
+ base.height0 = box->height;
base.depth0 = 0;
base.last_level = 0;
base.nr_samples = 0;
- base.tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC |
- R300_TEXTURE_USAGE_TRANSFER;
+ base._usage = PIPE_USAGE_DYNAMIC;
+ base.flags = R300_RESOURCE_FLAG_TRANSFER;
/* For texture reading, the temporary (detiled) texture is used as
* a render target when blitting from a tiled texture. */
if (usage & PIPE_TRANSFER_READ) {
- base.tex_usage |= trans->render_target_usage;
+ base.bind |= trans->render_target_usage;
}
/* For texture writing, the temporary texture is used as a sampler
* when blitting into a tiled texture. */
if (usage & PIPE_TRANSFER_WRITE) {
- base.tex_usage |= PIPE_TEXTURE_USAGE_SAMPLER;
+ base.bind |= PIPE_BIND_SAMPLER_VIEW;
}
/* Create the temporary texture. */
trans->detiled_texture = r300_texture(
- ctx->screen->texture_create(ctx->screen,
- &base));
+ ctx->screen->resource_create(ctx->screen,
+ &base));
assert(!trans->detiled_texture->microtile &&
!trans->detiled_texture->macrotile);
/* Set the stride.
- * Parameters x, y, level, zslice, and face remain zero. */
+ *
+ * Even though we are using an internal texture for this,
+ * the transfer sr, box and usage parameters still reflect
+ * the arguments received to get_transfer. We just do the
+ * right thing internally.
+ */
trans->transfer.stride =
r300_texture_get_stride(r300screen, trans->detiled_texture, 0);
r300_copy_from_tiled_texture(ctx, trans);
}
} else {
- trans->transfer.x = x;
- trans->transfer.y = y;
trans->transfer.stride =
- r300_texture_get_stride(r300screen, tex, level);
- trans->transfer.level = level;
- trans->transfer.zslice = zslice;
- trans->transfer.face = face;
- trans->offset = r300_texture_get_offset(tex, level, zslice, face);
+ r300_texture_get_stride(r300screen, tex, sr.level);
+ trans->offset = r300_texture_get_offset(tex, sr.level, box->z, sr.face);
}
}
return &trans->transfer;
}
-static void r300_tex_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *trans)
+void r300_texture_transfer_destroy(struct pipe_context *ctx,
+ struct pipe_transfer *trans)
{
struct r300_transfer *r300transfer = r300_transfer(trans);
r300_copy_into_tiled_texture(r300transfer->ctx, r300transfer);
}
- pipe_texture_reference(
- (struct pipe_texture**)&r300transfer->detiled_texture, NULL);
+ pipe_resource_reference(
+ (struct pipe_resource**)&r300transfer->detiled_texture, NULL);
}
- pipe_texture_reference(&trans->texture, NULL);
+ pipe_resource_reference(&trans->resource, NULL);
FREE(trans);
}
-static void* r300_transfer_map(struct pipe_context *ctx,
- struct pipe_transfer *transfer)
+void* r300_texture_transfer_map(struct pipe_context *ctx,
+ struct pipe_transfer *transfer)
{
struct r300_winsys_screen *rws = (struct r300_winsys_screen *)ctx->winsys;
struct r300_transfer *r300transfer = r300_transfer(transfer);
- struct r300_texture *tex = r300_texture(transfer->texture);
+ struct r300_texture *tex = r300_texture(transfer->resource);
char *map;
- enum pipe_format format = tex->tex.format;
+ enum pipe_format format = tex->b.b.format;
if (r300transfer->detiled_texture) {
/* The detiled texture is of the same size as the region being mapped
* (no offset needed). */
return rws->buffer_map(rws,
r300transfer->detiled_texture->buffer,
- pipe_transfer_buffer_flags(transfer));
+ transfer->usage);
} else {
/* Tiling is disabled. */
map = rws->buffer_map(rws, tex->buffer,
- pipe_transfer_buffer_flags(transfer));
+ transfer->usage);
if (!map) {
return NULL;
}
return map + r300_transfer(transfer)->offset +
- transfer->y / util_format_get_blockheight(format) * transfer->stride +
- transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
+ transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
}
}
-static void r300_transfer_unmap(struct pipe_context *ctx,
- struct pipe_transfer *transfer)
+void r300_texture_transfer_unmap(struct pipe_context *ctx,
+ struct pipe_transfer *transfer)
{
struct r300_winsys_screen *rws = (struct r300_winsys_screen *)ctx->winsys;
struct r300_transfer *r300transfer = r300_transfer(transfer);
- struct r300_texture *tex = r300_texture(transfer->texture);
+ struct r300_texture *tex = r300_texture(transfer->resource);
if (r300transfer->detiled_texture) {
rws->buffer_unmap(rws, r300transfer->detiled_texture->buffer);
}
}
-
-void r300_init_transfer_functions( struct r300_context *r300ctx )
-{
- struct pipe_context *ctx = &r300ctx->context;
-
- ctx->get_tex_transfer = r300_get_tex_transfer;
- ctx->tex_transfer_destroy = r300_tex_transfer_destroy;
- ctx->transfer_map = r300_transfer_map;
- ctx->transfer_unmap = r300_transfer_unmap;
-}
struct r300_context;
-void r300_init_transfer_functions(struct r300_context *r300ctx);
+struct pipe_transfer*
+r300_texture_get_transfer(struct pipe_context *ctx,
+ struct pipe_resource *texture,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box);
+
+void
+r300_texture_transfer_destroy(struct pipe_context *ctx,
+ struct pipe_transfer *trans);
+
+void*
+r300_texture_transfer_map(struct pipe_context *ctx,
+ struct pipe_transfer *transfer);
+
+void
+r300_texture_transfer_unmap(struct pipe_context *ctx,
+ struct pipe_transfer *transfer);
+
#endif
struct r300_winsys_buffer;
+/* XXX: this is just a bandaid on larger problems in
+ * r300_screen_buffer.h which doesn't seem to be fully ported to
+ * gallium-resources.
+ */
+#define R300_BIND_OQBO (1<<21)
-boolean r300_get_texture_buffer(struct pipe_screen* screen,
- struct pipe_texture* texture,
- struct r300_winsys_buffer** buffer,
- unsigned *stride);
enum r300_value_id {
R300_VID_PCI_ID,
unsigned offset,
unsigned length);
- /* Add a pipe_buffer to the list of buffer objects to validate. */
+ /* Add a pipe_resource to the list of buffer objects to validate. */
boolean (*add_buffer)(struct r300_winsys_screen *winsys,
struct r300_winsys_buffer *buf,
uint32_t rd,
C_SOURCES = \
sp_fs_exec.c \
sp_fs_sse.c \
- sp_buffer.c \
sp_clear.c \
sp_fence.c \
sp_flush.c \
sp_tex_sample.c \
sp_tex_tile_cache.c \
sp_tile_cache.c \
- sp_surface.c \
- sp_video_context.c
+ sp_surface.c
include ../../Makefile.template
source = [
'sp_fs_exec.c',
'sp_fs_sse.c',
- 'sp_buffer.c',
'sp_clear.c',
'sp_context.c',
'sp_draw_arrays.c',
'sp_tex_tile_cache.c',
'sp_texture.c',
'sp_tile_cache.c',
- 'sp_video_context.c'
])
Export('softpipe')
+++ /dev/null
-/**************************************************************************
- *
- * 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 "sp_screen.h"
-#include "sp_buffer.h"
-
-
-static void *
-softpipe_buffer_map(struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned flags)
-{
- struct softpipe_buffer *softpipe_buf = softpipe_buffer(buf);
- return softpipe_buf->data;
-}
-
-
-static void
-softpipe_buffer_unmap(struct pipe_screen *screen,
- struct pipe_buffer *buf)
-{
-}
-
-
-static void
-softpipe_buffer_destroy(struct pipe_buffer *buf)
-{
- struct softpipe_buffer *sbuf = softpipe_buffer(buf);
-
- if (!sbuf->userBuffer)
- align_free(sbuf->data);
-
- FREE(sbuf);
-}
-
-
-static struct pipe_buffer *
-softpipe_buffer_create(struct pipe_screen *screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct softpipe_buffer *buffer = CALLOC_STRUCT(softpipe_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 *
-softpipe_user_buffer_create(struct pipe_screen *screen,
- void *ptr,
- unsigned bytes)
-{
- struct softpipe_buffer *buffer;
-
- buffer = CALLOC_STRUCT(softpipe_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
-softpipe_init_screen_buffer_funcs(struct pipe_screen *screen)
-{
- screen->buffer_create = softpipe_buffer_create;
- screen->user_buffer_create = softpipe_user_buffer_create;
- screen->buffer_map = softpipe_buffer_map;
- screen->buffer_unmap = softpipe_buffer_unmap;
- screen->buffer_destroy = softpipe_buffer_destroy;
-}
+++ /dev/null
-/**************************************************************************
- *
- * 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 SP_BUFFER_H
-#define SP_BUFFER_H
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_state.h"
-
-
-struct softpipe_buffer
-{
- struct pipe_buffer base;
- boolean userBuffer; /** Is this a user-space buffer? */
- void *data;
-};
-
-
-/** Cast wrapper */
-static INLINE struct softpipe_buffer *
-softpipe_buffer( struct pipe_buffer *buf )
-{
- return (struct softpipe_buffer *)buf;
-}
-
-
-void
-softpipe_init_screen_buffer_funcs(struct pipe_screen *screen);
-
-
-#endif /* SP_BUFFER_H */
for (j = 0; j < PIPE_MAX_CONSTANT_BUFFERS; j++) {
if (softpipe->constants[i][j]) {
- pipe_buffer_reference(&softpipe->constants[i][j], NULL);
+ pipe_resource_reference(&softpipe->constants[i][j], NULL);
}
}
}
* return PIPE_UNREFERENCED
*/
static unsigned int
-softpipe_is_texture_referenced( struct pipe_context *pipe,
- struct pipe_texture *texture,
+softpipe_is_resource_referenced( struct pipe_context *pipe,
+ struct pipe_resource *texture,
unsigned face, unsigned level)
{
struct softpipe_context *softpipe = softpipe_context( pipe );
unsigned i;
+ if (texture->target == PIPE_BUFFER)
+ return PIPE_UNREFERENCED;
+
/* check if any of the bound drawing surfaces are this texture */
if (softpipe->dirty_render_cache) {
for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) {
}
-static unsigned int
-softpipe_is_buffer_referenced( struct pipe_context *pipe,
- struct pipe_buffer *buf)
-{
- return PIPE_UNREFERENCED;
-}
static void
softpipe->pipe.clear = softpipe_clear;
softpipe->pipe.flush = softpipe_flush;
- softpipe->pipe.is_texture_referenced = softpipe_is_texture_referenced;
- softpipe->pipe.is_buffer_referenced = softpipe_is_buffer_referenced;
+ softpipe->pipe.is_resource_referenced = softpipe_is_resource_referenced;
softpipe_init_query_funcs( softpipe );
softpipe_init_texture_funcs( &softpipe->pipe );
struct pipe_blend_color blend_color;
struct pipe_stencil_ref stencil_ref;
struct pipe_clip_state clip;
- struct pipe_buffer *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
+ struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
struct pipe_framebuffer_state framebuffer;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
#include "sp_context.h"
#include "sp_query.h"
#include "sp_state.h"
-#include "sp_buffer.h"
+#include "sp_texture.h"
#include "draw/draw_context.h"
*/
static void
softpipe_draw_range_elements_instanced(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
void
softpipe_draw_range_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned min_index,
unsigned max_index,
void
softpipe_draw_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
void
softpipe_draw_elements_instanced(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode,
unsigned start,
static void
softpipe_draw_range_elements_instanced(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
/* Map vertex buffers */
for (i = 0; i < sp->num_vertex_buffers; i++) {
- void *buf = softpipe_buffer(sp->vertex_buffer[i].buffer)->data;
+ void *buf = softpipe_resource(sp->vertex_buffer[i].buffer)->data;
draw_set_mapped_vertex_buffer(draw, i, buf);
}
/* Map index buffer, if present */
if (indexBuffer) {
- void *mapped_indexes = softpipe_buffer(indexBuffer)->data;
+ void *mapped_indexes = softpipe_resource(indexBuffer)->data;
draw_set_mapped_element_buffer_range(draw,
indexSize,
minIndex,
#include "sp_texture.h"
#include "sp_screen.h"
#include "sp_context.h"
-#include "sp_buffer.h"
#include "sp_fence.h"
#include "sp_public.h"
break;
}
- if(tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED)) {
+ if(tex_usage & (PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED)) {
if(!winsys->is_displaytarget_format_supported(winsys, tex_usage, format))
return FALSE;
}
{
struct softpipe_screen *screen = softpipe_screen(_screen);
struct sw_winsys *winsys = screen->winsys;
- struct softpipe_texture *texture = softpipe_texture(surface->texture);
+ struct softpipe_resource *texture = softpipe_resource(surface->texture);
assert(texture->dt);
if (texture->dt)
util_format_s3tc_init();
softpipe_init_screen_texture_funcs(&screen->base);
- softpipe_init_screen_buffer_funcs(&screen->base);
softpipe_init_screen_fence_funcs(&screen->base);
return &screen->base;
void softpipe_set_constant_buffer(struct pipe_context *,
uint shader, uint index,
- struct pipe_buffer *buf);
+ struct pipe_resource *buf);
void *softpipe_create_fs_state(struct pipe_context *,
const struct pipe_shader_state *);
struct pipe_sampler_view *
softpipe_create_sampler_view(struct pipe_context *pipe,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
const struct pipe_sampler_view *templ);
void
unsigned start, unsigned count);
void softpipe_draw_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count);
void
softpipe_draw_range_elements(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned min_index,
unsigned max_index,
void
softpipe_draw_elements_instanced(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode,
unsigned start,
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
struct softpipe_tex_tile_cache *tc = softpipe->tex_cache[i];
if (tc->texture) {
- struct softpipe_texture *spt = softpipe_texture(tc->texture);
+ struct softpipe_resource *spt = softpipe_resource(tc->texture);
if (spt->timestamp != tc->timestamp) {
sp_tex_tile_cache_validate_texture( tc );
/*
struct softpipe_tex_tile_cache *tc = softpipe->vertex_tex_cache[i];
if (tc->texture) {
- struct softpipe_texture *spt = softpipe_texture(tc->texture);
+ struct softpipe_resource *spt = softpipe_resource(tc->texture);
if (spt->timestamp != tc->timestamp) {
sp_tex_tile_cache_validate_texture(tc);
#include "sp_context.h"
#include "sp_state.h"
#include "sp_fs.h"
-#include "sp_buffer.h"
+#include "sp_texture.h"
#include "pipe/p_defines.h"
#include "util/u_memory.h"
void
softpipe_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
- struct pipe_buffer *constants)
+ struct pipe_resource *constants)
{
struct softpipe_context *softpipe = softpipe_context(pipe);
- unsigned size = constants ? constants->size : 0;
- const void *data = constants ? softpipe_buffer(constants)->data : NULL;
+ unsigned size = constants ? constants->width0 : 0;
+ const void *data = constants ? softpipe_resource(constants)->data : NULL;
assert(shader < PIPE_SHADER_TYPES);
assert(index == 0);
draw_flush(softpipe->draw);
/* note: reference counting */
- pipe_buffer_reference(&softpipe->constants[shader][index], constants);
+ pipe_resource_reference(&softpipe->constants[shader][index], constants);
if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) {
draw_set_mapped_constant_buffer(softpipe->draw, shader, index, data, size);
*/
#include "util/u_memory.h"
+#include "util/u_inlines.h"
#include "draw/draw_context.h"
#include "draw/draw_context.h"
struct pipe_sampler_view *
softpipe_create_sampler_view(struct pipe_context *pipe,
- struct pipe_texture *texture,
+ struct pipe_resource *resource,
const struct pipe_sampler_view *templ)
{
struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view);
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
- pipe_texture_reference(&view->texture, texture);
+ pipe_resource_reference(&view->texture, resource);
view->context = pipe;
}
softpipe_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);
}
static struct sp_sampler_varient *
get_sampler_varient( unsigned unit,
struct sp_sampler *sampler,
- struct pipe_texture *texture,
+ struct pipe_resource *resource,
unsigned processor )
{
- struct softpipe_texture *sp_texture = softpipe_texture(texture);
+ struct softpipe_resource *sp_texture = softpipe_resource(resource);
struct sp_sampler_varient *v = NULL;
union sp_sampler_key key;
*/
for (i = 0; i <= softpipe->vs->max_sampler; i++) {
if (softpipe->vertex_samplers[i]) {
- struct pipe_texture *texture = NULL;
+ struct pipe_resource *texture = NULL;
if (softpipe->vertex_sampler_views[i]) {
texture = softpipe->vertex_sampler_views[i]->texture;
for (i = 0; i <= softpipe->fs->info.file_max[TGSI_FILE_SAMPLER]; i++) {
if (softpipe->sampler[i]) {
- struct pipe_texture *texture = NULL;
+ struct pipe_resource *texture = NULL;
if (softpipe->sampler_views[i]) {
texture = softpipe->sampler_views[i]->texture;
const float t[QUAD_SIZE],
const float p[QUAD_SIZE])
{
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]);
float rho = MAX2(dsdx, dsdy) * texture->width0;
const float t[QUAD_SIZE],
const float p[QUAD_SIZE])
{
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]);
float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]);
const float t[QUAD_SIZE],
const float p[QUAD_SIZE])
{
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]);
float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]);
float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]);
get_texel_2d(const struct sp_sampler_varient *samp,
union tex_tile_address addr, int x, int y)
{
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
unsigned level = addr.bits.level;
if (x < 0 || x >= (int) u_minify(texture->width0, level) ||
get_texel_3d(const struct sp_sampler_varient *samp,
union tex_tile_address addr, int x, int y, int z)
{
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
unsigned level = addr.bits.level;
if (x < 0 || x >= (int) u_minify(texture->width0, level) ||
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
unsigned level0, j;
int width;
int x[4];
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
unsigned level0, j;
int width, height;
int x[4], y[4];
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
const unsigned *faces = samp->faces; /* zero when not cube-mapping */
unsigned level0, j;
int width, height;
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
unsigned level0, j;
int width, height, depth;
int x[4], y[4], z[4];
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
unsigned level0, j;
int width;
int x0[4], x1[4];
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
unsigned level0, j;
int width, height;
int x0[4], y0[4], x1[4], y1[4];
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
const unsigned *faces = samp->faces; /* zero when not cube-mapping */
unsigned level0, j;
int width, height;
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
unsigned level0, j;
int width, height, depth;
int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4];
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
int level0;
float lambda;
float lod[QUAD_SIZE];
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
float lambda;
float lod[QUAD_SIZE];
float rgba[NUM_CHANNELS][QUAD_SIZE])
{
struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler);
- const struct pipe_texture *texture = samp->texture;
+ const struct pipe_resource *texture = samp->texture;
int level0;
float lambda;
float lod[QUAD_SIZE];
void
sp_sampler_varient_bind_texture( struct sp_sampler_varient *samp,
struct softpipe_tex_tile_cache *tex_cache,
- const struct pipe_texture *texture )
+ const struct pipe_resource *texture )
{
const struct pipe_sampler_state *sampler = samp->sampler;
/* Currently bound texture:
*/
- const struct pipe_texture *texture;
+ const struct pipe_resource *texture;
struct softpipe_tex_tile_cache *cache;
unsigned processor;
void sp_sampler_varient_bind_texture( struct sp_sampler_varient *varient,
struct softpipe_tex_tile_cache *tex_cache,
- const struct pipe_texture *tex );
+ const struct pipe_resource *tex );
void sp_sampler_varient_destroy( struct sp_sampler_varient * );
/*assert(tc->entries[pos].x < 0);*/
}
if (tc->transfer) {
- tc->pipe->tex_transfer_destroy(tc->pipe, tc->transfer);
+ tc->pipe->transfer_destroy(tc->pipe, tc->transfer);
}
if (tc->tex_trans) {
- tc->pipe->tex_transfer_destroy(tc->pipe, tc->tex_trans);
+ tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
}
FREE( tc );
sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc,
struct pipe_sampler_view *view)
{
- struct pipe_texture *texture = view ? view->texture : NULL;
+ struct pipe_resource *texture = view ? view->texture : NULL;
uint i;
assert(!tc->transfer);
if (tc->texture != texture) {
- pipe_texture_reference(&tc->texture, texture);
+ pipe_resource_reference(&tc->texture, texture);
if (tc->tex_trans) {
if (tc->tex_trans_map) {
tc->tex_trans_map = NULL;
}
- tc->pipe->tex_transfer_destroy(tc->pipe, tc->tex_trans);
+ tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
tc->tex_trans = NULL;
}
tc->tex_trans_map = NULL;
}
- tc->pipe->tex_transfer_destroy(tc->pipe, tc->tex_trans);
+ tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
tc->tex_trans = NULL;
}
tc->tex_trans =
- tc->pipe->get_tex_transfer(tc->pipe, tc->texture,
- addr.bits.face,
- addr.bits.level,
- addr.bits.z,
- PIPE_TRANSFER_READ, 0, 0,
- u_minify(tc->texture->width0, addr.bits.level),
- u_minify(tc->texture->height0, addr.bits.level));
+ pipe_get_transfer(tc->pipe, tc->texture,
+ addr.bits.face,
+ addr.bits.level,
+ addr.bits.z,
+ PIPE_TRANSFER_READ, 0, 0,
+ u_minify(tc->texture->width0, addr.bits.level),
+ u_minify(tc->texture->height0, addr.bits.level));
tc->tex_trans_map = tc->pipe->transfer_map(tc->pipe, tc->tex_trans);
struct pipe_transfer *transfer;
void *transfer_map;
- struct pipe_texture *texture; /**< if caching a texture */
+ struct pipe_resource *texture; /**< if caching a texture */
unsigned timestamp;
struct softpipe_tex_cached_tile entries[NUM_ENTRIES];
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_transfer.h"
#include "sp_context.h"
#include "sp_texture.h"
* Use a simple, maximally packed layout.
*/
static boolean
-softpipe_texture_layout(struct pipe_screen *screen,
- struct softpipe_texture * spt)
+softpipe_resource_layout(struct pipe_screen *screen,
+ struct softpipe_resource * spt)
{
- struct pipe_texture *pt = &spt->base;
+ struct pipe_resource *pt = &spt->base;
unsigned level;
unsigned width = pt->width0;
unsigned height = pt->height0;
*/
static boolean
softpipe_displaytarget_layout(struct pipe_screen *screen,
- struct softpipe_texture * spt)
+ struct softpipe_resource * spt)
{
struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
/* Round up the surface size to a multiple of the tile size?
*/
spt->dt = winsys->displaytarget_create(winsys,
- spt->base.tex_usage,
+ spt->base.bind,
spt->base.format,
spt->base.width0,
spt->base.height0,
/**
- * Create new pipe_texture given the template information.
+ * Create new pipe_resource given the template information.
*/
-static struct pipe_texture *
-softpipe_texture_create(struct pipe_screen *screen,
- const struct pipe_texture *template)
+static struct pipe_resource *
+softpipe_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
{
- struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture);
+ struct softpipe_resource *spt = CALLOC_STRUCT(softpipe_resource);
if (!spt)
return NULL;
+ assert(template->format != PIPE_FORMAT_NONE);
+
spt->base = *template;
pipe_reference_init(&spt->base.reference, 1);
spt->base.screen = screen;
util_is_power_of_two(template->height0) &&
util_is_power_of_two(template->depth0));
- if (spt->base.tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_SCANOUT |
- PIPE_TEXTURE_USAGE_SHARED)) {
+ if (spt->base.bind & (PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED)) {
if (!softpipe_displaytarget_layout(screen, spt))
goto fail;
}
else {
- if (!softpipe_texture_layout(screen, spt))
+ if (!softpipe_resource_layout(screen, spt))
goto fail;
}
static void
-softpipe_texture_destroy(struct pipe_texture *pt)
+softpipe_resource_destroy(struct pipe_screen *pscreen,
+ struct pipe_resource *pt)
{
- struct softpipe_screen *screen = softpipe_screen(pt->screen);
- struct softpipe_texture *spt = softpipe_texture(pt);
+ struct softpipe_screen *screen = softpipe_screen(pscreen);
+ struct softpipe_resource *spt = softpipe_resource(pt);
if (spt->dt) {
/* display target */
struct sw_winsys *winsys = screen->winsys;
winsys->displaytarget_destroy(winsys, spt->dt);
}
- else {
+ else if (!spt->userBuffer) {
/* regular texture */
align_free(spt->data);
}
}
-static struct pipe_texture *
-softpipe_texture_from_handle(struct pipe_screen *screen,
- const struct pipe_texture *template,
+static struct pipe_resource *
+softpipe_resource_from_handle(struct pipe_screen *screen,
+ const struct pipe_resource *template,
struct winsys_handle *whandle)
{
struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
- struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture);
+ struct softpipe_resource *spt = CALLOC_STRUCT(softpipe_resource);
if (!spt)
return NULL;
static boolean
-softpipe_texture_get_handle(struct pipe_screen *screen,
- struct pipe_texture *pt,
+softpipe_resource_get_handle(struct pipe_screen *screen,
+ struct pipe_resource *pt,
struct winsys_handle *whandle)
{
struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
- struct softpipe_texture *spt = softpipe_texture(pt);
+ struct softpipe_resource *spt = softpipe_resource(pt);
assert(spt->dt);
if (!spt->dt)
*/
static struct pipe_surface *
softpipe_get_tex_surface(struct pipe_screen *screen,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
unsigned face, unsigned level, unsigned zslice,
unsigned usage)
{
- struct softpipe_texture *spt = softpipe_texture(pt);
+ struct softpipe_resource *spt = softpipe_resource(pt);
struct pipe_surface *ps;
assert(level <= pt->last_level);
ps = CALLOC_STRUCT(pipe_surface);
if (ps) {
pipe_reference_init(&ps->reference, 1);
- pipe_texture_reference(&ps->texture, pt);
+ pipe_resource_reference(&ps->texture, pt);
ps->format = pt->format;
ps->width = u_minify(pt->width0, level);
ps->height = u_minify(pt->height0, level);
ps->offset = spt->level_offset[level];
ps->usage = usage;
- /* Because we are softpipe, anything that the state tracker
- * thought was going to be done with the GPU will actually get
- * done with the CPU. Let's adjust the flags to take that into
- * account.
- */
- if (ps->usage & PIPE_BUFFER_USAGE_GPU_WRITE) {
- /* GPU_WRITE means "render" and that can involve reads (blending) */
- ps->usage |= PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_CPU_READ;
- }
-
- if (ps->usage & PIPE_BUFFER_USAGE_GPU_READ)
- ps->usage |= PIPE_BUFFER_USAGE_CPU_READ;
-
- if (ps->usage & (PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_GPU_WRITE)) {
- /* Mark the surface as dirty. The tile cache will look for this. */
- spt->timestamp++;
- softpipe_screen(screen)->timestamp++;
- }
-
ps->face = face;
ps->level = level;
ps->zslice = zslice;
* where it would happen. For softpipe, nothing to do.
*/
assert(surf->texture);
- pipe_texture_reference(&surf->texture, NULL);
+ pipe_resource_reference(&surf->texture, NULL);
FREE(surf);
}
* \param height height of region to read/write
*/
static struct pipe_transfer *
-softpipe_get_tex_transfer(struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
+softpipe_get_transfer(struct pipe_context *pipe,
+ struct pipe_resource *resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
{
- struct softpipe_texture *sptex = softpipe_texture(texture);
+ struct softpipe_resource *sptex = softpipe_resource(resource);
struct softpipe_transfer *spt;
- assert(texture);
- assert(level <= texture->last_level);
+ assert(resource);
+ assert(sr.level <= resource->last_level);
/* make sure the requested region is in the image bounds */
- assert(x + w <= u_minify(texture->width0, level));
- assert(y + h <= u_minify(texture->height0, level));
+ assert(box->x + box->width <= u_minify(resource->width0, sr.level));
+ assert(box->y + box->height <= u_minify(resource->height0, sr.level));
+ assert(box->z + box->depth <= u_minify(resource->depth0, sr.level));
spt = CALLOC_STRUCT(softpipe_transfer);
if (spt) {
struct pipe_transfer *pt = &spt->base;
- int nblocksy = util_format_get_nblocksy(texture->format, u_minify(texture->height0, level));
- pipe_texture_reference(&pt->texture, texture);
- pt->x = x;
- pt->y = y;
- pt->width = w;
- pt->height = h;
- pt->stride = sptex->stride[level];
+ enum pipe_format format = resource->format;
+ int nblocksy = util_format_get_nblocksy(resource->format,
+ u_minify(resource->height0, sr.level));
+ pipe_resource_reference(&pt->resource, resource);
+ pt->sr = sr;
pt->usage = usage;
- pt->face = face;
- pt->level = level;
- pt->zslice = zslice;
+ pt->box = *box;
+ pt->stride = sptex->stride[sr.level];
- spt->offset = sptex->level_offset[level];
+ spt->offset = sptex->level_offset[sr.level];
- if (texture->target == PIPE_TEXTURE_CUBE) {
- spt->offset += face * nblocksy * pt->stride;
+ if (resource->target == PIPE_TEXTURE_CUBE) {
+ spt->offset += sr.face * nblocksy * pt->stride;
}
- else if (texture->target == PIPE_TEXTURE_3D) {
- spt->offset += zslice * nblocksy * pt->stride;
+ else if (resource->target == PIPE_TEXTURE_3D) {
+ spt->offset += box->z * nblocksy * pt->stride;
}
else {
- assert(face == 0);
- assert(zslice == 0);
+ assert(sr.face == 0);
+ assert(box->z == 0);
}
+
+ spt->offset +=
+ box->y / util_format_get_blockheight(format) * spt->base.stride +
+ box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+
return pt;
}
return NULL;
/**
* Free a pipe_transfer object which was created with
- * softpipe_get_tex_transfer().
+ * softpipe_get_transfer().
*/
static void
-softpipe_tex_transfer_destroy(struct pipe_context *pipe,
+softpipe_transfer_destroy(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
- /* Effectively do the texture_update work here - if texture images
- * needed post-processing to put them into hardware layout, this is
- * where it would happen. For softpipe, nothing to do.
- */
- assert (transfer->texture);
- pipe_texture_reference(&transfer->texture, NULL);
+ pipe_resource_reference(&transfer->resource, NULL);
FREE(transfer);
}
softpipe_transfer_map( struct pipe_context *pipe,
struct pipe_transfer *transfer )
{
- ubyte *map, *xfer_map;
- struct softpipe_texture *spt;
- enum pipe_format format;
-
- assert(transfer->texture);
- spt = softpipe_texture(transfer->texture);
- format = transfer->texture->format;
-
- if (spt->dt) {
- /* display target */
- struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys;
-
- map = winsys->displaytarget_map(winsys, spt->dt,
- pipe_transfer_buffer_flags(transfer));
- if (map == NULL)
- return NULL;
+ struct softpipe_transfer *sp_transfer = softpipe_transfer(transfer);
+ struct softpipe_resource *sp_resource = softpipe_resource(transfer->resource);
+ struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys;
+ uint8_t *map;
+
+ /* resources backed by display target treated specially:
+ */
+ if (sp_resource->dt) {
+ map = winsys->displaytarget_map(winsys,
+ sp_resource->dt,
+ transfer->usage);
}
else {
- map = spt->data;
- if (map == NULL)
- return NULL;
- }
-
- /* May want to different things here depending on read/write nature
- * of the map:
- */
- if (transfer->texture && (transfer->usage & PIPE_TRANSFER_WRITE)) {
- /* Do something to notify sharing contexts of a texture change.
- * In softpipe, that would mean flushing the texture cache.
- */
- softpipe_screen(pipe->screen)->timestamp++;
+ map = sp_resource->data;
}
- xfer_map = map + softpipe_transfer(transfer)->offset +
- transfer->y / util_format_get_blockheight(format) * transfer->stride +
- transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
- /*printf("map = %p xfer map = %p\n", map, xfer_map);*/
- return xfer_map;
+ if (map == NULL)
+ return NULL;
+ else
+ return map + sp_transfer->offset;
}
softpipe_transfer_unmap(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
- struct softpipe_texture *spt;
+ struct softpipe_resource *spt;
- assert(transfer->texture);
- spt = softpipe_texture(transfer->texture);
+ assert(transfer->resource);
+ spt = softpipe_resource(transfer->resource);
if (spt->dt) {
/* display target */
}
}
-
-static struct pipe_video_surface*
-softpipe_video_surface_create(struct pipe_screen *screen,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
+/**
+ * Create buffer which wraps user-space data.
+ */
+static struct pipe_resource *
+softpipe_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind_flags)
{
- struct softpipe_video_surface *sp_vsfc;
- struct pipe_texture template;
+ struct softpipe_resource *buffer;
- assert(screen);
- assert(width && height);
-
- sp_vsfc = CALLOC_STRUCT(softpipe_video_surface);
- if (!sp_vsfc)
+ buffer = CALLOC_STRUCT(softpipe_resource);
+ if(!buffer)
return NULL;
- pipe_reference_init(&sp_vsfc->base.reference, 1);
- sp_vsfc->base.screen = screen;
- sp_vsfc->base.chroma_format = chroma_format;
- /*sp_vsfc->base.surface_format = PIPE_VIDEO_SURFACE_FORMAT_VUYA;*/
- sp_vsfc->base.width = width;
- sp_vsfc->base.height = height;
-
- memset(&template, 0, sizeof(struct pipe_texture));
- template.target = PIPE_TEXTURE_2D;
- template.format = PIPE_FORMAT_B8G8R8X8_UNORM;
- template.last_level = 0;
- /* vl_mpeg12_mc_renderer expects this when it's initialized with pot_buffers=true */
- template.width0 = util_next_power_of_two(width);
- template.height0 = util_next_power_of_two(height);
- template.depth0 = 1;
- template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;
-
- sp_vsfc->tex = screen->texture_create(screen, &template);
- if (!sp_vsfc->tex) {
- FREE(sp_vsfc);
- return NULL;
- }
-
- return &sp_vsfc->base;
+
+ pipe_reference_init(&buffer->base.reference, 1);
+ buffer->base.screen = screen;
+ buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */
+ buffer->base.bind = bind_flags;
+ buffer->base._usage = PIPE_USAGE_IMMUTABLE;
+ buffer->base.flags = 0;
+ buffer->base.width0 = bytes;
+ buffer->base.height0 = 1;
+ buffer->base.depth0 = 1;
+ buffer->userBuffer = TRUE;
+ buffer->data = ptr;
+
+ return &buffer->base;
}
-static void
-softpipe_video_surface_destroy(struct pipe_video_surface *vsfc)
-{
- struct softpipe_video_surface *sp_vsfc = softpipe_video_surface(vsfc);
- pipe_texture_reference(&sp_vsfc->tex, NULL);
- FREE(sp_vsfc);
-}
void
softpipe_init_texture_funcs(struct pipe_context *pipe)
{
- pipe->get_tex_transfer = softpipe_get_tex_transfer;
- pipe->tex_transfer_destroy = softpipe_tex_transfer_destroy;
+ pipe->get_transfer = softpipe_get_transfer;
+ pipe->transfer_destroy = softpipe_transfer_destroy;
pipe->transfer_map = softpipe_transfer_map;
pipe->transfer_unmap = softpipe_transfer_unmap;
+
+ pipe->transfer_flush_region = u_default_transfer_flush_region;
+ pipe->transfer_inline_write = u_default_transfer_inline_write;
}
void
softpipe_init_screen_texture_funcs(struct pipe_screen *screen)
{
- screen->texture_create = softpipe_texture_create;
- screen->texture_destroy = softpipe_texture_destroy;
- screen->texture_from_handle = softpipe_texture_from_handle;
- screen->texture_get_handle = softpipe_texture_get_handle;
+ screen->resource_create = softpipe_resource_create;
+ screen->resource_destroy = softpipe_resource_destroy;
+ screen->resource_from_handle = softpipe_resource_from_handle;
+ screen->resource_get_handle = softpipe_resource_get_handle;
+ screen->user_buffer_create = softpipe_user_buffer_create;
screen->get_tex_surface = softpipe_get_tex_surface;
screen->tex_surface_destroy = softpipe_tex_surface_destroy;
-
- screen->video_surface_create = softpipe_video_surface_create;
- screen->video_surface_destroy = softpipe_video_surface_destroy;
}
#include "pipe/p_state.h"
-#include "pipe/p_video_state.h"
#define SP_MAX_TEXTURE_2D_LEVELS 13 /* 4K x 4K */
struct softpipe_context;
-struct softpipe_texture
+struct softpipe_resource
{
- struct pipe_texture base;
+ struct pipe_resource base;
unsigned long level_offset[SP_MAX_TEXTURE_2D_LEVELS];
unsigned stride[SP_MAX_TEXTURE_2D_LEVELS];
/**
- * Display target, for textures with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET
- * usage.
+ * Display target, only valid for PIPE_TEXTURE_2D with the
+ * PIPE_BIND_DISPLAY_TARGET usage.
*/
struct sw_displaytarget *dt;
/**
- * Malloc'ed data for regular textures, or a mapping to dt above.
+ * Malloc'ed data for regular buffers and textures, or a mapping to dt above.
*/
void *data;
/* True if texture images are power-of-two in all dimensions:
*/
boolean pot;
+ boolean userBuffer;
unsigned timestamp;
};
unsigned long offset;
};
-struct softpipe_video_surface
-{
- struct pipe_video_surface base;
-
- /* The data is held here:
- */
- struct pipe_texture *tex;
-};
/** cast wrappers */
-static INLINE struct softpipe_texture *
-softpipe_texture(struct pipe_texture *pt)
+static INLINE struct softpipe_resource *
+softpipe_resource(struct pipe_resource *pt)
{
- return (struct softpipe_texture *) pt;
+ return (struct softpipe_resource *) pt;
}
static INLINE struct softpipe_transfer *
return (struct softpipe_transfer *) pt;
}
-static INLINE struct softpipe_video_surface *
-softpipe_video_surface(struct pipe_video_surface *pvs)
-{
- return (struct softpipe_video_surface *) pvs;
-}
-
extern void
softpipe_init_screen_texture_funcs(struct pipe_screen *screen);
/*assert(tc->entries[pos].x < 0);*/
}
if (tc->transfer) {
- tc->pipe->tex_transfer_destroy(tc->pipe, tc->transfer);
+ tc->pipe->transfer_destroy(tc->pipe, tc->transfer);
}
FREE( tc );
tc->transfer_map = NULL;
}
- pipe->tex_transfer_destroy(pipe, tc->transfer);
+ pipe->transfer_destroy(pipe, tc->transfer);
tc->transfer = NULL;
}
tc->surface = ps;
if (ps) {
- tc->transfer = pipe->get_tex_transfer(pipe, ps->texture, ps->face,
- ps->level, ps->zslice,
- PIPE_TRANSFER_READ_WRITE,
- 0, 0, ps->width, ps->height);
+ tc->transfer = pipe_get_transfer(pipe, ps->texture, ps->face,
+ ps->level, ps->zslice,
+ PIPE_TRANSFER_READ_WRITE,
+ 0, 0, ps->width, ps->height);
tc->depth_stencil = (ps->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
ps->format == PIPE_FORMAT_Z24X8_UNORM ||
sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc)
{
struct pipe_transfer *pt = tc->transfer;
- const uint w = tc->transfer->width;
- const uint h = tc->transfer->height;
+ const uint w = tc->transfer->box.width;
+ const uint h = tc->transfer->box.height;
uint x, y;
uint numCleared = 0;
- assert(pt->texture);
+ assert(pt->resource);
/* clear the scratch tile to the clear value */
- clear_tile(&tc->tile, pt->texture->format, tc->clear_val);
+ clear_tile(&tc->tile, pt->resource->format, tc->clear_val);
/* push the tile to all positions marked as clear */
for (y = 0; y < h; y += TILE_SIZE) {
if (addr.value != tile->addr.value) {
- assert(pt->texture);
+ assert(pt->resource);
if (tile->addr.bits.invalid == 0) {
/* put dirty tile back in framebuffer */
if (tc->depth_stencil) {
if (is_clear_flag_set(tc->clear_flags, addr)) {
/* don't get tile from framebuffer, just clear it */
if (tc->depth_stencil) {
- clear_tile(tile, pt->texture->format, tc->clear_val);
+ clear_tile(tile, pt->resource->format, tc->clear_val);
}
else {
- clear_tile_rgba(tile, pt->texture->format, tc->clear_color);
+ clear_tile_rgba(tile, pt->resource->format, tc->clear_color);
}
clear_clear_flag(tc->clear_flags, addr);
}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include "util/u_inlines.h"
-#include "util/u_memory.h"
-
-#include "sp_video_context.h"
-#include "sp_texture.h"
-
-
-static void
-sp_mpeg12_destroy(struct pipe_video_context *vpipe)
-{
- struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
-
- assert(vpipe);
-
- /* Asserted in softpipe_delete_fs_state() for some reason */
- ctx->pipe->bind_vs_state(ctx->pipe, NULL);
- ctx->pipe->bind_fs_state(ctx->pipe, NULL);
-
- ctx->pipe->delete_blend_state(ctx->pipe, ctx->blend);
- ctx->pipe->delete_rasterizer_state(ctx->pipe, ctx->rast);
- ctx->pipe->delete_depth_stencil_alpha_state(ctx->pipe, ctx->dsa);
-
- pipe_video_surface_reference(&ctx->decode_target, NULL);
- vl_compositor_cleanup(&ctx->compositor);
- vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
- ctx->pipe->destroy(ctx->pipe);
-
- FREE(ctx);
-}
-
-static void
-sp_mpeg12_decode_macroblocks(struct pipe_video_context *vpipe,
- struct pipe_video_surface *past,
- struct pipe_video_surface *future,
- unsigned num_macroblocks,
- struct pipe_macroblock *macroblocks,
- struct pipe_fence_handle **fence)
-{
- struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
- struct pipe_mpeg12_macroblock *mpeg12_macroblocks = (struct pipe_mpeg12_macroblock*)macroblocks;
-
- assert(vpipe);
- assert(num_macroblocks);
- assert(macroblocks);
- assert(macroblocks->codec == PIPE_VIDEO_CODEC_MPEG12);
- assert(ctx->decode_target);
-
- vl_mpeg12_mc_renderer_render_macroblocks(&ctx->mc_renderer,
- softpipe_video_surface(ctx->decode_target)->tex,
- past ? softpipe_video_surface(past)->tex : NULL,
- future ? softpipe_video_surface(future)->tex : NULL,
- num_macroblocks, mpeg12_macroblocks, fence);
-}
-
-static void
-sp_mpeg12_clear_surface(struct pipe_video_context *vpipe,
- unsigned x, unsigned y,
- unsigned width, unsigned height,
- unsigned value,
- struct pipe_surface *surface)
-{
- struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
-
- assert(vpipe);
- assert(surface);
-
- ctx->pipe->surface_fill(ctx->pipe, surface, x, y, width, height, value);
-}
-
-static void
-sp_mpeg12_render_picture(struct pipe_video_context *vpipe,
- /*struct pipe_surface *backround,
- struct pipe_video_rect *backround_area,*/
- struct pipe_video_surface *src_surface,
- enum pipe_mpeg12_picture_type picture_type,
- /*unsigned num_past_surfaces,
- struct pipe_video_surface *past_surfaces,
- unsigned num_future_surfaces,
- struct pipe_video_surface *future_surfaces,*/
- struct pipe_video_rect *src_area,
- struct pipe_surface *dst_surface,
- struct pipe_video_rect *dst_area,
- /*unsigned num_layers,
- struct pipe_surface *layers,
- struct pipe_video_rect *layer_src_areas,
- struct pipe_video_rect *layer_dst_areas*/
- struct pipe_fence_handle **fence)
-{
- struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
-
- assert(vpipe);
- assert(src_surface);
- assert(src_area);
- assert(dst_surface);
- assert(dst_area);
-
- vl_compositor_render(&ctx->compositor, softpipe_video_surface(src_surface)->tex,
- picture_type, src_area, dst_surface->texture, dst_area, fence);
-}
-
-static void
-sp_mpeg12_set_decode_target(struct pipe_video_context *vpipe,
- struct pipe_video_surface *dt)
-{
- struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
-
- assert(vpipe);
- assert(dt);
-
- pipe_video_surface_reference(&ctx->decode_target, dt);
-}
-
-static void sp_mpeg12_set_csc_matrix(struct pipe_video_context *vpipe, const float *mat)
-{
- struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
-
- assert(vpipe);
-
- vl_compositor_set_csc_matrix(&ctx->compositor, mat);
-}
-
-static bool
-init_pipe_state(struct sp_mpeg12_context *ctx)
-{
- struct pipe_rasterizer_state rast;
- struct pipe_blend_state blend;
- struct pipe_depth_stencil_alpha_state dsa;
- unsigned i;
-
- assert(ctx);
-
- rast.flatshade = 1;
- rast.flatshade_first = 0;
- rast.light_twoside = 0;
- rast.front_winding = PIPE_WINDING_CCW;
- rast.cull_mode = PIPE_WINDING_CW;
- rast.fill_cw = PIPE_POLYGON_MODE_FILL;
- rast.fill_ccw = PIPE_POLYGON_MODE_FILL;
- rast.offset_cw = 0;
- rast.offset_ccw = 0;
- rast.scissor = 0;
- rast.poly_smooth = 0;
- rast.poly_stipple_enable = 0;
- rast.sprite_coord_enable = 0;
- rast.point_size_per_vertex = 0;
- rast.multisample = 0;
- rast.line_smooth = 0;
- rast.line_stipple_enable = 0;
- rast.line_stipple_factor = 0;
- rast.line_stipple_pattern = 0;
- rast.line_last_pixel = 0;
- rast.line_width = 1;
- rast.point_smooth = 0;
- rast.point_quad_rasterization = 0;
- rast.point_size = 1;
- rast.offset_units = 1;
- rast.offset_scale = 1;
- ctx->rast = ctx->pipe->create_rasterizer_state(ctx->pipe, &rast);
- ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rast);
-
- blend.independent_blend_enable = 0;
- blend.rt[0].blend_enable = 0;
- blend.rt[0].rgb_func = PIPE_BLEND_ADD;
- blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
- blend.rt[0].alpha_func = PIPE_BLEND_ADD;
- blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
- blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
- blend.logicop_enable = 0;
- blend.logicop_func = PIPE_LOGICOP_CLEAR;
- /* Needed to allow color writes to FB, even if blending disabled */
- blend.rt[0].colormask = PIPE_MASK_RGBA;
- blend.dither = 0;
- ctx->blend = ctx->pipe->create_blend_state(ctx->pipe, &blend);
- ctx->pipe->bind_blend_state(ctx->pipe, ctx->blend);
-
- dsa.depth.enabled = 0;
- dsa.depth.writemask = 0;
- dsa.depth.func = PIPE_FUNC_ALWAYS;
- for (i = 0; i < 2; ++i) {
- dsa.stencil[i].enabled = 0;
- dsa.stencil[i].func = PIPE_FUNC_ALWAYS;
- dsa.stencil[i].fail_op = PIPE_STENCIL_OP_KEEP;
- dsa.stencil[i].zpass_op = PIPE_STENCIL_OP_KEEP;
- dsa.stencil[i].zfail_op = PIPE_STENCIL_OP_KEEP;
- dsa.stencil[i].valuemask = 0;
- dsa.stencil[i].writemask = 0;
- }
- dsa.alpha.enabled = 0;
- dsa.alpha.func = PIPE_FUNC_ALWAYS;
- dsa.alpha.ref_value = 0;
- ctx->dsa = ctx->pipe->create_depth_stencil_alpha_state(ctx->pipe, &dsa);
- ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, ctx->dsa);
-
- return true;
-}
-
-static struct pipe_video_context *
-sp_mpeg12_create(struct pipe_screen *screen, enum pipe_video_profile profile,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
-{
- struct sp_mpeg12_context *ctx;
-
- assert(u_reduce_video_profile(profile) == PIPE_VIDEO_CODEC_MPEG12);
-
- ctx = CALLOC_STRUCT(sp_mpeg12_context);
-
- if (!ctx)
- return NULL;
-
- ctx->base.profile = profile;
- ctx->base.chroma_format = chroma_format;
- ctx->base.width = width;
- ctx->base.height = height;
-
- ctx->base.screen = screen;
- ctx->base.destroy = sp_mpeg12_destroy;
- ctx->base.decode_macroblocks = sp_mpeg12_decode_macroblocks;
- ctx->base.clear_surface = sp_mpeg12_clear_surface;
- ctx->base.render_picture = sp_mpeg12_render_picture;
- ctx->base.set_decode_target = sp_mpeg12_set_decode_target;
- ctx->base.set_csc_matrix = sp_mpeg12_set_csc_matrix;
-
- ctx->pipe = screen->context_create(screen, NULL);
- if (!ctx->pipe) {
- FREE(ctx);
- return NULL;
- }
-
- /* TODO: Use slice buffering for softpipe when implemented, no advantage to buffering an entire picture */
- if (!vl_mpeg12_mc_renderer_init(&ctx->mc_renderer, ctx->pipe,
- width, height, chroma_format,
- VL_MPEG12_MC_RENDERER_BUFFER_PICTURE,
- /* TODO: Use XFER_NONE when implemented */
- VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE,
- true)) {
- ctx->pipe->destroy(ctx->pipe);
- FREE(ctx);
- return NULL;
- }
-
- if (!vl_compositor_init(&ctx->compositor, ctx->pipe)) {
- vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
- ctx->pipe->destroy(ctx->pipe);
- FREE(ctx);
- return NULL;
- }
-
- if (!init_pipe_state(ctx)) {
- vl_compositor_cleanup(&ctx->compositor);
- vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
- ctx->pipe->destroy(ctx->pipe);
- FREE(ctx);
- return NULL;
- }
-
- return &ctx->base;
-}
-
-struct pipe_video_context *
-sp_video_create(struct pipe_screen *screen, enum pipe_video_profile profile,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
-{
- assert(screen);
- assert(width && height);
-
- switch (u_reduce_video_profile(profile)) {
- case PIPE_VIDEO_CODEC_MPEG12:
- return sp_mpeg12_create(screen, profile,
- chroma_format,
- width, height);
- default:
- return NULL;
- }
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 SP_VIDEO_CONTEXT_H
-#define SP_VIDEO_CONTEXT_H
-
-#include <pipe/p_video_context.h>
-#include <vl/vl_mpeg12_mc_renderer.h>
-#include <vl/vl_compositor.h>
-
-struct pipe_screen;
-struct pipe_context;
-struct pipe_video_surface;
-
-struct sp_mpeg12_context
-{
- struct pipe_video_context base;
- struct pipe_context *pipe;
- struct pipe_video_surface *decode_target;
- struct vl_mpeg12_mc_renderer mc_renderer;
- struct vl_compositor compositor;
-
- void *rast;
- void *dsa;
- void *blend;
-};
-
-struct pipe_video_context *
-sp_video_create(struct pipe_screen *screen, enum pipe_video_profile profile,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height);
-
-#endif /* SP_VIDEO_CONTEXT_H */
svga_pipe_vertex.c \
svga_pipe_vs.c \
svga_screen.c \
- svga_screen_buffer.c \
- svga_screen_texture.c \
svga_screen_cache.c \
svga_state.c \
svga_state_need_swtnl.c \
svga_tgsi.c \
svga_tgsi_decl_sm20.c \
svga_tgsi_decl_sm30.c \
- svga_tgsi_insn.c
+ svga_tgsi_insn.c \
+ svga_sampler_view.c \
+ svga_surface.c \
+ svga_resource.c \
+ svga_resource_texture.c \
+ svga_resource_buffer.c \
+ svga_resource_buffer_upload.c
+
LIBRARY_INCLUDES = \
-I$(TOP)/src/gallium/drivers/svga/include
'svga_pipe_sampler.c',
'svga_pipe_vertex.c',
'svga_pipe_vs.c',
+ 'svga_resource.c',
+ 'svga_resource_buffer.c',
+ 'svga_resource_buffer_upload.c',
+ 'svga_resource_texture.c',
+ 'svga_sampler_view.c',
'svga_screen.c',
- 'svga_screen_buffer.c',
'svga_screen_cache.c',
- 'svga_screen_texture.c',
'svga_state.c',
'svga_state_constants.c',
'svga_state_framebuffer.c',
'svga_state_vdecl.c',
'svga_state_fs.c',
'svga_state_vs.c',
+ 'svga_surface.c',
'svga_swtnl_backend.c',
'svga_swtnl_draw.c',
'svga_swtnl_state.c',
*/
#include "svga_winsys.h"
-#include "svga_screen_buffer.h"
-#include "svga_screen_texture.h"
+#include "svga_resource_buffer.h"
+#include "svga_resource_texture.h"
+#include "svga_surface.h"
#include "svga_cmd.h"
/*
if(!cmd)
return PIPE_ERROR_OUT_OF_MEMORY;
- swc->surface_relocation(swc, &cmd->sid, sid, PIPE_BUFFER_USAGE_GPU_WRITE);
+ swc->surface_relocation(swc, &cmd->sid, sid, SVGA_RELOC_WRITE);
cmd->surfaceFlags = flags;
cmd->format = format;
if(!cmd)
return PIPE_ERROR_OUT_OF_MEMORY;
- swc->surface_relocation(swc, &cmd->sid, sid, PIPE_BUFFER_USAGE_GPU_READ);
+ swc->surface_relocation(swc, &cmd->sid, sid, SVGA_RELOC_READ);
swc->commit(swc);;
return PIPE_OK;
const SVGA3dCopyBox *boxes, // IN
uint32 numBoxes) // IN
{
- struct svga_texture *texture = svga_texture(st->base.texture);
+ struct svga_texture *texture = svga_texture(st->base.resource);
SVGA3dCmdSurfaceDMA *cmd;
SVGA3dCmdSurfaceDMASuffix *pSuffix;
uint32 boxesSize = sizeof *boxes * numBoxes;
unsigned surface_flags;
if(transfer == SVGA3D_WRITE_HOST_VRAM) {
- region_flags = PIPE_BUFFER_USAGE_GPU_READ;
- surface_flags = PIPE_BUFFER_USAGE_GPU_WRITE;
+ region_flags = SVGA_RELOC_READ;
+ surface_flags = SVGA_RELOC_WRITE;
}
else if(transfer == SVGA3D_READ_HOST_VRAM) {
- region_flags = PIPE_BUFFER_USAGE_GPU_WRITE;
- surface_flags = PIPE_BUFFER_USAGE_GPU_READ;
+ region_flags = SVGA_RELOC_WRITE;
+ surface_flags = SVGA_RELOC_READ;
}
else {
assert(0);
cmd->guest.pitch = st->base.stride;
swc->surface_relocation(swc, &cmd->host.sid, texture->handle, surface_flags);
- cmd->host.face = st->base.face; /* PIPE_TEX_FACE_* and SVGA3D_CUBEFACE_* match */
- cmd->host.mipmap = st->base.level;
+ cmd->host.face = st->base.sr.face; /* PIPE_TEX_FACE_* and SVGA3D_CUBEFACE_* match */
+ cmd->host.mipmap = st->base.sr.level;
cmd->transfer = transfer;
unsigned surface_flags;
if(transfer == SVGA3D_WRITE_HOST_VRAM) {
- region_flags = PIPE_BUFFER_USAGE_GPU_READ;
- surface_flags = PIPE_BUFFER_USAGE_GPU_WRITE;
+ region_flags = SVGA_RELOC_READ;
+ surface_flags = SVGA_RELOC_WRITE;
}
else if(transfer == SVGA3D_READ_HOST_VRAM) {
- region_flags = PIPE_BUFFER_USAGE_GPU_WRITE;
- surface_flags = PIPE_BUFFER_USAGE_GPU_READ;
+ region_flags = SVGA_RELOC_WRITE;
+ surface_flags = SVGA_RELOC_READ;
}
else {
assert(0);
cmd->type = type;
- surface_to_surfaceid(swc, surface, &cmd->target, PIPE_BUFFER_USAGE_GPU_WRITE);
+ surface_to_surfaceid(swc, surface, &cmd->target, SVGA_RELOC_WRITE);
swc->commit(swc);
if(!cmd)
return PIPE_ERROR_OUT_OF_MEMORY;
- surface_to_surfaceid(swc, src, &cmd->src, PIPE_BUFFER_USAGE_GPU_READ);
- surface_to_surfaceid(swc, dest, &cmd->dest, PIPE_BUFFER_USAGE_GPU_WRITE);
+ surface_to_surfaceid(swc, src, &cmd->src, SVGA_RELOC_READ);
+ surface_to_surfaceid(swc, dest, &cmd->dest, SVGA_RELOC_WRITE);
*boxes = (SVGA3dCopyBox*) &cmd[1];
memset(*boxes, 0, boxesSize);
if(!cmd)
return PIPE_ERROR_OUT_OF_MEMORY;
- surface_to_surfaceid(swc, src, &cmd->src, PIPE_BUFFER_USAGE_GPU_READ);
- surface_to_surfaceid(swc, dest, &cmd->dest, PIPE_BUFFER_USAGE_GPU_WRITE);
+ surface_to_surfaceid(swc, src, &cmd->src, SVGA_RELOC_READ);
+ surface_to_surfaceid(swc, dest, &cmd->dest, SVGA_RELOC_WRITE);
cmd->boxSrc = *boxSrc;
cmd->boxDest = *boxDest;
cmd->mode = mode;
cmd->type = type;
swc->region_relocation(swc, &cmd->guestResult, buffer, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ SVGA_RELOC_WRITE);
swc->commit(swc);
cmd->type = type;
swc->region_relocation(swc, &cmd->guestResult, buffer, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ SVGA_RELOC_WRITE);
swc->commit(swc);
#include "pipe/p_defines.h"
-struct pipe_buffer;
struct pipe_surface;
struct svga_transfer;
struct svga_winsys_context;
#include "svga_context.h"
#include "svga_screen.h"
-#include "svga_screen_texture.h"
-#include "svga_screen_buffer.h"
+#include "svga_resource_texture.h"
+#include "svga_resource_buffer.h"
+#include "svga_resource.h"
#include "svga_winsys.h"
#include "svga_swtnl.h"
#include "svga_draw.h"
util_bitmask_destroy( svga->fs_bm );
for(shader = 0; shader < PIPE_SHADER_TYPES; ++shader)
- pipe_buffer_reference( &svga->curr.cb[shader], NULL );
+ pipe_resource_reference( &svga->curr.cb[shader], NULL );
FREE( svga );
}
-static unsigned int
-svga_is_texture_referenced( struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level)
-{
- struct svga_texture *tex = svga_texture(texture);
- struct svga_screen *ss = svga_screen(pipe->screen);
-
- /**
- * The screen does not cache texture writes.
- */
-
- if (!tex->handle || ss->sws->surface_is_flushed(ss->sws, tex->handle))
- return PIPE_UNREFERENCED;
-
- /**
- * sws->surface_is_flushed() does not distinguish between read references
- * and write references. So assume a reference is both.
- */
-
- return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
-}
-
-static unsigned int
-svga_is_buffer_referenced( struct pipe_context *pipe,
- struct pipe_buffer *buf)
-
-{
- struct svga_screen *ss = svga_screen(pipe->screen);
- struct svga_buffer *sbuf = svga_buffer(buf);
-
- /**
- * XXX: Check this.
- * The screen may cache buffer writes, but when we map, we map out
- * of those cached writes, so we don't need to set a
- * PIPE_REFERENCED_FOR_WRITE flag for cached buffers.
- */
-
- if (!sbuf->handle || ss->sws->surface_is_flushed(ss->sws, sbuf->handle))
- return PIPE_UNREFERENCED;
-
- /**
- * sws->surface_is_flushed() does not distinguish between read references
- * and write references. So assume a reference is both,
- * however, we make an exception for index- and vertex buffers, to avoid
- * a flush in st_bufferobj_get_subdata, during display list replay.
- */
-
- if (sbuf->base.usage & (PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_INDEX))
- return PIPE_REFERENCED_FOR_READ;
-
- return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
-}
struct pipe_context *svga_context_create( struct pipe_screen *screen,
svga->pipe.destroy = svga_destroy;
svga->pipe.clear = svga_clear;
- svga->pipe.is_texture_referenced = svga_is_texture_referenced;
- svga->pipe.is_buffer_referenced = svga_is_buffer_referenced;
-
svga->swc = svgascreen->sws->context_create(svgascreen->sws);
if(!svga->swc)
goto no_swc;
+ svga_init_resource_functions(svga);
svga_init_blend_functions(svga);
svga_init_blit_functions(svga);
svga_init_depth_stencil_functions(svga);
svga_init_constbuffer_functions(svga);
svga_init_query_functions(svga);
- svga_init_texture_functions(&svga->pipe);
/* debug */
svga->debug.no_swtnl = debug_get_bool_option("SVGA_NO_SWTNL", FALSE);
if (svga->vs_bm == NULL)
goto no_vs_bm;
- svga->upload_ib = u_upload_create( svga->pipe.screen,
+ svga->upload_ib = u_upload_create( &svga->pipe,
32 * 1024,
16,
- PIPE_BUFFER_USAGE_INDEX );
+ PIPE_BIND_INDEX_BUFFER );
if (svga->upload_ib == NULL)
goto no_upload_ib;
- svga->upload_vb = u_upload_create( svga->pipe.screen,
+ svga->upload_vb = u_upload_create( &svga->pipe,
128 * 1024,
16,
- PIPE_BUFFER_USAGE_VERTEX );
+ PIPE_BIND_VERTEX_BUFFER );
if (svga->upload_vb == NULL)
goto no_upload_vb;
struct svga_vertex_shader *vs;
struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
- struct pipe_buffer *cb[PIPE_SHADER_TYPES];
+ struct pipe_resource *cb[PIPE_SHADER_TYPES];
struct pipe_framebuffer_state framebuffer;
float depthscale;
struct svga_hw_view_state
{
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct svga_sampler_view *v;
unsigned min_lod;
unsigned max_lod;
#include "svga_draw_private.h"
#include "svga_debug.h"
#include "svga_screen.h"
-#include "svga_screen_buffer.h"
-#include "svga_screen_texture.h"
+#include "svga_resource_buffer.h"
+#include "svga_resource_texture.h"
+#include "svga_surface.h"
#include "svga_winsys.h"
#include "svga_cmd.h"
for (i = 0; i < PIPE_PRIM_MAX; i++) {
for (j = 0; j < IDX_CACHE_MAX; j++) {
- pipe_buffer_reference( &hwtnl->index_cache[i][j].buffer,
+ pipe_resource_reference( &hwtnl->index_cache[i][j].buffer,
NULL );
}
}
for (i = 0; i < hwtnl->cmd.vdecl_count; i++)
- pipe_buffer_reference(&hwtnl->cmd.vdecl_vb[i], NULL);
+ pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i], NULL);
for (i = 0; i < hwtnl->cmd.prim_count; i++)
- pipe_buffer_reference(&hwtnl->cmd.prim_ib[i], NULL);
+ pipe_resource_reference(&hwtnl->cmd.prim_ib[i], NULL);
FREE(hwtnl);
assert(hwtnl->cmd.prim_count == 0);
for (i = count; i < hwtnl->cmd.vdecl_count; i++) {
- pipe_buffer_reference(&hwtnl->cmd.vdecl_vb[i],
+ pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i],
NULL);
}
void svga_hwtnl_vdecl( struct svga_hwtnl *hwtnl,
- unsigned i,
- const SVGA3dVertexDecl *decl,
- struct pipe_buffer *vb)
+ unsigned i,
+ const SVGA3dVertexDecl *decl,
+ struct pipe_resource *vb)
{
assert(hwtnl->cmd.prim_count == 0);
hwtnl->cmd.vdecl[i] = *decl;
- pipe_buffer_reference(&hwtnl->cmd.vdecl_vb[i],
- vb);
+ pipe_resource_reference(&hwtnl->cmd.vdecl_vb[i], vb);
}
swc->surface_relocation(swc,
&vdecl[i].array.surfaceId,
vb_handle[i],
- PIPE_BUFFER_USAGE_GPU_READ);
+ SVGA_RELOC_READ);
}
memcpy( prim,
swc->surface_relocation(swc,
&prim[i].indexArray.surfaceId,
ib_handle[i],
- PIPE_BUFFER_USAGE_GPU_READ);
- pipe_buffer_reference(&hwtnl->cmd.prim_ib[i], NULL);
+ SVGA_RELOC_READ);
+ pipe_resource_reference(&hwtnl->cmd.prim_ib[i], NULL);
}
SVGA_FIFOCommitAll( swc );
const SVGA3dPrimitiveRange *range,
unsigned min_index,
unsigned max_index,
- struct pipe_buffer *ib )
+ struct pipe_resource *ib )
{
int ret = PIPE_OK;
{
unsigned i;
for (i = 0; i < hwtnl->cmd.vdecl_count; i++) {
- struct pipe_buffer *vb = hwtnl->cmd.vdecl_vb[i];
- unsigned size = vb ? vb->size : 0;
+ struct pipe_resource *vb = hwtnl->cmd.vdecl_vb[i];
+ unsigned size = vb ? vb->width0 : 0;
unsigned offset = hwtnl->cmd.vdecl[i].array.offset;
unsigned stride = hwtnl->cmd.vdecl[i].array.stride;
unsigned index_bias = range->indexBias;
assert(range->indexWidth == range->indexArray.stride);
if(ib) {
- unsigned size = ib->size;
+ unsigned size = ib->width0;
unsigned offset = range->indexArray.offset;
unsigned stride = range->indexArray.stride;
unsigned count;
hwtnl->cmd.prim[hwtnl->cmd.prim_count] = *range;
- pipe_buffer_reference(&hwtnl->cmd.prim_ib[hwtnl->cmd.prim_count], ib);
+ pipe_resource_reference(&hwtnl->cmd.prim_ib[hwtnl->cmd.prim_count], ib);
hwtnl->cmd.prim_count++;
return ret;
struct svga_winsys_context;
struct svga_screen;
struct svga_context;
-struct pipe_buffer;
+struct pipe_resource;
struct u_upload_mgr;
struct svga_hwtnl *svga_hwtnl_create( struct svga_context *svga,
void svga_hwtnl_vdecl( struct svga_hwtnl *hwtnl,
unsigned i,
const SVGA3dVertexDecl *decl,
- struct pipe_buffer *vb);
+ struct pipe_resource *vb);
void svga_hwtnl_reset_vdecl( struct svga_hwtnl *hwtnl,
unsigned count );
enum pipe_error
svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned index_size,
unsigned min_index,
unsigned max_index,
unsigned nr,
unsigned index_size,
u_generate_func generate,
- struct pipe_buffer **out_buf )
+ struct pipe_resource **out_buf )
{
- struct pipe_screen *screen = hwtnl->svga->pipe.screen;
+ struct pipe_context *pipe = &hwtnl->svga->pipe;
+ struct pipe_transfer *transfer;
unsigned size = index_size * nr;
- struct pipe_buffer *dst = NULL;
+ struct pipe_resource *dst = NULL;
void *dst_map = NULL;
- dst = screen->buffer_create( screen, 32,
- PIPE_BUFFER_USAGE_INDEX |
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_GPU_READ,
- size );
+ dst = pipe_buffer_create( pipe->screen,
+ PIPE_BIND_INDEX_BUFFER,
+ size );
if (dst == NULL)
goto fail;
- dst_map = pipe_buffer_map( screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE );
+ dst_map = pipe_buffer_map( pipe, dst, PIPE_TRANSFER_WRITE,
+ &transfer);
if (dst_map == NULL)
goto fail;
generate( nr,
dst_map );
- pipe_buffer_unmap( screen, dst );
+ pipe_buffer_unmap( pipe, dst, transfer );
*out_buf = dst;
return PIPE_OK;
fail:
if (dst_map)
- screen->buffer_unmap( screen, dst );
+ pipe_buffer_unmap( pipe, dst, transfer );
if (dst)
- screen->buffer_destroy( dst );
-
+ pipe->screen->resource_destroy( pipe->screen, dst );
+
return PIPE_ERROR_OUT_OF_MEMORY;
}
unsigned gen_nr,
unsigned gen_size,
u_generate_func generate,
- struct pipe_buffer **out_buf )
+ struct pipe_resource **out_buf )
{
enum pipe_error ret = PIPE_OK;
int i;
{
if (compare(hwtnl->index_cache[prim][i].gen_nr, gen_nr, gen_type))
{
- pipe_buffer_reference( out_buf,
+ pipe_resource_reference( out_buf,
hwtnl->index_cache[prim][i].buffer );
if (DBG)
}
else if (gen_type == U_GENERATE_REUSABLE)
{
- pipe_buffer_reference( &hwtnl->index_cache[prim][i].buffer,
+ pipe_resource_reference( &hwtnl->index_cache[prim][i].buffer,
NULL );
if (DBG)
assert (smallest != IDX_CACHE_MAX);
- pipe_buffer_reference( &hwtnl->index_cache[prim][smallest].buffer,
+ pipe_resource_reference( &hwtnl->index_cache[prim][smallest].buffer,
NULL );
if (DBG)
hwtnl->index_cache[prim][i].generate = generate;
hwtnl->index_cache[prim][i].gen_nr = gen_nr;
- pipe_buffer_reference( &hwtnl->index_cache[prim][i].buffer,
+ pipe_resource_reference( &hwtnl->index_cache[prim][i].buffer,
*out_buf );
if (DBG)
return simple_draw_arrays( hwtnl, gen_prim, start, count );
}
else {
- struct pipe_buffer *gen_buf = NULL;
+ struct pipe_resource *gen_buf = NULL;
/* Need to draw as indexed primitive.
* Potentially need to run the gen func to build an index buffer.
done:
if (gen_buf)
- pipe_buffer_reference( &gen_buf, NULL );
+ pipe_resource_reference( &gen_buf, NULL );
return ret;
}
#include "svga_cmd.h"
#include "svga_draw.h"
#include "svga_draw_private.h"
-#include "svga_screen_buffer.h"
+#include "svga_resource_buffer.h"
#include "svga_winsys.h"
#include "svga_context.h"
static enum pipe_error
translate_indices( struct svga_hwtnl *hwtnl,
- struct pipe_buffer *src,
+ struct pipe_resource *src,
unsigned offset,
unsigned nr,
unsigned index_size,
u_translate_func translate,
- struct pipe_buffer **out_buf )
+ struct pipe_resource **out_buf )
{
- struct pipe_screen *screen = hwtnl->svga->pipe.screen;
+ struct pipe_context *pipe = &hwtnl->svga->pipe;
+ struct pipe_transfer *src_transfer = NULL;
+ struct pipe_transfer *dst_transfer = NULL;
unsigned size = index_size * nr;
const void *src_map = NULL;
- struct pipe_buffer *dst = NULL;
+ struct pipe_resource *dst = NULL;
void *dst_map = NULL;
- dst = screen->buffer_create( screen, 32,
- PIPE_BUFFER_USAGE_INDEX |
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_GPU_READ,
- size );
+ dst = pipe_buffer_create( pipe->screen,
+ PIPE_BIND_INDEX_BUFFER,
+ size );
if (dst == NULL)
goto fail;
- src_map = pipe_buffer_map( screen, src, PIPE_BUFFER_USAGE_CPU_READ );
+ src_map = pipe_buffer_map( pipe, src, PIPE_TRANSFER_READ, &src_transfer );
if (src_map == NULL)
goto fail;
- dst_map = pipe_buffer_map( screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE );
+ dst_map = pipe_buffer_map( pipe, dst, PIPE_TRANSFER_WRITE, &dst_transfer );
if (dst_map == NULL)
goto fail;
nr,
dst_map );
- pipe_buffer_unmap( screen, src );
- pipe_buffer_unmap( screen, dst );
+ pipe_buffer_unmap( pipe, src, src_transfer );
+ pipe_buffer_unmap( pipe, dst, dst_transfer );
*out_buf = dst;
return PIPE_OK;
fail:
if (src_map)
- screen->buffer_unmap( screen, src );
+ pipe_buffer_unmap( pipe, src, src_transfer );
if (dst_map)
- screen->buffer_unmap( screen, dst );
+ pipe_buffer_unmap( pipe, dst, dst_transfer );
if (dst)
- screen->buffer_destroy( dst );
+ pipe->screen->resource_destroy( pipe->screen, dst );
return PIPE_ERROR_OUT_OF_MEMORY;
}
enum pipe_error
svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl,
- struct pipe_buffer *index_buffer,
+ struct pipe_resource *index_buffer,
unsigned index_size,
unsigned min_index,
unsigned max_index,
unsigned count,
unsigned bias )
{
- struct pipe_buffer *upload_buffer = NULL;
+ struct pipe_resource *upload_buffer = NULL;
SVGA3dPrimitiveRange range;
unsigned hw_prim;
unsigned hw_count;
if (index_buffer &&
svga_buffer_is_user_buffer(index_buffer))
{
- assert( index_buffer->size >= index_offset + count * index_size );
+ assert( index_buffer->width0 >= index_offset + count * index_size );
ret = u_upload_buffer( hwtnl->upload_ib,
index_offset,
done:
if (upload_buffer)
- pipe_buffer_reference( &upload_buffer, NULL );
+ pipe_resource_reference( &upload_buffer, NULL );
return ret;
}
enum pipe_error
svga_hwtnl_draw_range_elements( struct svga_hwtnl *hwtnl,
- struct pipe_buffer *index_buffer,
+ struct pipe_resource *index_buffer,
unsigned index_size,
unsigned min_index,
unsigned max_index,
gen_prim, start, count, bias );
}
else {
- struct pipe_buffer *gen_buf = NULL;
+ struct pipe_resource *gen_buf = NULL;
/* Need to allocate a new index buffer and run the translate
* func to populate it. Could potentially cache this translated
done:
if (gen_buf)
- pipe_buffer_reference( &gen_buf, NULL );
+ pipe_resource_reference( &gen_buf, NULL );
return ret;
}
/* If non-null, this buffer is filled by calling
* generate(nr, map(buffer))
*/
- struct pipe_buffer *buffer;
+ struct pipe_resource *buffer;
};
#define QSZ 32
struct svga_winsys_context *swc;
SVGA3dVertexDecl vdecl[SVGA3D_INPUTREG_MAX];
- struct pipe_buffer *vdecl_vb[SVGA3D_INPUTREG_MAX];
+ struct pipe_resource *vdecl_vb[SVGA3D_INPUTREG_MAX];
unsigned vdecl_count;
SVGA3dPrimitiveRange prim[QSZ];
- struct pipe_buffer *prim_ib[QSZ];
+ struct pipe_resource *prim_ib[QSZ];
unsigned prim_count;
unsigned min_index[QSZ];
unsigned max_index[QSZ];
const SVGA3dPrimitiveRange *range,
unsigned min_index,
unsigned max_index,
- struct pipe_buffer *ib );
+ struct pipe_resource *ib );
enum pipe_error
svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned index_size,
unsigned min_index,
unsigned max_index,
*
**********************************************************/
-#include "svga_screen_texture.h"
+#include "svga_resource_texture.h"
#include "svga_context.h"
#include "svga_debug.h"
#include "svga_cmd.h"
+#include "svga_surface.h"
#define FILE_DEBUG_FLAG DEBUG_BLIT
#include "svga_context.h"
#include "svga_state.h"
-#include "svga_screen_texture.h"
+#include "svga_surface.h"
static enum pipe_error
static void svga_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
- struct pipe_buffer *buf)
+ struct pipe_resource *buf)
{
struct svga_context *svga = svga_context(pipe);
assert(shader < PIPE_SHADER_TYPES);
assert(index == 0);
- pipe_buffer_reference( &svga->curr.cb[shader],
+ pipe_resource_reference( &svga->curr.cb[shader],
buf );
if (shader == PIPE_SHADER_FRAGMENT)
static enum pipe_error
retry_draw_range_elements( struct svga_context *svga,
- struct pipe_buffer *index_buffer,
+ struct pipe_resource *index_buffer,
unsigned index_size,
unsigned min_index,
unsigned max_index,
static void
svga_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,
static void
svga_draw_elements( struct pipe_context *pipe,
- struct pipe_buffer *index_buffer,
+ struct pipe_resource *index_buffer,
unsigned index_size,
unsigned prim, unsigned start, unsigned count)
{
#include "pipe/p_defines.h"
#include "svga_screen.h"
-#include "svga_screen_texture.h"
+#include "svga_surface.h"
#include "svga_context.h"
#include "svga_debug.h"
#include "util/u_inlines.h"
#include "svga_context.h"
-#include "svga_screen_texture.h"
+#include "svga_surface.h"
static void svga_set_scissor_state( struct pipe_context *pipe,
#include "svga_cmd.h"
#include "svga_context.h"
#include "svga_screen.h"
-#include "svga_screen_buffer.h"
+#include "svga_resource_buffer.h"
#include "svga_winsys.h"
#include "svga_debug.h"
sq->queryResult = (SVGA3dQueryResult *)sws->buffer_map(sws,
sq->hwbuf,
- PIPE_BUFFER_USAGE_CPU_WRITE);
+ PIPE_TRANSFER_WRITE);
if(!sq->queryResult)
goto no_query_result;
#include "tgsi/tgsi_parse.h"
#include "svga_context.h"
-#include "svga_screen_texture.h"
+#include "svga_resource_texture.h"
#include "svga_debug.h"
static struct pipe_sampler_view *
svga_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);
*view = *templ;
view->reference.count = 1;
view->texture = NULL;
- pipe_texture_reference(&view->texture, texture);
+ pipe_resource_reference(&view->texture, texture);
view->context = pipe;
}
svga_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);
}
#include "tgsi/tgsi_parse.h"
#include "svga_screen.h"
-#include "svga_screen_buffer.h"
+#include "svga_resource_buffer.h"
#include "svga_context.h"
/* Adjust refcounts */
for (i = 0; i < count; i++) {
- pipe_buffer_reference(&svga->curr.vb[i].buffer, buffers[i].buffer);
+ pipe_resource_reference(&svga->curr.vb[i].buffer, buffers[i].buffer);
if (svga_buffer_is_user_buffer(buffers[i].buffer))
any_user_buffer = TRUE;
}
for ( ; i < svga->curr.num_vertex_buffers; i++)
- pipe_buffer_reference(&svga->curr.vb[i].buffer, NULL);
+ pipe_resource_reference(&svga->curr.vb[i].buffer, NULL);
/* Copy remaining data */
memcpy(svga->curr.vb, buffers, count * sizeof buffers[0]);
unsigned i;
for (i = 0 ; i < svga->curr.num_vertex_buffers; i++)
- pipe_buffer_reference(&svga->curr.vb[i].buffer, NULL);
+ pipe_resource_reference(&svga->curr.vb[i].buffer, NULL);
}
--- /dev/null
+#include "util/u_debug.h"
+
+#include "svga_resource.h"
+#include "svga_resource_buffer.h"
+#include "svga_resource_texture.h"
+#include "svga_context.h"
+#include "svga_screen.h"
+
+
+static struct pipe_resource *
+svga_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ if (template->target == PIPE_BUFFER)
+ return svga_buffer_create(screen, template);
+ else
+ return svga_resource_create(screen, template);
+
+}
+
+static struct pipe_resource *
+svga_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 svga_resource_from_handle(screen, template, whandle);
+}
+
+
+void
+svga_init_resource_functions(struct svga_context *svga)
+{
+ svga->pipe.get_transfer = u_get_transfer_vtbl;
+ svga->pipe.transfer_map = u_transfer_map_vtbl;
+ svga->pipe.transfer_flush_region = u_transfer_flush_region_vtbl;
+ svga->pipe.transfer_unmap = u_transfer_unmap_vtbl;
+ svga->pipe.transfer_destroy = u_transfer_destroy_vtbl;
+ svga->pipe.transfer_inline_write = u_transfer_inline_write_vtbl;
+}
+
+void
+svga_init_screen_resource_functions(struct svga_screen *is)
+{
+ is->screen.resource_create = svga_resource_create;
+ is->screen.resource_from_handle = svga_resource_from_handle;
+ is->screen.resource_get_handle = u_resource_get_handle_vtbl;
+ is->screen.resource_destroy = u_resource_destroy_vtbl;
+ is->screen.user_buffer_create = svga_user_buffer_create;
+}
+
+
+
--- /dev/null
+/**************************************************************************
+ *
+ * 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 SVGA_RESOURCE_H
+#define SVGA_RESOURCE_H
+
+struct svga_screen;
+
+#include "util/u_debug.h"
+
+struct svga_context;
+struct svga_screen;
+
+
+void svga_init_screen_resource_functions(struct svga_screen *is);
+void svga_init_resource_functions(struct svga_context *svga );
+
+
+#endif /* SVGA_RESOURCE_H */
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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.
+ *
+ **********************************************************/
+
+#include "svga_cmd.h"
+
+#include "pipe/p_state.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "os/os_thread.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+#include "svga_context.h"
+#include "svga_screen.h"
+#include "svga_resource_buffer.h"
+#include "svga_resource_buffer_upload.h"
+#include "svga_winsys.h"
+#include "svga_debug.h"
+
+
+/**
+ * Vertex and index buffers need hardware backing. Constant buffers
+ * do not. No other types of buffers currently supported.
+ */
+static INLINE boolean
+svga_buffer_needs_hw_storage(unsigned usage)
+{
+ return usage & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER);
+}
+
+
+static unsigned int
+svga_buffer_is_referenced( struct pipe_context *pipe,
+ struct pipe_resource *buf,
+ unsigned face, unsigned level)
+{
+ struct svga_screen *ss = svga_screen(pipe->screen);
+ struct svga_buffer *sbuf = svga_buffer(buf);
+
+ /**
+ * XXX: Check this.
+ * The screen may cache buffer writes, but when we map, we map out
+ * of those cached writes, so we don't need to set a
+ * PIPE_REFERENCED_FOR_WRITE flag for cached buffers.
+ */
+
+ if (!sbuf->handle || ss->sws->surface_is_flushed(ss->sws, sbuf->handle))
+ return PIPE_UNREFERENCED;
+
+ /**
+ * sws->surface_is_flushed() does not distinguish between read references
+ * and write references. So assume a reference is both,
+ * however, we make an exception for index- and vertex buffers, to avoid
+ * a flush in st_bufferobj_get_subdata, during display list replay.
+ */
+
+ if (sbuf->b.b.bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER))
+ return PIPE_REFERENCED_FOR_READ;
+
+ return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
+}
+
+
+
+
+
+
+static void *
+svga_buffer_map_range( struct pipe_screen *screen,
+ struct pipe_resource *buf,
+ unsigned offset,
+ unsigned length,
+ unsigned usage )
+{
+ struct svga_screen *ss = svga_screen(screen);
+ struct svga_winsys_screen *sws = ss->sws;
+ struct svga_buffer *sbuf = svga_buffer( buf );
+ void *map;
+
+ if (!sbuf->swbuf && !sbuf->hwbuf) {
+ if (svga_buffer_create_hw_storage(ss, sbuf) != PIPE_OK) {
+ /*
+ * We can't create a hardware buffer big enough, so create a malloc
+ * buffer instead.
+ */
+ debug_printf("%s: failed to allocate %u KB of DMA, splitting DMA transfers\n",
+ __FUNCTION__,
+ (sbuf->b.b.width0 + 1023)/1024);
+
+ sbuf->swbuf = align_malloc(sbuf->b.b.width0, 16);
+ }
+ }
+
+ if (sbuf->swbuf) {
+ /* User/malloc buffer */
+ map = sbuf->swbuf;
+ }
+ else if (sbuf->hwbuf) {
+ map = sws->buffer_map(sws, sbuf->hwbuf, usage);
+ }
+ else {
+ map = NULL;
+ }
+
+ if(map) {
+ pipe_mutex_lock(ss->swc_mutex);
+
+ ++sbuf->map.count;
+
+ if (usage & PIPE_TRANSFER_WRITE) {
+ assert(sbuf->map.count <= 1);
+ sbuf->map.writing = TRUE;
+ if (usage & PIPE_TRANSFER_FLUSH_EXPLICIT)
+ sbuf->map.flush_explicit = TRUE;
+ }
+
+ pipe_mutex_unlock(ss->swc_mutex);
+ }
+
+ return map;
+}
+
+
+
+static void
+svga_buffer_flush_mapped_range( struct pipe_screen *screen,
+ struct pipe_resource *buf,
+ unsigned offset, unsigned length)
+{
+ struct svga_buffer *sbuf = svga_buffer( buf );
+ struct svga_screen *ss = svga_screen(screen);
+
+ pipe_mutex_lock(ss->swc_mutex);
+ assert(sbuf->map.writing);
+ if(sbuf->map.writing) {
+ assert(sbuf->map.flush_explicit);
+ svga_buffer_add_range(sbuf, offset, offset + length);
+ }
+ pipe_mutex_unlock(ss->swc_mutex);
+}
+
+static void
+svga_buffer_unmap( struct pipe_screen *screen,
+ struct pipe_resource *buf)
+{
+ struct svga_screen *ss = svga_screen(screen);
+ struct svga_winsys_screen *sws = ss->sws;
+ struct svga_buffer *sbuf = svga_buffer( buf );
+
+ pipe_mutex_lock(ss->swc_mutex);
+
+ assert(sbuf->map.count);
+ if(sbuf->map.count)
+ --sbuf->map.count;
+
+ if(sbuf->hwbuf)
+ sws->buffer_unmap(sws, sbuf->hwbuf);
+
+ if(sbuf->map.writing) {
+ if(!sbuf->map.flush_explicit) {
+ /* No mapped range was flushed -- flush the whole buffer */
+ SVGA_DBG(DEBUG_DMA, "flushing the whole buffer\n");
+
+ svga_buffer_add_range(sbuf, 0, sbuf->b.b.width0);
+ }
+
+ sbuf->map.writing = FALSE;
+ sbuf->map.flush_explicit = FALSE;
+ }
+
+ pipe_mutex_unlock(ss->swc_mutex);
+}
+
+
+
+static void
+svga_buffer_destroy( struct pipe_screen *screen,
+ struct pipe_resource *buf )
+{
+ struct svga_screen *ss = svga_screen(screen);
+ struct svga_buffer *sbuf = svga_buffer( buf );
+
+ assert(!p_atomic_read(&buf->reference.count));
+
+ assert(!sbuf->dma.pending);
+
+ if(sbuf->handle)
+ svga_buffer_destroy_host_surface(ss, sbuf);
+
+ if(sbuf->uploaded.buffer)
+ pipe_resource_reference(&sbuf->uploaded.buffer, NULL);
+
+ if(sbuf->hwbuf)
+ svga_buffer_destroy_hw_storage(ss, sbuf);
+
+ if(sbuf->swbuf && !sbuf->user)
+ align_free(sbuf->swbuf);
+
+ FREE(sbuf);
+}
+
+
+/* Keep the original code more or less intact, implement transfers in
+ * terms of the old functions.
+ */
+static void *
+svga_buffer_transfer_map( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ uint8_t *map = svga_buffer_map_range( pipe->screen,
+ transfer->resource,
+ transfer->box.x,
+ transfer->box.width,
+ transfer->usage );
+ if (map == NULL)
+ return NULL;
+
+ /* map_buffer() returned a pointer to the beginning of the buffer,
+ * but transfers are expected to return a pointer to just the
+ * region specified in the box.
+ */
+ return map + transfer->box.x;
+}
+
+
+
+static void svga_buffer_transfer_flush_region( struct pipe_context *pipe,
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box)
+{
+ assert(box->x + box->width <= transfer->box.width);
+
+ svga_buffer_flush_mapped_range(pipe->screen,
+ transfer->resource,
+ transfer->box.x + box->x,
+ box->width);
+}
+
+static void svga_buffer_transfer_unmap( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ svga_buffer_unmap(pipe->screen,
+ transfer->resource);
+}
+
+
+
+
+
+
+
+struct u_resource_vtbl svga_buffer_vtbl =
+{
+ u_default_resource_get_handle, /* get_handle */
+ svga_buffer_destroy, /* resource_destroy */
+ svga_buffer_is_referenced, /* is_resource_referenced */
+ u_default_get_transfer, /* get_transfer */
+ u_default_transfer_destroy, /* transfer_destroy */
+ svga_buffer_transfer_map, /* transfer_map */
+ svga_buffer_transfer_flush_region, /* transfer_flush_region */
+ svga_buffer_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+struct pipe_resource *
+svga_buffer_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ struct svga_screen *ss = svga_screen(screen);
+ struct svga_buffer *sbuf;
+
+ sbuf = CALLOC_STRUCT(svga_buffer);
+ if(!sbuf)
+ goto error1;
+
+ sbuf->b.b = *template;
+ sbuf->b.vtbl = &svga_buffer_vtbl;
+ pipe_reference_init(&sbuf->b.b.reference, 1);
+ sbuf->b.b.screen = screen;
+
+ if(svga_buffer_needs_hw_storage(template->bind)) {
+ if(svga_buffer_create_host_surface(ss, sbuf) != PIPE_OK)
+ goto error2;
+ }
+ else {
+ sbuf->swbuf = align_malloc(template->width0, 64);
+ if(!sbuf->swbuf)
+ goto error2;
+ }
+
+ return &sbuf->b.b;
+
+error2:
+ FREE(sbuf);
+error1:
+ return NULL;
+}
+
+struct pipe_resource *
+svga_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind)
+{
+ struct svga_buffer *sbuf;
+
+ sbuf = CALLOC_STRUCT(svga_buffer);
+ if(!sbuf)
+ goto no_sbuf;
+
+ pipe_reference_init(&sbuf->b.b.reference, 1);
+ sbuf->b.vtbl = &svga_buffer_vtbl;
+ sbuf->b.b.screen = screen;
+ sbuf->b.b.format = PIPE_FORMAT_R8_UNORM; /* ?? */
+ sbuf->b.b._usage = PIPE_USAGE_IMMUTABLE;
+ sbuf->b.b.bind = bind;
+ sbuf->b.b.width0 = bytes;
+ sbuf->b.b.height0 = 1;
+ sbuf->b.b.depth0 = 1;
+
+ sbuf->swbuf = ptr;
+ sbuf->user = TRUE;
+
+ return &sbuf->b.b;
+
+no_sbuf:
+ return NULL;
+}
+
+
+
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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 SVGA_BUFFER_H
+#define SVGA_BUFFER_H
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_state.h"
+#include "util/u_transfer.h"
+
+#include "util/u_double_list.h"
+
+#include "svga_screen_cache.h"
+
+
+/**
+ * Maximum number of discontiguous ranges
+ */
+#define SVGA_BUFFER_MAX_RANGES 32
+
+
+struct svga_screen;
+struct svga_context;
+struct svga_winsys_buffer;
+struct svga_winsys_surface;
+
+
+extern struct u_resource_vtbl svga_buffer_vtbl;
+
+struct svga_buffer_range
+{
+ unsigned start;
+ unsigned end;
+};
+
+
+/**
+ * SVGA pipe buffer.
+ */
+struct svga_buffer
+{
+ struct u_resource b;
+
+ /**
+ * Regular (non DMA'able) memory.
+ *
+ * Used for user buffers or for buffers which we know before hand that can
+ * never be used by the virtual hardware directly, such as constant buffers.
+ */
+ void *swbuf;
+
+ /**
+ * Whether swbuf was created by the user or not.
+ */
+ boolean user;
+
+ /**
+ * Creation key for the host surface handle.
+ *
+ * This structure describes all the host surface characteristics so that it
+ * can be looked up in cache, since creating a host surface is often a slow
+ * operation.
+ */
+ struct svga_host_surface_cache_key key;
+
+ /**
+ * Host surface handle.
+ *
+ * This is a platform independent abstraction for host SID. We create when
+ * trying to bind
+ */
+ struct svga_winsys_surface *handle;
+
+ /**
+ * Information about ongoing and past map operations.
+ */
+ struct {
+ /**
+ * Number of concurrent mappings.
+ *
+ * XXX: It is impossible to guarantee concurrent maps work in all
+ * circumstances -- pipe_buffers really need transfer objects too.
+ */
+ unsigned count;
+
+ /**
+ * Whether this buffer is currently mapped for writing.
+ */
+ boolean writing;
+
+ /**
+ * Whether the application will tell us explicity which ranges it touched
+ * or not.
+ */
+ boolean flush_explicit;
+
+ /**
+ * Dirty ranges.
+ *
+ * Ranges that were touched by the application and need to be uploaded to
+ * the host.
+ *
+ * This information will be copied into dma.boxes, when emiting the
+ * SVGA3dCmdSurfaceDMA command.
+ */
+ struct svga_buffer_range ranges[SVGA_BUFFER_MAX_RANGES];
+ unsigned num_ranges;
+ } map;
+
+ /**
+ * Information about uploaded version of user buffers.
+ */
+ struct {
+ struct pipe_resource *buffer;
+
+ /**
+ * We combine multiple user buffers into the same hardware buffer. This
+ * is the relative offset within that buffer.
+ */
+ unsigned offset;
+ } uploaded;
+
+ /**
+ * DMA'ble memory.
+ *
+ * A piece of GMR memory, with the same size of the buffer. It is created
+ * when mapping the buffer, and will be used to upload vertex data to the
+ * host.
+ */
+ struct svga_winsys_buffer *hwbuf;
+
+ /**
+ * Information about pending DMA uploads.
+ *
+ */
+ struct {
+ /**
+ * Whether this buffer has an unfinished DMA upload command.
+ *
+ * If not set then the rest of the information is null.
+ */
+ boolean pending;
+
+ SVGA3dSurfaceDMAFlags flags;
+
+ /**
+ * Pointer to the DMA copy box *inside* the command buffer.
+ */
+ SVGA3dCopyBox *boxes;
+
+ /**
+ * Context that has the pending DMA to this buffer.
+ */
+ struct svga_context *svga;
+ } dma;
+
+ /**
+ * Linked list head, used to gather all buffers with pending dma uploads on
+ * a context. It is only valid if the dma.pending is set above.
+ */
+ struct list_head head;
+};
+
+
+static INLINE struct svga_buffer *
+svga_buffer(struct pipe_resource *buffer)
+{
+ if (buffer) {
+ assert(((struct svga_buffer *)buffer)->b.vtbl == &svga_buffer_vtbl);
+ return (struct svga_buffer *)buffer;
+ }
+ return NULL;
+}
+
+
+/**
+ * Returns TRUE for user buffers. We may
+ * decide to use an alternate upload path for these buffers.
+ */
+static INLINE boolean
+svga_buffer_is_user_buffer( struct pipe_resource *buffer )
+{
+ return svga_buffer(buffer)->user;
+}
+
+
+
+
+struct pipe_resource *
+svga_user_buffer_create(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned usage);
+
+struct pipe_resource *
+svga_buffer_create(struct pipe_screen *screen,
+ const struct pipe_resource *template);
+
+
+
+/**
+ * Get the host surface handle for this buffer.
+ *
+ * This will ensure the host surface is updated, issuing DMAs as needed.
+ *
+ * NOTE: This may insert new commands in the context, so it *must* be called
+ * before reserving command buffer space. And, in order to insert commands
+ * it may need to call svga_context_flush().
+ */
+struct svga_winsys_surface *
+svga_buffer_handle(struct svga_context *svga,
+ struct pipe_resource *buf);
+
+void
+svga_context_flush_buffers(struct svga_context *svga);
+
+struct svga_winsys_buffer *
+svga_winsys_buffer_create(struct svga_screen *ss,
+ unsigned alignment,
+ unsigned usage,
+ unsigned size);
+
+#endif /* SVGA_BUFFER_H */
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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.
+ *
+ **********************************************************/
+
+#include "svga_cmd.h"
+
+#include "pipe/p_state.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "os/os_thread.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+#include "svga_context.h"
+#include "svga_screen.h"
+#include "svga_resource_buffer.h"
+#include "svga_resource_buffer_upload.h"
+#include "svga_winsys.h"
+#include "svga_debug.h"
+
+
+/* Allocate a winsys_buffer (ie. DMA, aka GMR memory).
+ */
+struct svga_winsys_buffer *
+svga_winsys_buffer_create( struct svga_screen *ss,
+ unsigned alignment,
+ unsigned usage,
+ unsigned size )
+{
+ struct svga_winsys_screen *sws = ss->sws;
+ struct svga_winsys_buffer *buf;
+
+ /* Just try */
+ buf = sws->buffer_create(sws, alignment, usage, size);
+ if(!buf) {
+
+ SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "flushing screen to find %d bytes GMR\n",
+ size);
+
+ /* Try flushing all pending DMAs */
+ svga_screen_flush(ss, NULL);
+ buf = sws->buffer_create(sws, alignment, usage, size);
+
+ }
+
+ return buf;
+}
+
+
+void
+svga_buffer_destroy_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf)
+{
+ struct svga_winsys_screen *sws = ss->sws;
+
+ assert(!sbuf->map.count);
+ assert(sbuf->hwbuf);
+ if(sbuf->hwbuf) {
+ sws->buffer_destroy(sws, sbuf->hwbuf);
+ sbuf->hwbuf = NULL;
+ }
+}
+
+
+
+/**
+ * Allocate DMA'ble storage for the buffer.
+ *
+ * Called before mapping a buffer.
+ */
+enum pipe_error
+svga_buffer_create_hw_storage(struct svga_screen *ss,
+ struct svga_buffer *sbuf)
+{
+ assert(!sbuf->user);
+
+ if(!sbuf->hwbuf) {
+ unsigned alignment = 16;
+ unsigned usage = 0;
+ unsigned size = sbuf->b.b.width0;
+
+ sbuf->hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
+ if(!sbuf->hwbuf)
+ return PIPE_ERROR_OUT_OF_MEMORY;
+
+ assert(!sbuf->dma.pending);
+ }
+
+ return PIPE_OK;
+}
+
+
+
+enum pipe_error
+svga_buffer_create_host_surface(struct svga_screen *ss,
+ struct svga_buffer *sbuf)
+{
+ if(!sbuf->handle) {
+ sbuf->key.flags = 0;
+
+ sbuf->key.format = SVGA3D_BUFFER;
+ if(sbuf->b.b.bind & PIPE_BIND_VERTEX_BUFFER)
+ sbuf->key.flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
+ if(sbuf->b.b.bind & PIPE_BIND_INDEX_BUFFER)
+ sbuf->key.flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
+
+ sbuf->key.size.width = sbuf->b.b.width0;
+ sbuf->key.size.height = 1;
+ sbuf->key.size.depth = 1;
+
+ sbuf->key.numFaces = 1;
+ sbuf->key.numMipLevels = 1;
+ sbuf->key.cachable = 1;
+
+ SVGA_DBG(DEBUG_DMA, "surface_create for buffer sz %d\n", sbuf->b.b.width0);
+
+ sbuf->handle = svga_screen_surface_create(ss, &sbuf->key);
+ if(!sbuf->handle)
+ return PIPE_ERROR_OUT_OF_MEMORY;
+
+ /* Always set the discard flag on the first time the buffer is written
+ * as svga_screen_surface_create might have passed a recycled host
+ * buffer.
+ */
+ sbuf->dma.flags.discard = TRUE;
+
+ SVGA_DBG(DEBUG_DMA, " --> got sid %p sz %d (buffer)\n", sbuf->handle, sbuf->b.b.width0);
+ }
+
+ return PIPE_OK;
+}
+
+
+void
+svga_buffer_destroy_host_surface(struct svga_screen *ss,
+ struct svga_buffer *sbuf)
+{
+ if(sbuf->handle) {
+ SVGA_DBG(DEBUG_DMA, " ungrab sid %p sz %d\n", sbuf->handle, sbuf->b.b.width0);
+ svga_screen_surface_destroy(ss, &sbuf->key, &sbuf->handle);
+ }
+}
+
+
+/**
+ * Variant of SVGA3D_BufferDMA which leaves the copy box temporarily in blank.
+ */
+static enum pipe_error
+svga_buffer_upload_command(struct svga_context *svga,
+ struct svga_buffer *sbuf)
+{
+ struct svga_winsys_context *swc = svga->swc;
+ struct svga_winsys_buffer *guest = sbuf->hwbuf;
+ struct svga_winsys_surface *host = sbuf->handle;
+ SVGA3dTransferType transfer = SVGA3D_WRITE_HOST_VRAM;
+ SVGA3dCmdSurfaceDMA *cmd;
+ uint32 numBoxes = sbuf->map.num_ranges;
+ SVGA3dCopyBox *boxes;
+ SVGA3dCmdSurfaceDMASuffix *pSuffix;
+ unsigned region_flags;
+ unsigned surface_flags;
+ struct pipe_resource *dummy;
+
+ if(transfer == SVGA3D_WRITE_HOST_VRAM) {
+ region_flags = SVGA_RELOC_READ;
+ surface_flags = SVGA_RELOC_WRITE;
+ }
+ else if(transfer == SVGA3D_READ_HOST_VRAM) {
+ region_flags = SVGA_RELOC_WRITE;
+ surface_flags = SVGA_RELOC_READ;
+ }
+ else {
+ assert(0);
+ return PIPE_ERROR_BAD_INPUT;
+ }
+
+ assert(numBoxes);
+
+ cmd = SVGA3D_FIFOReserve(swc,
+ SVGA_3D_CMD_SURFACE_DMA,
+ sizeof *cmd + numBoxes * sizeof *boxes + sizeof *pSuffix,
+ 2);
+ if(!cmd)
+ return PIPE_ERROR_OUT_OF_MEMORY;
+
+ swc->region_relocation(swc, &cmd->guest.ptr, guest, 0, region_flags);
+ cmd->guest.pitch = 0;
+
+ swc->surface_relocation(swc, &cmd->host.sid, host, surface_flags);
+ cmd->host.face = 0;
+ cmd->host.mipmap = 0;
+
+ cmd->transfer = transfer;
+
+ sbuf->dma.boxes = (SVGA3dCopyBox *)&cmd[1];
+ sbuf->dma.svga = svga;
+
+ /* Increment reference count */
+ dummy = NULL;
+ pipe_resource_reference(&dummy, &sbuf->b.b);
+
+ pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + numBoxes * sizeof *boxes);
+ pSuffix->suffixSize = sizeof *pSuffix;
+ pSuffix->maximumOffset = sbuf->b.b.width0;
+ pSuffix->flags = sbuf->dma.flags;
+
+ SVGA_FIFOCommitAll(swc);
+
+ sbuf->dma.flags.discard = FALSE;
+
+ return PIPE_OK;
+}
+
+
+/**
+ * Patch up the upload DMA command reserved by svga_buffer_upload_command
+ * with the final ranges.
+ */
+static void
+svga_buffer_upload_flush(struct svga_context *svga,
+ struct svga_buffer *sbuf)
+{
+ SVGA3dCopyBox *boxes;
+ unsigned i;
+
+ assert(sbuf->handle);
+ assert(sbuf->hwbuf);
+ assert(sbuf->map.num_ranges);
+ assert(sbuf->dma.svga == svga);
+ assert(sbuf->dma.boxes);
+
+ /*
+ * Patch the DMA command with the final copy box.
+ */
+
+ SVGA_DBG(DEBUG_DMA, "dma to sid %p\n", sbuf->handle);
+
+ boxes = sbuf->dma.boxes;
+ for(i = 0; i < sbuf->map.num_ranges; ++i) {
+ SVGA_DBG(DEBUG_DMA, " bytes %u - %u\n",
+ sbuf->map.ranges[i].start, sbuf->map.ranges[i].end);
+
+ boxes[i].x = sbuf->map.ranges[i].start;
+ boxes[i].y = 0;
+ boxes[i].z = 0;
+ boxes[i].w = sbuf->map.ranges[i].end - sbuf->map.ranges[i].start;
+ boxes[i].h = 1;
+ boxes[i].d = 1;
+ boxes[i].srcx = sbuf->map.ranges[i].start;
+ boxes[i].srcy = 0;
+ boxes[i].srcz = 0;
+ }
+
+ sbuf->map.num_ranges = 0;
+
+ assert(sbuf->head.prev && sbuf->head.next);
+ LIST_DEL(&sbuf->head);
+#ifdef DEBUG
+ sbuf->head.next = sbuf->head.prev = NULL;
+#endif
+ sbuf->dma.pending = FALSE;
+
+ sbuf->dma.svga = NULL;
+ sbuf->dma.boxes = NULL;
+
+ /* Decrement reference count */
+ pipe_reference(&(sbuf->b.b.reference), NULL);
+ sbuf = NULL;
+}
+
+
+
+/**
+ * Note a dirty range.
+ *
+ * This function only notes the range down. It doesn't actually emit a DMA
+ * upload command. That only happens when a context tries to refer to this
+ * buffer, and the DMA upload command is added to that context's command buffer.
+ *
+ * We try to lump as many contiguous DMA transfers together as possible.
+ */
+void
+svga_buffer_add_range(struct svga_buffer *sbuf,
+ unsigned start,
+ unsigned end)
+{
+ unsigned i;
+ unsigned nearest_range;
+ unsigned nearest_dist;
+
+ assert(end > start);
+
+ if (sbuf->map.num_ranges < SVGA_BUFFER_MAX_RANGES) {
+ nearest_range = sbuf->map.num_ranges;
+ nearest_dist = ~0;
+ } else {
+ nearest_range = SVGA_BUFFER_MAX_RANGES - 1;
+ nearest_dist = 0;
+ }
+
+ /*
+ * Try to grow one of the ranges.
+ *
+ * Note that it is not this function task to care about overlapping ranges,
+ * as the GMR was already given so it is too late to do anything. Situations
+ * where overlapping ranges may pose a problem should be detected via
+ * pipe_context::is_resource_referenced and the context that refers to the
+ * buffer should be flushed.
+ */
+
+ for(i = 0; i < sbuf->map.num_ranges; ++i) {
+ int left_dist;
+ int right_dist;
+ int dist;
+
+ left_dist = start - sbuf->map.ranges[i].end;
+ right_dist = sbuf->map.ranges[i].start - end;
+ dist = MAX2(left_dist, right_dist);
+
+ if (dist <= 0) {
+ /*
+ * Ranges are contiguous or overlapping -- extend this one and return.
+ */
+
+ sbuf->map.ranges[i].start = MIN2(sbuf->map.ranges[i].start, start);
+ sbuf->map.ranges[i].end = MAX2(sbuf->map.ranges[i].end, end);
+ return;
+ }
+ else {
+ /*
+ * Discontiguous ranges -- keep track of the nearest range.
+ */
+
+ if (dist < nearest_dist) {
+ nearest_range = i;
+ nearest_dist = dist;
+ }
+ }
+ }
+
+ /*
+ * We cannot add a new range to an existing DMA command, so patch-up the
+ * pending DMA upload and start clean.
+ */
+
+ if(sbuf->dma.pending)
+ svga_buffer_upload_flush(sbuf->dma.svga, sbuf);
+
+ assert(!sbuf->dma.pending);
+ assert(!sbuf->dma.svga);
+ assert(!sbuf->dma.boxes);
+
+ if (sbuf->map.num_ranges < SVGA_BUFFER_MAX_RANGES) {
+ /*
+ * Add a new range.
+ */
+
+ sbuf->map.ranges[sbuf->map.num_ranges].start = start;
+ sbuf->map.ranges[sbuf->map.num_ranges].end = end;
+ ++sbuf->map.num_ranges;
+ } else {
+ /*
+ * Everything else failed, so just extend the nearest range.
+ *
+ * It is OK to do this because we always keep a local copy of the
+ * host buffer data, for SW TNL, and the host never modifies the buffer.
+ */
+
+ assert(nearest_range < SVGA_BUFFER_MAX_RANGES);
+ assert(nearest_range < sbuf->map.num_ranges);
+ sbuf->map.ranges[nearest_range].start = MIN2(sbuf->map.ranges[nearest_range].start, start);
+ sbuf->map.ranges[nearest_range].end = MAX2(sbuf->map.ranges[nearest_range].end, end);
+ }
+}
+
+
+
+/**
+ * Copy the contents of the malloc buffer to a hardware buffer.
+ */
+static INLINE enum pipe_error
+svga_buffer_update_hw(struct svga_screen *ss, struct svga_buffer *sbuf)
+{
+ assert(!sbuf->user);
+ if(!sbuf->hwbuf) {
+ enum pipe_error ret;
+ void *map;
+
+ assert(sbuf->swbuf);
+ if(!sbuf->swbuf)
+ return PIPE_ERROR;
+
+ ret = svga_buffer_create_hw_storage(ss, sbuf);
+ if(ret != PIPE_OK)
+ return ret;
+
+ pipe_mutex_lock(ss->swc_mutex);
+ map = ss->sws->buffer_map(ss->sws, sbuf->hwbuf, PIPE_TRANSFER_WRITE);
+ assert(map);
+ if(!map) {
+ pipe_mutex_unlock(ss->swc_mutex);
+ svga_buffer_destroy_hw_storage(ss, sbuf);
+ return PIPE_ERROR;
+ }
+
+ memcpy(map, sbuf->swbuf, sbuf->b.b.width0);
+ ss->sws->buffer_unmap(ss->sws, sbuf->hwbuf);
+
+ /* This user/malloc buffer is now indistinguishable from a gpu buffer */
+ assert(!sbuf->map.count);
+ if(!sbuf->map.count) {
+ if(sbuf->user)
+ sbuf->user = FALSE;
+ else
+ align_free(sbuf->swbuf);
+ sbuf->swbuf = NULL;
+ }
+
+ pipe_mutex_unlock(ss->swc_mutex);
+ }
+
+ return PIPE_OK;
+}
+
+
+/**
+ * Upload the buffer to the host in a piecewise fashion.
+ *
+ * Used when the buffer is too big to fit in the GMR aperture.
+ */
+static INLINE enum pipe_error
+svga_buffer_upload_piecewise(struct svga_screen *ss,
+ struct svga_context *svga,
+ struct svga_buffer *sbuf)
+{
+ struct svga_winsys_screen *sws = ss->sws;
+ const unsigned alignment = sizeof(void *);
+ const unsigned usage = 0;
+ unsigned i;
+
+ assert(sbuf->map.num_ranges);
+ assert(!sbuf->dma.pending);
+
+ SVGA_DBG(DEBUG_DMA, "dma to sid %p\n", sbuf->handle);
+
+ for (i = 0; i < sbuf->map.num_ranges; ++i) {
+ struct svga_buffer_range *range = &sbuf->map.ranges[i];
+ unsigned offset = range->start;
+ unsigned size = range->end - range->start;
+
+ while (offset < range->end) {
+ struct svga_winsys_buffer *hwbuf;
+ uint8_t *map;
+ enum pipe_error ret;
+
+ if (offset + size > range->end)
+ size = range->end - offset;
+
+ hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
+ while (!hwbuf) {
+ size /= 2;
+ if (!size)
+ return PIPE_ERROR_OUT_OF_MEMORY;
+ hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
+ }
+
+ SVGA_DBG(DEBUG_DMA, " bytes %u - %u\n",
+ offset, offset + size);
+
+ map = sws->buffer_map(sws, hwbuf,
+ PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_DISCARD);
+ assert(map);
+ if (map) {
+ memcpy(map, sbuf->swbuf, size);
+ sws->buffer_unmap(sws, hwbuf);
+ }
+
+ ret = SVGA3D_BufferDMA(svga->swc,
+ hwbuf, sbuf->handle,
+ SVGA3D_WRITE_HOST_VRAM,
+ size, 0, offset, sbuf->dma.flags);
+ if(ret != PIPE_OK) {
+ svga_context_flush(svga, NULL);
+ ret = SVGA3D_BufferDMA(svga->swc,
+ hwbuf, sbuf->handle,
+ SVGA3D_WRITE_HOST_VRAM,
+ size, 0, offset, sbuf->dma.flags);
+ assert(ret == PIPE_OK);
+ }
+
+ sbuf->dma.flags.discard = FALSE;
+
+ sws->buffer_destroy(sws, hwbuf);
+
+ offset += size;
+ }
+ }
+
+ sbuf->map.num_ranges = 0;
+
+ return PIPE_OK;
+}
+
+
+
+
+/* Get (or create/upload) the winsys surface handle so that we can
+ * refer to this buffer in fifo commands.
+ */
+struct svga_winsys_surface *
+svga_buffer_handle(struct svga_context *svga,
+ struct pipe_resource *buf)
+{
+ struct pipe_screen *screen = svga->pipe.screen;
+ struct svga_screen *ss = svga_screen(screen);
+ struct svga_buffer *sbuf;
+ enum pipe_error ret;
+
+ if(!buf)
+ return NULL;
+
+ sbuf = svga_buffer(buf);
+
+ assert(!sbuf->map.count);
+ assert(!sbuf->user);
+
+ if(!sbuf->handle) {
+ ret = svga_buffer_create_host_surface(ss, sbuf);
+ if(ret != PIPE_OK)
+ return NULL;
+ }
+
+ assert(sbuf->handle);
+
+ if (sbuf->map.num_ranges) {
+ if (!sbuf->dma.pending) {
+ /*
+ * No pending DMA upload yet, so insert a DMA upload command now.
+ */
+
+ /*
+ * Migrate the data from swbuf -> hwbuf if necessary.
+ */
+ ret = svga_buffer_update_hw(ss, sbuf);
+ if (ret == PIPE_OK) {
+ /*
+ * Queue a dma command.
+ */
+
+ ret = svga_buffer_upload_command(svga, sbuf);
+ if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
+ svga_context_flush(svga, NULL);
+ ret = svga_buffer_upload_command(svga, sbuf);
+ assert(ret == PIPE_OK);
+ }
+ if (ret == PIPE_OK) {
+ sbuf->dma.pending = TRUE;
+ assert(!sbuf->head.prev && !sbuf->head.next);
+ LIST_ADDTAIL(&sbuf->head, &svga->dirty_buffers);
+ }
+ }
+ else if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
+ /*
+ * The buffer is too big to fit in the GMR aperture, so break it in
+ * smaller pieces.
+ */
+ ret = svga_buffer_upload_piecewise(ss, svga, sbuf);
+ }
+
+ if (ret != PIPE_OK) {
+ /*
+ * Something unexpected happened above. There is very little that
+ * we can do other than proceeding while ignoring the dirty ranges.
+ */
+ assert(0);
+ sbuf->map.num_ranges = 0;
+ }
+ }
+ else {
+ /*
+ * There a pending dma already. Make sure it is from this context.
+ */
+ assert(sbuf->dma.svga == svga);
+ }
+ }
+
+ assert(!sbuf->map.num_ranges || sbuf->dma.pending);
+
+ return sbuf->handle;
+}
+
+
+
+void
+svga_context_flush_buffers(struct svga_context *svga)
+{
+ struct list_head *curr, *next;
+ struct svga_buffer *sbuf;
+
+ curr = svga->dirty_buffers.next;
+ next = curr->next;
+ while(curr != &svga->dirty_buffers) {
+ sbuf = LIST_ENTRY(struct svga_buffer, curr, head);
+
+ assert(p_atomic_read(&sbuf->b.b.reference.count) != 0);
+ assert(sbuf->dma.pending);
+
+ svga_buffer_upload_flush(svga, sbuf);
+
+ curr = next;
+ next = curr->next;
+ }
+}
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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 SVGA_BUFFER_UPLOAD_H
+#define SVGA_BUFFER_UPLOAD_H
+
+
+void
+svga_buffer_add_range(struct svga_buffer *sbuf,
+ unsigned start,
+ unsigned end);
+
+enum pipe_error
+svga_buffer_create_hw_storage(struct svga_screen *ss,
+ struct svga_buffer *sbuf);
+
+void
+svga_buffer_destroy_hw_storage(struct svga_screen *ss,
+ struct svga_buffer *sbuf);
+
+enum pipe_error
+svga_buffer_create_host_surface(struct svga_screen *ss,
+ struct svga_buffer *sbuf);
+
+void
+svga_buffer_destroy_host_surface(struct svga_screen *ss,
+ struct svga_buffer *sbuf);
+
+
+
+
+#endif /* SVGA_BUFFER_H */
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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.
+ *
+ **********************************************************/
+
+#include "svga_cmd.h"
+
+#include "pipe/p_state.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "os/os_thread.h"
+#include "util/u_format.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+#include "svga_screen.h"
+#include "svga_context.h"
+#include "svga_resource_texture.h"
+#include "svga_resource_buffer.h"
+#include "svga_sampler_view.h"
+#include "svga_winsys.h"
+#include "svga_debug.h"
+
+#include <util/u_string.h>
+
+
+/* XXX: This isn't a real hardware flag, but just a hack for kernel to
+ * know about primary surfaces. Find a better way to accomplish this.
+ */
+#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9)
+
+
+static unsigned int
+svga_texture_is_referenced( struct pipe_context *pipe,
+ struct pipe_resource *texture,
+ unsigned face, unsigned level)
+{
+ struct svga_texture *tex = svga_texture(texture);
+ struct svga_screen *ss = svga_screen(pipe->screen);
+
+ /**
+ * The screen does not cache texture writes.
+ */
+
+ if (!tex->handle || ss->sws->surface_is_flushed(ss->sws, tex->handle))
+ return PIPE_UNREFERENCED;
+
+ /**
+ * sws->surface_is_flushed() does not distinguish between read references
+ * and write references. So assume a reference is both.
+ */
+
+ return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
+}
+
+
+
+/*
+ * Helper function and arrays
+ */
+
+SVGA3dSurfaceFormat
+svga_translate_format(enum pipe_format format)
+{
+ switch(format) {
+
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ return SVGA3D_A8R8G8B8;
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ return SVGA3D_X8R8G8B8;
+
+ /* Required for GL2.1:
+ */
+ case PIPE_FORMAT_B8G8R8A8_SRGB:
+ return SVGA3D_A8R8G8B8;
+
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ return SVGA3D_R5G6B5;
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ return SVGA3D_A1R5G5B5;
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ return SVGA3D_A4R4G4B4;
+
+
+ /* XXX: Doesn't seem to work properly.
+ case PIPE_FORMAT_Z32_UNORM:
+ return SVGA3D_Z_D32;
+ */
+ case PIPE_FORMAT_Z16_UNORM:
+ return SVGA3D_Z_D16;
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ return SVGA3D_Z_D24S8;
+ case PIPE_FORMAT_X8Z24_UNORM:
+ return SVGA3D_Z_D24X8;
+
+ case PIPE_FORMAT_A8_UNORM:
+ return SVGA3D_ALPHA8;
+ case PIPE_FORMAT_L8_UNORM:
+ return SVGA3D_LUMINANCE8;
+
+ case PIPE_FORMAT_DXT1_RGB:
+ case PIPE_FORMAT_DXT1_RGBA:
+ return SVGA3D_DXT1;
+ case PIPE_FORMAT_DXT3_RGBA:
+ return SVGA3D_DXT3;
+ case PIPE_FORMAT_DXT5_RGBA:
+ return SVGA3D_DXT5;
+
+ default:
+ return SVGA3D_FORMAT_INVALID;
+ }
+}
+
+
+SVGA3dSurfaceFormat
+svga_translate_format_render(enum pipe_format format)
+{
+ switch(format) {
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+ case PIPE_FORMAT_X8Z24_UNORM:
+ case PIPE_FORMAT_Z32_UNORM:
+ case PIPE_FORMAT_Z16_UNORM:
+ case PIPE_FORMAT_L8_UNORM:
+ return svga_translate_format(format);
+
+#if 1
+ /* For on host conversion */
+ case PIPE_FORMAT_DXT1_RGB:
+ return SVGA3D_X8R8G8B8;
+ case PIPE_FORMAT_DXT1_RGBA:
+ case PIPE_FORMAT_DXT3_RGBA:
+ case PIPE_FORMAT_DXT5_RGBA:
+ return SVGA3D_A8R8G8B8;
+#endif
+
+ default:
+ return SVGA3D_FORMAT_INVALID;
+ }
+}
+
+
+static INLINE void
+svga_transfer_dma_band(struct svga_transfer *st,
+ SVGA3dTransferType transfer,
+ unsigned y, unsigned h, unsigned srcy)
+{
+ struct svga_texture *texture = svga_texture(st->base.resource);
+ struct svga_screen *screen = svga_screen(texture->b.b.screen);
+ SVGA3dCopyBox box;
+ enum pipe_error ret;
+
+ SVGA_DBG(DEBUG_DMA, "dma %s sid %p, face %u, (%u, %u, %u) - (%u, %u, %u), %ubpp\n",
+ transfer == SVGA3D_WRITE_HOST_VRAM ? "to" : "from",
+ texture->handle,
+ st->base.sr.face,
+ st->base.box.x,
+ y,
+ st->base.box.z,
+ st->base.box.x + st->base.box.width,
+ y + h,
+ st->base.box.z + 1,
+ util_format_get_blocksize(texture->b.b.format) * 8 /
+ (util_format_get_blockwidth(texture->b.b.format)*util_format_get_blockheight(texture->b.b.format)));
+
+ box.x = st->base.box.x;
+ box.y = y;
+ box.z = st->base.box.z;
+ box.w = st->base.box.width;
+ box.h = h;
+ box.d = 1;
+ box.srcx = 0;
+ box.srcy = srcy;
+ box.srcz = 0;
+
+ pipe_mutex_lock(screen->swc_mutex);
+ ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1);
+ if(ret != PIPE_OK) {
+ screen->swc->flush(screen->swc, NULL);
+ ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1);
+ assert(ret == PIPE_OK);
+ }
+ pipe_mutex_unlock(screen->swc_mutex);
+}
+
+
+static INLINE void
+svga_transfer_dma(struct svga_transfer *st,
+ SVGA3dTransferType transfer)
+{
+ struct svga_texture *texture = svga_texture(st->base.resource);
+ struct svga_screen *screen = svga_screen(texture->b.b.screen);
+ struct svga_winsys_screen *sws = screen->sws;
+ struct pipe_fence_handle *fence = NULL;
+
+ if (transfer == SVGA3D_READ_HOST_VRAM) {
+ SVGA_DBG(DEBUG_PERF, "%s: readback transfer\n", __FUNCTION__);
+ }
+
+
+ if(!st->swbuf) {
+ /* Do the DMA transfer in a single go */
+
+ svga_transfer_dma_band(st, transfer, st->base.box.y, st->base.box.height, 0);
+
+ if(transfer == SVGA3D_READ_HOST_VRAM) {
+ svga_screen_flush(screen, &fence);
+ sws->fence_finish(sws, fence, 0);
+ sws->fence_reference(sws, &fence, NULL);
+ }
+ }
+ else {
+ unsigned y, h, srcy;
+ unsigned blockheight = util_format_get_blockheight(st->base.resource->format);
+ h = st->hw_nblocksy * blockheight;
+ srcy = 0;
+ for(y = 0; y < st->base.box.height; y += h) {
+ unsigned offset, length;
+ void *hw, *sw;
+
+ if (y + h > st->base.box.height)
+ h = st->base.box.height - y;
+
+ /* Transfer band must be aligned to pixel block boundaries */
+ assert(y % blockheight == 0);
+ assert(h % blockheight == 0);
+
+ offset = y * st->base.stride / blockheight;
+ length = h * st->base.stride / blockheight;
+
+ sw = (uint8_t *)st->swbuf + offset;
+
+ if(transfer == SVGA3D_WRITE_HOST_VRAM) {
+ /* Wait for the previous DMAs to complete */
+ /* TODO: keep one DMA (at half the size) in the background */
+ if(y) {
+ svga_screen_flush(screen, &fence);
+ sws->fence_finish(sws, fence, 0);
+ sws->fence_reference(sws, &fence, NULL);
+ }
+
+ hw = sws->buffer_map(sws, st->hwbuf, PIPE_TRANSFER_WRITE);
+ assert(hw);
+ if(hw) {
+ memcpy(hw, sw, length);
+ sws->buffer_unmap(sws, st->hwbuf);
+ }
+ }
+
+ svga_transfer_dma_band(st, transfer, y, h, srcy);
+
+ if(transfer == SVGA3D_READ_HOST_VRAM) {
+ svga_screen_flush(screen, &fence);
+ sws->fence_finish(sws, fence, 0);
+
+ hw = sws->buffer_map(sws, st->hwbuf, PIPE_TRANSFER_READ);
+ assert(hw);
+ if(hw) {
+ memcpy(sw, hw, length);
+ sws->buffer_unmap(sws, st->hwbuf);
+ }
+ }
+ }
+ }
+}
+
+
+
+
+
+static boolean
+svga_texture_get_handle(struct pipe_screen *screen,
+ struct pipe_resource *texture,
+ struct winsys_handle *whandle)
+{
+ struct svga_winsys_screen *sws = svga_winsys_screen(texture->screen);
+ unsigned stride;
+
+ assert(svga_texture(texture)->key.cachable == 0);
+ svga_texture(texture)->key.cachable = 0;
+ stride = util_format_get_nblocksx(texture->format, texture->width0) *
+ util_format_get_blocksize(texture->format);
+ return sws->surface_get_handle(sws, svga_texture(texture)->handle, stride, whandle);
+}
+
+
+static void
+svga_texture_destroy(struct pipe_screen *screen,
+ struct pipe_resource *pt)
+{
+ struct svga_screen *ss = svga_screen(screen);
+ struct svga_texture *tex = (struct svga_texture *)pt;
+
+ ss->texture_timestamp++;
+
+ svga_sampler_view_reference(&tex->cached_view, NULL);
+
+ /*
+ DBG("%s deleting %p\n", __FUNCTION__, (void *) tex);
+ */
+ SVGA_DBG(DEBUG_DMA, "unref sid %p (texture)\n", tex->handle);
+ svga_screen_surface_destroy(ss, &tex->key, &tex->handle);
+
+ FREE(tex);
+}
+
+
+
+
+
+
+
+/* XXX: Still implementing this as if it was a screen function, but
+ * can now modify it to queue transfers on the context.
+ */
+static struct pipe_transfer *
+svga_texture_get_transfer(struct pipe_context *pipe,
+ struct pipe_resource *texture,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
+{
+ struct svga_screen *ss = svga_screen(pipe->screen);
+ struct svga_winsys_screen *sws = ss->sws;
+ struct svga_transfer *st;
+ unsigned nblocksx = util_format_get_nblocksx(texture->format, box->width);
+ unsigned nblocksy = util_format_get_nblocksy(texture->format, box->height);
+
+ /* We can't map texture storage directly */
+ if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
+ return NULL;
+
+ st = CALLOC_STRUCT(svga_transfer);
+ if (!st)
+ return NULL;
+
+ pipe_resource_reference(&st->base.resource, texture);
+ st->base.sr = sr;
+ st->base.usage = usage;
+ st->base.box = *box;
+ st->base.stride = nblocksx*util_format_get_blocksize(texture->format);
+ st->base.slice_stride = 0;
+
+ st->hw_nblocksy = nblocksy;
+
+ st->hwbuf = svga_winsys_buffer_create(ss,
+ 1,
+ 0,
+ st->hw_nblocksy*st->base.stride);
+ while(!st->hwbuf && (st->hw_nblocksy /= 2)) {
+ st->hwbuf = svga_winsys_buffer_create(ss,
+ 1,
+ 0,
+ st->hw_nblocksy*st->base.stride);
+ }
+
+ if(!st->hwbuf)
+ goto no_hwbuf;
+
+ if(st->hw_nblocksy < nblocksy) {
+ /* We couldn't allocate a hardware buffer big enough for the transfer,
+ * so allocate regular malloc memory instead */
+ debug_printf("%s: failed to allocate %u KB of DMA, splitting into %u x %u KB DMA transfers\n",
+ __FUNCTION__,
+ (nblocksy*st->base.stride + 1023)/1024,
+ (nblocksy + st->hw_nblocksy - 1)/st->hw_nblocksy,
+ (st->hw_nblocksy*st->base.stride + 1023)/1024);
+ st->swbuf = MALLOC(nblocksy*st->base.stride);
+ if(!st->swbuf)
+ goto no_swbuf;
+ }
+
+ if (usage & PIPE_TRANSFER_READ)
+ svga_transfer_dma(st, SVGA3D_READ_HOST_VRAM);
+
+ return &st->base;
+
+no_swbuf:
+ sws->buffer_destroy(sws, st->hwbuf);
+no_hwbuf:
+ FREE(st);
+ return NULL;
+}
+
+
+/* XXX: Still implementing this as if it was a screen function, but
+ * can now modify it to queue transfers on the context.
+ */
+static void *
+svga_texture_transfer_map( struct pipe_context *pipe,
+ struct pipe_transfer *transfer )
+{
+ struct svga_screen *ss = svga_screen(pipe->screen);
+ struct svga_winsys_screen *sws = ss->sws;
+ struct svga_transfer *st = svga_transfer(transfer);
+
+ if(st->swbuf)
+ return st->swbuf;
+ else
+ /* The wait for read transfers already happened when svga_transfer_dma
+ * was called. */
+ return sws->buffer_map(sws, st->hwbuf, transfer->usage);
+}
+
+
+/* XXX: Still implementing this as if it was a screen function, but
+ * can now modify it to queue transfers on the context.
+ */
+static void
+svga_texture_transfer_unmap(struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
+{
+ struct svga_screen *ss = svga_screen(pipe->screen);
+ struct svga_winsys_screen *sws = ss->sws;
+ struct svga_transfer *st = svga_transfer(transfer);
+
+ if(!st->swbuf)
+ sws->buffer_unmap(sws, st->hwbuf);
+}
+
+
+static void
+svga_texture_transfer_destroy(struct pipe_context *pipe,
+ struct pipe_transfer *transfer)
+{
+ struct svga_texture *tex = svga_texture(transfer->resource);
+ struct svga_screen *ss = svga_screen(pipe->screen);
+ struct svga_winsys_screen *sws = ss->sws;
+ struct svga_transfer *st = svga_transfer(transfer);
+
+ if (st->base.usage & PIPE_TRANSFER_WRITE) {
+ svga_transfer_dma(st, SVGA3D_WRITE_HOST_VRAM);
+ ss->texture_timestamp++;
+ tex->view_age[transfer->sr.level] = ++(tex->age);
+ tex->defined[transfer->sr.face][transfer->sr.level] = TRUE;
+ }
+
+ pipe_resource_reference(&st->base.resource, NULL);
+ FREE(st->swbuf);
+ sws->buffer_destroy(sws, st->hwbuf);
+ FREE(st);
+}
+
+
+
+
+
+struct u_resource_vtbl svga_texture_vtbl =
+{
+ svga_texture_get_handle, /* get_handle */
+ svga_texture_destroy, /* resource_destroy */
+ svga_texture_is_referenced, /* is_resource_referenced */
+ svga_texture_get_transfer, /* get_transfer */
+ svga_texture_transfer_destroy, /* transfer_destroy */
+ svga_texture_transfer_map, /* transfer_map */
+ u_default_transfer_flush_region, /* transfer_flush_region */
+ svga_texture_transfer_unmap, /* transfer_unmap */
+ u_default_transfer_inline_write /* transfer_inline_write */
+};
+
+
+
+
+struct pipe_resource *
+svga_texture_create(struct pipe_screen *screen,
+ const struct pipe_resource *template)
+{
+ struct svga_screen *svgascreen = svga_screen(screen);
+ struct svga_texture *tex = CALLOC_STRUCT(svga_texture);
+
+ if (!tex)
+ goto error1;
+
+ tex->b.b = *template;
+ tex->b.vtbl = &svga_texture_vtbl;
+ pipe_reference_init(&tex->b.b.reference, 1);
+ tex->b.b.screen = screen;
+
+ assert(template->last_level < SVGA_MAX_TEXTURE_LEVELS);
+ if(template->last_level >= SVGA_MAX_TEXTURE_LEVELS)
+ goto error2;
+
+ tex->key.flags = 0;
+ tex->key.size.width = template->width0;
+ tex->key.size.height = template->height0;
+ tex->key.size.depth = template->depth0;
+
+ if(template->target == PIPE_TEXTURE_CUBE) {
+ tex->key.flags |= SVGA3D_SURFACE_CUBEMAP;
+ tex->key.numFaces = 6;
+ }
+ else {
+ tex->key.numFaces = 1;
+ }
+
+ tex->key.cachable = 1;
+
+ if (template->bind & PIPE_BIND_SAMPLER_VIEW)
+ tex->key.flags |= SVGA3D_SURFACE_HINT_TEXTURE;
+
+ if (template->bind & PIPE_BIND_DISPLAY_TARGET) {
+ tex->key.cachable = 0;
+ }
+
+ if (template->bind & PIPE_BIND_SHARED) {
+ tex->key.cachable = 0;
+ }
+
+ if (template->bind & PIPE_BIND_SCANOUT) {
+ tex->key.flags |= SVGA3D_SURFACE_HINT_SCANOUT;
+ tex->key.cachable = 0;
+ }
+
+ /*
+ * XXX: Never pass the SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot
+ * know beforehand whether a texture will be used as a rendertarget or not
+ * and it always requests PIPE_BIND_RENDER_TARGET, therefore
+ * passing the SVGA3D_SURFACE_HINT_RENDERTARGET here defeats its purpose.
+ */
+#if 0
+ if((template->bind & PIPE_BIND_RENDER_TARGET) &&
+ !util_format_is_s3tc(template->format))
+ tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
+#endif
+
+ if(template->bind & PIPE_BIND_DEPTH_STENCIL)
+ tex->key.flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
+
+ tex->key.numMipLevels = template->last_level + 1;
+
+ tex->key.format = svga_translate_format(template->format);
+ if(tex->key.format == SVGA3D_FORMAT_INVALID)
+ goto error2;
+
+ SVGA_DBG(DEBUG_DMA, "surface_create for texture\n", tex->handle);
+ tex->handle = svga_screen_surface_create(svgascreen, &tex->key);
+ if (tex->handle)
+ SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle);
+
+ return &tex->b.b;
+
+error2:
+ FREE(tex);
+error1:
+ return NULL;
+}
+
+
+
+
+struct pipe_resource *
+svga_texture_from_handle(struct pipe_screen *screen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle)
+{
+ struct svga_winsys_screen *sws = svga_winsys_screen(screen);
+ struct svga_winsys_surface *srf;
+ struct svga_texture *tex;
+ enum SVGA3dSurfaceFormat format = 0;
+ assert(screen);
+
+ /* Only supports one type */
+ if (template->target != PIPE_TEXTURE_2D ||
+ template->last_level != 0 ||
+ template->depth0 != 1) {
+ return NULL;
+ }
+
+ srf = sws->surface_from_handle(sws, whandle, &format);
+
+ if (!srf)
+ return NULL;
+
+ if (svga_translate_format(template->format) != format) {
+ unsigned f1 = svga_translate_format(template->format);
+ unsigned f2 = format;
+
+ /* It's okay for XRGB and ARGB or depth with/out stencil to get mixed up */
+ if ( !( (f1 == SVGA3D_X8R8G8B8 && f2 == SVGA3D_A8R8G8B8) ||
+ (f1 == SVGA3D_A8R8G8B8 && f2 == SVGA3D_X8R8G8B8) ||
+ (f1 == SVGA3D_Z_D24X8 && f2 == SVGA3D_Z_D24S8) ) ) {
+ debug_printf("%s wrong format %u != %u\n", __FUNCTION__, f1, f2);
+ return NULL;
+ }
+ }
+
+ tex = CALLOC_STRUCT(svga_texture);
+ if (!tex)
+ return NULL;
+
+ tex->b.b = *template;
+ tex->b.vtbl = &svga_texture_vtbl;
+ pipe_reference_init(&tex->b.b.reference, 1);
+ tex->b.b.screen = screen;
+
+ if (format == SVGA3D_X8R8G8B8)
+ tex->b.b.format = PIPE_FORMAT_B8G8R8X8_UNORM;
+ else if (format == SVGA3D_A8R8G8B8)
+ tex->b.b.format = PIPE_FORMAT_B8G8R8A8_UNORM;
+ else {
+ /* ?? */
+ }
+
+ SVGA_DBG(DEBUG_DMA, "wrap surface sid %p\n", srf);
+
+ tex->key.cachable = 0;
+ tex->handle = srf;
+
+ return &tex->b.b;
+}
+
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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 SVGA_TEXTURE_H
+#define SVGA_TEXTURE_H
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_state.h"
+#include "util/u_inlines.h"
+#include "util/u_transfer.h"
+#include "svga_screen_cache.h"
+
+struct pipe_context;
+struct pipe_screen;
+struct svga_context;
+struct svga_winsys_surface;
+enum SVGA3dSurfaceFormat;
+
+
+#define SVGA_MAX_TEXTURE_LEVELS 16
+
+
+extern struct u_resource_vtbl svga_texture_vtbl;
+
+
+struct svga_texture
+{
+ struct u_resource b;
+
+ boolean defined[6][SVGA_MAX_TEXTURE_LEVELS];
+
+ struct svga_sampler_view *cached_view;
+
+ unsigned view_age[SVGA_MAX_TEXTURE_LEVELS];
+ unsigned age;
+
+ boolean views_modified;
+
+ /**
+ * Creation key for the host surface handle.
+ *
+ * This structure describes all the host surface characteristics so that it
+ * can be looked up in cache, since creating a host surface is often a slow
+ * operation.
+ */
+ struct svga_host_surface_cache_key key;
+
+ /**
+ * Handle for the host side surface.
+ *
+ * This handle is owned by this texture. Views should hold on to a reference
+ * to this texture and never destroy this handle directly.
+ */
+ struct svga_winsys_surface *handle;
+};
+
+
+
+/* Note this is only used for texture (not buffer) transfers:
+ */
+struct svga_transfer
+{
+ struct pipe_transfer base;
+
+ struct svga_winsys_buffer *hwbuf;
+
+ /* Height of the hardware buffer in pixel blocks */
+ unsigned hw_nblocksy;
+
+ /* Temporary malloc buffer when we can't allocate a hardware buffer
+ * big enough */
+ void *swbuf;
+};
+
+
+static INLINE struct svga_texture *svga_texture( struct pipe_resource *resource )
+{
+ struct svga_texture *tex = (struct svga_texture *)resource;
+ assert(tex == NULL || tex->b.vtbl == &svga_texture_vtbl);
+ return tex;
+}
+
+
+static INLINE struct svga_transfer *
+svga_transfer(struct pipe_transfer *transfer)
+{
+ assert(transfer);
+ return (struct svga_transfer *)transfer;
+}
+
+
+
+struct pipe_resource *
+svga_texture_create(struct pipe_screen *screen,
+ const struct pipe_resource *template);
+
+struct pipe_resource *
+svga_texture_from_handle(struct pipe_screen * screen,
+ const struct pipe_resource *template,
+ struct winsys_handle *whandle);
+
+
+
+enum SVGA3dSurfaceFormat
+svga_translate_format(enum pipe_format format);
+
+enum SVGA3dSurfaceFormat
+svga_translate_format_render(enum pipe_format format);
+
+
+#endif /* SVGA_TEXTURE_H */
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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.
+ *
+ **********************************************************/
+
+#include "svga_cmd.h"
+
+#include "pipe/p_state.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "os/os_thread.h"
+#include "util/u_format.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+#include "svga_screen.h"
+#include "svga_context.h"
+#include "svga_resource_texture.h"
+#include "svga_sampler_view.h"
+#include "svga_winsys.h"
+#include "svga_debug.h"
+#include "svga_surface.h"
+
+#include <util/u_string.h>
+
+
+struct svga_sampler_view *
+svga_get_tex_sampler_view(struct pipe_context *pipe,
+ struct pipe_resource *pt,
+ unsigned min_lod, unsigned max_lod)
+{
+ struct svga_screen *ss = svga_screen(pt->screen);
+ struct svga_texture *tex = svga_texture(pt);
+ struct svga_sampler_view *sv = NULL;
+ SVGA3dSurfaceFormat format = svga_translate_format(pt->format);
+ boolean view = TRUE;
+
+ assert(pt);
+ assert(min_lod >= 0);
+ assert(min_lod <= max_lod);
+ assert(max_lod <= pt->last_level);
+
+
+ /* Is a view needed */
+ {
+ /*
+ * Can't control max lod. For first level views and when we only
+ * look at one level we disable mip filtering to achive the same
+ * results as a view.
+ */
+ if (min_lod == 0 && max_lod >= pt->last_level)
+ view = FALSE;
+
+ if (util_format_is_s3tc(pt->format) && view) {
+ format = svga_translate_format_render(pt->format);
+ }
+
+ if (ss->debug.no_sampler_view)
+ view = FALSE;
+
+ if (ss->debug.force_sampler_view)
+ view = TRUE;
+ }
+
+ /* First try the cache */
+ if (view) {
+ pipe_mutex_lock(ss->tex_mutex);
+ if (tex->cached_view &&
+ tex->cached_view->min_lod == min_lod &&
+ tex->cached_view->max_lod == max_lod) {
+ svga_sampler_view_reference(&sv, tex->cached_view);
+ pipe_mutex_unlock(ss->tex_mutex);
+ SVGA_DBG(DEBUG_VIEWS, "svga: Sampler view: reuse %p, %u %u, last %u\n",
+ pt, min_lod, max_lod, pt->last_level);
+ svga_validate_sampler_view(svga_context(pipe), sv);
+ return sv;
+ }
+ pipe_mutex_unlock(ss->tex_mutex);
+ }
+
+ sv = CALLOC_STRUCT(svga_sampler_view);
+ pipe_reference_init(&sv->reference, 1);
+ pipe_resource_reference(&sv->texture, pt);
+ sv->min_lod = min_lod;
+ sv->max_lod = max_lod;
+
+ /* No view needed just use the whole texture */
+ if (!view) {
+ SVGA_DBG(DEBUG_VIEWS,
+ "svga: Sampler view: no %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n",
+ pt, min_lod, max_lod,
+ max_lod - min_lod + 1,
+ pt->width0,
+ pt->height0,
+ pt->depth0,
+ pt->last_level);
+ sv->key.cachable = 0;
+ sv->handle = tex->handle;
+ return sv;
+ }
+
+ SVGA_DBG(DEBUG_VIEWS,
+ "svga: Sampler view: yes %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n",
+ pt, min_lod, max_lod,
+ max_lod - min_lod + 1,
+ pt->width0,
+ pt->height0,
+ pt->depth0,
+ pt->last_level);
+
+ sv->age = tex->age;
+ sv->handle = svga_texture_view_surface(pipe, tex, format,
+ min_lod,
+ max_lod - min_lod + 1,
+ -1, -1,
+ &sv->key);
+
+ if (!sv->handle) {
+ assert(0);
+ sv->key.cachable = 0;
+ sv->handle = tex->handle;
+ return sv;
+ }
+
+ pipe_mutex_lock(ss->tex_mutex);
+ svga_sampler_view_reference(&tex->cached_view, sv);
+ pipe_mutex_unlock(ss->tex_mutex);
+
+ return sv;
+}
+
+void
+svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v)
+{
+ struct svga_texture *tex = svga_texture(v->texture);
+ unsigned numFaces;
+ unsigned age = 0;
+ int i, k;
+
+ assert(svga);
+
+ if (v->handle == tex->handle)
+ return;
+
+ age = tex->age;
+
+ if(tex->b.b.target == PIPE_TEXTURE_CUBE)
+ numFaces = 6;
+ else
+ numFaces = 1;
+
+ for (i = v->min_lod; i <= v->max_lod; i++) {
+ for (k = 0; k < numFaces; k++) {
+ if (v->age < tex->view_age[i])
+ svga_texture_copy_handle(svga, NULL,
+ tex->handle, 0, 0, 0, i, k,
+ v->handle, 0, 0, 0, i - v->min_lod, k,
+ u_minify(tex->b.b.width0, i),
+ u_minify(tex->b.b.height0, i),
+ u_minify(tex->b.b.depth0, i));
+ }
+ }
+
+ v->age = age;
+}
+
+void
+svga_destroy_sampler_view_priv(struct svga_sampler_view *v)
+{
+ struct svga_texture *tex = svga_texture(v->texture);
+
+ if(v->handle != tex->handle) {
+ struct svga_screen *ss = svga_screen(v->texture->screen);
+ SVGA_DBG(DEBUG_DMA, "unref sid %p (sampler view)\n", v->handle);
+ svga_screen_surface_destroy(ss, &v->key, &v->handle);
+ }
+ pipe_resource_reference(&v->texture, NULL);
+ FREE(v);
+}
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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 SVGA_SAMPLER_VIEW_H
+#define SVGA_SAMPLER_VIEW_H
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_state.h"
+#include "util/u_inlines.h"
+#include "svga_screen_cache.h"
+
+struct pipe_context;
+struct pipe_screen;
+struct svga_context;
+struct svga_winsys_surface;
+enum SVGA3dSurfaceFormat;
+
+
+/**
+ * A sampler's view into a texture
+ *
+ * We currently cache one sampler view on
+ * the texture and in there by holding a reference
+ * from the texture to the sampler view.
+ *
+ * Because of this we can not hold a refernce to the
+ * texture from the sampler view. So the user
+ * of the sampler views must make sure that the
+ * texture has a reference take for as long as
+ * the sampler view is refrenced.
+ *
+ * Just unreferencing the sampler_view before the
+ * texture is enough.
+ */
+struct svga_sampler_view
+{
+ struct pipe_reference reference;
+
+ struct pipe_resource *texture;
+
+ int min_lod;
+ int max_lod;
+
+ unsigned age;
+
+ struct svga_host_surface_cache_key key;
+ struct svga_winsys_surface *handle;
+};
+
+
+
+extern struct svga_sampler_view *
+svga_get_tex_sampler_view(struct pipe_context *pipe,
+ struct pipe_resource *pt,
+ unsigned min_lod, unsigned max_lod);
+
+void
+svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v);
+
+void
+svga_destroy_sampler_view_priv(struct svga_sampler_view *v);
+
+static INLINE void
+svga_sampler_view_reference(struct svga_sampler_view **ptr, struct svga_sampler_view *v)
+{
+ struct svga_sampler_view *old = *ptr;
+
+ if (pipe_reference(&(*ptr)->reference, &v->reference))
+ svga_destroy_sampler_view_priv(old);
+ *ptr = v;
+}
+
+
+#endif
#include "svga_winsys.h"
#include "svga_context.h"
#include "svga_screen.h"
-#include "svga_screen_texture.h"
-#include "svga_screen_buffer.h"
+#include "svga_resource_texture.h"
+#include "svga_resource_buffer.h"
+#include "svga_resource.h"
#include "svga_debug.h"
#include "svga3d_shaderdefs.h"
assert(tex_usage);
/* Override host capabilities */
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
+ if (tex_usage & PIPE_BIND_RENDER_TARGET) {
switch(format) {
/* Often unsupported/problematic. This means we end up with the same
SVGA3dSurfaceFormatCaps mask;
mask.value = 0;
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
+ if (tex_usage & PIPE_BIND_RENDER_TARGET)
mask.offscreenRenderTarget = 1;
- if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL)
+ if (tex_usage & PIPE_BIND_DEPTH_STENCIL)
mask.zStencil = 1;
- if (tex_usage & PIPE_TEXTURE_USAGE_SAMPLER)
+ if (tex_usage & PIPE_BIND_SAMPLER_VIEW)
mask.texture = 1;
if ((result.u & mask.value) == mask.value)
* duplicated list of supported formats which is prone to getting
* out of sync:
*/
- if(tex_usage & (PIPE_TEXTURE_USAGE_RENDER_TARGET | PIPE_TEXTURE_USAGE_DEPTH_STENCIL))
+ if(tex_usage & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL))
return svga_translate_format_render(format) != SVGA3D_FORMAT_INVALID;
else
return svga_translate_format(format) != SVGA3D_FORMAT_INVALID;
screen->fence_finish = svga_fence_finish;
svgascreen->sws = sws;
- svga_screen_init_texture_functions(screen);
- svga_screen_init_buffer_functions(screen);
+ svga_init_screen_resource_functions(svgascreen);
svgascreen->use_ps30 =
sws->get_cap(sws, SVGA3D_DEVCAP_FRAGMENT_SHADER_VERSION, &result) &&
+++ /dev/null
-/**********************************************************
- * Copyright 2008-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, 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 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.
- *
- **********************************************************/
-
-#include "svga_cmd.h"
-
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-#include "os/os_thread.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
-
-#include "svga_context.h"
-#include "svga_screen.h"
-#include "svga_screen_buffer.h"
-#include "svga_winsys.h"
-#include "svga_debug.h"
-
-
-/**
- * Vertex and index buffers have to be treated slightly differently from
- * regular guest memory regions because the SVGA device sees them as
- * surfaces, and the state tracker can create/destroy without the pipe
- * driver, therefore we must do the uploads from the vws.
- */
-static INLINE boolean
-svga_buffer_needs_hw_storage(unsigned usage)
-{
- return usage & (PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_INDEX);
-}
-
-
-static INLINE enum pipe_error
-svga_buffer_create_host_surface(struct svga_screen *ss,
- struct svga_buffer *sbuf)
-{
- if(!sbuf->handle) {
- sbuf->key.flags = 0;
-
- sbuf->key.format = SVGA3D_BUFFER;
- if(sbuf->base.usage & PIPE_BUFFER_USAGE_VERTEX)
- sbuf->key.flags |= SVGA3D_SURFACE_HINT_VERTEXBUFFER;
- if(sbuf->base.usage & PIPE_BUFFER_USAGE_INDEX)
- sbuf->key.flags |= SVGA3D_SURFACE_HINT_INDEXBUFFER;
-
- sbuf->key.size.width = sbuf->base.size;
- sbuf->key.size.height = 1;
- sbuf->key.size.depth = 1;
-
- sbuf->key.numFaces = 1;
- sbuf->key.numMipLevels = 1;
- sbuf->key.cachable = 1;
-
- SVGA_DBG(DEBUG_DMA, "surface_create for buffer sz %d\n", sbuf->base.size);
-
- sbuf->handle = svga_screen_surface_create(ss, &sbuf->key);
- if(!sbuf->handle)
- return PIPE_ERROR_OUT_OF_MEMORY;
-
- /* Always set the discard flag on the first time the buffer is written
- * as svga_screen_surface_create might have passed a recycled host
- * buffer.
- */
- sbuf->dma.flags.discard = TRUE;
-
- SVGA_DBG(DEBUG_DMA, " --> got sid %p sz %d (buffer)\n", sbuf->handle, sbuf->base.size);
- }
-
- return PIPE_OK;
-}
-
-
-static INLINE void
-svga_buffer_destroy_host_surface(struct svga_screen *ss,
- struct svga_buffer *sbuf)
-{
- if(sbuf->handle) {
- SVGA_DBG(DEBUG_DMA, " ungrab sid %p sz %d\n", sbuf->handle, sbuf->base.size);
- svga_screen_surface_destroy(ss, &sbuf->key, &sbuf->handle);
- }
-}
-
-
-static INLINE void
-svga_buffer_destroy_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf)
-{
- struct svga_winsys_screen *sws = ss->sws;
-
- assert(!sbuf->map.count);
- assert(sbuf->hwbuf);
- if(sbuf->hwbuf) {
- sws->buffer_destroy(sws, sbuf->hwbuf);
- sbuf->hwbuf = NULL;
- }
-}
-
-struct svga_winsys_buffer *
-svga_winsys_buffer_create( struct svga_screen *ss,
- unsigned alignment,
- unsigned usage,
- unsigned size )
-{
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_winsys_buffer *buf;
-
- /* Just try */
- buf = sws->buffer_create(sws, alignment, usage, size);
- if(!buf) {
-
- SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "flushing screen to find %d bytes GMR\n",
- size);
-
- /* Try flushing all pending DMAs */
- svga_screen_flush(ss, NULL);
- buf = sws->buffer_create(sws, alignment, usage, size);
-
- }
-
- return buf;
-}
-
-
-/**
- * Allocate DMA'ble storage for the buffer.
- *
- * Called before mapping a buffer.
- */
-static INLINE enum pipe_error
-svga_buffer_create_hw_storage(struct svga_screen *ss,
- struct svga_buffer *sbuf)
-{
- assert(!sbuf->user);
-
- if(!sbuf->hwbuf) {
- unsigned alignment = sbuf->base.alignment;
- unsigned usage = 0;
- unsigned size = sbuf->base.size;
-
- sbuf->hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
- if(!sbuf->hwbuf)
- return PIPE_ERROR_OUT_OF_MEMORY;
-
- assert(!sbuf->dma.pending);
- }
-
- return PIPE_OK;
-}
-
-
-/**
- * Variant of SVGA3D_BufferDMA which leaves the copy box temporarily in blank.
- */
-static enum pipe_error
-svga_buffer_upload_command(struct svga_context *svga,
- struct svga_buffer *sbuf)
-{
- struct svga_winsys_context *swc = svga->swc;
- struct svga_winsys_buffer *guest = sbuf->hwbuf;
- struct svga_winsys_surface *host = sbuf->handle;
- SVGA3dTransferType transfer = SVGA3D_WRITE_HOST_VRAM;
- SVGA3dCmdSurfaceDMA *cmd;
- uint32 numBoxes = sbuf->map.num_ranges;
- SVGA3dCopyBox *boxes;
- SVGA3dCmdSurfaceDMASuffix *pSuffix;
- unsigned region_flags;
- unsigned surface_flags;
- struct pipe_buffer *dummy;
-
- if(transfer == SVGA3D_WRITE_HOST_VRAM) {
- region_flags = PIPE_BUFFER_USAGE_GPU_READ;
- surface_flags = PIPE_BUFFER_USAGE_GPU_WRITE;
- }
- else if(transfer == SVGA3D_READ_HOST_VRAM) {
- region_flags = PIPE_BUFFER_USAGE_GPU_WRITE;
- surface_flags = PIPE_BUFFER_USAGE_GPU_READ;
- }
- else {
- assert(0);
- return PIPE_ERROR_BAD_INPUT;
- }
-
- assert(numBoxes);
-
- cmd = SVGA3D_FIFOReserve(swc,
- SVGA_3D_CMD_SURFACE_DMA,
- sizeof *cmd + numBoxes * sizeof *boxes + sizeof *pSuffix,
- 2);
- if(!cmd)
- return PIPE_ERROR_OUT_OF_MEMORY;
-
- swc->region_relocation(swc, &cmd->guest.ptr, guest, 0, region_flags);
- cmd->guest.pitch = 0;
-
- swc->surface_relocation(swc, &cmd->host.sid, host, surface_flags);
- cmd->host.face = 0;
- cmd->host.mipmap = 0;
-
- cmd->transfer = transfer;
-
- sbuf->dma.boxes = (SVGA3dCopyBox *)&cmd[1];
- sbuf->dma.svga = svga;
-
- /* Increment reference count */
- dummy = NULL;
- pipe_buffer_reference(&dummy, &sbuf->base);
-
- pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + numBoxes * sizeof *boxes);
- pSuffix->suffixSize = sizeof *pSuffix;
- pSuffix->maximumOffset = sbuf->base.size;
- pSuffix->flags = sbuf->dma.flags;
-
- SVGA_FIFOCommitAll(swc);
-
- sbuf->dma.flags.discard = FALSE;
-
- return PIPE_OK;
-}
-
-
-/**
- * Patch up the upload DMA command reserved by svga_buffer_upload_command
- * with the final ranges.
- */
-static void
-svga_buffer_upload_flush(struct svga_context *svga,
- struct svga_buffer *sbuf)
-{
- SVGA3dCopyBox *boxes;
- unsigned i;
-
- assert(sbuf->handle);
- assert(sbuf->hwbuf);
- assert(sbuf->map.num_ranges);
- assert(sbuf->dma.svga == svga);
- assert(sbuf->dma.boxes);
-
- /*
- * Patch the DMA command with the final copy box.
- */
-
- SVGA_DBG(DEBUG_DMA, "dma to sid %p\n", sbuf->handle);
-
- boxes = sbuf->dma.boxes;
- for(i = 0; i < sbuf->map.num_ranges; ++i) {
- SVGA_DBG(DEBUG_DMA, " bytes %u - %u\n",
- sbuf->map.ranges[i].start, sbuf->map.ranges[i].end);
-
- boxes[i].x = sbuf->map.ranges[i].start;
- boxes[i].y = 0;
- boxes[i].z = 0;
- boxes[i].w = sbuf->map.ranges[i].end - sbuf->map.ranges[i].start;
- boxes[i].h = 1;
- boxes[i].d = 1;
- boxes[i].srcx = sbuf->map.ranges[i].start;
- boxes[i].srcy = 0;
- boxes[i].srcz = 0;
- }
-
- sbuf->map.num_ranges = 0;
-
- assert(sbuf->head.prev && sbuf->head.next);
- LIST_DEL(&sbuf->head);
-#ifdef DEBUG
- sbuf->head.next = sbuf->head.prev = NULL;
-#endif
- sbuf->dma.pending = FALSE;
-
- sbuf->dma.svga = NULL;
- sbuf->dma.boxes = NULL;
-
- /* Decrement reference count */
- pipe_reference(&(sbuf->base.reference), NULL);
- sbuf = NULL;
-}
-
-
-/**
- * Note a dirty range.
- *
- * This function only notes the range down. It doesn't actually emit a DMA
- * upload command. That only happens when a context tries to refer to this
- * buffer, and the DMA upload command is added to that context's command buffer.
- *
- * We try to lump as many contiguous DMA transfers together as possible.
- */
-static void
-svga_buffer_add_range(struct svga_buffer *sbuf,
- unsigned start,
- unsigned end)
-{
- unsigned i;
- unsigned nearest_range;
- unsigned nearest_dist;
-
- assert(end > start);
-
- if (sbuf->map.num_ranges < SVGA_BUFFER_MAX_RANGES) {
- nearest_range = sbuf->map.num_ranges;
- nearest_dist = ~0;
- } else {
- nearest_range = SVGA_BUFFER_MAX_RANGES - 1;
- nearest_dist = 0;
- }
-
- /*
- * Try to grow one of the ranges.
- *
- * Note that it is not this function task to care about overlapping ranges,
- * as the GMR was already given so it is too late to do anything. Situations
- * where overlapping ranges may pose a problem should be detected via
- * pipe_context::is_buffer_referenced and the context that refers to the
- * buffer should be flushed.
- */
-
- for(i = 0; i < sbuf->map.num_ranges; ++i) {
- int left_dist;
- int right_dist;
- int dist;
-
- left_dist = start - sbuf->map.ranges[i].end;
- right_dist = sbuf->map.ranges[i].start - end;
- dist = MAX2(left_dist, right_dist);
-
- if (dist <= 0) {
- /*
- * Ranges are contiguous or overlapping -- extend this one and return.
- */
-
- sbuf->map.ranges[i].start = MIN2(sbuf->map.ranges[i].start, start);
- sbuf->map.ranges[i].end = MAX2(sbuf->map.ranges[i].end, end);
- return;
- }
- else {
- /*
- * Discontiguous ranges -- keep track of the nearest range.
- */
-
- if (dist < nearest_dist) {
- nearest_range = i;
- nearest_dist = dist;
- }
- }
- }
-
- /*
- * We cannot add a new range to an existing DMA command, so patch-up the
- * pending DMA upload and start clean.
- */
-
- if(sbuf->dma.pending)
- svga_buffer_upload_flush(sbuf->dma.svga, sbuf);
-
- assert(!sbuf->dma.pending);
- assert(!sbuf->dma.svga);
- assert(!sbuf->dma.boxes);
-
- if (sbuf->map.num_ranges < SVGA_BUFFER_MAX_RANGES) {
- /*
- * Add a new range.
- */
-
- sbuf->map.ranges[sbuf->map.num_ranges].start = start;
- sbuf->map.ranges[sbuf->map.num_ranges].end = end;
- ++sbuf->map.num_ranges;
- } else {
- /*
- * Everything else failed, so just extend the nearest range.
- *
- * It is OK to do this because we always keep a local copy of the
- * host buffer data, for SW TNL, and the host never modifies the buffer.
- */
-
- assert(nearest_range < SVGA_BUFFER_MAX_RANGES);
- assert(nearest_range < sbuf->map.num_ranges);
- sbuf->map.ranges[nearest_range].start = MIN2(sbuf->map.ranges[nearest_range].start, start);
- sbuf->map.ranges[nearest_range].end = MAX2(sbuf->map.ranges[nearest_range].end, end);
- }
-}
-
-
-static void *
-svga_buffer_map_range( struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned offset, unsigned length,
- unsigned usage )
-{
- struct svga_screen *ss = svga_screen(screen);
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_buffer *sbuf = svga_buffer( buf );
- void *map;
-
- if (!sbuf->swbuf && !sbuf->hwbuf) {
- if (svga_buffer_create_hw_storage(ss, sbuf) != PIPE_OK) {
- /*
- * We can't create a hardware buffer big enough, so create a malloc
- * buffer instead.
- */
-
- debug_printf("%s: failed to allocate %u KB of DMA, splitting DMA transfers\n",
- __FUNCTION__,
- (sbuf->base.size + 1023)/1024);
-
- sbuf->swbuf = align_malloc(sbuf->base.size, sbuf->base.alignment);
- }
- }
-
- if (sbuf->swbuf) {
- /* User/malloc buffer */
- map = sbuf->swbuf;
- }
- else if (sbuf->hwbuf) {
- map = sws->buffer_map(sws, sbuf->hwbuf, usage);
- }
- else {
- map = NULL;
- }
-
- if(map) {
- pipe_mutex_lock(ss->swc_mutex);
-
- ++sbuf->map.count;
-
- if (usage & PIPE_BUFFER_USAGE_CPU_WRITE) {
- assert(sbuf->map.count <= 1);
- sbuf->map.writing = TRUE;
- if (usage & PIPE_BUFFER_USAGE_FLUSH_EXPLICIT)
- sbuf->map.flush_explicit = TRUE;
- }
-
- pipe_mutex_unlock(ss->swc_mutex);
- }
-
- return map;
-}
-
-static void
-svga_buffer_flush_mapped_range( struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned offset, unsigned length)
-{
- struct svga_buffer *sbuf = svga_buffer( buf );
- struct svga_screen *ss = svga_screen(screen);
-
- pipe_mutex_lock(ss->swc_mutex);
- assert(sbuf->map.writing);
- if(sbuf->map.writing) {
- assert(sbuf->map.flush_explicit);
- svga_buffer_add_range(sbuf, offset, offset + length);
- }
- pipe_mutex_unlock(ss->swc_mutex);
-}
-
-static void
-svga_buffer_unmap( struct pipe_screen *screen,
- struct pipe_buffer *buf)
-{
- struct svga_screen *ss = svga_screen(screen);
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_buffer *sbuf = svga_buffer( buf );
-
- pipe_mutex_lock(ss->swc_mutex);
-
- assert(sbuf->map.count);
- if(sbuf->map.count)
- --sbuf->map.count;
-
- if(sbuf->hwbuf)
- sws->buffer_unmap(sws, sbuf->hwbuf);
-
- if(sbuf->map.writing) {
- if(!sbuf->map.flush_explicit) {
- /* No mapped range was flushed -- flush the whole buffer */
- SVGA_DBG(DEBUG_DMA, "flushing the whole buffer\n");
-
- svga_buffer_add_range(sbuf, 0, sbuf->base.size);
- }
-
- sbuf->map.writing = FALSE;
- sbuf->map.flush_explicit = FALSE;
- }
-
- pipe_mutex_unlock(ss->swc_mutex);
-}
-
-static void
-svga_buffer_destroy( struct pipe_buffer *buf )
-{
- struct svga_screen *ss = svga_screen(buf->screen);
- struct svga_buffer *sbuf = svga_buffer( buf );
-
- assert(!p_atomic_read(&buf->reference.count));
-
- assert(!sbuf->dma.pending);
-
- if(sbuf->handle)
- svga_buffer_destroy_host_surface(ss, sbuf);
-
- if(sbuf->uploaded.buffer)
- pipe_buffer_reference(&sbuf->uploaded.buffer, NULL);
-
- if(sbuf->hwbuf)
- svga_buffer_destroy_hw_storage(ss, sbuf);
-
- if(sbuf->swbuf && !sbuf->user)
- align_free(sbuf->swbuf);
-
- FREE(sbuf);
-}
-
-static struct pipe_buffer *
-svga_buffer_create(struct pipe_screen *screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct svga_screen *ss = svga_screen(screen);
- struct svga_buffer *sbuf;
-
- assert(size);
- assert(alignment);
-
- sbuf = CALLOC_STRUCT(svga_buffer);
- if(!sbuf)
- goto error1;
-
- sbuf->magic = SVGA_BUFFER_MAGIC;
-
- pipe_reference_init(&sbuf->base.reference, 1);
- sbuf->base.screen = screen;
- sbuf->base.alignment = alignment;
- sbuf->base.usage = usage;
- sbuf->base.size = size;
-
- if(svga_buffer_needs_hw_storage(usage)) {
- if(svga_buffer_create_host_surface(ss, sbuf) != PIPE_OK)
- goto error2;
- }
- else {
- if(alignment < sizeof(void*))
- alignment = sizeof(void*);
-
- usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
-
- sbuf->swbuf = align_malloc(size, alignment);
- if(!sbuf->swbuf)
- goto error2;
- }
-
- return &sbuf->base;
-
-error2:
- FREE(sbuf);
-error1:
- return NULL;
-}
-
-static struct pipe_buffer *
-svga_user_buffer_create(struct pipe_screen *screen,
- void *ptr,
- unsigned bytes)
-{
- struct svga_buffer *sbuf;
-
- sbuf = CALLOC_STRUCT(svga_buffer);
- if(!sbuf)
- goto no_sbuf;
-
- sbuf->magic = SVGA_BUFFER_MAGIC;
-
- sbuf->swbuf = ptr;
- sbuf->user = TRUE;
-
- pipe_reference_init(&sbuf->base.reference, 1);
- sbuf->base.screen = screen;
- sbuf->base.alignment = 1;
- sbuf->base.usage = 0;
- sbuf->base.size = bytes;
-
- return &sbuf->base;
-
-no_sbuf:
- return NULL;
-}
-
-
-void
-svga_screen_init_buffer_functions(struct pipe_screen *screen)
-{
- screen->buffer_create = svga_buffer_create;
- screen->user_buffer_create = svga_user_buffer_create;
- screen->buffer_map_range = svga_buffer_map_range;
- screen->buffer_flush_mapped_range = svga_buffer_flush_mapped_range;
- screen->buffer_unmap = svga_buffer_unmap;
- screen->buffer_destroy = svga_buffer_destroy;
-}
-
-
-/**
- * Copy the contents of the malloc buffer to a hardware buffer.
- */
-static INLINE enum pipe_error
-svga_buffer_update_hw(struct svga_screen *ss, struct svga_buffer *sbuf)
-{
- assert(!sbuf->user);
- if(!sbuf->hwbuf) {
- enum pipe_error ret;
- void *map;
-
- assert(sbuf->swbuf);
- if(!sbuf->swbuf)
- return PIPE_ERROR;
-
- ret = svga_buffer_create_hw_storage(ss, sbuf);
- if(ret != PIPE_OK)
- return ret;
-
- pipe_mutex_lock(ss->swc_mutex);
- map = ss->sws->buffer_map(ss->sws, sbuf->hwbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
- assert(map);
- if(!map) {
- pipe_mutex_unlock(ss->swc_mutex);
- svga_buffer_destroy_hw_storage(ss, sbuf);
- return PIPE_ERROR;
- }
-
- memcpy(map, sbuf->swbuf, sbuf->base.size);
- ss->sws->buffer_unmap(ss->sws, sbuf->hwbuf);
-
- /* This user/malloc buffer is now indistinguishable from a gpu buffer */
- assert(!sbuf->map.count);
- if(!sbuf->map.count) {
- if(sbuf->user)
- sbuf->user = FALSE;
- else
- align_free(sbuf->swbuf);
- sbuf->swbuf = NULL;
- }
-
- pipe_mutex_unlock(ss->swc_mutex);
- }
-
- return PIPE_OK;
-}
-
-
-/**
- * Upload the buffer to the host in a piecewise fashion.
- *
- * Used when the buffer is too big to fit in the GMR aperture.
- */
-static INLINE enum pipe_error
-svga_buffer_upload_piecewise(struct svga_screen *ss,
- struct svga_context *svga,
- struct svga_buffer *sbuf)
-{
- struct svga_winsys_screen *sws = ss->sws;
- const unsigned alignment = sizeof(void *);
- const unsigned usage = 0;
- unsigned i;
-
- assert(sbuf->map.num_ranges);
- assert(!sbuf->dma.pending);
-
- SVGA_DBG(DEBUG_DMA, "dma to sid %p\n", sbuf->handle);
-
- for (i = 0; i < sbuf->map.num_ranges; ++i) {
- struct svga_buffer_range *range = &sbuf->map.ranges[i];
- unsigned offset = range->start;
- unsigned size = range->end - range->start;
-
- while (offset < range->end) {
- struct svga_winsys_buffer *hwbuf;
- uint8_t *map;
- enum pipe_error ret;
-
- if (offset + size > range->end)
- size = range->end - offset;
-
- hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
- while (!hwbuf) {
- size /= 2;
- if (!size)
- return PIPE_ERROR_OUT_OF_MEMORY;
- hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
- }
-
- SVGA_DBG(DEBUG_DMA, " bytes %u - %u\n",
- offset, offset + size);
-
- map = sws->buffer_map(sws, hwbuf,
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_DISCARD);
- assert(map);
- if (map) {
- memcpy(map, sbuf->swbuf, size);
- sws->buffer_unmap(sws, hwbuf);
- }
-
- ret = SVGA3D_BufferDMA(svga->swc,
- hwbuf, sbuf->handle,
- SVGA3D_WRITE_HOST_VRAM,
- size, 0, offset, sbuf->dma.flags);
- if(ret != PIPE_OK) {
- svga_context_flush(svga, NULL);
- ret = SVGA3D_BufferDMA(svga->swc,
- hwbuf, sbuf->handle,
- SVGA3D_WRITE_HOST_VRAM,
- size, 0, offset, sbuf->dma.flags);
- assert(ret == PIPE_OK);
- }
-
- sbuf->dma.flags.discard = FALSE;
-
- sws->buffer_destroy(sws, hwbuf);
-
- offset += size;
- }
- }
-
- sbuf->map.num_ranges = 0;
-
- return PIPE_OK;
-}
-
-
-struct svga_winsys_surface *
-svga_buffer_handle(struct svga_context *svga,
- struct pipe_buffer *buf)
-{
- struct pipe_screen *screen = svga->pipe.screen;
- struct svga_screen *ss = svga_screen(screen);
- struct svga_buffer *sbuf;
- enum pipe_error ret;
-
- if(!buf)
- return NULL;
-
- sbuf = svga_buffer(buf);
-
- assert(!sbuf->map.count);
- assert(!sbuf->user);
-
- if(!sbuf->handle) {
- ret = svga_buffer_create_host_surface(ss, sbuf);
- if(ret != PIPE_OK)
- return NULL;
- }
-
- assert(sbuf->handle);
-
- if (sbuf->map.num_ranges) {
- if (!sbuf->dma.pending) {
- /*
- * No pending DMA upload yet, so insert a DMA upload command now.
- */
-
- /*
- * Migrate the data from swbuf -> hwbuf if necessary.
- */
- ret = svga_buffer_update_hw(ss, sbuf);
- if (ret == PIPE_OK) {
- /*
- * Queue a dma command.
- */
-
- ret = svga_buffer_upload_command(svga, sbuf);
- if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
- svga_context_flush(svga, NULL);
- ret = svga_buffer_upload_command(svga, sbuf);
- assert(ret == PIPE_OK);
- }
- if (ret == PIPE_OK) {
- sbuf->dma.pending = TRUE;
- assert(!sbuf->head.prev && !sbuf->head.next);
- LIST_ADDTAIL(&sbuf->head, &svga->dirty_buffers);
- }
- }
- else if (ret == PIPE_ERROR_OUT_OF_MEMORY) {
- /*
- * The buffer is too big to fit in the GMR aperture, so break it in
- * smaller pieces.
- */
- ret = svga_buffer_upload_piecewise(ss, svga, sbuf);
- }
-
- if (ret != PIPE_OK) {
- /*
- * Something unexpected happened above. There is very little that
- * we can do other than proceeding while ignoring the dirty ranges.
- */
- assert(0);
- sbuf->map.num_ranges = 0;
- }
- }
- else {
- /*
- * There a pending dma already. Make sure it is from this context.
- */
- assert(sbuf->dma.svga == svga);
- }
- }
-
- assert(!sbuf->map.num_ranges || sbuf->dma.pending);
-
- return sbuf->handle;
-}
-
-
-struct pipe_buffer *
-svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
- enum SVGA3dSurfaceFormat format,
- struct svga_winsys_surface *srf)
-{
- struct pipe_buffer *buf;
- struct svga_buffer *sbuf;
- struct svga_winsys_screen *sws = svga_winsys_screen(screen);
-
- buf = svga_buffer_create(screen, 0, SVGA_BUFFER_USAGE_WRAPPED, 0);
- if (!buf)
- return NULL;
-
- sbuf = svga_buffer(buf);
-
- /*
- * We are not the creator of this surface and therefore we must not
- * cache it for reuse. Set the cacheable flag to zero in the key to
- * prevent this.
- */
- sbuf->key.format = format;
- sbuf->key.cachable = 0;
- sws->surface_reference(sws, &sbuf->handle, srf);
-
- return buf;
-}
-
-
-struct svga_winsys_surface *
-svga_screen_buffer_get_winsys_surface(struct pipe_buffer *buffer)
-{
- struct svga_winsys_screen *sws = svga_winsys_screen(buffer->screen);
- struct svga_winsys_surface *vsurf = NULL;
-
- assert(svga_buffer(buffer)->key.cachable == 0);
- svga_buffer(buffer)->key.cachable = 0;
- sws->surface_reference(sws, &vsurf, svga_buffer(buffer)->handle);
- return vsurf;
-}
-
-void
-svga_context_flush_buffers(struct svga_context *svga)
-{
- struct list_head *curr, *next;
- struct svga_buffer *sbuf;
-
- curr = svga->dirty_buffers.next;
- next = curr->next;
- while(curr != &svga->dirty_buffers) {
- sbuf = LIST_ENTRY(struct svga_buffer, curr, head);
-
- assert(p_atomic_read(&sbuf->base.reference.count) != 0);
- assert(sbuf->dma.pending);
-
- svga_buffer_upload_flush(svga, sbuf);
-
- curr = next;
- next = curr->next;
- }
-}
+++ /dev/null
-/**********************************************************
- * Copyright 2008-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, 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 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 SVGA_BUFFER_H
-#define SVGA_BUFFER_H
-
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_state.h"
-
-#include "util/u_double_list.h"
-
-#include "svga_screen_cache.h"
-
-
-#define SVGA_BUFFER_MAGIC 0x344f9005
-
-/**
- * Maximum number of discontiguous ranges
- */
-#define SVGA_BUFFER_MAX_RANGES 32
-
-
-struct svga_screen;
-struct svga_context;
-struct svga_winsys_buffer;
-struct svga_winsys_surface;
-
-
-struct svga_buffer_range
-{
- unsigned start;
- unsigned end;
-};
-
-
-/**
- * SVGA pipe buffer.
- */
-struct svga_buffer
-{
- struct pipe_buffer base;
-
- /**
- * Marker to detect bad casts in runtime.
- */
- uint32_t magic;
-
- /**
- * Regular (non DMA'able) memory.
- *
- * Used for user buffers or for buffers which we know before hand that can
- * never be used by the virtual hardware directly, such as constant buffers.
- */
- void *swbuf;
-
- /**
- * Whether swbuf was created by the user or not.
- */
- boolean user;
-
- /**
- * Creation key for the host surface handle.
- *
- * This structure describes all the host surface characteristics so that it
- * can be looked up in cache, since creating a host surface is often a slow
- * operation.
- */
- struct svga_host_surface_cache_key key;
-
- /**
- * Host surface handle.
- *
- * This is a platform independent abstraction for host SID. We create when
- * trying to bind
- */
- struct svga_winsys_surface *handle;
-
- /**
- * Information about ongoing and past map operations.
- */
- struct {
- /**
- * Number of concurrent mappings.
- *
- * XXX: It is impossible to guarantee concurrent maps work in all
- * circumstances -- pipe_buffers really need transfer objects too.
- */
- unsigned count;
-
- /**
- * Whether this buffer is currently mapped for writing.
- */
- boolean writing;
-
- /**
- * Whether the application will tell us explicity which ranges it touched
- * or not.
- */
- boolean flush_explicit;
-
- /**
- * Dirty ranges.
- *
- * Ranges that were touched by the application and need to be uploaded to
- * the host.
- *
- * This information will be copied into dma.boxes, when emiting the
- * SVGA3dCmdSurfaceDMA command.
- */
- struct svga_buffer_range ranges[SVGA_BUFFER_MAX_RANGES];
- unsigned num_ranges;
- } map;
-
- /**
- * Information about uploaded version of user buffers.
- */
- struct {
- struct pipe_buffer *buffer;
-
- /**
- * We combine multiple user buffers into the same hardware buffer. This
- * is the relative offset within that buffer.
- */
- unsigned offset;
- } uploaded;
-
- /**
- * DMA'ble memory.
- *
- * A piece of GMR memory, with the same size of the buffer. It is created
- * when mapping the buffer, and will be used to upload vertex data to the
- * host.
- */
- struct svga_winsys_buffer *hwbuf;
-
- /**
- * Information about pending DMA uploads.
- *
- */
- struct {
- /**
- * Whether this buffer has an unfinished DMA upload command.
- *
- * If not set then the rest of the information is null.
- */
- boolean pending;
-
- SVGA3dSurfaceDMAFlags flags;
-
- /**
- * Pointer to the DMA copy box *inside* the command buffer.
- */
- SVGA3dCopyBox *boxes;
-
- /**
- * Context that has the pending DMA to this buffer.
- */
- struct svga_context *svga;
- } dma;
-
- /**
- * Linked list head, used to gather all buffers with pending dma uploads on
- * a context. It is only valid if the dma.pending is set above.
- */
- struct list_head head;
-};
-
-
-static INLINE struct svga_buffer *
-svga_buffer(struct pipe_buffer *buffer)
-{
- if (buffer) {
- assert(((struct svga_buffer *)buffer)->magic == SVGA_BUFFER_MAGIC);
- return (struct svga_buffer *)buffer;
- }
- return NULL;
-}
-
-
-/**
- * Returns TRUE for user buffers. We may
- * decide to use an alternate upload path for these buffers.
- */
-static INLINE boolean
-svga_buffer_is_user_buffer( struct pipe_buffer *buffer )
-{
- return svga_buffer(buffer)->user;
-}
-
-
-void
-svga_screen_init_buffer_functions(struct pipe_screen *screen);
-
-
-/**
- * Get the host surface handle for this buffer.
- *
- * This will ensure the host surface is updated, issuing DMAs as needed.
- *
- * NOTE: This may insert new commands in the context, so it *must* be called
- * before reserving command buffer space. And, in order to insert commands
- * it may need to call svga_context_flush().
- */
-struct svga_winsys_surface *
-svga_buffer_handle(struct svga_context *svga,
- struct pipe_buffer *buf);
-
-void
-svga_context_flush_buffers(struct svga_context *svga);
-
-struct svga_winsys_buffer *
-svga_winsys_buffer_create(struct svga_screen *ss,
- unsigned alignment,
- unsigned usage,
- unsigned size);
-
-#endif /* SVGA_BUFFER_H */
+++ /dev/null
-/**********************************************************
- * Copyright 2008-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, 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 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.
- *
- **********************************************************/
-
-#include "svga_cmd.h"
-
-#include "pipe/p_state.h"
-#include "pipe/p_defines.h"
-#include "util/u_inlines.h"
-#include "os/os_thread.h"
-#include "util/u_format.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
-
-#include "svga_screen.h"
-#include "svga_context.h"
-#include "svga_screen_texture.h"
-#include "svga_screen_buffer.h"
-#include "svga_winsys.h"
-#include "svga_debug.h"
-#include "svga_screen_buffer.h"
-
-
-/* XXX: This isn't a real hardware flag, but just a hack for kernel to
- * know about primary surfaces. Find a better way to accomplish this.
- */
-#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9)
-
-
-/*
- * Helper function and arrays
- */
-
-SVGA3dSurfaceFormat
-svga_translate_format(enum pipe_format format)
-{
- switch(format) {
-
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- return SVGA3D_A8R8G8B8;
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- return SVGA3D_X8R8G8B8;
-
- /* Required for GL2.1:
- */
- case PIPE_FORMAT_B8G8R8A8_SRGB:
- return SVGA3D_A8R8G8B8;
-
- case PIPE_FORMAT_B5G6R5_UNORM:
- return SVGA3D_R5G6B5;
- case PIPE_FORMAT_B5G5R5A1_UNORM:
- return SVGA3D_A1R5G5B5;
- case PIPE_FORMAT_B4G4R4A4_UNORM:
- return SVGA3D_A4R4G4B4;
-
-
- /* XXX: Doesn't seem to work properly.
- case PIPE_FORMAT_Z32_UNORM:
- return SVGA3D_Z_D32;
- */
- case PIPE_FORMAT_Z16_UNORM:
- return SVGA3D_Z_D16;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- return SVGA3D_Z_D24S8;
- case PIPE_FORMAT_X8Z24_UNORM:
- return SVGA3D_Z_D24X8;
-
- case PIPE_FORMAT_A8_UNORM:
- return SVGA3D_ALPHA8;
- case PIPE_FORMAT_L8_UNORM:
- return SVGA3D_LUMINANCE8;
-
- case PIPE_FORMAT_DXT1_RGB:
- case PIPE_FORMAT_DXT1_RGBA:
- return SVGA3D_DXT1;
- case PIPE_FORMAT_DXT3_RGBA:
- return SVGA3D_DXT3;
- case PIPE_FORMAT_DXT5_RGBA:
- return SVGA3D_DXT5;
-
- default:
- return SVGA3D_FORMAT_INVALID;
- }
-}
-
-
-SVGA3dSurfaceFormat
-svga_translate_format_render(enum pipe_format format)
-{
- switch(format) {
- case PIPE_FORMAT_B8G8R8A8_UNORM:
- case PIPE_FORMAT_B8G8R8X8_UNORM:
- case PIPE_FORMAT_B5G5R5A1_UNORM:
- case PIPE_FORMAT_B4G4R4A4_UNORM:
- case PIPE_FORMAT_B5G6R5_UNORM:
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- case PIPE_FORMAT_X8Z24_UNORM:
- case PIPE_FORMAT_Z32_UNORM:
- case PIPE_FORMAT_Z16_UNORM:
- case PIPE_FORMAT_L8_UNORM:
- return svga_translate_format(format);
-
-#if 1
- /* For on host conversion */
- case PIPE_FORMAT_DXT1_RGB:
- return SVGA3D_X8R8G8B8;
- case PIPE_FORMAT_DXT1_RGBA:
- case PIPE_FORMAT_DXT3_RGBA:
- case PIPE_FORMAT_DXT5_RGBA:
- return SVGA3D_A8R8G8B8;
-#endif
-
- default:
- return SVGA3D_FORMAT_INVALID;
- }
-}
-
-
-static INLINE void
-svga_transfer_dma_band(struct svga_transfer *st,
- SVGA3dTransferType transfer,
- unsigned y, unsigned h, unsigned srcy)
-{
- struct svga_texture *texture = svga_texture(st->base.texture);
- struct svga_screen *screen = svga_screen(texture->base.screen);
- SVGA3dCopyBox box;
- enum pipe_error ret;
-
- SVGA_DBG(DEBUG_DMA, "dma %s sid %p, face %u, (%u, %u, %u) - (%u, %u, %u), %ubpp\n",
- transfer == SVGA3D_WRITE_HOST_VRAM ? "to" : "from",
- texture->handle,
- st->base.face,
- st->base.x,
- y,
- st->base.zslice,
- st->base.x + st->base.width,
- y + h,
- st->base.zslice + 1,
- util_format_get_blocksize(texture->base.format)*8/
- (util_format_get_blockwidth(texture->base.format)*util_format_get_blockheight(texture->base.format)));
-
- box.x = st->base.x;
- box.y = y;
- box.z = st->base.zslice;
- box.w = st->base.width;
- box.h = h;
- box.d = 1;
- box.srcx = 0;
- box.srcy = srcy;
- box.srcz = 0;
-
- pipe_mutex_lock(screen->swc_mutex);
- ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1);
- if(ret != PIPE_OK) {
- screen->swc->flush(screen->swc, NULL);
- ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1);
- assert(ret == PIPE_OK);
- }
- pipe_mutex_unlock(screen->swc_mutex);
-}
-
-
-static INLINE void
-svga_transfer_dma(struct svga_transfer *st,
- SVGA3dTransferType transfer)
-{
- struct svga_texture *texture = svga_texture(st->base.texture);
- struct svga_screen *screen = svga_screen(texture->base.screen);
- struct svga_winsys_screen *sws = screen->sws;
- struct pipe_fence_handle *fence = NULL;
-
- if (transfer == SVGA3D_READ_HOST_VRAM) {
- SVGA_DBG(DEBUG_PERF, "%s: readback transfer\n", __FUNCTION__);
- }
-
-
- if(!st->swbuf) {
- /* Do the DMA transfer in a single go */
-
- svga_transfer_dma_band(st, transfer, st->base.y, st->base.height, 0);
-
- if(transfer == SVGA3D_READ_HOST_VRAM) {
- svga_screen_flush(screen, &fence);
- sws->fence_finish(sws, fence, 0);
- sws->fence_reference(sws, &fence, NULL);
- }
- }
- else {
- unsigned y, h, srcy;
- unsigned blockheight = util_format_get_blockheight(st->base.texture->format);
- h = st->hw_nblocksy * blockheight;
- srcy = 0;
- for(y = 0; y < st->base.height; y += h) {
- unsigned offset, length;
- void *hw, *sw;
-
- if (y + h > st->base.height)
- h = st->base.height - y;
-
- /* Transfer band must be aligned to pixel block boundaries */
- assert(y % blockheight == 0);
- assert(h % blockheight == 0);
-
- offset = y * st->base.stride / blockheight;
- length = h * st->base.stride / blockheight;
-
- sw = (uint8_t *)st->swbuf + offset;
-
- if(transfer == SVGA3D_WRITE_HOST_VRAM) {
- /* Wait for the previous DMAs to complete */
- /* TODO: keep one DMA (at half the size) in the background */
- if(y) {
- svga_screen_flush(screen, &fence);
- sws->fence_finish(sws, fence, 0);
- sws->fence_reference(sws, &fence, NULL);
- }
-
- hw = sws->buffer_map(sws, st->hwbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
- assert(hw);
- if(hw) {
- memcpy(hw, sw, length);
- sws->buffer_unmap(sws, st->hwbuf);
- }
- }
-
- svga_transfer_dma_band(st, transfer, y, h, srcy);
-
- if(transfer == SVGA3D_READ_HOST_VRAM) {
- svga_screen_flush(screen, &fence);
- sws->fence_finish(sws, fence, 0);
-
- hw = sws->buffer_map(sws, st->hwbuf, PIPE_BUFFER_USAGE_CPU_READ);
- assert(hw);
- if(hw) {
- memcpy(sw, hw, length);
- sws->buffer_unmap(sws, st->hwbuf);
- }
- }
- }
- }
-}
-
-
-static struct pipe_texture *
-svga_texture_create(struct pipe_screen *screen,
- const struct pipe_texture *templat)
-{
- struct svga_screen *svgascreen = svga_screen(screen);
- struct svga_texture *tex = CALLOC_STRUCT(svga_texture);
- unsigned width, height, depth;
- unsigned level;
-
- if (!tex)
- goto error1;
-
- tex->base = *templat;
- pipe_reference_init(&tex->base.reference, 1);
- tex->base.screen = screen;
-
- assert(templat->last_level < SVGA_MAX_TEXTURE_LEVELS);
- if(templat->last_level >= SVGA_MAX_TEXTURE_LEVELS)
- goto error2;
-
- width = templat->width0;
- height = templat->height0;
- depth = templat->depth0;
- for(level = 0; level <= templat->last_level; ++level) {
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- depth = u_minify(depth, 1);
- }
-
- tex->key.flags = 0;
- tex->key.size.width = templat->width0;
- tex->key.size.height = templat->height0;
- tex->key.size.depth = templat->depth0;
-
- if(templat->target == PIPE_TEXTURE_CUBE) {
- tex->key.flags |= SVGA3D_SURFACE_CUBEMAP;
- tex->key.numFaces = 6;
- }
- else {
- tex->key.numFaces = 1;
- }
-
- tex->key.cachable = 1;
-
- if(templat->tex_usage & PIPE_TEXTURE_USAGE_SAMPLER)
- tex->key.flags |= SVGA3D_SURFACE_HINT_TEXTURE;
-
- if(templat->tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) {
- tex->key.cachable = 0;
- }
-
- if(templat->tex_usage & PIPE_TEXTURE_USAGE_SHARED) {
- tex->key.cachable = 0;
- }
-
- if(templat->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) {
- tex->key.flags |= SVGA3D_SURFACE_HINT_SCANOUT;
- tex->key.cachable = 0;
- }
-
- /*
- * XXX: Never pass the SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot
- * know beforehand whether a texture will be used as a rendertarget or not
- * and it always requests PIPE_TEXTURE_USAGE_RENDER_TARGET, therefore
- * passing the SVGA3D_SURFACE_HINT_RENDERTARGET here defeats its purpose.
- */
-#if 0
- if((templat->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) &&
- !util_format_is_s3tc(templat->format))
- tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
-#endif
-
- if(templat->tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL)
- tex->key.flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
-
- tex->key.numMipLevels = templat->last_level + 1;
-
- tex->key.format = svga_translate_format(templat->format);
- if(tex->key.format == SVGA3D_FORMAT_INVALID)
- goto error2;
-
- SVGA_DBG(DEBUG_DMA, "surface_create for texture\n", tex->handle);
- tex->handle = svga_screen_surface_create(svgascreen, &tex->key);
- if (tex->handle)
- SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle);
-
- return &tex->base;
-
-error2:
- FREE(tex);
-error1:
- return NULL;
-}
-
-
-
-
-
-static struct pipe_texture *
-svga_screen_texture_from_handle(struct pipe_screen *screen,
- const struct pipe_texture *base,
- struct winsys_handle *whandle)
-{
- struct svga_winsys_screen *sws = svga_winsys_screen(screen);
- struct svga_winsys_surface *srf;
- struct svga_texture *tex;
- enum SVGA3dSurfaceFormat format = 0;
- assert(screen);
-
- /* Only supports one type */
- if (base->target != PIPE_TEXTURE_2D ||
- base->last_level != 0 ||
- base->depth0 != 1) {
- return NULL;
- }
-
- srf = sws->surface_from_handle(sws, whandle, &format);
-
- if (!srf)
- return NULL;
-
- if (svga_translate_format(base->format) != format) {
- unsigned f1 = svga_translate_format(base->format);
- unsigned f2 = format;
-
- /* It's okay for XRGB and ARGB or depth with/out stencil to get mixed up */
- if ( !( (f1 == SVGA3D_X8R8G8B8 && f2 == SVGA3D_A8R8G8B8) ||
- (f1 == SVGA3D_A8R8G8B8 && f2 == SVGA3D_X8R8G8B8) ||
- (f1 == SVGA3D_Z_D24X8 && f2 == SVGA3D_Z_D24S8) ) ) {
- debug_printf("%s wrong format %u != %u\n", __FUNCTION__, f1, f2);
- return NULL;
- }
- }
-
- tex = CALLOC_STRUCT(svga_texture);
- if (!tex)
- return NULL;
-
- tex->base = *base;
-
-
- if (format == 1)
- tex->base.format = PIPE_FORMAT_B8G8R8X8_UNORM;
- else if (format == 2)
- tex->base.format = PIPE_FORMAT_B8G8R8A8_UNORM;
-
- pipe_reference_init(&tex->base.reference, 1);
- tex->base.screen = screen;
-
- SVGA_DBG(DEBUG_DMA, "wrap surface sid %p\n", srf);
-
- tex->key.cachable = 0;
- tex->handle = srf;
-
- return &tex->base;
-}
-
-
-static boolean
-svga_screen_texture_get_handle(struct pipe_screen *screen,
- struct pipe_texture *texture,
- struct winsys_handle *whandle)
-{
- struct svga_winsys_screen *sws = svga_winsys_screen(texture->screen);
- unsigned stride;
-
- assert(svga_texture(texture)->key.cachable == 0);
- svga_texture(texture)->key.cachable = 0;
- stride = util_format_get_nblocksx(texture->format, texture->width0) *
- util_format_get_blocksize(texture->format);
- return sws->surface_get_handle(sws, svga_texture(texture)->handle, stride, whandle);
-}
-
-
-static void
-svga_texture_destroy(struct pipe_texture *pt)
-{
- struct svga_screen *ss = svga_screen(pt->screen);
- struct svga_texture *tex = (struct svga_texture *)pt;
-
- ss->texture_timestamp++;
-
- svga_sampler_view_reference(&tex->cached_view, NULL);
-
- /*
- DBG("%s deleting %p\n", __FUNCTION__, (void *) tex);
- */
- SVGA_DBG(DEBUG_DMA, "unref sid %p (texture)\n", tex->handle);
- svga_screen_surface_destroy(ss, &tex->key, &tex->handle);
-
- FREE(tex);
-}
-
-
-static void
-svga_texture_copy_handle(struct svga_context *svga,
- struct svga_screen *ss,
- struct svga_winsys_surface *src_handle,
- unsigned src_x, unsigned src_y, unsigned src_z,
- unsigned src_level, unsigned src_face,
- struct svga_winsys_surface *dst_handle,
- unsigned dst_x, unsigned dst_y, unsigned dst_z,
- unsigned dst_level, unsigned dst_face,
- unsigned width, unsigned height, unsigned depth)
-{
- struct svga_surface dst, src;
- enum pipe_error ret;
- SVGA3dCopyBox box, *boxes;
-
- assert(svga || ss);
-
- src.handle = src_handle;
- src.real_level = src_level;
- src.real_face = src_face;
- src.real_zslice = 0;
-
- dst.handle = dst_handle;
- dst.real_level = dst_level;
- dst.real_face = dst_face;
- dst.real_zslice = 0;
-
- box.x = dst_x;
- box.y = dst_y;
- box.z = dst_z;
- box.w = width;
- box.h = height;
- box.d = depth;
- box.srcx = src_x;
- box.srcy = src_y;
- box.srcz = src_z;
-
-/*
- SVGA_DBG(DEBUG_VIEWS, "mipcopy src: %p %u (%ux%ux%u), dst: %p %u (%ux%ux%u)\n",
- src_handle, src_level, src_x, src_y, src_z,
- dst_handle, dst_level, dst_x, dst_y, dst_z);
-*/
-
- if (svga) {
- ret = SVGA3D_BeginSurfaceCopy(svga->swc,
- &src.base,
- &dst.base,
- &boxes, 1);
- if(ret != PIPE_OK) {
- svga_context_flush(svga, NULL);
- ret = SVGA3D_BeginSurfaceCopy(svga->swc,
- &src.base,
- &dst.base,
- &boxes, 1);
- assert(ret == PIPE_OK);
- }
- *boxes = box;
- SVGA_FIFOCommitAll(svga->swc);
- } else {
- pipe_mutex_lock(ss->swc_mutex);
- ret = SVGA3D_BeginSurfaceCopy(ss->swc,
- &src.base,
- &dst.base,
- &boxes, 1);
- if(ret != PIPE_OK) {
- ss->swc->flush(ss->swc, NULL);
- ret = SVGA3D_BeginSurfaceCopy(ss->swc,
- &src.base,
- &dst.base,
- &boxes, 1);
- assert(ret == PIPE_OK);
- }
- *boxes = box;
- SVGA_FIFOCommitAll(ss->swc);
- pipe_mutex_unlock(ss->swc_mutex);
- }
-}
-
-static struct svga_winsys_surface *
-svga_texture_view_surface(struct pipe_context *pipe,
- struct svga_texture *tex,
- SVGA3dSurfaceFormat format,
- unsigned start_mip,
- unsigned num_mip,
- int face_pick,
- int zslice_pick,
- struct svga_host_surface_cache_key *key) /* OUT */
-{
- struct svga_screen *ss = svga_screen(tex->base.screen);
- struct svga_winsys_surface *handle;
- uint32_t i, j;
- unsigned z_offset = 0;
-
- SVGA_DBG(DEBUG_PERF,
- "svga: Create surface view: face %d zslice %d mips %d..%d\n",
- face_pick, zslice_pick, start_mip, start_mip+num_mip-1);
-
- key->flags = 0;
- key->format = format;
- key->numMipLevels = num_mip;
- key->size.width = u_minify(tex->base.width0, start_mip);
- key->size.height = u_minify(tex->base.height0, start_mip);
- key->size.depth = zslice_pick < 0 ? u_minify(tex->base.depth0, start_mip) : 1;
- key->cachable = 1;
- assert(key->size.depth == 1);
-
- if(tex->base.target == PIPE_TEXTURE_CUBE && face_pick < 0) {
- key->flags |= SVGA3D_SURFACE_CUBEMAP;
- key->numFaces = 6;
- } else {
- key->numFaces = 1;
- }
-
- if(key->format == SVGA3D_FORMAT_INVALID) {
- key->cachable = 0;
- return NULL;
- }
-
- SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n");
- handle = svga_screen_surface_create(ss, key);
- if (!handle) {
- key->cachable = 0;
- return NULL;
- }
-
- SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture view)\n", handle);
-
- if (face_pick < 0)
- face_pick = 0;
-
- if (zslice_pick >= 0)
- z_offset = zslice_pick;
-
- for (i = 0; i < key->numMipLevels; i++) {
- for (j = 0; j < key->numFaces; j++) {
- if(tex->defined[j + face_pick][i + start_mip]) {
- unsigned depth = (zslice_pick < 0 ?
- u_minify(tex->base.depth0, i + start_mip) :
- 1);
-
- svga_texture_copy_handle(svga_context(pipe),
- ss,
- tex->handle,
- 0, 0, z_offset,
- i + start_mip,
- j + face_pick,
- handle, 0, 0, 0, i, j,
- u_minify(tex->base.width0, i + start_mip),
- u_minify(tex->base.height0, i + start_mip),
- depth);
- }
- }
- }
-
- return handle;
-}
-
-
-static struct pipe_surface *
-svga_get_tex_surface(struct pipe_screen *screen,
- struct pipe_texture *pt,
- unsigned face, unsigned level, unsigned zslice,
- unsigned flags)
-{
- struct svga_texture *tex = svga_texture(pt);
- struct svga_surface *s;
- boolean render = flags & PIPE_BUFFER_USAGE_GPU_WRITE ? TRUE : FALSE;
- boolean view = FALSE;
- SVGA3dSurfaceFormat format;
-
- s = CALLOC_STRUCT(svga_surface);
- if (!s)
- return NULL;
-
- pipe_reference_init(&s->base.reference, 1);
- pipe_texture_reference(&s->base.texture, pt);
- s->base.format = pt->format;
- s->base.width = u_minify(pt->width0, level);
- s->base.height = u_minify(pt->height0, level);
- s->base.usage = flags;
- s->base.level = level;
- s->base.face = face;
- s->base.zslice = zslice;
-
- if (!render)
- format = svga_translate_format(pt->format);
- else
- format = svga_translate_format_render(pt->format);
-
- assert(format != SVGA3D_FORMAT_INVALID);
- assert(!(flags & PIPE_BUFFER_USAGE_CPU_READ_WRITE));
-
-
- if (svga_screen(screen)->debug.force_surface_view)
- view = TRUE;
-
- /* Currently only used for compressed textures */
- if (render &&
- format != svga_translate_format(pt->format)) {
- view = TRUE;
- }
-
- if (level != 0 &&
- svga_screen(screen)->debug.force_level_surface_view)
- view = TRUE;
-
- if (pt->target == PIPE_TEXTURE_3D)
- view = TRUE;
-
- if (svga_screen(screen)->debug.no_surface_view)
- view = FALSE;
-
- if (view) {
- SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: yes %p, level %u face %u z %u, %p\n",
- pt, level, face, zslice, s);
-
- s->handle = svga_texture_view_surface(NULL, tex, format, level, 1, face, zslice,
- &s->key);
- s->real_face = 0;
- s->real_level = 0;
- s->real_zslice = 0;
- } else {
- SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: no %p, level %u, face %u, z %u, %p\n",
- pt, level, face, zslice, s);
-
- memset(&s->key, 0, sizeof s->key);
- s->handle = tex->handle;
- s->real_face = face;
- s->real_level = level;
- s->real_zslice = zslice;
- }
-
- return &s->base;
-}
-
-
-static void
-svga_tex_surface_destroy(struct pipe_surface *surf)
-{
- struct svga_surface *s = svga_surface(surf);
- struct svga_texture *t = svga_texture(surf->texture);
- struct svga_screen *ss = svga_screen(surf->texture->screen);
-
- if(s->handle != t->handle) {
- SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle);
- svga_screen_surface_destroy(ss, &s->key, &s->handle);
- }
-
- pipe_texture_reference(&surf->texture, NULL);
- FREE(surf);
-}
-
-
-static INLINE void
-svga_mark_surface_dirty(struct pipe_surface *surf)
-{
- struct svga_surface *s = svga_surface(surf);
-
- if(!s->dirty) {
- struct svga_texture *tex = svga_texture(surf->texture);
-
- s->dirty = TRUE;
-
- if (s->handle == tex->handle)
- tex->defined[surf->face][surf->level] = TRUE;
- else {
- /* this will happen later in svga_propagate_surface */
- }
- }
-}
-
-
-void svga_mark_surfaces_dirty(struct svga_context *svga)
-{
- unsigned i;
-
- for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
- if (svga->curr.framebuffer.cbufs[i])
- svga_mark_surface_dirty(svga->curr.framebuffer.cbufs[i]);
- }
- if (svga->curr.framebuffer.zsbuf)
- svga_mark_surface_dirty(svga->curr.framebuffer.zsbuf);
-}
-
-/**
- * Progagate any changes from surfaces to texture.
- * pipe is optional context to inline the blit command in.
- */
-void
-svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf)
-{
- struct svga_surface *s = svga_surface(surf);
- struct svga_texture *tex = svga_texture(surf->texture);
- struct svga_screen *ss = svga_screen(surf->texture->screen);
-
- if (!s->dirty)
- return;
-
- s->dirty = FALSE;
- ss->texture_timestamp++;
- tex->view_age[surf->level] = ++(tex->age);
-
- if (s->handle != tex->handle) {
- SVGA_DBG(DEBUG_VIEWS, "svga: Surface propagate: tex %p, level %u, from %p\n", tex, surf->level, surf);
- svga_texture_copy_handle(svga_context(pipe), ss,
- s->handle, 0, 0, 0, s->real_level, s->real_face,
- tex->handle, 0, 0, surf->zslice, surf->level, surf->face,
- u_minify(tex->base.width0, surf->level),
- u_minify(tex->base.height0, surf->level), 1);
- tex->defined[surf->face][surf->level] = TRUE;
- }
-}
-
-/**
- * Check if we should call svga_propagate_surface on the surface.
- */
-extern boolean
-svga_surface_needs_propagation(struct pipe_surface *surf)
-{
- struct svga_surface *s = svga_surface(surf);
- struct svga_texture *tex = svga_texture(surf->texture);
-
- return s->dirty && s->handle != tex->handle;
-}
-
-/* XXX: Still implementing this as if it was a screen function, but
- * can now modify it to queue transfers on the context.
- */
-static struct pipe_transfer *
-svga_get_tex_transfer(struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage, unsigned x, unsigned y,
- unsigned w, unsigned h)
-{
- struct svga_screen *ss = svga_screen(pipe->screen);
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_transfer *st;
- unsigned nblocksx = util_format_get_nblocksx(texture->format, w);
- unsigned nblocksy = util_format_get_nblocksy(texture->format, h);
-
- /* We can't map texture storage directly */
- if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
- return NULL;
-
- st = CALLOC_STRUCT(svga_transfer);
- if (!st)
- return NULL;
-
- st->base.x = x;
- st->base.y = y;
- st->base.width = w;
- st->base.height = h;
- st->base.stride = nblocksx*util_format_get_blocksize(texture->format);
- st->base.usage = usage;
- st->base.face = face;
- st->base.level = level;
- st->base.zslice = zslice;
-
- st->hw_nblocksy = nblocksy;
-
- st->hwbuf = svga_winsys_buffer_create(ss,
- 1,
- 0,
- st->hw_nblocksy*st->base.stride);
- while(!st->hwbuf && (st->hw_nblocksy /= 2)) {
- st->hwbuf = svga_winsys_buffer_create(ss,
- 1,
- 0,
- st->hw_nblocksy*st->base.stride);
- }
-
- if(!st->hwbuf)
- goto no_hwbuf;
-
- if(st->hw_nblocksy < nblocksy) {
- /* We couldn't allocate a hardware buffer big enough for the transfer,
- * so allocate regular malloc memory instead */
- debug_printf("%s: failed to allocate %u KB of DMA, splitting into %u x %u KB DMA transfers\n",
- __FUNCTION__,
- (nblocksy*st->base.stride + 1023)/1024,
- (nblocksy + st->hw_nblocksy - 1)/st->hw_nblocksy,
- (st->hw_nblocksy*st->base.stride + 1023)/1024);
- st->swbuf = MALLOC(nblocksy*st->base.stride);
- if(!st->swbuf)
- goto no_swbuf;
- }
-
- pipe_texture_reference(&st->base.texture, texture);
-
- if (usage & PIPE_TRANSFER_READ)
- svga_transfer_dma(st, SVGA3D_READ_HOST_VRAM);
-
- return &st->base;
-
-no_swbuf:
- sws->buffer_destroy(sws, st->hwbuf);
-no_hwbuf:
- FREE(st);
- return NULL;
-}
-
-
-/* XXX: Still implementing this as if it was a screen function, but
- * can now modify it to queue transfers on the context.
- */
-static void *
-svga_transfer_map( struct pipe_context *pipe,
- struct pipe_transfer *transfer )
-{
- struct svga_screen *ss = svga_screen(pipe->screen);
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_transfer *st = svga_transfer(transfer);
-
- if(st->swbuf)
- return st->swbuf;
- else
- /* The wait for read transfers already happened when svga_transfer_dma
- * was called. */
- return sws->buffer_map(sws, st->hwbuf,
- pipe_transfer_buffer_flags(transfer));
-}
-
-
-/* XXX: Still implementing this as if it was a screen function, but
- * can now modify it to queue transfers on the context.
- */
-static void
-svga_transfer_unmap(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct svga_screen *ss = svga_screen(pipe->screen);
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_transfer *st = svga_transfer(transfer);
-
- if(!st->swbuf)
- sws->buffer_unmap(sws, st->hwbuf);
-}
-
-
-static void
-svga_tex_transfer_destroy(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct svga_texture *tex = svga_texture(transfer->texture);
- struct svga_screen *ss = svga_screen(pipe->screen);
- struct svga_winsys_screen *sws = ss->sws;
- struct svga_transfer *st = svga_transfer(transfer);
-
- if (st->base.usage & PIPE_TRANSFER_WRITE) {
- svga_transfer_dma(st, SVGA3D_WRITE_HOST_VRAM);
- ss->texture_timestamp++;
- tex->view_age[transfer->level] = ++(tex->age);
- tex->defined[transfer->face][transfer->level] = TRUE;
- }
-
- pipe_texture_reference(&st->base.texture, NULL);
- FREE(st->swbuf);
- sws->buffer_destroy(sws, st->hwbuf);
- FREE(st);
-}
-
-
-void
-svga_init_texture_functions(struct pipe_context *pipe)
-{
- pipe->get_tex_transfer = svga_get_tex_transfer;
- pipe->transfer_map = svga_transfer_map;
- pipe->transfer_unmap = svga_transfer_unmap;
- pipe->tex_transfer_destroy = svga_tex_transfer_destroy;
-}
-
-
-void
-svga_screen_init_texture_functions(struct pipe_screen *screen)
-{
- screen->texture_create = svga_texture_create;
- screen->texture_from_handle = svga_screen_texture_from_handle;
- screen->texture_get_handle = svga_screen_texture_get_handle;
- screen->texture_destroy = svga_texture_destroy;
- screen->get_tex_surface = svga_get_tex_surface;
- screen->tex_surface_destroy = svga_tex_surface_destroy;
-}
-
-/***********************************************************************
- */
-
-struct svga_sampler_view *
-svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt,
- unsigned min_lod, unsigned max_lod)
-{
- struct svga_screen *ss = svga_screen(pt->screen);
- struct svga_texture *tex = svga_texture(pt);
- struct svga_sampler_view *sv = NULL;
- SVGA3dSurfaceFormat format = svga_translate_format(pt->format);
- boolean view = TRUE;
-
- assert(pt);
- assert(min_lod >= 0);
- assert(min_lod <= max_lod);
- assert(max_lod <= pt->last_level);
-
-
- /* Is a view needed */
- {
- /*
- * Can't control max lod. For first level views and when we only
- * look at one level we disable mip filtering to achive the same
- * results as a view.
- */
- if (min_lod == 0 && max_lod >= pt->last_level)
- view = FALSE;
-
- if (util_format_is_s3tc(pt->format) && view) {
- format = svga_translate_format_render(pt->format);
- }
-
- if (ss->debug.no_sampler_view)
- view = FALSE;
-
- if (ss->debug.force_sampler_view)
- view = TRUE;
- }
-
- /* First try the cache */
- if (view) {
- pipe_mutex_lock(ss->tex_mutex);
- if (tex->cached_view &&
- tex->cached_view->min_lod == min_lod &&
- tex->cached_view->max_lod == max_lod) {
- svga_sampler_view_reference(&sv, tex->cached_view);
- pipe_mutex_unlock(ss->tex_mutex);
- SVGA_DBG(DEBUG_VIEWS, "svga: Sampler view: reuse %p, %u %u, last %u\n",
- pt, min_lod, max_lod, pt->last_level);
- svga_validate_sampler_view(svga_context(pipe), sv);
- return sv;
- }
- pipe_mutex_unlock(ss->tex_mutex);
- }
-
- sv = CALLOC_STRUCT(svga_sampler_view);
- pipe_reference_init(&sv->reference, 1);
- pipe_texture_reference(&sv->texture, pt);
- sv->min_lod = min_lod;
- sv->max_lod = max_lod;
-
- /* No view needed just use the whole texture */
- if (!view) {
- SVGA_DBG(DEBUG_VIEWS,
- "svga: Sampler view: no %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n",
- pt, min_lod, max_lod,
- max_lod - min_lod + 1,
- pt->width0,
- pt->height0,
- pt->depth0,
- pt->last_level);
- sv->key.cachable = 0;
- sv->handle = tex->handle;
- return sv;
- }
-
- SVGA_DBG(DEBUG_VIEWS,
- "svga: Sampler view: yes %p, mips %u..%u, nr %u, size (%ux%ux%u), last %u\n",
- pt, min_lod, max_lod,
- max_lod - min_lod + 1,
- pt->width0,
- pt->height0,
- pt->depth0,
- pt->last_level);
-
- sv->age = tex->age;
- sv->handle = svga_texture_view_surface(pipe, tex, format,
- min_lod,
- max_lod - min_lod + 1,
- -1, -1,
- &sv->key);
-
- if (!sv->handle) {
- assert(0);
- sv->key.cachable = 0;
- sv->handle = tex->handle;
- return sv;
- }
-
- pipe_mutex_lock(ss->tex_mutex);
- svga_sampler_view_reference(&tex->cached_view, sv);
- pipe_mutex_unlock(ss->tex_mutex);
-
- return sv;
-}
-
-void
-svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v)
-{
- struct svga_texture *tex = svga_texture(v->texture);
- unsigned numFaces;
- unsigned age = 0;
- int i, k;
-
- assert(svga);
-
- if (v->handle == tex->handle)
- return;
-
- age = tex->age;
-
- if(tex->base.target == PIPE_TEXTURE_CUBE)
- numFaces = 6;
- else
- numFaces = 1;
-
- for (i = v->min_lod; i <= v->max_lod; i++) {
- for (k = 0; k < numFaces; k++) {
- if (v->age < tex->view_age[i])
- svga_texture_copy_handle(svga, NULL,
- tex->handle, 0, 0, 0, i, k,
- v->handle, 0, 0, 0, i - v->min_lod, k,
- u_minify(tex->base.width0, i),
- u_minify(tex->base.height0, i),
- u_minify(tex->base.depth0, i));
- }
- }
-
- v->age = age;
-}
-
-void
-svga_destroy_sampler_view_priv(struct svga_sampler_view *v)
-{
- struct svga_texture *tex = svga_texture(v->texture);
-
- if(v->handle != tex->handle) {
- struct svga_screen *ss = svga_screen(v->texture->screen);
- SVGA_DBG(DEBUG_DMA, "unref sid %p (sampler view)\n", v->handle);
- svga_screen_surface_destroy(ss, &v->key, &v->handle);
- }
- pipe_texture_reference(&v->texture, NULL);
- FREE(v);
-}
+++ /dev/null
-/**********************************************************
- * Copyright 2008-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, 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 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 SVGA_TEXTURE_H
-#define SVGA_TEXTURE_H
-
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_state.h"
-#include "util/u_inlines.h"
-#include "svga_screen_cache.h"
-
-struct pipe_context;
-struct pipe_screen;
-struct svga_context;
-struct svga_winsys_surface;
-enum SVGA3dSurfaceFormat;
-
-
-#define SVGA_MAX_TEXTURE_LEVELS 16
-
-
-/**
- * A sampler's view into a texture
- *
- * We currently cache one sampler view on
- * the texture and in there by holding a reference
- * from the texture to the sampler view.
- *
- * Because of this we can not hold a refernce to the
- * texture from the sampler view. So the user
- * of the sampler views must make sure that the
- * texture has a reference take for as long as
- * the sampler view is refrenced.
- *
- * Just unreferencing the sampler_view before the
- * texture is enough.
- */
-struct svga_sampler_view
-{
- struct pipe_reference reference;
-
- struct pipe_texture *texture;
-
- int min_lod;
- int max_lod;
-
- unsigned age;
-
- struct svga_host_surface_cache_key key;
- struct svga_winsys_surface *handle;
-};
-
-
-struct svga_texture
-{
- struct pipe_texture base;
-
- boolean defined[6][SVGA_MAX_TEXTURE_LEVELS];
-
- struct svga_sampler_view *cached_view;
-
- unsigned view_age[SVGA_MAX_TEXTURE_LEVELS];
- unsigned age;
-
- boolean views_modified;
-
- /**
- * Creation key for the host surface handle.
- *
- * This structure describes all the host surface characteristics so that it
- * can be looked up in cache, since creating a host surface is often a slow
- * operation.
- */
- struct svga_host_surface_cache_key key;
-
- /**
- * Handle for the host side surface.
- *
- * This handle is owned by this texture. Views should hold on to a reference
- * to this texture and never destroy this handle directly.
- */
- struct svga_winsys_surface *handle;
-};
-
-
-struct svga_surface
-{
- struct pipe_surface base;
-
- struct svga_host_surface_cache_key key;
- struct svga_winsys_surface *handle;
-
- unsigned real_face;
- unsigned real_level;
- unsigned real_zslice;
-
- boolean dirty;
-};
-
-
-struct svga_transfer
-{
- struct pipe_transfer base;
-
- struct svga_winsys_buffer *hwbuf;
-
- /* Height of the hardware buffer in pixel blocks */
- unsigned hw_nblocksy;
-
- /* Temporary malloc buffer when we can't allocate a hardware buffer
- * big enough */
- void *swbuf;
-};
-
-
-static INLINE struct svga_texture *
-svga_texture(struct pipe_texture *texture)
-{
- return (struct svga_texture *)texture;
-}
-
-static INLINE struct svga_surface *
-svga_surface(struct pipe_surface *surface)
-{
- assert(surface);
- return (struct svga_surface *)surface;
-}
-
-static INLINE struct svga_transfer *
-svga_transfer(struct pipe_transfer *transfer)
-{
- assert(transfer);
- return (struct svga_transfer *)transfer;
-}
-
-extern struct svga_sampler_view *
-svga_get_tex_sampler_view(struct pipe_context *pipe,
- struct pipe_texture *pt,
- unsigned min_lod, unsigned max_lod);
-
-void
-svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v);
-
-void
-svga_destroy_sampler_view_priv(struct svga_sampler_view *v);
-
-static INLINE void
-svga_sampler_view_reference(struct svga_sampler_view **ptr, struct svga_sampler_view *v)
-{
- struct svga_sampler_view *old = *ptr;
-
- if (pipe_reference(&(*ptr)->reference, &v->reference))
- svga_destroy_sampler_view_priv(old);
- *ptr = v;
-}
-
-extern void
-svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf);
-
-extern boolean
-svga_surface_needs_propagation(struct pipe_surface *surf);
-
-extern void
-svga_screen_init_texture_functions(struct pipe_screen *screen);
-
-void
-svga_init_texture_functions(struct pipe_context *pipe);
-
-enum SVGA3dSurfaceFormat
-svga_translate_format(enum pipe_format format);
-
-enum SVGA3dSurfaceFormat
-svga_translate_format_render(enum pipe_format format);
-
-
-#endif /* SVGA_TEXTURE_H */
int offset,
int unit )
{
- struct pipe_screen *screen = svga->pipe.screen;
+ struct pipe_transfer *transfer = NULL;
unsigned count;
const float (*data)[4] = NULL;
unsigned i;
if (svga->curr.cb[unit] == NULL)
goto done;
- count = svga->curr.cb[unit]->size / (4 * sizeof(float));
+ count = svga->curr.cb[unit]->width0 / (4 * sizeof(float));
- data = (const float (*)[4])pipe_buffer_map(screen,
+ data = (const float (*)[4])pipe_buffer_map(&svga->pipe,
svga->curr.cb[unit],
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &transfer);
if (data == NULL) {
ret = PIPE_ERROR_OUT_OF_MEMORY;
goto done;
done:
if (data)
- pipe_buffer_unmap(screen, svga->curr.cb[unit]);
+ pipe_buffer_unmap(&svga->pipe, svga->curr.cb[unit], transfer);
return ret;
}
for (i = 0; i < key->num_textures; i++) {
if (key->tex[i].unnormalized) {
- struct pipe_texture *tex = svga->curr.sampler_views[i]->texture;
+ struct pipe_resource *tex = svga->curr.sampler_views[i]->texture;
float data[4];
data[0] = 1.0 / (float)tex->width0;
#include "pipe/p_defines.h"
#include "util/u_math.h"
-#include "svga_screen_texture.h"
+#include "svga_sampler_view.h"
#include "svga_winsys.h"
#include "svga_context.h"
#include "svga_state.h"
svga_sampler_view_reference(&view->v, NULL);
pipe_sampler_view_reference( &svga->curr.sampler_views[i], NULL );
- pipe_texture_reference( &view->texture, NULL );
+ pipe_resource_reference( &view->texture, NULL );
view->dirty = 1;
}
for (i = 0; i < count; i++) {
const struct svga_sampler_state *s = svga->curr.sampler[i];
struct svga_hw_view_state *view = &svga->state.hw_draw.views[i];
- struct pipe_texture *texture = NULL;
+ struct pipe_resource *texture = NULL;
/* get min max lod */
if (svga->curr.sampler_views[i]) {
view->max_lod != max_lod) {
svga_sampler_view_reference(&view->v, NULL);
- pipe_texture_reference( &view->texture, texture );
+ pipe_resource_reference( &view->texture, texture );
view->dirty = TRUE;
view->min_lod = min_lod;
svga->swc->surface_relocation(svga->swc,
&ts[i].value,
queue.bind[i].view->v->handle,
- PIPE_BUFFER_USAGE_GPU_READ);
+ SVGA_RELOC_READ);
}
else {
ts[i].value = SVGA3D_INVALID_ID;
#include "svga_draw.h"
#include "svga_tgsi.h"
#include "svga_screen.h"
-#include "svga_screen_buffer.h"
+#include "svga_resource_buffer.h"
#include "svga_hw_reg.h"
if (!buffer->uploaded.buffer) {
ret = u_upload_buffer( svga->upload_vb,
0,
- buffer->base.size,
- &buffer->base,
+ buffer->b.b.width0,
+ &buffer->b.b,
&buffer->uploaded.offset,
&buffer->uploaded.buffer );
if (ret)
buffer,
buffer->uploaded.buffer,
buffer->uploaded.offset,
- buffer->base.size);
+ buffer->b.b.width0);
}
- pipe_buffer_reference( &svga->curr.vb[i].buffer, buffer->uploaded.buffer );
+ pipe_resource_reference( &svga->curr.vb[i].buffer, buffer->uploaded.buffer );
svga->curr.vb[i].buffer_offset = buffer->uploaded.offset;
}
}
const struct pipe_vertex_element *vel = &svga->curr.velems->velem[i];
const struct pipe_vertex_buffer *vbuffer = &svga->curr.vb[
vel->vertex_buffer_index];
+
if (vbuffer->stride == 0) {
unsigned const_idx =
svga->curr.num_zero_stride_vertex_elements;
+ struct pipe_transfer *transfer;
struct translate *translate;
struct translate_key key;
void *mapped_buffer;
assert(vel->src_offset == 0);
- mapped_buffer = pipe_buffer_map_range(svga->pipe.screen,
+ mapped_buffer = pipe_buffer_map_range(&svga->pipe,
vbuffer->buffer,
vel->src_offset,
util_format_get_blocksize(vel->src_format),
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &transfer);
+
translate->set_buffer(translate, vel->vertex_buffer_index,
mapped_buffer,
vbuffer->stride);
translate->run(translate, 0, 1, 0,
svga->curr.zero_stride_constants);
- pipe_buffer_unmap(svga->pipe.screen,
- vbuffer->buffer);
+ pipe_buffer_unmap(&svga->pipe,
+ vbuffer->buffer,
+ transfer);
+
translate->release(translate);
}
}
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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.
+ *
+ **********************************************************/
+
+#include "svga_cmd.h"
+
+#include "pipe/p_state.h"
+#include "pipe/p_defines.h"
+#include "util/u_inlines.h"
+#include "os/os_thread.h"
+#include "util/u_format.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
+#include "svga_screen.h"
+#include "svga_context.h"
+#include "svga_resource_texture.h"
+#include "svga_surface.h"
+#include "svga_winsys.h"
+#include "svga_debug.h"
+
+#include <util/u_string.h>
+
+
+void
+svga_texture_copy_handle(struct svga_context *svga,
+ struct svga_screen *ss,
+ struct svga_winsys_surface *src_handle,
+ unsigned src_x, unsigned src_y, unsigned src_z,
+ unsigned src_level, unsigned src_face,
+ struct svga_winsys_surface *dst_handle,
+ unsigned dst_x, unsigned dst_y, unsigned dst_z,
+ unsigned dst_level, unsigned dst_face,
+ unsigned width, unsigned height, unsigned depth)
+{
+ struct svga_surface dst, src;
+ enum pipe_error ret;
+ SVGA3dCopyBox box, *boxes;
+
+ assert(svga || ss);
+
+ src.handle = src_handle;
+ src.real_level = src_level;
+ src.real_face = src_face;
+ src.real_zslice = 0;
+
+ dst.handle = dst_handle;
+ dst.real_level = dst_level;
+ dst.real_face = dst_face;
+ dst.real_zslice = 0;
+
+ box.x = dst_x;
+ box.y = dst_y;
+ box.z = dst_z;
+ box.w = width;
+ box.h = height;
+ box.d = depth;
+ box.srcx = src_x;
+ box.srcy = src_y;
+ box.srcz = src_z;
+
+/*
+ SVGA_DBG(DEBUG_VIEWS, "mipcopy src: %p %u (%ux%ux%u), dst: %p %u (%ux%ux%u)\n",
+ src_handle, src_level, src_x, src_y, src_z,
+ dst_handle, dst_level, dst_x, dst_y, dst_z);
+*/
+
+ if (svga) {
+ ret = SVGA3D_BeginSurfaceCopy(svga->swc,
+ &src.base,
+ &dst.base,
+ &boxes, 1);
+ if(ret != PIPE_OK) {
+ svga_context_flush(svga, NULL);
+ ret = SVGA3D_BeginSurfaceCopy(svga->swc,
+ &src.base,
+ &dst.base,
+ &boxes, 1);
+ assert(ret == PIPE_OK);
+ }
+ *boxes = box;
+ SVGA_FIFOCommitAll(svga->swc);
+ } else {
+ pipe_mutex_lock(ss->swc_mutex);
+ ret = SVGA3D_BeginSurfaceCopy(ss->swc,
+ &src.base,
+ &dst.base,
+ &boxes, 1);
+ if(ret != PIPE_OK) {
+ ss->swc->flush(ss->swc, NULL);
+ ret = SVGA3D_BeginSurfaceCopy(ss->swc,
+ &src.base,
+ &dst.base,
+ &boxes, 1);
+ assert(ret == PIPE_OK);
+ }
+ *boxes = box;
+ SVGA_FIFOCommitAll(ss->swc);
+ pipe_mutex_unlock(ss->swc_mutex);
+ }
+}
+
+
+struct svga_winsys_surface *
+svga_texture_view_surface(struct pipe_context *pipe,
+ struct svga_texture *tex,
+ SVGA3dSurfaceFormat format,
+ unsigned start_mip,
+ unsigned num_mip,
+ int face_pick,
+ int zslice_pick,
+ struct svga_host_surface_cache_key *key) /* OUT */
+{
+ struct svga_screen *ss = svga_screen(pipe->screen);
+ struct svga_winsys_surface *handle;
+ uint32_t i, j;
+ unsigned z_offset = 0;
+
+ SVGA_DBG(DEBUG_PERF,
+ "svga: Create surface view: face %d zslice %d mips %d..%d\n",
+ face_pick, zslice_pick, start_mip, start_mip+num_mip-1);
+
+ key->flags = 0;
+ key->format = format;
+ key->numMipLevels = num_mip;
+ key->size.width = u_minify(tex->b.b.width0, start_mip);
+ key->size.height = u_minify(tex->b.b.height0, start_mip);
+ key->size.depth = zslice_pick < 0 ? u_minify(tex->b.b.depth0, start_mip) : 1;
+ key->cachable = 1;
+ assert(key->size.depth == 1);
+
+ if(tex->b.b.target == PIPE_TEXTURE_CUBE && face_pick < 0) {
+ key->flags |= SVGA3D_SURFACE_CUBEMAP;
+ key->numFaces = 6;
+ } else {
+ key->numFaces = 1;
+ }
+
+ if(key->format == SVGA3D_FORMAT_INVALID) {
+ key->cachable = 0;
+ return NULL;
+ }
+
+ SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n");
+ handle = svga_screen_surface_create(ss, key);
+ if (!handle) {
+ key->cachable = 0;
+ return NULL;
+ }
+
+ SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture view)\n", handle);
+
+ if (face_pick < 0)
+ face_pick = 0;
+
+ if (zslice_pick >= 0)
+ z_offset = zslice_pick;
+
+ for (i = 0; i < key->numMipLevels; i++) {
+ for (j = 0; j < key->numFaces; j++) {
+ if(tex->defined[j + face_pick][i + start_mip]) {
+ unsigned depth = (zslice_pick < 0 ?
+ u_minify(tex->b.b.depth0, i + start_mip) :
+ 1);
+
+ svga_texture_copy_handle(svga_context(pipe),
+ ss,
+ tex->handle,
+ 0, 0, z_offset,
+ i + start_mip,
+ j + face_pick,
+ handle, 0, 0, 0, i, j,
+ u_minify(tex->b.b.width0, i + start_mip),
+ u_minify(tex->b.b.height0, i + start_mip),
+ depth);
+ }
+ }
+ }
+
+ return handle;
+}
+
+
+static struct pipe_surface *
+svga_get_tex_surface(struct pipe_screen *screen,
+ struct pipe_resource *pt,
+ unsigned face, unsigned level, unsigned zslice,
+ unsigned flags)
+{
+ struct svga_texture *tex = svga_texture(pt);
+ struct svga_surface *s;
+ boolean render = (flags & (PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_DEPTH_STENCIL)) ? TRUE : FALSE;
+ boolean view = FALSE;
+ SVGA3dSurfaceFormat format;
+
+ s = CALLOC_STRUCT(svga_surface);
+ if (!s)
+ return NULL;
+
+ pipe_reference_init(&s->base.reference, 1);
+ pipe_resource_reference(&s->base.texture, pt);
+ s->base.format = pt->format;
+ s->base.width = u_minify(pt->width0, level);
+ s->base.height = u_minify(pt->height0, level);
+ s->base.usage = flags;
+ s->base.level = level;
+ s->base.face = face;
+ s->base.zslice = zslice;
+
+ if (!render)
+ format = svga_translate_format(pt->format);
+ else
+ format = svga_translate_format_render(pt->format);
+
+ assert(format != SVGA3D_FORMAT_INVALID);
+
+ if (svga_screen(screen)->debug.force_surface_view)
+ view = TRUE;
+
+ /* Currently only used for compressed textures */
+ if (render &&
+ format != svga_translate_format(pt->format)) {
+ view = TRUE;
+ }
+
+ if (level != 0 &&
+ svga_screen(screen)->debug.force_level_surface_view)
+ view = TRUE;
+
+ if (pt->target == PIPE_TEXTURE_3D)
+ view = TRUE;
+
+ if (svga_screen(screen)->debug.no_surface_view)
+ view = FALSE;
+
+ if (view) {
+ SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: yes %p, level %u face %u z %u, %p\n",
+ pt, level, face, zslice, s);
+
+ s->handle = svga_texture_view_surface(NULL, tex, format, level, 1, face, zslice,
+ &s->key);
+ s->real_face = 0;
+ s->real_level = 0;
+ s->real_zslice = 0;
+ } else {
+ SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: no %p, level %u, face %u, z %u, %p\n",
+ pt, level, face, zslice, s);
+
+ memset(&s->key, 0, sizeof s->key);
+ s->handle = tex->handle;
+ s->real_face = face;
+ s->real_level = level;
+ s->real_zslice = zslice;
+ }
+
+ return &s->base;
+}
+
+
+static void
+svga_tex_surface_destroy(struct pipe_surface *surf)
+{
+ struct svga_surface *s = svga_surface(surf);
+ struct svga_texture *t = svga_texture(surf->texture);
+ struct svga_screen *ss = svga_screen(surf->texture->screen);
+
+ if(s->handle != t->handle) {
+ SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle);
+ svga_screen_surface_destroy(ss, &s->key, &s->handle);
+ }
+
+ pipe_resource_reference(&surf->texture, NULL);
+ FREE(surf);
+}
+
+
+static INLINE void
+svga_mark_surface_dirty(struct pipe_surface *surf)
+{
+ struct svga_surface *s = svga_surface(surf);
+
+ if(!s->dirty) {
+ struct svga_texture *tex = svga_texture(surf->texture);
+
+ s->dirty = TRUE;
+
+ if (s->handle == tex->handle)
+ tex->defined[surf->face][surf->level] = TRUE;
+ else {
+ /* this will happen later in svga_propagate_surface */
+ }
+ }
+}
+
+
+void svga_mark_surfaces_dirty(struct svga_context *svga)
+{
+ unsigned i;
+
+ for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
+ if (svga->curr.framebuffer.cbufs[i])
+ svga_mark_surface_dirty(svga->curr.framebuffer.cbufs[i]);
+ }
+ if (svga->curr.framebuffer.zsbuf)
+ svga_mark_surface_dirty(svga->curr.framebuffer.zsbuf);
+}
+
+
+/**
+ * Progagate any changes from surfaces to texture.
+ * pipe is optional context to inline the blit command in.
+ */
+void
+svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf)
+{
+ struct svga_surface *s = svga_surface(surf);
+ struct svga_texture *tex = svga_texture(surf->texture);
+ struct svga_screen *ss = svga_screen(surf->texture->screen);
+
+ if (!s->dirty)
+ return;
+
+ s->dirty = FALSE;
+ ss->texture_timestamp++;
+ tex->view_age[surf->level] = ++(tex->age);
+
+ if (s->handle != tex->handle) {
+ SVGA_DBG(DEBUG_VIEWS, "svga: Surface propagate: tex %p, level %u, from %p\n", tex, surf->level, surf);
+ svga_texture_copy_handle(svga_context(pipe), ss,
+ s->handle, 0, 0, 0, s->real_level, s->real_face,
+ tex->handle, 0, 0, surf->zslice, surf->level, surf->face,
+ u_minify(tex->b.b.width0, surf->level),
+ u_minify(tex->b.b.height0, surf->level), 1);
+ tex->defined[surf->face][surf->level] = TRUE;
+ }
+}
+
+/**
+ * Check if we should call svga_propagate_surface on the surface.
+ */
+boolean
+svga_surface_needs_propagation(struct pipe_surface *surf)
+{
+ struct svga_surface *s = svga_surface(surf);
+ struct svga_texture *tex = svga_texture(surf->texture);
+
+ return s->dirty && s->handle != tex->handle;
+}
+
+
+
+
+
+
+void
+svga_screen_init_surface_functions(struct pipe_screen *screen)
+{
+ screen->get_tex_surface = svga_get_tex_surface;
+ screen->tex_surface_destroy = svga_tex_surface_destroy;
+}
+
--- /dev/null
+/**********************************************************
+ * Copyright 2008-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, 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 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 SVGA_SURFACE_H
+#define SVGA_SURFACE_H
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_state.h"
+#include "util/u_inlines.h"
+#include "svga_screen_cache.h"
+
+struct pipe_context;
+struct pipe_screen;
+struct svga_context;
+struct svga_texture;
+struct svga_winsys_surface;
+enum SVGA3dSurfaceFormat;
+
+
+struct svga_surface
+{
+ struct pipe_surface base;
+
+ struct svga_host_surface_cache_key key;
+ struct svga_winsys_surface *handle;
+
+ unsigned real_face;
+ unsigned real_level;
+ unsigned real_zslice;
+
+ boolean dirty;
+};
+
+
+extern void
+svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf);
+
+extern boolean
+svga_surface_needs_propagation(struct pipe_surface *surf);
+
+struct svga_winsys_surface *
+svga_texture_view_surface(struct pipe_context *pipe,
+ struct svga_texture *tex,
+ SVGA3dSurfaceFormat format,
+ unsigned start_mip,
+ unsigned num_mip,
+ int face_pick,
+ int zslice_pick,
+ struct svga_host_surface_cache_key *key); /* OUT */
+
+
+void
+svga_texture_copy_handle(struct svga_context *svga,
+ struct svga_screen *ss,
+ struct svga_winsys_surface *src_handle,
+ unsigned src_x, unsigned src_y, unsigned src_z,
+ unsigned src_level, unsigned src_face,
+ struct svga_winsys_surface *dst_handle,
+ unsigned dst_x, unsigned dst_y, unsigned dst_z,
+ unsigned dst_level, unsigned dst_face,
+ unsigned width, unsigned height, unsigned depth);
+
+
+static INLINE struct svga_surface *
+svga_surface(struct pipe_surface *surface)
+{
+ assert(surface);
+ return (struct svga_surface *)surface;
+}
+
+void
+svga_screen_init_surface_functions(struct pipe_screen *screen);
+
+#endif
enum pipe_error
svga_swtnl_draw_range_elements(struct svga_context *svga,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned min_index,
unsigned max_index,
new_vbuf = TRUE;
if (new_vbuf)
- pipe_buffer_reference(&svga_render->vbuf, NULL);
+ pipe_resource_reference(&svga_render->vbuf, NULL);
if (new_ibuf)
- pipe_buffer_reference(&svga_render->ibuf, NULL);
+ pipe_resource_reference(&svga_render->ibuf, NULL);
if (!svga_render->vbuf) {
svga_render->vbuf_size = MAX2(size, svga_render->vbuf_alloc_size);
svga_render->vbuf = pipe_buffer_create(screen,
- 16,
- PIPE_BUFFER_USAGE_VERTEX,
+ PIPE_BIND_VERTEX_BUFFER,
svga_render->vbuf_size);
if(!svga_render->vbuf) {
svga_context_flush(svga, NULL);
svga_render->vbuf = pipe_buffer_create(screen,
- 16,
- PIPE_BUFFER_USAGE_VERTEX,
+ PIPE_BIND_VERTEX_BUFFER,
svga_render->vbuf_size);
assert(svga_render->vbuf);
}
{
struct svga_vbuf_render *svga_render = svga_vbuf_render(render);
struct svga_context *svga = svga_render->svga;
- struct pipe_screen *screen = svga->pipe.screen;
- char *ptr = (char*)pipe_buffer_map(screen,
+ char *ptr = (char*)pipe_buffer_map(&svga->pipe,
svga_render->vbuf,
- PIPE_BUFFER_USAGE_CPU_WRITE |
- PIPE_BUFFER_USAGE_FLUSH_EXPLICIT |
- PIPE_BUFFER_USAGE_DISCARD |
- PIPE_BUFFER_USAGE_UNSYNCHRONIZED);
+ PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_FLUSH_EXPLICIT |
+ PIPE_TRANSFER_DISCARD |
+ PIPE_TRANSFER_UNSYNCHRONIZED,
+ &svga_render->vbuf_transfer);
return ptr + svga_render->vbuf_offset;
}
{
struct svga_vbuf_render *svga_render = svga_vbuf_render(render);
struct svga_context *svga = svga_render->svga;
- struct pipe_screen *screen = svga->pipe.screen;
unsigned offset, length;
size_t used = svga_render->vertex_size * ((size_t)max_index + 1);
offset = svga_render->vbuf_offset + svga_render->vertex_size * min_index;
length = svga_render->vertex_size * (max_index + 1 - min_index);
- pipe_buffer_flush_mapped_range(screen, svga_render->vbuf, offset, length);
- pipe_buffer_unmap(screen, svga_render->vbuf);
+ pipe_buffer_flush_mapped_range(&svga->pipe,
+ svga_render->vbuf_transfer,
+ offset, length);
+ pipe_buffer_unmap(&svga->pipe, svga_render->vbuf, svga_render->vbuf_transfer);
svga_render->min_index = min_index;
svga_render->max_index = max_index;
svga_render->vbuf_used = MAX2(svga_render->vbuf_used, used);
assert(( svga_render->vbuf_offset - svga_render->vdecl_offset) % svga_render->vertex_size == 0);
if (svga_render->ibuf_size < svga_render->ibuf_offset + size)
- pipe_buffer_reference(&svga_render->ibuf, NULL);
+ pipe_resource_reference(&svga_render->ibuf, NULL);
if (!svga_render->ibuf) {
svga_render->ibuf_size = MAX2(size, svga_render->ibuf_alloc_size);
svga_render->ibuf = pipe_buffer_create(screen,
- 2,
- PIPE_BUFFER_USAGE_VERTEX,
+ PIPE_BIND_INDEX_BUFFER,
svga_render->ibuf_size);
svga_render->ibuf_offset = 0;
}
- pipe_buffer_write_nooverlap(screen, svga_render->ibuf,
- svga_render->ibuf_offset, 2 * nr_indices, indices);
+ pipe_buffer_write_nooverlap(&svga->pipe, svga_render->ibuf,
+ svga_render->ibuf_offset, 2 * nr_indices, indices);
/* off to hardware */
{
struct svga_vbuf_render *svga_render = svga_vbuf_render(render);
- pipe_buffer_reference(&svga_render->vbuf, NULL);
- pipe_buffer_reference(&svga_render->ibuf, NULL);
+ pipe_resource_reference(&svga_render->vbuf, NULL);
+ pipe_resource_reference(&svga_render->ibuf, NULL);
FREE(svga_render);
}
enum pipe_error
svga_swtnl_draw_range_elements(struct svga_context *svga,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned min_index,
unsigned max_index,
unsigned prim, unsigned start, unsigned count)
{
+ struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
+ struct pipe_transfer *ib_transfer;
+ struct pipe_transfer *cb_transfer;
struct draw_context *draw = svga->swtnl.draw;
unsigned i;
const void *map;
* Map vertex buffers
*/
for (i = 0; i < svga->curr.num_vertex_buffers; i++) {
- map = pipe_buffer_map(svga->pipe.screen,
+ map = pipe_buffer_map(&svga->pipe,
svga->curr.vb[i].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &vb_transfer[i]);
draw_set_mapped_vertex_buffer(draw, i, map);
}
/* Map index buffer, if present */
if (indexBuffer) {
- map = pipe_buffer_map(svga->pipe.screen, indexBuffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(&svga->pipe, indexBuffer,
+ PIPE_TRANSFER_READ,
+ &ib_transfer);
draw_set_mapped_element_buffer_range(draw,
indexSize,
}
if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
- map = pipe_buffer_map(svga->pipe.screen,
+ map = pipe_buffer_map(&svga->pipe,
svga->curr.cb[PIPE_SHADER_VERTEX],
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &cb_transfer);
assert(map);
draw_set_mapped_constant_buffer(
draw, PIPE_SHADER_VERTEX, 0,
map,
- svga->curr.cb[PIPE_SHADER_VERTEX]->size);
+ svga->curr.cb[PIPE_SHADER_VERTEX]->width0);
}
draw_arrays(svga->swtnl.draw, prim, start, count);
* unmap vertex/index buffers
*/
for (i = 0; i < svga->curr.num_vertex_buffers; i++) {
- pipe_buffer_unmap(svga->pipe.screen, svga->curr.vb[i].buffer);
+ pipe_buffer_unmap(&svga->pipe, svga->curr.vb[i].buffer,
+ vb_transfer[i]);
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
if (indexBuffer) {
- pipe_buffer_unmap(svga->pipe.screen, indexBuffer);
+ pipe_buffer_unmap(&svga->pipe, indexBuffer, ib_transfer);
draw_set_mapped_element_buffer(draw, 0, NULL);
}
if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
- pipe_buffer_unmap(svga->pipe.screen,
- svga->curr.cb[PIPE_SHADER_VERTEX]);
+ pipe_buffer_unmap(&svga->pipe,
+ svga->curr.cb[PIPE_SHADER_VERTEX],
+ cb_transfer);
}
return ret;
unsigned prim;
- struct pipe_buffer *vbuf;
- struct pipe_buffer *ibuf;
+ struct pipe_resource *vbuf;
+ struct pipe_resource *ibuf;
+ struct pipe_transfer *vbuf_transfer;
+ struct pipe_transfer *ibuf_transfer;
/* current size of buffer */
size_t vbuf_size;
struct pipe_screen;
struct pipe_context;
struct pipe_fence_handle;
-struct pipe_texture;
+struct pipe_resource;
struct svga_region;
struct winsys_handle;
-#define SVGA_BUFFER_USAGE_PINNED (PIPE_BUFFER_USAGE_CUSTOM << 0)
-#define SVGA_BUFFER_USAGE_WRAPPED (PIPE_BUFFER_USAGE_CUSTOM << 1)
+#define SVGA_BUFFER_USAGE_PINNED (1 << 0)
+#define SVGA_BUFFER_USAGE_WRAPPED (1 << 1)
+
+
+#define SVGA_RELOC_WRITE 0x1
+#define SVGA_RELOC_READ 0x2
+
/** Opaque surface handle */
/**
* Creates a surface from a winsys handle.
- * Used to implement pipe_screen::texture_from_handle.
+ * Used to implement pipe_screen::resource_from_handle.
*/
struct svga_winsys_surface *
(*surface_from_handle)(struct svga_winsys_screen *sws,
/**
* Get a winsys_handle from a surface.
- * Used to implement pipe_screen::texture_get_handle.
+ * Used to implement pipe_screen::resource_get_handle.
*/
boolean
(*surface_get_handle)(struct svga_winsys_screen *sws,
/**
* Buffer management. Buffer attributes are mostly fixed over its lifetime.
*
- * Remember that gallium gets to choose the interface it needs, and the
- * window systems must then implement that interface (rather than the
- * other way around...).
- *
- * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
- * usage argument is only an optimization hint, not a guarantee, therefore
- * proper behavior must be observed in all circumstances.
+ * XXX usage seems to be a bitmask of SVGA_BUFFER_USAGE_* flags.
*
* alignment indicates the client's alignment requirements, eg for
* SSE instructions.
/**
* Map the entire data store of a buffer object into the client's address.
* flags is a bitmask of:
- * - PIPE_BUFFER_USAGE_CPU_READ/WRITE
- * - PIPE_BUFFER_USAGE_DONTBLOCK
- * - PIPE_BUFFER_USAGE_UNSYNCHRONIZED
+ * - PB_USAGE_CPU_READ/WRITE
+ * - PB_USAGE_DONTBLOCK
+ * - PB_USAGE_UNSYNCHRONIZED
*/
void *
(*buffer_map)( struct svga_winsys_screen *sws,
struct svga_winsys_screen *
svga_winsys_screen(struct pipe_screen *screen);
-struct pipe_buffer *
+struct pipe_resource *
svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
enum SVGA3dSurfaceFormat format,
struct svga_winsys_surface *srf);
struct svga_winsys_surface *
-svga_screen_buffer_get_winsys_surface(struct pipe_buffer *buffer);
+svga_screen_buffer_get_winsys_surface(struct pipe_resource *buffer);
#endif /* SVGA_WINSYS_H_ */
LIBNAME = trace
C_SOURCES = \
- tr_buffer.c \
tr_context.c \
tr_dump.c \
tr_dump_state.c \
trace = env.ConvenienceLibrary(
target = 'trace',
source = [
- 'tr_buffer.c',
'tr_context.c',
'tr_drm.c',
'tr_dump.c',
+++ /dev/null
-/**************************************************************************
- *
- * 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 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.
- *
- **************************************************************************/
-
-
-#include "util/u_inlines.h"
-#include "util/u_memory.h"
-#include "util/u_simple_list.h"
-
-#include "tr_buffer.h"
-
-struct pipe_buffer *
-trace_buffer_create(struct trace_screen *tr_scr,
- struct pipe_buffer *buffer)
-{
- struct trace_buffer *tr_buf;
-
- if(!buffer)
- goto error;
-
- assert(buffer->screen == tr_scr->screen);
-
- tr_buf = CALLOC_STRUCT(trace_buffer);
- if(!tr_buf)
- goto error;
-
- memcpy(&tr_buf->base, buffer, sizeof(struct pipe_buffer));
-
- pipe_reference_init(&tr_buf->base.reference, 1);
- tr_buf->base.screen = &tr_scr->base;
- tr_buf->buffer = buffer;
-
- trace_screen_add_to_list(tr_scr, buffers, tr_buf);
-
- return &tr_buf->base;
-
-error:
- pipe_buffer_reference(&buffer, NULL);
- return NULL;
-}
-
-
-void
-trace_buffer_destroy(struct trace_screen *tr_scr,
- struct pipe_buffer *buffer)
-{
- struct trace_buffer *tr_buf = trace_buffer(buffer);
-
- trace_screen_remove_from_list(tr_scr, buffers, tr_buf);
-
- pipe_buffer_reference(&tr_buf->buffer, NULL);
- FREE(tr_buf);
-}
+++ /dev/null
-/**************************************************************************
- *
- * 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 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 TR_BUFFER_H_
-#define TR_BUFFER_H_
-
-
-#include "pipe/p_compiler.h"
-#include "pipe/p_state.h"
-
-#include "tr_screen.h"
-
-
-struct trace_buffer
-{
- struct pipe_buffer base;
-
- struct pipe_buffer *buffer;
-
- struct tr_list list;
-
- void *map;
- boolean range_flushed;
-};
-
-
-static INLINE struct trace_buffer *
-trace_buffer(struct pipe_buffer *buffer)
-{
- if(!buffer)
- return NULL;
- (void)trace_screen(buffer->screen);
- return (struct trace_buffer *)buffer;
-}
-
-
-struct pipe_buffer *
-trace_buffer_create(struct trace_screen *tr_scr,
- struct pipe_buffer *buffer);
-
-void
-trace_buffer_destroy(struct trace_screen *tr_scr,
- struct pipe_buffer *buffer);
-
-
-#endif
#include "tr_dump.h"
#include "tr_dump_state.h"
#include "tr_state.h"
-#include "tr_buffer.h"
#include "tr_screen.h"
#include "tr_texture.h"
-static INLINE struct pipe_buffer *
-trace_buffer_unwrap(struct trace_context *tr_ctx,
- struct pipe_buffer *buffer)
-{
- struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
- struct trace_buffer *tr_buf;
-
- if(!buffer)
- return NULL;
- tr_buf = trace_buffer(buffer);
- assert(tr_buf->buffer);
- assert(tr_buf->buffer->screen == tr_scr->screen);
- (void) tr_scr;
- return tr_buf->buffer;
-}
-
-static INLINE struct pipe_texture *
-trace_texture_unwrap(struct trace_context *tr_ctx,
- struct pipe_texture *texture)
+static INLINE struct pipe_resource *
+trace_resource_unwrap(struct trace_context *tr_ctx,
+ struct pipe_resource *resource)
{
- struct trace_texture *tr_tex;
+ struct trace_resource *tr_tex;
- if(!texture)
+ if(!resource)
return NULL;
- tr_tex = trace_texture(texture);
+ tr_tex = trace_resource(resource);
- assert(tr_tex->texture);
- return tr_tex->texture;
+ assert(tr_tex->resource);
+ return tr_tex->resource;
}
static INLINE void
trace_context_draw_elements(struct pipe_context *_pipe,
- struct pipe_buffer *_indexBuffer,
+ struct pipe_resource *_indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
struct trace_context *tr_ctx = trace_context(_pipe);
- struct trace_buffer *tr_buf = trace_buffer(_indexBuffer);
+ struct trace_resource *tr_buf = trace_resource(_indexBuffer);
struct pipe_context *pipe = tr_ctx->pipe;
- struct pipe_buffer *indexBuffer = tr_buf->buffer;
+ struct pipe_resource *indexBuffer = tr_buf->resource;
if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
return;
trace_context_draw_block(tr_ctx, 1);
- trace_screen_user_buffer_update(_pipe->screen, indexBuffer);
-
trace_dump_call_begin("pipe_context", "draw_elements");
trace_dump_arg(ptr, pipe);
static INLINE void
trace_context_draw_range_elements(struct pipe_context *_pipe,
- struct pipe_buffer *_indexBuffer,
+ struct pipe_resource *_indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
unsigned count)
{
struct trace_context *tr_ctx = trace_context(_pipe);
- struct trace_buffer *tr_buf = trace_buffer(_indexBuffer);
+ struct trace_resource *tr_buf = trace_resource(_indexBuffer);
struct pipe_context *pipe = tr_ctx->pipe;
- struct pipe_buffer *indexBuffer = tr_buf->buffer;
+ struct pipe_resource *indexBuffer = tr_buf->resource;
if (tr_ctx->curr.fs->disabled || tr_ctx->curr.vs->disabled)
return;
trace_context_draw_block(tr_ctx, 1);
- trace_screen_user_buffer_update(_pipe->screen, indexBuffer);
-
trace_dump_call_begin("pipe_context", "draw_range_elements");
trace_dump_arg(ptr, pipe);
static INLINE void
trace_context_set_constant_buffer(struct pipe_context *_pipe,
uint shader, uint index,
- struct pipe_buffer *buffer)
+ struct pipe_resource *buffer)
{
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
if (buffer) {
- trace_screen_user_buffer_update(_pipe->screen, buffer);
- buffer = trace_buffer_unwrap(tr_ctx, buffer);
+ buffer = trace_resource_unwrap(tr_ctx, buffer);
}
trace_dump_call_begin("pipe_context", "set_constant_buffer");
tr_ctx->curr.nr_cbufs = state->nr_cbufs;
for (i = 0; i < state->nr_cbufs; i++)
if (state->cbufs[i])
- tr_ctx->curr.cbufs[i] = trace_texture(state->cbufs[i]->texture);
+ tr_ctx->curr.cbufs[i] = trace_resource(state->cbufs[i]->texture);
else
tr_ctx->curr.cbufs[i] = NULL;
if (state->zsbuf)
- tr_ctx->curr.zsbuf = trace_texture(state->zsbuf->texture);
+ tr_ctx->curr.zsbuf = trace_resource(state->zsbuf->texture);
else
tr_ctx->curr.zsbuf = NULL;
}
static struct pipe_sampler_view *
trace_create_sampler_view(struct pipe_context *_pipe,
- struct pipe_texture *_texture,
+ struct pipe_resource *_resource,
const struct pipe_sampler_view *templ)
{
struct trace_context *tr_ctx = trace_context(_pipe);
- struct trace_texture *tr_tex = trace_texture(_texture);
+ struct trace_resource *tr_tex = trace_resource(_resource);
struct pipe_context *pipe = tr_ctx->pipe;
- struct pipe_texture *texture = tr_tex->texture;
+ struct pipe_resource *texture = tr_tex->resource;
struct trace_sampler_view *result = CALLOC_STRUCT(trace_sampler_view);
trace_dump_call_begin("pipe_context", "create_sampler_view");
result->base = *templ;
result->base.reference.count = 1;
result->base.texture = NULL;
- pipe_texture_reference(&result->base.texture, _texture);
+ pipe_resource_reference(&result->base.texture, _resource);
result->base.context = _pipe;
trace_dump_ret(ptr, result);
trace_dump_call_end();
- pipe_texture_reference(&_view->texture, NULL);
+ pipe_resource_reference(&_view->texture, NULL);
FREE(_view);
}
struct pipe_context *pipe = tr_ctx->pipe;
unsigned i;
- for(i = 0; i < num_buffers; ++i)
- trace_screen_user_buffer_update(_pipe->screen, buffers[i].buffer);
-
trace_dump_call_begin("pipe_context", "set_vertex_buffers");
trace_dump_arg(ptr, pipe);
struct pipe_vertex_buffer *_buffers = malloc(num_buffers * sizeof(*_buffers));
memcpy(_buffers, buffers, num_buffers * sizeof(*_buffers));
for (i = 0; i < num_buffers; i++)
- _buffers[i].buffer = trace_buffer_unwrap(tr_ctx, buffers[i].buffer);
+ _buffers[i].buffer = trace_resource_unwrap(tr_ctx, buffers[i].buffer);
pipe->set_vertex_buffers(pipe, num_buffers, _buffers);
free(_buffers);
} else {
}
static unsigned int
-trace_is_texture_referenced( struct pipe_context *_pipe,
- struct pipe_texture *_texture,
- unsigned face, unsigned level)
+trace_is_resource_referenced( struct pipe_context *_pipe,
+ struct pipe_resource *_resource,
+ unsigned face, unsigned level)
{
struct trace_context *tr_ctx = trace_context(_pipe);
- struct trace_texture *tr_tex = trace_texture(_texture);
+ struct trace_resource *tr_tex = trace_resource(_resource);
struct pipe_context *pipe = tr_ctx->pipe;
- struct pipe_texture *texture = tr_tex->texture;
+ struct pipe_resource *texture = tr_tex->resource;
unsigned int referenced;
- trace_dump_call_begin("pipe_context", "is_texture_referenced");
+ trace_dump_call_begin("pipe_context", "is_resource_referenced");
trace_dump_arg(ptr, pipe);
trace_dump_arg(ptr, texture);
trace_dump_arg(uint, face);
trace_dump_arg(uint, level);
- referenced = pipe->is_texture_referenced(pipe, texture, face, level);
-
- trace_dump_ret(uint, referenced);
- trace_dump_call_end();
-
- return referenced;
-}
-
-static unsigned int
-trace_is_buffer_referenced( struct pipe_context *_pipe,
- struct pipe_buffer *_buf)
-{
- struct trace_context *tr_ctx = trace_context(_pipe);
- struct trace_buffer *tr_buf = trace_buffer(_buf);
- struct pipe_context *pipe = tr_ctx->pipe;
- struct pipe_buffer *buf = tr_buf->buffer;
- unsigned int referenced;
-
- trace_dump_call_begin("pipe_context", "is_buffer_referenced");
- trace_dump_arg(ptr, pipe);
- trace_dump_arg(ptr, buf);
-
- referenced = pipe->is_buffer_referenced(pipe, buf);
+ referenced = pipe->is_resource_referenced(pipe, texture, face, level);
trace_dump_ret(uint, referenced);
trace_dump_call_end();
static struct pipe_transfer *
-trace_context_get_tex_transfer(struct pipe_context *_context,
- struct pipe_texture *_texture,
- unsigned face, unsigned level,
- unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y, unsigned w, unsigned h)
+trace_context_get_transfer(struct pipe_context *_context,
+ struct pipe_resource *_resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
{
struct trace_context *tr_context = trace_context(_context);
- struct trace_texture *tr_tex = trace_texture(_texture);
+ struct trace_resource *tr_tex = trace_resource(_resource);
struct pipe_context *context = tr_context->pipe;
- struct pipe_texture *texture = tr_tex->texture;
+ struct pipe_resource *texture = tr_tex->resource;
struct pipe_transfer *result = NULL;
assert(texture->screen == context->screen);
- trace_dump_call_begin("pipe_context", "get_tex_transfer");
+ trace_dump_call_begin("pipe_context", "get_transfer");
trace_dump_arg(ptr, context);
trace_dump_arg(ptr, texture);
- trace_dump_arg(uint, face);
- trace_dump_arg(uint, level);
- trace_dump_arg(uint, zslice);
+ trace_dump_arg(uint, sr.face);
+ trace_dump_arg(uint, sr.level);
trace_dump_arg(uint, usage);
+ trace_dump_arg(uint, box->x);
+ trace_dump_arg(uint, box->y);
+ trace_dump_arg(uint, box->z);
+ trace_dump_arg(uint, box->width);
+ trace_dump_arg(uint, box->height);
+ trace_dump_arg(uint, box->depth);
- trace_dump_arg(uint, x);
- trace_dump_arg(uint, y);
- trace_dump_arg(uint, w);
- trace_dump_arg(uint, h);
-
- result = context->get_tex_transfer(context, texture, face, level, zslice, usage,
- x, y, w, h);
+ result = context->get_transfer(context, texture, sr, usage, box);
trace_dump_ret(ptr, result);
static void
-trace_context_tex_transfer_destroy(struct pipe_context *_context,
+trace_context_transfer_destroy(struct pipe_context *_context,
struct pipe_transfer *_transfer)
{
struct trace_context *tr_context = trace_context(_context);
struct pipe_context *context = tr_context->pipe;
struct pipe_transfer *transfer = tr_trans->transfer;
- trace_dump_call_begin("pipe_context", "tex_transfer_destroy");
+ trace_dump_call_begin("pipe_context", "transfer_destroy");
trace_dump_arg(ptr, context);
trace_dump_arg(ptr, transfer);
}
+static void
+trace_context_transfer_flush_region( struct pipe_context *_context,
+ struct pipe_transfer *_transfer,
+ const struct pipe_box *box)
+{
+ struct trace_context *tr_context = trace_context(_context);
+ struct trace_transfer *tr_transfer = trace_transfer(_transfer);
+ struct pipe_context *context = tr_context->pipe;
+ struct pipe_transfer *transfer = tr_transfer->transfer;
+
+ trace_dump_call_begin("pipe_context", "transfer_flush_region");
+
+ trace_dump_arg(ptr, context);
+ trace_dump_arg(ptr, transfer);
+ trace_dump_arg(uint, box->x);
+ trace_dump_arg(uint, box->y);
+ trace_dump_arg(uint, box->z);
+ trace_dump_arg(uint, box->width);
+ trace_dump_arg(uint, box->height);
+ trace_dump_arg(uint, box->depth);
+ trace_dump_call_end();
+
+ context->transfer_flush_region(context,
+ transfer,
+ box);
+}
+
static void
trace_context_transfer_unmap(struct pipe_context *_context,
struct pipe_transfer *_transfer)
struct pipe_transfer *transfer = tr_trans->transfer;
if(tr_trans->map) {
- size_t size = util_format_get_nblocksy(transfer->texture->format, transfer->height) * transfer->stride;
-
trace_dump_call_begin("pipe_context", "transfer_write");
trace_dump_arg(ptr, context);
trace_dump_arg_end();
trace_dump_arg_begin("data");
- trace_dump_bytes(tr_trans->map, size);
+ trace_dump_box_bytes(tr_trans->map,
+ transfer->resource->format,
+ &transfer->box,
+ transfer->stride,
+ transfer->slice_stride);
trace_dump_arg_end();
- trace_dump_arg_begin("size");
- trace_dump_uint(size);
- trace_dump_arg_end();
+// trace_dump_arg_begin("size");
+// trace_dump_uint(size);
+// trace_dump_arg_end();
trace_dump_call_end();
context->transfer_unmap(context, transfer);
}
+
+static void
+trace_context_transfer_inline_write(struct pipe_context *_context,
+ struct pipe_resource *_resource,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned slice_stride)
+{
+ struct trace_context *tr_context = trace_context(_context);
+ struct trace_resource *tr_tex = trace_resource(_resource);
+ struct pipe_context *context = tr_context->pipe;
+ struct pipe_resource *resource = tr_tex->resource;
+
+ assert(resource->screen == context->screen);
+
+ trace_dump_call_begin("pipe_context", "transfer_inline_write");
+
+ trace_dump_arg(ptr, context);
+ trace_dump_arg(ptr, resource);
+ trace_dump_arg(uint, sr.face);
+ trace_dump_arg(uint, sr.level);
+ trace_dump_arg(uint, usage);
+ trace_dump_arg(uint, box->x);
+ trace_dump_arg(uint, box->y);
+ trace_dump_arg(uint, box->z);
+ trace_dump_arg(uint, box->width);
+ trace_dump_arg(uint, box->height);
+ trace_dump_arg(uint, box->depth);
+ trace_dump_arg(uint, stride);
+ trace_dump_arg(uint, slice_stride);
+
+ trace_dump_arg_begin("data");
+ trace_dump_box_bytes(data,
+ resource->format,
+ box,
+ stride,
+ slice_stride);
+ trace_dump_arg_end();
+
+ trace_dump_call_end();
+
+ context->transfer_inline_write(context, resource,
+ sr, usage, box, data, stride, slice_stride);
+}
+
+
+
+
static const struct debug_named_value rbug_blocker_flags[] = {
{"before", 1},
{"after", 2},
tr_ctx->base.surface_fill = trace_context_surface_fill;
tr_ctx->base.clear = trace_context_clear;
tr_ctx->base.flush = trace_context_flush;
- tr_ctx->base.is_texture_referenced = trace_is_texture_referenced;
- tr_ctx->base.is_buffer_referenced = trace_is_buffer_referenced;
+ tr_ctx->base.is_resource_referenced = trace_is_resource_referenced;
- tr_ctx->base.get_tex_transfer = trace_context_get_tex_transfer;
- tr_ctx->base.tex_transfer_destroy = trace_context_tex_transfer_destroy;
+ tr_ctx->base.get_transfer = trace_context_get_transfer;
+ tr_ctx->base.transfer_destroy = trace_context_transfer_destroy;
tr_ctx->base.transfer_map = trace_context_transfer_map;
tr_ctx->base.transfer_unmap = trace_context_transfer_unmap;
+ tr_ctx->base.transfer_flush_region = trace_context_transfer_flush_region;
+ tr_ctx->base.transfer_inline_write = trace_context_transfer_inline_write;
tr_ctx->pipe = pipe;
unsigned num_vert_sampler_views;
unsigned nr_cbufs;
- struct trace_texture *cbufs[PIPE_MAX_COLOR_BUFS];
- struct trace_texture *zsbuf;
+ struct trace_resource *cbufs[PIPE_MAX_COLOR_BUFS];
+ struct trace_resource *zsbuf;
} curr;
struct {
struct trace_shader *vs;
struct trace_sampler_view *sampler_view;
- struct trace_texture *surf;
+ struct trace_resource *surf;
int blocker;
} draw_rule;
#include "tr_dump.h"
#include "tr_screen.h"
#include "tr_texture.h"
-#include "tr_buffer.h"
static struct os_stream *stream = NULL;
trace_dump_writes("</bytes>");
}
+void trace_dump_box_bytes(const void *data,
+ unsigned format,
+ const struct pipe_box *box,
+ unsigned stride,
+ unsigned slice_stride)
+{
+ //size_t size = util_format_get_nblocksy(transfer->resource->format, transfer->box.height) * transfer->stride;
+
+}
+
void trace_dump_string(const char *str)
{
if (!dumping)
trace_dump_null();
}
-void trace_dump_buffer_ptr(struct pipe_buffer *_buffer)
-{
- if (!dumping)
- return;
-
- if (_buffer) {
- struct trace_buffer *tr_buf = trace_buffer(_buffer);
- trace_dump_ptr(tr_buf->buffer);
- } else {
- trace_dump_null();
- }
-}
-void trace_dump_texture_ptr(struct pipe_texture *_texture)
+void trace_dump_resource_ptr(struct pipe_resource *_resource)
{
if (!dumping)
return;
- if (_texture) {
- struct trace_texture *tr_tex = trace_texture(_texture);
- trace_dump_ptr(tr_tex->texture);
+ if (_resource) {
+ struct trace_resource *tr_resource = trace_resource(_resource);
+ trace_dump_ptr(tr_resource->resource);
} else {
trace_dump_null();
}
#include "pipe/p_compiler.h"
-
struct pipe_buffer;
-struct pipe_texture;
+struct pipe_resource;
struct pipe_surface;
struct pipe_transfer;
+struct pipe_box;
/*
* Call before use.
void trace_dump_uint(long long unsigned value);
void trace_dump_float(double value);
void trace_dump_bytes(const void *data, size_t size);
+void trace_dump_box_bytes(const void *data,
+ unsigned format,
+ const struct pipe_box *box,
+ unsigned stride,
+ unsigned slice_stride);
void trace_dump_string(const char *str);
void trace_dump_enum(const char *value);
void trace_dump_array_begin(void);
void trace_dump_null(void);
void trace_dump_ptr(const void *value);
/* will turn a wrapped object into the real one and dump ptr */
-void trace_dump_buffer_ptr(struct pipe_buffer *_buffer);
-void trace_dump_texture_ptr(struct pipe_texture *_texture);
+void trace_dump_resource_ptr(struct pipe_resource *_texture);
void trace_dump_surface_ptr(struct pipe_surface *_surface);
void trace_dump_transfer_ptr(struct pipe_transfer *_transfer);
}
-void trace_dump_template(const struct pipe_texture *templat)
+void trace_dump_template(const struct pipe_resource *templat)
{
if (!trace_dumping_enabled_locked())
return;
return;
}
- trace_dump_struct_begin("pipe_texture");
+ trace_dump_struct_begin("pipe_resource");
trace_dump_member(int, templat, target);
trace_dump_member(format, templat, format);
trace_dump_member_end();
trace_dump_member(uint, templat, last_level);
- trace_dump_member(uint, templat, tex_usage);
+ trace_dump_member(uint, templat, _usage);
+ trace_dump_member(uint, templat, bind);
+ trace_dump_member(uint, templat, flags);
trace_dump_struct_end();
}
trace_dump_struct_begin("pipe_transfer");
- trace_dump_member(uint, state, width);
- trace_dump_member(uint, state, height);
+ trace_dump_member(uint, state, box.width);
+ trace_dump_member(uint, state, box.height);
trace_dump_member(uint, state, stride);
trace_dump_member(uint, state, usage);
- trace_dump_member(ptr, state, texture);
- trace_dump_member(uint, state, face);
- trace_dump_member(uint, state, level);
- trace_dump_member(uint, state, zslice);
+ trace_dump_member(ptr, state, resource);
+ trace_dump_member(uint, state, sr.face);
+ trace_dump_member(uint, state, sr.level);
+ trace_dump_member(uint, state, box.z);
trace_dump_struct_end();
}
trace_dump_member(uint, state, stride);
trace_dump_member(uint, state, max_index);
trace_dump_member(uint, state, buffer_offset);
- trace_dump_member(buffer_ptr, state, buffer);
+ trace_dump_member(resource_ptr, state, buffer);
trace_dump_struct_end();
}
void trace_dump_format(enum pipe_format format);
-void trace_dump_template(const struct pipe_texture *templat);
+void trace_dump_template(const struct pipe_resource *templat);
void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state);
#include "os/os_thread.h"
#include "util/u_format.h"
#include "util/u_string.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
#include "util/u_simple_list.h"
#include "util/u_network.h"
#include "tr_dump.h"
#include "tr_state.h"
-#include "tr_buffer.h"
#include "tr_texture.h"
#include "rbug/rbug.h"
trace_rbug_texture_list(struct trace_rbug *tr_rbug, struct rbug_header *header, uint32_t serial)
{
struct trace_screen *tr_scr = tr_rbug->tr_scr;
- struct trace_texture *tr_tex = NULL;
+ struct trace_resource *tr_tex = NULL;
struct tr_list *ptr;
rbug_texture_t *texs;
int i = 0;
pipe_mutex_lock(tr_scr->list_mutex);
texs = MALLOC(tr_scr->num_textures * sizeof(rbug_texture_t));
foreach(ptr, &tr_scr->textures) {
- tr_tex = (struct trace_texture *)((char*)ptr - offsetof(struct trace_texture, list));
+ tr_tex = (struct trace_resource *)((char*)ptr - offsetof(struct trace_resource, list));
texs[i++] = VOID2U64(tr_tex);
}
pipe_mutex_unlock(tr_scr->list_mutex);
trace_rbug_texture_info(struct trace_rbug *tr_rbug, struct rbug_header *header, uint32_t serial)
{
struct trace_screen *tr_scr = tr_rbug->tr_scr;
- struct trace_texture *tr_tex = NULL;
+ struct trace_resource *tr_tex = NULL;
struct rbug_proto_texture_info *gpti = (struct rbug_proto_texture_info *)header;
struct tr_list *ptr;
- struct pipe_texture *t;
+ struct pipe_resource *t;
pipe_mutex_lock(tr_scr->list_mutex);
foreach(ptr, &tr_scr->textures) {
- tr_tex = (struct trace_texture *)((char*)ptr - offsetof(struct trace_texture, list));
+ tr_tex = (struct trace_resource *)((char*)ptr - offsetof(struct trace_resource, list));
if (gpti->texture == VOID2U64(tr_tex))
break;
tr_tex = NULL;
return -ESRCH;
}
- t = tr_tex->texture;
+ t = tr_tex->resource;
rbug_send_texture_info_reply(tr_rbug->con, serial,
t->target, t->format,
&t->width0, 1,
util_format_get_blocksize(t->format),
t->last_level,
t->nr_samples,
- t->tex_usage,
+ t->bind,
NULL);
pipe_mutex_unlock(tr_scr->list_mutex);
struct rbug_proto_texture_read *gptr = (struct rbug_proto_texture_read *)header;
struct trace_screen *tr_scr = tr_rbug->tr_scr;
- struct trace_texture *tr_tex = NULL;
+ struct trace_resource *tr_tex = NULL;
struct tr_list *ptr;
struct pipe_context *context = tr_scr->private_context;
- struct pipe_texture *tex;
+ struct pipe_resource *tex;
struct pipe_transfer *t;
void *map;
pipe_mutex_lock(tr_scr->list_mutex);
foreach(ptr, &tr_scr->textures) {
- tr_tex = (struct trace_texture *)((char*)ptr - offsetof(struct trace_texture, list));
+ tr_tex = (struct trace_resource *)((char*)ptr - offsetof(struct trace_resource, list));
if (gptr->texture == VOID2U64(tr_tex))
break;
tr_tex = NULL;
return -ESRCH;
}
- tex = tr_tex->texture;
- t = context->get_tex_transfer(context, tex,
+ tex = tr_tex->resource;
+ t = pipe_get_transfer(context, tex,
gptr->face, gptr->level, gptr->zslice,
PIPE_TRANSFER_READ,
gptr->x, gptr->y, gptr->w, gptr->h);
map = context->transfer_map(context, t);
rbug_send_texture_read_reply(tr_rbug->con, serial,
- t->texture->format,
- util_format_get_blockwidth(t->texture->format),
- util_format_get_blockheight(t->texture->format),
- util_format_get_blocksize(t->texture->format),
+ t->resource->format,
+ util_format_get_blockwidth(t->resource->format),
+ util_format_get_blockheight(t->resource->format),
+ util_format_get_blocksize(t->resource->format),
(uint8_t*)map,
- t->stride * util_format_get_nblocksy(t->texture->format, t->height),
+ t->stride * util_format_get_nblocksy(t->resource->format,
+ t->box.height),
t->stride,
NULL);
context->transfer_unmap(context, t);
- context->tex_transfer_destroy(context, t);
+ context->transfer_destroy(context, t);
pipe_mutex_unlock(tr_scr->list_mutex);
#include "util/u_memory.h"
#include "util/u_simple_list.h"
-#include "tr_buffer.h"
#include "tr_dump.h"
#include "tr_dump_state.h"
#include "tr_texture.h"
*/
-static struct pipe_texture *
-trace_screen_texture_create(struct pipe_screen *_screen,
- const struct pipe_texture *templat)
+static struct pipe_resource *
+trace_screen_resource_create(struct pipe_screen *_screen,
+ const struct pipe_resource *templat)
{
struct trace_screen *tr_scr = trace_screen(_screen);
struct pipe_screen *screen = tr_scr->screen;
- struct pipe_texture *result;
+ struct pipe_resource *result;
- trace_dump_call_begin("pipe_screen", "texture_create");
+ trace_dump_call_begin("pipe_screen", "resource_create");
trace_dump_arg(ptr, screen);
trace_dump_arg(template, templat);
- result = screen->texture_create(screen, templat);
+ result = screen->resource_create(screen, templat);
trace_dump_ret(ptr, result);
trace_dump_call_end();
- result = trace_texture_create(tr_scr, result);
+ result = trace_resource_create(tr_scr, result);
return result;
}
-static struct pipe_texture *
-trace_screen_texture_from_handle(struct pipe_screen *_screen,
- const struct pipe_texture *templ,
+static struct pipe_resource *
+trace_screen_resource_from_handle(struct pipe_screen *_screen,
+ const struct pipe_resource *templ,
struct winsys_handle *handle)
{
struct trace_screen *tr_screen = trace_screen(_screen);
struct pipe_screen *screen = tr_screen->screen;
- struct pipe_texture *result;
+ struct pipe_resource *result;
/* TODO trace call */
- result = screen->texture_from_handle(screen, templ, handle);
+ result = screen->resource_from_handle(screen, templ, handle);
- result = trace_texture_create(trace_screen(_screen), result);
+ result = trace_resource_create(trace_screen(_screen), result);
return result;
}
static boolean
-trace_screen_texture_get_handle(struct pipe_screen *_screen,
- struct pipe_texture *_texture,
+trace_screen_resource_get_handle(struct pipe_screen *_screen,
+ struct pipe_resource *_texture,
struct winsys_handle *handle)
{
struct trace_screen *tr_screen = trace_screen(_screen);
- struct trace_texture *tr_texture = trace_texture(_texture);
+ struct trace_resource *tr_texture = trace_resource(_texture);
struct pipe_screen *screen = tr_screen->screen;
- struct pipe_texture *texture = tr_texture->texture;
+ struct pipe_resource *texture = tr_texture->resource;
/* TODO trace call */
- return screen->texture_get_handle(screen, texture, handle);
+ return screen->resource_get_handle(screen, texture, handle);
}
static void
-trace_screen_texture_destroy(struct pipe_texture *_texture)
+trace_screen_resource_destroy(struct pipe_screen *_screen,
+ struct pipe_resource *_texture)
{
- struct trace_screen *tr_scr = trace_screen(_texture->screen);
- struct trace_texture *tr_tex = trace_texture(_texture);
+ struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_resource *tr_tex = trace_resource(_texture);
struct pipe_screen *screen = tr_scr->screen;
- struct pipe_texture *texture = tr_tex->texture;
+ struct pipe_resource *texture = tr_tex->resource;
assert(texture->screen == screen);
trace_dump_call_end();
- trace_texture_destroy(tr_tex);
+ trace_resource_destroy(tr_scr, tr_tex);
}
static struct pipe_surface *
trace_screen_get_tex_surface(struct pipe_screen *_screen,
- struct pipe_texture *_texture,
+ struct pipe_resource *_texture,
unsigned face, unsigned level,
unsigned zslice,
unsigned usage)
{
struct trace_screen *tr_scr = trace_screen(_screen);
- struct trace_texture *tr_tex = trace_texture(_texture);
+ struct trace_resource *tr_tex = trace_resource(_texture);
struct pipe_screen *screen = tr_scr->screen;
- struct pipe_texture *texture = tr_tex->texture;
+ struct pipe_resource *texture = tr_tex->resource;
struct pipe_surface *result = NULL;
assert(texture->screen == screen);
-
-
-static struct pipe_buffer *
-trace_screen_buffer_create(struct pipe_screen *_screen,
- unsigned alignment,
- unsigned usage,
- unsigned size)
-{
- struct trace_screen *tr_scr = trace_screen(_screen);
- struct pipe_screen *screen = tr_scr->screen;
- struct pipe_buffer *result;
-
- trace_dump_call_begin("pipe_screen", "buffer_create");
-
- trace_dump_arg(ptr, screen);
- trace_dump_arg(uint, alignment);
- trace_dump_arg(uint, usage);
- trace_dump_arg(uint, size);
-
- result = screen->buffer_create(screen, alignment, usage, size);
-
- trace_dump_ret(ptr, result);
-
- trace_dump_call_end();
-
- /* Zero the buffer to avoid dumping uninitialized memory */
- if(result->usage & PIPE_BUFFER_USAGE_CPU_WRITE) {
- void *map;
- map = pipe_buffer_map(screen, result, PIPE_BUFFER_USAGE_CPU_WRITE);
- if(map) {
- memset(map, 0, result->size);
- screen->buffer_unmap(screen, result);
- }
- }
-
- return trace_buffer_create(tr_scr, result);
-}
-
-
-static struct pipe_buffer *
+static struct pipe_resource *
trace_screen_user_buffer_create(struct pipe_screen *_screen,
void *data,
- unsigned size)
+ unsigned size,
+ unsigned usage)
{
struct trace_screen *tr_scr = trace_screen(_screen);
struct pipe_screen *screen = tr_scr->screen;
- struct pipe_buffer *result;
+ struct pipe_resource *result;
trace_dump_call_begin("pipe_screen", "user_buffer_create");
trace_dump_bytes(data, size);
trace_dump_arg_end();
trace_dump_arg(uint, size);
+ trace_dump_arg(uint, usage);
- result = screen->user_buffer_create(screen, data, size);
+ result = screen->user_buffer_create(screen, data, size, usage);
trace_dump_ret(ptr, result);
trace_dump_call_end();
if(result) {
- assert(!(result->usage & TRACE_BUFFER_USAGE_USER));
- result->usage |= TRACE_BUFFER_USAGE_USER;
- }
-
- return trace_buffer_create(tr_scr, result);
-}
-
-
-/**
- * This function is used to track if data has been changed on a user buffer
- * without map/unmap being called.
- */
-void
-trace_screen_user_buffer_update(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer)
-{
-#if 0
- struct trace_screen *tr_scr = trace_screen(_screen);
- struct pipe_screen *screen = tr_scr->screen;
- const void *map;
-
- if(buffer && buffer->usage & TRACE_BUFFER_USAGE_USER) {
- map = screen->buffer_map(screen, buffer, PIPE_BUFFER_USAGE_CPU_READ);
- if(map) {
- trace_dump_call_begin("pipe_winsys", "buffer_write");
-
- trace_dump_arg(ptr, screen);
-
- trace_dump_arg(ptr, buffer);
-
- trace_dump_arg_begin("data");
- trace_dump_bytes(map, buffer->size);
- trace_dump_arg_end();
-
- trace_dump_arg_begin("size");
- trace_dump_uint(buffer->size);
- trace_dump_arg_end();
-
- trace_dump_call_end();
-
- screen->buffer_unmap(screen, buffer);
- }
- }
-#endif
-}
-
-
-static void *
-trace_screen_buffer_map(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer,
- unsigned usage)
-{
- struct trace_screen *tr_scr = trace_screen(_screen);
- struct trace_buffer *tr_buf = trace_buffer(_buffer);
- struct pipe_screen *screen = tr_scr->screen;
- struct pipe_buffer *buffer = tr_buf->buffer;
- void *map;
-
- assert(screen->buffer_map);
- map = screen->buffer_map(screen, buffer, usage);
- if(map) {
- if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) {
- tr_buf->map = map;
- }
- }
-
- return map;
-}
-
-
-static void *
-trace_screen_buffer_map_range(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer,
- unsigned offset,
- unsigned length,
- unsigned usage)
-{
- struct trace_screen *tr_scr = trace_screen(_screen);
- struct trace_buffer *tr_buf = trace_buffer(_buffer);
- struct pipe_screen *screen = tr_scr->screen;
- struct pipe_buffer *buffer = tr_buf->buffer;
- void *map;
-
- assert(screen->buffer_map_range);
- map = screen->buffer_map_range(screen, buffer, offset, length, usage);
- if(map) {
- if(usage & PIPE_BUFFER_USAGE_CPU_WRITE) {
- tr_buf->map = map;
- }
+ assert(!(result->flags & TRACE_FLAG_USER_BUFFER));
+ result->flags |= TRACE_FLAG_USER_BUFFER;
}
- return map;
-}
-
-
-static void
-buffer_write(struct pipe_screen *screen,
- struct pipe_buffer *buffer,
- unsigned offset,
- const char *map,
- unsigned size)
-{
- assert(map);
-
- trace_dump_call_begin("pipe_screen", "buffer_write");
-
- trace_dump_arg(ptr, screen);
-
- trace_dump_arg(ptr, buffer);
-
- trace_dump_arg(uint, offset);
-
- trace_dump_arg_begin("data");
- trace_dump_bytes(map + offset, size);
- trace_dump_arg_end();
-
- trace_dump_arg(uint, size);
-
- trace_dump_call_end();
-
-}
-
-
-static void
-trace_screen_buffer_flush_mapped_range(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer,
- unsigned offset,
- unsigned length)
-{
- struct trace_screen *tr_scr = trace_screen(_screen);
- struct trace_buffer *tr_buf = trace_buffer(_buffer);
- struct pipe_screen *screen = tr_scr->screen;
- struct pipe_buffer *buffer = tr_buf->buffer;
-
- assert(tr_buf->map);
- buffer_write(screen, buffer, offset, tr_buf->map, length);
- tr_buf->range_flushed = TRUE;
- screen->buffer_flush_mapped_range(screen, buffer, offset, length);
+ return trace_resource_create(tr_scr, result);
}
-static void
-trace_screen_buffer_unmap(struct pipe_screen *_screen,
- struct pipe_buffer *_buffer)
-{
- struct trace_screen *tr_scr = trace_screen(_screen);
- struct trace_buffer *tr_buf = trace_buffer(_buffer);
- struct pipe_screen *screen = tr_scr->screen;
- struct pipe_buffer *buffer = tr_buf->buffer;
-
- if (tr_buf->map && !tr_buf->range_flushed)
- buffer_write(screen, buffer, 0, tr_buf->map, buffer->size);
- tr_buf->map = NULL;
- tr_buf->range_flushed = FALSE;
- screen->buffer_unmap(screen, buffer);
-}
-
-
-static void
-trace_screen_buffer_destroy(struct pipe_buffer *_buffer)
-{
- struct trace_screen *tr_scr = trace_screen(_buffer->screen);
- struct trace_buffer *tr_buf = trace_buffer(_buffer);
- struct pipe_screen *screen = tr_scr->screen;
- struct pipe_buffer *buffer = tr_buf->buffer;
-
- trace_dump_call_begin("pipe_screen", "buffer_destroy");
-
- trace_dump_arg(ptr, screen);
- trace_dump_arg(ptr, buffer);
-
- trace_dump_call_end();
-
- trace_buffer_destroy(tr_scr, _buffer);
-}
/********************************************************************
tr_scr->base.is_format_supported = trace_screen_is_format_supported;
assert(screen->context_create);
tr_scr->base.context_create = trace_screen_context_create;
- tr_scr->base.texture_create = trace_screen_texture_create;
- tr_scr->base.texture_from_handle = trace_screen_texture_from_handle;
- tr_scr->base.texture_get_handle = trace_screen_texture_get_handle;
- tr_scr->base.texture_destroy = trace_screen_texture_destroy;
+ tr_scr->base.resource_create = trace_screen_resource_create;
+ tr_scr->base.resource_from_handle = trace_screen_resource_from_handle;
+ tr_scr->base.resource_get_handle = trace_screen_resource_get_handle;
+ tr_scr->base.resource_destroy = trace_screen_resource_destroy;
tr_scr->base.get_tex_surface = trace_screen_get_tex_surface;
tr_scr->base.tex_surface_destroy = trace_screen_tex_surface_destroy;
- tr_scr->base.buffer_create = trace_screen_buffer_create;
tr_scr->base.user_buffer_create = trace_screen_user_buffer_create;
- if (screen->buffer_map)
- tr_scr->base.buffer_map = trace_screen_buffer_map;
- if (screen->buffer_map_range)
- tr_scr->base.buffer_map_range = trace_screen_buffer_map_range;
- if (screen->buffer_flush_mapped_range)
- tr_scr->base.buffer_flush_mapped_range = trace_screen_buffer_flush_mapped_range;
- if (screen->buffer_unmap)
- tr_scr->base.buffer_unmap = trace_screen_buffer_unmap;
- tr_scr->base.buffer_destroy = trace_screen_buffer_destroy;
tr_scr->base.fence_reference = trace_screen_fence_reference;
tr_scr->base.fence_signalled = trace_screen_fence_signalled;
tr_scr->base.fence_finish = trace_screen_fence_finish;
* without mapping/unmapping. This flag marks user buffers, so that their
* contents can be dumpped before being used by the pipe context.
*/
-#define TRACE_BUFFER_USAGE_USER (1 << 31)
+#define TRACE_FLAG_USER_BUFFER (1 << 31)
struct trace_screen
struct trace_screen *
trace_screen(struct pipe_screen *screen);
-void
-trace_screen_user_buffer_update(struct pipe_screen *screen,
- struct pipe_buffer *buffer);
-
#define trace_screen_add_to_list(tr_scr, name, obj) \
do { \
pipe_mutex_lock(tr_scr->list_mutex); \
#include "tr_texture.h"
-struct pipe_texture *
-trace_texture_create(struct trace_screen *tr_scr,
- struct pipe_texture *texture)
+struct pipe_resource *
+trace_resource_create(struct trace_screen *tr_scr,
+ struct pipe_resource *texture)
{
- struct trace_texture *tr_tex;
+ struct trace_resource *tr_tex;
if(!texture)
goto error;
assert(texture->screen == tr_scr->screen);
- tr_tex = CALLOC_STRUCT(trace_texture);
+ tr_tex = CALLOC_STRUCT(trace_resource);
if(!tr_tex)
goto error;
- memcpy(&tr_tex->base, texture, sizeof(struct pipe_texture));
+ memcpy(&tr_tex->base, texture, sizeof(struct pipe_resource));
pipe_reference_init(&tr_tex->base.reference, 1);
tr_tex->base.screen = &tr_scr->base;
- tr_tex->texture = texture;
+ tr_tex->resource = texture;
trace_screen_add_to_list(tr_scr, textures, tr_tex);
return &tr_tex->base;
error:
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&texture, NULL);
return NULL;
}
void
-trace_texture_destroy(struct trace_texture *tr_tex)
+trace_resource_destroy(struct trace_screen *tr_scr,
+ struct trace_resource *tr_tex)
{
- struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
-
trace_screen_remove_from_list(tr_scr, textures, tr_tex);
- pipe_texture_reference(&tr_tex->texture, NULL);
+ pipe_resource_reference(&tr_tex->resource, NULL);
FREE(tr_tex);
}
struct pipe_surface *
-trace_surface_create(struct trace_texture *tr_tex,
+trace_surface_create(struct trace_resource *tr_tex,
struct pipe_surface *surface)
{
struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
if(!surface)
goto error;
- assert(surface->texture == tr_tex->texture);
+ assert(surface->texture == tr_tex->resource);
tr_surf = CALLOC_STRUCT(trace_surface);
if(!tr_surf)
pipe_reference_init(&tr_surf->base.reference, 1);
tr_surf->base.texture = NULL;
- pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base);
+ pipe_resource_reference(&tr_surf->base.texture, &tr_tex->base);
tr_surf->surface = surface;
trace_screen_add_to_list(tr_scr, surfaces, tr_surf);
trace_screen_remove_from_list(tr_scr, surfaces, tr_surf);
- pipe_texture_reference(&tr_surf->base.texture, NULL);
+ pipe_resource_reference(&tr_surf->base.texture, NULL);
pipe_surface_reference(&tr_surf->surface, NULL);
FREE(tr_surf);
}
struct pipe_transfer *
trace_transfer_create(struct trace_context *tr_ctx,
- struct trace_texture *tr_tex,
+ struct trace_resource *tr_tex,
struct pipe_transfer *transfer)
{
struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
if(!transfer)
goto error;
- assert(transfer->texture == tr_tex->texture);
+ assert(transfer->resource == tr_tex->resource);
tr_trans = CALLOC_STRUCT(trace_transfer);
if(!tr_trans)
memcpy(&tr_trans->base, transfer, sizeof(struct pipe_transfer));
- tr_trans->base.texture = NULL;
+ tr_trans->base.resource = NULL;
tr_trans->transfer = transfer;
- pipe_texture_reference(&tr_trans->base.texture, &tr_tex->base);
- assert(tr_trans->base.texture == &tr_tex->base);
+ pipe_resource_reference(&tr_trans->base.resource, &tr_tex->base);
+ assert(tr_trans->base.resource == &tr_tex->base);
trace_screen_add_to_list(tr_scr, transfers, tr_trans);
return &tr_trans->base;
error:
- tr_ctx->pipe->tex_transfer_destroy(tr_ctx->pipe, transfer);
+ tr_ctx->pipe->transfer_destroy(tr_ctx->pipe, transfer);
return NULL;
}
trace_screen_remove_from_list(tr_scr, transfers, tr_trans);
- pipe_texture_reference(&tr_trans->base.texture, NULL);
- context->tex_transfer_destroy(context, transfer);
+ pipe_resource_reference(&tr_trans->base.resource, NULL);
+ context->transfer_destroy(context, transfer);
FREE(tr_trans);
}
struct trace_context;
-struct trace_texture
+struct trace_resource
{
- struct pipe_texture base;
+ struct pipe_resource base;
- struct pipe_texture *texture;
+ struct pipe_resource *resource;
struct tr_list list;
};
};
-static INLINE struct trace_texture *
-trace_texture(struct pipe_texture *texture)
+static INLINE struct trace_resource *
+trace_resource(struct pipe_resource *texture)
{
if(!texture)
return NULL;
(void)trace_screen(texture->screen);
- return (struct trace_texture *)texture;
+ return (struct trace_resource *)texture;
}
{
if(!surface)
return NULL;
- (void)trace_texture(surface->texture);
+ (void)trace_resource(surface->texture);
return (struct trace_surface *)surface;
}
{
if(!transfer)
return NULL;
- (void)trace_texture(transfer->texture);
+ (void)trace_resource(transfer->resource);
return (struct trace_transfer *)transfer;
}
-struct pipe_texture *
-trace_texture_create(struct trace_screen *tr_scr,
- struct pipe_texture *texture);
+struct pipe_resource *
+trace_resource_create(struct trace_screen *tr_scr,
+ struct pipe_resource *texture);
void
-trace_texture_destroy(struct trace_texture *tr_tex);
+trace_resource_destroy(struct trace_screen *tr_scr,
+ struct trace_resource *tr_tex);
struct pipe_surface *
-trace_surface_create(struct trace_texture *tr_tex,
+trace_surface_create(struct trace_resource *tr_tex,
struct pipe_surface *surface);
void
struct pipe_transfer *
trace_transfer_create(struct trace_context *tr_ctx,
- struct trace_texture *tr_tex,
+ struct trace_resource *tr_tex,
struct pipe_transfer *transfer);
void
unsigned mode, unsigned start, unsigned count);
void (*draw_elements)( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count);
unsigned instanceCount);
void (*draw_elements_instanced)(struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode,
unsigned start,
* module.
*/
void (*draw_range_elements)( struct pipe_context *pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
void (*set_constant_buffer)( struct pipe_context *,
uint shader, uint index,
- struct pipe_buffer *buf );
+ struct pipe_resource *buf );
void (*set_framebuffer_state)( struct pipe_context *,
const struct pipe_framebuffer_state * );
* \param level mipmap level.
* \return mask of PIPE_REFERENCED_FOR_READ/WRITE or PIPE_UNREFERENCED
*/
- unsigned int (*is_texture_referenced)(struct pipe_context *pipe,
- struct pipe_texture *texture,
- unsigned face, unsigned level);
-
- /**
- * Check whether a buffer is referenced by an unflushed hw command.
- * The state-tracker uses this function to avoid unnecessary flushes.
- * It is safe (but wasteful) to always return
- * PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE.
- * \param pipe context whose unflushed hw commands will be checked.
- * \param buf buffer to check.
- * \return mask of PIPE_REFERENCED_FOR_READ/WRITE or PIPE_UNREFERENCED
- */
- unsigned int (*is_buffer_referenced)(struct pipe_context *pipe,
- struct pipe_buffer *buf);
+ unsigned int (*is_resource_referenced)(struct pipe_context *pipe,
+ struct pipe_resource *texture,
+ unsigned face, unsigned level);
/**
* Create a view on a texture to be used by a shader stage.
*/
struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
const struct pipe_sampler_view *templat);
void (*sampler_view_destroy)(struct pipe_context *ctx,
* Transfers are (by default) context-private and allow uploads to be
* interleaved with
*/
- struct pipe_transfer *(*get_tex_transfer)(struct pipe_context *,
- struct pipe_texture *texture,
- unsigned face, unsigned level,
- unsigned zslice,
- enum pipe_transfer_usage usage,
- unsigned x, unsigned y,
- unsigned w, unsigned h);
-
- void (*tex_transfer_destroy)(struct pipe_context *,
+ struct pipe_transfer *(*get_transfer)(struct pipe_context *,
+ struct pipe_resource *resource,
+ struct pipe_subresource,
+ unsigned usage, /* a combination of PIPE_TRANSFER_x */
+ const struct pipe_box *);
+
+ void (*transfer_destroy)(struct pipe_context *,
struct pipe_transfer *);
void *(*transfer_map)( struct pipe_context *,
struct pipe_transfer *transfer );
+ /* If transfer was created with WRITE|FLUSH_EXPLICIT, only the
+ * regions specified with this call are guaranteed to be written to
+ * the resource.
+ */
+ 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 );
+ /* One-shot transfer operation with data supplied in a user
+ * pointer. XXX: strides??
+ */
+ void (*transfer_inline_write)( struct pipe_context *,
+ struct pipe_resource *,
+ struct pipe_subresource,
+ unsigned usage, /* a combination of PIPE_TRANSFER_x */
+ const struct pipe_box *,
+ const void *data,
+ unsigned stride,
+ unsigned slice_stride);
+
};
/** Texture types */
enum pipe_texture_target {
- PIPE_TEXTURE_1D = 0,
- PIPE_TEXTURE_2D = 1,
- PIPE_TEXTURE_3D = 2,
- PIPE_TEXTURE_CUBE = 3,
+ PIPE_BUFFER = 0,
+ PIPE_TEXTURE_1D = 1,
+ PIPE_TEXTURE_2D = 2,
+ PIPE_TEXTURE_3D = 3,
+ PIPE_TEXTURE_CUBE = 4,
PIPE_MAX_TEXTURE_TYPES
};
#define PIPE_TEX_COMPARE_NONE 0
#define PIPE_TEX_COMPARE_R_TO_TEXTURE 1
-#define PIPE_TEXTURE_USAGE_RENDER_TARGET 0x1
-#define PIPE_TEXTURE_USAGE_DISPLAY_TARGET 0x2 /* windows presentable buffer, ie a backbuffer */
-#define PIPE_TEXTURE_USAGE_SCANOUT 0x4 /* ie a frontbuffer */
-#define PIPE_TEXTURE_USAGE_DEPTH_STENCIL 0x8
-#define PIPE_TEXTURE_USAGE_SAMPLER 0x10
-#define PIPE_TEXTURE_USAGE_DYNAMIC 0x20
-#define PIPE_TEXTURE_USAGE_SHARED 0x40
-/** Pipe driver custom usage flags should be greater or equal to this value */
-#define PIPE_TEXTURE_USAGE_CUSTOM (1 << 16)
-
-#define PIPE_TEXTURE_GEOM_NON_SQUARE 0x1
-#define PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO 0x2
-
/**
- * Surface layout
+ * Surface layout -- a hint? Or some driver-internal poking out into
+ * the interface?
*/
#define PIPE_SURFACE_LAYOUT_LINEAR 0
* Transfer object usage flags
*/
enum pipe_transfer_usage {
+ /**
+ * Resource contents read back (or accessed directly) at transfer
+ * create time.
+ */
PIPE_TRANSFER_READ = (1 << 0),
+
+ /**
+ * Resource contents will be written back at transfer_destroy
+ * time (or modified as a result of being accessed directly).
+ */
PIPE_TRANSFER_WRITE = (1 << 1),
- /** Read/modify/write */
+
+ /**
+ * Read/modify/write
+ */
PIPE_TRANSFER_READ_WRITE = PIPE_TRANSFER_READ | PIPE_TRANSFER_WRITE,
+
/**
* The transfer should map the texture storage directly. The driver may
* return NULL if that isn't possible, and the state tracker needs to cope
* does read/modify/write cycles on them directly, and a more complicated
* path which uses minimal read and write transfers.
*/
- PIPE_TRANSFER_MAP_DIRECTLY = (1 << 2)
-};
+ PIPE_TRANSFER_MAP_DIRECTLY = (1 << 2),
+
+ /**
+ * Discards the memory within the mapped region.
+ *
+ * It should not be used with PIPE_TRANSFER_CPU_READ.
+ *
+ * See also:
+ * - OpenGL's ARB_map_buffer_range extension, MAP_INVALIDATE_RANGE_BIT flag.
+ * - Direct3D's D3DLOCK_DISCARD flag.
+ */
+ PIPE_TRANSFER_DISCARD = (1 << 8),
+ /**
+ * Fail if the resource cannot be mapped immediately.
+ *
+ * See also:
+ * - Direct3D's D3DLOCK_DONOTWAIT flag.
+ * - Mesa3D's MESA_MAP_NOWAIT_BIT flag.
+ * - WDDM's D3DDDICB_LOCKFLAGS.DonotWait flag.
+ */
+ PIPE_TRANSFER_DONTBLOCK = (1 << 9),
-/*
- * Buffer usage flags
- */
+ /**
+ * Do not attempt to synchronize pending operations on the resource when mapping.
+ *
+ * It should not be used with PIPE_TRANSFER_CPU_READ.
+ *
+ * See also:
+ * - OpenGL's ARB_map_buffer_range extension, MAP_UNSYNCHRONIZED_BIT flag.
+ * - Direct3D's D3DLOCK_NOOVERWRITE flag.
+ * - WDDM's D3DDDICB_LOCKFLAGS.IgnoreSync flag.
+ */
+ PIPE_TRANSFER_UNSYNCHRONIZED = (1 << 10),
+ PIPE_TRANSFER_NOOVERWRITE = (1 << 10), /* are these really the same?? */
+
+ /**
+ * Written ranges will be notified later with
+ * pipe_context::transfer_flush_region.
+ *
+ * It should not be used with PIPE_TRANSFER_CPU_READ.
+ *
+ * See also:
+ * - pipe_context::transfer_flush_region
+ * - OpenGL's ARB_map_buffer_range extension, MAP_FLUSH_EXPLICIT_BIT flag.
+ */
+ PIPE_TRANSFER_FLUSH_EXPLICIT = (1 << 11),
+
+};
-#define PIPE_BUFFER_USAGE_CPU_READ (1 << 0)
-#define PIPE_BUFFER_USAGE_CPU_WRITE (1 << 1)
-#define PIPE_BUFFER_USAGE_GPU_READ (1 << 2)
-#define PIPE_BUFFER_USAGE_GPU_WRITE (1 << 3)
-#define PIPE_BUFFER_USAGE_PIXEL (1 << 4)
-#define PIPE_BUFFER_USAGE_VERTEX (1 << 5)
-#define PIPE_BUFFER_USAGE_INDEX (1 << 6)
-#define PIPE_BUFFER_USAGE_CONSTANT (1 << 7)
/*
- * CPU access flags.
- *
- * These flags should only be used for texture transfers or when mapping
- * buffers.
- *
- * Note that the PIPE_BUFFER_USAGE_CPU_xxx flags above are also used for
- * mapping. Either PIPE_BUFFER_USAGE_CPU_READ or PIPE_BUFFER_USAGE_CPU_WRITE
- * must be set.
+ * Resource binding flags -- state tracker must specify in advance all
+ * the ways a resource might be used.
*/
-
-/**
- * Discards the memory within the mapped region.
+#define PIPE_BIND_DEPTH_STENCIL (1 << 0) /* get_tex_surface */
+#define PIPE_BIND_RENDER_TARGET (1 << 1) /* get_tex_surface */
+#define PIPE_BIND_SAMPLER_VIEW (1 << 2) /* get_sampler_view */
+#define PIPE_BIND_VERTEX_BUFFER (1 << 3) /* set_vertex_buffers */
+#define PIPE_BIND_INDEX_BUFFER (1 << 4) /* draw_elements */
+#define PIPE_BIND_CONSTANT_BUFFER (1 << 5) /* set_constant_buffer */
+#define PIPE_BIND_BLIT_SOURCE (1 << 6) /* surface_copy */
+#define PIPE_BIND_BLIT_DESTINATION (1 << 7) /* surface_copy, fill */
+#define PIPE_BIND_DISPLAY_TARGET (1 << 8) /* flush_front_buffer */
+#define PIPE_BIND_TRANSFER_WRITE (1 << 9) /* get_transfer */
+#define PIPE_BIND_TRANSFER_READ (1 << 10) /* get_transfer */
+#define PIPE_BIND_CUSTOM (1 << 16) /* state-tracker/winsys usages */
+
+/* The first two flags were previously part of the amorphous
+ * TEXTURE_USAGE, most of which are now descriptions of the ways a
+ * particular texture can be bound to the gallium pipeline. These two
+ * do not fit within that and probably need to be migrated to some
+ * other place.
*
- * It should not be used with PIPE_BUFFER_USAGE_CPU_READ.
+ * It seems like scanout is used by the Xorg state tracker to ask for
+ * a texture suitable for actual scanout (hence the name), which
+ * implies extra layout constraints on some hardware. It may also
+ * have some special meaning regarding mouse cursor images.
*
- * See also:
- * - OpenGL's ARB_map_buffer_range extension, MAP_INVALIDATE_RANGE_BIT flag.
- * - Direct3D's D3DLOCK_DISCARD flag.
+ * The shared flag is quite underspecified, but certainly isn't a
+ * binding flag - it seems more like a message to the winsys to create
+ * a shareable allocation. Could it mean that this texture is a valid argument for
*/
-#define PIPE_BUFFER_USAGE_DISCARD (1 << 8)
+#define PIPE_BIND_SCANOUT (1 << 14) /* */
+#define PIPE_BIND_SHARED (1 << 15) /* get_texture_handle ??? */
-/**
- * Fail if the resource cannot be mapped immediately.
- *
- * See also:
- * - Direct3D's D3DLOCK_DONOTWAIT flag.
- * - Mesa3D's MESA_MAP_NOWAIT_BIT flag.
- * - WDDM's D3DDDICB_LOCKFLAGS.DonotWait flag.
- */
-#define PIPE_BUFFER_USAGE_DONTBLOCK (1 << 9)
-/**
- * Do not attempt to synchronize pending operations on the resource when mapping.
- *
- * It should not be used with PIPE_BUFFER_USAGE_CPU_READ.
- *
- * See also:
- * - OpenGL's ARB_map_buffer_range extension, MAP_UNSYNCHRONIZED_BIT flag.
- * - Direct3D's D3DLOCK_NOOVERWRITE flag.
- * - WDDM's D3DDDICB_LOCKFLAGS.IgnoreSync flag.
+/* Flags for the driver about resource behaviour:
*/
-#define PIPE_BUFFER_USAGE_UNSYNCHRONIZED (1 << 10)
+#define PIPE_RESOURCE_FLAG_GEN_MIPS (1 << 0) /* Driver performs autogen mips */
+#define PIPE_RESOURCE_FLAG_DRV_PRIV (1 << 16) /* driver/winsys private */
+#define PIPE_RESOURCE_FLAG_ST_PRIV (1 << 24) /* state-tracker/winsys private */
-/**
- * Written ranges will be notified later with
- * pipe_screen::buffer_flush_mapped_range.
- *
- * It should not be used with PIPE_BUFFER_USAGE_CPU_READ.
- *
- * See also:
- * - pipe_screen::buffer_flush_mapped_range
- * - OpenGL's ARB_map_buffer_range extension, MAP_FLUSH_EXPLICIT_BIT flag.
+/* Hint about the expected lifecycle of a resource.
*/
-#define PIPE_BUFFER_USAGE_FLUSH_EXPLICIT (1 << 11)
+#define PIPE_USAGE_DEFAULT 0 /* many uploads, draws intermixed */
+#define PIPE_USAGE_DYNAMIC 1 /* many uploads, draws intermixed */
+#define PIPE_USAGE_STATIC 2 /* same as immutable?? */
+#define PIPE_USAGE_IMMUTABLE 3 /* no change after first upload */
+#define PIPE_USAGE_STREAM 4 /* upload, draw, upload, draw */
-/** Pipe driver custom usage flags should be greater or equal to this value */
-#define PIPE_BUFFER_USAGE_CUSTOM (1 << 16)
-/* Convenient shortcuts */
-#define PIPE_BUFFER_USAGE_CPU_READ_WRITE \
- ( PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE )
-#define PIPE_BUFFER_USAGE_GPU_READ_WRITE \
- ( PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE )
-#define PIPE_BUFFER_USAGE_WRITE \
- ( PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_GPU_WRITE )
+/* These are intended to be used in calls to is_format_supported, but
+ * no driver actually uses these flags, and only the glx/xlib state
+ * tracker issues them.
+ *
+ * Deprecate?
+ */
+#define PIPE_TEXTURE_GEOM_NON_SQUARE 0x1
+#define PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO 0x2
/**
#define PIPE_REFERENCED_FOR_WRITE (1 << 1)
-enum pipe_video_codec
-{
- PIPE_VIDEO_CODEC_UNKNOWN = 0,
- PIPE_VIDEO_CODEC_MPEG12, /**< MPEG1, MPEG2 */
- PIPE_VIDEO_CODEC_MPEG4, /**< DIVX, XVID */
- PIPE_VIDEO_CODEC_VC1, /**< WMV */
- PIPE_VIDEO_CODEC_MPEG4_AVC /**< H.264 */
-};
-
-enum pipe_video_profile
-{
- PIPE_VIDEO_PROFILE_MPEG1,
- PIPE_VIDEO_PROFILE_MPEG2_SIMPLE,
- PIPE_VIDEO_PROFILE_MPEG2_MAIN,
- PIPE_VIDEO_PROFILE_MPEG4_SIMPLE,
- PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE,
- PIPE_VIDEO_PROFILE_VC1_SIMPLE,
- PIPE_VIDEO_PROFILE_VC1_MAIN,
- PIPE_VIDEO_PROFILE_VC1_ADVANCED,
- PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE,
- PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN,
- PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
-};
-
#ifdef __cplusplus
}
#endif
};
-enum pipe_video_chroma_format
-{
- PIPE_VIDEO_CHROMA_FORMAT_420,
- PIPE_VIDEO_CHROMA_FORMAT_422,
- PIPE_VIDEO_CHROMA_FORMAT_444
-};
-
-#if 0
-enum pipe_video_surface_format
-{
- PIPE_VIDEO_SURFACE_FORMAT_NV12, /**< Planar; Y plane, UV plane */
- PIPE_VIDEO_SURFACE_FORMAT_YV12, /**< Planar; Y plane, U plane, V plane */
- PIPE_VIDEO_SURFACE_FORMAT_YUYV, /**< Interleaved; Y,U,Y,V,Y,U,Y,V */
- PIPE_VIDEO_SURFACE_FORMAT_UYVY, /**< Interleaved; U,Y,V,Y,U,Y,V,Y */
- PIPE_VIDEO_SURFACE_FORMAT_VUYA /**< Packed; A31-24|Y23-16|U15-8|V7-0 */
-};
-#endif
-
#ifdef __cplusplus
}
#endif
/** Opaque type */
struct pipe_fence_handle;
struct pipe_winsys;
-struct pipe_buffer;
struct pipe_texture;
+struct pipe_resource;
struct pipe_surface;
-struct pipe_video_surface;
struct pipe_transfer;
/**
* Check if the given pipe_format is supported as a texture or
* drawing surface.
- * \param tex_usage bitmask of PIPE_TEXTURE_USAGE_*
+ * \param tex_usage bitmask of PIPE_BIND_*
* \param geom_flags bitmask of PIPE_TEXTURE_GEOM_*
*/
boolean (*is_format_supported)( struct pipe_screen *,
/**
* Create a new texture object, using the given template info.
*/
- struct pipe_texture * (*texture_create)(struct pipe_screen *,
- const struct pipe_texture *templat);
+ struct pipe_resource * (*resource_create)(struct pipe_screen *,
+ const struct pipe_resource *templat);
/**
* Create a texture from a winsys_handle. The handle is often created in
* another process by first creating a pipe texture and then calling
* texture_get_handle.
*/
- struct pipe_texture * (*texture_from_handle)(struct pipe_screen *,
- const struct pipe_texture *templat,
- struct winsys_handle *handle);
+ struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,
+ const struct pipe_resource *templat,
+ struct winsys_handle *handle);
/**
* Get a winsys_handle from a texture. Some platforms/winsys requires
* that the texture is created with a special usage flag like
* DISPLAYTARGET or PRIMARY.
*/
- boolean (*texture_get_handle)(struct pipe_screen *,
- struct pipe_texture *tex,
- struct winsys_handle *handle);
+ boolean (*resource_get_handle)(struct pipe_screen *,
+ struct pipe_resource *tex,
+ struct winsys_handle *handle);
- void (*texture_destroy)(struct pipe_texture *pt);
+ void (*resource_destroy)(struct pipe_screen *,
+ struct pipe_resource *pt);
/** Get a 2D surface which is a "view" into a texture
- * \param usage bitmaks of PIPE_BUFFER_USAGE_* read/write flags
+ * \param usage bitmaks of PIPE_BIND_* flags
*/
struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
- struct pipe_texture *texture,
+ struct pipe_resource *resource,
unsigned face, unsigned level,
unsigned zslice,
unsigned usage );
- /**
- * Create a new buffer.
- * \param alignment buffer start address alignment in bytes
- * \param usage bitmask of PIPE_BUFFER_USAGE_x
- * \param size size in bytes
- */
- struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen,
- unsigned alignment,
- unsigned usage,
- unsigned size );
-
/**
* Create a buffer that wraps user-space data.
*
* Note that ptr may be accessed at any time upto the time when the
* buffer is destroyed, so the data must not be freed before then.
*/
- struct pipe_buffer *(*user_buffer_create)(struct pipe_screen *screen,
- void *ptr,
- unsigned bytes);
-
-
-
- /**
- * Map the entire data store of a buffer object into the client's address.
- * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
- */
- void *(*buffer_map)( struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned usage );
- /**
- * Map a subrange of the buffer data store into the client's address space.
- *
- * The returned pointer is always relative to buffer start, regardless of
- * the specified range. This is different from the ARB_map_buffer_range
- * semantics because we don't forbid multiple mappings of the same buffer
- * (yet).
- */
- void *(*buffer_map_range)( struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned offset,
- unsigned length,
- unsigned usage);
-
- /**
- * Notify a range that was actually written into.
- *
- * Can only be used if the buffer was mapped with the
- * PIPE_BUFFER_USAGE_CPU_WRITE and PIPE_BUFFER_USAGE_FLUSH_EXPLICIT flags
- * set.
- *
- * The range is relative to the buffer start, regardless of the range
- * specified to buffer_map_range. This is different from the
- * ARB_map_buffer_range semantics because we don't forbid multiple mappings
- * of the same buffer (yet).
- *
- */
- void (*buffer_flush_mapped_range)( struct pipe_screen *screen,
- struct pipe_buffer *buf,
- unsigned offset,
- unsigned length);
-
- /**
- * Unmap buffer.
- *
- * If the buffer was mapped with PIPE_BUFFER_USAGE_CPU_WRITE flag but not
- * PIPE_BUFFER_USAGE_FLUSH_EXPLICIT then the pipe driver will
- * assume that the whole buffer was written. This is mostly for backward
- * compatibility purposes and may affect performance -- the state tracker
- * should always specify exactly what got written while the buffer was
- * mapped.
- */
- void (*buffer_unmap)( struct pipe_screen *screen,
- struct pipe_buffer *buf );
-
- void (*buffer_destroy)( struct pipe_buffer *buf );
-
- /**
- * Create a video surface suitable for use as a decoding target by the
- * driver's pipe_video_context.
- */
- struct pipe_video_surface*
- (*video_surface_create)( struct pipe_screen *screen,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height );
-
- void (*video_surface_destroy)( struct pipe_video_surface *vsfc );
+ struct pipe_resource *(*user_buffer_create)(struct pipe_screen *screen,
+ void *ptr,
+ unsigned bytes,
+ unsigned bind_flags);
/**
* Do any special operations to ensure buffer size is correct
};
-/**
- * The driver will certainly subclass this to include actual memory
- * management information.
- */
-struct pipe_buffer
-{
- struct pipe_reference reference;
- unsigned size;
- struct pipe_screen *screen;
- unsigned alignment;
- unsigned usage;
-};
-
/**
* Primitive (point/line/tri) rasterization info
struct pipe_surface
{
struct pipe_reference reference;
+ struct pipe_resource *texture; /**< resource into which this is a view */
enum pipe_format format;
+
unsigned width; /**< logical width in pixels */
unsigned height; /**< logical height in pixels */
+
unsigned layout; /**< PIPE_SURFACE_LAYOUT_x */
unsigned offset; /**< offset from start of buffer, in bytes */
- unsigned usage; /**< bitmask of PIPE_BUFFER_USAGE_x */
+ unsigned usage; /**< bitmask of PIPE_BIND_x */
unsigned zslice;
- struct pipe_texture *texture; /**< texture into which this is a view */
unsigned face;
unsigned level;
};
+
+
+
/**
* A view into a texture that can be bound to a shader stage.
*/
{
struct pipe_reference reference;
enum pipe_format format; /**< typed PIPE_FORMAT_x */
- struct pipe_texture *texture; /**< texture into which this is a view */
+ struct pipe_resource *texture; /**< texture into which this is a view */
struct pipe_context *context; /**< context this view belongs to */
unsigned first_level:8; /**< first mipmap level */
unsigned last_level:8; /**< last mipmap level */
};
-/**
- * Transfer object. For data transfer to/from a texture.
- */
-struct pipe_transfer
+struct pipe_box
{
- unsigned x; /**< x offset from start of texture image */
- unsigned y; /**< y offset from start of texture image */
- unsigned width; /**< logical width in pixels */
- unsigned height; /**< logical height in pixels */
- unsigned stride; /**< stride in bytes between rows of blocks */
- enum pipe_transfer_usage usage; /**< PIPE_TRANSFER_* */
-
- struct pipe_texture *texture; /**< texture to transfer to/from */
- unsigned face;
- unsigned level;
- unsigned zslice;
+ unsigned x;
+ unsigned y;
+ unsigned z;
+ unsigned width;
+ unsigned height;
+ unsigned depth;
};
-/**
- * Texture object.
- */
-struct pipe_texture
-{
- struct pipe_reference reference;
+struct pipe_resource
+{
+ struct pipe_reference reference;
+ struct pipe_screen *screen; /**< screen that this texture belongs to */
enum pipe_texture_target target; /**< PIPE_TEXTURE_x */
enum pipe_format format; /**< PIPE_FORMAT_x */
unsigned depth0;
unsigned last_level:8; /**< Index of last mipmap level present/defined */
-
unsigned nr_samples:8; /**< for multisampled surfaces, nr of samples */
+ unsigned _usage:8; /* PIPE_USAGE_x (not a bitmask) */
- unsigned tex_usage; /**< bitmask of PIPE_TEXTURE_USAGE_* */
+ unsigned bind; /* PIPE_BIND_x */
+ unsigned flags; /* PIPE_RESOURCE_FLAG_x */
+};
- struct pipe_screen *screen; /**< screen that this texture belongs to */
+
+struct pipe_subresource
+{
+ unsigned face:16;
+ unsigned level:16;
+};
+
+
+/**
+ * Transfer object. For data transfer to/from a texture.
+ */
+struct pipe_transfer
+{
+ struct pipe_resource *resource; /**< resource to transfer to/from */
+ struct pipe_subresource sr;
+ enum pipe_transfer_usage usage;
+ struct pipe_box box;
+ unsigned stride;
+ unsigned slice_stride;
+ void *data;
};
+
/**
* A vertex buffer. Typically, all the vertex data/attributes for
* drawing something will be in one buffer. But it's also possible, for
unsigned stride; /**< stride to same attrib in next vertex, in bytes */
unsigned max_index; /**< number of vertices in this buffer */
unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
- struct pipe_buffer *buffer; /**< the actual buffer */
+ struct pipe_resource *buffer; /**< the actual buffer */
};
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 PIPE_VIDEO_CONTEXT_H
-#define PIPE_VIDEO_CONTEXT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <pipe/p_video_state.h>
-
-struct pipe_screen;
-struct pipe_buffer;
-struct pipe_surface;
-struct pipe_video_surface;
-struct pipe_macroblock;
-struct pipe_picture_desc;
-struct pipe_fence_handle;
-
-/**
- * Gallium video rendering context
- */
-struct pipe_video_context
-{
- struct pipe_screen *screen;
- enum pipe_video_profile profile;
- enum pipe_video_chroma_format chroma_format;
- unsigned width;
- unsigned height;
-
- void *priv; /**< context private data (for DRI for example) */
-
- void (*destroy)(struct pipe_video_context *vpipe);
-
- /**
- * Picture decoding and displaying
- */
- /*@{*/
- void (*decode_bitstream)(struct pipe_video_context *vpipe,
- unsigned num_bufs,
- struct pipe_buffer **bitstream_buf);
-
- void (*decode_macroblocks)(struct pipe_video_context *vpipe,
- struct pipe_video_surface *past,
- struct pipe_video_surface *future,
- unsigned num_macroblocks,
- struct pipe_macroblock *macroblocks,
- struct pipe_fence_handle **fence);
-
- void (*clear_surface)(struct pipe_video_context *vpipe,
- unsigned x, unsigned y,
- unsigned width, unsigned height,
- unsigned value,
- struct pipe_surface *surface);
-
- void (*render_picture)(struct pipe_video_context *vpipe,
- /*struct pipe_surface *backround,
- struct pipe_video_rect *backround_area,*/
- struct pipe_video_surface *src_surface,
- enum pipe_mpeg12_picture_type picture_type,
- /*unsigned num_past_surfaces,
- struct pipe_video_surface *past_surfaces,
- unsigned num_future_surfaces,
- struct pipe_video_surface *future_surfaces,*/
- struct pipe_video_rect *src_area,
- struct pipe_surface *dst_surface,
- struct pipe_video_rect *dst_area,
- /*unsigned num_layers,
- struct pipe_texture *layers,
- struct pipe_video_rect *layer_src_areas,
- struct pipe_video_rect *layer_dst_areas,*/
- struct pipe_fence_handle **fence);
- /*@}*/
-
- /**
- * Parameter-like states (or properties)
- */
- /*@{*/
- void (*set_picture_desc)(struct pipe_video_context *vpipe,
- const struct pipe_picture_desc *desc);
-
- void (*set_decode_target)(struct pipe_video_context *vpipe,
- struct pipe_video_surface *dt);
-
- void (*set_csc_matrix)(struct pipe_video_context *vpipe, const float *mat);
-
- /* TODO: Interface for scaling modes, post-processing, etc. */
- /*@}*/
-};
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PIPE_VIDEO_CONTEXT_H */
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 PIPE_VIDEO_STATE_H
-#define PIPE_VIDEO_STATE_H
-
-/* u_reduce_video_profile() needs these */
-#include <pipe/p_compiler.h>
-
-#include <pipe/p_defines.h>
-#include <pipe/p_format.h>
-#include <pipe/p_state.h>
-#include <pipe/p_screen.h>
-#include <util/u_inlines.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct pipe_video_surface
-{
- struct pipe_reference reference;
- struct pipe_screen *screen;
- enum pipe_video_chroma_format chroma_format;
- /*enum pipe_video_surface_format surface_format;*/
- unsigned width;
- unsigned height;
-};
-
-static INLINE void
-pipe_video_surface_reference(struct pipe_video_surface **ptr, struct pipe_video_surface *surf)
-{
- struct pipe_video_surface *old_surf = *ptr;
-
- if (pipe_reference(&(*ptr)->reference, &surf->reference))
- old_surf->screen->video_surface_destroy(old_surf);
- *ptr = surf;
-}
-
-struct pipe_video_rect
-{
- unsigned x, y, w, h;
-};
-
-static INLINE enum pipe_video_codec
-u_reduce_video_profile(enum pipe_video_profile profile)
-{
- switch (profile)
- {
- case PIPE_VIDEO_PROFILE_MPEG1:
- case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
- case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
- return PIPE_VIDEO_CODEC_MPEG12;
-
- case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
- case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
- return PIPE_VIDEO_CODEC_MPEG4;
-
- case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
- case PIPE_VIDEO_PROFILE_VC1_MAIN:
- case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
- return PIPE_VIDEO_CODEC_VC1;
-
- case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
- case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
- case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
- return PIPE_VIDEO_CODEC_MPEG4_AVC;
-
- default:
- assert(0);
- return PIPE_VIDEO_CODEC_UNKNOWN;
- }
-}
-
-enum pipe_mpeg12_picture_type
-{
- PIPE_MPEG12_PICTURE_TYPE_FIELD_TOP,
- PIPE_MPEG12_PICTURE_TYPE_FIELD_BOTTOM,
- PIPE_MPEG12_PICTURE_TYPE_FRAME
-};
-
-enum pipe_mpeg12_macroblock_type
-{
- PIPE_MPEG12_MACROBLOCK_TYPE_INTRA,
- PIPE_MPEG12_MACROBLOCK_TYPE_FWD,
- PIPE_MPEG12_MACROBLOCK_TYPE_BKWD,
- PIPE_MPEG12_MACROBLOCK_TYPE_BI,
-
- PIPE_MPEG12_MACROBLOCK_NUM_TYPES
-};
-
-enum pipe_mpeg12_motion_type
-{
- PIPE_MPEG12_MOTION_TYPE_FIELD,
- PIPE_MPEG12_MOTION_TYPE_FRAME,
- PIPE_MPEG12_MOTION_TYPE_DUALPRIME,
- PIPE_MPEG12_MOTION_TYPE_16x8
-};
-
-enum pipe_mpeg12_dct_type
-{
- PIPE_MPEG12_DCT_TYPE_FIELD,
- PIPE_MPEG12_DCT_TYPE_FRAME
-};
-
-struct pipe_macroblock
-{
- enum pipe_video_codec codec;
-};
-
-struct pipe_mpeg12_macroblock
-{
- struct pipe_macroblock base;
-
- unsigned mbx;
- unsigned mby;
- enum pipe_mpeg12_macroblock_type mb_type;
- enum pipe_mpeg12_motion_type mo_type;
- enum pipe_mpeg12_dct_type dct_type;
- signed pmv[2][2][2];
- unsigned cbp;
- void *blocks;
-};
-
-#if 0
-struct pipe_picture_desc
-{
- enum pipe_video_format format;
-};
-
-struct pipe_mpeg12_picture_desc
-{
- struct pipe_picture_desc base;
-
- /* TODO: Use bitfields where possible? */
- struct pipe_surface *forward_reference;
- struct pipe_surface *backward_reference;
- unsigned picture_coding_type;
- unsigned fcode;
- unsigned intra_dc_precision;
- unsigned picture_structure;
- unsigned top_field_first;
- unsigned frame_pred_frame_dct;
- unsigned concealment_motion_vectors;
- unsigned q_scale_type;
- unsigned intra_vlc_format;
- unsigned alternate_scan;
- unsigned full_pel_forward_vector;
- unsigned full_pel_backward_vector;
- struct pipe_buffer *intra_quantizer_matrix;
- struct pipe_buffer *non_intra_quantizer_matrix;
- struct pipe_buffer *chroma_intra_quantizer_matrix;
- struct pipe_buffer *chroma_non_intra_quantizer_matrix;
-};
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PIPE_VIDEO_STATE_H */
struct pipe_winsys;
struct pipe_buffer;
struct pipe_context;
-struct pipe_texture;
+struct pipe_resource;
struct drm_clip_rect;
struct pipe_winsys;
struct pipe_buffer;
struct pipe_context;
-struct pipe_texture;
+struct pipe_resource;
enum drm_create_screen_mode {
DRM_CREATE_NORMAL = 0,
typedef void (*st_proc_t)(void);
struct pipe_context;
-struct pipe_texture;
+struct pipe_resource;
struct pipe_fence_handle;
/**
void *resource;
/* this is owned by the caller */
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
};
/**
void *egl_image;
/* this is owned by the caller */
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
unsigned face;
unsigned level;
boolean (*validate)(struct st_framebuffer_iface *stfbi,
const enum st_attachment_type *statts,
unsigned count,
- struct pipe_texture **out);
+ struct pipe_resource **out);
};
/**
*/
boolean (*teximage)(struct st_context_iface *stctxi, enum st_texture_type target,
int level, enum pipe_format internal_format,
- struct pipe_texture *tex, boolean mipmap);
+ struct pipe_resource *tex, boolean mipmap);
/**
* Used to implement glXCopyContext.
struct winsys_handle;
struct pipe_screen;
struct pipe_context;
-struct pipe_texture;
+struct pipe_resource;
/**
* pools, or obtained directly from the windowing system.
*
* This callback is invoked by the pipe_screen when creating a texture marked
- * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
+ * with the PIPE_BIND_DISPLAY_TARGET flag to get the underlying
* storage.
*/
struct sw_displaytarget *
*/
struct sw_displaytarget *
(*displaytarget_from_handle)( struct sw_winsys *ws,
- const struct pipe_texture *templat,
+ const struct pipe_resource *template,
struct winsys_handle *whandle,
unsigned *stride );
struct winsys_handle *whandle );
/**
- * \param flags bitmask of PIPE_BUFFER_USAGE_x flags
+ * \param flags bitmask of PIPE_TRANSFER_x flags
*/
void *
(*displaytarget_map)( struct sw_winsys *ws,
}
struct pipe_surface *
-dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex)
+dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_resource *ptex)
{
struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen;
struct pipe_surface *psurf = drawable->dri1_surface;
pipe_surface_reference(&drawable->dri1_surface, NULL);
drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen,
- ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ);
+ ptex, 0, 0, 0, PIPE_BIND_BLIT_SOURCE);
psurf = drawable->dri1_surface;
}
dri1_swap_fences_clear(struct dri_drawable *drawable);
struct pipe_surface *
-dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex);
+dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_resource *ptex);
void
dri1_destroy_pipe_surface(struct dri_drawable *drawable);
unsigned old_w;
unsigned old_h;
- struct pipe_texture *textures[ST_ATTACHMENT_COUNT];
+ struct pipe_resource *textures[ST_ATTACHMENT_COUNT];
unsigned int texture_mask, texture_stamp;
struct pipe_fence_handle *swap_fences[DRI_SWAP_FENCES_MAX];
pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ PIPE_BIND_DEPTH_STENCIL, 0);
pf_z24x8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8Z24_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ PIPE_BIND_DEPTH_STENCIL, 0);
pf_s8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ PIPE_BIND_DEPTH_STENCIL, 0);
pf_z24s8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ PIPE_BIND_DEPTH_STENCIL, 0);
pf_a8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8A8_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0);
+ PIPE_BIND_RENDER_TARGET, 0);
pf_x8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0);
+ PIPE_BIND_RENDER_TARGET, 0);
pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0);
+ PIPE_BIND_RENDER_TARGET, 0);
/* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */
if (dri_with_format(screen->sPriv)) {
pf_z16 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z16_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ PIPE_BIND_DEPTH_STENCIL, 0);
pf_z32 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z32_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ PIPE_BIND_DEPTH_STENCIL, 0);
} else {
pf_z16 = FALSE;
pf_z32 = FALSE;
dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
const enum st_attachment_type *statts,
unsigned count,
- struct pipe_texture **out)
+ struct pipe_resource **out)
{
struct dri_drawable *drawable =
(struct dri_drawable *) stfbi->st_manager_private;
for (i = 0; i < count; i++) {
out[i] = NULL;
- pipe_texture_reference(&out[i], drawable->textures[statts[i]]);
+ pipe_resource_reference(&out[i], drawable->textures[statts[i]]);
}
return TRUE;
int i;
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
- pipe_texture_reference(&drawable->textures[i], NULL);
+ pipe_resource_reference(&drawable->textures[i], NULL);
FREE(stfbi);
}
return FALSE;
stimg->texture = NULL;
- pipe_texture_reference(&stimg->texture, img->texture);
+ pipe_resource_reference(&stimg->texture, img->texture);
stimg->face = img->face;
stimg->level = img->level;
stimg->zslice = img->zslice;
struct dri_drawable;
struct __DRIimageRec {
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
unsigned face;
unsigned level;
unsigned zslice;
static void
dri1_present_texture_locked(__DRIdrawable * dPriv,
- struct pipe_texture *ptex,
+ struct pipe_resource *ptex,
const struct drm_clip_rect *sub_box,
struct pipe_fence_handle **fence)
{
static void
dri1_copy_to_front(struct dri_context *ctx,
- struct pipe_texture *ptex,
+ struct pipe_resource *ptex,
__DRIdrawable * dPriv,
const struct drm_clip_rect *sub_box,
struct pipe_fence_handle **fence)
struct dri_screen *screen = dri_screen(draw->sPriv);
struct pipe_screen *pipe_screen = screen->pipe_screen;
struct pipe_fence_handle *dummy_fence;
- struct pipe_texture *ptex;
+ struct pipe_resource *ptex;
if (!ctx)
return; /* For now */
struct dri_screen *screen = dri_screen(draw->sPriv);
struct pipe_screen *pipe_screen = screen->pipe_screen;
struct pipe_fence_handle *fence;
- struct pipe_texture *ptex;
+ struct pipe_resource *ptex;
assert(__dri1_api_hooks != NULL);
struct drm_clip_rect sub_bbox;
struct dri_drawable *draw = dri_drawable(dPriv);
struct pipe_fence_handle *dummy_fence;
- struct pipe_texture *ptex;
+ struct pipe_resource *ptex;
assert(__dri1_api_hooks != NULL);
unsigned mask)
{
struct dri_screen *screen = dri_screen(drawable->sPriv);
- struct pipe_texture templ;
+ struct pipe_resource templ;
unsigned width, height;
boolean resized;
int i;
/* remove outdated textures */
if (resized) {
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
- pipe_texture_reference(&drawable->textures[i], NULL);
+ pipe_resource_reference(&drawable->textures[i], NULL);
}
memset(&templ, 0, sizeof(templ));
case ST_ATTACHMENT_FRONT_RIGHT:
case ST_ATTACHMENT_BACK_RIGHT:
format = drawable->stvis.color_format;
- tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ tex_usage = PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_RENDER_TARGET;
break;
case ST_ATTACHMENT_DEPTH_STENCIL:
format = drawable->stvis.depth_stencil_format;
- tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ tex_usage = PIPE_BIND_DEPTH_STENCIL;
break;
default:
format = PIPE_FORMAT_NONE;
if (format != PIPE_FORMAT_NONE) {
templ.format = format;
- templ.tex_usage = tex_usage;
+ templ.bind = tex_usage;
drawable->textures[i] =
- screen->pipe_screen->texture_create(screen->pipe_screen, &templ);
+ screen->pipe_screen->resource_create(screen->pipe_screen, &templ);
}
}
{
struct dri_context *ctx = dri_context(pDRICtx);
struct dri_drawable *drawable = dri_drawable(dPriv);
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT);
return format;
}
+
/**
* Retrieve __DRIbuffer from the DRI loader.
*/
}
/**
- * Process __DRIbuffer and convert them into pipe_textures.
+ * Process __DRIbuffer and convert them into pipe_resources.
*/
static void
dri2_drawable_process_buffers(struct dri_drawable *drawable,
{
struct dri_screen *screen = dri_screen(drawable->sPriv);
__DRIdrawable *dri_drawable = drawable->dPriv;
- struct pipe_texture templ;
+ struct pipe_resource templ;
struct winsys_handle whandle;
boolean have_depth = FALSE;
unsigned i;
return;
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
- pipe_texture_reference(&drawable->textures[i], NULL);
+ pipe_resource_reference(&drawable->textures[i], NULL);
memset(&templ, 0, sizeof(templ));
- templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ templ.bind = PIPE_BIND_RENDER_TARGET;
templ.target = PIPE_TEXTURE_2D;
templ.last_level = 0;
templ.width0 = dri_drawable->w;
whandle.stride = buf->pitch;
drawable->textures[statt] =
- screen->pipe_screen->texture_from_handle(screen->pipe_screen,
+ screen->pipe_screen->resource_from_handle(screen->pipe_screen,
&templ, &whandle);
}
{
struct dri_screen *screen = dri_screen(context->driScreenPriv);
__DRIimage *img;
- struct pipe_texture templ;
+ struct pipe_resource templ;
struct winsys_handle whandle;
unsigned tex_usage;
enum pipe_format pf;
- tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET | PIPE_TEXTURE_USAGE_SAMPLER;
+ tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
switch (format) {
case __DRI_IMAGE_FORMAT_RGB565:
return NULL;
memset(&templ, 0, sizeof(templ));
- templ.tex_usage = tex_usage;
+ templ.bind = tex_usage;
templ.format = pf;
templ.target = PIPE_TEXTURE_2D;
templ.last_level = 0;
whandle.handle = name;
whandle.stride = pitch * util_format_get_blocksize(pf);
- img->texture = screen->pipe_screen->texture_from_handle(screen->pipe_screen,
+ img->texture = screen->pipe_screen->resource_from_handle(screen->pipe_screen,
&templ, &whandle);
if (!img->texture) {
FREE(img);
static void
dri2_destroy_image(__DRIimage *img)
{
- pipe_texture_reference(&img->texture, NULL);
+ pipe_resource_reference(&img->texture, NULL);
FREE(img);
}
static INLINE void
drisw_present_texture(__DRIdrawable *dPriv,
- struct pipe_texture *ptex)
+ struct pipe_resource *ptex)
{
struct dri_drawable *drawable = dri_drawable(dPriv);
struct dri_screen *screen = dri_screen(drawable->sPriv);
static INLINE void
drisw_copy_to_front(__DRIdrawable * dPriv,
- struct pipe_texture *ptex)
+ struct pipe_resource *ptex)
{
drisw_present_texture(dPriv, ptex);
{
struct dri_context *ctx = dri_get_current();
struct dri_drawable *drawable = dri_drawable(dPriv);
- struct pipe_texture *ptex;
+ struct pipe_resource *ptex;
if (!ctx)
return;
enum st_attachment_type statt)
{
struct dri_context *ctx = dri_get_current();
- struct pipe_texture *ptex;
+ struct pipe_resource *ptex;
if (!ctx)
return;
unsigned mask)
{
struct dri_screen *screen = dri_screen(drawable->sPriv);
- struct pipe_texture templ;
+ struct pipe_resource templ;
unsigned width, height;
boolean resized;
int i;
/* remove outdated textures */
if (resized) {
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
- pipe_texture_reference(&drawable->textures[i], NULL);
+ pipe_resource_reference(&drawable->textures[i], NULL);
}
memset(&templ, 0, sizeof(templ));
case ST_ATTACHMENT_FRONT_RIGHT:
case ST_ATTACHMENT_BACK_RIGHT:
format = drawable->stvis.color_format;
- tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ tex_usage = PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_RENDER_TARGET;
break;
case ST_ATTACHMENT_DEPTH_STENCIL:
format = drawable->stvis.depth_stencil_format;
- tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ tex_usage = PIPE_BIND_DEPTH_STENCIL;
break;
default:
format = PIPE_FORMAT_NONE;
if (format != PIPE_FORMAT_NONE) {
templ.format = format;
- templ.tex_usage = tex_usage;
+ templ.bind = tex_usage;
drawable->textures[i] =
- screen->pipe_screen->texture_create(screen->pipe_screen, &templ);
+ screen->pipe_screen->resource_create(screen->pipe_screen, &templ);
}
}
if (!dpy->Initialized)
_eglLog(_EGL_FATAL, "destroy a surface with an unitialized display");
- pipe_texture_reference(&gsurf->render_texture, NULL);
+ pipe_resource_reference(&gsurf->render_texture, NULL);
egl_g3d_destroy_st_framebuffer(gsurf->stfbi);
if (gsurf->native)
gsurf->native->destroy(gsurf->native);
*/
static struct pipe_surface *
get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf,
- enum native_attachment natt)
+ enum native_attachment natt,
+ unsigned bind)
{
- struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+ struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
struct pipe_surface *psurf;
textures[natt] = NULL;
return NULL;
psurf = ndpy->screen->get_tex_surface(ndpy->screen, textures[natt],
- 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
- pipe_texture_reference(&textures[natt], NULL);
+ 0, 0, 0, bind);
+ pipe_resource_reference(&textures[natt], NULL);
return psurf;
}
return EGL_FALSE;
}
- psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT);
+ psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT,
+ PIPE_BIND_BLIT_DESTINATION);
if (psurf) {
struct pipe_surface *psrc;
psrc = screen->get_tex_surface(screen, gsurf->render_texture,
- 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ);
+ 0, 0, 0, PIPE_BIND_BLIT_SOURCE);
if (psrc) {
gdpy->pipe->surface_copy(gdpy->pipe, psurf, 0, 0,
psrc, 0, 0, psurf->width, psurf->height);
/* the native surface; NULL for pbuffers */
struct native_surface *native;
- struct pipe_texture *render_texture;
+ struct pipe_resource *render_texture;
unsigned int sequence_number;
};
struct egl_g3d_image {
_EGLImage base;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
unsigned face;
unsigned level;
unsigned zslice;
/**
* Reference and return the front left buffer of the native pixmap.
*/
-static struct pipe_texture *
+static struct pipe_resource *
egl_g3d_reference_native_pixmap(_EGLDisplay *dpy, EGLNativePixmapType pix)
{
struct egl_g3d_display *gdpy = egl_g3d_display(dpy);
struct egl_g3d_config *gconf;
struct native_surface *nsurf;
- struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+ struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
enum native_attachment natt;
gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, pix));
EGLenum target, EGLClientBuffer buffer,
const EGLint *attribs)
{
- struct pipe_texture *ptex;
+ struct pipe_resource *ptex;
struct egl_g3d_image *gimg;
unsigned face = 0, level = 0, zslice = 0;
if (level > ptex->last_level) {
_eglError(EGL_BAD_MATCH, "eglCreateEGLImageKHR");
- pipe_texture_reference(&gimg->texture, NULL);
+ pipe_resource_reference(&gimg->texture, NULL);
free(gimg);
return NULL;
}
if (zslice > ptex->depth0) {
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
- pipe_texture_reference(&gimg->texture, NULL);
+ pipe_resource_reference(&gimg->texture, NULL);
free(gimg);
return NULL;
}
{
struct egl_g3d_image *gimg = egl_g3d_image(img);
- pipe_texture_reference(&gimg->texture, NULL);
+ pipe_resource_reference(&gimg->texture, NULL);
free(gimg);
return EGL_TRUE;
gimg = egl_g3d_image(img);
stimg->texture = NULL;
- pipe_texture_reference(&stimg->texture, gimg->texture);
+ pipe_resource_reference(&stimg->texture, gimg->texture);
stimg->face = gimg->face;
stimg->level = gimg->level;
stimg->zslice = gimg->zslice;
egl_g3d_st_framebuffer_validate_pbuffer(struct st_framebuffer_iface *stfbi,
const enum st_attachment_type *statts,
unsigned count,
- struct pipe_texture **out)
+ struct pipe_resource **out)
{
_EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
- struct pipe_texture templ;
+ struct pipe_resource templ;
unsigned i;
for (i = 0; i < count; i++) {
templ.height0 = gsurf->base.Height;
templ.depth0 = 1;
templ.format = gsurf->stvis.color_format;
- templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ templ.bind = PIPE_BIND_RENDER_TARGET;
- gsurf->render_texture = screen->texture_create(screen, &templ);
+ gsurf->render_texture = screen->resource_create(screen, &templ);
}
- pipe_texture_reference(&out[i], gsurf->render_texture);
+ pipe_resource_reference(&out[i], gsurf->render_texture);
}
return TRUE;
egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
const enum st_attachment_type *statts,
unsigned count,
- struct pipe_texture **out)
+ struct pipe_resource **out)
{
_EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
- struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+ struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
uint attachment_mask = 0;
unsigned i;
return FALSE;
for (i = 0; i < count; i++) {
- struct pipe_texture *tex;
+ struct pipe_resource *tex;
int natt;
switch (statts[i]) {
tex = textures[natt];
if (statts[i] == stfbi->visual->render_buffer)
- pipe_texture_reference(&gsurf->render_texture, tex);
+ pipe_resource_reference(&gsurf->render_texture, tex);
if (attachment_mask & (1 << natt)) {
/* transfer the ownership to the caller */
}
else {
/* the attachment is listed more than once */
- pipe_texture_reference(&out[i], tex);
+ pipe_resource_reference(&out[i], tex);
}
}
}
* behavior might change in the future.
*/
boolean (*validate)(struct native_surface *nsurf, uint attachment_mask,
- unsigned int *seq_num, struct pipe_texture **textures,
+ unsigned int *seq_num, struct pipe_resource **textures,
int *width, int *height);
/**
static boolean
kms_surface_validate(struct native_surface *nsurf, uint attachment_mask,
- unsigned int *seq_num, struct pipe_texture **textures,
+ unsigned int *seq_num, struct pipe_resource **textures,
int *width, int *height)
{
struct kms_surface *ksurf = kms_surface(nsurf);
struct kms_display *kdpy = ksurf->kdpy;
struct pipe_screen *screen = kdpy->base.screen;
- struct pipe_texture templ, *ptex;
+ struct pipe_resource templ, *ptex;
int att;
if (attachment_mask) {
templ.height0 = ksurf->height;
templ.depth0 = 1;
templ.format = ksurf->color_format;
- templ.tex_usage =
- PIPE_TEXTURE_USAGE_RENDER_TARGET | PIPE_TEXTURE_USAGE_SCANOUT;
+ templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SCANOUT;
}
/* create textures */
ptex = ksurf->textures[att];
if (!ptex) {
- ptex = screen->texture_create(screen, &templ);
+ ptex = screen->resource_create(screen, &templ);
ksurf->textures[att] = ptex;
}
if (textures) {
textures[att] = NULL;
- pipe_texture_reference(&textures[att], ptex);
+ pipe_resource_reference(&textures[att], ptex);
}
}
if (!ksurf->textures[natt])
return FALSE;
- pipe_texture_reference(&fb->texture, ksurf->textures[natt]);
+ pipe_resource_reference(&fb->texture, ksurf->textures[natt]);
}
/* already initialized */
memset(&whandle, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_KMS;
- if (!kdpy->base.screen->texture_get_handle(kdpy->base.screen,
+ if (!kdpy->base.screen->resource_get_handle(kdpy->base.screen,
fb->texture, &whandle))
return FALSE;
struct kms_crtc *kcrtc = &ksurf->current_crtc;
struct kms_display *kdpy = ksurf->kdpy;
struct kms_framebuffer tmp_fb;
- struct pipe_texture *tmp_texture;
+ struct pipe_resource *tmp_texture;
int err;
if (!ksurf->back_fb.buffer_id) {
if (ksurf->front_fb.buffer_id)
drmModeRmFB(ksurf->kdpy->fd, ksurf->front_fb.buffer_id);
- pipe_texture_reference(&ksurf->front_fb.texture, NULL);
+ pipe_resource_reference(&ksurf->front_fb.texture, NULL);
if (ksurf->back_fb.buffer_id)
drmModeRmFB(ksurf->kdpy->fd, ksurf->back_fb.buffer_id);
- pipe_texture_reference(&ksurf->back_fb.texture, NULL);
+ pipe_resource_reference(&ksurf->back_fb.texture, NULL);
for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
- struct pipe_texture *ptex = ksurf->textures[i];
- pipe_texture_reference(&ptex, NULL);
+ struct pipe_resource *ptex = ksurf->textures[i];
+ pipe_resource_reference(&ptex, NULL);
}
free(ksurf);
{
return ndpy->screen->is_format_supported(ndpy->screen,
fmt, PIPE_TEXTURE_2D,
- (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET :
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ (is_color) ? PIPE_BIND_RENDER_TARGET :
+ PIPE_BIND_DEPTH_STENCIL, 0);
}
static const struct native_config **
};
struct kms_framebuffer {
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
boolean is_passive;
uint32_t buffer_id;
struct kms_display *kdpy;
int width, height;
- struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+ struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
unsigned int sequence_number;
struct kms_framebuffer front_fb, back_fb;
unsigned int server_stamp;
unsigned int client_stamp;
int width, height;
- struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS];
+ struct pipe_resource *textures[NUM_NATIVE_ATTACHMENTS];
uint valid_mask;
boolean have_back, have_fake;
{
struct dri2_surface *dri2surf = dri2_surface(nsurf);
struct dri2_display *dri2dpy = dri2surf->dri2dpy;
- struct pipe_texture templ;
+ struct pipe_resource templ;
struct winsys_handle whandle;
uint valid_mask;
int i;
/* free the old textures */
for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++)
- pipe_texture_reference(&dri2surf->textures[i], NULL);
+ pipe_resource_reference(&dri2surf->textures[i], NULL);
dri2surf->valid_mask = 0x0;
dri2surf->have_back = FALSE;
templ.height0 = dri2surf->height;
templ.depth0 = 1;
templ.format = dri2surf->color_format;
- templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ templ.bind = PIPE_BIND_RENDER_TARGET;
valid_mask = 0x0;
for (i = 0; i < num_xbufs; i++) {
memset(&whandle, 0, sizeof(whandle));
whandle.stride = xbuf->pitch;
whandle.handle = xbuf->name;
- dri2surf->textures[natt] = dri2dpy->base.screen->texture_from_handle(
+ dri2surf->textures[natt] = dri2dpy->base.screen->resource_from_handle(
dri2dpy->base.screen, &templ, &whandle);
if (dri2surf->textures[natt])
valid_mask |= 1 << natt;
static boolean
dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask,
- unsigned int *seq_num, struct pipe_texture **textures,
+ unsigned int *seq_num, struct pipe_resource **textures,
int *width, int *height)
{
struct dri2_surface *dri2surf = dri2_surface(nsurf);
int att;
for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) {
if (native_attachment_mask_test(attachment_mask, att)) {
- struct pipe_texture *ptex = dri2surf->textures[att];
+ struct pipe_resource *ptex = dri2surf->textures[att];
textures[att] = NULL;
- pipe_texture_reference(&textures[att], ptex);
+ pipe_resource_reference(&textures[att], ptex);
}
}
}
free(dri2surf->last_xbufs);
for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) {
- struct pipe_texture *ptex = dri2surf->textures[i];
- pipe_texture_reference(&ptex, NULL);
+ struct pipe_resource *ptex = dri2surf->textures[i];
+ pipe_resource_reference(&ptex, NULL);
}
if (dri2surf->drawable) {
enum pipe_format fmt, boolean is_color)
{
return screen->is_format_supported(screen, fmt, PIPE_TEXTURE_2D,
- (is_color) ? PIPE_TEXTURE_USAGE_RENDER_TARGET :
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ (is_color) ? PIPE_BIND_RENDER_TARGET :
+ PIPE_BIND_DEPTH_STENCIL, 0);
}
static boolean
};
struct ximage_buffer {
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct xlib_drawable xdraw;
};
struct ximage_surface *xsurf = ximage_surface(nsurf);
struct ximage_buffer *xbuf = &xsurf->buffers[which];
- pipe_texture_reference(&xbuf->texture, NULL);
+ pipe_resource_reference(&xbuf->texture, NULL);
}
static boolean
struct ximage_surface *xsurf = ximage_surface(nsurf);
struct ximage_buffer *xbuf = &xsurf->buffers[which];
struct pipe_screen *screen = xsurf->xdpy->base.screen;
- struct pipe_texture templ;
+ struct pipe_resource templ;
/* free old data */
if (xbuf->texture)
templ.width0 = xsurf->width;
templ.height0 = xsurf->height;
templ.depth0 = 1;
- templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ templ.bind = PIPE_BIND_RENDER_TARGET;
switch (which) {
case NATIVE_ATTACHMENT_FRONT_LEFT:
case NATIVE_ATTACHMENT_FRONT_RIGHT:
- templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT;
+ templ.bind |= PIPE_BIND_SCANOUT;
break;
case NATIVE_ATTACHMENT_BACK_LEFT:
case NATIVE_ATTACHMENT_BACK_RIGHT:
- templ.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+ templ.bind |= PIPE_BIND_DISPLAY_TARGET;
break;
default:
break;
}
-
- xbuf->texture = screen->texture_create(screen, &templ);
+ xbuf->texture = screen->resource_create(screen, &templ);
if (xbuf->texture) {
xbuf->xdraw.visual = xsurf->visual.visual;
xbuf->xdraw.depth = xsurf->visual.depth;
pipe_surface_reference(&xsurf->draw_surface, NULL);
psurf = screen->get_tex_surface(screen,
- xbuf->texture, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ);
+ xbuf->texture, 0, 0, 0, PIPE_BIND_DISPLAY_TARGET);
if (!psurf)
return FALSE;
static boolean
ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask,
- unsigned int *seq_num, struct pipe_texture **textures,
+ unsigned int *seq_num, struct pipe_resource **textures,
int *width, int *height)
{
struct ximage_surface *xsurf = ximage_surface(nsurf);
struct ximage_buffer *xbuf = &xsurf->buffers[att];
textures[att] = NULL;
- pipe_texture_reference(&textures[att], xbuf->texture);
+ pipe_resource_reference(&textures[att], xbuf->texture);
}
}
}
choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil)
{
const enum pipe_texture_target target = PIPE_TEXTURE_2D;
- const unsigned tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ const unsigned tex_usage = PIPE_BIND_DEPTH_STENCIL;
const unsigned geom_flags = (PIPE_TEXTURE_GEOM_NON_SQUARE |
PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO);
enum pipe_format formats[8], fmt;
struct st_visual stvis;
unsigned texture_width, texture_height, texture_mask;
- struct pipe_texture *textures[ST_ATTACHMENT_COUNT];
+ struct pipe_resource *textures[ST_ATTACHMENT_COUNT];
struct pipe_surface *display_surface;
};
enum st_attachment_type statt)
{
struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi);
- struct pipe_texture *ptex = xstfb->textures[statt];
+ struct pipe_resource *ptex = xstfb->textures[statt];
struct pipe_surface *psurf;
if (!ptex)
pipe_surface_reference(&xstfb->display_surface, NULL);
psurf = xstfb->screen->get_tex_surface(xstfb->screen,
- ptex, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ);
+ ptex, 0, 0, 0, PIPE_BIND_DISPLAY_TARGET);
if (!psurf)
return FALSE;
unsigned width, unsigned height)
{
struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi);
- struct pipe_texture *src_ptex = xstfb->textures[src_statt];
- struct pipe_texture *dst_ptex = xstfb->textures[dst_statt];
+ struct pipe_resource *src_ptex = xstfb->textures[src_statt];
+ struct pipe_resource *dst_ptex = xstfb->textures[dst_statt];
struct pipe_surface *src, *dst;
struct pipe_context *pipe;
}
src = xstfb->screen->get_tex_surface(xstfb->screen,
- src_ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ);
+ src_ptex, 0, 0, 0, PIPE_BIND_BLIT_SOURCE);
dst = xstfb->screen->get_tex_surface(xstfb->screen,
- dst_ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+ dst_ptex, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION);
if (src && dst)
pipe->surface_copy(pipe, dst, x, y, src, x, y, width, height);
unsigned mask)
{
struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi);
- struct pipe_texture templ;
+ struct pipe_resource templ;
unsigned i;
/* remove outdated textures */
if (xstfb->texture_width != width || xstfb->texture_height != height) {
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
- pipe_texture_reference(&xstfb->textures[i], NULL);
+ pipe_resource_reference(&xstfb->textures[i], NULL);
}
memset(&templ, 0, sizeof(templ));
for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
enum pipe_format format;
- unsigned tex_usage;
+ unsigned bind;
/* the texture already exists or not requested */
if (xstfb->textures[i] || !(mask & (1 << i))) {
case ST_ATTACHMENT_FRONT_RIGHT:
case ST_ATTACHMENT_BACK_RIGHT:
format = xstfb->stvis.color_format;
- tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ bind = PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_RENDER_TARGET;
break;
case ST_ATTACHMENT_DEPTH_STENCIL:
format = xstfb->stvis.depth_stencil_format;
- tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ bind = PIPE_BIND_DEPTH_STENCIL;
break;
default:
format = PIPE_FORMAT_NONE;
if (format != PIPE_FORMAT_NONE) {
templ.format = format;
- templ.tex_usage = tex_usage;
+ templ.bind = bind;
xstfb->textures[i] =
- xstfb->screen->texture_create(xstfb->screen, &templ);
+ xstfb->screen->resource_create(xstfb->screen, &templ);
}
}
xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
const enum st_attachment_type *statts,
unsigned count,
- struct pipe_texture **out)
+ struct pipe_resource **out)
{
struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi);
unsigned statt_mask, new_mask, i;
for (i = 0; i < count; i++) {
out[i] = NULL;
- pipe_texture_reference(&out[i], xstfb->textures[statts[i]]);
+ pipe_resource_reference(&out[i], xstfb->textures[statts[i]]);
}
return TRUE;
pipe_surface_reference(&xstfb->display_surface, NULL);
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
- pipe_texture_reference(&xstfb->textures[i], NULL);
+ pipe_resource_reference(&xstfb->textures[i], NULL);
FREE(xstfb);
FREE(stfbi);
ret = xmesa_st_framebuffer_display(stfbi, ST_ATTACHMENT_BACK_LEFT);
if (ret) {
- struct pipe_texture **front, **back, *tmp;
+ struct pipe_resource **front, **back, *tmp;
front = &xstfb->textures[ST_ATTACHMENT_FRONT_LEFT];
back = &xstfb->textures[ST_ATTACHMENT_BACK_LEFT];
%rename(Device) st_device;
%rename(Context) st_context;
-%rename(Texture) pipe_texture;
+%rename(Resource) pipe_resource;
%rename(Surface) st_surface;
-%rename(Buffer) pipe_buffer;
%rename(BlendColor) pipe_blend_color;
%rename(Blend) pipe_blend_state;
}
void set_constant_buffer(unsigned shader, unsigned index,
- struct pipe_buffer *buffer )
+ struct pipe_resource *buffer )
{
$self->pipe->set_constant_buffer($self->pipe, shader, index, buffer);
}
}
void set_fragment_sampler_texture(unsigned index,
- struct pipe_texture *texture) {
+ struct pipe_resource *texture) {
struct pipe_sampler_view templ;
if(!texture)
}
void set_vertex_sampler_texture(unsigned index,
- struct pipe_texture *texture) {
+ struct pipe_resource *texture) {
struct pipe_sampler_view templ;
if(!texture)
unsigned stride,
unsigned max_index,
unsigned buffer_offset,
- struct pipe_buffer *buffer)
+ struct pipe_resource *buffer)
{
unsigned i;
struct pipe_vertex_buffer state;
$self->pipe->draw_arrays($self->pipe, mode, start, count);
}
- void draw_elements( struct pipe_buffer *indexBuffer,
+ void draw_elements( struct pipe_resource *indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
mode, start, count);
}
- void draw_range_elements( struct pipe_buffer *indexBuffer,
+ void draw_range_elements( struct pipe_resource *indexBuffer,
unsigned indexSize, unsigned minIndex, unsigned maxIndex,
unsigned mode, unsigned start, unsigned count)
{
{
struct pipe_context *pipe = $self->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_buffer *vbuf;
+ struct pipe_resource *vbuf;
+ struct pipe_transfer *transfer;
struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
struct pipe_vertex_buffer vbuffer;
float *map;
size = num_verts * num_attribs * 4 * sizeof(float);
vbuf = pipe_buffer_create(screen,
- 32,
- PIPE_BUFFER_USAGE_VERTEX,
+ PIPE_BIND_VERTEX_BUFFER,
size);
if(!vbuf)
goto error1;
-
- map = pipe_buffer_map(screen, vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
+
+ map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer);
if (!map)
goto error2;
memcpy(map, vertices, size);
- pipe_buffer_unmap(screen, vbuf);
+ pipe_buffer_unmap(pipe, vbuf, transfer);
cso_save_vertex_elements($self->cso);
cso_restore_vertex_elements($self->cso);
error2:
- pipe_buffer_reference(&vbuf, NULL);
+ pipe_resource_reference(&vbuf, NULL);
error1:
;
}
struct pipe_surface *_dst = NULL;
struct pipe_surface *_src = NULL;
- _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
+ _dst = st_pipe_surface(dst, PIPE_BIND_BLIT_DESTINATION);
if(!_dst)
SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
- _src = st_pipe_surface(src, PIPE_BUFFER_USAGE_GPU_READ);
+ _src = st_pipe_surface(src, PIPE_BIND_BLIT_SOURCE);
if(!_src)
SWIG_exception(SWIG_ValueError, "couldn't acquire source surface for reading");
{
struct pipe_surface *_dst = NULL;
- _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
+ _dst = st_pipe_surface(dst, PIPE_BIND_BLIT_DESTINATION);
if(!_dst)
SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
unsigned x, unsigned y, unsigned w, unsigned h,
char **STRING, int *LENGTH)
{
- struct pipe_texture *texture = surface->texture;
+ struct pipe_resource *texture = surface->texture;
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
unsigned stride;
if(!*STRING)
return;
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_READ,
- x, y, w, h);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_READ,
+ x, y, w, h);
if(transfer) {
pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
}
unsigned x, unsigned y, unsigned w, unsigned h,
const char *STRING, unsigned LENGTH, unsigned stride = 0)
{
- struct pipe_texture *texture = surface->texture;
+ struct pipe_resource *texture = surface->texture;
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_WRITE,
- x, y, w, h);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_WRITE,
+ x, y, w, h);
if(!transfer)
SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
fail:
return;
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_READ,
- x, y, w, h);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_READ,
+ x, y, w, h);
if(transfer) {
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
}
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_WRITE,
- x, y, w, h);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_WRITE,
+ x, y, w, h);
if(transfer) {
pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
}
rgba8 = (unsigned char *) *STRING;
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_READ,
- x, y,
- w, h);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_READ,
+ x, y, w, h);
if(transfer) {
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
for(j = 0; j < h; ++j) {
for(k = 0; k <4; ++k)
rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
}
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
free(rgba);
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_READ,
- x, y, w, h);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_READ,
+ x, y, w, h);
if(transfer) {
pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
}
{
struct pipe_context *pipe = $self->pipe;
struct pipe_transfer *transfer;
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_WRITE,
- x, y, w, h);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_WRITE,
+ x, y, w, h);
if(transfer) {
pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
}
if(!rgba2)
return ~0;
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_READ,
- x, y, w, h);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_READ,
+ x, y, w, h);
if(!transfer) {
FREE(rgba2);
return ~0;
}
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
p1 = rgba;
p2 = rgba2;
/**
* Check if the given pipe_format is supported as a texture or
* drawing surface.
- * \param type one of PIPE_TEXTURE, PIPE_SURFACE
+ * \param tex_usage bitmask of PIPE_BIND flags
*/
int is_format_supported( enum pipe_format format,
enum pipe_texture_target target,
unsigned geom_flags ) {
/* We can't really display surfaces with the python statetracker so mask
* out that usage */
- tex_usage &= ~PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+ tex_usage &= ~PIPE_BIND_DISPLAY_TARGET;
return $self->screen->is_format_supported( $self->screen,
format,
return st_context_create($self);
}
- struct pipe_texture *
+ struct pipe_resource *
texture_create(
enum pipe_format format,
unsigned width,
enum pipe_texture_target target = PIPE_TEXTURE_2D,
unsigned tex_usage = 0
) {
- struct pipe_texture templat;
+ struct pipe_resource templat;
/* We can't really display surfaces with the python statetracker so mask
* out that usage */
- tex_usage &= ~PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+ tex_usage &= ~PIPE_BIND_DISPLAY_TARGET;
memset(&templat, 0, sizeof(templat));
templat.format = format;
templat.depth0 = depth;
templat.last_level = last_level;
templat.target = target;
- templat.tex_usage = tex_usage;
+ templat.bind = tex_usage;
- return $self->screen->texture_create($self->screen, &templat);
+ return $self->screen->resource_create($self->screen, &templat);
}
-
- struct pipe_buffer *
- buffer_create(unsigned size, unsigned alignment = 0, unsigned usage = 0) {
- return pipe_buffer_create($self->screen, alignment, usage, size);
+
+ struct pipe_resource *
+ buffer_create(unsigned size, unsigned bind = 0) {
+ return pipe_buffer_create($self->screen, bind, size);
}
};
SWIG_exception(SWIG_ValueError, "index out of bounds");
if(surface) {
- _surface = st_pipe_surface(surface, PIPE_BUFFER_USAGE_GPU_WRITE);
+ _surface = st_pipe_surface(surface, PIPE_BIND_RENDER_TARGET);
if(!_surface)
SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing");
}
struct pipe_surface *_surface = NULL;
if(surface) {
- _surface = st_pipe_surface(surface, PIPE_BUFFER_USAGE_GPU_WRITE);
+ _surface = st_pipe_surface(surface, PIPE_BIND_DEPTH_STENCIL);
if(!_surface)
SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing");
}
*/
-%nodefaultctor pipe_texture;
+%nodefaultctor pipe_resource;
%nodefaultctor st_surface;
-%nodefaultctor pipe_buffer;
-%nodefaultdtor pipe_texture;
+%nodefaultdtor pipe_resource;
%nodefaultdtor st_surface;
-%nodefaultdtor pipe_buffer;
-%ignore pipe_texture::screen;
+%ignore pipe_resource::screen;
%immutable st_surface::texture;
%immutable st_surface::face;
%immutable st_surface::level;
%immutable st_surface::zslice;
-%newobject pipe_texture::get_surface;
+%newobject pipe_resource::get_surface;
+/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */
+%rename(read) read_;
+%rename(write) write_;
-%extend pipe_texture {
-
- ~pipe_texture() {
- struct pipe_texture *ptr = $self;
- pipe_texture_reference(&ptr, NULL);
+%extend pipe_resource {
+
+ ~pipe_resource() {
+ struct pipe_resource *ptr = $self;
+ pipe_resource_reference(&ptr, NULL);
}
-
+
unsigned get_width(unsigned level=0) {
return u_minify($self->width0, level);
}
-
+
unsigned get_height(unsigned level=0) {
return u_minify($self->height0, level);
}
-
+
unsigned get_depth(unsigned level=0) {
return u_minify($self->depth0, level);
}
-
+
/** Get a surface which is a "view" into a texture */
struct st_surface *
get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0)
{
struct st_surface *surface;
-
+
if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U))
SWIG_exception(SWIG_ValueError, "face out of bounds");
if(level > $self->last_level)
SWIG_exception(SWIG_ValueError, "level out of bounds");
if(zslice >= u_minify($self->depth0, level))
SWIG_exception(SWIG_ValueError, "zslice out of bounds");
-
+
surface = CALLOC_STRUCT(st_surface);
if(!surface)
return NULL;
-
- pipe_texture_reference(&surface->texture, $self);
+
+ pipe_resource_reference(&surface->texture, $self);
surface->face = face;
surface->level = level;
surface->zslice = zslice;
-
+
return surface;
fail:
return NULL;
}
-
+
+ unsigned __len__(void)
+ {
+ assert($self->target == PIPE_BUFFER);
+ assert(p_atomic_read(&$self->reference.count) > 0);
+ return $self->width0;
+ }
+
+ %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
+ void read_(char **STRING, int *LENGTH)
+ {
+ struct pipe_screen *screen = $self->screen;
+ /* XXX need context here not screen */
+
+ assert($self->target == PIPE_BUFFER);
+ assert(p_atomic_read(&$self->reference.count) > 0);
+
+ *LENGTH = $self->width0;
+ *STRING = (char *) malloc($self->width0);
+ if(!*STRING)
+ return;
+
+ pipe_buffer_read(screen, $self, 0, $self->width0, *STRING);
+ }
+
+ %cstring_input_binary(const char *STRING, unsigned LENGTH);
+ void write_(const char *STRING, unsigned LENGTH, unsigned offset = 0)
+ {
+ struct pipe_screen *screen = $self->screen;
+ /* XXX need context here not screen */
+
+ assert($self->target == PIPE_BUFFER);
+ assert(p_atomic_read(&$self->reference.count) > 0);
+
+ if(offset > $self->width0)
+ SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
+
+ if(offset + LENGTH > $self->width0)
+ SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
+
+ pipe_buffer_write(screen, $self, offset, LENGTH, STRING);
+
+fail:
+ return;
+ }
+
+
};
struct st_surface
{
%immutable;
-
- struct pipe_texture *texture;
+
+ struct pipe_resource *texture;
unsigned face;
unsigned level;
unsigned zslice;
-
+
};
%extend st_surface {
-
+
%immutable;
-
+
unsigned format;
unsigned width;
unsigned height;
-
+
~st_surface() {
- pipe_texture_reference(&$self->texture, NULL);
+ pipe_resource_reference(&$self->texture, NULL);
FREE($self);
}
-
+
};
return u_minify(surface->texture->height0, surface->level);
}
%}
-
-/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */
-%rename(read) read_;
-%rename(write) write_;
-
-%extend pipe_buffer {
-
- ~pipe_buffer() {
- struct pipe_buffer *ptr = $self;
- pipe_buffer_reference(&ptr, NULL);
- }
-
- unsigned __len__(void)
- {
- assert(p_atomic_read(&$self->reference.count) > 0);
- return $self->size;
- }
-
- %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
- void read_(char **STRING, int *LENGTH)
- {
- struct pipe_screen *screen = $self->screen;
-
- assert(p_atomic_read(&$self->reference.count) > 0);
-
- *LENGTH = $self->size;
- *STRING = (char *) malloc($self->size);
- if(!*STRING)
- return;
-
- pipe_buffer_read(screen, $self, 0, $self->size, *STRING);
- }
-
- %cstring_input_binary(const char *STRING, unsigned LENGTH);
- void write_(const char *STRING, unsigned LENGTH, unsigned offset = 0)
- {
- struct pipe_screen *screen = $self->screen;
-
- assert(p_atomic_read(&$self->reference.count) > 0);
-
- if(offset > $self->size)
- SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
-
- if(offset + LENGTH > $self->size)
- SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
-
- pipe_buffer_write(screen, $self, offset, LENGTH, STRING);
-
-fail:
- return;
- }
-};
pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], NULL);
for(i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], NULL);
- pipe_texture_reference(&st_ctx->default_texture, NULL);
+ pipe_resource_reference(&st_ctx->default_texture, NULL);
FREE(st_ctx);
{
struct pipe_context *pipe = st_ctx->pipe;
struct pipe_screen *screen = st_dev->screen;
- struct pipe_texture templat;
- struct pipe_transfer *transfer;
+ struct pipe_resource templat;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *view;
unsigned i;
templat.depth0 = 1;
templat.last_level = 0;
- st_ctx->default_texture = screen->texture_create( screen, &templat );
+ st_ctx->default_texture = screen->resource_create( screen, &templat );
if(st_ctx->default_texture) {
- transfer = pipe->get_tex_transfer(pipe,
- st_ctx->default_texture,
- 0, 0, 0,
- PIPE_TRANSFER_WRITE,
- 0, 0,
- st_ctx->default_texture->width0,
- st_ctx->default_texture->height0);
- if (transfer) {
- uint32_t *map;
- map = (uint32_t *) pipe->transfer_map(pipe, transfer);
- if(map) {
- *map = 0x00000000;
- pipe->transfer_unmap(pipe, transfer);
- }
- pipe->tex_transfer_destroy(pipe, transfer);
- }
+ struct pipe_box box;
+ uint32_t zero = 0;
+
+ u_box_origin_2d( 1, 1, &box );
+
+ pipe->transfer_inline_write(pipe,
+ st_ctx->default_texture,
+ u_subresource(0,0),
+ PIPE_TRANSFER_WRITE,
+ &box,
+ &zero,
+ sizeof zero,
+ 0);
}
u_sampler_view_default_template(&view_templ,
struct st_surface
{
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
unsigned face;
unsigned level;
unsigned zslice;
void *fs;
void *gs;
- struct pipe_texture *default_texture;
+ struct pipe_resource *default_texture;
struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
static INLINE struct pipe_surface *
st_pipe_surface(struct st_surface *surface, unsigned usage)
{
- struct pipe_texture *texture = surface->texture;
+ struct pipe_resource *texture = surface->texture;
struct pipe_screen *screen = texture->screen;
return screen->get_tex_surface(screen, texture, surface->face, surface->level, surface->zslice, usage);
}
float *rgba,
boolean norm)
{
- struct pipe_texture *texture = surface->texture;
+ struct pipe_resource *texture = surface->texture;
unsigned width = u_minify(texture->width0, surface->level);
unsigned height = u_minify(texture->height0, surface->level);
uint rgba_stride = width * 4;
struct pipe_transfer *transfer;
void *raw;
- transfer = pipe->get_tex_transfer(pipe,
- surface->texture,
- surface->face,
- surface->level,
- surface->zslice,
- PIPE_TRANSFER_WRITE,
- 0, 0,
- width,
- height);
+ transfer = pipe_get_transfer(pipe,
+ surface->texture,
+ surface->face,
+ surface->level,
+ surface->zslice,
+ PIPE_TRANSFER_WRITE,
+ 0, 0,
+ width,
+ height);
if (!transfer)
return;
pipe->transfer_unmap(pipe, transfer);
}
-
- pipe->tex_transfer_destroy(pipe, transfer);
+
+ pipe->transfer_destroy(pipe, transfer);
}
struct pipe_sampler_view *extra_texture_view;
};
-static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx,
+static INLINE struct pipe_resource *create_texture_1d(struct vg_context *ctx,
const VGuint *color_data,
const VGint color_data_len)
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture *tex = 0;
- struct pipe_texture templ;
+ struct pipe_resource *tex = 0;
+ struct pipe_resource templ;
memset(&templ, 0, sizeof(templ));
templ.target = PIPE_TEXTURE_1D;
templ.width0 = color_data_len;
templ.height0 = 1;
templ.depth0 = 1;
- templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ templ.bind = PIPE_BIND_SAMPLER_VIEW;
- tex = screen->texture_create(screen, &templ);
+ tex = screen->resource_create(screen, &templ);
{ /* upload color_data */
struct pipe_transfer *transfer =
- pipe->get_tex_transfer(pipe, tex,
+ pipe_get_transfer(pipe, tex,
0, 0, 0,
PIPE_TRANSFER_READ_WRITE ,
0, 0, tex->width0, tex->height0);
void *map = pipe->transfer_map(pipe, transfer);
memcpy(map, color_data, sizeof(VGint)*color_data_len);
pipe->transfer_unmap(pipe, transfer);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
return tex;
const VGint color_data_len)
{
struct pipe_context *pipe = ctx->pipe;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *view;
u_sampler_view_default_template(&view_templ, texture, texture->format);
view = pipe->create_sampler_view(pipe, texture, &view_templ);
/* want the texture to go away if the view is freed */
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&texture, NULL);
return view;
}
struct pipe_framebuffer_state fb;
struct pipe_surface *dst_surf = pipe->screen->get_tex_surface(
pipe->screen, dst->sampler_view->texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET);
/* drawing dest */
memset(&fb, 0, sizeof(fb));
VGint param_bytes)
{
struct pipe_context *pipe = ctx->pipe;
- struct pipe_buffer **cbuf = &ctx->filter.buffer;
+ struct pipe_resource **cbuf = &ctx->filter.buffer;
/* We always need to get a new buffer, to keep the drivers simple and
* avoid gratuitous rendering synchronization. */
- pipe_buffer_reference(cbuf, NULL);
+ pipe_resource_reference(cbuf, NULL);
- *cbuf = pipe_buffer_create(pipe->screen, 16,
- PIPE_BUFFER_USAGE_CONSTANT,
+ *cbuf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_CONSTANT_BUFFER,
param_bytes);
if (*cbuf) {
{
struct pipe_transfer *transfer;
- transfer = pipe->get_tex_transfer(pipe, strb->texture, 0, 0, 0,
- PIPE_TRANSFER_READ,
- 0, 0, width, height);
+ transfer = pipe_get_transfer(pipe, strb->texture, 0, 0, 0,
+ PIPE_TRANSFER_READ,
+ 0, 0, width, height);
/* Do a row at a time to flip image data vertically */
for (i = 0; i < height; i++) {
dst += dataStride;
}
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
}
const VGfloat color[4])
{
struct pipe_context *pipe = st->pipe;
- struct pipe_buffer *buf;
+ struct pipe_resource *buf;
VGuint i;
/* positions */
/* put vertex data into vbuf */
buf = pipe_user_buffer_create(pipe->screen,
st->clear.vertices,
- sizeof(st->clear.vertices));
+ sizeof(st->clear.vertices),
+ PIPE_BIND_VERTEX_BUFFER);
/* draw */
4, /* verts */
2); /* attribs/vert */
- pipe_buffer_reference(&buf, NULL);
+ pipe_resource_reference(&buf, NULL);
}
}
static void vg_copy_texture(struct vg_context *ctx,
- struct pipe_texture *dst, VGint dx, VGint dy,
+ struct pipe_resource *dst, VGint dx, VGint dy,
struct pipe_sampler_view *src, VGint sx, VGint sy,
VGint width, VGint height)
{
}
-static struct pipe_texture *image_texture(struct vg_image *img)
+static struct pipe_resource *image_texture(struct vg_image *img)
{
- struct pipe_texture *tex = img->sampler_view->texture;
+ struct pipe_resource *tex = img->sampler_view->texture;
return tex;
}
struct pipe_context *pipe = ctx->pipe;
struct vg_image *image = CALLOC_STRUCT(vg_image);
enum pipe_format pformat = vg_format_to_pipe(format);
- struct pipe_texture pt, *newtex;
+ struct pipe_resource pt, *newtex;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *view;
struct pipe_screen *screen = ctx->pipe->screen;
image->sampler.normalized_coords = 1;
assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0));
+ PIPE_BIND_SAMPLER_VIEW, 0));
memset(&pt, 0, sizeof(pt));
pt.target = PIPE_TEXTURE_2D;
pt.width0 = width;
pt.height0 = height;
pt.depth0 = 1;
- pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ pt.bind = PIPE_BIND_SAMPLER_VIEW;
- newtex = screen->texture_create(screen, &pt);
+ newtex = screen->resource_create(screen, &pt);
debug_assert(newtex);
u_sampler_view_default_template(&view_templ, newtex, newtex->format);
view = pipe->create_sampler_view(pipe, newtex, &view_templ);
/* want the texture to go away if the view is freed */
- pipe_texture_reference(&newtex, NULL);
+ pipe_resource_reference(&newtex, NULL);
image->sampler_view = view;
VGint i;
struct vg_context *ctx = vg_current_context();
struct pipe_context *pipe = ctx->pipe;
- struct pipe_texture *texture = image_texture(image);
+ struct pipe_resource *texture = image_texture(image);
VGint xoffset = 0, yoffset = 0;
if (x < 0) {
}
{ /* upload color_data */
- struct pipe_transfer *transfer = pipe->get_tex_transfer(
+ struct pipe_transfer *transfer = pipe_get_transfer(
pipe, texture, 0, 0, 0,
PIPE_TRANSFER_WRITE, 0, 0, texture->width0, texture->height0);
src += (dataStride * yoffset);
y += yStep;
src += dataStride;
}
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
}
{
struct pipe_transfer *transfer =
- pipe->get_tex_transfer(pipe,
+ pipe_get_transfer(pipe,
image->sampler_view->texture, 0, 0, 0,
PIPE_TRANSFER_READ,
0, 0,
dst += dataStride;
}
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
}
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
surf = screen->get_tex_surface(screen, image_texture(src), 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ);
+ PIPE_BIND_BLIT_SOURCE);
vg_copy_surface(ctx, strb->surface, dx, dy,
surf, sx+src->x, sy+src->y, width, height);
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
surf = screen->get_tex_surface(screen, image_texture(dst), 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE |
- PIPE_BUFFER_USAGE_GPU_READ);
+ PIPE_BIND_BLIT_SOURCE);
+
vg_copy_surface(ctx, surf, dst->x + dx, dst->y + dy,
strb->surface, sx, sy, width, height);
#include "vg_context.h"
#include "pipe/p_state.h"
-struct pipe_texture;
+struct pipe_resource;
struct array;
struct vg_context;
struct pipe_surface;
struct pipe_surface *surf;
surf = screen->get_tex_surface(screen, strb->texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_BIND_TRANSFER_READ);
/* Do a row at a time to flip image data vertically */
for (i = 0; i < height; i++) {
static void setup_mask_operation(VGMaskOperation operation)
{
struct vg_context *ctx = vg_current_context();
- struct pipe_buffer **cbuf = &ctx->mask.cbuf;
+ struct pipe_resource **cbuf = &ctx->mask.cbuf;
const VGint param_bytes = 4 * sizeof(VGfloat);
const VGfloat ones[4] = {1.f, 1.f, 1.f, 1.f};
void *shader = 0;
/* We always need to get a new buffer, to keep the drivers simple and
* avoid gratuitous rendering synchronization.
*/
- pipe_buffer_reference(cbuf, NULL);
+ pipe_resource_reference(cbuf, NULL);
- *cbuf = pipe_buffer_create(ctx->pipe->screen, 1,
- PIPE_BUFFER_USAGE_CONSTANT,
+ *cbuf = pipe_buffer_create(ctx->pipe->screen,
+ PIPE_BIND_CONSTANT_BUFFER,
param_bytes);
if (*cbuf) {
st_no_flush_pipe_buffer_write(ctx, *cbuf,
static void setup_mask_fill(const VGfloat color[4])
{
struct vg_context *ctx = vg_current_context();
- struct pipe_buffer **cbuf = &ctx->mask.cbuf;
+ struct pipe_resource **cbuf = &ctx->mask.cbuf;
const VGint param_bytes = 4 * sizeof(VGfloat);
/* We always need to get a new buffer, to keep the drivers simple and
* avoid gratuitous rendering synchronization.
*/
- pipe_buffer_reference(cbuf, NULL);
+ pipe_resource_reference(cbuf, NULL);
- *cbuf = pipe_buffer_create(ctx->pipe->screen, 1,
- PIPE_BUFFER_USAGE_CONSTANT,
+ *cbuf = pipe_buffer_create(ctx->pipe->screen,
+ PIPE_BIND_CONSTANT_BUFFER,
param_bytes);
if (*cbuf) {
st_no_flush_pipe_buffer_write(ctx, *cbuf, 0, param_bytes, color);
VGint width, VGint height)
{
struct vg_context *ctx = vg_current_context();
- struct pipe_texture *texture = sampler_view->texture;
+ struct pipe_resource *texture = sampler_view->texture;
struct pipe_surface *surface =
- alpha_mask_surface(ctx, PIPE_BUFFER_USAGE_GPU_WRITE);
+ alpha_mask_surface(ctx, PIPE_BIND_RENDER_TARGET);
VGint offsets[4], loc[4];
if (!surface)
mask->height = height;
{
- struct pipe_texture pt;
+ struct pipe_resource pt;
struct pipe_context *pipe = ctx->pipe;
struct pipe_screen *screen = ctx->pipe->screen;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *view = NULL;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
memset(&pt, 0, sizeof(pt));
pt.target = PIPE_TEXTURE_2D;
pt.width0 = width;
pt.height0 = height;
pt.depth0 = 1;
- pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ pt.bind = PIPE_BIND_SAMPLER_VIEW;
pt.compressed = 0;
- texture = screen->texture_create(screen, &pt);
+ texture = screen->resource_create(screen, &pt);
if (texture) {
u_sampler_view_default_template(&view_templ, texture, texture->format);
view = pipe->create_sampler_view(pipe, texture, &view_templ);
}
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&texture, NULL);
mask->sampler_view = view;
}
struct vg_context *ctx = vg_current_context();
vg_context_remove_object(ctx, VG_OBJECT_MASK, layer);
- pipe_texture_release(&layer->texture);
+ pipe_resource_release(&layer->texture);
free(layer);
}
surface = ctx->pipe->screen->get_tex_surface(
ctx->pipe->screen, layer->sampler_view->texture,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET);
surface_fill(surface,
layer->width, layer->height,
struct pipe_surface *surface;
surface = screen->get_tex_surface(screen, layer->sampler_view->texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET);
cso_save_framebuffer(ctx->cso_context);
cso_save_fragment_shader(ctx->cso_context);
struct vg_context *ctx = vg_current_context();
VGfloat alpha_color[4] = {.0f, .0f, .0f, value};
struct pipe_surface *surf = alpha_mask_surface(
- ctx, PIPE_BUFFER_USAGE_GPU_WRITE);
+ ctx, PIPE_BIND_RENDER_TARGET);
#if DEBUG_MASKS
debug_printf("mask_fill(%d, %d, %d, %d) with rgba(%f, %f, %f, %f)\n",
struct path;
struct vg_image;
-struct pipe_texture;
+struct pipe_resource;
struct vg_mask_layer *mask_layer_create(VGint width, VGint height);
void mask_layer_destroy(struct vg_mask_layer *layer);
} pattern;
/* XXX next 3 all unneded? */
- struct pipe_buffer *cbuf;
+ struct pipe_resource *cbuf;
struct pipe_shader_state fs_state;
void *fs;
};
data[size-1] = last_color;
}
-static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p)
+static INLINE struct pipe_resource *create_gradient_texture(struct vg_paint *p)
{
struct pipe_context *pipe = p->base.ctx->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture *tex = 0;
- struct pipe_texture templ;
+ struct pipe_resource *tex = 0;
+ struct pipe_resource templ;
memset(&templ, 0, sizeof(templ));
templ.target = PIPE_TEXTURE_1D;
templ.width0 = 1024;
templ.height0 = 1;
templ.depth0 = 1;
- templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ templ.bind = PIPE_BIND_SAMPLER_VIEW;
- tex = screen->texture_create(screen, &templ);
+ tex = screen->resource_create(screen, &templ);
{ /* upload color_data */
struct pipe_transfer *transfer =
- st_no_flush_get_tex_transfer(p->base.ctx, tex, 0, 0, 0,
+ st_no_flush_get_transfer(p->base.ctx, tex, 0, 0, 0,
PIPE_TRANSFER_WRITE, 0, 0, 1024, 1);
void *map = pipe->transfer_map(pipe, transfer);
memcpy(map, p->gradient.color_data, sizeof(VGint)*1024);
pipe->transfer_unmap(pipe, transfer);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
return tex;
static INLINE struct pipe_sampler_view *create_gradient_sampler_view(struct vg_paint *p)
{
struct pipe_context *pipe = p->base.ctx->pipe;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *view;
u_sampler_view_default_template(&view_templ, texture, texture->format);
view = pipe->create_sampler_view(pipe, texture, &view_templ);
/* want the texture to go away if the view is freed */
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&texture, NULL);
return view;
}
struct vg_paint;
struct vg_image;
struct pipe_sampler_state;
-struct pipe_texture;
+struct pipe_resource;
struct vg_paint *paint_create(struct vg_context *ctx);
void paint_destroy(struct vg_paint *paint);
VGint num_verts;
VGboolean dirty;
- struct pipe_buffer *vbuf;
+ struct pipe_resource *vbuf;
struct pipe_screen *screen;
};
void polygon_destroy(struct polygon *poly)
{
if (poly->vbuf)
- pipe_buffer_reference(&poly->vbuf, NULL);
+ pipe_resource_reference(&poly->vbuf, NULL);
free(poly->data);
free(poly);
if (poly->vbuf == NULL || poly->dirty) {
if (poly->vbuf) {
- pipe_buffer_reference(&poly->vbuf,
+ pipe_resource_reference(&poly->vbuf,
NULL);
}
poly->screen = pipe->screen;
poly->vbuf= pipe_user_buffer_create(poly->screen,
poly->data,
- vert_size);
+ vert_size,
+ PIPE_BIND_VERTEX_BUFFER);
poly->dirty = VG_FALSE;
}
ctx->fs = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D);
}
-static struct pipe_buffer *
+static struct pipe_resource *
setup_vertex_data(struct renderer *ctx,
float x0, float y0, float x1, float y1, float z)
{
return pipe_user_buffer_create( ctx->pipe->screen,
ctx->vertices,
- sizeof(ctx->vertices) );
+ sizeof(ctx->vertices),
+ PIPE_BIND_VERTEX_BUFFER);
}
-static struct pipe_buffer *
+static struct pipe_resource *
setup_vertex_data_tex(struct renderer *ctx,
float x0, float y0, float x1, float y1,
float s0, float t0, float s1, float t1,
return pipe_user_buffer_create( ctx->pipe->screen,
ctx->vertices,
- sizeof(ctx->vertices) );
+ sizeof(ctx->vertices),
+ PIPE_BIND_VERTEX_BUFFER);
}
-static struct pipe_buffer *
+static struct pipe_resource *
setup_vertex_data_qtex(struct renderer *ctx,
float x0, float y0, float x1, float y1,
float x2, float y2, float x3, float y3,
return pipe_user_buffer_create( ctx->pipe->screen,
ctx->vertices,
- sizeof(ctx->vertices) );
+ sizeof(ctx->vertices),
+ PIPE_BIND_VERTEX_BUFFER);
}
struct renderer * renderer_create(struct vg_context *owner)
VGfloat x2, VGfloat y2,
VGfloat depth)
{
- struct pipe_buffer *buf;
+ struct pipe_resource *buf;
buf = setup_vertex_data(r, x1, y1, x2, y2, depth);
4, /* verts */
2); /* attribs/vert */
- pipe_buffer_reference( &buf,
+ pipe_resource_reference( &buf,
NULL );
}
}
void renderer_draw_texture(struct renderer *r,
- struct pipe_texture *tex,
+ struct pipe_resource *tex,
VGfloat x1offset, VGfloat y1offset,
VGfloat x2offset, VGfloat y2offset,
VGfloat x1, VGfloat y1,
VGfloat x2, VGfloat y2)
{
struct pipe_context *pipe = r->pipe;
- struct pipe_buffer *buf;
+ struct pipe_resource *buf;
VGfloat s0, t0, s1, t1;
assert(tex->width0 != 0);
4, /* verts */
2); /* attribs/vert */
- pipe_buffer_reference( &buf,
+ pipe_resource_reference( &buf,
NULL );
}
struct pipe_sampler_view *src,
VGfloat sx1, VGfloat sy1,
VGfloat sx2, VGfloat sy2,
- struct pipe_texture *dst,
+ struct pipe_resource *dst,
VGfloat dx1, VGfloat dy1,
VGfloat dx2, VGfloat dy2)
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture *tex = src->texture;
- struct pipe_buffer *buf;
+ struct pipe_resource *tex = src->texture;
+ struct pipe_resource *buf;
struct pipe_surface *dst_surf = screen->get_tex_surface(
screen, dst, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET);
struct pipe_framebuffer_state fb;
float s0, t0, s1, t1;
#endif
assert(screen->is_format_supported(screen, dst_surf->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
+ PIPE_BIND_RENDER_TARGET, 0));
/* save state (restored below) */
cso_save_blend(ctx->cso);
4, /* verts */
2); /* attribs/vert */
- pipe_buffer_reference( &buf,
+ pipe_resource_reference( &buf,
NULL );
}
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_buffer *buf;
+ struct pipe_resource *buf;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *view;
- struct pipe_texture texTemp, *tex;
+ struct pipe_resource texTemp, *tex;
struct pipe_surface *texSurf;
struct pipe_framebuffer_state fb;
struct st_framebuffer *stfb = ctx->owner->draw_buffer;
}
assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0));
+ PIPE_BIND_SAMPLER_VIEW, 0));
assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0));
+ PIPE_BIND_SAMPLER_VIEW, 0));
assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0));
+ PIPE_BIND_RENDER_TARGET, 0));
/*
* XXX for now we're always creating a temporary texture.
texTemp.height0 = srcH;
texTemp.depth0 = 1;
- tex = screen->texture_create(screen, &texTemp);
+ tex = screen->resource_create(screen, &texTemp);
if (!tex)
return;
return;
texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET);
/* load temp texture */
if (pipe->surface_copy) {
4, /* verts */
2); /* attribs/vert */
- pipe_buffer_reference( &buf,
+ pipe_resource_reference( &buf,
NULL );
}
cso_restore_vertex_shader(ctx->cso);
cso_restore_viewport(ctx->cso);
- pipe_texture_reference(&tex, NULL);
+ pipe_resource_reference(&tex, NULL);
pipe_sampler_view_reference(&view, NULL);
}
void renderer_texture_quad(struct renderer *r,
- struct pipe_texture *tex,
+ struct pipe_resource *tex,
VGfloat x1offset, VGfloat y1offset,
VGfloat x2offset, VGfloat y2offset,
VGfloat x1, VGfloat y1,
VGfloat x4, VGfloat y4)
{
struct pipe_context *pipe = r->pipe;
- struct pipe_buffer *buf;
+ struct pipe_resource *buf;
VGfloat s0, t0, s1, t1;
assert(tex->width0 != 0);
4, /* verts */
2); /* attribs/vert */
- pipe_buffer_reference(&buf,
+ pipe_resource_reference(&buf,
NULL);
}
struct renderer;
struct vg_context;
-struct pipe_texture;
+struct pipe_resource;
struct pipe_sampler_view;
struct pipe_surface;
VGfloat x2, VGfloat y2,
VGfloat depth);
void renderer_draw_texture(struct renderer *,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
VGfloat x1offset, VGfloat y1offset,
VGfloat x2offset, VGfloat y2offset,
VGfloat x1, VGfloat y1,
VGfloat x2, VGfloat y2);
void renderer_texture_quad(struct renderer *,
- struct pipe_texture *texture,
+ struct pipe_resource *texture,
VGfloat x1offset, VGfloat y1offset,
VGfloat x2offset, VGfloat y2offset,
VGfloat x1, VGfloat y1,
struct pipe_sampler_view *src,
VGfloat sx1, VGfloat sy1,
VGfloat sx2, VGfloat sy2,
- struct pipe_texture *dst,
+ struct pipe_resource *dst,
VGfloat dx1, VGfloat dy1,
VGfloat dx2, VGfloat dy2);
void renderer_copy_surface(struct renderer *r,
VGImageMode image_mode;
float constants[MAX_CONSTANTS];
- struct pipe_buffer *cbuf;
+ struct pipe_resource *cbuf;
struct pipe_shader_state fs_state;
void *fs;
};
{
struct vg_context *ctx = shader->context;
struct pipe_context *pipe = shader->context->pipe;
- struct pipe_buffer **cbuf = &shader->cbuf;
+ struct pipe_resource **cbuf = &shader->cbuf;
VGint param_bytes = paint_constant_buffer_size(shader->paint);
float temp_buf[MAX_CONSTANTS];
if (*cbuf == NULL ||
memcmp(temp_buf, shader->constants, param_bytes) != 0)
{
- pipe_buffer_reference(cbuf, NULL);
+ pipe_resource_reference(cbuf, NULL);
memcpy(shader->constants, temp_buf, param_bytes);
*cbuf = pipe_user_buffer_create(pipe->screen,
&shader->constants,
- sizeof(shader->constants));
+ sizeof(shader->constants),
+ PIPE_BIND_VERTEX_BUFFER);
}
ctx->pipe->set_constant_buffer(ctx->pipe, PIPE_SHADER_FRAGMENT, 0, *cbuf);
#include "pipe/p_state.h"
static INLINE struct pipe_transfer *
-st_cond_flush_get_tex_transfer(struct vg_context *st,
- struct pipe_texture *pt,
+st_cond_flush_get_transfer(struct vg_context *st,
+ struct pipe_resource *pt,
unsigned int face,
unsigned int level,
unsigned int zslice,
unsigned int w, unsigned int h)
{
struct pipe_context *pipe = st->pipe;
- unsigned referenced =
- pipe->is_texture_referenced(pipe, pt, face, level);
- if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
- (usage & PIPE_TRANSFER_WRITE)))
- vgFlush();
-
- return pipe->get_tex_transfer(pipe, pt, face, level, zslice, usage,
- x, y, w, h);
+ return pipe_get_transfer(pipe, pt, face, level, zslice, usage,
+ x, y, w, h);
}
static INLINE struct pipe_transfer *
-st_no_flush_get_tex_transfer(struct vg_context *st,
- struct pipe_texture *pt,
+st_no_flush_get_transfer(struct vg_context *st,
+ struct pipe_resource *pt,
unsigned int face,
unsigned int level,
unsigned int zslice,
{
struct pipe_context *pipe = st->pipe;
- return pipe->get_tex_transfer(pipe, pt, face, level,
- zslice, usage, x, y, w, h);
-}
-
-static INLINE void *
-st_cond_flush_pipe_buffer_map(struct vg_context *st,
- struct pipe_buffer *buf,
- unsigned int map_flags)
-{
- struct pipe_context *pipe = st->pipe;
- unsigned int referenced = pipe->is_buffer_referenced(pipe, buf);
-
- if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
- (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE)))
- vgFlush();
-
- return pipe_buffer_map(pipe->screen, buf, map_flags);
-}
-
-static INLINE void *
-st_no_flush_pipe_buffer_map(struct vg_context *st,
- struct pipe_buffer *buf,
- unsigned int map_flags)
-{
- return pipe_buffer_map(st->pipe->screen, buf, map_flags);
+ return pipe_get_transfer(pipe, pt, face, level,
+ zslice, usage, x, y, w, h);
}
static INLINE void
st_cond_flush_pipe_buffer_write(struct vg_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
const void * data)
{
struct pipe_context *pipe = st->pipe;
- if (pipe->is_buffer_referenced(pipe, buf))
- vgFlush();
-
- pipe_buffer_write(pipe->screen, buf, offset, size, data);
+ pipe_buffer_write(pipe, buf, offset, size, data);
}
static INLINE void
st_no_flush_pipe_buffer_write(struct vg_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
const void * data)
{
- pipe_buffer_write(st->pipe->screen, buf, offset, size, data);
+ pipe_buffer_write(st->pipe, buf, offset, size, data);
}
static INLINE void
st_cond_flush_pipe_buffer_read(struct vg_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
void * data)
{
struct pipe_context *pipe = st->pipe;
- if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE)
- vgFlush();
-
- pipe_buffer_read(pipe->screen, buf, offset, size, data);
+ pipe_buffer_read(pipe, buf, offset, size, data);
}
static INLINE void
st_no_flush_pipe_buffer_read(struct vg_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
void * data)
{
- pipe_buffer_read(st->pipe->screen, buf, offset, size, data);
+ pipe_buffer_read(st->pipe, buf, offset, size, data);
}
#endif
void vg_destroy_context(struct vg_context *ctx)
{
- struct pipe_buffer **cbuf = &ctx->mask.cbuf;
- struct pipe_buffer **vsbuf = &ctx->vs_const_buffer;
+ struct pipe_resource **cbuf = &ctx->mask.cbuf;
+ struct pipe_resource **vsbuf = &ctx->vs_const_buffer;
util_destroy_blit(ctx->blit);
renderer_destroy(ctx->renderer);
paint_destroy(ctx->default_paint);
if (*cbuf)
- pipe_buffer_reference(cbuf, NULL);
+ pipe_resource_reference(cbuf, NULL);
if (*vsbuf)
- pipe_buffer_reference(vsbuf, NULL);
+ pipe_resource_reference(vsbuf, NULL);
if (ctx->clear.fs) {
cso_delete_fragment_shader(ctx->cso_context, ctx->clear.fs);
2.f/fb->width, 2.f/fb->height, 1, 1,
-1, -1, 0, 0
};
- struct pipe_buffer **cbuf = &ctx->vs_const_buffer;
+ struct pipe_resource **cbuf = &ctx->vs_const_buffer;
vg_set_viewport(ctx, VEGA_Y0_BOTTOM);
- pipe_buffer_reference(cbuf, NULL);
- *cbuf = pipe_buffer_create(ctx->pipe->screen, 16,
- PIPE_BUFFER_USAGE_CONSTANT,
- param_bytes);
+ pipe_resource_reference(cbuf, NULL);
+ *cbuf = pipe_buffer_create(ctx->pipe->screen,
+ PIPE_BIND_CONSTANT_BUFFER,
+ param_bytes);
if (*cbuf) {
st_no_flush_pipe_buffer_write(ctx, *cbuf,
dest_surface = pipe->screen->get_tex_surface(pipe->screen,
stfb->blend_texture_view->texture,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION |
+ PIPE_BIND_RENDER_TARGET);
/* flip it, because we want to use it as a sampler */
util_blit_pixels_tex(ctx->blit,
view,
dest_surface = pipe->screen->get_tex_surface(pipe->screen,
stfb->blend_texture_view->texture,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION |
+ PIPE_BIND_RENDER_TARGET);
/* flip it, because we want to use it as a sampler */
util_blit_pixels_tex(ctx->blit,
struct st_renderbuffer {
enum pipe_format format;
struct pipe_surface *surface;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
VGint width, height;
};
} clear;
struct {
- struct pipe_buffer *cbuf;
+ struct pipe_resource *cbuf;
struct pipe_sampler_state sampler;
struct vg_shader *union_fs;
struct cso_context *cso_context;
- struct pipe_buffer *stencil_quad;
+ struct pipe_resource *stencil_quad;
VGfloat stencil_vertices[4][2][4];
struct renderer *renderer;
struct pipe_sampler_state blend_sampler;
struct {
- struct pipe_buffer *buffer;
+ struct pipe_resource *buffer;
void *color_matrix_fs;
} filter;
struct vg_paint *default_paint;
struct vg_shader *plain_vs;
struct vg_shader *clear_vs;
struct vg_shader *texture_vs;
- struct pipe_buffer *vs_const_buffer;
+ struct pipe_resource *vs_const_buffer;
struct pipe_vertex_element velems[2];
};
struct pipe_screen *screen = ctx->pipe->screen;
struct st_framebuffer *stfb = ctx->draw_buffer;
struct st_renderbuffer *rb;
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
/* no binding surface */
if (!stfb)
rb = stfb->strb;
if (rb->texture == pt) {
- pipe_texture_reference(&pt, NULL);
+ pipe_resource_reference(&pt, NULL);
return;
}
/* unreference existing ones */
pipe_surface_reference(&rb->surface, NULL);
- pipe_texture_reference(&rb->texture, NULL);
+ pipe_resource_reference(&rb->texture, NULL);
rb->texture = pt;
rb->surface = screen->get_tex_surface(screen, rb->texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION);
rb->width = rb->surface->width;
rb->height = rb->surface->height;
destroy_renderbuffer(struct st_renderbuffer *strb)
{
pipe_surface_reference(&strb->surface, NULL);
- pipe_texture_reference(&strb->texture, NULL);
+ pipe_resource_reference(&strb->texture, NULL);
free(strb);
}
/* advertise OpenVG support */
PUBLIC const int st_api_OpenVG = 1;
-static struct pipe_texture *
+static struct pipe_resource *
create_texture(struct pipe_context *pipe, enum pipe_format format,
VGint width, VGint height)
{
- struct pipe_texture templ;
+ struct pipe_resource templ;
memset(&templ, 0, sizeof(templ));
templ.last_level = 0;
if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) {
- templ.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ templ.bind = PIPE_BIND_DEPTH_STENCIL;
} else {
- templ.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_RENDER_TARGET |
- PIPE_TEXTURE_USAGE_SAMPLER);
+ templ.bind = (PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_SAMPLER_VIEW);
}
- return pipe->screen->texture_create(pipe->screen, &templ);
+ return pipe->screen->resource_create(pipe->screen, &templ);
}
static struct pipe_sampler_view *
create_tex_and_view(struct pipe_context *pipe, enum pipe_format format,
VGint width, VGint height)
{
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *view;
u_sampler_view_default_template(&view_templ, texture, texture->format);
view = pipe->create_sampler_view(pipe, texture, &view_templ);
/* want the texture to go away if the view is freed */
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&texture, NULL);
return view;
}
/* Free the old surface and texture
*/
pipe_surface_reference(&strb->surface, NULL);
- pipe_texture_reference(&strb->texture, NULL);
+ pipe_resource_reference(&strb->texture, NULL);
/* Probably need dedicated flags for surface usage too:
*/
- surface_usage = (PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ surface_usage = (PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION);
strb->texture = create_texture(pipe, strb->format, width, height);
pipe->screen,
stfb->alpha_mask_view->texture,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_BLIT_DESTINATION);
struct pipe_surface *old_surface = pipe->screen->get_tex_surface(
pipe->screen,
old_sampler_view->texture,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ);
+ PIPE_BIND_BLIT_SOURCE);
if (pipe->surface_copy) {
pipe->surface_copy(pipe,
surface,
/* unreference existing surfaces */
pipe_surface_reference( &rb->surface, NULL );
- pipe_texture_reference( &rb->texture, NULL );
+ pipe_resource_reference( &rb->texture, NULL );
/* reference new ones */
pipe_surface_reference( &rb->surface, surf );
- pipe_texture_reference( &rb->texture, surf->texture );
+ pipe_resource_reference( &rb->texture, surf->texture );
rb->width = surf->width;
rb->height = surf->height;
}
int st_get_framebuffer_texture(struct st_framebuffer *stfb,
- uint surfIndex, struct pipe_texture **tex)
+ uint surfIndex, struct pipe_resource **tex)
{
struct st_renderbuffer *rb = stfb->strb;
*tex = rb->texture;
PUBLIC
int st_get_framebuffer_texture(struct st_framebuffer *stfb,
- uint surfIndex, struct pipe_texture **tex);
+ uint surfIndex, struct pipe_resource **tex);
PUBLIC
void *st_framebuffer_private(struct st_framebuffer *stfb);
const struct stw_pf_color_info *color = &stw_pf_color[j];
if(!screen->is_format_supported(screen, color->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET |
- PIPE_TEXTURE_USAGE_DISPLAY_TARGET, 0))
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_DISPLAY_TARGET, 0))
continue;
for(k = 0; k < Elements(stw_pf_doublebuffer); ++k) {
const struct stw_pf_depth_info *depth = &stw_pf_depth_stencil[l];
if(!screen->is_format_supported(screen, depth->format, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0))
+ PIPE_BIND_DEPTH_STENCIL, 0))
continue;
stw_pixelformat_add( stw_dev, color, depth, 0, doublebuffer, samples );
drmModeCrtcPtr drm_crtc;
/* hwcursor */
- struct pipe_texture *cursor_tex;
+ struct pipe_resource *cursor_tex;
struct kms_bo *cursor_bo;
unsigned cursor_handle;
struct pipe_transfer *transfer;
if (!crtcp->cursor_tex) {
- struct pipe_texture templat;
+ struct pipe_resource templat;
struct winsys_handle whandle;
memset(&templat, 0, sizeof(templat));
- templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
- templat.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT;
+ templat.bind |= PIPE_BIND_RENDER_TARGET;
+ templat.bind |= PIPE_BIND_SCANOUT;
templat.target = PIPE_TEXTURE_2D;
templat.last_level = 0;
templat.depth0 = 1;
memset(&whandle, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_KMS;
- crtcp->cursor_tex = ms->screen->texture_create(ms->screen,
+ crtcp->cursor_tex = ms->screen->resource_create(ms->screen,
&templat);
- ms->screen->texture_get_handle(ms->screen, crtcp->cursor_tex, &whandle);
+ ms->screen->resource_get_handle(ms->screen, crtcp->cursor_tex, &whandle);
crtcp->cursor_handle = whandle.handle;
}
- transfer = ms->ctx->get_tex_transfer(ms->ctx, crtcp->cursor_tex,
+ transfer = pipe_get_transfer(ms->ctx, crtcp->cursor_tex,
0, 0, 0,
PIPE_TRANSFER_WRITE,
0, 0, 64, 64);
transfer->stride, 0, 0,
64, 64, (void*)image, 64 * 4, 0, 0);
ms->ctx->transfer_unmap(ms->ctx, transfer);
- ms->ctx->tex_transfer_destroy(ms->ctx, transfer);
+ ms->ctx->transfer_destroy(ms->ctx, transfer);
}
#if HAVE_LIBKMS
struct crtc_private *crtcp = crtc->driver_private;
if (crtcp->cursor_tex)
- pipe_texture_reference(&crtcp->cursor_tex, NULL);
+ pipe_resource_reference(&crtcp->cursor_tex, NULL);
#ifdef HAVE_LIBKMS
if (crtcp->cursor_bo)
kms_bo_destroy(&crtcp->cursor_bo);
typedef struct {
PixmapPtr pPixmap;
- struct pipe_texture *tex;
+ struct pipe_resource *tex;
struct pipe_fence_handle *fence;
} *BufferPrivatePtr;
static Bool
dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int format)
{
- struct pipe_texture *tex = NULL;
+ struct pipe_resource *tex = NULL;
ScreenPtr pScreen = pDraw->pScreen;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
modesettingPtr ms = modesettingPTR(pScrn);
/* Fall through */
case DRI2BufferDepth:
if (exa_priv->depth_stencil_tex)
- pipe_texture_reference(&tex, exa_priv->depth_stencil_tex);
+ pipe_resource_reference(&tex, exa_priv->depth_stencil_tex);
else {
- struct pipe_texture template;
+ struct pipe_resource template;
unsigned depthBits = (format != 0) ? format : pDraw->depth;
memset(&template, 0, sizeof(template));
template.target = PIPE_TEXTURE_2D;
template.height0 = pDraw->height;
template.depth0 = 1;
template.last_level = 0;
- template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL |
- PIPE_TEXTURE_USAGE_SHARED;
- tex = ms->screen->texture_create(ms->screen, &template);
- pipe_texture_reference(&exa_priv->depth_stencil_tex, tex);
+ template.bind = PIPE_BIND_DEPTH_STENCIL |
+ PIPE_BIND_SHARED;
+ tex = ms->screen->resource_create(ms->screen, &template);
+ pipe_resource_reference(&exa_priv->depth_stencil_tex, tex);
}
break;
}
memset(&whandle, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_SHARED;
- ms->screen->texture_get_handle(ms->screen, tex, &whandle);
+ ms->screen->resource_get_handle(ms->screen, tex, &whandle);
buffer->name = whandle.handle;
buffer->pitch = whandle.stride;
BufferPrivatePtr private = buffer->driverPrivate;
struct exa_pixmap_priv *exa_priv = exaGetPixmapDriverPrivate(private->pPixmap);
- pipe_texture_reference(&private->tex, NULL);
+ pipe_resource_reference(&private->tex, NULL);
ms->screen->fence_reference(ms->screen, &private->fence, NULL);
- pipe_texture_reference(&exa_priv->depth_stencil_tex, NULL);
+ pipe_resource_reference(&exa_priv->depth_stencil_tex, NULL);
(*pScreen->DestroyPixmap)(private->pPixmap);
}
ms->d_depth_bits_last =
ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24X8_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ PIPE_BIND_DEPTH_STENCIL, 0);
ms->ds_depth_bits_last =
ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
+ PIPE_BIND_DEPTH_STENCIL, 0);
return DRI2ScreenInit(pScreen, &dri2info);
}
ms->fb_id = -1;
}
- pipe_texture_reference(&ms->root_texture, NULL);
+ pipe_resource_reference(&ms->root_texture, NULL);
return TRUE;
}
drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn)
{
modesettingPtr ms = modesettingPTR(pScrn);
- struct pipe_texture *tex;
+ struct pipe_resource *tex;
struct winsys_handle whandle;
unsigned fb_id;
int ret;
memset(&whandle, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_KMS;
- if (!ms->screen->texture_get_handle(ms->screen, tex, &whandle))
+ if (!ms->screen->resource_get_handle(ms->screen, tex, &whandle))
goto err_destroy;
ret = drmModeAddFB(ms->fd,
pScrn->frameY0 = 0;
drv_adjust_frame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
- pipe_texture_reference(&ms->root_texture, tex);
- pipe_texture_reference(&tex, NULL);
+ pipe_resource_reference(&ms->root_texture, tex);
+ pipe_resource_reference(&tex, NULL);
ms->fb_id = fb_id;
return TRUE;
err_destroy:
- pipe_texture_reference(&tex, NULL);
+ pipe_resource_reference(&tex, NULL);
return FALSE;
}
modesettingPtr ms = modesettingPTR(pScrn);
ScreenPtr pScreen = pScrn->pScreen;
PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
- struct pipe_texture *check;
+ struct pipe_resource *check;
xorg_exa_set_displayed_usage(rootPixmap);
xorg_exa_set_shared_usage(rootPixmap);
if (ms->root_texture != check)
FatalError("Created new root texture\n");
- pipe_texture_reference(&check, NULL);
+ pipe_resource_reference(&check, NULL);
return TRUE;
}
if (!priv || !priv->tex)
return FALSE;
- transfer = exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0,
+ transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0,
PIPE_TRANSFER_READ, x, y, w, h);
if (!transfer)
return FALSE;
transfer->stride, 0, 0);
exa->pipe->transfer_unmap(exa->pipe, transfer);
- exa->pipe->tex_transfer_destroy(exa->pipe, transfer);
+ exa->pipe->transfer_destroy(exa->pipe, transfer);
return TRUE;
}
if (!priv || !priv->tex)
return FALSE;
- transfer = exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0,
+ transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0,
PIPE_TRANSFER_WRITE, x, y, w, h);
if (!transfer)
return FALSE;
(unsigned char*)src, src_pitch, 0, 0);
exa->pipe->transfer_unmap(exa->pipe, transfer);
- exa->pipe->tex_transfer_destroy(exa->pipe, transfer);
+ exa->pipe->transfer_destroy(exa->pipe, transfer);
return TRUE;
}
assert(pPix->drawable.height <= priv->tex->height0);
priv->map_transfer =
- exa->pipe->get_tex_transfer(exa->pipe, priv->tex, 0, 0, 0,
+ pipe_get_transfer(exa->pipe, priv->tex, 0, 0, 0,
#ifdef EXA_MIXED_PIXMAPS
PIPE_TRANSFER_MAP_DIRECTLY |
#endif
if (--priv->map_count == 0) {
assert(priv->map_transfer);
exa->pipe->transfer_unmap(exa->pipe, priv->map_transfer);
- exa->pipe->tex_transfer_destroy(exa->pipe, priv->map_transfer);
+ exa->pipe->transfer_destroy(exa->pipe, priv->map_transfer);
priv->map_transfer = NULL;
pPix->devPrivate.ptr = NULL;
}
if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
priv->tex->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ PIPE_BIND_RENDER_TARGET, 0)) {
XORG_FALLBACK("format %s", util_format_name(priv->tex->format));
}
if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
priv->tex->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0))
+ PIPE_BIND_RENDER_TARGET, 0))
XORG_FALLBACK("pDst format %s", util_format_name(priv->tex->format));
if (!exa->scrn->is_format_supported(exa->scrn, src_priv->tex->format,
src_priv->tex->target,
- PIPE_TEXTURE_USAGE_SAMPLER, 0))
+ PIPE_BIND_SAMPLER_VIEW, 0))
XORG_FALLBACK("pSrc format %s", util_format_name(src_priv->tex->format));
exa->copy.src = src_priv;
exa->scrn->get_tex_surface( exa->scrn,
exa->copy.src->tex,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ);
+ PIPE_BIND_BLIT_SOURCE);
exa->copy.dst_surface =
exa->scrn->get_tex_surface( exa->scrn,
exa->copy.dst->tex,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE );
+ PIPE_BIND_BLIT_DESTINATION );
}
else {
exa->copy.use_surface_copy = FALSE;
exa->copy.src_texture = renderer_clone_texture( exa->renderer,
exa->copy.src->tex );
else
- pipe_texture_reference(&exa->copy.src_texture,
+ pipe_resource_reference(&exa->copy.src_texture,
exa->copy.src->tex);
exa->copy.dst_surface =
exa->scrn->get_tex_surface(exa->scrn,
exa->copy.dst->tex,
0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
renderer_copy_prepare(exa->renderer,
exa->copy.dst = NULL;
pipe_surface_reference(&exa->copy.src_surface, NULL);
pipe_surface_reference(&exa->copy.dst_surface, NULL);
- pipe_texture_reference(&exa->copy.src_texture, NULL);
+ pipe_resource_reference(&exa->copy.src_texture, NULL);
}
if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
priv->tex->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0))
+ PIPE_BIND_RENDER_TARGET, 0))
XORG_FALLBACK("pDst format: %s", util_format_name(priv->tex->format));
if (priv->picture_format != pDstPicture->format)
if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
priv->tex->target,
- PIPE_TEXTURE_USAGE_SAMPLER, 0))
+ PIPE_BIND_SAMPLER_VIEW, 0))
XORG_FALLBACK("pSrc format: %s", util_format_name(priv->tex->format));
if (!picture_check_formats(priv, pSrcPicture))
if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
priv->tex->target,
- PIPE_TEXTURE_USAGE_SAMPLER, 0))
+ PIPE_BIND_SAMPLER_VIEW, 0))
XORG_FALLBACK("pMask format: %s", util_format_name(priv->tex->format));
if (!picture_check_formats(priv, pMaskPicture))
if (!priv)
return;
- pipe_texture_reference(&priv->tex, NULL);
+ pipe_resource_reference(&priv->tex, NULL);
xfree(priv);
}
return 0;
}
- priv->flags |= PIPE_TEXTURE_USAGE_SCANOUT;
+ priv->flags |= PIPE_BIND_SCANOUT;
return 0;
}
return 0;
}
- priv->flags |= PIPE_TEXTURE_USAGE_SHARED;
+ priv->flags |= PIPE_BIND_SHARED;
return 0;
}
!size_match(width, priv->tex->width0) ||
!size_match(height, priv->tex->height0) ||
priv->tex_flags != priv->flags)) {
- struct pipe_texture *texture = NULL;
- struct pipe_texture template;
+ struct pipe_resource *texture = NULL;
+ struct pipe_resource template;
memset(&template, 0, sizeof(template));
template.target = PIPE_TEXTURE_2D;
template.depth0 = 1;
template.last_level = 0;
- template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET | priv->flags;
+ template.bind = PIPE_BIND_RENDER_TARGET | priv->flags;
priv->tex_flags = priv->flags;
- texture = exa->scrn->texture_create(exa->scrn, &template);
+ texture = exa->scrn->resource_create(exa->scrn, &template);
if (priv->tex) {
struct pipe_surface *dst_surf;
struct pipe_surface *src_surf;
dst_surf = exa->scrn->get_tex_surface(
- exa->scrn, texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE);
+ exa->scrn, texture, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION);
src_surf = xorg_gpu_surface(exa->pipe->screen, priv);
if (exa->pipe->surface_copy) {
exa->pipe->surface_copy(exa->pipe, dst_surf, 0, 0, src_surf,
exa->scrn->tex_surface_destroy(src_surf);
}
- pipe_texture_reference(&priv->tex, texture);
+ pipe_resource_reference(&priv->tex, texture);
/* the texture we create has one reference */
- pipe_texture_reference(&texture, NULL);
+ pipe_resource_reference(&texture, NULL);
}
return TRUE;
}
-struct pipe_texture *
+struct pipe_resource *
xorg_exa_get_texture(PixmapPtr pPixmap)
{
struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
- struct pipe_texture *tex = NULL;
- pipe_texture_reference(&tex, priv->tex);
+ struct pipe_resource *tex = NULL;
+ pipe_resource_reference(&tex, priv->tex);
return tex;
}
Bool
-xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_texture *tex)
+xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_resource *tex)
{
struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
- int mask = PIPE_TEXTURE_USAGE_SHARED | PIPE_TEXTURE_USAGE_SCANOUT;
+ int mask = PIPE_BIND_SHARED | PIPE_BIND_SCANOUT;
if (!priv)
return FALSE;
pPixmap->drawable.height != tex->height0)
return FALSE;
- pipe_texture_reference(&priv->tex, tex);
- priv->tex_flags = tex->tex_usage & mask;
+ pipe_resource_reference(&priv->tex, tex);
+ priv->tex_flags = tex->bind & mask;
return TRUE;
}
-struct pipe_texture *
+struct pipe_resource *
xorg_exa_create_root_texture(ScrnInfoPtr pScrn,
int width, int height,
int depth, int bitsPerPixel)
{
modesettingPtr ms = modesettingPTR(pScrn);
struct exa_context *exa = ms->exa;
- struct pipe_texture template;
+ struct pipe_resource template;
int dummy;
memset(&template, 0, sizeof(template));
template.height0 = height;
template.depth0 = 1;
template.last_level = 0;
- template.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
- template.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT;
- template.tex_usage |= PIPE_TEXTURE_USAGE_SHARED;
+ template.bind |= PIPE_BIND_RENDER_TARGET;
+ template.bind |= PIPE_BIND_SCANOUT;
+ template.bind |= PIPE_BIND_SHARED;
- return exa->scrn->texture_create(exa->scrn, &template);
+ return exa->scrn->resource_create(exa->scrn, &template);
}
void
struct pipe_surface *
xorg_gpu_surface(struct pipe_screen *scrn, struct exa_pixmap_priv *priv)
{
+
+ /* seems to get called both for blits and render target usage */
return scrn->get_tex_surface(scrn, priv->tex, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION |
+ PIPE_BIND_RENDER_TARGET);
}
struct pipe_surface *src_surface;
struct pipe_surface *dst_surface;
- struct pipe_texture *src_texture;
+ struct pipe_resource *src_texture;
} copy;
};
int picture_format;
- struct pipe_texture *tex;
- struct pipe_texture *depth_stencil_tex;
+ struct pipe_resource *tex;
+ struct pipe_resource *depth_stencil_tex;
struct pipe_transfer *map_transfer;
unsigned map_count;
}
}
-static INLINE struct pipe_buffer *
+static INLINE struct pipe_resource *
renderer_buffer_create(struct xorg_renderer *r)
{
- struct pipe_buffer *buf =
+ struct pipe_resource *buf =
pipe_user_buffer_create(r->pipe->screen,
r->buffer,
sizeof(float)*
- r->buffer_size);
+ r->buffer_size,
+/* XXX was: PIPE_BUFFER_USAGE_PIXEL/PIPE_BUFFER_USAGE_GPU_WRITE even though this is a vertex buffer??? */
+ PIPE_BIND_VERTEX_BUFFER);
r->buffer_size = 0;
return buf;
renderer_draw(struct xorg_renderer *r)
{
struct pipe_context *pipe = r->pipe;
- struct pipe_buffer *buf = 0;
+ struct pipe_resource *buf = 0;
int num_verts = r->buffer_size/(r->attrs_per_vertex * NUM_COMPONENTS);
if (!r->buffer_size)
num_verts, /* verts */
r->attrs_per_vertex); /* attribs/vert */
- pipe_buffer_reference(&buf, NULL);
+ pipe_resource_reference(&buf, NULL);
}
}
add_vertex_data1(struct xorg_renderer *r,
float srcX, float srcY, float dstX, float dstY,
float width, float height,
- struct pipe_texture *src, float *src_matrix)
+ struct pipe_resource *src, float *src_matrix)
{
float s0, t0, s1, t1, s2, t2, s3, t3;
float pt0[2], pt1[2], pt2[2], pt3[2];
add_vertex_data2(struct xorg_renderer *r,
float srcX, float srcY, float maskX, float maskY,
float dstX, float dstY, float width, float height,
- struct pipe_texture *src,
- struct pipe_texture *mask,
+ struct pipe_resource *src,
+ struct pipe_resource *mask,
float *src_matrix, float *mask_matrix)
{
float src_s0, src_t0, src_s1, src_t1;
src_s0, src_t1, mask_s0, mask_t1);
}
-static struct pipe_buffer *
+static struct pipe_resource *
setup_vertex_data_yuv(struct xorg_renderer *r,
float srcX, float srcY, float srcW, float srcH,
float dstX, float dstY, float dstW, float dstH,
- struct pipe_texture **tex)
+ struct pipe_resource **tex)
{
float s0, t0, s1, t1;
float spt0[2], spt1[2];
void renderer_destroy(struct xorg_renderer *r)
{
- struct pipe_buffer **vsbuf = &r->vs_const_buffer;
- struct pipe_buffer **fsbuf = &r->fs_const_buffer;
+ struct pipe_resource **vsbuf = &r->vs_const_buffer;
+ struct pipe_resource **fsbuf = &r->fs_const_buffer;
if (*vsbuf)
- pipe_buffer_reference(vsbuf, NULL);
+ pipe_resource_reference(vsbuf, NULL);
if (*fsbuf)
- pipe_buffer_reference(fsbuf, NULL);
+ pipe_resource_reference(fsbuf, NULL);
if (r->shaders) {
xorg_shaders_destroy(r->shaders);
const float *params,
int param_bytes)
{
- struct pipe_buffer **cbuf =
+ struct pipe_resource **cbuf =
(shader_type == PIPE_SHADER_VERTEX) ? &r->vs_const_buffer :
&r->fs_const_buffer;
- pipe_buffer_reference(cbuf, NULL);
- *cbuf = pipe_buffer_create(r->pipe->screen, 16,
- PIPE_BUFFER_USAGE_CONSTANT,
+ pipe_resource_reference(cbuf, NULL);
+ *cbuf = pipe_buffer_create(r->pipe->screen,
+ PIPE_BIND_CONSTANT_BUFFER,
param_bytes);
if (*cbuf) {
- pipe_buffer_write(r->pipe->screen, *cbuf,
+ pipe_buffer_write(r->pipe, *cbuf,
0, param_bytes, params);
}
r->pipe->set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
void renderer_copy_prepare(struct xorg_renderer *r,
struct pipe_surface *dst_surface,
- struct pipe_texture *src_texture)
+ struct pipe_resource *src_texture)
{
struct pipe_context *pipe = r->pipe;
struct pipe_screen *screen = pipe->screen;
assert(screen->is_format_supported(screen, dst_surface->format,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET,
+ PIPE_BIND_RENDER_TARGET,
0));
(void) screen;
r->attrs_per_vertex = 2;
}
-struct pipe_texture *
+struct pipe_resource *
renderer_clone_texture(struct xorg_renderer *r,
- struct pipe_texture *src)
+ struct pipe_resource *src)
{
enum pipe_format format;
struct pipe_context *pipe = r->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture *pt;
- struct pipe_texture templ;
+ struct pipe_resource *pt;
+ struct pipe_resource templ;
- if (pipe->is_texture_referenced(pipe, src, 0, 0) &
+ if (pipe->is_resource_referenced(pipe, src, 0, 0) &
PIPE_REFERENCED_FOR_WRITE)
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
/* the coming in texture should already have that invariance */
debug_assert(screen->is_format_supported(screen, src->format,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0));
+ PIPE_BIND_SAMPLER_VIEW, 0));
format = src->format;
templ.width0 = src->width0;
templ.height0 = src->height0;
templ.depth0 = 1;
- templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ templ.bind = PIPE_BIND_SAMPLER_VIEW;
- pt = screen->texture_create(screen, &templ);
+ pt = screen->resource_create(screen, &templ);
debug_assert(!pt || pipe_is_referenced(&pt->reference));
{
/* copy source framebuffer surface into texture */
struct pipe_surface *ps_read = screen->get_tex_surface(
- screen, src, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ);
+ screen, src, 0, 0, 0, PIPE_BIND_BLIT_SOURCE);
struct pipe_surface *ps_tex = screen->get_tex_surface(
- screen, pt, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE );
+ screen, pt, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION );
if (pipe->surface_copy) {
pipe->surface_copy(pipe,
ps_tex, /* dest */
void renderer_draw_yuv(struct xorg_renderer *r,
int src_x, int src_y, int src_w, int src_h,
int dst_x, int dst_y, int dst_w, int dst_h,
- struct pipe_texture **textures)
+ struct pipe_resource **textures)
{
struct pipe_context *pipe = r->pipe;
- struct pipe_buffer *buf = 0;
+ struct pipe_resource *buf = 0;
buf = setup_vertex_data_yuv(r,
src_x, src_y, src_w, src_h,
4, /* verts */
num_attribs); /* attribs/vert */
- pipe_buffer_reference(&buf, NULL);
+ pipe_resource_reference(&buf, NULL);
}
}
int fb_width;
int fb_height;
- struct pipe_buffer *vs_const_buffer;
- struct pipe_buffer *fs_const_buffer;
+ struct pipe_resource *vs_const_buffer;
+ struct pipe_resource *fs_const_buffer;
float buffer[BUF_SIZE];
int buffer_size;
void renderer_draw_yuv(struct xorg_renderer *r,
int src_x, int src_y, int src_w, int src_h,
int dst_x, int dst_y, int dst_w, int dst_h,
- struct pipe_texture **textures);
+ struct pipe_resource **textures);
void renderer_begin_solid(struct xorg_renderer *r);
void renderer_solid(struct xorg_renderer *r,
void renderer_draw_flush(struct xorg_renderer *r);
-struct pipe_texture *
+struct pipe_resource *
renderer_clone_texture(struct xorg_renderer *r,
- struct pipe_texture *src);
+ struct pipe_resource *src);
void renderer_copy_prepare(struct xorg_renderer *r,
struct pipe_surface *dst_surface,
- struct pipe_texture *src_texture);
+ struct pipe_resource *src_texture);
void renderer_copy_pixmap(struct xorg_renderer *r,
int dx, int dy,
struct pipe_context *ctx;
boolean d_depth_bits_last;
boolean ds_depth_bits_last;
- struct pipe_texture *root_texture;
+ struct pipe_resource *root_texture;
/* exa */
struct exa_context *exa;
/***********************************************************************
* xorg_exa.c
*/
-struct pipe_texture *
+struct pipe_resource *
xorg_exa_get_texture(PixmapPtr pPixmap);
int
xorg_exa_set_shared_usage(PixmapPtr pPixmap);
Bool
-xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_texture *tex);
+xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_resource *tex);
-struct pipe_texture *
+struct pipe_resource *
xorg_exa_create_root_texture(ScrnInfoPtr pScrn,
int width, int height,
int depth, int bpp);
int current_set;
/* juggle two sets of seperate Y, U and V
* textures */
- struct pipe_texture *yuv[2][3];
+ struct pipe_resource *yuv[2][3];
struct pipe_sampler_view *yuv_views[2][3];
};
*p_h = drw_h;
}
-static INLINE struct pipe_texture *
+static INLINE struct pipe_resource *
create_component_texture(struct pipe_context *pipe,
int width, int height)
{
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture *tex = 0;
- struct pipe_texture templ;
+ struct pipe_resource *tex = 0;
+ struct pipe_resource templ;
memset(&templ, 0, sizeof(templ));
templ.target = PIPE_TEXTURE_2D;
templ.width0 = width;
templ.height0 = height;
templ.depth0 = 1;
- templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ templ.bind = PIPE_BIND_SAMPLER_VIEW;
- tex = screen->texture_create(screen, &templ);
+ tex = screen->resource_create(screen, &templ);
return tex;
}
static int
check_yuv_textures(struct xorg_xv_port_priv *priv, int width, int height)
{
- struct pipe_texture **dst = priv->yuv[priv->current_set];
+ struct pipe_resource **dst = priv->yuv[priv->current_set];
struct pipe_sampler_view **dst_view = priv->yuv_views[priv->current_set];
struct pipe_sampler_view view_templ;
struct pipe_context *pipe = priv->r->pipe;
if (!dst[0] ||
dst[0]->width0 != width ||
dst[0]->height0 != height) {
- pipe_texture_reference(&dst[0], NULL);
+ pipe_resource_reference(&dst[0], NULL);
pipe_sampler_view_reference(&dst_view[0], NULL);
}
if (!dst[1] ||
dst[1]->width0 != width ||
dst[1]->height0 != height) {
- pipe_texture_reference(&dst[1], NULL);
+ pipe_resource_reference(&dst[1], NULL);
pipe_sampler_view_reference(&dst_view[1], NULL);
}
if (!dst[2] ||
dst[2]->width0 != width ||
dst[2]->height0 != height) {
- pipe_texture_reference(&dst[2], NULL);
+ pipe_resource_reference(&dst[2], NULL);
pipe_sampler_view_reference(&dst_view[2], NULL);
}
unsigned short w, unsigned short h)
{
int i, j;
- struct pipe_texture **dst = port->yuv[port->current_set];
+ struct pipe_resource **dst = port->yuv[port->current_set];
struct pipe_transfer *ytrans, *utrans, *vtrans;
struct pipe_context *pipe = port->r->pipe;
char *ymap, *vmap, *umap;
int yidx, uidx, vidx;
int y_array_size = w * h;
- ytrans = pipe->get_tex_transfer(pipe, dst[0],
+ ytrans = pipe_get_transfer(pipe, dst[0],
0, 0, 0,
PIPE_TRANSFER_WRITE,
left, top, w, h);
- utrans = pipe->get_tex_transfer(pipe, dst[1],
+ utrans = pipe_get_transfer(pipe, dst[1],
0, 0, 0,
PIPE_TRANSFER_WRITE,
left, top, w, h);
- vtrans = pipe->get_tex_transfer(pipe, dst[2],
+ vtrans = pipe_get_transfer(pipe, dst[2],
0, 0, 0,
PIPE_TRANSFER_WRITE,
left, top, w, h);
pipe->transfer_unmap(pipe, ytrans);
pipe->transfer_unmap(pipe, utrans);
pipe->transfer_unmap(pipe, vtrans);
- pipe->tex_transfer_destroy(pipe, ytrans);
- pipe->tex_transfer_destroy(pipe, utrans);
- pipe->tex_transfer_destroy(pipe, vtrans);
+ pipe->transfer_destroy(pipe, ytrans);
+ pipe->transfer_destroy(pipe, utrans);
+ pipe->transfer_destroy(pipe, vtrans);
}
int src_x, int src_y, int src_w, int src_h,
int dst_x, int dst_y, int dst_w, int dst_h)
{
- struct pipe_texture **textures = port->yuv[port->current_set];
+ struct pipe_resource **textures = port->yuv[port->current_set];
/*debug_printf(" draw_yuv([%d, %d, %d ,%d], [%d, %d, %d, %d])\n",
src_x, src_y, src_w, src_h,
}
static INLINE void
-conditional_flush(struct pipe_context *pipe, struct pipe_texture **tex,
+conditional_flush(struct pipe_context *pipe, struct pipe_resource **tex,
int num)
{
int i;
for (i = 0; i < num; ++i) {
- if (tex[i] && pipe->is_texture_referenced(pipe, tex[i], 0, 0) &
+ if (tex[i] && pipe->is_resource_referenced(pipe, tex[i], 0, 0) &
PIPE_REFERENCED_FOR_WRITE) {
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
return;
{
struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
struct pipe_sampler_state sampler;
- struct pipe_texture **dst = port->yuv[port->current_set];
+ struct pipe_resource **dst = port->yuv[port->current_set];
struct pipe_sampler_view **dst_views = port->yuv_views[port->current_set];
memset(&sampler, 0, sizeof(struct pipe_sampler_state));
+++ /dev/null
-TOP = ../../../../..
-include $(TOP)/configs/current
-
-LIBNAME = xvmctracker
-
-LIBRARY_INCLUDES = \
- $(shell pkg-config --cflags-only-I xvmc) \
- -I$(TOP)/src/gallium/winsys/g3dvl
-
-C_SOURCES = block.c \
- surface.c \
- context.c \
- subpicture.c \
- attributes.c
-
-include ../../../Makefile.template
+++ /dev/null
-#######################################################################
-# SConscript for xvmc state_tracker
-
-Import('*')
-
-if 'xorg/xvmc' in env['statetrackers']:
-
- env = env.Clone()
-
- env.Append(CPPPATH = [
- '#/src/gallium/include',
- '#/src/gallium/auxiliary',
- '#/src/gallium/winsys/g3dvl',
- ])
-
- env.ParseConfig('pkg-config --cflags --libs xvmc')
-
- st_xvmc = env.ConvenienceLibrary(
- target = 'st_xvmc',
- source = [ 'block.c',
- 'surface.c',
- 'context.c',
- 'subpicture.c',
- 'attributes.c',
- ]
- )
- Export('st_xvmc')
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <X11/Xlib.h>
-#include <X11/extensions/Xvlib.h>
-#include <X11/extensions/XvMClib.h>
-
-XvAttribute* XvMCQueryAttributes(Display *dpy, XvMCContext *context, int *number)
-{
- return NULL;
-}
-
-Status XvMCSetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int value)
-{
- return BadImplementation;
-}
-
-Status XvMCGetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int *value)
-{
- return BadImplementation;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <X11/Xlib.h>
-#include <X11/extensions/XvMClib.h>
-#include <util/u_memory.h>
-#include "xvmc_private.h"
-
-Status XvMCCreateBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCBlockArray *blocks)
-{
- assert(dpy);
-
- if (!context)
- return XvMCBadContext;
- if (num_blocks == 0)
- return BadValue;
-
- assert(blocks);
-
- blocks->context_id = context->context_id;
- blocks->num_blocks = num_blocks;
- blocks->blocks = MALLOC(BLOCK_SIZE_BYTES * num_blocks);
- blocks->privData = NULL;
-
- return Success;
-}
-
-Status XvMCDestroyBlocks(Display *dpy, XvMCBlockArray *blocks)
-{
- assert(dpy);
- assert(blocks);
- FREE(blocks->blocks);
-
- return Success;
-}
-
-Status XvMCCreateMacroBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCMacroBlockArray *blocks)
-{
- assert(dpy);
-
- if (!context)
- return XvMCBadContext;
- if (num_blocks == 0)
- return BadValue;
-
- assert(blocks);
-
- blocks->context_id = context->context_id;
- blocks->num_blocks = num_blocks;
- blocks->macro_blocks = MALLOC(sizeof(XvMCMacroBlock) * num_blocks);
- blocks->privData = NULL;
-
- return Success;
-}
-
-Status XvMCDestroyMacroBlocks(Display *dpy, XvMCMacroBlockArray *blocks)
-{
- assert(dpy);
- assert(blocks);
- FREE(blocks->macro_blocks);
-
- return Success;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <X11/Xlibint.h>
-#include <X11/extensions/XvMClib.h>
-#include <pipe/p_screen.h>
-#include <pipe/p_video_context.h>
-#include <pipe/p_video_state.h>
-#include <pipe/p_state.h>
-#include <vl_winsys.h>
-#include <util/u_memory.h>
-#include <util/u_debug.h>
-#include <vl/vl_csc.h>
-#include "xvmc_private.h"
-
-static Status Validate(Display *dpy, XvPortID port, int surface_type_id,
- unsigned int width, unsigned int height, int flags,
- bool *found_port, int *screen, int *chroma_format,
- int *mc_type, int *surface_flags)
-{
- bool found_surface = false;
- XvAdaptorInfo *adaptor_info;
- unsigned int num_adaptors;
- int num_types;
- unsigned int max_width, max_height;
- Status ret;
-
- assert(dpy);
- assert(found_port);
- assert(screen);
- assert(chroma_format);
- assert(mc_type);
- assert(surface_flags);
-
- *found_port = false;
-
- for (unsigned int i = 0; i < XScreenCount(dpy); ++i) {
- ret = XvQueryAdaptors(dpy, XRootWindow(dpy, i), &num_adaptors, &adaptor_info);
- if (ret != Success)
- return ret;
-
- for (unsigned int j = 0; j < num_adaptors && !*found_port; ++j) {
- for (unsigned int k = 0; k < adaptor_info[j].num_ports && !*found_port; ++k) {
- XvMCSurfaceInfo *surface_info;
-
- if (adaptor_info[j].base_id + k != port)
- continue;
-
- *found_port = true;
-
- surface_info = XvMCListSurfaceTypes(dpy, adaptor_info[j].base_id, &num_types);
- if (!surface_info) {
- XvFreeAdaptorInfo(adaptor_info);
- return BadAlloc;
- }
-
- for (unsigned int l = 0; l < num_types && !found_surface; ++l) {
- if (surface_info[l].surface_type_id != surface_type_id)
- continue;
-
- found_surface = true;
- max_width = surface_info[l].max_width;
- max_height = surface_info[l].max_height;
- *chroma_format = surface_info[l].chroma_format;
- *mc_type = surface_info[l].mc_type;
- *surface_flags = surface_info[l].flags;
- *screen = i;
- }
-
- XFree(surface_info);
- }
- }
-
- XvFreeAdaptorInfo(adaptor_info);
- }
-
- if (!*found_port)
- return XvBadPort;
- if (!found_surface)
- return BadMatch;
- if (width > max_width || height > max_height)
- return BadValue;
- if (flags != XVMC_DIRECT && flags != 0)
- return BadValue;
-
- return Success;
-}
-
-static enum pipe_video_profile ProfileToPipe(int xvmc_profile)
-{
- if (xvmc_profile & XVMC_MPEG_1)
- assert(0);
- if (xvmc_profile & XVMC_MPEG_2)
- return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
- if (xvmc_profile & XVMC_H263)
- assert(0);
- if (xvmc_profile & XVMC_MPEG_4)
- assert(0);
-
- assert(0);
-
- return -1;
-}
-
-static enum pipe_video_chroma_format FormatToPipe(int xvmc_format)
-{
- switch (xvmc_format) {
- case XVMC_CHROMA_FORMAT_420:
- return PIPE_VIDEO_CHROMA_FORMAT_420;
- case XVMC_CHROMA_FORMAT_422:
- return PIPE_VIDEO_CHROMA_FORMAT_422;
- case XVMC_CHROMA_FORMAT_444:
- return PIPE_VIDEO_CHROMA_FORMAT_444;
- default:
- assert(0);
- }
-
- return -1;
-}
-
-Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id,
- int width, int height, int flags, XvMCContext *context)
-{
- bool found_port;
- int scrn;
- int chroma_format;
- int mc_type;
- int surface_flags;
- Status ret;
- struct pipe_screen *screen;
- struct pipe_video_context *vpipe;
- XvMCContextPrivate *context_priv;
- float csc[16];
-
- assert(dpy);
-
- if (!context)
- return XvMCBadContext;
-
- ret = Validate(dpy, port, surface_type_id, width, height, flags,
- &found_port, &scrn, &chroma_format, &mc_type, &surface_flags);
-
- /* Success and XvBadPort have the same value */
- if (ret != Success || !found_port)
- return ret;
-
- /* XXX: Current limits */
- if (chroma_format != XVMC_CHROMA_FORMAT_420) {
- debug_printf("[XvMCg3dvl] Cannot decode requested surface type. Unsupported chroma format.\n");
- return BadImplementation;
- }
- if (mc_type != (XVMC_MOCOMP | XVMC_MPEG_2)) {
- debug_printf("[XvMCg3dvl] Cannot decode requested surface type. Non-MPEG2/Mocomp acceleration unsupported.\n");
- return BadImplementation;
- }
- if (!(surface_flags & XVMC_INTRA_UNSIGNED)) {
- debug_printf("[XvMCg3dvl] Cannot decode requested surface type. Signed intra unsupported.\n");
- return BadImplementation;
- }
-
- context_priv = CALLOC(1, sizeof(XvMCContextPrivate));
- if (!context_priv)
- return BadAlloc;
-
- /* TODO: Reuse screen if process creates another context */
- screen = vl_screen_create(dpy, scrn);
-
- if (!screen) {
- FREE(context_priv);
- return BadAlloc;
- }
-
- vpipe = vl_video_create(dpy, scrn, screen, ProfileToPipe(mc_type),
- FormatToPipe(chroma_format), width, height);
-
- if (!vpipe) {
- screen->destroy(screen);
- FREE(context_priv);
- return BadAlloc;
- }
-
- /* TODO: Define some Xv attribs to allow users to specify color standard, procamp */
- vl_csc_get_matrix
- (
- debug_get_bool_option("G3DVL_NO_CSC", FALSE) ?
- VL_CSC_COLOR_STANDARD_IDENTITY : VL_CSC_COLOR_STANDARD_BT_601,
- NULL, true, csc
- );
- vpipe->set_csc_matrix(vpipe, csc);
-
- context_priv->vpipe = vpipe;
-
- context->context_id = XAllocID(dpy);
- context->surface_type_id = surface_type_id;
- context->width = width;
- context->height = height;
- context->flags = flags;
- context->port = port;
- context->privData = context_priv;
-
- SyncHandle();
-
- return Success;
-}
-
-Status XvMCDestroyContext(Display *dpy, XvMCContext *context)
-{
- struct pipe_screen *screen;
- struct pipe_video_context *vpipe;
- XvMCContextPrivate *context_priv;
-
- assert(dpy);
-
- if (!context || !context->privData)
- return XvMCBadContext;
-
- context_priv = context->privData;
- vpipe = context_priv->vpipe;
- pipe_surface_reference(&context_priv->backbuffer, NULL);
- screen = vpipe->screen;
- vpipe->destroy(vpipe);
- screen->destroy(screen);
- FREE(context_priv);
- context->privData = NULL;
-
- return Success;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <X11/Xlibint.h>
-#include <X11/extensions/XvMClib.h>
-
-Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture,
- unsigned short width, unsigned short height, int xvimage_id)
-{
- assert(dpy);
-
- if (!context)
- return XvMCBadContext;
-
- assert(subpicture);
-
- /*if (width > || height > )
- return BadValue;*/
-
- /*if (xvimage_id != )
- return BadMatch;*/
-
- subpicture->subpicture_id = XAllocID(dpy);
- subpicture->context_id = context->context_id;
- subpicture->xvimage_id = xvimage_id;
- subpicture->width = width;
- subpicture->height = height;
- subpicture->num_palette_entries = 0;
- subpicture->entry_bytes = 0;
- subpicture->component_order[0] = 0;
- subpicture->component_order[1] = 0;
- subpicture->component_order[2] = 0;
- subpicture->component_order[3] = 0;
- /* TODO: subpicture->privData = ;*/
-
- SyncHandle();
-
- return Success;
-}
-
-Status XvMCClearSubpicture(Display *dpy, XvMCSubpicture *subpicture, short x, short y,
- unsigned short width, unsigned short height, unsigned int color)
-{
- assert(dpy);
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- /* TODO: Assert clear rect is within bounds? Or clip? */
-
- return Success;
-}
-
-Status XvMCCompositeSubpicture(Display *dpy, XvMCSubpicture *subpicture, XvImage *image,
- short srcx, short srcy, unsigned short width, unsigned short height,
- short dstx, short dsty)
-{
- assert(dpy);
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- assert(image);
-
- if (subpicture->xvimage_id != image->id)
- return BadMatch;
-
- /* TODO: Assert rects are within bounds? Or clip? */
-
- return Success;
-}
-
-Status XvMCDestroySubpicture(Display *dpy, XvMCSubpicture *subpicture)
-{
- assert(dpy);
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- return BadImplementation;
-}
-
-Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsigned char *palette)
-{
- assert(dpy);
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- assert(palette);
-
- /* We don't support paletted subpictures */
- return BadMatch;
-}
-
-Status XvMCBlendSubpicture(Display *dpy, XvMCSurface *target_surface, XvMCSubpicture *subpicture,
- short subx, short suby, unsigned short subw, unsigned short subh,
- short surfx, short surfy, unsigned short surfw, unsigned short surfh)
-{
- assert(dpy);
-
- if (!target_surface)
- return XvMCBadSurface;
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- if (target_surface->context_id != subpicture->context_id)
- return BadMatch;
-
- /* TODO: Assert rects are within bounds? Or clip? */
- return Success;
-}
-
-Status XvMCBlendSubpicture2(Display *dpy, XvMCSurface *source_surface, XvMCSurface *target_surface,
- XvMCSubpicture *subpicture, short subx, short suby, unsigned short subw, unsigned short subh,
- short surfx, short surfy, unsigned short surfw, unsigned short surfh)
-{
- assert(dpy);
-
- if (!source_surface || !target_surface)
- return XvMCBadSurface;
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- if (source_surface->context_id != subpicture->context_id)
- return BadMatch;
-
- if (source_surface->context_id != subpicture->context_id)
- return BadMatch;
-
- /* TODO: Assert rects are within bounds? Or clip? */
- return Success;
-}
-
-Status XvMCSyncSubpicture(Display *dpy, XvMCSubpicture *subpicture)
-{
- assert(dpy);
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- return Success;
-}
-
-Status XvMCFlushSubpicture(Display *dpy, XvMCSubpicture *subpicture)
-{
- assert(dpy);
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- return Success;
-}
-
-Status XvMCGetSubpictureStatus(Display *dpy, XvMCSubpicture *subpicture, int *status)
-{
- assert(dpy);
-
- if (!subpicture)
- return XvMCBadSubpicture;
-
- assert(status);
-
- /* TODO */
- *status = 0;
-
- return Success;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <X11/Xlibint.h>
-#include <pipe/p_video_context.h>
-#include <pipe/p_video_state.h>
-#include <pipe/p_state.h>
-#include <util/u_memory.h>
-#include "xvmc_private.h"
-
-static enum pipe_mpeg12_macroblock_type TypeToPipe(int xvmc_mb_type)
-{
- if (xvmc_mb_type & XVMC_MB_TYPE_INTRA)
- return PIPE_MPEG12_MACROBLOCK_TYPE_INTRA;
- if ((xvmc_mb_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)) == XVMC_MB_TYPE_MOTION_FORWARD)
- return PIPE_MPEG12_MACROBLOCK_TYPE_FWD;
- if ((xvmc_mb_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)) == XVMC_MB_TYPE_MOTION_BACKWARD)
- return PIPE_MPEG12_MACROBLOCK_TYPE_BKWD;
- if ((xvmc_mb_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)) == (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD))
- return PIPE_MPEG12_MACROBLOCK_TYPE_BI;
-
- assert(0);
-
- return -1;
-}
-
-static enum pipe_mpeg12_picture_type PictureToPipe(int xvmc_pic)
-{
- switch (xvmc_pic) {
- case XVMC_TOP_FIELD:
- return PIPE_MPEG12_PICTURE_TYPE_FIELD_TOP;
- case XVMC_BOTTOM_FIELD:
- return PIPE_MPEG12_PICTURE_TYPE_FIELD_BOTTOM;
- case XVMC_FRAME_PICTURE:
- return PIPE_MPEG12_PICTURE_TYPE_FRAME;
- default:
- assert(0);
- }
-
- return -1;
-}
-
-static enum pipe_mpeg12_motion_type MotionToPipe(int xvmc_motion_type, int xvmc_dct_type)
-{
- switch (xvmc_motion_type) {
- case XVMC_PREDICTION_FRAME:
- return xvmc_dct_type == XVMC_DCT_TYPE_FIELD ?
- PIPE_MPEG12_MOTION_TYPE_16x8 : PIPE_MPEG12_MOTION_TYPE_FRAME;
- case XVMC_PREDICTION_FIELD:
- return PIPE_MPEG12_MOTION_TYPE_FIELD;
- case XVMC_PREDICTION_DUAL_PRIME:
- return PIPE_MPEG12_MOTION_TYPE_DUALPRIME;
- default:
- assert(0);
- }
-
- return -1;
-}
-
-static bool
-CreateOrResizeBackBuffer(struct pipe_video_context *vpipe, unsigned int width, unsigned int height,
- struct pipe_surface **backbuffer)
-{
- struct pipe_texture template;
- struct pipe_texture *tex;
-
- assert(vpipe);
-
- if (*backbuffer) {
- if ((*backbuffer)->width != width || (*backbuffer)->height != height)
- pipe_surface_reference(backbuffer, NULL);
- else
- return true;
- }
-
- memset(&template, 0, sizeof(struct pipe_texture));
- template.target = PIPE_TEXTURE_2D;
- /* XXX: Needs to match the drawable's format? */
- template.format = PIPE_FORMAT_B8G8R8X8_UNORM;
- template.last_level = 0;
- template.width0 = width;
- template.height0 = height;
- template.depth0 = 1;
- template.tex_usage = PIPE_TEXTURE_USAGE_SHARED;
-
- tex = vpipe->screen->texture_create(vpipe->screen, &template);
- if (!tex)
- return false;
-
- *backbuffer = vpipe->screen->get_tex_surface(vpipe->screen, tex, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
- pipe_texture_reference(&tex, NULL);
-
- if (!*backbuffer)
- return false;
-
- /* Clear the backbuffer in case the video doesn't cover the whole window */
- /* FIXME: Need to clear every time a frame moves and leaves dirty rects */
- vpipe->clear_surface(vpipe, 0, 0, width, height, 0, *backbuffer);
-
- return true;
-}
-
-static void
-MacroBlocksToPipe(const XvMCMacroBlockArray *xvmc_macroblocks,
- const XvMCBlockArray *xvmc_blocks,
- unsigned int first_macroblock,
- unsigned int num_macroblocks,
- struct pipe_mpeg12_macroblock *pipe_macroblocks)
-{
- unsigned int i, j, k, l;
- XvMCMacroBlock *xvmc_mb;
-
- assert(xvmc_macroblocks);
- assert(xvmc_blocks);
- assert(pipe_macroblocks);
- assert(num_macroblocks);
-
- xvmc_mb = xvmc_macroblocks->macro_blocks + first_macroblock;
-
- for (i = 0; i < num_macroblocks; ++i) {
- pipe_macroblocks->base.codec = PIPE_VIDEO_CODEC_MPEG12;
- pipe_macroblocks->mbx = xvmc_mb->x;
- pipe_macroblocks->mby = xvmc_mb->y;
- pipe_macroblocks->mb_type = TypeToPipe(xvmc_mb->macroblock_type);
- if (pipe_macroblocks->mb_type != PIPE_MPEG12_MACROBLOCK_TYPE_INTRA)
- pipe_macroblocks->mo_type = MotionToPipe(xvmc_mb->motion_type, xvmc_mb->dct_type);
- /* Get rid of Valgrind 'undefined' warnings */
- else
- pipe_macroblocks->mo_type = -1;
- pipe_macroblocks->dct_type = xvmc_mb->dct_type == XVMC_DCT_TYPE_FIELD ?
- PIPE_MPEG12_DCT_TYPE_FIELD : PIPE_MPEG12_DCT_TYPE_FRAME;
-
- for (j = 0; j < 2; ++j)
- for (k = 0; k < 2; ++k)
- for (l = 0; l < 2; ++l)
- pipe_macroblocks->pmv[j][k][l] = xvmc_mb->PMV[j][k][l];
-
- pipe_macroblocks->cbp = xvmc_mb->coded_block_pattern;
- pipe_macroblocks->blocks = xvmc_blocks->blocks + xvmc_mb->index * BLOCK_SIZE_SAMPLES;
-
- ++pipe_macroblocks;
- ++xvmc_mb;
- }
-}
-
-Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surface)
-{
- XvMCContextPrivate *context_priv;
- struct pipe_video_context *vpipe;
- XvMCSurfacePrivate *surface_priv;
- struct pipe_video_surface *vsfc;
-
- assert(dpy);
-
- if (!context)
- return XvMCBadContext;
- if (!surface)
- return XvMCBadSurface;
-
- context_priv = context->privData;
- vpipe = context_priv->vpipe;
-
- surface_priv = CALLOC(1, sizeof(XvMCSurfacePrivate));
- if (!surface_priv)
- return BadAlloc;
-
- vsfc = vpipe->screen->video_surface_create(vpipe->screen, vpipe->chroma_format,
- vpipe->width, vpipe->height);
- if (!vsfc) {
- FREE(surface_priv);
- return BadAlloc;
- }
-
- surface_priv->pipe_vsfc = vsfc;
- surface_priv->context = context;
-
- surface->surface_id = XAllocID(dpy);
- surface->context_id = context->context_id;
- surface->surface_type_id = context->surface_type_id;
- surface->width = context->width;
- surface->height = context->height;
- surface->privData = surface_priv;
-
- SyncHandle();
-
- return Success;
-}
-
-Status XvMCRenderSurface(Display *dpy, XvMCContext *context, unsigned int picture_structure,
- XvMCSurface *target_surface, XvMCSurface *past_surface, XvMCSurface *future_surface,
- unsigned int flags, unsigned int num_macroblocks, unsigned int first_macroblock,
- XvMCMacroBlockArray *macroblocks, XvMCBlockArray *blocks
-)
-{
- struct pipe_video_context *vpipe;
- struct pipe_surface *t_vsfc;
- struct pipe_surface *p_vsfc;
- struct pipe_surface *f_vsfc;
- XvMCContextPrivate *context_priv;
- XvMCSurfacePrivate *target_surface_priv;
- XvMCSurfacePrivate *past_surface_priv;
- XvMCSurfacePrivate *future_surface_priv;
- struct pipe_mpeg12_macroblock pipe_macroblocks[num_macroblocks];
-
- assert(dpy);
-
- if (!context || !context->privData)
- return XvMCBadContext;
- if (!target_surface || !target_surface->privData)
- return XvMCBadSurface;
-
- if (picture_structure != XVMC_TOP_FIELD &&
- picture_structure != XVMC_BOTTOM_FIELD &&
- picture_structure != XVMC_FRAME_PICTURE)
- return BadValue;
- /* Bkwd pred equivalent to fwd (past && !future) */
- if (future_surface && !past_surface)
- return BadMatch;
-
- assert(context->context_id == target_surface->context_id);
- assert(!past_surface || context->context_id == past_surface->context_id);
- assert(!future_surface || context->context_id == future_surface->context_id);
-
- assert(macroblocks);
- assert(blocks);
-
- assert(macroblocks->context_id == context->context_id);
- assert(blocks->context_id == context->context_id);
-
- assert(flags == 0 || flags == XVMC_SECOND_FIELD);
-
- target_surface_priv = target_surface->privData;
- past_surface_priv = past_surface ? past_surface->privData : NULL;
- future_surface_priv = future_surface ? future_surface->privData : NULL;
-
- assert(target_surface_priv->context == context);
- assert(!past_surface || past_surface_priv->context == context);
- assert(!future_surface || future_surface_priv->context == context);
-
- context_priv = context->privData;
- vpipe = context_priv->vpipe;
-
- t_vsfc = target_surface_priv->pipe_vsfc;
- p_vsfc = past_surface ? past_surface_priv->pipe_vsfc : NULL;
- f_vsfc = future_surface ? future_surface_priv->pipe_vsfc : NULL;
-
- MacroBlocksToPipe(macroblocks, blocks, first_macroblock,
- num_macroblocks, pipe_macroblocks);
-
- vpipe->set_decode_target(vpipe, t_vsfc);
- vpipe->decode_macroblocks(vpipe, p_vsfc, f_vsfc, num_macroblocks,
- &pipe_macroblocks->base, target_surface_priv->render_fence);
-
- return Success;
-}
-
-Status XvMCFlushSurface(Display *dpy, XvMCSurface *surface)
-{
- assert(dpy);
-
- if (!surface)
- return XvMCBadSurface;
-
- return Success;
-}
-
-Status XvMCSyncSurface(Display *dpy, XvMCSurface *surface)
-{
- assert(dpy);
-
- if (!surface)
- return XvMCBadSurface;
-
- return Success;
-}
-
-Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable,
- short srcx, short srcy, unsigned short srcw, unsigned short srch,
- short destx, short desty, unsigned short destw, unsigned short desth,
- int flags)
-{
- Window root;
- int x, y;
- unsigned int width, height;
- unsigned int border_width;
- unsigned int depth;
- struct pipe_video_context *vpipe;
- XvMCSurfacePrivate *surface_priv;
- XvMCContextPrivate *context_priv;
- XvMCContext *context;
- struct pipe_video_rect src_rect = {srcx, srcy, srcw, srch};
- struct pipe_video_rect dst_rect = {destx, desty, destw, desth};
-
- assert(dpy);
-
- if (!surface || !surface->privData)
- return XvMCBadSurface;
-
- if (XGetGeometry(dpy, drawable, &root, &x, &y, &width, &height, &border_width, &depth) == BadDrawable)
- return BadDrawable;
-
- assert(flags == XVMC_TOP_FIELD || flags == XVMC_BOTTOM_FIELD || flags == XVMC_FRAME_PICTURE);
- assert(srcx + srcw - 1 < surface->width);
- assert(srcy + srch - 1 < surface->height);
- /*
- * Some apps (mplayer) hit these asserts because they call
- * this function after the window has been resized by the WM
- * but before they've handled the corresponding XEvent and
- * know about the new dimensions. The output should be clipped
- * until the app updates destw and desth.
- */
- /*
- assert(destx + destw - 1 < width);
- assert(desty + desth - 1 < height);
- */
-
- surface_priv = surface->privData;
- context = surface_priv->context;
- context_priv = context->privData;
- vpipe = context_priv->vpipe;
-
- if (!CreateOrResizeBackBuffer(vpipe, width, height, &context_priv->backbuffer))
- return BadAlloc;
-
- vpipe->render_picture(vpipe, surface_priv->pipe_vsfc, PictureToPipe(flags), &src_rect,
- context_priv->backbuffer, &dst_rect, surface_priv->disp_fence);
-
- vl_video_bind_drawable(vpipe, drawable);
-
- vpipe->screen->flush_frontbuffer
- (
- vpipe->screen,
- context_priv->backbuffer,
- vpipe->priv
- );
-
- return Success;
-}
-
-Status XvMCGetSurfaceStatus(Display *dpy, XvMCSurface *surface, int *status)
-{
- assert(dpy);
-
- if (!surface)
- return XvMCBadSurface;
-
- assert(status);
-
- *status = 0;
-
- return Success;
-}
-
-Status XvMCDestroySurface(Display *dpy, XvMCSurface *surface)
-{
- XvMCSurfacePrivate *surface_priv;
-
- assert(dpy);
-
- if (!surface || !surface->privData)
- return XvMCBadSurface;
-
- surface_priv = surface->privData;
- pipe_video_surface_reference(&surface_priv->pipe_vsfc, NULL);
- FREE(surface_priv);
- surface->privData = NULL;
-
- return Success;
-}
-
-Status XvMCHideSurface(Display *dpy, XvMCSurface *surface)
-{
- assert(dpy);
-
- if (!surface || !surface->privData)
- return XvMCBadSurface;
-
- /* No op, only for overlaid rendering */
-
- return Success;
-}
+++ /dev/null
-test_context
-test_surface
-test_blocks
-test_rendering
-xvmc_bench
+++ /dev/null
-TOP = ../../../../../..
-include $(TOP)/configs/current
-
-LIBS = -lXvMCW -lXvMC -lXv -lX11
-
-#############################################
-
-.PHONY: default clean
-
-default: test_context test_surface test_blocks test_rendering xvmc_bench
-
-test_context: test_context.o testlib.o
- $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-test_surface: test_surface.o testlib.o
- $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-test_blocks: test_blocks.o testlib.o
- $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-test_rendering: test_rendering.o testlib.o
- $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-xvmc_bench: xvmc_bench.o testlib.o
- $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-clean:
- $(RM) -rf *.o test_context test_surface test_blocks test_rendering xvmc_bench
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <error.h>
-#include "testlib.h"
-
-int main(int argc, char **argv)
-{
- const unsigned int width = 16, height = 16;
- const unsigned int min_required_blocks = 1, min_required_macroblocks = 1;
- const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
-
- Display *display;
- XvPortID port_num;
- int surface_type_id;
- unsigned int is_overlay, intra_unsigned;
- int colorkey;
- XvMCContext context;
- XvMCSurface surface;
- XvMCBlockArray blocks = {0};
- XvMCMacroBlockArray macroblocks = {0};
-
- display = XOpenDisplay(NULL);
-
- if (!GetPort
- (
- display,
- width,
- height,
- XVMC_CHROMA_FORMAT_420,
- mc_types,
- 2,
- &port_num,
- &surface_type_id,
- &is_overlay,
- &intra_unsigned
- ))
- {
- XCloseDisplay(display);
- error(1, 0, "Error, unable to find a good port.\n");
- }
-
- if (is_overlay)
- {
- Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
- XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
- }
-
- assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
- assert(XvMCCreateSurface(display, &context, &surface) == Success);
-
- /* Test NULL context */
- assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext);
- /* Test 0 blocks */
- assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue);
- /* Test valid params */
- assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success);
- /* Test context id assigned and correct */
- assert(blocks.context_id == context.context_id);
- /* Test number of blocks assigned and correct */
- assert(blocks.num_blocks == min_required_blocks);
- /* Test block pointer valid */
- assert(blocks.blocks != NULL);
- /* Test NULL context */
- assert(XvMCCreateMacroBlocks(display, NULL, 1, ¯oblocks) == XvMCBadContext);
- /* Test 0 macroblocks */
- assert(XvMCCreateMacroBlocks(display, &context, 0, ¯oblocks) == BadValue);
- /* Test valid params */
- assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, ¯oblocks) == Success);
- /* Test context id assigned and correct */
- assert(macroblocks.context_id == context.context_id);
- /* Test macroblock pointer valid */
- assert(macroblocks.macro_blocks != NULL);
- /* Test valid params */
- assert(XvMCDestroyMacroBlocks(display, ¯oblocks) == Success);
- /* Test valid params */
- assert(XvMCDestroyBlocks(display, &blocks) == Success);
-
- assert(XvMCDestroySurface(display, &surface) == Success);
- assert(XvMCDestroyContext(display, &context) == Success);
-
- XvUngrabPort(display, port_num, CurrentTime);
- XCloseDisplay(display);
-
- return 0;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <error.h>
-#include "testlib.h"
-
-int main(int argc, char **argv)
-{
- const unsigned int width = 16, height = 16;
- const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
-
- Display *display;
- XvPortID port_num;
- int surface_type_id;
- unsigned int is_overlay, intra_unsigned;
- int colorkey;
- XvMCContext context = {0};
-
- display = XOpenDisplay(NULL);
-
- if (!GetPort
- (
- display,
- width,
- height,
- XVMC_CHROMA_FORMAT_420,
- mc_types,
- 2,
- &port_num,
- &surface_type_id,
- &is_overlay,
- &intra_unsigned
- ))
- {
- XCloseDisplay(display);
- error(1, 0, "Error, unable to find a good port.\n");
- }
-
- if (is_overlay)
- {
- Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
- XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
- }
-
- /* Test NULL context */
- /* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */
- assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext);
- /* Test invalid port */
- /* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */
- assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort);
- /* Test invalid surface */
- assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch);
- /* Test invalid flags */
- assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue);
- /* Test huge width */
- assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue);
- /* Test huge height */
- assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue);
- /* Test huge width & height */
- assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue);
- /* Test valid params */
- assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
- /* Test context id assigned */
- assert(context.context_id != 0);
- /* Test surface type id assigned and correct */
- assert(context.surface_type_id == surface_type_id);
- /* Test width & height assigned and correct */
- assert(context.width == width && context.height == height);
- /* Test port assigned and correct */
- assert(context.port == port_num);
- /* Test flags assigned and correct */
- assert(context.flags == XVMC_DIRECT);
- /* Test NULL context */
- assert(XvMCDestroyContext(display, NULL) == XvMCBadContext);
- /* Test valid params */
- assert(XvMCDestroyContext(display, &context) == Success);
- /* Test awkward but valid width */
- assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success);
- assert(context.width >= width + 1);
- assert(XvMCDestroyContext(display, &context) == Success);
- /* Test awkward but valid height */
- assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success);
- assert(context.height >= height + 1);
- assert(XvMCDestroyContext(display, &context) == Success);
- /* Test awkward but valid width & height */
- assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success);
- assert(context.width >= width + 1 && context.height >= height + 1);
- assert(XvMCDestroyContext(display, &context) == Success);
-
- XvUngrabPort(display, port_num, CurrentTime);
- XCloseDisplay(display);
-
- return 0;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <error.h>
-#include "testlib.h"
-
-#define BLOCK_WIDTH 8
-#define BLOCK_HEIGHT 8
-#define BLOCK_SIZE (BLOCK_WIDTH * BLOCK_HEIGHT)
-#define MACROBLOCK_WIDTH 16
-#define MACROBLOCK_HEIGHT 16
-#define MACROBLOCK_WIDTH_IN_BLOCKS (MACROBLOCK_WIDTH / BLOCK_WIDTH)
-#define MACROBLOCK_HEIGHT_IN_BLOCKS (MACROBLOCK_HEIGHT / BLOCK_HEIGHT)
-#define BLOCKS_PER_MACROBLOCK 6
-
-#define INPUT_WIDTH 16
-#define INPUT_HEIGHT 16
-#define INPUT_WIDTH_IN_MACROBLOCKS (INPUT_WIDTH / MACROBLOCK_WIDTH)
-#define INPUT_HEIGHT_IN_MACROBLOCKS (INPUT_HEIGHT / MACROBLOCK_HEIGHT)
-#define NUM_MACROBLOCKS (INPUT_WIDTH_IN_MACROBLOCKS * INPUT_HEIGHT_IN_MACROBLOCKS)
-
-#define DEFAULT_OUTPUT_WIDTH INPUT_WIDTH
-#define DEFAULT_OUTPUT_HEIGHT INPUT_HEIGHT
-#define DEFAULT_ACCEPTABLE_ERR 0.01
-
-void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt);
-void Gradient(short *block, unsigned int start, unsigned int stop, int horizontal);
-
-void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt)
-{
- int fail = 0;
- int i;
-
- *output_width = DEFAULT_OUTPUT_WIDTH;
- *output_height = DEFAULT_OUTPUT_WIDTH;
- *acceptable_error = DEFAULT_ACCEPTABLE_ERR;
- *prompt = 1;
-
- for (i = 1; i < argc && !fail; ++i)
- {
- if (!strcmp(argv[i], "-w"))
- {
- if (sscanf(argv[++i], "%u", output_width) != 1)
- fail = 1;
- }
- else if (!strcmp(argv[i], "-h"))
- {
- if (sscanf(argv[++i], "%u", output_height) != 1)
- fail = 1;
- }
- else if (!strcmp(argv[i], "-e"))
- {
- if (sscanf(argv[++i], "%lf", acceptable_error) != 1)
- fail = 1;
- }
- else if (strcmp(argv[i], "-n"))
- *prompt = 0;
- else
- fail = 1;
- }
-
- if (fail)
- error
- (
- 1, 0,
- "Bad argument.\n"
- "\n"
- "Usage: %s [options]\n"
- "\t-w <width>\tOutput width\n"
- "\t-h <height>\tOutput height\n"
- "\t-e <error>\tAcceptable margin of error per pixel, from 0 to 1\n"
- "\t-n\tDon't prompt for quit\n",
- argv[0]
- );
-}
-
-void Gradient(short *block, unsigned int start, unsigned int stop, int horizontal)
-{
- unsigned int x, y;
- unsigned int range = stop - start;
-
- if (horizontal)
- {
- for (y = 0; y < BLOCK_HEIGHT; ++y)
- for (x = 0; x < BLOCK_WIDTH; ++x)
- block[y * BLOCK_WIDTH + x] = (short)(start + range * (x / (float)(BLOCK_WIDTH - 1)));
- }
- else
- {
- for (y = 0; y < BLOCK_HEIGHT; ++y)
- for (x = 0; x < BLOCK_WIDTH; ++x)
- block[y * BLOCK_WIDTH + x] = (short)(start + range * (y / (float)(BLOCK_HEIGHT - 1)));
- }
-}
-
-int main(int argc, char **argv)
-{
- unsigned int output_width;
- unsigned int output_height;
- double acceptable_error;
- int prompt;
- Display *display;
- Window root, window;
- const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
- XvPortID port_num;
- int surface_type_id;
- unsigned int is_overlay, intra_unsigned;
- int colorkey;
- XvMCContext context;
- XvMCSurface surface;
- XvMCBlockArray block_array;
- XvMCMacroBlockArray mb_array;
- int mbx, mby, bx, by;
- XvMCMacroBlock *mb;
- short *blocks;
- int quit = 0;
-
- ParseArgs(argc, argv, &output_width, &output_height, &acceptable_error, &prompt);
-
- display = XOpenDisplay(NULL);
-
- if (!GetPort
- (
- display,
- INPUT_WIDTH,
- INPUT_HEIGHT,
- XVMC_CHROMA_FORMAT_420,
- mc_types,
- 2,
- &port_num,
- &surface_type_id,
- &is_overlay,
- &intra_unsigned
- ))
- {
- XCloseDisplay(display);
- error(1, 0, "Error, unable to find a good port.\n");
- }
-
- if (is_overlay)
- {
- Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
- XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
- }
-
- root = XDefaultRootWindow(display);
- window = XCreateSimpleWindow(display, root, 0, 0, output_width, output_height, 0, 0, colorkey);
-
- assert(XvMCCreateContext(display, port_num, surface_type_id, INPUT_WIDTH, INPUT_HEIGHT, XVMC_DIRECT, &context) == Success);
- assert(XvMCCreateSurface(display, &context, &surface) == Success);
- assert(XvMCCreateBlocks(display, &context, NUM_MACROBLOCKS * BLOCKS_PER_MACROBLOCK, &block_array) == Success);
- assert(XvMCCreateMacroBlocks(display, &context, NUM_MACROBLOCKS, &mb_array) == Success);
-
- mb = mb_array.macro_blocks;
- blocks = block_array.blocks;
-
- for (mby = 0; mby < INPUT_HEIGHT_IN_MACROBLOCKS; ++mby)
- for (mbx = 0; mbx < INPUT_WIDTH_IN_MACROBLOCKS; ++mbx)
- {
- mb->x = mbx;
- mb->y = mby;
- mb->macroblock_type = XVMC_MB_TYPE_INTRA;
- /*mb->motion_type = ;*/
- /*mb->motion_vertical_field_select = ;*/
- mb->dct_type = XVMC_DCT_TYPE_FRAME;
- /*mb->PMV[0][0][0] = ;
- mb->PMV[0][0][1] = ;
- mb->PMV[0][1][0] = ;
- mb->PMV[0][1][1] = ;
- mb->PMV[1][0][0] = ;
- mb->PMV[1][0][1] = ;
- mb->PMV[1][1][0] = ;
- mb->PMV[1][1][1] = ;*/
- mb->index = (mby * INPUT_WIDTH_IN_MACROBLOCKS + mbx) * BLOCKS_PER_MACROBLOCK;
- mb->coded_block_pattern = 0x3F;
-
- mb++;
-
- for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS; ++by)
- for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS; ++bx)
- {
- const int start = 16, stop = 235, range = stop - start;
-
- Gradient
- (
- blocks,
- (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
- (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
- 1
- );
-
- blocks += BLOCK_SIZE;
- }
-
- for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS / 2; ++by)
- for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS / 2; ++bx)
- {
- const int start = 16, stop = 240, range = stop - start;
-
- Gradient
- (
- blocks,
- (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
- (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
- 1
- );
-
- blocks += BLOCK_SIZE;
-
- Gradient
- (
- blocks,
- (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
- (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
- 1
- );
-
- blocks += BLOCK_SIZE;
- }
- }
-
- XSelectInput(display, window, ExposureMask | KeyPressMask);
- XMapWindow(display, window);
- XSync(display, 0);
-
- /* Test NULL context */
- assert(XvMCRenderSurface(display, NULL, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadContext);
- /* Test NULL surface */
- assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, NULL, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadSurface);
- /* Test bad picture structure */
- assert(XvMCRenderSurface(display, &context, 0, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == BadValue);
- /* Test valid params */
- assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == Success);
-
- /* Test NULL surface */
- assert(XvMCPutSurface(display, NULL, window, 0, 0, INPUT_WIDTH, INPUT_HEIGHT, 0, 0, output_width, output_height, XVMC_FRAME_PICTURE) == XvMCBadSurface);
- /* Test bad window */
- /* XXX: X halts with a bad drawable for some reason, doesn't return BadDrawable as expected */
- /*assert(XvMCPutSurface(display, &surface, 0, 0, 0, width, height, 0, 0, width, height, XVMC_FRAME_PICTURE) == BadDrawable);*/
-
- if (prompt)
- {
- puts("Press any button to quit...");
-
- while (!quit)
- {
- if (XPending(display) > 0)
- {
- XEvent event;
-
- XNextEvent(display, &event);
-
- switch (event.type)
- {
- case Expose:
- {
- /* Test valid params */
- assert
- (
- XvMCPutSurface
- (
- display, &surface, window,
- 0, 0, INPUT_WIDTH, INPUT_HEIGHT,
- 0, 0, output_width, output_height,
- XVMC_FRAME_PICTURE
- ) == Success
- );
- break;
- }
- case KeyPress:
- {
- quit = 1;
- break;
- }
- }
- }
- }
- }
-
- assert(XvMCDestroyBlocks(display, &block_array) == Success);
- assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success);
- assert(XvMCDestroySurface(display, &surface) == Success);
- assert(XvMCDestroyContext(display, &context) == Success);
-
- XvUngrabPort(display, port_num, CurrentTime);
- XDestroyWindow(display, window);
- XCloseDisplay(display);
-
- return 0;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <error.h>
-#include "testlib.h"
-
-int main(int argc, char **argv)
-{
- const unsigned int width = 16, height = 16;
- const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
-
- Display *display;
- XvPortID port_num;
- int surface_type_id;
- unsigned int is_overlay, intra_unsigned;
- int colorkey;
- XvMCContext context;
- XvMCSurface surface = {0};
-
- display = XOpenDisplay(NULL);
-
- if (!GetPort
- (
- display,
- width,
- height,
- XVMC_CHROMA_FORMAT_420,
- mc_types,
- 2,
- &port_num,
- &surface_type_id,
- &is_overlay,
- &intra_unsigned
- ))
- {
- XCloseDisplay(display);
- error(1, 0, "Error, unable to find a good port.\n");
- }
-
- if (is_overlay)
- {
- Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
- XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
- }
-
- assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
-
- /* Test NULL context */
- assert(XvMCCreateSurface(display, NULL, &surface) == XvMCBadContext);
- /* Test NULL surface */
- assert(XvMCCreateSurface(display, &context, NULL) == XvMCBadSurface);
- /* Test valid params */
- assert(XvMCCreateSurface(display, &context, &surface) == Success);
- /* Test surface id assigned */
- assert(surface.surface_id != 0);
- /* Test context id assigned and correct */
- assert(surface.context_id == context.context_id);
- /* Test surface type id assigned and correct */
- assert(surface.surface_type_id == surface_type_id);
- /* Test width & height assigned and correct */
- assert(surface.width == width && surface.height == height);
- /* Test valid params */
- assert(XvMCDestroySurface(display, &surface) == Success);
- /* Test NULL surface */
- assert(XvMCDestroySurface(display, NULL) == XvMCBadSurface);
-
- assert(XvMCDestroyContext(display, &context) == Success);
-
- XvUngrabPort(display, port_num, CurrentTime);
- XCloseDisplay(display);
-
- return 0;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include "testlib.h"
-#include <stdio.h>
-
-/*
-void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line)
-{
- fputs(doc_string, stderr);
- if (!pred)
- fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line);
- else
- fputs(" PASS!\n", stderr);
-}
-*/
-
-int GetPort
-(
- Display *display,
- unsigned int width,
- unsigned int height,
- unsigned int chroma_format,
- const unsigned int *mc_types,
- unsigned int num_mc_types,
- XvPortID *port_id,
- int *surface_type_id,
- unsigned int *is_overlay,
- unsigned int *intra_unsigned
-)
-{
- unsigned int found_port = 0;
- XvAdaptorInfo *adaptor_info;
- unsigned int num_adaptors;
- int num_types;
- int ev_base, err_base;
- unsigned int i, j, k, l;
-
- if (!XvMCQueryExtension(display, &ev_base, &err_base))
- return 0;
- if (XvQueryAdaptors(display, XDefaultRootWindow(display), &num_adaptors, &adaptor_info) != Success)
- return 0;
-
- for (i = 0; i < num_adaptors && !found_port; ++i)
- {
- if (adaptor_info[i].type & XvImageMask)
- {
- XvMCSurfaceInfo *surface_info = XvMCListSurfaceTypes(display, adaptor_info[i].base_id, &num_types);
-
- if (surface_info)
- {
- for (j = 0; j < num_types && !found_port; ++j)
- {
- if
- (
- surface_info[j].chroma_format == chroma_format &&
- surface_info[j].max_width >= width &&
- surface_info[j].max_height >= height
- )
- {
- for (k = 0; k < num_mc_types && !found_port; ++k)
- {
- if (surface_info[j].mc_type == mc_types[k])
- {
- for (l = 0; l < adaptor_info[i].num_ports && !found_port; ++l)
- {
- if (XvGrabPort(display, adaptor_info[i].base_id + l, CurrentTime) == Success)
- {
- *port_id = adaptor_info[i].base_id + l;
- *surface_type_id = surface_info[j].surface_type_id;
- *is_overlay = surface_info[j].flags & XVMC_OVERLAID_SURFACE;
- *intra_unsigned = surface_info[j].flags & XVMC_INTRA_UNSIGNED;
- found_port = 1;
- }
- }
- }
- }
- }
- }
-
- XFree(surface_info);
- }
- }
- }
-
- XvFreeAdaptorInfo(adaptor_info);
-
- return found_port;
-}
-
-unsigned int align(unsigned int value, unsigned int alignment)
-{
- return (value + alignment - 1) & ~(alignment - 1);
-}
-
-/* From the glibc manual */
-int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
-{
- /* Perform the carry for the later subtraction by updating y. */
- if (x->tv_usec < y->tv_usec)
- {
- int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
- y->tv_usec -= 1000000 * nsec;
- y->tv_sec += nsec;
- }
- if (x->tv_usec - y->tv_usec > 1000000)
- {
- int nsec = (x->tv_usec - y->tv_usec) / 1000000;
- y->tv_usec += 1000000 * nsec;
- y->tv_sec -= nsec;
- }
-
- /*
- * Compute the time remaining to wait.
- * tv_usec is certainly positive.
- */
- result->tv_sec = x->tv_sec - y->tv_sec;
- result->tv_usec = x->tv_usec - y->tv_usec;
-
- /* Return 1 if result is negative. */
- return x->tv_sec < y->tv_sec;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 testlib_h
-#define testlib_h
-
-/*
-#define TEST(pred, doc) test(pred, #pred, doc, __FILE__, __LINE__)
-
-void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line);
-*/
-
-#include <sys/time.h>
-#include <X11/Xlib.h>
-#include <X11/extensions/XvMClib.h>
-
-/*
- * display: IN A valid X display
- * width, height: IN Surface size that the port must display
- * chroma_format: IN Chroma format that the port must display
- * mc_types, num_mc_types: IN List of MC types that the port must support, first port that matches the first mc_type will be returned
- * port_id: OUT Your port's ID
- * surface_type_id: OUT Your port's surface ID
- * is_overlay: OUT If 1, port uses overlay surfaces, you need to set a colorkey
- * intra_unsigned: OUT If 1, port uses unsigned values for intra-coded blocks
- */
-int GetPort
-(
- Display *display,
- unsigned int width,
- unsigned int height,
- unsigned int chroma_format,
- const unsigned int *mc_types,
- unsigned int num_mc_types,
- XvPortID *port_id,
- int *surface_type_id,
- unsigned int *is_overlay,
- unsigned int *intra_unsigned
-);
-
-unsigned int align(unsigned int value, unsigned int alignment);
-
-int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y);
-
-#endif
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <error.h>
-#include <sys/time.h>
-#include "testlib.h"
-
-#define MACROBLOCK_WIDTH 16
-#define MACROBLOCK_HEIGHT 16
-#define BLOCKS_PER_MACROBLOCK 6
-
-#define DEFAULT_INPUT_WIDTH 720
-#define DEFAULT_INPUT_HEIGHT 480
-#define DEFAULT_REPS 100
-
-#define PIPELINE_STEP_MC 1
-#define PIPELINE_STEP_CSC 2
-#define PIPELINE_STEP_SWAP 4
-
-#define MB_TYPE_I 1
-#define MB_TYPE_P 2
-#define MB_TYPE_B 4
-
-struct Config
-{
- unsigned int input_width;
- unsigned int input_height;
- unsigned int output_width;
- unsigned int output_height;
- unsigned int pipeline;
- unsigned int mb_types;
- unsigned int reps;
-};
-
-void ParseArgs(int argc, char **argv, struct Config *config);
-
-void ParseArgs(int argc, char **argv, struct Config *config)
-{
- int fail = 0;
- int i;
-
- config->input_width = DEFAULT_INPUT_WIDTH;
- config->input_height = DEFAULT_INPUT_HEIGHT;
- config->output_width = 0;
- config->output_height = 0;
- config->pipeline = 0;
- config->mb_types = 0;
- config->reps = DEFAULT_REPS;
-
- for (i = 1; i < argc && !fail; ++i)
- {
- if (!strcmp(argv[i], "-iw"))
- {
- if (sscanf(argv[++i], "%u", &config->input_width) != 1)
- fail = 1;
- }
- else if (!strcmp(argv[i], "-ih"))
- {
- if (sscanf(argv[++i], "%u", &config->input_height) != 1)
- fail = 1;
- }
- else if (!strcmp(argv[i], "-ow"))
- {
- if (sscanf(argv[++i], "%u", &config->output_width) != 1)
- fail = 1;
- }
- else if (!strcmp(argv[i], "-oh"))
- {
- if (sscanf(argv[++i], "%u", &config->output_height) != 1)
- fail = 1;
- }
- else if (!strcmp(argv[i], "-p"))
- {
- char *token = strtok(argv[++i], ",");
-
- while (token && !fail)
- {
- if (!strcmp(token, "mc"))
- config->pipeline |= PIPELINE_STEP_MC;
- else if (!strcmp(token, "csc"))
- config->pipeline |= PIPELINE_STEP_CSC;
- else if (!strcmp(token, "swp"))
- config->pipeline |= PIPELINE_STEP_SWAP;
- else
- fail = 1;
-
- if (!fail)
- token = strtok(NULL, ",");
- }
- }
- else if (!strcmp(argv[i], "-mb"))
- {
- char *token = strtok(argv[++i], ",");
-
- while (token && !fail)
- {
- if (strcmp(token, "i"))
- config->mb_types |= MB_TYPE_I;
- else if (strcmp(token, "p"))
- config->mb_types |= MB_TYPE_P;
- else if (strcmp(token, "b"))
- config->mb_types |= MB_TYPE_B;
- else
- fail = 1;
-
- if (!fail)
- token = strtok(NULL, ",");
- }
- }
- else if (!strcmp(argv[i], "-r"))
- {
- if (sscanf(argv[++i], "%u", &config->reps) != 1)
- fail = 1;
- }
- else
- fail = 1;
- }
-
- if (fail)
- error
- (
- 1, 0,
- "Bad argument.\n"
- "\n"
- "Usage: %s [options]\n"
- "\t-iw <width>\tInput width\n"
- "\t-ih <height>\tInput height\n"
- "\t-ow <width>\tOutput width\n"
- "\t-oh <height>\tOutput height\n"
- "\t-p <pipeline>\tPipeline to test\n"
- "\t-mb <mb type>\tMacroBlock types to use\n"
- "\t-r <reps>\tRepetitions\n\n"
- "\tPipeline steps: mc,csc,swap\n"
- "\tMB types: i,p,b\n",
- argv[0]
- );
-
- if (config->output_width == 0)
- config->output_width = config->input_width;
- if (config->output_height == 0)
- config->output_height = config->input_height;
- if (!config->pipeline)
- config->pipeline = PIPELINE_STEP_MC | PIPELINE_STEP_CSC | PIPELINE_STEP_SWAP;
- if (!config->mb_types)
- config->mb_types = MB_TYPE_I | MB_TYPE_P | MB_TYPE_B;
-}
-
-int main(int argc, char **argv)
-{
- struct Config config;
- Display *display;
- Window root, window;
- const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
- XvPortID port_num;
- int surface_type_id;
- unsigned int is_overlay, intra_unsigned;
- int colorkey;
- XvMCContext context;
- XvMCSurface surface;
- XvMCBlockArray block_array;
- XvMCMacroBlockArray mb_array;
- unsigned int mbw, mbh;
- unsigned int mbx, mby;
- unsigned int reps;
- struct timeval start, stop, diff;
- double diff_secs;
-
- ParseArgs(argc, argv, &config);
-
- mbw = align(config.input_width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH;
- mbh = align(config.input_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT;
-
- display = XOpenDisplay(NULL);
-
- if (!GetPort
- (
- display,
- config.input_width,
- config.input_height,
- XVMC_CHROMA_FORMAT_420,
- mc_types,
- 2,
- &port_num,
- &surface_type_id,
- &is_overlay,
- &intra_unsigned
- ))
- {
- XCloseDisplay(display);
- error(1, 0, "Error, unable to find a good port.\n");
- }
-
- if (is_overlay)
- {
- Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
- XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
- }
-
- root = XDefaultRootWindow(display);
- window = XCreateSimpleWindow(display, root, 0, 0, config.output_width, config.output_height, 0, 0, colorkey);
-
- assert(XvMCCreateContext(display, port_num, surface_type_id, config.input_width, config.input_height, XVMC_DIRECT, &context) == Success);
- assert(XvMCCreateSurface(display, &context, &surface) == Success);
- assert(XvMCCreateBlocks(display, &context, mbw * mbh * BLOCKS_PER_MACROBLOCK, &block_array) == Success);
- assert(XvMCCreateMacroBlocks(display, &context, mbw * mbh, &mb_array) == Success);
-
- for (mby = 0; mby < mbh; ++mby)
- for (mbx = 0; mbx < mbw; ++mbx)
- {
- mb_array.macro_blocks[mby * mbw + mbx].x = mbx;
- mb_array.macro_blocks[mby * mbw + mbx].y = mby;
- mb_array.macro_blocks[mby * mbw + mbx].macroblock_type = XVMC_MB_TYPE_INTRA;
- /*mb->motion_type = ;*/
- /*mb->motion_vertical_field_select = ;*/
- mb_array.macro_blocks[mby * mbw + mbx].dct_type = XVMC_DCT_TYPE_FRAME;
- /*mb->PMV[0][0][0] = ;
- mb->PMV[0][0][1] = ;
- mb->PMV[0][1][0] = ;
- mb->PMV[0][1][1] = ;
- mb->PMV[1][0][0] = ;
- mb->PMV[1][0][1] = ;
- mb->PMV[1][1][0] = ;
- mb->PMV[1][1][1] = ;*/
- mb_array.macro_blocks[mby * mbw + mbx].index = (mby * mbw + mbx) * BLOCKS_PER_MACROBLOCK;
- mb_array.macro_blocks[mby * mbw + mbx].coded_block_pattern = 0x3F;
- }
-
- XSelectInput(display, window, ExposureMask | KeyPressMask);
- XMapWindow(display, window);
- XSync(display, 0);
-
- gettimeofday(&start, NULL);
-
- for (reps = 0; reps < config.reps; ++reps)
- {
- if (config.pipeline & PIPELINE_STEP_MC)
- {
- assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, mbw * mbh, 0, &mb_array, &block_array) == Success);
- assert(XvMCFlushSurface(display, &surface) == Success);
- }
- if (config.pipeline & PIPELINE_STEP_CSC)
- assert(XvMCPutSurface(display, &surface, window, 0, 0, config.input_width, config.input_height, 0, 0, config.output_width, config.output_height, XVMC_FRAME_PICTURE) == Success);
- }
-
- gettimeofday(&stop, NULL);
-
- timeval_subtract(&diff, &stop, &start);
- diff_secs = (double)diff.tv_sec + (double)diff.tv_usec / 1000000.0;
-
- printf("XvMC Benchmark\n");
- printf("Input: %u,%u\nOutput: %u,%u\n", config.input_width, config.input_height, config.output_width, config.output_height);
- printf("Pipeline: ");
- if (config.pipeline & PIPELINE_STEP_MC)
- printf("|mc|");
- if (config.pipeline & PIPELINE_STEP_CSC)
- printf("|csc|");
- if (config.pipeline & PIPELINE_STEP_SWAP)
- printf("|swap|");
- printf("\n");
- printf("Reps: %u\n", config.reps);
- printf("Total time: %.2lf (%.2lf reps / sec)\n", diff_secs, config.reps / diff_secs);
-
- assert(XvMCDestroyBlocks(display, &block_array) == Success);
- assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success);
- assert(XvMCDestroySurface(display, &surface) == Success);
- assert(XvMCDestroyContext(display, &context) == Success);
-
- XvUngrabPort(display, port_num, CurrentTime);
- XDestroyWindow(display, window);
- XCloseDisplay(display);
-
- return 0;
-}
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 xvmc_private_h
-#define xvmc_private_h
-
-#include <X11/Xlib.h>
-#include <X11/extensions/XvMClib.h>
-
-#define BLOCK_SIZE_SAMPLES 64
-#define BLOCK_SIZE_BYTES (BLOCK_SIZE_SAMPLES * 2)
-
-struct pipe_video_context;
-struct pipe_surface;
-struct pipe_fence_handle;
-
-typedef struct
-{
- struct pipe_video_context *vpipe;
- struct pipe_surface *backbuffer;
-} XvMCContextPrivate;
-
-typedef struct
-{
- struct pipe_video_surface *pipe_vsfc;
- struct pipe_fence_handle *render_fence;
- struct pipe_fence_handle *disp_fence;
-
- /* Some XvMC functions take a surface but not a context,
- so we keep track of which context each surface belongs to. */
- XvMCContext *context;
-} XvMCSurfacePrivate;
-
-#endif /* xvmc_private_h */
* other structs such as this stw_winsys as well...
*/
gdi_sw_display(llvmpipe_screen(screen)->winsys,
- llvmpipe_texture(surface->texture)->dt,
+ llvmpipe_resource(surface->texture)->dt,
hDC);
}
* other structs such as this stw_winsys as well...
*/
gdi_sw_display(softpipe_screen(screen)->winsys,
- softpipe_texture(surface->texture)->dt,
+ softpipe_resource(surface->texture)->dt,
hDC);
}
+++ /dev/null
-TOP = ../../../..
-include $(TOP)/configs/current
-
-SUBDIRS = $(GALLIUM_WINSYS_DIRS)
-
-default install clean:
- @for dir in $(SUBDIRS) ; do \
- if [ -d $$dir ] ; then \
- (cd $$dir && $(MAKE) $@) || exit 1; \
- fi \
- done
+++ /dev/null
-TARGET = libnouveau_dri.so
-GALLIUMDIR = ../../..
-DRMDIR ?= /usr
-DRIDIR = ../../../../driclient
-
-OBJECTS = nouveau_screen_vl.o nouveau_context_vl.o nouveau_swapbuffers.o
-
-CFLAGS += -g -Wall -Werror=implicit-function-declaration -fPIC \
- -I${GALLIUMDIR}/include \
- -I${GALLIUMDIR}/winsys/g3dvl \
- -I${GALLIUMDIR}/winsys/drm/nouveau \
- -I${DRMDIR}/include \
- -I${DRMDIR}/include/drm \
- -I${DRMDIR}/include/nouveau \
- -I${GALLIUMDIR}/drivers \
- -I${GALLIUMDIR}/auxiliary \
- -I${DRIDIR}/include
-
-LDFLAGS += -L${DRMDIR}/lib \
- -L${DRIDIR}/lib \
- -L${GALLIUMDIR}/winsys/drm/nouveau/common \
- -L${GALLIUMDIR}/auxiliary \
- -L${GALLIUMDIR}/drivers/nv30 \
- -L${GALLIUMDIR}/drivers/nv40 \
- -L${GALLIUMDIR}/drivers/nv50
-
-LIBS += -lnouveaudrm -ldriclient -ldrm_nouveau -ldrm -lnv30 -lnv40 -lnv50 -lgallium -lm
-
-#############################################
-
-.PHONY = all clean libdriclient
-
-all: ${TARGET}
-
-${TARGET}: ${OBJECTS} libdriclient
- $(CC) ${LDFLAGS} -shared -o $@ ${OBJECTS} ${LIBS}
-
-libdriclient:
- cd ${DRIDIR}/src; ${MAKE}
-
-clean:
- cd ${DRIDIR}/src; ${MAKE} clean
- rm -rf ${OBJECTS} ${TARGET}
+++ /dev/null
-#include "nouveau_context_vl.h"
-#include <pipe/p_defines.h>
-#include <pipe/p_context.h>
-#include <pipe/p_screen.h>
-#include <util/u_memory.h>
-#include <common/nouveau_dri.h>
-#include <common/nouveau_local.h>
-#include <common/nouveau_winsys_pipe.h>
-#include "nouveau_screen_vl.h"
-
-/*
-#ifdef DEBUG
-static const struct dri_debug_control debug_control[] = {
- { "bo", DEBUG_BO },
- { NULL, 0 }
-};
-int __nouveau_debug = 0;
-#endif
-*/
-
-int
-nouveau_context_create(dri_context_t *dri_context)
-{
- dri_screen_t *dri_screen;
- struct nouveau_screen_vl *nv_screen;
- struct nouveau_context_vl *nv;
-
- assert (dri_context);
-
- dri_screen = dri_context->dri_screen;
- nv_screen = dri_screen->private;
- nv = CALLOC_STRUCT(nouveau_context_vl);
-
- if (!nv)
- return 1;
-
- if (nouveau_context_init(&nv_screen->base, dri_context->drm_context,
- (drmLock*)&dri_screen->sarea->lock, NULL, &nv->base))
- {
- FREE(nv);
- return 1;
- }
-
- dri_context->private = (void*)nv;
- nv->dri_context = dri_context;
- nv->nv_screen = nv_screen;
-
- /*
- driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache,
- nv->dri_screen->myNum, "nouveau");
-#ifdef DEBUG
- __nouveau_debug = driParseDebugString(getenv("NOUVEAU_DEBUG"),
- debug_control);
-#endif
- */
-
- nv->base.nvc->pctx[nv->base.pctx_id]->priv = nv;
-
- return 0;
-}
-
-void
-nouveau_context_destroy(dri_context_t *dri_context)
-{
- struct nouveau_context_vl *nv = dri_context->private;
-
- assert(dri_context);
-
- nouveau_context_cleanup(&nv->base);
-
- FREE(nv);
-}
-
-int
-nouveau_context_bind(struct nouveau_context_vl *nv, dri_drawable_t *dri_drawable)
-{
- assert(nv);
- assert(dri_drawable);
-
- if (nv->dri_drawable != dri_drawable)
- {
- nv->dri_drawable = dri_drawable;
- dri_drawable->private = nv;
- }
-
- return 0;
-}
-
-int
-nouveau_context_unbind(struct nouveau_context_vl *nv)
-{
- assert(nv);
-
- nv->dri_drawable = NULL;
-
- return 0;
-}
-
-/* Show starts here */
-
-int bind_pipe_drawable(struct pipe_context *pipe, Drawable drawable)
-{
- struct nouveau_context_vl *nv;
- dri_drawable_t *dri_drawable;
-
- assert(pipe);
-
- nv = pipe->priv;
-
- driCreateDrawable(nv->nv_screen->dri_screen, drawable, &dri_drawable);
-
- nouveau_context_bind(nv, dri_drawable);
-
- return 0;
-}
-
-int unbind_pipe_drawable(struct pipe_context *pipe)
-{
- assert (pipe);
-
- nouveau_context_unbind(pipe->priv);
-
- return 0;
-}
-
-struct pipe_context* create_pipe_context(Display *display, int screen)
-{
- dri_screen_t *dri_screen;
- dri_framebuffer_t dri_framebuf;
- dri_context_t *dri_context;
- struct nouveau_context_vl *nv;
-
- assert(display);
-
- driCreateScreen(display, screen, &dri_screen, &dri_framebuf);
- driCreateContext(dri_screen, XDefaultVisual(display, screen), &dri_context);
-
- nouveau_screen_create(dri_screen, &dri_framebuf);
- nouveau_context_create(dri_context);
-
- nv = dri_context->private;
-
- return nv->base.nvc->pctx[nv->base.pctx_id];
-}
-
-int destroy_pipe_context(struct pipe_context *pipe)
-{
- struct pipe_screen *screen;
- struct pipe_winsys *winsys;
- struct nouveau_context_vl *nv;
- dri_screen_t *dri_screen;
- dri_context_t *dri_context;
-
- assert(pipe);
-
- screen = pipe->screen;
- winsys = pipe->winsys;
- nv = pipe->priv;
- dri_context = nv->dri_context;
- dri_screen = dri_context->dri_screen;
-
- pipe->destroy(pipe);
- screen->destroy(screen);
- FREE(winsys);
-
- nouveau_context_destroy(dri_context);
- nouveau_screen_destroy(dri_screen);
- driDestroyContext(dri_context);
- driDestroyScreen(dri_screen);
-
- return 0;
-}
+++ /dev/null
-#ifndef __NOUVEAU_CONTEXT_VL_H__
-#define __NOUVEAU_CONTEXT_VL_H__
-
-#include <driclient.h>
-#include <nouveau/nouveau_winsys.h>
-#include <common/nouveau_context.h>
-
-/*#include "xmlconfig.h"*/
-
-struct nouveau_context_vl {
- struct nouveau_context base;
- struct nouveau_screen_vl *nv_screen;
- dri_context_t *dri_context;
- dri_drawable_t *dri_drawable;
- unsigned int last_stamp;
- /*driOptionCache dri_option_cache;*/
- drm_context_t drm_context;
- drmLock drm_lock;
-};
-
-extern int nouveau_context_create(dri_context_t *);
-extern void nouveau_context_destroy(dri_context_t *);
-extern int nouveau_context_bind(struct nouveau_context_vl *, dri_drawable_t *);
-extern int nouveau_context_unbind(struct nouveau_context_vl *);
-
-#ifdef DEBUG
-extern int __nouveau_debug;
-
-#define DEBUG_BO (1 << 0)
-
-#define DBG(flag, ...) do { \
- if (__nouveau_debug & (DEBUG_##flag)) \
- NOUVEAU_ERR(__VA_ARGS__); \
-} while(0)
-#else
-#define DBG(flag, ...)
-#endif
-
-#endif
+++ /dev/null
-#include "nouveau_screen_vl.h"
-#include <util/u_memory.h>
-#include <nouveau_drm.h>
-#include <common/nouveau_dri.h>
-#include <common/nouveau_local.h>
-
-#if NOUVEAU_DRM_HEADER_PATCHLEVEL != 12
-#error nouveau_drm.h version does not match expected version
-#endif
-
-/*
-PUBLIC const char __driConfigOptions[] =
-DRI_CONF_BEGIN
-DRI_CONF_END;
-static const GLuint __driNConfigOptions = 0;
-*/
-
-int nouveau_check_dri_drm_ddx(dri_version_t *dri, dri_version_t *drm, dri_version_t *ddx)
-{
- static const dri_version_t ddx_expected = {0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL};
- static const dri_version_t dri_expected = {4, 0, 0};
- static const dri_version_t drm_expected = {0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL};
-
- assert(dri);
- assert(drm);
- assert(ddx);
-
- if (dri->major != dri_expected.major || dri->minor < dri_expected.minor)
- {
- NOUVEAU_ERR("Unexpected DRI version.\n");
- return 1;
- }
- if (drm->major != drm_expected.major || drm->minor < drm_expected.minor)
- {
- NOUVEAU_ERR("Unexpected DRM version.\n");
- return 1;
- }
- if (ddx->major != ddx_expected.major || ddx->minor < ddx_expected.minor)
- {
- NOUVEAU_ERR("Unexpected DDX version.\n");
- return 1;
- }
-
- return 0;
-}
-
-int
-nouveau_screen_create(dri_screen_t *dri_screen, dri_framebuffer_t *dri_framebuf)
-{
- struct nouveau_dri *nv_dri = dri_framebuf->private;
- struct nouveau_screen_vl *nv_screen;
-
- assert(dri_screen);
- assert(dri_framebuf);
-
- if (nouveau_check_dri_drm_ddx(&dri_screen->dri, &dri_screen->drm, &dri_screen->ddx))
- return 1;
-
- nv_screen = CALLOC_STRUCT(nouveau_screen_vl);
-
- if (!nv_screen)
- return 1;
-
- if (nouveau_screen_init(nv_dri, dri_screen->fd, &nv_screen->base))
- {
- FREE(nv_screen);
- return 1;
- }
-
- /*
- driParseOptionInfo(&nv_screen->option_cache,
- __driConfigOptions, __driNConfigOptions);
- */
-
- nv_screen->dri_screen = dri_screen;
- dri_screen->private = (void*)nv_screen;
-
- return 0;
-}
-
-void
-nouveau_screen_destroy(dri_screen_t *dri_screen)
-{
- struct nouveau_screen_vl *nv_screen = dri_screen->private;
-
- nouveau_screen_cleanup(&nv_screen->base);
- FREE(nv_screen);
-}
+++ /dev/null
-#ifndef __NOUVEAU_SCREEN_VL_H__
-#define __NOUVEAU_SCREEN_VL_H__
-
-#include <driclient.h>
-#include <common/nouveau_screen.h>
-
-/* TODO: Investigate using DRI options for interesting things */
-/*#include "xmlconfig.h"*/
-
-struct nouveau_screen_vl
-{
- struct nouveau_screen base;
- dri_screen_t *dri_screen;
- /*driOptionCache option_cache;*/
-};
-
-int nouveau_screen_create(dri_screen_t *dri_screen, dri_framebuffer_t *dri_framebuf);
-void nouveau_screen_destroy(dri_screen_t *dri_screen);
-
-#endif
+++ /dev/null
-#include <driclient.h>
-#include <common/nouveau_local.h>
-#include <common/nouveau_screen.h>
-#include "nouveau_context_vl.h"
-#include "nouveau_swapbuffers.h"
-
-void
-nouveau_copy_buffer(dri_drawable_t *dri_drawable, struct pipe_surface *surf,
- const drm_clip_rect_t *rect)
-{
- struct nouveau_context_vl *nv = dri_drawable->private;
- struct pipe_context *pipe = nv->base.nvc->pctx[nv->base.pctx_id];
- drm_clip_rect_t *pbox;
- int nbox, i;
-
- LOCK_HARDWARE(&nv->base);
- if (!dri_drawable->num_cliprects) {
- UNLOCK_HARDWARE(&nv->base);
- return;
- }
- pbox = dri_drawable->cliprects;
- nbox = dri_drawable->num_cliprects;
-
- for (i = 0; i < nbox; i++, pbox++) {
- int sx, sy, dx, dy, w, h;
-
- sx = pbox->x1 - dri_drawable->x;
- sy = pbox->y1 - dri_drawable->y;
- dx = pbox->x1;
- dy = pbox->y1;
- w = pbox->x2 - pbox->x1;
- h = pbox->y2 - pbox->y1;
-
- pipe->surface_copy(pipe, nv->base.frontbuffer,
- dx, dy, surf, sx, sy, w, h);
- }
-
- FIRE_RING(nv->base.nvc->channel);
- UNLOCK_HARDWARE(&nv->base);
-}
-
-void
-nouveau_copy_sub_buffer(dri_drawable_t *dri_drawable, struct pipe_surface *surf, int x, int y, int w, int h)
-{
- if (surf) {
- drm_clip_rect_t rect;
- rect.x1 = x;
- rect.y1 = y;
- rect.x2 = x + w;
- rect.y2 = y + h;
-
- nouveau_copy_buffer(dri_drawable, surf, &rect);
- }
-}
-
-void
-nouveau_swap_buffers(dri_drawable_t *dri_drawable, struct pipe_surface *surf)
-{
- if (surf)
- nouveau_copy_buffer(dri_drawable, surf, NULL);
-}
-
-void
-nouveau_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf,
- void *context_private)
-{
- struct nouveau_context_vl *nv;
- dri_drawable_t *dri_drawable;
-
- assert(pws);
- assert(surf);
- assert(context_private);
-
- nv = context_private;
- dri_drawable = nv->dri_drawable;
-
- nouveau_copy_buffer(dri_drawable, surf, NULL);
-}
-
-void
-nouveau_contended_lock(struct nouveau_context *nv)
-{
- struct nouveau_context_vl *nv_vl = (struct nouveau_context_vl*)nv;
- dri_drawable_t *dri_drawable = nv_vl->dri_drawable;
- dri_screen_t *dri_screen = nv_vl->dri_context->dri_screen;
-
- /* If the window moved, may need to set a new cliprect now.
- *
- * NOTE: This releases and regains the hw lock, so all state
- * checking must be done *after* this call:
- */
- if (dri_drawable)
- DRI_VALIDATE_DRAWABLE_INFO(dri_screen, dri_drawable);
-}
+++ /dev/null
-#ifndef __NOUVEAU_SWAPBUFFERS_H__
-#define __NOUVEAU_SWAPBUFFERS_H__
-
-extern void nouveau_copy_buffer(dri_drawable_t *, struct pipe_surface *,
- const drm_clip_rect_t *);
-extern void nouveau_copy_sub_buffer(dri_drawable_t *, struct pipe_surface *,
- int x, int y, int w, int h);
-extern void nouveau_swap_buffers(dri_drawable_t *, struct pipe_surface *);
-
-#endif
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 vl_winsys_h
-#define vl_winsys_h
-
-#include <X11/Xlib.h>
-#include <pipe/p_defines.h>
-#include <pipe/p_format.h>
-
-struct pipe_screen;
-struct pipe_video_context;
-
-struct pipe_screen*
-vl_screen_create(Display *display, int screen);
-
-struct pipe_video_context*
-vl_video_create(Display *display, int screen,
- struct pipe_screen *p_screen,
- enum pipe_video_profile profile,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height);
-
-Drawable
-vl_video_bind_drawable(struct pipe_video_context *vpipe, Drawable drawable);
-
-#endif
+++ /dev/null
-# This makefile produces a "stand-alone" libXvMCg3dvl.so which is
-# based on Xlib (no DRI HW acceleration)
-
-TOP = ../../../../..
-include $(TOP)/configs/current
-
-XVMC_MAJOR = 1
-XVMC_MINOR = 0
-XVMC_LIB = XvMCg3dvl
-XVMC_LIB_NAME = lib$(XVMC_LIB).so
-XVMC_LIB_DEPS = $(EXTRA_LIB_PATH) -lXvMC -lXv -lX11 -lm
-
-INCLUDES = -I$(TOP)/src/gallium/include \
- -I$(TOP)/src/gallium/auxiliary \
- -I$(TOP)/src/gallium/drivers \
- -I$(TOP)/src/gallium/winsys/g3dvl
-
-DEFINES += -DGALLIUM_SOFTPIPE \
- -DGALLIUM_TRACE
-
-SOURCES = xsp_winsys.c
-
-# XXX: Hack, if we include libxvmctracker.a in LIBS none of the symbols are
-# pulled in by the linker because xsp_winsys.c doesn't refer to them
-OBJECTS = $(SOURCES:.c=.o) $(TOP)/src/gallium/state_trackers/xorg/xvmc/*.o
-
-LIBS = $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
- $(TOP)/src/gallium/auxiliary/libgallium.a
-
-.c.o:
- $(CC) -c $(INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@
-
-.S.o:
- $(CC) -c $(INCLUDES) $(DEFINES) $(CFLAGS) $< -o $@
-
-.PHONY: default $(TOP)/$(LIB_DIR)/gallium clean
-
-default: depend $(TOP)/$(LIB_DIR)/gallium $(TOP)/$(LIB_DIR)/gallium/$(XVMC_LIB_NAME)
-
-$(TOP)/$(LIB_DIR)/gallium:
- @mkdir -p $(TOP)/$(LIB_DIR)/gallium
-
-# Make the libXvMCg3dvl.so library
-$(TOP)/$(LIB_DIR)/gallium/$(XVMC_LIB_NAME): $(OBJECTS) $(LIBS) Makefile
- $(MKLIB) -o $(XVMC_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
- -major $(XVMC_MAJOR) -minor $(XVMC_MINOR) $(MKLIB_OPTIONS) \
- -install $(TOP)/$(LIB_DIR)/gallium -id $(INSTALL_LIB_DIR)/lib$(XVMC_LIB).1.dylib \
- $(XVMC_LIB_DEPS) $(OBJECTS) $(LIBS)
-
-depend: $(SOURCES) Makefile
- $(RM) depend
- touch depend
- $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDES) $(SOURCES)
-
-#install: default
-# $(INSTALL) -d $(INSTALL_DIR)/include/GL
-# $(INSTALL) -d $(INSTALL_DIR)/$(LIB_DIR)
-# $(INSTALL) -m 644 $(TOP)/include/GL/*.h $(INSTALL_DIR)/include/GL
-# @if [ -e $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) ]; then \
-# $(INSTALL) $(TOP)/$(LIB_DIR)/libGL* $(INSTALL_DIR)/$(LIB_DIR); \
-# fi
-
-clean: Makefile
- $(RM) $(TOP)/$(LIB_DIR)/gallium/$(XVMC_LIB_NAME)
- $(RM) *.o *~
- $(RM) depend depend.bak
-
--include depend
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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.
- *
- **************************************************************************/
-
-#include <vl_winsys.h>
-#include <X11/Xutil.h>
-#include <util/u_simple_screen.h>
-#include <pipe/p_state.h>
-#include <util/u_inlines.h>
-#include <util/u_format.h>
-#include <util/u_memory.h>
-#include <util/u_math.h>
-#include <softpipe/sp_winsys.h>
-#include <softpipe/sp_video_context.h>
-#include <softpipe/sp_texture.h>
-
-/* pipe_winsys implementation */
-
-struct xsp_pipe_winsys
-{
- struct pipe_winsys base;
- Display *display;
- int screen;
- XImage *fbimage;
-};
-
-struct xsp_context
-{
- Drawable drawable;
-
- void (*pipe_destroy)(struct pipe_video_context *vpipe);
-};
-
-struct xsp_buffer
-{
- struct pipe_buffer base;
- boolean is_user_buffer;
- void *data;
- void *mapped_data;
-};
-
-static struct pipe_buffer* xsp_buffer_create(struct pipe_winsys *pws, unsigned alignment, unsigned usage, unsigned size)
-{
- struct xsp_buffer *buffer;
-
- assert(pws);
-
- buffer = calloc(1, sizeof(struct xsp_buffer));
- pipe_reference_init(&buffer->base.reference, 1);
- buffer->base.alignment = alignment;
- buffer->base.usage = usage;
- buffer->base.size = size;
- buffer->data = align_malloc(size, alignment);
-
- return (struct pipe_buffer*)buffer;
-}
-
-static struct pipe_buffer* xsp_user_buffer_create(struct pipe_winsys *pws, void *data, unsigned size)
-{
- struct xsp_buffer *buffer;
-
- assert(pws);
-
- buffer = calloc(1, sizeof(struct xsp_buffer));
- pipe_reference_init(&buffer->base.reference, 1);
- buffer->base.size = size;
- buffer->is_user_buffer = TRUE;
- buffer->data = data;
-
- return (struct pipe_buffer*)buffer;
-}
-
-static void* xsp_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buffer, unsigned flags)
-{
- struct xsp_buffer *xsp_buf = (struct xsp_buffer*)buffer;
-
- assert(pws);
- assert(buffer);
-
- xsp_buf->mapped_data = xsp_buf->data;
-
- return xsp_buf->mapped_data;
-}
-
-static void xsp_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buffer)
-{
- struct xsp_buffer *xsp_buf = (struct xsp_buffer*)buffer;
-
- assert(pws);
- assert(buffer);
-
- xsp_buf->mapped_data = NULL;
-}
-
-static void xsp_buffer_destroy(struct pipe_buffer *buffer)
-{
- struct xsp_buffer *xsp_buf = (struct xsp_buffer*)buffer;
-
- assert(buffer);
-
- if (!xsp_buf->is_user_buffer)
- align_free(xsp_buf->data);
-
- free(xsp_buf);
-}
-
-static struct pipe_buffer* xsp_surface_buffer_create
-(
- struct pipe_winsys *pws,
- unsigned width,
- unsigned height,
- enum pipe_format format,
- unsigned usage,
- unsigned tex_usage,
- unsigned *stride
-)
-{
- const unsigned int ALIGNMENT = 1;
- unsigned nblocksy;
-
- nblocksy = util_format_get_nblocksy(format, height);
- *stride = align(util_format_get_stride(format, width), ALIGNMENT);
-
- return pws->buffer_create(pws, ALIGNMENT, usage,
- *stride * nblocksy);
-}
-
-static void xsp_fence_reference(struct pipe_winsys *pws, struct pipe_fence_handle **ptr, struct pipe_fence_handle *fence)
-{
- assert(pws);
- assert(ptr);
- assert(fence);
-}
-
-static int xsp_fence_signalled(struct pipe_winsys *pws, struct pipe_fence_handle *fence, unsigned flag)
-{
- assert(pws);
- assert(fence);
-
- return 0;
-}
-
-static int xsp_fence_finish(struct pipe_winsys *pws, struct pipe_fence_handle *fence, unsigned flag)
-{
- assert(pws);
- assert(fence);
-
- return 0;
-}
-
-static void xsp_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surface, void *context_private)
-{
- struct xsp_pipe_winsys *xsp_winsys;
- struct xsp_context *xsp_context;
-
- assert(pws);
- assert(surface);
- assert(context_private);
-
- xsp_winsys = (struct xsp_pipe_winsys*)pws;
- xsp_context = (struct xsp_context*)context_private;
- xsp_winsys->fbimage->width = surface->width;
- xsp_winsys->fbimage->height = surface->height;
- xsp_winsys->fbimage->bytes_per_line = surface->width * (xsp_winsys->fbimage->bits_per_pixel >> 3);
- xsp_winsys->fbimage->data = (char*)((struct xsp_buffer *)softpipe_texture(surface->texture)->buffer)->data + surface->offset;
-
- XPutImage
- (
- xsp_winsys->display, xsp_context->drawable,
- XDefaultGC(xsp_winsys->display, xsp_winsys->screen),
- xsp_winsys->fbimage, 0, 0, 0, 0,
- surface->width, surface->height
- );
- XFlush(xsp_winsys->display);
-}
-
-static const char* xsp_get_name(struct pipe_winsys *pws)
-{
- assert(pws);
- return "X11 SoftPipe";
-}
-
-static void xsp_destroy(struct pipe_winsys *pws)
-{
- struct xsp_pipe_winsys *xsp_winsys = (struct xsp_pipe_winsys*)pws;
-
- assert(pws);
-
- /* XDestroyImage() wants to free the data as well */
- xsp_winsys->fbimage->data = NULL;
-
- XDestroyImage(xsp_winsys->fbimage);
- FREE(xsp_winsys);
-}
-
-/* Called through pipe_video_context::destroy() */
-static void xsp_pipe_destroy(struct pipe_video_context *vpipe)
-{
- struct xsp_context *xsp_context;
-
- assert(vpipe);
-
- xsp_context = vpipe->priv;
-
- /* Call the original destroy */
- xsp_context->pipe_destroy(vpipe);
-
- FREE(xsp_context);
-}
-
-/* Show starts here */
-
-Drawable
-vl_video_bind_drawable(struct pipe_video_context *vpipe, Drawable drawable)
-{
- struct xsp_context *xsp_context;
- Drawable old_drawable;
-
- assert(vpipe);
-
- xsp_context = vpipe->priv;
- old_drawable = xsp_context->drawable;
- xsp_context->drawable = drawable;
-
- return old_drawable;
-}
-
-struct pipe_screen*
-vl_screen_create(Display *display, int screen)
-{
- struct xsp_pipe_winsys *xsp_winsys;
-
- assert(display);
-
- xsp_winsys = CALLOC_STRUCT(xsp_pipe_winsys);
- if (!xsp_winsys)
- return NULL;
-
- xsp_winsys->base.buffer_create = xsp_buffer_create;
- xsp_winsys->base.user_buffer_create = xsp_user_buffer_create;
- xsp_winsys->base.buffer_map = xsp_buffer_map;
- xsp_winsys->base.buffer_unmap = xsp_buffer_unmap;
- xsp_winsys->base.buffer_destroy = xsp_buffer_destroy;
- xsp_winsys->base.surface_buffer_create = xsp_surface_buffer_create;
- xsp_winsys->base.fence_reference = xsp_fence_reference;
- xsp_winsys->base.fence_signalled = xsp_fence_signalled;
- xsp_winsys->base.fence_finish = xsp_fence_finish;
- xsp_winsys->base.flush_frontbuffer = xsp_flush_frontbuffer;
- xsp_winsys->base.get_name = xsp_get_name;
- xsp_winsys->base.destroy = xsp_destroy;
- xsp_winsys->display = display;
- xsp_winsys->screen = screen;
- xsp_winsys->fbimage = XCreateImage
- (
- display,
- XDefaultVisual(display, screen),
- XDefaultDepth(display, screen),
- ZPixmap,
- 0,
- NULL,
- 0, /* Don't know the width and height until flush_frontbuffer */
- 0,
- 32,
- 0
- );
-
- if (!xsp_winsys->fbimage) {
- FREE(xsp_winsys);
- return NULL;
- }
-
- XInitImage(xsp_winsys->fbimage);
-
- return softpipe_create_screen(&xsp_winsys->base);
-}
-
-struct pipe_video_context*
-vl_video_create(Display *display, int screen,
- struct pipe_screen *p_screen,
- enum pipe_video_profile profile,
- enum pipe_video_chroma_format chroma_format,
- unsigned width, unsigned height)
-{
- struct pipe_video_context *vpipe;
- struct xsp_context *xsp_context;
-
- assert(p_screen);
- assert(width && height);
-
- vpipe = sp_video_create(p_screen, profile, chroma_format, width, height);
- if (!vpipe)
- return NULL;
-
- xsp_context = CALLOC_STRUCT(xsp_context);
- if (!xsp_context) {
- vpipe->destroy(vpipe);
- return NULL;
- }
-
- /* Override this so we can free our xsp_context when the pipe is freed */
- xsp_context->pipe_destroy = vpipe->destroy;
- vpipe->destroy = xsp_pipe_destroy;
-
- vpipe->priv = xsp_context;
-
- return vpipe;
-}
unsigned width, unsigned height, unsigned pitch)
{
struct pipe_surface *ps = NULL;
- struct pipe_texture *pt = NULL;
- struct pipe_texture tmpl;
+ struct pipe_resource *pt = NULL;
+ struct pipe_resource tmpl;
struct winsys_handle whandle;
+ unsigned bind = (PIPE_BIND_SCANOUT |
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_BLIT_DESTINATION |
+ PIPE_BIND_BLIT_SOURCE);
memset(&tmpl, 0, sizeof(tmpl));
- tmpl.tex_usage = PIPE_TEXTURE_USAGE_SCANOUT;
+ tmpl.bind = bind;
tmpl.target = PIPE_TEXTURE_2D;
tmpl.last_level = 0;
tmpl.depth0 = 1;
whandle.stride = pitch;
whandle.handle = handle;
- pt = pscreen->texture_from_handle(pscreen, &tmpl, &whandle);
+ pt = pscreen->resource_from_handle(pscreen, &tmpl, &whandle);
if (!pt)
return NULL;
- ps = pscreen->get_tex_surface(pscreen, pt, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ ps = pscreen->get_tex_surface(pscreen, pt, 0, 0, 0, bind);
/* we don't need the texture from this point on */
- pipe_texture_reference(&pt, NULL);
+ pipe_resource_reference(&pt, NULL);
return ps;
}
int drmFB,
struct drm_create_screen_arg *arg);
-boolean radeon_buffer_from_texture(struct drm_api* api,
- struct pipe_screen* screen,
- struct pipe_texture* texture,
- struct pipe_buffer** buffer,
- unsigned* stride);
-
-boolean radeon_handle_from_buffer(struct drm_api* api,
- struct pipe_screen* screen,
- struct pipe_buffer* buffer,
- unsigned* handle);
-
-boolean radeon_global_handle_from_buffer(struct drm_api* api,
- struct pipe_screen* screen,
- struct pipe_buffer* buffer,
- unsigned* handle);
-
void radeon_destroy_drm_api(struct drm_api* api);
/* Guess at whether this chipset should use r300g.
struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf);
int write = 0;
- if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) {
- if ((_buf->base.usage & PIPE_BUFFER_USAGE_VERTEX) ||
- (_buf->base.usage & PIPE_BUFFER_USAGE_INDEX))
+ if (flags & PIPE_TRANSFER_DONTBLOCK) {
+ if ((_buf->base.usage & PIPE_BIND_VERTEX_BUFFER) ||
+ (_buf->base.usage & PIPE_BIND_INDEX_BUFFER))
if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs))
return NULL;
}
if (buf->bo->ptr != NULL)
return buf->bo->ptr;
- if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) {
+ if (flags & PIPE_TRANSFER_DONTBLOCK) {
uint32_t domain;
if (radeon_bo_is_busy(buf->bo, &domain))
return NULL;
buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data);
}
- if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) {
+ if (flags & PIPE_TRANSFER_WRITE) {
write = 1;
}
{
uint32_t domain = 0;
- if (usage & PIPE_BUFFER_USAGE_GPU_WRITE) {
+ if (usage & PIPE_BIND_RENDER_TARGET) {
domain |= RADEON_GEM_DOMAIN_VRAM;
}
- if (usage & PIPE_BUFFER_USAGE_PIXEL) {
+ if (usage & PIPE_BIND_DEPTH_STENCIL) {
domain |= RADEON_GEM_DOMAIN_VRAM;
}
- if (usage & PIPE_BUFFER_USAGE_VERTEX) {
+ if (usage & PIPE_BIND_SAMPLER_VIEW) {
+ domain |= RADEON_GEM_DOMAIN_VRAM;
+ }
+ /* also need BIND_BLIT_SOURCE/DESTINATION ? */
+ if (usage & PIPE_BIND_VERTEX_BUFFER) {
domain |= RADEON_GEM_DOMAIN_GTT;
}
- if (usage & PIPE_BUFFER_USAGE_INDEX) {
+ if (usage & PIPE_BIND_INDEX_BUFFER) {
domain |= RADEON_GEM_DOMAIN_GTT;
}
pipe_reference_init(&buf->base.base.reference, 1);
buf->base.base.alignment = 0;
- buf->base.base.usage = PIPE_BUFFER_USAGE_PIXEL;
+ buf->base.base.usage = PIPE_BIND_SAMPLER_VIEW;
buf->base.base.size = 0;
buf->base.vtbl = &radeon_drm_buffer_vtbl;
buf->mgr = mgr;
desc.alignment = alignment;
desc.usage = usage;
- if (usage & PIPE_BUFFER_USAGE_CONSTANT)
+ if (usage & PIPE_BIND_CONSTANT_BUFFER)
provider = ws->mman;
- else if ((usage & PIPE_BUFFER_USAGE_VERTEX) ||
- (usage & PIPE_BUFFER_USAGE_INDEX))
+ else if ((usage & PIPE_BIND_VERTEX_BUFFER) ||
+ (usage & PIPE_BIND_INDEX_BUFFER))
provider = ws->cman;
else
provider = ws->kman;
static struct sw_displaytarget *
dri_sw_displaytarget_from_handle(struct sw_winsys *winsys,
- const struct pipe_texture *templ,
+ const struct pipe_resource *templ,
struct winsys_handle *whandle,
unsigned *stride)
{
static struct sw_displaytarget *
gdi_sw_displaytarget_from_handle(struct sw_winsys *winsys,
- const struct pipe_texture *templet,
+ const struct pipe_resource *templet,
struct winsys_handle *whandle,
unsigned *stride)
{
static struct sw_displaytarget *
null_sw_displaytarget_from_handle(struct sw_winsys *winsys,
- const struct pipe_texture *templet,
+ const struct pipe_resource *templet,
struct winsys_handle *whandle,
unsigned *stride)
{
struct wrapper_sw_displaytarget
{
struct wrapper_sw_winsys *winsys;
- struct pipe_texture *tex;
+ struct pipe_resource *tex;
struct pipe_transfer *transfer;
unsigned width;
wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt, unsigned *stride)
{
struct pipe_context *pipe = wdt->winsys->pipe;
- struct pipe_texture *tex = wdt->tex;
+ struct pipe_resource *tex = wdt->tex;
struct pipe_transfer *tr;
- tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0,
- PIPE_TRANSFER_READ_WRITE,
- 0, 0, wdt->width, wdt->height);
+ tr = pipe_get_transfer(pipe, tex, 0, 0, 0,
+ PIPE_TRANSFER_READ_WRITE,
+ 0, 0, wdt->width, wdt->height);
if (!tr)
return FALSE;
*stride = tr->stride;
wdt->stride = tr->stride;
- pipe->tex_transfer_destroy(pipe, tr);
+ pipe->transfer_destroy(pipe, tr);
return TRUE;
}
static struct sw_displaytarget *
wsw_dt_wrap_texture(struct wrapper_sw_winsys *wsw,
- struct pipe_texture *tex, unsigned *stride)
+ struct pipe_resource *tex, unsigned *stride)
{
struct wrapper_sw_displaytarget *wdt = CALLOC_STRUCT(wrapper_sw_displaytarget);
if (!wdt)
err_free:
FREE(wdt);
err_unref:
- pipe_texture_reference(&tex, NULL);
+ pipe_resource_reference(&tex, NULL);
return NULL;
}
static struct sw_displaytarget *
wsw_dt_create(struct sw_winsys *ws,
- unsigned tex_usage,
+ unsigned bind,
enum pipe_format format,
unsigned width, unsigned height,
unsigned alignment,
unsigned *stride)
{
struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws);
- struct pipe_texture templ;
- struct pipe_texture *tex;
+ struct pipe_resource templ;
+ struct pipe_resource *tex;
/*
* XXX Why don't we just get the template.
templ.width0 = width;
templ.height0 = height;
templ.format = format;
- templ.tex_usage = tex_usage;
+ templ.bind = bind;
/* XXX alignment: we can't do anything about this */
- tex = wsw->screen->texture_create(wsw->screen, &templ);
+ tex = wsw->screen->resource_create(wsw->screen, &templ);
if (!tex)
return NULL;
static struct sw_displaytarget *
wsw_dt_from_handle(struct sw_winsys *ws,
- const struct pipe_texture *templ,
+ const struct pipe_resource *templ,
struct winsys_handle *whandle,
unsigned *stride)
{
struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws);
- struct pipe_texture *tex;
+ struct pipe_resource *tex;
- tex = wsw->screen->texture_from_handle(wsw->screen, templ, whandle);
+ tex = wsw->screen->resource_from_handle(wsw->screen, templ, whandle);
if (!tex)
return NULL;
{
struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt);
struct pipe_context *pipe = wdt->winsys->pipe;
- struct pipe_texture *tex = wdt->tex;
+ struct pipe_resource *tex = wdt->tex;
struct pipe_transfer *tr;
void *ptr;
assert(!wdt->transfer);
- tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0,
- PIPE_TRANSFER_READ_WRITE,
- 0, 0, wdt->width, wdt->height);
+ tr = pipe_get_transfer(pipe, tex, 0, 0, 0,
+ PIPE_TRANSFER_READ_WRITE,
+ 0, 0, wdt->width, wdt->height);
if (!tr)
return NULL;
return wdt->ptr;
err:
- pipe->tex_transfer_destroy(pipe, tr);
+ pipe->transfer_destroy(pipe, tr);
return NULL;
}
return;
pipe->transfer_unmap(pipe, wdt->transfer);
- pipe->tex_transfer_destroy(pipe, wdt->transfer);
+ pipe->transfer_destroy(pipe, wdt->transfer);
wdt->transfer = NULL;
}
{
struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt);
- pipe_texture_reference(&wdt->tex, NULL);
+ pipe_resource_reference(&wdt->tex, NULL);
FREE(wdt);
}
#include <X11/extensions/XShm.h>
/**
- * Subclass of pipe_buffer for Xlib winsys.
+ * Display target for Xlib winsys.
* Low-level OS/window system memory buffer
*/
struct xm_displaytarget
static struct sw_displaytarget *
xm_displaytarget_from_handle(struct sw_winsys *winsys,
- const struct pipe_texture *templet,
+ const struct pipe_resource *templet,
struct winsys_handle *whandle,
unsigned *stride)
{
struct st_context *st = ctx->st;
struct pipe_context *pipe = st->pipe;
struct cso_context *cso = ctx->st->cso_context;
- struct pipe_buffer *vbuffer;
+ struct pipe_resource *vbuffer;
+ struct pipe_transfer *vbuffer_transfer;
GLuint i, numTexCoords, numAttribs;
GLboolean emitColor;
uint semantic_names[2 + MAX_TEXTURE_UNITS];
/* create the vertex buffer */
- vbuffer = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
+ vbuffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER,
numAttribs * 4 * 4 * sizeof(GLfloat));
/* load vertex buffer */
} while (0)
const GLfloat x0 = x, y0 = y, x1 = x + width, y1 = y + height;
- GLfloat *vbuf = (GLfloat *) pipe_buffer_map(pipe->screen, vbuffer,
- PIPE_BUFFER_USAGE_CPU_WRITE);
+ GLfloat *vbuf = (GLfloat *) pipe_buffer_map(pipe, vbuffer,
+ PIPE_TRANSFER_WRITE,
+ &vbuffer_transfer);
GLuint attr;
z = CLAMP(z, 0.0f, 1.0f);
}
}
- pipe_buffer_unmap(pipe->screen, vbuffer);
+ pipe_buffer_unmap(pipe, vbuffer, vbuffer_transfer);
#undef SET_ATTRIB
}
numAttribs); /* attribs/vert */
- pipe_buffer_reference(&vbuffer, NULL);
+ pipe_resource_reference(&vbuffer, NULL);
/* restore state */
cso_restore_viewport(cso);
unsigned shader_type)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_buffer **cbuf = &st->state.constants[shader_type];
+ struct pipe_resource **cbuf = &st->state.constants[shader_type];
assert(shader_type == PIPE_SHADER_VERTEX ||
shader_type == PIPE_SHADER_FRAGMENT);
/* We always need to get a new buffer, to keep the drivers simple and
* avoid gratuitous rendering synchronization.
*/
- pipe_buffer_reference(cbuf, NULL );
- *cbuf = pipe_buffer_create(pipe->screen, 16,
- PIPE_BUFFER_USAGE_CONSTANT,
- paramBytes );
+ pipe_resource_reference(cbuf, NULL );
+ *cbuf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_CONSTANT_BUFFER,
+ paramBytes );
if (ST_DEBUG & DEBUG_CONSTANTS) {
debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n",
/**
* When doing GL render to texture, we have to be sure that finalize_texture()
- * didn't yank out the pipe_texture that we earlier created a surface for.
+ * didn't yank out the pipe_resource that we earlier created a surface for.
* Check for that here and create a new surface if needed.
*/
static void
struct st_renderbuffer *strb)
{
struct pipe_screen *screen = st->pipe->screen;
- struct pipe_texture *texture = strb->rtt->pt;
+ struct pipe_resource *resource = strb->rtt->pt;
int rtt_width = strb->Base.Width;
int rtt_height = strb->Base.Height;
if (!strb->surface ||
- strb->surface->texture != texture ||
+ strb->surface->texture != resource ||
strb->surface->width != rtt_width ||
strb->surface->height != rtt_height) {
GLuint level;
/* find matching mipmap level size */
- for (level = 0; level <= texture->last_level; level++) {
- if (u_minify(texture->width0, level) == rtt_width &&
- u_minify(texture->height0, level) == rtt_height) {
+ for (level = 0; level <= resource->last_level; level++) {
+ if (u_minify(resource->width0, level) == rtt_width &&
+ u_minify(resource->height0, level) == rtt_height) {
pipe_surface_reference(&strb->surface, NULL);
strb->surface = screen->get_tex_surface(screen,
- texture,
- strb->rtt_face,
- level,
- strb->rtt_slice,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ resource,
+ strb->rtt_face,
+ level,
+ strb->rtt_slice,
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION );
#if 0
printf("-- alloc new surface %d x %d into tex %p\n",
strb->surface->width, strb->surface->height,
}
-static struct pipe_texture *
+static struct pipe_resource *
create_color_map_texture(GLcontext *ctx)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
enum pipe_format format;
const uint texSize = 256; /* simple, and usually perfect */
/* find an RGBA texture format */
format = st_choose_format(pipe->screen, GL_RGBA,
- PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER);
+ PIPE_TEXTURE_2D, PIPE_BIND_SAMPLER_VIEW);
/* create texture for color map/table */
pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0,
- texSize, texSize, 1, PIPE_TEXTURE_USAGE_SAMPLER);
+ texSize, texSize, 1, PIPE_BIND_SAMPLER_VIEW);
return pt;
}
* Update the pixelmap texture with the contents of the R/G/B/A pixel maps.
*/
static void
-load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt)
+load_color_map_texture(GLcontext *ctx, struct pipe_resource *pt)
{
struct pipe_context *pipe = ctx->st->pipe;
struct pipe_transfer *transfer;
transfer = st_cond_flush_get_tex_transfer(st_context(ctx),
pt, 0, 0, 0, PIPE_TRANSFER_WRITE,
0, 0, texSize, texSize);
- dest = (uint *) pipe->transfer_map(pipe, transfer);
+ dest = (uint *) pipe_transfer_map(pipe, transfer);
/* Pack four 1D maps into a 2D texture:
* R map is placed horizontally, indexed by S, in channel 0
}
}
- pipe->transfer_unmap(pipe, transfer);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe_transfer_unmap(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
}
if (ST_DEBUG & DEBUG_FALLBACK)
debug_printf("%s: fallback processing\n", __FUNCTION__);
- color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture,
+ color_trans = st_cond_flush_get_tex_transfer(st,
+ color_strb->texture,
0, 0, 0,
PIPE_TRANSFER_READ, xpos, ypos,
width, height);
}
free(buf);
- pipe->tex_transfer_destroy(pipe, color_trans);
+ pipe->transfer_destroy(pipe, color_trans);
}
}
free(buf);
- pipe->tex_transfer_destroy(pipe, color_trans);
+ pipe->transfer_destroy(pipe, color_trans);
}
pipe_put_tile_rgba(pipe, color_trans, 0, 0, width, height, buf);
free(buf);
- pipe->tex_transfer_destroy(pipe, color_trans);
+ pipe->transfer_destroy(pipe, color_trans);
}
/** Bitmap's Z position */
GLfloat zpos;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_transfer *trans;
GLboolean empty;
/**
* Create a texture which represents a bitmap image.
*/
-static struct pipe_texture *
+static struct pipe_resource *
make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height,
const struct gl_pixelstore_attrib *unpack,
const GLubyte *bitmap)
struct pipe_context *pipe = ctx->st->pipe;
struct pipe_transfer *transfer;
ubyte *dest;
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
/* PBO source... */
bitmap = _mesa_map_pbo_source(ctx, unpack, bitmap);
*/
pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, ctx->st->bitmap.tex_format,
0, width, height, 1,
- PIPE_TEXTURE_USAGE_SAMPLER);
+ PIPE_BIND_SAMPLER_VIEW);
if (!pt) {
_mesa_unmap_pbo_source(ctx, unpack);
return NULL;
PIPE_TRANSFER_WRITE,
0, 0, width, height);
- dest = pipe->transfer_map(pipe, transfer);
+ dest = pipe_transfer_map(pipe, transfer);
/* Put image into texture transfer */
memset(dest, 0xff, height * transfer->stride);
_mesa_unmap_pbo_source(ctx, unpack);
/* Release transfer */
- pipe->transfer_unmap(pipe, transfer);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe_transfer_unmap(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
return pt;
}
GLuint i;
if (st->bitmap.vbuf_slot >= max_slots) {
- pipe_buffer_reference(&st->bitmap.vbuf, NULL);
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
st->bitmap.vbuf_slot = 0;
}
if (!st->bitmap.vbuf) {
- st->bitmap.vbuf = pipe_buffer_create(pipe->screen, 32,
- PIPE_BUFFER_USAGE_VERTEX,
+ st->bitmap.vbuf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_VERTEX_BUFFER,
max_slots * sizeof(st->bitmap.vertices));
}
cache->ymax = -1000000;
if (cache->trans) {
- pipe->tex_transfer_destroy(pipe, cache->trans);
+ pipe->transfer_destroy(pipe, cache->trans);
cache->trans = NULL;
}
cache->texture = st_texture_create(st, PIPE_TEXTURE_2D,
st->bitmap.tex_format, 0,
BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT,
- 1, PIPE_TEXTURE_USAGE_SAMPLER);
+ 1,
+ PIPE_BIND_SAMPLER_VIEW);
}
PIPE_TRANSFER_WRITE, 0, 0,
BITMAP_CACHE_WIDTH,
BITMAP_CACHE_HEIGHT);
- cache->buffer = pipe->transfer_map(pipe, cache->trans);
+ cache->buffer = pipe_transfer_map(pipe, cache->trans);
/* init image to all 0xff */
memset(cache->buffer, 0xff, cache->trans->stride * BITMAP_CACHE_HEIGHT);
if (cache->trans) {
if (0)
print_cache(cache);
- pipe->transfer_unmap(pipe, cache->trans);
+ pipe_transfer_unmap(pipe, cache->trans);
cache->buffer = NULL;
- pipe->tex_transfer_destroy(pipe, cache->trans);
+ pipe->transfer_destroy(pipe, cache->trans);
cache->trans = NULL;
}
}
/* release/free the texture */
- pipe_texture_reference(&cache->texture, NULL);
+ pipe_resource_reference(&cache->texture, NULL);
reset_cache(st);
}
/* Release vertex buffer to avoid synchronous rendering if we were
* to map it in the next frame.
*/
- pipe_buffer_reference(&st->bitmap.vbuf, NULL);
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
st->bitmap.vbuf_slot = 0;
}
const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap )
{
struct st_context *st = ctx->st;
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
if (width == 0 || height == 0)
return;
}
/* release/free the texture */
- pipe_texture_reference(&pt, NULL);
+ pipe_resource_reference(&pt, NULL);
}
}
/* find a usable texture format */
if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM;
}
else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM;
}
else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM;
}
else {
}
if (st->bitmap.vbuf) {
- pipe_buffer_reference(&st->bitmap.vbuf, NULL);
+ pipe_resource_reference(&st->bitmap.vbuf, NULL);
st->bitmap.vbuf = NULL;
}
if (cache) {
if (cache->trans) {
- pipe->transfer_unmap(pipe, cache->trans);
- pipe->tex_transfer_destroy(pipe, cache->trans);
+ pipe_transfer_unmap(pipe, cache->trans);
+ pipe->transfer_destroy(pipe, cache->trans);
}
- pipe_texture_reference(&st->bitmap.cache->texture, NULL);
+ pipe_resource_reference(&st->bitmap.cache->texture, NULL);
free(st->bitmap.cache);
st->bitmap.cache = NULL;
}
srcAtt->CubeMapFace,
srcAtt->TextureLevel,
srcAtt->Zoffset,
- PIPE_BUFFER_USAGE_GPU_READ);
+ PIPE_BIND_BLIT_SOURCE);
if(!srcSurf)
return;
struct st_buffer_object *st_obj = st_buffer_object(obj);
assert(obj->RefCount == 0);
+ assert(st_obj->transfer == NULL);
if (st_obj->buffer)
- pipe_buffer_reference(&st_obj->buffer, NULL);
+ pipe_resource_reference(&st_obj->buffer, NULL);
free(st_obj);
}
if (!data)
return;
- st_cond_flush_pipe_buffer_write(st_context(ctx), st_obj->buffer,
- offset, size, data);
+ /* Now that transfers are per-context, we don't have to figure out
+ * flushing here. Usually drivers won't need to flush in this case
+ * even if the buffer is currently referenced by hardware - they
+ * just queue the upload as dma rather than mapping the underlying
+ * buffer directly.
+ */
+ pipe_buffer_write(st_context(ctx)->pipe,
+ st_obj->buffer,
+ offset, size, data);
}
if (!size)
return;
- st_cond_flush_pipe_buffer_read(st_context(ctx), st_obj->buffer,
- offset, size, data);
+ pipe_buffer_read(st_context(ctx)->pipe, st_obj->buffer,
+ offset, size, data);
}
switch(target) {
case GL_PIXEL_PACK_BUFFER_ARB:
case GL_PIXEL_UNPACK_BUFFER_ARB:
- buffer_usage = PIPE_BUFFER_USAGE_PIXEL;
+ buffer_usage = (PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION);
break;
case GL_ARRAY_BUFFER_ARB:
- buffer_usage = PIPE_BUFFER_USAGE_VERTEX;
+ buffer_usage = PIPE_BIND_VERTEX_BUFFER;
break;
case GL_ELEMENT_ARRAY_BUFFER_ARB:
- buffer_usage = PIPE_BUFFER_USAGE_INDEX;
+ buffer_usage = PIPE_BIND_INDEX_BUFFER;
break;
default:
buffer_usage = 0;
}
- pipe_buffer_reference( &st_obj->buffer, NULL );
+ pipe_resource_reference( &st_obj->buffer, NULL );
if (size != 0) {
- st_obj->buffer = pipe_buffer_create(pipe->screen, 32, buffer_usage, size);
+ st_obj->buffer = pipe_buffer_create(pipe->screen, buffer_usage, size);
if (!st_obj->buffer) {
return GL_FALSE;
switch (access) {
case GL_WRITE_ONLY:
- flags = PIPE_BUFFER_USAGE_CPU_WRITE;
+ flags = PIPE_TRANSFER_WRITE;
break;
case GL_READ_ONLY:
- flags = PIPE_BUFFER_USAGE_CPU_READ;
+ flags = PIPE_TRANSFER_READ;
break;
case GL_READ_WRITE:
- /* fall-through */
default:
- flags = PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE;
+ flags = PIPE_TRANSFER_READ_WRITE;
break;
}
- obj->Pointer = st_cond_flush_pipe_buffer_map(st_context(ctx),
- st_obj->buffer,
- flags);
+ obj->Pointer = pipe_buffer_map(st_context(ctx)->pipe,
+ st_obj->buffer,
+ flags,
+ &st_obj->transfer);
+
if (obj->Pointer) {
obj->Offset = 0;
obj->Length = obj->Size;
{
struct pipe_context *pipe = st_context(ctx)->pipe;
struct st_buffer_object *st_obj = st_buffer_object(obj);
- uint flags = 0x0;
+ enum pipe_transfer_usage flags = 0x0;
if (access & GL_MAP_WRITE_BIT)
- flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
+ flags |= PIPE_TRANSFER_WRITE;
if (access & GL_MAP_READ_BIT)
- flags |= PIPE_BUFFER_USAGE_CPU_READ;
+ flags |= PIPE_TRANSFER_READ;
if (access & GL_MAP_FLUSH_EXPLICIT_BIT)
- flags |= PIPE_BUFFER_USAGE_FLUSH_EXPLICIT;
+ flags |= PIPE_TRANSFER_FLUSH_EXPLICIT;
if (access & GL_MAP_UNSYNCHRONIZED_BIT)
- flags |= PIPE_BUFFER_USAGE_UNSYNCHRONIZED;
+ flags |= PIPE_TRANSFER_UNSYNCHRONIZED;
/* ... other flags ...
*/
if (access & MESA_MAP_NOWAIT_BIT)
- flags |= PIPE_BUFFER_USAGE_DONTBLOCK;
+ flags |= PIPE_TRANSFER_DONTBLOCK;
assert(offset >= 0);
assert(length >= 0);
obj->Pointer = &st_bufferobj_zero_length_range;
}
else {
- obj->Pointer = pipe_buffer_map_range(pipe->screen, st_obj->buffer, offset, length, flags);
+ obj->Pointer = pipe_buffer_map_range(pipe,
+ st_obj->buffer,
+ offset, length,
+ flags,
+ &st_obj->transfer);
if (obj->Pointer) {
obj->Pointer = (ubyte *) obj->Pointer + offset;
}
assert(offset >= 0);
assert(length >= 0);
assert(offset + length <= obj->Length);
+ assert(obj->Pointer);
if (!length)
return;
- pipe_buffer_flush_mapped_range(pipe->screen, st_obj->buffer,
+ pipe_buffer_flush_mapped_range(pipe, st_obj->transfer,
obj->Offset + offset, length);
}
struct pipe_context *pipe = st_context(ctx)->pipe;
struct st_buffer_object *st_obj = st_buffer_object(obj);
- if(obj->Length)
- pipe_buffer_unmap(pipe->screen, st_obj->buffer);
+ if (obj->Length)
+ pipe_buffer_unmap(pipe, st_obj->buffer, st_obj->transfer);
+ st_obj->transfer = NULL;
obj->Pointer = NULL;
obj->Offset = 0;
obj->Length = 0;
struct pipe_context *pipe = st_context(ctx)->pipe;
struct st_buffer_object *srcObj = st_buffer_object(src);
struct st_buffer_object *dstObj = st_buffer_object(dst);
+ struct pipe_transfer *src_transfer;
+ struct pipe_transfer *dst_transfer;
ubyte *srcPtr, *dstPtr;
if(!size)
assert(!src->Pointer);
assert(!dst->Pointer);
- srcPtr = (ubyte *) pipe_buffer_map_range(pipe->screen,
+ srcPtr = (ubyte *) pipe_buffer_map_range(pipe,
srcObj->buffer,
readOffset, size,
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &src_transfer);
- dstPtr = (ubyte *) pipe_buffer_map_range(pipe->screen,
+ dstPtr = (ubyte *) pipe_buffer_map_range(pipe,
dstObj->buffer,
writeOffset, size,
- PIPE_BUFFER_USAGE_CPU_WRITE);
+ PIPE_TRANSFER_WRITE,
+ &dst_transfer);
if (srcPtr && dstPtr)
memcpy(dstPtr + writeOffset, srcPtr + readOffset, size);
- pipe_buffer_unmap(pipe->screen, srcObj->buffer);
- pipe_buffer_unmap(pipe->screen, dstObj->buffer);
+ pipe_buffer_unmap(pipe, srcObj->buffer, src_transfer);
+ pipe_buffer_unmap(pipe, dstObj->buffer, dst_transfer);
+}
+
+
+/* TODO: if buffer wasn't created with appropriate usage flags, need
+ * to recreate it now and copy contents -- or possibly create a
+ * gallium entrypoint to extend the usage flags and let the driver
+ * decide if a copy is necessary.
+ */
+void
+st_bufferobj_validate_usage(struct st_context *st,
+ struct st_buffer_object *obj,
+ unsigned usage)
+{
}
struct st_context;
struct gl_buffer_object;
-struct pipe_buffer;
+struct pipe_resource;
/**
* State_tracker vertex/pixel buffer object, derived from Mesa's
struct st_buffer_object
{
struct gl_buffer_object Base;
- struct pipe_buffer *buffer;
+ struct pipe_resource *buffer; /* GPU storage */
+ struct pipe_transfer *transfer; /* In-progress map information */
};
st->clear.vs = NULL;
}
if (st->clear.vbuf) {
- pipe_buffer_reference(&st->clear.vbuf, NULL);
+ pipe_resource_reference(&st->clear.vbuf, NULL);
st->clear.vbuf = NULL;
}
}
GLuint i;
if (st->clear.vbuf_slot >= max_slots) {
- pipe_buffer_reference(&st->clear.vbuf, NULL);
+ pipe_resource_reference(&st->clear.vbuf, NULL);
st->clear.vbuf_slot = 0;
}
if (!st->clear.vbuf) {
- st->clear.vbuf = pipe_buffer_create(pipe->screen, 32,
- PIPE_BUFFER_USAGE_VERTEX,
+ st->clear.vbuf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_VERTEX_BUFFER,
max_slots * sizeof(st->clear.vertices));
}
/* Release vertex buffer to avoid synchronous rendering if we were
* to map it in the next frame.
*/
- pipe_buffer_reference(&st->clear.vbuf, NULL);
+ pipe_resource_reference(&st->clear.vbuf, NULL);
st->clear.vbuf_slot = 0;
}
* If width, height are not POT and the driver only handles POT textures,
* allocate the next larger size of texture that is POT.
*/
-static struct pipe_texture *
+static struct pipe_resource *
alloc_texture(struct st_context *st, GLsizei width, GLsizei height,
enum pipe_format texFormat)
{
struct pipe_context *pipe = st->pipe;
struct pipe_screen *screen = pipe->screen;
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
int ptw, pth;
ptw = width;
}
pt = st_texture_create(st, PIPE_TEXTURE_2D, texFormat, 0,
- ptw, pth, 1, PIPE_TEXTURE_USAGE_SAMPLER);
+ ptw, pth, 1, PIPE_BIND_SAMPLER_VIEW);
return pt;
}
* Make texture containing an image for glDrawPixels image.
* If 'pixels' is NULL, leave the texture image data undefined.
*/
-static struct pipe_texture *
+static struct pipe_resource *
make_texture(struct st_context *st,
GLsizei width, GLsizei height, GLenum format, GLenum type,
const struct gl_pixelstore_attrib *unpack,
GLcontext *ctx = st->ctx;
struct pipe_context *pipe = st->pipe;
gl_format mformat;
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
enum pipe_format pipeFormat;
GLuint cpp;
GLenum baseFormat;
width, height);
/* map texture transfer */
- dest = pipe->transfer_map(pipe, transfer);
+ dest = pipe_transfer_map(pipe, transfer);
/* Put image into texture transfer.
unpack);
/* unmap */
- pipe->transfer_unmap(pipe, transfer);
- pipe->tex_transfer_destroy(pipe, transfer);
+ pipe_transfer_unmap(pipe, transfer);
+ pipe->transfer_destroy(pipe, transfer);
assert(success);
}
{
- struct pipe_buffer *buf;
+ struct pipe_resource *buf;
/* allocate/load buffer object with vertex data */
- buf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
+ buf = pipe_buffer_create(pipe->screen,
+ PIPE_BIND_VERTEX_BUFFER,
sizeof(verts));
st_no_flush_pipe_buffer_write(st, buf, 0, sizeof(verts), verts);
PIPE_PRIM_QUADS,
4, /* verts */
3); /* attribs/vert */
- pipe_buffer_reference(&buf, NULL);
+ pipe_resource_reference(&buf, NULL);
}
}
usage, x, y,
width, height);
- stmap = pipe->transfer_map(pipe, pt);
+ stmap = pipe_transfer_map(pipe, pt);
pixels = _mesa_map_pbo_source(ctx, &clippedUnpack, pixels);
assert(pixels);
}
/* now pack the stencil (and Z) values in the dest format */
- switch (pt->texture->format) {
+ switch (pt->resource->format) {
case PIPE_FORMAT_S8_USCALED:
{
ubyte *dest = stmap + spanY * pt->stride + spanX;
_mesa_unmap_pbo_source(ctx, &clippedUnpack);
/* unmap the stencil buffer */
- pipe->transfer_unmap(pipe, pt);
- pipe->tex_transfer_destroy(pipe, pt);
+ pipe_transfer_unmap(pipe, pt);
+ pipe->transfer_destroy(pipe, pt);
}
/* draw with textured quad */
{
- struct pipe_texture *pt
+ struct pipe_resource *pt
= make_texture(st, width, height, format, type, unpack, pixels);
if (pt) {
struct pipe_sampler_view *sv = st_sampler_view_from_texture(st->pipe, pt);
color, GL_FALSE);
pipe_sampler_view_reference(&sv, NULL);
}
- pipe_texture_reference(&pt, NULL);
+ pipe_resource_reference(&pt, NULL);
}
}
}
usage, dstx, dsty,
width, height);
- assert(util_format_get_blockwidth(ptDraw->texture->format) == 1);
- assert(util_format_get_blockheight(ptDraw->texture->format) == 1);
+ assert(util_format_get_blockwidth(ptDraw->resource->format) == 1);
+ assert(util_format_get_blockheight(ptDraw->resource->format) == 1);
/* map the stencil buffer */
- drawMap = pipe->transfer_map(pipe, ptDraw);
+ drawMap = pipe_transfer_map(pipe, ptDraw);
/* draw */
/* XXX PixelZoom not handled yet */
dst = drawMap + y * ptDraw->stride;
src = buffer + i * width;
- switch (ptDraw->texture->format) {
+ switch (ptDraw->resource->format) {
case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
{
uint *dst4 = (uint *) dst;
free(buffer);
/* unmap the stencil buffer */
- pipe->transfer_unmap(pipe, ptDraw);
- pipe->tex_transfer_destroy(pipe, ptDraw);
+ pipe_transfer_unmap(pipe, ptDraw);
+ pipe->transfer_destroy(pipe, ptDraw);
}
struct pipe_screen *screen = pipe->screen;
struct st_renderbuffer *rbRead;
void *driver_vp, *driver_fp;
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
struct pipe_sampler_view *sv;
GLfloat *color;
enum pipe_format srcFormat, texFormat;
srcFormat = rbRead->texture->format;
if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
texFormat = srcFormat;
}
else {
if (type == GL_DEPTH) {
texFormat = st_choose_format(screen, GL_DEPTH_COMPONENT,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL);
+ PIPE_BIND_DEPTH_STENCIL);
assert(texFormat != PIPE_FORMAT_NONE);
}
else {
/* default color format */
texFormat = st_choose_format(screen, GL_RGBA, PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER);
+ PIPE_BIND_SAMPLER_VIEW);
assert(texFormat != PIPE_FORMAT_NONE);
}
}
sv = st_sampler_view_from_texture(st->pipe, pt);
if (!sv) {
- pipe_texture_reference(&pt, NULL);
+ pipe_resource_reference(&pt, NULL);
return;
}
/* copy source framebuffer surface into mipmap/texture */
struct pipe_surface *psRead = screen->get_tex_surface(screen,
rbRead->texture, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ);
+ PIPE_BIND_BLIT_SOURCE);
struct pipe_surface *psTex = screen->get_tex_surface(screen, pt, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE );
-
+ PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_BLIT_DESTINATION);
pipe->surface_copy(pipe,
psTex, /* dest surf */
pack.SkipPixels, pack.SkipRows, /* dest pos */
free(buf);
}
- pipe->tex_transfer_destroy(pipe, ptRead);
- pipe->tex_transfer_destroy(pipe, ptTex);
+ pipe->transfer_destroy(pipe, ptRead);
+ pipe->transfer_destroy(pipe, ptTex);
}
/* OK, the texture 'pt' contains the src image/pixels. Now draw a
driver_fp,
color, invertTex);
- pipe_texture_reference(&pt, NULL);
+ pipe_resource_reference(&pt, NULL);
pipe_sampler_view_reference(&sv, NULL);
}
struct pipe_surface *ps;
unsigned usage;
- usage = PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
+ usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_BLIT_SOURCE | PIPE_BIND_BLIT_DESTINATION;
ps = st_manager_get_egl_image_surface(st, (void *) image_handle, usage);
if (ps) {
strb->Base.Width = ps->width;
strb->Base.InternalFormat = strb->Base._BaseFormat;
pipe_surface_reference(&strb->surface, ps);
- pipe_texture_reference(&strb->texture, ps->texture);
+ pipe_resource_reference(&strb->texture, ps->texture);
pipe_surface_reference(&ps, NULL);
}
stObj->pipe = ctx->st->pipe;
/* FIXME create a non-default sampler view from the pipe_surface? */
- pipe_texture_reference(&stImage->pt, ps->texture);
+ pipe_resource_reference(&stImage->pt, ps->texture);
_mesa_dirty_texobj(ctx, texObj, GL_TRUE);
}
struct pipe_surface *ps;
unsigned usage;
- usage = PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
+ usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_BLIT_DESTINATION | PIPE_BIND_BLIT_SOURCE;
ps = st_manager_get_egl_image_surface(st, (void *) image_handle, usage);
if (ps) {
st_bind_surface(ctx, target, texObj, texImage, ps);
return strb->data != NULL;
}
else {
- struct pipe_texture template;
- unsigned surface_usage;
+ struct pipe_resource template;
/* Free the old surface and texture
*/
pipe_surface_reference( &strb->surface, NULL );
- pipe_texture_reference( &strb->texture, NULL );
+ pipe_resource_reference( &strb->texture, NULL );
pipe_sampler_view_reference(&strb->sampler_view, NULL);
/* Setup new texture template.
template.last_level = 0;
template.nr_samples = rb->NumSamples;
if (util_format_is_depth_or_stencil(format)) {
- template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ template.bind = PIPE_BIND_DEPTH_STENCIL;
}
else {
- template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_RENDER_TARGET);
+ template.bind = (PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_RENDER_TARGET);
}
- /* Probably need dedicated flags for surface usage too:
- */
- surface_usage = (PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
-#if 0
- PIPE_BUFFER_USAGE_CPU_READ |
- PIPE_BUFFER_USAGE_CPU_WRITE);
-#endif
-
- strb->texture = screen->texture_create(screen, &template);
+ strb->texture = screen->resource_create(screen, &template);
if (!strb->texture)
return FALSE;
strb->surface = screen->get_tex_surface(screen,
strb->texture,
0, 0, 0,
- surface_usage);
+ template.bind);
if (strb->surface) {
assert(strb->surface->texture);
assert(strb->surface->format);
struct st_renderbuffer *strb = st_renderbuffer(rb);
ASSERT(strb);
pipe_surface_reference(&strb->surface, NULL);
- pipe_texture_reference(&strb->texture, NULL);
+ pipe_resource_reference(&strb->texture, NULL);
pipe_sampler_view_reference(&strb->sampler_view, NULL);
free(strb->data);
free(strb);
struct pipe_screen *screen = ctx->st->pipe->screen;
struct st_renderbuffer *strb;
struct gl_renderbuffer *rb;
- struct pipe_texture *pt = st_get_texobj_texture(att->Texture);
+ struct pipe_resource *pt = st_get_texobj_texture(att->Texture);
struct st_texture_object *stObj;
const struct gl_texture_image *texImage;
GLint pt_level;
/*printf("***** pipe texture %d x %d\n", pt->width0, pt->height0);*/
- pipe_texture_reference( &strb->texture, pt );
+ pipe_resource_reference( &strb->texture, pt );
pipe_surface_reference(&strb->surface, NULL);
strb->rtt_face,
strb->rtt_level,
strb->rtt_slice,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET);
strb->format = pt->format;
if (!st_validate_attachment(screen,
&fb->Attachment[BUFFER_DEPTH],
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) {
+ PIPE_BIND_DEPTH_STENCIL)) {
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
return;
}
if (!st_validate_attachment(screen,
&fb->Attachment[BUFFER_STENCIL],
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) {
+ PIPE_BIND_DEPTH_STENCIL)) {
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
return;
}
for (i = 0; i < ctx->Const.MaxColorAttachments; i++) {
if (!st_validate_attachment(screen,
&fb->Attachment[BUFFER_COLOR0 + i],
- PIPE_TEXTURE_USAGE_RENDER_TARGET)) {
+ PIPE_BIND_RENDER_TARGET)) {
fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT;
return;
}
struct st_renderbuffer
{
struct gl_renderbuffer Base;
- struct pipe_texture *texture;
+ struct pipe_resource *texture;
struct pipe_surface *surface; /* temporary view into texture */
struct pipe_sampler_view *sampler_view;
enum pipe_format format; /** preferred format, or PIPE_FORMAT_NONE */
int rtt_level, rtt_face, rtt_slice;
/** Render to texture state */
- struct pipe_texture *texture_save;
+ struct pipe_resource *texture_save;
struct pipe_surface *surface_save;
struct pipe_sampler_view *sampler_view_save;
};
width, height);
/* map the stencil buffer */
- stmap = pipe->transfer_map(pipe, pt);
+ stmap = pipe_transfer_map(pipe, pt);
/* width should never be > MAX_WIDTH since we did clipping earlier */
ASSERT(width <= MAX_WIDTH);
}
/* get stencil (and Z) values */
- switch (pt->texture->format) {
+ switch (pt->resource->format) {
case PIPE_FORMAT_S8_USCALED:
{
const ubyte *src = stmap + srcY * pt->stride;
}
/* unmap the stencil buffer */
- pipe->transfer_unmap(pipe, pt);
- pipe->tex_transfer_destroy(pipe, pt);
+ pipe_transfer_unmap(pipe, pt);
+ pipe->transfer_destroy(pipe, pt);
}
return GL_FALSE;
}
- map = pipe->transfer_map(pipe, trans);
+ map = pipe_transfer_map(pipe, trans);
if (!map) {
- pipe->tex_transfer_destroy(pipe, trans);
+ pipe->transfer_destroy(pipe, trans);
return GL_FALSE;
}
; /* nothing */
}
- pipe->transfer_unmap(pipe, trans);
- pipe->tex_transfer_destroy(pipe, trans);
+ pipe_transfer_unmap(pipe, trans);
+ pipe->transfer_destroy(pipe, trans);
}
return GL_TRUE;
const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width,
format, type);
- if (trans->texture->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
- trans->texture->format == PIPE_FORMAT_Z24X8_UNORM) {
+ if (trans->resource->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
+ trans->resource->format == PIPE_FORMAT_Z24X8_UNORM) {
if (format == GL_DEPTH_COMPONENT) {
for (i = 0; i < height; i++) {
GLuint ztemp[MAX_WIDTH];
}
}
}
- else if (trans->texture->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
- trans->texture->format == PIPE_FORMAT_X8Z24_UNORM) {
+ else if (trans->resource->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
+ trans->resource->format == PIPE_FORMAT_X8Z24_UNORM) {
if (format == GL_DEPTH_COMPONENT) {
for (i = 0; i < height; i++) {
GLuint ztemp[MAX_WIDTH];
}
}
}
- else if (trans->texture->format == PIPE_FORMAT_Z16_UNORM) {
+ else if (trans->resource->format == PIPE_FORMAT_Z16_UNORM) {
for (i = 0; i < height; i++) {
GLushort ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
dst += dstStride;
}
}
- else if (trans->texture->format == PIPE_FORMAT_Z32_UNORM) {
+ else if (trans->resource->format == PIPE_FORMAT_Z32_UNORM) {
for (i = 0; i < height; i++) {
GLuint ztemp[MAX_WIDTH];
GLfloat zfloat[MAX_WIDTH];
}
}
- pipe->tex_transfer_destroy(pipe, trans);
+ pipe->transfer_destroy(pipe, trans);
_mesa_unmap_pbo_dest(ctx, &clippedPacking);
}
{
struct st_texture_object *stObj = st_texture_object(texObj);
if (stObj->pt)
- pipe_texture_reference(&stObj->pt, NULL);
+ pipe_resource_reference(&stObj->pt, NULL);
if (stObj->sampler_view) {
if (stObj->sampler_view->context != ctx->st->pipe) {
/* Take "ownership" of this texture sampler view by setting
DBG("%s\n", __FUNCTION__);
if (stImage->pt) {
- pipe_texture_reference(&stImage->pt, NULL);
+ pipe_resource_reference(&stImage->pt, NULL);
}
if (texImage->Data) {
static GLuint
default_usage(enum pipe_format fmt)
{
- GLuint usage = PIPE_TEXTURE_USAGE_SAMPLER;
+ GLuint usage = PIPE_BIND_SAMPLER_VIEW;
if (util_format_is_depth_or_stencil(fmt))
- usage |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ usage |= PIPE_BIND_DEPTH_STENCIL;
else
- usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ usage |= PIPE_BIND_RENDER_TARGET;
return usage;
}
/**
- * Allocate a pipe_texture object for the given st_texture_object using
+ * Allocate a pipe_resource object for the given st_texture_object using
* the given st_texture_image to guess the mipmap size/levels.
*
* [comments...]
struct pipe_context *pipe = ctx->st->pipe;
struct pipe_screen *screen = pipe->screen;
gl_format mesa_format;
- struct pipe_texture templ;
- struct pipe_texture *src_tex;
+ struct pipe_resource templ;
+ struct pipe_resource *src_tex;
struct pipe_sampler_view view_templ;
struct pipe_sampler_view *src_view;
struct pipe_surface *dst_surface;
/* get destination surface (in the compressed texture) */
dst_surface = screen->get_tex_surface(screen, stImage->pt,
stImage->face, stImage->level, 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
if (!dst_surface) {
/* can't render into this format (or other problem) */
return GL_FALSE;
templ.height0 = height;
templ.depth0 = 1;
templ.last_level = 0;
- templ.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER;
- src_tex = screen->texture_create(screen, &templ);
+ templ._usage = PIPE_USAGE_DEFAULT;
+ templ.bind = PIPE_BIND_SAMPLER_VIEW;
+ src_tex = screen->resource_create(screen, &templ);
if (!src_tex)
return GL_FALSE;
0, 0, 0, /* face, level are zero */
PIPE_TRANSFER_WRITE,
0, 0, width, height); /* x, y, w, h */
- map = pipe->transfer_map(pipe, tex_xfer);
+ map = pipe_transfer_map(pipe, tex_xfer);
_mesa_texstore(ctx, 2, GL_RGBA, mesa_format,
map, /* dest ptr */
pixels, /* source data */
unpack); /* source data packing */
- pipe->transfer_unmap(pipe, tex_xfer);
- pipe->tex_transfer_destroy(pipe, tex_xfer);
+ pipe_transfer_unmap(pipe, tex_xfer);
+ pipe->transfer_destroy(pipe, tex_xfer);
/* Create temporary sampler view */
u_sampler_view_default_template(&view_templ,
PIPE_TEX_MIPFILTER_NEAREST);
pipe_surface_reference(&dst_surface, NULL);
- pipe_texture_reference(&src_tex, NULL);
+ pipe_resource_reference(&src_tex, NULL);
pipe_sampler_view_reference(&src_view, NULL);
return GL_TRUE;
* Release any old malloced memory.
*/
if (stImage->pt) {
- pipe_texture_reference(&stImage->pt, NULL);
+ pipe_resource_reference(&stImage->pt, NULL);
assert(!texImage->Data);
}
else if (texImage->Data) {
!st_texture_match_image(stObj->pt, &stImage->base,
stImage->face, stImage->level)) {
DBG("release it\n");
- pipe_texture_reference(&stObj->pt, NULL);
+ pipe_resource_reference(&stObj->pt, NULL);
assert(!stObj->pt);
pipe_sampler_view_reference(&stObj->sampler_view, NULL);
stObj->teximage_realloc = FALSE;
st_texture_match_image(stObj->pt, &stImage->base,
stImage->face, stImage->level)) {
- pipe_texture_reference(&stImage->pt, stObj->pt);
+ pipe_resource_reference(&stImage->pt, stObj->pt);
assert(stImage->pt);
}
screen->is_format_supported(screen,
stImage->pt->format,
stImage->pt->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ PIPE_BIND_RENDER_TARGET, 0)) {
if (!pixels)
goto done;
const GLuint width = texImage->Width;
const GLuint height = texImage->Height;
struct pipe_surface *dst_surface;
- struct pipe_texture *dst_texture;
+ struct pipe_resource *dst_texture;
struct pipe_transfer *tex_xfer;
+ unsigned bind = (PIPE_BIND_BLIT_DESTINATION |
+ PIPE_BIND_RENDER_TARGET | /* util_blit may choose to render */
+ PIPE_BIND_TRANSFER_READ);
/* create temp / dest surface */
- if (!util_create_rgba_surface(screen, width, height,
+ if (!util_create_rgba_surface(screen, width, height, bind,
&dst_texture, &dst_surface)) {
_mesa_problem(ctx, "util_create_rgba_surface() failed "
"in decompress_with_blit()");
/* blit/render/decompress */
util_blit_pixels_tex(ctx->st->blit,
- src_view, /* pipe_texture (src) */
+ src_view, /* pipe_resource (src) */
0, 0, /* src x0, y0 */
width, height, /* src x1, y1 */
dst_surface, /* pipe_surface (dst) */
if (st_equal_formats(stImage->pt->format, format, type)) {
/* memcpy */
const uint bytesPerRow = width * util_format_get_blocksize(stImage->pt->format);
- ubyte *map = pipe->transfer_map(pipe, tex_xfer);
+ ubyte *map = pipe_transfer_map(pipe, tex_xfer);
GLuint row;
for (row = 0; row < height; row++) {
GLvoid *dest = _mesa_image_address2d(&ctx->Pack, pixels, width,
memcpy(dest, map, bytesPerRow);
map += tex_xfer->stride;
}
- pipe->transfer_unmap(pipe, tex_xfer);
+ pipe_transfer_unmap(pipe, tex_xfer);
}
else {
/* format translation via floats */
_mesa_unmap_pbo_dest(ctx, &ctx->Pack);
- pipe->tex_transfer_destroy(pipe, tex_xfer);
+ pipe->transfer_destroy(pipe, tex_xfer);
/* destroy the temp / dest surface */
util_destroy_rgba_surface(dst_texture, dst_surface);
screen->is_format_supported(screen,
stImage->pt->format,
stImage->pt->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ PIPE_BIND_RENDER_TARGET, 0)) {
if (compress_with_blit(ctx, target, level,
xoffset, yoffset, zoffset,
width, height, depth,
}
st_texture_image_unmap(ctx->st, stImage);
- pipe->tex_transfer_destroy(pipe, src_trans);
+ pipe->transfer_destroy(pipe, src_trans);
}
dest_surface = screen->get_tex_surface(screen, stImage->pt,
stImage->face, stImage->level,
destZ,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
/* for surface_copy(), y=0=top, always */
pipe->surface_copy(pipe,
texBaseFormat != GL_DEPTH_STENCIL &&
screen->is_format_supported(screen, src_format,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER,
+ PIPE_BIND_SAMPLER_VIEW,
0) &&
screen->is_format_supported(screen, dest_format,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET,
+ PIPE_BIND_RENDER_TARGET,
0)) {
/* draw textured quad to do the copy */
GLint srcY0, srcY1;
dest_surface = screen->get_tex_surface(screen, stImage->pt,
stImage->face, stImage->level,
destZ,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
if (do_flip) {
srcY1 = strb->Base.Height - srcY - height;
stImage->pt, /* src texture */
stImage->face);
- pipe_texture_reference(&stImage->pt, NULL);
+ pipe_resource_reference(&stImage->pt, NULL);
}
else if (stImage->base.Data) {
/* More straightforward upload.
stImage->base.Data = NULL;
}
- pipe_texture_reference(&stImage->pt, stObj->pt);
+ pipe_resource_reference(&stImage->pt, stObj->pt);
}
if (firstImage->pt &&
firstImage->pt != stObj->pt &&
firstImage->pt->last_level >= stObj->lastLevel) {
- pipe_texture_reference(&stObj->pt, firstImage->pt);
+ pipe_resource_reference(&stObj->pt, firstImage->pt);
pipe_sampler_view_reference(&stObj->sampler_view, NULL);
}
stObj->pt->height0 != firstImage->base.Height2 ||
stObj->pt->depth0 != firstImage->base.Depth2)
{
- pipe_texture_reference(&stObj->pt, NULL);
+ pipe_resource_reference(&stObj->pt, NULL);
pipe_sampler_view_reference(&stObj->sampler_view, NULL);
ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER;
}
for (i = 0; i < Elements(st->state.constants); i++) {
if (st->state.constants[i]) {
- pipe_buffer_reference(&st->state.constants[i], NULL);
+ pipe_resource_reference(&st->state.constants[i], NULL);
}
}
struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS];
struct pipe_sampler_state *sampler_list[PIPE_MAX_SAMPLERS];
struct pipe_clip_state clip;
- struct pipe_buffer *constants[2];
+ struct pipe_resource *constants[2];
struct pipe_framebuffer_state framebuffer;
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
struct pipe_scissor_state scissor;
GLuint user_prog_sn; /**< user fragment program serial no. */
struct st_fragment_program *combined_prog;
GLuint combined_prog_sn;
- struct pipe_texture *pixelmap_texture;
+ struct pipe_resource *pixelmap_texture;
struct pipe_sampler_view *pixelmap_sampler_view;
boolean pixelmap_enabled; /**< use the pixelmap texture? */
} pixel_xfer;
enum pipe_format tex_format;
void *vs;
float vertices[4][3][4]; /**< vertex pos + color + texcoord */
- struct pipe_buffer *vbuf;
+ struct pipe_resource *vbuf;
unsigned vbuf_slot; /* next free slot in vbuf */
struct bitmap_cache *cache;
} bitmap;
void *vs;
void *fs;
float vertices[4][2][4]; /**< vertex pos + color */
- struct pipe_buffer *vbuf;
+ struct pipe_resource *vbuf;
unsigned vbuf_slot;
} clear;
offset0 = low;
if (userSpace) {
vbuffer->buffer =
- pipe_user_buffer_create(pipe->screen, (void *) low, high - low);
+ pipe_user_buffer_create(pipe->screen, (void *) low, high - low,
+ PIPE_BIND_VERTEX_BUFFER);
vbuffer->buffer_offset = 0;
}
else {
vbuffer->buffer = NULL;
- pipe_buffer_reference(&vbuffer->buffer, stobj->buffer);
+ pipe_resource_reference(&vbuffer->buffer, stobj->buffer);
vbuffer->buffer_offset = pointer_to_offset(low);
}
vbuffer->stride = stride; /* in bytes */
/*printf("stobj %u = %p\n", attr, (void*) stobj);*/
vbuffer[attr].buffer = NULL;
- pipe_buffer_reference(&vbuffer[attr].buffer, stobj->buffer);
+ pipe_resource_reference(&vbuffer[attr].buffer, stobj->buffer);
vbuffer[attr].buffer_offset = pointer_to_offset(arrays[mesaAttr]->Ptr);
velements[attr].src_offset = 0;
}
bytes = arrays[mesaAttr]->Size
* _mesa_sizeof_type(arrays[mesaAttr]->Type);
}
- vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen,
- (void *) arrays[mesaAttr]->Ptr, bytes);
+ vbuffer[attr].buffer =
+ pipe_user_buffer_create(pipe->screen,
+ (void *) arrays[mesaAttr]->Ptr, bytes,
+ PIPE_BIND_VERTEX_BUFFER);
}
else {
/* no array, use ctx->Current.Attrib[] value */
bytes = sizeof(ctx->Current.Attrib[0]);
- vbuffer[attr].buffer = pipe_user_buffer_create(pipe->screen,
- (void *) ctx->Current.Attrib[mesaAttr], bytes);
+ vbuffer[attr].buffer =
+ pipe_user_buffer_create(pipe->screen,
+ (void *) ctx->Current.Attrib[mesaAttr],
+ bytes,
+ PIPE_BIND_VERTEX_BUFFER);
stride = 0;
}
if (ib) {
/* indexed primitive */
struct gl_buffer_object *bufobj = ib->obj;
- struct pipe_buffer *indexBuf = NULL;
+ struct pipe_resource *indexBuf = NULL;
unsigned indexSize, indexOffset, i;
unsigned prim;
if (bufobj && bufobj->Name) {
/* elements/indexes are in a real VBO */
struct st_buffer_object *stobj = st_buffer_object(bufobj);
- pipe_buffer_reference(&indexBuf, stobj->buffer);
+ pipe_resource_reference(&indexBuf, stobj->buffer);
indexOffset = pointer_to_offset(ib->ptr) / indexSize;
}
else {
/* element/indicies are in user space memory */
indexBuf = pipe_user_buffer_create(pipe->screen, (void *) ib->ptr,
- ib->count * indexSize);
+ ib->count * indexSize,
+ PIPE_BIND_INDEX_BUFFER);
indexOffset = 0;
}
}
}
- pipe_buffer_reference(&indexBuf, NULL);
+ pipe_resource_reference(&indexBuf, NULL);
}
else {
/* non-indexed */
/* unreference buffers (frees wrapped user-space buffer objects) */
for (attr = 0; attr < num_vbuffers; attr++) {
- pipe_buffer_reference(&vbuffer[attr].buffer, NULL);
+ pipe_resource_reference(&vbuffer[attr].buffer, NULL);
assert(!vbuffer[attr].buffer);
}
struct draw_context *draw = st->draw;
const struct st_vertex_program *vp;
const struct pipe_shader_state *vs;
- struct pipe_buffer *index_buffer_handle = 0;
+ struct pipe_resource *index_buffer_handle = 0;
struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS];
struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
+ struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
+ struct pipe_transfer *ib_transfer;
+ struct pipe_transfer *cb_transfer;
GLuint attr, i;
ubyte *mapped_constants;
assert(stobj->buffer);
vbuffers[attr].buffer = NULL;
- pipe_buffer_reference(&vbuffers[attr].buffer, stobj->buffer);
+ pipe_resource_reference(&vbuffers[attr].buffer, stobj->buffer);
vbuffers[attr].buffer_offset = pointer_to_offset(arrays[0]->Ptr);
velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr;
}
/* wrap user data */
vbuffers[attr].buffer
= pipe_user_buffer_create(pipe->screen, (void *) arrays[mesaAttr]->Ptr,
- bytes);
+ bytes,
+ PIPE_BIND_VERTEX_BUFFER);
vbuffers[attr].buffer_offset = 0;
velements[attr].src_offset = 0;
}
#endif
/* map the attrib buffer */
- map = pipe_buffer_map(pipe->screen, vbuffers[attr].buffer,
- PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(pipe, vbuffers[attr].buffer,
+ PIPE_TRANSFER_READ,
+ &vb_transfer[attr]);
draw_set_mapped_vertex_buffer(draw, attr, map);
}
index_buffer_handle = stobj->buffer;
- map = pipe_buffer_map(pipe->screen, index_buffer_handle,
- PIPE_BUFFER_USAGE_CPU_READ);
+ map = pipe_buffer_map(pipe, index_buffer_handle,
+ PIPE_TRANSFER_READ, &ib_transfer);
draw_set_mapped_element_buffer(draw, indexSize, map);
}
else {
draw_set_mapped_element_buffer(draw, indexSize, (void *) ib->ptr);
+ ib_transfer = NULL;
}
}
else {
/* map constant buffers */
- mapped_constants = pipe_buffer_map(pipe->screen,
+ mapped_constants = pipe_buffer_map(pipe,
st->state.constants[PIPE_SHADER_VERTEX],
- PIPE_BUFFER_USAGE_CPU_READ);
+ PIPE_TRANSFER_READ,
+ &cb_transfer);
draw_set_mapped_constant_buffer(st->draw, PIPE_SHADER_VERTEX, 0,
mapped_constants,
- st->state.constants[PIPE_SHADER_VERTEX]->size);
+ st->state.constants[PIPE_SHADER_VERTEX]->width0);
/* draw here */
/* unmap constant buffers */
- pipe_buffer_unmap(pipe->screen, st->state.constants[PIPE_SHADER_VERTEX]);
+ pipe_buffer_unmap(pipe, st->state.constants[PIPE_SHADER_VERTEX],
+ cb_transfer);
/*
* unmap vertex/index buffers
*/
for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
if (draw->pt.vertex_buffer[i].buffer) {
- pipe_buffer_unmap(pipe->screen, draw->pt.vertex_buffer[i].buffer);
- pipe_buffer_reference(&draw->pt.vertex_buffer[i].buffer, NULL);
+ pipe_buffer_unmap(pipe, draw->pt.vertex_buffer[i].buffer,
+ vb_transfer[i]);
+ pipe_resource_reference(&draw->pt.vertex_buffer[i].buffer, NULL);
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
}
if (index_buffer_handle) {
- pipe_buffer_unmap(pipe->screen, index_buffer_handle);
+ pipe_buffer_unmap(pipe, index_buffer_handle, ib_transfer);
draw_set_mapped_element_buffer(draw, 0, NULL);
}
}
*/
if (screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0) &&
+ PIPE_BIND_DEPTH_STENCIL, 0) &&
screen->is_format_supported(screen, PIPE_FORMAT_S8_USCALED_Z24_UNORM,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
}
else if (screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0) &&
+ PIPE_BIND_DEPTH_STENCIL, 0) &&
screen->is_format_supported(screen, PIPE_FORMAT_Z24_UNORM_S8_USCALED,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
ctx->Extensions.EXT_packed_depth_stencil = GL_TRUE;
}
/* sRGB support */
if (screen->is_format_supported(screen, PIPE_FORMAT_A8B8G8R8_SRGB,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0) ||
+ PIPE_BIND_SAMPLER_VIEW, 0) ||
screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_SRGB,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
ctx->Extensions.EXT_texture_sRGB = GL_TRUE;
}
/* s3tc support */
if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0) &&
+ PIPE_BIND_SAMPLER_VIEW, 0) &&
(ctx->Mesa_DXTn ||
screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0))) {
+ PIPE_BIND_RENDER_TARGET, 0))) {
ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE;
ctx->Extensions.S3_s3tc = GL_TRUE;
}
/* ycbcr support */
if (screen->is_format_supported(screen, PIPE_FORMAT_UYVY,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0) ||
+ PIPE_BIND_SAMPLER_VIEW, 0) ||
screen->is_format_supported(screen, PIPE_FORMAT_YUYV,
PIPE_TEXTURE_2D,
- PIPE_TEXTURE_USAGE_SAMPLER, 0)) {
+ PIPE_BIND_SAMPLER_VIEW, 0)) {
ctx->Extensions.MESA_ycbcr_texture = GL_TRUE;
}
if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM, target, tex_usage, geom_flags)) {
return PIPE_FORMAT_R16G16B16A16_SNORM;
}
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
+ if (tex_usage & PIPE_BIND_RENDER_TARGET)
return default_rgba_format(screen, target, tex_usage, geom_flags);
else
return PIPE_FORMAT_NONE;
* Given an OpenGL internalFormat value for a texture or surface, return
* the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.
* \param target one of PIPE_TEXTURE_x
- * \param tex_usage either PIPE_TEXTURE_USAGE_RENDER_TARGET
- * or PIPE_TEXTURE_USAGE_SAMPLER
+ * \param tex_usage either PIPE_BIND_RENDER_TARGET
+ * or PIPE_BIND_SAMPLER_VIEW
*/
enum pipe_format
st_choose_format(struct pipe_screen *screen, GLenum internalFormat,
case GL_COMPRESSED_RGB:
return default_rgb_format( screen, target, tex_usage, geom_flags );
case GL_RGBA16:
- if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET)
+ if (tex_usage & PIPE_BIND_RENDER_TARGET)
return default_deep_rgba_format( screen, target, tex_usage, geom_flags );
else
return default_rgba_format( screen, target, tex_usage, geom_flags );
{
uint usage;
if (is_depth_or_stencil_format(internalFormat))
- usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
+ usage = PIPE_BIND_DEPTH_STENCIL;
else
- usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+ usage = PIPE_BIND_RENDER_TARGET;
return st_choose_format(screen, internalFormat, PIPE_TEXTURE_2D, usage);
}
(void) type;
pFormat = st_choose_format(ctx->st->pipe->screen, internalFormat,
- PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER);
+ PIPE_TEXTURE_2D, PIPE_BIND_SAMPLER_VIEW);
if (pFormat == PIPE_FORMAT_NONE)
return MESA_FORMAT_NONE;
/* replace the renderbuffer's surface/texture pointers */
pipe_surface_reference( &strb->surface, surf );
- pipe_texture_reference( &strb->texture, surf->texture );
+ pipe_resource_reference( &strb->texture, surf->texture );
pipe_sampler_view_reference(&strb->sampler_view, NULL);
if (ctx) {
}
int
-st_get_framebuffer_texture(struct st_framebuffer *stfb, uint surfIndex, struct pipe_texture **texture)
+st_get_framebuffer_texture(struct st_framebuffer *stfb, uint surfIndex, struct pipe_resource **texture)
{
struct st_renderbuffer *strb;
/* check if we can render in the texture's format */
if (!screen->is_format_supported(screen, psv->format, psv->texture->target,
- PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) {
+ PIPE_BIND_RENDER_TARGET, 0)) {
return FALSE;
}
struct gl_texture_object *texObj)
{
struct pipe_context *pipe = ctx->st->pipe;
- struct pipe_texture *pt = st_get_texobj_texture(texObj);
+ struct pipe_resource *pt = st_get_texobj_texture(texObj);
const uint baseLevel = texObj->BaseLevel;
const uint lastLevel = pt->last_level;
const uint face = _mesa_tex_target_to_face(target), zslice = 0;
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
- srcData = (ubyte *) pipe->transfer_map(pipe, srcTrans);
- dstData = (ubyte *) pipe->transfer_map(pipe, dstTrans);
+ srcData = (ubyte *) pipe_transfer_map(pipe, srcTrans);
+ dstData = (ubyte *) pipe_transfer_map(pipe, dstTrans);
- srcStride = srcTrans->stride / util_format_get_blocksize(srcTrans->texture->format);
- dstStride = dstTrans->stride / util_format_get_blocksize(dstTrans->texture->format);
+ srcStride = srcTrans->stride / util_format_get_blocksize(srcTrans->resource->format);
+ dstStride = dstTrans->stride / util_format_get_blocksize(dstTrans->resource->format);
_mesa_generate_mipmap_level(target, datatype, comps,
0 /*border*/,
dstData,
dstStride); /* stride in texels */
- pipe->transfer_unmap(pipe, srcTrans);
- pipe->transfer_unmap(pipe, dstTrans);
+ pipe_transfer_unmap(pipe, srcTrans);
+ pipe_transfer_unmap(pipe, dstTrans);
- pipe->tex_transfer_destroy(pipe, srcTrans);
- pipe->tex_transfer_destroy(pipe, dstTrans);
+ pipe->transfer_destroy(pipe, srcTrans);
+ pipe->transfer_destroy(pipe, dstTrans);
}
}
{
struct st_context *st = ctx->st;
struct st_texture_object *stObj = st_texture_object(texObj);
- struct pipe_texture *pt = st_get_texobj_texture(texObj);
+ struct pipe_resource *pt = st_get_texobj_texture(texObj);
const uint baseLevel = texObj->BaseLevel;
uint lastLevel;
uint dstLevel;
/* The current gallium texture doesn't have space for all the
* mipmap levels we need to generate. So allocate a new texture.
*/
- struct pipe_texture *oldTex = stObj->pt;
+ struct pipe_resource *oldTex = stObj->pt;
GLboolean needFlush;
/* create new texture with space for more levels */
oldTex->width0,
oldTex->height0,
oldTex->depth0,
- oldTex->tex_usage);
+ oldTex->bind);
/* The texture isn't in a "complete" state yet so set the expected
* lastLevel here, since it won't get done in st_finalize_texture().
st_finalize_texture(ctx, st->pipe, texObj, &needFlush);
/* release the old tex (will likely be freed too) */
- pipe_texture_reference(&oldTex, NULL);
+ pipe_resource_reference(&oldTex, NULL);
pipe_sampler_view_reference(&stObj->sampler_view, NULL);
pt = stObj->pt;
dstImage->TexFormat = srcImage->TexFormat;
stImage = (struct st_texture_image *) dstImage;
- pipe_texture_reference(&stImage->pt, pt);
+ pipe_resource_reference(&stImage->pt, pt);
}
}
#include "pipe/p_screen.h"
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
+#include "util/u_box.h"
#include "pipe/p_state.h"
#include "st_context.h"
static INLINE struct pipe_transfer *
st_cond_flush_get_tex_transfer(struct st_context *st,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
unsigned int face,
unsigned int level,
unsigned int zslice,
unsigned int w, unsigned int h)
{
struct pipe_context *context = st->pipe;
+ struct pipe_subresource subresource;
+ struct pipe_box box;
+
+ subresource.face = face;
+ subresource.level = level;
+
+ u_box_2d_zslice(x, y, zslice, w, h, &box);
st_teximage_flush_before_map(st, pt, face, level, usage);
- return context->get_tex_transfer(context, pt, face, level, zslice, usage,
- x, y, w, h);
+
+ return context->get_transfer(context,
+ pt,
+ subresource,
+ usage,
+ &box);
}
static INLINE struct pipe_transfer *
st_no_flush_get_tex_transfer(struct st_context *st,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
unsigned int face,
unsigned int level,
unsigned int zslice,
unsigned int w, unsigned int h)
{
struct pipe_context *context = st->pipe;
-
- return context->get_tex_transfer(context, pt, face, level,
- zslice, usage, x, y, w, h);
-}
-
-static INLINE void *
-st_cond_flush_pipe_buffer_map(struct st_context *st,
- struct pipe_buffer *buf,
- unsigned int map_flags)
-{
- struct pipe_context *pipe = st->pipe;
- unsigned int referenced = pipe->is_buffer_referenced(pipe, buf);
-
- if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
- (map_flags & PIPE_BUFFER_USAGE_CPU_WRITE)))
- st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
-
- return pipe_buffer_map(pipe->screen, buf, map_flags);
-}
-
-static INLINE void *
-st_no_flush_pipe_buffer_map(struct st_context *st,
- struct pipe_buffer *buf,
- unsigned int map_flags)
-{
- return pipe_buffer_map(st->pipe->screen, buf, map_flags);
+ struct pipe_box box;
+ struct pipe_subresource subresource = u_subresource( face, level );
+
+ u_box_2d_zslice( x, y, zslice,
+ w, h,
+ &box );
+
+ return context->get_transfer(context,
+ pt,
+ subresource,
+ usage,
+ &box);
}
static INLINE void
st_cond_flush_pipe_buffer_write(struct st_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
const void * data)
{
struct pipe_context *pipe = st->pipe;
- if (pipe->is_buffer_referenced(pipe, buf))
- st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
-
- pipe_buffer_write(pipe->screen, buf, offset, size, data);
+ pipe_buffer_write(pipe, buf, offset, size, data);
}
static INLINE void
st_no_flush_pipe_buffer_write(struct st_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
const void * data)
{
- pipe_buffer_write(st->pipe->screen, buf, offset, size, data);
+ pipe_buffer_write(st->pipe, buf, offset, size, data);
}
static INLINE void
st_no_flush_pipe_buffer_write_nooverlap(struct st_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
const void * data)
{
- pipe_buffer_write_nooverlap(st->pipe->screen, buf, offset, size, data);
+ pipe_buffer_write_nooverlap(st->pipe, buf, offset, size, data);
}
static INLINE void
st_cond_flush_pipe_buffer_read(struct st_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
void * data)
{
struct pipe_context *pipe = st->pipe;
- if (pipe->is_buffer_referenced(pipe, buf) & PIPE_REFERENCED_FOR_WRITE)
+ if (pipe->is_resource_referenced(pipe, buf, 0, 0) & PIPE_REFERENCED_FOR_WRITE)
st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
- pipe_buffer_read(pipe->screen, buf, offset, size, data);
+ pipe_buffer_read(pipe, buf, offset, size, data);
}
static INLINE void
st_no_flush_pipe_buffer_read(struct st_context *st,
- struct pipe_buffer *buf,
+ struct pipe_resource *buf,
unsigned int offset,
unsigned int size,
void * data)
{
- pipe_buffer_read(st->pipe->screen, buf, offset, size, data);
+ pipe_buffer_read(st->pipe, buf, offset, size, data);
}
#endif
st_framebuffer_validate(struct st_framebuffer *stfb, struct st_context *st)
{
struct pipe_screen *screen = st->pipe->screen;
- struct pipe_texture *textures[ST_ATTACHMENT_COUNT];
+ struct pipe_resource *textures[ST_ATTACHMENT_COUNT];
uint width, height;
unsigned i;
boolean changed = FALSE;
idx = attachment_to_buffer_index(stfb->statts[i]);
if (idx >= BUFFER_COUNT) {
- pipe_texture_reference(&textures[i], NULL);
+ pipe_resource_reference(&textures[i], NULL);
continue;
}
strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer);
assert(strb);
if (strb->texture == textures[i]) {
- pipe_texture_reference(&textures[i], NULL);
+ pipe_resource_reference(&textures[i], NULL);
continue;
}
ps = screen->get_tex_surface(screen, textures[i], 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_RENDER_TARGET);
if (ps) {
pipe_surface_reference(&strb->surface, ps);
- pipe_texture_reference(&strb->texture, ps->texture);
+ pipe_resource_reference(&strb->texture, ps->texture);
/* ownership transfered */
pipe_surface_reference(&ps, NULL);
height = strb->Base.Height;
}
- pipe_texture_reference(&textures[i], NULL);
+ pipe_resource_reference(&textures[i], NULL);
}
if (changed) {
static boolean
st_context_teximage(struct st_context_iface *stctxi, enum st_texture_type target,
int level, enum pipe_format internal_format,
- struct pipe_texture *tex, boolean mipmap)
+ struct pipe_resource *tex, boolean mipmap)
{
struct st_context *st = (struct st_context *) stctxi;
GLcontext *ctx = st->ctx;
}
stObj->pipe = st->pipe;
- pipe_texture_reference(&stImage->pt, tex);
+ pipe_resource_reference(&stImage->pt, tex);
_mesa_dirty_texobj(ctx, texObj, GL_TRUE);
_mesa_unlock_texture(ctx, texObj);
ps = smapi->screen->get_tex_surface(smapi->screen,
stimg.texture, stimg.face, stimg.level, stimg.zslice, usage);
- pipe_texture_reference(&stimg.texture, NULL);
+ pipe_resource_reference(&stimg.texture, NULL);
return ps;
}
struct pipe_context;
struct pipe_fence_handle;
struct pipe_surface;
-struct pipe_texture;
+struct pipe_resource;
PUBLIC
PUBLIC
int st_get_framebuffer_texture(struct st_framebuffer *stfb,
- uint surfIndex, struct pipe_texture **texture);
+ uint surfIndex, struct pipe_resource **texture);
PUBLIC
void *st_framebuffer_private( struct st_framebuffer *stfb );
/**
- * Allocate a new pipe_texture object
+ * Allocate a new pipe_resource object
* width0, height0, depth0 are the dimensions of the level 0 image
* (the highest resolution). last_level indicates how many mipmap levels
* to allocate storage for. For non-mipmapped textures, this will be zero.
*/
-struct pipe_texture *
+struct pipe_resource *
st_texture_create(struct st_context *st,
enum pipe_texture_target target,
enum pipe_format format,
GLuint width0,
GLuint height0,
GLuint depth0,
- GLuint usage )
+ GLuint bind )
{
- struct pipe_texture pt, *newtex;
+ struct pipe_resource pt, *newtex;
struct pipe_screen *screen = st->pipe->screen;
assert(target <= PIPE_TEXTURE_CUBE);
assert(format);
assert(screen->is_format_supported(screen, format, target,
- PIPE_TEXTURE_USAGE_SAMPLER, 0));
+ PIPE_BIND_SAMPLER_VIEW, 0));
memset(&pt, 0, sizeof(pt));
pt.target = target;
pt.width0 = width0;
pt.height0 = height0;
pt.depth0 = depth0;
- pt.tex_usage = usage;
+ pt._usage = PIPE_USAGE_DEFAULT;
+ pt.bind = bind;
+ pt.flags = 0;
- newtex = screen->texture_create(screen, &pt);
+ newtex = screen->resource_create(screen, &pt);
assert(!newtex || pipe_is_referenced(&newtex->reference));
* Check if a texture image can be pulled into a unified mipmap texture.
*/
GLboolean
-st_texture_match_image(const struct pipe_texture *pt,
+st_texture_match_image(const struct pipe_resource *pt,
const struct gl_texture_image *image,
GLuint face, GLuint level)
{
* These functions present that view to mesa:
*/
const GLuint *
-st_texture_depth_offsets(struct pipe_texture *pt, GLuint level)
+st_texture_depth_offsets(struct pipe_resource *pt, GLuint level)
{
static const GLuint zero = 0;
* texture memory buffer, in bytes.
*/
GLuint
-st_texture_image_offset(const struct pipe_texture * pt,
+st_texture_image_offset(const struct pipe_resource * pt,
GLuint face, GLuint level)
{
if (pt->target == PIPE_TEXTURE_CUBE)
GLuint x, GLuint y, GLuint w, GLuint h)
{
struct pipe_context *pipe = st->pipe;
- struct pipe_texture *pt = stImage->pt;
+ struct pipe_resource *pt = stImage->pt;
DBG("%s \n", __FUNCTION__);
usage, x, y, w, h);
if (stImage->transfer)
- return pipe->transfer_map(pipe, stImage->transfer);
+ return pipe_transfer_map(pipe, stImage->transfer);
else
return NULL;
}
DBG("%s\n", __FUNCTION__);
- pipe->transfer_unmap(pipe, stImage->transfer);
+ pipe_transfer_unmap(pipe, stImage->transfer);
- pipe->tex_transfer_destroy(pipe, stImage->transfer);
+ pipe->transfer_destroy(pipe, stImage->transfer);
}
const void *src, unsigned src_stride,
unsigned srcx, unsigned srcy, unsigned width, unsigned height)
{
- void *map = pipe->transfer_map(pipe, dst);
+ void *map = pipe_transfer_map(pipe, dst);
- assert(dst->texture);
+ assert(dst->resource);
util_copy_rect(map,
- dst->texture->format,
+ dst->resource->format,
dst->stride,
dstx, dsty,
width, height,
src, src_stride,
srcx, srcy);
- pipe->transfer_unmap(pipe, dst);
+ pipe_transfer_unmap(pipe, dst);
}
*/
void
st_texture_image_data(struct st_context *st,
- struct pipe_texture *dst,
+ struct pipe_resource *dst,
GLuint face,
GLuint level,
void *src,
u_minify(dst->width0, level),
u_minify(dst->height0, level)); /* width, height */
- pipe->tex_transfer_destroy(pipe, dst_transfer);
+ pipe->transfer_destroy(pipe, dst_transfer);
srcUB += src_image_stride;
}
*/
void
st_texture_image_copy(struct pipe_context *pipe,
- struct pipe_texture *dst, GLuint dstLevel,
- struct pipe_texture *src,
+ struct pipe_resource *dst, GLuint dstLevel,
+ struct pipe_resource *src,
GLuint face)
{
struct pipe_screen *screen = pipe->screen;
#endif
dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i,
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ PIPE_BIND_BLIT_DESTINATION);
src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i,
- PIPE_BUFFER_USAGE_GPU_READ);
+ PIPE_BIND_BLIT_SOURCE);
pipe->surface_copy(pipe,
dst_surface,
texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat,
GL_RGBA, GL_UNSIGNED_BYTE);
_mesa_set_fetch_functions(texImage, 2);
- pipe_texture_reference(&stImage->pt, ps->texture);
+ pipe_resource_reference(&stImage->pt, ps->texture);
_mesa_dirty_texobj(ctx, texObj, GL_TRUE);
_mesa_unlock_texture(ctx, texObj);
/* Make sure the pipe surface is still bound. The texture object is still
* considered surface based even if this is the last bound surface. */
if (stImage->pt == ps->texture) {
- pipe_texture_reference(&stImage->pt, NULL);
+ pipe_resource_reference(&stImage->pt, NULL);
_mesa_clear_texture_image(ctx, texImage);
_mesa_dirty_texobj(ctx, texObj, GL_TRUE);
st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
/* save the renderbuffer's surface/texture info */
- pipe_texture_reference(&strb->texture_save, strb->texture);
+ pipe_resource_reference(&strb->texture_save, strb->texture);
pipe_surface_reference(&strb->surface_save, strb->surface);
pipe_sampler_view_reference(&strb->sampler_view_save, strb->sampler_view);
/* plug in new surface/texture info */
- pipe_texture_reference(&strb->texture, stImage->pt);
+ pipe_resource_reference(&strb->texture, stImage->pt);
/* XXX: Shouldn't we release reference to old surface here?
*/
strb->surface = screen->get_tex_surface(screen, strb->texture,
face, level, slice,
- (PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE));
+ (PIPE_BIND_RENDER_TARGET |
+ PIPE_BIND_BLIT_SOURCE |
+ PIPE_BIND_BLIT_DESTINATION));
pipe_sampler_view_reference(&strb->sampler_view, NULL);
/* free tex surface, restore original */
pipe_surface_reference(&strb->surface, strb->surface_save);
- pipe_texture_reference(&strb->texture, strb->texture_save);
+ pipe_resource_reference(&strb->texture, strb->texture_save);
pipe_sampler_view_reference(&strb->sampler_view, strb->sampler_view_save);
pipe_surface_reference(&strb->surface_save, NULL);
- pipe_texture_reference(&strb->texture_save, NULL);
+ pipe_resource_reference(&strb->texture_save, NULL);
pipe_sampler_view_reference(&strb->sampler_view, NULL);
st->dirty.st |= ST_NEW_FRAMEBUFFER;
void
st_teximage_flush_before_map(struct st_context *st,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
unsigned int face,
unsigned int level,
enum pipe_transfer_usage usage)
{
struct pipe_context *pipe = st->pipe;
unsigned referenced =
- pipe->is_texture_referenced(pipe, pt, face, level);
+ pipe->is_resource_referenced(pipe, pt, face, level);
if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
(usage & PIPE_TRANSFER_WRITE)))
#include "main/mtypes.h"
struct pipe_context;
-struct pipe_texture;
+struct pipe_resource;
struct st_texture_image
* Else if stImage->base.Data != NULL, image is stored there.
* Else there is no image data.
*/
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
struct pipe_transfer *transfer;
};
/* On validation any active images held in main memory or in other
* textures will be copied to this texture and the old storage freed.
*/
- struct pipe_texture *pt;
+ struct pipe_resource *pt;
/* Default sampler view attached to this texture object. Created lazily
* on first binding.
}
-static INLINE struct pipe_texture *
+static INLINE struct pipe_resource *
st_get_texobj_texture(struct gl_texture_object *texObj)
{
struct st_texture_object *stObj = st_texture_object(texObj);
}
-static INLINE struct pipe_texture *
+static INLINE struct pipe_resource *
st_get_stobj_texture(struct st_texture_object *stObj)
{
return stObj ? stObj->pt : NULL;
static INLINE struct pipe_sampler_view *
st_sampler_view_from_texture(struct pipe_context *pipe,
- struct pipe_texture *texture)
+ struct pipe_resource *texture)
{
struct pipe_sampler_view templ;
}
-extern struct pipe_texture *
+extern struct pipe_resource *
st_texture_create(struct st_context *st,
enum pipe_texture_target target,
enum pipe_format format,
/* Check if an image fits into an existing texture object.
*/
extern GLboolean
-st_texture_match_image(const struct pipe_texture *pt,
+st_texture_match_image(const struct pipe_resource *pt,
const struct gl_texture_image *image,
GLuint face, GLuint level);
* value.
*/
extern const GLuint *
-st_texture_depth_offsets(struct pipe_texture *pt, GLuint level);
+st_texture_depth_offsets(struct pipe_resource *pt, GLuint level);
/* Return the linear offset of an image relative to the start of its region.
*/
extern GLuint
-st_texture_image_offset(const struct pipe_texture *pt,
+st_texture_image_offset(const struct pipe_resource *pt,
GLuint face, GLuint level);
extern GLuint
-st_texture_texel_offset(const struct pipe_texture * pt,
+st_texture_texel_offset(const struct pipe_resource * pt,
GLuint face, GLuint level,
GLuint col, GLuint row, GLuint img);
*/
extern void
st_texture_image_data(struct st_context *st,
- struct pipe_texture *dst,
+ struct pipe_resource *dst,
GLuint face, GLuint level, void *src,
GLuint src_row_pitch, GLuint src_image_pitch);
*/
extern void
st_texture_image_copy(struct pipe_context *pipe,
- struct pipe_texture *dst, GLuint dstLevel,
- struct pipe_texture *src,
+ struct pipe_resource *dst, GLuint dstLevel,
+ struct pipe_resource *src,
GLuint face);
extern void
st_teximage_flush_before_map(struct st_context *st,
- struct pipe_texture *pt,
+ struct pipe_resource *pt,
unsigned int face,
unsigned int level,
enum pipe_transfer_usage usage);