/* * Copyright (c) 2022, Stephan Unverwerth * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace VirtGPU { class Device final : public GPU::Device { public: Device(NonnullOwnPtr); static ErrorOr> create(Gfx::IntSize min_size); // FIXME: Once the kernel driver supports destroying contexts we need to add this functionality here ErrorOr initialize_context(Gfx::IntSize min_size); virtual GPU::DeviceInfo info() const override; virtual void draw_primitives(GPU::PrimitiveType, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform, Vector& vertices) override; virtual void resize(Gfx::IntSize min_size) override; virtual void clear_color(FloatVector4 const&) override; virtual void clear_depth(GPU::DepthType) override; virtual void clear_stencil(GPU::StencilType) override; virtual void blit_from_color_buffer(Gfx::Bitmap& target) override; virtual void blit_from_color_buffer(NonnullRefPtr, u32 level, Vector2 input_size, Vector2 input_offset, Vector3 output_offset) override; virtual void blit_from_color_buffer(void*, Vector2 offset, GPU::ImageDataLayout const&) override; virtual void blit_from_depth_buffer(void*, Vector2 offset, GPU::ImageDataLayout const&) override; virtual void blit_from_depth_buffer(NonnullRefPtr, u32 level, Vector2 input_size, Vector2 input_offset, Vector3 output_offset) override; virtual void blit_to_color_buffer_at_raster_position(void const*, GPU::ImageDataLayout const&) override; virtual void blit_to_depth_buffer_at_raster_position(void const*, GPU::ImageDataLayout const&) override; virtual void set_options(GPU::RasterizerOptions const&) override; virtual void set_light_model_params(GPU::LightModelParameters const&) override; virtual GPU::RasterizerOptions options() const override; virtual GPU::LightModelParameters light_model() const override; virtual NonnullRefPtr create_image(GPU::PixelFormat const&, u32 width, u32 height, u32 depth, u32 max_levels) override; virtual ErrorOr> create_shader(GPU::IR::Shader const&) override; virtual void set_sampler_config(unsigned, GPU::SamplerConfig const&) override; virtual void set_light_state(unsigned, GPU::Light const&) override; virtual void set_material_state(GPU::Face, GPU::Material const&) override; virtual void set_stencil_configuration(GPU::Face, GPU::StencilConfiguration const&) override; virtual void set_texture_unit_configuration(GPU::TextureUnitIndex, GPU::TextureUnitConfiguration const&) override; virtual void set_clip_planes(Vector const&) override; virtual GPU::RasterPosition raster_position() const override; virtual void set_raster_position(GPU::RasterPosition const& raster_position) override; virtual void set_raster_position(FloatVector4 const& position, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform) override; virtual void bind_fragment_shader(RefPtr) override; private: void encode_constant_buffer(Gfx::FloatMatrix4x4 const&, Vector&); Protocol::ObjectHandle allocate_handle(); ErrorOr create_virgl_resource(VirGL3DResourceSpec&); ErrorOr upload_command_buffer(Vector const&); NonnullOwnPtr m_gpu_file; Protocol::ResourceID m_vbo_resource_id { 0 }; Protocol::ResourceID m_drawtarget { 0 }; Protocol::ResourceID m_depthbuffer_surface { 0 }; Protocol::ObjectHandle m_blend_handle { 0 }; Protocol::ObjectHandle m_drawtarget_surface_handle { 0 }; Protocol::ObjectHandle m_depthbuffer_surface_handle { 0 }; Protocol::ObjectHandle m_ve_handle { 0 }; Protocol::ObjectHandle m_frag_shader_handle { 0 }; Protocol::ObjectHandle m_vert_shader_handle { 0 }; Protocol::ObjectHandle m_rasterizer_handle { 0 }; Protocol::ObjectHandle m_dsa_handle { 0 }; u32 m_last_allocated_handle { 0 }; struct VertexData { float r; float g; float b; float x; float y; float z; }; Vector m_vertices; Vector m_constant_buffer_data; }; }