[Mesa-dev] [PATCH 4/5] i965: handle nir_intrinsic_image_size
Martin Peres
martin.peres at linux.intel.com
Tue Aug 11 09:43:31 PDT 2015
Signed-off-by: Martin Peres <martin.peres at linux.intel.com>
---
src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 51 ++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
index ce4153d..3d172ff 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
@@ -1406,6 +1406,57 @@ fs_visitor::nir_emit_intrinsic(const fs_builder &bld, nir_intrinsic_instr *instr
break;
}
+ case nir_intrinsic_image_size: {
+ bool isCubeMapImage = false, is1DArrayImage = false;
+
+ /* Get the referenced image variable and type. */
+ const nir_variable *var = instr->variables[0]->var;
+ const glsl_type *type = var->type->without_array();
+ const brw_reg_type base_type = get_image_base_type(type);
+
+ /* Get the size of the image. */
+ const fs_reg image = get_nir_image_deref(instr->variables[0]);
+ const fs_reg size = offset(image, bld, BRW_IMAGE_PARAM_SIZE_OFFSET);
+
+ /*
+ * For CubeMapArray images, we should count the number of cubes instead
+ * of the number of faces. Fix it by dividing the (Z component) by 6.
+ */
+ if (type == glsl_type::imageCubeArray_type ||
+ type == glsl_type::iimageCubeArray_type ||
+ type == glsl_type::uimageCubeArray_type) {
+ isCubeMapImage = true;
+ }
+
+ /*
+ * For 1DArray image types, the array index is stored in the Z component.
+ * Fix this by swizzling the Z component to the Y component.
+ */
+ if (type == glsl_type::image1DArray_type ||
+ type == glsl_type::iimage1DArray_type ||
+ type == glsl_type::uimage1DArray_type) {
+ is1DArrayImage = true;
+ }
+
+ /* Copy all the components. */
+ const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
+ for (unsigned c = 0; c < info->dest_components; ++c) {
+ if (c == 1 && is1DArrayImage) {
+ bld.MOV(offset(retype(dest, base_type), bld, c),
+ offset(size, bld, 2));
+ } else if (c == 2 && isCubeMapImage) {
+ bld.emit(SHADER_OPCODE_INT_QUOTIENT,
+ offset(retype(dest, base_type), bld, c),
+ offset(size, bld, c), fs_reg(6));
+ } else {
+ bld.MOV(offset(retype(dest, base_type), bld, c),
+ offset(size, bld, c));
+ }
+ }
+
+ break;
+ }
+
case nir_intrinsic_load_front_face:
bld.MOV(retype(dest, BRW_REGISTER_TYPE_D),
*emit_frontfacing_interpolation());
--
2.5.0
More information about the mesa-dev
mailing list