swr: Report format max_samples=1 to maintain support for "fake" msaa.
[mesa.git] / src / gallium / drivers / swr / swr_context.cpp
index 6f46d666ac59909f1bb790e9c8599b545b8363bb..c058870f2762bf279d6c5b0ed2909f1cd580be2c 100644 (file)
@@ -271,16 +271,27 @@ static void
 swr_blit(struct pipe_context *pipe, const struct pipe_blit_info *blit_info)
 {
    struct swr_context *ctx = swr_context(pipe);
+   /* Make a copy of the const blit_info, so we can modify it */
    struct pipe_blit_info info = *blit_info;
 
-   if (blit_info->render_condition_enable && !swr_check_render_cond(pipe))
+   if (info.render_condition_enable && !swr_check_render_cond(pipe))
       return;
 
    if (info.src.resource->nr_samples > 1 && info.dst.resource->nr_samples <= 1
        && !util_format_is_depth_or_stencil(info.src.resource->format)
        && !util_format_is_pure_integer(info.src.resource->format)) {
-      debug_printf("swr: color resolve unimplemented\n");
-      return;
+      debug_printf("swr_blit: color resolve : %d -> %d\n",
+            info.src.resource->nr_samples, info.dst.resource->nr_samples);
+
+      /* Resolve is done as part of the surface store. */
+      swr_store_dirty_resource(pipe, info.src.resource, SWR_TILE_RESOLVED);
+
+      struct pipe_resource *src_resource = info.src.resource;
+      struct pipe_resource *resolve_target =
+         swr_resource(src_resource)->resolve_target;
+
+      /* The resolve target becomes the new source for the blit. */
+      info.src.resource = resolve_target;
    }
 
    if (util_try_blit_via_copy_region(pipe, &info)) {
@@ -300,8 +311,8 @@ swr_blit(struct pipe_context *pipe, const struct pipe_blit_info *blit_info)
    }
 
    if (ctx->active_queries) {
-      SwrEnableStatsFE(ctx->swrContext, FALSE);
-      SwrEnableStatsBE(ctx->swrContext, FALSE);
+      ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, FALSE);
+      ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, FALSE);
    }
 
    util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer);
@@ -338,8 +349,8 @@ swr_blit(struct pipe_context *pipe, const struct pipe_blit_info *blit_info)
    util_blitter_blit(ctx->blitter, &info);
 
    if (ctx->active_queries) {
-      SwrEnableStatsFE(ctx->swrContext, TRUE);
-      SwrEnableStatsBE(ctx->swrContext, TRUE);
+      ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, TRUE);
+      ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, TRUE);
    }
 }
 
@@ -372,10 +383,10 @@ swr_destroy(struct pipe_context *pipe)
 
    /* Idle core after destroying buffer resources, but before deleting
     * context.  Destroying resources has potentially called StoreTiles.*/
-   SwrWaitForIdle(ctx->swrContext);
+   ctx->api.pfnSwrWaitForIdle(ctx->swrContext);
 
    if (ctx->swrContext)
-      SwrDestroyContext(ctx->swrContext);
+      ctx->api.pfnSwrDestroyContext(ctx->swrContext);
 
    delete ctx->blendJIT;
 
@@ -411,7 +422,7 @@ swr_UpdateStats(HANDLE hPrivateContext, const SWR_STATS *pStats)
    if (!pDC)
       return;
 
-   struct swr_query_result *pqr = (struct swr_query_result *)pDC->pStats;
+   struct swr_query_result *pqr = pDC->pStats;
 
    SWR_STATS *pSwrStats = &pqr->core;
 
@@ -428,7 +439,7 @@ swr_UpdateStatsFE(HANDLE hPrivateContext, const SWR_STATS_FE *pStats)
    if (!pDC)
       return;
 
-   struct swr_query_result *pqr = (struct swr_query_result *)pDC->pStats;
+   struct swr_query_result *pqr = pDC->pStats;
 
    SWR_STATS_FE *pSwrStats = &pqr->coreFE;
    p_atomic_add(&pSwrStats->IaVertices, pStats->IaVertices);
@@ -456,6 +467,9 @@ swr_create_context(struct pipe_screen *p_screen, void *priv, unsigned flags)
       AlignedMalloc(sizeof(struct swr_context), KNOB_SIMD_BYTES);
    memset(ctx, 0, sizeof(struct swr_context));
 
+   swr_screen(p_screen)->pfnSwrGetInterface(ctx->api);
+   ctx->swrDC.pAPI = &ctx->api;
+
    ctx->blendJIT =
       new std::unordered_map<BLEND_COMPILE_STATE, PFN_BLEND_JIT_FUNC>;
 
@@ -467,12 +481,9 @@ swr_create_context(struct pipe_screen *p_screen, void *priv, unsigned flags)
    createInfo.pfnClearTile = swr_StoreHotTileClear;
    createInfo.pfnUpdateStats = swr_UpdateStats;
    createInfo.pfnUpdateStatsFE = swr_UpdateStatsFE;
-   ctx->swrContext = SwrCreateContext(&createInfo);
-
-   /* Init Load/Store/ClearTiles Tables */
-   swr_InitMemoryModule();
+   ctx->swrContext = ctx->api.pfnSwrCreateContext(&createInfo);
 
-   InitBackendFuncTables();
+   ctx->api.pfnSwrInit();
 
    if (ctx->swrContext == NULL)
       goto fail;