blob: 13f1eb721365a67f2b0a07657a5e2657dbc7ce4b [file] [log] [blame]
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -06001/*
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#ifndef XGLRENDERFRAMEWORK_H
29#define XGLRENDERFRAMEWORK_H
30
31#include "xgltestframework.h"
Chia-I Wufb1459b2014-12-29 15:23:20 +080032
33class XglDevice : public xgl_testing::Device
34{
35public:
36 XglDevice(XGL_UINT id, XGL_PHYSICAL_GPU obj);
37
38 XGL_DEVICE device() { return obj(); }
39 void get_device_queue();
40
41 XGL_UINT id;
42 XGL_PHYSICAL_GPU_PROPERTIES props;
43 const XGL_PHYSICAL_GPU_QUEUE_PROPERTIES *queue_props;
44
45 XGL_QUEUE m_queue;
46};
47
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060048
49class XglRenderFramework : public XglTestFramework
50{
51public:
52 XglRenderFramework();
53 ~XglRenderFramework();
54
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060055 XGL_DEVICE device() {return m_device->device();}
Tobin Ehlisca915872014-11-18 11:28:33 -070056 XGL_PHYSICAL_GPU gpu() {return objs[0];}
Jon Ashburncdc40be2015-01-02 18:27:14 -070057 XGL_RENDER_PASS renderPass() {return m_renderPass;}
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060058 void InitViewport(float width, float height);
Courtney Goeltzenleuchter02d33c12014-10-08 14:26:40 -060059 void InitViewport();
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060060 void InitRenderTarget();
61 void InitFramework();
Courtney Goeltzenleuchter53d8d892014-10-08 12:20:26 -060062 void ShutdownFramework();
63 void InitState();
Tony Barboure2c58df2014-11-25 13:18:32 -070064
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060065
66protected:
Tony Barbourf52346d2015-01-16 14:27:35 -070067 XGL_APPLICATION_INFO app_info;
68 XGL_PHYSICAL_GPU objs[XGL_MAX_PHYSICAL_GPUS];
69 XGL_UINT gpu_count;
70 XglDevice *m_device;
71 XGL_CMD_BUFFER m_cmdBuffer;
72 XGL_RENDER_PASS m_renderPass;
73 XGL_MEMORY_REF m_memRefs[5];
74 XGL_DYNAMIC_RS_STATE_OBJECT m_stateRaster;
75 XGL_DYNAMIC_CB_STATE_OBJECT m_colorBlend;
76 XGL_DYNAMIC_VP_STATE_OBJECT m_stateViewport;
77 XGL_DYNAMIC_DS_STATE_OBJECT m_stateDepthStencil;
78 vector<XglImage*> m_renderTargets;
79 XGL_UINT m_renderTargetCount;
80 XGL_FLOAT m_width, m_height;
81 XGL_FORMAT m_render_target_fmt;
82 XGL_COLOR_ATTACHMENT_BIND_INFO m_colorBindings[8];
83 XGL_DEPTH_STENCIL_BIND_INFO m_depthStencilBinding;
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060084
85 /*
86 * SetUp and TearDown are called by the Google Test framework
87 * to initialize a test framework based on this class.
88 */
89 virtual void SetUp() {
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060090 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
91 this->app_info.pNext = NULL;
Chia-I Wuf1a5a742014-12-27 15:16:07 +080092 this->app_info.pAppName = "base";
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060093 this->app_info.appVersion = 1;
Chia-I Wuf1a5a742014-12-27 15:16:07 +080094 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060095 this->app_info.engineVersion = 1;
96 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
97
Chia-I Wu8089cc12014-12-29 15:18:43 +080098 InitFramework();
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -060099 }
100
101 virtual void TearDown() {
Chia-I Wu8089cc12014-12-29 15:18:43 +0800102 ShutdownFramework();
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600103 }
104};
105
Tony Barbour30cc9e82014-12-17 11:53:55 -0700106class XglIndexBufferObj;
107class XglConstantBufferObj;
108
Chia-I Wud28343c2014-12-28 15:12:48 +0800109class XglCommandBufferObj : xgl_testing::CmdBuffer
Tony Barbour6d047bf2014-12-10 14:34:45 -0700110{
111public:
112 XglCommandBufferObj(XglDevice *device);
Tony Barbour471338d2014-12-10 17:28:39 -0700113 XGL_CMD_BUFFER GetBufferHandle();
Jon Ashburnc4164b12014-12-31 17:10:47 -0700114 XGL_RESULT BeginCommandBuffer(XGL_CMD_BUFFER_BEGIN_INFO *pInfo);
Jeremy Hayesd65ae082015-01-14 16:17:08 -0700115 XGL_RESULT BeginCommandBuffer(XGL_RENDER_PASS renderpass_obj);
116 XGL_RESULT BeginCommandBuffer();
Tony Barbour471338d2014-12-10 17:28:39 -0700117 XGL_RESULT EndCommandBuffer();
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800118 void PrepareBufferRegions(int transitionCount, XGL_BUFFER_STATE_TRANSITION *transitionPtr);
Tony Barbour30cc9e82014-12-17 11:53:55 -0700119 void AddRenderTarget(XglImage *renderTarget);
120 void AddDepthStencil();
121 void ClearAllBuffers();
122 void ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage);
Jon Ashburncdc40be2015-01-02 18:27:14 -0700123 void PrepareAttachments();
Tony Barbour30cc9e82014-12-17 11:53:55 -0700124 void BindPipeline(XGL_PIPELINE pipeline);
125 void BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet);
126 void BindVertexBuffer(XglConstantBufferObj *vertexBuffer, XGL_UINT offset, XGL_UINT binding);
127 void BindIndexBuffer(XglIndexBufferObj *indexBuffer, XGL_UINT offset);
Tony Barbourf52346d2015-01-16 14:27:35 -0700128 void BindStateObject(XGL_STATE_BIND_POINT stateBindPoint, XGL_DYNAMIC_STATE_OBJECT stateObject);
Tony Barbour30cc9e82014-12-17 11:53:55 -0700129 void Draw(XGL_UINT firstVertex, XGL_UINT vertexCount, XGL_UINT firstInstance, XGL_UINT instanceCount);
130 void DrawIndexed(XGL_UINT firstIndex, XGL_UINT indexCount, XGL_INT vertexOffset, XGL_UINT firstInstance, XGL_UINT instanceCount);
131 void QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs);
Tony Barbour6d047bf2014-12-10 14:34:45 -0700132
133protected:
134 XglDevice *m_device;
Tony Barbour30cc9e82014-12-17 11:53:55 -0700135 vector<XglImage*> m_renderTargets;
136 XGL_UINT m_renderTargetCount;
Tony Barbour6d047bf2014-12-10 14:34:45 -0700137
138};
139
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800140class XglConstantBufferObj : public xgl_testing::Buffer
Tony Barbour9d951a02014-11-19 16:33:11 -0700141{
142public:
Courtney Goeltzenleuchter3b0a8152014-12-04 15:18:47 -0700143 XglConstantBufferObj(XglDevice *device);
Tony Barbourac3692c2014-11-20 15:06:56 -0700144 XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data);
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800145 void SetBufferState(XGL_BUFFER_STATE newState);
Courtney Goeltzenleuchter37640302014-12-04 15:26:56 -0700146 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding);
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800147
148 XGL_BUFFER_VIEW_ATTACH_INFO m_bufferViewInfo;
Tony Barbour9d951a02014-11-19 16:33:11 -0700149
150protected:
Tony Barbourac3692c2014-11-20 15:06:56 -0700151 XglDevice *m_device;
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800152 xgl_testing::BufferView m_bufferView;
Tony Barbourac3692c2014-11-20 15:06:56 -0700153 int m_numVertices;
154 int m_stride;
Tony Barbour38422802014-12-10 14:36:31 -0700155 XglCommandBufferObj *m_commandBuffer;
Chia-I Wua07fee62014-12-28 15:26:08 +0800156 xgl_testing::Fence m_fence;
Tony Barbour9d951a02014-11-19 16:33:11 -0700157};
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700158
159class XglIndexBufferObj : public XglConstantBufferObj
160{
161public:
162 XglIndexBufferObj(XglDevice *device);
163 void CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE dataFormat, const void* data);
164 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset);
Tony Barbouraf1f9192014-12-17 10:57:58 -0700165 XGL_INDEX_TYPE GetIndexType();
Courtney Goeltzenleuchter8a785932014-12-04 15:24:05 -0700166
167protected:
168 XGL_INDEX_TYPE m_indexType;
169};
170
Chia-I Wua6bc0ce2014-12-29 14:38:28 +0800171class XglImage : public xgl_testing::Image
172{
173public:
174 XglImage(XglDevice *dev);
175
176 // Image usage flags
177 // typedef enum _XGL_IMAGE_USAGE_FLAGS
178 // {
179 // XGL_IMAGE_USAGE_SHADER_ACCESS_READ_BIT = 0x00000001,
180 // XGL_IMAGE_USAGE_SHADER_ACCESS_WRITE_BIT = 0x00000002,
181 // XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT = 0x00000004,
182 // XGL_IMAGE_USAGE_DEPTH_STENCIL_BIT = 0x00000008,
183 // } XGL_IMAGE_USAGE_FLAGS;
184public:
185 void init( XGL_UINT32 w, XGL_UINT32 h,
186 XGL_FORMAT fmt, XGL_FLAGS usage,
187 XGL_IMAGE_TILING tiling=XGL_LINEAR_TILING);
188
189 // void clear( CommandBuffer*, XGL_UINT[4] );
190 // void prepare( CommandBuffer*, XGL_IMAGE_STATE );
191
192 void state( XGL_IMAGE_STATE state )
193 {
194 m_imageInfo.state = state;
195 }
196 XGL_GPU_MEMORY memory() const
197 {
198 const std::vector<XGL_GPU_MEMORY> mems = memories();
199 return mems.empty() ? XGL_NULL_HANDLE : mems[0];
200 }
201
202
203 XGL_IMAGE image() const
204 {
205 return obj();
206 }
207 XGL_COLOR_ATTACHMENT_VIEW targetView()const
208 {
209 return m_targetView.obj();
210 }
211
212 XGL_IMAGE_STATE state() const
213 {
214 return ( XGL_IMAGE_STATE )m_imageInfo.state;
215 }
216 XGL_UINT32 width() const
217 {
218 return extent().width;
219 }
220 XGL_UINT32 height() const
221 {
222 return extent().height;
223 }
224
225 XGL_RESULT MapMemory(XGL_VOID** ptr);
226 XGL_RESULT UnmapMemory();
227
228protected:
229 XglDevice *m_device;
230
231 xgl_testing::ColorAttachmentView m_targetView;
232 XGL_IMAGE_VIEW_ATTACH_INFO m_imageInfo;
233};
234
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800235class XglTextureObj : public xgl_testing::Image
Tony Barbour9d951a02014-11-19 16:33:11 -0700236{
237public:
238 XglTextureObj(XglDevice *device);
Tony Barbourd1b1bd12014-11-21 17:17:49 -0700239 void ChangeColors(uint32_t color1, uint32_t color2);
Tony Barbour9d951a02014-11-19 16:33:11 -0700240 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
Tony Barbour9d951a02014-11-19 16:33:11 -0700241
242protected:
243 XglDevice *m_device;
Chia-I Wu13a3aa82014-12-28 15:55:09 +0800244 xgl_testing::ImageView m_textureView;
245 XGL_GPU_SIZE m_rowPitch;
Tony Barbour9d951a02014-11-19 16:33:11 -0700246};
247
Chia-I Wue9864b52014-12-28 16:32:24 +0800248class XglSamplerObj : public xgl_testing::Sampler
Tony Barbour9d951a02014-11-19 16:33:11 -0700249{
250public:
251 XglSamplerObj(XglDevice *device);
Tony Barbour9d951a02014-11-19 16:33:11 -0700252
253protected:
Tony Barbour9d951a02014-11-19 16:33:11 -0700254 XglDevice *m_device;
255
256};
257
Chia-I Wuac0f1e72014-12-28 22:32:36 +0800258class XglDescriptorSetObj : public xgl_testing::DescriptorSet
Tony Barbour9d951a02014-11-19 16:33:11 -0700259{
260public:
Tony Barbourac3692c2014-11-20 15:06:56 -0700261 XglDescriptorSetObj(XglDevice *device);
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800262 void AttachBufferView(XglConstantBufferObj* constantBuffer);
Tony Barbourac3692c2014-11-20 15:06:56 -0700263 void AttachSampler( XglSamplerObj* sampler);
264 void AttachImageView( XglTextureObj* texture);
265 void BindCommandBuffer(XGL_CMD_BUFFER commandBuffer);
Tony Barbourb5f4d082014-12-17 10:54:03 -0700266 void CreateXGLDescriptorSet();
267 XGL_DESCRIPTOR_SET GetDescriptorSetHandle();
Tony Barbour824b7712014-12-18 17:06:21 -0700268 int GetTotalSlots();
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800269 XGL_DESCRIPTOR_SLOT_INFO * GetSlotInfo(vector<int>slots, vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types, vector<void*>objs );
Tony Barbour9d951a02014-11-19 16:33:11 -0700270
271protected:
Tony Barbourac3692c2014-11-20 15:06:56 -0700272 XglDevice *m_device;
273 XGL_DESCRIPTOR_SLOT_INFO *m_slotInfo;
274 int m_nextSlot;
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800275 vector<int> m_bufferSlots;
276 vector<XGL_BUFFER_VIEW_ATTACH_INFO*> m_bufferViews;
Tony Barbourac3692c2014-11-20 15:06:56 -0700277 vector<int> m_samplerSlots;
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800278 vector<XglSamplerObj*> m_samplers;
Tony Barbourac3692c2014-11-20 15:06:56 -0700279 vector<int> m_imageSlots;
280 vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageViews;
Tony Barbour9d951a02014-11-19 16:33:11 -0700281};
Tony Barbourac3692c2014-11-20 15:06:56 -0700282
283
Chia-I Wubabc0fd2014-12-29 14:14:03 +0800284class XglShaderObj : public xgl_testing::Shader
Tony Barbour9d951a02014-11-19 16:33:11 -0700285{
286public:
Tony Barboure2c58df2014-11-25 13:18:32 -0700287 XglShaderObj(XglDevice *device, const char * shaderText, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework);
Tony Barbour5420af02014-12-03 13:58:15 -0700288 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* GetStageCreateInfo(XglDescriptorSetObj *descriptorSet);
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800289 void BindShaderEntitySlotToBuffer(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer);
Tony Barbourac3692c2014-11-20 15:06:56 -0700290 void BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture);
291 void BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler);
Tony Barbour9d951a02014-11-19 16:33:11 -0700292
293protected:
294 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO stage_info;
Tony Barbour9d951a02014-11-19 16:33:11 -0700295 XGL_PIPELINE_SHADER_STAGE m_stage;
296 XglDevice *m_device;
Chia-I Wu1a28fe02015-01-01 07:55:04 +0800297 vector<int> m_bufferSlots;
298 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_bufferTypes;
299 vector<XGL_BUFFER_VIEW_ATTACH_INFO*> m_bufferObjs;
Tony Barbour9d951a02014-11-19 16:33:11 -0700300 vector<int> m_samplerSlots;
301 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_samplerTypes;
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800302 vector<XglSamplerObj*> m_samplerObjs;
Tony Barbour9d951a02014-11-19 16:33:11 -0700303 vector<int> m_imageSlots;
304 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_imageTypes;
Chia-I Wuc86b54c2014-12-28 16:07:01 +0800305 vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageObjs;
Tony Barbour9d951a02014-11-19 16:33:11 -0700306
307};
308
Chia-I Wu2648d092014-12-29 14:24:14 +0800309class XglPipelineObj : public xgl_testing::Pipeline
Tony Barbour9d951a02014-11-19 16:33:11 -0700310{
311public:
312 XglPipelineObj(XglDevice *device);
Tony Barbour5420af02014-12-03 13:58:15 -0700313 void BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet);
Tony Barbour9d951a02014-11-19 16:33:11 -0700314 void AddShader(XglShaderObj* shaderObj);
315 void AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count);
316 void AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count);
317 void AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding);
Tony Barbourf52346d2015-01-16 14:27:35 -0700318 void AddColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att);
319 void SetDepthStencil(XGL_PIPELINE_DS_STATE_CREATE_INFO *);
Tony Barbour976e1cf2014-12-17 11:57:31 -0700320 void CreateXGLPipeline(XglDescriptorSetObj *descriptorSet);
321 XGL_PIPELINE GetPipelineHandle();
Tony Barbour9d951a02014-11-19 16:33:11 -0700322
323protected:
Tony Barbour9d951a02014-11-19 16:33:11 -0700324 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO m_vi_state;
325 XGL_PIPELINE_IA_STATE_CREATE_INFO m_ia_state;
326 XGL_PIPELINE_RS_STATE_CREATE_INFO m_rs_state;
Tony Barbourf52346d2015-01-16 14:27:35 -0700327 XGL_PIPELINE_CB_STATE_CREATE_INFO m_cb_state;
328 XGL_PIPELINE_DS_STATE_CREATE_INFO m_ds_state;
329 XGL_PIPELINE_MS_STATE_CREATE_INFO m_ms_state;
Tony Barbour9d951a02014-11-19 16:33:11 -0700330 XglDevice *m_device;
Tony Barbour9d951a02014-11-19 16:33:11 -0700331 vector<XglShaderObj*> m_shaderObjs;
332 vector<XglConstantBufferObj*> m_vertexBufferObjs;
333 vector<int> m_vertexBufferBindings;
Tony Barbourf52346d2015-01-16 14:27:35 -0700334 vector<XGL_PIPELINE_CB_ATTACHMENT_STATE> m_colorAttachments;
Tony Barbour9d951a02014-11-19 16:33:11 -0700335 int m_vertexBufferCount;
336
337};
338class XglMemoryRefManager{
339public:
340 XglMemoryRefManager();
Tony Barbourac3692c2014-11-20 15:06:56 -0700341 void AddMemoryRef(XglConstantBufferObj* constantBuffer);
342 void AddMemoryRef(XglTextureObj *texture);
Tony Barbour9d951a02014-11-19 16:33:11 -0700343 XGL_MEMORY_REF* GetMemoryRefList();
344 int GetNumRefs();
345
346protected:
347 int m_numRefs;
Chia-I Wu283d7a62014-12-28 15:43:42 +0800348 vector<XGL_GPU_MEMORY> m_bufferObjs;
Tony Barbour9d951a02014-11-19 16:33:11 -0700349
350};
351
352
Courtney Goeltzenleuchtera4b278b2014-10-08 08:50:49 -0600353#endif // XGLRENDERFRAMEWORK_H