Commit f236f966 authored by Luca Barbieri's avatar Luca Barbieri

nvfx: fix for gallium-resources

It seems to work with basic applications but almost surely needs more work.

In particular, it probably shouldn't use PIPE_BUFFER_USAGE_* flags
and should use PIPE_TRANSFER_* in several places.

Also, we probably don't want the vtable indirect calls and that ought
to be replaced with something better instead.
parent 5a136ad7
......@@ -15,6 +15,7 @@
/* 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)
......@@ -92,20 +93,20 @@ nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes)
}
static inline uint32_t
nouveau_screen_map_flags(unsigned pipe)
nouveau_screen_map_flags(unsigned usage)
{
uint32_t flags = 0;
if (pipe & PIPE_BUFFER_USAGE_CPU_READ)
if (usage & PIPE_TRANSFER_READ)
flags |= NOUVEAU_BO_RD;
if (pipe & PIPE_BUFFER_USAGE_CPU_WRITE)
if (usage & PIPE_TRANSFER_WRITE)
flags |= NOUVEAU_BO_WR;
if (pipe & PIPE_BUFFER_USAGE_DISCARD)
if (usage & PIPE_TRANSFER_DISCARD)
flags |= NOUVEAU_BO_INVAL;
if (pipe & PIPE_BUFFER_USAGE_DONTBLOCK)
if (usage & PIPE_TRANSFER_DONTBLOCK)
flags |= NOUVEAU_BO_NOWAIT;
else
if (pipe & PIPE_BUFFER_USAGE_UNSYNCHRONIZED)
if (usage & PIPE_TRANSFER_UNSYNCHRONIZED)
flags |= NOUVEAU_BO_NOSYNC;
return flags;
......@@ -113,10 +114,9 @@ nouveau_screen_map_flags(unsigned pipe)
void *
nouveau_screen_bo_map(struct pipe_screen *pscreen,
struct nouveau_bo *pb,
struct nouveau_bo *bo,
unsigned usage)
{
struct nouveau_screen *nscreen = nouveau_screen(pscreen);
int ret;
ret = nouveau_bo_map(bo, nouveau_screen_map_flags(usage));
......@@ -132,7 +132,6 @@ void *
nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct nouveau_bo *bo,
unsigned offset, unsigned length, unsigned usage)
{
struct nouveau_screen *nscreen = nouveau_screen(pscreen);
uint32_t flags = nouveau_screen_map_flags(usage);
int ret;
......@@ -197,7 +196,8 @@ nouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
unsigned *out_stride)
{
struct nouveau_device *dev = nouveau_screen(pscreen)->device;
struct nouveau_bo *bo;
struct nouveau_bo *bo = 0;
int ret;
ret = nouveau_bo_handle_ref(dev, whandle->handle, &bo);
if (ret) {
......@@ -217,12 +217,12 @@ nouveau_screen_bo_get_handle(struct pipe_screen *pscreen,
unsigned stride,
struct winsys_handle *whandle)
{
whandle->stride = util_format_get_stride(mt->base.format, mt->base.width0);
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;
......
......@@ -92,7 +92,7 @@ struct nouveau_stateobj *
nv30_fragtex_build(struct nvfx_context *nvfx, int unit)
{
struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
struct nvfx_miptree *nv30mt = nvfx->tex_miptree[unit];
struct nvfx_miptree *nv30mt = (struct nvfx_miptree *)nvfx->fragment_sampler_views[unit]->texture;
struct pipe_resource *pt = &nv30mt->base.base;
struct nouveau_bo *bo = nv30mt->base.bo;
struct nv30_texture_format *tf;
......
......@@ -110,7 +110,7 @@ struct nouveau_stateobj *
nv40_fragtex_build(struct nvfx_context *nvfx, int unit)
{
struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
struct nvfx_miptree *nv40mt = nvfx->tex_miptree[unit];
struct nvfx_miptree *nv40mt = (struct nvfx_miptree *)nvfx->fragment_sampler_views[unit]->texture;
struct nouveau_bo *bo = nv40mt->base.bo;
struct pipe_resource *pt = &nv40mt->base.base;
struct nv40_texture_format *tf;
......
......@@ -73,7 +73,7 @@ nvfx_create(struct pipe_screen *pscreen, void *priv)
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);
/* Create, configure, and install fallback swtnl path */
nvfx->draw = draw_create();
......
......@@ -157,7 +157,6 @@ struct nvfx_context {
struct pipe_resource *idxbuf;
unsigned idxbuf_format;
struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
struct nvfx_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
unsigned nr_samplers;
unsigned nr_textures;
......
......@@ -132,6 +132,7 @@ nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_resource *pt)
return NULL;
mt->base.base = *pt;
mt->base.vtbl = &nvfx_miptree_vtbl;
pipe_reference_init(&mt->base.base.reference, 1);
mt->base.base.screen = pscreen;
......
......@@ -76,7 +76,7 @@ nvfx_miptree_transfer_new(struct pipe_context *pcontext,
tx->surface = pscreen->get_tex_surface(pscreen, pt,
sr.face, sr.level,
box->z,
pipe_transfer_buffer_flags(&tx->base));
usage);
return &tx->base;
}
......@@ -95,7 +95,7 @@ nvfx_miptree_transfer_new(struct pipe_context *pcontext,
tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
0, 0, 0,
pipe_transfer_buffer_flags(&tx->base));
tx->base.usage);
pipe_resource_reference(&tx_tex, NULL);
......@@ -167,8 +167,7 @@ nvfx_miptree_transfer_map(struct pipe_context *pcontext, struct pipe_transfer *p
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;
uint8_t *map = nouveau_screen_bo_map(pscreen, mt->base.bo,
pipe_transfer_buffer_flags(ptx));
uint8_t *map = nouveau_screen_bo_map(pscreen, mt->base.bo, ptx->usage);
if(!tx->direct)
return map + ns->base.offset;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment