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 | { |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 43 | // clear the back buffer to dark grey |
| 44 | m_clear_color.color.rawColor[0] = 64; |
| 45 | m_clear_color.color.rawColor[1] = 64; |
| 46 | m_clear_color.color.rawColor[2] = 64; |
| 47 | m_clear_color.color.rawColor[3] = 0; |
| 48 | m_clear_color.useRawValue = true; |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 49 | |
Courtney Goeltzenleuchter | 32e486c | 2014-10-22 14:12:38 -0600 | [diff] [blame] | 50 | m_depthStencilBinding.view = XGL_NULL_HANDLE; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | XglRenderFramework::~XglRenderFramework() |
| 54 | { |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 55 | |
| 56 | } |
| 57 | |
| 58 | void XglRenderFramework::InitFramework() |
| 59 | { |
| 60 | XGL_RESULT err; |
| 61 | |
Jon Ashburn | 1e46489 | 2015-01-29 15:48:00 -0700 | [diff] [blame] | 62 | err = xglCreateInstance(&app_info, NULL, &this->inst); |
| 63 | ASSERT_XGL_SUCCESS(err); |
| 64 | err = xglEnumerateGpus(inst, XGL_MAX_PHYSICAL_GPUS, &this->gpu_count, |
| 65 | objs); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 66 | ASSERT_XGL_SUCCESS(err); |
Jon Ashburn | bf843b2 | 2014-11-26 11:06:49 -0700 | [diff] [blame] | 67 | ASSERT_GE(this->gpu_count, 1) << "No GPU available"; |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 68 | |
| 69 | m_device = new XglDevice(0, objs[0]); |
| 70 | m_device->get_device_queue(); |
| 71 | } |
| 72 | |
| 73 | void XglRenderFramework::ShutdownFramework() |
| 74 | { |
| 75 | if (m_colorBlend) xglDestroyObject(m_colorBlend); |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 76 | if (m_stateDepthStencil) xglDestroyObject(m_stateDepthStencil); |
| 77 | if (m_stateRaster) xglDestroyObject(m_stateRaster); |
| 78 | if (m_cmdBuffer) xglDestroyObject(m_cmdBuffer); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 79 | if (m_framebuffer) xglDestroyObject(m_framebuffer); |
Tobin Ehlis | 976fc16 | 2015-03-26 08:23:25 -0600 | [diff] [blame] | 80 | if (m_renderPass) xglDestroyObject(m_renderPass); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 81 | |
| 82 | if (m_stateViewport) { |
| 83 | xglDestroyObject(m_stateViewport); |
| 84 | } |
Tobin Ehlis | 976fc16 | 2015-03-26 08:23:25 -0600 | [diff] [blame] | 85 | while (!m_renderTargets.empty()) { |
| 86 | xglDestroyObject(m_renderTargets.back()->targetView()); |
| 87 | xglBindObjectMemory(m_renderTargets.back()->image(), 0, XGL_NULL_HANDLE, 0); |
| 88 | xglDestroyObject(m_renderTargets.back()->image()); |
| 89 | xglFreeMemory(m_renderTargets.back()->memory()); |
| 90 | m_renderTargets.pop_back(); |
| 91 | } |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 92 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 93 | // reset the driver |
Chia-I Wu | b76e0fa | 2014-12-28 14:27:28 +0800 | [diff] [blame] | 94 | delete m_device; |
Jon Ashburn | 1e46489 | 2015-01-29 15:48:00 -0700 | [diff] [blame] | 95 | xglDestroyInstance(this->inst); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 96 | } |
| 97 | |
Courtney Goeltzenleuchter | 53d8d89 | 2014-10-08 12:20:26 -0600 | [diff] [blame] | 98 | void XglRenderFramework::InitState() |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 99 | { |
| 100 | XGL_RESULT err; |
| 101 | |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 102 | m_render_target_fmt = XGL_FMT_B8G8R8A8_UNORM; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 103 | |
| 104 | // create a raster state (solid, back-face culling) |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 105 | XGL_DYNAMIC_RS_STATE_CREATE_INFO raster = {}; |
| 106 | raster.sType = XGL_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO; |
| 107 | raster.pointSize = 1.0; |
| 108 | |
| 109 | err = xglCreateDynamicRasterState( device(), &raster, &m_stateRaster ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 110 | ASSERT_XGL_SUCCESS(err); |
| 111 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 112 | XGL_DYNAMIC_CB_STATE_CREATE_INFO blend = {}; |
| 113 | blend.sType = XGL_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO; |
| 114 | err = xglCreateDynamicColorBlendState(device(), &blend, &m_colorBlend); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 115 | ASSERT_XGL_SUCCESS( err ); |
| 116 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 117 | XGL_DYNAMIC_DS_STATE_CREATE_INFO depthStencil = {}; |
| 118 | depthStencil.sType = XGL_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 119 | depthStencil.minDepth = 0.f; |
| 120 | depthStencil.maxDepth = 1.f; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 121 | depthStencil.stencilFrontRef = 0; |
| 122 | depthStencil.stencilBackRef = 0; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 123 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 124 | err = xglCreateDynamicDepthStencilState( device(), &depthStencil, &m_stateDepthStencil ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 125 | ASSERT_XGL_SUCCESS( err ); |
| 126 | |
| 127 | XGL_CMD_BUFFER_CREATE_INFO cmdInfo = {}; |
| 128 | |
| 129 | cmdInfo.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO; |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 130 | cmdInfo.queueNodeIndex = m_device->graphics_queue_node_index_; |
| 131 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 132 | err = xglCreateCommandBuffer(device(), &cmdInfo, &m_cmdBuffer); |
| 133 | ASSERT_XGL_SUCCESS(err) << "xglCreateCommandBuffer failed"; |
| 134 | } |
| 135 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 136 | void XglRenderFramework::InitViewport(float width, float height) |
| 137 | { |
| 138 | XGL_RESULT err; |
| 139 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 140 | XGL_VIEWPORT viewport; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 141 | XGL_RECT scissor; |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 142 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 143 | XGL_DYNAMIC_VP_STATE_CREATE_INFO viewportCreate = {}; |
| 144 | viewportCreate.sType = XGL_STRUCTURE_TYPE_DYNAMIC_VP_STATE_CREATE_INFO; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 145 | viewportCreate.viewportAndScissorCount = 1; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 146 | viewport.originX = 0; |
| 147 | viewport.originY = 0; |
| 148 | viewport.width = 1.f * width; |
| 149 | viewport.height = 1.f * height; |
| 150 | viewport.minDepth = 0.f; |
| 151 | viewport.maxDepth = 1.f; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 152 | scissor.extent.width = width; |
| 153 | scissor.extent.height = height; |
| 154 | scissor.offset.x = 0; |
| 155 | scissor.offset.y = 0; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 156 | viewportCreate.pViewports = &viewport; |
Courtney Goeltzenleuchter | bbe3cc5 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 157 | viewportCreate.pScissors = &scissor; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 158 | |
| 159 | err = xglCreateDynamicViewportState( device(), &viewportCreate, &m_stateViewport ); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 160 | ASSERT_XGL_SUCCESS( err ); |
| 161 | m_width = width; |
| 162 | m_height = height; |
| 163 | } |
| 164 | |
Courtney Goeltzenleuchter | 02d33c1 | 2014-10-08 14:26:40 -0600 | [diff] [blame] | 165 | void XglRenderFramework::InitViewport() |
| 166 | { |
| 167 | InitViewport(m_width, m_height); |
| 168 | } |
| 169 | |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 170 | void XglRenderFramework::InitRenderTarget() |
| 171 | { |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 172 | InitRenderTarget(1); |
| 173 | } |
| 174 | |
| 175 | void XglRenderFramework::InitRenderTarget(uint32_t targets) |
| 176 | { |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 177 | std::vector<XGL_ATTACHMENT_LOAD_OP> load_ops; |
| 178 | std::vector<XGL_ATTACHMENT_STORE_OP> store_ops; |
| 179 | std::vector<XGL_CLEAR_COLOR> clear_colors; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 180 | uint32_t i; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 181 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 182 | for (i = 0; i < targets; i++) { |
Chia-I Wu | f50ee21 | 2014-12-29 14:31:52 +0800 | [diff] [blame] | 183 | XglImage *img = new XglImage(m_device); |
| 184 | img->init(m_width, m_height, m_render_target_fmt, |
| 185 | XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT | |
| 186 | XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 187 | m_colorBindings[i].view = img->targetView(); |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 188 | m_colorBindings[i].layout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 189 | m_renderTargets.push_back(img); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 190 | load_ops.push_back(XGL_ATTACHMENT_LOAD_OP_LOAD); |
| 191 | store_ops.push_back(XGL_ATTACHMENT_STORE_OP_STORE); |
| 192 | clear_colors.push_back(m_clear_color); |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 193 | } |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 194 | // Create Framebuffer and RenderPass with color attachments and any depth/stencil attachment |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 195 | XGL_DEPTH_STENCIL_BIND_INFO *dsBinding; |
| 196 | if (m_depthStencilBinding.view) |
| 197 | dsBinding = &m_depthStencilBinding; |
| 198 | else |
| 199 | dsBinding = NULL; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 200 | XGL_FRAMEBUFFER_CREATE_INFO fb_info = {}; |
| 201 | fb_info.sType = XGL_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; |
| 202 | fb_info.pNext = NULL; |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 203 | fb_info.colorAttachmentCount = m_renderTargets.size(); |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 204 | fb_info.pColorAttachments = m_colorBindings; |
| 205 | fb_info.pDepthStencilAttachment = dsBinding; |
| 206 | fb_info.sampleCount = 1; |
| 207 | fb_info.width = (uint32_t)m_width; |
| 208 | fb_info.height = (uint32_t)m_height; |
| 209 | fb_info.layers = 1; |
| 210 | |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 211 | XGL_RENDER_PASS_CREATE_INFO rp_info; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 212 | |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 213 | memset(&rp_info, 0 , sizeof(rp_info)); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 214 | xglCreateFramebuffer(device(), &fb_info, &m_framebuffer); |
| 215 | |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 216 | rp_info.sType = XGL_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; |
| 217 | rp_info.renderArea.extent.width = m_width; |
| 218 | rp_info.renderArea.extent.height = m_height; |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 219 | rp_info.colorAttachmentCount = m_renderTargets.size(); |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 220 | rp_info.pColorFormats = &m_render_target_fmt; |
| 221 | rp_info.pColorLayouts = &m_colorBindings[0].layout; |
| 222 | rp_info.pColorLoadOps = &load_ops[0]; |
| 223 | rp_info.pColorStoreOps = &store_ops[0]; |
| 224 | rp_info.pColorLoadClearValues = &clear_colors[0]; |
| 225 | rp_info.depthStencilFormat = m_depth_stencil_fmt; |
| 226 | rp_info.depthStencilLayout = m_depthStencilBinding.layout; |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 227 | rp_info.depthLoadOp = XGL_ATTACHMENT_LOAD_OP_LOAD; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 228 | rp_info.depthLoadClearValue = m_depth_clear_color; |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 229 | rp_info.depthStoreOp = XGL_ATTACHMENT_STORE_OP_STORE; |
| 230 | rp_info.stencilLoadOp = XGL_ATTACHMENT_LOAD_OP_LOAD; |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 231 | rp_info.stencilLoadClearValue = m_stencil_clear_color; |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 232 | rp_info.stencilStoreOp = XGL_ATTACHMENT_STORE_OP_STORE; |
| 233 | xglCreateRenderPass(device(), &rp_info, &m_renderPass); |
Courtney Goeltzenleuchter | a4b278b | 2014-10-08 08:50:49 -0600 | [diff] [blame] | 234 | } |
| 235 | |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 236 | |
| 237 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 238 | XglDevice::XglDevice(uint32_t id, XGL_PHYSICAL_GPU obj) : |
Chia-I Wu | fb1459b | 2014-12-29 15:23:20 +0800 | [diff] [blame] | 239 | xgl_testing::Device(obj), id(id) |
| 240 | { |
| 241 | init(); |
| 242 | |
| 243 | props = gpu().properties(); |
| 244 | queue_props = &gpu().queue_properties()[0]; |
| 245 | } |
| 246 | |
| 247 | void XglDevice::get_device_queue() |
| 248 | { |
| 249 | ASSERT_NE(true, graphics_queues().empty()); |
| 250 | m_queue = graphics_queues()[0]->obj(); |
| 251 | } |
| 252 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 253 | XglDescriptorSetObj::XglDescriptorSetObj(XglDevice *device) |
| 254 | { |
| 255 | m_device = device; |
| 256 | m_nextSlot = 0; |
| 257 | |
| 258 | } |
| 259 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 260 | XglDescriptorSetObj::~XglDescriptorSetObj() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 261 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 262 | delete m_set; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 263 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 264 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 265 | int XglDescriptorSetObj::AppendDummy() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 266 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 267 | /* request a descriptor but do not update it */ |
| 268 | XGL_DESCRIPTOR_TYPE_COUNT tc = {}; |
| 269 | tc.type = XGL_DESCRIPTOR_TYPE_RAW_BUFFER; |
| 270 | tc.count = 1; |
| 271 | m_type_counts.push_back(tc); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 272 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 273 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 274 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 275 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 276 | int XglDescriptorSetObj::AppendBuffer(XGL_DESCRIPTOR_TYPE type, XglConstantBufferObj *constantBuffer) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 277 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 278 | XGL_DESCRIPTOR_TYPE_COUNT tc = {}; |
| 279 | tc.type = type; |
| 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 | m_bufferInfo.push_back(&constantBuffer->m_bufferViewInfo); |
| 284 | |
| 285 | m_updateBuffers.push_back(xgl_testing::DescriptorSet::update(type, m_nextSlot, 1, |
| 286 | (const XGL_BUFFER_VIEW_ATTACH_INFO **) NULL)); |
| 287 | |
| 288 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 289 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 290 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 291 | int XglDescriptorSetObj::AppendSamplerTexture( XglSamplerObj* sampler, XglTextureObj* texture) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 292 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 293 | XGL_DESCRIPTOR_TYPE_COUNT tc = {}; |
| 294 | tc.type = XGL_DESCRIPTOR_TYPE_SAMPLER_TEXTURE; |
| 295 | tc.count = 1; |
| 296 | m_type_counts.push_back(tc); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 297 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 298 | XGL_SAMPLER_IMAGE_VIEW_INFO tmp = {}; |
| 299 | tmp.pSampler = sampler->obj(); |
| 300 | tmp.pImageView = &texture->m_textureViewInfo; |
| 301 | m_samplerTextureInfo.push_back(tmp); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 302 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 303 | m_updateSamplerTextures.push_back(xgl_testing::DescriptorSet::update(m_nextSlot, 1, |
| 304 | (const XGL_SAMPLER_IMAGE_VIEW_INFO *) NULL)); |
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 | return m_nextSlot++; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 307 | } |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 308 | |
| 309 | XGL_DESCRIPTOR_SET_LAYOUT XglDescriptorSetObj::GetLayout() |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 310 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 311 | return m_layout.obj(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | XGL_DESCRIPTOR_SET XglDescriptorSetObj::GetDescriptorSetHandle() |
| 315 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 316 | return m_set->obj(); |
Tony Barbour | b5f4d08 | 2014-12-17 10:54:03 -0700 | [diff] [blame] | 317 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 318 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 319 | void XglDescriptorSetObj::CreateXGLDescriptorSet(XglCommandBufferObj *cmdBuffer) |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 320 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 321 | // create XGL_DESCRIPTOR_REGION |
| 322 | XGL_DESCRIPTOR_REGION_CREATE_INFO region = {}; |
| 323 | region.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_REGION_CREATE_INFO; |
| 324 | region.count = m_type_counts.size(); |
| 325 | region.pTypeCount = &m_type_counts[0]; |
| 326 | init(*m_device, XGL_DESCRIPTOR_REGION_USAGE_ONE_SHOT, 1, region); |
Tony Barbour | 824b771 | 2014-12-18 17:06:21 -0700 | [diff] [blame] | 327 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 328 | // create XGL_DESCRIPTOR_SET_LAYOUT |
| 329 | vector<XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO> layout; |
| 330 | layout.resize(m_type_counts.size()); |
| 331 | for (int i = 0; i < m_type_counts.size(); i++) { |
| 332 | layout[i].sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; |
| 333 | layout[i].descriptorType = m_type_counts[i].type; |
| 334 | layout[i].count = m_type_counts[i].count; |
| 335 | layout[i].stageFlags = XGL_SHADER_STAGE_FLAGS_ALL; |
| 336 | layout[i].immutableSampler = XGL_NULL_HANDLE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 337 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 338 | if (i < m_type_counts.size() - 1) |
| 339 | layout[i].pNext = &layout[i + 1]; |
| 340 | else |
| 341 | layout[i].pNext = NULL; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 342 | } |
Chia-I Wu | ac0f1e7 | 2014-12-28 22:32:36 +0800 | [diff] [blame] | 343 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 344 | m_layout.init(*m_device, 0, layout[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 345 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 346 | // create XGL_DESCRIPTOR_SET |
| 347 | m_set = alloc_sets(XGL_DESCRIPTOR_SET_USAGE_STATIC, m_layout); |
| 348 | |
| 349 | // build the update chain |
| 350 | for (int i = 0; i < m_updateBuffers.size(); i++) { |
| 351 | m_updateBuffers[i].pBufferViews = &m_bufferInfo[i]; |
| 352 | |
| 353 | if (i < m_updateBuffers.size() - 1) |
| 354 | m_updateBuffers[i].pNext = &m_updateBuffers[i + 1]; |
| 355 | else if (m_updateSamplerTextures.empty()) |
| 356 | m_updateBuffers[i].pNext = NULL; |
| 357 | else |
| 358 | m_updateBuffers[i].pNext = &m_updateSamplerTextures[0]; |
| 359 | } |
| 360 | for (int i = 0; i < m_updateSamplerTextures.size(); i++) { |
| 361 | m_updateSamplerTextures[i].pSamplerImageViews = &m_samplerTextureInfo[i]; |
| 362 | |
| 363 | if (i < m_updateSamplerTextures.size() - 1) |
| 364 | m_updateSamplerTextures[i].pNext = &m_updateSamplerTextures[i + 1]; |
| 365 | else |
| 366 | m_updateSamplerTextures[i].pNext = NULL; |
| 367 | } |
| 368 | const void *chain = (!m_updateBuffers.empty()) ? (const void *) &m_updateBuffers[0] : |
| 369 | (!m_updateSamplerTextures.empty()) ? (const void *) &m_updateSamplerTextures[0] : |
| 370 | NULL; |
| 371 | |
| 372 | // do the updates |
| 373 | m_device->begin_descriptor_region_update(XGL_DESCRIPTOR_UPDATE_MODE_FASTEST); |
| 374 | clear_sets(*m_set); |
| 375 | m_set->update(chain); |
| 376 | m_device->end_descriptor_region_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 | |
| 493 | XGL_IMAGE_COPY copy_region = {}; |
| 494 | copy_region.srcSubresource.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 495 | copy_region.srcSubresource.arraySlice = 0; |
| 496 | copy_region.srcSubresource.mipLevel = 0; |
| 497 | copy_region.srcOffset.x = 0; |
| 498 | copy_region.srcOffset.y = 0; |
| 499 | copy_region.srcOffset.z = 0; |
| 500 | copy_region.destSubresource.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 501 | copy_region.destSubresource.arraySlice = 0; |
| 502 | copy_region.destSubresource.mipLevel = 0; |
| 503 | copy_region.destOffset.x = 0; |
| 504 | copy_region.destOffset.y = 0; |
| 505 | copy_region.destOffset.z = 0; |
| 506 | copy_region.extent = fromImage.extent(); |
| 507 | |
| 508 | xglCmdCopyImage(cmd_buf, fromImage.obj(), obj(), 1, ©_region); |
| 509 | |
| 510 | XGL_IMAGE_MEMORY_BARRIER image_memory_barrier = {}; |
| 511 | image_memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 512 | image_memory_barrier.pNext = NULL; |
| 513 | image_memory_barrier.outputMask = XGL_MEMORY_OUTPUT_COPY_BIT; |
| 514 | image_memory_barrier.inputMask = XGL_MEMORY_INPUT_SHADER_READ_BIT | XGL_MEMORY_INPUT_COPY_BIT; |
| 515 | image_memory_barrier.oldLayout = XGL_IMAGE_LAYOUT_GENERAL; |
| 516 | image_memory_barrier.newLayout = XGL_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL; |
| 517 | image_memory_barrier.image = fromImage.obj(); |
| 518 | image_memory_barrier.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 519 | image_memory_barrier.subresourceRange.baseMipLevel = 0; |
| 520 | image_memory_barrier.subresourceRange.mipLevels = 1; |
| 521 | image_memory_barrier.subresourceRange.baseArraySlice = 0; |
| 522 | image_memory_barrier.subresourceRange.arraySize = 0; |
| 523 | |
| 524 | XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &image_memory_barrier; |
| 525 | |
| 526 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 527 | XGL_PIPELINE_BARRIER pipeline_barrier; |
| 528 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 529 | pipeline_barrier.pNext = NULL; |
| 530 | pipeline_barrier.eventCount = 1; |
| 531 | pipeline_barrier.pEvents = set_events; |
| 532 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 533 | pipeline_barrier.memBarrierCount = 1; |
| 534 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
| 535 | |
| 536 | // write barrier to the command buffer |
| 537 | xglCmdPipelineBarrier(cmd_buf, &pipeline_barrier); |
| 538 | |
| 539 | err = xglEndCommandBuffer(cmd_buf); |
| 540 | assert(!err); |
| 541 | |
| 542 | const XGL_CMD_BUFFER cmd_bufs[] = { cmd_buf }; |
| 543 | XGL_MEMORY_REF mem_refs[16]; |
| 544 | uint32_t num_refs = 0; |
| 545 | const std::vector<XGL_GPU_MEMORY> from_mems = fromImage.memories(); |
| 546 | const std::vector<XGL_GPU_MEMORY> to_mems = memories(); |
| 547 | |
| 548 | for (uint32_t j = 0; j < from_mems.size(); j++) { |
| 549 | mem_refs[num_refs].flags = XGL_MEMORY_REF_READ_ONLY_BIT; |
| 550 | mem_refs[num_refs].mem = from_mems[j]; |
| 551 | num_refs++; |
| 552 | assert(num_refs < 16); |
| 553 | } |
| 554 | |
| 555 | for (uint32_t j = 0; j < to_mems.size(); j++) { |
| 556 | mem_refs[num_refs].flags = XGL_MEMORY_REF_READ_ONLY_BIT; |
| 557 | mem_refs[num_refs].mem = to_mems[j]; |
| 558 | num_refs++; |
| 559 | assert(num_refs < 16); |
| 560 | } |
| 561 | |
| 562 | err = xglQueueSubmit(m_device->m_queue, 1, cmd_bufs, |
| 563 | num_refs, mem_refs, XGL_NULL_HANDLE); |
| 564 | assert(!err); |
| 565 | |
| 566 | err = xglQueueWaitIdle(m_device->m_queue); |
| 567 | assert(!err); |
| 568 | |
| 569 | xglDestroyObject(cmd_buf); |
| 570 | |
| 571 | return XGL_SUCCESS; |
| 572 | } |
| 573 | |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 574 | XglTextureObj::XglTextureObj(XglDevice *device, uint32_t *colors) |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 575 | :XglImage(device) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 576 | { |
| 577 | m_device = device; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 578 | const XGL_FORMAT tex_format = XGL_FMT_B8G8R8A8_UNORM; |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 579 | uint32_t tex_colors[2] = { 0xffff0000, 0xff00ff00 }; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 580 | void *data; |
| 581 | int32_t x, y; |
| 582 | XglImage stagingImage(device); |
| 583 | |
| 584 | stagingImage.init(16, 16, tex_format, 0, XGL_LINEAR_TILING); |
| 585 | 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] | 586 | |
| 587 | if (colors == NULL) |
| 588 | colors = tex_colors; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 589 | |
| 590 | memset(&m_textureViewInfo,0,sizeof(m_textureViewInfo)); |
| 591 | |
| 592 | m_textureViewInfo.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO; |
| 593 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 594 | XGL_IMAGE_VIEW_CREATE_INFO view = {}; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 595 | view.sType = XGL_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 596 | view.pNext = NULL; |
| 597 | view.image = XGL_NULL_HANDLE; |
| 598 | view.viewType = XGL_IMAGE_VIEW_2D; |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 599 | view.format = tex_format; |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 600 | view.channels.r = XGL_CHANNEL_SWIZZLE_R; |
| 601 | view.channels.g = XGL_CHANNEL_SWIZZLE_G; |
| 602 | view.channels.b = XGL_CHANNEL_SWIZZLE_B; |
| 603 | view.channels.a = XGL_CHANNEL_SWIZZLE_A; |
| 604 | view.subresourceRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 605 | view.subresourceRange.baseMipLevel = 0; |
| 606 | view.subresourceRange.mipLevels = 1; |
| 607 | view.subresourceRange.baseArraySlice = 0; |
| 608 | view.subresourceRange.arraySize = 1; |
| 609 | view.minLod = 0.0f; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 610 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 611 | /* create image */ |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 612 | 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] | 613 | |
| 614 | /* create image view */ |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 615 | view.image = obj(); |
| 616 | m_textureView.init(*m_device, view); |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 617 | m_textureViewInfo.view = m_textureView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 618 | |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 619 | data = stagingImage.map(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 620 | |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 621 | for (y = 0; y < extent().height; y++) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 622 | uint32_t *row = (uint32_t *) ((char *) data + layout.rowPitch * y); |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 623 | for (x = 0; x < extent().width; x++) |
Tony Barbour | ebc093f | 2015-04-01 16:38:10 -0600 | [diff] [blame] | 624 | row[x] = colors[(x & 1) ^ (y & 1)]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 625 | } |
Tony Barbour | 5dc515d | 2015-04-01 17:47:06 -0600 | [diff] [blame] | 626 | stagingImage.unmap(); |
| 627 | XglImage::CopyImage(stagingImage); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 628 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 629 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 630 | XglSamplerObj::XglSamplerObj(XglDevice *device) |
| 631 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 632 | m_device = device; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 633 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 634 | XGL_SAMPLER_CREATE_INFO samplerCreateInfo; |
| 635 | memset(&samplerCreateInfo,0,sizeof(samplerCreateInfo)); |
| 636 | samplerCreateInfo.sType = XGL_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; |
| 637 | samplerCreateInfo.magFilter = XGL_TEX_FILTER_NEAREST; |
| 638 | samplerCreateInfo.minFilter = XGL_TEX_FILTER_NEAREST; |
| 639 | samplerCreateInfo.mipMode = XGL_TEX_MIPMAP_BASE; |
| 640 | samplerCreateInfo.addressU = XGL_TEX_ADDRESS_WRAP; |
| 641 | samplerCreateInfo.addressV = XGL_TEX_ADDRESS_WRAP; |
| 642 | samplerCreateInfo.addressW = XGL_TEX_ADDRESS_WRAP; |
| 643 | samplerCreateInfo.mipLodBias = 0.0; |
| 644 | samplerCreateInfo.maxAnisotropy = 0.0; |
| 645 | samplerCreateInfo.compareFunc = XGL_COMPARE_NEVER; |
| 646 | samplerCreateInfo.minLod = 0.0; |
| 647 | samplerCreateInfo.maxLod = 0.0; |
| 648 | samplerCreateInfo.borderColorType = XGL_BORDER_COLOR_OPAQUE_WHITE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 649 | |
Chia-I Wu | e9864b5 | 2014-12-28 16:32:24 +0800 | [diff] [blame] | 650 | init(*m_device, samplerCreateInfo); |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 651 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 652 | |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 653 | /* |
| 654 | * Basic ConstantBuffer constructor. Then use create methods to fill in the details. |
| 655 | */ |
| 656 | XglConstantBufferObj::XglConstantBufferObj(XglDevice *device) |
| 657 | { |
| 658 | m_device = device; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 659 | m_commandBuffer = 0; |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 660 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 661 | memset(&m_bufferViewInfo,0,sizeof(m_bufferViewInfo)); |
Courtney Goeltzenleuchter | 3b0a815 | 2014-12-04 15:18:47 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 664 | XglConstantBufferObj::XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data) |
| 665 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 666 | m_device = device; |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 667 | m_commandBuffer = 0; |
| 668 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 669 | memset(&m_bufferViewInfo,0,sizeof(m_bufferViewInfo)); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 670 | m_numVertices = constantCount; |
| 671 | m_stride = constantSize; |
| 672 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 673 | const size_t allocationSize = constantCount * constantSize; |
| 674 | init(*m_device, allocationSize); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 675 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 676 | void *pData = map(); |
| 677 | memcpy(pData, data, allocationSize); |
| 678 | unmap(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 679 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 680 | // set up the buffer view for the constant buffer |
| 681 | XGL_BUFFER_VIEW_CREATE_INFO view_info = {}; |
| 682 | view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 683 | view_info.buffer = obj(); |
Chia-I Wu | bb0c8d2 | 2015-01-16 22:31:25 +0800 | [diff] [blame] | 684 | view_info.viewType = XGL_BUFFER_VIEW_RAW; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 685 | view_info.offset = 0; |
| 686 | view_info.range = allocationSize; |
| 687 | m_bufferView.init(*m_device, view_info); |
| 688 | |
| 689 | this->m_bufferViewInfo.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO; |
| 690 | this->m_bufferViewInfo.view = m_bufferView.obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 691 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 692 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 693 | 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] | 694 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 695 | xglCmdBindVertexBuffer(cmdBuffer, obj(), offset, binding); |
Courtney Goeltzenleuchter | 3764030 | 2014-12-04 15:26:56 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 699 | void XglConstantBufferObj::BufferMemoryBarrier( |
| 700 | XGL_FLAGS outputMask /*= |
| 701 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 702 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 703 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 704 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 705 | XGL_MEMORY_OUTPUT_COPY_BIT*/, |
| 706 | XGL_FLAGS inputMask /*= |
| 707 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 708 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 709 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 710 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 711 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 712 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 713 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 714 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 715 | XGL_MEMORY_INPUT_COPY_BIT*/) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 716 | { |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 717 | XGL_RESULT err = XGL_SUCCESS; |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 718 | |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 719 | if (!m_commandBuffer) |
| 720 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 721 | m_fence.init(*m_device, xgl_testing::Fence::create_info(0)); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 722 | |
| 723 | m_commandBuffer = new XglCommandBufferObj(m_device); |
| 724 | |
| 725 | } |
| 726 | else |
| 727 | { |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 728 | m_device->wait(m_fence); |
Tony Barbour | 3842280 | 2014-12-10 14:36:31 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 731 | // open the command buffer |
Tony Barbour | bdf0a31 | 2015-04-01 17:10:07 -0600 | [diff] [blame] | 732 | XGL_CMD_BUFFER_BEGIN_INFO cmd_buf_info = {}; |
| 733 | cmd_buf_info.sType = XGL_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO; |
| 734 | cmd_buf_info.pNext = NULL; |
| 735 | cmd_buf_info.flags = 0; |
| 736 | |
Jon Ashburn | c4164b1 | 2014-12-31 17:10:47 -0700 | [diff] [blame] | 737 | err = m_commandBuffer->BeginCommandBuffer(&cmd_buf_info); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 738 | ASSERT_XGL_SUCCESS(err); |
| 739 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 740 | XGL_BUFFER_MEMORY_BARRIER memory_barrier = |
| 741 | buffer_memory_barrier(outputMask, inputMask, 0, m_numVertices * m_stride); |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 742 | XGL_BUFFER_MEMORY_BARRIER *pmemory_barrier = &memory_barrier; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 743 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 744 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 745 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 746 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 747 | pipeline_barrier.eventCount = 1; |
| 748 | pipeline_barrier.pEvents = set_events; |
| 749 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 750 | pipeline_barrier.memBarrierCount = 1; |
Mark Lobodzinski | d5d83ed | 2015-02-02 11:55:52 -0600 | [diff] [blame] | 751 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 752 | |
| 753 | // write barrier to the command buffer |
| 754 | m_commandBuffer->PipelineBarrier(&pipeline_barrier); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 755 | |
| 756 | // finish recording the command buffer |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 757 | err = m_commandBuffer->EndCommandBuffer(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 758 | ASSERT_XGL_SUCCESS(err); |
| 759 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 760 | uint32_t numMemRefs=1; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 761 | XGL_MEMORY_REF memRefs; |
| 762 | // this command buffer only uses the vertex buffer memory |
| 763 | memRefs.flags = 0; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 764 | memRefs.mem = memories()[0]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 765 | |
| 766 | // submit the command buffer to the universal queue |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 767 | XGL_CMD_BUFFER bufferArray[1]; |
| 768 | bufferArray[0] = m_commandBuffer->GetBufferHandle(); |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 769 | 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] | 770 | ASSERT_XGL_SUCCESS(err); |
| 771 | } |
| 772 | |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 773 | XglIndexBufferObj::XglIndexBufferObj(XglDevice *device) |
| 774 | : XglConstantBufferObj(device) |
| 775 | { |
| 776 | |
| 777 | } |
| 778 | |
| 779 | void XglIndexBufferObj::CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE indexType, const void* data) |
| 780 | { |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 781 | XGL_FORMAT viewFormat; |
| 782 | |
| 783 | m_numVertices = numIndexes; |
| 784 | m_indexType = indexType; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 785 | switch (indexType) { |
| 786 | case XGL_INDEX_8: |
| 787 | m_stride = 1; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 788 | viewFormat = XGL_FMT_R8_UINT; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 789 | break; |
| 790 | case XGL_INDEX_16: |
| 791 | m_stride = 2; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 792 | viewFormat = XGL_FMT_R16_UINT; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 793 | break; |
| 794 | case XGL_INDEX_32: |
| 795 | m_stride = 4; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 796 | viewFormat = XGL_FMT_R32_UINT; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 797 | break; |
Chia-I Wu | b4c2aa4 | 2014-12-15 23:50:11 +0800 | [diff] [blame] | 798 | default: |
| 799 | assert(!"unknown index type"); |
| 800 | break; |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 803 | const size_t allocationSize = numIndexes * m_stride; |
| 804 | init(*m_device, allocationSize); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 805 | |
Chia-I Wu | a07fee6 | 2014-12-28 15:26:08 +0800 | [diff] [blame] | 806 | void *pData = map(); |
| 807 | memcpy(pData, data, allocationSize); |
| 808 | unmap(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 809 | |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 810 | // set up the buffer view for the constant buffer |
| 811 | XGL_BUFFER_VIEW_CREATE_INFO view_info = {}; |
| 812 | view_info.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; |
| 813 | view_info.buffer = obj(); |
| 814 | view_info.viewType = XGL_BUFFER_VIEW_TYPED; |
| 815 | view_info.stride = m_stride; |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 816 | view_info.format = viewFormat; |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 817 | view_info.offset = 0; |
| 818 | view_info.range = allocationSize; |
| 819 | m_bufferView.init(*m_device, view_info); |
| 820 | |
| 821 | this->m_bufferViewInfo.sType = XGL_STRUCTURE_TYPE_BUFFER_VIEW_ATTACH_INFO; |
| 822 | this->m_bufferViewInfo.view = m_bufferView.obj(); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | void XglIndexBufferObj::Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset) |
| 826 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 827 | xglCmdBindIndexBuffer(cmdBuffer, obj(), offset, m_indexType); |
Courtney Goeltzenleuchter | 8a78593 | 2014-12-04 15:24:05 -0700 | [diff] [blame] | 828 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 829 | |
Tony Barbour | af1f919 | 2014-12-17 10:57:58 -0700 | [diff] [blame] | 830 | XGL_INDEX_TYPE XglIndexBufferObj::GetIndexType() |
| 831 | { |
| 832 | return m_indexType; |
| 833 | } |
| 834 | |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 835 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* XglShaderObj::GetStageCreateInfo() |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 836 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 837 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO *stageInfo = (XGL_PIPELINE_SHADER_STAGE_CREATE_INFO*) calloc( 1,sizeof(XGL_PIPELINE_SHADER_STAGE_CREATE_INFO) ); |
| 838 | stageInfo->sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; |
| 839 | stageInfo->shader.stage = m_stage; |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 840 | stageInfo->shader.shader = obj(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 841 | stageInfo->shader.linkConstBufferCount = 0; |
| 842 | stageInfo->shader.pLinkConstBufferInfo = XGL_NULL_HANDLE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 843 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 844 | return stageInfo; |
| 845 | } |
| 846 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 847 | XglShaderObj::XglShaderObj(XglDevice *device, const char * shader_code, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework) |
| 848 | { |
| 849 | XGL_RESULT err = XGL_SUCCESS; |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 850 | std::vector<unsigned int> spv; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 851 | XGL_SHADER_CREATE_INFO createInfo; |
| 852 | size_t shader_len; |
| 853 | |
| 854 | m_stage = stage; |
| 855 | m_device = device; |
| 856 | |
| 857 | createInfo.sType = XGL_STRUCTURE_TYPE_SHADER_CREATE_INFO; |
| 858 | createInfo.pNext = NULL; |
| 859 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 860 | if (!framework->m_use_spv) { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 861 | |
| 862 | shader_len = strlen(shader_code); |
| 863 | createInfo.codeSize = 3 * sizeof(uint32_t) + shader_len + 1; |
| 864 | createInfo.pCode = malloc(createInfo.codeSize); |
| 865 | createInfo.flags = 0; |
| 866 | |
| 867 | /* try version 0 first: XGL_PIPELINE_SHADER_STAGE followed by GLSL */ |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 868 | ((uint32_t *) createInfo.pCode)[0] = ICD_SPV_MAGIC; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 869 | ((uint32_t *) createInfo.pCode)[1] = 0; |
| 870 | ((uint32_t *) createInfo.pCode)[2] = stage; |
| 871 | memcpy(((uint32_t *) createInfo.pCode + 3), shader_code, shader_len + 1); |
| 872 | |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 873 | err = init_try(*m_device, createInfo); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 876 | if (framework->m_use_spv || err) { |
| 877 | std::vector<unsigned int> spv; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 878 | err = XGL_SUCCESS; |
| 879 | |
Cody Northrop | 3bfd27c | 2015-03-17 15:55:58 -0600 | [diff] [blame] | 880 | // Use Reference GLSL to SPV compiler |
| 881 | framework->GLSLtoSPV(stage, shader_code, spv); |
| 882 | createInfo.pCode = spv.data(); |
| 883 | createInfo.codeSize = spv.size() * sizeof(unsigned int); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 884 | createInfo.flags = 0; |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 885 | |
Chia-I Wu | babc0fd | 2014-12-29 14:14:03 +0800 | [diff] [blame] | 886 | init(*m_device, createInfo); |
| 887 | } |
Tony Barbour | f325bf1 | 2014-12-03 15:59:38 -0700 | [diff] [blame] | 888 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 889 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 890 | XglPipelineObj::XglPipelineObj(XglDevice *device) |
| 891 | { |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 892 | m_device = device; |
| 893 | m_vi_state.attributeCount = m_vi_state.bindingCount = 0; |
| 894 | m_vertexBufferCount = 0; |
| 895 | |
| 896 | m_ia_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO; |
| 897 | m_ia_state.pNext = XGL_NULL_HANDLE; |
| 898 | m_ia_state.topology = XGL_TOPOLOGY_TRIANGLE_LIST; |
| 899 | m_ia_state.disableVertexReuse = XGL_FALSE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 900 | m_ia_state.primitiveRestartEnable = XGL_FALSE; |
| 901 | m_ia_state.primitiveRestartIndex = 0; |
| 902 | |
| 903 | m_rs_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO; |
| 904 | m_rs_state.pNext = &m_ia_state; |
| 905 | m_rs_state.depthClipEnable = XGL_FALSE; |
| 906 | m_rs_state.rasterizerDiscardEnable = XGL_FALSE; |
Chia-I Wu | c8d1ec5 | 2015-03-24 11:01:50 +0800 | [diff] [blame] | 907 | m_rs_state.programPointSize = XGL_FALSE; |
| 908 | m_rs_state.pointOrigin = XGL_COORDINATE_ORIGIN_UPPER_LEFT; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 909 | m_rs_state.provokingVertex = XGL_PROVOKING_VERTEX_LAST; |
| 910 | m_rs_state.fillMode = XGL_FILL_SOLID; |
| 911 | m_rs_state.cullMode = XGL_CULL_NONE; |
| 912 | m_rs_state.frontFace = XGL_FRONT_FACE_CCW; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 913 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 914 | memset(&m_cb_state,0,sizeof(m_cb_state)); |
| 915 | m_cb_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO; |
| 916 | m_cb_state.pNext = &m_rs_state; |
| 917 | m_cb_state.alphaToCoverageEnable = XGL_FALSE; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 918 | m_cb_state.logicOp = XGL_LOGIC_OP_COPY; |
| 919 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 920 | m_ms_state.pNext = &m_cb_state; |
| 921 | m_ms_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_MS_STATE_CREATE_INFO; |
| 922 | m_ms_state.multisampleEnable = XGL_FALSE; |
| 923 | m_ms_state.sampleMask = 1; // Do we have to specify MSAA even just to disable it? |
| 924 | m_ms_state.samples = 1; |
| 925 | m_ms_state.minSampleShading = 0; |
| 926 | m_ms_state.sampleShadingEnable = 0; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 927 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 928 | m_ds_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_DS_STATE_CREATE_INFO; |
| 929 | m_ds_state.pNext = &m_ms_state, |
Jeremy Hayes | a058eee | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 930 | m_ds_state.format = XGL_FMT_D32_SFLOAT; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 931 | m_ds_state.depthTestEnable = XGL_FALSE; |
| 932 | m_ds_state.depthWriteEnable = XGL_FALSE; |
| 933 | m_ds_state.depthBoundsEnable = XGL_FALSE; |
| 934 | m_ds_state.depthFunc = XGL_COMPARE_LESS_EQUAL; |
| 935 | m_ds_state.back.stencilDepthFailOp = XGL_STENCIL_OP_KEEP; |
| 936 | m_ds_state.back.stencilFailOp = XGL_STENCIL_OP_KEEP; |
| 937 | m_ds_state.back.stencilPassOp = XGL_STENCIL_OP_KEEP; |
| 938 | m_ds_state.back.stencilFunc = XGL_COMPARE_ALWAYS; |
| 939 | m_ds_state.stencilTestEnable = XGL_FALSE; |
| 940 | m_ds_state.front = m_ds_state.back; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 941 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 942 | XGL_PIPELINE_CB_ATTACHMENT_STATE att = {}; |
| 943 | att.blendEnable = XGL_FALSE; |
Tony Barbour | a53a694 | 2015-02-25 11:25:11 -0700 | [diff] [blame] | 944 | att.format = XGL_FMT_B8G8R8A8_UNORM; |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 945 | att.channelWriteMask = 0xf; |
| 946 | AddColorAttachment(0, &att); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 947 | |
| 948 | }; |
| 949 | |
| 950 | void XglPipelineObj::AddShader(XglShaderObj* shader) |
| 951 | { |
| 952 | m_shaderObjs.push_back(shader); |
| 953 | } |
| 954 | |
| 955 | void XglPipelineObj::AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count) |
| 956 | { |
| 957 | m_vi_state.pVertexAttributeDescriptions = vi_attrib; |
| 958 | m_vi_state.attributeCount = count; |
| 959 | } |
| 960 | |
| 961 | void XglPipelineObj::AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count) |
| 962 | { |
| 963 | m_vi_state.pVertexBindingDescriptions = vi_binding; |
| 964 | m_vi_state.bindingCount = count; |
| 965 | } |
| 966 | |
| 967 | void XglPipelineObj::AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding) |
| 968 | { |
| 969 | m_vertexBufferObjs.push_back(vertexDataBuffer); |
| 970 | m_vertexBufferBindings.push_back(binding); |
| 971 | m_vertexBufferCount++; |
| 972 | } |
| 973 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 974 | 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] | 975 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 976 | if (binding+1 > m_colorAttachments.size()) |
| 977 | { |
| 978 | m_colorAttachments.resize(binding+1); |
| 979 | } |
| 980 | m_colorAttachments[binding] = *att; |
| 981 | } |
| 982 | |
| 983 | void XglPipelineObj::SetDepthStencil(XGL_PIPELINE_DS_STATE_CREATE_INFO *ds_state) |
| 984 | { |
| 985 | m_ds_state.format = ds_state->format; |
| 986 | m_ds_state.depthTestEnable = ds_state->depthTestEnable; |
| 987 | m_ds_state.depthWriteEnable = ds_state->depthWriteEnable; |
| 988 | m_ds_state.depthBoundsEnable = ds_state->depthBoundsEnable; |
| 989 | m_ds_state.depthFunc = ds_state->depthFunc; |
| 990 | m_ds_state.stencilTestEnable = ds_state->stencilTestEnable; |
| 991 | m_ds_state.back = ds_state->back; |
| 992 | m_ds_state.front = ds_state->front; |
Chia-I Wu | ecebf75 | 2014-12-05 10:45:15 +0800 | [diff] [blame] | 993 | } |
| 994 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 995 | void XglPipelineObj::CreateXGLPipeline(XglDescriptorSetObj *descriptorSet) |
| 996 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 997 | void* head_ptr = &m_ds_state; |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 998 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 999 | |
| 1000 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo; |
| 1001 | |
| 1002 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 1003 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1004 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1005 | shaderCreateInfo->pNext = head_ptr; |
| 1006 | head_ptr = shaderCreateInfo; |
| 1007 | } |
| 1008 | |
| 1009 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 1010 | { |
| 1011 | m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO; |
| 1012 | m_vi_state.pNext = head_ptr; |
| 1013 | head_ptr = &m_vi_state; |
| 1014 | } |
| 1015 | |
| 1016 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1017 | info.pNext = head_ptr; |
| 1018 | info.flags = 0; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1019 | info.lastSetLayout = descriptorSet->GetLayout(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1020 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1021 | m_cb_state.attachmentCount = m_colorAttachments.size(); |
| 1022 | m_cb_state.pAttachments = &m_colorAttachments[0]; |
| 1023 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1024 | init(*m_device, info); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1025 | } |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1026 | |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1027 | XGL_PIPELINE XglPipelineObj::GetPipelineHandle() |
| 1028 | { |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1029 | return obj(); |
Tony Barbour | 976e1cf | 2014-12-17 11:57:31 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Tony Barbour | 5420af0 | 2014-12-03 13:58:15 -0700 | [diff] [blame] | 1032 | void XglPipelineObj::BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet) |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1033 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1034 | void* head_ptr = &m_ds_state; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1035 | XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {}; |
| 1036 | |
| 1037 | XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* shaderCreateInfo; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1038 | |
| 1039 | for (int i=0; i<m_shaderObjs.size(); i++) |
| 1040 | { |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1041 | shaderCreateInfo = m_shaderObjs[i]->GetStageCreateInfo(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1042 | shaderCreateInfo->pNext = head_ptr; |
| 1043 | head_ptr = shaderCreateInfo; |
| 1044 | } |
| 1045 | |
| 1046 | if (m_vi_state.attributeCount && m_vi_state.bindingCount) |
| 1047 | { |
| 1048 | m_vi_state.sType = XGL_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO; |
| 1049 | m_vi_state.pNext = head_ptr; |
| 1050 | head_ptr = &m_vi_state; |
| 1051 | } |
| 1052 | |
| 1053 | info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; |
| 1054 | info.pNext = head_ptr; |
| 1055 | info.flags = 0; |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1056 | info.lastSetLayout = descriptorSet->GetLayout(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1057 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1058 | init(*m_device, info); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1059 | |
Chia-I Wu | 2648d09 | 2014-12-29 14:24:14 +0800 | [diff] [blame] | 1060 | xglCmdBindPipeline( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, obj() ); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1061 | |
| 1062 | |
| 1063 | for (int i=0; i < m_vertexBufferCount; i++) |
| 1064 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1065 | m_vertexBufferObjs[i]->Bind(m_cmdBuffer, 0, m_vertexBufferBindings[i]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1066 | } |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1067 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1068 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1069 | XglMemoryRefManager::XglMemoryRefManager() { |
| 1070 | |
| 1071 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1072 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1073 | void XglMemoryRefManager::AddMemoryRef(XglConstantBufferObj *constantBuffer) { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1074 | const std::vector<XGL_GPU_MEMORY> mems = constantBuffer->memories(); |
| 1075 | if (!mems.empty()) |
| 1076 | m_bufferObjs.push_back(mems[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1077 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1078 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1079 | void XglMemoryRefManager::AddMemoryRef(XglTextureObj *texture) { |
Chia-I Wu | 13a3aa8 | 2014-12-28 15:55:09 +0800 | [diff] [blame] | 1080 | const std::vector<XGL_GPU_MEMORY> mems = texture->memories(); |
| 1081 | if (!mems.empty()) |
| 1082 | m_bufferObjs.push_back(mems[0]); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1083 | } |
Tony Barbour | 82c3952 | 2014-12-04 14:33:33 -0700 | [diff] [blame] | 1084 | |
Mark Lobodzinski | c52b775 | 2015-02-18 16:38:17 -0600 | [diff] [blame] | 1085 | void XglMemoryRefManager::AddMemoryRef(XGL_GPU_MEMORY *mem, uint32_t refCount) { |
| 1086 | for (size_t i = 0; i < refCount; i++) { |
| 1087 | m_bufferObjs.push_back(mem[i]); |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | void XglMemoryRefManager::AddRTMemoryRefs(vector<XglImage*>images, uint32_t rtCount) { |
| 1092 | for (uint32_t i = 0; i < rtCount; i++) { |
| 1093 | const std::vector<XGL_GPU_MEMORY> mems = images[i]->memories(); |
| 1094 | if (!mems.empty()) |
| 1095 | m_bufferObjs.push_back(mems[0]); |
| 1096 | } |
| 1097 | } |
| 1098 | |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1099 | XGL_MEMORY_REF* XglMemoryRefManager::GetMemoryRefList() { |
| 1100 | |
| 1101 | XGL_MEMORY_REF *localRefs; |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1102 | uint32_t numRefs=m_bufferObjs.size(); |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1103 | |
| 1104 | if (numRefs <= 0) |
| 1105 | return NULL; |
| 1106 | |
| 1107 | localRefs = (XGL_MEMORY_REF*) malloc( numRefs * sizeof(XGL_MEMORY_REF) ); |
| 1108 | for (int i=0; i<numRefs; i++) |
| 1109 | { |
| 1110 | localRefs[i].flags = 0; |
Chia-I Wu | 283d7a6 | 2014-12-28 15:43:42 +0800 | [diff] [blame] | 1111 | localRefs[i].mem = m_bufferObjs[i]; |
Tony Barbour | e2c58df | 2014-11-25 13:18:32 -0700 | [diff] [blame] | 1112 | } |
| 1113 | return localRefs; |
| 1114 | } |
| 1115 | int XglMemoryRefManager::GetNumRefs() { |
| 1116 | return m_bufferObjs.size(); |
| 1117 | } |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1118 | |
| 1119 | XglCommandBufferObj::XglCommandBufferObj(XglDevice *device) |
Courtney Goeltzenleuchter | 18248e6 | 2015-03-05 18:09:39 -0700 | [diff] [blame] | 1120 | : 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] | 1121 | { |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1122 | m_device = device; |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1123 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1124 | |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1125 | XGL_CMD_BUFFER XglCommandBufferObj::GetBufferHandle() |
| 1126 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1127 | return obj(); |
Tony Barbour | 6d047bf | 2014-12-10 14:34:45 -0700 | [diff] [blame] | 1128 | } |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1129 | |
Jon Ashburn | c4164b1 | 2014-12-31 17:10:47 -0700 | [diff] [blame] | 1130 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer(XGL_CMD_BUFFER_BEGIN_INFO *pInfo) |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1131 | { |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1132 | begin(pInfo); |
| 1133 | return XGL_SUCCESS; |
| 1134 | } |
| 1135 | |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 1136 | 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] | 1137 | { |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 1138 | begin(renderpass_obj, framebuffer_obj); |
Jeremy Hayes | d65ae08 | 2015-01-14 16:17:08 -0700 | [diff] [blame] | 1139 | return XGL_SUCCESS; |
| 1140 | } |
| 1141 | |
| 1142 | XGL_RESULT XglCommandBufferObj::BeginCommandBuffer() |
| 1143 | { |
| 1144 | begin(); |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1145 | return XGL_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | XGL_RESULT XglCommandBufferObj::EndCommandBuffer() |
| 1149 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1150 | end(); |
| 1151 | return XGL_SUCCESS; |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1154 | void XglCommandBufferObj::PipelineBarrier(XGL_PIPELINE_BARRIER *barrierPtr) |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1155 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1156 | xglCmdPipelineBarrier(obj(), barrierPtr); |
Tony Barbour | 471338d | 2014-12-10 17:28:39 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 1159 | void XglCommandBufferObj::ClearAllBuffers(XGL_CLEAR_COLOR clear_color, float depth_clear_color, uint32_t stencil_clear_color, |
| 1160 | XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1161 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1162 | uint32_t i; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1163 | const XGL_FLAGS output_mask = |
| 1164 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1165 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1166 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1167 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1168 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1169 | const XGL_FLAGS input_mask = 0; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1170 | |
| 1171 | // whatever we want to do, we do it to the whole buffer |
| 1172 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 1173 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 1174 | srRange.baseMipLevel = 0; |
| 1175 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1176 | srRange.baseArraySlice = 0; |
| 1177 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1178 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1179 | XGL_IMAGE_MEMORY_BARRIER memory_barrier = {}; |
| 1180 | memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 1181 | memory_barrier.outputMask = output_mask; |
| 1182 | memory_barrier.inputMask = input_mask; |
| 1183 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1184 | memory_barrier.subresourceRange = srRange; |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 1185 | XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &memory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1186 | |
| 1187 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 1188 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1189 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1190 | pipeline_barrier.eventCount = 1; |
| 1191 | pipeline_barrier.pEvents = set_events; |
| 1192 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1193 | pipeline_barrier.memBarrierCount = 1; |
Mark Lobodzinski | d5d83ed | 2015-02-02 11:55:52 -0600 | [diff] [blame] | 1194 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1195 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 1196 | for (i = 0; i < m_renderTargets.size(); i++) { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1197 | memory_barrier.image = m_renderTargets[i]->image(); |
| 1198 | memory_barrier.oldLayout = m_renderTargets[i]->layout(); |
| 1199 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1200 | m_renderTargets[i]->layout(memory_barrier.newLayout); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1201 | |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 1202 | xglCmdClearColorImage( obj(), m_renderTargets[i]->image(), clear_color, 1, &srRange ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | if (depthStencilImage) |
| 1206 | { |
| 1207 | XGL_IMAGE_SUBRESOURCE_RANGE dsRange = {}; |
| 1208 | dsRange.aspect = XGL_IMAGE_ASPECT_DEPTH; |
| 1209 | dsRange.baseMipLevel = 0; |
| 1210 | dsRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1211 | dsRange.baseArraySlice = 0; |
| 1212 | dsRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1213 | |
| 1214 | // prepare the depth buffer for clear |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1215 | |
| 1216 | memory_barrier.oldLayout = depthStencilBinding->layout; |
| 1217 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1218 | memory_barrier.image = depthStencilImage; |
| 1219 | memory_barrier.subresourceRange = dsRange; |
| 1220 | |
| 1221 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1222 | depthStencilBinding->layout = memory_barrier.newLayout; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1223 | |
Courtney Goeltzenleuchter | 679bbfa | 2015-03-05 17:26:38 -0700 | [diff] [blame] | 1224 | xglCmdClearDepthStencil(obj(), depthStencilImage, |
| 1225 | depth_clear_color, stencil_clear_color, |
| 1226 | 1, &dsRange); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1227 | |
| 1228 | // prepare depth buffer for rendering |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1229 | memory_barrier.image = depthStencilImage; |
| 1230 | memory_barrier.oldLayout = XGL_IMAGE_LAYOUT_CLEAR_OPTIMAL; |
| 1231 | memory_barrier.newLayout = depthStencilBinding->layout; |
| 1232 | memory_barrier.subresourceRange = dsRange; |
| 1233 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1234 | depthStencilBinding->layout = memory_barrier.newLayout; |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | |
Jon Ashburn | cdc40be | 2015-01-02 18:27:14 -0700 | [diff] [blame] | 1238 | void XglCommandBufferObj::PrepareAttachments() |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1239 | { |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1240 | uint32_t i; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1241 | const XGL_FLAGS output_mask = |
| 1242 | XGL_MEMORY_OUTPUT_CPU_WRITE_BIT | |
| 1243 | XGL_MEMORY_OUTPUT_SHADER_WRITE_BIT | |
| 1244 | XGL_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT | |
| 1245 | XGL_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1246 | XGL_MEMORY_OUTPUT_COPY_BIT; |
| 1247 | const XGL_FLAGS input_mask = |
| 1248 | XGL_MEMORY_INPUT_CPU_READ_BIT | |
| 1249 | XGL_MEMORY_INPUT_INDIRECT_COMMAND_BIT | |
| 1250 | XGL_MEMORY_INPUT_INDEX_FETCH_BIT | |
| 1251 | XGL_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT | |
| 1252 | XGL_MEMORY_INPUT_UNIFORM_READ_BIT | |
| 1253 | XGL_MEMORY_INPUT_SHADER_READ_BIT | |
| 1254 | XGL_MEMORY_INPUT_COLOR_ATTACHMENT_BIT | |
| 1255 | XGL_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT | |
| 1256 | XGL_MEMORY_INPUT_COPY_BIT; |
| 1257 | |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1258 | XGL_IMAGE_SUBRESOURCE_RANGE srRange = {}; |
| 1259 | srRange.aspect = XGL_IMAGE_ASPECT_COLOR; |
| 1260 | srRange.baseMipLevel = 0; |
| 1261 | srRange.mipLevels = XGL_LAST_MIP_OR_SLICE; |
| 1262 | srRange.baseArraySlice = 0; |
| 1263 | srRange.arraySize = XGL_LAST_MIP_OR_SLICE; |
| 1264 | |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1265 | XGL_IMAGE_MEMORY_BARRIER memory_barrier = {}; |
| 1266 | memory_barrier.sType = XGL_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; |
| 1267 | memory_barrier.outputMask = output_mask; |
| 1268 | memory_barrier.inputMask = input_mask; |
| 1269 | memory_barrier.newLayout = XGL_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 1270 | memory_barrier.subresourceRange = srRange; |
Mark Lobodzinski | 837ef92 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 1271 | XGL_IMAGE_MEMORY_BARRIER *pmemory_barrier = &memory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1272 | |
| 1273 | XGL_SET_EVENT set_events[] = { XGL_SET_EVENT_GPU_COMMANDS_COMPLETE }; |
| 1274 | XGL_PIPELINE_BARRIER pipeline_barrier = {}; |
| 1275 | pipeline_barrier.sType = XGL_STRUCTURE_TYPE_PIPELINE_BARRIER; |
| 1276 | pipeline_barrier.eventCount = 1; |
| 1277 | pipeline_barrier.pEvents = set_events; |
| 1278 | pipeline_barrier.waitEvent = XGL_WAIT_EVENT_TOP_OF_PIPE; |
| 1279 | pipeline_barrier.memBarrierCount = 1; |
Mark Lobodzinski | d5d83ed | 2015-02-02 11:55:52 -0600 | [diff] [blame] | 1280 | pipeline_barrier.ppMemBarriers = (const void **)&pmemory_barrier; |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1281 | |
Courtney Goeltzenleuchter | b4337c1 | 2015-03-05 16:47:18 -0700 | [diff] [blame] | 1282 | for(i=0; i<m_renderTargets.size(); i++) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1283 | { |
Mike Stroyan | fb80d5f | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 1284 | memory_barrier.image = m_renderTargets[i]->image(); |
| 1285 | memory_barrier.oldLayout = m_renderTargets[i]->layout(); |
| 1286 | xglCmdPipelineBarrier( obj(), &pipeline_barrier); |
| 1287 | m_renderTargets[i]->layout(memory_barrier.newLayout); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1288 | } |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Courtney Goeltzenleuchter | 69894b7 | 2015-04-03 15:25:24 -0600 | [diff] [blame^] | 1291 | void XglCommandBufferObj::BeginRenderPass(XGL_RENDER_PASS renderpass, XGL_FRAMEBUFFER framebuffer) |
| 1292 | { |
| 1293 | XGL_RENDER_PASS_BEGIN rp_begin = { |
| 1294 | renderpass, |
| 1295 | framebuffer, |
| 1296 | }; |
| 1297 | |
| 1298 | xglCmdBeginRenderPass( obj(), &rp_begin); |
| 1299 | } |
| 1300 | |
| 1301 | void XglCommandBufferObj::EndRenderPass(XGL_RENDER_PASS renderpass) |
| 1302 | { |
| 1303 | xglCmdEndRenderPass( obj(), renderpass); |
| 1304 | } |
| 1305 | |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1306 | 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] | 1307 | { |
Tony Barbour | f52346d | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 1308 | xglCmdBindDynamicStateObject( obj(), stateBindPoint, stateObject); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | void XglCommandBufferObj::AddRenderTarget(XglImage *renderTarget) |
| 1312 | { |
| 1313 | m_renderTargets.push_back(renderTarget); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1316 | 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] | 1317 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1318 | xglCmdDrawIndexed(obj(), firstIndex, indexCount, vertexOffset, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1319 | } |
| 1320 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1321 | 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] | 1322 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1323 | xglCmdDraw(obj(), firstVertex, vertexCount, firstInstance, instanceCount); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1326 | void XglCommandBufferObj::QueueCommandBuffer(XGL_MEMORY_REF *memRefs, uint32_t numMemRefs) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1327 | { |
| 1328 | XGL_RESULT err = XGL_SUCCESS; |
| 1329 | |
| 1330 | // submit the command buffer to the universal queue |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1331 | err = xglQueueSubmit( m_device->m_queue, 1, &obj(), numMemRefs, memRefs, NULL ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1332 | ASSERT_XGL_SUCCESS( err ); |
| 1333 | |
| 1334 | err = xglQueueWaitIdle( m_device->m_queue ); |
| 1335 | ASSERT_XGL_SUCCESS( err ); |
| 1336 | |
| 1337 | // Wait for work to finish before cleaning up. |
| 1338 | xglDeviceWaitIdle(m_device->device()); |
| 1339 | |
| 1340 | } |
| 1341 | void XglCommandBufferObj::BindPipeline(XGL_PIPELINE pipeline) |
| 1342 | { |
Chia-I Wu | d28343c | 2014-12-28 15:12:48 +0800 | [diff] [blame] | 1343 | xglCmdBindPipeline( obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, pipeline ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | void XglCommandBufferObj::BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet) |
| 1347 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1348 | // bind pipeline, vertex buffer (descriptor set) and WVP (dynamic buffer view) |
Chia-I Wu | 11078b0 | 2015-01-04 16:27:24 +0800 | [diff] [blame] | 1349 | xglCmdBindDescriptorSet(obj(), XGL_PIPELINE_BIND_POINT_GRAPHICS, descriptorSet, NULL ); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1350 | } |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1351 | void XglCommandBufferObj::BindIndexBuffer(XglIndexBufferObj *indexBuffer, uint32_t offset) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1352 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1353 | xglCmdBindIndexBuffer(obj(), indexBuffer->obj(), offset, indexBuffer->GetIndexType()); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1354 | } |
Mark Lobodzinski | 17caf57 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 1355 | void XglCommandBufferObj::BindVertexBuffer(XglConstantBufferObj *vertexBuffer, uint32_t offset, uint32_t binding) |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1356 | { |
Chia-I Wu | 1a28fe0 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 1357 | xglCmdBindVertexBuffer(obj(), vertexBuffer->obj(), offset, binding); |
Tony Barbour | 30cc9e8 | 2014-12-17 11:53:55 -0700 | [diff] [blame] | 1358 | } |