diff --git a/src/broadcom/vulkan/meson.build b/src/broadcom/vulkan/meson.build index 4b35c5b4cdd..472d2dc75f2 100644 --- a/src/broadcom/vulkan/meson.build +++ b/src/broadcom/vulkan/meson.build @@ -53,6 +53,10 @@ libv3dv_files = files( 'v3dv_wsi.c', ) +files_per_version = files( + 'v3dvx_queue.c', +) + # The vulkan driver only supports version >= 42, which is the version present in # Rpi4. We need to explicitly set it as we are reusing pieces from the GL v3d # driver. @@ -96,7 +100,7 @@ endif libvulkan_broadcom = shared_library( 'vulkan_broadcom', - [libv3dv_files, v3dv_entrypoints, sha1_h], + [libv3dv_files, files_per_version, v3dv_entrypoints, sha1_h], include_directories : [ inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_broadcom, inc_compiler, inc_util, inc_vulkan_wsi, ], diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 9443c58387d..c989e0b8393 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -2146,4 +2146,31 @@ u64_compare(const void *key1, const void *key2) return memcmp(key1, key2, sizeof(uint64_t)) == 0; } +/* Helper to call hw ver speficic functions */ +#define v3dv_X(device, thing) ({ \ + __typeof(&v3d42_##thing) v3d_X_thing; \ + switch (device->devinfo.ver) { \ + case 42: \ + v3d_X_thing = &v3d42_##thing; \ + break; \ + default: \ + unreachable("Unsupported hardware generation"); \ + } \ + v3d_X_thing; \ +}) + + +/* v3d_macros from common requires v3dX and V3DX definitions. Below we need to + * define v3dX for each version supported, because when we compile code that + * is not version-specific, all version-specific macros need to be already + * defined. + */ +#ifdef v3dX +# include "v3dvx_private.h" +#else +# define v3dX(x) v3d42_##x +# include "v3dvx_private.h" +# undef v3dX +#endif + #endif /* V3DV_PRIVATE_H */ diff --git a/src/broadcom/vulkan/v3dv_queue.c b/src/broadcom/vulkan/v3dv_queue.c index 25cc6c723e3..b72aff33e26 100644 --- a/src/broadcom/vulkan/v3dv_queue.c +++ b/src/broadcom/vulkan/v3dv_queue.c @@ -758,91 +758,6 @@ queue_submit_job(struct v3dv_queue *queue, } } -static void -emit_noop_bin(struct v3dv_job *job) -{ - v3dv_job_start_frame(job, 1, 1, 1, 1, V3D_INTERNAL_BPP_32, false); - v3dv_job_emit_binning_flush(job); -} - -static void -emit_noop_render(struct v3dv_job *job) -{ - struct v3dv_cl *rcl = &job->rcl; - v3dv_cl_ensure_space_with_branch(rcl, 200 + 1 * 256 * - cl_packet_length(SUPERTILE_COORDINATES)); - - cl_emit(rcl, TILE_RENDERING_MODE_CFG_COMMON, config) { - config.early_z_disable = true; - config.image_width_pixels = 1; - config.image_height_pixels = 1; - config.number_of_render_targets = 1; - config.multisample_mode_4x = false; - config.maximum_bpp_of_all_render_targets = V3D_INTERNAL_BPP_32; - } - - cl_emit(rcl, TILE_RENDERING_MODE_CFG_COLOR, rt) { - rt.render_target_0_internal_bpp = V3D_INTERNAL_BPP_32; - rt.render_target_0_internal_type = V3D_INTERNAL_TYPE_8; - rt.render_target_0_clamp = V3D_RENDER_TARGET_CLAMP_NONE; - } - - cl_emit(rcl, TILE_RENDERING_MODE_CFG_ZS_CLEAR_VALUES, clear) { - clear.z_clear_value = 1.0f; - clear.stencil_clear_value = 0; - }; - - cl_emit(rcl, TILE_LIST_INITIAL_BLOCK_SIZE, init) { - init.use_auto_chained_tile_lists = true; - init.size_of_first_block_in_chained_tile_lists = - TILE_ALLOCATION_BLOCK_SIZE_64B; - } - - cl_emit(rcl, MULTICORE_RENDERING_TILE_LIST_SET_BASE, list) { - list.address = v3dv_cl_address(job->tile_alloc, 0); - } - - cl_emit(rcl, MULTICORE_RENDERING_SUPERTILE_CFG, config) { - config.number_of_bin_tile_lists = 1; - config.total_frame_width_in_tiles = 1; - config.total_frame_height_in_tiles = 1; - config.supertile_width_in_tiles = 1; - config.supertile_height_in_tiles = 1; - config.total_frame_width_in_supertiles = 1; - config.total_frame_height_in_supertiles = 1; - } - - struct v3dv_cl *icl = &job->indirect; - v3dv_cl_ensure_space(icl, 200, 1); - struct v3dv_cl_reloc tile_list_start = v3dv_cl_get_address(icl); - - cl_emit(icl, TILE_COORDINATES_IMPLICIT, coords); - - cl_emit(icl, END_OF_LOADS, end); - - cl_emit(icl, BRANCH_TO_IMPLICIT_TILE_LIST, branch); - - cl_emit(icl, STORE_TILE_BUFFER_GENERAL, store) { - store.buffer_to_store = NONE; - } - - cl_emit(icl, END_OF_TILE_MARKER, end); - - cl_emit(icl, RETURN_FROM_SUB_LIST, ret); - - cl_emit(rcl, START_ADDRESS_OF_GENERIC_TILE_LIST, branch) { - branch.start = tile_list_start; - branch.end = v3dv_cl_get_address(icl); - } - - cl_emit(rcl, SUPERTILE_COORDINATES, coords) { - coords.column_number_in_supertiles = 0; - coords.row_number_in_supertiles = 0; - } - - cl_emit(rcl, END_OF_RENDERING, end); -} - static VkResult queue_create_noop_job(struct v3dv_queue *queue) { @@ -853,8 +768,7 @@ queue_create_noop_job(struct v3dv_queue *queue) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); v3dv_job_init(queue->noop_job, V3DV_JOB_TYPE_GPU_CL, device, NULL, -1); - emit_noop_bin(queue->noop_job); - emit_noop_render(queue->noop_job); + v3dv_X(device, job_emit_noop)(queue->noop_job); return VK_SUCCESS; } diff --git a/src/broadcom/vulkan/v3dvx_private.h b/src/broadcom/vulkan/v3dvx_private.h new file mode 100644 index 00000000000..436d2518d00 --- /dev/null +++ b/src/broadcom/vulkan/v3dvx_private.h @@ -0,0 +1,34 @@ +/* + * Copyright © 2021 Raspberry Pi + * + * 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. + */ + +/* This file generates the per-v3d-version function prototypes. It must only + * be included from v3dv_private.h. + */ + +#ifndef V3DV_PRIVATE_H +#error This file is included by means other than v3dv_private.h +#endif + +/* Used at v3dv_queue */ +void +v3dX(job_emit_noop)(struct v3dv_job *job); diff --git a/src/broadcom/vulkan/v3dvx_queue.c b/src/broadcom/vulkan/v3dvx_queue.c new file mode 100644 index 00000000000..3d082291b16 --- /dev/null +++ b/src/broadcom/vulkan/v3dvx_queue.c @@ -0,0 +1,108 @@ +/* + * Copyright © 2021 Raspberry Pi + * + * 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 "v3dv_private.h" +#include "broadcom/common/v3d_macros.h" +#include "broadcom/cle/v3dx_pack.h" +#include "broadcom/compiler/v3d_compiler.h" + +void +v3dX(job_emit_noop)(struct v3dv_job *job) +{ + v3dv_job_start_frame(job, 1, 1, 1, 1, V3D_INTERNAL_BPP_32, false); + v3dv_job_emit_binning_flush(job); + + struct v3dv_cl *rcl = &job->rcl; + v3dv_cl_ensure_space_with_branch(rcl, 200 + 1 * 256 * + cl_packet_length(SUPERTILE_COORDINATES)); + + cl_emit(rcl, TILE_RENDERING_MODE_CFG_COMMON, config) { + config.early_z_disable = true; + config.image_width_pixels = 1; + config.image_height_pixels = 1; + config.number_of_render_targets = 1; + config.multisample_mode_4x = false; + config.maximum_bpp_of_all_render_targets = V3D_INTERNAL_BPP_32; + } + + cl_emit(rcl, TILE_RENDERING_MODE_CFG_COLOR, rt) { + rt.render_target_0_internal_bpp = V3D_INTERNAL_BPP_32; + rt.render_target_0_internal_type = V3D_INTERNAL_TYPE_8; + rt.render_target_0_clamp = V3D_RENDER_TARGET_CLAMP_NONE; + } + + cl_emit(rcl, TILE_RENDERING_MODE_CFG_ZS_CLEAR_VALUES, clear) { + clear.z_clear_value = 1.0f; + clear.stencil_clear_value = 0; + }; + + cl_emit(rcl, TILE_LIST_INITIAL_BLOCK_SIZE, init) { + init.use_auto_chained_tile_lists = true; + init.size_of_first_block_in_chained_tile_lists = + TILE_ALLOCATION_BLOCK_SIZE_64B; + } + + cl_emit(rcl, MULTICORE_RENDERING_TILE_LIST_SET_BASE, list) { + list.address = v3dv_cl_address(job->tile_alloc, 0); + } + + cl_emit(rcl, MULTICORE_RENDERING_SUPERTILE_CFG, config) { + config.number_of_bin_tile_lists = 1; + config.total_frame_width_in_tiles = 1; + config.total_frame_height_in_tiles = 1; + config.supertile_width_in_tiles = 1; + config.supertile_height_in_tiles = 1; + config.total_frame_width_in_supertiles = 1; + config.total_frame_height_in_supertiles = 1; + } + + struct v3dv_cl *icl = &job->indirect; + v3dv_cl_ensure_space(icl, 200, 1); + struct v3dv_cl_reloc tile_list_start = v3dv_cl_get_address(icl); + + cl_emit(icl, TILE_COORDINATES_IMPLICIT, coords); + + cl_emit(icl, END_OF_LOADS, end); + + cl_emit(icl, BRANCH_TO_IMPLICIT_TILE_LIST, branch); + + cl_emit(icl, STORE_TILE_BUFFER_GENERAL, store) { + store.buffer_to_store = NONE; + } + + cl_emit(icl, END_OF_TILE_MARKER, end); + + cl_emit(icl, RETURN_FROM_SUB_LIST, ret); + + cl_emit(rcl, START_ADDRESS_OF_GENERIC_TILE_LIST, branch) { + branch.start = tile_list_start; + branch.end = v3dv_cl_get_address(icl); + } + + cl_emit(rcl, SUPERTILE_COORDINATES, coords) { + coords.column_number_in_supertiles = 0; + coords.row_number_in_supertiles = 0; + } + + cl_emit(rcl, END_OF_RENDERING, end); +}