| 1 |
/* |
| 2 |
* Copyright © 2024 Collabora Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "panvk_cmd_alloc.h" |
| 7 |
#include "panvk_cmd_buffer.h" |
| 8 |
#include "panvk_entrypoints.h" |
| 9 |
|
| 10 |
VkResult |
| 11 |
panvk_per_arch(cmd_prepare_push_uniforms)( |
| 12 |
struct panvk_cmd_buffer *cmdbuf, const struct panvk_shader_variant *shader, |
| 13 |
uint32_t repeat_count) |
| 14 |
{ |
| 15 |
struct panvk_device *dev = to_panvk_device(cmdbuf->vk.base.device); |
| 16 |
uint64_t *push_ptr; |
| 17 |
|
| 18 |
switch (shader->info.stage) { |
| 19 |
case MESA_SHADER_COMPUTE: |
| 20 |
if (!compute_state_dirty(cmdbuf, PUSH_UNIFORMS)) |
| 21 |
return VK_SUCCESS; |
| 22 |
push_ptr = &cmdbuf->state.compute.push_uniforms; |
| 23 |
break; |
| 24 |
case MESA_SHADER_VERTEX: |
| 25 |
if (!gfx_state_dirty(cmdbuf, VS_PUSH_UNIFORMS)) |
| 26 |
return VK_SUCCESS; |
| 27 |
push_ptr = &cmdbuf->state.gfx.vs.push_uniforms; |
| 28 |
break; |
| 29 |
case MESA_SHADER_FRAGMENT: |
| 30 |
if (!gfx_state_dirty(cmdbuf, FS_PUSH_UNIFORMS)) |
| 31 |
return VK_SUCCESS; |
| 32 |
push_ptr = &cmdbuf->state.gfx.fs.push_uniforms; |
| 33 |
break; |
| 34 |
default: |
| 35 |
assert(!"Invalid stage"); |
| 36 |
return VK_SUCCESS; |
| 37 |
} |
| 38 |
|
| 39 |
if (!shader->fau.total_count) { |
| 40 |
*push_ptr = 0; |
| 41 |
return VK_SUCCESS; |
| 42 |
} |
| 43 |
|
| 44 |
struct pan_ptr push_uniforms = panvk_cmd_alloc_dev_mem( |
| 45 |
cmdbuf, desc, shader->fau.total_count * sizeof(uint64_t) * repeat_count, |
| 46 |
sizeof(uint64_t)); |
| 47 |
|
| 48 |
if (!push_uniforms.gpu) |
| 49 |
return VK_ERROR_OUT_OF_DEVICE_MEMORY; |
| 50 |
|
| 51 |
const uint64_t *sysvals = shader->info.stage == MESA_SHADER_COMPUTE |
| 52 |
? (uint64_t *)&cmdbuf->state.compute.sysvals |
| 53 |
: (uint64_t *)&cmdbuf->state.gfx.sysvals; |
| 54 |
|
| 55 |
struct panvk_common_sysvals_inner common_inner = { |
| 56 |
.printf_buffer_address = dev->printf.bo->addr.dev, |
| 57 |
}; |
| 58 |
uint64_t *common = (uint64_t *)&common_inner; |
| 59 |
|
| 60 |
uint64_t *push_consts = cmdbuf->state.push_constants.data; |
| 61 |
uint64_t *faus = push_uniforms.cpu; |
| 62 |
uint32_t w, fau = 0; |
| 63 |
|
| 64 |
for (uint32_t r = 0; r < repeat_count; r++) { |
| 65 |
common_inner.push_uniforms = |
| 66 |
push_uniforms.gpu + r * shader->fau.total_count * sizeof(uint64_t); |
| 67 |
|
| 68 |
/* After packing, the sysvals come first, followed by the user push |
| 69 |
* constants. The ordering is encoded shader side, so don't re-order |
| 70 |
* these loops. */ |
| 71 |
BITSET_FOREACH_SET(w, shader->fau.used_sysvals, MAX_SYSVAL_FAUS) { |
| 72 |
if (w >= SYSVALS_COMMON_START && w < SYSVALS_COMMON_END) |
| 73 |
faus[fau++] = common[w - SYSVALS_COMMON_START]; |
| 74 |
else |
| 75 |
faus[fau++] = sysvals[w]; |
| 76 |
} |
| 77 |
|
| 78 |
BITSET_FOREACH_SET(w, shader->fau.used_push_consts, MAX_PUSH_CONST_FAUS) |
| 79 |
faus[fau++] = push_consts[w]; |
| 80 |
|
| 81 |
for (uint32_t i = 0; i < shader->info.fau_consts_count; i += 2) { |
| 82 |
faus[fau++] = (uint64_t)shader->info.fau_consts[i + 1] << 32 | |
| 83 |
shader->info.fau_consts[i]; |
| 84 |
} |
| 85 |
assert(fau % shader->fau.total_count == 0); |
| 86 |
} |
| 87 |
|
| 88 |
*push_ptr = push_uniforms.gpu; |
| 89 |
return VK_SUCCESS; |
| 90 |
} |
| 91 |
|
| 92 |
VKAPI_ATTR void VKAPI_CALL |
| 93 |
panvk_per_arch(CmdPushConstants2KHR)( |
| 94 |
VkCommandBuffer commandBuffer, |
| 95 |
const VkPushConstantsInfoKHR *pPushConstantsInfo) |
| 96 |
{ |
| 97 |
VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer); |
| 98 |
|
| 99 |
if (pPushConstantsInfo->stageFlags & VK_SHADER_STAGE_VERTEX_BIT) |
| 100 |
gfx_state_set_dirty(cmdbuf, VS_PUSH_UNIFORMS); |
| 101 |
|
| 102 |
if (pPushConstantsInfo->stageFlags & VK_SHADER_STAGE_FRAGMENT_BIT) |
| 103 |
gfx_state_set_dirty(cmdbuf, FS_PUSH_UNIFORMS); |
| 104 |
|
| 105 |
if (pPushConstantsInfo->stageFlags & VK_SHADER_STAGE_COMPUTE_BIT) |
| 106 |
compute_state_set_dirty(cmdbuf, PUSH_UNIFORMS); |
| 107 |
|
| 108 |
uint8_t *data = |
| 109 |
(uint8_t *)cmdbuf->state.push_constants.data + pPushConstantsInfo->offset; |
| 110 |
|
| 111 |
memcpy(data, pPushConstantsInfo->pValues, pPushConstantsInfo->size); |
| 112 |
} |