summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSoftGPU/ISA.h
blob: 4f34cfae1d83128afa489278e1734f4180234cba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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;
};

}