blob: ea1b57697019b7b4fee3516b46e4ccd012d242f9 [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
39 void CreateQueryPool(XGL_QUERY_TYPE type, XGL_UINT slots,
40 XGL_QUERY_POOL *pPool, XGL_GPU_MEMORY *pMem);
41 void DestroyQueryPool(XGL_QUERY_POOL pool, XGL_GPU_MEMORY mem);
42
43 XGL_DEVICE device() {return m_device->device();}
Tobin Ehlis3c26a542014-11-18 11:28:33 -070044 XGL_PHYSICAL_GPU gpu() {return objs[0];}
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060045 void CreateShader(XGL_PIPELINE_SHADER_STAGE stage, const char *shader_code, XGL_SHADER *pshader);
46 void InitPipeline();
47 void InitMesh( XGL_UINT32 numVertices, XGL_GPU_SIZE vbStride, const void* vertices );
48 void InitConstantBuffer( int constantCount, int constantSize, const void* data );
Courtney Goeltzenleuchter34b81772014-10-10 18:04:39 -060049 void UpdateConstantBuffer(const void* data);
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060050 void InitViewport(float width, float height);
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -060051 void InitViewport();
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060052 void InitRenderTarget();
53 void InitFramework();
Courtney Goeltzenleuchtercb5a89c2014-10-08 12:20:26 -060054 void ShutdownFramework();
55 void InitState();
Courtney Goeltzenleuchtere5409342014-10-08 14:26:40 -060056 void CreateDefaultPipeline(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
57 void GenerateClearAndPrepareBufferCmds();
58 void GenerateBindRenderTargetCmd();
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060059 void GenerateBindStateAndPipelineCmds(XGL_PIPELINE* pipeline);
Tony Barbourf43b6982014-11-25 13:18:32 -070060 void GenerateBindStateAndPipelineCmds();
61
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060062
63protected:
64 XGL_APPLICATION_INFO app_info;
65 XGL_PHYSICAL_GPU objs[MAX_GPUS];
66 XGL_UINT gpu_count;
67 XGL_GPU_MEMORY m_descriptor_set_mem;
68 XGL_GPU_MEMORY m_pipe_mem;
69 XglDevice *m_device;
70 XGL_CMD_BUFFER m_cmdBuffer;
71 XGL_UINT32 m_numVertices;
72 XGL_MEMORY_VIEW_ATTACH_INFO m_vtxBufferView;
73 XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
74 XGL_GPU_MEMORY m_vtxBufferMem;
75 XGL_GPU_MEMORY m_constantBufferMem;
76 XGL_UINT32 m_numMemRefs;
77 XGL_MEMORY_REF m_memRefs[5];
78 XGL_RASTER_STATE_OBJECT m_stateRaster;
79 XGL_COLOR_BLEND_STATE_OBJECT m_colorBlend;
80 XGL_VIEWPORT_STATE_OBJECT m_stateViewport;
81 XGL_DEPTH_STENCIL_STATE_OBJECT m_stateDepthStencil;
82 XGL_MSAA_STATE_OBJECT m_stateMsaa;
83 XGL_DESCRIPTOR_SET m_rsrcDescSet;
84 XglImage *m_renderTarget;
85 XGL_FLOAT m_width, m_height;
86 XGL_FORMAT m_render_target_fmt;
Courtney Goeltzenleuchterb66e7de2014-10-22 14:12:38 -060087 XGL_COLOR_ATTACHMENT_BIND_INFO m_colorBinding;
88 XGL_DEPTH_STENCIL_BIND_INFO m_depthStencilBinding;
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -060089
90 /*
91 * SetUp and TearDown are called by the Google Test framework
92 * to initialize a test framework based on this class.
93 */
94 virtual void SetUp() {
95 XGL_RESULT err;
96
97 this->app_info.sType = XGL_STRUCTURE_TYPE_APPLICATION_INFO;
98 this->app_info.pNext = NULL;
99 this->app_info.pAppName = (const XGL_CHAR *) "base";
100 this->app_info.appVersion = 1;
101 this->app_info.pEngineName = (const XGL_CHAR *) "unittest";
102 this->app_info.engineVersion = 1;
103 this->app_info.apiVersion = XGL_MAKE_VERSION(0, 22, 0);
104
105 memset(&m_vtxBufferView, 0, sizeof(m_vtxBufferView));
106 m_vtxBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO;
107
108 memset(&m_constantBufferView, 0, sizeof(m_constantBufferView));
109 m_constantBufferView.sType = XGL_STRUCTURE_TYPE_MEMORY_VIEW_ATTACH_INFO;
110
111 err = xglInitAndEnumerateGpus(&app_info, NULL,
112 MAX_GPUS, &this->gpu_count, objs);
113 ASSERT_XGL_SUCCESS(err);
Jon Ashburn19733c92014-11-26 11:06:49 -0700114 ASSERT_GE(this->gpu_count, 1) << "No GPU available";
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -0600115
116 m_device = new XglDevice(0, objs[0]);
117 m_device->get_device_queue();
118 }
119
120 virtual void TearDown() {
121 xglInitAndEnumerateGpus(&this->app_info, XGL_NULL_HANDLE, 0, &gpu_count, XGL_NULL_HANDLE);
122 }
123};
124
Tony Barbour685f4332014-11-20 15:06:56 -0700125class XglConstantBufferObj
Tony Barbourf12bfb92014-11-19 16:33:11 -0700126{
127public:
Courtney Goeltzenleuchterea2db0d2014-12-04 15:18:47 -0700128 XglConstantBufferObj(XglDevice *device);
Tony Barbour685f4332014-11-20 15:06:56 -0700129 XglConstantBufferObj(XglDevice *device, int constantCount, int constantSize, const void* data);
130 void SetMemoryState(XGL_CMD_BUFFER cmdBuffer, XGL_MEMORY_STATE newState);
Courtney Goeltzenleuchter7715bc42014-12-04 15:26:56 -0700131 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset, XGL_UINT binding);
Tony Barbour685f4332014-11-20 15:06:56 -0700132 XGL_MEMORY_VIEW_ATTACH_INFO m_constantBufferView;
133 XGL_GPU_MEMORY m_constantBufferMem;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700134
135protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700136 XglDevice *m_device;
137 int m_numVertices;
138 int m_stride;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700139};
Courtney Goeltzenleuchterfa834c92014-12-04 15:24:05 -0700140
141class XglIndexBufferObj : public XglConstantBufferObj
142{
143public:
144 XglIndexBufferObj(XglDevice *device);
145 void CreateAndInitBuffer(int numIndexes, XGL_INDEX_TYPE dataFormat, const void* data);
146 void Bind(XGL_CMD_BUFFER cmdBuffer, XGL_GPU_SIZE offset);
147
148protected:
149 XGL_INDEX_TYPE m_indexType;
150};
151
Tony Barbourf12bfb92014-11-19 16:33:11 -0700152class XglTextureObj
153{
154public:
155 XglTextureObj(XglDevice *device);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700156 ~XglTextureObj();
Tony Barbour84d3d022014-11-21 17:17:49 -0700157 void ChangeColors(uint32_t color1, uint32_t color2);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700158 XGL_IMAGE m_texture;
159 XGL_IMAGE_VIEW_ATTACH_INFO m_textureViewInfo;
160 XGL_GPU_MEMORY m_textureMem;
161
162protected:
163 XglDevice *m_device;
164 XGL_IMAGE_VIEW m_textureView;
Tony Barbour84d3d022014-11-21 17:17:49 -0700165 int m_texHeight;
166 int m_texWidth;
167 int m_rowPitch;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700168
169};
170
171class XglSamplerObj
172{
173public:
174 XglSamplerObj(XglDevice *device);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700175 ~XglSamplerObj();
Tony Barbourf12bfb92014-11-19 16:33:11 -0700176 XGL_SAMPLER m_sampler;
177
178protected:
179 XGL_SAMPLER_CREATE_INFO m_samplerCreateInfo;
180 XglDevice *m_device;
181
182};
183
Tony Barbour685f4332014-11-20 15:06:56 -0700184class XglDescriptorSetObj
Tony Barbourf12bfb92014-11-19 16:33:11 -0700185{
186public:
Tony Barbour685f4332014-11-20 15:06:56 -0700187 XglDescriptorSetObj(XglDevice *device);
Tony Barbour342ae3b2014-12-03 13:59:18 -0700188 ~XglDescriptorSetObj();
Tony Barbour685f4332014-11-20 15:06:56 -0700189 void AttachMemoryView(XglConstantBufferObj* constantBuffer);
190 void AttachSampler( XglSamplerObj* sampler);
191 void AttachImageView( XglTextureObj* texture);
192 void BindCommandBuffer(XGL_CMD_BUFFER commandBuffer);
193 XGL_DESCRIPTOR_SLOT_INFO * GetSlotInfo(vector<int>slots, vector<XGL_DESCRIPTOR_SET_SLOT_TYPE>types, vector<XGL_OBJECT>objs );
Tony Barbourf12bfb92014-11-19 16:33:11 -0700194
195protected:
Tony Barbour685f4332014-11-20 15:06:56 -0700196 XGL_DESCRIPTOR_SET_CREATE_INFO m_descriptorInfo;
197 XGL_DESCRIPTOR_SET m_rsrcDescSet;
198 XGL_GPU_MEMORY m_descriptor_set_mem;
199 XglDevice *m_device;
200 XGL_DESCRIPTOR_SLOT_INFO *m_slotInfo;
201 int m_nextSlot;
202 vector<int> m_memorySlots;
203 vector<XGL_MEMORY_VIEW_ATTACH_INFO*> m_memoryViews;
204 vector<int> m_samplerSlots;
205 vector<XGL_SAMPLER*> m_samplers;
206 vector<int> m_imageSlots;
207 vector<XGL_IMAGE_VIEW_ATTACH_INFO*> m_imageViews;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700208};
Tony Barbour685f4332014-11-20 15:06:56 -0700209
210
Tony Barbourf12bfb92014-11-19 16:33:11 -0700211class XglShaderObj
212{
213public:
Tony Barbourf43b6982014-11-25 13:18:32 -0700214 XglShaderObj(XglDevice *device, const char * shaderText, XGL_PIPELINE_SHADER_STAGE stage, XglRenderFramework *framework);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700215 ~XglShaderObj();
Tony Barbourbf678472014-12-03 13:58:15 -0700216 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO* GetStageCreateInfo(XglDescriptorSetObj *descriptorSet);
Tony Barbour685f4332014-11-20 15:06:56 -0700217 void BindShaderEntitySlotToMemory(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglConstantBufferObj *constantBuffer);
218 void BindShaderEntitySlotToImage(int slot, XGL_DESCRIPTOR_SET_SLOT_TYPE type, XglTextureObj *texture);
219 void BindShaderEntitySlotToSampler(int slot, XglSamplerObj *sampler);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700220
221protected:
222 XGL_PIPELINE_SHADER_STAGE_CREATE_INFO stage_info;
223 XGL_SHADER m_shader;
224 XGL_PIPELINE_SHADER_STAGE m_stage;
225 XglDevice *m_device;
226 vector<int> m_memSlots;
227 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_memTypes;
228 vector<XGL_OBJECT> m_memObjs;
229 vector<int> m_samplerSlots;
230 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_samplerTypes;
231 vector<XGL_OBJECT> m_samplerObjs;
232 vector<int> m_imageSlots;
233 vector<XGL_DESCRIPTOR_SET_SLOT_TYPE> m_imageTypes;
234 vector<XGL_OBJECT> m_imageObjs;
235
236};
237
238class XglPipelineObj
239{
240public:
241 XglPipelineObj(XglDevice *device);
Tony Barbour2cb6bf52014-12-03 15:59:38 -0700242 ~XglPipelineObj();
Tony Barbourbf678472014-12-03 13:58:15 -0700243 void BindPipelineCommandBuffer(XGL_CMD_BUFFER m_cmdBuffer, XglDescriptorSetObj *descriptorSet);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700244 void AddShader(XglShaderObj* shaderObj);
245 void AddVertexInputAttribs(XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* vi_attrib, int count);
246 void AddVertexInputBindings(XGL_VERTEX_INPUT_BINDING_DESCRIPTION* vi_binding, int count);
247 void AddVertexDataBuffer(XglConstantBufferObj* vertexDataBuffer, int binding);
248
249protected:
250 XGL_PIPELINE m_pipeline;
251 XGL_PIPELINE_VERTEX_INPUT_CREATE_INFO m_vi_state;
252 XGL_PIPELINE_IA_STATE_CREATE_INFO m_ia_state;
253 XGL_PIPELINE_RS_STATE_CREATE_INFO m_rs_state;
254 XGL_PIPELINE_CB_STATE m_cb_state;
255 XGL_PIPELINE_DB_STATE_CREATE_INFO m_db_state;
256 XGL_FORMAT m_render_target_format;
257 XGL_PIPELINE_CB_ATTACHMENT_STATE m_cb_attachment_state;
258 XGL_GPU_MEMORY m_pipe_mem;
259 XglDevice *m_device;
Tony Barbourf12bfb92014-11-19 16:33:11 -0700260 vector<XglShaderObj*> m_shaderObjs;
261 vector<XglConstantBufferObj*> m_vertexBufferObjs;
262 vector<int> m_vertexBufferBindings;
263 int m_vertexBufferCount;
264
265};
266class XglMemoryRefManager{
267public:
268 XglMemoryRefManager();
Tony Barbour685f4332014-11-20 15:06:56 -0700269 void AddMemoryRef(XglConstantBufferObj* constantBuffer);
270 void AddMemoryRef(XglTextureObj *texture);
Tony Barbourf12bfb92014-11-19 16:33:11 -0700271 XGL_MEMORY_REF* GetMemoryRefList();
272 int GetNumRefs();
273
274protected:
275 int m_numRefs;
276 vector<XGL_GPU_MEMORY*> m_bufferObjs;
277
278};
279
280
Courtney Goeltzenleuchter5744b972014-10-08 08:50:49 -0600281#endif // XGLRENDERFRAMEWORK_H