svga: rework framebuffer state
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

Create svga_framebuffer_state as a subclass of pipe_framebuffer_state.
This contains pointers to svga_surface objects which correspond to
pipe_framebuffer_state's surfaces.

Replace pipe_surface with svga_surface in many functions.

Stop using deprecated util_framebuffer_init() function.

See https://gitlab.freedesktop.org/mesa/mesa/-/issues/13262

Signed-off-by: Brian Paul <brian.paul@broadcom.com>x
Reviewed-by: Neha Bhende <neha.bhende@broadcom.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35238>
This commit is contained in:
Brian Paul 2025-05-29 09:02:28 -06:00 committed by Marge Bot
parent b7774effbf
commit f29d939824
18 changed files with 259 additions and 197 deletions

View file

@ -41,12 +41,11 @@
static inline void
surface_to_surfaceid(struct svga_winsys_context *swc, // IN
struct pipe_surface *surface, // IN
struct svga_surface *s, // IN
SVGA3dSurfaceImageId *id, // OUT
unsigned flags) // IN
{
if (surface) {
struct svga_surface *s = svga_surface(surface);
if (s) {
swc->surface_relocation(swc, &id->sid, NULL, s->handle, flags);
id->face = s->real_layer; /* faces have the same order */
id->mipmap = s->real_level;
@ -569,7 +568,7 @@ SVGA3D_BufferDMA(struct svga_winsys_context *swc,
enum pipe_error
SVGA3D_SetRenderTarget(struct svga_winsys_context *swc,
SVGA3dRenderTargetType type, // IN
struct pipe_surface *surface) // IN
struct svga_surface *surface) // IN
{
SVGA3dCmdSetRenderTarget *cmd;
@ -1036,8 +1035,8 @@ SVGA3D_BeginDrawPrimitives(struct svga_winsys_context *swc,
enum pipe_error
SVGA3D_BeginSurfaceCopy(struct svga_winsys_context *swc,
struct pipe_surface *src, // IN
struct pipe_surface *dest, // IN
struct svga_surface *src, // IN
struct svga_surface *dest, // IN
SVGA3dCopyBox **boxes, // OUT
uint32 numBoxes) // IN
{
@ -1079,8 +1078,8 @@ SVGA3D_BeginSurfaceCopy(struct svga_winsys_context *swc,
enum pipe_error
SVGA3D_SurfaceStretchBlt(struct svga_winsys_context *swc,
struct pipe_surface *src, // IN
struct pipe_surface *dest, // IN
struct svga_surface *src, // IN
struct svga_surface *dest, // IN
SVGA3dBox *boxSrc, // IN
SVGA3dBox *boxDest, // IN
SVGA3dStretchBltMode mode) // IN

View file

@ -24,6 +24,7 @@
struct pipe_surface;
struct svga_surface;
struct svga_transfer;
struct svga_winsys_context;
struct svga_winsys_buffer;
@ -147,15 +148,15 @@ SVGA3D_BeginDrawPrimitives(struct svga_winsys_context *swc,
enum pipe_error
SVGA3D_BeginSurfaceCopy(struct svga_winsys_context *swc,
struct pipe_surface *src,
struct pipe_surface *dest,
struct svga_surface *src,
struct svga_surface *dest,
SVGA3dCopyBox **boxes, uint32 numBoxes);
enum pipe_error
SVGA3D_SurfaceStretchBlt(struct svga_winsys_context *swc,
struct pipe_surface *src,
struct pipe_surface *dest,
struct svga_surface *src,
struct svga_surface *dest,
SVGA3dBox *boxSrc, SVGA3dBox *boxDest,
SVGA3dStretchBltMode mode);
@ -166,7 +167,7 @@ SVGA3D_SurfaceStretchBlt(struct svga_winsys_context *swc,
enum pipe_error
SVGA3D_SetRenderTarget(struct svga_winsys_context *swc,
SVGA3dRenderTargetType type,
struct pipe_surface *surface);
struct svga_surface *surface);
enum pipe_error
SVGA3D_SetZRange(struct svga_winsys_context *swc,

View file

@ -260,9 +260,6 @@ svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags)
// but some fields have to be zero/null:
memset(&svga->state.hw_clear.framebuffer, 0x0,
sizeof(svga->state.hw_clear.framebuffer));
memset(&svga->state.hw_clear.fb_cbufs, 0x0,
sizeof(svga->state.hw_clear.fb_cbufs));
svga->state.hw_clear.fb_zsbuf = NULL;
memset(&svga->state.hw_clear.rtv, 0, sizeof(svga->state.hw_clear.rtv));
svga->state.hw_clear.num_rendertargets = 0;
svga->state.hw_clear.dsv = NULL;

View file

@ -99,6 +99,7 @@ enum svga_surface_state
struct draw_vertex_shader;
struct draw_fragment_shader;
struct svga_shader_variant;
struct svga_surface;
struct SVGACmdMemory;
struct util_bitmask;
@ -279,6 +280,18 @@ struct svga_raw_buffer {
int32 srvid;
};
/*
* Subclass of pipe_framebuffer_state which has dynamically allocated
* svga_surface objects.
*/
struct svga_framebuffer_state
{
struct pipe_framebuffer_state base;
struct svga_surface *cbufs[PIPE_MAX_COLOR_BUFS];
struct svga_surface *zsbuf;
};
/* Use to calculate differences between state emitted to hardware and
* current driver-calculated state.
*/
@ -309,8 +322,8 @@ struct svga_state
struct pipe_constant_buffer constbufs[PIPE_SHADER_TYPES][SVGA_MAX_CONST_BUFS];
struct svga_raw_buffer rawbufs[PIPE_SHADER_TYPES][SVGA_MAX_RAW_BUFS];
PIPE_FB_SURFACES; //STOP USING THIS
struct pipe_framebuffer_state framebuffer;
struct svga_framebuffer_state framebuffer;
float depthscale;
/* Hack to limit the number of different render targets between
@ -378,8 +391,7 @@ struct svga_depthrange {
*/
struct svga_hw_clear_state
{
PIPE_FB_SURFACES; //STOP USING THIS
struct pipe_framebuffer_state framebuffer;
struct svga_framebuffer_state framebuffer;
/* VGPU9 only */
SVGA3dRect viewport;

View file

@ -252,8 +252,8 @@ draw_vgpu9(struct svga_hwtnl *hwtnl)
}
SVGA_DBG(DEBUG_DMA, "draw to sid %p, %d prims\n",
svga->curr.framebuffer.cbufs[0].texture ?
svga_surface(svga->curr.fb_cbufs[0])->handle : NULL,
svga->curr.framebuffer.cbufs[0] ?
svga->curr.framebuffer.cbufs[0]->handle : NULL,
hwtnl->cmd.prim_count);
ret = SVGA3D_BeginDrawPrimitives(swc,

View file

@ -15,6 +15,7 @@
#include "svga_winsys.h"
#include "svga_screen.h"
#include "svga_surface.h"
#include "svga_format.h"
@ -1886,9 +1887,9 @@ svga_has_any_integer_cbufs(const struct svga_context *svga)
{
unsigned i;
for (i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) {
const struct pipe_surface *cbuf = &svga->curr.framebuffer.cbufs[i];
const struct svga_surface *cbuf = svga->curr.framebuffer.cbufs[i];
if (cbuf->texture && util_format_is_pure_integer(cbuf->format)) {
if (cbuf && cbuf->base.texture && util_format_is_pure_integer(cbuf->base.format)) {
return true;
}
}

View file

@ -214,8 +214,8 @@ is_blending_enabled(struct svga_context *svga,
if (svga->curr.blend) {
if (svga->curr.blend->independent_blend_enable) {
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
struct pipe_surface *cbuf = &svga->curr.framebuffer.cbufs[i];
if (cbuf && (cbuf->texture == blit->dst.resource)) {
struct svga_surface *cbuf = svga->curr.framebuffer.cbufs[i];
if (cbuf && (cbuf->base.texture == blit->dst.resource)) {
if (svga->curr.blend->rt[i].blend_enable) {
blend_enable = true;
}
@ -623,7 +623,7 @@ try_blit(struct svga_context *svga, const struct pipe_blit_info *blit_info)
(void*)svga->curr.depth);
util_blitter_save_stencil_ref(svga->blitter, &svga->curr.stencil_ref);
util_blitter_save_sample_mask(svga->blitter, svga->curr.sample_mask, 0);
util_blitter_save_framebuffer(svga->blitter, &svga->curr.framebuffer);
util_blitter_save_framebuffer(svga->blitter, &svga->curr.framebuffer.base);
util_blitter_save_fragment_sampler_states(svga->blitter,
svga->curr.num_samplers[PIPE_SHADER_FRAGMENT],
(void**)svga->curr.sampler[PIPE_SHADER_FRAGMENT]);

View file

@ -57,7 +57,7 @@ clear_buffers_with_quad(struct svga_context *svga,
const union pipe_color_union *color,
double depth, unsigned stencil)
{
const struct pipe_framebuffer_state *fb = &svga->curr.framebuffer;
const struct pipe_framebuffer_state *fb = &svga->curr.framebuffer.base;
begin_blit(svga);
util_blitter_clear(svga->blitter,
@ -73,7 +73,7 @@ clear_buffers_with_quad(struct svga_context *svga,
* Check if any of the color buffers are integer buffers.
*/
static bool
is_integer_target(struct pipe_framebuffer_state *fb, unsigned buffers)
is_integer_target(const struct pipe_framebuffer_state *fb, unsigned buffers)
{
unsigned i;
@ -115,7 +115,7 @@ try_clear(struct svga_context *svga,
SVGA3dRect rect = { 0, 0, 0, 0 };
bool restore_viewport = false;
SVGA3dClearFlag flags = 0;
struct pipe_framebuffer_state *fb = &svga->curr.framebuffer;
struct pipe_framebuffer_state *fb = &svga->curr.framebuffer.base;
union util_color uc = {0};
ret = svga_update_state(svga, SVGA_STATE_HW_CLEAR);
@ -189,7 +189,7 @@ try_clear(struct svga_context *svga,
continue;
rtv = svga_validate_surface_view(svga,
svga_surface(svga->curr.fb_cbufs[i]));
svga->curr.framebuffer.cbufs[i]);
if (!rtv)
return PIPE_ERROR_OUT_OF_MEMORY;
@ -201,7 +201,7 @@ try_clear(struct svga_context *svga,
}
if (flags & (SVGA3D_CLEAR_DEPTH | SVGA3D_CLEAR_STENCIL)) {
struct pipe_surface *dsv =
svga_validate_surface_view(svga, svga_surface(svga->curr.fb_zsbuf));
svga_validate_surface_view(svga, svga->curr.framebuffer.zsbuf);
if (!dsv)
return PIPE_ERROR_OUT_OF_MEMORY;
@ -239,8 +239,8 @@ svga_clear(struct pipe_context *pipe, unsigned buffers, const struct pipe_scisso
if (buffers & PIPE_CLEAR_COLOR) {
struct svga_winsys_surface *h = NULL;
if (svga->curr.fb_cbufs[0]) {
h = svga_surface(svga->curr.fb_cbufs[0])->handle;
if (svga->curr.framebuffer.cbufs[0]) {
h = svga->curr.framebuffer.cbufs[0]->handle;
}
SVGA_DBG(DEBUG_DMA, "clear sid %p\n", h);
}
@ -334,7 +334,7 @@ svga_clear_texture(struct pipe_context *pipe,
/* To clear subtexture use software fallback */
util_blitter_save_framebuffer(svga->blitter,
&svga->curr.framebuffer);
&svga->curr.framebuffer.base);
begin_blit(svga);
util_blitter_clear_depth_stencil(svga->blitter,
dsv, clear_flags,
@ -365,8 +365,8 @@ svga_clear_texture(struct pipe_context *pipe,
if (box->x == 0 && box->y == 0 && box->width == pipe_surface_width(surface) &&
box->height == pipe_surface_height(surface)) {
struct pipe_framebuffer_state *curr = &svga->curr.framebuffer;
bool int_target = is_integer_target(curr, PIPE_CLEAR_COLOR);
bool int_target =
is_integer_target(&svga->curr.framebuffer.base, PIPE_CLEAR_COLOR);
if (int_target && !ints_fit_in_floats(&color)) {
/* To clear full texture with integer format */
@ -410,7 +410,7 @@ svga_clear_texture(struct pipe_context *pipe,
PIPE_BIND_RENDER_TARGET)) {
/* clear with quad drawing */
util_blitter_save_framebuffer(svga->blitter,
&svga->curr.framebuffer);
&svga->curr.framebuffer.base);
begin_blit(svga);
util_blitter_clear_render_target(svga->blitter,
rtv,
@ -484,7 +484,7 @@ svga_blitter_clear_render_target(struct svga_context *svga,
unsigned width, unsigned height)
{
begin_blit(svga);
util_blitter_save_framebuffer(svga->blitter, &svga->curr.framebuffer);
util_blitter_save_framebuffer(svga->blitter, &svga->curr.framebuffer.base);
util_blitter_clear_render_target(svga->blitter, dst, color,
dstx, dsty, width, height);

View file

@ -36,7 +36,7 @@ static void svga_flush( struct pipe_context *pipe,
/* Enable to dump BMPs of the color/depth buffers each frame */
if (0) {
struct pipe_framebuffer_state *fb = &svga->curr.framebuffer;
struct pipe_framebuffer_state *fb = &svga->curr.framebuffer.base;
static unsigned frame_no = 1;
char filename[256];
unsigned i;

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: MIT
*/
#include "util/u_framebuffer.h"
#include "util/u_inlines.h"
#include "util/u_pstipple.h"
@ -70,15 +69,17 @@ svga_set_polygon_stipple(struct pipe_context *pipe,
}
/**
* Release all the context's framebuffer surfaces.
*/
void
svga_cleanup_framebuffer(struct svga_context *svga)
{
struct pipe_framebuffer_state *curr = &svga->curr.framebuffer;
struct pipe_framebuffer_state *hw = &svga->state.hw_clear.framebuffer;
util_framebuffer_init(&svga->pipe, NULL, svga->curr.fb_cbufs, &svga->curr.fb_zsbuf);
util_unreference_framebuffer_state(curr);
util_unreference_framebuffer_state(hw);
struct svga_framebuffer_state *fb = &svga->curr.framebuffer;
for (unsigned i = 0; i < fb->base.nr_cbufs; i++) {
svga_surface_unref(&svga->pipe, &fb->cbufs[i]);
}
svga_surface_unref(&svga->pipe, &fb->zsbuf);
}
@ -87,12 +88,66 @@ svga_cleanup_framebuffer(struct svga_context *svga)
#define DEPTH_BIAS_SCALE_FACTOR_D32 ((float)(1<<31))
/*
* Copy pipe_framebuffer_state to svga_framebuffer_state while
* creating svga_surface objects as needed.
*/
static void
svga_copy_framebuffer_state(struct svga_context *svga,
struct svga_framebuffer_state *dst,
const struct pipe_framebuffer_state *src)
{
struct pipe_context *pctx = &svga->pipe;
const unsigned prev_nr_cbufs = dst->base.nr_cbufs;
dst->base = *src; // struct copy
// Create svga_surfaces for each color buffer
for (unsigned i = 0; i < src->nr_cbufs; i++) {
if (dst->cbufs[i] &&
pipe_surface_equal(&src->cbufs[i], &dst->cbufs[i]->base)) {
continue;
}
struct pipe_surface *psurf = src->cbufs[i].texture
? pctx->create_surface(pctx, src->cbufs[i].texture, &src->cbufs[i])
: NULL;
if (dst->cbufs[i]) {
svga_surface_unref(pctx, &dst->cbufs[i]);
}
dst->cbufs[i] = svga_surface(psurf);
}
// unref any remaining surfaces
for (unsigned i = src->nr_cbufs; i < prev_nr_cbufs; i++) {
if (dst->cbufs[i]) {
svga_surface_unref(pctx, &dst->cbufs[i]);
}
}
dst->base.nr_cbufs = src->nr_cbufs;
// depth/stencil surface
if (dst->zsbuf &&
pipe_surface_equal(&src->zsbuf, &dst->zsbuf->base)) {
return;
}
struct pipe_surface *psurf = src->zsbuf.texture
? pctx->create_surface(pctx, src->zsbuf.texture, &src->zsbuf)
: NULL;
if (dst->zsbuf) {
svga_surface_unref(pctx, &dst->zsbuf);
}
dst->zsbuf = svga_surface(psurf);
}
static void
svga_set_framebuffer_state(struct pipe_context *pipe,
const struct pipe_framebuffer_state *fb)
{
struct svga_context *svga = svga_context(pipe);
struct pipe_framebuffer_state *dst = &svga->curr.framebuffer;
/* make sure any pending drawing calls are flushed before changing
* the framebuffer state
@ -126,11 +181,10 @@ svga_set_framebuffer_state(struct pipe_context *pipe,
}
}
util_framebuffer_init(pipe, fb, svga->curr.fb_cbufs, &svga->curr.fb_zsbuf);
util_copy_framebuffer_state(dst, fb);
svga_copy_framebuffer_state(svga, &svga->curr.framebuffer, fb);
if (svga->curr.framebuffer.zsbuf.texture) {
switch (svga->curr.framebuffer.zsbuf.texture->format) {
if (svga->curr.framebuffer.zsbuf) {
switch (svga->curr.framebuffer.zsbuf->base.texture->format) {
case PIPE_FORMAT_Z16_UNORM:
svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D16;
break;

View file

@ -1366,12 +1366,12 @@ svga_validate_texture_resource(struct svga_context *svga,
for (unsigned i = 0; i < svga->state.hw_clear.num_rendertargets; i++) {
s = svga->state.hw_clear.rtv[i];
if (s && need_update_texture_resource(s, tex))
svga_propagate_surface(svga, s, true);
svga_propagate_surface(svga, svga_surface(s), true);
}
s = svga->state.hw_clear.dsv;
if (s && need_update_texture_resource(s, tex))
svga_propagate_surface(svga, s, true);
svga_propagate_surface(svga, svga_surface(s), true);
}

View file

@ -31,15 +31,13 @@
#define MAX_RT_PER_BATCH 8
static enum pipe_error
emit_fb_vgpu9(struct svga_context *svga)
{
struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
const struct pipe_framebuffer_state *curr = &svga->curr.framebuffer;
struct pipe_framebuffer_state *hw = &svga->state.hw_clear.framebuffer;
const struct svga_framebuffer_state *currfb = &svga->curr.framebuffer;
struct svga_framebuffer_state *hwfb = &svga->state.hw_clear.framebuffer;
bool reemit = svga->rebind.flags.rendertargets;
unsigned i;
enum pipe_error ret;
assert(!svga_have_vgpu10(svga));
@ -49,47 +47,47 @@ emit_fb_vgpu9(struct svga_context *svga)
* dirty, to ensure that the resources are paged in.
*/
for (i = 0; i < svgascreen->max_color_buffers; i++) {
if (!pipe_surface_equal(&curr->cbufs[i], &hw->cbufs[i]) ||
(reemit && svga->state.hw_clear.fb_cbufs[i])) {
for (unsigned i = 0; i < svgascreen->max_color_buffers; i++) {
if (!svga_surface_equal(currfb->cbufs[i], hwfb->cbufs[i]) ||
(reemit && hwfb->base.cbufs[i].texture)) {
if (svga->curr.nr_fbs++ > MAX_RT_PER_BATCH)
return PIPE_ERROR_OUT_OF_MEMORY;
/* Check to see if we need to propagate the render target surface */
if (svga_surface_needs_propagation(svga->state.hw_clear.fb_cbufs[i]))
svga_propagate_surface(svga, svga->state.hw_clear.fb_cbufs[i], true);
if (svga_surface_needs_propagation(svga->state.hw_clear.framebuffer.cbufs[i]))
svga_propagate_surface(svga, svga->state.hw_clear.framebuffer.cbufs[i], true);
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_COLOR0 + i,
svga->curr.fb_cbufs[i]);
svga->curr.framebuffer.cbufs[i]);
if (ret != PIPE_OK)
return ret;
pipe_surface_reference(&svga->state.hw_clear.fb_cbufs[i],
svga->curr.fb_cbufs[i]);
svga_surface_reference(&svga->state.hw_clear.framebuffer.cbufs[i],
svga->curr.framebuffer.cbufs[i]);
}
/* Set the rendered-to flag */
struct pipe_surface *s = svga->curr.fb_cbufs[i];
if (s->texture) {
svga_set_texture_rendered_to(svga_texture(s->texture));
struct svga_surface *s = svga->curr.framebuffer.cbufs[i];
if (s && s->base.texture) {
svga_set_texture_rendered_to(svga_texture(s->base.texture));
}
}
if (!pipe_surface_equal(&curr->zsbuf, &hw->zsbuf) ||
(reemit && svga->state.hw_clear.fb_zsbuf)) {
if (!svga_surface_equal(currfb->zsbuf, hwfb->zsbuf) ||
(reemit && svga->state.hw_clear.framebuffer.zsbuf)) {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_DEPTH,
svga->curr.fb_zsbuf);
currfb->zsbuf);
if (ret != PIPE_OK)
return ret;
/* Check to see if we need to propagate the depth stencil surface */
if (svga_surface_needs_propagation(svga->state.hw_clear.fb_zsbuf))
svga_propagate_surface(svga, svga->state.hw_clear.fb_zsbuf, true);
if (svga_surface_needs_propagation(hwfb->zsbuf))
svga_propagate_surface(svga, hwfb->zsbuf, true);
if (curr->zsbuf.texture &&
util_format_is_depth_and_stencil(curr->zsbuf.format)) {
if (currfb->zsbuf->base.texture &&
util_format_is_depth_and_stencil(currfb->zsbuf->base.format)) {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_STENCIL,
svga->curr.fb_zsbuf);
currfb->zsbuf);
if (ret != PIPE_OK)
return ret;
}
@ -99,13 +97,13 @@ emit_fb_vgpu9(struct svga_context *svga)
return ret;
}
pipe_surface_reference(&svga->state.hw_clear.fb_zsbuf,
svga->curr.fb_zsbuf);
svga_surface_reference(&svga->state.hw_clear.framebuffer.zsbuf,
svga->curr.framebuffer.zsbuf);
/* Set the rendered-to flag */
struct pipe_surface *s = svga->curr.fb_zsbuf;
if (s->texture) {
svga_set_texture_rendered_to(svga_texture(s->texture));
struct svga_surface *s = currfb->zsbuf;
if (s && s->base.texture) {
svga_set_texture_rendered_to(svga_texture(s->base.texture));
}
}
@ -125,41 +123,31 @@ static enum pipe_error
svga_reemit_framebuffer_bindings_vgpu9(struct svga_context *svga)
{
struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
unsigned i;
enum pipe_error ret;
enum pipe_error ret = PIPE_OK;
assert(!svga_have_vgpu10(svga));
for (i = 0; i < svgascreen->max_color_buffers; i++) {
if (svga->state.hw_clear.fb_cbufs[i]) {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_COLOR0 + i,
svga->state.hw_clear.fb_cbufs[i]);
for (unsigned i = 0; i < svgascreen->max_color_buffers; i++) {
struct svga_surface *cbuf = svga->state.hw_clear.framebuffer.cbufs[i];
if (cbuf) {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_COLOR0 + i, cbuf);
if (ret != PIPE_OK) {
return ret;
}
}
}
if (svga->state.hw_clear.fb_zsbuf) {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_DEPTH,
svga->state.hw_clear.fb_zsbuf);
struct svga_surface *zsbuf = svga->state.hw_clear.framebuffer.zsbuf;
if (zsbuf) {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_DEPTH, zsbuf);
if (ret != PIPE_OK) {
return ret;
}
if (svga->state.hw_clear.fb_zsbuf &&
util_format_is_depth_and_stencil(svga->state.hw_clear.fb_zsbuf->format)) {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_STENCIL,
svga->state.hw_clear.fb_zsbuf);
if (ret != PIPE_OK) {
return ret;
}
}
else {
if (util_format_is_depth_and_stencil(zsbuf->base.format)) {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_STENCIL, zsbuf);
} else {
ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_STENCIL, NULL);
if (ret != PIPE_OK) {
return ret;
}
}
}
@ -174,9 +162,9 @@ emit_fb_vgpu10(struct svga_context *svga)
const struct svga_screen *ss = svga_screen(svga->pipe.screen);
struct pipe_surface *rtv[SVGA3D_DX_MAX_RENDER_TARGETS];
struct pipe_surface *dsv;
struct pipe_framebuffer_state *curr = &svga->curr.framebuffer;
struct pipe_framebuffer_state *hw = &svga->state.hw_clear.framebuffer;
const unsigned num_color = MAX2(curr->nr_cbufs, hw->nr_cbufs);
struct svga_framebuffer_state *currfb = &svga->curr.framebuffer;
struct svga_framebuffer_state *hwfb = &svga->state.hw_clear.framebuffer;
const unsigned num_color = MAX2(currfb->base.nr_cbufs, hwfb->base.nr_cbufs);
int last_rtv = -1;
assert(svga_have_vgpu10(svga));
@ -193,11 +181,11 @@ emit_fb_vgpu10(struct svga_context *svga)
* than the old number of buffers.
*/
for (unsigned i = 0; i < num_color; i++) {
if (curr->cbufs[i].texture) {
struct pipe_surface *s = svga->curr.fb_cbufs[i];
if (currfb->base.cbufs[i].texture) {
struct svga_surface *s = currfb->cbufs[i];
if (!pipe_surface_equal(&curr->cbufs[i], &hw->cbufs[i])) {
rtv[i] = svga_validate_surface_view(svga, svga_surface(s));
if (!svga_surface_equal(s, hwfb->cbufs[i])) {
rtv[i] = svga_validate_surface_view(svga, s);
if (rtv[i] == NULL) {
return PIPE_ERROR_OUT_OF_MEMORY;
}
@ -209,7 +197,7 @@ emit_fb_vgpu10(struct svga_context *svga)
last_rtv = i;
/* Set the rendered-to flag */
svga_set_texture_rendered_to(svga_texture(s->texture));
svga_set_texture_rendered_to(svga_texture(s->base.texture));
}
else {
rtv[i] = NULL;
@ -217,11 +205,11 @@ emit_fb_vgpu10(struct svga_context *svga)
}
/* Setup depth stencil view */
if (curr->zsbuf.texture) {
struct pipe_surface *s = svga->curr.fb_zsbuf;
if (currfb->zsbuf) {
struct svga_surface *s = currfb->zsbuf;
if (svga->curr.fb_zsbuf != svga->state.hw_clear.fb_zsbuf) {
dsv = svga_validate_surface_view(svga, svga_surface(svga->curr.fb_zsbuf));
if (s != hwfb->zsbuf) {
dsv = svga_validate_surface_view(svga, s);
if (!dsv) {
return PIPE_ERROR_OUT_OF_MEMORY;
}
@ -230,7 +218,7 @@ emit_fb_vgpu10(struct svga_context *svga)
}
/* Set the rendered-to flag */
svga_set_texture_rendered_to(svga_texture(s->texture));
svga_set_texture_rendered_to(svga_texture(s->base.texture));
}
else {
dsv = NULL;
@ -250,43 +238,36 @@ emit_fb_vgpu10(struct svga_context *svga)
* unbound render targets.
*/
for (unsigned i = 0; i < ss->max_color_buffers; i++) {
if (!pipe_surface_equal(&hw->cbufs[i], &curr->cbufs[i])) {
if (!svga_surface_equal(hwfb->cbufs[i], currfb->cbufs[i])) {
/* propagate the backed view surface before unbinding it */
if (hw->cbufs[i].texture &&
svga_surface(svga->state.hw_clear.fb_cbufs[i])->backed) {
svga_propagate_surface(svga,
&svga_surface(svga->state.hw_clear.fb_cbufs[i])->backed->base,
true);
if (hwfb->cbufs[i] && hwfb->cbufs[i]->backed) {
svga_propagate_surface(svga, hwfb->cbufs[i]->backed, true);
}
else if (svga->state.hw_clear.rtv[i] != svga->state.hw_clear.fb_cbufs[i] &&
else if (svga_surface(svga->state.hw_clear.rtv[i]) != hwfb->cbufs[i] &&
svga->state.hw_clear.rtv[i]) {
/* Free the alternate surface view when it is unbound. */
pipe_surface_unref(&svga->pipe, &svga->state.hw_clear.rtv[i]);
}
pipe_surface_reference(&svga->state.hw_clear.fb_cbufs[i],
svga->curr.fb_cbufs[i]);
svga_surface_reference(&hwfb->cbufs[i], currfb->cbufs[i]);
}
}
svga->state.hw_clear.num_rendertargets = last_rtv + 1;
for (unsigned i = 0; i < num_color; i++) {
pipe_surface_reference(&svga->state.hw_clear.rtv[i], rtv[i]);
}
hw->nr_cbufs = curr->nr_cbufs;
hwfb->base.nr_cbufs = currfb->base.nr_cbufs;
if (!pipe_surface_equal(&hw->zsbuf, &curr->zsbuf)) {
if (!svga_surface_equal(hwfb->zsbuf, currfb->zsbuf)) {
/* propagate the backed view surface before unbinding it */
if (svga->state.hw_clear.fb_zsbuf && svga_surface(svga->state.hw_clear.fb_zsbuf)->backed) {
svga_propagate_surface(svga,
&svga_surface(svga->state.hw_clear.fb_zsbuf)->backed->base,
true);
if (hwfb->zsbuf && hwfb->zsbuf->backed) {
svga_propagate_surface(svga, hwfb->zsbuf->backed, true);
}
else if (svga->state.hw_clear.dsv != svga->state.hw_clear.fb_zsbuf &&
else if (svga_surface(svga->state.hw_clear.dsv) != hwfb->zsbuf &&
svga->state.hw_clear.dsv) {
/* Free the alternate surface view when it is unbound. */
svga->pipe.surface_destroy(&svga->pipe, svga->state.hw_clear.dsv);
pipe_surface_unref(&svga->pipe, &svga->state.hw_clear.dsv);
}
pipe_surface_reference(&svga->state.hw_clear.fb_zsbuf,
svga->curr.fb_zsbuf);
svga_surface_reference(&hwfb->zsbuf, currfb->zsbuf);
}
pipe_surface_reference(&svga->state.hw_clear.dsv, dsv);
}
@ -401,8 +382,8 @@ get_viewport_prescale(struct svga_context *svga,
bool degenerate = false;
bool invertY = false;
float fb_width = (float) svga->curr.framebuffer.width;
float fb_height = (float) svga->curr.framebuffer.height;
float fb_width = (float) svga->curr.framebuffer.base.width;
float fb_height = (float) svga->curr.framebuffer.base.height;
float fx = viewport->scale[0] * -1.0f + viewport->translate[0];
float fy = flip * viewport->scale[1] * -1.0f + viewport->translate[1];

View file

@ -287,7 +287,7 @@ make_fs_key(const struct svga_context *svga,
if (fs->base.info.fs.color0_writes_all_cbufs ||
svga->curr.blend->need_white_fragments) {
/* Replicate color0 output (or white) to N colorbuffers */
key->fs.write_color0_to_n_cbufs = svga->curr.framebuffer.nr_cbufs;
key->fs.write_color0_to_n_cbufs = svga->curr.framebuffer.base.nr_cbufs;
}
return PIPE_OK;

View file

@ -247,7 +247,7 @@ emit_rss_vgpu9(struct svga_context *svga, uint64_t dirty)
* pipeline is active.
*/
if (!svga->state.sw.need_pipeline &&
svga->curr.framebuffer.zsbuf.texture)
svga->curr.framebuffer.base.zsbuf.texture)
{
slope = curr->slopescaledepthbias;
bias = svga->curr.depthscale * curr->depthbias;
@ -260,8 +260,8 @@ emit_rss_vgpu9(struct svga_context *svga, uint64_t dirty)
if (dirty & SVGA_NEW_FRAME_BUFFER) {
/* XXX: we only look at the first color buffer's sRGB state */
float gamma = 1.0f;
if (svga->curr.framebuffer.cbufs[0].texture &&
util_format_is_srgb(svga->curr.framebuffer.cbufs[0].format)) {
if (svga->curr.framebuffer.base.cbufs[0].texture &&
util_format_is_srgb(svga->curr.framebuffer.base.cbufs[0].format)) {
gamma = 2.2f;
}
EMIT_RS_FLOAT(svga, gamma, OUTPUTGAMMA);
@ -479,11 +479,11 @@ emit_rss_vgpu10(struct svga_context *svga, uint64_t dirty)
/* In the case of no-attachment framebuffer, the sample count will be
* specified in forcedSampleCount in the RasterizerState_v2 object.
*/
if ((svga->curr.framebuffer.nr_cbufs == 0) &&
(svga->curr.framebuffer.zsbuf.texture == NULL)) {
if ((svga->curr.framebuffer.base.nr_cbufs == 0) &&
(svga->curr.framebuffer.base.zsbuf.texture == NULL)) {
rastId =
get_alt_rasterizer_state_id(svga, rast,
svga->curr.framebuffer.samples);
svga->curr.framebuffer.base.samples);
if (rastId == SVGA3D_INVALID_ID)
return PIPE_ERROR;

View file

@ -85,8 +85,8 @@ svga_check_sampler_framebuffer_resource_collision(struct svga_context *svga,
struct svga_surface *surf;
unsigned i;
for (i = 0; i < svga->curr.framebuffer.nr_cbufs; i++) {
surf = svga_surface(svga->curr.fb_cbufs[i]);
for (i = 0; i < svga->curr.framebuffer.base.nr_cbufs; i++) {
surf = svga->curr.framebuffer.cbufs[i];
if (surf &&
svga_check_sampler_view_resource_collision(svga, surf->handle,
shader)) {
@ -94,7 +94,7 @@ svga_check_sampler_framebuffer_resource_collision(struct svga_context *svga,
}
}
surf = svga_surface(svga->curr.fb_zsbuf);
surf = svga->curr.framebuffer.zsbuf;
if (surf &&
svga_check_sampler_view_resource_collision(svga, surf->handle, shader)) {
return true;

View file

@ -24,7 +24,7 @@
#include "svga_surface.h"
#include "svga_debug.h"
static void svga_mark_surface_dirty(struct pipe_surface *surf);
static void svga_mark_surface_dirty(struct svga_surface *s);
void
svga_texture_copy_region(struct svga_context *svga,
@ -97,11 +97,7 @@ svga_texture_copy_handle(struct svga_context *svga,
dst_handle, dst_level, dst_x, dst_y, dst_z);
*/
SVGA_RETRY(svga, SVGA3D_BeginSurfaceCopy(svga->swc,
&src.base,
&dst.base,
&boxes, 1));
SVGA_RETRY(svga, SVGA3D_BeginSurfaceCopy(svga->swc, &src, &dst, &boxes, 1));
*boxes = box;
SVGA_FIFOCommitAll(svga->swc);
}
@ -492,7 +488,7 @@ create_backed_surface_view(struct svga_context *svga, struct svga_surface *s,
zslice, s->base.level, layer);
}
svga_mark_surface_dirty(&s->backed->base);
svga_mark_surface_dirty(s->backed);
s->backed->age = tex->age;
assert(s->backed->base.context == &svga->pipe);
@ -644,7 +640,7 @@ svga_surface_destroy(struct pipe_context *pipe,
/* Destroy the backed view surface if it exists */
if (s->backed) {
pipe_surface_unref(pipe, (struct pipe_surface **) &s->backed);
svga_surface_unref(pipe, &s->backed);
}
/* Destroy the surface handle if this is a backed handle and
@ -690,18 +686,17 @@ svga_surface_destroy(struct pipe_context *pipe,
static void
svga_mark_surface_dirty(struct pipe_surface *surf)
svga_mark_surface_dirty(struct svga_surface *s)
{
struct svga_surface *s = svga_surface(surf);
struct svga_texture *tex = svga_texture(surf->texture);
struct svga_texture *tex = svga_texture(s->base.texture);
if (!s->dirty) {
s->dirty = true;
if (s->handle == tex->handle) {
/* hmm so 3d textures always have all their slices marked ? */
svga_define_texture_level(tex, surf->first_layer,
surf->level);
svga_define_texture_level(tex, s->base.first_layer,
s->base.level);
}
else {
/* this will happen later in svga_propagate_surface */
@ -714,7 +709,7 @@ svga_mark_surface_dirty(struct pipe_surface *surf)
* backed surface is propagated to the original surface.
*/
if (s->handle == tex->handle)
svga_age_texture_view(tex, surf->level);
svga_age_texture_view(tex, s->base.level);
}
@ -729,17 +724,17 @@ svga_mark_surfaces_dirty(struct svga_context *svga)
*/
for (unsigned i = 0; i < hw->num_rendertargets; i++) {
if (hw->rtv[i])
svga_mark_surface_dirty(hw->rtv[i]);
svga_mark_surface_dirty(svga_surface(hw->rtv[i]));
}
if (hw->dsv)
svga_mark_surface_dirty(hw->dsv);
svga_mark_surface_dirty(svga_surface(hw->dsv));
} else {
for (unsigned i = 0; i < svga->curr.framebuffer.nr_cbufs; i++) {
if (svga->curr.framebuffer.cbufs[i].texture)
svga_mark_surface_dirty(svga->curr.fb_cbufs[i]);
for (unsigned i = 0; i < svga->curr.framebuffer.base.nr_cbufs; i++) {
if (svga->curr.framebuffer.base.cbufs[i].texture)
svga_mark_surface_dirty(svga->curr.framebuffer.cbufs[i]);
}
if (svga->curr.framebuffer.zsbuf.texture)
svga_mark_surface_dirty(svga->curr.fb_zsbuf);
if (svga->curr.framebuffer.base.zsbuf.texture)
svga_mark_surface_dirty(svga->curr.framebuffer.zsbuf);
}
}
@ -749,12 +744,11 @@ svga_mark_surfaces_dirty(struct svga_context *svga)
* pipe is optional context to inline the blit command in.
*/
void
svga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf,
svga_propagate_surface(struct svga_context *svga, struct svga_surface *s,
bool reset)
{
struct svga_surface *s = svga_surface(surf);
struct svga_texture *tex = svga_texture(surf->texture);
struct svga_screen *ss = svga_screen(surf->texture->screen);
struct svga_texture *tex = svga_texture(s->base.texture);
struct svga_screen *ss = svga_screen(s->base.texture->screen);
if (!s->dirty)
return;
@ -770,36 +764,36 @@ svga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf,
s->dirty = !reset;
ss->texture_timestamp++;
svga_age_texture_view(tex, surf->level);
svga_age_texture_view(tex, s->base.level);
if (s->handle != tex->handle) {
unsigned zslice, layer;
unsigned nlayers = 1;
const unsigned numMipLevels = tex->b.last_level + 1;
const unsigned srcLevel = s->real_level;
const unsigned dstLevel = surf->level;
const unsigned dstLevel = s->base.level;
const unsigned width = u_minify(tex->b.width0, dstLevel);
const unsigned height = u_minify(tex->b.height0, dstLevel);
if (surf->texture->target == PIPE_TEXTURE_CUBE) {
if (s->base.texture->target == PIPE_TEXTURE_CUBE) {
zslice = 0;
layer = surf->first_layer;
layer = s->base.first_layer;
}
else if (surf->texture->target == PIPE_TEXTURE_1D_ARRAY ||
surf->texture->target == PIPE_TEXTURE_2D_ARRAY ||
surf->texture->target == PIPE_TEXTURE_CUBE_ARRAY) {
else if (s->base.texture->target == PIPE_TEXTURE_1D_ARRAY ||
s->base.texture->target == PIPE_TEXTURE_2D_ARRAY ||
s->base.texture->target == PIPE_TEXTURE_CUBE_ARRAY) {
zslice = 0;
layer = surf->first_layer;
nlayers = surf->last_layer - surf->first_layer + 1;
layer = s->base.first_layer;
nlayers = s->base.last_layer - s->base.first_layer + 1;
}
else {
zslice = surf->first_layer;
zslice = s->base.first_layer;
layer = 0;
}
SVGA_DBG(DEBUG_VIEWS,
"Propagate surface %p to resource %p, level %u\n",
surf, tex, surf->level);
s, tex, s->base.level);
if (svga_have_vgpu10(svga)) {
unsigned srcSubResource, dstSubResource;
@ -859,14 +853,14 @@ svga_propagate_rendertargets(struct svga_context *svga)
* surfaces which may be backing surface views (the actual render targets).
*/
for (unsigned i = 0; i < svga->state.hw_clear.num_rendertargets; i++) {
struct pipe_surface *s = svga->state.hw_clear.rtv[i];
struct svga_surface *s = svga_surface(svga->state.hw_clear.rtv[i]);
if (s) {
svga_propagate_surface(svga, s, false);
}
}
if (svga->state.hw_clear.dsv) {
svga_propagate_surface(svga, svga->state.hw_clear.dsv, false);
svga_propagate_surface(svga, svga_surface(svga->state.hw_clear.dsv), false);
}
}
@ -875,13 +869,12 @@ svga_propagate_rendertargets(struct svga_context *svga)
* Check if we should call svga_propagate_surface on the surface.
*/
bool
svga_surface_needs_propagation(const struct pipe_surface *surf)
svga_surface_needs_propagation(const struct svga_surface *s)
{
if (surf == NULL) {
if (s == NULL) {
return false;
} else {
const struct svga_surface *s = svga_surface_const(surf);
struct svga_texture *tex = svga_texture(surf->texture);
struct svga_texture *tex = svga_texture(s->base.texture);
return s->dirty && s->handle != tex->handle;
}
}

View file

@ -60,18 +60,45 @@ struct svga_surface
};
static inline void
svga_surface_reference(struct svga_surface **dst,
struct svga_surface *src)
{
pipe_surface_reference((struct pipe_surface **) dst,
(struct pipe_surface *) src);
}
static inline void
svga_surface_unref(struct pipe_context *pipe,
struct svga_surface **s)
{
pipe_surface_unref(pipe, (struct pipe_surface **) s);
}
static inline bool
svga_surface_equal(const struct svga_surface *s1, const struct svga_surface *s2)
{
if (s1 == NULL && s2 == NULL)
return true;
return pipe_surface_equal((struct pipe_surface *) s1,
(struct pipe_surface *) s2);
}
void
svga_mark_surfaces_dirty(struct svga_context *svga);
extern void
svga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf,
svga_propagate_surface(struct svga_context *svga, struct svga_surface *surf,
bool reset);
void
svga_propagate_rendertargets(struct svga_context *svga);
extern bool
svga_surface_needs_propagation(const struct pipe_surface *surf);
svga_surface_needs_propagation(const struct svga_surface *s);
struct svga_winsys_surface *
svga_texture_view_surface(struct svga_context *svga,
@ -124,9 +151,6 @@ svga_surface_const(const struct pipe_surface *surface)
struct pipe_surface *
svga_validate_surface_view(struct svga_context *svga, struct svga_surface *s);
void
svga_propagate_surface(struct svga_context *svga, struct pipe_surface *surf,
bool reset);
static inline SVGA3dResourceType
svga_resource_type(enum pipe_texture_target target)

View file

@ -125,8 +125,8 @@ update_swtnl_draw(struct svga_context *svga, uint64_t dirty)
*/
if (dirty & SVGA_NEW_FRAME_BUFFER)
draw_set_zs_format(svga->swtnl.draw,
(svga->curr.framebuffer.zsbuf.texture) ?
svga->curr.framebuffer.zsbuf.format : PIPE_FORMAT_NONE);
(svga->curr.framebuffer.base.zsbuf.texture) ?
svga->curr.framebuffer.base.zsbuf.format : PIPE_FORMAT_NONE);
SVGA_STATS_TIME_POP(svga_sws(svga));
return PIPE_OK;