swr: [rasterizer archrast] move to pass by value
[mesa.git] / src / gallium / drivers / swr / swr_state.cpp
index 4c9a4327e29a85ade2e97ad4951d3803b137007f..65327f39d026bd59513d80cf92e253af5d5fae85 100644 (file)
@@ -38,6 +38,7 @@
 #include "util/u_inlines.h"
 #include "util/u_helpers.h"
 #include "util/u_framebuffer.h"
+#include "util/u_viewport.h"
 
 #include "swr_state.h"
 #include "swr_context.h"
@@ -235,7 +236,7 @@ swr_create_sampler_state(struct pipe_context *pipe,
 
 static void
 swr_bind_sampler_states(struct pipe_context *pipe,
-                        unsigned shader,
+                        enum pipe_shader_type shader,
                         unsigned start,
                         unsigned num,
                         void **samplers)
@@ -282,7 +283,7 @@ swr_create_sampler_view(struct pipe_context *pipe,
 
 static void
 swr_set_sampler_views(struct pipe_context *pipe,
-                      unsigned shader,
+                      enum pipe_shader_type shader,
                       unsigned start,
                       unsigned num,
                       struct pipe_sampler_view **views)
@@ -920,6 +921,7 @@ swr_update_derived(struct pipe_context *pipe,
          rastState->depthFormat = swr_resource(zb->texture)->swr.format;
 
       rastState->depthClipEnable = rasterizer->depth_clip;
+      rastState->clipHalfZ = rasterizer->clip_halfz;
 
       rastState->clipDistanceMask =
          ctx->vs->info.base.num_written_clipdistance ?
@@ -951,13 +953,8 @@ swr_update_derived(struct pipe_context *pipe,
       vp->width = state->translate[0] + state->scale[0];
       vp->y = state->translate[1] - fabs(state->scale[1]);
       vp->height = state->translate[1] + fabs(state->scale[1]);
-      if (rasterizer->clip_halfz == 0) {
-         vp->minZ = state->translate[2] - state->scale[2];
-         vp->maxZ = state->translate[2] + state->scale[2];
-      } else {
-         vp->minZ = state->translate[2];
-         vp->maxZ = state->translate[2] + state->scale[2];
-      }
+      util_viewport_zmin_zmax(state, rasterizer->clip_halfz,
+                              &vp->minZ, &vp->maxZ);
 
       vpm->m00[0] = state->scale[0];
       vpm->m11[0] = state->scale[1];
@@ -1205,6 +1202,7 @@ swr_update_derived(struct pipe_context *pipe,
       struct pipe_depth_state *depth = &(ctx->depth_stencil->depth);
       struct pipe_stencil_state *stencil = ctx->depth_stencil->stencil;
       SWR_DEPTH_STENCIL_STATE depthStencilState = {{0}};
+      SWR_DEPTH_BOUNDS_STATE depthBoundsState = {0};
 
       /* XXX, incomplete.  Need to flesh out stencil & alpha test state
       struct pipe_stencil_state *front_stencil =
@@ -1251,6 +1249,11 @@ swr_update_derived(struct pipe_context *pipe,
       depthStencilState.depthTestFunc = swr_convert_depth_func(depth->func);
       depthStencilState.depthWriteEnable = depth->writemask;
       SwrSetDepthStencilState(ctx->swrContext, &depthStencilState);
+
+      depthBoundsState.depthBoundsTestEnable = depth->bounds_test;
+      depthBoundsState.depthBoundsTestMinValue = depth->bounds_min;
+      depthBoundsState.depthBoundsTestMaxValue = depth->bounds_max;
+      SwrSetDepthBoundsState(ctx->swrContext, &depthBoundsState);
    }
 
    /* Blend State */
@@ -1299,8 +1302,15 @@ swr_update_derived(struct pipe_context *pipe,
                    &ctx->blend->compileState[target],
                    sizeof(compileState.blendState));
 
+            const SWR_FORMAT_INFO& info = GetFormatInfo(compileState.format);
+            if (compileState.blendState.logicOpEnable &&
+                ((info.type[0] == SWR_TYPE_FLOAT) || info.isSRGB)) {
+               compileState.blendState.logicOpEnable = false;
+            }
+
             if (compileState.blendState.blendEnable == false &&
-                compileState.blendState.logicOpEnable == false) {
+                compileState.blendState.logicOpEnable == false &&
+                ctx->depth_stencil->alpha.enabled == 0) {
                SwrSetBlendFunc(ctx->swrContext, target, NULL);
                continue;
             }
@@ -1308,7 +1318,12 @@ swr_update_derived(struct pipe_context *pipe,
             compileState.desc.alphaTestEnable =
                ctx->depth_stencil->alpha.enabled;
             compileState.desc.independentAlphaBlendEnable =
-               ctx->blend->pipe.independent_blend_enable;
+               (compileState.blendState.sourceBlendFactor !=
+                compileState.blendState.sourceAlphaBlendFactor) ||
+               (compileState.blendState.destBlendFactor !=
+                compileState.blendState.destAlphaBlendFactor) ||
+               (compileState.blendState.colorBlendFunc !=
+                compileState.blendState.alphaBlendFunc);
             compileState.desc.alphaToCoverageEnable =
                ctx->blend->pipe.alpha_to_coverage;
             compileState.desc.sampleMaskEnable = 0; // XXX
@@ -1318,6 +1333,8 @@ swr_update_derived(struct pipe_context *pipe,
                swr_convert_depth_func(ctx->depth_stencil->alpha.func);
             compileState.alphaTestFormat = ALPHA_TEST_FLOAT32; // xxx
 
+            compileState.Canonicalize();
+            
             PFN_BLEND_JIT_FUNC func = NULL;
             auto search = ctx->blendJIT->find(compileState);
             if (search != ctx->blendJIT->end()) {