Пример #1
0
void *gpu_write_thread(void *data)
{
	workload_t *w = (workload_t *)data;
	struct limare_state *state;
	double t1, t2;
	int i = 0;
	int ret;
	int width, height;

	load_mali_kernel_module();

	state = limare_init();
	assert(state);

	ret = limare_state_setup(state, 0, 0, 0xFF505050);
	assert(ret == 0);

	limare_buffer_size(state, &width, &height);

	while (1) {
		state->clear_color = 0xFF000040 + abs((i++ * 1) %
				((255 - 0x40) * 2) - (255 - 0x40));
		limare_frame_new(state);
		ret = limare_frame_flush(state);
		assert(!ret);
		limare_buffer_swap(state);

		pthread_mutex_lock(&bandwidth_counters_mutex);
		w->bytes_counter += width * height * (state->fb->bpp / 8);
		pthread_mutex_unlock(&bandwidth_counters_mutex);
	}

	limare_finish(state);
	return 0;
}
Пример #2
0
int
main(int argc, char *argv[])
{
	struct limare_state *state;
	int ret;

	const char *vertex_shader_source =
		"uniform mat4 modelviewMatrix;\n"
		"uniform mat4 modelviewprojectionMatrix;\n"
		"uniform mat3 normalMatrix;\n"
		"\n"
		"attribute vec4 in_position;    \n"
		"attribute vec3 in_normal;      \n"
		"attribute vec2 in_coord;       \n"
		"\n"
		"vec4 lightSource = vec4(10.0, 20.0, 40.0, 0.0);\n"
		"                             \n"
		"varying vec4 vVaryingColor;  \n"
		"varying vec2 coord;          \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_Position = modelviewprojectionMatrix * in_position;\n"
		"    vec3 vEyeNormal = normalMatrix * in_normal;\n"
		"    vec4 vPosition4 = modelviewMatrix * in_position;\n"
		"    vec3 vPosition3 = vPosition4.xyz / vPosition4.w;\n"
		"    vec3 vLightDir = normalize(lightSource.xyz - vPosition3);\n"
		"    float diff = max(0.0, dot(vEyeNormal, vLightDir));\n"
		"    vVaryingColor = vec4(diff * vec3(1.0, 1.0, 1.0), 1.0);\n"
		"    coord = in_coord;        \n"
		"}                            \n";
	const char *fragment_shader_source =
		"precision mediump float;     \n"
		"                             \n"
		"varying vec4 vVaryingColor;  \n"
		"varying vec2 coord;          \n"
		"                             \n"
		"uniform sampler2D in_texture; \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_FragColor = vVaryingColor * texture2D(in_texture, coord);\n"
		"}                            \n";

	float *vertices_array = companion_vertices_array();
	float *texture_coordinates_array =
		companion_texture_coordinates_array();
	float *normals_array = companion_normals_array();

	state = limare_init();
	if (!state)
		return -1;

	limare_buffer_clear(state);

	ret = limare_state_setup(state, 0, 0, 0xFF505050);
	if (ret)
		return ret;

	int width, height;
	limare_buffer_size(state, &width, &height);
	float aspect = (float) height / width;

	limare_enable(state, GL_DEPTH_TEST);
	limare_enable(state, GL_CULL_FACE);
	limare_depth_mask(state, 1);

	int program = limare_program_new(state);
	vertex_shader_attach(state, program, vertex_shader_source);
	fragment_shader_attach(state, program, fragment_shader_source);

	limare_link(state);

	int vertices_buffer =
		limare_attribute_buffer_upload(state, LIMARE_ATTRIB_FLOAT,
					       3, 0, COMPANION_ARRAY_COUNT,
					       vertices_array);

	int texture_coordinates_buffer =
		limare_attribute_buffer_upload(state, LIMARE_ATTRIB_FLOAT,
					       2, 0, COMPANION_ARRAY_COUNT,
					       texture_coordinates_array);

	int normals_buffer =
		limare_attribute_buffer_upload(state, LIMARE_ATTRIB_FLOAT,
					       3, 0, COMPANION_ARRAY_COUNT,
					       normals_array);

	limare_attribute_buffer_attach(state, "in_position", vertices_buffer);
	limare_attribute_buffer_attach(state, "in_coord",
				       texture_coordinates_buffer);
	limare_attribute_buffer_attach(state, "in_normal", normals_buffer);

	int texture = limare_texture_upload(state, companion_texture,
					    COMPANION_TEXTURE_WIDTH,
					    COMPANION_TEXTURE_HEIGHT,
					    COMPANION_TEXTURE_FORMAT, 0);
	limare_texture_attach(state, "in_texture", texture);

	ESMatrix modelview;
	esMatrixLoadIdentity(&modelview);
	esTranslate(&modelview, 0.0, 0.0, -4.0);
	esRotate(&modelview, -30.0, 1.0, 0.0, 0.0);
	esRotate(&modelview, -45.0, 0.0, 1.0, 0.0);

	ESMatrix projection;
	esMatrixLoadIdentity(&projection);
	esFrustum(&projection, -1.0, +1.0, -1.0 * aspect, +1.0 * aspect,
		  1.0, 10.0);

	ESMatrix modelviewprojection;
	esMatrixLoadIdentity(&modelviewprojection);
	esMatrixMultiply(&modelviewprojection, &modelview, &projection);

	float normal[9];
	normal[0] = modelview.m[0][0];
	normal[1] = modelview.m[0][1];
	normal[2] = modelview.m[0][2];
	normal[3] = modelview.m[1][0];
	normal[4] = modelview.m[1][1];
	normal[5] = modelview.m[1][2];
	normal[6] = modelview.m[2][0];
	normal[7] = modelview.m[2][1];
	normal[8] = modelview.m[2][2];

	limare_uniform_attach(state, "modelviewMatrix", 16,
			      &modelview.m[0][0]);
	limare_uniform_attach(state, "modelviewprojectionMatrix", 16,
			      &modelviewprojection.m[0][0]);
	limare_uniform_attach(state, "normalMatrix", 9, normal);

	limare_frame_new(state);

	ret = limare_draw_arrays(state, GL_TRIANGLES, 0, COMPANION_ARRAY_COUNT);
	if (ret)
		return ret;

	ret = limare_frame_flush(state);
	if (ret)
		return ret;

	limare_buffer_swap(state);

	limare_finish(state);

	return 0;
}
Пример #3
0
int
main(int argc, char *argv[])
{
	struct limare_state *state;
	int ret;

	const char *vertex_shader_source =
		"attribute vec4 aPosition;    \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_Position = aPosition; \n"
		"}                            \n";
	const char *fragment_shader_source =
		"precision mediump float;     \n"
		"                             \n"
		"uniform vec4 uColor;         \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_FragColor = uColor;   \n"
		"}                            \n";

	float vertices[] = {-0.45, -0.75, 0.0,
			     0.45, -0.75, 0.0,
			    -0.45,  0.75, 0.0,
			     0.45,  0.75, 0.0};
	float color[] = {1.0, 0.0, 0.0, 1.0};

	state = limare_init();
	if (!state)
		return -1;

	limare_buffer_clear(state);

	ret = limare_state_setup(state, 0, 0, 0xFF505050);
	if (ret)
		return ret;

	int program = limare_program_new(state);
	vertex_shader_attach(state, program, vertex_shader_source);
	fragment_shader_attach(state, program, fragment_shader_source);

	limare_link(state);

	limare_attribute_pointer(state, "aPosition", LIMARE_ATTRIB_FLOAT,
				 3, 0, 4, vertices);

	limare_uniform_attach(state, "uColor", 4, color);

	limare_frame_new(state);

	ret = limare_draw_arrays(state, GL_TRIANGLE_STRIP, 0, 4);
	if (ret)
		return ret;

	ret = limare_frame_flush(state);
	if (ret)
		return ret;

	limare_buffer_swap(state);

	limare_finish(state);

	return 0;
}
Пример #4
0
void *gpu_copy_thread(void *data)
{
	workload_t *w = (workload_t *)data;
	struct limare_state *state;
	int ret, width, height, x, y;

	#include "shader_v.h"
	#include "shader_f.h"

	load_mali_kernel_module();

	state = limare_init();
	assert(state);

	ret = limare_state_setup(state, 0, 0, 0xFF505050);
	assert(state);

	limare_buffer_size(state, &width, &height);

	int program = limare_program_new(state);
	vertex_shader_attach_mbs_stream(state, program, vertex_shader_binary,
						sizeof(vertex_shader_binary));
	fragment_shader_attach_mbs_stream(state, program, fragment_shader_binary,
						sizeof(fragment_shader_binary));
	limare_link(state);

	limare_attribute_pointer(state, "in_position", LIMARE_ATTRIB_FLOAT,
				 3, 0, COPYTEST_VERTEX_COUNT, copytest_vertices);
	limare_attribute_pointer(state, "in_coord", LIMARE_ATTRIB_FLOAT,
				 2, 0, COPYTEST_VERTEX_COUNT,
				 copytest_texture_coordinates);

	/* Generate a texture */
	uint32_t *checkerboard_texture = malloc(width * height * sizeof(uint32_t));
	assert(checkerboard_texture);
	for (y = 0; y < height; y++) {
		for (x = 0; x < width; x++) {
			uint32_t color;
			if (((x * 8 / width) % 2 == 0) ^ ((y * 8 / height) % 2 == 0))
				color = (x % 2) ? 0xFFFFFFFF : 0;
			else
				color = (y % 2) ? 0xFFFFFFFF : 0;
			checkerboard_texture[y * width + x] = color;
		}
	}

	int texture = limare_texture_upload(state, checkerboard_texture,
					    width, height,
					    LIMA_TEXEL_FORMAT_RGBA_8888, 0);
	limare_texture_attach(state, "in_texture", texture);

	ESMatrix modelviewprojection;
	esMatrixLoadIdentity(&modelviewprojection);
	esTranslate(&modelviewprojection, 0.0, 0.0, -0.5);

	while (1) {
		limare_uniform_attach(state, "modelviewprojectionMatrix", 16,
				      &modelviewprojection.m[0][0]);
		limare_frame_new(state);
		ret = limare_draw_elements(state, GL_TRIANGLES,
					   COPYTEST_INDEX_COUNT,
					   &copytest_indices,
					   GL_UNSIGNED_BYTE);
		assert(!ret);
		ret = limare_frame_flush(state);
		assert(!ret);
		limare_buffer_swap(state);

		pthread_mutex_lock(&bandwidth_counters_mutex);
		w->bytes_counter += width * height * (state->fb->bpp / 8) +
				    width * height * 4;
		pthread_mutex_unlock(&bandwidth_counters_mutex);
	}

	limare_finish(state);
	free(checkerboard_texture);

	return 0;
}
Пример #5
0
int
main(int argc, char *argv[])
{
	struct limare_state *state;
	int ret;

	float vertices[] = { -0.45, -0.75, 0.0,
			         0.45, -0.75, 0.0,
				-0.45,  0.75, 0.0,
				 0.45,  0.75, 0.0 };
	float color[] = {1.0, 0.0, 0.0, 1.0 };

	const char *vertex_shader_source =
		"precision mediump float;     \n"
		"attribute vec4 aPosition;    \n"
		"                             \n"
                "void main()                  \n"
                "{                            \n"
                "    gl_Position = aPosition; \n"
                "}                            \n";

	const char *fragment_shader_source =
		"precision mediump float;     \n"
		"uniform vec4 uColor;         \n"
		"                             \n"
		"void main()                  \n"
		"{                            \n"
		"    gl_FragColor = uColor;   \n"
		"}                            \n";

	fb_clear();

	state = limare_init();
	if (!state)
		return -1;

	ret = limare_state_setup(state, WIDTH, HEIGHT, 0xFF505050);
	if (ret)
		return ret;

	vertex_shader_attach(state, vertex_shader_source);
	fragment_shader_attach(state, fragment_shader_source);

	limare_link(state);

	limare_attribute_pointer(state, "aPosition", 4, 3, vertices);

	limare_uniform_attach(state, "uColor", 4, 4, color);

	ret = limare_draw_arrays(state, GL_TRIANGLE_STRIP, 0, 4);
	if (ret)
		return ret;

	ret = limare_flush(state);
	if (ret)
		return ret;

	bmp_dump(state->pp->frame_address, state, "/sdcard/limare.bmp");

	fb_dump(state->pp->frame_address, 0, state->width, state->height);

	limare_finish();

	return 0;
}