1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
|
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2019-2022 Baldur Karlsson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#pragma once
#if defined(WIN32)
#include "win32/win32_platform.h"
#elif defined(__linux__)
#include "linux/linux_platform.h"
#elif defined(__APPLE__)
#include "apple/apple_platform.h"
#else
#error UNKNOWN PLATFORM
#endif
#include <math.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include "renderdoc_app.h"
typedef uint8_t byte;
#define STRINGIZE2(a) #a
#define STRINGIZE(a) STRINGIZE2(a)
#define CONCAT2(a, b) a##b
#define CONCAT(a, b) CONCAT2(a, b)
#define PCI_VENDOR_NV 0x10DE
#define PCI_VENDOR_AMD 0x1002
#define PCI_VENDOR_INTEL 0x8086
enum class SPIRVTarget
{
opengl,
vulkan,
vulkan11,
vulkan12,
};
enum class ShaderLang
{
glsl,
hlsl,
spvasm,
};
enum class ShaderStage
{
vert,
tesscontrol,
tesseval,
geom,
frag,
comp
};
bool InternalSpvCompiler();
bool SpvCompilationSupported();
std::vector<uint32_t> CompileShaderToSpv(const std::string &source_text, SPIRVTarget target,
ShaderLang lang, ShaderStage stage, const char *entry_point,
const std::map<std::string, std::string> ¯os = {});
struct Vec2f
{
Vec2f(float X = 0.0f, float Y = 0.0f)
{
x = X;
y = Y;
}
float x;
float y;
};
class Vec3f
{
public:
Vec3f(const float X = 0.0f, const float Y = 0.0f, const float Z = 0.0f) : x(X), y(Y), z(Z) {}
inline float Dot(const Vec3f &o) const { return x * o.x + y * o.y + z * o.z; }
inline Vec3f Cross(const Vec3f &o) const
{
return Vec3f(y * o.z - z * o.y, z * o.x - x * o.z, x * o.y - y * o.x);
}
inline float Length() const { return sqrtf(Dot(*this)); }
inline void Normalise()
{
float l = Length();
x /= l;
y /= l;
z /= l;
}
float x, y, z;
};
struct Vec4f
{
Vec4f(float X = 0.0f, float Y = 0.0f, float Z = 0.0f, float W = 0.0f)
{
x = X;
y = Y;
z = Z;
w = W;
}
bool operator==(const Vec4f &o) { return x == o.x && y == o.y && z == o.z && w == o.w; }
bool operator!=(const Vec4f &o) { return !(*this == o); }
float x, y, z, w;
};
struct Vec4i
{
Vec4i(int32_t X = 0, int32_t Y = 0, int32_t Z = 0, int32_t W = 0)
{
x = X;
y = Y;
z = Z;
w = W;
}
int32_t x, y, z, w;
};
struct Vec4u
{
Vec4u(uint32_t X = 0, uint32_t Y = 0, uint32_t Z = 0, uint32_t W = 0)
{
x = X;
y = Y;
z = Z;
w = W;
}
uint32_t x, y, z, w;
};
struct DefaultA2V
{
Vec3f pos;
Vec4f col;
Vec2f uv;
};
extern const DefaultA2V DefaultTri[3];
extern const char *SmileyTexture[63];
struct Texture
{
uint32_t width;
uint32_t height;
std::vector<uint32_t> data;
};
void LoadXPM(const char **XPM, Texture &tex);
struct GraphicsWindow
{
GraphicsWindow(const std::string &title) : title(title) {}
virtual ~GraphicsWindow() {}
virtual void Resize(int width, int height) = 0;
virtual bool Update() = 0;
std::string title;
};
struct GraphicsTest
{
virtual ~GraphicsTest() {}
virtual GraphicsWindow *MakeWindow(int width, int height, const char *title) { return NULL; }
virtual int main() { return 9; }
virtual void Prepare(int argc, char **argv);
virtual void SetName(const char *name) { screenTitle = name; }
virtual bool Init();
virtual void Shutdown();
std::string Avail;
std::string GetDataPath(const std::string &filename);
bool FrameLimit();
int curFrame = -1;
const char *screenTitle = "RenderDoc test program";
bool headless = false;
RENDERDOC_API_1_0_0 *rdoc = NULL;
// shared parameters
static int maxFrameCount;
static std::string dataRoot;
static int screenWidth;
static int screenHeight;
static bool debugDevice;
};
enum class TestAPI
{
D3D11,
Vulkan,
OpenGL,
D3D12,
Count,
};
inline const char *APIName(TestAPI API)
{
switch(API)
{
case TestAPI::D3D11: return "D3D11";
case TestAPI::Vulkan: return "Vulkan";
case TestAPI::OpenGL: return "OpenGL";
case TestAPI::D3D12: return "D3D12";
case TestAPI::Count: break;
}
return "???";
}
struct TestMetadata
{
TestAPI API;
const char *Name;
const char *Description;
GraphicsTest *test;
bool IsAvailable() const { return test->Avail.empty(); }
const char *AvailMessage() const { return test->Avail.c_str(); }
bool operator<(const TestMetadata &o) const
{
if(API != o.API)
return API < o.API;
int ret = strcmp(Name, o.Name);
if(ret != 0)
return ret < 0;
return test < o.test;
}
};
void RegisterTest(TestMetadata test);
#define RD_TEST(Test, Parent) \
struct Test; \
int CONCAT(unique_, Test); \
typedef Test CurrentTest; \
namespace \
{ \
constexpr const char *TestName = #Test; \
}; \
struct Test : Parent
#define REGISTER_TEST() \
namespace \
{ \
struct TestRegistration \
{ \
CurrentTest m_impl; \
TestRegistration() \
{ \
TestMetadata test; \
test.API = CurrentTest::API; \
test.Name = TestName; \
test.Description = CurrentTest::Description; \
test.test = &m_impl; \
RegisterTest(test); \
} \
} Anon##__LINE__; \
};
std::string GetCWD();
std::string GetEnvVar(const char *var);
uint64_t GetMemoryUsage();
#ifndef ARRAY_COUNT
#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof(arr[0]))
#endif
#define RANDF(mn, mx) ((float(rand()) / float(RAND_MAX)) * ((mx) - (mn)) + (mn))
template <typename T>
inline T AlignUp(T x, T a)
{
return (x + (a - 1)) & (~(a - 1));
}
template <typename T, typename A>
inline T AlignUpPtr(T x, A a)
{
return (T)AlignUp<uintptr_t>((uintptr_t)x, (uintptr_t)a);
}
// quick and dirty half conversion, doesn't handle NaN/inf/subnormal/truncation/rounding
uint16_t MakeHalf(float f);
std::string strlower(const std::string &str);
std::string strupper(const std::string &str);
std::string trim(const std::string &str);
void DebugPrint(const char *fmt, ...);
#define TEST_ASSERT(cond, fmt, ...) \
do \
{ \
if(!(cond)) \
{ \
DebugPrint("%s:%d Assert Failure '%s': " fmt "\n", __FILE__, __LINE__, #cond, ##__VA_ARGS__); \
DEBUG_BREAK(); \
} \
} while(0)
#define TEST_LOG(fmt, ...) \
do \
{ \
DebugPrint("%s:%d Log: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
} while(0)
#define TEST_WARN(fmt, ...) \
do \
{ \
DebugPrint("%s:%d Warning: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
} while(0)
#define TEST_ERROR(fmt, ...) \
do \
{ \
DebugPrint("%s:%d Error: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
DEBUG_BREAK(); \
} while(0)
#define TEST_FATAL(fmt, ...) \
do \
{ \
DebugPrint("%s:%d Fatal Error: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
DEBUG_BREAK(); \
exit(0); \
} while(0)
#define TEST_UNIMPLEMENTED(fmt, ...) \
do \
{ \
DebugPrint("%s:%d Unimplemented: " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
DEBUG_BREAK(); \
exit(0); \
} while(0)
namespace TextureZoo
{
enum class DataType
{
Float,
UNorm,
SNorm,
UInt,
SInt,
Count,
};
enum class TextureType
{
Unknown,
Regular,
R9G9B9E5,
G4R4,
A4R4G4B4,
R4G4B4A4,
R5G6B5,
R5G5B5A1,
A1R5G5B5,
RGB10A2,
BC1,
BC2,
BC3,
BC4,
BC5,
BC6,
BC7,
};
static const uint32_t texWidth = 8;
static const uint32_t texHeight = 8;
static const uint32_t texDepth = 10;
static const uint32_t texMips = 3;
static const uint32_t texSlices = 2;
static const uint32_t texSamples = 2;
struct TexConfig
{
TextureType type;
uint32_t componentCount;
uint32_t componentBytes;
DataType data;
};
struct TexData
{
std::vector<byte> byteData;
uint32_t rowPitch = 0;
uint32_t slicePitch = 0;
};
void MakeData(TexData &data, const TexConfig &cfg, Vec4i dimensions, uint32_t mip, uint32_t slice);
}; // namespace TextureZoo
|