swr: [rasterizer jitter] canonicalize blend compile state
authorTim Rowley <timothy.o.rowley@intel.com>
Fri, 30 Sep 2016 20:18:13 +0000 (15:18 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Mon, 3 Oct 2016 14:57:31 +0000 (09:57 -0500)
Canonicalize to prevent unnecessary JIT compiles.

Signed-off-by: Tim Rowley <timothy.o.rowley@intel.com>
src/gallium/drivers/swr/rasterizer/jitter/blend_jit.h
src/gallium/drivers/swr/swr_state.cpp

index af317cc5fe3371a3216102981249c9a30e554d8d..ddb7374d406d0f915b6ea7e11fd0eae88f7215e9 100644 (file)
@@ -89,4 +89,41 @@ struct BLEND_COMPILE_STATE
     {
         return memcmp(this, &other, sizeof(BLEND_COMPILE_STATE)) == 0;
     }
+
+    // Canonicalize state to reduce unnecessary JIT compiles
+    void Canonicalize()
+    {
+        if (!desc.alphaTestEnable)
+        {
+            alphaTestFormat = (ALPHA_TEST_FORMAT)0;
+            alphaTestFunction = (SWR_ZFUNCTION)0;
+        }
+
+        if (!blendState.blendEnable)
+        {
+            blendState.sourceAlphaBlendFactor = (SWR_BLEND_FACTOR)0;
+            blendState.destAlphaBlendFactor = (SWR_BLEND_FACTOR)0;
+            blendState.sourceBlendFactor = (SWR_BLEND_FACTOR)0;
+            blendState.destBlendFactor = (SWR_BLEND_FACTOR)0;
+            blendState.colorBlendFunc = (SWR_BLEND_OP)0;
+            blendState.alphaBlendFunc = (SWR_BLEND_OP)0;
+        }
+
+        if (!blendState.logicOpEnable)
+        {
+            blendState.logicOpFunc = (SWR_LOGIC_OP)0;
+        }
+
+        if (!blendState.blendEnable && !blendState.logicOpEnable)
+        {
+            format = (SWR_FORMAT)0;
+        }
+
+        if (!desc.independentAlphaBlendEnable)
+        {
+            blendState.sourceAlphaBlendFactor = (SWR_BLEND_FACTOR)0;
+            blendState.destAlphaBlendFactor = (SWR_BLEND_FACTOR)0;
+            blendState.alphaBlendFunc = (SWR_BLEND_OP)0;
+        }
+    }
 };
index 7d49ce7b896f5de367c3a940ef7be7cd0d7c6bd8..3e023225433bc0eba2155068fe5f266eb6928ce5 100644 (file)
@@ -1318,6 +1318,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()) {