diff options
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Device.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/ISA.h | 63 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Shader.cpp | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Shader.h | 9 |
4 files changed, 74 insertions, 3 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index e971ad01a7..356b078bbe 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -1638,7 +1638,7 @@ NonnullRefPtr<GPU::Image> Device::create_image(GPU::PixelFormat const& pixel_for ErrorOr<NonnullRefPtr<GPU::Shader>> Device::create_shader(GPU::IR::Shader const&) { - return adopt_ref(*new Shader(this)); + return adopt_ref(*new Shader(this, {})); } void Device::set_sampler_config(unsigned sampler, GPU::SamplerConfig const& config) diff --git a/Userland/Libraries/LibSoftGPU/ISA.h b/Userland/Libraries/LibSoftGPU/ISA.h new file mode 100644 index 0000000000..4f34cfae1d --- /dev/null +++ b/Userland/Libraries/LibSoftGPU/ISA.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022, Stephan Unverwerth <s.unverwerth@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Types.h> + +namespace SoftGPU { + +constexpr u8 swizzle_pattern(u8 a, u8 b, u8 c, u8 d) +{ + return a | (b << 2) | (c << 4) | (d << 6); +} + +constexpr u8 swizzle_index(u8 pattern, u8 element) +{ + return (pattern & (3 << (element * 2))) >> (element * 2); +} + +enum class Opcode : u8 { + Input, + Output, + Sample2D, + Swizzle, + Add, + Sub, + Mul, + Div, +}; + +struct Instruction final { + union Arguments { + struct { + u16 target_register; + u8 input_index; + } input; + struct { + u16 source_register; + u8 output_index; + } output; + struct { + u16 target_register; + u16 coordinates_register; + u8 sampler_index; + } sample; + struct { + u16 target_register; + u16 source_register; + u8 pattern; + } swizzle; + struct { + u16 target_register; + u16 source_register1; + u16 source_register2; + } binop; + } arguments; + Opcode operation; +}; + +} diff --git a/Userland/Libraries/LibSoftGPU/Shader.cpp b/Userland/Libraries/LibSoftGPU/Shader.cpp index 44bb9635ea..ae68fcfd22 100644 --- a/Userland/Libraries/LibSoftGPU/Shader.cpp +++ b/Userland/Libraries/LibSoftGPU/Shader.cpp @@ -8,8 +8,9 @@ namespace SoftGPU { -Shader::Shader(void const* ownership_token) +Shader::Shader(void const* ownership_token, Vector<Instruction> const& instructions) : GPU::Shader(ownership_token) + , m_instructions(instructions) { } diff --git a/Userland/Libraries/LibSoftGPU/Shader.h b/Userland/Libraries/LibSoftGPU/Shader.h index 7c6b899d05..e75c094d46 100644 --- a/Userland/Libraries/LibSoftGPU/Shader.h +++ b/Userland/Libraries/LibSoftGPU/Shader.h @@ -6,13 +6,20 @@ #pragma once +#include <AK/Vector.h> #include <LibGPU/Shader.h> +#include <LibSoftGPU/ISA.h> namespace SoftGPU { class Shader final : public GPU::Shader { public: - Shader(void const* ownership_token); + Shader(void const* ownership_token, Vector<Instruction> const&); + + Vector<Instruction> const& instructions() const { return m_instructions; } + +private: + Vector<Instruction> m_instructions; }; } |