[Mesa-dev] [PATCH 21/24] radv: use ac_gpu_info

Nicolai Hähnle nhaehnle at gmail.com
Sun May 14 21:47:07 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/amd/vulkan/radv_device.c                      |  10 +-
 src/amd/vulkan/radv_private.h                     |   1 +
 src/amd/vulkan/radv_radeon_winsys.h               |  55 +------
 src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c | 175 +---------------------
 src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h |   1 +
 5 files changed, 13 insertions(+), 229 deletions(-)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index b4f2331..102b9fd 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -731,21 +731,21 @@ void radv_GetPhysicalDeviceProperties2KHR(
 	}
 }
 
 static void radv_get_physical_device_queue_family_properties(
 	struct radv_physical_device*                pdevice,
 	uint32_t*                                   pCount,
 	VkQueueFamilyProperties**                    pQueueFamilyProperties)
 {
 	int num_queue_families = 1;
 	int idx;
-	if (pdevice->rad_info.compute_rings > 0 &&
+	if (pdevice->rad_info.num_compute_rings > 0 &&
 	    pdevice->rad_info.chip_class >= CIK &&
 	    !(pdevice->instance->debug_flags & RADV_DEBUG_NO_COMPUTE_QUEUE))
 		num_queue_families++;
 
 	if (pQueueFamilyProperties == NULL) {
 		*pCount = num_queue_families;
 		return;
 	}
 
 	if (!*pCount)
@@ -758,29 +758,29 @@ static void radv_get_physical_device_queue_family_properties(
 			              VK_QUEUE_COMPUTE_BIT |
 			              VK_QUEUE_TRANSFER_BIT |
 			              VK_QUEUE_SPARSE_BINDING_BIT,
 			.queueCount = 1,
 			.timestampValidBits = 64,
 			.minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 },
 		};
 		idx++;
 	}
 
