From: Alyssa Rosenzweig Date: Tue, 7 Jul 2020 20:24:41 +0000 (-0400) Subject: panfrost: Move pool routines to common code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c8d848b2782b99eb617cb83958a3d977c406e8ff;p=mesa.git panfrost: Move pool routines to common code We finally have it decoupled from Galliumisms (and OpenGLisms, indeed) so we can share the file. Signed-off-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/gallium/drivers/panfrost/Makefile.sources b/src/gallium/drivers/panfrost/Makefile.sources index 2453edec60c..4688754672c 100644 --- a/src/gallium/drivers/panfrost/Makefile.sources +++ b/src/gallium/drivers/panfrost/Makefile.sources @@ -2,8 +2,6 @@ C_SOURCES := \ nir/nir_lower_blend.c \ nir/nir_lower_blend.h \ \ - pan_allocate.c \ - pan_allocate.h \ pan_assemble.c \ pan_blend_cso.c \ pan_blend.h \ diff --git a/src/gallium/drivers/panfrost/meson.build b/src/gallium/drivers/panfrost/meson.build index b3ebb16fe2d..154d05a7344 100644 --- a/src/gallium/drivers/panfrost/meson.build +++ b/src/gallium/drivers/panfrost/meson.build @@ -31,7 +31,6 @@ files_panfrost = files( 'pan_context.c', 'pan_blit.c', 'pan_job.c', - 'pan_allocate.c', 'pan_assemble.c', 'pan_blending.c', 'pan_blend_shaders.c', diff --git a/src/gallium/drivers/panfrost/pan_allocate.c b/src/gallium/drivers/panfrost/pan_allocate.c deleted file mode 100644 index ed8d26f127e..00000000000 --- a/src/gallium/drivers/panfrost/pan_allocate.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * © Copyright 2018 Alyssa Rosenzweig - * Copyright (C) 2019 Collabora, Ltd. - * - * 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 -#include -#include -#include -#include -#include -#include "pan_bo.h" -#include "pan_context.h" - -/* TODO: What does this actually have to be? */ -#define ALIGNMENT 128 - -/* Transient command stream pooling: command stream uploads try to simply copy - * into whereever we left off. If there isn't space, we allocate a new entry - * into the pool and copy there */ - -struct pan_pool -panfrost_create_pool(void *memctx, struct panfrost_device *dev) -{ - struct pan_pool pool = { - .dev = dev, - .transient_offset = 0, - .transient_bo = NULL - }; - - pool.bos = _mesa_hash_table_create(memctx, _mesa_hash_pointer, - _mesa_key_pointer_equal); - - - return pool; -} - -struct panfrost_transfer -panfrost_pool_alloc(struct pan_pool *pool, size_t sz) -{ - /* Pad the size */ - sz = ALIGN_POT(sz, ALIGNMENT); - - /* Find or create a suitable BO */ - struct panfrost_bo *bo = NULL; - - unsigned offset = 0; - - bool fits_in_current = (pool->transient_offset + sz) < TRANSIENT_SLAB_SIZE; - - if (likely(pool->transient_bo && fits_in_current)) { - /* We can reuse the current BO, so get it */ - bo = pool->transient_bo; - - /* Use the specified offset */ - offset = pool->transient_offset; - pool->transient_offset = offset + sz; - } else { - size_t bo_sz = sz < TRANSIENT_SLAB_SIZE ? - TRANSIENT_SLAB_SIZE : ALIGN_POT(sz, 4096); - - /* We can't reuse the current BO, but we can create a new one. - * We don't know what the BO will be used for, so let's flag it - * RW and attach it to both the fragment and vertex/tiler jobs. - * TODO: if we want fine grained BO assignment we should pass - * flags to this function and keep the read/write, - * fragment/vertex+tiler pools separate. - */ - bo = panfrost_bo_create(pool->dev, bo_sz, 0); - - uintptr_t flags = PAN_BO_ACCESS_PRIVATE | - PAN_BO_ACCESS_RW | - PAN_BO_ACCESS_VERTEX_TILER | - PAN_BO_ACCESS_FRAGMENT; - - _mesa_hash_table_insert(pool->bos, bo, (void *) flags); - - if (sz < TRANSIENT_SLAB_SIZE) { - pool->transient_bo = bo; - pool->transient_offset = offset + sz; - } - } - - struct panfrost_transfer ret = { - .cpu = bo->cpu + offset, - .gpu = bo->gpu + offset, - }; - - return ret; - -} - -mali_ptr -panfrost_pool_upload(struct pan_pool *pool, const void *data, size_t sz) -{ - struct panfrost_transfer transfer = panfrost_pool_alloc(pool, sz); - memcpy(transfer.cpu, data, sz); - return transfer.gpu; -} diff --git a/src/gallium/drivers/panfrost/pan_allocate.h b/src/gallium/drivers/panfrost/pan_allocate.h deleted file mode 100644 index fa41d4c87c4..00000000000 --- a/src/gallium/drivers/panfrost/pan_allocate.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * © Copyright 2017-2018 Alyssa Rosenzweig - * - * 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 __PAN_ALLOCATE_H__ -#define __PAN_ALLOCATE_H__ - -#include -#include -#include - -#include - -#include "util/list.h" - -struct panfrost_batch; - -/* Represents a pool of memory that can only grow, used to allocate objects - * with the same lifetime as the pool itself. In OpenGL, a pool is owned by the - * batch for transient structures. In Vulkan, it may be owned by e.g. the - * command pool */ - -struct pan_pool { - /* Parent device for allocation */ - struct panfrost_device *dev; - - /* panfrost_bo -> access_flags owned by the pool */ - struct hash_table *bos; - - /* Current transient BO */ - struct panfrost_bo *transient_bo; - - /* Within the topmost transient BO, how much has been used? */ - unsigned transient_offset; -}; - -struct pan_pool -panfrost_create_pool(void *memctx, struct panfrost_device *dev); - -/* Represents a fat pointer for GPU-mapped memory, returned from the transient - * allocator and not used for much else */ - -struct panfrost_transfer { - uint8_t *cpu; - mali_ptr gpu; -}; - -struct panfrost_transfer -panfrost_pool_alloc(struct pan_pool *pool, size_t sz); - -mali_ptr -panfrost_pool_upload(struct pan_pool *pool, const void *data, size_t sz); - -#endif /* __PAN_ALLOCATE_H__ */ diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index fd2e72b2b1f..e761c63c38b 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -28,7 +28,7 @@ #include "panfrost-quirks.h" -#include "pan_allocate.h" +#include "pan_pool.h" #include "pan_bo.h" #include "pan_cmdstream.h" #include "pan_context.h" diff --git a/src/gallium/drivers/panfrost/pan_job.h b/src/gallium/drivers/panfrost/pan_job.h index c0a569bbf64..43ae7795d69 100644 --- a/src/gallium/drivers/panfrost/pan_job.h +++ b/src/gallium/drivers/panfrost/pan_job.h @@ -28,7 +28,7 @@ #include "util/u_dynarray.h" #include "pipe/p_state.h" -#include "pan_allocate.h" +#include "pan_pool.h" #include "pan_resource.h" /* panfrost_batch_fence is the out fence of a batch that users or other batches diff --git a/src/gallium/drivers/panfrost/pan_resource.h b/src/gallium/drivers/panfrost/pan_resource.h index 209a6c185cc..bc4e0dbb6c4 100644 --- a/src/gallium/drivers/panfrost/pan_resource.h +++ b/src/gallium/drivers/panfrost/pan_resource.h @@ -28,7 +28,7 @@ #include #include "pan_screen.h" -#include "pan_allocate.h" +#include "pan_pool.h" #include "pan_minmax_cache.h" #include "pan_texture.h" #include "drm-uapi/drm.h" diff --git a/src/gallium/drivers/panfrost/pan_scoreboard.c b/src/gallium/drivers/panfrost/pan_scoreboard.c index 7023ebc4385..63a0f86e737 100644 --- a/src/gallium/drivers/panfrost/pan_scoreboard.c +++ b/src/gallium/drivers/panfrost/pan_scoreboard.c @@ -24,7 +24,7 @@ #include "pan_context.h" #include "pan_job.h" -#include "pan_allocate.h" +#include "pan_pool.h" #include "panfrost-quirks.h" #include "util/bitset.h" diff --git a/src/gallium/drivers/panfrost/pan_screen.h b/src/gallium/drivers/panfrost/pan_screen.h index f67856949e2..6fe6381e20f 100644 --- a/src/gallium/drivers/panfrost/pan_screen.h +++ b/src/gallium/drivers/panfrost/pan_screen.h @@ -39,7 +39,7 @@ #include #include "pan_device.h" -#include "pan_allocate.h" +#include "pan_pool.h" struct panfrost_batch; struct panfrost_context; diff --git a/src/panfrost/Makefile.sources b/src/panfrost/Makefile.sources index 568729887de..d085b763e3e 100644 --- a/src/panfrost/Makefile.sources +++ b/src/panfrost/Makefile.sources @@ -29,6 +29,8 @@ encoder_FILES := \ encoder/pan_encoder.h \ encoder/pan_format.c \ encoder/pan_invocation.c \ + encoder/pan_pool.c \ + encoder/pan_pool.h \ encoder/pan_props.c \ encoder/pan_sampler.c \ encoder/pan_tiler.c \ diff --git a/src/panfrost/encoder/meson.build b/src/panfrost/encoder/meson.build index 0086834977b..2e5baea4fc5 100644 --- a/src/panfrost/encoder/meson.build +++ b/src/panfrost/encoder/meson.build @@ -31,6 +31,7 @@ libpanfrost_encoder_files = files( 'pan_tiler.c', 'pan_texture.c', 'pan_scratch.c', + 'pan_pool.c', 'pan_props.c', ) diff --git a/src/panfrost/encoder/pan_pool.c b/src/panfrost/encoder/pan_pool.c new file mode 100644 index 00000000000..1a08be2aacf --- /dev/null +++ b/src/panfrost/encoder/pan_pool.c @@ -0,0 +1,114 @@ +/* + * © Copyright 2018 Alyssa Rosenzweig + * Copyright (C) 2019 Collabora, Ltd. + * + * 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 "util/hash_table.h" +#include "pan_bo.h" +#include "pan_pool.h" + +/* TODO: What does this actually have to be? */ +#define ALIGNMENT 128 + +/* Transient command stream pooling: command stream uploads try to simply copy + * into whereever we left off. If there isn't space, we allocate a new entry + * into the pool and copy there */ + +struct pan_pool +panfrost_create_pool(void *memctx, struct panfrost_device *dev) +{ + struct pan_pool pool = { + .dev = dev, + .transient_offset = 0, + .transient_bo = NULL + }; + + pool.bos = _mesa_hash_table_create(memctx, _mesa_hash_pointer, + _mesa_key_pointer_equal); + + + return pool; +} + +struct panfrost_transfer +panfrost_pool_alloc(struct pan_pool *pool, size_t sz) +{ + /* Pad the size */ + sz = ALIGN_POT(sz, ALIGNMENT); + + /* Find or create a suitable BO */ + struct panfrost_bo *bo = NULL; + + unsigned offset = 0; + + bool fits_in_current = (pool->transient_offset + sz) < TRANSIENT_SLAB_SIZE; + + if (likely(pool->transient_bo && fits_in_current)) { + /* We can reuse the current BO, so get it */ + bo = pool->transient_bo; + + /* Use the specified offset */ + offset = pool->transient_offset; + pool->transient_offset = offset + sz; + } else { + size_t bo_sz = sz < TRANSIENT_SLAB_SIZE ? + TRANSIENT_SLAB_SIZE : ALIGN_POT(sz, 4096); + + /* We can't reuse the current BO, but we can create a new one. + * We don't know what the BO will be used for, so let's flag it + * RW and attach it to both the fragment and vertex/tiler jobs. + * TODO: if we want fine grained BO assignment we should pass + * flags to this function and keep the read/write, + * fragment/vertex+tiler pools separate. + */ + bo = panfrost_bo_create(pool->dev, bo_sz, 0); + + uintptr_t flags = PAN_BO_ACCESS_PRIVATE | + PAN_BO_ACCESS_RW | + PAN_BO_ACCESS_VERTEX_TILER | + PAN_BO_ACCESS_FRAGMENT; + + _mesa_hash_table_insert(pool->bos, bo, (void *) flags); + + if (sz < TRANSIENT_SLAB_SIZE) { + pool->transient_bo = bo; + pool->transient_offset = offset + sz; + } + } + + struct panfrost_transfer ret = { + .cpu = bo->cpu + offset, + .gpu = bo->gpu + offset, + }; + + return ret; + +} + +mali_ptr +panfrost_pool_upload(struct pan_pool *pool, const void *data, size_t sz) +{ + struct panfrost_transfer transfer = panfrost_pool_alloc(pool, sz); + memcpy(transfer.cpu, data, sz); + return transfer.gpu; +} diff --git a/src/panfrost/encoder/pan_pool.h b/src/panfrost/encoder/pan_pool.h new file mode 100644 index 00000000000..6d7899800ce --- /dev/null +++ b/src/panfrost/encoder/pan_pool.h @@ -0,0 +1,66 @@ +/* + * © Copyright 2017-2018 Alyssa Rosenzweig + * + * 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 __PAN_POOL_H__ +#define __PAN_POOL_H__ + +#include + +/* Represents a pool of memory that can only grow, used to allocate objects + * with the same lifetime as the pool itself. In OpenGL, a pool is owned by the + * batch for transient structures. In Vulkan, it may be owned by e.g. the + * command pool */ + +struct pan_pool { + /* Parent device for allocation */ + struct panfrost_device *dev; + + /* panfrost_bo -> access_flags owned by the pool */ + struct hash_table *bos; + + /* Current transient BO */ + struct panfrost_bo *transient_bo; + + /* Within the topmost transient BO, how much has been used? */ + unsigned transient_offset; +}; + +struct pan_pool +panfrost_create_pool(void *memctx, struct panfrost_device *dev); + +/* Represents a fat pointer for GPU-mapped memory, returned from the transient + * allocator and not used for much else */ + +struct panfrost_transfer { + uint8_t *cpu; + mali_ptr gpu; +}; + +struct panfrost_transfer +panfrost_pool_alloc(struct pan_pool *pool, size_t sz); + +mali_ptr +panfrost_pool_upload(struct pan_pool *pool, const void *data, size_t sz); + +#endif