mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-06 05:06:07 +00:00
DawnTest: Factor Instance creation, Adapter discovery, and config logging
Bug: dawn:396 Change-Id: Idae3f388cf001e97c7fb4c84c50bca6825a2020b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/21761 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
0b8e319407
commit
5133221139
@ -146,7 +146,13 @@ void InitDawnEnd2EndTestEnvironment(int argc, char** argv) {
|
|||||||
testing::AddGlobalTestEnvironment(gTestEnv);
|
testing::AddGlobalTestEnvironment(gTestEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
void DawnTestEnvironment::SetEnvironment(DawnTestEnvironment* env) {
|
||||||
|
gTestEnv = env;
|
||||||
|
}
|
||||||
|
|
||||||
DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
|
DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
|
||||||
|
size_t argLen = 0; // Set when parsing --arg=X arguments
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (strcmp("-w", argv[i]) == 0 || strcmp("--use-wire", argv[i]) == 0) {
|
if (strcmp("-w", argv[i]) == 0 || strcmp("--use-wire", argv[i]) == 0) {
|
||||||
mUseWire = true;
|
mUseWire = true;
|
||||||
@ -235,8 +241,9 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr const char kVendorIdFilterArg[] = "--adapter-vendor-id=";
|
constexpr const char kVendorIdFilterArg[] = "--adapter-vendor-id=";
|
||||||
if (strstr(argv[i], kVendorIdFilterArg) == argv[i]) {
|
argLen = sizeof(kVendorIdFilterArg) - 1;
|
||||||
const char* vendorIdFilter = argv[i] + strlen(kVendorIdFilterArg);
|
if (strncmp(argv[i], kVendorIdFilterArg, argLen) == 0) {
|
||||||
|
const char* vendorIdFilter = argv[i] + argLen;
|
||||||
if (vendorIdFilter[0] != '\0') {
|
if (vendorIdFilter[0] != '\0') {
|
||||||
mVendorIdFilter = strtoul(vendorIdFilter, nullptr, 16);
|
mVendorIdFilter = strtoul(vendorIdFilter, nullptr, 16);
|
||||||
// Set filter flag if vendor id is non-zero.
|
// Set filter flag if vendor id is non-zero.
|
||||||
@ -246,8 +253,9 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr const char kWireTraceDirArg[] = "--wire-trace-dir=";
|
constexpr const char kWireTraceDirArg[] = "--wire-trace-dir=";
|
||||||
if (strstr(argv[i], kWireTraceDirArg) == argv[i]) {
|
argLen = sizeof(kWireTraceDirArg) - 1;
|
||||||
const char* wireTraceDir = argv[i] + strlen(kWireTraceDirArg);
|
if (strncmp(argv[i], kWireTraceDirArg, argLen) == 0) {
|
||||||
|
const char* wireTraceDir = argv[i] + argLen;
|
||||||
if (wireTraceDir[0] != '\0') {
|
if (wireTraceDir[0] != '\0') {
|
||||||
const char* sep = GetPathSeparator();
|
const char* sep = GetPathSeparator();
|
||||||
mWireTraceDir = wireTraceDir;
|
mWireTraceDir = wireTraceDir;
|
||||||
@ -281,20 +289,39 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
std::unique_ptr<dawn_native::Instance> DawnTestEnvironment::CreateInstanceAndDiscoverAdapters()
|
||||||
void DawnTestEnvironment::SetEnvironment(DawnTestEnvironment* env) {
|
const {
|
||||||
gTestEnv = env;
|
auto instance = std::make_unique<dawn_native::Instance>();
|
||||||
|
instance->EnableBackendValidation(mEnableBackendValidation);
|
||||||
|
instance->EnableBeginCaptureOnStartup(mBeginCaptureOnStartup);
|
||||||
|
|
||||||
|
instance->DiscoverDefaultAdapters();
|
||||||
|
|
||||||
|
#ifdef DAWN_ENABLE_BACKEND_OPENGL
|
||||||
|
if (!glfwInit()) {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
glfwDefaultWindowHints();
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
|
||||||
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
|
std::string windowName = "Dawn OpenGL test window";
|
||||||
|
GLFWwindow* window = glfwCreateWindow(400, 400, windowName.c_str(), nullptr, nullptr);
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
dawn_native::opengl::AdapterDiscoveryOptions adapterOptions;
|
||||||
|
adapterOptions.getProc = reinterpret_cast<void* (*)(const char*)>(glfwGetProcAddress);
|
||||||
|
instance->DiscoverAdapters(&adapterOptions);
|
||||||
|
#endif // DAWN_ENABLE_BACKEND_OPENGL
|
||||||
|
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DawnTestEnvironment::SetUp() {
|
void DawnTestEnvironment::PrintTestConfigurationAndAdapterInfo() const {
|
||||||
mInstance = std::make_unique<dawn_native::Instance>();
|
dawn::LogMessage log = dawn::InfoLog();
|
||||||
mInstance->EnableBackendValidation(mEnableBackendValidation);
|
log << "Testing configuration\n"
|
||||||
mInstance->EnableBeginCaptureOnStartup(mBeginCaptureOnStartup);
|
|
||||||
|
|
||||||
mInstance.get()->DiscoverDefaultAdapters();
|
|
||||||
DiscoverOpenGLAdapter();
|
|
||||||
|
|
||||||
dawn::InfoLog() << "Testing configuration\n"
|
|
||||||
"---------------------\n"
|
"---------------------\n"
|
||||||
"UseWire: "
|
"UseWire: "
|
||||||
<< (mUseWire ? "true" : "false")
|
<< (mUseWire ? "true" : "false")
|
||||||
@ -316,10 +343,10 @@ void DawnTestEnvironment::SetUp() {
|
|||||||
<< "\n"
|
<< "\n"
|
||||||
"\n"
|
"\n"
|
||||||
<< "System adapters: \n";
|
<< "System adapters: \n";
|
||||||
|
|
||||||
for (const dawn_native::Adapter& adapter : mInstance->GetAdapters()) {
|
for (const dawn_native::Adapter& adapter : mInstance->GetAdapters()) {
|
||||||
wgpu::AdapterProperties properties;
|
wgpu::AdapterProperties properties;
|
||||||
adapter.GetProperties(&properties);
|
adapter.GetProperties(&properties);
|
||||||
|
|
||||||
std::ostringstream vendorId;
|
std::ostringstream vendorId;
|
||||||
std::ostringstream deviceId;
|
std::ostringstream deviceId;
|
||||||
vendorId << std::setfill('0') << std::uppercase << std::internal << std::hex << std::setw(4)
|
vendorId << std::setfill('0') << std::uppercase << std::internal << std::hex << std::setw(4)
|
||||||
@ -328,19 +355,23 @@ void DawnTestEnvironment::SetUp() {
|
|||||||
<< properties.deviceID;
|
<< properties.deviceID;
|
||||||
|
|
||||||
// Preparing for outputting hex numbers
|
// Preparing for outputting hex numbers
|
||||||
dawn::InfoLog() << std::showbase << std::hex << std::setfill('0') << std::setw(4)
|
log << std::showbase << std::hex << std::setfill('0') << std::setw(4)
|
||||||
|
|
||||||
<< " - \"" << properties.name << "\"\n"
|
<< " - \"" << properties.name << "\"\n"
|
||||||
<< " type: " << AdapterTypeName(properties.adapterType)
|
<< " type: " << AdapterTypeName(properties.adapterType)
|
||||||
<< ", backend: " << ParamName(properties.backendType) << "\n"
|
<< ", backend: " << ParamName(properties.backendType) << "\n"
|
||||||
<< " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str()
|
<< " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str()
|
||||||
<< (mHasVendorIdFilter && mVendorIdFilter == properties.vendorID
|
<< (mHasVendorIdFilter && mVendorIdFilter == properties.vendorID ? " [Selected]" : "")
|
||||||
? " [Selected]"
|
|
||||||
: "")
|
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DawnTestEnvironment::SetUp() {
|
||||||
|
mInstance = CreateInstanceAndDiscoverAdapters();
|
||||||
|
ASSERT(mInstance);
|
||||||
|
PrintTestConfigurationAndAdapterInfo();
|
||||||
|
}
|
||||||
|
|
||||||
void DawnTestEnvironment::TearDown() {
|
void DawnTestEnvironment::TearDown() {
|
||||||
// When Vulkan validation layers are enabled, it's unsafe to call Vulkan APIs in the destructor
|
// When Vulkan validation layers are enabled, it's unsafe to call Vulkan APIs in the destructor
|
||||||
// of a static/global variable, so the instance must be manually released beforehand.
|
// of a static/global variable, so the instance must be manually released beforehand.
|
||||||
@ -386,27 +417,6 @@ const char* DawnTestEnvironment::GetWireTraceDir() const {
|
|||||||
return mWireTraceDir.c_str();
|
return mWireTraceDir.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DawnTestEnvironment::DiscoverOpenGLAdapter() {
|
|
||||||
#ifdef DAWN_ENABLE_BACKEND_OPENGL
|
|
||||||
if (!glfwInit()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
glfwDefaultWindowHints();
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
|
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
||||||
|
|
||||||
std::string windowName = "Dawn OpenGL test window";
|
|
||||||
GLFWwindow* window = glfwCreateWindow(400, 400, windowName.c_str(), nullptr, nullptr);
|
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
dawn_native::opengl::AdapterDiscoveryOptions adapterOptions;
|
|
||||||
adapterOptions.getProc = reinterpret_cast<void* (*)(const char*)>(glfwGetProcAddress);
|
|
||||||
mInstance->DiscoverAdapters(&adapterOptions);
|
|
||||||
#endif // DAWN_ENABLE_BACKEND_OPENGL
|
|
||||||
}
|
|
||||||
|
|
||||||
class WireServerTraceLayer : public dawn_wire::CommandHandler {
|
class WireServerTraceLayer : public dawn_wire::CommandHandler {
|
||||||
public:
|
public:
|
||||||
WireServerTraceLayer(const char* file, dawn_wire::CommandHandler* handler)
|
WireServerTraceLayer(const char* file, dawn_wire::CommandHandler* handler)
|
||||||
|
@ -157,7 +157,8 @@ class DawnTestEnvironment : public testing::Environment {
|
|||||||
std::unique_ptr<dawn_native::Instance> mInstance;
|
std::unique_ptr<dawn_native::Instance> mInstance;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DiscoverOpenGLAdapter();
|
std::unique_ptr<dawn_native::Instance> CreateInstanceAndDiscoverAdapters() const;
|
||||||
|
void PrintTestConfigurationAndAdapterInfo() const;
|
||||||
|
|
||||||
bool mUseWire = false;
|
bool mUseWire = false;
|
||||||
bool mEnableBackendValidation = false;
|
bool mEnableBackendValidation = false;
|
||||||
|
@ -78,6 +78,7 @@ void InitDawnPerfTestEnvironment(int argc, char** argv) {
|
|||||||
|
|
||||||
DawnPerfTestEnvironment::DawnPerfTestEnvironment(int argc, char** argv)
|
DawnPerfTestEnvironment::DawnPerfTestEnvironment(int argc, char** argv)
|
||||||
: DawnTestEnvironment(argc, argv) {
|
: DawnTestEnvironment(argc, argv) {
|
||||||
|
size_t argLen = 0; // Set when parsing --arg=X arguments
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (strcmp("--calibration", argv[i]) == 0) {
|
if (strcmp("--calibration", argv[i]) == 0) {
|
||||||
mIsCalibrating = true;
|
mIsCalibrating = true;
|
||||||
@ -85,8 +86,9 @@ DawnPerfTestEnvironment::DawnPerfTestEnvironment(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr const char kOverrideStepsArg[] = "--override-steps=";
|
constexpr const char kOverrideStepsArg[] = "--override-steps=";
|
||||||
if (strstr(argv[i], kOverrideStepsArg) == argv[i]) {
|
argLen = sizeof(kOverrideStepsArg) - 1;
|
||||||
const char* overrideSteps = argv[i] + strlen(kOverrideStepsArg);
|
if (strncmp(argv[i], kOverrideStepsArg, argLen) == 0) {
|
||||||
|
const char* overrideSteps = argv[i] + argLen;
|
||||||
if (overrideSteps[0] != '\0') {
|
if (overrideSteps[0] != '\0') {
|
||||||
mOverrideStepsToRun = strtoul(overrideSteps, nullptr, 0);
|
mOverrideStepsToRun = strtoul(overrideSteps, nullptr, 0);
|
||||||
}
|
}
|
||||||
@ -94,8 +96,9 @@ DawnPerfTestEnvironment::DawnPerfTestEnvironment(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr const char kTraceFileArg[] = "--trace-file=";
|
constexpr const char kTraceFileArg[] = "--trace-file=";
|
||||||
if (strstr(argv[i], kTraceFileArg) == argv[i]) {
|
argLen = sizeof(kTraceFileArg) - 1;
|
||||||
const char* traceFile = argv[i] + strlen(kTraceFileArg);
|
if (strncmp(argv[i], kTraceFileArg, argLen) == 0) {
|
||||||
|
const char* traceFile = argv[i] + argLen;
|
||||||
if (traceFile[0] != '\0') {
|
if (traceFile[0] != '\0') {
|
||||||
mTraceFile = traceFile;
|
mTraceFile = traceFile;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user