Regres: Skip the Vulkan Loader

Previously we relied on setting VK_ICD_FILENAMES to point the system's
Vulkan Loader library (libvulkan.so.1) to SwiftShader's ICD. This change
makes Regres directly load SwiftShader's build of the libvulkan.so.1
library, which exports all of the API entry functions too. Loading of
Vulkan Layers is not supported by it.

This has the advantage of not depending on the version of the Vulkan
Loader, which can affect Regres' test results. The system running
Regres doesn't even require having a Vulkan Loader at all this way.
It is also measurably faster.

The compromise is that it currently causes 1 test to fail:
dEQP-VK.api.version_check.entry_points, due to the lack of support for
loading layers. Note that implicitly loaded layers could also affect the
Regres results, so this isn't necessarily a bad thing.

We also wouldn't be alerted if changes broke the compatibility of our
ICD with the Vulkan Loader. This is unlikely to happen though if tests
that are being run during development (e.g. using Cherry) are set up to
use the Vulkan Loader, especially when touching code that affects this
interface. In addition, downstream tests (e.g. Chromium) would quickly
detect any bugs that slip through.

Note that this change works by appending the LD_LIBRARY_PATH with the
path to SwiftShader's libvulkan.so.1, not prepending it, so one can
still point LD_LIBRARY_PATH to a Vulkan Loader library and not have it
being skipped.

Bug: b/200679975
Change-Id: I0ba2dd06fa1ca0749e852b1dc62955199f61c6b3
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/57348
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Sean Risser <srisser@google.com>
diff --git a/docs/Regres.md b/docs/Regres.md
index 2f3f900..abe5d93 100644
--- a/docs/Regres.md
+++ b/docs/Regres.md
@@ -195,6 +195,21 @@
 dEQP used are dictated by the change being tested, and so both used as part of
 the cache key.
 
+### Vulkan Loader usage
+
+Applications make use of the Vulkan API by loading the [Vulkan Loader](https://github.com/KhronosGroup/Vulkan-Loader)
+library (`libvulkan.so.1` on Linux), which enumerates available Vulkan
+implementations (typically GPUs and their drivers) before an actual 'instance'
+is created to communicate with a specific Installable Client Driver (ICD).
+
+However, SwiftShader can build into libvulkan.so.1 itself, which implements the
+same API entry functions as the Vulkan Loader. Regres by default will make dEQP
+load this SwiftShader library instead of the system's Vulkan Loader. It ensures
+test results are independent of the system's Vulkan setup.
+
+To override this, one can set LD_LIBRARY_PATH to point to the location of a
+Loader's libvulkan.so.1.
+
 ### Code coverage
 
 The [daily run](#daily-run-continuous-integration-testing) produces code
diff --git a/tests/regres/cmd/regres/main.go b/tests/regres/cmd/regres/main.go
index fc56cfb..e2be34f 100644
--- a/tests/regres/cmd/regres/main.go
+++ b/tests/regres/cmd/regres/main.go
@@ -1166,6 +1166,10 @@
 	tempDir := filepath.Join(t.buildDir, "temp")
 	os.MkdirAll(tempDir, 0777)
 
+	// Path to SwiftShader's libvulkan.so.1, which can be loaded directly by
+	// dEQP without use of the Vulkan Loader.
+	swiftshaderLibvulkanPath := filepath.Join(t.buildDir, "Linux")
+
 	config := deqp.Config{
 		ExeEgl:    filepath.Join(d.path, "build", "modules", "egl", "deqp-egl"),
 		ExeGles2:  filepath.Join(d.path, "build", "modules", "gles2", "deqp-gles2"),
@@ -1174,7 +1178,7 @@
 		TempDir:   tempDir,
 		TestLists: testLists,
 		Env: []string{
-			"LD_LIBRARY_PATH=" + t.buildDir + ":" + os.Getenv("LD_LIBRARY_PATH"),
+			"LD_LIBRARY_PATH=" + os.Getenv("LD_LIBRARY_PATH") + ":" + swiftshaderLibvulkanPath,
 			"VK_ICD_FILENAMES=" + swiftshaderICDJSON,
 			"DISPLAY=" + os.Getenv("DISPLAY"),
 			"LIBC_FATAL_STDERR_=1", // Put libc explosions into logs.