blob: ca3d7085f222fffcde9a3b458cea6c06540c04ac [file] [log] [blame]
Courtney Goeltzenleuchter5744b972014-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"
32
33class XglRenderFramework : public XglTestFramework
34{
35public:
36 XglRenderFramework();
37 ~XglRenderFramework();
38
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060039 XGL_DEVICE device() {return m_device->device();}
Tobin Ehlis3c26a542014-11-18 11:28:33 -070040 XGL_PHYSICAL_GPU gpu() {return objs[0];}
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060041 void InitViewport(float width, float height);
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -060042 void InitViewport();
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060043 void InitRenderTarget();
44 void InitFramework();
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060045 void ShutdownFramework();
46 void InitState();
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -060047 void GenerateClearAndPrepareBufferCmds();
48 void GenerateBindRenderTargetCmd();
Tony Barbourf43b6982014-11-25 13:18:32 -070049 void GenerateBindStateAndPipelineCmds();
50
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060051
52protected:
53 XGL_APPLICATION_INFO app_info;
Chia-I Wu9c877b22014-12-28 14:37:25 +080054 XGL_PHYSICAL_GPU objs[XGL_MAX_PHYSICAL_GPUS];
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060055 XGL_UINT gpu_count;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060056 XglDevice *m_device;
57 XGL_CMD_BUFFER m_cmdBuffer;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060058 XGL_MEMORY_REF m_memRefs[5];
59 XGL_RASTER_STATE_OBJECT m_stateRaster;
60 XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend;
61 XGL_VIEWPORT_STATE_OBJECT m_stateViewport;
62 XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil;
63 XGL_MSAA_STATE_OBJECT m_stateMsaa;
Chia-I Wue7748802014-12-05 10:45:15 +080064 XglImage *m_renderTargets[XGL_MAX_COLOR_ATTACHMENTS];
65 XGL_UINT m_renderTargetCount;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060066 XGL_FLOAT m_width, m_height;
67 XGL_FORMAT m_render_target_fmt;
Chia-I Wue7748802014-12-05 10:45:15 +080068 XGL_COLOR_ATTACHMENT_BIND_INFO m_colorBindings[XGL_MAX_COLOR_ATTACHMENTS];
Courtney Goeltzenleuchterb66e7de2014-10-22 14:12:38 -060069 XGL_DEPTH_STENCIL_BIND_INFO m_depthStencilBinding;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060070
71 /*
72 * SetUp and TearDown are called by the Google Test framework
73 * to initialize a test framework based on this class.
74 */
75 virtual void SetUp() {
76 XGL_RESULT err;
77
78 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
79 this->app_info.pNext = NULL;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080080 this->app_info.pAppName = "base";
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060081 this->app_info.appVersion = 1;
Chia-I Wu7461fcf2014-12-27 15:16:07 +080082 this->app_info.pEngineName = "unittest";
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060083 this->app_info.engineVersion = 1;
84 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
85
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060086 err = xglInitAndEnumerateGpus(&app_info, NULL,
Chia-I Wu9c877b22014-12-28 14:37:25 +080087 XGL_MAX_PHYSICAL_GPUS, &this->gpu_count, objs);
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060088 ASSERT_XGL_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -070089 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060090
91 m_device = new XglDevice(0, objs[0]);
92 m_device->get_device_queue();
93 }
94
95 virtual void TearDown() {
96 xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE);
97 }
98};
99
Tony Barbour1d7a55d2014-12-17 11:53:55 -0700100class XglIndexBufferObj;
101class XglConstantBufferObj;
102
Chia-I Wuae0564f2014-12-28 15:12:48 +0800103class XglCommandBufferObj : xgl_testing::CmdBuffer
Tony Barbour4f3e5a62014-12-10 14:34:45 -0700104{
105public:
106 XglCommandBufferObj(XglDevice *device);
Tony Barboure8f14162014-12-10 17:28:39 -0700107 XGL_CMD_BUFFER GetBufferHandle();
108 XGL_RESULT BeginCommandBuffer(XGL_FLAGS flags);
109 XGL_RESULT EndCommandBuffer();
110 void PrepareMemoryRegions(int transitionCount, XGL_MEMORY_STATE_TRANSITION *transitionPtr);
Tony Barbour1d7a55d2014-12-17 11:53:55 -0700111 void AddRenderTarget(XglImage *renderTarget);
112 void AddDepthStencil();
113 void ClearAllBuffers();
114 void ClearAllBuffers(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding, XGL_IMAGE depthStencilImage);
115 void BindAttachments(XGL_DEPTH_STENCIL_BIND_INFO *depthStencilBinding);
116 void BindAttachments();
117 void BindPipeline(XGL_PIPELINE pipeline);
118 void BindDescriptorSet(XGL_DESCRIPTOR_SET descriptorSet);
119 void BindVertexBuffer(XglConstantBufferObj *vertexBuffer, XGL_UINT offset, XGL_UINT binding);
120 void BindIndexBuffer(XglIndexBufferObj *indexBuffer, XGL_UINT offset);
121 void BindState(XGL_RASTER_STATE_OBJECT stateRaster, XGL_VIEWPORT_STATE_OBJECT stateViewport,
122 XGL_COLOR_BLEND_STATE_OBJECT colorBlend, XGL_DEPTH_STENCIL_STATE_OBJECT stateDepthStencil,
123 XGL_MSAA_STATE_OBJECT stateMsaa);
124 void Draw(XGL_UINT firstVertex, XGL_UINT vertexCount, XGL_UINT firstInstance, XGL_UINT instanceCount);
125 void DrawIndexed(XGL_UINT firstIndex, XGL_UINT indexCount, XGL_INT vertexOffset, XGL_UINT firstInstance, XGL_UINT instanceCount);
126 void QueueCommandBuffer(XGL_MEMORY_REF *memRefs, XGL_UINT32 numMemRefs);
Tony Barbour4f3e5a62014-12-10 14:34:45 -0700127
128protected:
129 XglDevice *m_device;
Tony Barbour1d7a55d2014-12-17 11:53:55 -0700130 vector<XglImage*> m_renderTargets;
131 XGL_UINT m_renderTargetCount;
Tony Barbour4f3e5a62014-12-10 14:34:45 -0700132
133};
134
Chia-I Wu67ee00f2014-12-28 15:26:08 +0800135class XglConstantBufferObj : public xgl_testing::GpuMemory
Tony Barbourf12bfb92014-11-19 16:33:11 -0700136{
137public:
Courtney Goeltzenleuchterea2db0d2014-12-04 15:18:47 -0700138 XglConstantBufferObj(XglDevice *device);
Tony Barbour685f4332014-11-20 15:06:56 -0700139 XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data);
Tony Barboure6152042014-12-10 17:40:15 -0700140 void SetMemoryState(XGL_MEMORY_STATE newState);
Courtney Goeltzenleuchter7715bc42014-12-04 15:26:56 -0700141 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding);
Tony Barbour685f4332014-11-20 15:06:56 -0700142 XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700143
144protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700145 XglDevice *m_device;
146 int m_numVertices;
147 int m_stride;
Tony Barbour9f47dc72014-12-10 14:36:31 -0700148 XglCommandBufferObj *m_commandBuffer;
Chia-I Wu67ee00f2014-12-28 15:26:08 +0800149 xgl_testing::Fence m_fence;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700150};
Courtney Goeltzenleuchterfa834c92014-12-04 15:24:05 -0700151
152class XglIndexBufferObj : public XglConstantBufferObj
153{
154public:
155 XglIndexBufferObj(XglDevice *device);
156 void CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE dataFormat, const void* data);
157 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset);
Tony Barbour140a59f2014-12-17 10:57:58 -0700158 XGL_INDEX_TYPE GetIndexType();
Courtney Goeltzenleuchterfa834c92014-12-04 15:24:05 -0700159
160protected:
161 XGL_INDEX_TYPE m_indexType;
162};
163
Chia-I Wudbec1222014-12-28 15:55:09 +0800164class XglTextureObj : public xgl_testing::Image
Tony Barbourf12bfb92014-11-19 16:33:11 -0700165{
166public:
167 XglTextureObj(XglDevice *device);
Tony Barbour84d3d022014-11-21 17:17:49 -0700168 void ChangeColors(uint32_t color1, uint32_t color2);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700169 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700170
171protected:
172 XglDevice *m_device;
Chia-I Wudbec1222014-12-28 15:55:09 +0800173 xgl_testing::ImageView m_textureView;
174 XGL_GPU_SIZE m_rowPitch;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700175};
176
177class XglSamplerObj
178{
179public:
180 XglSamplerObj(XglDevice *device);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700181 ~XglSamplerObj();
Tony Barbourf12bfb92014-11-19 16:33:11 -0700182 XGL_SAMPLER m_sampler;
183
184protected:
185 XGL_SAMPLER_CREATE_INFO m_samplerCreateInfo;
186 XglDevice *m_device;
187
188};
189
Tony Barbour685f4332014-11-20 15:06:56 -0700190class XglDescriptorSetObj
Tony Barbourf12bfb92014-11-19 16:33:11 -0700191{
192public:
Tony Barbour685f4332014-11-20 15:06:56 -0700193 XglDescriptorSetObj(XglDevice *device);
Tony Barbour342ae3b2014-12-03 13:59:18 -0700194 ~XglDescriptorSetObj();
Tony Barbour685f4332014-11-20 15:06:56 -0700195 void AttachMemoryView(XglConstantBufferObj* constantBuffer);
196 void AttachSampler( XglSamplerObj* sampler);
197 void AttachImageView( XglTextureObj* texture);
198 void BindCommandBuffer(XGL_CMD_BUFFER commandBuffer);
Tony Barbour3edb6ac2014-12-17 10:54:03 -0700199 void CreateXGLDescriptorSet();
200 XGL_DESCRIPTOR_SET GetDescriptorSetHandle();
Tony Barboura5712982014-12-18 17:06:21 -0700201 int GetTotalSlots();
Chia-I Wu5c590de2014-12-28 16:07:01 +0800202 XGL_DESCRIPTOR_SLOT_INFO * GetSlotInfo(vector<int>slots, vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types, vector<void*>objs );
Tony Barbourf12bfb92014-11-19 16:33:11 -0700203
204protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700205 XGL_DESCRIPTOR_SET_CREATE_INFO m_descriptorInfo;
206 XGL_DESCRIPTOR_SET m_rsrcDescSet;
207 XGL_GPU_MEMORY m_descriptor_set_mem;
208 XglDevice *m_device;
209 XGL_DESCRIPTOR_SLOT_INFO *m_slotInfo;
210 int m_nextSlot;
211 vector<int> m_memorySlots;
212 vector<XGL_MEMORY_VIEW_ATTACH_INFO*> m_memoryViews;
213 vector<int> m_samplerSlots;
Chia-I Wu5c590de2014-12-28 16:07:01 +0800214 vector<XglSamplerObj*> m_samplers;
Tony Barbour685f4332014-11-20 15:06:56 -0700215 vector<int> m_imageSlots;
216 vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageViews;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700217};
Tony Barbour685f4332014-11-20 15:06:56 -0700218
219
Tony Barbourf12bfb92014-11-19 16:33:11 -0700220class XglShaderObj
221{
222public:
Tony Barbourf43b6982014-11-25 13:18:32 -0700223 XglShaderObj(XglDevice *device, const char * shaderText, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700224 ~XglShaderObj();
Tony Barbourbf678472014-12-03 13:58:15 -0700225 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* GetStageCreateInfo(XglDescriptorSetObj *descriptorSet);
Tony Barbour685f4332014-11-20 15:06:56 -0700226 void BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer);
227 void BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture);
228 void BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700229
230protected:
231 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO stage_info;
232 XGL_SHADER m_shader;
233 XGL_PIPELINE_SHADER_STAGE m_stage;
234 XglDevice *m_device;
235 vector<int> m_memSlots;
236 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_memTypes;
Chia-I Wu5c590de2014-12-28 16:07:01 +0800237 vector<XGL_MEMORY_VIEW_ATTACH_INFO*> m_memObjs;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700238 vector<int> m_samplerSlots;
239 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_samplerTypes;
Chia-I Wu5c590de2014-12-28 16:07:01 +0800240 vector<XglSamplerObj*> m_samplerObjs;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700241 vector<int> m_imageSlots;
242 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_imageTypes;
Chia-I Wu5c590de2014-12-28 16:07:01 +0800243 vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageObjs;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700244
245};
246
247class XglPipelineObj
248{
249public:
250 XglPipelineObj(XglDevice *device);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700251 ~XglPipelineObj();
Tony Barbourbf678472014-12-03 13:58:15 -0700252 void BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700253 void AddShader(XglShaderObj* shaderObj);
254 void AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count);
255 void AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count);
256 void AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding);
Chia-I Wue7748802014-12-05 10:45:15 +0800257 void SetColorAttachment(XGL_UINT binding, const XGL_PIPELINE_CB_ATTACHMENT_STATE *att);
Tony Barboure7f2c7c2014-12-17 11:57:31 -0700258 void CreateXGLPipeline(XglDescriptorSetObj *descriptorSet);
259 XGL_PIPELINE GetPipelineHandle();
Tony Barbourf12bfb92014-11-19 16:33:11 -0700260
261protected:
262 XGL_PIPELINE m_pipeline;
263 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO m_vi_state;
264 XGL_PIPELINE_IA_STATE_CREATE_INFO m_ia_state;
265 XGL_PIPELINE_RS_STATE_CREATE_INFO m_rs_state;
266 XGL_PIPELINE_CB_STATE m_cb_state;
267 XGL_PIPELINE_DB_STATE_CREATE_INFO m_db_state;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700268 XGL_GPU_MEMORY m_pipe_mem;
269 XglDevice *m_device;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700270 vector<XglShaderObj*> m_shaderObjs;
271 vector<XglConstantBufferObj*> m_vertexBufferObjs;
272 vector<int> m_vertexBufferBindings;
273 int m_vertexBufferCount;
274
275};
276class XglMemoryRefManager{
277public:
278 XglMemoryRefManager();
Tony Barbour685f4332014-11-20 15:06:56 -0700279 void AddMemoryRef(XglConstantBufferObj* constantBuffer);
280 void AddMemoryRef(XglTextureObj *texture);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700281 XGL_MEMORY_REF* GetMemoryRefList();
282 int GetNumRefs();
283
284protected:
285 int m_numRefs;
Chia-I Wu5b308132014-12-28 15:43:42 +0800286 vector<XGL_GPU_MEMORY> m_bufferObjs;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700287
288};
289
290
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -0600291#endif // XGLRENDERFRAMEWORK_H