From b5acfba487291575e04fd82cdc7a12495c585af5 Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Wed, 21 Dec 2022 15:55:47 +0100 Subject: [PATCH] LibVirtGPU: Improve append_set_framebuffer_state_no_attach() Remove hardcoded framebuffer size and add argument verification. --- .../LibVirtGPU/CommandBufferBuilder.cpp | 17 ++++++++++------- .../Libraries/LibVirtGPU/CommandBufferBuilder.h | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibVirtGPU/CommandBufferBuilder.cpp b/Userland/Libraries/LibVirtGPU/CommandBufferBuilder.cpp index 3353955db4..6fb49fdefe 100644 --- a/Userland/Libraries/LibVirtGPU/CommandBufferBuilder.cpp +++ b/Userland/Libraries/LibVirtGPU/CommandBufferBuilder.cpp @@ -15,10 +15,6 @@ namespace VirtGPU { -constexpr int DRAWTARGET_WIDTH = 500; -constexpr int DRAWTARGET_HEIGHT = 500; - - static u32 encode_command(u16 length, Protocol::ObjectType object_type, Protocol::VirGLCommand command) { u8 command_value = to_underlying(command); @@ -236,11 +232,18 @@ void CommandBufferBuilder::append_viewport(Gfx::IntSize size) builder.appendf32(0.5f); // translate_z } -void CommandBufferBuilder::append_set_framebuffer_state_no_attach() +void CommandBufferBuilder::append_set_framebuffer_state_no_attach(Gfx::IntSize size) { + VERIFY(size.width() <= NumericLimits::max()); + VERIFY(size.height() <= NumericLimits::max()); + CommandBuilder builder(m_buffer, Protocol::VirGLCommand::SET_FRAMEBUFFER_STATE_NO_ATTACH, Protocol::ObjectType::NONE); - builder.appendu32((DRAWTARGET_HEIGHT << 16) | DRAWTARGET_WIDTH); // (height << 16) | width - builder.appendu32(0); // (samples << 16) | layers + + u16 samples = 0; + u16 layers = 0; + + builder.appendu32((size.height() << 16) | size.width()); + builder.appendu32((samples << 16) | layers); } void CommandBufferBuilder::append_set_constant_buffer(Vector const& constant_buffer) diff --git a/Userland/Libraries/LibVirtGPU/CommandBufferBuilder.h b/Userland/Libraries/LibVirtGPU/CommandBufferBuilder.h index 4d7607b443..16a69c163d 100644 --- a/Userland/Libraries/LibVirtGPU/CommandBufferBuilder.h +++ b/Userland/Libraries/LibVirtGPU/CommandBufferBuilder.h @@ -31,7 +31,7 @@ public: void append_create_vertex_elements(Protocol::ObjectHandle handle); void append_bind_vertex_elements(Protocol::ObjectHandle handle); void append_viewport(Gfx::IntSize); - void append_set_framebuffer_state_no_attach(); + void append_set_framebuffer_state_no_attach(Gfx::IntSize); void append_set_constant_buffer(Vector const& constant_buffer); void append_create_shader(Protocol::ObjectHandle handle, Gallium::ShaderType shader_type, StringView shader_data); void append_bind_shader(Protocol::ObjectHandle handle, Gallium::ShaderType shader_type);