radv: implement a dummy winsys for creating devices without AMDGPU
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 17 Feb 2020 13:45:47 +0000 (14:45 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 26 Feb 2020 07:09:46 +0000 (08:09 +0100)
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@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@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>

16 files changed:
docs/envvars.html
src/amd/vulkan/Makefile.sources
src/amd/vulkan/meson.build
src/amd/vulkan/radv_debug.h
src/amd/vulkan/radv_device.c
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys_public.h
src/amd/vulkan/winsys/null/radv_null_bo.c [new file with mode: 0644]
src/amd/vulkan/winsys/null/radv_null_bo.h [new file with mode: 0644]
src/amd/vulkan/winsys/null/radv_null_cs.c [new file with mode: 0644]
src/amd/vulkan/winsys/null/radv_null_cs.h [new file with mode: 0644]
src/amd/vulkan/winsys/null/radv_null_winsys.c [new file with mode: 0644]
src/amd/vulkan/winsys/null/radv_null_winsys.h [new file with mode: 0644]
src/amd/vulkan/winsys/null/radv_null_winsys_public.h [new file with mode: 0644]

index df4377209eb76cb098baebce3718e2a56978b8ae..eacd1b604bd184614e3fe304452e45729f4fbb99 100644 (file)
@@ -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>
index 002f2ea1ebe5bffc179436ce9007e795001df250..4b1bca2d879dbf39e17de554b9f47922c7609131 100644 (file)
@@ -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
index e620478a43b97ff4b752a6879f8497123f8b5f51..bd5f6f515989086c9381191b5b1bd00099ebee6f 100644 (file)
@@ -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',
index f7001adcee2fde059adec556ec9e04fc74711d0f..545eaa51caf78be9b55de69897b2d1a5b0cd605d 100644 (file)
@@ -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 {
index c9947592dd7eb6e52eaac240f4fc33a0ed64578e..be84c2793a0a353ffd487323f220c04d346588e8 100644 (file)
@@ -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)
index c6c9de93777a80b27ac2ea495d4e9ce194d80df0..299707f0c2b5c97414131fd8e806c1488a20e6fc 100644 (file)
@@ -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,
index bac68e9f7fcfe1029ef4d85872bfb273ea1a5f6a..b1d204a6d31fc79582a9c7e7547155ee9d3c1a5c 100644 (file)
@@ -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;
index 1178600384d9c96a16cb38a0e84875d8bf8ce25b..8cbac2900439c437b3dca3dbefe2ff14b9d96a54 100644 (file)
@@ -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;
index 709669b2a570383ac5315b927e0d9c73825be7a6..e8b8298c6c8ec4236fe7e57ea4623941b5db1438 100644 (file)
@@ -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 (file)
index 0000000..02aad5f
--- /dev/null
@@ -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 (file)
index 0000000..2f2f8b7
--- /dev/null
@@ -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 (file)
index 0000000..ebf3395
--- /dev/null
@@ -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 (file)
index 0000000..344e950
--- /dev/null
@@ -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 (file)
index 0000000..1054021
--- /dev/null
@@ -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 (file)
index 0000000..7953ab4
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2016 Red Hat.
+ * Copyright © 2016 Bas Nieuwenhuizen
+ * based on amdgpu winsys.
+ * Copyright © 2011 Marek Olšák <maraeo@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 (file)
index 0000000..7111c43
--- /dev/null
@@ -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 */