Make high precision filtering a build flag

The Vulkan extension used for this is not registered.  The functionality
is only used by Chromium, and so is turned into a build flag.

This avoids having to register this extension with dubious arguments;
it's only there to satisfy Chrome's stringent tests.

Bug: chromium:726075
Change-Id: I6441135ae5280e935ce5d2a81b37ea47a7f0ccdf
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/72708
Presubmit-Ready: Shahbaz Youssefi <syoussefi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
diff --git a/src/Pipeline/SpirvShaderSampling.cpp b/src/Pipeline/SpirvShaderSampling.cpp
index 5225a79..47ce57b 100644
--- a/src/Pipeline/SpirvShaderSampling.cpp
+++ b/src/Pipeline/SpirvShaderSampling.cpp
@@ -66,7 +66,7 @@
 			samplerState.customBorder = vkSamplerState->customBorderColor;
 
 			samplerState.mipmapFilter = convertMipmapMode(vkSamplerState);
-			samplerState.highPrecisionFiltering = (vkSamplerState->filteringPrecision == VK_SAMPLER_FILTERING_PRECISION_MODE_HIGH_GOOGLE);
+			samplerState.highPrecisionFiltering = vkSamplerState->highPrecisionFiltering;
 
 			samplerState.compareEnable = (vkSamplerState->compareEnable != VK_FALSE);
 			samplerState.compareOp = vkSamplerState->compareOp;
diff --git a/src/Vulkan/BUILD.gn b/src/Vulkan/BUILD.gn
index 5556abd..81ba736 100644
--- a/src/Vulkan/BUILD.gn
+++ b/src/Vulkan/BUILD.gn
@@ -12,18 +12,16 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build/config/ozone.gni")
 import("//build_overrides/build.gni")
 import("//build_overrides/wayland.gni")
-import("//build/config/ozone.gni")
 import("../swiftshader.gni")
 import("vulkan.gni")
 
 # Need a separate config to ensure the warnings are added to the end.
 config("swiftshader_libvulkan_private_config") {
   if (is_linux) {
-    defines = [
-      "VK_EXPORT=__attribute__((visibility(\"default\")))",
-    ]
+    defines = [ "VK_EXPORT=__attribute__((visibility(\"default\")))" ]
     if (ozone_platform_x11) {
       defines += [ "VK_USE_PLATFORM_XCB_KHR" ]
     }
@@ -31,9 +29,7 @@
       defines += [ "VK_USE_PLATFORM_WAYLAND_KHR" ]
     }
   } else if (is_chromeos) {
-    defines = [
-      "VK_EXPORT=__attribute__((visibility(\"default\")))",
-    ]
+    defines = [ "VK_EXPORT=__attribute__((visibility(\"default\")))" ]
   } else if (is_fuchsia) {
     defines = [
       "VK_USE_PLATFORM_FUCHSIA=1",
@@ -62,10 +58,16 @@
   }
 
   defines += [
-     "SWIFTSHADER_ENABLE_ASTC",  # TODO(b/150130101)
-     "SWIFTSHADER_LEGACY_PRECISION=true",  # TODO(chromium:1299047)
-     "SWIFTSHADER_ZERO_INITIALIZE_DEVICE_MEMORY",
+    "SWIFTSHADER_ENABLE_ASTC",  # TODO(b/150130101)
+    "SWIFTSHADER_LEGACY_PRECISION=true",  # TODO(chromium:1299047)
+    "SWIFTSHADER_ZERO_INITIALIZE_DEVICE_MEMORY",
   ]
+
+  if (build_with_chromium) {
+    # Chromium requires higher precision filtering to pass the layout tests with SwiftShader.
+    # http://crbug.com/726075
+    defines += [ "SWIFTSHADER_HIGH_PRECISION_FILTERING" ]
+  }
 }
 
 swiftshader_source_set("swiftshader_libvulkan_headers") {
@@ -118,9 +120,7 @@
       "VkSemaphoreExternalLinux.hpp",
     ]
   } else if (is_mac) {
-    sources += [
-      "VkDeviceMemoryExternalMac.hpp",
-    ]
+    sources += [ "VkDeviceMemoryExternalMac.hpp" ]
   } else if (is_fuchsia) {
     sources += [ "VkSemaphoreExternalFuchsia.hpp" ]
   }
@@ -195,21 +195,20 @@
           rebase_path("vk_swiftshader.exports", root_build_dir),
     ]
   } else if (is_linux || is_chromeos || is_fuchsia) {
-    inputs = [
-      "vk_swiftshader.lds",
-    ]
+    inputs = [ "vk_swiftshader.lds" ]
     ldflags = [
       # -Bsymbolic binds symbol references to their global definitions within
       # a shared object, thereby preventing symbol preemption.
       "-Wl,-Bsymbolic",
       "-Wl,--version-script=" +
-          rebase_path("vk_swiftshader.lds", root_build_dir) ]
+          rebase_path("vk_swiftshader.lds", root_build_dir),
+    ]
   }
 
   deps = [
+    "../../third_party/SPIRV-Tools:spvtools_headers",
     "../../third_party/SPIRV-Tools:spvtools_opt",
     "../../third_party/SPIRV-Tools:spvtools_val",
-    "../../third_party/SPIRV-Tools:spvtools_headers",
     "../../third_party/marl:Marl",
     "../Device",
     "../Pipeline",
@@ -225,9 +224,7 @@
     "../../third_party/SPIRV-Headers/include",
   ]
 
