pvr: Add PVR_DW_TO_BYTES()
authorKarmjit Mahil <Karmjit.Mahil@imgtec.com>
Tue, 14 Feb 2023 13:04:39 +0000 (13:04 +0000)
committerMarge Bot <emma+marge@anholt.net>
Tue, 25 Apr 2023 12:55:43 +0000 (12:55 +0000)
We use dwords (32 bit) quite a bit around the code base. Previously
we used '* 4', '<< 2', or '* sizeof(uint32_t)' to go from dwords to
bytes. The conversion isn't always clear when other operations
happen in the same line, which can leave one wondering where the
multiplication came from.
PVR_DW_TO_BYTES() should make the code more obvious as well as
making the conversion more consistent.

Signed-off-by: Karmjit Mahil <Karmjit.Mahil@imgtec.com>
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22658>

18 files changed:
src/imagination/include/pvr_types.h
src/imagination/vulkan/pds/pvr_pipeline_pds.c
src/imagination/vulkan/pvr_blit.c
src/imagination/vulkan/pvr_clear.c
src/imagination/vulkan/pvr_cmd_buffer.c
src/imagination/vulkan/pvr_common.h
src/imagination/vulkan/pvr_csb.c
src/imagination/vulkan/pvr_csb.h
src/imagination/vulkan/pvr_descriptor_set.c
src/imagination/vulkan/pvr_device.c
src/imagination/vulkan/pvr_job_compute.c
src/imagination/vulkan/pvr_job_context.c
src/imagination/vulkan/pvr_job_transfer.c
src/imagination/vulkan/pvr_pass.c
src/imagination/vulkan/pvr_pipeline.c
src/imagination/vulkan/pvr_query_compute.c
src/imagination/vulkan/pvr_spm.c
src/imagination/vulkan/pvr_transfer_frag_store.c

index eaf8ca2..b820e10 100644 (file)
 #include <inttypes.h>
 #include <stdint.h>
 
+/**
+ * \brief Convert dwords to bytes.
+ *
+ * Throughout the code base we keep sizes in dwords (e.g. code_size and
+ * data_size returned by the pds api) and in some cases we need to convert those
+ * to be in bytes.
+ *
+ * This macro makes the conversion more obvious.
+ */
+/* clang-format off */
+#define PVR_DW_TO_BYTES(_value) ((_value) * 4)
+/* clang-format on */
+
 /*****************************************************************************
    Device virtual addresses
 *****************************************************************************/
index f3ecb5a..f441106 100644 (file)
@@ -32,6 +32,7 @@
 #include "pvr_rogue_pds_defs.h"
 #include "pvr_rogue_pds_disasm.h"
 #include "pvr_rogue_pds_encode.h"
+#include "pvr_types.h"
 #include "util/log.h"
 #include "util/macros.h"
 
@@ -1568,7 +1569,7 @@ void pvr_pds_generate_descriptor_upload_program(
 
       addr_literal_buffer_entry->type =
          PVR_PDS_CONST_MAP_ENTRY_TYPE_ADDR_LITERAL_BUFFER;
-      addr_literal_buffer_entry->size = size_in_dwords * sizeof(uint32_t);
+      addr_literal_buffer_entry->size = PVR_DW_TO_BYTES(size_in_dwords);
       addr_literal_buffer_entry->const_offset = next_const64 * 2;
 
       for (unsigned int i = 0; i < input_program->addr_literal_count; i++) {
index 4da28f2..e40c73f 100644 (file)
@@ -1783,9 +1783,9 @@ static void pvr_clear_attachments(struct pvr_cmd_buffer *cmd_buffer,
       pvr_clear_needs_rt_id_output(dev_info, rect_count, rects);
 
    /* 4 because we're expecting the USC to output X, Y, Z, and W. */
-   vs_output_size_in_bytes = 4 * sizeof(uint32_t);
+   vs_output_size_in_bytes = PVR_DW_TO_BYTES(4);
    if (vs_has_rt_id_output)
-      vs_output_size_in_bytes += sizeof(uint32_t);
+      vs_output_size_in_bytes += PVR_DW_TO_BYTES(1);
 
    for (uint32_t i = 0; i < attachment_count; i++) {
       const VkClearAttachment *attachment = &attachments[i];
index b2cf694..8ed1bdf 100644 (file)
@@ -31,6 +31,7 @@
 #include "pvr_private.h"
 #include "pvr_shader_factory.h"
 #include "pvr_static_shaders.h"
+#include "pvr_types.h"
 #include "vk_alloc.h"
 #include "vk_log.h"
 
@@ -170,7 +171,7 @@ VkResult pvr_emit_ppp_from_template(
 
    result = pvr_bo_alloc(device,
                          device->heaps.general_heap,
-                         dword_count * sizeof(uint32_t),
+                         PVR_DW_TO_BYTES(dword_count),
                          cache_line_size,
                          PVR_BO_ALLOC_FLAG_CPU_MAPPED,
                          &pvr_bo);
@@ -326,8 +327,8 @@ pvr_device_init_clear_attachment_programs(struct pvr_device *device)
       pvr_pds_set_sizes_pixel_shader_uniform_texture_code(&texture_pds_program);
 
       pds_texture_program_offsets[offset_idx] = alloc_size;
-      alloc_size +=
-         ALIGN_POT(texture_pds_program.code_size * 4, pds_prog_alignment);
+      alloc_size += ALIGN_POT(PVR_DW_TO_BYTES(texture_pds_program.code_size),
+                              pds_prog_alignment);
 
       /* Pixel program to load fragment shader. */
 
@@ -343,7 +344,7 @@ pvr_device_init_clear_attachment_programs(struct pvr_device *device)
 
       program_size = pixel_shader_pds_program.code_size +
                      pixel_shader_pds_program.data_size;
-      program_size *= sizeof(uint32_t);
+      program_size = PVR_DW_TO_BYTES(program_size);
 
       pds_pixel_program_offsets[offset_idx] = alloc_size;
       alloc_size += ALIGN_POT(program_size, pds_prog_alignment);
@@ -657,7 +658,7 @@ VkResult pvr_pds_clear_vertex_shader_program_create_and_upload(
    pvr_pds_vertex_shader(program, NULL, PDS_GENERATE_SIZES, dev_info);
 
    staging_buffer_size =
-      (program->code_size + program->data_size) * sizeof(*staging_buffer);
+      PVR_DW_TO_BYTES(program->code_size + program->data_size);
 
    staging_buffer = vk_alloc(&device->vk.alloc,
                              staging_buffer_size,
@@ -716,7 +717,7 @@ VkResult pvr_pds_clear_vertex_shader_program_create_and_upload_data(
 
    pvr_pds_vertex_shader(program, NULL, PDS_GENERATE_SIZES, dev_info);
 
-   staging_buffer_size = program->data_size * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program->data_size);
 
    staging_buffer = vk_alloc(&cmd_buffer->device->vk.alloc,
                              staging_buffer_size,
@@ -792,7 +793,7 @@ VkResult pvr_pds_clear_rta_vertex_shader_program_create_and_upload_code(
 
    pvr_pds_vertex_shader(program, NULL, PDS_GENERATE_SIZES, dev_info);
 
-   staging_buffer_size = program->code_size * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program->code_size);
 
    staging_buffer = vk_alloc(&cmd_buffer->device->vk.alloc,
                              staging_buffer_size,
@@ -900,7 +901,7 @@ void pvr_pack_clear_vdm_state(
          DIV_ROUND_UP(temps,
                       PVRX(VDMCTRL_VDM_STATE5_VS_PDS_TEMP_SIZE_UNIT_SIZE));
       state5.vs_pds_data_size =
-         DIV_ROUND_UP(program->data_size << 2,
+         DIV_ROUND_UP(PVR_DW_TO_BYTES(program->data_size),
                       PVRX(VDMCTRL_VDM_STATE5_VS_PDS_DATA_SIZE_UNIT_SIZE));
    }
    stream += pvr_cmd_length(VDMCTRL_VDM_STATE5);
index c82ec1a..1214570 100644 (file)
@@ -494,7 +494,7 @@ static VkResult pvr_sub_cmd_gfx_per_job_fragment_programs_create_and_upload(
       .num_emit_word_pairs = 0,
    };
    const uint32_t staging_buffer_size =
-      cmd_buffer->device->pixel_event_data_size_in_dwords * sizeof(uint32_t);
+      PVR_DW_TO_BYTES(cmd_buffer->device->pixel_event_data_size_in_dwords);
    const VkAllocationCallbacks *const allocator = &cmd_buffer->vk.pool->alloc;
    struct pvr_device *const device = cmd_buffer->device;
    struct util_dynarray eot_program_bin;
@@ -810,7 +810,7 @@ static VkResult pvr_load_op_pds_data_create_and_upload(
 
    pvr_pds_set_sizes_pixel_shader_sa_texture_data(&program, dev_info);
 
-   staging_buffer_size = program.data_size * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program.data_size);
 
    staging_buffer = vk_alloc(&cmd_buffer->vk.pool->alloc,
                              staging_buffer_size,
@@ -1624,7 +1624,7 @@ pvr_compute_generate_idfwdf(struct pvr_cmd_buffer *cmd_buffer,
       .usc_unified_size = 0U,
       .pds_temp_size = 0U,
       .pds_data_size =
-         DIV_ROUND_UP(program->data_size << 2,
+         DIV_ROUND_UP(PVR_DW_TO_BYTES(program->data_size),
                       PVRX(CDMCTRL_KERNEL0_PDS_DATA_SIZE_UNIT_SIZE)),
       .usc_target = PVRX(CDMCTRL_USC_TARGET_ALL),
       .is_fence = false,
@@ -1663,7 +1663,7 @@ void pvr_compute_generate_fence(struct pvr_cmd_buffer *cmd_buffer,
       .usc_unified_size = 0U,
       .pds_temp_size = 0U,
       .pds_data_size =
-         DIV_ROUND_UP(program->data_size << 2,
+         DIV_ROUND_UP(PVR_DW_TO_BYTES(program->data_size),
                       PVRX(CDMCTRL_KERNEL0_PDS_DATA_SIZE_UNIT_SIZE)),
       .usc_target = PVRX(CDMCTRL_USC_TARGET_ANY),
       .is_fence = true,
@@ -2975,11 +2975,12 @@ pvr_setup_vertex_buffers(struct pvr_cmd_buffer *cmd_buffer,
    struct pvr_bo *pvr_bo;
    VkResult result;
 
-   result = pvr_cmd_buffer_alloc_mem(cmd_buffer,
-                                     cmd_buffer->device->heaps.pds_heap,
-                                     pds_info->data_size_in_dwords << 2,
-                                     PVR_BO_ALLOC_FLAG_CPU_MAPPED,
-                                     &pvr_bo);
+   result =
+      pvr_cmd_buffer_alloc_mem(cmd_buffer,
+                               cmd_buffer->device->heaps.pds_heap,
+                               PVR_DW_TO_BYTES(pds_info->data_size_in_dwords),
+                               PVR_BO_ALLOC_FLAG_CPU_MAPPED,
+                               &pvr_bo);
    if (result != VK_SUCCESS)
       return result;
 
@@ -3185,11 +3186,12 @@ static VkResult pvr_setup_descriptor_mappings_old(
    if (!pds_info->data_size_in_dwords)
       return VK_SUCCESS;
 
-   result = pvr_cmd_buffer_alloc_mem(cmd_buffer,
-                                     cmd_buffer->device->heaps.pds_heap,
-                                     pds_info->data_size_in_dwords << 2,
-                                     PVR_BO_ALLOC_FLAG_CPU_MAPPED,
-                                     &pvr_bo);
+   result =
+      pvr_cmd_buffer_alloc_mem(cmd_buffer,
+                               cmd_buffer->device->heaps.pds_heap,
+                               PVR_DW_TO_BYTES(pds_info->data_size_in_dwords),
+                               PVR_BO_ALLOC_FLAG_CPU_MAPPED,
+                               &pvr_bo);
    if (result != VK_SUCCESS)
       return result;
 
@@ -3248,9 +3250,9 @@ static VkResult pvr_setup_descriptor_mappings_old(
          assert(descriptor->type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
 
          assert(descriptor->buffer_desc_range ==
-                const_buffer_entry->size_in_dwords * sizeof(uint32_t));
+                PVR_DW_TO_BYTES(const_buffer_entry->size_in_dwords));
          assert(descriptor->buffer_whole_range ==
-                const_buffer_entry->size_in_dwords * sizeof(uint32_t));
+                PVR_DW_TO_BYTES(const_buffer_entry->size_in_dwords));
 
          buffer_addr =
             PVR_DEV_ADDR_OFFSET(descriptor->buffer_dev_addr,
@@ -3271,6 +3273,7 @@ static VkResult pvr_setup_descriptor_mappings_old(
          const uint32_t desc_set_num = desc_set_entry->descriptor_set;
          const struct pvr_descriptor_set *descriptor_set;
          pvr_dev_addr_t desc_set_addr;
+         uint64_t desc_portion_offset;
 
          assert(desc_set_num < PVR_MAX_DESCRIPTOR_SETS);
 
@@ -3320,22 +3323,22 @@ static VkResult pvr_setup_descriptor_mappings_old(
          desc_set_addr = descriptor_set->pvr_bo->vma->dev_addr;
 
          if (desc_set_entry->primary) {
-            desc_set_addr = PVR_DEV_ADDR_OFFSET(
-               desc_set_addr,
+            desc_portion_offset =
                descriptor_set->layout->memory_layout_in_dwords_per_stage[stage]
-                     .primary_offset
-                  << 2U);
+                  .primary_offset;
          } else {
-            desc_set_addr = PVR_DEV_ADDR_OFFSET(
-               desc_set_addr,
+            desc_portion_offset =
                descriptor_set->layout->memory_layout_in_dwords_per_stage[stage]
-                     .secondary_offset
-                  << 2U);
+                  .secondary_offset;
          }
+         desc_portion_offset = PVR_DW_TO_BYTES(desc_portion_offset);
+
+         desc_set_addr =
+            PVR_DEV_ADDR_OFFSET(desc_set_addr, desc_portion_offset);
 
          desc_set_addr = PVR_DEV_ADDR_OFFSET(
             desc_set_addr,
-            (uint64_t)desc_set_entry->offset_in_dwords << 2U);
+            PVR_DW_TO_BYTES((uint64_t)desc_set_entry->offset_in_dwords));
 
          PVR_WRITE(qword_buffer,
                    desc_set_addr.addr,
@@ -3483,9 +3486,9 @@ static VkResult pvr_cmd_buffer_upload_patched_desc_set(
 {
    const struct pvr_descriptor_set_layout *layout = desc_set->layout;
    const uint64_t normal_desc_set_size =
-      layout->total_size_in_dwords * sizeof(uint32_t);
+      PVR_DW_TO_BYTES(layout->total_size_in_dwords);
    const uint64_t dynamic_descs_size =
-      layout->total_dynamic_size_in_dwords * sizeof(uint32_t);
+      PVR_DW_TO_BYTES(layout->total_dynamic_size_in_dwords);
    struct pvr_descriptor_size_info dynamic_uniform_buffer_size_info;
    struct pvr_descriptor_size_info dynamic_storage_buffer_size_info;
    struct pvr_device *device = cmd_buffer->device;
@@ -3601,10 +3604,10 @@ static VkResult pvr_cmd_buffer_upload_patched_desc_set(
 
             memcpy(mem_ptr + primary_offset + size_info->primary * desc_idx,
                    &addr.addr,
-                   size_info->primary * sizeof(uint32_t));
+                   PVR_DW_TO_BYTES(size_info->primary));
             memcpy(mem_ptr + secondary_offset + size_info->secondary * desc_idx,
                    &range,
-                   size_info->secondary * sizeof(uint32_t));
+                   PVR_DW_TO_BYTES(size_info->secondary));
          }
       }
    }
@@ -3787,7 +3790,7 @@ static VkResult pvr_setup_descriptor_mappings_new(
 
    result = pvr_cmd_buffer_alloc_mem(cmd_buffer,
                                      cmd_buffer->device->heaps.pds_heap,
-                                     pds_info->data_size_in_dwords << 2,
+                                     PVR_DW_TO_BYTES(pds_info->data_size_in_dwords),
                                      PVR_BO_ALLOC_FLAG_CPU_MAPPED,
                                      &pvr_bo);
    if (result != VK_SUCCESS)
@@ -3974,7 +3977,7 @@ static void pvr_compute_update_shared(struct pvr_cmd_buffer *cmd_buffer,
 
       info.pds_data_offset = state->pds_compute_descriptor_data_offset;
       info.pds_data_size =
-         DIV_ROUND_UP(pds_data_size_in_dwords << 2U,
+         DIV_ROUND_UP(PVR_DW_TO_BYTES(pds_data_size_in_dwords),
                       PVRX(CDMCTRL_KERNEL0_PDS_DATA_SIZE_UNIT_SIZE));
 
       /* Check that we have upload the code section. */
@@ -3985,7 +3988,7 @@ static void pvr_compute_update_shared(struct pvr_cmd_buffer *cmd_buffer,
 
       info.pds_data_offset = program->data_offset;
       info.pds_data_size =
-         DIV_ROUND_UP(program->data_size << 2U,
+         DIV_ROUND_UP(PVR_DW_TO_BYTES(program->data_size),
                       PVRX(CDMCTRL_KERNEL0_PDS_DATA_SIZE_UNIT_SIZE));
       info.pds_code_offset = program->code_offset;
    }
@@ -4022,7 +4025,7 @@ void pvr_compute_update_shared_private(
          DIV_ROUND_UP(const_shared_regs,
                       PVRX(CDMCTRL_KERNEL0_USC_COMMON_SIZE_UNIT_SIZE)),
       .pds_data_size =
-         DIV_ROUND_UP(pipeline->pds_shared_update_data_size_dw << 2U,
+         DIV_ROUND_UP(PVR_DW_TO_BYTES(pipeline->pds_shared_update_data_size_dw),
                       PVRX(CDMCTRL_KERNEL0_PDS_DATA_SIZE_UNIT_SIZE)),
       .usc_target = PVRX(CDMCTRL_USC_TARGET_ALL),
       .pds_data_offset = pipeline->pds_shared_update_data_offset,
@@ -4092,7 +4095,7 @@ void pvr_compute_update_kernel_private(
                       PVRX(CDMCTRL_KERNEL0_PDS_TEMP_SIZE_UNIT_SIZE)),
 
       .pds_data_size =
-         DIV_ROUND_UP(pipeline->pds_data_size_dw << 2U,
+         DIV_ROUND_UP(PVR_DW_TO_BYTES(pipeline->pds_data_size_dw),
                       PVRX(CDMCTRL_KERNEL0_PDS_DATA_SIZE_UNIT_SIZE)),
       .pds_data_offset = pipeline->pds_data_offset,
       .pds_code_offset = pipeline->pds_code_offset,
@@ -4177,7 +4180,7 @@ static void pvr_compute_update_kernel(
                       PVRX(CDMCTRL_KERNEL0_PDS_TEMP_SIZE_UNIT_SIZE)),
 
       .pds_data_size =
-         DIV_ROUND_UP(program_info->data_size_in_dwords << 2U,
+         DIV_ROUND_UP(PVR_DW_TO_BYTES(program_info->data_size_in_dwords),
                       PVRX(CDMCTRL_KERNEL0_PDS_DATA_SIZE_UNIT_SIZE)),
       .pds_data_offset = pipeline->primary_program.data_offset,
       .pds_code_offset = pipeline->primary_program.code_offset,
@@ -4453,7 +4456,7 @@ pvr_emit_dirty_pds_state(const struct pvr_cmd_buffer *const cmd_buffer,
                       PVRX(VDMCTRL_PDS_STATE0_USC_COMMON_SIZE_UNIT_SIZE));
 
       state0.pds_data_size = DIV_ROUND_UP(
-         vertex_descriptor_state->pds_info.data_size_in_dwords << 2,
+         PVR_DW_TO_BYTES(vertex_descriptor_state->pds_info.data_size_in_dwords),
          PVRX(VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE));
    }
 
@@ -5500,7 +5503,7 @@ static VkResult pvr_emit_ppp_state(struct pvr_cmd_buffer *const cmd_buffer,
 
    result = pvr_cmd_buffer_alloc_mem(cmd_buffer,
                                      cmd_buffer->device->heaps.general_heap,
-                                     ppp_state_words_count * sizeof(uint32_t),
+                                     PVR_DW_TO_BYTES(ppp_state_words_count),
                                      PVR_BO_ALLOC_FLAG_CPU_MAPPED,
                                      &pvr_bo);
    if (result != VK_SUCCESS)
@@ -5508,7 +5511,7 @@ static VkResult pvr_emit_ppp_state(struct pvr_cmd_buffer *const cmd_buffer,
 
    memcpy(pvr_bo->bo->map,
           ppp_state_words,
-          ppp_state_words_count * sizeof(uint32_t));
+          PVR_DW_TO_BYTES(ppp_state_words_count));
 
    /* Write the VDM state update into the VDM control stream. */
    pvr_csb_emit (control_stream, VDMCTRL_PPP_STATE0, state0) {
@@ -5870,9 +5873,9 @@ static void pvr_emit_dirty_vdm_state(struct pvr_cmd_buffer *const cmd_buffer,
          state5.vs_pds_temp_size =
             DIV_ROUND_UP(state->pds_shader.info->temps_required << 2,
                          PVRX(VDMCTRL_VDM_STATE5_VS_PDS_TEMP_SIZE_UNIT_SIZE));
-         state5.vs_pds_data_size =
-            DIV_ROUND_UP(state->pds_shader.info->data_size_in_dwords << 2,
-                         PVRX(VDMCTRL_VDM_STATE5_VS_PDS_DATA_SIZE_UNIT_SIZE));
+         state5.vs_pds_data_size = DIV_ROUND_UP(
+            PVR_DW_TO_BYTES(state->pds_shader.info->data_size_in_dwords),
+            PVRX(VDMCTRL_VDM_STATE5_VS_PDS_DATA_SIZE_UNIT_SIZE));
       }
    }
 }
@@ -6155,9 +6158,8 @@ pvr_write_draw_indirect_vdm_stream(struct pvr_cmd_buffer *cmd_buffer,
                                                dev_info);
       }
 
-      pds_size = (pds_prog.program.data_size_aligned +
-                  pds_prog.program.code_size_aligned)
-                 << 2;
+      pds_size = PVR_DW_TO_BYTES(pds_prog.program.data_size_aligned +
+                                 pds_prog.program.code_size_aligned);
 
       result = pvr_cmd_buffer_alloc_mem(cmd_buffer,
                                         cmd_buffer->device->heaps.pds_heap,
@@ -6170,7 +6172,7 @@ pvr_write_draw_indirect_vdm_stream(struct pvr_cmd_buffer *cmd_buffer,
       pds_base = pds_bo->bo->map;
       memcpy(pds_base,
              pds_prog.program.code,
-             pds_prog.program.code_size_aligned << 2);
+             PVR_DW_TO_BYTES(pds_prog.program.code_size_aligned));
 
       if (state->draw_state.draw_indexed) {
          pvr_pds_generate_draw_elements_indirect(
@@ -6193,17 +6195,18 @@ pvr_write_draw_indirect_vdm_stream(struct pvr_cmd_buffer *cmd_buffer,
          state0.usc_target = PVRX(VDMCTRL_USC_TARGET_ANY);
 
          state0.pds_temp_size =
-            DIV_ROUND_UP(pds_prog.program.temp_size_aligned << 2,
+            DIV_ROUND_UP(PVR_DW_TO_BYTES(pds_prog.program.temp_size_aligned),
                          PVRX(VDMCTRL_PDS_STATE0_PDS_TEMP_SIZE_UNIT_SIZE));
 
          state0.pds_data_size =
-            DIV_ROUND_UP(pds_prog.program.data_size_aligned << 2,
+            DIV_ROUND_UP(PVR_DW_TO_BYTES(pds_prog.program.data_size_aligned),
                          PVRX(VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE));
       }
 
       pvr_csb_emit (csb, VDMCTRL_PDS_STATE1, state1) {
          const uint32_t data_offset =
-            pds_bo->vma->dev_addr.addr + (pds_prog.program.code_size << 2) -
+            pds_bo->vma->dev_addr.addr +
+            PVR_DW_TO_BYTES(pds_prog.program.code_size) -
             cmd_buffer->device->heaps.pds_heap->base_addr.addr;
 
          state1.pds_data_addr = PVR_DEV_ADDR(data_offset);
@@ -7060,10 +7063,10 @@ static void pvr_insert_transparent_obj(struct pvr_cmd_buffer *const cmd_buffer,
    /* Emit VDM state. */
 
    static_assert(sizeof(device->static_clear_state.large_clear_vdm_words) >=
-                    PVR_CLEAR_VDM_STATE_DWORD_COUNT * sizeof(uint32_t),
+                    PVR_DW_TO_BYTES(PVR_CLEAR_VDM_STATE_DWORD_COUNT),
                  "Large clear VDM control stream word length mismatch");
    static_assert(sizeof(device->static_clear_state.vdm_words) ==
-                    PVR_CLEAR_VDM_STATE_DWORD_COUNT * sizeof(uint32_t),
+                    PVR_DW_TO_BYTES(PVR_CLEAR_VDM_STATE_DWORD_COUNT),
                  "Clear VDM control stream word length mismatch");
 
    pvr_emit_clear_words(cmd_buffer, sub_cmd);
index 04caadb..e7642ea 100644 (file)
@@ -228,7 +228,7 @@ CHECK_STRUCT_FIELD_SIZE(pvr_combined_image_sampler_descriptor,
                         ROGUE_NUM_TEXSTATE_IMAGE_WORDS * sizeof(uint64_t));
 CHECK_STRUCT_FIELD_SIZE(pvr_combined_image_sampler_descriptor,
                         image,
-                        PVR_IMAGE_DESCRIPTOR_SIZE * sizeof(uint32_t));
+                        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.
index e664fdb..4c5a31f 100644 (file)
@@ -39,6 +39,7 @@
 #include "pvr_debug.h"
 #include "pvr_device_info.h"
 #include "pvr_private.h"
+#include "pvr_types.h"
 #include "util/list.h"
 #include "util/u_dynarray.h"
 #include "vk_log.h"
@@ -224,7 +225,7 @@ static bool pvr_csb_buffer_extend(struct pvr_csb *csb)
  */
 void *pvr_csb_alloc_dwords(struct pvr_csb *csb, uint32_t num_dwords)
 {
-   const uint32_t required_space = num_dwords * 4;
+   const uint32_t required_space = PVR_DW_TO_BYTES(num_dwords);
    void *p;
 
    if (csb->status != VK_SUCCESS)
index 571c4a5..ab0f1dc 100644 (file)
@@ -226,14 +226,15 @@ void pvr_csb_dump(const struct pvr_csb *csb,
  *                     This can be used by the caller to modify the command or
  *                     state information before it's packed.
  */
-#define pvr_csb_pack(_dst, cmd, name)                                 \
-   for (struct PVRX(cmd) name = { pvr_cmd_header(cmd) },              \
-                         *_loop_terminate = &name;                    \
-        __builtin_expect(_loop_terminate != NULL, 1);                 \
-        ({                                                            \
-           STATIC_ASSERT(sizeof(*(_dst)) == pvr_cmd_length(cmd) * 4); \
-           pvr_cmd_pack(cmd)((_dst), &name);                          \
-           _loop_terminate = NULL;                                    \
+#define pvr_csb_pack(_dst, cmd, name)                           \
+   for (struct PVRX(cmd) name = { pvr_cmd_header(cmd) },        \
+                         *_loop_terminate = &name;              \
+        __builtin_expect(_loop_terminate != NULL, 1);           \
+        ({                                                      \
+           STATIC_ASSERT(sizeof(*(_dst)) ==                     \
+                         PVR_DW_TO_BYTES(pvr_cmd_length(cmd))); \
+           pvr_cmd_pack(cmd)((_dst), &name);                    \
+           _loop_terminate = NULL;                              \
         }))
 
 /**
@@ -245,12 +246,12 @@ void pvr_csb_dump(const struct pvr_csb *csb,
  * \param[in] _src     Pointer to read the packed command/state from.
  * \param[in] cmd      Command/state type.
  */
-#define pvr_csb_unpack(_src, cmd)                                \
-   ({                                                            \
-      struct PVRX(cmd) _name;                                    \
-      STATIC_ASSERT(sizeof(*(_src)) == pvr_cmd_length(cmd) * 4); \
-      pvr_cmd_unpack(cmd)((_src), &_name);                       \
-      _name;                                                     \
+#define pvr_csb_unpack(_src, cmd)                                             \
+   ({                                                                         \
+      struct PVRX(cmd) _name;                                                 \
+      STATIC_ASSERT(sizeof(*(_src)) == PVR_DW_TO_BYTES(pvr_cmd_length(cmd))); \
+      pvr_cmd_unpack(cmd)((_src), &_name);                                    \
+      _name;                                                                  \
    })
 
 /**
@@ -263,13 +264,13 @@ void pvr_csb_dump(const struct pvr_csb *csb,
  * \param[in]     cmd Command/state type.
  * \param[in]     val Pre-packed value to write.
  */
-#define pvr_csb_write_value(dst, cmd, val)                                    \
-   do {                                                                       \
-      static_assert(sizeof(*(dst)) == pvr_cmd_length(cmd) * sizeof(uint32_t), \
-                    "Size mismatch");                                         \
-      static_assert(sizeof(*(dst)) == sizeof(val), "Size mismatch");          \
-      *(dst) = (val);                                                         \
-      (dst)++;                                                                \
+#define pvr_csb_write_value(dst, cmd, val)                                  \
+   do {                                                                     \
+      static_assert(sizeof(*(dst)) == PVR_DW_TO_BYTES(pvr_cmd_length(cmd)), \
+                    "Size mismatch");                                       \
+      static_assert(sizeof(*(dst)) == sizeof(val), "Size mismatch");        \
+      *(dst) = (val);                                                       \
+      (dst)++;                                                              \
    } while (0)
 
 /**
@@ -283,12 +284,12 @@ void pvr_csb_dump(const struct pvr_csb *csb,
  * \param[in]     cmd Command/state type.
  * \param[in]     val Command/state struct to pack and write.
  */
-#define pvr_csb_write_struct(dst, cmd, val)                                   \
-   do {                                                                       \
-      static_assert(sizeof(*(dst)) == pvr_cmd_length(cmd) * sizeof(uint32_t), \
-                    "Size mismatch");                                         \
-      pvr_cmd_pack(cmd)((dst), (val));                                        \
-      (dst)++;                                                                \
+#define pvr_csb_write_struct(dst, cmd, val)                                 \
+   do {                                                                     \
+      static_assert(sizeof(*(dst)) == PVR_DW_TO_BYTES(pvr_cmd_length(cmd)), \
+                    "Size mismatch");                                       \
+      pvr_cmd_pack(cmd)((dst), (val));                                      \
+      (dst)++;                                                              \
    } while (0)
 
 /**@}*/
index 2c32d28..3ed9391 100644 (file)
@@ -1257,7 +1257,7 @@ pvr_descriptor_set_create(struct pvr_device *device,
             if (binding->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
                offset_in_dwords += 4;
 
-            memcpy((uint8_t *)map + offset_in_dwords * sizeof(uint32_t),
+            memcpy((uint8_t *)map + PVR_DW_TO_BYTES(offset_in_dwords),
                    sampler->descriptor.words,
                    sizeof(sampler->descriptor.words));
          }
@@ -1400,8 +1400,12 @@ static void pvr_descriptor_update_buffer_info(
                                                 j,
                                                 write_set->dstArrayElement + i);
 
-         memcpy(mem_ptr + primary_offset, &addr, size_info.primary << 2);
-         memcpy(mem_ptr + secondary_offset, &range, size_info.secondary << 2);
+         memcpy(mem_ptr + primary_offset,
+                &addr,
+                PVR_DW_TO_BYTES(size_info.primary));
+         memcpy(mem_ptr + secondary_offset,
+                &range,
+                PVR_DW_TO_BYTES(size_info.secondary));
       }
    }
 }
@@ -2014,11 +2018,11 @@ static void pvr_copy_descriptor_set(struct pvr_device *device,
 
       memcpy(dst_mem_ptr + dst_primary_offset,
              src_mem_ptr + src_primary_offset,
-             size_info.primary * 4U * copy_set->descriptorCount);
+             PVR_DW_TO_BYTES(size_info.primary) * copy_set->descriptorCount);
 
       memcpy(dst_mem_ptr + dst_secondary_offset,
              src_mem_ptr + src_secondary_offset,
-             size_info.secondary * 4U * copy_set->descriptorCount);
+             PVR_DW_TO_BYTES(size_info.secondary) * copy_set->descriptorCount);
    }
 }
 
index 7a65deb..1a9f75e 100644 (file)
@@ -1178,7 +1178,7 @@ VkResult pvr_pds_compute_shader_create_and_upload(
     */
    /* Code size is in bytes, data size in dwords. */
    staging_buffer_size =
-      program->data_size * sizeof(uint32_t) + program->code_size;
+      PVR_DW_TO_BYTES(program->data_size) + program->code_size;
 
    staging_buffer = vk_alloc(&device->vk.alloc,
                              staging_buffer_size,
@@ -1277,8 +1277,7 @@ static VkResult pvr_pds_idfwdf_programs_create_and_upload(
 
    pvr_pds_vertex_shader_sa(&program, NULL, PDS_GENERATE_SIZES, dev_info);
 
-   staging_buffer_size =
-      (program.code_size + program.data_size) * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program.code_size + program.data_size);
 
    staging_buffer = vk_alloc(&device->vk.alloc,
                              staging_buffer_size,
@@ -1322,7 +1321,7 @@ static VkResult pvr_pds_idfwdf_programs_create_and_upload(
       pvr_pds_vertex_shader_sa(&program, NULL, PDS_GENERATE_SIZES, dev_info);
 
       staging_buffer_size =
-         (program.code_size + program.data_size) * sizeof(*staging_buffer);
+         PVR_DW_TO_BYTES(program.code_size + program.data_size);
 
       staging_buffer = vk_realloc(&device->vk.alloc,
                                   staging_buffer,
@@ -1574,8 +1573,7 @@ static VkResult pvr_device_init_nop_program(struct pvr_device *device)
 
    pvr_pds_set_sizes_pixel_shader(&program);
 
-   staging_buffer_size =
-      (program.code_size + program.data_size) * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program.code_size + program.data_size);
 
    staging_buffer = vk_alloc(&device->vk.alloc,
                              staging_buffer_size,
@@ -2541,8 +2539,8 @@ VkResult pvr_gpu_upload_pds(struct pvr_device *device,
                             struct pvr_pds_upload *const pds_upload_out)
 {
    /* All alignment and sizes below are in bytes. */
-   const size_t data_size = data_size_dwords * sizeof(*data);
-   const size_t code_size = code_size_dwords * sizeof(*code);
+   const size_t data_size = PVR_DW_TO_BYTES(data_size_dwords);
+   const size_t code_size = PVR_DW_TO_BYTES(code_size_dwords);
    const uint64_t data_aligned_size = ALIGN_POT(data_size, data_alignment);
    const uint64_t code_aligned_size = ALIGN_POT(code_size, code_alignment);
    const uint32_t code_offset = ALIGN_POT(data_aligned_size, code_alignment);
index 2f81499..c22960b 100644 (file)
@@ -32,6 +32,7 @@
 #include "pvr_job_context.h"
 #include "pvr_job_compute.h"
 #include "pvr_private.h"
+#include "pvr_types.h"
 #include "pvr_winsys.h"
 #include "util/macros.h"
 
@@ -69,9 +70,8 @@ pvr_submit_info_stream_init(struct pvr_compute_ctx *ctx,
    stream_ptr += pvr_cmd_length(CR_CDM_CONTEXT_STATE_BASE);
 
    pvr_csb_pack (stream_ptr, CR_CDM_CONTEXT_PDS1, state) {
-      /* Convert the data size from dwords to bytes. */
       const uint32_t load_program_data_size =
-         ctx_switch->sr[0].pds.load_program.data_size * 4U;
+         PVR_DW_TO_BYTES(ctx_switch->sr[0].pds.load_program.data_size);
 
       state.pds_seq_dep = false;
       state.usc_seq_dep = false;
index f809651..0ea3a82 100644 (file)
@@ -348,7 +348,7 @@ static VkResult pvr_pds_render_ctx_sr_program_create_and_upload(
                                               PDS_GENERATE_CODE_SEGMENT,
                                               dev_info);
 
-   assert((uint32_t)(buffer_end - staging_buffer) * 4 <
+   assert((uint32_t)(buffer_end - staging_buffer) * sizeof(staging_buffer[0]) <
           ROGUE_PDS_TASK_PROGRAM_SIZE);
 
    return pvr_gpu_upload_pds(device,
@@ -426,7 +426,7 @@ static VkResult pvr_pds_compute_ctx_sr_program_create_and_upload(
                                                  dev_info);
    }
 
-   assert((uint32_t)(buffer_ptr - staging_buffer) * 4 <
+   assert((uint32_t)(buffer_ptr - staging_buffer) * sizeof(staging_buffer[0]) <
           ROGUE_PDS_TASK_PROGRAM_SIZE);
 
    STATIC_ASSERT(PVRX(CR_CDM_CONTEXT_PDS0_DATA_ADDR_ALIGNMENT) ==
@@ -716,7 +716,7 @@ pvr_rogue_get_vdmctrl_pds_state_words(struct pvr_pds_upload *pds_program,
 {
    pvr_csb_pack (state0_out, VDMCTRL_PDS_STATE0, state) {
       /* Convert the data size from dwords to bytes. */
-      const uint32_t pds_data_size = pds_program->data_size * 4;
+      const uint32_t pds_data_size = PVR_DW_TO_BYTES(pds_program->data_size);
 
       state.dm_target = PVRX(VDMCTRL_DM_TARGET_VDM);
       state.usc_target = usc_target;
@@ -744,7 +744,7 @@ pvr_rogue_get_geom_state_stream_out_words(struct pvr_pds_upload *pds_program,
 {
    pvr_csb_pack (stream_out1_out, TA_STATE_STREAM_OUT1, state) {
       /* Convert the data size from dwords to bytes. */
-      const uint32_t pds_data_size = pds_program->data_size * 4;
+      const uint32_t pds_data_size = PVR_DW_TO_BYTES(pds_program->data_size);
 
       state.sync = true;
 
@@ -963,7 +963,7 @@ static VkResult pvr_pds_sr_fence_terminate_program_create_and_upload(
                                                PDS_GENERATE_CODE_SEGMENT,
                                                &device->pdevice->dev_info);
 
-   assert((uint64_t)(buffer_end - staging_buffer) * 4U <
+   assert((uint64_t)(buffer_end - staging_buffer) * sizeof(staging_buffer[0]) <
           ROGUE_PDS_TASK_PROGRAM_SIZE);
 
    return pvr_gpu_upload_pds(device,
@@ -1007,9 +1007,8 @@ static void pvr_compute_ctx_ws_static_state_init(
    pvr_csb_pack (&static_state->cdm_ctx_store_pds1,
                  CR_CDM_CONTEXT_PDS1,
                  state) {
-      /* Convert the data size from dwords to bytes. */
       const uint32_t store_program_data_size =
-         ctx_switch->sr[0].pds.store_program.data_size * 4U;
+         PVR_DW_TO_BYTES(ctx_switch->sr[0].pds.store_program.data_size);
 
       state.pds_seq_dep = true;
       state.usc_seq_dep = false;
@@ -1044,7 +1043,7 @@ static void pvr_compute_ctx_ws_static_state_init(
                  state) {
       /* Convert the data size from dwords to bytes. */
       const uint32_t fence_terminate_program_data_size =
-         ctx_switch->sr_fence_terminate_program.data_size * 4U;
+         PVR_DW_TO_BYTES(ctx_switch->sr_fence_terminate_program.data_size);
 
       state.pds_seq_dep = true;
       state.usc_seq_dep = false;
index 79a428b..cdb642c 100644 (file)
@@ -1091,8 +1091,7 @@ static VkResult pvr_pbe_setup_emit(const struct pvr_transfer_cmd *transfer_cmd,
 
    pvr_pds_set_sizes_pixel_event(&program, dev_info);
 
-   staging_buffer_size =
-      (program.code_size + program.data_size) * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program.code_size + program.data_size);
 
    staging_buffer = vk_alloc(&device->vk.alloc,
                              staging_buffer_size,
@@ -2093,11 +2092,12 @@ pvr_pds_unitex(const struct pvr_device_info *dev_info,
       ALIGN_POT(program->data_size,
                 PVRX(TA_STATE_PDS_SIZEINFO1_PDS_TEXTURESTATESIZE_UNIT_SIZE));
 
-   result = pvr_cmd_buffer_alloc_mem(transfer_cmd->cmd_buffer,
-                                     ctx->device->heaps.pds_heap,
-                                     state->tex_state_data_size << 2U,
-                                     PVR_BO_ALLOC_FLAG_CPU_MAPPED,
-                                     &pvr_bo);
+   result =
+      pvr_cmd_buffer_alloc_mem(transfer_cmd->cmd_buffer,
+                               ctx->device->heaps.pds_heap,
+                               PVR_DW_TO_BYTES(state->tex_state_data_size),
+                               PVR_BO_ALLOC_FLAG_CPU_MAPPED,
+                               &pvr_bo);
    if (result != VK_SUCCESS)
       return result;
 
@@ -2825,7 +2825,7 @@ static VkResult pvr_3d_copy_blit_core(struct pvr_transfer_ctx *ctx,
 
       result = pvr_cmd_buffer_alloc_mem(transfer_cmd->cmd_buffer,
                                         device->heaps.general_heap,
-                                        tex_state_dma_size_dw << 2U,
+                                        PVR_DW_TO_BYTES(tex_state_dma_size_dw),
                                         PVR_BO_ALLOC_FLAG_CPU_MAPPED,
                                         &pvr_bo);
       if (result != VK_SUCCESS)
@@ -3019,12 +3019,12 @@ pvr_pds_coeff_task(struct pvr_transfer_ctx *ctx,
 
    pvr_pds_set_sizes_coeff_loading(&program);
 
-   result =
-      pvr_cmd_buffer_alloc_mem(transfer_cmd->cmd_buffer,
-                               ctx->device->heaps.pds_heap,
-                               (program.data_size + program.code_size) << 2U,
-                               PVR_BO_ALLOC_FLAG_CPU_MAPPED,
-                               &pvr_bo);
+   result = pvr_cmd_buffer_alloc_mem(
+      transfer_cmd->cmd_buffer,
+      ctx->device->heaps.pds_heap,
+      PVR_DW_TO_BYTES(program.data_size + program.code_size),
+      PVR_BO_ALLOC_FLAG_CPU_MAPPED,
+      &pvr_bo);
    if (result != VK_SUCCESS)
       return result;
 
@@ -3700,8 +3700,8 @@ pvr_isp_primitive_block_size(const struct pvr_device_info *dev_info,
          src->surface.mem_layout == PVR_MEMLAYOUT_3DTWIDDLED ? 4U : 2U;
    }
 
-   tsp_data_size = num_isp_vertices * PVR_TRANSFER_NUM_LAYERS * 4U *
-                   num_tsp_vertices_per_isp_vertex;
+   tsp_data_size = PVR_DW_TO_BYTES(num_isp_vertices * PVR_TRANSFER_NUM_LAYERS *
+                                   num_tsp_vertices_per_isp_vertex);
 
    if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format)) {
       /* An XYZ vertex is 16/16/32 bits => 8 bytes. */
@@ -3731,10 +3731,10 @@ pvr_isp_primitive_block_size(const struct pvr_device_info *dev_info,
       pds_state_size_dw = 7U;
    }
 
-   stream_size = tsp_data_size + (idx_data_size_dw + tsp_comp_format_dw +
-                                  isp_vertex_data_size_dw + isp_state_size_dw +
-                                  pds_state_size_dw) *
-                                    4U;
+   stream_size =
+      tsp_data_size + PVR_DW_TO_BYTES(idx_data_size_dw + tsp_comp_format_dw +
+                                      isp_vertex_data_size_dw +
+                                      isp_state_size_dw + pds_state_size_dw);
 
    return stream_size;
 }
@@ -3770,8 +3770,9 @@ pvr_isp_primitive_block(const struct pvr_device_info *dev_info,
          src->surface.mem_layout == PVR_MEMLAYOUT_3DTWIDDLED ? 4U : 2U;
    }
 
-   tsp_data_size_in_bytes = num_isp_vertices * PVR_TRANSFER_NUM_LAYERS * 4U *
-                            num_tsp_vertices_per_isp_vert;
+   tsp_data_size_in_bytes =
+      PVR_DW_TO_BYTES(num_isp_vertices * PVR_TRANSFER_NUM_LAYERS *
+                      num_tsp_vertices_per_isp_vert);
 
    if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format)) {
       tsp_comp_format_in_dw = 0U;
@@ -3850,7 +3851,7 @@ pvr_isp_primitive_block(const struct pvr_device_info *dev_info,
       pvr_isp_prim_block_pds_state(dev_info, ctx, state, cs_ptr_out);
 
       /* Point the CS_PRIM_BASE here. */
-      *cs_start_offset = (*cs_ptr_out - cs_ptr_start) * sizeof(uint32_t);
+      *cs_start_offset = (*cs_ptr_out - cs_ptr_start) * sizeof(cs_ptr_start[0]);
 
       /* This includes:
        *    ISP state words.
@@ -3876,7 +3877,7 @@ pvr_isp_primitive_block(const struct pvr_device_info *dev_info,
          return result;
    }
 
-   assert((*cs_ptr_out - cs_ptr_start) * sizeof(uint32_t) ==
+   assert((*cs_ptr_out - cs_ptr_start) * sizeof(cs_ptr_start[0]) ==
           stream_size_in_bytes);
 
    return VK_SUCCESS;
@@ -3885,7 +3886,7 @@ pvr_isp_primitive_block(const struct pvr_device_info *dev_info,
 static inline uint32_t
 pvr_transfer_prim_blocks_per_alloc(const struct pvr_device_info *dev_info)
 {
-   uint32_t ret = PVRX(IPF_CONTROL_STREAM_SIZE_DWORDS) * sizeof(uint32_t);
+   uint32_t ret = PVR_DW_TO_BYTES(PVRX(IPF_CONTROL_STREAM_SIZE_DWORDS));
 
    if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format))
       return ret / sizeof(uint64_t) / 2U;
@@ -4284,7 +4285,7 @@ static VkResult pvr_isp_ctrl_stream(const struct pvr_device_info *dev_info,
                num_region_arrays++;
                next_region_array_vaddr.addr +=
                   num_region_arrays *
-                  (PVRX(IPF_CONTROL_STREAM_SIZE_DWORDS) * 4);
+                  PVR_DW_TO_BYTES(PVRX(IPF_CONTROL_STREAM_SIZE_DWORDS));
 
                if (PVR_HAS_FEATURE(dev_info,
                                    simple_internal_parameter_format_v2)) {
@@ -4301,7 +4302,8 @@ static VkResult pvr_isp_ctrl_stream(const struct pvr_device_info *dev_info,
                   pvr_isp_ctrl_stream_sipf_write_aligned(
                      (uint8_t *)cs_ptr,
                      link_addr,
-                     pvr_cmd_length(IPF_CONTROL_STREAM_LINK_SIPF2) * 4);
+                     PVR_DW_TO_BYTES(
+                        pvr_cmd_length(IPF_CONTROL_STREAM_LINK_SIPF2)));
                } else {
                   pvr_csb_pack (cs_ptr, IPF_CONTROL_STREAM, control_stream) {
                      control_stream.cs_type = PVRX(IPF_CS_TYPE_LINK);
index 49abb3a..c7fe97d 100644 (file)
@@ -31,6 +31,7 @@
 #include "pvr_hw_pass.h"
 #include "pvr_pds.h"
 #include "pvr_private.h"
+#include "pvr_types.h"
 #include "pvr_usc_fragment_shader.h"
 #include "util/macros.h"
 #include "rogue/rogue.h"
@@ -166,7 +167,7 @@ VkResult pvr_pds_unitex_state_program_create_and_upload(
 
    pvr_pds_set_sizes_pixel_shader_uniform_texture_code(&program);
 
-   staging_buffer_size = program.code_size * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program.code_size);
 
    staging_buffer = vk_alloc2(&device->vk.alloc,
                               allocator,
index dac9152..9c3b957 100644 (file)
@@ -89,8 +89,7 @@ static VkResult pvr_pds_coeff_program_create_and_upload(
       return VK_SUCCESS;
    }
 
-   staging_buffer_size =
-      (program.code_size + program.data_size) * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program.code_size + program.data_size);
 
    staging_buffer = vk_alloc2(&device->vk.alloc,
                               allocator,
@@ -164,8 +163,7 @@ VkResult pvr_pds_fragment_program_create_and_upload(
 
    pvr_pds_kick_usc(&program, NULL, 0, false, PDS_GENERATE_SIZES);
 
-   staging_buffer_size =
-      (program.code_size + program.data_size) * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program.code_size + program.data_size);
 
    staging_buffer = vk_alloc2(&device->vk.alloc,
                               allocator,
@@ -384,7 +382,7 @@ static VkResult pvr_pds_vertex_attrib_program_create_and_upload(
                                            &device->pdevice->dev_info);
 
    code_size_in_dwords = info->code_size_in_dwords;
-   staging_buffer_size = info->code_size_in_dwords * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(info->code_size_in_dwords);
 
    staging_buffer = vk_alloc2(&device->vk.alloc,
                               allocator,
@@ -824,8 +822,7 @@ static VkResult pvr_pds_descriptor_program_create_and_upload(
    pvr_pds_generate_descriptor_upload_program(&program, NULL, pds_info);
 
    code_size_in_dwords = pds_info->code_size_in_dwords;
-   staging_buffer_size =
-      pds_info->code_size_in_dwords * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(pds_info->code_size_in_dwords);
 
    if (!staging_buffer_size) {
       vk_free2(&device->vk.alloc, allocator, entries_buffer);
@@ -971,8 +968,7 @@ static VkResult pvr_pds_compute_program_create_and_upload(
    /* FIXME: According to pvr_device_init_compute_pds_program() the code size
     * is in bytes. Investigate this.
     */
-   staging_buffer_size =
-      (program.code_size + program.data_size) * sizeof(*staging_buffer);
+   staging_buffer_size = PVR_DW_TO_BYTES(program.code_size + program.data_size);
 
    staging_buffer = vk_alloc2(&device->vk.alloc,
                               allocator,
@@ -1062,7 +1058,7 @@ static VkResult pvr_pds_compute_base_workgroup_variant_program_init(
    /* FIXME: According to pvr_device_init_compute_pds_program() the code size
     * is in bytes. Investigate this.
     */
-   buffer_size = MAX2(program.code_size, program.data_size) * sizeof(*buffer);
+   buffer_size = PVR_DW_TO_BYTES(MAX2(program.code_size, program.data_size));
 
    buffer = vk_alloc2(&device->vk.alloc,
                       allocator,
index 05c6a2d..ea31742 100644 (file)
@@ -36,6 +36,7 @@
 #include "pvr_shader_factory.h"
 #include "pvr_static_shaders.h"
 #include "pvr_tex_state.h"
+#include "pvr_types.h"
 #include "vk_alloc.h"
 #include "vk_command_pool.h"
 #include "vk_util.h"
@@ -89,7 +90,7 @@ static VkResult pvr_create_compute_secondary_prog(
    staging_buffer_size = info->code_size_in_dwords;
 
    staging_buffer = vk_alloc(&device->vk.alloc,
-                             staging_buffer_size * sizeof(*staging_buffer),
+                             PVR_DW_TO_BYTES(staging_buffer_size),
                              8,
                              VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
    if (!staging_buffer) {
@@ -207,7 +208,7 @@ static VkResult pvr_write_compute_query_pds_data_section(
 
    result = pvr_cmd_buffer_alloc_mem(cmd_buffer,
                                      cmd_buffer->device->heaps.pds_heap,
-                                     info->data_size_in_dwords << 2,
+                                     PVR_DW_TO_BYTES(info->data_size_in_dwords),
                                      PVR_BO_ALLOC_FLAG_CPU_MAPPED,
                                      &pvr_bo);
    if (result != VK_SUCCESS)
@@ -222,7 +223,7 @@ static VkResult pvr_write_compute_query_pds_data_section(
     * not needed. If it's needed we should probably be using LITERAL entries for
     * this instead.
     */
-   memset(dword_buffer, 0xFE, info->data_size_in_dwords << 2);
+   memset(dword_buffer, 0xFE, PVR_DW_TO_BYTES(info->data_size_in_dwords));
 
    pipeline->pds_shared_update_data_size_dw = info->data_size_in_dwords;
 
index e07a6f5..81ae9b6 100644 (file)
@@ -110,7 +110,8 @@ pvr_spm_scratch_buffer_calc_required_size(const struct pvr_render_pass *pass,
 
    buffer_size = ALIGN_POT((uint64_t)framebuffer_width,
                            PVRX(CR_PBE_WORD0_MRT0_LINESTRIDE_ALIGNMENT));
-   buffer_size *= (uint64_t)framebuffer_height * dwords_per_pixel * 4;
+   buffer_size *=
+      (uint64_t)framebuffer_height * PVR_DW_TO_BYTES(dwords_per_pixel);
 
    return buffer_size;
 }
@@ -325,15 +326,17 @@ VkResult pvr_device_init_spm_load_state(struct pvr_device *device)
 
       pds_texture_aligned_offsets[i] = pds_allocation_size;
       /* FIXME: Figure out the define for alignment of 16. */
-      pds_allocation_size += ALIGN_POT(pds_texture_program.code_size * 4, 16);
+      pds_allocation_size +=
+         ALIGN_POT(PVR_DW_TO_BYTES(pds_texture_program.code_size), 16);
 
       pvr_pds_set_sizes_pixel_shader(&pds_kick_program);
 
       pds_kick_aligned_offsets[i] = pds_allocation_size;
       /* FIXME: Figure out the define for alignment of 16. */
-      pds_allocation_size += ALIGN_POT(
-         (pds_kick_program.code_size + pds_kick_program.data_size) * 4,
-         16);
+      pds_allocation_size +=
+         ALIGN_POT(PVR_DW_TO_BYTES(pds_kick_program.code_size +
+                                   pds_kick_program.data_size),
+                   16);
    }
 
    /* FIXME: Figure out the define for alignment of 16. */
@@ -470,7 +473,7 @@ static uint64_t pvr_spm_setup_pbe_state(
                       pbe_reg_words_out);
 
    return (uint64_t)stride * framebuffer_size->height * sample_count *
-          dword_count * sizeof(uint32_t);
+          PVR_DW_TO_BYTES(dword_count);
 }
 
 static inline void pvr_set_pbe_all_valid_mask(struct usc_mrt_desc *desc)
@@ -536,10 +539,10 @@ static uint64_t pvr_spm_setup_pbe_eight_dword_write(
 
    mrt_resources[render_target_used] = (struct usc_mrt_resource){
       .mrt_desc = {
-         .intermediate_size = max_pbe_write_size_dw * sizeof(uint32_t),
+         .intermediate_size = PVR_DW_TO_BYTES(max_pbe_write_size_dw),
       },
       .type = source_type,
-      .intermediate_size = max_pbe_write_size_dw * sizeof(uint32_t),
+      .intermediate_size = PVR_DW_TO_BYTES(max_pbe_write_size_dw),
    };
 
    if (source_type == USC_MRT_RESOURCE_TYPE_MEMORY)
@@ -562,10 +565,10 @@ static uint64_t pvr_spm_setup_pbe_eight_dword_write(
 
    mrt_resources[render_target_used] = (struct usc_mrt_resource){
       .mrt_desc = {
-         .intermediate_size = max_pbe_write_size_dw * sizeof(uint32_t),
+         .intermediate_size = PVR_DW_TO_BYTES(max_pbe_write_size_dw),
       },
       .type = source_type,
-      .intermediate_size = max_pbe_write_size_dw * sizeof(uint32_t),
+      .intermediate_size = PVR_DW_TO_BYTES(max_pbe_write_size_dw),
    };
 
    if (source_type == USC_MRT_RESOURCE_TYPE_OUTPUT_REG) {
@@ -611,7 +614,7 @@ static VkResult pvr_pds_pixel_event_program_create_and_upload(
 
    staging_buffer =
       vk_alloc(&device->vk.alloc,
-               device->pixel_event_data_size_in_dwords * sizeof(uint32_t),
+               PVR_DW_TO_BYTES(device->pixel_event_data_size_in_dwords),
                8,
                VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
    if (!staging_buffer)
@@ -883,7 +886,7 @@ static VkResult pvr_spm_setup_texture_state_words(
    if (result != VK_SUCCESS)
       return result;
 
-   *mem_used_out = fb_area * dword_count * sizeof(uint32_t) * sample_count;
+   *mem_used_out = fb_area * PVR_DW_TO_BYTES(dword_count) * sample_count;
 
    return VK_SUCCESS;
 }
@@ -922,7 +925,7 @@ static VkResult pvr_pds_bgnd_program_create_and_upload(
    assert(texture_program_data_size_in_dwords == texture_program.data_size);
 #endif
 
-   staging_buffer_size = texture_program_data_size_in_dwords * sizeof(uint32_t);
+   staging_buffer_size = PVR_DW_TO_BYTES(texture_program_data_size_in_dwords);
 
    staging_buffer = vk_alloc(&device->vk.alloc,
                              staging_buffer_size,
index d1354d4..a12706b 100644 (file)
@@ -260,13 +260,13 @@ static VkResult pvr_transfer_frag_store_entry_data_create(
 
    pvr_pds_kick_usc(&kick_usc_pds_prog, NULL, 0U, false, PDS_GENERATE_SIZES);
 
-   result = pvr_bo_alloc(
-      device,
-      device->heaps.pds_heap,
-      (kick_usc_pds_prog.data_size + kick_usc_pds_prog.code_size) * 4,
-      16,
-      PVR_BO_ALLOC_FLAG_CPU_MAPPED,
-      &entry_data->kick_usc_pds_upload);
+   result = pvr_bo_alloc(device,
+                         device->heaps.pds_heap,
+                         PVR_DW_TO_BYTES(kick_usc_pds_prog.data_size +
+                                         kick_usc_pds_prog.code_size),
+                         16,
+                         PVR_BO_ALLOC_FLAG_CPU_MAPPED,
+                         &entry_data->kick_usc_pds_upload);
    if (result != VK_SUCCESS)
       goto err_free_usc_upload;