[Mesa-dev] [PATCH] radeonsi: clean up winsys creation
Marek Olšák
maraeo at gmail.com
Fri May 17 19:39:02 UTC 2019
From: Marek Olšák <marek.olsak at amd.com>
- unify the code
- choose radeon or amdgpu based on the DRM version, not based on which one
succeeds first
---
.../auxiliary/target-helpers/drm_helper.h | 13 ++-------
src/gallium/drivers/radeonsi/si_pipe.c | 27 +++++++++++++++++--
src/gallium/drivers/radeonsi/si_public.h | 5 +---
.../targets/pipe-loader/pipe_radeonsi.c | 13 ++-------
src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c | 8 ------
5 files changed, 30 insertions(+), 36 deletions(-)
diff --git a/src/gallium/auxiliary/target-helpers/drm_helper.h b/src/gallium/auxiliary/target-helpers/drm_helper.h
index ac891d1d307..6bdd1a008db 100644
--- a/src/gallium/auxiliary/target-helpers/drm_helper.h
+++ b/src/gallium/auxiliary/target-helpers/drm_helper.h
@@ -154,37 +154,28 @@ pipe_r600_create_screen(int fd, const struct pipe_screen_config *config)
struct pipe_screen *
pipe_r600_create_screen(int fd, const struct pipe_screen_config *config)
{
fprintf(stderr, "r600: driver missing\n");
return NULL;
}
#endif
#ifdef GALLIUM_RADEONSI
-#include "radeon/radeon_winsys.h"
-#include "radeon/drm/radeon_drm_public.h"
-#include "amdgpu/drm/amdgpu_public.h"
#include "radeonsi/si_public.h"
struct pipe_screen *
pipe_radeonsi_create_screen(int fd, const struct pipe_screen_config *config)
{
- struct radeon_winsys *rw;
-
- /* First, try amdgpu. */
- rw = amdgpu_winsys_create(fd, config, radeonsi_screen_create);
+ struct pipe_screen *screen = radeonsi_screen_create(fd, config);
- if (!rw)
- rw = radeon_drm_winsys_create(fd, config, radeonsi_screen_create);
-
- return rw ? debug_screen_wrap(rw->screen) : NULL;
+ return screen ? debug_screen_wrap(screen) : NULL;
}
const char *radeonsi_driconf_xml =
#include "radeonsi/si_driinfo.h"
;
#else
struct pipe_screen *
pipe_radeonsi_create_screen(int fd, const struct pipe_screen_config *config)
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index 9ddf7802746..c19a2cd97d3 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -35,20 +35,24 @@
#include "util/disk_cache.h"
#include "util/u_log.h"
#include "util/u_memory.h"
#include "util/u_suballoc.h"
#include "util/u_tests.h"
#include "util/u_upload_mgr.h"
#include "util/xmlconfig.h"
#include "vl/vl_decoder.h"
#include "driver_ddebug/dd_util.h"
+#include "gallium/winsys/radeon/drm/radeon_drm_public.h"
+#include "gallium/winsys/amdgpu/drm/amdgpu_public.h"
+#include <xf86drm.h>
+
static const struct debug_named_value debug_options[] = {
/* Shader logging options: */
{ "vs", DBG(VS), "Print vertex shaders" },
{ "ps", DBG(PS), "Print pixel shaders" },
{ "gs", DBG(GS), "Print geometry shaders" },
{ "tcs", DBG(TCS), "Print tessellation control shaders" },
{ "tes", DBG(TES), "Print tessellation evaluation shaders" },
{ "cs", DBG(CS), "Print compute shaders" },
{ "noir", DBG(NO_IR), "Don't print the LLVM IR"},
{ "notgsi", DBG(NO_TGSI), "Don't print the TGSI"},
@@ -872,22 +876,23 @@ static bool si_is_parallel_shader_compilation_finished(struct pipe_screen *scree
if (shader_type == PIPE_SHADER_COMPUTE) {
struct si_compute *cs = (struct si_compute*)shader;
return util_queue_fence_is_signalled(&cs->ready);
}
struct si_shader_selector *sel = (struct si_shader_selector *)shader;
return util_queue_fence_is_signalled(&sel->ready);
}
-struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
- const struct pipe_screen_config *config)
+static struct pipe_screen *
+radeonsi_screen_create_impl(struct radeon_winsys *ws,
+ const struct pipe_screen_config *config)
{
struct si_screen *sscreen = CALLOC_STRUCT(si_screen);
unsigned hw_threads, num_comp_hi_threads, num_comp_lo_threads, i;
if (!sscreen) {
return NULL;
}
sscreen->ws = ws;
ws->query_info(ws, &sscreen->info);
@@ -1218,10 +1223,28 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
si_test_gds_memory_management((struct si_context*)sscreen->aux_context,
32 * 1024, 4, RADEON_DOMAIN_GDS);
}
if (sscreen->debug_flags & DBG(TEST_GDS_OA_MM)) {
si_test_gds_memory_management((struct si_context*)sscreen->aux_context,
4, 1, RADEON_DOMAIN_OA);
}
return &sscreen->b;
}
+
+struct pipe_screen *radeonsi_screen_create(int fd, const struct pipe_screen_config *config)
+{
+ drmVersionPtr version = drmGetVersion(fd);
+ struct radeon_winsys *rw = NULL;
+
+ switch (version->version_major) {
+ case 2:
+ rw = radeon_drm_winsys_create(fd, config, radeonsi_screen_create_impl);
+ break;
+ case 3:
+ rw = amdgpu_winsys_create(fd, config, radeonsi_screen_create_impl);
+ break;
+ }
+
+ drmFreeVersion(version);
+ return rw ? rw->screen : NULL;
+}
diff --git a/src/gallium/drivers/radeonsi/si_public.h b/src/gallium/drivers/radeonsi/si_public.h
index c8721babb05..8a1f6e1d93b 100644
--- a/src/gallium/drivers/radeonsi/si_public.h
+++ b/src/gallium/drivers/radeonsi/si_public.h
@@ -18,16 +18,13 @@
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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 SI_PUBLIC_H
#define SI_PUBLIC_H
-struct radeon_winsys;
-
-struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
- const struct pipe_screen_config *config);
+struct pipe_screen *radeonsi_screen_create(int fd, const struct pipe_screen_config *config);
#endif
diff --git a/src/gallium/targets/pipe-loader/pipe_radeonsi.c b/src/gallium/targets/pipe-loader/pipe_radeonsi.c
index 5657595af19..9d925c727f1 100644
--- a/src/gallium/targets/pipe-loader/pipe_radeonsi.c
+++ b/src/gallium/targets/pipe-loader/pipe_radeonsi.c
@@ -1,28 +1,19 @@
#include "state_tracker/drm_driver.h"
#include "target-helpers/inline_debug_helper.h"
-#include "radeon/drm/radeon_drm_public.h"
-#include "radeon/radeon_winsys.h"
-#include "amdgpu/drm/amdgpu_public.h"
#include "radeonsi/si_public.h"
#include "util/xmlpool.h"
static struct pipe_screen *
create_screen(int fd, const struct pipe_screen_config *config)
{
- struct radeon_winsys *rw;
+ struct pipe_screen *screen = radeonsi_screen_create(fd, config);
- /* First, try amdgpu. */
- rw = amdgpu_winsys_create(fd, config, radeonsi_screen_create);
-
- if (!rw)
- rw = radeon_drm_winsys_create(fd, config, radeonsi_screen_create);
-
- return rw ? debug_screen_wrap(rw->screen) : NULL;
+ return screen ? debug_screen_wrap(screen) : NULL;
}
static const char *driconf_xml =
#include "radeonsi/si_driinfo.h"
;
PUBLIC
DRM_DRIVER_DESCRIPTOR("radeonsi", &driconf_xml, create_screen)
diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
index 1430c94d3e4..d2776b347cb 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
@@ -277,31 +277,23 @@ static void amdgpu_pin_threads_to_L3_cache(struct radeon_winsys *rws,
util_pin_thread_to_L3(ws->cs_queue.threads[0], cache,
util_cpu_caps.cores_per_L3);
}
PUBLIC struct radeon_winsys *
amdgpu_winsys_create(int fd, const struct pipe_screen_config *config,
radeon_screen_create_t screen_create)
{
struct amdgpu_winsys *ws;
- drmVersionPtr version = drmGetVersion(fd);
amdgpu_device_handle dev;
uint32_t drm_major, drm_minor, r;
- /* The DRM driver version of amdgpu is 3.x.x. */
- if (version->version_major != 3) {
- drmFreeVersion(version);
- return NULL;
- }
- drmFreeVersion(version);
-
/* Look up the winsys from the dev table. */
simple_mtx_lock(&dev_tab_mutex);
if (!dev_tab)
dev_tab = util_hash_table_create(hash_pointer, compare_pointers);
/* Initialize the amdgpu device. This should always return the same pointer
* for the same fd. */
r = amdgpu_device_initialize(fd, &drm_major, &drm_minor, &dev);
if (r) {
simple_mtx_unlock(&dev_tab_mutex);
--
2.17.1
More information about the mesa-dev
mailing list