Re: [Mesa-dev] [PATCH 8/9] radeonsi: decompress DCC in set_framebuffer_state instead of create_surface

2017-03-30 Thread Nicolai Hähnle

On 29.03.2017 19:58, Marek Olšák wrote:

From: Marek Olšák 

for threaded gallium, which can't use pipe_context in create_surface
---
 src/gallium/drivers/radeon/r600_pipe_common.h |  8 +++
 src/gallium/drivers/radeon/r600_texture.c | 33 +++
 src/gallium/drivers/radeonsi/si_state.c   | 26 +
 3 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h 
b/src/gallium/drivers/radeon/r600_pipe_common.h
index 035ab1c..c9cb586 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.h
+++ b/src/gallium/drivers/radeon/r600_pipe_common.h
@@ -276,20 +276,21 @@ struct r600_surface {
struct pipe_surface base;

bool color_initialized;
bool depth_initialized;

/* Misc. color flags. */
bool alphatest_bypass;
bool export_16bpc;
bool color_is_int8;
bool color_is_int10;
+   bool dcc_incompatible;

/* Color registers. */
unsigned cb_color_info;
unsigned cb_color_base;
unsigned cb_color_view;
unsigned cb_color_size; /* R600 only */
unsigned cb_color_dim;  /* EG only */
unsigned cb_color_pitch;/* EG and later */
unsigned cb_color_slice;/* EG and later */
unsigned cb_color_attrib;   /* EG and later */
@@ -784,20 +785,27 @@ void r600_texture_get_cmask_info(struct 
r600_common_screen *rscreen,
 struct r600_texture *rtex,
 struct r600_cmask_info *out);
 bool r600_init_flushed_depth_texture(struct pipe_context *ctx,
 struct pipe_resource *texture,
 struct r600_texture **staging);
 void r600_print_texture_info(struct r600_texture *rtex, FILE *f);
 struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
const struct pipe_resource *templ);
 bool vi_dcc_formats_compatible(enum pipe_format format1,
   enum pipe_format format2);
+bool vi_dcc_formats_are_incompatible(struct pipe_resource *tex,
+unsigned level,
+enum pipe_format view_format);
+void vi_disable_dcc_if_incompatible_flag(struct r600_common_context *rctx,
+struct pipe_resource *tex,
+unsigned level,
+bool dcc_incompatible);


Why pass the dcc_incompatible flag as a parameter? It makes more sense 
for the callers to check this flag, and as far as I can tell, all 
callers actually do check it already.


Apart from that, the series is

Reviewed-by: Nicolai Hähnle 



 void vi_disable_dcc_if_incompatible_format(struct r600_common_context *rctx,
   struct pipe_resource *tex,
   unsigned level,
   enum pipe_format view_format);
 struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
