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