diff options
author | Matthew McClure <[email protected]> | 2013-10-22 15:48:00 -0700 |
---|---|---|
committer | José Fonseca <[email protected]> | 2013-10-29 15:53:48 +0000 |
commit | be0b67a1436eb2b899f9874725b2a68eb26f9f3f (patch) | |
tree | 0520a19b3579cc98ec2e61fef69934782625602e /src/gallium/auxiliary | |
parent | d0eaf6752d6faa8a17e3270b9e64b7c09ef705c2 (diff) |
util,llvmpipe: correctly set the minimum representable depth value
Reviewed-by: Roland Scheidegger <[email protected]>
Reviewed-by: Jose Fonseca <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/util/u_format.c | 41 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format.h | 11 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c index a8aa5719d39..9ef3bb53ff2 100644 --- a/src/gallium/auxiliary/util/u_format.c +++ b/src/gallium/auxiliary/util/u_format.c @@ -208,6 +208,47 @@ util_format_is_supported(enum pipe_format format, unsigned bind) } +/** + * Calculates the MRD for the depth format. MRD is used in depth bias + * for UNORM and unbound depth buffers. When the depth buffer is floating + * point, the depth bias calculation does not use the MRD. However, the + * default MRD will be 1.0 / ((1 << 24) - 1). + */ +double +util_get_depth_format_mrd(enum pipe_format format) +{ + struct util_format_description *format_desc; + /* + * Depth buffer formats without a depth component OR scenarios + * without a bound depth buffer default to D24. + */ + double mrd = 1.0 / ((1 << 24) - 1); + unsigned depth_channel; + + format_desc = (struct util_format_description *) + util_format_description(format); + + assert(format_desc); + + /* + * Some depth formats do not store the depth component in the first + * channel, detect the format and adjust the depth channel. Get the + * swizzled depth component channel. + */ + depth_channel = format_desc->swizzle[0]; + + if (format_desc->channel[depth_channel].type == UTIL_FORMAT_TYPE_UNSIGNED && + format_desc->channel[depth_channel].normalized) { + int depth_bits; + + depth_bits = format_desc->channel[depth_channel].size; + mrd = 1.0 / ((1ULL << depth_bits) - 1); + } + + return mrd; +} + + void util_format_read_4f(enum pipe_format format, float *dst, unsigned dst_stride, diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 84f16d503d7..dc777c35c19 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -544,6 +544,17 @@ util_format_is_depth_and_stencil(enum pipe_format format) util_format_has_stencil(desc); } + +/** + * Calculates the MRD for the depth format. MRD is used in depth bias + * for UNORM and unbound depth buffers. When the depth buffer is floating + * point, the depth bias calculation does not use the MRD. However, the + * default MRD will be 1.0 / ((1 << 24) - 1). + */ +double +util_get_depth_format_mrd(enum pipe_format format); + + /** * Return whether this is an RGBA, Z, S, or combined ZS format. * Useful for initializing pipe_blit_info::mask. |