Mesa (master): radv: implement a dummy winsys for creating devices without AMDGPU

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Feb 26 07:56:26 UTC 2020


Module: Mesa
Branch: master
Commit: cd6ec2b1abbd96f4456e92613c2232c919bb9023
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cd6ec2b1abbd96f4456e92613c2232c919bb9023

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Mon Feb 17 14:45:47 2020 +0100

radv: implement a dummy winsys for creating devices without AMDGPU

To allow developers to test the compiler backends without having
any AMD GPUs. To create a null device, set eg.
RADV_FORCE_FAMILY=polaris10 in your environment.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3872>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3872>

---

 docs/envvars.html                                  |   2 -
 src/amd/vulkan/Makefile.sources                    |  12 +-
 src/amd/vulkan/meson.build                         |   6 +
 src/amd/vulkan/radv_debug.h                        |   1 -
 src/amd/vulkan/radv_device.c                       | 120 ++++++++---------
 src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c      |   3 -
 src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c  |   1 -
 src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h  |   1 -
 .../winsys/amdgpu/radv_amdgpu_winsys_public.h      |   2 +
 src/amd/vulkan/winsys/null/radv_null_bo.c          |  79 +++++++++++
 src/amd/vulkan/winsys/null/radv_null_bo.h          |  47 +++++++
 src/amd/vulkan/winsys/null/radv_null_cs.c          |  99 ++++++++++++++
 src/amd/vulkan/winsys/null/radv_null_cs.h          |  46 +++++++
 src/amd/vulkan/winsys/null/radv_null_winsys.c      | 146 +++++++++++++++++++++
 src/amd/vulkan/winsys/null/radv_null_winsys.h      |  47 +++++++
 .../vulkan/winsys/null/radv_null_winsys_public.h   |  33 +++++
 16 files changed, 568 insertions(+), 77 deletions(-)

diff --git a/docs/envvars.html b/docs/envvars.html
index df4377209eb..eacd1b604bd 100644
--- a/docs/envvars.html
+++ b/docs/envvars.html
@@ -585,8 +585,6 @@ Mesa EGL supports different sets of environment variables.  See the
    <dd>disable memory shaders cache</dd>
    <dt><code>nongg</code></dt>
    <dd>disable NGG for GFX10+</dd>
-   <dt><code>noop</code></dt>
-   <dd>do not submit any IBs</dd>
    <dt><code>nooutoforder</code></dt>
    <dd>disable out-of-order rasterization</dd>
    <dt><code>noshaderballot</code></dt>
diff --git a/src/amd/vulkan/Makefile.sources b/src/amd/vulkan/Makefile.sources
index 002f2ea1ebe..4b1bca2d879 100644
--- a/src/amd/vulkan/Makefile.sources
+++ b/src/amd/vulkan/Makefile.sources
@@ -30,6 +30,15 @@ RADV_WS_AMDGPU_FILES := \
 	winsys/amdgpu/radv_amdgpu_winsys.h \
 	winsys/amdgpu/radv_amdgpu_winsys_public.h
 
+RADV_WS_NULL_FILES := \
+	winsys/null/radv_null_bo.c \
+	winsys/null/radv_null_bo.h \
+	winsys/null/radv_null_cs.c \
+	winsys/null/radv_null_cs.h \
+	winsys/null/radv_null_winsys.c \
+	winsys/null/radv_null_winsys.h \
+	winsys/null/radv_null_winsys_public.h
+
 VULKAN_FILES := \
 	radv_cmd_buffer.c \
 	radv_cs.h \
@@ -74,7 +83,8 @@ VULKAN_FILES := \
 	radv_wsi.c \
 	si_cmd_buffer.c \
 	vk_format.h \
-	$(RADV_WS_AMDGPU_FILES)
+	$(RADV_WS_AMDGPU_FILES) \
+	$(RADV_WS_NULL_FILES)
 
 VULKAN_ANDROID_FILES := \
 	radv_android.c
diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build
index e620478a43b..bd5f6f51598 100644
--- a/src/amd/vulkan/meson.build
+++ b/src/amd/vulkan/meson.build
@@ -67,6 +67,12 @@ libradv_files = files(
   'winsys/amdgpu/radv_amdgpu_winsys.c',
   'winsys/amdgpu/radv_amdgpu_winsys.h',
   'winsys/amdgpu/radv_amdgpu_winsys_public.h',
+  'winsys/null/radv_null_bo.c',
+  'winsys/null/radv_null_bo.h',
+  'winsys/null/radv_null_cs.c',
+  'winsys/null/radv_null_cs.h',
+  'winsys/null/radv_null_winsys.c',
+  'winsys/null/radv_null_winsys_public.h',
   'radv_android.c',
   'radv_cmd_buffer.c',
   'radv_cs.h',
diff --git a/src/amd/vulkan/radv_debug.h b/src/amd/vulkan/radv_debug.h
index f7001adcee2..545eaa51caf 100644
--- a/src/amd/vulkan/radv_debug.h
+++ b/src/amd/vulkan/radv_debug.h
@@ -56,7 +56,6 @@ enum {
 	RADV_DEBUG_ALL_ENTRYPOINTS   = 0x2000000,
 	RADV_DEBUG_DUMP_META_SHADERS = 0x4000000,
 	RADV_DEBUG_NO_MEMORY_CACHE   = 0x8000000,
-	RADV_DEBUG_NOOP              = 0x10000000,
 };
 
 enum {
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index c9947592dd7..be84c2793a0 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -53,6 +53,7 @@
 #include <amdgpu.h>
 #include <amdgpu_drm.h>
 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
+#include "winsys/null/radv_null_winsys_public.h"
 #include "ac_llvm_util.h"
 #include "vk_format.h"
 #include "sid.h"
@@ -287,91 +288,63 @@ radv_physical_device_init_mem_types(struct radv_physical_device *device)
 	}
 }
 
