On 6 June 2012 23:42, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 06/06/2012 12:20 PM, Paul Berry wrote:<br>
> Previously the blorp engine only supported RGBA8 color buffers and<br>
> 24-bit depth buffers. This patch adds support for any color buffer<br>
> format that is supported as a render target, and for 16-bit and 32-bit<br>
> depth buffers.<br>
><br>
> This required threading the brw_context struct through into<br>
> brw_blorp_surface_info::set() so that it can consult the<br>
> brw->render_target_format array.<br>
> ---<br>
> src/mesa/drivers/dri/i965/brw_blorp.cpp | 37 +++++++++++++++++++++++---<br>
> src/mesa/drivers/dri/i965/brw_blorp.h | 3 +-<br>
> src/mesa/drivers/dri/i965/brw_blorp_blit.cpp | 4 +-<br>
> 3 files changed, 37 insertions(+), 7 deletions(-)<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_blorp.cpp b/src/mesa/drivers/dri/i965/brw_blorp.cpp<br>
> index d6d00e7..32ea738 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_blorp.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_blorp.cpp<br>
> @@ -53,23 +53,52 @@ brw_blorp_mip_info::set(struct intel_mipmap_tree *mt,<br>
> }<br>
><br>
> void<br>
> -brw_blorp_surface_info::set(struct intel_mipmap_tree *mt,<br>
> +brw_blorp_surface_info::set(struct brw_context *brw,<br>
> + struct intel_mipmap_tree *mt,<br>
> unsigned int level, unsigned int layer)<br>
> {<br>
> brw_blorp_mip_info::set(mt, level, layer);<br>
> this->num_samples = mt->num_samples;<br>
> this->array_spacing_lod0 = mt->array_spacing_lod0;<br>
> + this->map_stencil_as_y_tiled = false;<br>
><br>
> - if (mt->format == MESA_FORMAT_S8) {<br>
> + switch (mt->format) {<br>
> + case MESA_FORMAT_S8:<br>
> /* The miptree is a W-tiled stencil buffer. Surface states can't be set<br>
> * up for W tiling, so we'll need to use Y tiling and have the WM<br>
> * program swizzle the coordinates.<br>
> */<br>
> this->map_stencil_as_y_tiled = true;<br>
> this->brw_surfaceformat = BRW_SURFACEFORMAT_R8_UNORM;<br>
> - } else {<br>
> - this->map_stencil_as_y_tiled = false;<br>
> + break;<br>
> + case MESA_FORMAT_X8_Z24:<br>
> + case MESA_FORMAT_Z32_FLOAT:<br>
> + /* The miptree consists of 32 bits per pixel, arranged either as 24-bit<br>
> + * depth values interleaved with 8 "don't care" bits, or as 32-bit<br>
> + * floating point depth values. Since depth values don't require any<br>
> + * blending, it doesn't matter how we interpret the bit pattern as long<br>
> + * as we copy the right amount of data, so just map it as 8-bit RGBA.<br>
<br>
</div></div>Nitpick...you're not mapping it as RGBA. I would believe either<br>
"just map it as 8-bit BGRA" ... or "as 8-bit ARGB" since I can never<br>
keep the endianness straight.<br>
<br>
Of course, the point of the comment is precisely that it doesn't<br>
matter... :)<br></blockquote><div><br>Yeah, I didn't want to trouble the reader with this subtlety, but you are technically correct. I'll update the comment.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im"><br>
> + */<br>
> this->brw_surfaceformat = BRW_SURFACEFORMAT_B8G8R8A8_UNORM;<br>
> + break;<br>
> + case MESA_FORMAT_Z16:<br>
> + /* The miptree consists of 16 bits per pixel of depth data. Since depth<br>
> + * values don't require any blending, it doesn't matter how we interpret<br>
> + * the bit pattern as long as we copy the right amount of data, so just<br>
> + * map is as 8-bit RG.<br>
> + */<br>
> + this->brw_surfaceformat = BRW_SURFACEFORMAT_R8G8_UNORM;<br>
> + break;<br>
> + default:<br>
> + /* Blorp blits don't support any sort of format conversion, so we can<br>
> + * safely assume that the same format is being used for the source and<br>
> + * destination. Therefore the format must be supported as a render<br>
> + * target, even if this is the source image. So we can convert to a<br>
> + * surface format using brw->render_target_format.<br>
> + */<br>
> + assert(brw->format_supported_as_render_target[mt->format]);<br>
> + this->brw_surfaceformat = brw->render_target_format[mt->format];<br>
<br>
</div>Why not just do:<br>
<br>
default:<br>
this->brw_surfaceformat = brw_format_for_mesa_format(mt->format);<br></blockquote><div><br>The trouble is that brw->render_target_format[] and brw_format_for_mesa_format() don't do the same thing. In particular, brw->render_target_format maps several formats that are otherwise unsupported as render targets onto equivalent formats that are supported:<br>
<br>BRW_SURFACEFORMAT_B8G8R8X8_UNORM -> BRW_SURFACEFORMAT_B8G8R8A8_UNORM<br>BRW_SURFACEFORMAT_I32_FLOAT -> BRW_SURFACEFORMAT_R32_FLOAT<br>BRW_SURFACEFORMAT_L32_FLOAT -> BRW_SURFACEFORMAT_R32_FLOAT<br>BRW_SURFACEFORMAT_I16_FLOAT -> BRW_SURFACEFORMAT_R16_FLOAT<br>
BRW_SURFACEFORMAT_L16_FLOAT -> BRW_SURFACEFORMAT_R16_FLOAT<br><br>Blorp needs to use brw->render_target_format[] so that these mappings will occur, otherwise it will try to map the render target using an unsupported format.<br>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Then you don't need to explain why it's safe to assume that source<br>
formats are render formats and access the array directly. Obviously, it<br>
still needs to be renderable, but that's probably best captured<br>
elsewhere in an assert like<br>
<br>
assert(source_format == dest_format);<br>
<br>
which I assume you already have.<br>
<br>
With those minor changes, this is:<br>
Reviewed-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
<div class="HOEnZb"><div class="h5"><br>
> + break;<br>
> }<br>
> }<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_blorp.h b/src/mesa/drivers/dri/i965/brw_blorp.h<br>
> index 0de3d1e..4c74c91 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_blorp.h<br>
> +++ b/src/mesa/drivers/dri/i965/brw_blorp.h<br>
> @@ -66,7 +66,8 @@ class brw_blorp_surface_info : public brw_blorp_mip_info<br>
> public:<br>
> brw_blorp_surface_info();<br>
><br>
> - void set(struct intel_mipmap_tree *mt,<br>
> +void set(struct brw_context *brw,<br>
> + struct intel_mipmap_tree *mt,<br>
> unsigned int level, unsigned int layer);<br>
><br>
> /* Setting this flag indicates that the buffer's contents are W-tiled<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
> index 93c3f73..180468b 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_blorp_blit.cpp<br>
> @@ -1274,8 +1274,8 @@ brw_blorp_blit_params::brw_blorp_blit_params(struct brw_context *brw,<br>
> GLuint dst_x1, GLuint dst_y1,<br>
> bool mirror_x, bool mirror_y)<br>
> {<br>
> - src.set(src_mt, 0, 0);<br>
> - dst.set(dst_mt, 0, 0);<br>
> + src.set(brw, src_mt, 0, 0);<br>
> + dst.set(brw, dst_mt, 0, 0);<br>
><br>
> use_wm_prog = true;<br>
> memset(&wm_prog_key, 0, sizeof(wm_prog_key));<br>
</div></div></blockquote></div><br>