From 79466c13138c8c975f90a5eaf9a1049db87e20e0 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 21 Apr 2018 01:42:06 -0700 Subject: [PATCH] iris: move bo_offset_from_sba for wider use --- src/gallium/drivers/iris/iris_bufmgr.h | 16 +++++++++++ src/gallium/drivers/iris/iris_resource.h | 7 +++++ src/gallium/drivers/iris/iris_state.c | 34 ++++++------------------ 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h index 48ea7da9a5f..05d0f922951 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.h +++ b/src/gallium/drivers/iris/iris_bufmgr.h @@ -329,5 +329,21 @@ int iris_reg_read(struct iris_bufmgr *bufmgr, uint32_t offset, uint64_t *out); int drm_ioctl(int fd, unsigned long request, void *arg); +/** + * Returns the BO's address relative to the appropriate base address. + * + * All of our base addresses are programmed to the start of a 4GB region, + * so simply returning the bottom 32 bits of the BO address will give us + * the offset from whatever base address corresponds to that memory region. + */ +static inline uint32_t +iris_bo_offset_from_base_address(struct iris_bo *bo) +{ + /* This only works for buffers in the memory zones corresponding to a + * base address - the top, unbounded memory zone doesn't have a base. + */ + assert(bo->gtt_offset < IRIS_MEMZONE_OTHER_START); + return bo->gtt_offset; +} #endif /* IRIS_BUFMGR_H */ diff --git a/src/gallium/drivers/iris/iris_resource.h b/src/gallium/drivers/iris/iris_resource.h index 8e4d8d413a9..211089b569f 100644 --- a/src/gallium/drivers/iris/iris_resource.h +++ b/src/gallium/drivers/iris/iris_resource.h @@ -36,4 +36,11 @@ enum isl_format iris_isl_format_for_pipe_format(enum pipe_format pf); void iris_init_screen_resource_functions(struct pipe_screen *pscreen); +static inline struct iris_bo * +iris_resource_bo(struct pipe_resource *p_res) +{ + struct iris_resource *res = (void *) p_res; + return res->bo; +} + #endif diff --git a/src/gallium/drivers/iris/iris_state.c b/src/gallium/drivers/iris/iris_state.c index 2e10b3970ef..4460f80d217 100644 --- a/src/gallium/drivers/iris/iris_state.c +++ b/src/gallium/drivers/iris/iris_state.c @@ -272,25 +272,6 @@ ro_bo(struct iris_bo *bo, uint64_t offset) return (struct iris_address) { .bo = bo, .offset = offset }; } -/** - * Returns the BO's address relative to the appropriate base address. - * - * All of our base addresses are programmed to the start of a 4GB region, - * so simply returning the bottom 32 bits of the BO address will give us - * the offset from whatever base address corresponds to that memory region. - */ -static uint32_t -bo_offset_from_base_address(struct pipe_resource *res) -{ - struct iris_bo *bo = ((struct iris_resource *) res)->bo; - - /* This only works for buffers in the memory zones corresponding to a - * base address - the top, unbounded memory zone doesn't have a base. - */ - assert(bo->gtt_offset < 3 * (1ull << 32)); - return bo->gtt_offset; -} - static uint32_t * stream_state(struct iris_batch *batch, struct u_upload_mgr *uploader, @@ -303,10 +284,10 @@ stream_state(struct iris_batch *batch, u_upload_alloc(uploader, 0, size, alignment, out_offset, &res, &ptr); - struct iris_bo *bo = ((struct iris_resource *) res)->bo; + struct iris_bo *bo = iris_resource_bo(res); iris_use_pinned_bo(batch, bo, false); - *out_offset += bo_offset_from_base_address(res); + *out_offset += iris_bo_offset_from_base_address(bo); pipe_resource_reference(&res, NULL); @@ -867,8 +848,9 @@ iris_bind_sampler_states(struct pipe_context *ctx, if (unlikely(!map)) return; + struct pipe_resource *res = ice->state.sampler_table_resource[stage]; ice->state.sampler_table_offset[stage] += - bo_offset_from_base_address(ice->state.sampler_table_resource[stage]); + iris_bo_offset_from_base_address(iris_resource_bo(res)); for (int i = 0; i < count; i++) { struct iris_sampler_state *state = states[i]; @@ -965,8 +947,8 @@ iris_create_sampler_view(struct pipe_context *ctx, if (!unlikely(map)) return NULL; - isv->surface_state_offset += - bo_offset_from_base_address(isv->surface_state_resource); + struct iris_bo *state_bo = iris_resource_bo(isv->surface_state_resource); + isv->surface_state_offset += iris_bo_offset_from_base_address(state_bo); isl_surf_fill_state(&screen->isl_dev, map, .surf = &itex->surf, .view = &isv->view, @@ -1034,8 +1016,8 @@ iris_create_surface(struct pipe_context *ctx, if (!unlikely(map)) return NULL; - surf->surface_state_offset += - bo_offset_from_base_address(surf->surface_state_resource); + struct iris_bo *state_bo = iris_resource_bo(surf->surface_state_resource); + surf->surface_state_offset += iris_bo_offset_from_base_address(state_bo); isl_surf_fill_state(&screen->isl_dev, map, .surf = &itex->surf, .view = &surf->view, -- 2.30.2