1 /*
2 * Copyright © 2021 Raspberry Pi Ltd
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "v3dv_private.h"
25 #include "broadcom/common/v3d_macros.h"
26 #include "broadcom/cle/v3dx_pack.h"
27 #include "broadcom/compiler/v3d_compiler.h"
28
29 /*
30 * Returns how much space a given descriptor type needs on a bo (GPU
31 * memory).
32 */
33 uint32_t
v3dX(descriptor_bo_size)34 v3dX(descriptor_bo_size)(VkDescriptorType type)
35 {
36 switch(type) {
37 case VK_DESCRIPTOR_TYPE_SAMPLER:
38 return cl_aligned_packet_length(SAMPLER_STATE, 32);
39 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
40 return cl_aligned_packet_length(SAMPLER_STATE, 32) +
41 cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
42 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
43 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
44 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
45 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
46 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
47 return cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
48 default:
49 return 0;
50 }
51 }
52
53 /* To compute the max_bo_size we want to iterate through the descriptor
54 * types. Unfourtunately we can't just use the descriptor type enum values, as
55 * the values are not defined consecutively (so extensions could add new
56 * descriptor types), and VK_DESCRIPTOR_TYPE_MAX_ENUM is also a really big
57 * number.
58 */
59 static const uint32_t supported_descriptor_types[] = {
60 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
61 VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
62 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
63 VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC,
64 VK_DESCRIPTOR_TYPE_SAMPLER,
65 VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
66 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
67 VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
68 VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
69 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
70 VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
71 };
72
73 uint32_t
v3dX(max_descriptor_bo_size)74 v3dX(max_descriptor_bo_size)(void)
75 {
76 static uint32_t max = 0;
77
78 if (max == 0) {
79 for (uint32_t i = 0; i < ARRAY_SIZE(supported_descriptor_types); i++)
80 max = MAX2(max, v3dX(descriptor_bo_size)(supported_descriptor_types[i]));
81 }
82 assert(max != 0);
83
84 return max;
85 }
86
87
88 uint32_t
v3dX(combined_image_sampler_texture_state_offset)89 v3dX(combined_image_sampler_texture_state_offset)(void)
90 {
91 return 0;
92 }
93
94 uint32_t
v3dX(combined_image_sampler_sampler_state_offset)95 v3dX(combined_image_sampler_sampler_state_offset)(void)
96 {
97 return cl_aligned_packet_length(TEXTURE_SHADER_STATE, 32);
98 }
99