static void
vc5_set_blend_color(struct pipe_context *pctx,
                    const struct pipe_blend_color *blend_color)
{
        struct vc5_context *vc5 = vc5_context(pctx);
        vc5->blend_color.f = *blend_color;
        for (int i = 0; i < 4; i++) {
                vc5->blend_color.hf[i] =
                        util_float_to_half(blend_color->color[i]);
        }
        vc5->dirty |= VC5_DIRTY_BLEND_COLOR;
}
Exemple #2
0
/* helper for setting up border-color buffer for a3xx/a4xx: */
void
fd_setup_border_colors(struct fd_texture_stateobj *tex, void *ptr,
		unsigned offset)
{
	unsigned i, j;

	for (i = 0; i < tex->num_samplers; i++) {
		struct pipe_sampler_state *sampler = tex->samplers[i];
		uint16_t *bcolor = (uint16_t *)((uint8_t *)ptr +
				(BORDERCOLOR_SIZE * offset) +
				(BORDERCOLOR_SIZE * i));
		uint32_t *bcolor32 = (uint32_t *)&bcolor[16];

		if (!sampler)
			continue;

		/*
		 * XXX HACK ALERT XXX
		 *
		 * The border colors need to be swizzled in a particular
		 * format-dependent order. Even though samplers don't know about
		 * formats, we can assume that with a GL state tracker, there's a
		 * 1:1 correspondence between sampler and texture. Take advantage
		 * of that knowledge.
		 */
		if (i < tex->num_textures && tex->textures[i]) {
			const struct util_format_description *desc =
					util_format_description(tex->textures[i]->format);
			for (j = 0; j < 4; j++) {
				if (desc->swizzle[j] >= 4)
					continue;

				const struct util_format_channel_description *chan =
					&desc->channel[desc->swizzle[j]];
				if (chan->pure_integer) {
					bcolor32[desc->swizzle[j] + 4] = sampler->border_color.i[j];
					bcolor[desc->swizzle[j] + 8] = sampler->border_color.i[j];
				} else {
					bcolor32[desc->swizzle[j]] = fui(sampler->border_color.f[j]);
					bcolor[desc->swizzle[j]] =
						util_float_to_half(sampler->border_color.f[j]);
				}
			}
		}
	}
}
Exemple #3
0
int main(int argc, char** argv)
{
   struct translate *(*create_fn)(const struct translate_key *key) = 0;

   struct translate_key key;
   unsigned output_format;
   unsigned input_format;
   unsigned buffer_size = 4096;
   unsigned char* buffer[5];
   unsigned char* byte_buffer;
   float* float_buffer;
   double* double_buffer;
   uint16_t *half_buffer;
   unsigned * elts;
   unsigned count = 4;
   unsigned i, j, k;
   unsigned passed = 0;
   unsigned total = 0;
   const float error = 0.03125;

   create_fn = 0;

   util_cpu_detect();

   if(argc <= 1)
   {}
   else if (!strcmp(argv[1], "generic"))
      create_fn = translate_generic_create;
   else if (!strcmp(argv[1], "x86"))
      create_fn = translate_sse2_create;
   else if (!strcmp(argv[1], "nosse"))
   {
      util_cpu_caps.has_sse = 0;
      util_cpu_caps.has_sse2 = 0;
      util_cpu_caps.has_sse3 = 0;
      util_cpu_caps.has_sse4_1 = 0;
      create_fn = translate_sse2_create;
   }
   else if (!strcmp(argv[1], "sse"))
   {
      if(!util_cpu_caps.has_sse || !rtasm_cpu_has_sse())
      {
         printf("Error: CPU doesn't support SSE (test with qemu)\n");
         return 2;
      }
      util_cpu_caps.has_sse2 = 0;
      util_cpu_caps.has_sse3 = 0;
      util_cpu_caps.has_sse4_1 = 0;
      create_fn = translate_sse2_create;
   }
   else if (!strcmp(argv[1], "sse2"))
   {
      if(!util_cpu_caps.has_sse2 || !rtasm_cpu_has_sse())
      {
         printf("Error: CPU doesn't support SSE2 (test with qemu)\n");
         return 2;
      }
      util_cpu_caps.has_sse3 = 0;
      util_cpu_caps.has_sse4_1 = 0;
      create_fn = translate_sse2_create;
   }
   else if (!strcmp(argv[1], "sse3"))
   {
      if(!util_cpu_caps.has_sse3 || !rtasm_cpu_has_sse())
      {
         printf("Error: CPU doesn't support SSE3 (test with qemu)\n");
         return 2;
      }
      util_cpu_caps.has_sse4_1 = 0;
      create_fn = translate_sse2_create;
   }
   else if (!strcmp(argv[1], "sse4.1"))
   {
      if(!util_cpu_caps.has_sse4_1 || !rtasm_cpu_has_sse())
      {
         printf("Error: CPU doesn't support SSE4.1 (test with qemu)\n");
         return 2;
      }
      create_fn = translate_sse2_create;
   }

   if (!create_fn)
   {
      printf("Usage: ./translate_test [generic|x86|nosse|sse|sse2|sse3|sse4.1]\n");
      return 2;
   }

   for (i = 1; i < Elements(buffer); ++i)
      buffer[i] = align_malloc(buffer_size, 4096);

   byte_buffer = align_malloc(buffer_size, 4096);
   float_buffer = align_malloc(buffer_size, 4096);
   double_buffer = align_malloc(buffer_size, 4096);
   half_buffer = align_malloc(buffer_size, 4096);

   elts = align_malloc(count * sizeof *elts, 4096);

   key.nr_elements = 1;
   key.element[0].input_buffer = 0;
   key.element[0].input_offset = 0;
   key.element[0].output_offset = 0;
   key.element[0].type = TRANSLATE_ELEMENT_NORMAL;
   key.element[0].instance_divisor = 0;

   srand(4359025);

   /* avoid negative values that work badly when converted to unsigned format*/
   for (i = 0; i < buffer_size; ++i)
      byte_buffer[i] = rand() & 0x7f7f7f7f;

   for (i = 0; i < buffer_size / sizeof(float); ++i)
      float_buffer[i] = (float)rand_double();

   for (i = 0; i < buffer_size / sizeof(double); ++i)
      double_buffer[i] = rand_double();

   for (i = 0; i < buffer_size / sizeof(double); ++i)
      half_buffer[i] = util_float_to_half((float) rand_double());

   for (i = 0; i < count; ++i)
      elts[i] = i;

   for (output_format = 1; output_format < PIPE_FORMAT_COUNT; ++output_format)
   {
      const struct util_format_description* output_format_desc = util_format_description(output_format);
      unsigned output_format_size;
      unsigned output_normalized = 0;

      if (!output_format_desc
            || !output_format_desc->fetch_rgba_float
            || !output_format_desc->pack_rgba_float
            || output_format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB
            || output_format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN
            || !translate_is_output_format_supported(output_format))
         continue;

      for(i = 0; i < output_format_desc->nr_channels; ++i)
      {
         if(output_format_desc->channel[i].type != UTIL_FORMAT_TYPE_FLOAT)
            output_normalized |= (1 << output_format_desc->channel[i].normalized);
      }

      output_format_size = util_format_get_stride(output_format, 1);

      for (input_format = 1; input_format < PIPE_FORMAT_COUNT; ++input_format)
      {
         const struct util_format_description* input_format_desc = util_format_description(input_format);
         unsigned input_format_size;
         struct translate* translate[2];
         unsigned fail = 0;
         unsigned used_generic = 0;
         unsigned input_normalized = 0;
         boolean input_is_float = FALSE;

         if (!input_format_desc
               || !input_format_desc->fetch_rgba_float
               || !input_format_desc->pack_rgba_float
               || input_format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB
               || input_format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN
               || !translate_is_output_format_supported(input_format))
            continue;

         input_format_size = util_format_get_stride(input_format, 1);

         for(i = 0; i < input_format_desc->nr_channels; ++i)
         {
            if(input_format_desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT)
            {
               input_is_float = 1;
               input_normalized |= 1 << 1;
            }
            else
               input_normalized |= (1 << input_format_desc->channel[i].normalized);
         }

         if(((input_normalized | output_normalized) == 3)
               || ((input_normalized & 1) && (output_normalized & 1)
                     && input_format_size * output_format_desc->nr_channels > output_format_size * input_format_desc->nr_channels))
            continue;

         key.element[0].input_format = input_format;
         key.element[0].output_format = output_format;
         key.output_stride = output_format_size;
         translate[0] = create_fn(&key);
         if (!translate[0])
            continue;

         key.element[0].input_format = output_format;
         key.element[0].output_format = input_format;
         key.output_stride = input_format_size;
         translate[1] = create_fn(&key);
         if(!translate[1])
         {
            used_generic = 1;
            translate[1] = translate_generic_create(&key);
            if(!translate[1])
               continue;
         }

         for(i = 1; i < 5; ++i)
            memset(buffer[i], 0xcd - (0x22 * i), 4096);

         if(input_is_float && input_format_desc->channel[0].size == 32)
            buffer[0] = (unsigned char*)float_buffer;
         else if(input_is_float && input_format_desc->channel[0].size == 64)
            buffer[0] = (unsigned char*)double_buffer;
         else if(input_is_float && input_format_desc->channel[0].size == 16)
            buffer[0] = (unsigned char*)half_buffer;
         else if(input_is_float)
            abort();
         else
            buffer[0] = byte_buffer;

         translate[0]->set_buffer(translate[0], 0, buffer[0], input_format_size, count - 1);
         translate[0]->run_elts(translate[0], elts, count, 0, 0, buffer[1]);
         translate[1]->set_buffer(translate[1], 0, buffer[1], output_format_size, count - 1);
         translate[1]->run_elts(translate[1], elts, count, 0, 0, buffer[2]);
         translate[0]->set_buffer(translate[0], 0, buffer[2], input_format_size, count - 1);
         translate[0]->run_elts(translate[0], elts, count, 0, 0, buffer[3]);
         translate[1]->set_buffer(translate[1], 0, buffer[3], output_format_size, count - 1);
         translate[1]->run_elts(translate[1], elts, count, 0, 0, buffer[4]);

         for (i = 0; i < count; ++i)
         {
            float a[4];
            float b[4];
            input_format_desc->fetch_rgba_float(a, buffer[2] + i * input_format_size, 0, 0);
            input_format_desc->fetch_rgba_float(b, buffer[4] + i * input_format_size, 0, 0);

            for (j = 0; j < count; ++j)
            {
               float d = a[j] - b[j];
               if (d > error || d < -error)
               {
                  fail = 1;
                  break;
               }
            }
         }

         printf("%s%s: %s -> %s -> %s -> %s -> %s\n",
               fail ? "FAIL" : "PASS",
               used_generic ? "[GENERIC]" : "",
               input_format_desc->name, output_format_desc->name, input_format_desc->name, output_format_desc->name, input_format_desc->name);

         if (1)
         {
            for (i = 0; i < Elements(buffer); ++i)
            {
               unsigned format_size = (i & 1) ? output_format_size : input_format_size;
               printf("%c ", (i == 2 || i == 4) ? '*' : ' ');
               for (j = 0; j < count; ++j)
               {
                  for (k = 0; k < format_size; ++k)
                  {
                     printf("%02x", buffer[i][j * format_size + k]);
                  }
                  printf(" ");
               }
               printf("\n");
            }
         }

         if (!fail)
            ++passed;
         ++total;

         if(translate[1])
            translate[1]->release(translate[1]);
         translate[0]->release(translate[0]);
      }
   }

   printf("%u/%u tests passed for translate_%s\n", passed, total, argv[1]);
   return passed != total;
}
Exemple #4
0
bool radv_format_pack_clear_color(VkFormat format,
				  uint32_t clear_vals[2],
				  VkClearColorValue *value)
{
	uint8_t r = 0, g = 0, b = 0, a = 0;
	const struct vk_format_description *desc = vk_format_description(format);

	if (vk_format_get_component_bits(format, VK_FORMAT_COLORSPACE_RGB, 0) <= 8) {
		if (desc->colorspace == VK_FORMAT_COLORSPACE_RGB) {
			r = float_to_ubyte(value->float32[0]);
			g = float_to_ubyte(value->float32[1]);
			b = float_to_ubyte(value->float32[2]);
			a = float_to_ubyte(value->float32[3]);
		} else if (desc->colorspace == VK_FORMAT_COLORSPACE_SRGB) {
			r = util_format_linear_float_to_srgb_8unorm(value->float32[0]);
			g = util_format_linear_float_to_srgb_8unorm(value->float32[1]);
			b = util_format_linear_float_to_srgb_8unorm(value->float32[2]);
			a = float_to_ubyte(value->float32[3]);
		}
	}
	switch (format) {
	case VK_FORMAT_R8_UNORM:
	case VK_FORMAT_R8_SRGB:
		clear_vals[0] = r;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R8G8_UNORM:
	case VK_FORMAT_R8G8_SRGB:
		clear_vals[0] = r | g << 8;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R8G8B8A8_SRGB:
	case VK_FORMAT_R8G8B8A8_UNORM:
		clear_vals[0] = r | g << 8 | b << 16 | a << 24;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_B8G8R8A8_SRGB:
	case VK_FORMAT_B8G8R8A8_UNORM:
		clear_vals[0] = b | g << 8 | r << 16 | a << 24;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
	case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
		clear_vals[0] = r | g << 8 | b << 16 | a << 24;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R8_UINT:
		clear_vals[0] = value->uint32[0] & 0xff;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R16_UINT:
		clear_vals[0] = value->uint32[0] & 0xffff;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R8G8_UINT:
		clear_vals[0] = value->uint32[0] & 0xff;
		clear_vals[0] |= (value->uint32[1] & 0xff) << 8;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R8G8B8A8_UINT:
		clear_vals[0] = value->uint32[0] & 0xff;
		clear_vals[0] |= (value->uint32[1] & 0xff) << 8;
		clear_vals[0] |= (value->uint32[2] & 0xff) << 16;
		clear_vals[0] |= (value->uint32[3] & 0xff) << 24;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_A8B8G8R8_UINT_PACK32:
		clear_vals[0] = value->uint32[0] & 0xff;
		clear_vals[0] |= (value->uint32[1] & 0xff) << 8;
		clear_vals[0] |= (value->uint32[2] & 0xff) << 16;
		clear_vals[0] |= (value->uint32[3] & 0xff) << 24;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R16G16_UINT:
		clear_vals[0] = value->uint32[0] & 0xffff;
		clear_vals[0] |= (value->uint32[1] & 0xffff) << 16;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R16G16B16A16_UINT:
		clear_vals[0] = value->uint32[0] & 0xffff;
		clear_vals[0] |= (value->uint32[1] & 0xffff) << 16;
		clear_vals[1] = value->uint32[2] & 0xffff;
		clear_vals[1] |= (value->uint32[3] & 0xffff) << 16;
		break;
	case VK_FORMAT_R32_UINT:
		clear_vals[0] = value->uint32[0];
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R32G32_UINT:
		clear_vals[0] = value->uint32[0];
		clear_vals[1] = value->uint32[1];
		break;
	case VK_FORMAT_R32_SINT:
		clear_vals[0] = value->int32[0];
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R16_SFLOAT:
		clear_vals[0] = util_float_to_half(value->float32[0]);
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R16G16_SFLOAT:
		clear_vals[0] = util_float_to_half(value->float32[0]);
		clear_vals[0] |= (uint32_t)util_float_to_half(value->float32[1]) << 16;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R16G16B16A16_SFLOAT:
		clear_vals[0] = util_float_to_half(value->float32[0]);
		clear_vals[0] |= (uint32_t)util_float_to_half(value->float32[1]) << 16;
		clear_vals[1] = util_float_to_half(value->float32[2]);
		clear_vals[1] |= (uint32_t)util_float_to_half(value->float32[3]) << 16;
		break;
	case VK_FORMAT_R16_UNORM:
		clear_vals[0] = ((uint16_t)util_iround(CLAMP(value->float32[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R16G16_UNORM:
		clear_vals[0] = ((uint16_t)util_iround(CLAMP(value->float32[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
		clear_vals[0] |= ((uint16_t)util_iround(CLAMP(value->float32[1], 0.0f, 1.0f) * 0xffff)) << 16;
		clear_vals[1] = 0;
		break;
	case VK_FORMAT_R16G16B16A16_UNORM:
		clear_vals[0] = ((uint16_t)util_iround(CLAMP(value->float32[0], 0.0f, 1.0f) * 0xffff)) & 0xffff;
		clear_vals[0] |= ((uint16_t)util_iround(CLAMP(value->float32[1], 0.0f, 1.0f) * 0xffff)) << 16;
		clear_vals[1] = ((uint16_t)util_iround(CLAMP(value->float32[2], 0.0f, 1.0f) * 0xffff)) & 0xffff;
		clear_vals[1] |= ((uint16_t)util_iround(CLAMP(value->float32[3], 0.0f, 1.0f) * 0xffff)) << 16;
		break;
	case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
		/* TODO */
		return false;
	case VK_FORMAT_R32G32_SFLOAT:
		clear_vals[0] = fui(value->float32[0]);
		clear_vals[1] = fui(value->float32[1]);
		break;
	case VK_FORMAT_R32_SFLOAT:
		clear_vals[1] = 0;
		clear_vals[0] = fui(value->float32[0]);
		break;
	default:
		fprintf(stderr, "failed to fast clear %d\n", format);
		return false;
	}
	return true;
}