pvr: clarify image/sampler state word packing

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33998>
This commit is contained in:
Simon Perretta 2024-11-20 09:52:00 +00:00 committed by Marge Bot
parent 8b8e33106d
commit 51a3372ff2
13 changed files with 140 additions and 179 deletions

View file

@ -323,7 +323,7 @@ SOFTWARE.
<field name="stride" start="0" end="14" type="uint"/>
</struct>
<struct name="SAMPLER" length="2">
<struct name="SAMPLER_WORD0" length="2">
<field name="texaddr_plane2_lo" start="50" end="63" shift="2" type="address"/>
<field name="cmp_mode" start="59" end="61" type="CMP_MODE"/>
<field name="addrmode_w" start="56" end="58" type="ADDRMODE"/>

View file

@ -32,7 +32,7 @@
#include "util/bitset.h"
#define PVR_BORDER_COLOR_TABLE_NR_ENTRIES \
(ROGUE_TEXSTATE_SAMPLER_BORDERCOLOR_INDEX_MAX_SIZE + 1)
(ROGUE_TEXSTATE_SAMPLER_WORD0_BORDERCOLOR_INDEX_MAX_SIZE + 1)
#define PVR_BORDER_COLOR_TABLE_NR_BUILTIN_ENTRIES \
(VK_BORDER_COLOR_INT_OPAQUE_WHITE + 1)

View file

