OSDN Git Service

Fixed default color values for R and RG types
authorAlexis Hetu <sugoi@google.com>
Fri, 21 Jul 2017 15:41:13 +0000 (11:41 -0400)
committerAlexis Hétu <sugoi@google.com>
Fri, 21 Jul 2017 15:50:35 +0000 (15:50 +0000)
By default, in D3D, R, G or B channels default to 1 when no
value is assigned to them. In OpenGL, these channels default
to 0. Added an entry to Conventions to fix this issue.

In dEQP, this fixes all R and RG types tests from:
functional.texture.format.*

Change-Id: Ib5552aa36eaf4e3e1132f016f002250b40436227
Reviewed-on: https://swiftshader-review.googlesource.com/10828
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/Renderer/Context.cpp
src/Renderer/Renderer.cpp
src/Renderer/Renderer.hpp
src/Shader/SamplerCore.cpp

index caa4592..e5ee4dc 100644 (file)
@@ -33,6 +33,7 @@ namespace sw
        bool fullPixelPositionRegister = false;
        bool leadingVertexFirst = false;         // Flat shading uses first vertex, else last
        bool secondaryColor = false;             // Specular lighting is applied after texturing
+       bool colorsDefaultToZero = false;
 
        bool forceWindowed = false;
        bool quadLayoutEnabled = false;
index a67ba22..7afbb9f 100644 (file)
@@ -48,6 +48,7 @@ namespace sw
        extern bool fullPixelPositionRegister;
        extern bool leadingVertexFirst;         // Flat shading uses first vertex, else last
        extern bool secondaryColor;             // Specular lighting is applied after texturing
+       extern bool colorsDefaultToZero;
 
        extern bool forceWindowed;
        extern bool complementaryDepthBuffer;
@@ -110,6 +111,7 @@ namespace sw
                sw::fullPixelPositionRegister = conventions.fullPixelPositionRegister;
                sw::leadingVertexFirst = conventions.leadingVertexFirst;
                sw::secondaryColor = conventions.secondaryColor;
+               sw::colorsDefaultToZero = conventions.colorsDefaultToZero;
                sw::exactColorRounding = exactColorRounding;
 
                setRenderTarget(0, 0);
index c29020f..dedd17a 100644 (file)
@@ -65,6 +65,7 @@ namespace sw
                bool fullPixelPositionRegister;
                bool leadingVertexFirst;
                bool secondaryColor;
+               bool colorsDefaultToZero;
        };
 
        static const Conventions OpenGL =
@@ -74,7 +75,8 @@ namespace sw
                true,    // booleanFaceRegister
                true,    // fullPixelPositionRegister
                false,   // leadingVertexFirst
-               false    // secondaryColor
+               false,   // secondaryColor
+               true,    // colorsDefaultToZero
        };
 
        static const Conventions Direct3D =
@@ -85,6 +87,7 @@ namespace sw
                false,   // fullPixelPositionRegister
                true,    // leadingVertexFirst
                true,    // secondardyColor
+               false,   // colorsDefaultToZero
        };
 
        struct Query
index f0d482f..0ee9014 100644 (file)
@@ -50,6 +50,8 @@ namespace
 
 namespace sw
 {
+       extern bool colorsDefaultToZero;
+
        SamplerCore::SamplerCore(Pointer<Byte> &constants, const Sampler::State &state) : constants(constants), state(state)
        {
        }
@@ -186,6 +188,7 @@ namespace sw
                        if(fixed12 && state.textureFilter != FILTER_GATHER)
                        {
                                int componentCount = textureComponentCount();
+                               short defaultColorValue = colorsDefaultToZero ? 0x0000 : 0x1000;
 
                                switch(state.textureFormat)
                                {
@@ -237,8 +240,8 @@ namespace sw
                                case FORMAT_YV12_BT601:
                                case FORMAT_YV12_BT709:
                                case FORMAT_YV12_JFIF:
-                                       if(componentCount < 2) c.y = Short4(0x1000);
-                                       if(componentCount < 3) c.z = Short4(0x1000);
+                                       if(componentCount < 2) c.y = Short4(defaultColorValue);
+                                       if(componentCount < 3) c.z = Short4(defaultColorValue);
                                        if(componentCount < 4) c.w = Short4(0x1000);
                                        break;
                                case FORMAT_A8:
@@ -259,9 +262,9 @@ namespace sw
                                        c.z = c.x;
                                        break;
                                case FORMAT_R32F:
-                                       c.y = Short4(0x1000);
+                                       c.y = Short4(defaultColorValue);
                                case FORMAT_G32R32F:
-                                       c.z = Short4(0x1000);
+                                       c.z = Short4(defaultColorValue);
                                case FORMAT_X32B32G32R32F:
                                        c.w = Short4(0x1000);
                                case FORMAT_A32B32G32R32F:
@@ -438,6 +441,7 @@ namespace sw
                        }
 
                        int componentCount = textureComponentCount();
+                       float defaultColorValue = colorsDefaultToZero ? 0.0f : 1.0f;
 
                        if(state.textureFilter != FILTER_GATHER)
                        {
@@ -495,8 +499,8 @@ namespace sw
                                case FORMAT_YV12_BT601:
                                case FORMAT_YV12_BT709:
                                case FORMAT_YV12_JFIF:
-                                       if(componentCount < 2) c.y = Float4(1.0f);
-                                       if(componentCount < 3) c.z = Float4(1.0f);
+                                       if(componentCount < 2) c.y = Float4(defaultColorValue);
+                                       if(componentCount < 3) c.z = Float4(defaultColorValue);
                                        if(componentCount < 4) c.w = Float4(1.0f);
                                        break;
                                case FORMAT_A8:
@@ -517,9 +521,9 @@ namespace sw
                                        c.z = c.x;
                                        break;
                                case FORMAT_R32F:
-                                       c.y = Float4(1.0f);
+                                       c.y = Float4(defaultColorValue);
                                case FORMAT_G32R32F:
-                                       c.z = Float4(1.0f);
+                                       c.z = Float4(defaultColorValue);
                                case FORMAT_X32B32G32R32F:
                                        c.w = Float4(1.0f);
                                case FORMAT_A32B32G32R32F: