renderer: ABI break: overhaul viewport/scissor state

add support for multiple viewports, and reduce
viewport size.
macos/master
Dave Airlie 10 years ago
parent e13ebc57e1
commit 0ff22a06b7
  1. 4
      src/gallium/include/pipe/p_state.h
  2. 1
      src/virgl_hw.h
  3. 24
      src/virgl_protocol.h
  4. 56
      src/vrend_decode.c
  5. 7
      src/vrend_renderer.c
  6. 3
      src/vrend_renderer.h
  7. 19
      tests/testvirgl_encode.c
  8. 2
      tests/testvirgl_encode.h

@ -166,8 +166,8 @@ struct pipe_poly_stipple
struct pipe_viewport_state struct pipe_viewport_state
{ {
float scale[4]; float scale[3];
float translate[4]; float translate[3];
}; };

@ -220,6 +220,7 @@ struct virgl_caps_v1 {
uint32_t prim_mask; uint32_t prim_mask;
uint32_t max_tbo_size; uint32_t max_tbo_size;
uint32_t max_uniform_blocks; uint32_t max_uniform_blocks;
uint32_t max_viewports;
}; };
union virgl_caps { union virgl_caps {

@ -198,15 +198,14 @@ enum virgl_context_cmd {
#define VIRGL_OBJ_SHADER_SO_OUTPUT_DST_OFFSET(x) (((x) & 0xffff) << 16) #define VIRGL_OBJ_SHADER_SO_OUTPUT_DST_OFFSET(x) (((x) & 0xffff) << 16)
/* viewport state */ /* viewport state */
#define VIRGL_SET_VIEWPORT_STATE_SIZE 8 #define VIRGL_SET_VIEWPORT_STATE_SIZE(num_viewports) ((6 * num_viewports) + 1)
#define VIRGL_SET_VIEWPORT_STATE_SCALE_0 1 #define VIRGL_SET_VIEWPORT_START_SLOT 1
#define VIRGL_SET_VIEWPORT_STATE_SCALE_1 2 #define VIRGL_SET_VIEWPORT_STATE_SCALE_0(x) (2 + (x * 6))
#define VIRGL_SET_VIEWPORT_STATE_SCALE_2 3 #define VIRGL_SET_VIEWPORT_STATE_SCALE_1(x) (3 + (x * 6))
#define VIRGL_SET_VIEWPORT_STATE_SCALE_3 4 #define VIRGL_SET_VIEWPORT_STATE_SCALE_2(x) (4 + (x * 6))
#define VIRGL_SET_VIEWPORT_STATE_TRANSLATE_0 5 #define VIRGL_SET_VIEWPORT_STATE_TRANSLATE_0(x) (5 + (x * 6))
#define VIRGL_SET_VIEWPORT_STATE_TRANSLATE_1 6 #define VIRGL_SET_VIEWPORT_STATE_TRANSLATE_1(x) (6 + (x * 6))
#define VIRGL_SET_VIEWPORT_STATE_TRANSLATE_2 7 #define VIRGL_SET_VIEWPORT_STATE_TRANSLATE_2(x) (7 + (x * 6))
#define VIRGL_SET_VIEWPORT_STATE_TRANSLATE_3 8
/* framebuffer state */ /* framebuffer state */
#define VIRGL_SET_FRAMEBUFFER_STATE_SIZE(nr_cbufs) (nr_cbufs + 2) #define VIRGL_SET_FRAMEBUFFER_STATE_SIZE(nr_cbufs) (nr_cbufs + 2)
@ -333,9 +332,10 @@ enum virgl_context_cmd {
#define VIRGL_SET_BLEND_COLOR(x) ((x) + 1) #define VIRGL_SET_BLEND_COLOR(x) ((x) + 1)
/* set scissor state */ /* set scissor state */
#define VIRGL_SET_SCISSOR_STATE_SIZE 2 #define VIRGL_SET_SCISSOR_STATE_SIZE(x) (1 + 2 * x)
#define VIRGL_SET_SCISSOR_MINX_MINY 1 #define VIRGL_SET_SCISSOR_START_SLOT 1
#define VIRGL_SET_SCISSOR_MAXX_MAXY 2 #define VIRGL_SET_SCISSOR_MINX_MINY(x) (2 + (x * 2))
#define VIRGL_SET_SCISSOR_MAXX_MAXY(x) (3 + (x * 3))
/* resource copy region */ /* resource copy region */
#define VIRGL_CMD_RESOURCE_COPY_REGION_SIZE 13 #define VIRGL_CMD_RESOURCE_COPY_REGION_SIZE 13

@ -187,18 +187,28 @@ static float uif(unsigned int ui)
static int vrend_decode_set_viewport_state(struct vrend_decode_ctx *ctx, int length) static int vrend_decode_set_viewport_state(struct vrend_decode_ctx *ctx, int length)
{ {
struct pipe_viewport_state vps; struct pipe_viewport_state vps[PIPE_MAX_VIEWPORTS];
int i; int i, v;
int num_viewports, start_slot;
if (length < 1)
return EINVAL;
if (length != VIRGL_SET_VIEWPORT_STATE_SIZE) if ((length - 1) % 6)
return EINVAL; return EINVAL;
for (i = 0; i < 4; i++) num_viewports = (length - 1) / 6;
vps.scale[i] = uif(get_buf_entry(ctx, VIRGL_SET_VIEWPORT_STATE_SCALE_0 + i)); if (num_viewports > PIPE_MAX_VIEWPORTS)
for (i = 0; i < 4; i++) return EINVAL;
vps.translate[i] = uif(get_buf_entry(ctx, VIRGL_SET_VIEWPORT_STATE_TRANSLATE_0 + i));
start_slot = get_buf_entry(ctx, VIRGL_SET_VIEWPORT_START_SLOT);
for (v = 0; v < num_viewports; v++) {
for (i = 0; i < 3; i++)
vps[v].scale[i] = uif(get_buf_entry(ctx, VIRGL_SET_VIEWPORT_STATE_SCALE_0(v) + i));
for (i = 0; i < 3; i++)
vps[v].translate[i] = uif(get_buf_entry(ctx, VIRGL_SET_VIEWPORT_STATE_TRANSLATE_0(v) + i));
}
vrend_set_viewport_state(ctx->grctx, &vps); vrend_set_viewport_states(ctx->grctx, start_slot, num_viewports, vps);
return 0; return 0;
} }
@ -748,21 +758,33 @@ static int vrend_decode_set_blend_color(struct vrend_decode_ctx *ctx, int length
static int vrend_decode_set_scissor_state(struct vrend_decode_ctx *ctx, int length) static int vrend_decode_set_scissor_state(struct vrend_decode_ctx *ctx, int length)
{ {
struct pipe_scissor_state ss; struct pipe_scissor_state ss[PIPE_MAX_VIEWPORTS];
uint32_t temp; uint32_t temp;
int num_scissor, start_slot;
int s;
if (length < 1)
return EINVAL;
if (length != VIRGL_SET_SCISSOR_STATE_SIZE) if ((length - 1) % 2)
return EINVAL; return EINVAL;
temp = get_buf_entry(ctx, VIRGL_SET_SCISSOR_MINX_MINY); num_scissor = (length - 1) / 2;
ss.minx = temp & 0xffff; if (num_scissor > PIPE_MAX_VIEWPORTS)
ss.miny = (temp >> 16) & 0xffff; return EINVAL;
temp = get_buf_entry(ctx, VIRGL_SET_SCISSOR_MAXX_MAXY); start_slot = get_buf_entry(ctx, VIRGL_SET_SCISSOR_START_SLOT);
ss.maxx = temp & 0xffff;
ss.maxy = (temp >> 16) & 0xffff; for (s = 0; s < num_scissor; s++) {
temp = get_buf_entry(ctx, VIRGL_SET_SCISSOR_MINX_MINY(s));
ss[s].minx = temp & 0xffff;
ss[s].miny = (temp >> 16) & 0xffff;
temp = get_buf_entry(ctx, VIRGL_SET_SCISSOR_MAXX_MAXY(s));
ss[s].maxx = temp & 0xffff;
ss[s].maxy = (temp >> 16) & 0xffff;
}
vrend_set_scissor_state(ctx->grctx, &ss); vrend_set_scissor_state(ctx->grctx, &ss[0]);
return 0; return 0;
} }

@ -1331,7 +1331,9 @@ void vrend_set_framebuffer_state(struct vrend_context *ctx,
* if the viewport Y scale factor is > 0 then we are rendering to * if the viewport Y scale factor is > 0 then we are rendering to
* an FBO already so don't need to invert rendering? * an FBO already so don't need to invert rendering?
*/ */
void vrend_set_viewport_state(struct vrend_context *ctx, void vrend_set_viewport_states(struct vrend_context *ctx,
int start_slots,
int num_viewports,
const struct pipe_viewport_state *state) const struct pipe_viewport_state *state)
{ {
/* convert back to glViewport */ /* convert back to glViewport */
@ -5204,6 +5206,9 @@ void vrend_renderer_fill_caps(uint32_t set, uint32_t version,
caps->v1.max_tbo_size = max; caps->v1.max_tbo_size = max;
} }
/* initial support */
caps->v1.max_viewports = 1;
caps->v1.prim_mask = (1 << PIPE_PRIM_POINTS) | (1 << PIPE_PRIM_LINES) | (1 << PIPE_PRIM_LINE_STRIP) | (1 << PIPE_PRIM_LINE_LOOP) | (1 << PIPE_PRIM_TRIANGLES) | (1 << PIPE_PRIM_TRIANGLE_STRIP) | (1 << PIPE_PRIM_TRIANGLE_FAN); caps->v1.prim_mask = (1 << PIPE_PRIM_POINTS) | (1 << PIPE_PRIM_LINES) | (1 << PIPE_PRIM_LINE_STRIP) | (1 << PIPE_PRIM_LINE_LOOP) | (1 << PIPE_PRIM_TRIANGLES) | (1 << PIPE_PRIM_TRIANGLE_STRIP) | (1 << PIPE_PRIM_TRIANGLE_FAN);
if (use_core_profile == 0) { if (use_core_profile == 0) {
caps->v1.prim_mask |= (1 << PIPE_PRIM_QUADS) | (1 << PIPE_PRIM_QUAD_STRIP) | (1 << PIPE_PRIM_POLYGON); caps->v1.prim_mask |= (1 << PIPE_PRIM_QUADS) | (1 << PIPE_PRIM_QUAD_STRIP) | (1 << PIPE_PRIM_POLYGON);

@ -213,7 +213,8 @@ int vrend_transfer_inline_write(struct vrend_context *ctx,
struct vrend_transfer_info *info, struct vrend_transfer_info *info,
unsigned usage); unsigned usage);
void vrend_set_viewport_state(struct vrend_context *ctx, void vrend_set_viewport_states(struct vrend_context *ctx,
int start_slot, int num_viewports,
const struct pipe_viewport_state *state); const struct pipe_viewport_state *state);
void vrend_set_num_sampler_views(struct vrend_context *ctx, void vrend_set_num_sampler_views(struct vrend_context *ctx,
uint32_t shader_type, uint32_t shader_type,

@ -278,10 +278,11 @@ int virgl_encoder_set_viewport_state(struct virgl_context *ctx,
const struct pipe_viewport_state *state) const struct pipe_viewport_state *state)
{ {
int i; int i;
virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_SET_VIEWPORT_STATE, 0, VIRGL_SET_VIEWPORT_STATE_SIZE)); virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_SET_VIEWPORT_STATE, 0, VIRGL_SET_VIEWPORT_STATE_SIZE(1)));
for (i = 0; i < 4; i++) virgl_encoder_write_dword(ctx->cbuf, 0);
for (i = 0; i < 3; i++)
virgl_encoder_write_dword(ctx->cbuf, fui(state->scale[i])); virgl_encoder_write_dword(ctx->cbuf, fui(state->scale[i]));
for (i = 0; i < 4; i++) for (i = 0; i < 3; i++)
virgl_encoder_write_dword(ctx->cbuf, fui(state->translate[i])); virgl_encoder_write_dword(ctx->cbuf, fui(state->translate[i]));
return 0; return 0;
} }
@ -640,11 +641,17 @@ int virgl_encoder_set_blend_color(struct virgl_context *ctx,
} }
int virgl_encoder_set_scissor_state(struct virgl_context *ctx, int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
int start_slot,
int num_scissors,
const struct pipe_scissor_state *ss) const struct pipe_scissor_state *ss)
{ {
virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_SET_SCISSOR_STATE, 0, VIRGL_SET_SCISSOR_STATE_SIZE)); int s;
virgl_encoder_write_dword(ctx->cbuf, (ss->minx | ss->miny << 16)); virgl_encoder_write_cmd_dword(ctx, VIRGL_CMD0(VIRGL_CCMD_SET_SCISSOR_STATE, 0, VIRGL_SET_SCISSOR_STATE_SIZE(num_scissors)));
virgl_encoder_write_dword(ctx->cbuf, (ss->maxx | ss->maxy << 16)); virgl_encoder_write_dword(ctx->cbuf, start_slot);
for (s = 0; s < num_scissors; s++) {
virgl_encoder_write_dword(ctx->cbuf, (ss[s].minx | ss[s].miny << 16));
virgl_encoder_write_dword(ctx->cbuf, (ss[s].maxx | ss[s].maxy << 16));
}
return 0; return 0;
} }

@ -159,6 +159,8 @@ int virgl_encoder_set_blend_color(struct virgl_context *ctx,
const struct pipe_blend_color *color); const struct pipe_blend_color *color);
int virgl_encoder_set_scissor_state(struct virgl_context *ctx, int virgl_encoder_set_scissor_state(struct virgl_context *ctx,
int start_slot,
int num_scissors,
const struct pipe_scissor_state *ss); const struct pipe_scissor_state *ss);
void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx, void virgl_encoder_set_polygon_stipple(struct virgl_context *ctx,

Loading…
Cancel
Save