Skip to content

[NFC] Simplify window size handling #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions benchmarks/graphics_pipeline/GraphicsBenchmarkApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ void GraphicsBenchmarkApp::Config(ppx::ApplicationSettings& settings)
{
settings.appName = "graphics_pipeline";
settings.enableImGui = true;
settings.window.width = 1920;
settings.window.height = 1080;
settings.grfx.api = kApi;
settings.grfx.numFramesInFlight = 1;
settings.grfx.swapchain.depthFormat = grfx::FORMAT_D32_FLOAT;
Expand All @@ -192,6 +190,7 @@ void GraphicsBenchmarkApp::Config(ppx::ApplicationSettings& settings)
#endif
settings.standardKnobsDefaultValue.enableMetrics = true;
settings.standardKnobsDefaultValue.overwriteMetricsFile = true;
settings.standardKnobsDefaultValue.resolution = std::make_pair(1920, 1080);
}

void GraphicsBenchmarkApp::Setup()
Expand Down
28 changes: 19 additions & 9 deletions include/ppx/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ struct ApplicationSettings

struct
{
uint32_t width = 0;
uint32_t height = 0;
std::string title = "";
bool resizable = false;
} window;
Expand Down Expand Up @@ -198,7 +196,7 @@ struct ApplicationSettings
bool listGpus = false;
std::string metricsFilename = "report_@.json";
bool overwriteMetricsFile = false;
std::pair<int, int> resolution = std::make_pair(0, 0);
std::pair<int, int> resolution = std::make_pair(1280, 720);
uint32_t runTimeMs = 0;
int screenshotFrameNumber = -1;
std::string screenshotPath = "screenshot_frame_#.ppm";
Expand All @@ -219,7 +217,7 @@ class Application
{
public:
Application();
Application(uint32_t windowWidth, uint32_t windowHeight, const char* windowTitle);
Application(const char* windowTitle);
virtual ~Application();

static Application* Get();
Expand Down Expand Up @@ -288,15 +286,27 @@ class Application

const ApplicationSettings* GetSettings() const { return &mSettings; }
const StandardOptions& GetStandardOptions() const { return mStandardOpts; }
uint32_t GetWindowWidth() const { return mSettings.window.width; }
uint32_t GetWindowHeight() const { return mSettings.window.height; }
bool IsWindowIconified() const;
bool IsWindowMaximized() const;
uint32_t GetUIWidth() const;
uint32_t GetUIHeight() const;
float GetWindowAspect() const { return static_cast<float>(mSettings.window.width) / static_cast<float>(mSettings.window.height); }
grfx::Rect GetScissor() const;
grfx::Viewport GetViewport(float minDepth = 0.0f, float maxDepth = 1.0f) const;

std::pair<uint32_t, uint32_t> GetWindowSize() const
{
return mWindow != nullptr ? mWindow->Size() : mStandardOpts.pResolution->GetValue();
}

uint32_t GetWindowWidth() const { return GetWindowSize().first; }
uint32_t GetWindowHeight() const { return GetWindowSize().second; }

float GetWindowAspect() const
{
const auto size = GetWindowSize();
return static_cast<float>(size.first) / static_cast<float>(size.second);
}

grfx::Rect GetScissor() const;
grfx::Viewport GetViewport(float minDepth = 0.0f, float maxDepth = 1.0f) const;

// Loads a DXIL or SPV shader from baseDir.
//
Expand Down
6 changes: 6 additions & 0 deletions include/ppx/command_line_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class CliOptions
// not counting multiple appearances of the same flag such as: --assets-path a --assets-path b
size_t GetNumUniqueOptions() const { return mAllOptions.size(); }

// Returns true if the given option is present in the commandline. False otherwise.
bool HasOption(const std::string& optionName) const
{
return mAllOptions.cend() != mAllOptions.find(optionName);
}

// Tries to parse the option string into the type of the default value and return it.
// If the value fails to be converted, return the specified default value.
// Warning: If this is called instead of the vector overload for multiple-value flags,
Expand Down
9 changes: 7 additions & 2 deletions include/ppx/knob.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ class KnobFlag final
{
public:
KnobFlag(const std::string& flagName, T defaultValue)
: Knob(flagName, false)
: Knob(flagName, false), mDirty(false)
{
SetValue(defaultValue);
}

KnobFlag(const std::string& flagName, T defaultValue, T minValue, T maxValue)
: Knob(flagName, false)
: Knob(flagName, false), mDirty(false)
{
static_assert(std::is_arithmetic_v<T>, "KnobFlag can only be defined with min/max when it's of arithmetic type");
PPX_ASSERT_MSG(minValue < maxValue, "invalid range to initialize KnobFlag");
Expand All @@ -400,6 +400,8 @@ class KnobFlag final

T GetValue() const { return mValue; }

bool IsDefaultValue() const { return !mDirty; }

void SetValidator(std::function<bool(T)> validatorFunc) { mValidatorFunc = validatorFunc; }

private:
Expand All @@ -418,6 +420,8 @@ class KnobFlag final

void UpdateFromFlags(const CliOptions& opts) override
{
if (opts.HasOption(mFlagName))
mDirty = true;
SetValue(opts.GetOptionValueOrDefault(mFlagName, mValue));
}

Expand All @@ -438,6 +442,7 @@ class KnobFlag final
private:
T mValue;
std::function<bool(T)> mValidatorFunc;
bool mDirty;
};

// KnobManager holds the knobs in an application
Expand Down
9 changes: 9 additions & 0 deletions include/ppx/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ struct WindowSize
WindowSize() = default;
WindowSize(uint32_t width_, uint32_t height_)
: width(width_), height(height_) {}
WindowSize(const std::pair<int, int>&& size)
: WindowSize(size.first, size.second) {}
WindowSize(const std::pair<uint32_t, uint32_t>&& size)
: WindowSize(size.first, size.second) {}

operator std::pair<uint32_t, uint32_t>()
{
return {width, height};
}

bool operator==(const WindowSize& other) const { return width == other.width && height == other.height; };
};
Expand Down
24 changes: 12 additions & 12 deletions include/ppx/xr_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ struct XrComponentCreateInfo
#else
grfx::Format colorFormat = grfx::FORMAT_B8G8R8A8_SRGB;
#endif
grfx::Format depthFormat = grfx::FORMAT_D32_FLOAT;
XrRefSpace refSpaceType = XrRefSpace::XR_STAGE;
XrViewConfigurationType viewConfigType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
bool enableDebug = false;
bool enableQuadLayer = false;
bool enableDepthSwapchain = false;
XrComponentResolution resolution = {0, 0};
XrComponentResolution uiResolution = {0, 0};
grfx::Format depthFormat = grfx::FORMAT_D32_FLOAT;
XrRefSpace refSpaceType = XrRefSpace::XR_STAGE;
XrViewConfigurationType viewConfigType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
bool enableDebug = false;
bool enableQuadLayer = false;
bool enableDepthSwapchain = false;
std::optional<XrComponentResolution> resolution = (XrComponentResolution){0, 0};
XrComponentResolution uiResolution = {0, 0};

std::vector<std::string> requiredExtensions = {};
};
Expand Down Expand Up @@ -174,16 +174,16 @@ class XrComponent
{
if (mConfigViews.empty())
return 0;
if (mCreateInfo.resolution.width > 0)
return mCreateInfo.resolution.width;
if (mCreateInfo.resolution.has_value())
return mCreateInfo.resolution->width;
return mConfigViews[0].recommendedImageRectWidth;
}
uint32_t GetHeight() const
{
if (mConfigViews.empty())
return 0;
if (mCreateInfo.resolution.height > 0)
return mCreateInfo.resolution.height;
if (mCreateInfo.resolution.has_value())
return mCreateInfo.resolution->height;
return mConfigViews[0].recommendedImageRectHeight;
}
uint32_t GetUIWidth() const
Expand Down
4 changes: 2 additions & 2 deletions projects/async_compute/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ void ProjApp::Config(ppx::ApplicationSettings& settings)
settings.appName = "async_compute";
settings.enableImGui = true;
settings.grfx.api = kApi;
settings.window.width = 1920;
settings.window.height = 1080;
settings.grfx.swapchain.imageCount = mNumFramesInFlight;
settings.grfx.device.computeQueueCount = 1;
settings.grfx.numFramesInFlight = mNumFramesInFlight;

settings.standardKnobsDefaultValue.resolution = std::make_pair(1920, 1080);
}

void ProjApp::Setup()
Expand Down
4 changes: 2 additions & 2 deletions projects/gltf/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ void ProjApp::Config(ppx::ApplicationSettings& settings)
{
settings.appName = "gltf";
settings.enableImGui = true;
settings.window.width = 1920;
settings.window.height = 1080;
settings.grfx.api = kApi;
settings.grfx.swapchain.depthFormat = grfx::FORMAT_D32_FLOAT;

settings.standardKnobsDefaultValue.resolution = std::make_pair(1920, 1080);
}

void ProjApp::LoadTexture(
Expand Down
Loading