-	if (pdevice->rad_info.compute_rings > 0 &&
+	if (pdevice->rad_info.num_compute_rings > 0 &&
 	    pdevice->rad_info.chip_class >= CIK &&
 	    !(pdevice->instance->debug_flags & RADV_DEBUG_NO_COMPUTE_QUEUE)) {
 		if (*pCount > idx) {
 			*pQueueFamilyProperties[idx] = (VkQueueFamilyProperties) {
 				.queueFlags = VK_QUEUE_COMPUTE_BIT |
 				              VK_QUEUE_TRANSFER_BIT |
 				              VK_QUEUE_SPARSE_BINDING_BIT,
-				.queueCount = pdevice->rad_info.compute_rings,
+				.queueCount = pdevice->rad_info.num_compute_rings,
 				.timestampValidBits = 64,
 				.minImageTransferGranularity = (VkExtent3D) { 1, 1, 1 },
 			};
 			idx++;
 		}
 	}
 	*pCount = idx;
 }
 
 void radv_GetPhysicalDeviceQueueFamilyProperties(
@@ -850,25 +850,25 @@ void radv_GetPhysicalDeviceMemoryProperties(
 		VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
 		VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
 		.heapIndex = RADV_MEM_HEAP_GTT,
 	};
 
 	STATIC_ASSERT(RADV_MEM_HEAP_COUNT <= VK_MAX_MEMORY_HEAPS);
 
 	pMemoryProperties->memoryHeapCount = RADV_MEM_HEAP_COUNT;
 	pMemoryProperties->memoryHeaps[RADV_MEM_HEAP_VRAM] = (VkMemoryHeap) {
 		.size = physical_device->rad_info.vram_size -
-				physical_device->rad_info.visible_vram_size,
+				physical_device->rad_info.vram_vis_size,
 		.flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
 	};
 	pMemoryProperties->memoryHeaps[RADV_MEM_HEAP_VRAM_CPU_ACCESS] = (VkMemoryHeap) {
-		.size = physical_device->rad_info.visible_vram_size,
+		.size = physical_device->rad_info.vram_vis_size,
 		.flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
 	};
 	pMemoryProperties->memoryHeaps[RADV_MEM_HEAP_GTT] = (VkMemoryHeap) {
 		.size = physical_device->rad_info.gart_size,
 		.flags = 0,
 	};
 }
 
 void radv_GetPhysicalDeviceMemoryProperties2KHR(
 	VkPhysicalDevice                            physicalDevice,
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index 518ed6c..302fd47 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -46,20 +46,21 @@
 #include <amdgpu.h>
 #include "compiler/shader_enums.h"
 #include "util/macros.h"
 #include "util/list.h"
 #include "util/vk_alloc.h"
 #include "main/macros.h"
 
 #include "radv_radeon_winsys.h"
 #include "ac_binary.h"
 #include "ac_nir_to_llvm.h"
+#include "ac_gpu_info.h"
 #include "ac_surface.h"
 #include "radv_debug.h"
 #include "radv_descriptor_set.h"
 
 #include <llvm-c/TargetMachine.h>
 
 /* Pre-declarations needed for WSI entrypoints */
 struct wl_surface;
 struct wl_display;
 typedef struct xcb_connection_t xcb_connection_t;
diff --git a/src/amd/vulkan/radv_radeon_winsys.h b/src/amd/vulkan/radv_radeon_winsys.h
index 855a2d7..397f28e 100644
--- a/src/amd/vulkan/radv_radeon_winsys.h
+++ b/src/amd/vulkan/radv_radeon_winsys.h
@@ -28,20 +28,21 @@
 
 #ifndef RADV_RADEON_WINSYS_H
 #define RADV_RADEON_WINSYS_H
 
 #include <stdint.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include "main/macros.h"
 #include "amd_family.h"
 
+struct radeon_info;
 struct ac_surf_info;
 struct radeon_surf;
 
 #define FREE(x) free(x)
 
 enum radeon_bo_domain { /* bitfield */
 	RADEON_DOMAIN_GTT  = 2,
 	RADEON_DOMAIN_VRAM = 4,
 	RADEON_DOMAIN_VRAM_GTT = RADEON_DOMAIN_VRAM | RADEON_DOMAIN_GTT
 };
@@ -67,74 +68,20 @@ enum ring_type {
 	RING_VCE,
 	RING_LAST,
 };
 
 struct radeon_winsys_cs {
 	unsigned cdw;  /* Number of used dwords. */
 	unsigned max_dw; /* Maximum number of dwords. */
 	uint32_t *buf; /* The base pointer of the chunk. */
 };
 
-struct radeon_info {
-	/* PCI info: domain:bus:dev:func */
-	uint32_t                    pci_domain;
-	uint32_t                    pci_bus;
-	uint32_t                    pci_dev;
-	uint32_t                    pci_func;
-
-	/* Device info. */
-	uint32_t                    pci_id;
-	enum radeon_family          family;
-	enum chip_class             chip_class;
-	uint32_t                    gart_page_size;
-	uint64_t                    gart_size;
-	uint64_t                    vram_size;
-	uint64_t                    visible_vram_size;
-	bool                        has_dedicated_vram;
-	bool                     has_virtual_memory;
-	bool                        gfx_ib_pad_with_type2;
-	bool                     has_uvd;
-	uint32_t                    sdma_rings;
-	uint32_t                    compute_rings;
-	uint32_t                    vce_fw_version;
-	uint32_t                    vce_harvest_config;
-	uint32_t                    clock_crystal_freq; /* in kHz */
-
-	/* Kernel info. */
-	uint32_t                    drm_major; /* version */
-	uint32_t                    drm_minor;
-	uint32_t                    drm_patchlevel;
-	bool                     has_userptr;
-
-	/* Shader cores. */
-	uint32_t                    r600_max_quad_pipes; /* wave size / 16 */
-	uint32_t                    max_shader_clock;
-	uint32_t                    num_good_compute_units;
-	uint32_t                    max_se; /* shader engines */
-	uint32_t                    max_sh_per_se; /* shader arrays per shader engine */
-
-	/* Render backends (color + depth blocks). */
-	uint32_t                    r300_num_gb_pipes;
-	uint32_t                    r300_num_z_pipes;
-	uint32_t                    r600_gb_backend_map; /* R600 harvest config */
-	bool                     r600_gb_backend_map_valid;
-	uint32_t                    r600_num_banks;
-	uint32_t                    num_render_backends;
-	uint32_t                    num_tile_pipes; /* pipe count from PIPE_CONFIG */
-	uint32_t                    pipe_interleave_bytes;
-	uint32_t                    enabled_rb_mask; /* GCN harvest config */
-
-	/* Tile modes. */
-	uint32_t                    si_tile_mode_array[32];
-	uint32_t                    cik_macrotile_mode_array[16];
-};
-
 #define RADEON_SURF_TYPE_MASK                   0xFF
 #define RADEON_SURF_TYPE_SHIFT                  0
 #define     RADEON_SURF_TYPE_1D                     0
 #define     RADEON_SURF_TYPE_2D                     1
 #define     RADEON_SURF_TYPE_3D                     2
 #define     RADEON_SURF_TYPE_CUBEMAP                3
 #define     RADEON_SURF_TYPE_1D_ARRAY               4
 #define     RADEON_SURF_TYPE_2D_ARRAY               5
 #define RADEON_SURF_MODE_MASK                   0xFF
 #define RADEON_SURF_MODE_SHIFT                  8
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
index d144d03..2ebb856 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
@@ -32,153 +32,28 @@
 #include "xf86drm.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <amdgpu_drm.h>
 #include <assert.h>
 #include "radv_amdgpu_cs.h"
 #include "radv_amdgpu_bo.h"
 #include "radv_amdgpu_surface.h"
 
-#define CIK_TILE_MODE_COLOR_2D			14
-
-#define CIK__GB_TILE_MODE__PIPE_CONFIG(x)        (((x) >> 6) & 0x1f)
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P2               0
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P4_8x16          4
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P4_16x16         5
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P4_16x32         6
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P4_32x32         7
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P8_16x16_8x16    8
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P8_16x32_8x16    9
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_8x16    10
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P8_16x32_16x16   11
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_16x16   12
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_16x32   13
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P8_32x64_32x32   14
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P16_32X32_8X16   16
-#define     CIK__PIPE_CONFIG__ADDR_SURF_P16_32X32_16X16  17
-
-static unsigned radv_cik_get_num_tile_pipes(struct amdgpu_gpu_info *info)
-{
-	unsigned mode2d = info->gb_tile_mode[CIK_TILE_MODE_COLOR_2D];
-
-	switch (CIK__GB_TILE_MODE__PIPE_CONFIG(mode2d)) {
-	case CIK__PIPE_CONFIG__ADDR_SURF_P2:
-		return 2;
-	case CIK__PIPE_CONFIG__ADDR_SURF_P4_8x16:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P4_16x16:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P4_16x32:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P4_32x32:
-		return 4;
-	case CIK__PIPE_CONFIG__ADDR_SURF_P8_16x16_8x16:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P8_16x32_8x16:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_8x16:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P8_16x32_16x16:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_16x16:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P8_32x32_16x32:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P8_32x64_32x32:
-		return 8;
-	case CIK__PIPE_CONFIG__ADDR_SURF_P16_32X32_8X16:
-	case CIK__PIPE_CONFIG__ADDR_SURF_P16_32X32_16X16:
-		return 16;
-	default:
-		fprintf(stderr, "Invalid CIK pipe configuration, assuming P2\n");
-		assert(!"this should never occur");
-		return 2;
-	}
-}
-
 static bool
 do_winsys_init(struct radv_amdgpu_winsys *ws, int fd)
 {
-	struct amdgpu_buffer_size_alignments alignment_info = {};
-	struct amdgpu_heap_info vram, visible_vram, gtt;
-	struct drm_amdgpu_info_hw_ip dma = {};
-	struct drm_amdgpu_info_hw_ip compute = {};
-	drmDevicePtr devinfo;
-	int r;
-	int i, j;
-	/* Get PCI info. */
-	r = drmGetDevice2(fd, 0, &devinfo);
-	if (r) {
-		fprintf(stderr, "amdgpu: drmGetDevice2 failed.\n");
-		goto fail;
-	}
-	ws->info.pci_domain = devinfo->businfo.pci->domain;
-	ws->info.pci_bus = devinfo->businfo.pci->bus;
-	ws->info.pci_dev = devinfo->businfo.pci->dev;
-	ws->info.pci_func = devinfo->businfo.pci->func;
-	drmFreeDevice(&devinfo);
-
-	/* Query hardware and driver information. */
-	r = amdgpu_query_gpu_info(ws->dev, &ws->amdinfo);
-	if (r) {
-		fprintf(stderr, "amdgpu: amdgpu_query_gpu_info failed.\n");
+	if (!ac_query_gpu_info(fd, ws->dev, &ws->info, &ws->amdinfo))
 		goto fail;
-	}
-
-	r = amdgpu_query_buffer_size_alignment(ws->dev, &alignment_info);
-	if (r) {
-		fprintf(stderr, "amdgpu: amdgpu_query_buffer_size_alignment failed.\n");
-		goto fail;
-	}
-
-	r = amdgpu_query_heap_info(ws->dev, AMDGPU_GEM_DOMAIN_VRAM, 0, &vram);
-	if (r) {
-		fprintf(stderr, "amdgpu: amdgpu_query_heap_info(vram) failed.\n");
-		goto fail;
-	}
-
-	r = amdgpu_query_heap_info(ws->dev, AMDGPU_GEM_DOMAIN_VRAM,
-	                           AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED, &visible_vram);
-	if (r) {
-		fprintf(stderr, "amdgpu: amdgpu_query_heap_info(visible_vram) failed.\n");
-		goto fail;
-	}
 
-	r = amdgpu_query_heap_info(ws->dev, AMDGPU_GEM_DOMAIN_GTT, 0, &gtt);
-	if (r) {
-		fprintf(stderr, "amdgpu: amdgpu_query_heap_info(gtt) failed.\n");
-		goto fail;
-	}
-
-	r = amdgpu_query_hw_ip_info(ws->dev, AMDGPU_HW_IP_DMA, 0, &dma);
-	if (r) {
-		fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(dma) failed.\n");
-		goto fail;
-	}
-
-	r = amdgpu_query_hw_ip_info(ws->dev, AMDGPU_HW_IP_COMPUTE, 0, &compute);
-	if (r) {
-		fprintf(stderr, "amdgpu: amdgpu_query_hw_ip_info(compute) failed.\n");
-		goto fail;
-	}
-	ws->info.pci_id = ws->amdinfo.asic_id; /* TODO: is this correct? */
-	ws->info.vce_harvest_config = ws->amdinfo.vce_harvest_config;
-
-	switch (ws->info.pci_id) {
-#define CHIPSET(pci_id, name, cfamily) case pci_id: ws->info.family = CHIP_##cfamily; break;
-#include "pci_ids/radeonsi_pci_ids.h"
-#undef CHIPSET
-	default:
-		fprintf(stderr, "amdgpu: Invalid PCI ID.\n");
-		goto fail;
-	}
-
-	if (ws->info.family >= CHIP_TONGA)
-		ws->info.chip_class = VI;
-	else if (ws->info.family >= CHIP_BONAIRE)
-		ws->info.chip_class = CIK;
-	else if (ws->info.family >= CHIP_TAHITI)
-		ws->info.chip_class = SI;
-	else {
-		fprintf(stderr, "amdgpu: Unknown family.\n");
+	if (ws->info.chip_class >= GFX9) {
+		fprintf(stderr, "radv: GFX9 is not supported.\n");
 		goto fail;
 	}
 
 	/* family and rev_id are for addrlib */
 	switch (ws->info.family) {
 	case CHIP_TAHITI:
 		ws->family = FAMILY_SI;
 		ws->rev_id = SI_TAHITI_P_A0;
 		break;
 	case CHIP_PITCAIRN:
@@ -253,62 +128,22 @@ do_winsys_init(struct radv_amdgpu_winsys *ws, int fd)
 		fprintf(stderr, "amdgpu: Unknown family.\n");
 		goto fail;
 	}
 
 	ws->addrlib = radv_amdgpu_addr_create(&ws->amdinfo, ws->family, ws->rev_id, ws->info.chip_class);
 	if (!ws->addrlib) {
 		fprintf(stderr, "amdgpu: Cannot create addrlib.\n");
 		goto fail;
 	}
 
-	assert(util_is_power_of_two(dma.available_rings + 1));
-	assert(util_is_power_of_two(compute.available_rings + 1));
-
-	/* Set hardware information. */
-	ws->info.gart_size = gtt.heap_size;
-	ws->info.vram_size = vram.heap_size;
-	ws->info.visible_vram_size = visible_vram.heap_size;
-	/* convert the shader clock from KHz to MHz */
-	ws->info.max_shader_clock = ws->amdinfo.max_engine_clk / 1000;
-	ws->info.max_se = ws->amdinfo.num_shader_engines;
-	ws->info.max_sh_per_se = ws->amdinfo.num_shader_arrays_per_engine;
-	ws->info.has_uvd = 0;
-	ws->info.vce_fw_version = 0;
-	ws->info.has_userptr = TRUE;
-	ws->info.num_render_backends = ws->amdinfo.rb_pipes;
-	ws->info.clock_crystal_freq = ws->amdinfo.gpu_counter_freq;
-	ws->info.num_tile_pipes = radv_cik_get_num_tile_pipes(&ws->amdinfo);
-	ws->info.pipe_interleave_bytes = 256 << ((ws->amdinfo.gb_addr_cfg >> 4) & 0x7);
-	ws->info.has_virtual_memory = TRUE;
-	ws->info.sdma_rings = MIN2(util_bitcount(dma.available_rings),
-	                           MAX_RINGS_PER_TYPE);
-	ws->info.compute_rings = MIN2(util_bitcount(compute.available_rings),
-	                              MAX_RINGS_PER_TYPE);
-
-	/* Get the number of good compute units. */
-	ws->info.num_good_compute_units = 0;
-	for (i = 0; i < ws->info.max_se; i++)
-		for (j = 0; j < ws->info.max_sh_per_se; j++)
-			ws->info.num_good_compute_units +=
-				util_bitcount(ws->amdinfo.cu_bitmap[i][j]);
-
-	memcpy(ws->info.si_tile_mode_array, ws->amdinfo.gb_tile_mode,
-	       sizeof(ws->amdinfo.gb_tile_mode));
-	ws->info.enabled_rb_mask = ws->amdinfo.enabled_rb_pipes_mask;
-
-	memcpy(ws->info.cik_macrotile_mode_array, ws->amdinfo.gb_macro_tile_mode,
-	       sizeof(ws->amdinfo.gb_macro_tile_mode));
-
-	ws->info.gart_page_size = alignment_info.size_remote;
-
-	if (ws->info.chip_class == SI)
-		ws->info.gfx_ib_pad_with_type2 = TRUE;
+	ws->info.num_sdma_rings = MIN2(ws->info.num_sdma_rings, MAX_RINGS_PER_TYPE);
+	ws->info.num_compute_rings = MIN2(ws->info.num_compute_rings, MAX_RINGS_PER_TYPE);
 
 	ws->use_ib_bos = ws->family >= FAMILY_CI;
 	return true;
 fail:
 	return false;
 }
 
 static void radv_amdgpu_winsys_query_info(struct radeon_winsys *rws,
                                      struct radeon_info *info)
 {
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
index abb238b..93f4c2c 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
@@ -22,20 +22,21 @@
  * 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_AMDGPU_WINSYS_H
 #define RADV_AMDGPU_WINSYS_H
 
 #include "radv_radeon_winsys.h"
+#include "ac_gpu_info.h"
 #include "addrlib/addrinterface.h"
 #include <amdgpu.h>
 #include "util/list.h"
 
 struct radv_amdgpu_winsys {
 	struct radeon_winsys base;
 	amdgpu_device_handle dev;
 
 	struct radeon_info info;
 	struct amdgpu_gpu_info amdinfo;
-- 
2.9.3



More information about the mesa-dev mailing list