Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 1 | #define _GNU_SOURCE |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | #include <stdbool.h> |
| 6 | #include <assert.h> |
| 7 | |
| 8 | #include <xcb/xcb.h> |
| 9 | #include <xgl.h> |
| 10 | #include <xglDbg.h> |
| 11 | #include <xglWsiX11Ext.h> |
| 12 | |
| 13 | #include "icd-bil.h" |
| 14 | |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 15 | #include "linmath.h" |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 16 | #include <unistd.h> |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 17 | #include <png.h> |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 18 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 19 | #define DEMO_BUFFER_COUNT 2 |
| 20 | #define DEMO_TEXTURE_COUNT 1 |
| 21 | |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 22 | /* |
| 23 | * When not defined, code will use built-in GLSL compiler |
| 24 | * which may not be supported on all drivers |
| 25 | */ |
| 26 | #define EXTERNAL_BIL |
| 27 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 28 | /* |
| 29 | * structure to track all objects related to a texture. |
| 30 | */ |
| 31 | struct texture_objects { |
| 32 | XGL_SAMPLER sampler; |
| 33 | |
| 34 | XGL_IMAGE image; |
| 35 | uint32_t num_mem; |
| 36 | XGL_GPU_MEMORY *mem; |
| 37 | XGL_IMAGE_VIEW view; |
| 38 | int32_t tex_width, tex_height; |
| 39 | }; |
| 40 | |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 41 | static char *tex_files[] = { |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 42 | "lunarg-logo-256x256-solid.png" |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 43 | }; |
| 44 | |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 45 | struct xglcube_vs_uniform { |
| 46 | // Must start with MVP |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 47 | float mvp[4][4]; |
| 48 | float position[12*3][4]; |
| 49 | float color[12*3][4]; |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct xgltexcube_vs_uniform { |
| 53 | // Must start with MVP |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 54 | float mvp[4][4]; |
| 55 | float position[12*3][4]; |
| 56 | float attr[12*3][4]; |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 57 | }; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 58 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 59 | //-------------------------------------------------------------------------------------- |
| 60 | // Mesh and VertexFormat Data |
| 61 | //-------------------------------------------------------------------------------------- |
| 62 | struct Vertex |
| 63 | { |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 64 | float posX, posY, posZ, posW; // Position data |
| 65 | float r, g, b, a; // Color |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 66 | }; |
| 67 | |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 68 | struct VertexPosTex |
| 69 | { |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 70 | float posX, posY, posZ, posW; // Position data |
| 71 | float u, v, s, t; // Texcoord |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 72 | }; |
| 73 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 74 | #define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 75 | #define UV(_u_, _v_) (_u_), (_v_), 0.f, 1.f |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 76 | |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 77 | static const float g_vertex_buffer_data[] = { |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 78 | -1.0f,-1.0f,-1.0f, // Vertex 0 |
| 79 | -1.0f,-1.0f, 1.0f, |
| 80 | -1.0f, 1.0f, 1.0f, |
| 81 | |
| 82 | -1.0f, 1.0f, 1.0f, // Vertex 1 |
| 83 | -1.0f, 1.0f,-1.0f, |
| 84 | -1.0f,-1.0f,-1.0f, |
| 85 | |
| 86 | -1.0f,-1.0f,-1.0f, // Vertex 2 |
| 87 | 1.0f, 1.0f,-1.0f, |
| 88 | 1.0f,-1.0f,-1.0f, |
| 89 | |
| 90 | -1.0f,-1.0f,-1.0f, // Vertex 3 |
| 91 | 1.0f, 1.0f,-1.0f, |
| 92 | -1.0f, 1.0f,-1.0f, |
| 93 | |
| 94 | -1.0f,-1.0f,-1.0f, // Vertex 4 |
| 95 | 1.0f,-1.0f, 1.0f, |
| 96 | 1.0f,-1.0f,-1.0f, |
| 97 | |
| 98 | -1.0f,-1.0f,-1.0f, // Vertex 5 |
| 99 | -1.0f,-1.0f, 1.0f, |
| 100 | 1.0f,-1.0f, 1.0f, |
| 101 | |
| 102 | -1.0f, 1.0f,-1.0f, // Vertex 6 |
| 103 | -1.0f, 1.0f, 1.0f, |
| 104 | 1.0f, 1.0f, 1.0f, |
| 105 | |
| 106 | -1.0f, 1.0f,-1.0f, // Vertex 7 |
| 107 | 1.0f, 1.0f,-1.0f, |
| 108 | 1.0f, 1.0f, 1.0f, |
| 109 | |
| 110 | 1.0f, 1.0f,-1.0f, // Vertex 8 |
| 111 | 1.0f, 1.0f, 1.0f, |
| 112 | 1.0f,-1.0f, 1.0f, |
| 113 | |
| 114 | 1.0f,-1.0f, 1.0f, // Vertex 9 |
| 115 | 1.0f,-1.0f,-1.0f, |
| 116 | 1.0f, 1.0f,-1.0f, |
| 117 | |
| 118 | -1.0f, 1.0f, 1.0f, // Vertex 10 |
| 119 | 1.0f, 1.0f, 1.0f, |
| 120 | -1.0f,-1.0f, 1.0f, |
| 121 | |
| 122 | -1.0f,-1.0f, 1.0f, // Vertex 11 |
| 123 | 1.0f,-1.0f, 1.0f, |
| 124 | 1.0f, 1.0f, 1.0f, |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 125 | }; |
| 126 | |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 127 | static const float g_uv_buffer_data[] = { |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 128 | 1.0f, 0.0f, // Vertex 0 |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 129 | 0.0f, 0.0f, |
| 130 | 0.0f, 1.0f, |
| 131 | |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 132 | 0.0f, 1.0f, // Vertex 1 |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 133 | 1.0f, 1.0f, |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 134 | 1.0f, 0.0f, |
| 135 | |
| 136 | // 0.0f, 1.0f, // Vertex 2 |
| 137 | // 1.0f, 0.0f, |
| 138 | // 0.0f, 0.0f, |
| 139 | |
| 140 | // 0.0f, 1.0f, // Vertex 3 |
| 141 | // 1.0f, 0.0f, |
| 142 | // 1.0f, 1.0f, |
| 143 | |
| 144 | 0.0f, 0.0f, // Vertex 2 |
| 145 | 1.0f, 1.0f, |
| 146 | 1.0f, 0.0f, |
| 147 | |
| 148 | 0.0f, 0.0f, // Vertex 3 |
| 149 | 1.0f, 1.0f, |
| 150 | 0.0f, 1.0f, |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 151 | |
| 152 | 0.0f, 1.0f, // Vertex 4 |
| 153 | 1.0f, 0.0f, |
| 154 | 0.0f, 0.0f, |
| 155 | |
| 156 | 0.0f, 1.0f, // Vertex 5 |
| 157 | 1.0f, 1.0f, |
| 158 | 1.0f, 0.0f, |
| 159 | |
| 160 | 0.0f, 1.0f, // Vertex 6 |
| 161 | 1.0f, 1.0f, |
| 162 | 1.0f, 0.0f, |
| 163 | |
| 164 | 0.0f, 1.0f, // Vertex 7 |
| 165 | 0.0f, 0.0f, |
| 166 | 1.0f, 0.0f, |
| 167 | |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 168 | 0.0f, 1.0f, // Vertex 8 |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 169 | 1.0f, 1.0f, |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 170 | 1.0f, 0.0f, |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 171 | |
| 172 | 1.0f, 0.0f, // Vertex 9 |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 173 | 0.0f, 0.0f, |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 174 | 0.0f, 1.0f, |
| 175 | |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 176 | 1.0f, 1.0f, // Vertex 10 |
| 177 | 0.0f, 1.0f, |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 178 | 1.0f, 0.0f, |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 179 | |
| 180 | 1.0f, 0.0f, // Vertex 11 |
| 181 | 0.0f, 0.0f, |
| 182 | 0.0f, 1.0f, |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | void dumpMatrix(const char *note, mat4x4 MVP) |
| 186 | { |
| 187 | int i; |
| 188 | |
| 189 | printf("%s: \n", note); |
| 190 | for (i=0; i<4; i++) { |
| 191 | printf("%f, %f, %f, %f\n", MVP[i][0], MVP[i][1], MVP[i][2], MVP[i][3]); |
| 192 | } |
| 193 | printf("\n"); |
| 194 | fflush(stdout); |
| 195 | } |
| 196 | |
| 197 | void dumpVec4(const char *note, vec4 vector) |
| 198 | { |
| 199 | printf("%s: \n", note); |
| 200 | printf("%f, %f, %f, %f\n", vector[0], vector[1], vector[2], vector[3]); |
| 201 | printf("\n"); |
| 202 | fflush(stdout); |
| 203 | } |
| 204 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 205 | struct demo { |
| 206 | xcb_connection_t *connection; |
| 207 | xcb_screen_t *screen; |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 208 | bool use_staging_buffer; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 209 | |
Jon Ashburn | 93cfc43 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 210 | XGL_INSTANCE inst; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 211 | XGL_PHYSICAL_GPU gpu; |
| 212 | XGL_DEVICE device; |
| 213 | XGL_QUEUE queue; |
| 214 | |
| 215 | int width, height; |
| 216 | XGL_FORMAT format; |
| 217 | |
| 218 | struct { |
| 219 | XGL_IMAGE image; |
| 220 | XGL_GPU_MEMORY mem; |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 221 | XGL_CMD_BUFFER cmd; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 222 | |
| 223 | XGL_COLOR_ATTACHMENT_VIEW view; |
Chia-I Wu | bb57f64 | 2014-11-07 14:30:34 +0800 | [diff] [blame] | 224 | XGL_FENCE fence; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 225 | } buffers[DEMO_BUFFER_COUNT]; |
| 226 | |
| 227 | struct { |
| 228 | XGL_FORMAT format; |
| 229 | |
| 230 | XGL_IMAGE image; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 231 | uint32_t num_mem; |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 232 | XGL_GPU_MEMORY *mem; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 233 | XGL_DEPTH_STENCIL_VIEW view; |
| 234 | } depth; |
| 235 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 236 | struct texture_objects textures[DEMO_TEXTURE_COUNT]; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 237 | |
| 238 | struct { |
Chia-I Wu | 8ea21c7 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 239 | XGL_BUFFER buf; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 240 | uint32_t num_mem; |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 241 | XGL_GPU_MEMORY *mem; |
Chia-I Wu | 8ea21c7 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 242 | XGL_BUFFER_VIEW view; |
| 243 | XGL_BUFFER_VIEW_ATTACH_INFO attach; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 244 | } uniform_data; |
| 245 | |
Chia-I Wu | 87544e7 | 2015-02-23 10:41:08 -0700 | [diff] [blame] | 246 | XGL_DESCRIPTOR_SET_LAYOUT desc_layout; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 247 | XGL_PIPELINE pipeline; |
| 248 | |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 249 | XGL_DYNAMIC_VP_STATE_OBJECT viewport; |
| 250 | XGL_DYNAMIC_RS_STATE_OBJECT raster; |
| 251 | XGL_DYNAMIC_CB_STATE_OBJECT color_blend; |
| 252 | XGL_DYNAMIC_DS_STATE_OBJECT depth_stencil; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 253 | |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 254 | mat4x4 projection_matrix; |
| 255 | mat4x4 view_matrix; |
| 256 | mat4x4 model_matrix; |
| 257 | |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 258 | float spin_angle; |
| 259 | float spin_increment; |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 260 | bool pause; |
| 261 | |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 262 | XGL_DESCRIPTOR_REGION desc_region; |
| 263 | XGL_DESCRIPTOR_SET desc_set; |
| 264 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 265 | xcb_window_t window; |
Courtney Goeltzenleuchter | 98cb2cb | 2014-11-06 14:27:52 -0700 | [diff] [blame] | 266 | xcb_intern_atom_reply_t *atom_wm_delete_window; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 267 | |
| 268 | bool quit; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 269 | uint32_t current_buffer; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 270 | }; |
| 271 | |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 272 | static void demo_draw_build_cmd(struct demo *demo, XGL_CMD_BUFFER cmd_buf) |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 273 | { |
| 274 | const XGL_COLOR_ATTACHMENT_BIND_INFO color_attachment = { |
| 275 | .view = demo->buffers[demo->current_buffer].view, |
Mike Stroyan | 3bd2d89 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 276 | .layout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 277 | }; |
| 278 | const XGL_DEPTH_STENCIL_BIND_INFO depth_stencil = { |
| 279 | .view = demo->depth.view, |
Mike Stroyan | 3bd2d89 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 280 | .layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 281 | }; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 282 | const float clear_color[4] = { 0.2f, 0.2f, 0.2f, 0.2f }; |
| 283 | const float clear_depth = 1.0f; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 284 | XGL_IMAGE_SUBRESOURCE_RANGE clear_range; |
Jon Ashburn | 08f6eb9 | 2015-01-02 18:24:05 -0700 | [diff] [blame] | 285 | XGL_CMD_BUFFER_GRAPHICS_BEGIN_INFO graphics_cmd_buf_info = { |
| 286 | .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_GRAPHICS_BEGIN_INFO, |
| 287 | .pNext = NULL, |
Jon Ashburn | 08f6eb9 | 2015-01-02 18:24:05 -0700 | [diff] [blame] | 288 | }; |
Jon Ashburn | 60ccfbe | 2014-12-31 17:08:35 -0700 | [diff] [blame] | 289 | XGL_CMD_BUFFER_BEGIN_INFO cmd_buf_info = { |
| 290 | .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO, |
Jon Ashburn | 08f6eb9 | 2015-01-02 18:24:05 -0700 | [diff] [blame] | 291 | .pNext = &graphics_cmd_buf_info, |
Jon Ashburn | 60ccfbe | 2014-12-31 17:08:35 -0700 | [diff] [blame] | 292 | .flags = XGL_CMD_BUFFER_OPTIMIZE_GPU_SMALL_BATCH_BIT | |
| 293 | XGL_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT, |
| 294 | }; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 295 | XGL_RESULT err; |
Jon Ashburn | 08f6eb9 | 2015-01-02 18:24:05 -0700 | [diff] [blame] | 296 | XGL_ATTACHMENT_LOAD_OP load_op = XGL_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 297 | XGL_ATTACHMENT_STORE_OP store_op = XGL_ATTACHMENT_STORE_OP_DONT_CARE; |
| 298 | const XGL_FRAMEBUFFER_CREATE_INFO fb_info = { |
| 299 | .sType = XGL_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, |
| 300 | .pNext = NULL, |
| 301 | .colorAttachmentCount = 1, |
| 302 | .pColorAttachments = (XGL_COLOR_ATTACHMENT_BIND_INFO*) &color_attachment, |
| 303 | .pDepthStencilAttachment = (XGL_DEPTH_STENCIL_BIND_INFO*) &depth_stencil, |
| 304 | .sampleCount = 1, |
Mark Lobodzinski | c06b741 | 2015-01-27 13:24:03 -0600 | [diff] [blame] | 305 | .width = demo->width, |
| 306 | .height = demo->height, |
| 307 | .layers = 1, |
Jon Ashburn | 08f6eb9 | 2015-01-02 18:24:05 -0700 | [diff] [blame] | 308 | }; |
| 309 | XGL_RENDER_PASS_CREATE_INFO rp_info; |
| 310 | |
| 311 | memset(&rp_info, 0 , sizeof(rp_info)); |
| 312 | err = xglCreateFramebuffer(demo->device, &fb_info, &(rp_info.framebuffer)); |
| 313 | assert(!err); |
| 314 | rp_info.sType = XGL_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 315 | rp_info.renderArea.extent.width = demo->width; |
| 316 | rp_info.renderArea.extent.height = demo->height; |
Courtney Goeltzenleuchter | c17d7de | 2015-02-10 14:06:25 -0700 | [diff] [blame] | 317 | rp_info.colorAttachmentCount = 1; |
Jon Ashburn | 08f6eb9 | 2015-01-02 18:24:05 -0700 | [diff] [blame] | 318 | rp_info.pColorLoadOps = &load_op; |
| 319 | rp_info.pColorStoreOps = &store_op; |
| 320 | rp_info.depthLoadOp = XGL_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 321 | rp_info.depthStoreOp = XGL_ATTACHMENT_STORE_OP_DONT_CARE; |
| 322 | rp_info.stencilLoadOp = XGL_ATTACHMENT_LOAD_OP_DONT_CARE; |
| 323 | rp_info.stencilStoreOp = XGL_ATTACHMENT_STORE_OP_DONT_CARE; |
| 324 | err = xglCreateRenderPass(demo->device, &rp_info, &(graphics_cmd_buf_info.renderPass)); |
| 325 | assert(!err); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 326 | |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 327 | err = xglBeginCommandBuffer(cmd_buf, &cmd_buf_info); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 328 | assert(!err); |
| 329 | |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 330 | xglCmdBindPipeline(cmd_buf, XGL_PIPELINE_BIND_POINT_GRAPHICS, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 331 | demo->pipeline); |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 332 | xglCmdBindDescriptorSet(cmd_buf, XGL_PIPELINE_BIND_POINT_GRAPHICS, |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 333 | demo->desc_set, NULL); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 334 | |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 335 | xglCmdBindDynamicStateObject(cmd_buf, XGL_STATE_BIND_VIEWPORT, demo->viewport); |
| 336 | xglCmdBindDynamicStateObject(cmd_buf, XGL_STATE_BIND_RASTER, demo->raster); |
| 337 | xglCmdBindDynamicStateObject(cmd_buf, XGL_STATE_BIND_COLOR_BLEND, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 338 | demo->color_blend); |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 339 | xglCmdBindDynamicStateObject(cmd_buf, XGL_STATE_BIND_DEPTH_STENCIL, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 340 | demo->depth_stencil); |
| 341 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 342 | xglCmdBeginRenderPass(cmd_buf, graphics_cmd_buf_info.renderPass); |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 343 | clear_range.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 344 | clear_range.baseMipLevel = 0; |
| 345 | clear_range.mipLevels = 1; |
| 346 | clear_range.baseArraySlice = 0; |
| 347 | clear_range.arraySize = 1; |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 348 | xglCmdClearColorImage(cmd_buf, |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 349 | demo->buffers[demo->current_buffer].image, |
| 350 | clear_color, 1, &clear_range); |
| 351 | |
| 352 | clear_range.aspect = XGL_IMAGE_ASPECT_DEPTH; |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 353 | xglCmdClearDepthStencil(cmd_buf, demo->depth.image, |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 354 | clear_depth, 0, 1, &clear_range); |
| 355 | |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 356 | xglCmdDraw(cmd_buf, 0, 12 * 3, 0, 1); |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 357 | xglCmdEndRenderPass(cmd_buf, graphics_cmd_buf_info.renderPass); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 358 | |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 359 | err = xglEndCommandBuffer(cmd_buf); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 360 | assert(!err); |
| 361 | } |
| 362 | |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 363 | |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 364 | void demo_update_data_buffer(struct demo *demo) |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 365 | { |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 366 | mat4x4 MVP, Model, VP; |
| 367 | int matrixSize = sizeof(MVP); |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 368 | uint8_t *pData; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 369 | XGL_RESULT err; |
| 370 | |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 371 | mat4x4_mul(VP, demo->projection_matrix, demo->view_matrix); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 372 | |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 373 | // Rotate 22.5 degrees around the Y axis |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 374 | mat4x4_dup(Model, demo->model_matrix); |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 375 | mat4x4_rotate(demo->model_matrix, Model, 0.0f, 1.0f, 0.0f, degreesToRadians(demo->spin_angle)); |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 376 | mat4x4_mul(MVP, VP, demo->model_matrix); |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 377 | |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 378 | assert(demo->uniform_data.num_mem == 1); |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 379 | err = xglMapMemory(demo->uniform_data.mem[0], 0, (void **) &pData); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 380 | assert(!err); |
| 381 | |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 382 | memcpy(pData, (const void*) &MVP[0][0], matrixSize); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 383 | |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 384 | err = xglUnmapMemory(demo->uniform_data.mem[0]); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 385 | assert(!err); |
| 386 | } |
| 387 | |
| 388 | static void demo_draw(struct demo *demo) |
| 389 | { |
| 390 | const XGL_WSI_X11_PRESENT_INFO present = { |
| 391 | .destWindow = demo->window, |
| 392 | .srcImage = demo->buffers[demo->current_buffer].image, |
Chia-I Wu | bb57f64 | 2014-11-07 14:30:34 +0800 | [diff] [blame] | 393 | .async = true, |
| 394 | .flip = false, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 395 | }; |
Chia-I Wu | bb57f64 | 2014-11-07 14:30:34 +0800 | [diff] [blame] | 396 | XGL_FENCE fence = demo->buffers[demo->current_buffer].fence; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 397 | XGL_RESULT err; |
| 398 | |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 399 | err = xglWaitForFences(demo->device, 1, &fence, XGL_TRUE, ~((uint64_t) 0)); |
Chia-I Wu | bb57f64 | 2014-11-07 14:30:34 +0800 | [diff] [blame] | 400 | assert(err == XGL_SUCCESS || err == XGL_ERROR_UNAVAILABLE); |
| 401 | |
Mark Lobodzinski | 7b8fee6 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 402 | uint32_t i, idx = 0; |
| 403 | XGL_MEMORY_REF *memRefs; |
| 404 | memRefs = malloc(sizeof(XGL_MEMORY_REF) * (DEMO_BUFFER_COUNT + |
| 405 | demo->depth.num_mem + |
| 406 | demo->textures[0].num_mem + |
| 407 | demo->uniform_data.num_mem)); |
| 408 | for (i = 0; i < demo->depth.num_mem; i++, idx++) { |
| 409 | memRefs[idx].mem = demo->depth.mem[i]; |
| 410 | memRefs[idx].flags = 0; |
| 411 | } |
| 412 | for (i = 0; i < demo->textures[0].num_mem; i++, idx++) { |
| 413 | memRefs[idx].mem = demo->textures[0].mem[i]; |
| 414 | memRefs[idx].flags = 0; |
| 415 | } |
| 416 | memRefs[idx].mem = demo->buffers[0].mem; |
| 417 | memRefs[idx++].flags = 0; |
| 418 | memRefs[idx].mem = demo->buffers[1].mem; |
| 419 | memRefs[idx++].flags = 0; |
| 420 | for (i = 0; i < demo->uniform_data.num_mem; i++, idx++) { |
| 421 | memRefs[idx].mem = demo->uniform_data.mem[i]; |
| 422 | memRefs[idx].flags = 0; |
| 423 | } |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 424 | err = xglQueueSubmit(demo->queue, 1, &demo->buffers[demo->current_buffer].cmd, |
| 425 | 0, NULL, XGL_NULL_HANDLE); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 426 | assert(!err); |
| 427 | |
Chia-I Wu | bb57f64 | 2014-11-07 14:30:34 +0800 | [diff] [blame] | 428 | err = xglWsiX11QueuePresent(demo->queue, &present, fence); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 429 | assert(!err); |
| 430 | |
| 431 | demo->current_buffer = (demo->current_buffer + 1) % DEMO_BUFFER_COUNT; |
| 432 | } |
| 433 | |
| 434 | static void demo_prepare_buffers(struct demo *demo) |
| 435 | { |
| 436 | const XGL_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO presentable_image = { |
| 437 | .format = demo->format, |
| 438 | .usage = XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, |
| 439 | .extent = { |
| 440 | .width = demo->width, |
| 441 | .height = demo->height, |
| 442 | }, |
| 443 | .flags = 0, |
| 444 | }; |
Chia-I Wu | bb57f64 | 2014-11-07 14:30:34 +0800 | [diff] [blame] | 445 | const XGL_FENCE_CREATE_INFO fence = { |
| 446 | .sType = XGL_STRUCTURE_TYPE_FENCE_CREATE_INFO, |
| 447 | .pNext = NULL, |
| 448 | .flags = 0, |
| 449 | }; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 450 | XGL_RESULT err; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 451 | uint32_t i; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 452 | |
| 453 | for (i = 0; i < DEMO_BUFFER_COUNT; i++) { |
| 454 | XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO color_attachment_view = { |
| 455 | .sType = XGL_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO, |
| 456 | .pNext = NULL, |
| 457 | .format = demo->format, |
| 458 | .mipLevel = 0, |
| 459 | .baseArraySlice = 0, |
| 460 | .arraySize = 1, |
| 461 | }; |
| 462 | |
| 463 | err = xglWsiX11CreatePresentableImage(demo->device, &presentable_image, |
| 464 | &demo->buffers[i].image, &demo->buffers[i].mem); |
| 465 | assert(!err); |
| 466 | |
| 467 | color_attachment_view.image = demo->buffers[i].image; |
| 468 | |
| 469 | err = xglCreateColorAttachmentView(demo->device, |
| 470 | &color_attachment_view, &demo->buffers[i].view); |
| 471 | assert(!err); |
Chia-I Wu | bb57f64 | 2014-11-07 14:30:34 +0800 | [diff] [blame] | 472 | |
| 473 | err = xglCreateFence(demo->device, |
| 474 | &fence, &demo->buffers[i].fence); |
| 475 | assert(!err); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | |
| 479 | static void demo_prepare_depth(struct demo *demo) |
| 480 | { |
Jeremy Hayes | 9958ea8 | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 481 | const XGL_FORMAT depth_format = XGL_FMT_D16_UNORM; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 482 | const XGL_IMAGE_CREATE_INFO image = { |
| 483 | .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 484 | .pNext = NULL, |
| 485 | .imageType = XGL_IMAGE_2D, |
| 486 | .format = depth_format, |
| 487 | .extent = { demo->width, demo->height, 1 }, |
| 488 | .mipLevels = 1, |
| 489 | .arraySize = 1, |
| 490 | .samples = 1, |
| 491 | .tiling = XGL_OPTIMAL_TILING, |
| 492 | .usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT, |
| 493 | .flags = 0, |
| 494 | }; |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 495 | XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc = { |
| 496 | .sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO, |
| 497 | .pNext = NULL, |
| 498 | }; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 499 | XGL_MEMORY_ALLOC_INFO mem_alloc = { |
| 500 | .sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 501 | .pNext = &img_alloc, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 502 | .allocationSize = 0, |
Jon Ashburn | c483a8c | 2015-01-20 13:55:32 -0700 | [diff] [blame] | 503 | .memProps = XGL_MEMORY_PROPERTY_GPU_ONLY, |
Jon Ashburn | bdee4e8 | 2015-01-20 15:06:59 -0700 | [diff] [blame] | 504 | .memType = XGL_MEMORY_TYPE_IMAGE, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 505 | .memPriority = XGL_MEMORY_PRIORITY_NORMAL, |
| 506 | }; |
| 507 | XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view = { |
| 508 | .sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO, |
| 509 | .pNext = NULL, |
| 510 | .image = XGL_NULL_HANDLE, |
| 511 | .mipLevel = 0, |
| 512 | .baseArraySlice = 0, |
| 513 | .arraySize = 1, |
| 514 | .flags = 0, |
| 515 | }; |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 516 | XGL_MEMORY_REQUIREMENTS *mem_reqs; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 517 | size_t mem_reqs_size = sizeof(XGL_MEMORY_REQUIREMENTS); |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 518 | XGL_IMAGE_MEMORY_REQUIREMENTS img_reqs; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 519 | size_t img_reqs_size = sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 520 | XGL_RESULT err; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 521 | uint32_t num_allocations = 0; |
| 522 | size_t num_alloc_size = sizeof(num_allocations); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 523 | |
| 524 | demo->depth.format = depth_format; |
| 525 | |
| 526 | /* create image */ |
| 527 | err = xglCreateImage(demo->device, &image, |
| 528 | &demo->depth.image); |
| 529 | assert(!err); |
| 530 | |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 531 | |
| 532 | err = xglGetObjectInfo(demo->depth.image, XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, &num_alloc_size, &num_allocations); |
| 533 | assert(!err && num_alloc_size == sizeof(num_allocations)); |
| 534 | mem_reqs = malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); |
| 535 | demo->depth.mem = malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); |
| 536 | demo->depth.num_mem = num_allocations; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 537 | err = xglGetObjectInfo(demo->depth.image, |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 538 | XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 539 | &mem_reqs_size, mem_reqs); |
| 540 | assert(!err && mem_reqs_size == num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 541 | err = xglGetObjectInfo(demo->depth.image, |
| 542 | XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS, |
| 543 | &img_reqs_size, &img_reqs); |
| 544 | assert(!err && img_reqs_size == sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS)); |
| 545 | img_alloc.usage = img_reqs.usage; |
| 546 | img_alloc.formatClass = img_reqs.formatClass; |
| 547 | img_alloc.samples = img_reqs.samples; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 548 | for (uint32_t i = 0; i < num_allocations; i ++) { |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 549 | mem_alloc.allocationSize = mem_reqs[i].size; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 550 | |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 551 | /* allocate memory */ |
| 552 | err = xglAllocMemory(demo->device, &mem_alloc, |
| 553 | &(demo->depth.mem[i])); |
| 554 | assert(!err); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 555 | |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 556 | /* bind memory */ |
| 557 | err = xglBindObjectMemory(demo->depth.image, i, |
| 558 | demo->depth.mem[i], 0); |
| 559 | assert(!err); |
| 560 | } |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 561 | |
| 562 | /* create image view */ |
| 563 | view.image = demo->depth.image; |
| 564 | err = xglCreateDepthStencilView(demo->device, &view, |
| 565 | &demo->depth.view); |
| 566 | assert(!err); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 567 | } |
| 568 | |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 569 | /** loadTexture |
| 570 | * loads a png file into an memory object, using cstdio , libpng. |
| 571 | * |
| 572 | * \param demo : Needed to access XGL calls |
| 573 | * \param filename : the png file to be loaded |
| 574 | * \param width : width of png, to be updated as a side effect of this function |
| 575 | * \param height : height of png, to be updated as a side effect of this function |
| 576 | * |
| 577 | * \return bool : an opengl texture id. true if successful?, |
| 578 | * should be validated by the client of this function. |
| 579 | * |
| 580 | * Source: http://en.wikibooks.org/wiki/OpenGL_Programming/Intermediate/Textures |
| 581 | * Modified to copy image to memory |
| 582 | * |
| 583 | */ |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 584 | bool loadTexture(const char *filename, uint8_t *rgba_data, |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 585 | XGL_SUBRESOURCE_LAYOUT *layout, |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 586 | int32_t *width, int32_t *height) |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 587 | { |
| 588 | //header for testing if it is a png |
| 589 | png_byte header[8]; |
Ian Elliott | 1e42dff | 2015-02-13 14:29:21 -0700 | [diff] [blame] | 590 | int is_png, bit_depth, color_type,rowbytes; |
| 591 | png_uint_32 i, twidth, theight; |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 592 | png_structp png_ptr; |
| 593 | png_infop info_ptr, end_info; |
| 594 | png_byte *image_data; |
| 595 | png_bytep *row_pointers; |
| 596 | |
| 597 | //open file as binary |
| 598 | FILE *fp = fopen(filename, "rb"); |
| 599 | if (!fp) { |
| 600 | return false; |
| 601 | } |
| 602 | |
| 603 | //read the header |
| 604 | fread(header, 1, 8, fp); |
| 605 | |
| 606 | //test if png |
| 607 | is_png = !png_sig_cmp(header, 0, 8); |
| 608 | if (!is_png) { |
| 609 | fclose(fp); |
| 610 | return false; |
| 611 | } |
| 612 | |
| 613 | //create png struct |
| 614 | png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, |
| 615 | NULL, NULL); |
| 616 | if (!png_ptr) { |
| 617 | fclose(fp); |
| 618 | return (false); |
| 619 | } |
| 620 | |
| 621 | //create png info struct |
| 622 | info_ptr = png_create_info_struct(png_ptr); |
| 623 | if (!info_ptr) { |
| 624 | png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL); |
| 625 | fclose(fp); |
| 626 | return (false); |
| 627 | } |
| 628 | |
| 629 | //create png info struct |
| 630 | end_info = png_create_info_struct(png_ptr); |
| 631 | if (!end_info) { |
| 632 | png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); |
| 633 | fclose(fp); |
| 634 | return (false); |
| 635 | } |
| 636 | |
| 637 | //png error stuff, not sure libpng man suggests this. |
| 638 | if (setjmp(png_jmpbuf(png_ptr))) { |
| 639 | png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
| 640 | fclose(fp); |
| 641 | return (false); |
| 642 | } |
| 643 | |
| 644 | //init png reading |
| 645 | png_init_io(png_ptr, fp); |
| 646 | |
| 647 | //let libpng know you already read the first 8 bytes |
| 648 | png_set_sig_bytes(png_ptr, 8); |
| 649 | |
| 650 | // read all the info up to the image data |
| 651 | png_read_info(png_ptr, info_ptr); |
| 652 | |
| 653 | // get info about png |
| 654 | png_get_IHDR(png_ptr, info_ptr, &twidth, &theight, &bit_depth, &color_type, |
| 655 | NULL, NULL, NULL); |
| 656 | |
| 657 | //update width and height based on png info |
| 658 | *width = twidth; |
| 659 | *height = theight; |
| 660 | |
| 661 | // Require that incoming texture be 8bits per color component |
| 662 | // and 4 components (RGBA). |
| 663 | if (png_get_bit_depth(png_ptr, info_ptr) != 8 || |
| 664 | png_get_channels(png_ptr, info_ptr) != 4) { |
| 665 | return false; |
| 666 | } |
| 667 | |
| 668 | if (rgba_data == NULL) { |
| 669 | // If data pointer is null, we just want the width & height |
| 670 | // clean up memory and close stuff |
| 671 | png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
| 672 | fclose(fp); |
| 673 | |
| 674 | return true; |
| 675 | } |
| 676 | |
| 677 | // Update the png info struct. |
| 678 | png_read_update_info(png_ptr, info_ptr); |
| 679 | |
| 680 | // Row size in bytes. |
| 681 | rowbytes = png_get_rowbytes(png_ptr, info_ptr); |
| 682 | |
| 683 | // Allocate the image_data as a big block, to be given to opengl |
| 684 | image_data = (png_byte *)malloc(rowbytes * theight * sizeof(png_byte)); |
| 685 | if (!image_data) { |
| 686 | //clean up memory and close stuff |
| 687 | png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
| 688 | fclose(fp); |
| 689 | return false; |
| 690 | } |
| 691 | |
| 692 | // row_pointers is for pointing to image_data for reading the png with libpng |
| 693 | row_pointers = (png_bytep *)malloc(theight * sizeof(png_bytep)); |
| 694 | if (!row_pointers) { |
| 695 | //clean up memory and close stuff |
| 696 | png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
| 697 | // delete[] image_data; |
| 698 | fclose(fp); |
| 699 | return false; |
| 700 | } |
| 701 | // set the individual row_pointers to point at the correct offsets of image_data |
| 702 | for (i = 0; i < theight; ++i) |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 703 | row_pointers[theight - 1 - i] = rgba_data + i * layout->rowPitch; |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 704 | |
| 705 | // read the png into image_data through row_pointers |
| 706 | png_read_image(png_ptr, row_pointers); |
| 707 | |
| 708 | // clean up memory and close stuff |
| 709 | png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); |
| 710 | free(row_pointers); |
| 711 | free(image_data); |
| 712 | fclose(fp); |
| 713 | |
| 714 | return true; |
| 715 | } |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 716 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 717 | static void demo_prepare_texture_image(struct demo *demo, |
| 718 | const char *filename, |
| 719 | struct texture_objects *tex_objs, |
| 720 | XGL_IMAGE_TILING tiling, |
| 721 | XGL_FLAGS mem_props) |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 722 | { |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 723 | const XGL_FORMAT tex_format = XGL_FMT_B8G8R8A8_UNORM; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 724 | int32_t tex_width; |
| 725 | int32_t tex_height; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 726 | XGL_RESULT err; |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 727 | |
| 728 | err = loadTexture(filename, NULL, NULL, &tex_width, &tex_height); |
| 729 | assert(err); |
| 730 | |
| 731 | tex_objs->tex_width = tex_width; |
| 732 | tex_objs->tex_height = tex_height; |
| 733 | |
| 734 | const XGL_IMAGE_CREATE_INFO image_create_info = { |
| 735 | .sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 736 | .pNext = NULL, |
| 737 | .imageType = XGL_IMAGE_2D, |
| 738 | .format = tex_format, |
| 739 | .extent = { tex_width, tex_height, 1 }, |
| 740 | .mipLevels = 1, |
| 741 | .arraySize = 1, |
| 742 | .samples = 1, |
| 743 | .tiling = tiling, |
| 744 | .usage = XGL_IMAGE_USAGE_TRANSFER_SOURCE_BIT, |
| 745 | .flags = 0, |
| 746 | }; |
| 747 | XGL_MEMORY_ALLOC_IMAGE_INFO img_alloc = { |
| 748 | .sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_IMAGE_INFO, |
| 749 | .pNext = NULL, |
| 750 | }; |
| 751 | XGL_MEMORY_ALLOC_INFO mem_alloc = { |
| 752 | .sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 753 | .pNext = &img_alloc, |
| 754 | .allocationSize = 0, |
| 755 | .memProps = mem_props, |
| 756 | .memType = XGL_MEMORY_TYPE_IMAGE, |
| 757 | .memPriority = XGL_MEMORY_PRIORITY_NORMAL, |
| 758 | }; |
| 759 | |
| 760 | XGL_MEMORY_REQUIREMENTS *mem_reqs; |
| 761 | size_t mem_reqs_size = sizeof(XGL_MEMORY_REQUIREMENTS); |
| 762 | XGL_IMAGE_MEMORY_REQUIREMENTS img_reqs; |
| 763 | size_t img_reqs_size = sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS); |
| 764 | uint32_t num_allocations = 0; |
| 765 | size_t num_alloc_size = sizeof(num_allocations); |
| 766 | |
| 767 | err = xglCreateImage(demo->device, &image_create_info, |
| 768 | &tex_objs->image); |
| 769 | assert(!err); |
| 770 | |
| 771 | err = xglGetObjectInfo(tex_objs->image, |
| 772 | XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, |
| 773 | &num_alloc_size, &num_allocations); |
| 774 | assert(!err && num_alloc_size == sizeof(num_allocations)); |
| 775 | mem_reqs = malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); |
| 776 | tex_objs->mem = malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); |
| 777 | err = xglGetObjectInfo(tex_objs->image, |
| 778 | XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
| 779 | &mem_reqs_size, mem_reqs); |
| 780 | assert(!err && mem_reqs_size == num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); |
| 781 | err = xglGetObjectInfo(tex_objs->image, |
| 782 | XGL_INFO_TYPE_IMAGE_MEMORY_REQUIREMENTS, |
| 783 | &img_reqs_size, &img_reqs); |
| 784 | assert(!err && img_reqs_size == sizeof(XGL_IMAGE_MEMORY_REQUIREMENTS)); |
| 785 | img_alloc.usage = img_reqs.usage; |
| 786 | img_alloc.formatClass = img_reqs.formatClass; |
| 787 | img_alloc.samples = img_reqs.samples; |
| 788 | mem_alloc.memProps = XGL_MEMORY_PROPERTY_CPU_VISIBLE_BIT; |
| 789 | for (uint32_t j = 0; j < num_allocations; j ++) { |
| 790 | mem_alloc.allocationSize = mem_reqs[j].size; |
Courtney Goeltzenleuchter | 02ba99a | 2015-02-25 11:48:28 -0700 | [diff] [blame] | 791 | mem_alloc.memType = mem_reqs[j].memType; |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 792 | |
| 793 | /* allocate memory */ |
| 794 | err = xglAllocMemory(demo->device, &mem_alloc, |
| 795 | &(tex_objs->mem[j])); |
| 796 | assert(!err); |
| 797 | |
| 798 | /* bind memory */ |
| 799 | err = xglBindObjectMemory(tex_objs->image, j, tex_objs->mem[j], 0); |
| 800 | assert(!err); |
| 801 | } |
| 802 | free(mem_reqs); |
| 803 | mem_reqs = NULL; |
| 804 | |
| 805 | tex_objs->num_mem = num_allocations; |
| 806 | |
| 807 | if (mem_props & XGL_MEMORY_PROPERTY_CPU_VISIBLE_BIT) { |
| 808 | const XGL_IMAGE_SUBRESOURCE subres = { |
| 809 | .aspect = XGL_IMAGE_ASPECT_COLOR, |
| 810 | .mipLevel = 0, |
| 811 | .arraySlice = 0, |
| 812 | }; |
| 813 | XGL_SUBRESOURCE_LAYOUT layout; |
| 814 | size_t layout_size = sizeof(XGL_SUBRESOURCE_LAYOUT); |
| 815 | void *data; |
| 816 | |
| 817 | err = xglGetImageSubresourceInfo(tex_objs->image, &subres, |
| 818 | XGL_INFO_TYPE_SUBRESOURCE_LAYOUT, |
| 819 | &layout_size, &layout); |
| 820 | assert(!err && layout_size == sizeof(layout)); |
| 821 | /* Linear texture must be within a single memory object */ |
| 822 | assert(num_allocations == 1); |
| 823 | |
| 824 | err = xglMapMemory(tex_objs->mem[0], 0, &data); |
| 825 | assert(!err); |
| 826 | |
| 827 | if (!loadTexture(filename, data, &layout, &tex_width, &tex_height)) { |
| 828 | fprintf(stderr, "Error loading texture: %s\n", filename); |
| 829 | } |
| 830 | |
| 831 | err = xglUnmapMemory(tex_objs->mem[0]); |
| 832 | assert(!err); |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | static void demo_destroy_texture_image(struct texture_objects *tex_objs) |
| 837 | { |
| 838 | /* clean up staging resources */ |
| 839 | for (uint32_t j = 0; j < tex_objs->num_mem; j ++) { |
| 840 | xglBindObjectMemory(tex_objs->image, j, XGL_NULL_HANDLE, 0); |
| 841 | xglFreeMemory(tex_objs->mem[j]); |
| 842 | } |
| 843 | |
| 844 | free(tex_objs->mem); |
| 845 | xglDestroyObject(tex_objs->image); |
| 846 | } |
| 847 | |
| 848 | static void demo_prepare_textures(struct demo *demo) |
| 849 | { |
| 850 | const XGL_FORMAT tex_format = XGL_FMT_R8G8B8A8_UNORM; |
| 851 | XGL_FORMAT_PROPERTIES props; |
| 852 | size_t size = sizeof(props); |
| 853 | XGL_RESULT err; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 854 | uint32_t i; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 855 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 856 | err = xglGetFormatInfo(demo->device, tex_format, |
| 857 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
| 858 | &size, &props); |
| 859 | assert(!err); |
| 860 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 861 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 862 | |
| 863 | if (props.linearTilingFeatures & XGL_FORMAT_IMAGE_SHADER_READ_BIT && !demo->use_staging_buffer) { |
| 864 | /* Device can texture using linear textures */ |
| 865 | demo_prepare_texture_image(demo, tex_files[i], &demo->textures[i], |
| 866 | XGL_LINEAR_TILING, XGL_MEMORY_PROPERTY_CPU_VISIBLE_BIT); |
| 867 | } else if (props.optimalTilingFeatures & XGL_FORMAT_IMAGE_SHADER_READ_BIT){ |
| 868 | /* Must use staging buffer to copy linear texture to optimized */ |
| 869 | struct texture_objects staging_texture; |
| 870 | |
| 871 | memset(&staging_texture, 0, sizeof(staging_texture)); |
| 872 | demo_prepare_texture_image(demo, tex_files[i], &staging_texture, |
| 873 | XGL_LINEAR_TILING, XGL_MEMORY_PROPERTY_CPU_VISIBLE_BIT); |
| 874 | |
| 875 | demo_prepare_texture_image(demo, tex_files[i], &demo->textures[i], |
| 876 | XGL_OPTIMAL_TILING, XGL_MEMORY_PROPERTY_GPU_ONLY); |
| 877 | |
| 878 | XGL_CMD_BUFFER staging_cmd_buf; |
| 879 | XGL_CMD_BUFFER_CREATE_INFO cmd_buf_create_info = { |
| 880 | .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO, |
| 881 | .pNext = NULL, |
| 882 | .queueType = XGL_QUEUE_TYPE_GRAPHICS, |
| 883 | .flags = 0 |
| 884 | }; |
| 885 | |
| 886 | err = xglCreateCommandBuffer(demo->device, &cmd_buf_create_info, &staging_cmd_buf); |
| 887 | assert(!err); |
| 888 | |
| 889 | /* Copy staging texture to usable texture */ |
| 890 | XGL_CMD_BUFFER_BEGIN_INFO cmd_buf_begin_info = { |
| 891 | .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO, |
| 892 | .pNext = NULL, |
| 893 | .flags = 0 |
| 894 | }; |
| 895 | |
| 896 | err = xglResetCommandBuffer(staging_cmd_buf); |
| 897 | assert(!err); |
| 898 | |
| 899 | err = xglBeginCommandBuffer(staging_cmd_buf, &cmd_buf_begin_info); |
| 900 | assert(!err); |
| 901 | |
| 902 | XGL_IMAGE_COPY copy_region = { |
| 903 | .srcSubresource = { XGL_IMAGE_ASPECT_COLOR, 0, 0 }, |
| 904 | .srcOffset = { 0, 0, 0 }, |
| 905 | .destSubresource = { XGL_IMAGE_ASPECT_COLOR, 0, 0 }, |
| 906 | .destOffset = { 0, 0, 0 }, |
| 907 | .extent = { staging_texture.tex_width, staging_texture.tex_height, 1 }, |
| 908 | }; |
| 909 | xglCmdCopyImage(staging_cmd_buf, staging_texture.image, demo->textures[i].image, 1, ©_region); |
| 910 | |
| 911 | XGL_IMAGE_MEMORY_BARRIER image_memory_barrier = { |
| 912 | .sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, |
| 913 | .pNext = NULL, |
| 914 | .outputMask = XGL_MEMORY_OUTPUT_COPY_BIT, |
| 915 | .inputMask = XGL_MEMORY_INPUT_SHADER_READ_BIT | XGL_MEMORY_INPUT_COPY_BIT, |
| 916 | .oldLayout = XGL_IMAGE_LAYOUT_GENERAL, |
| 917 | .newLayout = XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, |
| 918 | .image = staging_texture.image, |
| 919 | .subresourceRange = { XGL_IMAGE_ASPECT_COLOR, 0, 1, 0, 0 } |
| 920 | }; |
| 921 | XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &image_memory_barrier; |
| 922 | |
| 923 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 924 | XGL_PIPELINE_BARRIER pipeline_barrier; |
| 925 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 926 | pipeline_barrier.pNext = NULL; |
| 927 | pipeline_barrier.eventCount = 1; |
| 928 | pipeline_barrier.pEvents = set_events; |
| 929 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 930 | pipeline_barrier.memBarrierCount = 1; |
| 931 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
| 932 | |
| 933 | // write barrier to the command buffer |
| 934 | xglCmdPipelineBarrier(staging_cmd_buf, &pipeline_barrier); |
| 935 | |
| 936 | err = xglEndCommandBuffer(staging_cmd_buf); |
| 937 | assert(!err); |
| 938 | |
| 939 | const XGL_CMD_BUFFER cmd_bufs[] = { staging_cmd_buf }; |
| 940 | XGL_MEMORY_REF mem_refs[16]; |
| 941 | uint32_t num_refs = 0; |
| 942 | |
| 943 | for (uint32_t j = 0; j < staging_texture.num_mem; j++) { |
| 944 | mem_refs[num_refs].flags = XGL_MEMORY_REF_READ_ONLY_BIT; |
| 945 | mem_refs[num_refs].mem = staging_texture.mem[j]; |
| 946 | num_refs++; |
| 947 | assert(num_refs < 16); |
| 948 | } |
| 949 | |
| 950 | for (uint32_t j = 0; j < demo->textures[i].num_mem; j++) { |
| 951 | mem_refs[num_refs].flags = XGL_MEMORY_REF_READ_ONLY_BIT; |
| 952 | mem_refs[num_refs].mem = demo->textures[i].mem[j]; |
| 953 | num_refs++; |
| 954 | assert(num_refs < 16); |
| 955 | } |
| 956 | |
| 957 | err = xglQueueSubmit(demo->queue, 1, cmd_bufs, |
| 958 | num_refs, mem_refs, XGL_NULL_HANDLE); |
| 959 | assert(!err); |
| 960 | |
| 961 | err = xglQueueWaitIdle(demo->queue); |
| 962 | assert(!err); |
| 963 | |
| 964 | demo_destroy_texture_image(&staging_texture); |
| 965 | |
| 966 | xglDestroyObject(staging_cmd_buf); |
| 967 | } else { |
| 968 | /* Can't support XGL_FMT_B8G8R8A8_UNORM !? */ |
| 969 | assert(!"No support for tB8G8R8A8_UNORM as texture image format"); |
| 970 | } |
| 971 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 972 | const XGL_SAMPLER_CREATE_INFO sampler = { |
| 973 | .sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, |
| 974 | .pNext = NULL, |
| 975 | .magFilter = XGL_TEX_FILTER_NEAREST, |
| 976 | .minFilter = XGL_TEX_FILTER_NEAREST, |
| 977 | .mipMode = XGL_TEX_MIPMAP_BASE, |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 978 | .addressU = XGL_TEX_ADDRESS_CLAMP, |
| 979 | .addressV = XGL_TEX_ADDRESS_CLAMP, |
| 980 | .addressW = XGL_TEX_ADDRESS_CLAMP, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 981 | .mipLodBias = 0.0f, |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 982 | .maxAnisotropy = 1, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 983 | .compareFunc = XGL_COMPARE_NEVER, |
| 984 | .minLod = 0.0f, |
| 985 | .maxLod = 0.0f, |
| 986 | .borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE, |
| 987 | }; |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 988 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 989 | XGL_IMAGE_VIEW_CREATE_INFO view = { |
| 990 | .sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, |
| 991 | .pNext = NULL, |
| 992 | .image = XGL_NULL_HANDLE, |
| 993 | .viewType = XGL_IMAGE_VIEW_2D, |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 994 | .format = tex_format, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 995 | .channels = { XGL_CHANNEL_SWIZZLE_R, |
| 996 | XGL_CHANNEL_SWIZZLE_G, |
| 997 | XGL_CHANNEL_SWIZZLE_B, |
| 998 | XGL_CHANNEL_SWIZZLE_A, }, |
| 999 | .subresourceRange = { XGL_IMAGE_ASPECT_COLOR, 0, 1, 0, 1 }, |
| 1000 | .minLod = 0.0f, |
| 1001 | }; |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 1002 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1003 | /* create sampler */ |
| 1004 | err = xglCreateSampler(demo->device, &sampler, |
| 1005 | &demo->textures[i].sampler); |
| 1006 | assert(!err); |
| 1007 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1008 | /* create image view */ |
| 1009 | view.image = demo->textures[i].image; |
| 1010 | err = xglCreateImageView(demo->device, &view, |
| 1011 | &demo->textures[i].view); |
| 1012 | assert(!err); |
| 1013 | } |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1014 | } |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1015 | |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1016 | void demo_prepare_cube_data_buffer(struct demo *demo) |
| 1017 | { |
Chia-I Wu | 8ea21c7 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1018 | XGL_BUFFER_CREATE_INFO buf_info; |
| 1019 | XGL_BUFFER_VIEW_CREATE_INFO view_info; |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1020 | XGL_MEMORY_ALLOC_BUFFER_INFO buf_alloc = { |
| 1021 | .sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_BUFFER_INFO, |
| 1022 | .pNext = NULL, |
| 1023 | }; |
| 1024 | XGL_MEMORY_ALLOC_INFO alloc_info = { |
| 1025 | .sType = XGL_STRUCTURE_TYPE_MEMORY_ALLOC_INFO, |
| 1026 | .pNext = &buf_alloc, |
| 1027 | .allocationSize = 0, |
Jon Ashburn | c483a8c | 2015-01-20 13:55:32 -0700 | [diff] [blame] | 1028 | .memProps = XGL_MEMORY_PROPERTY_CPU_VISIBLE_BIT, |
Jon Ashburn | bdee4e8 | 2015-01-20 15:06:59 -0700 | [diff] [blame] | 1029 | .memType = XGL_MEMORY_TYPE_BUFFER, |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1030 | .memPriority = XGL_MEMORY_PRIORITY_NORMAL, |
| 1031 | }; |
| 1032 | XGL_MEMORY_REQUIREMENTS *mem_reqs; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1033 | size_t mem_reqs_size = sizeof(XGL_MEMORY_REQUIREMENTS); |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1034 | XGL_BUFFER_MEMORY_REQUIREMENTS buf_reqs; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1035 | size_t buf_reqs_size = sizeof(XGL_BUFFER_MEMORY_REQUIREMENTS); |
| 1036 | uint32_t num_allocations = 0; |
| 1037 | size_t num_alloc_size = sizeof(num_allocations); |
| 1038 | uint8_t *pData; |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1039 | int i; |
| 1040 | mat4x4 MVP, VP; |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1041 | XGL_RESULT err; |
| 1042 | struct xgltexcube_vs_uniform data; |
| 1043 | |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1044 | mat4x4_mul(VP, demo->projection_matrix, demo->view_matrix); |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1045 | mat4x4_mul(MVP, VP, demo->model_matrix); |
| 1046 | memcpy(data.mvp, MVP, sizeof(MVP)); |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1047 | // dumpMatrix("MVP", MVP); |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1048 | |
| 1049 | for (i=0; i<12*3; i++) { |
| 1050 | data.position[i][0] = g_vertex_buffer_data[i*3]; |
| 1051 | data.position[i][1] = g_vertex_buffer_data[i*3+1]; |
| 1052 | data.position[i][2] = g_vertex_buffer_data[i*3+2]; |
| 1053 | data.position[i][3] = 1.0f; |
| 1054 | data.attr[i][0] = g_uv_buffer_data[2*i]; |
| 1055 | data.attr[i][1] = g_uv_buffer_data[2*i + 1]; |
| 1056 | data.attr[i][2] = 0; |
| 1057 | data.attr[i][3] = 0; |
| 1058 | } |
| 1059 | |
Chia-I Wu | 8ea21c7 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1060 | memset(&buf_info, 0, sizeof(buf_info)); |
| 1061 | buf_info.sType = XGL_STRUCTURE_TYPE_BUFFER_CREATE_INFO; |
| 1062 | buf_info.size = sizeof(data); |
| 1063 | buf_info.usage = XGL_BUFFER_USAGE_UNIFORM_READ_BIT; |
| 1064 | err = xglCreateBuffer(demo->device, &buf_info, &demo->uniform_data.buf); |
| 1065 | assert(!err); |
| 1066 | |
| 1067 | err = xglGetObjectInfo(demo->uniform_data.buf, |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1068 | XGL_INFO_TYPE_MEMORY_ALLOCATION_COUNT, |
| 1069 | &num_alloc_size, &num_allocations); |
| 1070 | assert(!err && num_alloc_size == sizeof(num_allocations)); |
| 1071 | mem_reqs = malloc(num_allocations * sizeof(XGL_MEMORY_REQUIREMENTS)); |
| 1072 | demo->uniform_data.mem = malloc(num_allocations * sizeof(XGL_GPU_MEMORY)); |
| 1073 | demo->uniform_data.num_mem = num_allocations; |
| 1074 | err = xglGetObjectInfo(demo->uniform_data.buf, |
Chia-I Wu | 8ea21c7 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1075 | XGL_INFO_TYPE_MEMORY_REQUIREMENTS, |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1076 | &mem_reqs_size, mem_reqs); |
| 1077 | assert(!err && mem_reqs_size == num_allocations * sizeof(*mem_reqs)); |
| 1078 | err = xglGetObjectInfo(demo->uniform_data.buf, |
| 1079 | XGL_INFO_TYPE_BUFFER_MEMORY_REQUIREMENTS, |
| 1080 | &buf_reqs_size, &buf_reqs); |
| 1081 | assert(!err && buf_reqs_size == sizeof(XGL_BUFFER_MEMORY_REQUIREMENTS)); |
| 1082 | buf_alloc.usage = buf_reqs.usage; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1083 | for (uint32_t i = 0; i < num_allocations; i ++) { |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1084 | alloc_info.allocationSize = mem_reqs[i].size; |
Chia-I Wu | 8ea21c7 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1085 | |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1086 | err = xglAllocMemory(demo->device, &alloc_info, &(demo->uniform_data.mem[i])); |
| 1087 | assert(!err); |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1088 | |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1089 | err = xglMapMemory(demo->uniform_data.mem[i], 0, (void **) &pData); |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1090 | assert(!err); |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1091 | |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1092 | memcpy(pData, &data, alloc_info.allocationSize); |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1093 | |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1094 | err = xglUnmapMemory(demo->uniform_data.mem[i]); |
| 1095 | assert(!err); |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1096 | |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1097 | err = xglBindObjectMemory(demo->uniform_data.buf, i, |
| 1098 | demo->uniform_data.mem[i], 0); |
| 1099 | assert(!err); |
| 1100 | } |
Chia-I Wu | 8ea21c7 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1101 | |
| 1102 | memset(&view_info, 0, sizeof(view_info)); |
| 1103 | view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 1104 | view_info.buffer = demo->uniform_data.buf; |
Chia-I Wu | 378caea | 2015-01-16 22:31:25 +0800 | [diff] [blame] | 1105 | view_info.viewType = XGL_BUFFER_VIEW_RAW; |
Chia-I Wu | 8ea21c7 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1106 | view_info.offset = 0; |
| 1107 | view_info.range = sizeof(data); |
| 1108 | |
| 1109 | err = xglCreateBufferView(demo->device, &view_info, &demo->uniform_data.view); |
| 1110 | assert(!err); |
| 1111 | |
| 1112 | demo->uniform_data.attach.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO; |
| 1113 | demo->uniform_data.attach.view = demo->uniform_data.view; |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1114 | } |
| 1115 | |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1116 | static void demo_prepare_descriptor_layout(struct demo *demo) |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1117 | { |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1118 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO descriptor_layout_fs = { |
| 1119 | .sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1120 | .pNext = NULL, |
| 1121 | .descriptorType = XGL_DESCRIPTOR_TYPE_SAMPLER_TEXTURE, |
| 1122 | .count = DEMO_TEXTURE_COUNT, |
| 1123 | .stageFlags = XGL_SHADER_STAGE_FLAGS_FRAGMENT_BIT, |
| 1124 | .immutableSampler = XGL_NULL_HANDLE, |
| 1125 | }; |
Chia-I Wu | 87544e7 | 2015-02-23 10:41:08 -0700 | [diff] [blame] | 1126 | const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO descriptor_layout_vs = { |
| 1127 | .sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 1128 | .pNext = &descriptor_layout_fs, |
| 1129 | .descriptorType = XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 1130 | .count = 1, |
| 1131 | .stageFlags = XGL_SHADER_STAGE_FLAGS_VERTEX_BIT, |
| 1132 | .immutableSampler = XGL_NULL_HANDLE, |
| 1133 | }; |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1134 | const uint32_t bind_point = 0; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1135 | XGL_RESULT err; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1136 | |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1137 | err = xglCreateDescriptorSetLayout(demo->device, |
Chia-I Wu | 87544e7 | 2015-02-23 10:41:08 -0700 | [diff] [blame] | 1138 | XGL_SHADER_STAGE_FLAGS_ALL, &bind_point, |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1139 | XGL_NULL_HANDLE, &descriptor_layout_vs, |
Chia-I Wu | 87544e7 | 2015-02-23 10:41:08 -0700 | [diff] [blame] | 1140 | &demo->desc_layout); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1141 | assert(!err); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | static XGL_SHADER demo_prepare_shader(struct demo *demo, |
| 1145 | XGL_PIPELINE_SHADER_STAGE stage, |
| 1146 | const void *code, |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1147 | size_t size) |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1148 | { |
| 1149 | XGL_SHADER_CREATE_INFO createInfo; |
| 1150 | XGL_SHADER shader; |
| 1151 | XGL_RESULT err; |
| 1152 | |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1153 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1154 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 1155 | createInfo.pNext = NULL; |
| 1156 | |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1157 | #ifdef EXTERNAL_BIL |
| 1158 | createInfo.codeSize = size; |
| 1159 | createInfo.pCode = code; |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 1160 | createInfo.flags = 0; |
| 1161 | |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 1162 | err = xglCreateShader(demo->device, &createInfo, &shader); |
| 1163 | if (err) { |
| 1164 | free((void *) createInfo.pCode); |
| 1165 | } |
| 1166 | #else |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1167 | // Create fake BIL structure to feed GLSL |
| 1168 | // to the driver "under the covers" |
| 1169 | createInfo.codeSize = 3 * sizeof(uint32_t) + size + 1; |
| 1170 | createInfo.pCode = malloc(createInfo.codeSize); |
| 1171 | createInfo.flags = 0; |
| 1172 | |
| 1173 | /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */ |
| 1174 | ((uint32_t *) createInfo.pCode)[0] = ICD_BIL_MAGIC; |
| 1175 | ((uint32_t *) createInfo.pCode)[1] = 0; |
| 1176 | ((uint32_t *) createInfo.pCode)[2] = stage; |
| 1177 | memcpy(((uint32_t *) createInfo.pCode + 3), code, size + 1); |
| 1178 | |
| 1179 | err = xglCreateShader(demo->device, &createInfo, &shader); |
| 1180 | if (err) { |
| 1181 | free((void *) createInfo.pCode); |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1182 | return NULL; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1183 | } |
Courtney Goeltzenleuchter | 6836939 | 2014-10-29 15:59:49 -0600 | [diff] [blame] | 1184 | #endif |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1185 | |
| 1186 | return shader; |
| 1187 | } |
| 1188 | |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1189 | char *demo_read_bil(const char *filename, size_t *psize) |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1190 | { |
| 1191 | long int size; |
| 1192 | void *shader_code; |
| 1193 | |
| 1194 | FILE *fp = fopen(filename, "rb"); |
| 1195 | if (!fp) return NULL; |
| 1196 | |
| 1197 | fseek(fp, 0L, SEEK_END); |
| 1198 | size = ftell(fp); |
| 1199 | |
| 1200 | fseek(fp, 0L, SEEK_SET); |
| 1201 | |
| 1202 | shader_code = malloc(size); |
| 1203 | fread(shader_code, size, 1, fp); |
| 1204 | |
| 1205 | *psize = size; |
| 1206 | |
| 1207 | return shader_code; |
| 1208 | } |
| 1209 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1210 | static XGL_SHADER demo_prepare_vs(struct demo *demo) |
| 1211 | { |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1212 | #ifdef EXTERNAL_BIL |
| 1213 | void *vertShaderCode; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1214 | size_t size; |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1215 | |
| 1216 | vertShaderCode = demo_read_bil("cube-vert.bil", &size); |
| 1217 | |
| 1218 | return demo_prepare_shader(demo, XGL_SHADER_STAGE_VERTEX, |
| 1219 | vertShaderCode, size); |
| 1220 | #else |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1221 | static const char *vertShaderText = |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1222 | "#version 140\n" |
| 1223 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1224 | "#extension GL_ARB_shading_language_420pack : enable\n" |
| 1225 | "\n" |
| 1226 | "layout(binding = 0) uniform buf {\n" |
| 1227 | " mat4 MVP;\n" |
| 1228 | " vec4 position[12*3];\n" |
| 1229 | " vec4 attr[12*3];\n" |
| 1230 | "} ubuf;\n" |
| 1231 | "\n" |
| 1232 | "layout (location = 0) out vec4 texcoord;\n" |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1233 | "\n" |
| 1234 | "void main() \n" |
| 1235 | "{\n" |
| 1236 | " texcoord = ubuf.attr[gl_VertexID];\n" |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1237 | " gl_Position = ubuf.MVP * ubuf.position[gl_VertexID];\n" |
| 1238 | "}\n"; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1239 | |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1240 | return demo_prepare_shader(demo, XGL_SHADER_STAGE_VERTEX, |
| 1241 | (const void *) vertShaderText, |
| 1242 | strlen(vertShaderText)); |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1243 | #endif |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | static XGL_SHADER demo_prepare_fs(struct demo *demo) |
| 1247 | { |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1248 | #ifdef EXTERNAL_BIL |
| 1249 | void *fragShaderCode; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1250 | size_t size; |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1251 | |
| 1252 | fragShaderCode = demo_read_bil("cube-frag.bil", &size); |
| 1253 | |
| 1254 | return demo_prepare_shader(demo, XGL_SHADER_STAGE_FRAGMENT, |
| 1255 | fragShaderCode, size); |
| 1256 | #else |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1257 | static const char *fragShaderText = |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1258 | "#version 140\n" |
| 1259 | "#extension GL_ARB_separate_shader_objects : enable\n" |
| 1260 | "#extension GL_ARB_shading_language_420pack : enable\n" |
Courtney Goeltzenleuchter | 4d1acf1 | 2015-02-25 15:13:35 -0700 | [diff] [blame^] | 1261 | "layout (binding = 1) uniform sampler2D tex;\n" |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1262 | "\n" |
| 1263 | "layout (location = 0) in vec4 texcoord;\n" |
| 1264 | "void main() {\n" |
| 1265 | " gl_FragColor = texture(tex, texcoord.xy);\n" |
| 1266 | "}\n"; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1267 | |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1268 | return demo_prepare_shader(demo, XGL_SHADER_STAGE_FRAGMENT, |
| 1269 | (const void *) fragShaderText, |
| 1270 | strlen(fragShaderText)); |
Courtney Goeltzenleuchter | 97db1c1 | 2014-10-30 15:14:16 -0600 | [diff] [blame] | 1271 | #endif |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | static void demo_prepare_pipeline(struct demo *demo) |
| 1275 | { |
| 1276 | XGL_GRAPHICS_PIPELINE_CREATE_INFO pipeline; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1277 | XGL_PIPELINE_IA_STATE_CREATE_INFO ia; |
| 1278 | XGL_PIPELINE_RS_STATE_CREATE_INFO rs; |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1279 | XGL_PIPELINE_CB_STATE_CREATE_INFO cb; |
| 1280 | XGL_PIPELINE_DS_STATE_CREATE_INFO ds; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1281 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs; |
| 1282 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO fs; |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1283 | XGL_PIPELINE_VP_STATE_CREATE_INFO vp; |
| 1284 | XGL_PIPELINE_MS_STATE_CREATE_INFO ms; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1285 | XGL_RESULT err; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1286 | |
| 1287 | memset(&pipeline, 0, sizeof(pipeline)); |
| 1288 | pipeline.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
Chia-I Wu | 87544e7 | 2015-02-23 10:41:08 -0700 | [diff] [blame] | 1289 | pipeline.lastSetLayout = demo->desc_layout; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1290 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1291 | memset(&ia, 0, sizeof(ia)); |
| 1292 | ia.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO; |
| 1293 | ia.topology = XGL_TOPOLOGY_TRIANGLE_LIST; |
| 1294 | |
| 1295 | memset(&rs, 0, sizeof(rs)); |
| 1296 | rs.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO; |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1297 | rs.fillMode = XGL_FILL_SOLID; |
| 1298 | rs.cullMode = XGL_CULL_NONE; |
| 1299 | rs.frontFace = XGL_FRONT_FACE_CCW; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1300 | |
| 1301 | memset(&cb, 0, sizeof(cb)); |
| 1302 | cb.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO; |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1303 | XGL_PIPELINE_CB_ATTACHMENT_STATE att_state[1]; |
| 1304 | memset(att_state, 0, sizeof(att_state)); |
| 1305 | att_state[0].format = demo->format; |
| 1306 | att_state[0].channelWriteMask = 0xf; |
| 1307 | att_state[0].blendEnable = XGL_FALSE; |
| 1308 | cb.attachmentCount = 1; |
| 1309 | cb.pAttachments = att_state; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1310 | |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1311 | memset(&vp, 0, sizeof(vp)); |
| 1312 | vp.sType = XGL_STRUCTURE_TYPE_PIPELINE_VP_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 1313 | vp.numViewports = 1; |
| 1314 | vp.clipOrigin = XGL_COORDINATE_ORIGIN_UPPER_LEFT; |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1315 | |
| 1316 | memset(&ds, 0, sizeof(ds)); |
| 1317 | ds.sType = XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO; |
| 1318 | ds.format = demo->depth.format; |
| 1319 | ds.depthTestEnable = XGL_TRUE; |
| 1320 | ds.depthWriteEnable = XGL_TRUE; |
| 1321 | ds.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 1322 | ds.depthBoundsEnable = XGL_FALSE; |
| 1323 | ds.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 1324 | ds.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 1325 | ds.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 1326 | ds.stencilTestEnable = XGL_FALSE; |
| 1327 | ds.front = ds.back; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1328 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1329 | memset(&vs, 0, sizeof(vs)); |
| 1330 | vs.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1331 | vs.shader.stage = XGL_SHADER_STAGE_VERTEX; |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1332 | vs.shader.shader = demo_prepare_vs(demo); |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1333 | assert(vs.shader.shader != NULL); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1334 | |
| 1335 | memset(&fs, 0, sizeof(fs)); |
| 1336 | fs.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 1337 | fs.shader.stage = XGL_SHADER_STAGE_FRAGMENT; |
| 1338 | fs.shader.shader = demo_prepare_fs(demo); |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1339 | assert(fs.shader.shader != NULL); |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1340 | |
| 1341 | memset(&ms, 0, sizeof(ms)); |
| 1342 | ms.sType = XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO; |
| 1343 | ms.sampleMask = 1; |
| 1344 | ms.multisampleEnable = XGL_FALSE; |
| 1345 | ms.samples = 1; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1346 | |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1347 | pipeline.pNext = (const void *) &ia; |
| 1348 | ia.pNext = (const void *) &rs; |
| 1349 | rs.pNext = (const void *) &cb; |
| 1350 | cb.pNext = (const void *) &ms; |
| 1351 | ms.pNext = (const void *) &vp; |
| 1352 | vp.pNext = (const void *) &ds; |
| 1353 | ds.pNext = (const void *) &vs; |
| 1354 | vs.pNext = (const void *) &fs; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1355 | |
| 1356 | err = xglCreateGraphicsPipeline(demo->device, &pipeline, &demo->pipeline); |
| 1357 | assert(!err); |
| 1358 | |
| 1359 | xglDestroyObject(vs.shader.shader); |
| 1360 | xglDestroyObject(fs.shader.shader); |
| 1361 | } |
| 1362 | |
| 1363 | static void demo_prepare_dynamic_states(struct demo *demo) |
| 1364 | { |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1365 | XGL_DYNAMIC_VP_STATE_CREATE_INFO viewport_create; |
| 1366 | XGL_DYNAMIC_RS_STATE_CREATE_INFO raster; |
| 1367 | XGL_DYNAMIC_CB_STATE_CREATE_INFO color_blend; |
| 1368 | XGL_DYNAMIC_DS_STATE_CREATE_INFO depth_stencil; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1369 | XGL_RESULT err; |
| 1370 | |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1371 | memset(&viewport_create, 0, sizeof(viewport_create)); |
| 1372 | viewport_create.sType = XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 1710d8d | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 1373 | viewport_create.viewportAndScissorCount = 1; |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1374 | XGL_VIEWPORT viewport; |
Courtney Goeltzenleuchter | 1710d8d | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 1375 | XGL_RECT scissor; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1376 | viewport.height = (float) demo->height; |
| 1377 | viewport.width = (float) demo->width; |
| 1378 | viewport.minDepth = (float) 0.0f; |
| 1379 | viewport.maxDepth = (float) 1.0f; |
Courtney Goeltzenleuchter | 1710d8d | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 1380 | scissor.extent.width = demo->width; |
| 1381 | scissor.extent.height = demo->height; |
| 1382 | scissor.offset.x = 0; |
| 1383 | scissor.offset.y = 0; |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1384 | viewport_create.pViewports = &viewport; |
Courtney Goeltzenleuchter | 1710d8d | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 1385 | viewport_create.pScissors = &scissor; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1386 | |
| 1387 | memset(&raster, 0, sizeof(raster)); |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1388 | raster.sType = XGL_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1389 | |
| 1390 | memset(&color_blend, 0, sizeof(color_blend)); |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1391 | color_blend.sType = XGL_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1392 | |
| 1393 | memset(&depth_stencil, 0, sizeof(depth_stencil)); |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1394 | depth_stencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO; |
| 1395 | depth_stencil.stencilBackRef = 0; |
| 1396 | depth_stencil.stencilFrontRef = 0; |
| 1397 | depth_stencil.stencilReadMask = 0xff; |
| 1398 | depth_stencil.stencilWriteMask = 0xff; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1399 | |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1400 | err = xglCreateDynamicViewportState(demo->device, &viewport_create, &demo->viewport); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1401 | assert(!err); |
| 1402 | |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1403 | err = xglCreateDynamicRasterState(demo->device, &raster, &demo->raster); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1404 | assert(!err); |
| 1405 | |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1406 | err = xglCreateDynamicColorBlendState(demo->device, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1407 | &color_blend, &demo->color_blend); |
| 1408 | assert(!err); |
| 1409 | |
Tony Barbour | 29645d0 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1410 | err = xglCreateDynamicDepthStencilState(demo->device, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1411 | &depth_stencil, &demo->depth_stencil); |
| 1412 | assert(!err); |
| 1413 | } |
| 1414 | |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1415 | static void demo_prepare_descriptor_region(struct demo *demo) |
| 1416 | { |
| 1417 | const XGL_DESCRIPTOR_TYPE_COUNT type_counts[2] = { |
| 1418 | [0] = { |
| 1419 | .type = XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER, |
| 1420 | .count = 1, |
| 1421 | }, |
| 1422 | [1] = { |
| 1423 | .type = XGL_DESCRIPTOR_TYPE_SAMPLER_TEXTURE, |
| 1424 | .count = DEMO_TEXTURE_COUNT, |
| 1425 | }, |
| 1426 | }; |
| 1427 | const XGL_DESCRIPTOR_REGION_CREATE_INFO descriptor_region = { |
| 1428 | .sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_REGION_CREATE_INFO, |
| 1429 | .pNext = NULL, |
| 1430 | .count = 2, |
| 1431 | .pTypeCount = type_counts, |
| 1432 | }; |
| 1433 | XGL_RESULT err; |
| 1434 | |
| 1435 | err = xglCreateDescriptorRegion(demo->device, |
| 1436 | XGL_DESCRIPTOR_REGION_USAGE_ONE_SHOT, 1, |
| 1437 | &descriptor_region, &demo->desc_region); |
| 1438 | assert(!err); |
| 1439 | } |
| 1440 | |
| 1441 | static void demo_prepare_descriptor_set(struct demo *demo) |
| 1442 | { |
| 1443 | const XGL_BUFFER_VIEW_ATTACH_INFO *view_info_vs = |
| 1444 | &demo->uniform_data.attach; |
| 1445 | XGL_IMAGE_VIEW_ATTACH_INFO view_info[DEMO_TEXTURE_COUNT]; |
| 1446 | XGL_SAMPLER_IMAGE_VIEW_INFO combined_info[DEMO_TEXTURE_COUNT]; |
| 1447 | XGL_UPDATE_SAMPLER_TEXTURES update_fs; |
| 1448 | XGL_UPDATE_BUFFERS update_vs; |
| 1449 | XGL_RESULT err; |
| 1450 | uint32_t count; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1451 | uint32_t i; |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1452 | |
| 1453 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
| 1454 | view_info[i].sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 1455 | view_info[i].pNext = NULL; |
| 1456 | view_info[i].view = demo->textures[i].view, |
| 1457 | view_info[i].layout = XGL_IMAGE_LAYOUT_GENERAL; |
| 1458 | |
| 1459 | combined_info[i].pSampler = demo->textures[i].sampler; |
| 1460 | combined_info[i].pImageView = &view_info[i]; |
| 1461 | } |
| 1462 | |
| 1463 | memset(&update_vs, 0, sizeof(update_vs)); |
| 1464 | update_vs.sType = XGL_STRUCTURE_TYPE_UPDATE_BUFFERS; |
| 1465 | update_vs.pNext = &update_fs; |
| 1466 | update_vs.descriptorType = XGL_DESCRIPTOR_TYPE_UNIFORM_BUFFER; |
| 1467 | update_vs.count = 1; |
| 1468 | update_vs.pBufferViews = &view_info_vs; |
| 1469 | |
| 1470 | memset(&update_fs, 0, sizeof(update_fs)); |
| 1471 | update_fs.sType = XGL_STRUCTURE_TYPE_UPDATE_SAMPLER_TEXTURES; |
| 1472 | update_fs.index = 1; |
| 1473 | update_fs.count = DEMO_TEXTURE_COUNT; |
| 1474 | update_fs.pSamplerImageViews = combined_info; |
| 1475 | |
| 1476 | err = xglAllocDescriptorSets(demo->desc_region, |
| 1477 | XGL_DESCRIPTOR_SET_USAGE_STATIC, |
Chia-I Wu | 87544e7 | 2015-02-23 10:41:08 -0700 | [diff] [blame] | 1478 | 1, &demo->desc_layout, |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1479 | &demo->desc_set, &count); |
| 1480 | assert(!err && count == 1); |
| 1481 | |
| 1482 | xglBeginDescriptorRegionUpdate(demo->device, |
| 1483 | XGL_DESCRIPTOR_UPDATE_MODE_FASTEST); |
| 1484 | |
| 1485 | xglClearDescriptorSets(demo->desc_region, 1, &demo->desc_set); |
| 1486 | xglUpdateDescriptors(demo->desc_set, &update_vs); |
| 1487 | |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 1488 | xglEndDescriptorRegionUpdate(demo->device, demo->buffers[demo->current_buffer].cmd); |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1489 | } |
| 1490 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1491 | static void demo_prepare(struct demo *demo) |
| 1492 | { |
| 1493 | const XGL_CMD_BUFFER_CREATE_INFO cmd = { |
| 1494 | .sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO, |
| 1495 | .pNext = NULL, |
| 1496 | .queueType = XGL_QUEUE_TYPE_GRAPHICS, |
| 1497 | .flags = 0, |
| 1498 | }; |
| 1499 | XGL_RESULT err; |
| 1500 | |
| 1501 | demo_prepare_buffers(demo); |
| 1502 | demo_prepare_depth(demo); |
| 1503 | demo_prepare_textures(demo); |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1504 | demo_prepare_cube_data_buffer(demo); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1505 | |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1506 | demo_prepare_descriptor_layout(demo); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1507 | demo_prepare_pipeline(demo); |
| 1508 | demo_prepare_dynamic_states(demo); |
| 1509 | |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 1510 | for (int i = 0; i < DEMO_BUFFER_COUNT; i++) { |
| 1511 | err = xglCreateCommandBuffer(demo->device, &cmd, &demo->buffers[i].cmd); |
| 1512 | assert(!err); |
| 1513 | } |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1514 | |
| 1515 | demo_prepare_descriptor_region(demo); |
| 1516 | demo_prepare_descriptor_set(demo); |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 1517 | |
| 1518 | |
| 1519 | for (int i = 0; i < DEMO_BUFFER_COUNT; i++) { |
| 1520 | demo->current_buffer = i; |
| 1521 | demo_draw_build_cmd(demo, demo->buffers[i].cmd); |
| 1522 | } |
| 1523 | |
| 1524 | demo->current_buffer = 0; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | static void demo_handle_event(struct demo *demo, |
| 1528 | const xcb_generic_event_t *event) |
| 1529 | { |
Courtney Goeltzenleuchter | 98cb2cb | 2014-11-06 14:27:52 -0700 | [diff] [blame] | 1530 | u_int8_t event_code = event->response_type & 0x7f; |
| 1531 | switch (event_code) { |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1532 | case XCB_EXPOSE: |
Courtney Goeltzenleuchter | c465d6c | 2014-11-18 11:28:09 -0700 | [diff] [blame] | 1533 | // TODO: Resize window |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1534 | break; |
Courtney Goeltzenleuchter | 98cb2cb | 2014-11-06 14:27:52 -0700 | [diff] [blame] | 1535 | case XCB_CLIENT_MESSAGE: |
| 1536 | if((*(xcb_client_message_event_t*)event).data.data32[0] == |
| 1537 | (*demo->atom_wm_delete_window).atom) { |
| 1538 | demo->quit = true; |
| 1539 | } |
| 1540 | break; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1541 | case XCB_KEY_RELEASE: |
| 1542 | { |
| 1543 | const xcb_key_release_event_t *key = |
| 1544 | (const xcb_key_release_event_t *) event; |
| 1545 | |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1546 | switch (key->detail) { |
| 1547 | case 0x9: // Escape |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1548 | demo->quit = true; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1549 | break; |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1550 | case 0x71: // left arrow key |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1551 | demo->spin_angle += demo->spin_increment; |
Courtney Goeltzenleuchter | 4984d15 | 2014-10-28 14:50:30 -0600 | [diff] [blame] | 1552 | break; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1553 | case 0x72: // right arrow key |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1554 | demo->spin_angle -= demo->spin_increment; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1555 | break; |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1556 | case 0x41: |
| 1557 | demo->pause = !demo->pause; |
| 1558 | break; |
Courtney Goeltzenleuchter | fc3b953 | 2014-10-28 10:32:57 -0600 | [diff] [blame] | 1559 | } |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1560 | } |
| 1561 | break; |
| 1562 | default: |
| 1563 | break; |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | static void demo_run(struct demo *demo) |
| 1568 | { |
| 1569 | xcb_flush(demo->connection); |
| 1570 | |
| 1571 | while (!demo->quit) { |
| 1572 | xcb_generic_event_t *event; |
| 1573 | |
Courtney Goeltzenleuchter | c465d6c | 2014-11-18 11:28:09 -0700 | [diff] [blame] | 1574 | if (demo->pause) { |
| 1575 | event = xcb_wait_for_event(demo->connection); |
| 1576 | } else { |
| 1577 | event = xcb_poll_for_event(demo->connection); |
| 1578 | } |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1579 | if (event) { |
| 1580 | demo_handle_event(demo, event); |
| 1581 | free(event); |
Courtney Goeltzenleuchter | 9808555 | 2014-11-10 11:13:13 -0700 | [diff] [blame] | 1582 | } |
Courtney Goeltzenleuchter | c465d6c | 2014-11-18 11:28:09 -0700 | [diff] [blame] | 1583 | |
| 1584 | // Wait for work to finish before updating MVP. |
| 1585 | xglDeviceWaitIdle(demo->device); |
| 1586 | demo_update_data_buffer(demo); |
| 1587 | |
Courtney Goeltzenleuchter | 9808555 | 2014-11-10 11:13:13 -0700 | [diff] [blame] | 1588 | demo_draw(demo); |
Courtney Goeltzenleuchter | 1454f3c | 2014-11-18 11:28:09 -0700 | [diff] [blame] | 1589 | |
Courtney Goeltzenleuchter | 9808555 | 2014-11-10 11:13:13 -0700 | [diff] [blame] | 1590 | // Wait for work to finish before updating MVP. |
| 1591 | xglDeviceWaitIdle(demo->device); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | static void demo_create_window(struct demo *demo) |
| 1596 | { |
| 1597 | uint32_t value_mask, value_list[32]; |
| 1598 | |
| 1599 | demo->window = xcb_generate_id(demo->connection); |
| 1600 | |
| 1601 | value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; |
| 1602 | value_list[0] = demo->screen->black_pixel; |
| 1603 | value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | |
| 1604 | XCB_EVENT_MASK_EXPOSURE; |
| 1605 | |
| 1606 | xcb_create_window(demo->connection, |
| 1607 | XCB_COPY_FROM_PARENT, |
| 1608 | demo->window, demo->screen->root, |
| 1609 | 0, 0, demo->width, demo->height, 0, |
| 1610 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
| 1611 | demo->screen->root_visual, |
| 1612 | value_mask, value_list); |
| 1613 | |
Courtney Goeltzenleuchter | 98cb2cb | 2014-11-06 14:27:52 -0700 | [diff] [blame] | 1614 | /* Magic code that will send notification when window is destroyed */ |
| 1615 | xcb_intern_atom_cookie_t cookie = xcb_intern_atom(demo->connection, 1, 12, |
| 1616 | "WM_PROTOCOLS"); |
| 1617 | xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(demo->connection, cookie, 0); |
| 1618 | |
| 1619 | xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(demo->connection, 0, 16, "WM_DELETE_WINDOW"); |
| 1620 | demo->atom_wm_delete_window = xcb_intern_atom_reply(demo->connection, cookie2, 0); |
| 1621 | |
| 1622 | xcb_change_property(demo->connection, XCB_PROP_MODE_REPLACE, |
| 1623 | demo->window, (*reply).atom, 4, 32, 1, |
| 1624 | &(*demo->atom_wm_delete_window).atom); |
| 1625 | free(reply); |
| 1626 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1627 | xcb_map_window(demo->connection, demo->window); |
| 1628 | } |
| 1629 | |
| 1630 | static void demo_init_xgl(struct demo *demo) |
| 1631 | { |
| 1632 | const XGL_APPLICATION_INFO app = { |
| 1633 | .sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO, |
| 1634 | .pNext = NULL, |
Chia-I Wu | b2c8193 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 1635 | .pAppName = "cube", |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1636 | .appVersion = 0, |
Chia-I Wu | b2c8193 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 1637 | .pEngineName = "cube", |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1638 | .engineVersion = 0, |
Courtney Goeltzenleuchter | 97a89c4 | 2015-02-23 17:40:15 -0700 | [diff] [blame] | 1639 | .apiVersion = XGL_API_VERSION, |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1640 | }; |
| 1641 | const XGL_WSI_X11_CONNECTION_INFO connection = { |
| 1642 | .pConnection = demo->connection, |
| 1643 | .root = demo->screen->root, |
| 1644 | .provider = 0, |
| 1645 | }; |
| 1646 | const XGL_DEVICE_QUEUE_CREATE_INFO queue = { |
| 1647 | .queueNodeIndex = 0, |
| 1648 | .queueCount = 1, |
| 1649 | }; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1650 | const char *ext_names[] = { |
Chia-I Wu | b2c8193 | 2014-12-27 15:16:07 +0800 | [diff] [blame] | 1651 | "XGL_WSI_X11", |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1652 | }; |
| 1653 | const XGL_DEVICE_CREATE_INFO device = { |
| 1654 | .sType = XGL_STRUCTURE_TYPE_DEVICE_CREATE_INFO, |
| 1655 | .pNext = NULL, |
| 1656 | .queueRecordCount = 1, |
| 1657 | .pRequestedQueues = &queue, |
| 1658 | .extensionCount = 1, |
| 1659 | .ppEnabledExtensionNames = ext_names, |
| 1660 | .maxValidationLevel = XGL_VALIDATION_LEVEL_END_RANGE, |
| 1661 | .flags = XGL_DEVICE_CREATE_VALIDATION_BIT, |
| 1662 | }; |
| 1663 | XGL_RESULT err; |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1664 | uint32_t gpu_count; |
| 1665 | uint32_t i; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1666 | |
Jon Ashburn | 93cfc43 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 1667 | err = xglCreateInstance(&app, NULL, &demo->inst); |
| 1668 | assert(!err); |
| 1669 | err = xglEnumerateGpus(demo->inst, 1, &gpu_count, &demo->gpu); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1670 | assert(!err && gpu_count == 1); |
| 1671 | |
| 1672 | for (i = 0; i < device.extensionCount; i++) { |
| 1673 | err = xglGetExtensionSupport(demo->gpu, ext_names[i]); |
| 1674 | assert(!err); |
| 1675 | } |
| 1676 | |
| 1677 | err = xglWsiX11AssociateConnection(demo->gpu, &connection); |
| 1678 | assert(!err); |
| 1679 | |
| 1680 | err = xglCreateDevice(demo->gpu, &device, &demo->device); |
| 1681 | assert(!err); |
| 1682 | |
| 1683 | err = xglGetDeviceQueue(demo->device, XGL_QUEUE_TYPE_GRAPHICS, |
| 1684 | 0, &demo->queue); |
| 1685 | assert(!err); |
| 1686 | } |
| 1687 | |
| 1688 | static void demo_init_connection(struct demo *demo) |
| 1689 | { |
| 1690 | const xcb_setup_t *setup; |
| 1691 | xcb_screen_iterator_t iter; |
| 1692 | int scr; |
| 1693 | |
| 1694 | demo->connection = xcb_connect(NULL, &scr); |
| 1695 | |
| 1696 | setup = xcb_get_setup(demo->connection); |
| 1697 | iter = xcb_setup_roots_iterator(setup); |
| 1698 | while (scr-- > 0) |
| 1699 | xcb_screen_next(&iter); |
| 1700 | |
| 1701 | demo->screen = iter.data; |
| 1702 | } |
| 1703 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 1704 | static void demo_init(struct demo *demo, int argc, char **argv) |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1705 | { |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1706 | vec3 eye = {0.0f, 3.0f, 5.0f}; |
| 1707 | vec3 origin = {0, 0, 0}; |
| 1708 | vec3 up = {0.0f, -1.0f, 0.0}; |
| 1709 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1710 | memset(demo, 0, sizeof(*demo)); |
| 1711 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 1712 | for (int i = 0; i < argc; i++) { |
| 1713 | if (strncmp(argv[i], "--use_staging", strlen("--use_staging")) == 0) |
| 1714 | demo->use_staging_buffer = true; |
| 1715 | } |
| 1716 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1717 | demo_init_connection(demo); |
| 1718 | demo_init_xgl(demo); |
| 1719 | |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1720 | demo->width = 500; |
| 1721 | demo->height = 500; |
Jeremy Hayes | 9958ea8 | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1722 | demo->format = XGL_FMT_B8G8R8A8_UNORM; |
Courtney Goeltzenleuchter | 8879d3a | 2014-10-29 08:29:35 -0600 | [diff] [blame] | 1723 | |
| 1724 | demo->spin_angle = 0.01f; |
| 1725 | demo->spin_increment = 0.01f; |
| 1726 | demo->pause = false; |
| 1727 | |
| 1728 | mat4x4_perspective(demo->projection_matrix, degreesToRadians(45.0f), 1.0f, 0.1f, 100.0f); |
| 1729 | mat4x4_look_at(demo->view_matrix, eye, origin, up); |
| 1730 | mat4x4_identity(demo->model_matrix); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | static void demo_cleanup(struct demo *demo) |
| 1734 | { |
Mark Lobodzinski | c4fffc7 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1735 | uint32_t i, j; |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1736 | |
Chia-I Wu | 6a3c897 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1737 | xglDestroyObject(demo->desc_set); |
| 1738 | xglDestroyObject(demo->desc_region); |
| 1739 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1740 | xglDestroyObject(demo->viewport); |
| 1741 | xglDestroyObject(demo->raster); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1742 | xglDestroyObject(demo->color_blend); |
| 1743 | xglDestroyObject(demo->depth_stencil); |
| 1744 | |
| 1745 | xglDestroyObject(demo->pipeline); |
Chia-I Wu | 87544e7 | 2015-02-23 10:41:08 -0700 | [diff] [blame] | 1746 | xglDestroyObject(demo->desc_layout); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1747 | |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1748 | for (i = 0; i < DEMO_TEXTURE_COUNT; i++) { |
| 1749 | xglDestroyObject(demo->textures[i].view); |
Mark Lobodzinski | 7b8fee6 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1750 | xglBindObjectMemory(demo->textures[i].image, 0, XGL_NULL_HANDLE, 0); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1751 | xglDestroyObject(demo->textures[i].image); |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 1752 | for (j = 0; j < demo->textures[i].num_mem; j++) |
| 1753 | xglFreeMemory(demo->textures[i].mem[j]); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1754 | xglDestroyObject(demo->textures[i].sampler); |
| 1755 | } |
| 1756 | |
| 1757 | xglDestroyObject(demo->depth.view); |
Mark Lobodzinski | 7b8fee6 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1758 | xglBindObjectMemory(demo->depth.image, 0, XGL_NULL_HANDLE, 0); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1759 | xglDestroyObject(demo->depth.image); |
Jon Ashburn | b2a6665 | 2015-01-16 09:37:43 -0700 | [diff] [blame] | 1760 | for (j = 0; j < demo->depth.num_mem; j++) |
| 1761 | xglFreeMemory(demo->depth.mem[j]); |
Mark Lobodzinski | 7b8fee6 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1762 | |
| 1763 | xglDestroyObject(demo->uniform_data.view); |
| 1764 | xglBindObjectMemory(demo->uniform_data.buf, 0, XGL_NULL_HANDLE, 0); |
Jon Ashburn | ae7c21c | 2015-01-19 15:00:26 -0700 | [diff] [blame] | 1765 | xglDestroyObject(demo->uniform_data.buf); |
| 1766 | for (j = 0; j < demo->uniform_data.num_mem; j++) |
| 1767 | xglFreeMemory(demo->uniform_data.mem[j]); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1768 | |
| 1769 | for (i = 0; i < DEMO_BUFFER_COUNT; i++) { |
Chia-I Wu | bb57f64 | 2014-11-07 14:30:34 +0800 | [diff] [blame] | 1770 | xglDestroyObject(demo->buffers[i].fence); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1771 | xglDestroyObject(demo->buffers[i].view); |
| 1772 | xglDestroyObject(demo->buffers[i].image); |
Courtney Goeltzenleuchter | efc58ae | 2015-02-17 09:48:44 -0700 | [diff] [blame] | 1773 | xglDestroyObject(demo->buffers[i].cmd); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | xglDestroyDevice(demo->device); |
Jon Ashburn | 93cfc43 | 2015-01-29 15:47:01 -0700 | [diff] [blame] | 1777 | xglDestroyInstance(demo->inst); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1778 | |
| 1779 | xcb_destroy_window(demo->connection, demo->window); |
| 1780 | xcb_disconnect(demo->connection); |
| 1781 | } |
| 1782 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 1783 | int main(int argc, char **argv) |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1784 | { |
| 1785 | struct demo demo; |
| 1786 | |
Courtney Goeltzenleuchter | b4fc007 | 2015-02-17 12:54:31 -0700 | [diff] [blame] | 1787 | demo_init(&demo, argc, argv); |
Courtney Goeltzenleuchter | 7be88a8 | 2014-10-23 13:16:59 -0600 | [diff] [blame] | 1788 | |
| 1789 | demo_prepare(&demo); |
| 1790 | demo_create_window(&demo); |
| 1791 | demo_run(&demo); |
| 1792 | |
| 1793 | demo_cleanup(&demo); |
| 1794 | |
| 1795 | return 0; |
| 1796 | } |