Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 1 | /* |
| 2 | * XGL Tests |
| 3 | * |
| 4 | * Copyright (C) 2014 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #include "xglrenderframework.h" |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 29 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 30 | XglRenderFramework::XglRenderFramework() : |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 31 | m_cmdBuffer( XGL_NULL_HANDLE ), |
Chia-I Wu | 837f995 | 2014-12-15 23:29:34 +0800 | [diff] [blame] | 32 | m_stateRaster( XGL_NULL_HANDLE ), |
| 33 | m_colorBlend( XGL_NULL_HANDLE ), |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 34 | m_stateViewport( XGL_NULL_HANDLE ), |
Chia-I Wu | 837f995 | 2014-12-15 23:29:34 +0800 | [diff] [blame] | 35 | m_stateDepthStencil( XGL_NULL_HANDLE ), |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 36 | m_width( 256.0 ), // default window width |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 37 | m_height( 256.0 ), // default window height |
| 38 | m_render_target_fmt( XGL_FMT_R8G8B8A8_UNORM ), |
| 39 | m_depth_stencil_fmt( XGL_FMT_UNDEFINED ), |
| 40 | m_depth_clear_color( 1.0 ), |
| 41 | m_stencil_clear_color( 0 ) |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 42 | { |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 43 | |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 44 | // clear the back buffer to dark grey |
| 45 | m_clear_color.color.rawColor[0] = 64; |
| 46 | m_clear_color.color.rawColor[1] = 64; |
| 47 | m_clear_color.color.rawColor[2] = 64; |
| 48 | m_clear_color.color.rawColor[3] = 0; |
| 49 | m_clear_color.useRawValue = true; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | XglRenderFramework::~XglRenderFramework() |
| 53 | { |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 54 | |
| 55 | } |
| 56 | |
| 57 | void XglRenderFramework::InitFramework() |
| 58 | { |
| 59 | XGL_RESULT err; |
| 60 | |
Jon Ashburn | 1e46489 | 2015-01-29 15:48:00 -0700 | [diff] [blame] | 61 | err = xglCreateInstance(&app_info, NULL, &this->inst); |
| 62 | ASSERT_XGL_SUCCESS(err); |
| 63 | err = xglEnumerateGpus(inst, XGL_MAX_PHYSICAL_GPUS, &this->gpu_count, |
| 64 | objs); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 65 | ASSERT_XGL_SUCCESS(err); |
Jon Ashburn | bf843b2 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 66 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 67 | |
| 68 | m_device = new XglDevice(0, objs[0]); |
| 69 | m_device->get_device_queue(); |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 70 | |
| 71 | m_depthStencil = new XglDepthStencilObj(); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void XglRenderFramework::ShutdownFramework() |
| 75 | { |
| 76 | if (m_colorBlend) xglDestroyObject(m_colorBlend); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 77 | if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil); |
| 78 | if (m_stateRaster) xglDestroyObject(m_stateRaster); |
| 79 | if (m_cmdBuffer) xglDestroyObject(m_cmdBuffer); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 80 | if (m_framebuffer) xglDestroyObject(m_framebuffer); |
Tobin Ehlis | 976fc16 | 2015-03-26 08:23:25 -0600 | [diff] [blame] | 81 | if (m_renderPass) xglDestroyObject(m_renderPass); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 82 | |
| 83 | if (m_stateViewport) { |
| 84 | xglDestroyObject(m_stateViewport); |
| 85 | } |
Tobin Ehlis | 976fc16 | 2015-03-26 08:23:25 -0600 | [diff] [blame] | 86 | while (!m_renderTargets.empty()) { |
| 87 | xglDestroyObject(m_renderTargets.back()->targetView()); |
| 88 | xglBindObjectMemory(m_renderTargets.back()->image(), 0, XGL_NULL_HANDLE, 0); |
| 89 | xglDestroyObject(m_renderTargets.back()->image()); |
| 90 | xglFreeMemory(m_renderTargets.back()->memory()); |
| 91 | m_renderTargets.pop_back(); |
| 92 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 93 | |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 94 | delete m_depthStencil; |
| 95 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 96 | // reset the driver |
Chia-I Wu | b76e0fa | 2014-12-28 14:27:28 +0800 | [diff] [blame] | 97 | delete m_device; |
Jon Ashburn | 1e46489 | 2015-01-29 15:48:00 -0700 | [diff] [blame] | 98 | xglDestroyInstance(this->inst); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 99 | } |
| 100 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 101 | void XglRenderFramework::InitState() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 102 | { |
| 103 | XGL_RESULT err; |
| 104 | |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 105 | m_render_target_fmt = XGL_FMT_B8G8R8A8_UNORM; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 106 | |
| 107 | // create a raster state (solid, back-face culling) |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 108 | XGL_DYNAMIC_RS_STATE_CREATE_INFO raster = {}; |
| 109 | raster.sType = XGL_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO; |
| 110 | raster.pointSize = 1.0; |
| 111 | |
| 112 | err = xglCreateDynamicRasterState( device(), &raster, &m_stateRaster ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 113 | ASSERT_XGL_SUCCESS(err); |
| 114 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 115 | XGL_DYNAMIC_CB_STATE_CREATE_INFO blend = {}; |
| 116 | blend.sType = XGL_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO; |
| 117 | err = xglCreateDynamicColorBlendState(device(), &blend, &m_colorBlend); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 118 | ASSERT_XGL_SUCCESS( err ); |
| 119 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 120 | XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {}; |
| 121 | depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 122 | depthStencil.minDepth = 0.f; |
| 123 | depthStencil.maxDepth = 1.f; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 124 | depthStencil.stencilFrontRef = 0; |
| 125 | depthStencil.stencilBackRef = 0; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 126 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 127 | err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 128 | ASSERT_XGL_SUCCESS( err ); |
| 129 | |
| 130 | XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {}; |
| 131 | |
| 132 | cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 133 | cmdInfo.queueNodeIndex = m_device->graphics_queue_node_index_; |
| 134 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 135 | err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer); |
| 136 | ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed"; |
| 137 | } |
| 138 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 139 | void XglRenderFramework::InitViewport(float width, float height) |
| 140 | { |
| 141 | XGL_RESULT err; |
| 142 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 143 | XGL_VIEWPORT viewport; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 144 | XGL_RECT scissor; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 145 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 146 | XGL_DYNAMIC_VP_STATE_CREATE_INFO viewportCreate = {}; |
| 147 | viewportCreate.sType = XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 148 | viewportCreate.viewportAndScissorCount = 1; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 149 | viewport.originX = 0; |
| 150 | viewport.originY = 0; |
| 151 | viewport.width = 1.f * width; |
| 152 | viewport.height = 1.f * height; |
| 153 | viewport.minDepth = 0.f; |
| 154 | viewport.maxDepth = 1.f; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 155 | scissor.extent.width = width; |
| 156 | scissor.extent.height = height; |
| 157 | scissor.offset.x = 0; |
| 158 | scissor.offset.y = 0; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 159 | viewportCreate.pViewports = &viewport; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 160 | viewportCreate.pScissors = &scissor; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 161 | |
| 162 | err = xglCreateDynamicViewportState( device(), &viewportCreate, &m_stateViewport ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 163 | ASSERT_XGL_SUCCESS( err ); |
| 164 | m_width = width; |
| 165 | m_height = height; |
| 166 | } |
| 167 | |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 168 | void XglRenderFramework::InitViewport() |
| 169 | { |
| 170 | InitViewport(m_width, m_height); |
| 171 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 172 | void XglRenderFramework::InitRenderTarget() |
| 173 | { |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 174 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 175 | InitRenderTarget(1); |
| 176 | } |
| 177 | |
| 178 | void XglRenderFramework::InitRenderTarget(uint32_t targets) |
| 179 | { |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 180 | InitRenderTarget(targets, NULL); |
| 181 | } |
| 182 | |
| 183 | void XglRenderFramework::InitRenderTarget(XGL_DEPTH_STENCIL_BIND_INFO *dsBinding) |
| 184 | { |
| 185 | InitRenderTarget(1, dsBinding); |
| 186 | } |
| 187 | |
| 188 | void XglRenderFramework::InitRenderTarget(uint32_t targets, XGL_DEPTH_STENCIL_BIND_INFO *dsBinding) |
| 189 | { |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 190 | std::vector<XGL_ATTACHMENT_LOAD_OP> load_ops; |
| 191 | std::vector<XGL_ATTACHMENT_STORE_OP> store_ops; |
| 192 | std::vector<XGL_CLEAR_COLOR> clear_colors; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 193 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 194 | uint32_t i; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 195 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 196 | for (i = 0; i < targets; i++) { |
Chia-I Wu | f50ee21 | 2014-12-29 14:31:52 +0800 | [diff] [blame] | 197 | XglImage *img = new XglImage(m_device); |
| 198 | img->init(m_width, m_height, m_render_target_fmt, |
| 199 | XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | |
| 200 | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 201 | m_colorBindings[i].view = img->targetView(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 202 | m_colorBindings[i].layout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 203 | m_renderTargets.push_back(img); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 204 | load_ops.push_back(XGL_ATTACHMENT_LOAD_OP_LOAD); |
| 205 | store_ops.push_back(XGL_ATTACHMENT_STORE_OP_STORE); |
| 206 | clear_colors.push_back(m_clear_color); |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 207 | } |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 208 | // Create Framebuffer and RenderPass with color attachments and any depth/stencil attachment |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 209 | XGL_FRAMEBUFFER_CREATE_INFO fb_info = {}; |
| 210 | fb_info.sType = XGL_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 211 | fb_info.pNext = NULL; |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 212 | fb_info.colorAttachmentCount = m_renderTargets.size(); |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 213 | fb_info.pColorAttachments = m_colorBindings; |
| 214 | fb_info.pDepthStencilAttachment = dsBinding; |
| 215 | fb_info.sampleCount = 1; |
| 216 | fb_info.width = (uint32_t)m_width; |
| 217 | fb_info.height = (uint32_t)m_height; |
| 218 | fb_info.layers = 1; |
| 219 | |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 220 | xglCreateFramebuffer(device(), &fb_info, &m_framebuffer); |
| 221 | |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 222 | XGL_RENDER_PASS_CREATE_INFO rp_info = {}; |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 223 | rp_info.sType = XGL_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 224 | rp_info.renderArea.extent.width = m_width; |
| 225 | rp_info.renderArea.extent.height = m_height; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 226 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 227 | rp_info.colorAttachmentCount = m_renderTargets.size(); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 228 | rp_info.pColorFormats = &m_render_target_fmt; |
| 229 | rp_info.pColorLayouts = &m_colorBindings[0].layout; |
| 230 | rp_info.pColorLoadOps = &load_ops[0]; |
| 231 | rp_info.pColorStoreOps = &store_ops[0]; |
| 232 | rp_info.pColorLoadClearValues = &clear_colors[0]; |
| 233 | rp_info.depthStencilFormat = m_depth_stencil_fmt; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 234 | if (dsBinding) { |
| 235 | rp_info.depthStencilLayout = dsBinding->layout; |
| 236 | } |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 237 | rp_info.depthLoadOp = XGL_ATTACHMENT_LOAD_OP_LOAD; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 238 | rp_info.depthLoadClearValue = m_depth_clear_color; |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 239 | rp_info.depthStoreOp = XGL_ATTACHMENT_STORE_OP_STORE; |
| 240 | rp_info.stencilLoadOp = XGL_ATTACHMENT_LOAD_OP_LOAD; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 241 | rp_info.stencilLoadClearValue = m_stencil_clear_color; |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 242 | rp_info.stencilStoreOp = XGL_ATTACHMENT_STORE_OP_STORE; |
| 243 | xglCreateRenderPass(device(), &rp_info, &m_renderPass); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 244 | } |
| 245 | |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 246 | |
| 247 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 248 | XglDevice::XglDevice(uint32_t id, XGL_PHYSICAL_GPU obj) : |
Chia-I Wu | fb1459b | 2014-12-29 15:23:20 +0800 | [diff] [blame] | 249 | xgl_testing::Device(obj), id(id) |
| 250 | { |
| 251 | init(); |
| 252 | |
| 253 | props = gpu().properties(); |
| 254 | queue_props = &gpu().queue_properties()[0]; |
| 255 | } |
| 256 | |
| 257 | void XglDevice::get_device_queue() |
| 258 | { |
| 259 | ASSERT_NE(true, graphics_queues().empty()); |
| 260 | m_queue = graphics_queues()[0]->obj(); |
| 261 | } |
| 262 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 263 | XglDescriptorSetObj::XglDescriptorSetObj(XglDevice *device) |
| 264 | { |
| 265 | m_device = device; |
| 266 | m_nextSlot = 0; |
| 267 | |
| 268 | } |
| 269 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 270 | XglDescriptorSetObj::~XglDescriptorSetObj() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 271 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 272 | delete m_set; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 273 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 274 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 275 | int XglDescriptorSetObj::AppendDummy() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 276 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 277 | /* request a descriptor but do not update it */ |
| 278 | XGL_DESCRIPTOR_TYPE_COUNT tc = {}; |
Chia-I Wu | 47a5d6f | 2015-03-26 15:26:05 +0800 | [diff] [blame] | 279 | tc.type = XGL_DESCRIPTOR_TYPE_SHADER_STORAGE_BUFFER; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 280 | tc.count = 1; |
| 281 | m_type_counts.push_back(tc); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 282 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 283 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 284 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 285 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 286 | int XglDescriptorSetObj::AppendBuffer(XGL_DESCRIPTOR_TYPE type, XglConstantBufferObj *constantBuffer) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 287 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 288 | XGL_DESCRIPTOR_TYPE_COUNT tc = {}; |
| 289 | tc.type = type; |
| 290 | tc.count = 1; |
| 291 | m_type_counts.push_back(tc); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 292 | |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 293 | m_updateBuffers.push_back(xgl_testing::DescriptorSet::update(type, |
| 294 | m_nextSlot, 0, 1, &constantBuffer->m_bufferViewInfo)); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 295 | |
| 296 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 297 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 298 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 299 | int XglDescriptorSetObj::AppendSamplerTexture( XglSamplerObj* sampler, XglTextureObj* texture) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 300 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 301 | XGL_DESCRIPTOR_TYPE_COUNT tc = {}; |
| 302 | tc.type = XGL_DESCRIPTOR_TYPE_SAMPLER_TEXTURE; |
| 303 | tc.count = 1; |
| 304 | m_type_counts.push_back(tc); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 305 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 306 | XGL_SAMPLER_IMAGE_VIEW_INFO tmp = {}; |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 307 | tmp.sampler = sampler->obj(); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 308 | tmp.pImageView = &texture->m_textureViewInfo; |
| 309 | m_samplerTextureInfo.push_back(tmp); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 310 | |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 311 | m_updateSamplerTextures.push_back(xgl_testing::DescriptorSet::update(m_nextSlot, 0, 1, |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 312 | (const XGL_SAMPLER_IMAGE_VIEW_INFO *) NULL)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 313 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 314 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 315 | } |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 316 | |
Chia-I Wu | 53f07d7 | 2015-03-28 15:23:55 +0800 | [diff] [blame^] | 317 | XGL_DESCRIPTOR_SET_LAYOUT_CHAIN XglDescriptorSetObj::GetLayoutChain() const |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 318 | { |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 319 | return m_layout_chain.obj(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Chia-I Wu | 53f07d7 | 2015-03-28 15:23:55 +0800 | [diff] [blame^] | 322 | XGL_DESCRIPTOR_SET XglDescriptorSetObj::GetDescriptorSetHandle() const |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 323 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 324 | return m_set->obj(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 325 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 326 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 327 | void XglDescriptorSetObj::CreateXGLDescriptorSet(XglCommandBufferObj *cmdBuffer) |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 328 | { |
Chia-I Wu | 985ba16 | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 329 | // create XGL_DESCRIPTOR_POOL |
| 330 | XGL_DESCRIPTOR_POOL_CREATE_INFO pool = {}; |
| 331 | pool.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; |
| 332 | pool.count = m_type_counts.size(); |
| 333 | pool.pTypeCount = &m_type_counts[0]; |
| 334 | init(*m_device, XGL_DESCRIPTOR_POOL_USAGE_ONE_SHOT, 1, pool); |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 335 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 336 | // create XGL_DESCRIPTOR_SET_LAYOUT |
Chia-I Wu | b41393e | 2015-03-26 15:04:41 +0800 | [diff] [blame] | 337 | vector<XGL_DESCRIPTOR_SET_LAYOUT_BINDING> bindings; |
| 338 | bindings.resize(m_type_counts.size()); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 339 | for (int i = 0; i < m_type_counts.size(); i++) { |
Chia-I Wu | b41393e | 2015-03-26 15:04:41 +0800 | [diff] [blame] | 340 | bindings[i].descriptorType = m_type_counts[i].type; |
| 341 | bindings[i].count = m_type_counts[i].count; |
| 342 | bindings[i].stageFlags = XGL_SHADER_STAGE_FLAGS_ALL; |
Chia-I Wu | 0743e83 | 2015-03-27 12:56:09 +0800 | [diff] [blame] | 343 | bindings[i].pImmutableSamplers = NULL; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 344 | } |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 345 | |
Chia-I Wu | b41393e | 2015-03-26 15:04:41 +0800 | [diff] [blame] | 346 | // create XGL_DESCRIPTOR_SET_LAYOUT |
| 347 | XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO layout = {}; |
| 348 | layout.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 349 | layout.count = bindings.size(); |
| 350 | layout.pBinding = &bindings[0]; |
| 351 | |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 352 | m_layout.init(*m_device, layout); |
| 353 | |
| 354 | vector<const xgl_testing::DescriptorSetLayout *> layouts; |
| 355 | layouts.push_back(&m_layout); |
| 356 | m_layout_chain.init(*m_device, layouts); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 357 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 358 | // create XGL_DESCRIPTOR_SET |
| 359 | m_set = alloc_sets(XGL_DESCRIPTOR_SET_USAGE_STATIC, m_layout); |
| 360 | |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 361 | // build the update array |
| 362 | vector<const void *> update_array; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 363 | |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 364 | for (int i = 0; i < m_updateBuffers.size(); i++) { |
| 365 | update_array.push_back(&m_updateBuffers[i]); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 366 | } |
| 367 | for (int i = 0; i < m_updateSamplerTextures.size(); i++) { |
| 368 | m_updateSamplerTextures[i].pSamplerImageViews = &m_samplerTextureInfo[i]; |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 369 | update_array.push_back(&m_updateSamplerTextures[i]); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 370 | } |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 371 | |
| 372 | // do the updates |
Chia-I Wu | 985ba16 | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 373 | m_device->begin_descriptor_pool_update(XGL_DESCRIPTOR_UPDATE_MODE_FASTEST); |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 374 | clear_sets(*m_set); |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 375 | m_set->update(update_array); |
Chia-I Wu | 985ba16 | 2015-03-26 13:14:16 +0800 | [diff] [blame] | 376 | m_device->end_descriptor_pool_update(*cmdBuffer); |
Tony Barbour | 25ef8a6 | 2014-12-03 13:59:18 -0700 | [diff] [blame] | 377 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 378 | |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 379 | XglImage::XglImage(XglDevice *dev) |
| 380 | { |
| 381 | m_device = dev; |
| 382 | m_imageInfo.view = XGL_NULL_HANDLE; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 383 | m_imageInfo.layout = XGL_IMAGE_LAYOUT_GENERAL; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 384 | } |
| 385 | |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 386 | static bool IsCompatible(XGL_FLAGS usage, XGL_FLAGS features) |
| 387 | { |
| 388 | if ((usage & XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT) && |
| 389 | !(features & XGL_FORMAT_IMAGE_SHADER_READ_BIT)) |
| 390 | return false; |
| 391 | if ((usage & XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT) && |
| 392 | !(features & XGL_FORMAT_IMAGE_SHADER_WRITE_BIT)) |
| 393 | return false; |
| 394 | return true; |
| 395 | } |
| 396 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 397 | void XglImage::init(uint32_t w, uint32_t h, |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 398 | XGL_FORMAT fmt, XGL_FLAGS usage, |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 399 | XGL_IMAGE_TILING requested_tiling) |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 400 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 401 | uint32_t mipCount; |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 402 | XGL_FORMAT_PROPERTIES image_fmt; |
| 403 | XGL_IMAGE_TILING tiling; |
| 404 | XGL_RESULT err; |
| 405 | size_t size; |
| 406 | |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 407 | mipCount = 0; |
| 408 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 409 | uint32_t _w = w; |
| 410 | uint32_t _h = h; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 411 | while( ( _w > 0 ) || ( _h > 0 ) ) |
| 412 | { |
| 413 | _w >>= 1; |
| 414 | _h >>= 1; |
| 415 | mipCount++; |
| 416 | } |
| 417 | |
Tony Barbour | 579f780 | 2015-04-03 15:11:43 -0600 | [diff] [blame] | 418 | size = sizeof(image_fmt); |
| 419 | err = xglGetFormatInfo(m_device->obj(), fmt, |
| 420 | XGL_INFO_TYPE_FORMAT_PROPERTIES, |
| 421 | &size, &image_fmt); |
| 422 | ASSERT_XGL_SUCCESS(err); |
| 423 | |
| 424 | if (requested_tiling == XGL_LINEAR_TILING) { |
| 425 | if (IsCompatible(usage, image_fmt.linearTilingFeatures)) { |
| 426 | tiling = XGL_LINEAR_TILING; |
| 427 | } else if (IsCompatible(usage, image_fmt.optimalTilingFeatures)) { |
| 428 | tiling = XGL_OPTIMAL_TILING; |
| 429 | } else { |
| 430 | ASSERT_TRUE(false) << "Error: Cannot find requested tiling configuration"; |
| 431 | } |
| 432 | } else if (IsCompatible(usage, image_fmt.optimalTilingFeatures)) { |
| 433 | tiling = XGL_OPTIMAL_TILING; |
| 434 | } else if (IsCompatible(usage, image_fmt.linearTilingFeatures)) { |
| 435 | tiling = XGL_LINEAR_TILING; |
| 436 | } else { |
| 437 | ASSERT_TRUE(false) << "Error: Cannot find requested tiling configuration"; |
| 438 | } |
| 439 | |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 440 | XGL_IMAGE_CREATE_INFO imageCreateInfo = xgl_testing::Image::create_info(); |
| 441 | imageCreateInfo.imageType = XGL_IMAGE_2D; |
| 442 | imageCreateInfo.format = fmt; |
| 443 | imageCreateInfo.extent.width = w; |
| 444 | imageCreateInfo.extent.height = h; |
| 445 | imageCreateInfo.mipLevels = mipCount; |
| 446 | imageCreateInfo.tiling = tiling; |
| 447 | |
| 448 | imageCreateInfo.usage = usage; |
| 449 | |
| 450 | xgl_testing::Image::init(*m_device, imageCreateInfo); |
| 451 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 452 | m_imageInfo.layout = XGL_IMAGE_LAYOUT_GENERAL; |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 453 | } |
| 454 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 455 | XGL_RESULT XglImage::MapMemory(void** ptr) |
Chia-I Wu | a6bc0ce | 2014-12-29 14:38:28 +0800 | [diff] [blame] | 456 | { |
| 457 | *ptr = map(); |
| 458 | return (*ptr) ? XGL_SUCCESS : XGL_ERROR_UNKNOWN; |
| 459 | } |
| 460 | |
| 461 | XGL_RESULT XglImage::UnmapMemory() |
| 462 | { |
| 463 | unmap(); |
| 464 | return XGL_SUCCESS; |
| 465 | } |
| 466 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 467 | XGL_RESULT XglImage::CopyImage(XglImage &fromImage) |
| 468 | { |
| 469 | XGL_RESULT err; |
| 470 | |
| 471 | XGL_CMD_BUFFER cmd_buf; |
| 472 | XGL_CMD_BUFFER_CREATE_INFO cmd_buf_create_info = {}; |
| 473 | cmd_buf_create_info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
| 474 | cmd_buf_create_info.pNext = NULL; |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 475 | cmd_buf_create_info.queueNodeIndex = m_device->graphics_queue_node_index_; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 476 | cmd_buf_create_info.flags = 0; |
| 477 | |
| 478 | err = xglCreateCommandBuffer(m_device->device(), &cmd_buf_create_info, &cmd_buf); |
| 479 | assert(!err); |
| 480 | |
| 481 | /* Copy staging texture to usable texture */ |
| 482 | XGL_CMD_BUFFER_BEGIN_INFO cmd_buf_begin_info = {}; |
| 483 | cmd_buf_begin_info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 484 | cmd_buf_begin_info.pNext = NULL; |
| 485 | cmd_buf_begin_info.flags = 0; |
| 486 | |
| 487 | err = xglResetCommandBuffer(cmd_buf); |
| 488 | assert(!err); |
| 489 | |
| 490 | err = xglBeginCommandBuffer(cmd_buf, &cmd_buf_begin_info); |
| 491 | assert(!err); |
| 492 | |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 493 | XGL_IMAGE_MEMORY_BARRIER image_memory_barrier = {}; |
| 494 | image_memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 495 | image_memory_barrier.pNext = NULL; |
| 496 | image_memory_barrier.outputMask = XGL_MEMORY_OUTPUT_COPY_BIT; |
| 497 | image_memory_barrier.inputMask = XGL_MEMORY_INPUT_SHADER_READ_BIT | XGL_MEMORY_INPUT_COPY_BIT; |
| 498 | image_memory_barrier.oldLayout = fromImage.layout(); |
| 499 | image_memory_barrier.newLayout = XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL; |
| 500 | image_memory_barrier.image = fromImage.obj(); |
| 501 | image_memory_barrier.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 502 | image_memory_barrier.subresourceRange.baseMipLevel = 0; |
| 503 | image_memory_barrier.subresourceRange.mipLevels = 1; |
| 504 | image_memory_barrier.subresourceRange.baseArraySlice = 0; |
| 505 | image_memory_barrier.subresourceRange.arraySize = 0; |
| 506 | |
| 507 | XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &image_memory_barrier; |
| 508 | |
| 509 | XGL_PIPE_EVENT pipe_events[] = { XGL_PIPE_EVENT_GPU_COMMANDS_COMPLETE }; |
| 510 | XGL_PIPELINE_BARRIER pipeline_barrier; |
| 511 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 512 | pipeline_barrier.pNext = NULL; |
| 513 | pipeline_barrier.eventCount = 1; |
| 514 | pipeline_barrier.pEvents = pipe_events; |
| 515 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 516 | pipeline_barrier.memBarrierCount = 1; |
| 517 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
| 518 | |
| 519 | // write barrier to the command buffer |
| 520 | xglCmdPipelineBarrier(cmd_buf, &pipeline_barrier); |
| 521 | |
| 522 | image_memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 523 | image_memory_barrier.pNext = NULL; |
| 524 | image_memory_barrier.outputMask = XGL_MEMORY_OUTPUT_COPY_BIT; |
| 525 | image_memory_barrier.inputMask = XGL_MEMORY_INPUT_SHADER_READ_BIT | XGL_MEMORY_INPUT_COPY_BIT; |
| 526 | image_memory_barrier.oldLayout = this->layout(); |
| 527 | image_memory_barrier.newLayout = XGL_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL; |
| 528 | image_memory_barrier.image = this->obj(); |
| 529 | image_memory_barrier.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 530 | image_memory_barrier.subresourceRange.baseMipLevel = 0; |
| 531 | image_memory_barrier.subresourceRange.mipLevels = 1; |
| 532 | image_memory_barrier.subresourceRange.baseArraySlice = 0; |
| 533 | image_memory_barrier.subresourceRange.arraySize = 0; |
| 534 | |
| 535 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 536 | pipeline_barrier.pNext = NULL; |
| 537 | pipeline_barrier.eventCount = 1; |
| 538 | pipeline_barrier.pEvents = pipe_events; |
| 539 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 540 | pipeline_barrier.memBarrierCount = 1; |
| 541 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
| 542 | |
| 543 | // write barrier to the command buffer |
| 544 | xglCmdPipelineBarrier(cmd_buf, &pipeline_barrier); |
| 545 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 546 | XGL_IMAGE_COPY copy_region = {}; |
| 547 | copy_region.srcSubresource.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 548 | copy_region.srcSubresource.arraySlice = 0; |
| 549 | copy_region.srcSubresource.mipLevel = 0; |
| 550 | copy_region.srcOffset.x = 0; |
| 551 | copy_region.srcOffset.y = 0; |
| 552 | copy_region.srcOffset.z = 0; |
| 553 | copy_region.destSubresource.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 554 | copy_region.destSubresource.arraySlice = 0; |
| 555 | copy_region.destSubresource.mipLevel = 0; |
| 556 | copy_region.destOffset.x = 0; |
| 557 | copy_region.destOffset.y = 0; |
| 558 | copy_region.destOffset.z = 0; |
| 559 | copy_region.extent = fromImage.extent(); |
| 560 | |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 561 | xglCmdCopyImage(cmd_buf, fromImage.obj(), fromImage.layout(), |
| 562 | obj(), XGL_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL, |
| 563 | 1, ©_region); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 564 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 565 | image_memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 566 | image_memory_barrier.pNext = NULL; |
| 567 | image_memory_barrier.outputMask = XGL_MEMORY_OUTPUT_COPY_BIT; |
| 568 | image_memory_barrier.inputMask = XGL_MEMORY_INPUT_SHADER_READ_BIT | XGL_MEMORY_INPUT_COPY_BIT; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 569 | image_memory_barrier.oldLayout = XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL; |
| 570 | image_memory_barrier.newLayout = fromImage.layout(); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 571 | image_memory_barrier.image = fromImage.obj(); |
| 572 | image_memory_barrier.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 573 | image_memory_barrier.subresourceRange.baseMipLevel = 0; |
| 574 | image_memory_barrier.subresourceRange.mipLevels = 1; |
| 575 | image_memory_barrier.subresourceRange.baseArraySlice = 0; |
| 576 | image_memory_barrier.subresourceRange.arraySize = 0; |
| 577 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 578 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 579 | pipeline_barrier.pNext = NULL; |
| 580 | pipeline_barrier.eventCount = 1; |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 581 | pipeline_barrier.pEvents = pipe_events; |
| 582 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 583 | pipeline_barrier.memBarrierCount = 1; |
| 584 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
| 585 | |
| 586 | // write barrier to the command buffer |
| 587 | xglCmdPipelineBarrier(cmd_buf, &pipeline_barrier); |
| 588 | |
| 589 | image_memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 590 | image_memory_barrier.pNext = NULL; |
| 591 | image_memory_barrier.outputMask = XGL_MEMORY_OUTPUT_COPY_BIT; |
| 592 | image_memory_barrier.inputMask = XGL_MEMORY_INPUT_SHADER_READ_BIT | XGL_MEMORY_INPUT_COPY_BIT; |
| 593 | image_memory_barrier.oldLayout = XGL_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL; |
| 594 | image_memory_barrier.newLayout = this->layout(); |
| 595 | image_memory_barrier.image = this->obj(); |
| 596 | image_memory_barrier.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 597 | image_memory_barrier.subresourceRange.baseMipLevel = 0; |
| 598 | image_memory_barrier.subresourceRange.mipLevels = 1; |
| 599 | image_memory_barrier.subresourceRange.baseArraySlice = 0; |
| 600 | image_memory_barrier.subresourceRange.arraySize = 0; |
| 601 | |
| 602 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 603 | pipeline_barrier.pNext = NULL; |
| 604 | pipeline_barrier.eventCount = 1; |
| 605 | pipeline_barrier.pEvents = pipe_events; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 606 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 607 | pipeline_barrier.memBarrierCount = 1; |
| 608 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
| 609 | |
| 610 | // write barrier to the command buffer |
| 611 | xglCmdPipelineBarrier(cmd_buf, &pipeline_barrier); |
| 612 | |
| 613 | err = xglEndCommandBuffer(cmd_buf); |
| 614 | assert(!err); |
| 615 | |
| 616 | const XGL_CMD_BUFFER cmd_bufs[] = { cmd_buf }; |
| 617 | XGL_MEMORY_REF mem_refs[16]; |
| 618 | uint32_t num_refs = 0; |
| 619 | const std::vector<XGL_GPU_MEMORY> from_mems = fromImage.memories(); |
| 620 | const std::vector<XGL_GPU_MEMORY> to_mems = memories(); |
| 621 | |
| 622 | for (uint32_t j = 0; j < from_mems.size(); j++) { |
| 623 | mem_refs[num_refs].flags = XGL_MEMORY_REF_READ_ONLY_BIT; |
| 624 | mem_refs[num_refs].mem = from_mems[j]; |
| 625 | num_refs++; |
| 626 | assert(num_refs < 16); |
| 627 | } |
| 628 | |
| 629 | for (uint32_t j = 0; j < to_mems.size(); j++) { |
| 630 | mem_refs[num_refs].flags = XGL_MEMORY_REF_READ_ONLY_BIT; |
| 631 | mem_refs[num_refs].mem = to_mems[j]; |
| 632 | num_refs++; |
| 633 | assert(num_refs < 16); |
| 634 | } |
| 635 | |
| 636 | err = xglQueueSubmit(m_device->m_queue, 1, cmd_bufs, |
| 637 | num_refs, mem_refs, XGL_NULL_HANDLE); |
| 638 | assert(!err); |
| 639 | |
| 640 | err = xglQueueWaitIdle(m_device->m_queue); |
| 641 | assert(!err); |
| 642 | |
| 643 | xglDestroyObject(cmd_buf); |
| 644 | |
| 645 | return XGL_SUCCESS; |
| 646 | } |
| 647 | |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 648 | XglTextureObj::XglTextureObj(XglDevice *device, uint32_t *colors) |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 649 | :XglImage(device) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 650 | { |
| 651 | m_device = device; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 652 | const XGL_FORMAT tex_format = XGL_FMT_B8G8R8A8_UNORM; |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 653 | uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 }; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 654 | void *data; |
| 655 | int32_t x, y; |
| 656 | XglImage stagingImage(device); |
| 657 | |
| 658 | stagingImage.init(16, 16, tex_format, 0, XGL_LINEAR_TILING); |
| 659 | XGL_SUBRESOURCE_LAYOUT layout = stagingImage.subresource_layout(subresource(XGL_IMAGE_ASPECT_COLOR, 0, 0)); |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 660 | |
| 661 | if (colors == NULL) |
| 662 | colors = tex_colors; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 663 | |
| 664 | memset(&m_textureViewInfo,0,sizeof(m_textureViewInfo)); |
| 665 | |
| 666 | m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 667 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 668 | XGL_IMAGE_VIEW_CREATE_INFO view = {}; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 669 | view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 670 | view.pNext = NULL; |
| 671 | view.image = XGL_NULL_HANDLE; |
| 672 | view.viewType = XGL_IMAGE_VIEW_2D; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 673 | view.format = tex_format; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 674 | view.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 675 | view.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 676 | view.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 677 | view.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 678 | view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 679 | view.subresourceRange.baseMipLevel = 0; |
| 680 | view.subresourceRange.mipLevels = 1; |
| 681 | view.subresourceRange.baseArraySlice = 0; |
| 682 | view.subresourceRange.arraySize = 1; |
| 683 | view.minLod = 0.0f; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 684 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 685 | /* create image */ |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 686 | init(16, 16, tex_format, XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT, XGL_OPTIMAL_TILING); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 687 | |
| 688 | /* create image view */ |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 689 | view.image = obj(); |
| 690 | m_textureView.init(*m_device, view); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 691 | m_textureViewInfo.view = m_textureView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 692 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 693 | data = stagingImage.map(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 694 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 695 | for (y = 0; y < extent().height; y++) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 696 | uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y); |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 697 | for (x = 0; x < extent().width; x++) |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 698 | row[x] = colors[(x & 1) ^ (y & 1)]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 699 | } |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 700 | stagingImage.unmap(); |
| 701 | XglImage::CopyImage(stagingImage); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 702 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 703 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 704 | XglSamplerObj::XglSamplerObj(XglDevice *device) |
| 705 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 706 | m_device = device; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 707 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 708 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo; |
| 709 | memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo)); |
| 710 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 711 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 712 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 713 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 714 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 715 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 716 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 717 | samplerCreateInfo.mipLodBias = 0.0; |
| 718 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 719 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 720 | samplerCreateInfo.minLod = 0.0; |
| 721 | samplerCreateInfo.maxLod = 0.0; |
| 722 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 723 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 724 | init(*m_device, samplerCreateInfo); |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 725 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 726 | |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 727 | /* |
| 728 | * Basic ConstantBuffer constructor. Then use create methods to fill in the details. |
| 729 | */ |
| 730 | XglConstantBufferObj::XglConstantBufferObj(XglDevice *device) |
| 731 | { |
| 732 | m_device = device; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 733 | m_commandBuffer = 0; |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 734 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 735 | memset(&m_bufferViewInfo,0,sizeof(m_bufferViewInfo)); |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Tony Barbour | 044703b | 2015-03-26 12:37:52 -0600 | [diff] [blame] | 738 | XglConstantBufferObj::~XglConstantBufferObj() |
| 739 | { |
| 740 | if (m_commandBuffer) { |
| 741 | delete m_commandBuffer; |
| 742 | } |
| 743 | } |
| 744 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 745 | XglConstantBufferObj::XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data) |
| 746 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 747 | m_device = device; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 748 | m_commandBuffer = 0; |
| 749 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 750 | memset(&m_bufferViewInfo,0,sizeof(m_bufferViewInfo)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 751 | m_numVertices = constantCount; |
| 752 | m_stride = constantSize; |
| 753 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 754 | const size_t allocationSize = constantCount * constantSize; |
| 755 | init(*m_device, allocationSize); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 756 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 757 | void *pData = map(); |
| 758 | memcpy(pData, data, allocationSize); |
| 759 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 760 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 761 | // set up the buffer view for the constant buffer |
| 762 | XGL_BUFFER_VIEW_CREATE_INFO view_info = {}; |
| 763 | view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 764 | view_info.buffer = obj(); |
Chia-I Wu | bb0c8d2 | 2015-01-16 22:31:25 +0800 | [diff] [blame] | 765 | view_info.viewType = XGL_BUFFER_VIEW_RAW; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 766 | view_info.offset = 0; |
| 767 | view_info.range = allocationSize; |
| 768 | m_bufferView.init(*m_device, view_info); |
| 769 | |
| 770 | this->m_bufferViewInfo.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO; |
| 771 | this->m_bufferViewInfo.view = m_bufferView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 772 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 773 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 774 | void XglConstantBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, uint32_t binding) |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 775 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 776 | xglCmdBindVertexBuffer(cmdBuffer, obj(), offset, binding); |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 780 | void XglConstantBufferObj::BufferMemoryBarrier( |
| 781 | XGL_FLAGS outputMask /*= |
| 782 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 783 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 784 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 785 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 786 | XGL_MEMORY_OUTPUT_COPY_BIT*/, |
| 787 | XGL_FLAGS inputMask /*= |
| 788 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 789 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 790 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 791 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 792 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 793 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 794 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 795 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 796 | XGL_MEMORY_INPUT_COPY_BIT*/) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 797 | { |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 798 | XGL_RESULT err = XGL_SUCCESS; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 799 | |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 800 | if (!m_commandBuffer) |
| 801 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 802 | m_fence.init(*m_device, xgl_testing::Fence::create_info(0)); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 803 | |
| 804 | m_commandBuffer = new XglCommandBufferObj(m_device); |
| 805 | |
| 806 | } |
| 807 | else |
| 808 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 809 | m_device->wait(m_fence); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 812 | // open the command buffer |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 813 | XGL_CMD_BUFFER_BEGIN_INFO cmd_buf_info = {}; |
| 814 | cmd_buf_info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 815 | cmd_buf_info.pNext = NULL; |
| 816 | cmd_buf_info.flags = 0; |
| 817 | |
Jon Ashburn | c4164b1 | 2014-12-31 17:10:47 -0700 | [diff] [blame] | 818 | err = m_commandBuffer->BeginCommandBuffer(&cmd_buf_info); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 819 | ASSERT_XGL_SUCCESS(err); |
| 820 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 821 | XGL_BUFFER_MEMORY_BARRIER memory_barrier = |
| 822 | buffer_memory_barrier(outputMask, inputMask, 0, m_numVertices * m_stride); |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 823 | XGL_BUFFER_MEMORY_BARRIER *pmemory_barrier = &memory_barrier; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 824 | |
Courtney Goeltzenleuchter | 1e8f3be | 2015-03-24 18:02:34 -0600 | [diff] [blame] | 825 | XGL_PIPE_EVENT set_events[] = { XGL_PIPE_EVENT_GPU_COMMANDS_COMPLETE }; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 826 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 827 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 828 | pipeline_barrier.eventCount = 1; |
| 829 | pipeline_barrier.pEvents = set_events; |
| 830 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 831 | pipeline_barrier.memBarrierCount = 1; |
Mark Lobodzinski | d5d83ed | 2015-02-02 11:55:52 -0600 | [diff] [blame] | 832 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 833 | |
| 834 | // write barrier to the command buffer |
| 835 | m_commandBuffer->PipelineBarrier(&pipeline_barrier); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 836 | |
| 837 | // finish recording the command buffer |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 838 | err = m_commandBuffer->EndCommandBuffer(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 839 | ASSERT_XGL_SUCCESS(err); |
| 840 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 841 | uint32_t numMemRefs=1; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 842 | XGL_MEMORY_REF memRefs; |
| 843 | // this command buffer only uses the vertex buffer memory |
| 844 | memRefs.flags = 0; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 845 | memRefs.mem = memories()[0]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 846 | |
| 847 | // submit the command buffer to the universal queue |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 848 | XGL_CMD_BUFFER bufferArray[1]; |
| 849 | bufferArray[0] = m_commandBuffer->GetBufferHandle(); |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 850 | err = xglQueueSubmit( m_device->m_queue, 1, bufferArray, numMemRefs, &memRefs, m_fence.obj() ); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 851 | ASSERT_XGL_SUCCESS(err); |
| 852 | } |
| 853 | |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 854 | XglIndexBufferObj::XglIndexBufferObj(XglDevice *device) |
| 855 | : XglConstantBufferObj(device) |
| 856 | { |
| 857 | |
| 858 | } |
| 859 | |
| 860 | void XglIndexBufferObj::CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE indexType, const void* data) |
| 861 | { |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 862 | XGL_FORMAT viewFormat; |
| 863 | |
| 864 | m_numVertices = numIndexes; |
| 865 | m_indexType = indexType; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 866 | switch (indexType) { |
| 867 | case XGL_INDEX_8: |
| 868 | m_stride = 1; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 869 | viewFormat = XGL_FMT_R8_UINT; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 870 | break; |
| 871 | case XGL_INDEX_16: |
| 872 | m_stride = 2; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 873 | viewFormat = XGL_FMT_R16_UINT; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 874 | break; |
| 875 | case XGL_INDEX_32: |
| 876 | m_stride = 4; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 877 | viewFormat = XGL_FMT_R32_UINT; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 878 | break; |
Chia-I Wu | b4c2aa4 | 2014-12-15 23:50:11 +0800 | [diff] [blame] | 879 | default: |
| 880 | assert(!"unknown index type"); |
| 881 | break; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 884 | const size_t allocationSize = numIndexes * m_stride; |
| 885 | init(*m_device, allocationSize); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 886 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 887 | void *pData = map(); |
| 888 | memcpy(pData, data, allocationSize); |
| 889 | unmap(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 890 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 891 | // set up the buffer view for the constant buffer |
| 892 | XGL_BUFFER_VIEW_CREATE_INFO view_info = {}; |
| 893 | view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 894 | view_info.buffer = obj(); |
| 895 | view_info.viewType = XGL_BUFFER_VIEW_TYPED; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 896 | view_info.format = viewFormat; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 897 | view_info.offset = 0; |
| 898 | view_info.range = allocationSize; |
| 899 | m_bufferView.init(*m_device, view_info); |
| 900 | |
| 901 | this->m_bufferViewInfo.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO; |
| 902 | this->m_bufferViewInfo.view = m_bufferView.obj(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | void XglIndexBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset) |
| 906 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 907 | xglCmdBindIndexBuffer(cmdBuffer, obj(), offset, m_indexType); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 908 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 909 | |
Tony Barbour | af1f919 | 2014-12-17 10:57:58 -0700 | [diff] [blame] | 910 | XGL_INDEX_TYPE XglIndexBufferObj::GetIndexType() |
| 911 | { |
| 912 | return m_indexType; |
| 913 | } |
| 914 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 915 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* XglShaderObj::GetStageCreateInfo() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 916 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 917 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO *stageInfo = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) calloc( 1,sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO) ); |
| 918 | stageInfo->sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 919 | stageInfo->shader.stage = m_stage; |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 920 | stageInfo->shader.shader = obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 921 | stageInfo->shader.linkConstBufferCount = 0; |
| 922 | stageInfo->shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 923 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 924 | return stageInfo; |
| 925 | } |
| 926 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 927 | XglShaderObj::XglShaderObj(XglDevice *device, const char * shader_code, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework) |
| 928 | { |
| 929 | XGL_RESULT err = XGL_SUCCESS; |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 930 | std::vector<unsigned int> spv; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 931 | XGL_SHADER_CREATE_INFO createInfo; |
| 932 | size_t shader_len; |
| 933 | |
| 934 | m_stage = stage; |
| 935 | m_device = device; |
| 936 | |
| 937 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 938 | createInfo.pNext = NULL; |
| 939 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 940 | if (!framework->m_use_spv) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 941 | |
| 942 | shader_len = strlen(shader_code); |
| 943 | createInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 944 | createInfo.pCode = malloc(createInfo.codeSize); |
| 945 | createInfo.flags = 0; |
| 946 | |
| 947 | /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */ |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 948 | ((uint32_t *) createInfo.pCode)[0] = ICD_SPV_MAGIC; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 949 | ((uint32_t *) createInfo.pCode)[1] = 0; |
| 950 | ((uint32_t *) createInfo.pCode)[2] = stage; |
| 951 | memcpy(((uint32_t *) createInfo.pCode + 3), shader_code, shader_len + 1); |
| 952 | |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 953 | err = init_try(*m_device, createInfo); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 956 | if (framework->m_use_spv || err) { |
| 957 | std::vector<unsigned int> spv; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 958 | err = XGL_SUCCESS; |
| 959 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 960 | // Use Reference GLSL to SPV compiler |
| 961 | framework->GLSLtoSPV(stage, shader_code, spv); |
| 962 | createInfo.pCode = spv.data(); |
| 963 | createInfo.codeSize = spv.size() * sizeof(unsigned int); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 964 | createInfo.flags = 0; |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 965 | |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 966 | init(*m_device, createInfo); |
| 967 | } |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 968 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 969 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 970 | XglPipelineObj::XglPipelineObj(XglDevice *device) |
| 971 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 972 | m_device = device; |
| 973 | m_vi_state.attributeCount = m_vi_state.bindingCount = 0; |
| 974 | m_vertexBufferCount = 0; |
| 975 | |
| 976 | m_ia_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO; |
| 977 | m_ia_state.pNext = XGL_NULL_HANDLE; |
| 978 | m_ia_state.topology = XGL_TOPOLOGY_TRIANGLE_LIST; |
| 979 | m_ia_state.disableVertexReuse = XGL_FALSE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 980 | m_ia_state.primitiveRestartEnable = XGL_FALSE; |
| 981 | m_ia_state.primitiveRestartIndex = 0; |
| 982 | |
| 983 | m_rs_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO; |
| 984 | m_rs_state.pNext = &m_ia_state; |
| 985 | m_rs_state.depthClipEnable = XGL_FALSE; |
| 986 | m_rs_state.rasterizerDiscardEnable = XGL_FALSE; |
Chia-I Wu | c8d1ec5 | 2015-03-24 11:01:50 +0800 | [diff] [blame] | 987 | m_rs_state.programPointSize = XGL_FALSE; |
| 988 | m_rs_state.pointOrigin = XGL_COORDINATE_ORIGIN_UPPER_LEFT; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 989 | m_rs_state.provokingVertex = XGL_PROVOKING_VERTEX_LAST; |
| 990 | m_rs_state.fillMode = XGL_FILL_SOLID; |
| 991 | m_rs_state.cullMode = XGL_CULL_NONE; |
| 992 | m_rs_state.frontFace = XGL_FRONT_FACE_CCW; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 993 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 994 | memset(&m_cb_state,0,sizeof(m_cb_state)); |
| 995 | m_cb_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO; |
| 996 | m_cb_state.pNext = &m_rs_state; |
| 997 | m_cb_state.alphaToCoverageEnable = XGL_FALSE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 998 | m_cb_state.logicOp = XGL_LOGIC_OP_COPY; |
| 999 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1000 | m_ms_state.pNext = &m_cb_state; |
| 1001 | m_ms_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO; |
| 1002 | m_ms_state.multisampleEnable = XGL_FALSE; |
| 1003 | m_ms_state.sampleMask = 1; // Do we have to specify MSAA even just to disable it? |
| 1004 | m_ms_state.samples = 1; |
| 1005 | m_ms_state.minSampleShading = 0; |
| 1006 | m_ms_state.sampleShadingEnable = 0; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1007 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1008 | m_ds_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO; |
| 1009 | m_ds_state.pNext = &m_ms_state, |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 1010 | m_ds_state.format = XGL_FMT_D32_SFLOAT; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1011 | m_ds_state.depthTestEnable = XGL_FALSE; |
| 1012 | m_ds_state.depthWriteEnable = XGL_FALSE; |
| 1013 | m_ds_state.depthBoundsEnable = XGL_FALSE; |
| 1014 | m_ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 1015 | m_ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP; |
| 1016 | m_ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 1017 | m_ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 1018 | m_ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 1019 | m_ds_state.stencilTestEnable = XGL_FALSE; |
| 1020 | m_ds_state.front = m_ds_state.back; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1021 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1022 | XGL_PIPELINE_CB_ATTACHMENT_STATE att = {}; |
| 1023 | att.blendEnable = XGL_FALSE; |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 1024 | att.format = XGL_FMT_B8G8R8A8_UNORM; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1025 | att.channelWriteMask = 0xf; |
| 1026 | AddColorAttachment(0, &att); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1027 | |
| 1028 | }; |
| 1029 | |
| 1030 | void XglPipelineObj::AddShader(XglShaderObj* shader) |
| 1031 | { |
| 1032 | m_shaderObjs.push_back(shader); |
| 1033 | } |
| 1034 | |
| 1035 | void XglPipelineObj::AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count) |
| 1036 | { |
| 1037 | m_vi_state.pVertexAttributeDescriptions = vi_attrib; |
| 1038 | m_vi_state.attributeCount = count; |
| 1039 | } |
| 1040 | |
| 1041 | void XglPipelineObj::AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count) |
| 1042 | { |
| 1043 | m_vi_state.pVertexBindingDescriptions = vi_binding; |
| 1044 | m_vi_state.bindingCount = count; |
| 1045 | } |
| 1046 | |
| 1047 | void XglPipelineObj::AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding) |
| 1048 | { |
| 1049 | m_vertexBufferObjs.push_back(vertexDataBuffer); |
| 1050 | m_vertexBufferBindings.push_back(binding); |
| 1051 | m_vertexBufferCount++; |
| 1052 | } |
| 1053 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1054 | void XglPipelineObj::AddColorAttachment(uint32_t binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att) |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 1055 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1056 | if (binding+1 > m_colorAttachments.size()) |
| 1057 | { |
| 1058 | m_colorAttachments.resize(binding+1); |
| 1059 | } |
| 1060 | m_colorAttachments[binding] = *att; |
| 1061 | } |
| 1062 | |
| 1063 | void XglPipelineObj::SetDepthStencil(XGL_PIPELINE_DS_STATE_CREATE_INFO *ds_state) |
| 1064 | { |
| 1065 | m_ds_state.format = ds_state->format; |
| 1066 | m_ds_state.depthTestEnable = ds_state->depthTestEnable; |
| 1067 | m_ds_state.depthWriteEnable = ds_state->depthWriteEnable; |
| 1068 | m_ds_state.depthBoundsEnable = ds_state->depthBoundsEnable; |
| 1069 | m_ds_state.depthFunc = ds_state->depthFunc; |
| 1070 | m_ds_state.stencilTestEnable = ds_state->stencilTestEnable; |
| 1071 | m_ds_state.back = ds_state->back; |
| 1072 | m_ds_state.front = ds_state->front; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 1073 | } |
| 1074 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1075 | void XglPipelineObj::CreateXGLPipeline(XglDescriptorSetObj *descriptorSet) |
| 1076 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1077 | void* head_ptr = &m_ds_state; |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1078 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1079 | |
| 1080 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo; |
| 1081 | |
| 1082 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 1083 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1084 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1085 | shaderCreateInfo->pNext = head_ptr; |
| 1086 | head_ptr = shaderCreateInfo; |
| 1087 | } |
| 1088 | |
| 1089 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 1090 | { |
| 1091 | m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO; |
| 1092 | m_vi_state.pNext = head_ptr; |
| 1093 | head_ptr = &m_vi_state; |
| 1094 | } |
| 1095 | |
| 1096 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1097 | info.pNext = head_ptr; |
| 1098 | info.flags = 0; |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 1099 | info.pSetLayoutChain = descriptorSet->GetLayoutChain(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1100 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1101 | m_cb_state.attachmentCount = m_colorAttachments.size(); |
| 1102 | m_cb_state.pAttachments = &m_colorAttachments[0]; |
| 1103 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1104 | init(*m_device, info); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1105 | } |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1106 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1107 | XGL_PIPELINE XglPipelineObj::GetPipelineHandle() |
| 1108 | { |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1109 | return obj(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 1112 | void XglPipelineObj::BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1113 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1114 | void* head_ptr = &m_ds_state; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1115 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1116 | |
| 1117 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1118 | |
| 1119 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 1120 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1121 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1122 | shaderCreateInfo->pNext = head_ptr; |
| 1123 | head_ptr = shaderCreateInfo; |
| 1124 | } |
| 1125 | |
| 1126 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 1127 | { |
| 1128 | m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO; |
| 1129 | m_vi_state.pNext = head_ptr; |
| 1130 | head_ptr = &m_vi_state; |
| 1131 | } |
| 1132 | |
| 1133 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1134 | info.pNext = head_ptr; |
| 1135 | info.flags = 0; |
Chia-I Wu | 41126e5 | 2015-03-26 15:27:55 +0800 | [diff] [blame] | 1136 | info.pSetLayoutChain = descriptorSet->GetLayoutChain(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1137 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1138 | init(*m_device, info); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1139 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1140 | xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, obj() ); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1141 | |
| 1142 | |
| 1143 | for (int i=0; i < m_vertexBufferCount; i++) |
| 1144 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1145 | m_vertexBufferObjs[i]->Bind(m_cmdBuffer, 0, m_vertexBufferBindings[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1146 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1147 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1148 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1149 | XglMemoryRefManager::XglMemoryRefManager() { |
| 1150 | |
| 1151 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1152 | |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1153 | void XglMemoryRefManager::AddMemoryRef(xgl_testing::Object *xglObject) { |
| 1154 | const std::vector<XGL_GPU_MEMORY> mems = xglObject->memories(); |
| 1155 | for (size_t i = 0; i < mems.size(); i++) { |
| 1156 | m_bufferObjs.push_back(mems[i]); |
| 1157 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1158 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1159 | |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1160 | void XglMemoryRefManager::AddMemoryRef(XGL_GPU_MEMORY *mem, uint32_t refCount) { |
| 1161 | for (size_t i = 0; i < refCount; i++) { |
| 1162 | m_bufferObjs.push_back(mem[i]); |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | void XglMemoryRefManager::AddRTMemoryRefs(vector<XglImage*>images, uint32_t rtCount) { |
| 1167 | for (uint32_t i = 0; i < rtCount; i++) { |
| 1168 | const std::vector<XGL_GPU_MEMORY> mems = images[i]->memories(); |
| 1169 | if (!mems.empty()) |
| 1170 | m_bufferObjs.push_back(mems[0]); |
| 1171 | } |
| 1172 | } |
| 1173 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1174 | XGL_MEMORY_REF* XglMemoryRefManager::GetMemoryRefList() { |
| 1175 | |
| 1176 | XGL_MEMORY_REF *localRefs; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1177 | uint32_t numRefs=m_bufferObjs.size(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1178 | |
| 1179 | if (numRefs <= 0) |
| 1180 | return NULL; |
| 1181 | |
| 1182 | localRefs = (XGL_MEMORY_REF*) malloc( numRefs * sizeof(XGL_MEMORY_REF) ); |
| 1183 | for (int i=0; i<numRefs; i++) |
| 1184 | { |
| 1185 | localRefs[i].flags = 0; |
Chia-I Wu | 283d7a6 | 2014-12-28 15:43:42 +0800 | [diff] [blame] | 1186 | localRefs[i].mem = m_bufferObjs[i]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1187 | } |
| 1188 | return localRefs; |
| 1189 | } |
| 1190 | int XglMemoryRefManager::GetNumRefs() { |
| 1191 | return m_bufferObjs.size(); |
| 1192 | } |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1193 | |
| 1194 | XglCommandBufferObj::XglCommandBufferObj(XglDevice *device) |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 1195 | : xgl_testing::CmdBuffer(*device, xgl_testing::CmdBuffer::create_info(device->graphics_queue_node_index_)) |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1196 | { |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1197 | m_device = device; |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1198 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1199 | |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1200 | XGL_CMD_BUFFER XglCommandBufferObj::GetBufferHandle() |
| 1201 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1202 | return obj(); |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1203 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1204 | |
Jon Ashburn | c4164b1 | 2014-12-31 17:10:47 -0700 | [diff] [blame] | 1205 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_CMD_BUFFER_BEGIN_INFO *pInfo) |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1206 | { |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1207 | begin(pInfo); |
| 1208 | return XGL_SUCCESS; |
| 1209 | } |
| 1210 | |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1211 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_RENDER_PASS renderpass_obj, XGL_FRAMEBUFFER framebuffer_obj) |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1212 | { |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1213 | begin(renderpass_obj, framebuffer_obj); |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1214 | return XGL_SUCCESS; |
| 1215 | } |
| 1216 | |
| 1217 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer() |
| 1218 | { |
| 1219 | begin(); |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1220 | return XGL_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | XGL_RESULT XglCommandBufferObj::EndCommandBuffer() |
| 1224 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1225 | end(); |
| 1226 | return XGL_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1229 | void XglCommandBufferObj::PipelineBarrier(XGL_PIPELINE_BARRIER *barrierPtr) |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1230 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1231 | xglCmdPipelineBarrier(obj(), barrierPtr); |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 1234 | void XglCommandBufferObj::ClearAllBuffers(XGL_CLEAR_COLOR clear_color, float depth_clear_color, uint32_t stencil_clear_color, |
| 1235 | XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1236 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1237 | uint32_t i; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1238 | const XGL_FLAGS output_mask = |
| 1239 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1240 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1241 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1242 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1243 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1244 | const XGL_FLAGS input_mask = 0; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1245 | |
| 1246 | // whatever we want to do, we do it to the whole buffer |
| 1247 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 1248 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 1249 | srRange.baseMipLevel = 0; |
| 1250 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1251 | srRange.baseArraySlice = 0; |
| 1252 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1253 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1254 | XGL_IMAGE_MEMORY_BARRIER memory_barrier = {}; |
| 1255 | memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 1256 | memory_barrier.outputMask = output_mask; |
| 1257 | memory_barrier.inputMask = input_mask; |
| 1258 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1259 | memory_barrier.subresourceRange = srRange; |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 1260 | XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &memory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1261 | |
Courtney Goeltzenleuchter | 1e8f3be | 2015-03-24 18:02:34 -0600 | [diff] [blame] | 1262 | XGL_PIPE_EVENT set_events[] = { XGL_PIPE_EVENT_GPU_COMMANDS_COMPLETE }; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1263 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1264 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1265 | pipeline_barrier.eventCount = 1; |
| 1266 | pipeline_barrier.pEvents = set_events; |
| 1267 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1268 | pipeline_barrier.memBarrierCount = 1; |
Mark Lobodzinski | d5d83ed | 2015-02-02 11:55:52 -0600 | [diff] [blame] | 1269 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1270 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 1271 | for (i = 0; i < m_renderTargets.size(); i++) { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1272 | memory_barrier.image = m_renderTargets[i]->image(); |
| 1273 | memory_barrier.oldLayout = m_renderTargets[i]->layout(); |
| 1274 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1275 | m_renderTargets[i]->layout(memory_barrier.newLayout); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1276 | |
Courtney Goeltzenleuchter | b3efe9b | 2015-03-25 11:25:10 -0600 | [diff] [blame] | 1277 | xglCmdClearColorImage(obj(), |
| 1278 | m_renderTargets[i]->image(), XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
| 1279 | clear_color, 1, &srRange ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | if (depthStencilImage) |
| 1283 | { |
| 1284 | XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {}; |
| 1285 | dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH; |
| 1286 | dsRange.baseMipLevel = 0; |
| 1287 | dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1288 | dsRange.baseArraySlice = 0; |
| 1289 | dsRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1290 | |
| 1291 | // prepare the depth buffer for clear |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1292 | |
| 1293 | memory_barrier.oldLayout = depthStencilBinding->layout; |
| 1294 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1295 | memory_barrier.image = depthStencilImage; |
| 1296 | memory_barrier.subresourceRange = dsRange; |
| 1297 | |
| 1298 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1299 | depthStencilBinding->layout = memory_barrier.newLayout; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1300 | |
Courtney Goeltzenleuchter | b3efe9b | 2015-03-25 11:25:10 -0600 | [diff] [blame] | 1301 | xglCmdClearDepthStencil(obj(), |
| 1302 | depthStencilImage, XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL, |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 1303 | depth_clear_color, stencil_clear_color, |
| 1304 | 1, &dsRange); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1305 | |
| 1306 | // prepare depth buffer for rendering |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1307 | memory_barrier.image = depthStencilImage; |
| 1308 | memory_barrier.oldLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1309 | memory_barrier.newLayout = depthStencilBinding->layout; |
| 1310 | memory_barrier.subresourceRange = dsRange; |
| 1311 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1312 | depthStencilBinding->layout = memory_barrier.newLayout; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | |
Jon Ashburn | cdc40be | 2015-01-02 18:27:14 -0700 | [diff] [blame] | 1316 | void XglCommandBufferObj::PrepareAttachments() |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1317 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1318 | uint32_t i; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1319 | const XGL_FLAGS output_mask = |
| 1320 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1321 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1322 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1323 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1324 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1325 | const XGL_FLAGS input_mask = |
| 1326 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 1327 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1328 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1329 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1330 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1331 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 1332 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1333 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1334 | XGL_MEMORY_INPUT_COPY_BIT; |
| 1335 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1336 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 1337 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 1338 | srRange.baseMipLevel = 0; |
| 1339 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1340 | srRange.baseArraySlice = 0; |
| 1341 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1342 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1343 | XGL_IMAGE_MEMORY_BARRIER memory_barrier = {}; |
| 1344 | memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 1345 | memory_barrier.outputMask = output_mask; |
| 1346 | memory_barrier.inputMask = input_mask; |
| 1347 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 1348 | memory_barrier.subresourceRange = srRange; |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 1349 | XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &memory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1350 | |
Courtney Goeltzenleuchter | 1e8f3be | 2015-03-24 18:02:34 -0600 | [diff] [blame] | 1351 | XGL_PIPE_EVENT set_events[] = { XGL_PIPE_EVENT_GPU_COMMANDS_COMPLETE }; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1352 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1353 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1354 | pipeline_barrier.eventCount = 1; |
| 1355 | pipeline_barrier.pEvents = set_events; |
| 1356 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1357 | pipeline_barrier.memBarrierCount = 1; |
Mark Lobodzinski | d5d83ed | 2015-02-02 11:55:52 -0600 | [diff] [blame] | 1358 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1359 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 1360 | for(i=0; i<m_renderTargets.size(); i++) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1361 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1362 | memory_barrier.image = m_renderTargets[i]->image(); |
| 1363 | memory_barrier.oldLayout = m_renderTargets[i]->layout(); |
| 1364 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1365 | m_renderTargets[i]->layout(memory_barrier.newLayout); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1366 | } |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame] | 1369 | void XglCommandBufferObj::BeginRenderPass(XGL_RENDER_PASS renderpass, XGL_FRAMEBUFFER framebuffer) |
| 1370 | { |
| 1371 | XGL_RENDER_PASS_BEGIN rp_begin = { |
| 1372 | renderpass, |
| 1373 | framebuffer, |
| 1374 | }; |
| 1375 | |
| 1376 | xglCmdBeginRenderPass( obj(), &rp_begin); |
| 1377 | } |
| 1378 | |
| 1379 | void XglCommandBufferObj::EndRenderPass(XGL_RENDER_PASS renderpass) |
| 1380 | { |
| 1381 | xglCmdEndRenderPass( obj(), renderpass); |
| 1382 | } |
| 1383 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1384 | void XglCommandBufferObj::BindStateObject(XGL_STATE_BIND_POINT stateBindPoint, XGL_DYNAMIC_STATE_OBJECT stateObject) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1385 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1386 | xglCmdBindDynamicStateObject( obj(), stateBindPoint, stateObject); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | void XglCommandBufferObj::AddRenderTarget(XglImage *renderTarget) |
| 1390 | { |
| 1391 | m_renderTargets.push_back(renderTarget); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1394 | void XglCommandBufferObj::DrawIndexed(uint32_t firstIndex, uint32_t indexCount, int32_t vertexOffset, uint32_t firstInstance, uint32_t instanceCount) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1395 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1396 | xglCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1399 | void XglCommandBufferObj::Draw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1400 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1401 | xglCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1404 | void XglCommandBufferObj::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, uint32_t numMemRefs) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1405 | { |
| 1406 | XGL_RESULT err = XGL_SUCCESS; |
| 1407 | |
| 1408 | // submit the command buffer to the universal queue |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1409 | err = xglQueueSubmit( m_device->m_queue, 1, &obj(), numMemRefs, memRefs, NULL ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1410 | ASSERT_XGL_SUCCESS( err ); |
| 1411 | |
| 1412 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1413 | ASSERT_XGL_SUCCESS( err ); |
| 1414 | |
| 1415 | // Wait for work to finish before cleaning up. |
| 1416 | xglDeviceWaitIdle(m_device->device()); |
| 1417 | |
| 1418 | } |
| 1419 | void XglCommandBufferObj::BindPipeline(XGL_PIPELINE pipeline) |
| 1420 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1421 | xglCmdBindPipeline( obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Chia-I Wu | 53f07d7 | 2015-03-28 15:23:55 +0800 | [diff] [blame^] | 1424 | void XglCommandBufferObj::BindDescriptorSet(const XglDescriptorSetObj *set) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1425 | { |
Chia-I Wu | 53f07d7 | 2015-03-28 15:23:55 +0800 | [diff] [blame^] | 1426 | XGL_DESCRIPTOR_SET set_obj = set->GetDescriptorSetHandle(); |
| 1427 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1428 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view) |
Chia-I Wu | 53f07d7 | 2015-03-28 15:23:55 +0800 | [diff] [blame^] | 1429 | xglCmdBindDescriptorSets(obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, |
| 1430 | set->GetLayoutChain(), 0, 1, &set_obj, NULL ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1431 | } |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1432 | void XglCommandBufferObj::BindIndexBuffer(XglIndexBufferObj *indexBuffer, uint32_t offset) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1433 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1434 | xglCmdBindIndexBuffer(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType()); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1435 | } |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1436 | void XglCommandBufferObj::BindVertexBuffer(XglConstantBufferObj *vertexBuffer, uint32_t offset, uint32_t binding) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1437 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1438 | xglCmdBindVertexBuffer(obj(), vertexBuffer->obj(), offset, binding); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1439 | } |
Tony Barbour | 1c45ce0 | 2015-03-27 17:03:18 -0600 | [diff] [blame] | 1440 | XglDepthStencilObj::XglDepthStencilObj() |
| 1441 | { |
| 1442 | m_initialized = false; |
| 1443 | } |
| 1444 | bool XglDepthStencilObj::Initialized() |
| 1445 | { |
| 1446 | return m_initialized; |
| 1447 | } |
| 1448 | |
| 1449 | XGL_DEPTH_STENCIL_BIND_INFO* XglDepthStencilObj::BindInfo() |
| 1450 | { |
| 1451 | return &m_depthStencilBindInfo; |
| 1452 | } |
| 1453 | |
| 1454 | void XglDepthStencilObj::Init(XglDevice *device, int32_t width, int32_t height) |
| 1455 | { |
| 1456 | XGL_IMAGE_CREATE_INFO image_info; |
| 1457 | XGL_DEPTH_STENCIL_VIEW_CREATE_INFO view_info; |
| 1458 | |
| 1459 | m_device = device; |
| 1460 | m_initialized = true; |
| 1461 | m_depth_stencil_fmt = XGL_FMT_D16_UNORM; |
| 1462 | |
| 1463 | image_info.sType = XGL_STRUCTURE_TYPE_IMAGE_CREATE_INFO; |
| 1464 | image_info.pNext = NULL; |
| 1465 | image_info.imageType = XGL_IMAGE_2D; |
| 1466 | image_info.format = m_depth_stencil_fmt; |
| 1467 | image_info.extent.width = width; |
| 1468 | image_info.extent.height = height; |
| 1469 | image_info.extent.depth = 1; |
| 1470 | image_info.mipLevels = 1; |
| 1471 | image_info.arraySize = 1; |
| 1472 | image_info.samples = 1; |
| 1473 | image_info.tiling = XGL_OPTIMAL_TILING; |
| 1474 | image_info.usage = XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT; |
| 1475 | image_info.flags = 0; |
| 1476 | init(*m_device, image_info); |
| 1477 | |
| 1478 | view_info.sType = XGL_STRUCTURE_TYPE_DEPTH_STENCIL_VIEW_CREATE_INFO; |
| 1479 | view_info.pNext = NULL; |
| 1480 | view_info.image = XGL_NULL_HANDLE; |
| 1481 | view_info.mipLevel = 0; |
| 1482 | view_info.baseArraySlice = 0; |
| 1483 | view_info.arraySize = 1; |
| 1484 | view_info.flags = 0; |
| 1485 | view_info.image = obj(); |
| 1486 | m_depthStencilView.init(*m_device, view_info); |
| 1487 | |
| 1488 | m_depthStencilBindInfo.view = m_depthStencilView.obj(); |
| 1489 | m_depthStencilBindInfo.layout = XGL_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; |
| 1490 | } |