diff --git a/src/imagination/vulkan/pvr_cmd_buffer.c b/src/imagination/vulkan/pvr_cmd_buffer.c index 93e5a385d1b..a58f0a76d07 100644 --- a/src/imagination/vulkan/pvr_cmd_buffer.c +++ b/src/imagination/vulkan/pvr_cmd_buffer.c @@ -4350,12 +4350,11 @@ pvr_emit_dirty_ppp_state(struct pvr_cmd_buffer *const cmd_buffer, return VK_SUCCESS; } -static void -pvr_calculate_vertex_cam_size(const struct pvr_device_info *dev_info, - const uint32_t vs_output_size, - const bool raster_enable, - uint32_t *const cam_size_out, - uint32_t *const vs_max_instances_out) +void pvr_calculate_vertex_cam_size(const struct pvr_device_info *dev_info, + const uint32_t vs_output_size, + const bool raster_enable, + uint32_t *const cam_size_out, + uint32_t *const vs_max_instances_out) { /* First work out the size of a vertex in the UVS and multiply by 4 for * column ordering. diff --git a/src/imagination/vulkan/pvr_device.c b/src/imagination/vulkan/pvr_device.c index b87bda0a488..948af5091ee 100644 --- a/src/imagination/vulkan/pvr_device.c +++ b/src/imagination/vulkan/pvr_device.c @@ -1573,6 +1573,82 @@ static void pvr_device_setup_graphics_static_clear_ppp_templates( } } +static void pvr_device_setup_graphics_static_clear_vdm_state( + const struct pvr_device_info *const dev_info, + const struct pvr_pds_upload *const program, + uint32_t temps, + uint32_t index_count, + uint32_t vs_output_size_in_bytes, + uint32_t state_buffer[const static PVR_CLEAR_VDM_STATE_DWORD_COUNT]) +{ + const uint32_t vs_output_size = + DIV_ROUND_UP(vs_output_size_in_bytes, + PVRX(VDMCTRL_VDM_STATE4_VS_OUTPUT_SIZE_UNIT_SIZE)); + uint32_t *stream = state_buffer; + uint32_t max_instances; + uint32_t cam_size; + + pvr_calculate_vertex_cam_size(dev_info, + vs_output_size, + true, + &cam_size, + &max_instances); + + pvr_csb_pack (stream, VDMCTRL_VDM_STATE0, state0) { + state0.vs_data_addr_present = true; + state0.vs_other_present = true; + state0.cam_size = cam_size; + state0.uvs_scratch_size_select = + PVRX(VDMCTRL_UVS_SCRATCH_SIZE_SELECT_FIVE); + state0.flatshade_control = PVRX(VDMCTRL_FLATSHADE_CONTROL_VERTEX_0); + } + stream += pvr_cmd_length(VDMCTRL_VDM_STATE0); + + pvr_csb_pack (stream, VDMCTRL_VDM_STATE2, state2) { + state2.vs_pds_data_base_addr = PVR_DEV_ADDR(program->data_offset); + } + stream += pvr_cmd_length(VDMCTRL_VDM_STATE2); + + pvr_csb_pack (stream, VDMCTRL_VDM_STATE3, state3) { + state3.vs_pds_code_base_addr = PVR_DEV_ADDR(program->code_offset); + } + stream += pvr_cmd_length(VDMCTRL_VDM_STATE3); + + pvr_csb_pack (stream, VDMCTRL_VDM_STATE4, state4) { + state4.vs_output_size = vs_output_size; + } + stream += pvr_cmd_length(VDMCTRL_VDM_STATE4); + + pvr_csb_pack (stream, VDMCTRL_VDM_STATE5, state5) { + state5.vs_max_instances = max_instances; + /* TODO: Where does the 3 * sizeof(uint32_t) come from? */ + state5.vs_usc_unified_size = + DIV_ROUND_UP(3 * sizeof(uint32_t), + PVRX(VDMCTRL_VDM_STATE5_VS_USC_UNIFIED_SIZE_UNIT_SIZE)); + state5.vs_pds_temp_size = + 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, + PVRX(VDMCTRL_VDM_STATE5_VS_PDS_DATA_SIZE_UNIT_SIZE)); + } + stream += pvr_cmd_length(VDMCTRL_VDM_STATE5); + + pvr_csb_pack (stream, VDMCTRL_INDEX_LIST0, index_list0) { + index_list0.index_count_present = true; + index_list0.primitive_topology = + PVRX(VDMCTRL_PRIMITIVE_TOPOLOGY_TRI_STRIP); + } + stream += pvr_cmd_length(VDMCTRL_INDEX_LIST0); + + pvr_csb_pack (stream, VDMCTRL_INDEX_LIST2, index_list3) { + index_list3.index_count = index_count; + } + stream += pvr_cmd_length(VDMCTRL_INDEX_LIST2); + + assert((uint64_t)(stream - state_buffer) == PVR_CLEAR_VDM_STATE_DWORD_COUNT); +} + static VkResult pvr_device_init_graphics_static_clear_state(struct pvr_device *device) { @@ -1673,6 +1749,30 @@ pvr_device_init_graphics_static_clear_state(struct pvr_device *device) pvr_device_setup_graphics_static_clear_ppp_base(&state->ppp_base); pvr_device_setup_graphics_static_clear_ppp_templates(state->ppp_templates); + assert(pds_program.code_size <= state->pds.code_size); + + /* TODO: The difference between the large and normal words is only the last + * word. The value is 3 or 4 depending on the amount of indices. Should we + * dedup this? + */ + + /* TODO: Figure out where the 4 * sizeof(uint32_t) comes from. */ + pvr_device_setup_graphics_static_clear_vdm_state(&device->pdevice->dev_info, + &state->pds, + pds_program.temps_used, + 3, + 4 * sizeof(uint32_t), + state->vdm_words); + + /* TODO: Figure out where the 4 * sizeof(uint32_t) comes from. */ + pvr_device_setup_graphics_static_clear_vdm_state( + &device->pdevice->dev_info, + &state->pds, + pds_program.temps_used, + 4, + 4 * sizeof(uint32_t), + state->large_clear_vdm_words); + return VK_SUCCESS; err_free_staging_buffer: diff --git a/src/imagination/vulkan/pvr_private.h b/src/imagination/vulkan/pvr_private.h index 0102e7dd7bd..cd606866bcc 100644 --- a/src/imagination/vulkan/pvr_private.h +++ b/src/imagination/vulkan/pvr_private.h @@ -321,6 +321,12 @@ struct pvr_static_clear_ppp_template { } config; }; +#define PVR_CLEAR_VDM_STATE_DWORD_COUNT \ + (pvr_cmd_length(VDMCTRL_VDM_STATE0) + pvr_cmd_length(VDMCTRL_VDM_STATE2) + \ + pvr_cmd_length(VDMCTRL_VDM_STATE3) + pvr_cmd_length(VDMCTRL_VDM_STATE4) + \ + pvr_cmd_length(VDMCTRL_VDM_STATE5) + pvr_cmd_length(VDMCTRL_INDEX_LIST0) + \ + pvr_cmd_length(VDMCTRL_INDEX_LIST2)) + struct pvr_device { struct vk_device vk; struct pvr_instance *instance; @@ -376,6 +382,9 @@ struct pvr_device { struct pvr_static_clear_ppp_base ppp_base; struct pvr_static_clear_ppp_template ppp_templates[PVR_STATIC_CLEAR_VARIANT_COUNT]; + + uint32_t vdm_words[PVR_CLEAR_VDM_STATE_DWORD_COUNT]; + uint32_t large_clear_vdm_words[PVR_CLEAR_VDM_STATE_DWORD_COUNT]; } static_clear_state; VkPhysicalDeviceFeatures features; @@ -1425,6 +1434,12 @@ VkResult pvr_cmd_buffer_alloc_mem(struct pvr_cmd_buffer *cmd_buffer, uint32_t flags, struct pvr_bo **const pvr_bo_out); +void pvr_calculate_vertex_cam_size(const struct pvr_device_info *dev_info, + const uint32_t vs_output_size, + const bool raster_enable, + uint32_t *const cam_size_out, + uint32_t *const vs_max_instances_out); + static inline struct pvr_compute_pipeline * to_pvr_compute_pipeline(struct pvr_pipeline *pipeline) {