virgl: ARB_query_buffer_object support
authorDave Airlie <airlied@redhat.com>
Mon, 21 May 2018 23:32:42 +0000 (09:32 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 31 Jan 2019 01:23:38 +0000 (11:23 +1000)
v1.1: fix size define.

Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
src/gallium/drivers/virgl/virgl_encode.c
src/gallium/drivers/virgl/virgl_encode.h
src/gallium/drivers/virgl/virgl_hw.h
src/gallium/drivers/virgl/virgl_protocol.h
src/gallium/drivers/virgl/virgl_query.c
src/gallium/drivers/virgl/virgl_resource.h
src/gallium/drivers/virgl/virgl_screen.c

index 403f54e2842c5c6c590ca66fc268dd3b5788a499..5b8575699dcc1614c5f19c0f27bbdda7804be355 100644 (file)
@@ -1075,6 +1075,22 @@ int virgl_encode_host_debug_flagstring(struct virgl_context *ctx,
 
    virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_SET_DEBUG_FLAGS, 0, sslen));
    virgl_encoder_write_block(ctx->cbuf, (const uint8_t *)flagstring, string_length);
+   return 0;
+}
 
+int virgl_encode_get_query_result_qbo(struct virgl_context *ctx,
+                                      uint32_t handle,
+                                      struct virgl_resource *res, boolean wait,
+                                      uint32_t result_type,
+                                      uint32_t offset,
+                                      uint32_t index)
+{
+   virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_GET_QUERY_RESULT_QBO, 0, VIRGL_QUERY_RESULT_QBO_SIZE));
+   virgl_encoder_write_dword(ctx->cbuf, handle);
+   virgl_encoder_write_res(ctx, res);
+   virgl_encoder_write_dword(ctx->cbuf, wait ? 1 : 0);
+   virgl_encoder_write_dword(ctx->cbuf, result_type);
+   virgl_encoder_write_dword(ctx->cbuf, offset);
+   virgl_encoder_write_dword(ctx->cbuf, index);
    return 0;
 }
index f3729e8e92000ceb3eb787b59d3986a3bce64ed7..70fae1db4e5d4d248c6fd28e675fdf2d8e7fdf53 100644 (file)
@@ -279,4 +279,12 @@ int virgl_encode_texture_barrier(struct virgl_context *ctx,
 
 int virgl_encode_host_debug_flagstring(struct virgl_context *ctx,
                                   const char *envname);
+
+int virgl_encode_get_query_result_qbo(struct virgl_context *ctx,
+                                      uint32_t handle,
+                                      struct virgl_resource *res, boolean wait,
+                                      uint32_t result_type,
+                                      uint32_t offset,
+                                      uint32_t index);
+
 #endif
index 7b4c063f35356a1381c78bcb10a77b9ff151a41a..8759e577077c9a84b1d06d9e0c68f511d4c31c8e 100644 (file)
@@ -233,6 +233,7 @@ enum virgl_formats {
 #define VIRGL_CAP_TGSI_COMPONENTS      (1 << 13)
 #define VIRGL_CAP_GUEST_MAY_INIT_LOG   (1 << 14)
 #define VIRGL_CAP_SRGB_WRITE_CONTROL   (1 << 15)
+#define VIRGL_CAP_QBO                  (1 << 16)
 
 /* virgl bind flags - these are compatible with mesa 10.5 gallium.
  * but are fixed, no other should be passed to virgl either.
@@ -246,6 +247,7 @@ enum virgl_formats {
 #define VIRGL_BIND_DISPLAY_TARGET (1 << 7)
 #define VIRGL_BIND_STREAM_OUTPUT (1 << 11)
 #define VIRGL_BIND_SHADER_BUFFER (1 << 14)
+#define VIRGL_BIND_QUERY_BUFFER  (1 << 15)
 #define VIRGL_BIND_CURSOR        (1 << 16)
 #define VIRGL_BIND_CUSTOM        (1 << 17)
 #define VIRGL_BIND_SCANOUT       (1 << 18)
index 7c9ea9f7254a94e01c7392cedcd5be9790db13c1..57333553d77122065b6c7a0c183005e009514a5e 100644 (file)
@@ -93,6 +93,7 @@ enum virgl_context_cmd {
    VIRGL_CCMD_TEXTURE_BARRIER,
    VIRGL_CCMD_SET_ATOMIC_BUFFERS,
    VIRGL_CCMD_SET_DEBUG_FLAGS,
+   VIRGL_CCMD_GET_QUERY_RESULT_QBO,
 };
 
 /*
@@ -448,6 +449,7 @@ enum virgl_context_cmd {
 
 #define VIRGL_QUERY_END_HANDLE 1
 
+#define VIRGL_QUERY_RESULT_SIZE 2
 #define VIRGL_QUERY_RESULT_HANDLE 1
 #define VIRGL_QUERY_RESULT_WAIT 2
 
@@ -554,4 +556,13 @@ enum virgl_context_cmd {
 #define VIRGL_SET_ATOMIC_BUFFER_LENGTH(x) ((x) * VIRGL_SET_ATOMIC_BUFFER_ELEMENT_SIZE + 3)
 #define VIRGL_SET_ATOMIC_BUFFER_RES_HANDLE(x) ((x) * VIRGL_SET_ATOMIC_BUFFER_ELEMENT_SIZE + 4)
 
+/* qbo */
+#define VIRGL_QUERY_RESULT_QBO_SIZE 6
+#define VIRGL_QUERY_RESULT_QBO_HANDLE 1
+#define VIRGL_QUERY_RESULT_QBO_QBO_HANDLE 2
+#define VIRGL_QUERY_RESULT_QBO_WAIT 3
+#define VIRGL_QUERY_RESULT_QBO_RESULT_TYPE 4
+#define VIRGL_QUERY_RESULT_QBO_OFFSET 5
+#define VIRGL_QUERY_RESULT_QBO_INDEX 6
+
 #endif
index a75b29c7c9b86856bbabfa9ab985fb84f55e744c..23e24c53b020927852d1d8ea4da30d40395a1c09 100644 (file)
@@ -205,6 +205,22 @@ virgl_set_active_query_state(struct pipe_context *pipe, boolean enable)
 {
 }
 
+static void
+virgl_get_query_result_resource(struct pipe_context *ctx,
+                                struct pipe_query *q,
+                                boolean wait,
+                                enum pipe_query_value_type result_type,
+                                int index,
+                                struct pipe_resource *resource,
+                                unsigned offset)
+{
+   struct virgl_context *vctx = virgl_context(ctx);
+   struct virgl_query *query = virgl_query(q);
+   struct virgl_resource *qbo = (struct virgl_resource *)resource;
+
+   virgl_encode_get_query_result_qbo(vctx, query->handle, qbo, wait, result_type, offset, index);
+}
+
 void virgl_init_query_functions(struct virgl_context *vctx)
 {
    vctx->base.render_condition = virgl_render_condition;
@@ -214,4 +230,5 @@ void virgl_init_query_functions(struct virgl_context *vctx)
    vctx->base.end_query = virgl_end_query;
    vctx->base.get_query_result = virgl_get_query_result;
    vctx->base.set_active_query_state = virgl_set_active_query_state;
+   vctx->base.get_query_result_resource = virgl_get_query_result_resource;
 }
index e211fb881b19168df209288ab01c478e421ce19c..1dc789c456016765e72c835509749c2de5d9147a 100644 (file)
@@ -106,6 +106,8 @@ static inline unsigned pipe_to_virgl_bind(unsigned pbind)
       outbind |= VIRGL_BIND_SCANOUT;
    if (pbind & PIPE_BIND_SHADER_BUFFER)
       outbind |= VIRGL_BIND_SHADER_BUFFER;
+   if (pbind & PIPE_BIND_QUERY_BUFFER)
+     outbind |= VIRGL_BIND_QUERY_BUFFER;
    return outbind;
 }
 
index 9a8d0e648482270d547ba68c98761607a39bbe56..72afd4d95f0b35a04d62173fed9e6e42e47a4e5e 100644 (file)
@@ -258,6 +258,8 @@ virgl_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
    case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
       return 1; /* TODO: need to introduce a hw-cap for this */
+   case PIPE_CAP_QUERY_BUFFER_OBJECT:
+      return vscreen->caps.caps.v2.capability_bits & VIRGL_CAP_QBO;
    case PIPE_CAP_TEXTURE_GATHER_SM5:
    case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
    case PIPE_CAP_FAKE_SW_MSAA:
@@ -280,7 +282,6 @@ virgl_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_INVALIDATE_BUFFER:
    case PIPE_CAP_GENERATE_MIPMAP:
    case PIPE_CAP_SURFACE_REINTERPRET_BLOCKS:
-   case PIPE_CAP_QUERY_BUFFER_OBJECT:
    case PIPE_CAP_STRING_MARKER:
    case PIPE_CAP_QUERY_MEMORY_INFO:
    case PIPE_CAP_PCI_GROUP: