#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include "os/os_thread.h"
-#include "os/os_time.h"
#include "util/u_format.h"
#include "util/u_inlines.h"
#include "util/u_math.h"
svga_transfer_dma_band(struct svga_context *svga,
struct svga_transfer *st,
SVGA3dTransferType transfer,
- unsigned y, unsigned h, unsigned srcy,
+ unsigned x, unsigned y, unsigned z,
+ unsigned w, unsigned h, unsigned d,
+ unsigned srcx, unsigned srcy, unsigned srcz,
SVGA3dSurfaceDMAFlags flags)
{
struct svga_texture *texture = svga_texture(st->base.resource);
assert(!st->use_direct_map);
- box.x = st->base.box.x;
+ box.x = x;
box.y = y;
- box.z = st->base.box.z;
- box.w = st->base.box.width;
+ box.z = z;
+ box.w = w;
box.h = h;
- box.d = 1;
- box.srcx = 0;
+ box.d = d;
+ box.srcx = srcx;
box.srcy = srcy;
- box.srcz = 0;
+ box.srcz = srcz;
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->slice,
- st->base.box.x,
+ x,
y,
- box.z,
- st->base.box.x + st->base.box.width,
+ z,
+ x + w,
y + h,
- box.z + 1,
+ 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)));
if (!st->swbuf) {
/* Do the DMA transfer in a single go */
svga_transfer_dma_band(svga, st, transfer,
- st->base.box.y, st->base.box.height, 0,
+ st->base.box.x, st->base.box.y, st->base.box.z,
+ st->base.box.width, st->base.box.height, st->base.box.depth,
+ 0, 0, 0,
flags);
if (transfer == SVGA3D_READ_HOST_VRAM) {
}
}
- svga_transfer_dma_band(svga, st, transfer, y, h, srcy, flags);
+ svga_transfer_dma_band(svga, st, transfer,
+ st->base.box.x, y, st->base.box.z,
+ st->base.box.width, h, st->base.box.depth,
+ 0, srcy, 0, flags);
/*
* Prevent the texture contents to be discarded on the next band
FREE(tex->defined);
FREE(tex->rendered_to);
+ FREE(tex->dirty);
FREE(tex);
assert(ss->hud.num_resources > 0);
boolean use_direct_map = svga_have_gb_objects(svga) &&
!svga_have_gb_dma(svga);
unsigned d;
- void *returnVal;
- int64_t begin = os_time_get();
+ void *returnVal = NULL;
+ int64_t begin = svga_get_time(svga);
+
+ SVGA_STATS_TIME_PUSH(sws, SVGA_STATS_TIME_TEXTRANSFERMAP);
/* We can't map texture storage directly unless we have GB objects */
if (usage & PIPE_TRANSFER_MAP_DIRECTLY) {
if (svga_have_gb_objects(svga))
use_direct_map = TRUE;
else
- return NULL;
+ goto done;
}
st = CALLOC_STRUCT(svga_transfer);
if (!st)
- return NULL;
+ goto done;
+
+ st->base.level = level;
+ st->base.usage = usage;
+ st->base.box = *box;
+
+ switch (tex->b.b.target) {
+ case PIPE_TEXTURE_CUBE:
+ st->slice = st->base.box.z;
+ st->base.box.z = 0; /* so we don't apply double offsets below */
+ break;
+ case PIPE_TEXTURE_2D_ARRAY:
+ case PIPE_TEXTURE_1D_ARRAY:
+ st->slice = st->base.box.z;
+ st->base.box.z = 0; /* so we don't apply double offsets below */
+
+ /* Force direct map for transfering multiple slices */
+ if (st->base.box.depth > 1)
+ use_direct_map = svga_have_gb_objects(svga);
+
+ break;
+ default:
+ st->slice = 0;
+ break;
+ }
{
unsigned w, h;
pipe_resource_reference(&st->base.resource, texture);
- st->base.level = level;
- st->base.usage = usage;
- st->base.box = *box;
st->base.stride = nblocksx*util_format_get_blocksize(texture->format);
st->base.layer_stride = st->base.stride * nblocksy;
+ st->use_direct_map = use_direct_map;
+
+ *ptransfer = &st->base;
- switch (tex->b.b.target) {
- case PIPE_TEXTURE_CUBE:
- case PIPE_TEXTURE_2D_ARRAY:
- case PIPE_TEXTURE_1D_ARRAY:
- st->slice = st->base.box.z;
- st->base.box.z = 0; /* so we don't apply double offsets below */
- break;
- default:
- st->slice = 0;
- break;
- }
if (usage & PIPE_TRANSFER_WRITE) {
/* record texture upload for HUD */
if (!st->hwbuf) {
FREE(st);
- return NULL;
+ goto done;
}
if (st->hw_nblocksy < nblocksy) {
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);
+ (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 * d);
if (!st->swbuf) {
sws->buffer_destroy(sws, st->hwbuf);
FREE(st);
- return NULL;
+ goto done;
}
}
if (!surf) {
FREE(st);
- return NULL;
+ goto done;
+ }
+
+ /* If this is the first time mapping to the surface in this
+ * command buffer, clear the dirty masks of this surface.
+ */
+ if (sws->surface_is_flushed(sws, surf)) {
+ svga_clear_texture_dirty(tex);
}
if (need_tex_readback(transfer)) {
svga_surfaces_flush(svga);
if (svga_have_vgpu10(svga)) {
- ret = readback_image_vgpu10(svga, surf, st->slice, transfer->level,
+ ret = readback_image_vgpu10(svga, surf, st->slice, level,
tex->b.b.last_level + 1);
} else {
- ret = readback_image_vgpu9(svga, surf, st->slice, transfer->level);
+ ret = readback_image_vgpu9(svga, surf, st->slice, level);
}
+ svga->hud.num_readbacks++;
+ SVGA_STATS_COUNT_INC(sws, SVGA_STATS_COUNT_TEXREADBACK);
+
assert(ret == PIPE_OK);
(void) ret;
* Note: if PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE were specified
* we could potentially clear the flag for all faces/layers/mips.
*/
- svga_clear_texture_rendered_to(tex, st->slice, transfer->level);
+ svga_clear_texture_rendered_to(tex, st->slice, level);
}
else {
- assert(transfer->usage & PIPE_TRANSFER_WRITE);
- if ((transfer->usage & PIPE_TRANSFER_UNSYNCHRONIZED) == 0) {
- svga_surfaces_flush(svga);
- if (!sws->surface_is_flushed(sws, surf))
- svga_context_flush(svga, NULL);
+ assert(usage & PIPE_TRANSFER_WRITE);
+ if ((usage & PIPE_TRANSFER_UNSYNCHRONIZED) == 0) {
+ if (svga_is_texture_dirty(tex, st->slice, level)) {
+ /*
+ * do a surface flush if the subresource has been modified
+ * in this command buffer.
+ */
+ svga_surfaces_flush(svga);
+ if (!sws->surface_is_flushed(sws, surf)) {
+ svga->hud.surface_write_flushes++;
+ SVGA_STATS_COUNT_INC(sws, SVGA_STATS_COUNT_SURFACEWRITEFLUSH);
+ svga_context_flush(svga, NULL);
+ }
+ }
}
}
+ if (usage & PIPE_TRANSFER_WRITE) {
+ /* mark this texture level as dirty */
+ svga_set_texture_dirty(tex, st->slice, level);
+ }
}
- st->use_direct_map = use_direct_map;
-
- *ptransfer = &st->base;
-
/*
* Begin mapping code
*/
if (st->swbuf) {
returnVal = st->swbuf;
}
- else if (!st->use_direct_map) {
+ else if (!use_direct_map) {
returnVal = sws->buffer_map(sws, st->hwbuf, usage);
}
else {
SVGA3dSize baseLevelSize;
- struct svga_texture *tex = svga_texture(texture);
struct svga_winsys_surface *surf = tex->handle;
uint8_t *map;
boolean retry;
* At this point, the svga_surfaces_flush() should already have
* called in svga_texture_get_transfer().
*/
+ svga->hud.surface_write_flushes++;
svga_context_flush(svga, NULL);
map = svga->swc->surface_map(svga->swc, surf, usage, &retry);
}
*/
if (!map) {
FREE(st);
- return map;
+ returnVal = map;
+ goto done;
}
/**
baseLevelSize.height = tex->b.b.height0;
baseLevelSize.depth = tex->b.b.depth0;
+ if ((tex->b.b.target == PIPE_TEXTURE_1D_ARRAY) ||
+ (tex->b.b.target == PIPE_TEXTURE_2D_ARRAY)) {
+ st->base.layer_stride =
+ svga3dsurface_get_image_offset(tex->key.format, baseLevelSize,
+ tex->b.b.last_level + 1, 1, 0);
+ }
+
offset = svga3dsurface_get_image_offset(tex->key.format, baseLevelSize,
tex->b.b.last_level + 1, /* numMips */
st->slice, level);
returnVal = (void *) (map + offset);
}
- svga->hud.map_buffer_time += (os_time_get() - begin);
- svga->hud.num_resources_mapped++;
+ svga->hud.map_buffer_time += (svga_get_time(svga) - begin);
+ svga->hud.num_textures_mapped++;
+done:
+ SVGA_STATS_TIME_POP(sws);
return returnVal;
}
struct svga_transfer *st = svga_transfer(transfer);
struct svga_texture *tex = svga_texture(transfer->resource);
+ SVGA_STATS_TIME_PUSH(sws, SVGA_STATS_TIME_TEXTRANSFERUNMAP);
+
if (!st->swbuf) {
if (st->use_direct_map) {
svga_texture_surface_unmap(svga, transfer);
svga_transfer_dma(svga, st, SVGA3D_WRITE_HOST_VRAM, flags);
} else if (transfer->usage & PIPE_TRANSFER_WRITE) {
- struct svga_winsys_surface *surf =
- svga_texture(transfer->resource)->handle;
+ struct svga_winsys_surface *surf = tex->handle;
SVGA3dBox box;
enum pipe_error ret;
+ unsigned nlayers = 1;
assert(svga_have_gb_objects(svga));
/* update the effected region */
box.x = transfer->box.x;
box.y = transfer->box.y;
+ box.w = transfer->box.width;
+ box.h = transfer->box.height;
+ box.d = transfer->box.depth;
+
switch (tex->b.b.target) {
case PIPE_TEXTURE_CUBE:
+ box.z = 0;
+ break;
case PIPE_TEXTURE_2D_ARRAY:
+ nlayers = box.d;
box.z = 0;
+ box.d = 1;
break;
case PIPE_TEXTURE_1D_ARRAY:
+ nlayers = box.d;
box.y = box.z = 0;
+ box.d = 1;
break;
default:
box.z = transfer->box.z;
break;
}
- box.w = transfer->box.width;
- box.h = transfer->box.height;
- box.d = transfer->box.depth;
if (0)
debug_printf("%s %d, %d, %d %d x %d x %d\n",
box.w, box.h, box.d);
if (svga_have_vgpu10(svga)) {
- ret = update_image_vgpu10(svga, surf, &box, st->slice, transfer->level,
- tex->b.b.last_level + 1);
+ unsigned i;
+ for (i = 0; i < nlayers; i++) {
+ ret = update_image_vgpu10(svga, surf, &box,
+ st->slice + i, transfer->level,
+ tex->b.b.last_level + 1);
+ assert(ret == PIPE_OK);
+ }
} else {
+ assert(nlayers == 1);
ret = update_image_vgpu9(svga, surf, &box, st->slice, transfer->level);
+ assert(ret == PIPE_OK);
}
- assert(ret == PIPE_OK);
+ svga->hud.num_resource_updates++;
+
(void) ret;
}
sws->buffer_destroy(sws, st->hwbuf);
}
FREE(st);
+ SVGA_STATS_TIME_POP(sws);
}
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 svga_texture *tex;
unsigned bindings = template->bind;
+ SVGA_STATS_TIME_PUSH(svgascreen->sws,
+ SVGA_STATS_TIME_CREATETEXTURE);
+
assert(template->last_level < SVGA_MAX_TEXTURE_LEVELS);
if (template->last_level >= SVGA_MAX_TEXTURE_LEVELS) {
- return NULL;
+ goto fail_notex;
}
tex = CALLOC_STRUCT(svga_texture);
if (!tex) {
- return NULL;
+ goto fail_notex;
}
tex->defined = CALLOC(template->depth0 * template->array_size,
sizeof(tex->defined[0]));
if (!tex->defined) {
FREE(tex);
- return NULL;
+ goto fail_notex;
}
tex->rendered_to = CALLOC(template->depth0 * template->array_size,
sizeof(tex->rendered_to[0]));
if (!tex->rendered_to) {
- FREE(tex->defined);
- FREE(tex);
- return NULL;
+ goto fail;
+ }
+
+ tex->dirty = CALLOC(template->depth0 * template->array_size,
+ sizeof(tex->dirty[0]));
+ if (!tex->dirty) {
+ goto fail;
}
tex->b.b = *template;
tex->key.size.depth = template->depth0;
tex->key.arraySize = 1;
tex->key.numFaces = 1;
- tex->key.sampleCount = template->nr_samples;
+
+ /* single sample texture can be treated as non-multisamples texture */
+ tex->key.sampleCount = template->nr_samples > 1 ? template->nr_samples : 0;
if (template->nr_samples > 1) {
tex->key.flags |= SVGA3D_SURFACE_MASKABLE_ANTIALIAS;
tex->key.cachable = 1;
+ if ((bindings & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL)) &&
+ !(bindings & PIPE_BIND_SAMPLER_VIEW)) {
+ /* Also check if the format can be sampled from */
+ if (screen->is_format_supported(screen, template->format,
+ template->target,
+ template->nr_samples,
+ PIPE_BIND_SAMPLER_VIEW)) {
+ bindings |= PIPE_BIND_SAMPLER_VIEW;
+ }
+ }
+
if (bindings & PIPE_BIND_SAMPLER_VIEW) {
tex->key.flags |= SVGA3D_SURFACE_HINT_TEXTURE;
tex->key.flags |= SVGA3D_SURFACE_BIND_SHADER_RESOURCE;
tex->key.format = svga_translate_format(svgascreen, template->format,
bindings);
if (tex->key.format == SVGA3D_FORMAT_INVALID) {
- FREE(tex->defined);
- FREE(tex->rendered_to);
- FREE(tex);
- return NULL;
+ goto fail;
}
- /* Use typeless formats for sRGB and depth resources. Typeless
+ /* The actual allocation is done with a typeless format. Typeless
* formats can be reinterpreted as other formats. For example,
* SVGA3D_R8G8B8A8_UNORM_TYPELESS can be interpreted as
* SVGA3D_R8G8B8A8_UNORM_SRGB or SVGA3D_R8G8B8A8_UNORM.
+ * Do not use typeless formats for SHARED, DISPLAY_TARGET or SCANOUT
+ * buffers.
*/
- if (svgascreen->sws->have_vgpu10 &&
- (util_format_is_srgb(template->format) ||
- format_has_depth(template->format))) {
+ if (svgascreen->sws->have_vgpu10
+ && ((bindings & (PIPE_BIND_SHARED |
+ PIPE_BIND_DISPLAY_TARGET |
+ PIPE_BIND_SCANOUT)) == 0)) {
SVGA3dSurfaceFormat typeless = svga_typeless_format(tex->key.format);
if (0) {
debug_printf("Convert resource type %s -> %s (bind 0x%x)\n",
svga_format_name(typeless),
bindings);
}
+
+ if (svga_format_is_uncompressed_snorm(tex->key.format)) {
+ /* We can't normally render to snorm surfaces, but once we
+ * substitute a typeless format, we can if the rendertarget view
+ * is unorm. This can happen with GL_ARB_copy_image.
+ */
+ tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET;
+ tex->key.flags |= SVGA3D_SURFACE_BIND_RENDER_TARGET;
+ }
+
tex->key.format = typeless;
}
tex->handle = svga_screen_surface_create(svgascreen, bindings,
tex->b.b.usage, &tex->key);
if (!tex->handle) {
- FREE(tex->defined);
- FREE(tex->rendered_to);
- FREE(tex);
- return NULL;
+ goto fail;
}
SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture)\n", tex->handle);
svgascreen->hud.total_resource_bytes += tex->size;
svgascreen->hud.num_resources++;
+ SVGA_STATS_TIME_POP(svgascreen->sws);
+
return &tex->b.b;
+
+fail:
+ if (tex->dirty)
+ FREE(tex->dirty);
+ if (tex->rendered_to)
+ FREE(tex->rendered_to);
+ if (tex->defined)
+ FREE(tex->defined);
+ FREE(tex);
+fail_notex:
+ SVGA_STATS_TIME_POP(svgascreen->sws);
+ return NULL;
}
tex->handle = srf;
tex->rendered_to = CALLOC(1, sizeof(tex->rendered_to[0]));
+ if (!tex->rendered_to)
+ goto fail;
+
+ tex->dirty = CALLOC(1, sizeof(tex->dirty[0]));
+ if (!tex->dirty)
+ goto fail;
+
tex->imported = TRUE;
ss->hud.num_resources++;
return &tex->b.b;
+
+fail:
+ if (tex->defined)
+ FREE(tex->defined);
+ if (tex->rendered_to)
+ FREE(tex->rendered_to);
+ if (tex->dirty)
+ FREE(tex->dirty);
+ FREE(tex);
+ return NULL;
}
boolean
return FALSE;
sv = svga_pipe_sampler_view(psv);
- svga_validate_pipe_sampler_view(svga, sv);
+ ret = svga_validate_pipe_sampler_view(svga, sv);
+ if (ret != PIPE_OK) {
+ svga_context_flush(svga, NULL);
+ ret = svga_validate_pipe_sampler_view(svga, sv);
+ assert(ret == PIPE_OK);
+ }
ret = SVGA3D_vgpu10_GenMips(svga->swc, sv->id, tex->handle);
if (ret != PIPE_OK) {