Skip to content
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

Fix crash when window cannot be opened with same resolution #1568

Merged
merged 2 commits into from
Jan 21, 2025
Merged
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
5 changes: 5 additions & 0 deletions framework/application/android_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ std::string AndroidWindow::GetWsiExtension() const
return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
}

VkExtent2D AndroidWindow::GetSize() const
{
return { width_, height_ };
}

VkResult AndroidWindow::CreateSurface(const encode::VulkanInstanceTable* table,
VkInstance instance,
VkFlags flags,
Expand Down
2 changes: 2 additions & 0 deletions framework/application/android_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class AndroidWindow : public decode::Window

virtual std::string GetWsiExtension() const override;

virtual VkExtent2D GetSize() const override;

virtual VkResult CreateSurface(const encode::VulkanInstanceTable* table,
VkInstance instance,
VkFlags flags,
Expand Down
16 changes: 15 additions & 1 deletion framework/application/display_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(application)

DisplayWindow::DisplayWindow(DisplayContext* display_context) : display_context_(display_context)
DisplayWindow::DisplayWindow(DisplayContext* display_context) : display_context_(display_context), width_(0), height_(0)
{
assert(display_context_ != nullptr);
}
Expand Down Expand Up @@ -195,11 +195,22 @@ VkResult DisplayWindow::SelectPlane(const encode::VulkanInstanceTable* table,
return VK_ERROR_INITIALIZATION_FAILED;
}

void DisplayWindow::SetSize(const uint32_t width, const uint32_t height)
{
width_ = width;
height_ = height;
}

std::string DisplayWindow::GetWsiExtension() const
{
return VK_KHR_DISPLAY_EXTENSION_NAME;
}

VkExtent2D DisplayWindow::GetSize() const
{
return { width_, height_ };
}

VkResult DisplayWindow::CreateSurface(const encode::VulkanInstanceTable* table,
VkInstance instance,
VkFlags flags,
Expand Down Expand Up @@ -241,6 +252,9 @@ VkResult DisplayWindow::CreateSurface(const encode::VulkanInstanceTable* table,
return error;
}

width_ = mode_props.parameters.visibleRegion.width;
height_ = mode_props.parameters.visibleRegion.height;

VkExtent2D image_extent;
image_extent.width = mode_props.parameters.visibleRegion.width;
image_extent.height = mode_props.parameters.visibleRegion.height;
Expand Down
9 changes: 7 additions & 2 deletions framework/application/display_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class DisplayWindow : public decode::Window

virtual void SetPosition(const int32_t, const int32_t) override {}

virtual void SetSize(const uint32_t, const uint32_t) override{};
virtual void SetSize(const uint32_t width, const uint32_t height) override;

virtual void SetSizePreTransform(const uint32_t, const uint32_t, const uint32_t) override{};
virtual void SetSizePreTransform(const uint32_t, const uint32_t, const uint32_t) override {}

virtual void SetVisibility(bool) override {}

Expand All @@ -67,6 +67,8 @@ class DisplayWindow : public decode::Window

virtual std::string GetWsiExtension() const override;

virtual VkExtent2D GetSize() const override;

virtual VkResult CreateSurface(const encode::VulkanInstanceTable* table,
VkInstance instance,
VkFlags flags,
Expand Down Expand Up @@ -94,6 +96,9 @@ class DisplayWindow : public decode::Window

private:
DisplayContext* display_context_;

uint32_t width_;
uint32_t height_;
};

class DisplayWindowFactory : public decode::WindowFactory
Expand Down
18 changes: 12 additions & 6 deletions framework/application/headless_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ bool HeadlessWindow::Create(const std::string& title,
GFXRECON_UNREFERENCED_PARAMETER(title);
GFXRECON_UNREFERENCED_PARAMETER(xpos);
GFXRECON_UNREFERENCED_PARAMETER(ypos);
GFXRECON_UNREFERENCED_PARAMETER(width);
GFXRECON_UNREFERENCED_PARAMETER(height);
GFXRECON_UNREFERENCED_PARAMETER(force_windowed);

width_ = width;
height_ = height;

return true;
}

Expand All @@ -72,14 +73,14 @@ void HeadlessWindow::SetPosition(const int32_t x, const int32_t y)

void HeadlessWindow::SetSize(const uint32_t width, const uint32_t height)
{
GFXRECON_UNREFERENCED_PARAMETER(width);
GFXRECON_UNREFERENCED_PARAMETER(height);
width_ = width;
height_ = height;
}

void HeadlessWindow::SetSizePreTransform(const uint32_t width, const uint32_t height, const uint32_t pre_transform)
{
GFXRECON_UNREFERENCED_PARAMETER(width);
GFXRECON_UNREFERENCED_PARAMETER(height);
width_ = width;
height_ = height;
GFXRECON_UNREFERENCED_PARAMETER(pre_transform);
}

Expand All @@ -102,6 +103,11 @@ std::string HeadlessWindow::GetWsiExtension() const
return VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME;
}

VkExtent2D HeadlessWindow::GetSize() const
{
return { width_, height_ };
}

VkResult HeadlessWindow::CreateSurface(const encode::VulkanInstanceTable* table,
VkInstance instance,
VkFlags flags,
Expand Down
5 changes: 5 additions & 0 deletions framework/application/headless_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class HeadlessWindow : public decode::Window

virtual std::string GetWsiExtension() const override;

virtual VkExtent2D GetSize() const override;

virtual VkResult CreateSurface(const encode::VulkanInstanceTable* table,
VkInstance instance,
VkFlags flags,
Expand All @@ -75,6 +77,9 @@ class HeadlessWindow : public decode::Window

private:
HeadlessContext* headless_context_;

uint32_t width_;
uint32_t height_;
};

class HeadlessWindowFactory : public decode::WindowFactory
Expand Down
22 changes: 14 additions & 8 deletions framework/application/metal_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ GFXRECON_BEGIN_NAMESPACE(application)
class MetalContext;
class MetalWindow : public decode::Window
{
public:
public:
MetalWindow(MetalContext* metal_context);

~MetalWindow() override;
Expand Down Expand Up @@ -66,6 +66,8 @@ class MetalWindow : public decode::Window

std::string GetWsiExtension() const override;

VkExtent2D GetSize() const override;

VkResult CreateSurface(const encode::VulkanInstanceTable* table,
VkInstance instance,
VkFlags flags,
Expand All @@ -75,21 +77,25 @@ class MetalWindow : public decode::Window

private:
GFXReconWindowDelegate* window_delegate_;
MetalContext* metal_context_;
NSWindow* window_;
CAMetalLayer* layer_;
uint32_t width_;
uint32_t height_;
MetalContext* metal_context_;
NSWindow* window_;
CAMetalLayer* layer_;
uint32_t width_;
uint32_t height_;
};

class MetalWindowFactory : public decode::WindowFactory
{
public:
public:
MetalWindowFactory(MetalContext* metal_context);

const char* GetSurfaceExtensionName() const override { return VK_EXT_METAL_SURFACE_EXTENSION_NAME; }

decode::Window* Create(const int32_t x, const int32_t y, const uint32_t width, const uint32_t height, bool force_windowed = false) override;
decode::Window* Create(const int32_t x,
const int32_t y,
const uint32_t width,
const uint32_t height,
bool force_windowed = false) override;

void Destroy(decode::Window* window) override;

Expand Down
Loading
Loading