radeonsi: move PKT3_WRITE_DATA generation into a helper function
[mesa.git] / src / gallium / drivers / virgl / virgl_streamout.c
index 95420f688d35debe3474fa74e911a70644cba989..0fc3af67959c02880f01aaf971b195c66e4ebedc 100644 (file)
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-#include "util/u_memory.h"
 #include "util/u_inlines.h"
+#include "util/u_memory.h"
 #include "virgl_context.h"
 #include "virgl_encode.h"
+#include "virgl_protocol.h"
 #include "virgl_resource.h"
 
 static struct pipe_stream_output_target *virgl_create_so_target(
@@ -32,8 +33,8 @@ static struct pipe_stream_output_target *virgl_create_so_target(
    unsigned buffer_offset,
    unsigned buffer_size)
 {
-   struct virgl_context *vctx = (struct virgl_context *)ctx;
-   struct virgl_resource *res = (struct virgl_resource *)buffer;
+   struct virgl_context *vctx = virgl_context(ctx);
+   struct virgl_resource *res = virgl_resource(buffer);
    struct virgl_so_target *t = CALLOC_STRUCT(virgl_so_target);
    uint32_t handle;
 
@@ -55,8 +56,8 @@ static struct pipe_stream_output_target *virgl_create_so_target(
 static void virgl_destroy_so_target(struct pipe_context *ctx,
                                    struct pipe_stream_output_target *target)
 {
-   struct virgl_context *vctx = (struct virgl_context *)ctx;
-   struct virgl_so_target *t = (struct virgl_so_target *)target;
+   struct virgl_context *vctx = virgl_context(ctx);
+   struct virgl_so_target *t = virgl_so_target(target);
 
    pipe_resource_reference(&t->base.buffer, NULL);
    virgl_encode_delete_object(vctx, t->handle, VIRGL_OBJECT_STREAMOUT_TARGET);
@@ -68,10 +69,13 @@ static void virgl_set_so_targets(struct pipe_context *ctx,
                                 struct pipe_stream_output_target **targets,
                                 const unsigned *offset)
 {
-   struct virgl_context *vctx = (struct virgl_context *)ctx;
+   struct virgl_context *vctx = virgl_context(ctx);
    int i;
    for (i = 0; i < num_targets; i++) {
-      pipe_resource_reference(&vctx->so_targets[i].base.buffer, targets[i]->buffer);
+      if (targets[i])
+         pipe_resource_reference(&vctx->so_targets[i].base.buffer, targets[i]->buffer);
+      else
+         pipe_resource_reference(&vctx->so_targets[i].base.buffer, NULL);
    }
    for (i = num_targets; i < vctx->num_so_targets; i++)
       pipe_resource_reference(&vctx->so_targets[i].base.buffer, NULL);