Skip to content

Commit

Permalink
LibVirtGPU: Make BindTarget an enum and move it into VirtGPU::Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
sunverwerth authored and awesomekling committed Dec 26, 2022
1 parent 51ac0d7 commit ce57174
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
28 changes: 14 additions & 14 deletions Userland/Libraries/LibVirtGPU/CommandBufferBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void CommandBufferBuilder::append_set_tweaks(u32 id, u32 value)
builder.appendu32(value);
}

void CommandBufferBuilder::append_transfer3d(ResourceID resource, size_t width, size_t height, size_t depth, size_t direction)
void CommandBufferBuilder::append_transfer3d(Protocol::ResourceID resource, size_t width, size_t height, size_t depth, size_t direction)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::TRANSFER3D, 0);
builder.appendu32(resource.value()); // res_handle
Expand Down Expand Up @@ -158,15 +158,15 @@ void CommandBufferBuilder::append_gl_clear(float r, float g, float b)
builder.appendu32(0); // Stencil
}

void CommandBufferBuilder::append_set_vertex_buffers(u32 stride, u32 offset, ResourceID resource)
void CommandBufferBuilder::append_set_vertex_buffers(u32 stride, u32 offset, Protocol::ResourceID resource)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::SET_VERTEX_BUFFERS, 0);
builder.appendu32(stride);
builder.appendu32(offset);
builder.appendu32(resource.value());
}

void CommandBufferBuilder::append_create_blend(ObjectHandle handle)
void CommandBufferBuilder::append_create_blend(Protocol::ObjectHandle handle)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::CREATE_OBJECT, to_underlying(Protocol::ObjectType::BLEND));
builder.appendu32(handle.value());
Expand All @@ -178,13 +178,13 @@ void CommandBufferBuilder::append_create_blend(ObjectHandle handle)
}
}

void CommandBufferBuilder::append_bind_blend(ObjectHandle handle)
void CommandBufferBuilder::append_bind_blend(Protocol::ObjectHandle handle)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::BIND_OBJECT, to_underlying(Protocol::ObjectType::BLEND));
builder.appendu32(handle.value()); // VIRGL_OBJ_BIND_HANDLE
}

void CommandBufferBuilder::append_create_vertex_elements(ObjectHandle handle)
void CommandBufferBuilder::append_create_vertex_elements(Protocol::ObjectHandle handle)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::CREATE_OBJECT, to_underlying(Protocol::ObjectType::VERTEX_ELEMENTS));
builder.appendu32(handle.value());
Expand All @@ -198,13 +198,13 @@ void CommandBufferBuilder::append_create_vertex_elements(ObjectHandle handle)
builder.appendu32(30); // src_format_1 (PIPE_FORMAT_R32G32B32_FLOAT = 30)
}

void CommandBufferBuilder::append_bind_vertex_elements(ObjectHandle handle)
void CommandBufferBuilder::append_bind_vertex_elements(Protocol::ObjectHandle handle)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::BIND_OBJECT, to_underlying(Protocol::ObjectType::VERTEX_ELEMENTS));
builder.appendu32(handle.value()); // VIRGL_OBJ_BIND_HANDLE
}

void CommandBufferBuilder::append_create_surface(ResourceID drawtarget_resource, ObjectHandle drawtarget_handle, Protocol::TextureFormat format)
void CommandBufferBuilder::append_create_surface(Protocol::ResourceID drawtarget_resource, Protocol::ObjectHandle drawtarget_handle, Protocol::TextureFormat format)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::CREATE_OBJECT, to_underlying(Protocol::ObjectType::SURFACE));
builder.appendu32(drawtarget_handle.value());
Expand All @@ -214,7 +214,7 @@ void CommandBufferBuilder::append_create_surface(ResourceID drawtarget_resource,
builder.appendu32(0); // Last element / Texture Element
}

void CommandBufferBuilder::append_set_framebuffer_state(ObjectHandle drawtarget, ObjectHandle depthbuffer)
void CommandBufferBuilder::append_set_framebuffer_state(Protocol::ObjectHandle drawtarget, Protocol::ObjectHandle depthbuffer)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::SET_FRAMEBUFFER_STATE, 0);
builder.appendu32(1); // nr_cbufs
Expand Down Expand Up @@ -251,7 +251,7 @@ void CommandBufferBuilder::append_set_constant_buffer(Vector<float> const& const
}
}

