# vim:syntax=apparmor
# Rules for Mesa implementation of the OpenGL API

  abi <abi/4.0>,

  include <abstractions/dri-common>
  include <abstractions/dri-enumerate>

  # System files
  /dev/udmabuf rw,
  /usr/share/libdrm/amdgpu.ids r,

  # Needed to check if the kernel supports the i915 perf interface
  # (src/intel/perf/gen_perf.c, load_oa_metrics())
  @{PROC}/sys/dev/i915/perf_stream_paranoid r,

  @{sys}/devices/@{pci_bus}/**/{revision,config} r,

  # Thread scheduling
  @{sys}/devices/system/cpu/cpu[0-9]*/cpu_capacity r,

  # User files
  owner @{HOME}/.cache/ w, # if user clears all caches
  owner @{HOME}/.cache/mesa_shader_cache/ rw,
  owner @{HOME}/.cache/mesa_shader_cache/index mrwk,
  owner @{HOME}/.cache/mesa_shader_cache/marker rwk,
  owner @{HOME}/.cache/mesa_shader_cache/[a-f0-9][a-f0-9]/ rw,
  owner @{HOME}/.cache/mesa_shader_cache/[a-f0-9][a-f0-9]/[0-9a-f]* rw,
  owner @{HOME}/.cache/mesa_shader_cache/[a-f0-9][a-f0-9]/[0-9a-f]*.tmp rwk,

  owner @{HOME}/.cache/mesa_shader_cache_db/ rw,
  owner @{HOME}/.cache/mesa_shader_cache_db/index rwk,
  owner @{HOME}/.cache/mesa_shader_cache_db/part*/ rw,
  owner @{HOME}/.cache/mesa_shader_cache_db/part*/mesa_cache.db rwkl,
  owner @{HOME}/.cache/mesa_shader_cache_db/part*/mesa_cache.idx rwkl,

  owner @{HOME}/.cache/radv_builtin_shaders/ rw,
  owner @{HOME}/.cache/radv_builtin_shaders/index rwlk,
  owner @{HOME}/.cache/radv_builtin_shaders/part*/ rw,
  owner @{HOME}/.cache/radv_builtin_shaders/part*/mesa_cache.db rwlk,
  owner @{HOME}/.cache/radv_builtin_shaders/part*/mesa_cache.idx rwlk,

  # Fallback location when @{HOME}/.cache is not available
  owner /tmp/Temp-[a-f0-9]*/mesa_shader_cache/ rw,
  owner /tmp/Temp-[a-f0-9]*/mesa_shader_cache/index rw,
  owner /tmp/Temp-[a-f0-9]*/mesa_shader_cache/[a-f0-9][a-f0-9]/ rw,
  owner /tmp/Temp-[a-f0-9]*/mesa_shader_cache/[a-f0-9][a-f0-9]/[0-9a-f]* rw,
  owner /tmp/Temp-[a-f0-9]*/mesa_shader_cache/[a-f0-9][a-f0-9]/[0-9a-f]*.tmp rwk,

  # Include additions to the abstraction
  include if exists <abstractions/mesa.d>
