radv: add mipmaps support for DCC decompression on compute
[mesa.git] / src / amd / common / ac_binary.c
index 6ad6046894916600d32bf22053b8e7444d6f8fe9..c047666b656d2be446967efad11da1eb29a0ffbe 100644 (file)
@@ -206,43 +206,16 @@ const unsigned char *ac_shader_binary_config_start(
        return binary->config;
 }
 
-
-static const char *scratch_rsrc_dword0_symbol =
-       "SCRATCH_RSRC_DWORD0";
-
-static const char *scratch_rsrc_dword1_symbol =
-       "SCRATCH_RSRC_DWORD1";
-
-void ac_shader_binary_read_config(struct ac_shader_binary *binary,
-                                 struct ac_shader_config *conf,
-                                 unsigned symbol_offset,
-                                 bool supports_spill)
+/* Parse configuration data in .AMDGPU.config section format. */
+void ac_parse_shader_binary_config(const char *data, size_t nbytes,
+                                  bool really_needs_scratch,
+                                  struct ac_shader_config *conf)
 {
-       unsigned i;
-       const unsigned char *config =
-               ac_shader_binary_config_start(binary, symbol_offset);
-       bool really_needs_scratch = false;
        uint32_t wavesize = 0;
-       /* LLVM adds SGPR spills to the scratch size.
-        * Find out if we really need the scratch buffer.
-        */
-       if (supports_spill) {
-               really_needs_scratch = true;
-       } else {
-               for (i = 0; i < binary->reloc_count; i++) {
-                       const struct ac_shader_reloc *reloc = &binary->relocs[i];
 
-                       if (!strcmp(scratch_rsrc_dword0_symbol, reloc->name) ||
-                           !strcmp(scratch_rsrc_dword1_symbol, reloc->name)) {
-                               really_needs_scratch = true;
-                               break;
-                       }
-               }
-       }
-
-       for (i = 0; i < binary->config_size_per_symbol; i+= 8) {
-               unsigned reg = util_le32_to_cpu(*(uint32_t*)(config + i));
-               unsigned value = util_le32_to_cpu(*(uint32_t*)(config + i + 4));
+       for (size_t i = 0; i < nbytes; i += 8) {
+               unsigned reg = util_le32_to_cpu(*(uint32_t*)(data + i));
+               unsigned value = util_le32_to_cpu(*(uint32_t*)(data + i + 4));
                switch (reg) {
                case R_00B028_SPI_SHADER_PGM_RSRC1_PS:
                case R_00B128_SPI_SHADER_PGM_RSRC1_VS:
@@ -252,12 +225,14 @@ void ac_shader_binary_read_config(struct ac_shader_binary *binary,
                        conf->num_sgprs = MAX2(conf->num_sgprs, (G_00B028_SGPRS(value) + 1) * 8);
                        conf->num_vgprs = MAX2(conf->num_vgprs, (G_00B028_VGPRS(value) + 1) * 4);
                        conf->float_mode =  G_00B028_FLOAT_MODE(value);
+                       conf->rsrc1 = value;
                        break;
                case R_00B02C_SPI_SHADER_PGM_RSRC2_PS:
                        conf->lds_size = MAX2(conf->lds_size, G_00B02C_EXTRA_LDS_SIZE(value));
                        break;
                case R_00B84C_COMPUTE_PGM_RSRC2:
                        conf->lds_size = MAX2(conf->lds_size, G_00B84C_LDS_SIZE(value));
+                       conf->rsrc2 = value;
                        break;
                case R_0286CC_SPI_PS_INPUT_ENA:
                        conf->spi_ps_input_ena = value;
@@ -288,13 +263,62 @@ void ac_shader_binary_read_config(struct ac_shader_binary *binary,
                        }
                        break;
                }
-
-               if (!conf->spi_ps_input_addr)
-                       conf->spi_ps_input_addr = conf->spi_ps_input_ena;
        }
 
+       if (!conf->spi_ps_input_addr)
+               conf->spi_ps_input_addr = conf->spi_ps_input_ena;
+
        if (really_needs_scratch) {
                /* sgprs spills aren't spilling */
                conf->scratch_bytes_per_wave = G_00B860_WAVESIZE(wavesize) * 256 * 4;
        }
 }
+
+static const char *scratch_rsrc_dword0_symbol =
+       "SCRATCH_RSRC_DWORD0";
+
+static const char *scratch_rsrc_dword1_symbol =
+       "SCRATCH_RSRC_DWORD1";
+
+void ac_shader_binary_read_config(struct ac_shader_binary *binary,
+                                 struct ac_shader_config *conf,
+                                 unsigned symbol_offset,
+                                 bool supports_spill)
+{
+       unsigned i;
+       const char *config =
+               (const char *)ac_shader_binary_config_start(binary, symbol_offset);
+       bool really_needs_scratch = false;
+       /* LLVM adds SGPR spills to the scratch size.
+        * Find out if we really need the scratch buffer.
+        */
+       if (supports_spill) {
+               really_needs_scratch = true;
+       } else {
+               for (i = 0; i < binary->reloc_count; i++) {
+                       const struct ac_shader_reloc *reloc = &binary->relocs[i];
+
+                       if (!strcmp(scratch_rsrc_dword0_symbol, reloc->name) ||
+                           !strcmp(scratch_rsrc_dword1_symbol, reloc->name)) {
+                               really_needs_scratch = true;
+                               break;
+                       }
+               }
+       }
+
+       ac_parse_shader_binary_config(config, binary->config_size_per_symbol,
+                                     really_needs_scratch, conf);
+}
+
+void ac_shader_binary_clean(struct ac_shader_binary *b)
+{
+       if (!b)
+               return;
+       FREE(b->code);
+       FREE(b->config);
+       FREE(b->rodata);
+       FREE(b->global_symbol_offsets);
+       FREE(b->relocs);
+       FREE(b->disasm_string);
+       FREE(b->llvm_ir_string);
+}