void CommandBufferBuilder::append_create_shader(ObjectHandle handle, Gallium::ShaderType shader_type, StringView shader_data)
void CommandBufferBuilder::append_create_shader(Protocol::ObjectHandle handle, Gallium::ShaderType shader_type, StringView shader_data)
{
size_t shader_len = shader_data.length() + 1; // Need to remember to copy null terminator as well if needed
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::CREATE_OBJECT, to_underlying(Protocol::ObjectType::SHADER));
Expand All @@ -263,14 +263,14 @@ void CommandBufferBuilder::append_create_shader(ObjectHandle handle, Gallium::Sh
builder.append_string_null_padded(shader_data);
}

void CommandBufferBuilder::append_bind_shader(ObjectHandle handle, Gallium::ShaderType shader_type)
void CommandBufferBuilder::append_bind_shader(Protocol::ObjectHandle handle, Gallium::ShaderType shader_type)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::BIND_SHADER, 0);
builder.appendu32(handle.value()); // VIRGL_OBJ_BIND_HANDLE
builder.appendu32(to_underlying(shader_type));
}

void CommandBufferBuilder::append_create_rasterizer(ObjectHandle handle)
void CommandBufferBuilder::append_create_rasterizer(Protocol::ObjectHandle handle)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::CREATE_OBJECT, to_underlying(Protocol::ObjectType::RASTERIZER));
builder.appendu32(handle.value()); // Handle
Expand All @@ -284,13 +284,13 @@ void CommandBufferBuilder::append_create_rasterizer(ObjectHandle handle)
builder.appendf32(0.0); // Offset clamp
}

void CommandBufferBuilder::append_bind_rasterizer(ObjectHandle handle)
void CommandBufferBuilder::append_bind_rasterizer(Protocol::ObjectHandle handle)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::BIND_OBJECT, to_underlying(Protocol::ObjectType::RASTERIZER));
builder.appendu32(handle.value()); // VIRGL_OBJ_BIND_HANDLE
}

void CommandBufferBuilder::append_create_dsa(ObjectHandle handle)
void CommandBufferBuilder::append_create_dsa(Protocol::ObjectHandle handle)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::CREATE_OBJECT, to_underlying(Protocol::ObjectType::DSA));
builder.appendu32(handle.value()); // Handle
Expand All @@ -300,7 +300,7 @@ void CommandBufferBuilder::append_create_dsa(ObjectHandle handle)
builder.appendf32(1.0); // Alpha Ref
}

void CommandBufferBuilder::append_bind_dsa(ObjectHandle handle)
void CommandBufferBuilder::append_bind_dsa(Protocol::ObjectHandle handle)
{
CommandBuilder builder(m_buffer, Protocol::VirGLCommand::BIND_OBJECT, to_underlying(Protocol::ObjectType::DSA));
builder.appendu32(handle.value()); // VIRGL_OBJ_BIND_HANDLE
Expand Down
28 changes: 14 additions & 14 deletions Userland/Libraries/LibVirtGPU/CommandBufferBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ namespace VirtGPU {
class CommandBufferBuilder {
public:
void append_set_tweaks(u32 id, u32 value);
void append_transfer3d(ResourceID resource, size_t width, size_t height = 1, size_t depth = 1, size_t direction = VIRGL_DATA_DIR_GUEST_TO_HOST);
void append_transfer3d(Protocol::ResourceID resource, size_t width, size_t height = 1, size_t depth = 1, size_t direction = VIRGL_DATA_DIR_GUEST_TO_HOST);
void append_end_transfers_3d();
void append_draw_vbo(u32 count);
void append_gl_clear(float r, float g, float b);
void append_set_vertex_buffers(u32 stride, u32 offset, ResourceID resource);
void append_create_blend(ObjectHandle handle);
void append_bind_blend(ObjectHandle handle);
void append_create_surface(ResourceID drawtarget_resource, ObjectHandle drawtarget_handle, Protocol::TextureFormat format);
void append_set_framebuffer_state(ObjectHandle drawtarget, ObjectHandle depthbuffer = 0);
void append_create_vertex_elements(ObjectHandle handle);
void append_bind_vertex_elements(ObjectHandle handle);
void append_set_vertex_buffers(u32 stride, u32 offset, Protocol::ResourceID resource);
void append_create_blend(Protocol::ObjectHandle handle);
void append_bind_blend(Protocol::ObjectHandle handle);
void append_create_surface(Protocol::ResourceID drawtarget_resource, Protocol::ObjectHandle drawtarget_handle, Protocol::TextureFormat format);
void append_set_framebuffer_state(Protocol::ObjectHandle drawtarget, Protocol::ObjectHandle depthbuffer = 0);
void append_create_vertex_elements(Protocol::ObjectHandle handle);
void append_bind_vertex_elements(Protocol::ObjectHandle handle);
void append_gl_viewport();
void append_set_framebuffer_state_no_attach();
void append_set_constant_buffer(Vector<float> const& constant_buffer);
void append_create_shader(ObjectHandle handle, Gallium::ShaderType shader_type, StringView shader_data);
void append_bind_shader(ObjectHandle handle, Gallium::ShaderType shader_type);
void append_create_rasterizer(ObjectHandle handle);
void append_bind_rasterizer(ObjectHandle handle);
void append_create_dsa(ObjectHandle handle);
void append_bind_dsa(ObjectHandle handle);
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);
void append_create_rasterizer(Protocol::ObjectHandle handle);
void append_bind_rasterizer(Protocol::ObjectHandle handle);
void append_create_dsa(Protocol::ObjectHandle handle);
void append_bind_dsa(Protocol::ObjectHandle handle);
Vector<u32> const& build() { return m_buffer; }

private:
Expand Down
38 changes: 20 additions & 18 deletions Userland/Libraries/LibVirtGPU/VirGLProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@

namespace VirtGPU {

namespace Protocol {

AK_TYPEDEF_DISTINCT_ORDERED_ID(u32, ObjectHandle);
AK_TYPEDEF_DISTINCT_ORDERED_ID(u32, ResourceID);

#define VIRGL_BIND_DEPTH_STENCIL (1 << 0)
#define VIRGL_BIND_RENDER_TARGET (1 << 1)
#define VIRGL_BIND_SAMPLER_VIEW (1 << 3)
#define VIRGL_BIND_VERTEX_BUFFER (1 << 4)
#define VIRGL_BIND_INDEX_BUFFER (1 << 5)
#define VIRGL_BIND_CONSTANT_BUFFER (1 << 6)
#define VIRGL_BIND_DISPLAY_TARGET (1 << 7)
#define VIRGL_BIND_COMMAND_ARGS (1 << 8)
#define VIRGL_BIND_STREAM_OUTPUT (1 << 11)
#define VIRGL_BIND_SHADER_BUFFER (1 << 14)
#define VIRGL_BIND_QUERY_BUFFER (1 << 15)
#define VIRGL_BIND_CURSOR (1 << 16)
#define VIRGL_BIND_CUSTOM (1 << 17)
#define VIRGL_BIND_SCANOUT (1 << 18)
#define VIRGL_BIND_STAGING (1 << 19)
#define VIRGL_BIND_SHARED (1 << 20)

namespace Protocol {
enum class BindTarget : u32 {
VIRGL_BIND_DEPTH_STENCIL = (1 << 0),
VIRGL_BIND_RENDER_TARGET = (1 << 1),
VIRGL_BIND_SAMPLER_VIEW = (1 << 3),
VIRGL_BIND_VERTEX_BUFFER = (1 << 4),
VIRGL_BIND_INDEX_BUFFER = (1 << 5),
VIRGL_BIND_CONSTANT_BUFFER = (1 << 6),
VIRGL_BIND_DISPLAY_TARGET = (1 << 7),
VIRGL_BIND_COMMAND_ARGS = (1 << 8),
VIRGL_BIND_STREAM_OUTPUT = (1 << 11),
VIRGL_BIND_SHADER_BUFFER = (1 << 14),
VIRGL_BIND_QUERY_BUFFER = (1 << 15),
VIRGL_BIND_CURSOR = (1 << 16),
VIRGL_BIND_CUSTOM = (1 << 17),
VIRGL_BIND_SCANOUT = (1 << 18),
VIRGL_BIND_STAGING = (1 << 19),
VIRGL_BIND_SHARED = (1 << 20),
};

enum class TextureFormat : u32 {
// RGBA Formats
Expand Down

0 comments on commit ce57174

Please sign in to comment.