-static void
-radv_handle_env_var_force_family(struct radv_physical_device *device)
-{
-	const char *family = getenv("RADV_FORCE_FAMILY");
-	unsigned i;
-
-	if (!family)
-		return;
-
-	for (i = CHIP_TAHITI; i < CHIP_LAST; i++) {
-		if (!strcmp(family, ac_get_llvm_processor_name(i))) {
-			/* Override family and chip_class. */
-			device->rad_info.family = i;
-			device->rad_info.name = "OVERRIDDEN";
-
-			if (i >= CHIP_NAVI10)
-				device->rad_info.chip_class = GFX10;
-			else if (i >= CHIP_VEGA10)
-				device->rad_info.chip_class = GFX9;
-			else if (i >= CHIP_TONGA)
-				device->rad_info.chip_class = GFX8;
-			else if (i >= CHIP_BONAIRE)
-				device->rad_info.chip_class = GFX7;
-			else
-				device->rad_info.chip_class = GFX6;
-
-			/* Don't submit any IBs. */
-			device->instance->debug_flags |= RADV_DEBUG_NOOP;
-			return;
-		}
-	}
-
-	fprintf(stderr, "radv: Unknown family: %s\n", family);
-	exit(1);
-}
-
 static VkResult
 radv_physical_device_init(struct radv_physical_device *device,
 			  struct radv_instance *instance,
 			  drmDevicePtr drm_device)
 {
-	const char *path = drm_device->nodes[DRM_NODE_RENDER];
 	VkResult result;
-	drmVersionPtr version;
-	int fd;
+	int fd = -1;
 	int master_fd = -1;
 
-	fd = open(path, O_RDWR | O_CLOEXEC);
-	if (fd < 0) {
-		if (instance->debug_flags & RADV_DEBUG_STARTUP)
-			radv_logi("Could not open device '%s'", path);
+	if (drm_device) {
+		const char *path = drm_device->nodes[DRM_NODE_RENDER];
+		drmVersionPtr version;
 
-		return vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
-	}
+		fd = open(path, O_RDWR | O_CLOEXEC);
+		if (fd < 0) {
+			if (instance->debug_flags & RADV_DEBUG_STARTUP)
+				radv_logi("Could not open device '%s'", path);
 
-	version = drmGetVersion(fd);
-	if (!version) {
-		close(fd);
+			return vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
+		}
 
-		if (instance->debug_flags & RADV_DEBUG_STARTUP)
-			radv_logi("Could not get the kernel driver version for device '%s'", path);
+		version = drmGetVersion(fd);
+		if (!version) {
+			close(fd);
 
-		return vk_errorf(instance, VK_ERROR_INCOMPATIBLE_DRIVER,
-				 "failed to get version %s: %m", path);
-	}
+			if (instance->debug_flags & RADV_DEBUG_STARTUP)
+				radv_logi("Could not get the kernel driver version for device '%s'", path);
+
+			return vk_errorf(instance, VK_ERROR_INCOMPATIBLE_DRIVER,
+					 "failed to get version %s: %m", path);
+		}
+
+		if (strcmp(version->name, "amdgpu")) {
+			drmFreeVersion(version);
+			close(fd);
+
+			if (instance->debug_flags & RADV_DEBUG_STARTUP)
+				radv_logi("Device '%s' is not using the amdgpu kernel driver.", path);
 
-	if (strcmp(version->name, "amdgpu")) {
+			return VK_ERROR_INCOMPATIBLE_DRIVER;
+		}
 		drmFreeVersion(version);
-		close(fd);
 
 		if (instance->debug_flags & RADV_DEBUG_STARTUP)
-			radv_logi("Device '%s' is not using the amdgpu kernel driver.", path);
-
-		return VK_ERROR_INCOMPATIBLE_DRIVER;
+				radv_logi("Found compatible device '%s'.", path);
 	}
-	drmFreeVersion(version);
-
-	if (instance->debug_flags & RADV_DEBUG_STARTUP)
-			radv_logi("Found compatible device '%s'.", path);
 
 	device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
 	device->instance = instance;
 
-	device->ws = radv_amdgpu_winsys_create(fd, instance->debug_flags,
-					       instance->perftest_flags);
+	if (drm_device) {
+		device->ws = radv_amdgpu_winsys_create(fd, instance->debug_flags,
+						       instance->perftest_flags);
+	} else {
+		device->ws = radv_null_winsys_create();
+	}
+
 	if (!device->ws) {
 		result = vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
 		goto fail;
@@ -398,8 +371,6 @@ radv_physical_device_init(struct radv_physical_device *device,
 	device->local_fd = fd;
 	device->ws->query_info(device->ws, &device->rad_info);
 
-	radv_handle_env_var_force_family(device);
-
 	device->use_aco = instance->perftest_flags & RADV_PERFTEST_ACO;
 
 	snprintf(device->name, sizeof(device->name),
@@ -468,7 +439,8 @@ radv_physical_device_init(struct radv_physical_device *device,
 	radv_physical_device_init_mem_types(device);
 	radv_fill_device_extension_table(device, &device->supported_extensions);
 
-	device->bus_info = *drm_device->businfo.pci;
+	if (drm_device)
+		device->bus_info = *drm_device->businfo.pci;
 
 	if ((device->instance->debug_flags & RADV_DEBUG_INFO))
 		ac_print_gpu_info(&device->rad_info);
@@ -560,7 +532,6 @@ static const struct debug_control radv_debug_options[] = {
 	{"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS},
 	{"metashaders", RADV_DEBUG_DUMP_META_SHADERS},
 	{"nomemorycache", RADV_DEBUG_NO_MEMORY_CACHE},
-	{"noop", RADV_DEBUG_NOOP},
 	{NULL, 0}
 };
 
@@ -796,6 +767,19 @@ radv_enumerate_devices(struct radv_instance *instance)
 
 	instance->physicalDeviceCount = 0;
 
+	if (getenv("RADV_FORCE_FAMILY")) {
+		/* When RADV_FORCE_FAMILY is set, the driver creates a nul
+		 * device that allows to test the compiler without having an
+		 * AMDGPU instance.
+		 */
+		result = radv_physical_device_init(instance->physicalDevices +
+			                           instance->physicalDeviceCount,
+			                           instance, NULL);
+
+		++instance->physicalDeviceCount;
+		return VK_SUCCESS;
+	}
+
 	max_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
 
 	if (instance->debug_flags & RADV_DEBUG_STARTUP)
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c
index c6c9de93777..299707f0c2b 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c
@@ -1235,9 +1235,6 @@ static int radv_amdgpu_winsys_cs_submit(struct radeon_winsys_ctx *_ctx,
 	struct radv_amdgpu_ctx *ctx = radv_amdgpu_ctx(_ctx);
 	int ret;
 
-	if (cs->ws->noop)
-		abort();
-
 	assert(sem_info);
 	if (!cs->ws->use_ib_bos) {
 		ret = radv_amdgpu_winsys_cs_submit_sysmem(_ctx, queue_idx, sem_info, bo_list, cs_array,
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
index bac68e9f7fc..b1d204a6d31 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
@@ -189,7 +189,6 @@ radv_amdgpu_winsys_create(int fd, uint64_t debug_flags, uint64_t perftest_flags)
 
 	ws->use_local_bos = perftest_flags & RADV_PERFTEST_LOCAL_BOS;
 	ws->zero_all_vram_allocs = debug_flags & RADV_DEBUG_ZERO_VRAM;
-	ws->noop = debug_flags & RADV_DEBUG_NOOP;
 	list_inithead(&ws->global_bo_list);
 	pthread_mutex_init(&ws->global_bo_list_lock, NULL);
 	ws->base.query_info = radv_amdgpu_winsys_query_info;
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
index 1178600384d..8cbac290043 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
@@ -47,7 +47,6 @@ struct radv_amdgpu_winsys {
 	bool use_ib_bos;
 	bool zero_all_vram_allocs;
 	bool use_local_bos;
-	bool noop;
 	unsigned num_buffers;
 
 	pthread_mutex_t global_bo_list_lock;
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys_public.h b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys_public.h
index 709669b2a57..e8b8298c6c8 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys_public.h
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys_public.h
@@ -39,4 +39,6 @@
 struct radeon_winsys *radv_amdgpu_winsys_create(int fd, uint64_t debug_flags,
 						uint64_t perftest_flags);
 
+struct radeon_winsys *radv_dummy_winsys_create(void);
+
 #endif /* RADV_AMDGPU_WINSYS_PUBLIC_H */
diff --git a/src/amd/vulkan/winsys/null/radv_null_bo.c b/src/amd/vulkan/winsys/null/radv_null_bo.c
new file mode 100644
index 00000000000..02aad5f2ea4
--- /dev/null
+++ b/src/amd/vulkan/winsys/null/radv_null_bo.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright © 2020 Valve Corporation
+ *
+ * based on amdgpu winsys.
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "radv_null_bo.h"
+
+static struct radeon_winsys_bo *
+radv_null_winsys_bo_create(struct radeon_winsys *_ws,
+			   uint64_t size,
+			   unsigned alignment,
+			   enum radeon_bo_domain initial_domain,
+			   unsigned flags,
+			   unsigned priority)
+{
+	struct radv_null_winsys_bo *bo;
+
+	bo = CALLOC_STRUCT(radv_null_winsys_bo);
+	if (!bo)
+		return NULL;
+
+	bo->ptr = malloc(size);
+	if (!bo->ptr)
+		goto error_ptr_alloc;
+
+	return (struct radeon_winsys_bo *)bo;
+error_ptr_alloc:
+	FREE(bo);
+	return NULL;
+}
+
+static void *
+radv_null_winsys_bo_map(struct radeon_winsys_bo *_bo)
+{
+	struct radv_null_winsys_bo *bo = radv_null_winsys_bo(_bo);
+	return bo->ptr;
+}
+
+static void
+radv_null_winsys_bo_unmap(struct radeon_winsys_bo *_bo)
+{
+}
+
+static void radv_null_winsys_bo_destroy(struct radeon_winsys_bo *_bo)
+{
+	struct radv_null_winsys_bo *bo = radv_null_winsys_bo(_bo);
+	FREE(bo->ptr);
+	FREE(bo);
+}
+
+void radv_null_bo_init_functions(struct radv_null_winsys *ws)
+{
+	ws->base.buffer_create = radv_null_winsys_bo_create;
+	ws->base.buffer_destroy = radv_null_winsys_bo_destroy;
+	ws->base.buffer_map = radv_null_winsys_bo_map;
+	ws->base.buffer_unmap = radv_null_winsys_bo_unmap;
+}
diff --git a/src/amd/vulkan/winsys/null/radv_null_bo.h b/src/amd/vulkan/winsys/null/radv_null_bo.h
new file mode 100644
index 00000000000..2f2f8b711d6
--- /dev/null
+++ b/src/amd/vulkan/winsys/null/radv_null_bo.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2020 Valve Corporation
+ *
+ * based on amdgpu winsys.
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef RADV_NULL_BO_H
+#define RADV_NULL_BO_H
+
+#include "radv_null_winsys.h"
+
+struct radv_null_winsys_bo {
+	struct radeon_winsys_bo base;
+	struct radv_null_winsys *ws;
+	void *ptr;
+};
+
+static inline
+struct radv_null_winsys_bo *radv_null_winsys_bo(struct radeon_winsys_bo *bo)
+{
+	return (struct radv_null_winsys_bo *)bo;
+}
+
+void radv_null_bo_init_functions(struct radv_null_winsys *ws);
+
+#endif /* RADV_NULL_BO_H */
diff --git a/src/amd/vulkan/winsys/null/radv_null_cs.c b/src/amd/vulkan/winsys/null/radv_null_cs.c
new file mode 100644
index 00000000000..ebf3395bf30
--- /dev/null
+++ b/src/amd/vulkan/winsys/null/radv_null_cs.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright © 2020 Valve Corporation
+ *
+ * based on amdgpu winsys.
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "radv_null_cs.h"
+
+struct radv_null_cs {
+	struct radeon_cmdbuf base;
+	struct radv_null_winsys *ws;
+};
+
+static inline struct radv_null_cs *
+radv_null_cs(struct radeon_cmdbuf *base)
+{
+	return (struct radv_null_cs*)base;
+}
+
+static struct radeon_winsys_ctx *radv_null_ctx_create(struct radeon_winsys *_ws,
+						      enum radeon_ctx_priority priority)
+{
+	struct radv_null_ctx *ctx = CALLOC_STRUCT(radv_null_ctx);
+
+	if (!ctx)
+		return NULL;
+
+	return (struct radeon_winsys_ctx *)ctx;
+
+}
+
+static void radv_null_ctx_destroy(struct radeon_winsys_ctx *rwctx)
+{
+	struct radv_null_ctx *ctx = (struct radv_null_ctx *)rwctx;
+	FREE(ctx);
+}
+
+static struct radeon_cmdbuf *
+radv_null_cs_create(struct radeon_winsys *ws,
+		    enum ring_type ring_type)
+{
+	struct radv_null_cs *cs = calloc(1, sizeof(struct radv_null_cs));
+	if (!cs)
+		return NULL;
+
+	cs->ws = radv_null_winsys(ws);
+
+	cs->base.buf = malloc(16384);
+	cs->base.max_dw = 4096;
+	if (!cs->base.buf) {
+		FREE(cs);
+		return NULL;
+	}
+
+	return &cs->base;
+}
+
+static bool radv_null_cs_finalize(struct radeon_cmdbuf *_cs)
+{
+	return true;
+}
+
+static void radv_null_cs_destroy(struct radeon_cmdbuf *rcs)
+{
+	struct radv_null_cs *cs = radv_null_cs(rcs);
+	FREE(cs->base.buf);
+	FREE(cs);
+}
+
+void radv_null_cs_init_functions(struct radv_null_winsys *ws)
+{
+	ws->base.ctx_create = radv_null_ctx_create;
+	ws->base.ctx_destroy = radv_null_ctx_destroy;
+	ws->base.cs_create = radv_null_cs_create;
+	ws->base.cs_finalize = radv_null_cs_finalize;
+	ws->base.cs_destroy = radv_null_cs_destroy;
+
+}
diff --git a/src/amd/vulkan/winsys/null/radv_null_cs.h b/src/amd/vulkan/winsys/null/radv_null_cs.h
new file mode 100644
index 00000000000..344e9502ff6
--- /dev/null
+++ b/src/amd/vulkan/winsys/null/radv_null_cs.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2020 Valve Corporation
+ *
+ * based on amdgpu winsys.
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef RADV_NULL_CS_H
+#define RADV_NULL_CS_H
+
+#include "radv_radeon_winsys.h"
+#include "radv_null_winsys.h"
+
+struct radv_null_ctx {
+	struct radv_null_winsys *ws;
+};
+
+static inline struct radv_null_ctx *
+radv_null_ctx(struct radeon_winsys_ctx *base)
+{
+	return (struct radv_null_ctx *)base;
+}
+
+void radv_null_cs_init_functions(struct radv_null_winsys *ws);
+
+#endif /* RADV_NULL_CS_H */
diff --git a/src/amd/vulkan/winsys/null/radv_null_winsys.c b/src/amd/vulkan/winsys/null/radv_null_winsys.c
new file mode 100644
index 00000000000..105402144da
--- /dev/null
+++ b/src/amd/vulkan/winsys/null/radv_null_winsys.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright © 2020 Valve Corporation
+ *
+ * based on amdgpu winsys.
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+#include "radv_null_winsys_public.h"
+
+#include "radv_null_bo.h"
+#include "radv_null_cs.h"
+
+#include "ac_llvm_util.h"
+
+/* Hardcode some PCI IDs to allow external tools to recognize chips. */
+static const struct {
+	enum radeon_family family;
+	uint32_t pci_id;
+} pci_ids[] = {
+	{ CHIP_TAHITI, 0x6780 },
+	{ CHIP_PITCAIRN, 0x6800 },
+	{ CHIP_VERDE, 0x6820 },
+	{ CHIP_OLAND, 0x6060 },
+	{ CHIP_HAINAN, 0x6660 },
+	{ CHIP_BONAIRE, 0x6640 },
+	{ CHIP_KAVERI, 0x1304 },
+	{ CHIP_KABINI, 0x9830 },
+	{ CHIP_HAWAII, 0x67A0 },
+	{ CHIP_TONGA, 0x6920 },
+	{ CHIP_ICELAND, 0x6900 },
+	{ CHIP_CARRIZO, 0x9870 },
+	{ CHIP_FIJI, 0x7300 },
+	{ CHIP_STONEY, 0x98E4 },
+	{ CHIP_POLARIS10, 0x67C0 },
+	{ CHIP_POLARIS11, 0x67E0 },
+	{ CHIP_POLARIS12, 0x6980 },
+	{ CHIP_VEGAM, 0x694C },
+	{ CHIP_VEGA12, 0x6860 },
+	{ CHIP_VEGA12, 0x69A0 },
+	{ CHIP_VEGA20, 0x66A0 },
+	{ CHIP_RAVEN, 0x15DD },
+	{ CHIP_RENOIR, 0x1636 },
+	{ CHIP_ARCTURUS, 0x738C },
+	{ CHIP_NAVI10, 0x7310 },
+	{ CHIP_NAVI12, 0x7360 },
+	{ CHIP_NAVI14, 0x7340 },
+};
+
+static uint32_t
+radv_null_winsys_get_pci_id(enum radeon_family family)
+{
+	for (unsigned i = 0; i < ARRAY_SIZE(pci_ids); i++) {
+		if (pci_ids[i].family == family)
+			return pci_ids[i].pci_id;
+	}
+	return 0;
+}
+
+static void radv_null_winsys_query_info(struct radeon_winsys *rws,
+					struct radeon_info *info)
+{
+	const char *family = getenv("RADV_FORCE_FAMILY");
+	unsigned i;
+
+	info->chip_class = CLASS_UNKNOWN;
+	info->family = CHIP_UNKNOWN;
+
+	for (i = CHIP_TAHITI; i < CHIP_LAST; i++) {
+		if (!strcmp(family, ac_get_llvm_processor_name(i))) {
+			/* Override family and chip_class. */
+			info->family = i;
+			info->name = "OVERRIDDEN";
+
+			if (i >= CHIP_NAVI10)
+				info->chip_class = GFX10;
+			else if (i >= CHIP_VEGA10)
+				info->chip_class = GFX9;
+			else if (i >= CHIP_TONGA)
+				info->chip_class = GFX8;
+			else if (i >= CHIP_BONAIRE)
+				info->chip_class = GFX7;
+			else
+				info->chip_class = GFX6;
+		}
+	}
+
+	if (info->family == CHIP_UNKNOWN) {
+		fprintf(stderr, "radv: Unknown family: %s\n", family);
+		abort();
+	}
+
+	info->pci_id = radv_null_winsys_get_pci_id(info->family);
+	info->max_se = 4;
+	info->max_wave64_per_simd = info->family >= CHIP_POLARIS10 &&
+				    info->family <= CHIP_VEGAM ? 8 : 10;
+
+	if (info->chip_class >= GFX10)
+		info->num_physical_sgprs_per_simd = 128 * info->max_wave64_per_simd * 2;
+	else if (info->chip_class >= GFX8)
+		info->num_physical_sgprs_per_simd = 800;
+	else
+		info->num_physical_sgprs_per_simd = 512;
+
+	info->num_physical_wave64_vgprs_per_simd = info->chip_class >= GFX10 ? 512 : 256;
+}
+
+static void radv_null_winsys_destroy(struct radeon_winsys *rws)
+{
+	FREE(rws);
+}
+
+struct radeon_winsys *
+radv_null_winsys_create()
+{
+	struct radv_null_winsys *ws;
+
+	ws = calloc(1, sizeof(struct radv_null_winsys));
+	if (!ws)
+		return NULL;
+
+	ws->base.destroy = radv_null_winsys_destroy;
+	ws->base.query_info = radv_null_winsys_query_info;
+	radv_null_bo_init_functions(ws);
+	radv_null_cs_init_functions(ws);
+
+	return &ws->base;
+}
diff --git a/src/amd/vulkan/winsys/null/radv_null_winsys.h b/src/amd/vulkan/winsys/null/radv_null_winsys.h
new file mode 100644
index 00000000000..7953ab4792d
--- /dev/null
+++ b/src/amd/vulkan/winsys/null/radv_null_winsys.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ * based on amdgpu winsys.
+ * Copyright © 2011 Marek Olšák <maraeo at gmail.com>
+ * Copyright © 2015 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef RADV_NULL_WINSYS_H
+#define RADV_NULL_WINSYS_H
+
+#include "radv_radeon_winsys.h"
+#include "ac_gpu_info.h"
+#include "addrlib/inc/addrinterface.h"
+#include "util/list.h"
+#include <pthread.h>
+
+struct radv_null_winsys {
+	struct radeon_winsys base;
+};
+
+static inline struct radv_null_winsys *
+radv_null_winsys(struct radeon_winsys *base)
+{
+	return (struct radv_null_winsys*)base;
+}
+
+#endif /* RADV_NULL_WINSYS_H */
diff --git a/src/amd/vulkan/winsys/null/radv_null_winsys_public.h b/src/amd/vulkan/winsys/null/radv_null_winsys_public.h
new file mode 100644
index 00000000000..7111c43dc47
--- /dev/null
+++ b/src/amd/vulkan/winsys/null/radv_null_winsys_public.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2020 Valve Corporation
+ *
+ * based on amdgpu winsys.
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef RADV_NULL_WINSYS_PUBLIC_H
+#define RADV_NULL_WINSYS_PUBLIC_H
+
+struct radeon_winsys *radv_null_winsys_create(void);
+
+#endif /* RADV_NULL_WINSYS_PUBLIC_H */



More information about the mesa-commit mailing list