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