-
Notifications
You must be signed in to change notification settings - Fork 12
/
memspeed_gpu.c
184 lines (151 loc) · 4.77 KB
/
memspeed_gpu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* Copyright (c) 2014 Siarhei Siamashka
*
* Based on the textured cube demo from the lima driver
*
* Copyright (c) 2011-2013 Luc Verhaegen <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <assert.h>
#include <inttypes.h>
#include <pthread.h>
#include "limare.h"
#include "fb.h"
#include "formats.h"
#include "esUtil.h"
#include "lima-memspeed.h"
#include "memspeed_gpu.h"
#include "load_mali_kernel_module.h"
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;
}
/******************************************************************************/
#define COPYTEST_VERTEX_COUNT 4
#define COPYTEST_TRIANGLE_COUNT 2
#define COPYTEST_INDEX_COUNT (COPYTEST_TRIANGLE_COUNT * 3)
static float copytest_vertices[COPYTEST_VERTEX_COUNT][3] = {
{-1.0, -1.0, +1.0},
{+1.0, -1.0, +1.0},
{-1.0, +1.0, +1.0},
{+1.0, +1.0, +1.0},
};
static float copytest_texture_coordinates[COPYTEST_VERTEX_COUNT][2] = {
/* front */
{0.0, 1.0},
{1.0, 1.0},
{0.0, 0.0},
{1.0, 0.0},
};
static unsigned char copytest_indices[COPYTEST_TRIANGLE_COUNT][3] = {
{0, 1, 2},
{3, 2, 1},
};
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,
©test_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;
}