summaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2018-04-20 18:44:22 -0700
committerKenneth Graunke <[email protected]>2019-02-21 10:26:06 -0800
commit841b3b90032c4a31c98f464bd0cf041da0388f39 (patch)
treea1bae73e8f1e67c01962ff809e5eac4f82a2a23c /src/gallium
parentc75a1254a4c1b6d7ef9a93e4fcd235e9690dd778 (diff)
iris: Defines for base addresses rather than numbers everywhere
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/drivers/iris/iris_binder.h2
-rw-r--r--src/gallium/drivers/iris/iris_bufmgr.c23
-rw-r--r--src/gallium/drivers/iris/iris_bufmgr.h41
-rw-r--r--src/gallium/drivers/iris/iris_state.c5
4 files changed, 56 insertions, 15 deletions
diff --git a/src/gallium/drivers/iris/iris_binder.h b/src/gallium/drivers/iris/iris_binder.h
index 7a26602bf48..5830288b5c5 100644
--- a/src/gallium/drivers/iris/iris_binder.h
+++ b/src/gallium/drivers/iris/iris_binder.h
@@ -30,8 +30,6 @@
struct iris_bo;
struct iris_bufmgr;
-#define IRIS_BINDER_ADDRESS (1ull << 32)
-
struct iris_binder
{
struct iris_bo *bo;
diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c
index 023d9720558..3c7ce9f5bcf 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.c
+++ b/src/gallium/drivers/iris/iris_bufmgr.c
@@ -229,19 +229,22 @@ bucket_for_size(struct iris_bufmgr *bufmgr, uint64_t size)
static enum iris_memory_zone
memzone_for_address(uint64_t address)
{
- const uint64_t _4GB = 1ull << 32;
+ STATIC_ASSERT(IRIS_MEMZONE_OTHER_START > IRIS_MEMZONE_DYNAMIC_START);
+ STATIC_ASSERT(IRIS_MEMZONE_DYNAMIC_START > IRIS_MEMZONE_SURFACE_START);
+ STATIC_ASSERT(IRIS_MEMZONE_SURFACE_START > IRIS_MEMZONE_SHADER_START);
+ STATIC_ASSERT(IRIS_BINDER_ADDRESS == IRIS_MEMZONE_SURFACE_START);
- if (address >= 3 * _4GB)
+ if (address >= IRIS_MEMZONE_OTHER_START)
return IRIS_MEMZONE_OTHER;
- if (address >= 2 * _4GB)
+ if (address >= IRIS_MEMZONE_DYNAMIC_START)
return IRIS_MEMZONE_DYNAMIC;
- if (address > 1 * _4GB)
+ /* Use > to exclude the binder */
+ if (address > IRIS_MEMZONE_SURFACE_START)
return IRIS_MEMZONE_SURFACE;
- /* The binder isn't in any memory zone. */
- if (address == 1 * _4GB)
+ if (address == IRIS_BINDER_ADDRESS)
return IRIS_MEMZONE_BINDER;
return IRIS_MEMZONE_SHADER;
@@ -1537,16 +1540,18 @@ iris_bufmgr_init(struct gen_device_info *devinfo, int fd)
bufmgr->has_llc = devinfo->has_llc;
+ STATIC_ASSERT(IRIS_MEMZONE_SHADER_START == 0ull);
const uint64_t _4GB = 1ull << 32;
util_vma_heap_init(&bufmgr->vma_allocator[IRIS_MEMZONE_SHADER],
PAGE_SIZE, _4GB);
util_vma_heap_init(&bufmgr->vma_allocator[IRIS_MEMZONE_SURFACE],
- 1 * _4GB, _4GB);
+ IRIS_MEMZONE_SURFACE_START, _4GB);
util_vma_heap_init(&bufmgr->vma_allocator[IRIS_MEMZONE_DYNAMIC],
- 2 * _4GB, _4GB);
+ IRIS_MEMZONE_DYNAMIC_START, _4GB);
util_vma_heap_init(&bufmgr->vma_allocator[IRIS_MEMZONE_OTHER],
- 3 * _4GB, (1ull << 48) - 3 * _4GB);
+ IRIS_MEMZONE_OTHER_START,
+ (1ull << 48) - IRIS_MEMZONE_OTHER_START);
// XXX: driconf
bufmgr->bo_reuse = env_var_as_boolean("bo_reuse", true);
diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h
index eb2148da3f5..48ea7da9a5f 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.h
+++ b/src/gallium/drivers/iris/iris_bufmgr.h
@@ -36,10 +36,40 @@
struct gen_device_info;
struct pipe_debug_callback;
+/**
+ * Memory zones. When allocating a buffer, you can request that it is
+ * placed into a specific region of the virtual address space (PPGTT).
+ *
+ * Most buffers can go anywhere (IRIS_MEMZONE_OTHER). Some buffers are
+ * accessed via an offset from a base address. STATE_BASE_ADDRESS has
+ * a maximum 4GB size for each region, so we need to restrict those
+ * buffers to be within 4GB of the base. Each memory zone corresponds
+ * to a particular base address.
+ *
+ * We lay out the virtual address space as follows:
+ *
+ * - [0, 4K): Nothing (empty page for null address)
+ * - [4K, 4G): Shaders (Instruction Base Address)
+ * - [4G, 8G): Surfaces (Surface State Base Address, Bindless ...)
+ * - [8G, 12G): Dynamic (Dynamic State Base Address)
+ * - [12G, *): Other (everything else in the full 48-bit VMA)
+ *
+ * A special 64kB "binder" buffer lives at the start of the surface memory
+ * zone, holding binding tables referring to objects in the rest of the zone.
+ *
+ * Each GL context uses a separate GEM context, which technically gives them
+ * each a separate VMA. However, we assign address globally, so buffers will
+ * have the same address in all GEM contexts. This lets us have a single BO
+ * field for the address, which is easy and cheap.
+ *
+ * One exception is the special "binder" BO. Binders are context-local,
+ * so while there are many of them, all binders are stored at the same
+ * fixed address (in different VMAs).
+ */
enum iris_memory_zone {
- IRIS_MEMZONE_DYNAMIC,
- IRIS_MEMZONE_SURFACE,
IRIS_MEMZONE_SHADER,
+ IRIS_MEMZONE_SURFACE,
+ IRIS_MEMZONE_DYNAMIC,
IRIS_MEMZONE_OTHER,
IRIS_MEMZONE_BINDER,
@@ -48,6 +78,13 @@ enum iris_memory_zone {
/* Intentionally exclude IRIS_MEMZONE_BINDER */
#define IRIS_MEMZONE_COUNT (IRIS_MEMZONE_OTHER + 1)
+#define IRIS_MEMZONE_SHADER_START (0 * (1ull << 32))
+#define IRIS_MEMZONE_SURFACE_START (1 * (1ull << 32))
+#define IRIS_MEMZONE_DYNAMIC_START (2 * (1ull << 32))
+#define IRIS_MEMZONE_OTHER_START (3 * (1ull << 32))
+
+#define IRIS_BINDER_ADDRESS IRIS_MEMZONE_SURFACE_START
+
struct iris_bo {
/**
* Size in bytes of the buffer object.
diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c
index f1ea9a49b13..38c5f9c03f3 100644
--- a/src/gallium/drivers/iris/iris_state.c
+++ b/src/gallium/drivers/iris/iris_state.c
@@ -361,8 +361,9 @@ iris_init_render_context(struct iris_screen *screen,
sba.IndirectObjectBufferSizeModifyEnable = true;
sba.InstructionBuffersizeModifyEnable = true;
- sba.SurfaceStateBaseAddress = ro_bo(NULL, 1ull << 32);
- sba.DynamicStateBaseAddress = ro_bo(NULL, 2 * (1ull << 32));
+ sba.InstructionBaseAddress = ro_bo(NULL, IRIS_MEMZONE_SHADER_START);
+ sba.SurfaceStateBaseAddress = ro_bo(NULL, IRIS_MEMZONE_SURFACE_START);
+ sba.DynamicStateBaseAddress = ro_bo(NULL, IRIS_MEMZONE_DYNAMIC_START);
sba.GeneralStateBufferSize = 0xfffff;
sba.IndirectObjectBufferSize = 0xfffff;