Use a common function, fix the mess it was before.
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
#include "state_tracker/drm_driver.h"
#include "r600_screen.h"
#include "r600_context.h"
+#include "r600_resource.h"
extern struct u_resource_vtbl r600_buffer_vtbl;
-static u32 r600_domain_from_usage(unsigned usage)
+u32 r600_domain_from_usage(unsigned usage)
{
u32 domain = RADEON_GEM_DOMAIN_GTT;
const struct pipe_resource *templ)
{
struct r600_screen *rscreen = r600_screen(screen);
- struct r600_buffer *rbuffer;
+ struct r600_resource *rbuffer;
struct radeon_bo *bo;
struct pb_desc desc;
/* XXX We probably want a different alignment for buffers and textures. */
unsigned alignment = 4096;
- rbuffer = CALLOC_STRUCT(r600_buffer);
+ rbuffer = CALLOC_STRUCT(r600_resource);
if (rbuffer == NULL)
return NULL;
- rbuffer->b.b = *templ;
- pipe_reference_init(&rbuffer->b.b.reference, 1);
- rbuffer->b.b.screen = screen;
- rbuffer->b.vtbl = &r600_buffer_vtbl;
+ rbuffer->base.b = *templ;
+ pipe_reference_init(&rbuffer->base.b.reference, 1);
+ rbuffer->base.b.screen = screen;
+ rbuffer->base.vtbl = &r600_buffer_vtbl;
- if (rbuffer->b.b.bind & PIPE_BIND_CONSTANT_BUFFER) {
+ if (rbuffer->base.b.bind & PIPE_BIND_CONSTANT_BUFFER) {
desc.alignment = alignment;
- desc.usage = rbuffer->b.b.bind;
- rbuffer->pb = pb_malloc_buffer_create(rbuffer->b.b.width0,
+ desc.usage = rbuffer->base.b.bind;
+ rbuffer->pb = pb_malloc_buffer_create(rbuffer->base.b.width0,
&desc);
if (rbuffer->pb == NULL) {
free(rbuffer);
return NULL;
}
- return &rbuffer->b.b;
+ return &rbuffer->base.b;
}
- rbuffer->domain = r600_domain_from_usage(rbuffer->b.b.bind);
- bo = radeon_bo(rscreen->rw, 0, rbuffer->b.b.width0, alignment, NULL);
+ rbuffer->domain = r600_domain_from_usage(rbuffer->base.b.bind);
+ bo = radeon_bo(rscreen->rw, 0, rbuffer->base.b.width0, alignment, NULL);
if (bo == NULL) {
FREE(rbuffer);
return NULL;
}
rbuffer->bo = bo;
- return &rbuffer->b.b;
+ return &rbuffer->base.b;
}
struct pipe_resource *r600_user_buffer_create(struct pipe_screen *screen,
void *ptr, unsigned bytes,
unsigned bind)
{
- struct r600_buffer *rbuffer;
+ struct r600_resource *rbuffer;
struct r600_screen *rscreen = r600_screen(screen);
struct pipe_resource templ;
templ.height0 = 1;
templ.depth0 = 1;
- rbuffer = (struct r600_buffer*)r600_buffer_create(screen, &templ);
+ rbuffer = (struct r600_resource*)r600_buffer_create(screen, &templ);
if (rbuffer == NULL) {
return NULL;
}
radeon_bo_map(rscreen->rw, rbuffer->bo);
memcpy(rbuffer->bo->data, ptr, bytes);
radeon_bo_unmap(rscreen->rw, rbuffer->bo);
- return &rbuffer->b.b;
+ return &rbuffer->base.b;
}
static void r600_buffer_destroy(struct pipe_screen *screen,
struct pipe_resource *buf)
{
- struct r600_buffer *rbuffer = (struct r600_buffer*)buf;
+ struct r600_resource *rbuffer = (struct r600_resource*)buf;
struct r600_screen *rscreen = r600_screen(screen);
if (rbuffer->pb) {
static void *r600_buffer_transfer_map(struct pipe_context *pipe,
struct pipe_transfer *transfer)
{
- struct r600_buffer *rbuffer = (struct r600_buffer*)transfer->resource;
+ struct r600_resource *rbuffer = (struct r600_resource*)transfer->resource;
struct r600_screen *rscreen = r600_screen(pipe->screen);
int write = 0;
}
static void r600_buffer_transfer_unmap(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
+ struct pipe_transfer *transfer)
{
- struct r600_buffer *rbuffer = (struct r600_buffer*)transfer->resource;
+ struct r600_resource *rbuffer = (struct r600_resource*)transfer->resource;
struct r600_screen *rscreen = r600_screen(pipe->screen);
if (rbuffer->pb) {
struct pipe_resource *buf,
unsigned face, unsigned level)
{
- /* XXX */
+ /* FIXME */
return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
}
struct winsys_handle *whandle)
{
struct radeon *rw = (struct radeon*)screen->winsys;
- struct r600_buffer *rbuffer;
+ struct r600_resource *rbuffer;
struct radeon_bo *bo = NULL;
bo = radeon_bo(rw, whandle->handle, 0, 0, NULL);
return NULL;
}
- rbuffer = CALLOC_STRUCT(r600_buffer);
+ rbuffer = CALLOC_STRUCT(r600_resource);
if (rbuffer == NULL) {
radeon_bo_decref(rw, bo);
return NULL;
}
- pipe_reference_init(&rbuffer->b.b.reference, 1);
- rbuffer->b.b.target = PIPE_BUFFER;
- rbuffer->b.b.screen = screen;
- rbuffer->b.vtbl = &r600_buffer_vtbl;
+ pipe_reference_init(&rbuffer->base.b.reference, 1);
+ rbuffer->base.b.target = PIPE_BUFFER;
+ rbuffer->base.b.screen = screen;
+ rbuffer->base.vtbl = &r600_buffer_vtbl;
rbuffer->bo = bo;
- return &rbuffer->b.b;
+ return &rbuffer->base.b;
}
struct u_resource_vtbl r600_buffer_vtbl =
#include <util/u_format.h>
#include <util/u_memory.h>
#include <util/u_blitter.h>
-#include "r600_resource.h"
#include "r600_screen.h"
#include "r600_context.h"
+#include "r600_resource.h"
#include "r600d.h"
static void r600_destroy_context(struct pipe_context *context)
#include <util/u_memory.h>
#include "r600_screen.h"
#include "r600_context.h"
+#include "r600_resource.h"
#include "r600d.h"
struct r600_draw {
struct r600_context *rctx = r600_context(draw->ctx);
struct r600_screen *rscreen = rctx->screen;
struct radeon_state *vs_resource;
- struct r600_buffer *rbuffer;
+ struct r600_resource *rbuffer;
unsigned i, j, offset, format, prim;
u32 vgt_dma_index_type, vgt_draw_initiator;
int r;
for (i = 0 ; i < rctx->vertex_elements->count; i++) {
j = rctx->vertex_elements->elements[i].vertex_buffer_index;
- rbuffer = (struct r600_buffer*)rctx->vertex_buffer[j].buffer;
+ rbuffer = (struct r600_resource*)rctx->vertex_buffer[j].buffer;
offset = rctx->vertex_elements->elements[i].src_offset + rctx->vertex_buffer[j].buffer_offset;
r = r600_conv_pipe_format(rctx->vertex_elements->elements[i].src_format, &format);
if (r)
#include "r600_screen.h"
#include "r600_texture.h"
-static struct pipe_resource *
-r600_resource_create(struct pipe_screen *screen,
- const struct pipe_resource *templ)
+static struct pipe_resource *r600_resource_create(struct pipe_screen *screen,
+ const struct pipe_resource *templ)
{
- if (templ->target == PIPE_BUFFER)
- return r600_buffer_create(screen, templ);
- else
- return r600_texture_create(screen, templ);
+ if (templ->target == PIPE_BUFFER) {
+ return r600_buffer_create(screen, templ);
+ } else {
+ return r600_texture_create(screen, templ);
+ }
}
-static struct pipe_resource *
-r600_resource_from_handle(struct pipe_screen * screen,
- const struct pipe_resource *templ,
- struct winsys_handle *whandle)
+static struct pipe_resource *r600_resource_from_handle(struct pipe_screen * screen,
+ const struct pipe_resource *templ,
+ struct winsys_handle *whandle)
{
- if (templ->target == PIPE_BUFFER)
- return NULL;
- else
- return r600_texture_from_handle(screen, templ, whandle);
+ if (templ->target == PIPE_BUFFER) {
+ return NULL;
+ } else {
+ return r600_texture_from_handle(screen, templ, whandle);
+ }
}
void r600_init_context_resource_functions(struct r600_context *r600)
{
- r600->context.get_transfer = u_get_transfer_vtbl;
- r600->context.transfer_map = u_transfer_map_vtbl;
- r600->context.transfer_flush_region = u_transfer_flush_region_vtbl;
- r600->context.transfer_unmap = u_transfer_unmap_vtbl;
- r600->context.transfer_destroy = u_transfer_destroy_vtbl;
- r600->context.transfer_inline_write = u_transfer_inline_write_vtbl;
- r600->context.is_resource_referenced = u_is_resource_referenced_vtbl;
+ r600->context.get_transfer = u_get_transfer_vtbl;
+ r600->context.transfer_map = u_transfer_map_vtbl;
+ r600->context.transfer_flush_region = u_transfer_flush_region_vtbl;
+ r600->context.transfer_unmap = u_transfer_unmap_vtbl;
+ r600->context.transfer_destroy = u_transfer_destroy_vtbl;
+ r600->context.transfer_inline_write = u_transfer_inline_write_vtbl;
+ r600->context.is_resource_referenced = u_is_resource_referenced_vtbl;
}
void r600_init_screen_resource_functions(struct r600_screen *r600screen)
{
- r600screen->screen.resource_create = r600_resource_create;
- r600screen->screen.resource_from_handle = r600_resource_from_handle;
- r600screen->screen.resource_get_handle = u_resource_get_handle_vtbl;
- r600screen->screen.resource_destroy = u_resource_destroy_vtbl;
- r600screen->screen.user_buffer_create = r600_user_buffer_create;
+ r600screen->screen.resource_create = r600_resource_create;
+ r600screen->screen.resource_from_handle = r600_resource_from_handle;
+ r600screen->screen.resource_get_handle = u_resource_get_handle_vtbl;
+ r600screen->screen.resource_destroy = u_resource_destroy_vtbl;
+ r600screen->screen.user_buffer_create = r600_user_buffer_create;
}
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-
#ifndef R600_RESOURCE_H
#define R600_RESOURCE_H
+#include "util/u_transfer.h"
+
struct r600_context;
struct r600_screen;
+/* This gets further specialized into either buffer or texture
+ * structures. Use the vtbl struct to choose between the two
+ * underlying implementations.
+ */
+struct r600_resource {
+ struct u_resource base;
+ struct radeon_bo *bo;
+ u32 domain;
+ u32 flink;
+ struct pb_buffer *pb;
+};
+
+struct r600_resource_texture {
+ struct r600_resource resource;
+ unsigned long offset[PIPE_MAX_TEXTURE_LEVELS];
+ unsigned long pitch[PIPE_MAX_TEXTURE_LEVELS];
+ unsigned long stride[PIPE_MAX_TEXTURE_LEVELS];
+ unsigned long layer_size[PIPE_MAX_TEXTURE_LEVELS];
+ unsigned long stride_override;
+ unsigned long size;
+};
+
void r600_init_context_resource_functions(struct r600_context *r600);
void r600_init_screen_resource_functions(struct r600_screen *r600screen);
+/* r600_buffer */
+u32 r600_domain_from_usage(unsigned usage);
+
+/* r600_texture */
+struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
+ const struct pipe_resource *templ);
+struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
+ const struct pipe_resource *base,
+ struct winsys_handle *whandle);
+
#endif
* Jerome Glisse
* Corbin Simpson
*/
-#include <util/u_inlines.h>
-#include <util/u_format.h>
-#include <util/u_memory.h>
-#include "r600_resource.h"
+#include <stdio.h>
+#include "util/u_inlines.h"
+#include "util/u_format.h"
+#include "util/u_memory.h"
#include "r600_screen.h"
-#include "r600_texture.h"
#include "r600_context.h"
#include "r600_public.h"
-#include <stdio.h>
+#include "r600_resource.h"
static const char* r600_get_vendor(struct pipe_screen* pscreen)
{
return FALSE;
}
-struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
- struct pipe_resource *texture,
- struct pipe_subresource sr,
- unsigned usage,
- const struct pipe_box *box)
-{
- struct r600_texture *rtex = (struct r600_texture*)texture;
- struct r600_transfer *trans;
-
- trans = CALLOC_STRUCT(r600_transfer);
- if (trans == NULL)
- return NULL;
- pipe_resource_reference(&trans->transfer.resource, texture);
- trans->transfer.sr = sr;
- trans->transfer.usage = usage;
- trans->transfer.box = *box;
- trans->transfer.stride = rtex->stride[sr.level];
- trans->offset = r600_texture_get_offset(rtex, sr.level, box->z, sr.face);
- return &trans->transfer;
-}
-
-void r600_texture_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *trans)
-{
- pipe_resource_reference(&trans->resource, NULL);
- FREE(trans);
-}
-
-void* r600_texture_transfer_map(struct pipe_context *ctx,
- struct pipe_transfer* transfer)
-{
- struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
- struct r600_texture *rtex = (struct r600_texture*)transfer->resource;
- char *map;
- enum pipe_format format = rtex->b.b.format;
-
- map = pipe_buffer_map(ctx, rtex->buffer,
- transfer->usage,
- &rtransfer->buffer_transfer);
-
- if (!map) {
- return NULL;
- }
-
- return map + rtransfer->offset +
- transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
- transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
-}
-
-void r600_texture_transfer_unmap(struct pipe_context *ctx,
- struct pipe_transfer* transfer)
-{
- struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
- struct r600_texture *rtex = (struct r600_texture*)transfer->resource;
-
- pipe_buffer_unmap(ctx, rtex->buffer, rtransfer->buffer_transfer);
-}
-
static void r600_destroy_screen(struct pipe_screen* pscreen)
{
struct r600_screen* rscreen = r600_screen(pscreen);
unsigned offset;
};
-struct r600_buffer {
- struct u_resource b;
- struct radeon_bo *bo;
- u32 domain;
- u32 flink;
- struct pb_buffer *pb;
-};
-
struct r600_screen {
struct pipe_screen screen;
struct radeon *rw;
* Jerome Glisse
*/
#include <stdio.h>
-#include <util/u_inlines.h>
-#include <util/u_format.h>
-#include <util/u_memory.h>
+#include "util/u_inlines.h"
+#include "util/u_format.h"
+#include "util/u_memory.h"
#include "r600_screen.h"
-#include "r600_texture.h"
#include "r600_context.h"
+#include "r600_resource.h"
#include "r600d.h"
{
struct r600_screen *rscreen = r600_screen(ctx->screen);
struct r600_context *rctx = r600_context(ctx);
- struct r600_texture *rtex;
- struct r600_buffer *rbuffer;
+ struct r600_resource_texture *rtex;
+ struct r600_resource *rbuffer;
struct radeon_state *rstate;
unsigned level = state->cbufs[0]->level;
unsigned pitch, slice;
rstate = radeon_state(rscreen->rw, R600_CB0_TYPE, R600_CB0);
if (rstate == NULL)
return;
- rtex = (struct r600_texture*)state->cbufs[0]->texture;
- rbuffer = (struct r600_buffer*)rtex->buffer;
+ rtex = (struct r600_resource_texture*)state->cbufs[0]->texture;
+ rbuffer = &rtex->resource;
rstate->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
rstate->bo[1] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
rstate->bo[2] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
radeon_draw_set_new(rctx->draw, rstate);
rctx->db = radeon_state_decref(rctx->db);
if(state->zsbuf) {
- rtex = (struct r600_texture*)state->zsbuf->texture;
- rbuffer = (struct r600_buffer*)rtex->buffer;
+ rtex = (struct r600_resource_texture*)state->zsbuf->texture;
+ rbuffer = &rtex->resource;
rctx->db = radeon_state(rscreen->rw, R600_DB_TYPE, R600_DB);
if(rctx->db == NULL)
return;
struct r600_screen *rscreen = r600_screen(ctx->screen);
struct r600_texture_resource *rtexture;
const struct util_format_description *desc;
- struct r600_texture *tmp;
- struct r600_buffer *rbuffer;
+ struct r600_resource_texture *tmp;
+ struct r600_resource *rbuffer;
unsigned format;
if (r600_conv_pipe_format(texture->format, &format))
pipe_resource_reference(&rtexture->view.texture, texture);
rtexture->view.context = ctx;
- tmp = (struct r600_texture*)texture;
- rbuffer = (struct r600_buffer*)tmp->buffer;
+ tmp = (struct r600_resource_texture*)texture;
+ rbuffer = &tmp->resource;
rtexture->state->bo[0] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
rtexture->state->bo[1] = radeon_bo_incref(rscreen->rw, rbuffer->bo);
rtexture->state->nbo = 2;
#include "state_tracker/drm_driver.h"
#include "r600_screen.h"
#include "r600_context.h"
-#include "r600_texture.h"
+#include "r600_resource.h"
#include "r600d.h"
extern struct u_resource_vtbl r600_texture_vtbl;
-unsigned long r600_texture_get_offset(struct r600_texture *rtex, unsigned level, unsigned zslice, unsigned face)
+static unsigned long r600_texture_get_offset(struct r600_resource_texture *rtex,
+ unsigned level, unsigned zslice,
+ unsigned face)
{
unsigned long offset = rtex->offset[level];
- switch (rtex->b.b.target) {
+ switch (rtex->resource.base.b.target) {
case PIPE_TEXTURE_3D:
assert(face == 0);
return offset + zslice * rtex->layer_size[level];
}
}
-static void r600_setup_miptree(struct r600_screen *rscreen, struct r600_texture *rtex)
+static void r600_setup_miptree(struct r600_screen *rscreen, struct r600_resource_texture *rtex)
{
- struct pipe_resource *ptex = &rtex->b.b;
+ struct pipe_resource *ptex = &rtex->resource.base.b;
unsigned long w, h, stride, size, layer_size, i, offset;
for (i = 0, offset = 0; i <= ptex->last_level; i++) {
}
struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
- const struct pipe_resource *templ)
+ const struct pipe_resource *templ)
{
- struct r600_texture *rtex = CALLOC_STRUCT(r600_texture);
+ struct r600_resource_texture *rtex;
+ struct r600_resource *resource;
struct r600_screen *rscreen = r600_screen(screen);
- struct pipe_resource templ_buf;
+ rtex = CALLOC_STRUCT(r600_resource_texture);
if (!rtex) {
return NULL;
}
- rtex->b.b = *templ;
- rtex->b.vtbl = &r600_texture_vtbl;
- pipe_reference_init(&rtex->b.b.reference, 1);
- rtex->b.b.screen = screen;
+ resource = &rtex->resource;
+ resource->base.b = *templ;
+ resource->base.vtbl = &r600_texture_vtbl;
+ pipe_reference_init(&resource->base.b.reference, 1);
+ resource->base.b.screen = screen;
r600_setup_miptree(rscreen, rtex);
- memset(&templ_buf, 0, sizeof(struct pipe_resource));
- templ_buf.target = PIPE_BUFFER;
- templ_buf.format = PIPE_FORMAT_R8_UNORM;
- templ_buf.usage = templ->usage;
- templ_buf.bind = templ->bind;
- templ_buf.width0 = rtex->size;
- templ_buf.height0 = 1;
- templ_buf.depth0 = 1;
-
- rtex->buffer = screen->resource_create(screen, &templ_buf);
- if (!rtex->buffer) {
+ /* FIXME alignment 4096 enought ? too much ? */
+ resource->domain = r600_domain_from_usage(resource->base.b.bind);
+ resource->bo = radeon_bo(rscreen->rw, 0, rtex->size, 4096, NULL);
+ if (resource->bo == NULL) {
FREE(rtex);
return NULL;
}
- return &rtex->b.b;
+
+ return &resource->base.b;
}
static void r600_texture_destroy(struct pipe_screen *screen,
struct pipe_resource *ptex)
{
- struct r600_texture *rtex = (struct r600_texture*)ptex;
+ struct r600_resource_texture *rtex = (struct r600_resource_texture*)ptex;
+ struct r600_resource *resource = &rtex->resource;
+ struct r600_screen *rscreen = r600_screen(screen);
+ if (resource->bo) {
+ radeon_bo_decref(rscreen->rw, resource->bo);
+ }
FREE(rtex);
}
unsigned face, unsigned level,
unsigned zslice, unsigned flags)
{
- struct r600_texture *rtex = (struct r600_texture*)texture;
+ struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
struct pipe_surface *surface = CALLOC_STRUCT(pipe_surface);
unsigned long offset;
}
struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
- const struct pipe_resource *base,
+ const struct pipe_resource *templ,
struct winsys_handle *whandle)
{
- struct pipe_resource *buffer;
- struct r600_texture *rtex;
+ struct radeon *rw = (struct radeon*)screen->winsys;
+ struct r600_resource_texture *rtex;
+ struct r600_resource *resource;
+ struct radeon_bo *bo = NULL;
- buffer = r600_buffer_from_handle(screen, whandle);
- if (buffer == NULL) {
+ bo = radeon_bo(rw, whandle->handle, 0, 0, NULL);
+ if (bo == NULL) {
return NULL;
}
/* Support only 2D textures without mipmaps */
- if (base->target != PIPE_TEXTURE_2D || base->depth0 != 1 || base->last_level != 0)
+ if (templ->target != PIPE_TEXTURE_2D || templ->depth0 != 1 || templ->last_level != 0)
return NULL;
- rtex = CALLOC_STRUCT(r600_texture);
+ rtex = CALLOC_STRUCT(r600_resource_texture);
if (rtex == NULL)
return NULL;
- /* one ref already taken */
- rtex->buffer = buffer;
-
- rtex->b.b = *base;
- rtex->b.vtbl = &r600_texture_vtbl;
- pipe_reference_init(&rtex->b.b.reference, 1);
- rtex->b.b.screen = screen;
+ resource = &rtex->resource;
+ resource->base.b = *templ;
+ resource->base.vtbl = &r600_texture_vtbl;
+ pipe_reference_init(&resource->base.b.reference, 1);
+ resource->base.b.screen = screen;
+ resource->bo = bo;
rtex->stride_override = whandle->stride;
- rtex->pitch[0] = whandle->stride / util_format_get_blocksize(base->format);
+ rtex->pitch[0] = whandle->stride / util_format_get_blocksize(templ->format);
rtex->stride[0] = whandle->stride;
rtex->offset[0] = 0;
- rtex->size = align(rtex->stride[0] * base->height0, 32);
+ rtex->size = align(rtex->stride[0] * templ->height0, 32);
- return &rtex->b.b;
+ return &resource->base.b;
}
-static boolean r600_texture_get_handle(struct pipe_screen* screen,
- struct pipe_resource *texture,
- struct winsys_handle *whandle)
+static unsigned int r600_texture_is_referenced(struct pipe_context *context,
+ struct pipe_resource *texture,
+ unsigned face, unsigned level)
{
- struct r600_screen *rscreen = r600_screen(screen);
- struct r600_texture* rtex = (struct r600_texture*)texture;
+ /* FIXME */
+ return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
+}
- if (!rtex) {
- return FALSE;
- }
+struct pipe_transfer* r600_texture_get_transfer(struct pipe_context *ctx,
+ struct pipe_resource *texture,
+ struct pipe_subresource sr,
+ unsigned usage,
+ const struct pipe_box *box)
+{
+ struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
+ struct r600_transfer *trans;
- whandle->stride = rtex->stride[0];
+ trans = CALLOC_STRUCT(r600_transfer);
+ if (trans == NULL)
+ return NULL;
+ pipe_resource_reference(&trans->transfer.resource, texture);
+ trans->transfer.sr = sr;
+ trans->transfer.usage = usage;
+ trans->transfer.box = *box;
+ trans->transfer.stride = rtex->stride[sr.level];
+ trans->offset = r600_texture_get_offset(rtex, sr.level, box->z, sr.face);
+ return &trans->transfer;
+}
+
+void r600_texture_transfer_destroy(struct pipe_context *ctx,
+ struct pipe_transfer *trans)
+{
+ pipe_resource_reference(&trans->resource, NULL);
+ FREE(trans);
+}
+
+void* r600_texture_transfer_map(struct pipe_context *ctx,
+ struct pipe_transfer* transfer)
+{
+ struct r600_transfer *rtransfer = (struct r600_transfer*)transfer;
+ struct r600_resource *resource;
+ enum pipe_format format = transfer->resource->format;
+ struct r600_screen *rscreen = r600_screen(ctx->screen);
+ char *map;
- r600_buffer_get_handle(rscreen->rw, rtex->buffer, whandle);
+ resource = (struct r600_resource *)transfer->resource;
+ if (radeon_bo_map(rscreen->rw, resource->bo)) {
+ return NULL;
+ }
+ map = resource->bo->data;
- return TRUE;
+ return map + rtransfer->offset +
+ transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
+ transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
}
-static unsigned int r600_texture_is_referenced(struct pipe_context *context,
- struct pipe_resource *texture,
- unsigned face, unsigned level)
+void r600_texture_transfer_unmap(struct pipe_context *ctx,
+ struct pipe_transfer* transfer)
{
- struct r600_texture *rtex = (struct r600_texture*)texture;
+ struct r600_screen *rscreen = r600_screen(ctx->screen);
+ struct r600_resource *resource;
- return r600_buffer_is_referenced_by_cs(context, rtex->buffer, face, level);
+ resource = (struct r600_resource *)transfer->resource;
+ radeon_bo_unmap(rscreen->rw, resource->bo);
}
struct u_resource_vtbl r600_texture_vtbl =
{
- r600_texture_get_handle, /* get_handle */
+ u_default_resource_get_handle, /* get_handle */
r600_texture_destroy, /* resource_destroy */
r600_texture_is_referenced, /* is_resource_referenced */
r600_texture_get_transfer, /* get_transfer */
+++ /dev/null
-/*
- * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
- *
- * 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.
- */
-#ifndef R600_TEXTURE_H
-#define R600_TEXTURE_H
-
-#include <pipe/p_state.h>
-
-struct r600_texture {
- struct u_resource b;
- unsigned long offset[PIPE_MAX_TEXTURE_LEVELS];
- unsigned long pitch[PIPE_MAX_TEXTURE_LEVELS];
- unsigned long stride[PIPE_MAX_TEXTURE_LEVELS];
- unsigned long layer_size[PIPE_MAX_TEXTURE_LEVELS];
- unsigned long stride_override;
- unsigned long size;
- struct pipe_resource *buffer;
-};
-
-struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
- const struct pipe_resource *templ);
-unsigned long r600_texture_get_offset(struct r600_texture *rtex, unsigned level, unsigned zslice, unsigned face);
-struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
- const struct pipe_resource *base,
- struct winsys_handle *whandle);
-void r600_init_screen_texture_functions(struct pipe_screen *screen);
-
-/* This should be implemented by winsys. */
-boolean r600_buffer_get_handle(struct radeon *rw,
- struct pipe_resource *buf,
- struct winsys_handle *whandle);
-
-
-#endif