virgl_encode.h revision b8e80941
11.42Sthorpej/*
21.1Smanu * Copyright 2014, 2015 Red Hat.
31.1Smanu *
41.41Sthorpej * Permission is hereby granted, free of charge, to any person obtaining a
51.1Smanu * copy of this software and associated documentation files (the "Software"),
61.1Smanu * to deal in the Software without restriction, including without limitation
71.1Smanu * on the rights to use, copy, modify, merge, publish, distribute, sub
81.41Sthorpej * license, and/or sell copies of the Software, and to permit persons to whom
91.1Smanu * the Software is furnished to do so, subject to the following conditions:
101.1Smanu *
111.1Smanu * The above copyright notice and this permission notice (including the next
121.1Smanu * paragraph) shall be included in all copies or substantial portions of the
131.1Smanu * Software.
141.1Smanu *
151.1Smanu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161.1Smanu * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171.1Smanu * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
181.1Smanu * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
191.1Smanu * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
201.1Smanu * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
211.1Smanu * USE OR OTHER DEALINGS IN THE SOFTWARE.
221.1Smanu */
231.1Smanu#ifndef VIRGL_ENCODE_H
241.1Smanu#define VIRGL_ENCODE_H
251.1Smanu
261.1Smanu#include "pipe/p_defines.h"
271.1Smanu#include "pipe/p_state.h"
281.1Smanu
291.1Smanu#include "virgl_winsys.h"
301.1Smanu
311.4Slukemstruct tgsi_token;
321.4Slukem
331.42Sthorpejstruct virgl_context;
341.1Smanustruct virgl_resource;
351.1Smanustruct virgl_screen;
361.1Smanustruct virgl_transfer;
371.18Sdslstruct virgl_sampler_view;
381.1Smanu
391.1Smanustruct virgl_surface {
401.1Smanu   struct pipe_surface base;
411.1Smanu   uint32_t handle;
421.42Sthorpej};
431.1Smanu
441.25Stsutsuistruct virgl_indexbuf {
451.1Smanu   unsigned offset;
461.11Sfvdl   unsigned index_size;  /**< size of an index, in bytes */
471.11Sfvdl   struct pipe_resource *buffer; /**< the actual buffer */
481.1Smanu   const void *user_buffer;  /**< pointer to a user buffer if buffer == NULL */
491.1Smanu};
501.42Sthorpej
511.42Sthorpejstatic inline struct virgl_surface *virgl_surface(struct pipe_surface *surf)
521.1Smanu{
531.41Sthorpej   return (struct virgl_surface *)surf;
541.12Smanu}
551.11Sfvdl
561.19Snjolystatic inline void virgl_encoder_write_dword(struct virgl_cmd_buf *state,
571.19Snjoly                                            uint32_t dword)
581.1Smanu{
591.1Smanu   state->buf[state->cdw++] = dword;
601.1Smanu}
611.11Sfvdl
621.11Sfvdlstatic inline void virgl_encoder_write_qword(struct virgl_cmd_buf *state,
631.41Sthorpej                                            uint64_t qword)
641.41Sthorpej{
651.2Smanu   memcpy(state->buf + state->cdw, &qword, sizeof(uint64_t));
661.1Smanu   state->cdw += 2;
671.1Smanu}
681.1Smanu
691.9Sperrystatic inline void virgl_encoder_write_block(struct virgl_cmd_buf *state,
701.1Smanu                                            const uint8_t *ptr, uint32_t len)
711.1Smanu{
721.11Sfvdl   int x;
731.22Sdsl   memcpy(state->buf + state->cdw, ptr, len);
741.1Smanu   x = (len % 4);
751.22Sdsl   if (x) {
761.28Schristos      uint8_t *mp = (uint8_t *)(state->buf + state->cdw);
771.1Smanu      mp += len;
781.22Sdsl      memset(mp, 0, x);
791.1Smanu   }
801.1Smanu   state->cdw += (len + 3) / 4;
811.1Smanu}
821.28Schristos
831.9Sperryextern int virgl_encode_blend_state(struct virgl_context *ctx,
841.1Smanu                                   uint32_t handle,
851.1Smanu                                   const struct pipe_blend_state *blend_state);
861.1Smanuextern int virgl_encode_rasterizer_state(struct virgl_context *ctx,
871.1Smanu                                         uint32_t handle,
881.1Smanu                                         const struct pipe_rasterizer_state *state);
891.9Sperry
901.1Smanuextern int virgl_encode_shader_state(struct virgl_context *ctx,
911.9Sperry                                     uint32_t handle,
921.1Smanu                                     uint32_t type,
931.1Smanu                                     const struct pipe_stream_output_info *so_info,
941.1Smanu                                     uint32_t cs_req_local_mem,
951.1Smanu                                     const struct tgsi_token *tokens);
961.11Sfvdl
971.22Sdslint virgl_encode_stream_output_info(struct virgl_context *ctx,
981.1Smanu                                   uint32_t handle,
991.22Sdsl                                   uint32_t type,
1001.28Schristos                                   const struct pipe_shader_state *shader);
1011.1Smanu
1021.22Sdslint virgl_encoder_set_so_targets(struct virgl_context *ctx,
1031.1Smanu                                unsigned num_targets,
1041.1Smanu                                struct pipe_stream_output_target **targets,
1051.1Smanu                                unsigned append_bitmask);
1061.28Schristos
1071.9Sperryint virgl_encoder_create_so_target(struct virgl_context *ctx,
1081.1Smanu                                  uint32_t handle,
1091.1Smanu                                  struct virgl_resource *res,
1101.1Smanu                                  unsigned buffer_offset,
1111.1Smanu                                  unsigned buffer_size);
1121.39Sriastrad
1131.39Sriastradint virgl_encode_clear(struct virgl_context *ctx,
1141.39Sriastrad                      unsigned buffers,
1151.1Smanu                      const union pipe_color_union *color,
1161.9Sperry                      double depth, unsigned stencil);
1171.1Smanu
1181.17Sdslint virgl_encode_bind_object(struct virgl_context *ctx,
1191.1Smanu                            uint32_t handle, uint32_t object);
1201.1Smanuint virgl_encode_delete_object(struct virgl_context *ctx,
1211.1Smanu                              uint32_t handle, uint32_t object);
1221.2Smanu
1231.27Snjolyint virgl_encoder_set_framebuffer_state(struct virgl_context *ctx,
1241.41Sthorpej                                       const struct pipe_framebuffer_state *state);
1251.11Sfvdlint virgl_encoder_set_viewport_states(struct virgl_context *ctx,
1261.40Sriastrad                                      int start_slot,
1271.11Sfvdl                                      int num_viewports,
1281.11Sfvdl                                      const struct pipe_viewport_state *states);
1291.11Sfvdl
1301.11Sfvdlint virgl_encoder_draw_vbo(struct virgl_context *ctx,
1311.27Snjoly                          const struct pipe_draw_info *info);
1321.41Sthorpej
1331.11Sfvdl
1341.40Sriastradint virgl_encoder_create_surface(struct virgl_context *ctx,
1351.11Sfvdl                                uint32_t handle,
1361.11Sfvdl                                struct virgl_resource *res,
1371.11Sfvdl                                const struct pipe_surface *templat);
1381.11Sfvdl
1391.41Sthorpejint virgl_encoder_flush_frontbuffer(struct virgl_context *ctx,
1401.41Sthorpej                                   struct virgl_resource *res);
1411.41Sthorpej
1421.41Sthorpejint virgl_encoder_create_vertex_elements(struct virgl_context *ctx,
1431.41Sthorpej                                        uint32_t handle,
1441.41Sthorpej                                        unsigned num_elements,
1451.41Sthorpej                                        const struct pipe_vertex_element *element);
1461.41Sthorpej
1471.41Sthorpejint virgl_encoder_set_vertex_buffers(struct virgl_context *ctx,
1481.41Sthorpej                                    unsigned num_buffers,
1491.41Sthorpej                                    const struct pipe_vertex_buffer *buffers);
1501.41Sthorpej
1511.41Sthorpej
1521.41Sthorpejint virgl_encoder_inline_write(struct virgl_context *ctx,
1531.41Sthorpej                              struct virgl_resource *res,
1541.41Sthorpej                              unsigned level, unsigned usage,
1551.41Sthorpej                              const struct pipe_box *box,
1561.41Sthorpej                              const void *data, unsigned stride,
1571.23Snjoly                              unsigned layer_stride);
1581.26Snjolyint virgl_encode_sampler_state(struct virgl_context *ctx,
1591.26Snjoly                              uint32_t handle,
1601.26Snjoly                              const struct pipe_sampler_state *state);
1611.26Snjolyint virgl_encode_sampler_view(struct virgl_context *ctx,
1621.26Snjoly                             uint32_t handle,
1631.26Snjoly                             struct virgl_resource *res,
1641.26Snjoly                             const struct pipe_sampler_view *state);
1651.26Snjoly
1661.26Snjolyint virgl_encode_set_sampler_views(struct virgl_context *ctx,
1671.26Snjoly                                  uint32_t shader_type,
1681.26Snjoly                                  uint32_t start_slot,
1691.26Snjoly                                  uint32_t num_views,
1701.26Snjoly                                  struct virgl_sampler_view **views);
1711.26Snjoly
1721.26Snjolyint virgl_encode_bind_sampler_states(struct virgl_context *ctx,
1731.26Snjoly                                    uint32_t shader_type,
1741.36Schristos                                    uint32_t start_slot,
1751.36Schristos                                    uint32_t num_handles,
1761.26Snjoly                                    uint32_t *handles);
1771.26Snjoly
1781.26Snjolyint virgl_encoder_set_index_buffer(struct virgl_context *ctx,
1791.26Snjoly                                  const struct virgl_indexbuf *ib);
1801.26Snjoly
1811.26Snjolyuint32_t virgl_object_assign_handle(void);
1821.26Snjoly
1831.26Snjolyint virgl_encoder_write_constant_buffer(struct virgl_context *ctx,
1841.26Snjoly                                       uint32_t shader,
1851.11Sfvdl                                       uint32_t index,
1861.11Sfvdl                                       uint32_t size,
1871.11Sfvdl                                       const void *data);
1881.11Sfvdl
1891.11Sfvdlint virgl_encoder_set_uniform_buffer(struct virgl_context *ctx,
1901.11Sfvdl                                     uint32_t shader,
1911.11Sfvdl                                     uint32_t index,
1921.11Sfvdl                                     uint32_t offset,
1931.11Sfvdl                                     uint32_t length,
1941.11Sfvdl                                     struct virgl_resource *res);
1951.41Sthorpejint virgl_encode_dsa_state(struct virgl_context *ctx,
1961.41Sthorpej                          uint32_t handle,
1971.11Sfvdl                          const struct pipe_depth_stencil_alpha_state *dsa_state);
1981.41Sthorpej
1991.41Sthorpejint virgl_encoder_set_stencil_ref(struct virgl_context *ctx,
2001.41Sthorpej                                 const struct pipe_stencil_ref *ref);
2011.41Sthorpej
2021.41Sthorpejint virgl_encoder_set_blend_color(struct virgl_context *ctx,
2031.41Sthorpej                                 const struct pipe_blend_color *color);
2041.41Sthorpej
2051.41Sthorpejint virgl_encoder_set_scissor_state(struct virgl_context *ctx,
2061.41Sthorpej                                    unsigned start_slot,
2071.29Snjoly                                    int num_scissors,
2081.41Sthorpej                                    const struct pipe_scissor_state *ss);
2091.11Sfvdl
2101.11Sfvdlvoid virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,
2111.11Sfvdl                                      const struct pipe_poly_stipple *ps);
2121.11Sfvdl
2131.11Sfvdlvoid virgl_encoder_set_sample_mask(struct virgl_context *ctx,
2141.11Sfvdl                                  unsigned sample_mask);
2151.22Sdsl
2161.11Sfvdlvoid virgl_encoder_set_min_samples(struct virgl_context *ctx,
2171.22Sdsl                                  unsigned min_samples);
2181.11Sfvdl
2191.11Sfvdlvoid virgl_encoder_set_clip_state(struct virgl_context *ctx,
2201.22Sdsl                                 const struct pipe_clip_state *clip);
2211.32Snjoly
2221.32Snjolyint virgl_encode_resource_copy_region(struct virgl_context *ctx,
2231.18Sdsl                                     struct virgl_resource *dst_res,
2241.11Sfvdl                                     unsigned dst_level,
2251.11Sfvdl                                     unsigned dstx, unsigned dsty, unsigned dstz,
2261.32Snjoly                                     struct virgl_resource *src_res,
2271.32Snjoly                                     unsigned src_level,
2281.32Snjoly                                     const struct pipe_box *src_box);
2291.32Snjoly
2301.32Snjolyint virgl_encode_blit(struct virgl_context *ctx,
2311.32Snjoly                     struct virgl_resource *dst_res,
2321.32Snjoly                     struct virgl_resource *src_res,
2331.11Sfvdl                     const struct pipe_blit_info *blit);
2341.11Sfvdl
2351.11Sfvdlint virgl_encoder_create_query(struct virgl_context *ctx,
2361.11Sfvdl                              uint32_t handle,
2371.11Sfvdl                              uint query_type,
2381.11Sfvdl                              uint query_index,
2391.22Sdsl                              struct virgl_resource *res,
2401.11Sfvdl                              uint32_t offset);
2411.22Sdsl
2421.11Sfvdlint virgl_encoder_begin_query(struct virgl_context *ctx,
2431.11Sfvdl                             uint32_t handle);
2441.22Sdslint virgl_encoder_end_query(struct virgl_context *ctx,
2451.18Sdsl                           uint32_t handle);
2461.11Sfvdlint virgl_encoder_get_query_result(struct virgl_context *ctx,
2471.30Snjoly                                  uint32_t handle, boolean wait);
2481.11Sfvdl
2491.11Sfvdlint virgl_encoder_render_condition(struct virgl_context *ctx,
2501.30Snjoly                                  uint32_t handle, boolean condition,
2511.30Snjoly                                  enum pipe_render_cond_flag mode);
2521.30Snjoly
2531.11Sfvdlint virgl_encoder_set_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
2541.11Sfvdlint virgl_encoder_create_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
2551.11Sfvdlint virgl_encoder_destroy_sub_ctx(struct virgl_context *ctx, uint32_t sub_ctx_id);
2561.11Sfvdl
2571.11Sfvdlint virgl_encode_bind_shader(struct virgl_context *ctx,
2581.11Sfvdl                             uint32_t handle, uint32_t type);
2591.11Sfvdl
2601.30Snjolyint virgl_encode_set_tess_state(struct virgl_context *ctx,
2611.11Sfvdl                                const float outer[4],
2621.11Sfvdl                                const float inner[2]);
2631.11Sfvdl
2641.22Sdslint virgl_encode_set_shader_buffers(struct virgl_context *ctx,
2651.11Sfvdl                                    enum pipe_shader_type shader,
2661.22Sdsl                                    unsigned start_slot, unsigned count,
2671.11Sfvdl                                    const struct pipe_shader_buffer *buffers);
2681.11Sfvdlint virgl_encode_set_shader_images(struct virgl_context *ctx,
2691.22Sdsl                                   enum pipe_shader_type shader,
2701.18Sdsl                                   unsigned start_slot, unsigned count,
2711.11Sfvdl                                   const struct pipe_image_view *images);
2721.11Sfvdlint virgl_encode_set_hw_atomic_buffers(struct virgl_context *ctx,
2731.14Schristos                                       unsigned start_slot, unsigned count,
2741.11Sfvdl                                       const struct pipe_shader_buffer *buffers);
2751.11Sfvdlint virgl_encode_memory_barrier(struct virgl_context *ctx,
2761.18Sdsl                                unsigned flags);
2771.11Sfvdlint virgl_encode_launch_grid(struct virgl_context *ctx,
2781.11Sfvdl                             const struct pipe_grid_info *grid_info);
2791.31Snjolyint virgl_encode_texture_barrier(struct virgl_context *ctx,
2801.31Snjoly                                 unsigned flags);
2811.31Snjoly
2821.31Snjolyint virgl_encode_host_debug_flagstring(struct virgl_context *ctx,
2831.18Sdsl                                  const char *envname);
2841.18Sdsl
2851.11Sfvdlint virgl_encode_get_query_result_qbo(struct virgl_context *ctx,
2861.11Sfvdl                                      uint32_t handle,
2871.11Sfvdl                                      struct virgl_resource *res, boolean wait,
2881.22Sdsl                                      uint32_t result_type,
2891.11Sfvdl                                      uint32_t offset,
2901.22Sdsl                                      uint32_t index);
2911.11Sfvdl
2921.11Sfvdlvoid virgl_encode_transfer(struct virgl_screen *vs, struct virgl_cmd_buf *buf,
2931.11Sfvdl                           struct virgl_transfer *trans, uint32_t direction);
2941.11Sfvdl
2951.22Sdslvoid virgl_encode_end_transfers(struct virgl_cmd_buf *buf);
2961.11Sfvdl#endif
2971.11Sfvdl