@ -635,14 +635,12 @@ static VkResult pvr_setup_texture_state_words(
memcpy(&info.swizzle, swizzle, sizeof(info.swizzle));
/* TODO: Can we use image_view->texture_state instead of generating here? */
result = pvr_pack_tex_state(device, &info, descriptor->image);
result = pvr_pack_tex_state(device, &info, &descriptor->image);
if (result != VK_SUCCESS)
return result;
descriptor->sampler = (union pvr_sampler_descriptor){ 0 };
pvr_csb_pack (&descriptor->sampler.data.sampler_word,
TEXSTATE_SAMPLER,
pvr_csb_pack (&descriptor->sampler.words[0],
TEXSTATE_SAMPLER_WORD0,
sampler) {
sampler.non_normalized_coords = true;
sampler.addrmode_v = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
@ -652,6 +650,11 @@ static VkResult pvr_setup_texture_state_words(
sampler.dadjust = ROGUE_TEXSTATE_DADJUST_ZERO_UINT;
}
pvr_csb_pack (&descriptor->sampler.words[1],
TEXSTATE_SAMPLER_WORD1,
sampler) {
}
return VK_SUCCESS;
}

View file

@ -188,60 +188,34 @@ enum pvr_query_type {
PVR_QUERY_TYPE_COPY_QUERY_RESULTS,
};
union pvr_sampler_descriptor {
uint32_t words[PVR_SAMPLER_DESCRIPTOR_SIZE];
struct pvr_sampler_descriptor {
uint64_t words[ROGUE_NUM_TEXSTATE_SAMPLER_WORDS];
} PACKED;
static_assert(sizeof(struct pvr_sampler_descriptor) ==
ROGUE_NUM_TEXSTATE_SAMPLER_WORDS * sizeof(uint64_t),
"pvr_sampler_descriptor size is invalid.");
struct {
/* Packed ROGUE_TEXSTATE_SAMPLER. */
uint64_t sampler_word;
uint32_t compare_op;
/* TODO: Figure out what this word is for and rename.
* Sampler state word 1?
*/
uint32_t word3;
} data;
};
struct pvr_image_descriptor {
uint64_t words[ROGUE_NUM_TEXSTATE_IMAGE_WORDS];
} PACKED;
static_assert(sizeof(struct pvr_image_descriptor) ==
ROGUE_NUM_TEXSTATE_IMAGE_WORDS * sizeof(uint64_t),
"pvr_image_descriptor size is invalid.");
struct pvr_combined_image_sampler_descriptor {
/* | TEXSTATE_IMAGE_WORD0 | TEXSTATE_{STRIDE_,}IMAGE_WORD1 | */
uint64_t image[ROGUE_NUM_TEXSTATE_IMAGE_WORDS];
union pvr_sampler_descriptor sampler;
};
#define CHECK_STRUCT_FIELD_SIZE(_struct_type, _field_name, _size) \
static_assert(sizeof(((struct _struct_type *)NULL)->_field_name) == \
(_size), \
"Size of '" #_field_name "' in '" #_struct_type \
"' differs from expected")
CHECK_STRUCT_FIELD_SIZE(pvr_combined_image_sampler_descriptor,
image,
ROGUE_NUM_TEXSTATE_IMAGE_WORDS * sizeof(uint64_t));
CHECK_STRUCT_FIELD_SIZE(pvr_combined_image_sampler_descriptor,
image,
PVR_DW_TO_BYTES(PVR_IMAGE_DESCRIPTOR_SIZE));
#if 0
/* TODO: Don't really want to include pvr_csb.h in here since this header is
* shared with the compiler. Figure out a better place for these.
*/
CHECK_STRUCT_FIELD_SIZE(pvr_combined_image_sampler_descriptor,
image,
(pvr_cmd_length(TEXSTATE_IMAGE_WORD0) +
pvr_cmd_length(TEXSTATE_IMAGE_WORD1)) *
sizeof(uint32_t));
CHECK_STRUCT_FIELD_SIZE(pvr_combined_image_sampler_descriptor,
image,
(pvr_cmd_length(TEXSTATE_IMAGE_WORD0) +
pvr_cmd_length(TEXSTATE_STRIDE_IMAGE_WORD1)) *
sizeof(uint32_t));
#endif
#undef CHECK_STRUCT_FIELD_SIZE
struct pvr_image_descriptor image;
struct pvr_sampler_descriptor sampler;
} PACKED;
static_assert(sizeof(struct pvr_combined_image_sampler_descriptor) ==
(ROGUE_NUM_TEXSTATE_IMAGE_WORDS +
ROGUE_NUM_TEXSTATE_SAMPLER_WORDS) *
sizeof(uint64_t),
"pvr_combined_image_sampler_descriptor size is invalid.");
struct pvr_sampler {
struct vk_sampler vk;
union pvr_sampler_descriptor descriptor;
struct pvr_sampler_descriptor descriptor;
};
struct pvr_descriptor_size_info {

View file

@ -1449,14 +1449,14 @@ pvr_write_image_descriptor_primaries(const struct pvr_device_info *dev_info,
if (descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE &&
(iview->vk.view_type == VK_IMAGE_VIEW_TYPE_CUBE ||
iview->vk.view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)) {
qword_ptr[0] = iview->texture_state[PVR_TEXTURE_STATE_STORAGE][0];
qword_ptr[1] = iview->texture_state[PVR_TEXTURE_STATE_STORAGE][1];
qword_ptr[0] = iview->image_state[PVR_TEXTURE_STATE_STORAGE].words[0];
qword_ptr[1] = iview->image_state[PVR_TEXTURE_STATE_STORAGE].words[1];
} else if (descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) {
qword_ptr[0] = iview->texture_state[PVR_TEXTURE_STATE_ATTACHMENT][0];
qword_ptr[1] = iview->texture_state[PVR_TEXTURE_STATE_ATTACHMENT][1];
qword_ptr[0] = iview->image_state[PVR_TEXTURE_STATE_ATTACHMENT].words[0];
qword_ptr[1] = iview->image_state[PVR_TEXTURE_STATE_ATTACHMENT].words[1];
} else {
qword_ptr[0] = iview->texture_state[PVR_TEXTURE_STATE_SAMPLE][0];
qword_ptr[1] = iview->texture_state[PVR_TEXTURE_STATE_SAMPLE][1];
qword_ptr[0] = iview->image_state[PVR_TEXTURE_STATE_SAMPLE].words[0];
qword_ptr[1] = iview->image_state[PVR_TEXTURE_STATE_SAMPLE].words[1];
}
if (descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE &&
@ -1652,8 +1652,8 @@ static void pvr_write_buffer_descriptor(const struct pvr_device_info *dev_info,
{
uint64_t *qword_ptr = (uint64_t *)primary;
qword_ptr[0] = bview->texture_state[0];
qword_ptr[1] = bview->texture_state[1];
qword_ptr[0] = bview->image_state.words[0];
qword_ptr[1] = bview->image_state.words[1];
if (descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER &&
!PVR_HAS_FEATURE(dev_info, tpu_extended_integer_lookup)) {

View file

@ -1427,8 +1427,8 @@ static VkResult pvr_pds_idfwdf_programs_create_and_upload(
static VkResult pvr_device_init_compute_idfwdf_state(struct pvr_device *device)
{
uint64_t sampler_state[ROGUE_NUM_TEXSTATE_SAMPLER_WORDS];
uint64_t image_state[ROGUE_NUM_TEXSTATE_IMAGE_WORDS];
struct pvr_sampler_descriptor sampler_state;
struct pvr_image_descriptor image_state;
struct util_dynarray usc_program;
struct pvr_texture_state_info tex_info;
uint32_t *dword_ptr;
@ -1477,7 +1477,7 @@ static VkResult pvr_device_init_compute_idfwdf_state(struct pvr_device *device)
/* Pack state words. */
pvr_csb_pack (&sampler_state[0], TEXSTATE_SAMPLER, sampler) {
pvr_csb_pack (&sampler_state.words[0], TEXSTATE_SAMPLER_WORD0, sampler) {
sampler.dadjust = ROGUE_TEXSTATE_DADJUST_ZERO_UINT;
sampler.magfilter = ROGUE_TEXSTATE_FILTER_POINT;
sampler.addrmode_u = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
@ -1485,11 +1485,9 @@ static VkResult pvr_device_init_compute_idfwdf_state(struct pvr_device *device)
}
/* clang-format off */
pvr_csb_pack (&sampler_state[1], TEXSTATE_SAMPLER_WORD1, sampler_word1) {}
pvr_csb_pack (&sampler_state.words[1], TEXSTATE_SAMPLER_WORD1, sampler_word1) {}
/* clang-format on */
STATIC_ASSERT(1 + 1 == ROGUE_NUM_TEXSTATE_SAMPLER_WORDS);
tex_info = (struct pvr_texture_state_info){
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
.mem_layout = PVR_MEMLAYOUT_LINEAR,
@ -1506,7 +1504,7 @@ static VkResult pvr_device_init_compute_idfwdf_state(struct pvr_device *device)
.addr = device->idfwdf_state.store_bo->vma->dev_addr,
};
result = pvr_pack_tex_state(device, &tex_info, image_state);
result = pvr_pack_tex_state(device, &tex_info, &image_state);
if (result != VK_SUCCESS)
goto err_free_shareds_buffer;
@ -1528,15 +1526,15 @@ static VkResult pvr_device_init_compute_idfwdf_state(struct pvr_device *device)
dword_ptr[2] = 0U;
dword_ptr[3] = 0U;
dword_ptr[4] = LOW_32(image_state[0]);
dword_ptr[5] = HIGH_32(image_state[0]);
dword_ptr[6] = LOW_32(image_state[1]);
dword_ptr[7] = HIGH_32(image_state[1]);
dword_ptr[4] = LOW_32(image_state.words[0]);
dword_ptr[5] = HIGH_32(image_state.words[0]);
dword_ptr[6] = LOW_32(image_state.words[1]);
dword_ptr[7] = HIGH_32(image_state.words[1]);
dword_ptr[8] = LOW_32(sampler_state[0]);
dword_ptr[9] = HIGH_32(sampler_state[0]);
dword_ptr[10] = LOW_32(sampler_state[1]);
dword_ptr[11] = HIGH_32(sampler_state[1]);
dword_ptr[8] = LOW_32(sampler_state.words[0]);
dword_ptr[9] = HIGH_32(sampler_state.words[0]);
dword_ptr[10] = LOW_32(sampler_state.words[1]);
dword_ptr[11] = HIGH_32(sampler_state.words[1]);
assert(11 + 1 == usc_shareds);
#undef HIGH_32
@ -1745,7 +1743,9 @@ err_release_lock:
static void pvr_device_init_default_sampler_state(struct pvr_device *device)
{
pvr_csb_pack (&device->input_attachment_sampler, TEXSTATE_SAMPLER, sampler) {
pvr_csb_pack (&device->input_attachment_sampler,
TEXSTATE_SAMPLER_WORD0,
sampler) {
sampler.addrmode_u = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
sampler.addrmode_v = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
sampler.addrmode_w = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
@ -2992,9 +2992,6 @@ VkResult pvr_CreateSampler(VkDevice _device,
float min_lod;
float max_lod;
STATIC_ASSERT(sizeof(((union pvr_sampler_descriptor *)NULL)->data) ==
sizeof(((union pvr_sampler_descriptor *)NULL)->words));
sampler =
vk_sampler_create(&device->vk, pCreateInfo, pAllocator, sizeof(*sampler));
if (!sampler) {
@ -3035,18 +3032,9 @@ VkResult pvr_CreateSampler(VkDevice _device,
}
}
if (pCreateInfo->compareEnable) {
sampler->descriptor.data.compare_op =
(uint32_t)pvr_texstate_cmpmode(pCreateInfo->compareOp);
} else {
sampler->descriptor.data.compare_op =
(uint32_t)pvr_texstate_cmpmode(VK_COMPARE_OP_NEVER);
}
assert(!pCreateInfo->compareEnable);
sampler->descriptor.data.word3 = 0;
pvr_csb_pack (&sampler->descriptor.data.sampler_word,
TEXSTATE_SAMPLER,
word) {
pvr_csb_pack (&sampler->descriptor.words[0], TEXSTATE_SAMPLER_WORD0, word) {
const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
const float lod_clamp_max = (float)ROGUE_TEXSTATE_CLAMP_MAX /
(1 << ROGUE_TEXSTATE_CLAMP_FRACTIONAL_BITS);
@ -3070,13 +3058,6 @@ VkResult pvr_CreateSampler(VkDevice _device,
word.addrmode_w =
pvr_sampler_get_hw_addr_mode_from_vk(pCreateInfo->addressModeW);
/* TODO: Figure out defines for these. */
if (word.addrmode_u == ROGUE_TEXSTATE_ADDRMODE_FLIP)
sampler->descriptor.data.word3 |= 0x40000000;
if (word.addrmode_v == ROGUE_TEXSTATE_ADDRMODE_FLIP)
sampler->descriptor.data.word3 |= 0x20000000;
/* The Vulkan 1.0.205 spec says:
*
* The absolute value of mipLodBias must be less than or equal to
@ -3119,6 +3100,9 @@ VkResult pvr_CreateSampler(VkDevice _device,
word.non_normalized_coords = true;
}
pvr_csb_pack (&sampler->descriptor.words[1], TEXSTATE_SAMPLER_WORD1, word) {
}
*pSampler = pvr_sampler_to_handle(sampler);
return VK_SUCCESS;

View file

@ -346,7 +346,7 @@ VkResult pvr_CreateImageView(VkDevice _device,
result = pvr_pack_tex_state(device,
&info,
iview->texture_state[info.tex_state_type]);
&iview->image_state[info.tex_state_type]);
if (result != VK_SUCCESS)
goto err_vk_image_view_destroy;
@ -358,7 +358,7 @@ VkResult pvr_CreateImageView(VkDevice _device,
result = pvr_pack_tex_state(device,
&info,
iview->texture_state[info.tex_state_type]);
&iview->image_state[info.tex_state_type]);
if (result != VK_SUCCESS)
goto err_vk_image_view_destroy;
}
@ -389,7 +389,7 @@ VkResult pvr_CreateImageView(VkDevice _device,
result = pvr_pack_tex_state(device,
&info,
iview->texture_state[info.tex_state_type]);
&iview->image_state[info.tex_state_type]);
if (result != VK_SUCCESS)
goto err_vk_image_view_destroy;
}
@ -470,7 +470,7 @@ VkResult pvr_CreateBufferView(VkDevice _device,
format_swizzle = pvr_get_format_swizzle(info.format);
memcpy(info.swizzle, format_swizzle, sizeof(info.swizzle));
result = pvr_pack_tex_state(device, &info, bview->texture_state);
result = pvr_pack_tex_state(device, &info, &bview->image_state);
if (result != VK_SUCCESS)
goto err_vk_buffer_view_destroy;

View file

@ -1484,7 +1484,7 @@ static VkResult pvr_sampler_state_for_surface(
{
uint64_t sampler_state[2U] = { 0UL, 0UL };
pvr_csb_pack (&sampler_state[0U], TEXSTATE_SAMPLER, reg) {
pvr_csb_pack (&sampler_state[0U], TEXSTATE_SAMPLER_WORD0, reg) {
reg.anisoctl = ROGUE_TEXSTATE_ANISOCTL_DISABLED;
reg.minlod = ROGUE_TEXSTATE_CLAMP_MIN;
reg.maxlod = ROGUE_TEXSTATE_CLAMP_MIN;
@ -1528,6 +1528,7 @@ static inline VkResult pvr_image_state_set_codegen_defaults(
{
struct pvr_tq_layer_properties *layer = &state->shader_props.layer_props;
struct pvr_texture_state_info info = { 0U };
struct pvr_image_descriptor image_state;
VkResult result;
switch (surface->vk_format) {
@ -1607,10 +1608,12 @@ static inline VkResult pvr_image_state_set_codegen_defaults(
else
info.type = VK_IMAGE_VIEW_TYPE_1D;
result = pvr_pack_tex_state(device, &info, mem_ptr);
result = pvr_pack_tex_state(device, &info, &image_state);
if (result != VK_SUCCESS)
return result;
memcpy(mem_ptr, &image_state, sizeof(image_state));
return VK_SUCCESS;
}

View file

@ -342,7 +342,7 @@ struct pvr_image_view {
* We create separate texture states for sampling, storage and input
* attachment cases.
*/
uint64_t texture_state[PVR_TEXTURE_STATE_MAX_ENUM][2];
struct pvr_image_descriptor image_state[PVR_TEXTURE_STATE_MAX_ENUM];
};
struct pvr_buffer_view {
@ -351,7 +351,7 @@ struct pvr_buffer_view {
/* Prepacked Texture dword 0 and 1. It will be copied to the descriptor
* during pvr_UpdateDescriptorSets().
*/
uint64_t texture_state[2];
struct pvr_image_descriptor image_state;
};
#define PVR_TRANSFER_MAX_SOURCES 10U

View file

@ -488,7 +488,7 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
const uint32_t core_count = device->pdevice->dev_runtime_info.core_count;
const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
const struct pvr_shader_factory_info *shader_factory_info;
uint64_t sampler_state[ROGUE_NUM_TEXSTATE_SAMPLER_WORDS];
struct pvr_sampler_descriptor sampler_state;
const struct pvr_compute_query_shader *query_prog;
struct pvr_private_compute_pipeline pipeline;
const uint32_t buffer_count = core_count;
@ -498,7 +498,7 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
struct pvr_suballoc_bo *pvr_bo;
VkResult result;
pvr_csb_pack (&sampler_state[0U], TEXSTATE_SAMPLER, reg) {
pvr_csb_pack (&sampler_state.words[0], TEXSTATE_SAMPLER_WORD0, reg) {
reg.addrmode_u = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
reg.addrmode_v = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
reg.addrmode_w = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
@ -509,7 +509,7 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
}
/* clang-format off */
pvr_csb_pack (&sampler_state[1], TEXSTATE_SAMPLER_WORD1, sampler_word1) {}
pvr_csb_pack (&sampler_state.words[1], TEXSTATE_SAMPLER_WORD1, sampler_word1) {}
/* clang-format on */
switch (query_info->type) {
@ -576,11 +576,11 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
switch (query_info->type) {
case PVR_QUERY_TYPE_AVAILABILITY_WRITE: {
uint64_t image_sampler_state[3][ROGUE_NUM_TEXSTATE_SAMPLER_WORDS];
struct pvr_image_descriptor image_sampler_state[4];
uint32_t image_sampler_idx = 0;
memcpy(&image_sampler_state[image_sampler_idx][0],
&sampler_state[0],
memcpy(&image_sampler_state[image_sampler_idx],
&sampler_state,
sizeof(sampler_state));
image_sampler_idx++;
@ -591,7 +591,7 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
result = pvr_pack_tex_state(device,
&tex_info,
&image_sampler_state[image_sampler_idx][0]);
&image_sampler_state[image_sampler_idx]);
if (result != VK_SUCCESS) {
vk_free(&cmd_buffer->vk.pool->alloc, const_buffer);
return pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result);
@ -607,7 +607,7 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
result = pvr_pack_tex_state(device,
&tex_info,
&image_sampler_state[image_sampler_idx][0]);
&image_sampler_state[image_sampler_idx]);
if (result != VK_SUCCESS) {
vk_free(&cmd_buffer->vk.pool->alloc, const_buffer);
return pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result);
@ -616,8 +616,8 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
image_sampler_idx++;
memcpy(&const_buffer[0],
&image_sampler_state[0][0],
sizeof(image_sampler_state));
&image_sampler_state[image_sampler_idx],
sizeof(image_sampler_state[image_sampler_idx]));
/* Only PVR_QUERY_AVAILABILITY_WRITE_COUNT driver consts allowed. */
assert(shader_factory_info->num_driver_consts ==
@ -635,13 +635,14 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
PVR_FROM_HANDLE(pvr_buffer,
buffer,
query_info->copy_query_results.dst_buffer);
const uint32_t image_sampler_state_arr_size =
(buffer_count + 2) * ROGUE_NUM_TEXSTATE_SAMPLER_WORDS;
const uint32_t image_sampler_state_arr_size = buffer_count + 2;
uint32_t image_sampler_idx = 0;
pvr_dev_addr_t addr;
uint64_t offset;
STACK_ARRAY(uint64_t, image_sampler_state, image_sampler_state_arr_size);
STACK_ARRAY(struct pvr_image_descriptor,
image_sampler_state,
image_sampler_state_arr_size);
if (!image_sampler_state) {
vk_free(&cmd_buffer->vk.pool->alloc, const_buffer);
@ -649,11 +650,8 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
VK_ERROR_OUT_OF_HOST_MEMORY);
}
#define SAMPLER_ARR_2D(_arr, _i, _j) \
_arr[_i * ROGUE_NUM_TEXSTATE_SAMPLER_WORDS + _j]
memcpy(&SAMPLER_ARR_2D(image_sampler_state, image_sampler_idx, 0),
&sampler_state[0],
memcpy(&image_sampler_state[image_sampler_idx],
&sampler_state,
sizeof(sampler_state));
image_sampler_idx++;
@ -663,10 +661,9 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
pvr_init_tex_info(dev_info, &tex_info, num_query_indices, addr);
result = pvr_pack_tex_state(
device,
&tex_info,
&SAMPLER_ARR_2D(image_sampler_state, image_sampler_idx, 0));
result = pvr_pack_tex_state(device,
&tex_info,
&image_sampler_state[image_sampler_idx]);
if (result != VK_SUCCESS) {
vk_free(&cmd_buffer->vk.pool->alloc, const_buffer);
return pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result);
@ -680,10 +677,9 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
pvr_init_tex_info(dev_info, &tex_info, num_query_indices, addr);
result = pvr_pack_tex_state(
device,
&tex_info,
&SAMPLER_ARR_2D(image_sampler_state, image_sampler_idx, 0));
result = pvr_pack_tex_state(device,
&tex_info,
&image_sampler_state[image_sampler_idx]);
if (result != VK_SUCCESS) {
vk_free(&cmd_buffer->vk.pool->alloc, const_buffer);
return pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result);
@ -693,8 +689,8 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
}
memcpy(&const_buffer[0],
&SAMPLER_ARR_2D(image_sampler_state, 0, 0),
image_sampler_state_arr_size * sizeof(image_sampler_state[0]));
image_sampler_state,
image_sampler_state_arr_size * sizeof(*image_sampler_state));
STACK_ARRAY_FINISH(image_sampler_state);
@ -731,13 +727,14 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
PVR_FROM_HANDLE(pvr_query_pool,
pool,
query_info->reset_query_pool.query_pool);
const uint32_t image_sampler_state_arr_size =
(buffer_count + 2) * ROGUE_NUM_TEXSTATE_SAMPLER_WORDS;
const uint32_t image_sampler_state_arr_size = buffer_count + 2;
uint32_t image_sampler_idx = 0;
pvr_dev_addr_t addr;
uint64_t offset;
STACK_ARRAY(uint64_t, image_sampler_state, image_sampler_state_arr_size);
STACK_ARRAY(struct pvr_image_descriptor,
image_sampler_state,
image_sampler_state_arr_size);
if (!image_sampler_state) {
vk_free(&cmd_buffer->vk.pool->alloc, const_buffer);
@ -745,8 +742,8 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
VK_ERROR_OUT_OF_HOST_MEMORY);
}
memcpy(&SAMPLER_ARR_2D(image_sampler_state, image_sampler_idx, 0),
&sampler_state[0],
memcpy(&image_sampler_state[image_sampler_idx],
&sampler_state,
sizeof(sampler_state));
image_sampler_idx++;
@ -758,10 +755,9 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
pvr_init_tex_info(dev_info, &tex_info, num_query_indices, addr);
result = pvr_pack_tex_state(
device,
&tex_info,
&SAMPLER_ARR_2D(image_sampler_state, image_sampler_idx, 0));
result = pvr_pack_tex_state(device,
&tex_info,
&image_sampler_state[image_sampler_idx]);
if (result != VK_SUCCESS) {
vk_free(&cmd_buffer->vk.pool->alloc, const_buffer);
return pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result);
@ -774,10 +770,9 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
pvr_init_tex_info(dev_info, &tex_info, num_query_indices, addr);
result = pvr_pack_tex_state(
device,
&tex_info,
&SAMPLER_ARR_2D(image_sampler_state, image_sampler_idx, 0));
result = pvr_pack_tex_state(device,
&tex_info,
&image_sampler_state[image_sampler_idx]);
if (result != VK_SUCCESS) {
vk_free(&cmd_buffer->vk.pool->alloc, const_buffer);
return pvr_cmd_buffer_set_error_unwarned(cmd_buffer, result);
@ -785,11 +780,9 @@ VkResult pvr_add_query_program(struct pvr_cmd_buffer *cmd_buffer,
image_sampler_idx++;
#undef SAMPLER_ARR_2D
memcpy(&const_buffer[0],
&image_sampler_state[0],
image_sampler_state_arr_size * sizeof(image_sampler_state[0]));
image_sampler_state,
image_sampler_state_arr_size * sizeof(*image_sampler_state));
STACK_ARRAY_FINISH(image_sampler_state);

View file

@ -783,14 +783,14 @@ static VkFormat pvr_get_format_from_dword_count(uint32_t dword_count)
}
}
static VkResult pvr_spm_setup_texture_state_words(
struct pvr_device *device,
uint32_t dword_count,
const VkExtent2D framebuffer_size,
uint32_t sample_count,
pvr_dev_addr_t scratch_buffer_addr,
uint64_t image_descriptor[static const ROGUE_NUM_TEXSTATE_IMAGE_WORDS],
uint64_t *mem_used_out)
static VkResult
pvr_spm_setup_texture_state_words(struct pvr_device *device,
uint32_t dword_count,
const VkExtent2D framebuffer_size,
uint32_t sample_count,
pvr_dev_addr_t scratch_buffer_addr,
uint64_t *image_state_ptr,
uint64_t *mem_used_out)
{
/* We can ignore the framebuffer's layer count since we only support
* writing to layer 0.
@ -817,16 +817,19 @@ static VkResult pvr_spm_setup_texture_state_words(
ALIGN_POT(framebuffer_size.width,
ROGUE_CR_PBE_WORD0_MRT0_LINESTRIDE_ALIGNMENT);
const uint64_t fb_area = aligned_fb_width * framebuffer_size.height;
struct pvr_image_descriptor image_descriptor;
const uint8_t *format_swizzle;
VkResult result;
format_swizzle = pvr_get_format_swizzle(info.format);
memcpy(info.swizzle, format_swizzle, sizeof(info.swizzle));
result = pvr_pack_tex_state(device, &info, image_descriptor);
result = pvr_pack_tex_state(device, &info, &image_descriptor);
if (result != VK_SUCCESS)
return result;
memcpy(image_state_ptr, &image_descriptor, sizeof(image_descriptor));
*mem_used_out = fb_area * PVR_DW_TO_BYTES(dword_count) * sample_count;
return VK_SUCCESS;
@ -919,7 +922,7 @@ pvr_spm_init_bgobj_state(struct pvr_device *device,
struct pvr_spm_per_load_program_state *load_program_state;
struct pvr_pds_upload pds_texture_data_upload;
const struct pvr_shader_factory_info *info;
union pvr_sampler_descriptor *descriptor;
struct pvr_sampler_descriptor *descriptor;
uint64_t consts_buffer_size;
uint32_t dword_count;
uint32_t *mem_ptr;
@ -975,10 +978,10 @@ pvr_spm_init_bgobj_state(struct pvr_device *device,
/* TODO: The 32 comes from how the shaders are compiled. We should
* unhardcode it when this is hooked up to the compiler.
*/
descriptor = (union pvr_sampler_descriptor *)(mem_ptr + 32);
*descriptor = (union pvr_sampler_descriptor){ 0 };
descriptor = (struct pvr_sampler_descriptor *)(mem_ptr + 32);
*descriptor = (struct pvr_sampler_descriptor){ 0 };
pvr_csb_pack (&descriptor->data.sampler_word, TEXSTATE_SAMPLER, sampler) {
pvr_csb_pack (&descriptor->words[0], TEXSTATE_SAMPLER_WORD0, sampler) {
sampler.non_normalized_coords = true;
sampler.addrmode_v = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
sampler.addrmode_u = ROGUE_TEXSTATE_ADDRMODE_CLAMP_TO_EDGE;
@ -989,6 +992,9 @@ pvr_spm_init_bgobj_state(struct pvr_device *device,
sampler.dadjust = ROGUE_TEXSTATE_DADJUST_ZERO_UINT;
}
pvr_csb_pack (&descriptor->words[1], TEXSTATE_SAMPLER_WORD1, sampler) {
}
/* Even if we might have 8 output regs we can only pack and write 4 dwords
* using R32G32B32A32_UINT.
*/
@ -1001,10 +1007,10 @@ pvr_spm_init_bgobj_state(struct pvr_device *device,
uint64_t *mem_ptr_u64 = (uint64_t *)mem_ptr;
uint64_t mem_used = 0;
STATIC_ASSERT(ROGUE_NUM_TEXSTATE_IMAGE_WORDS * sizeof(uint64_t) /
sizeof(uint32_t) ==
STATIC_ASSERT((sizeof(struct pvr_image_descriptor) / sizeof(uint32_t)) ==
PVR_IMAGE_DESCRIPTOR_SIZE);
mem_ptr_u64 += i * ROGUE_NUM_TEXSTATE_IMAGE_WORDS;
mem_ptr_u64 +=
i * (sizeof(struct pvr_image_descriptor) / sizeof(uint64_t));
result = pvr_spm_setup_texture_state_words(device,
dword_count,

View file

@ -61,10 +61,9 @@ static enum ROGUE_TEXSTATE_SWIZ pvr_get_hw_swizzle(VkComponentSwizzle comp,
};
}
VkResult
pvr_pack_tex_state(struct pvr_device *device,
const struct pvr_texture_state_info *info,
uint64_t state[static const ROGUE_NUM_TEXSTATE_IMAGE_WORDS])
VkResult pvr_pack_tex_state(struct pvr_device *device,
const struct pvr_texture_state_info *info,
struct pvr_image_descriptor *state)
{
const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
enum pvr_memlayout mem_layout;
@ -85,7 +84,7 @@ pvr_pack_tex_state(struct pvr_device *device,
else
iview_type = info->type;
pvr_csb_pack (&state[0], TEXSTATE_IMAGE_WORD0, word0) {
pvr_csb_pack (&state->words[0], TEXSTATE_IMAGE_WORD0, word0) {
if (mem_layout == PVR_MEMLAYOUT_LINEAR) {
switch (iview_type) {
case VK_IMAGE_VIEW_TYPE_2D:
@ -176,7 +175,7 @@ pvr_pack_tex_state(struct pvr_device *device,
}
if (mem_layout == PVR_MEMLAYOUT_LINEAR) {
pvr_csb_pack (&state[1], TEXSTATE_STRIDE_IMAGE_WORD1, word1) {
pvr_csb_pack (&state->words[1], TEXSTATE_STRIDE_IMAGE_WORD1, word1) {
assert(info->stride > 0U);
word1.stride = info->stride - 1U;
word1.num_mip_levels = info->mip_levels;
@ -203,7 +202,7 @@ pvr_pack_tex_state(struct pvr_device *device,
ROGUE_TEXSTATE_COMPRESSION_MODE_TPU;
}
} else {
pvr_csb_pack (&state[1], TEXSTATE_IMAGE_WORD1, word1) {
pvr_csb_pack (&state->words[1], TEXSTATE_IMAGE_WORD1, word1) {
word1.num_mip_levels = info->mip_levels;
word1.mipmaps_present = info->mipmaps_present;
word1.baselevel = info->base_level;

View file

@ -105,9 +105,8 @@ struct pvr_texture_state_info {
pvr_dev_addr_t addr;
};
VkResult
pvr_pack_tex_state(struct pvr_device *device,
const struct pvr_texture_state_info *info,
uint64_t state[static const ROGUE_NUM_TEXSTATE_IMAGE_WORDS]);
VkResult pvr_pack_tex_state(struct pvr_device *device,
const struct pvr_texture_state_info *info,
struct pvr_image_descriptor *state);
#endif /* PVR_TEX_STATE_H */