mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 05:54:58 +00:00
LibSoftGPU: Define a simple shader instruction set
This adds a simple instruction set with basic operations and adds an instruction list to the shader class.
This commit is contained in:
parent
bb28492af0
commit
1e548a84d6
4 changed files with 74 additions and 3 deletions
|
@ -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)
|
||||
|
|
63
Userland/Libraries/LibSoftGPU/ISA.h
Normal file
63
Userland/Libraries/LibSoftGPU/ISA.h
Normal file
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue