+static bool
+swr_change_rt(struct swr_context *ctx,
+ unsigned attachment,
+ const struct pipe_surface *sf)
+{
+ swr_draw_context *pDC = &ctx->swrDC;
+ struct SWR_SURFACE_STATE *rt = &pDC->renderTargets[attachment];
+
+ /* Do nothing if the render target hasn't changed */
+ if ((!sf || !sf->texture) && rt->pBaseAddress == nullptr)
+ return false;
+
+ /* Deal with disabling RT up front */
+ if (!sf || !sf->texture) {
+ /* If detaching attachment, mark tiles as RESOLVED so core
+ * won't try to load from non-existent target. */
+ swr_store_render_target(&ctx->pipe, attachment, SWR_TILE_RESOLVED);
+ *rt = {0};
+ return true;
+ }
+
+ const struct swr_resource *swr = swr_resource(sf->texture);
+ const SWR_SURFACE_STATE *swr_surface = &swr->swr;
+ SWR_FORMAT fmt = mesa_to_swr_format(sf->format);
+
+ if (attachment == SWR_ATTACHMENT_STENCIL && swr->secondary.pBaseAddress) {
+ swr_surface = &swr->secondary;
+ fmt = swr_surface->format;
+ }
+
+ if (rt->pBaseAddress == swr_surface->pBaseAddress &&
+ rt->format == fmt &&
+ rt->lod == sf->u.tex.level &&
+ rt->arrayIndex == sf->u.tex.first_layer)
+ return false;
+
+ bool need_fence = false;
+
+ /* StoreTile for changed target */
+ if (rt->pBaseAddress) {
+ /* If changing attachment to a new target, mark tiles as
+ * INVALID so they are reloaded from surface. */
+ swr_store_render_target(&ctx->pipe, attachment, SWR_TILE_INVALID);
+ need_fence = true;
+ }
+
+ /* Make new attachment */
+ *rt = *swr_surface;
+ rt->format = fmt;
+ rt->lod = sf->u.tex.level;
+ rt->arrayIndex = sf->u.tex.first_layer;
+
+ return need_fence;
+}
+