#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "os/os_thread.h"
-#include "os/os_time.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_resource.h"
struct svga_screen *ss = svga_screen(pipe->screen);
struct svga_buffer *sbuf = svga_buffer(resource);
struct pipe_transfer *transfer;
- uint8_t *map;
- int64_t begin = os_time_get();
+ uint8_t *map = NULL;
+ int64_t begin = svga_get_time(svga);
+
+ SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_BUFFERTRANSFERMAP);
assert(box->y == 0);
assert(box->z == 0);
assert(box->height == 1);
assert(box->depth == 1);
- transfer = CALLOC_STRUCT(pipe_transfer);
+ transfer = MALLOC_STRUCT(pipe_transfer);
if (!transfer) {
- return NULL;
+ goto done;
}
transfer->resource = resource;
transfer->level = level;
transfer->usage = usage;
transfer->box = *box;
+ transfer->stride = 0;
+ transfer->layer_stride = 0;
+
+ if (usage & PIPE_TRANSFER_WRITE) {
+ /* If we write to the buffer for any reason, free any saved translated
+ * vertices.
+ */
+ pipe_resource_reference(&sbuf->translated_indices.buffer, NULL);
+ }
if ((usage & PIPE_TRANSFER_READ) && sbuf->dirty) {
- /* Only need to test for vgpu10 since only vgpu10 features (streamout,
- * buffer copy) can modify buffers on the device.
+ enum pipe_error ret;
+
+ /* Host-side buffers can only be dirtied with vgpu10 features
+ * (streamout and buffer copy).
*/
- if (svga_have_vgpu10(svga)) {
- enum pipe_error ret;
- assert(sbuf->handle);
- ret = SVGA3D_vgpu10_ReadbackSubResource(svga->swc, sbuf->handle, 0);
- if (ret != PIPE_OK) {
- svga_context_flush(svga, NULL);
- ret = SVGA3D_vgpu10_ReadbackSubResource(svga->swc, sbuf->handle, 0);
- assert(ret == PIPE_OK);
- }
+ assert(svga_have_vgpu10(svga));
+
+ if (!sbuf->user) {
+ (void) svga_buffer_handle(svga, resource);
+ }
+ if (sbuf->dma.pending > 0) {
+ svga_buffer_upload_flush(svga, sbuf);
svga_context_finish(svga);
+ }
+
+ assert(sbuf->handle);
- sbuf->dirty = FALSE;
+ ret = SVGA3D_vgpu10_ReadbackSubResource(svga->swc, sbuf->handle, 0);
+ if (ret != PIPE_OK) {
+ svga_context_flush(svga, NULL);
+ ret = SVGA3D_vgpu10_ReadbackSubResource(svga->swc, sbuf->handle, 0);
+ assert(ret == PIPE_OK);
}
+
+ svga->hud.num_readbacks++;
+
+ svga_context_finish(svga);
+
+ sbuf->dirty = FALSE;
}
if (usage & PIPE_TRANSFER_WRITE) {
*/
FREE(transfer);
- return NULL;
+ goto done;
}
svga_context_flush(svga, NULL);
sbuf->swbuf = align_malloc(sbuf->b.b.width0, 16);
if (!sbuf->swbuf) {
FREE(transfer);
- return NULL;
+ goto done;
}
}
}
FREE(transfer);
}
- svga->hud.map_buffer_time += (os_time_get() - begin);
+ svga->hud.map_buffer_time += (svga_get_time(svga) - begin);
+done:
+ SVGA_STATS_TIME_POP(svga_sws(svga));
return map;
}
assert(transfer->usage & PIPE_TRANSFER_WRITE);
assert(transfer->usage & PIPE_TRANSFER_FLUSH_EXPLICIT);
- pipe_mutex_lock(ss->swc_mutex);
+ mtx_lock(&ss->swc_mutex);
svga_buffer_add_range(sbuf, offset, offset + length);
pipe_mutex_unlock(ss->swc_mutex);
}
struct svga_context *svga = svga_context(pipe);
struct svga_buffer *sbuf = svga_buffer(transfer->resource);
- pipe_mutex_lock(ss->swc_mutex);
+ SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_BUFFERTRANSFERUNMAP);
+
+ mtx_lock(&ss->swc_mutex);
assert(sbuf->map.count);
if (sbuf->map.count) {
pipe_mutex_unlock(ss->swc_mutex);
FREE(transfer);
+ SVGA_STATS_TIME_POP(svga_sws(svga));
}
if (sbuf->swbuf && !sbuf->user)
align_free(sbuf->swbuf);
+ pipe_resource_reference(&sbuf->translated_indices.buffer, NULL);
+
ss->hud.total_resource_bytes -= sbuf->size;
assert(ss->hud.num_resources > 0);
if (ss->hud.num_resources > 0)
svga_buffer_transfer_map, /* transfer_map */
svga_buffer_transfer_flush_region, /* transfer_flush_region */
svga_buffer_transfer_unmap, /* transfer_unmap */
- u_default_transfer_inline_write /* transfer_inline_write */
};
struct svga_screen *ss = svga_screen(screen);
struct svga_buffer *sbuf;
+ SVGA_STATS_TIME_PUSH(ss->sws, SVGA_STATS_TIME_CREATEBUFFER);
+
sbuf = CALLOC_STRUCT(svga_buffer);
if (!sbuf)
goto error1;
ss->hud.total_resource_bytes += sbuf->size;
ss->hud.num_resources++;
+ SVGA_STATS_TIME_POP(ss->sws);
return &sbuf->b.b;
error2:
FREE(sbuf);
error1:
+ SVGA_STATS_TIME_POP(ss->sws);
return NULL;
}