-  public_deps = [
-    ":swiftshader_libvulkan_headers",
-  ]
+  public_deps = [ ":swiftshader_libvulkan_headers" ]
 }
 
 # Generates an ICD JSON file that can be used by all targets in this GN build
@@ -256,14 +253,8 @@
     library_path,
   ]
 
-  inputs = [
-    input_file,
-  ]
-  outputs = [
-    output_icd_file,
-  ]
+  inputs = [ input_file ]
+  outputs = [ output_icd_file ]
 
-  deps = [
-    ":swiftshader_libvulkan",
-  ]
+  deps = [ ":swiftshader_libvulkan" ]
 }
diff --git a/src/Vulkan/VkSampler.cpp b/src/Vulkan/VkSampler.cpp
index 1458fa3..0458f0a 100644
--- a/src/Vulkan/VkSampler.cpp
+++ b/src/Vulkan/VkSampler.cpp
@@ -17,7 +17,7 @@
 namespace vk {
 
 SamplerState::SamplerState(const VkSamplerCreateInfo *pCreateInfo, const vk::SamplerYcbcrConversion *ycbcrConversion,
-                           VkSamplerFilteringPrecisionModeGOOGLE filteringPrecision, const VkClearColorValue &customBorderColor)
+                           const VkClearColorValue &customBorderColor)
     : Memset(this, 0)
     , magFilter(pCreateInfo->magFilter)
     , minFilter(pCreateInfo->minFilter)
@@ -35,7 +35,9 @@
     , borderColor(pCreateInfo->borderColor)
     , customBorderColor(customBorderColor)
     , unnormalizedCoordinates(pCreateInfo->unnormalizedCoordinates)
-    , filteringPrecision(filteringPrecision)
+#ifdef SWIFTSHADER_HIGH_PRECISION_FILTERING
+    , highPrecisionFiltering(true)
+#endif
 {
 	if(ycbcrConversion)
 	{
diff --git a/src/Vulkan/VkSampler.hpp b/src/Vulkan/VkSampler.hpp
index 8684188..4a627c1 100644
--- a/src/Vulkan/VkSampler.hpp
+++ b/src/Vulkan/VkSampler.hpp
@@ -27,7 +27,7 @@
 struct SamplerState : sw::Memset<SamplerState>
 {
 	SamplerState(const VkSamplerCreateInfo *pCreateInfo, const vk::SamplerYcbcrConversion *ycbcrConversion,
-	             VkSamplerFilteringPrecisionModeGOOGLE filteringPrecision, const VkClearColorValue &customBorderColor);
+	             const VkClearColorValue &customBorderColor);
 
 	// Prevents accessing mipmap levels out of range.
 	static float ClampLod(float lod)
@@ -53,7 +53,7 @@
 	const VkBool32 unnormalizedCoordinates = VK_FALSE;
 
 	VkSamplerYcbcrModelConversion ycbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY;
-	const VkSamplerFilteringPrecisionModeGOOGLE filteringPrecision = VK_SAMPLER_FILTERING_PRECISION_MODE_LOW_GOOGLE;
+	const bool highPrecisionFiltering = false;
 	bool studioSwing = false;    // Narrow range
 	bool swappedChroma = false;  // Cb/Cr components in reverse order
 };
@@ -115,4 +115,4 @@
 
 }  // namespace vk
 
-#endif  // VK_SAMPLER_HPP_
\ No newline at end of file
+#endif  // VK_SAMPLER_HPP_
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp
index 626499e..4d9a94d 100644
--- a/src/Vulkan/libVulkan.cpp
+++ b/src/Vulkan/libVulkan.cpp
@@ -2485,7 +2485,6 @@
 
 	const VkBaseInStructure *extensionCreateInfo = reinterpret_cast<const VkBaseInStructure *>(pCreateInfo->pNext);
 	const vk::SamplerYcbcrConversion *ycbcrConversion = nullptr;
-	VkSamplerFilteringPrecisionModeGOOGLE filteringPrecision = VK_SAMPLER_FILTERING_PRECISION_MODE_LOW_GOOGLE;
 	VkClearColorValue borderColor = {};
 
 	while(extensionCreateInfo)
@@ -2501,11 +2500,7 @@
 			break;
 #if !defined(__ANDROID__)
 		case VK_STRUCTURE_TYPE_SAMPLER_FILTERING_PRECISION_GOOGLE:
-			{
-				const VkSamplerFilteringPrecisionGOOGLE *filteringInfo =
-				    reinterpret_cast<const VkSamplerFilteringPrecisionGOOGLE *>(extensionCreateInfo);
-				filteringPrecision = filteringInfo->samplerFilteringPrecisionMode;
-			}
+			// Ignore. Deprecated.
 			break;
 #endif
 		case VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT:
@@ -2524,7 +2519,7 @@
 		extensionCreateInfo = extensionCreateInfo->pNext;
 	}
 
-	vk::SamplerState samplerState(pCreateInfo, ycbcrConversion, filteringPrecision, borderColor);
+	vk::SamplerState samplerState(pCreateInfo, ycbcrConversion, borderColor);
 	uint32_t samplerID = vk::Cast(device)->indexSampler(samplerState);
 
 	VkResult result = vk::Sampler::Create(pAllocator, pCreateInfo, pSampler, samplerState, samplerID);