void
util_format_r8g8_b8g8_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride,
                                         const uint8_t *src_row, unsigned src_stride,
                                         unsigned width, unsigned height)
{
   unsigned x, y;

   for (y = 0; y < height; y += 1) {
      float *dst = dst_row;
      const uint32_t *src = (const uint32_t *)src_row;
      uint32_t value;
      float r, g0, g1, b;

      for (x = 0; x + 1 < width; x += 2) {
         value = util_cpu_to_le32(*src++);

         r  = ubyte_to_float((value >>  0) & 0xff);
         g0 = ubyte_to_float((value >>  8) & 0xff);
         b  = ubyte_to_float((value >> 16) & 0xff);
         g1 = ubyte_to_float((value >> 24) & 0xff);

         dst[0] = r;    /* r */
         dst[1] = g0;   /* g */
         dst[2] = b;    /* b */
         dst[3] = 1.0f; /* a */
         dst += 4;

         dst[0] = r;    /* r */
         dst[1] = g1;   /* g */
         dst[2] = b;    /* b */
         dst[3] = 1.0f; /* a */
         dst += 4;
      }

      if (x < width) {
         value = util_cpu_to_le32(*src);

         r  = ubyte_to_float((value >>  0) & 0xff);
         g0 = ubyte_to_float((value >>  8) & 0xff);
         b  = ubyte_to_float((value >> 16) & 0xff);
         g1 = ubyte_to_float((value >> 24) & 0xff);

         dst[0] = r;    /* r */
         dst[1] = g0;   /* g */
         dst[2] = b;    /* b */
         dst[3] = 1.0f; /* a */
      }

      src_row += src_stride/sizeof(*src_row);
      dst_row += dst_stride/sizeof(*dst_row);
   }
Ejemplo n.º 2
0
static void evergreen_set_global_binding(struct pipe_context *ctx,
					 unsigned first, unsigned n,
					 struct pipe_resource **resources,
					 uint32_t **handles)
{
	struct r600_context *rctx = (struct r600_context *)ctx;
	struct compute_memory_pool *pool = rctx->screen->global_pool;
	struct r600_resource_global **buffers =
		(struct r600_resource_global **)resources;
	unsigned i;

	COMPUTE_DBG(rctx->screen, "*** evergreen_set_global_binding first = %u n = %u\n",
			first, n);

	if (!resources) {
		/* XXX: Unset */
		return;
	}

	/* We mark these items for promotion to the pool if they
	 * aren't already there */
	for (i = first; i < first + n; i++) {
		struct compute_memory_item *item = buffers[i]->chunk;

		if (!is_item_in_pool(item))
			buffers[i]->chunk->status |= ITEM_FOR_PROMOTING;
	}

	if (compute_memory_finalize_pending(pool, ctx) == -1) {
		/* XXX: Unset */
		return;
	}

	for (i = first; i < first + n; i++)
	{
		uint32_t buffer_offset;
		uint32_t handle;
		assert(resources[i]->target == PIPE_BUFFER);
		assert(resources[i]->bind & PIPE_BIND_GLOBAL);

		buffer_offset = util_le32_to_cpu(*(handles[i]));
		handle = buffer_offset + buffers[i]->chunk->start_in_dw * 4;

		*(handles[i]) = util_cpu_to_le32(handle);
	}

	/* globals for writing */
	evergreen_set_rat(rctx->cs_shader_state.shader, 0, pool->bo, 0, pool->size_in_dw * 4);
	/* globals for reading */
	evergreen_cs_set_vertex_buffer(rctx, 1, 0,
				(struct pipe_resource*)pool->bo);

	/* constants for reading, LLVM puts them in text segment */
	evergreen_cs_set_vertex_buffer(rctx, 2, 0,
				(struct pipe_resource*)rctx->cs_shader_state.shader->code_bo);
}