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