Exemple #1
0
void
batch_draw_elements(GLenum mode, GLsizei count, const unsigned int *indices) {
    unsigned int i;
    if(count > BATCH_VERTS) {
        fprintf(stderr, "count: %d > BATCH_VERTS: %d", count, BATCH_VERTS);
        return;
    }
    if(batch.mode != mode || batch.array.count + count > BATCH_VERTS) {
        batch_flush();
        batch.mode = mode;
    }
    for(i = 0; i < count; ++i)
        batch.array.vertices[batch.array.count + i]
            = TFORMVEC2(batch.tform, batch.vertices[indices[i]]);
    if(batch.colors)
        for(i = 0; i < count; ++i)
            batch.array.colors[batch.array.count + i]
                = batch.colors[indices[i]];
    else
        for(i = 0; i < count; ++i)
            batch.array.colors[batch.array.count + i] = batch.color;
    if(batch.texcoords)
        for(i = 0; i < count; ++i)
            batch.array.texcoords[batch.array.count + i]
                = batch.texcoords[indices[i]];

    batch.array.count += count;
}
Exemple #2
0
void
batch_draw_arrays(GLenum mode, GLint first, GLsizei count) {
    unsigned int i;
    if(count > BATCH_VERTS) {
        fprintf(stderr, "count: %d > BATCH_VERTS: %d", count, BATCH_VERTS);
        return;
    }
    if(batch.mode != mode || batch.array.count + count > BATCH_VERTS) {
        batch_flush();
        batch.mode = mode;
    }
    for(i = 0; i < count; ++i)
        batch.array.vertices[batch.array.count + i]
            = TFORMVEC2(batch.tform, batch.vertices[first + i]);
    if(batch.colors)
        memcpy(batch.array.colors + batch.array.count,
               batch.colors + first,
               sizeof(*batch.colors) * count);
    else
        for(i = 0; i < count; ++i)
            batch.array.colors[batch.array.count + i] = batch.color;
    if(batch.texcoords)
        memcpy(batch.array.texcoords + batch.array.count,
               batch.texcoords + first,
               sizeof(*batch.texcoords) * count);

    batch.array.count += count;
}
Exemple #3
0
void
batch_bind_texture(GLuint texture) {
    if(batch.activetex == texture)
        return;

    batch_flush();
    glBindTexture(GL_TEXTURE_2D, texture);
    batch.activetex = texture;
}
static int
batch_reserve(struct intel_info *info, int count)
{
	int ret = 0;

	if (batch_count(info) + count > info->capacity)
		ret = batch_flush(info);

	return ret;
}
static void intel_blit(struct gralloc_drm_drv_t *drv,
		struct gralloc_drm_bo_t *dst,
		struct gralloc_drm_bo_t *src,
		uint16_t dst_x1, uint16_t dst_y1,
		uint16_t dst_x2, uint16_t dst_y2,
		uint16_t src_x1, uint16_t src_y1,
		uint16_t src_x2, uint16_t src_y2)
{
	struct intel_info *info = (struct intel_info *) drv;
	struct intel_buffer *dst_ib = (struct intel_buffer *) dst;
	struct intel_buffer *src_ib = (struct intel_buffer *) src;
	drm_intel_bo *bo_table[3];
	uint32_t cmd, br13, dst_pitch, src_pitch;

	/*
	 * XY_SRC_COPY_BLT_CMD does not support scaling,
	 * rectangle dimensions much match
	 */
	if (src_x2 - src_x1 != dst_x2 - dst_x1 ||
		src_y2 - src_y1 != dst_y2 - dst_y1) {
		ALOGE("%s, src and dst rect must match", __func__);
		return;
	}

	if (dst->handle->format != src->handle->format) {
		ALOGE("%s, src and dst format must match", __func__);
		return;
	}

	/* nothing to blit */
	if (src_x2 <= src_x1 || src_y2 <= src_y1)
		return;

	/* clamp x2, y2 to surface size */
	if (src_x2 > src->handle->width)
		src_x2 = src->handle->width;
	if (src_y2 > src->handle->height)
		src_y2 = src->handle->height;

	if (dst_x2 > dst->handle->width)
		dst_x2 = dst->handle->width;
	if (dst_y2 > dst->handle->height)
		dst_y2 = dst->handle->height;

	bo_table[0] = info->batch_ibo;
	bo_table[1] = src_ib->ibo;
	bo_table[2] = dst_ib->ibo;
	if (drm_intel_bufmgr_check_aperture_space(bo_table, 3)) {
		if (batch_flush(info))
			return;
		assert(!drm_intel_bufmgr_check_aperture_space(bo_table, 3));
	}

	cmd = XY_SRC_COPY_BLT_CMD;
	br13 = 0xcc << 16; /* ROP_S/GXcopy */
	dst_pitch = dst->handle->stride;
	src_pitch = src->handle->stride;

	/* Blit pitch must be dword-aligned.  Otherwise, the hardware appears to
	 * drop the low bits.
	 */
	if (src_pitch % 4 != 0 || dst_pitch % 4 != 0) {
		ALOGE("%s, src and dst pitch must be dword aligned", __func__);
		return;
	}

	switch (gralloc_drm_get_bpp(dst->handle->format)) {
	case 1:
		break;
	case 2:
		br13 |= (1 << 24);
		break;
	case 4:
		br13 |= (1 << 24) | (1 << 25);
		cmd |= XY_SRC_COPY_BLT_WRITE_ALPHA | XY_SRC_COPY_BLT_WRITE_RGB;
		break;
	default:
		ALOGE("%s, copy with unsupported format", __func__);
		return;
	}

	if (info->gen >= 40) {
		if (dst_ib->tiling != I915_TILING_NONE) {
			assert(dst_pitch % 512 == 0);
			dst_pitch >>= 2;
			cmd |= XY_SRC_COPY_BLT_DST_TILED;
		}
		if (src_ib->tiling != I915_TILING_NONE) {
			assert(src_pitch % 512 == 0);
			src_pitch >>= 2;
			cmd |= XY_SRC_COPY_BLT_SRC_TILED;
		}
Exemple #6
0
/* Gather or scatter the global base array between processes.
 * NB: this is a collective operation.
 *
 * @scatter If true we scatter else we gather
 * @global_ary Global base array
 */
static void comm_gather_scatter(int scatter, bh_base *global_ary)
{
    bh_error err;
    bh_base *local_ary = array_get_local(global_ary);
    bh_intp totalsize = global_ary->nelem;

    if(totalsize <= 0)
        return;

    //Find the local size for all processes
    int sendcnts[pgrid_worldsize], displs[pgrid_worldsize];
    {
        bh_intp s = totalsize / pgrid_worldsize;//local size for all but the last process
        s *= bh_type_size(global_ary->type);
        for(int i=0; i<pgrid_worldsize; ++i)
        {
            sendcnts[i] = s;
            displs[i] = s * i;
        }
        //The last process gets the rest
        sendcnts[pgrid_worldsize-1] += totalsize % pgrid_worldsize * bh_type_size(global_ary->type);
    }

    int e;
    if(scatter)
    {
        //The slave-processes may need to allocate memory
        if(sendcnts[pgrid_myrank] > 0 && local_ary->data == NULL)
        {
            if((err = bh_data_malloc(local_ary)) != BH_SUCCESS)
                EXCEPT_OUT_OF_MEMORY();
        }
        //The master-process MUST have allocated memory already
        assert(pgrid_myrank != 0 || global_ary->data != NULL);

        //Scatter from master to slaves
        e = MPI_Scatterv(global_ary->data, sendcnts, displs, MPI_BYTE,
                         local_ary->data, sendcnts[pgrid_myrank], MPI_BYTE,
                         0, MPI_COMM_WORLD);
    }
    else
    {
        //Lets make sure that the 'local_ary' is updated
        batch_schedule_inst_on_base(BH_SYNC, local_ary);
        batch_flush();

        //The master-processes may need to allocate memory
        if(pgrid_myrank == 0 && global_ary->data == NULL)
        {
            if((err = bh_data_malloc(global_ary)) != BH_SUCCESS)
                EXCEPT_OUT_OF_MEMORY();
        }

        //We will always allocate the local array when gathering because
        //only the last process knows if the array has been initiated.
        if((err = bh_data_malloc(local_ary)) != BH_SUCCESS)
            EXCEPT_OUT_OF_MEMORY();

        assert(sendcnts[pgrid_myrank] == 0 || local_ary->data != NULL);

        //Gather from the slaves to the master
        e = MPI_Gatherv(local_ary->data, sendcnts[pgrid_myrank], MPI_BYTE,
                        global_ary->data, sendcnts, displs, MPI_BYTE,
                        0, MPI_COMM_WORLD);
    }
    if(e != MPI_SUCCESS)
        EXCEPT_MPI(e);
}
Exemple #7
0
/* Gather the global base array data at the master processes.
 * NB: this is a collective operation.
 *
 * @global_ary Global base array
 */
void comm_slaves2master(bh_base *global_ary)
{
    batch_flush();
    comm_gather_scatter(0, global_ary);
}
Exemple #8
0
/* Distribute the global base array data to all slave processes.
 * The master-process MUST have allocated the @global_ary data.
 * NB: this is a collective operation.
 *
 * @global_ary Global base array
 */
void comm_master2slaves(bh_base *global_ary)
{
    batch_flush();
    comm_gather_scatter(1, global_ary);
}
Exemple #9
0
void
endscene(void) {
    batch_flush();
    glFlush();
    SDL_GL_SwapBuffers();
}