summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorKeith Whitwell <[email protected]>2009-12-01 10:57:37 +0000
committerKeith Whitwell <[email protected]>2009-12-01 10:57:37 +0000
commit06d3732a9094030fc33120f16f162e0d405f132c (patch)
tree185159951093f49f1877e78eaf01f6d1ea01e560 /src/gallium/drivers
parent853d4807fe220b17cf5af5a76b24f2466238013b (diff)
parentf17dbe256bb38c35d885260be7e5856f1561de97 (diff)
Merge commit 'origin/mesa_7_7_branch'
Conflicts: src/gallium/drivers/svga/svga_screen_texture.c src/gallium/state_trackers/xorg/xorg_composite.c src/gallium/state_trackers/xorg/xorg_exa.c src/gallium/state_trackers/xorg/xorg_renderer.c src/gallium/state_trackers/xorg/xorg_xv.c src/mesa/main/texgetimage.c src/mesa/main/version.h
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/svga/Makefile3
-rw-r--r--src/gallium/drivers/svga/svga_context.c4
-rw-r--r--src/gallium/drivers/svga/svga_context.h5
-rw-r--r--src/gallium/drivers/svga/svga_debug.h1
-rw-r--r--src/gallium/drivers/svga/svga_draw.c7
-rw-r--r--src/gallium/drivers/svga/svga_pipe_blit.c8
-rw-r--r--src/gallium/drivers/svga/svga_pipe_clear.c6
-rw-r--r--src/gallium/drivers/svga/svga_pipe_flush.c3
-rw-r--r--src/gallium/drivers/svga/svga_screen.c5
-rw-r--r--src/gallium/drivers/svga/svga_screen_buffer.c16
-rw-r--r--src/gallium/drivers/svga/svga_screen_cache.c109
-rw-r--r--src/gallium/drivers/svga/svga_screen_cache.h17
-rw-r--r--src/gallium/drivers/svga/svga_screen_texture.c159
-rw-r--r--src/gallium/drivers/svga/svga_screen_texture.h16
-rw-r--r--src/gallium/drivers/svga/svga_state_framebuffer.c3
-rw-r--r--src/gallium/drivers/svga/svga_tgsi.c14
16 files changed, 256 insertions, 120 deletions
diff --git a/src/gallium/drivers/svga/Makefile b/src/gallium/drivers/svga/Makefile
index 38b63394e38..f3619081875 100644
--- a/src/gallium/drivers/svga/Makefile
+++ b/src/gallium/drivers/svga/Makefile
@@ -50,6 +50,9 @@ C_SOURCES = \
LIBRARY_INCLUDES = \
-I$(TOP)/src/gallium/drivers/svga/include
+# With linux-debug we get a lots of warnings, filter out the bad flags.
+CFLAGS := $(filter-out -pedantic, $(filter-out -ansi, $(CFLAGS)))
+
LIBRARY_DEFINES = \
-std=gnu99 -fvisibility=hidden \
-DHAVE_STDINT_H -DHAVE_SYS_TYPES_H
diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c
index 73233957f36..c3de12b4a39 100644
--- a/src/gallium/drivers/svga/svga_context.c
+++ b/src/gallium/drivers/svga/svga_context.c
@@ -230,7 +230,9 @@ void svga_context_flush( struct svga_context *svga,
struct pipe_fence_handle **pfence )
{
struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
-
+
+ svga->curr.nr_fbs = 0;
+
/* Unmap upload manager buffers:
*/
u_upload_flush(svga->upload_vb);
diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index 9a3e92fd8d1..e650a251d19 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -191,6 +191,11 @@ struct svga_state
struct pipe_framebuffer_state framebuffer;
float depthscale;
+ /* Hack to limit the number of different render targets between
+ * flushes. Helps avoid blowing out our surface cache in EXA.
+ */
+ int nr_fbs;
+
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
struct pipe_blend_color blend_color;
diff --git a/src/gallium/drivers/svga/svga_debug.h b/src/gallium/drivers/svga/svga_debug.h
index b7bb5686ed3..3a3fcd8fae2 100644
--- a/src/gallium/drivers/svga/svga_debug.h
+++ b/src/gallium/drivers/svga/svga_debug.h
@@ -43,6 +43,7 @@
#define DEBUG_FLUSH 0x1000 /* flush after every draw */
#define DEBUG_SYNC 0x2000 /* sync after every flush */
#define DEBUG_QUERY 0x4000
+#define DEBUG_CACHE 0x8000
#ifdef DEBUG
extern int SVGA_DEBUG;
diff --git a/src/gallium/drivers/svga/svga_draw.c b/src/gallium/drivers/svga/svga_draw.c
index 1b371cecc61..8db40d0fd57 100644
--- a/src/gallium/drivers/svga/svga_draw.c
+++ b/src/gallium/drivers/svga/svga_draw.c
@@ -29,10 +29,13 @@
#include "util/u_memory.h"
#include "util/u_math.h"
+#include "svga_context.h"
#include "svga_draw.h"
#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_winsys.h"
#include "svga_cmd.h"
@@ -160,6 +163,10 @@ svga_hwtnl_flush( struct svga_hwtnl *hwtnl )
ib_handle[i] = handle;
}
+ SVGA_DBG(DEBUG_DMA, "draw to sid %p, %d prims\n",
+ svga_surface(svga->curr.framebuffer.cbufs[0])->handle,
+ hwtnl->cmd.prim_count);
+
ret = SVGA3D_BeginDrawPrimitives(swc,
&vdecl,
hwtnl->cmd.vdecl_count,
diff --git a/src/gallium/drivers/svga/svga_pipe_blit.c b/src/gallium/drivers/svga/svga_pipe_blit.c
index 5a4a8c0f5f1..4f575b06e62 100644
--- a/src/gallium/drivers/svga/svga_pipe_blit.c
+++ b/src/gallium/drivers/svga/svga_pipe_blit.c
@@ -25,6 +25,7 @@
#include "svga_screen_texture.h"
#include "svga_context.h"
+#include "svga_debug.h"
#include "svga_cmd.h"
#define FILE_DEBUG_FLAG DEBUG_BLIT
@@ -43,6 +44,13 @@ static void svga_surface_copy(struct pipe_context *pipe,
svga_hwtnl_flush_retry( svga );
+ SVGA_DBG(DEBUG_DMA, "blit to sid %p (%d,%d), from sid %p (%d,%d) sz %dx%d\n",
+ svga_surface(dest)->handle,
+ destx, desty,
+ svga_surface(src)->handle,
+ srcx, srcy,
+ width, height);
+
ret = SVGA3D_BeginSurfaceCopy(svga->swc,
src,
dest,
diff --git a/src/gallium/drivers/svga/svga_pipe_clear.c b/src/gallium/drivers/svga/svga_pipe_clear.c
index 8977d26541c..6195c3897ed 100644
--- a/src/gallium/drivers/svga/svga_pipe_clear.c
+++ b/src/gallium/drivers/svga/svga_pipe_clear.c
@@ -24,12 +24,14 @@
**********************************************************/
#include "svga_cmd.h"
+#include "svga_debug.h"
#include "pipe/p_defines.h"
#include "util/u_pack_color.h"
#include "svga_context.h"
#include "svga_state.h"
+#include "svga_screen_texture.h"
static enum pipe_error
@@ -98,6 +100,10 @@ svga_clear(struct pipe_context *pipe, unsigned buffers, const float *rgba,
{
struct svga_context *svga = svga_context( pipe );
int ret;
+
+ if (buffers & PIPE_CLEAR_COLOR)
+ SVGA_DBG(DEBUG_DMA, "clear sid %p\n",
+ svga_surface(svga->curr.framebuffer.cbufs[0])->handle);
ret = try_clear( svga, buffers, rgba, depth, stencil );
diff --git a/src/gallium/drivers/svga/svga_pipe_flush.c b/src/gallium/drivers/svga/svga_pipe_flush.c
index 942366de721..0becb0765ac 100644
--- a/src/gallium/drivers/svga/svga_pipe_flush.c
+++ b/src/gallium/drivers/svga/svga_pipe_flush.c
@@ -59,6 +59,9 @@ static void svga_flush( struct pipe_context *pipe,
/* Flush command queue.
*/
svga_context_flush(svga, fence);
+
+ SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s flags %x fence_ptr %p\n",
+ __FUNCTION__, flags, fence ? *fence : 0x0);
}
diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index 3afcaffff55..fc1b3c980ef 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -57,6 +57,7 @@ static const struct debug_named_value svga_debug_flags[] = {
{ "perf", DEBUG_PERF },
{ "flush", DEBUG_FLUSH },
{ "sync", DEBUG_SYNC },
+ { "cache", DEBUG_CACHE },
{NULL, 0}
};
#endif
@@ -297,6 +298,10 @@ svga_fence_finish(struct pipe_screen *screen,
unsigned flag)
{
struct svga_winsys_screen *sws = svga_screen(screen)->sws;
+
+ SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "%s fence_ptr %p\n",
+ __FUNCTION__, fence);
+
return sws->fence_finish(sws, fence, flag);
}
diff --git a/src/gallium/drivers/svga/svga_screen_buffer.c b/src/gallium/drivers/svga/svga_screen_buffer.c
index 3b7811734ed..1f8a8896723 100644
--- a/src/gallium/drivers/svga/svga_screen_buffer.c
+++ b/src/gallium/drivers/svga/svga_screen_buffer.c
@@ -71,7 +71,10 @@ svga_buffer_create_host_surface(struct svga_screen *ss,
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;
@@ -82,7 +85,7 @@ svga_buffer_create_host_surface(struct svga_screen *ss,
*/
sbuf->hw.flags.discard = TRUE;
- SVGA_DBG(DEBUG_DMA, " grab sid %p sz %d\n", sbuf->handle, sbuf->base.size);
+ SVGA_DBG(DEBUG_DMA, " --> got sid %p sz %d (buffer)\n", sbuf->handle, sbuf->base.size);
}
return PIPE_OK;
@@ -444,7 +447,7 @@ svga_buffer_map_range( struct pipe_screen *screen,
enum pipe_error ret;
struct pipe_fence_handle *fence = NULL;
- SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "dma from sid %p, bytes %u - %u\n",
+ SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "dma from sid %p (buffer), bytes %u - %u\n",
sbuf->handle, 0, sbuf->base.size);
memset(&flags, 0, sizeof flags);
@@ -776,12 +779,11 @@ svga_screen_buffer_wrap_surface(struct pipe_screen *screen,
/*
* We are not the creator of this surface and therefore we must not
- * cache it for reuse. The caching code only caches SVGA3D_BUFFER surfaces
- * so make sure this isn't one of those.
+ * cache it for reuse. Set the cacheable flag to zero in the key to
+ * prevent this.
*/
-
- assert(format != SVGA3D_BUFFER);
sbuf->key.format = format;
+ sbuf->key.cachable = 0;
sws->surface_reference(sws, &sbuf->handle, srf);
return buf;
@@ -794,6 +796,8 @@ 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;
}
diff --git a/src/gallium/drivers/svga/svga_screen_cache.c b/src/gallium/drivers/svga/svga_screen_cache.c
index 7360c1688bb..8a06383f61e 100644
--- a/src/gallium/drivers/svga/svga_screen_cache.c
+++ b/src/gallium/drivers/svga/svga_screen_cache.c
@@ -24,6 +24,7 @@
**********************************************************/
#include "util/u_memory.h"
+#include "util/u_hash.h"
#include "svga_debug.h"
#include "svga_winsys.h"
@@ -36,24 +37,11 @@
/**
* Compute the bucket for this key.
- *
- * We simply compute log2(width) for now, but
*/
static INLINE unsigned
svga_screen_cache_bucket(const struct svga_host_surface_cache_key *key)
{
- unsigned bucket = 0;
- unsigned size = key->size.width;
-
- while ((size >>= 1))
- ++bucket;
-
- if(key->flags & SVGA3D_SURFACE_HINT_INDEXBUFFER)
- bucket += 32;
-
- assert(bucket < SVGA_HOST_SURFACE_CACHE_BUCKETS);
-
- return bucket;
+ return util_hash_crc32( key, sizeof *key ) % SVGA_HOST_SURFACE_CACHE_BUCKETS;
}
@@ -69,6 +57,8 @@ svga_screen_cache_lookup(struct svga_screen *svgascreen,
unsigned bucket;
unsigned tries = 0;
+ assert(key->cachable);
+
bucket = svga_screen_cache_bucket(key);
pipe_mutex_lock(cache->mutex);
@@ -104,11 +94,9 @@ svga_screen_cache_lookup(struct svga_screen *svgascreen,
pipe_mutex_unlock(cache->mutex);
-#if 0
- _debug_printf("%s: cache %s after %u tries\n", __FUNCTION__, handle ? "hit" : "miss", tries);
-#else
- (void)tries;
-#endif
+ if (SVGA_DEBUG & DEBUG_DMA)
+ debug_printf("%s: cache %s after %u tries (bucket %d)\n", __FUNCTION__,
+ handle ? "hit" : "miss", tries, bucket);
return handle;
}
@@ -128,6 +116,7 @@ svga_screen_cache_add(struct svga_screen *svgascreen,
struct svga_host_surface_cache_entry *entry = NULL;
struct svga_winsys_surface *handle = *p_handle;
+ assert(key->cachable);
assert(handle);
if(!handle)
@@ -137,15 +126,16 @@ svga_screen_cache_add(struct svga_screen *svgascreen,
pipe_mutex_lock(cache->mutex);
if(!LIST_IS_EMPTY(&cache->empty)) {
- /* use the first empty entry */
- entry = LIST_ENTRY(struct svga_host_surface_cache_entry, cache->empty.next, head);
+ /* use the first empty entry */
+ entry = LIST_ENTRY(struct svga_host_surface_cache_entry, cache->empty.next, head);
- LIST_DEL(&entry->head);
- }
+ LIST_DEL(&entry->head);
+ }
else if(!LIST_IS_EMPTY(&cache->unused)) {
/* free the last used buffer and reuse its entry */
entry = LIST_ENTRY(struct svga_host_surface_cache_entry, cache->unused.prev, head);
- SVGA_DBG(DEBUG_DMA, "unref sid %p\n", entry->handle);
+ SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
+ "unref sid %p (make space)\n", entry->handle);
sws->surface_reference(sws, &entry->handle, NULL);
LIST_DEL(&entry->bucket_head);
@@ -157,11 +147,14 @@ svga_screen_cache_add(struct svga_screen *svgascreen,
entry->handle = handle;
memcpy(&entry->key, key, sizeof entry->key);
+ SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
+ "cache sid %p\n", entry->handle);
LIST_ADD(&entry->head, &cache->validated);
}
else {
/* Couldn't cache the buffer -- this really shouldn't happen */
- SVGA_DBG(DEBUG_DMA, "unref sid %p\n", handle);
+ SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
+ "unref sid %p (couldn't find space)\n", handle);
sws->surface_reference(sws, &handle, NULL);
}
@@ -220,7 +213,8 @@ svga_screen_cache_cleanup(struct svga_screen *svgascreen)
for(i = 0; i < SVGA_HOST_SURFACE_CACHE_SIZE; ++i) {
if(cache->entries[i].handle) {
- SVGA_DBG(DEBUG_DMA, "unref sid %p\n", cache->entries[i].handle);
+ SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
+ "unref sid %p (shutdown)\n", cache->entries[i].handle);
sws->surface_reference(sws, &cache->entries[i].handle, NULL);
}
@@ -261,18 +255,45 @@ svga_screen_surface_create(struct svga_screen *svgascreen,
{
struct svga_winsys_screen *sws = svgascreen->sws;
struct svga_winsys_surface *handle = NULL;
+ boolean cachable = SVGA_SURFACE_CACHE_ENABLED && key->cachable;
+
+ SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
+ "%s sz %dx%dx%d mips %d faces %d cachable %d\n",
+ __FUNCTION__,
+ key->size.width,
+ key->size.height,
+ key->size.depth,
+ key->numMipLevels,
+ key->numFaces,
+ key->cachable);
+
+ if (cachable) {
+ if (key->format == SVGA3D_BUFFER) {
+ /* For buffers, round the buffer size up to the nearest power
+ * of two to increase the probability of cache hits. Keep
+ * texture surface dimensions unchanged.
+ */
+ uint32_t size = 1;
+ while(size < key->size.width)
+ size <<= 1;
+ key->size.width = size;
+ }
- if (SVGA_SURFACE_CACHE_ENABLED && key->format == SVGA3D_BUFFER) {
- /* round the buffer size up to the nearest power of two to increase the
- * probability of cache hits */
- uint32_t size = 1;
- while(size < key->size.width)
- size <<= 1;
- key->size.width = size;
-
handle = svga_screen_cache_lookup(svgascreen, key);
- if (handle)
- SVGA_DBG(DEBUG_DMA, " reuse sid %p sz %d\n", handle, size);
+ if (handle) {
+ if (key->format == SVGA3D_BUFFER)
+ SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
+ "reuse sid %p sz %d (buffer)\n", handle,
+ key->size.width);
+ else
+ SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
+ "reuse sid %p sz %dx%dx%d mips %d faces %d\n", handle,
+ key->size.width,
+ key->size.height,
+ key->size.depth,
+ key->numMipLevels,
+ key->numFaces);
+ }
}
if (!handle) {
@@ -283,7 +304,12 @@ svga_screen_surface_create(struct svga_screen *svgascreen,
key->numFaces,
key->numMipLevels);
if (handle)
- SVGA_DBG(DEBUG_DMA, "create sid %p sz %d\n", handle, key->size);
+ SVGA_DBG(DEBUG_CACHE|DEBUG_DMA,
+ " CREATE sid %p sz %dx%dx%d\n",
+ handle,
+ key->size.width,
+ key->size.height,
+ key->size.depth);
}
return handle;
@@ -297,11 +323,16 @@ svga_screen_surface_destroy(struct svga_screen *svgascreen,
{
struct svga_winsys_screen *sws = svgascreen->sws;
- if(SVGA_SURFACE_CACHE_ENABLED && key->format == SVGA3D_BUFFER) {
+ /* We only set the cachable flag for surfaces of which we are the
+ * exclusive owner. So just hold onto our existing reference in
+ * that case.
+ */
+ if(SVGA_SURFACE_CACHE_ENABLED && key->cachable) {
svga_screen_cache_add(svgascreen, key, p_handle);
}
else {
- SVGA_DBG(DEBUG_DMA, "unref sid %p\n", *p_handle);
+ SVGA_DBG(DEBUG_DMA,
+ "unref sid %p (uncachable)\n", *p_handle);
sws->surface_reference(sws, p_handle, NULL);
}
}
diff --git a/src/gallium/drivers/svga/svga_screen_cache.h b/src/gallium/drivers/svga/svga_screen_cache.h
index 1bbe9877688..f5aa740d408 100644
--- a/src/gallium/drivers/svga/svga_screen_cache.h
+++ b/src/gallium/drivers/svga/svga_screen_cache.h
@@ -36,10 +36,18 @@
#include "util/u_double_list.h"
-/* TODO: Reduce this once we don't allocate an index buffer per draw call */
+/* Guess the storage size of cached surfaces and try and keep it under
+ * this amount:
+ */
+#define SVGA_HOST_SURFACE_CACHE_BYTES 16*1024*1024
+
+/* Maximum number of discrete surfaces in the cache:
+ */
#define SVGA_HOST_SURFACE_CACHE_SIZE 1024
-#define SVGA_HOST_SURFACE_CACHE_BUCKETS 64
+/* Number of hash buckets:
+ */
+#define SVGA_HOST_SURFACE_CACHE_BUCKETS 256
struct svga_winsys_surface;
@@ -53,8 +61,9 @@ struct svga_host_surface_cache_key
SVGA3dSurfaceFlags flags;
SVGA3dSurfaceFormat format;
SVGA3dSize size;
- uint32_t numFaces;
- uint32_t numMipLevels;
+ uint32_t numFaces:24;
+ uint32_t numMipLevels:7;
+ uint32_t cachable:1; /* False if this is a shared surface */
};
diff --git a/src/gallium/drivers/svga/svga_screen_texture.c b/src/gallium/drivers/svga/svga_screen_texture.c
index fb11b80dcf9..6e10d65a205 100644
--- a/src/gallium/drivers/svga/svga_screen_texture.c
+++ b/src/gallium/drivers/svga/svga_screen_texture.c
@@ -266,14 +266,8 @@ svga_texture_create(struct pipe_screen *screen,
const struct pipe_texture *templat)
{
struct svga_screen *svgascreen = svga_screen(screen);
- struct svga_winsys_screen *sws = svgascreen->sws;
struct svga_texture *tex = CALLOC_STRUCT(svga_texture);
unsigned width, height, depth;
- SVGA3dSurfaceFlags flags = 0;
- SVGA3dSurfaceFormat format;
- SVGA3dSize size;
- uint32 numFaces;
- uint32 numMipLevels;
unsigned level;
if (!tex)
@@ -298,23 +292,24 @@ svga_texture_create(struct pipe_screen *screen,
depth = u_minify(depth, 1);
}
- size.width = templat->width0;
- size.height = templat->height0;
- size.depth = templat->depth0;
+ 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) {
- flags |= SVGA3D_SURFACE_CUBEMAP;
- numFaces = 6;
+ tex->key.flags |= SVGA3D_SURFACE_CUBEMAP;
+ tex->key.numFaces = 6;
}
else {
- numFaces = 1;
+ tex->key.numFaces = 1;
}
if(templat->tex_usage & PIPE_TEXTURE_USAGE_SAMPLER)
- flags |= SVGA3D_SURFACE_HINT_TEXTURE;
+ tex->key.flags |= SVGA3D_SURFACE_HINT_TEXTURE;
if(templat->tex_usage & PIPE_TEXTURE_USAGE_PRIMARY)
- flags |= SVGA3D_SURFACE_HINT_SCANOUT;
+ tex->key.flags |= SVGA3D_SURFACE_HINT_SCANOUT;
/*
* XXX: Never pass the SVGA3D_SURFACE_HINT_RENDERTARGET hint. Mesa cannot
@@ -325,21 +320,24 @@ svga_texture_create(struct pipe_screen *screen,
#if 0
if((templat->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) &&
!pf_is_compressed(templat->format))
- flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
+ tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
#endif
if(templat->tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL)
- flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
+ tex->key.flags |= SVGA3D_SURFACE_HINT_DEPTHSTENCIL;
- numMipLevels = templat->last_level + 1;
+ tex->key.numMipLevels = templat->last_level + 1;
- format = svga_translate_format(templat->format);
- if(format == SVGA3D_FORMAT_INVALID)
+ tex->key.format = svga_translate_format(templat->format);
+ if(tex->key.format == SVGA3D_FORMAT_INVALID)
goto error2;
+
+ tex->key.cachable = 1;
- tex->handle = sws->surface_create(sws, flags, format, size, numFaces, numMipLevels);
+ 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, "create sid %p (texture)\n", tex->handle);
+ SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle);
return &tex->base;
@@ -395,6 +393,7 @@ svga_texture_blanket(struct pipe_screen * screen,
return NULL;
tex->base = *base;
+
if (sbuf->key.format == 1)
tex->base.format = PIPE_FORMAT_X8R8G8B8_UNORM;
@@ -404,6 +403,12 @@ svga_texture_blanket(struct pipe_screen * screen,
pipe_reference_init(&tex->base.reference, 1);
tex->base.screen = screen;
+ SVGA_DBG(DEBUG_DMA, "blanket sid %p\n", sbuf->handle);
+
+ /* We don't own this storage, so don't try to cache it.
+ */
+ assert(sbuf->key.cachable == 0);
+ tex->key.cachable = 0;
sws->surface_reference(sws, &tex->handle, sbuf->handle);
return &tex->base;
@@ -424,7 +429,7 @@ svga_texture_destroy(struct pipe_texture *pt)
DBG("%s deleting %p\n", __FUNCTION__, (void *) tex);
*/
SVGA_DBG(DEBUG_DMA, "unref sid %p (texture)\n", tex->handle);
- ss->sws->surface_reference(ss->sws, &tex->handle, NULL);
+ svga_screen_surface_destroy(ss, &tex->key, &tex->handle);
FREE(tex);
}
@@ -515,43 +520,47 @@ svga_texture_view_surface(struct pipe_context *pipe,
unsigned start_mip,
unsigned num_mip,
int face_pick,
- int zslice_pick)
+ int zslice_pick,
+ struct svga_host_surface_cache_key *key) /* OUT */
{
struct svga_screen *ss = svga_screen(tex->base.screen);
- struct svga_winsys_screen *sws = ss->sws;
struct svga_winsys_surface *handle;
int i, j;
- SVGA3dSurfaceFlags flags = 0;
- SVGA3dSize size;
- uint32 numFaces;
- uint32 numMipLevels = num_mip;
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);
- size.width = u_minify(tex->base.width0, start_mip);
- size.height = u_minify(tex->base.height0, start_mip);
- size.depth = zslice_pick < 0 ? u_minify(tex->base.depth0, start_mip) : 1;
- assert(size.depth == 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) {
- flags |= SVGA3D_SURFACE_CUBEMAP;
- numFaces = 6;
+ key->flags |= SVGA3D_SURFACE_CUBEMAP;
+ key->numFaces = 6;
} else {
- numFaces = 1;
+ key->numFaces = 1;
}
- if(format == SVGA3D_FORMAT_INVALID)
+ if(key->format == SVGA3D_FORMAT_INVALID) {
+ key->cachable = 0;
return NULL;
+ }
- handle = sws->surface_create(sws, flags, format, size, numFaces, numMipLevels);
-
- if (!handle)
+ 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, "create sid %p (texture view)\n", handle);
+ SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture view)\n", handle);
if (face_pick < 0)
face_pick = 0;
@@ -559,15 +568,23 @@ svga_texture_view_surface(struct pipe_context *pipe,
if (zslice_pick >= 0)
z_offset = zslice_pick;
- for (i = 0; i < num_mip; i++) {
- for (j = 0; j < numFaces; j++) {
+ 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,
+ 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);
+ u_minify(tex->base.height0, i + start_mip),
+ depth);
}
}
}
@@ -584,25 +601,23 @@ svga_get_tex_surface(struct pipe_screen *screen,
{
struct svga_texture *tex = svga_texture(pt);
struct svga_surface *s;
- struct pipe_surface *ps;
boolean render = flags & PIPE_BUFFER_USAGE_GPU_WRITE ? TRUE : FALSE;
boolean view = FALSE;
SVGA3dSurfaceFormat format;
s = CALLOC_STRUCT(svga_surface);
- ps = &s->base;
- if (!ps)
+ if (!s)
return NULL;
- 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->usage = flags;
- ps->level = level;
- ps->face = face;
- ps->zslice = zslice;
+ 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);
@@ -617,11 +632,13 @@ svga_get_tex_surface(struct pipe_screen *screen,
view = TRUE;
/* Currently only used for compressed textures */
- if (render && (format != svga_translate_format(pt->format))) {
+ if (render &&
+ format != svga_translate_format(pt->format)) {
view = TRUE;
}
- if (level != 0 && svga_screen(screen)->debug.force_level_surface_view)
+ if (level != 0 &&
+ svga_screen(screen)->debug.force_level_surface_view)
view = TRUE;
if (pt->target == PIPE_TEXTURE_3D)
@@ -632,9 +649,10 @@ svga_get_tex_surface(struct pipe_screen *screen,
if (view) {
SVGA_DBG(DEBUG_VIEWS, "svga: Surface view: yes %p, level %u face %u z %u, %p\n",
- pt, level, face, zslice, ps);
+ pt, level, face, zslice, s);
- s->handle = svga_texture_view_surface(NULL, tex, format, level, 1, face, zslice);
+ 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;
@@ -642,15 +660,16 @@ svga_get_tex_surface(struct pipe_screen *screen,
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, ps);
+ pt, level, face, zslice, s);
+ memset(&s->key, 0, sizeof s->key);
sws->surface_reference(sws, &s->handle, tex->handle);
s->real_face = face;
s->real_level = level;
s->real_zslice = zslice;
}
- return ps;
+ return &s->base;
}
@@ -661,7 +680,8 @@ svga_tex_surface_destroy(struct pipe_surface *surf)
struct svga_screen *ss = svga_screen(surf->texture->screen);
SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle);
- ss->sws->surface_reference(ss->sws, &s->handle, NULL);
+ assert(s->key.cachable == 0);
+ svga_screen_surface_destroy(ss, &s->key, &s->handle);
pipe_texture_reference(&surf->texture, NULL);
FREE(surf);
}
@@ -956,6 +976,7 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt,
pt->height0,
pt->depth0,
pt->last_level);
+ sv->key.cachable = 0;
sws->surface_reference(sws, &sv->handle, tex->handle);
return sv;
}
@@ -973,10 +994,12 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt,
sv->handle = svga_texture_view_surface(pipe, tex, format,
min_lod,
max_lod - min_lod + 1,
- -1, -1);
+ -1, -1,
+ &sv->key);
if (!sv->handle) {
assert(0);
+ sv->key.cachable = 0;
sws->surface_reference(sws, &sv->handle, tex->handle);
return sv;
}
@@ -1029,7 +1052,7 @@ 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);
- ss->sws->surface_reference(ss->sws, &v->handle, NULL);
+ svga_screen_surface_destroy(ss, &v->key, &v->handle);
FREE(v);
}
@@ -1059,6 +1082,8 @@ svga_screen_texture_get_winsys_surface(struct pipe_texture *texture)
struct svga_winsys_screen *sws = svga_winsys_screen(texture->screen);
struct svga_winsys_surface *vsurf = NULL;
+ assert(svga_texture(texture)->key.cachable == 0);
+ svga_texture(texture)->key.cachable = 0;
sws->surface_reference(sws, &vsurf, svga_texture(texture)->handle);
return vsurf;
}
diff --git a/src/gallium/drivers/svga/svga_screen_texture.h b/src/gallium/drivers/svga/svga_screen_texture.h
index 1e6fef59a39..1cc4063e653 100644
--- a/src/gallium/drivers/svga/svga_screen_texture.h
+++ b/src/gallium/drivers/svga/svga_screen_texture.h
@@ -29,7 +29,7 @@
#include "pipe/p_compiler.h"
#include "pipe/p_state.h"
-
+#include "svga_screen_cache.h"
struct pipe_context;
struct pipe_screen;
@@ -68,6 +68,7 @@ struct svga_sampler_view
unsigned age;
+ struct svga_host_surface_cache_key key;
struct svga_winsys_surface *handle;
};
@@ -76,8 +77,6 @@ struct svga_texture
{
struct pipe_texture base;
- struct svga_winsys_surface *handle;
-
boolean defined[6][PIPE_MAX_TEXTURE_LEVELS];
struct svga_sampler_view *cached_view;
@@ -86,6 +85,16 @@ struct svga_texture
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;
+ struct svga_winsys_surface *handle;
};
@@ -93,6 +102,7 @@ struct svga_surface
{
struct pipe_surface base;
+ struct svga_host_surface_cache_key key;
struct svga_winsys_surface *handle;
unsigned real_face;
diff --git a/src/gallium/drivers/svga/svga_state_framebuffer.c b/src/gallium/drivers/svga/svga_state_framebuffer.c
index 7d7f93d8e3c..cfdcae4ee4a 100644
--- a/src/gallium/drivers/svga/svga_state_framebuffer.c
+++ b/src/gallium/drivers/svga/svga_state_framebuffer.c
@@ -54,6 +54,9 @@ static int emit_framebuffer( struct svga_context *svga,
for(i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) {
if (curr->cbufs[i] != hw->cbufs[i]) {
+ if (svga->curr.nr_fbs++ > 8)
+ return PIPE_ERROR_OUT_OF_MEMORY;
+
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_COLOR0 + i, curr->cbufs[i]);
if (ret != PIPE_OK)
return ret;
diff --git a/src/gallium/drivers/svga/svga_tgsi.c b/src/gallium/drivers/svga/svga_tgsi.c
index 81eea1a145a..b8ef137c015 100644
--- a/src/gallium/drivers/svga/svga_tgsi.c
+++ b/src/gallium/drivers/svga/svga_tgsi.c
@@ -222,6 +222,20 @@ svga_tgsi_translate( const struct svga_shader *shader,
result->nr_tokens = (emit.ptr - emit.buf) / sizeof(unsigned);
memcpy(&result->key, &key, sizeof key);
+ if (SVGA_DEBUG & DEBUG_TGSI)
+ {
+ debug_printf( "#####################################\n" );
+ debug_printf( "Shader %u below\n", shader->id );
+ tgsi_dump( shader->tokens, 0 );
+ if (SVGA_DEBUG & DEBUG_TGSI) {
+ debug_printf( "Shader %u compiled below\n", shader->id );
+ svga_shader_dump( result->tokens,
+ result->nr_tokens ,
+ FALSE );
+ }
+ debug_printf( "#####################################\n" );
+ }
+
return result;
fail: