virgl: implement ARB_clear_texture
[mesa.git] / src / gallium / drivers / virgl / virgl_encode.c
index c255a1c12e46ac731d75c1566fa5fe7bed83e8be..292cc2bb0d6e8b4fdfbc11eb8f3e34c0b69a6b96 100644 (file)
@@ -579,6 +579,38 @@ int virgl_encode_clear(struct virgl_context *ctx,
    return 0;
 }
 
+int virgl_encode_clear_texture(struct virgl_context *ctx,
+                               struct virgl_resource *res,
+                               unsigned int level,
+                               const struct pipe_box *box,
+                               const void *data)
+{
+   const struct util_format_description *desc = util_format_description(res->u.b.format);
+   unsigned block_bits = desc->block.bits;
+   uint32_t arr[4] = {0};
+   /* The spec describe <data> as a pointer to an array of between one
+    * and four components of texel data that will be used as the source
+    * for the constant fill value.
+    * Here, we are just copying the memory into <arr>. We do not try to
+    * re-create the data array. The host part will take care of interpreting
+    * the memory and applying the correct format to the clear call.
+    */
+   memcpy(&arr, data, block_bits / 8);
+
+   virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_CLEAR_TEXTURE, 0, VIRGL_CLEAR_TEXTURE_SIZE));
+   virgl_encoder_write_res(ctx, res);
+   virgl_encoder_write_dword(ctx->cbuf, level);
+   virgl_encoder_write_dword(ctx->cbuf, box->x);
+   virgl_encoder_write_dword(ctx->cbuf, box->y);
+   virgl_encoder_write_dword(ctx->cbuf, box->z);
+   virgl_encoder_write_dword(ctx->cbuf, box->width);
+   virgl_encoder_write_dword(ctx->cbuf, box->height);
+   virgl_encoder_write_dword(ctx->cbuf, box->depth);
+   for (unsigned i = 0; i < 4; i++)
+      virgl_encoder_write_dword(ctx->cbuf, arr[i]);
+   return 0;
+}
+
 int virgl_encoder_set_framebuffer_state(struct virgl_context *ctx,
                                        const struct pipe_framebuffer_state *state)
 {