Skip to content

turnip: a7xx preparation, transition to C++

Danylo Piliaiev requested to merge Danil/mesa:turnip/feature/cpp-for-a7xx into main

Well, that took a bit more changes than I expected. Freedreno already prepared for a7xx and done a number of common changes in !21846 (merged)

Why C++? Freedreno a6xx code transitioned to C++ and we now have register definitions supporting several generations via templates. It would also be great to have nice containers (@Danil stares menacingly at hash_table, u_vector, and their friends) and other goodies.


Not too many changes to the common VK code. And since turnip is being tested by CI there is no worry that changes to the common code would break the turnip c++ compilation (I remember that it was an issue for Dozen when it used C++).

Notable changes are:

  • vk/util: Generate defines to help casting structs with vk_find_struct - the vk_find_struct usage generates lots and lots of warnings due to the cast from void *
  • vk/entry_points: Add option to generate template entrypoints - generates templated entrypoints, like this:
  template <chip CHIP>
  VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL tu_GetDeviceProcAddr(VkDevice device, const char* pName);

And creates separate vk_device_entrypoint_table for each template variant.


Almost all turnip changes are to avoid enabling -fpermissive with thousands unsilenceable warnings. We truly loved to cast from void * and take pointer of the rvalues...

Generation-dependent functions would look like this:

template <chip CHIP>
VKAPI_ATTR void VKAPI_CALL
tu_SomeFunc(...
{
   [...]

   tu_cs_emit_regs(cs,
                   HLSQ_CONTROL_1_REG(CHIP, .unknown = 0x7),
                   HLSQ_CONTROL_2_REG(CHIP,
                      .faceregid = face_regid,
                      .sampleid = samp_id_regid,
                      .samplemask = smask_in_regid,
                      .centerrhw = ij_regid[IJ_PERSP_CENTER_RHW]));

   if (CHIP == A7XX)
      emit_some_extra_regs;
}

TU_GENX(tu_SomeFunc_GENS);

// Where tu_SomeFunc_GENS is auto generated in *_entrypoints.h
// #define tu_SomeFunc_GENS(X)   template VKAPI_ATTR void VKAPI_CALL tu_SomeFunc_GENS<X>(some args);

@robclark Compiling tu_knl_drm_msm as c code to avoid errors with drm_msm_gem_submit_reloc::or did not work out.

Edited by Danylo Piliaiev

Merge request reports