summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/svga/svga_screen_texture.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/svga/svga_screen_texture.c')
-rw-r--r--src/gallium/drivers/svga/svga_screen_texture.c79
1 files changed, 40 insertions, 39 deletions
diff --git a/src/gallium/drivers/svga/svga_screen_texture.c b/src/gallium/drivers/svga/svga_screen_texture.c
index 6e10d65a20..2224c2d394 100644
--- a/src/gallium/drivers/svga/svga_screen_texture.c
+++ b/src/gallium/drivers/svga/svga_screen_texture.c
@@ -29,6 +29,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_inlines.h"
#include "pipe/p_thread.h"
+#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
@@ -158,7 +159,8 @@ svga_transfer_dma_band(struct svga_transfer *st,
st->base.x + st->base.width,
y + h,
st->base.zslice + 1,
- texture->base.block.size*8/(texture->base.block.width*texture->base.block.height));
+ 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;
@@ -208,7 +210,8 @@ svga_transfer_dma(struct svga_transfer *st,
}
else {
unsigned y, h, srcy;
- h = st->hw_nblocksy * st->base.block.height;
+ 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;
@@ -218,11 +221,11 @@ svga_transfer_dma(struct svga_transfer *st,
h = st->base.height - y;
/* Transfer band must be aligned to pixel block boundaries */
- assert(y % st->base.block.height == 0);
- assert(h % st->base.block.height == 0);
+ assert(y % blockheight == 0);
+ assert(h % blockheight == 0);
- offset = y * st->base.stride / st->base.block.height;
- length = h * st->base.stride / st->base.block.height;
+ offset = y * st->base.stride / blockheight;
+ length = h * st->base.stride / blockheight;
sw = (uint8_t *)st->swbuf + offset;
@@ -285,8 +288,6 @@ svga_texture_create(struct pipe_screen *screen,
height = templat->height0;
depth = templat->depth0;
for(level = 0; level <= templat->last_level; ++level) {
- tex->base.nblocksx[level] = pf_get_nblocksx(&tex->base.block, width);
- tex->base.nblocksy[level] = pf_get_nblocksy(&tex->base.block, height);
width = u_minify(width, 1);
height = u_minify(height, 1);
depth = u_minify(depth, 1);
@@ -319,7 +320,7 @@ svga_texture_create(struct pipe_screen *screen,
*/
#if 0
if((templat->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) &&
- !pf_is_compressed(templat->format))
+ !util_format_is_compressed(templat->format))
tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
#endif
@@ -525,7 +526,7 @@ svga_texture_view_surface(struct pipe_context *pipe,
{
struct svga_screen *ss = svga_screen(tex->base.screen);
struct svga_winsys_surface *handle;
- int i, j;
+ uint32_t i, j;
unsigned z_offset = 0;
SVGA_DBG(DEBUG_PERF,
@@ -657,13 +658,11 @@ svga_get_tex_surface(struct pipe_screen *screen,
s->real_level = 0;
s->real_zslice = 0;
} else {
- struct svga_winsys_screen *sws = svga_winsys_screen(screen);
-
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);
- sws->surface_reference(sws, &s->handle, tex->handle);
+ s->handle = tex->handle;
s->real_face = face;
s->real_level = level;
s->real_zslice = zslice;
@@ -677,11 +676,14 @@ 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);
- SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle);
- assert(s->key.cachable == 0);
- svga_screen_surface_destroy(ss, &s->key, &s->handle);
+ 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);
}
@@ -770,6 +772,8 @@ svga_get_tex_transfer(struct pipe_screen *screen,
struct svga_screen *ss = svga_screen(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)
@@ -779,21 +783,17 @@ svga_get_tex_transfer(struct pipe_screen *screen,
if (!st)
return NULL;
- st->base.format = texture->format;
- st->base.block = texture->block;
st->base.x = x;
st->base.y = y;
st->base.width = w;
st->base.height = h;
- st->base.nblocksx = pf_get_nblocksx(&texture->block, w);
- st->base.nblocksy = pf_get_nblocksy(&texture->block, h);
- st->base.stride = st->base.nblocksx*st->base.block.size;
+ 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 = st->base.nblocksy;
+ st->hw_nblocksy = nblocksy;
st->hwbuf = svga_winsys_buffer_create(ss,
1,
@@ -809,15 +809,15 @@ svga_get_tex_transfer(struct pipe_screen *screen,
if(!st->hwbuf)
goto no_hwbuf;
- if(st->hw_nblocksy < st->base.nblocksy) {
+ 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__,
- (st->base.nblocksy*st->base.stride + 1023)/1024,
- (st->base.nblocksy + st->hw_nblocksy - 1)/st->hw_nblocksy,
+ (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(st->base.nblocksy*st->base.stride);
+ st->swbuf = MALLOC(nblocksy*st->base.stride);
if(!st->swbuf)
goto no_swbuf;
}
@@ -911,7 +911,6 @@ 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_winsys_screen *sws = ss->sws;
struct svga_texture *tex = svga_texture(pt);
struct svga_sampler_view *sv = NULL;
SVGA3dSurfaceFormat format = svga_translate_format(pt->format);
@@ -933,7 +932,7 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt,
if (min_lod == 0 && max_lod >= pt->last_level)
view = FALSE;
- if (pf_is_compressed(pt->format) && view) {
+ if (util_format_is_compressed(pt->format) && view) {
format = svga_translate_format_render(pt->format);
}
@@ -962,7 +961,7 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt,
sv = CALLOC_STRUCT(svga_sampler_view);
pipe_reference_init(&sv->reference, 1);
- sv->texture = tex;
+ pipe_texture_reference(&sv->texture, pt);
sv->min_lod = min_lod;
sv->max_lod = max_lod;
@@ -977,7 +976,7 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt,
pt->depth0,
pt->last_level);
sv->key.cachable = 0;
- sws->surface_reference(sws, &sv->handle, tex->handle);
+ sv->handle = tex->handle;
return sv;
}
@@ -1000,7 +999,7 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt,
if (!sv->handle) {
assert(0);
sv->key.cachable = 0;
- sws->surface_reference(sws, &sv->handle, tex->handle);
+ sv->handle = tex->handle;
return sv;
}
@@ -1014,14 +1013,14 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt,
void
svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v)
{
- struct svga_texture *tex = v->texture;
+ struct svga_texture *tex = svga_texture(v->texture);
unsigned numFaces;
unsigned age = 0;
int i, k;
assert(svga);
- if (v->handle == v->texture->handle)
+ if (v->handle == tex->handle)
return;
age = tex->age;
@@ -1049,11 +1048,14 @@ svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *
void
svga_destroy_sampler_view_priv(struct svga_sampler_view *v)
{
- struct svga_screen *ss = svga_screen(v->texture->base.screen);
-
- SVGA_DBG(DEBUG_DMA, "unref sid %p (sampler view)\n", v->handle);
- svga_screen_surface_destroy(ss, &v->key, &v->handle);
+ 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);
}
@@ -1069,8 +1071,7 @@ svga_screen_buffer_from_texture(struct pipe_texture *texture,
svga_translate_format(texture->format),
stex->handle);
- *stride = pf_get_nblocksx(&texture->block, texture->width0) *
- texture->block.size;
+ *stride = util_format_get_stride(texture->format, texture->width0);
return *buffer != NULL;
}