From: Alyssa Rosenzweig Date: Tue, 18 Jun 2019 18:16:21 +0000 (-0700) Subject: lima,panfrost: Move lima_tiling.c/h to /src/panfrost X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=413242277a2653d12d5ea8d8acba533530281fd6;hp=c57b4c86c07adce6738c01fae5906f4a4a46d93f lima,panfrost: Move lima_tiling.c/h to /src/panfrost This will allow both drivers to share this code. Both drivers build-tested with meson. Android build not tested. v2: Change naming from tiling->shared, in case Lima and Panfrost can share more in the future. Fix Android build system. Signed-off-by: Alyssa Rosenzweig Reviewed-and-tested-by: Qiang Yu --- diff --git a/src/gallium/drivers/lima/Android.mk b/src/gallium/drivers/lima/Android.mk index eb8653e8524..516e714deff 100644 --- a/src/gallium/drivers/lima/Android.mk +++ b/src/gallium/drivers/lima/Android.mk @@ -67,8 +67,6 @@ LOCAL_SRC_FILES := \ lima_submit.h \ lima_texture.c \ lima_texture.h \ - lima_tiling.c \ - lima_tiling.h \ lima_util.c \ lima_util.h diff --git a/src/gallium/drivers/lima/lima_resource.c b/src/gallium/drivers/lima/lima_resource.c index 0aefb2c7900..b5dbfe5d3ef 100644 --- a/src/gallium/drivers/lima/lima_resource.c +++ b/src/gallium/drivers/lima/lima_resource.c @@ -44,7 +44,7 @@ #include "lima_resource.h" #include "lima_bo.h" #include "lima_util.h" -#include "lima_tiling.h" +#include "pan_tiling.h" static struct pipe_resource * lima_resource_create_scanout(struct pipe_screen *pscreen, @@ -505,7 +505,7 @@ lima_transfer_map(struct pipe_context *pctx, trans->staging = malloc(ptrans->stride * ptrans->box.height * ptrans->box.depth); if (usage & PIPE_TRANSFER_READ) - lima_load_tiled_image(trans->staging, bo->map + res->levels[level].offset, + panfrost_load_tiled_image(trans->staging, bo->map + res->levels[level].offset, &ptrans->box, ptrans->stride, res->levels[level].stride, @@ -545,7 +545,7 @@ lima_transfer_unmap(struct pipe_context *pctx, if (trans->staging) { pres = &res->base; if (ptrans->usage & PIPE_TRANSFER_WRITE) - lima_store_tiled_image(bo->map + res->levels[ptrans->level].offset, trans->staging, + panfrost_store_tiled_image(bo->map + res->levels[ptrans->level].offset, trans->staging, &ptrans->box, res->levels[ptrans->level].stride, ptrans->stride, diff --git a/src/gallium/drivers/lima/lima_tiling.c b/src/gallium/drivers/lima/lima_tiling.c deleted file mode 100644 index 6332e47055d..00000000000 --- a/src/gallium/drivers/lima/lima_tiling.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2011-2013 Luc Verhaegen - * Copyright (c) 2018 Alyssa Rosenzweig - * Copyright (c) 2018 Vasily Khoruzhick - * - * 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, sub license, - * 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 NON-INFRINGEMENT. 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 "lima_tiling.h" - -uint32_t space_filler[16][16] = { - { 0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85, }, - { 3, 2, 7, 6, 19, 18, 23, 22, 67, 66, 71, 70, 83, 82, 87, 86, }, - { 12, 13, 8, 9, 28, 29, 24, 25, 76, 77, 72, 73, 92, 93, 88, 89, }, - { 15, 14, 11, 10, 31, 30, 27, 26, 79, 78, 75, 74, 95, 94, 91, 90, }, - { 48, 49, 52, 53, 32, 33, 36, 37, 112, 113, 116, 117, 96, 97, 100, 101, }, - { 51, 50, 55, 54, 35, 34, 39, 38, 115, 114, 119, 118, 99, 98, 103, 102, }, - { 60, 61, 56, 57, 44, 45, 40, 41, 124, 125, 120, 121, 108, 109, 104, 105, }, - { 63, 62, 59, 58, 47, 46, 43, 42, 127, 126, 123, 122, 111, 110, 107, 106, }, - { 192, 193, 196, 197, 208, 209, 212, 213, 128, 129, 132, 133, 144, 145, 148, 149, }, - { 195, 194, 199, 198, 211, 210, 215, 214, 131, 130, 135, 134, 147, 146, 151, 150, }, - { 204, 205, 200, 201, 220, 221, 216, 217, 140, 141, 136, 137, 156, 157, 152, 153, }, - { 207, 206, 203, 202, 223, 222, 219, 218, 143, 142, 139, 138, 159, 158, 155, 154, }, - { 240, 241, 244, 245, 224, 225, 228, 229, 176, 177, 180, 181, 160, 161, 164, 165, }, - { 243, 242, 247, 246, 227, 226, 231, 230, 179, 178, 183, 182, 163, 162, 167, 166, }, - { 252, 253, 248, 249, 236, 237, 232, 233, 188, 189, 184, 185, 172, 173, 168, 169, }, - { 255, 254, 251, 250, 239, 238, 235, 234, 191, 190, 187, 186, 175, 174, 171, 170, }, -}; - -static void -lima_store_tiled_image_bpp4(void *dst, const void *src, - const struct pipe_box *box, - uint32_t dst_stride, - uint32_t src_stride) -{ - for (int y = box->y, src_y = 0; src_y < box->height; ++y, ++src_y) { - int block_y = y & ~0x0f; - int rem_y = y & 0x0F; - int block_start_s = block_y * dst_stride; - int source_start = src_y * src_stride; - - for (int x = box->x, src_x = 0; src_x < box->width; ++x, ++src_x) { - int block_x_s = (x >> 4) * 256; - int rem_x = x & 0x0F; - - int index = space_filler[rem_y][rem_x]; - const uint32_t *source = src + source_start + 4 * src_x; - uint32_t *dest = dst + block_start_s + 4 * (block_x_s + index); - - *dest = *source; - } - } -} - -static void -lima_store_tiled_image_generic(void *dst, const void *src, - const struct pipe_box *box, - uint32_t dst_stride, - uint32_t src_stride, - uint32_t bpp) -{ - for (int y = box->y, src_y = 0; src_y < box->height; ++y, ++src_y) { - int block_y = y & ~0x0f; - int rem_y = y & 0x0F; - int block_start_s = block_y * dst_stride; - int source_start = src_y * src_stride; - - for (int x = box->x, src_x = 0; src_x < box->width; ++x, ++src_x) { - int block_x_s = (x >> 4) * 256; - int rem_x = x & 0x0F; - - int index = space_filler[rem_y][rem_x]; - const uint8_t *src8 = src; - const uint8_t *source = &src8[source_start + bpp * src_x]; - uint8_t *dest = dst + block_start_s + bpp * (block_x_s + index); - - for (int b = 0; b < bpp; ++b) - dest[b] = source[b]; - } - } -} - -static void -lima_load_tiled_image_bpp4(void *dst, const void *src, - const struct pipe_box *box, - uint32_t dst_stride, - uint32_t src_stride) -{ - for (int y = box->y, dest_y = 0; dest_y < box->height; ++y, ++dest_y) { - int block_y = y & ~0x0f; - int rem_y = y & 0x0F; - int block_start_s = block_y * src_stride; - int dest_start = dest_y * dst_stride; - - for (int x = box->x, dest_x = 0; dest_x < box->width; ++x, ++dest_x) { - int block_x_s = (x >> 4) * 256; - int rem_x = x & 0x0F; - - int index = space_filler[rem_y][rem_x]; - uint32_t *dest = dst + dest_start + 4 * dest_x; - const uint32_t *source = src + block_start_s + 4 * (block_x_s + index); - - *dest = *source; - } - } -} - -static void -lima_load_tiled_image_generic(void *dst, const void *src, - const struct pipe_box *box, - uint32_t dst_stride, - uint32_t src_stride, - uint32_t bpp) -{ - for (int y = box->y, dest_y = 0; dest_y < box->height; ++y, ++dest_y) { - int block_y = y & ~0x0f; - int rem_y = y & 0x0F; - int block_start_s = block_y * src_stride; - int dest_start = dest_y * dst_stride; - - for (int x = box->x, dest_x = 0; dest_x < box->width; ++x, ++dest_x) { - int block_x_s = (x >> 4) * 256; - int rem_x = x & 0x0F; - - int index = space_filler[rem_y][rem_x]; - uint8_t *dst8 = dst; - uint8_t *dest = &dst8[dest_start + bpp * dest_x]; - const uint8_t *source = src + block_start_s + bpp * (block_x_s + index); - - for (int b = 0; b < bpp; ++b) - dest[b] = source[b]; - } - } -} - -void -lima_store_tiled_image(void *dst, const void *src, - const struct pipe_box *box, - uint32_t dst_stride, - uint32_t src_stride, - uint32_t bpp) -{ - switch (bpp) { - case 4: - lima_store_tiled_image_bpp4(dst, src, box, dst_stride, src_stride); - break; - default: - lima_store_tiled_image_generic(dst, src, box, dst_stride, src_stride, bpp); - } -} - -void -lima_load_tiled_image(void *dst, const void *src, - const struct pipe_box *box, - uint32_t dst_stride, - uint32_t src_stride, - uint32_t bpp) -{ - switch (bpp) { - case 4: - lima_load_tiled_image_bpp4(dst, src, box, dst_stride, src_stride); - break; - default: - lima_load_tiled_image_generic(dst, src, box, dst_stride, src_stride, bpp); - } -} diff --git a/src/gallium/drivers/lima/lima_tiling.h b/src/gallium/drivers/lima/lima_tiling.h deleted file mode 100644 index ea3a4219d66..00000000000 --- a/src/gallium/drivers/lima/lima_tiling.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2011-2013 Luc Verhaegen - * Copyright (c) 2018 Alyssa Rosenzweig - * Copyright (c) 2018 Vasily Khoruzhick - * - * 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, sub license, - * 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 NON-INFRINGEMENT. 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 H_LIMA_TILING -#define H_LIMA_TILING - -#include "util/u_box.h" - -void lima_load_tiled_image(void *dst, const void *src, - const struct pipe_box *box, - uint32_t dst_stride, - uint32_t src_stride, - uint32_t bpp); - -void lima_store_tiled_image(void *dst, const void *src, - const struct pipe_box *box, - uint32_t dst_stride, - uint32_t src_stride, - uint32_t bpp); - -#endif diff --git a/src/gallium/drivers/lima/meson.build b/src/gallium/drivers/lima/meson.build index a05f0e275ed..b6a197fcc8d 100644 --- a/src/gallium/drivers/lima/meson.build +++ b/src/gallium/drivers/lima/meson.build @@ -69,8 +69,6 @@ files_lima = files( 'lima_texture.h', 'lima_fence.c', 'lima_fence.h', - 'lima_tiling.c', - 'lima_tiling.h', ) liblima = static_library( @@ -78,12 +76,13 @@ liblima = static_library( files_lima, include_directories : [ inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_gallium_drivers, + inc_panfrost ], dependencies : [dep_libdrm, idep_nir_headers], ) driver_lima = declare_dependency( compile_args : '-DGALLIUM_LIMA', - link_with : [liblima, liblimawinsys], + link_with : [liblima, liblimawinsys, libpanfrost_shared], dependencies : idep_nir, ) diff --git a/src/gallium/drivers/panfrost/meson.build b/src/gallium/drivers/panfrost/meson.build index 39f1fd8e6b0..94b89098bc8 100644 --- a/src/gallium/drivers/panfrost/meson.build +++ b/src/gallium/drivers/panfrost/meson.build @@ -63,7 +63,7 @@ files_panfrost = files( 'pan_tiler.c', ) -inc_panfrost = [ +panfrost_includes = [ inc_common, inc_gallium, inc_gallium_aux, @@ -99,7 +99,7 @@ libpanfrost = static_library( dep_libdrm, idep_nir ], - include_directories : inc_panfrost, + include_directories : panfrost_includes, c_args : [c_vis_args, c_msvc_compat_args, compile_args_panfrost], ) @@ -151,7 +151,7 @@ files_pandecode = files( pandecode = executable( 'pandecode', files_pandecode, - include_directories : inc_panfrost, + include_directories : panfrost_includes, dependencies : [ dep_thread, ], diff --git a/src/meson.build b/src/meson.build index 8b983c15b60..0dcd7eef65d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -70,6 +70,9 @@ endif if with_gallium_freedreno or with_freedreno_vk subdir('freedreno') endif +if with_gallium_panfrost or with_gallium_lima + subdir('panfrost') +endif if with_dri_i965 or with_intel_vk or with_gallium_iris subdir('intel') endif diff --git a/src/panfrost/Android.mk b/src/panfrost/Android.mk new file mode 100644 index 00000000000..9ab5ddf9fdf --- /dev/null +++ b/src/panfrost/Android.mk @@ -0,0 +1,28 @@ +# Mesa 3-D graphics library +# +# Copyright (C) +# +# 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 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. + +# Android.mk for libpanfrost_* + +LOCAL_PATH := $(call my-dir) + +include $(LOCAL_PATH)/Makefile.sources +include $(LOCAL_PATH)/Android.shared.mk diff --git a/src/panfrost/Android.shared.mk b/src/panfrost/Android.shared.mk new file mode 100644 index 00000000000..e1dd3babfe6 --- /dev/null +++ b/src/panfrost/Android.shared.mk @@ -0,0 +1,43 @@ +# Mesa 3-D graphics library +# +# Copyright (C) +# +# 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 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. + +# Android.mk for libpanfrost_shared.a + +# --------------------------------------- +# Build libpanfrost_shared +# --------------------------------------- + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + $(shared_SOURCES) + +LOCAL_C_INCLUDES := \ + +LOCAL_STATIC_LIBRARIES := \ + +LOCAL_MODULE := libpanfrost_shared + +LOCAL_GENERATED_SOURCES := \ + +include $(MESA_COMMON_MK) +include $(BUILD_STATIC_LIBRARY) diff --git a/src/panfrost/Makefile.sources b/src/panfrost/Makefile.sources new file mode 100644 index 00000000000..3ab90f27913 --- /dev/null +++ b/src/panfrost/Makefile.sources @@ -0,0 +1,3 @@ +shared_FILES := \ + shared/pan_tiling.c \ + shared/pan_tiling.h diff --git a/src/panfrost/meson.build b/src/panfrost/meson.build new file mode 100644 index 00000000000..6b167d04b9c --- /dev/null +++ b/src/panfrost/meson.build @@ -0,0 +1,24 @@ +# Copyright © 2018 Rob Clark +# Copyright © 2019 Collabora + +# 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 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. + +inc_panfrost = include_directories(['.', 'shared']) + +subdir('shared') diff --git a/src/panfrost/shared/meson.build b/src/panfrost/shared/meson.build new file mode 100644 index 00000000000..0bf09dbbbf8 --- /dev/null +++ b/src/panfrost/shared/meson.build @@ -0,0 +1,34 @@ +# Copyright © 2018 Rob Clark +# Copyright © 2019 Collabora + +# 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 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. + +libpanfrost_shared_files = files( + 'pan_tiling.c', + 'pan_tiling.h', +) + +libpanfrost_shared = static_library( + 'panfrost_shared', + [libpanfrost_shared_files], + include_directories : [inc_common], + c_args : [c_vis_args, no_override_init_args], + cpp_args : [cpp_vis_args], + build_by_default : false, +) diff --git a/src/panfrost/shared/pan_tiling.c b/src/panfrost/shared/pan_tiling.c new file mode 100644 index 00000000000..413cd89420b --- /dev/null +++ b/src/panfrost/shared/pan_tiling.c @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2011-2013 Luc Verhaegen + * Copyright (c) 2018 Alyssa Rosenzweig + * Copyright (c) 2018 Vasily Khoruzhick + * + * 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, sub license, + * 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 NON-INFRINGEMENT. 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 "pan_tiling.h" + +uint32_t space_filler[16][16] = { + { 0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85, }, + { 3, 2, 7, 6, 19, 18, 23, 22, 67, 66, 71, 70, 83, 82, 87, 86, }, + { 12, 13, 8, 9, 28, 29, 24, 25, 76, 77, 72, 73, 92, 93, 88, 89, }, + { 15, 14, 11, 10, 31, 30, 27, 26, 79, 78, 75, 74, 95, 94, 91, 90, }, + { 48, 49, 52, 53, 32, 33, 36, 37, 112, 113, 116, 117, 96, 97, 100, 101, }, + { 51, 50, 55, 54, 35, 34, 39, 38, 115, 114, 119, 118, 99, 98, 103, 102, }, + { 60, 61, 56, 57, 44, 45, 40, 41, 124, 125, 120, 121, 108, 109, 104, 105, }, + { 63, 62, 59, 58, 47, 46, 43, 42, 127, 126, 123, 122, 111, 110, 107, 106, }, + { 192, 193, 196, 197, 208, 209, 212, 213, 128, 129, 132, 133, 144, 145, 148, 149, }, + { 195, 194, 199, 198, 211, 210, 215, 214, 131, 130, 135, 134, 147, 146, 151, 150, }, + { 204, 205, 200, 201, 220, 221, 216, 217, 140, 141, 136, 137, 156, 157, 152, 153, }, + { 207, 206, 203, 202, 223, 222, 219, 218, 143, 142, 139, 138, 159, 158, 155, 154, }, + { 240, 241, 244, 245, 224, 225, 228, 229, 176, 177, 180, 181, 160, 161, 164, 165, }, + { 243, 242, 247, 246, 227, 226, 231, 230, 179, 178, 183, 182, 163, 162, 167, 166, }, + { 252, 253, 248, 249, 236, 237, 232, 233, 188, 189, 184, 185, 172, 173, 168, 169, }, + { 255, 254, 251, 250, 239, 238, 235, 234, 191, 190, 187, 186, 175, 174, 171, 170, }, +}; + +static void +panfrost_store_tiled_image_bpp4(void *dst, const void *src, + const struct pipe_box *box, + uint32_t dst_stride, + uint32_t src_stride) +{ + for (int y = box->y, src_y = 0; src_y < box->height; ++y, ++src_y) { + int block_y = y & ~0x0f; + int rem_y = y & 0x0F; + int block_start_s = block_y * dst_stride; + int source_start = src_y * src_stride; + + for (int x = box->x, src_x = 0; src_x < box->width; ++x, ++src_x) { + int block_x_s = (x >> 4) * 256; + int rem_x = x & 0x0F; + + int index = space_filler[rem_y][rem_x]; + const uint32_t *source = src + source_start + 4 * src_x; + uint32_t *dest = dst + block_start_s + 4 * (block_x_s + index); + + *dest = *source; + } + } +} + +static void +panfrost_store_tiled_image_generic(void *dst, const void *src, + const struct pipe_box *box, + uint32_t dst_stride, + uint32_t src_stride, + uint32_t bpp) +{ + for (int y = box->y, src_y = 0; src_y < box->height; ++y, ++src_y) { + int block_y = y & ~0x0f; + int rem_y = y & 0x0F; + int block_start_s = block_y * dst_stride; + int source_start = src_y * src_stride; + + for (int x = box->x, src_x = 0; src_x < box->width; ++x, ++src_x) { + int block_x_s = (x >> 4) * 256; + int rem_x = x & 0x0F; + + int index = space_filler[rem_y][rem_x]; + const uint8_t *src8 = src; + const uint8_t *source = &src8[source_start + bpp * src_x]; + uint8_t *dest = dst + block_start_s + bpp * (block_x_s + index); + + for (int b = 0; b < bpp; ++b) + dest[b] = source[b]; + } + } +} + +static void +panfrost_load_tiled_image_bpp4(void *dst, const void *src, + const struct pipe_box *box, + uint32_t dst_stride, + uint32_t src_stride) +{ + for (int y = box->y, dest_y = 0; dest_y < box->height; ++y, ++dest_y) { + int block_y = y & ~0x0f; + int rem_y = y & 0x0F; + int block_start_s = block_y * src_stride; + int dest_start = dest_y * dst_stride; + + for (int x = box->x, dest_x = 0; dest_x < box->width; ++x, ++dest_x) { + int block_x_s = (x >> 4) * 256; + int rem_x = x & 0x0F; + + int index = space_filler[rem_y][rem_x]; + uint32_t *dest = dst + dest_start + 4 * dest_x; + const uint32_t *source = src + block_start_s + 4 * (block_x_s + index); + + *dest = *source; + } + } +} + +static void +panfrost_load_tiled_image_generic(void *dst, const void *src, + const struct pipe_box *box, + uint32_t dst_stride, + uint32_t src_stride, + uint32_t bpp) +{ + for (int y = box->y, dest_y = 0; dest_y < box->height; ++y, ++dest_y) { + int block_y = y & ~0x0f; + int rem_y = y & 0x0F; + int block_start_s = block_y * src_stride; + int dest_start = dest_y * dst_stride; + + for (int x = box->x, dest_x = 0; dest_x < box->width; ++x, ++dest_x) { + int block_x_s = (x >> 4) * 256; + int rem_x = x & 0x0F; + + int index = space_filler[rem_y][rem_x]; + uint8_t *dst8 = dst; + uint8_t *dest = &dst8[dest_start + bpp * dest_x]; + const uint8_t *source = src + block_start_s + bpp * (block_x_s + index); + + for (int b = 0; b < bpp; ++b) + dest[b] = source[b]; + } + } +} + +void +panfrost_store_tiled_image(void *dst, const void *src, + const struct pipe_box *box, + uint32_t dst_stride, + uint32_t src_stride, + uint32_t bpp) +{ + switch (bpp) { + case 4: + panfrost_store_tiled_image_bpp4(dst, src, box, dst_stride, src_stride); + break; + default: + panfrost_store_tiled_image_generic(dst, src, box, dst_stride, src_stride, bpp); + } +} + +void +panfrost_load_tiled_image(void *dst, const void *src, + const struct pipe_box *box, + uint32_t dst_stride, + uint32_t src_stride, + uint32_t bpp) +{ + switch (bpp) { + case 4: + panfrost_load_tiled_image_bpp4(dst, src, box, dst_stride, src_stride); + break; + default: + panfrost_load_tiled_image_generic(dst, src, box, dst_stride, src_stride, bpp); + } +} diff --git a/src/panfrost/shared/pan_tiling.h b/src/panfrost/shared/pan_tiling.h new file mode 100644 index 00000000000..1d55939ecbd --- /dev/null +++ b/src/panfrost/shared/pan_tiling.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2011-2013 Luc Verhaegen + * Copyright (c) 2018 Alyssa Rosenzweig + * Copyright (c) 2018 Vasily Khoruzhick + * + * 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, sub license, + * 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 NON-INFRINGEMENT. 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 H_PANFROST_TILING +#define H_PANFROST_TILING + +#include "util/u_box.h" + +void panfrost_load_tiled_image(void *dst, const void *src, + const struct pipe_box *box, + uint32_t dst_stride, + uint32_t src_stride, + uint32_t bpp); + +void panfrost_store_tiled_image(void *dst, const void *src, + const struct pipe_box *box, + uint32_t dst_stride, + uint32_t src_stride, + uint32_t bpp); + +#endif