struct pipe_resource *texture,
const struct pipe_surface 
*templ,
unsigned width, unsigned 
height);
 unsigned r600_translate_colorswap(enum pipe_format format, bool 
do_endian_swap);
 void vi_separate_dcc_start_query(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/radeon/r600_texture.c 
b/src/gallium/drivers/radeon/r600_texture.c
index 783f50c..1191a74 100644
--- a/src/gallium/drivers/radeon/r600_texture.c
+++ b/src/gallium/drivers/radeon/r600_texture.c
@@ -1733,59 +1733,82 @@ bool vi_dcc_formats_compatible(enum pipe_format format1,
return false;

type1 = vi_get_dcc_channel_type(desc1);
type2 = vi_get_dcc_channel_type(desc2);

return type1 != dcc_channel_incompatible &&
   type2 != dcc_channel_incompatible &&
   type1 == type2;
 }

+bool vi_dcc_formats_are_incompatible(struct pipe_resource *tex,
+unsigned level,
+enum pipe_format view_format)
+{
+   struct r600_texture *rtex = (struct r600_texture *)tex;
+
+   return vi_dcc_enabled(rtex, level) &&
+  !vi_dcc_formats_compatible(tex->format, view_format);
+}
+
+void vi_disable_dcc_if_incompatible_flag(struct r600_common_context *rctx,
+struct pipe_resource *tex,
+unsigned level,
+bool dcc_incompatible)
+{
+   struct r600_texture *rtex = (struct r600_texture *)tex;
+
+   if (vi_dcc_enabled(rtex, level) && dcc_incompatible)
+   if 

[Mesa-dev] [PATCH 8/9] radeonsi: decompress DCC in set_framebuffer_state instead of create_surface

2017-03-29 Thread Marek Olšák
From: Marek Olšák 

for threaded gallium, which can't use pipe_context in create_surface
---
 src/gallium/drivers/radeon/r600_pipe_common.h |  8 +++
 src/gallium/drivers/radeon/r600_texture.c | 33 +++
 src/gallium/drivers/radeonsi/si_state.c   | 26 +
 3 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h 
b/src/gallium/drivers/radeon/r600_pipe_common.h
index 035ab1c..c9cb586 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.h
+++ b/src/gallium/drivers/radeon/r600_pipe_common.h
@@ -276,20 +276,21 @@ struct r600_surface {
struct pipe_surface base;
 
bool color_initialized;
bool depth_initialized;
 
/* Misc. color flags. */
bool alphatest_bypass;
bool export_16bpc;
bool color_is_int8;
bool color_is_int10;
+   bool dcc_incompatible;
 
/* Color registers. */
unsigned cb_color_info;
unsigned cb_color_base;
unsigned cb_color_view;
unsigned cb_color_size; /* R600 only */
unsigned cb_color_dim;  /* EG only */
unsigned cb_color_pitch;/* EG and later */
unsigned cb_color_slice;/* EG and later */
unsigned cb_color_attrib;   /* EG and later */
@@ -784,20 +785,27 @@ void r600_texture_get_cmask_info(struct 
r600_common_screen *rscreen,
 struct r600_texture *rtex,
 struct r600_cmask_info *out);
 bool r600_init_flushed_depth_texture(struct pipe_context *ctx,
 struct pipe_resource *texture,
 struct r600_texture **staging);
 void r600_print_texture_info(struct r600_texture *rtex, FILE *f);
 struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
const struct pipe_resource *templ);
 bool vi_dcc_formats_compatible(enum pipe_format format1,
   enum pipe_format format2);
+bool vi_dcc_formats_are_incompatible(struct pipe_resource *tex,
+unsigned level,
+enum pipe_format view_format);
+void vi_disable_dcc_if_incompatible_flag(struct r600_common_context *rctx,
+struct pipe_resource *tex,
+unsigned level,
+bool dcc_incompatible);
 void vi_disable_dcc_if_incompatible_format(struct r600_common_context *rctx,
   struct pipe_resource *tex,
   unsigned level,
   enum pipe_format view_format);
 struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
struct pipe_resource *texture,
const struct pipe_surface 
*templ,
unsigned width, unsigned 
height);
 unsigned r600_translate_colorswap(enum pipe_format format, bool 
do_endian_swap);
 void vi_separate_dcc_start_query(struct pipe_context *ctx,
diff --git a/src/gallium/drivers/radeon/r600_texture.c 
b/src/gallium/drivers/radeon/r600_texture.c
index 783f50c..1191a74 100644
--- a/src/gallium/drivers/radeon/r600_texture.c
+++ b/src/gallium/drivers/radeon/r600_texture.c
@@ -1733,59 +1733,82 @@ bool vi_dcc_formats_compatible(enum pipe_format format1,
return false;
 
type1 = vi_get_dcc_channel_type(desc1);
type2 = vi_get_dcc_channel_type(desc2);
 
return type1 != dcc_channel_incompatible &&
   type2 != dcc_channel_incompatible &&
   type1 == type2;
 }
 
+bool vi_dcc_formats_are_incompatible(struct pipe_resource *tex,
+unsigned level,
+enum pipe_format view_format)
+{
+   struct r600_texture *rtex = (struct r600_texture *)tex;
+
+   return vi_dcc_enabled(rtex, level) &&
+  !vi_dcc_formats_compatible(tex->format, view_format);
+}
+
+void vi_disable_dcc_if_incompatible_flag(struct r600_common_context *rctx,
+struct pipe_resource *tex,
+unsigned level,
+bool dcc_incompatible)
+{
+   struct r600_texture *rtex = (struct r600_texture *)tex;
+
+   if (vi_dcc_enabled(rtex, level) && dcc_incompatible)
+   if (!r600_texture_disable_dcc(rctx, (struct r600_texture*)tex))
+   rctx->decompress_dcc(>b, rtex);
+}
+
+/* This can't be merged with the above function, because
+ * vi_dcc_formats_compatible should be called only when DCC is enabled. */
 void vi_disable_dcc_if_incompatible_format(struct