void util_format_r9g9b9e5_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height) { unsigned x, y; float p[3]; for(y = 0; y < height; y += 1) { const uint8_t *src = src_row; uint8_t *dst = dst_row; for(x = 0; x < width; x += 1) { uint32_t value; p[0] = ubyte_to_float(src[0]); p[1] = ubyte_to_float(src[1]); p[2] = ubyte_to_float(src[2]); value = float3_to_rgb9e5(p); #ifdef PIPE_ARCH_BIG_ENDIAN value = util_bswap32(value); #endif *(uint32_t *)dst = value; src += 4; dst += 4; } dst_row += dst_stride; src_row += src_stride/sizeof(*src_row); } }
void blorp_clear(struct blorp_batch *batch, const struct blorp_surf *surf, enum isl_format format, struct isl_swizzle swizzle, uint32_t level, uint32_t start_layer, uint32_t num_layers, uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, union isl_color_value clear_color, const bool color_write_disable[4]) { struct blorp_params params; blorp_params_init(¶ms); params.x0 = x0; params.y0 = y0; params.x1 = x1; params.y1 = y1; if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) { clear_color.u32[0] = float3_to_rgb9e5(clear_color.f32); format = ISL_FORMAT_R32_UINT; } memcpy(¶ms.wm_inputs, clear_color.f32, sizeof(float) * 4); bool use_simd16_replicated_data = true; /* From the SNB PRM (Vol4_Part1): * * "Replicated data (Message Type = 111) is only supported when * accessing tiled memory. Using this Message Type to access linear * (untiled) memory is UNDEFINED." */ if (surf->surf->tiling == ISL_TILING_LINEAR) use_simd16_replicated_data = false; /* Constant color writes ignore everyting in blend and color calculator * state. This is not documented. */ if (color_write_disable) { for (unsigned i = 0; i < 4; i++) { params.color_write_disable[i] = color_write_disable[i]; if (color_write_disable[i]) use_simd16_replicated_data = false; } } blorp_params_get_clear_kernel(batch->blorp, ¶ms, use_simd16_replicated_data); while (num_layers > 0) { brw_blorp_surface_info_init(batch->blorp, ¶ms.dst, surf, level, start_layer, format, true); params.dst.view.swizzle = swizzle; /* We may be restricted on the number of layers we can bind at any one * time. In particular, Sandy Bridge has a maximum number of layers of * 512 but a maximum 3D texture size is much larger. */ params.num_layers = MIN2(params.dst.view.array_len, num_layers); batch->blorp->exec(batch, ¶ms); start_layer += params.num_layers; num_layers -= params.num_layers; } }
// Create an image buffer and fill it so that a single image channel is // the max value (1.0) while the other channels are zero. For example, // if fillComponent==2 and we're filling a four-component image, the // pixels will be (0, 0, max, 0). // // We always leave the upper-right quadrant black/zero. This is to help // detect any image conversion issues related to stride, packing, etc. static GLubyte * MakeImage(int width, int height, GLenum format, GLenum type, int fillComponent) { assert(fillComponent < 4); if (type == GL_UNSIGNED_INT_5_9_9_9_REV) { GLubyte *image = new GLubyte [width * height * 4]; int i; assert(format == GL_RGB); GLuint *ui = (GLuint *) image; for (i = 0; i < width * height; i++) { float p[3] = {0, 0, 0}; if (!IsUpperRight(i, width, height)) p[fillComponent] = 1; ui[i] = float3_to_rgb9e5(p); } return image; } else if (IsPackedType(type)) { const int bpp = SizeofType(type); GLubyte *image = new GLubyte [width * height * bpp]; GLuint masks[4]; int pos[4]; int i; ComponentMasks(type, masks); ComponentPositions(format, pos); const GLuint value = masks[fillComponent]; switch (bpp) { case 1: for (i = 0; i < width * height; i++) { if (IsUpperRight(i, width, height)) image[i] = 0; else image[i] = (GLubyte) value; } break; case 2: { GLushort *image16 = (GLushort *) image; for (i = 0; i < width * height; i++) { if (IsUpperRight(i, width, height)) image16[i] = 0; else image16[i] = (GLushort) value; } } break; case 4: { GLuint *image32 = (GLuint *) image; for (i = 0; i < width * height; i++) { if (IsUpperRight(i, width, height)) image32[i] = 0; else image32[i] = (GLuint) value; } } break; default: abort(); } return image; } else { const int comps = NumberOfComponentsInFormat(format); const int bpp = comps * SizeofType(type); assert(bpp > 0); GLubyte *image = new GLubyte [width * height * bpp]; int i; switch (type) { case GL_UNSIGNED_BYTE: for (i = 0; i < width * height * comps; i++) { if (i % comps == fillComponent && !IsUpperRight(i/comps, width, height)) image[i] = 0xff; else image[i] = 0x0; } break; case GL_BYTE: { GLbyte *b = (GLbyte *) image; for (i = 0; i < width * height * comps; i++) { if (i % comps == fillComponent && !IsUpperRight(i/comps, width, height)) b[i] = 0x7f; else b[i] = 0x0; } } break; case GL_UNSIGNED_SHORT: { GLushort *us = (GLushort *) image; for (i = 0; i < width * height * comps; i++) { if (i % comps == fillComponent && !IsUpperRight(i/comps, width, height)) us[i] = 0xffff; else us[i] = 0x0; } } break; case GL_SHORT: { GLshort *s = (GLshort *) image; for (i = 0; i < width * height * comps; i++) { if (i % comps == fillComponent && !IsUpperRight(i/comps, width, height)) s[i] = 0x7fff; else s[i] = 0x0; } } break; case GL_UNSIGNED_INT: { GLuint *ui = (GLuint *) image; for (i = 0; i < width * height * comps; i++) { if (i % comps == fillComponent && !IsUpperRight(i/comps, width, height)) ui[i] = 0xffffffff; else ui[i] = 0x0; } } break; case GL_INT: { GLint *in = (GLint *) image; for (i = 0; i < width * height * comps; i++) { if (i % comps == fillComponent && !IsUpperRight(i/comps, width, height)) in[i] = 0x7fffffff; else in[i] = 0x0; } } break; case GL_FLOAT: { GLfloat *f = (GLfloat *) image; for (i = 0; i < width * height * comps; i++) { if (i % comps == fillComponent && !IsUpperRight(i/comps, width, height)) f[i] = 1.0; else f[i] = 0.0; } } break; case GL_HALF_FLOAT_ARB: { GLhalfARB *f = (GLhalfARB *) image; for (i = 0; i < width * height * comps; i++) { if (i % comps == fillComponent && !IsUpperRight(i/comps, width, height)) f[i] = 0x3c00; /* == 1.0 */ else f[i] = 0; } } break; default: abort(); } return image; } }