2019-04-22 04:41:09 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Connor Abbott <cwabbott0@gmail.com>
|
|
|
|
* Copyright (C) 2019 Lyude Paul <thatslyude@gmail.com>
|
|
|
|
* Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __bifrost_h__
|
|
|
|
#define __bifrost_h__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
2020-04-30 08:29:10 +01:00
|
|
|
#define BIFROST_DBG_MSGS 0x0001
|
|
|
|
#define BIFROST_DBG_SHADERS 0x0002
|
|
|
|
|
|
|
|
extern int bifrost_debug;
|
|
|
|
|
2020-10-02 19:02:25 +01:00
|
|
|
enum bifrost_message_type {
|
|
|
|
BIFROST_MESSAGE_NONE = 0,
|
|
|
|
BIFROST_MESSAGE_VARYING = 1,
|
|
|
|
BIFROST_MESSAGE_ATTRIBUTE = 2,
|
|
|
|
BIFROST_MESSAGE_TEX = 3,
|
|
|
|
BIFROST_MESSAGE_VARTEX = 4,
|
|
|
|
BIFROST_MESSAGE_LOAD = 5,
|
|
|
|
BIFROST_MESSAGE_STORE = 6,
|
|
|
|
BIFROST_MESSAGE_ATOMIC = 7,
|
|
|
|
BIFROST_MESSAGE_BARRIER = 8,
|
|
|
|
BIFROST_MESSAGE_BLEND = 9,
|
|
|
|
BIFROST_MESSAGE_TILE = 10,
|
2020-10-02 18:57:59 +01:00
|
|
|
/* type 11 reserved */
|
2020-10-02 19:02:25 +01:00
|
|
|
BIFROST_MESSAGE_Z_STENCIL = 12,
|
|
|
|
BIFROST_MESSAGE_ATEST = 13,
|
|
|
|
BIFROST_MESSAGE_JOB = 14,
|
|
|
|
BIFROST_MESSAGE_64BIT = 15
|
2020-03-18 17:23:00 +00:00
|
|
|
};
|
|
|
|
|
2020-10-02 18:23:33 +01:00
|
|
|
enum bifrost_ftz {
|
|
|
|
BIFROST_FTZ_DISABLE = 0,
|
|
|
|
BIFROST_FTZ_DX11 = 1,
|
|
|
|
BIFROST_FTZ_ALWAYS = 2,
|
|
|
|
BIFROST_FTZ_ABRUPT = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
enum bifrost_exceptions {
|
|
|
|
BIFROST_EXCEPTIONS_ENABLED = 0,
|
|
|
|
BIFROST_EXCEPTIONS_DISABLED = 1,
|
|
|
|
BIFROST_EXCEPTIONS_PRECISE_DIVISION = 2,
|
|
|
|
BIFROST_EXCEPTIONS_PRECISE_SQRT = 3,
|
|
|
|
};
|
|
|
|
|
2019-04-22 04:41:09 +01:00
|
|
|
struct bifrost_header {
|
2020-10-02 18:23:33 +01:00
|
|
|
/* Reserved */
|
|
|
|
unsigned zero1 : 5;
|
|
|
|
|
|
|
|
/* Flush-to-zero mode, leave zero for GL */
|
|
|
|
enum bifrost_ftz flush_to_zero : 2;
|
|
|
|
|
|
|
|
/* Convert any infinite result of any floating-point operation to the
|
|
|
|
* biggest representable number */
|
2019-04-22 04:41:09 +01:00
|
|
|
unsigned suppress_inf: 1;
|
2020-10-02 18:23:33 +01:00
|
|
|
|
|
|
|
/* Convert NaN to +0.0 */
|
2019-04-22 04:41:09 +01:00
|
|
|
unsigned suppress_nan : 1;
|
2020-10-02 18:23:33 +01:00
|
|
|
|
|
|
|
/* Floating-point excception handling mode */
|
|
|
|
enum bifrost_exceptions float_exceptions : 2;
|
|
|
|
|
2019-04-22 04:41:09 +01:00
|
|
|
// true if the execution mask of the next clause is the same as the mask of
|
|
|
|
// the current clause.
|
|
|
|
unsigned back_to_back : 1;
|
|
|
|
unsigned no_end_of_shader: 1;
|
|
|
|
unsigned unk2 : 2;
|
2020-10-02 18:27:15 +01:00
|
|
|
|
|
|
|
/* Terminate discarded threads, rather than continuing execution. Set
|
|
|
|
* for fragment shaders for standard GL behaviour of DISCARD. */
|
|
|
|
unsigned terminate_discarded_threads : 1;
|
|
|
|
|
2020-10-02 18:46:35 +01:00
|
|
|
/* If set, the hardware may prefetch the next clause. If false, the
|
|
|
|
* hardware may not. Clear for unconditional branches. */
|
|
|
|
unsigned next_clause_prefetch : 1;
|
|
|
|
|
2020-10-02 18:53:03 +01:00
|
|
|
/* If set, a barrier will be inserted after the clause waiting for all
|
|
|
|
* message passing instructions to read their staging registers, such
|
|
|
|
* that it is safe for the next clause to write them. */
|
|
|
|
unsigned staging_barrier: 1;
|
|
|
|
unsigned staging_register : 6;
|
2019-04-22 04:41:09 +01:00
|
|
|
unsigned scoreboard_deps: 8;
|
|
|
|
unsigned scoreboard_index: 3;
|
2020-10-02 19:02:25 +01:00
|
|
|
enum bifrost_message_type message_type : 5;
|
|
|
|
enum bifrost_message_type next_message_type : 5;
|
2020-03-18 02:42:54 +00:00
|
|
|
} __attribute__((packed));
|
2019-04-22 04:41:09 +01:00
|
|
|
|
2020-03-18 13:57:32 +00:00
|
|
|
enum bifrost_packed_src {
|
|
|
|
BIFROST_SRC_PORT0 = 0,
|
|
|
|
BIFROST_SRC_PORT1 = 1,
|
2020-09-20 21:24:04 +01:00
|
|
|
BIFROST_SRC_PORT2 = 2,
|
2020-03-18 13:57:32 +00:00
|
|
|
BIFROST_SRC_STAGE = 3,
|
|
|
|
BIFROST_SRC_CONST_LO = 4,
|
|
|
|
BIFROST_SRC_CONST_HI = 5,
|
|
|
|
BIFROST_SRC_PASS_FMA = 6,
|
|
|
|
BIFROST_SRC_PASS_ADD = 7,
|
|
|
|
};
|
|
|
|
|
2019-04-22 04:41:09 +01:00
|
|
|
struct bifrost_fma_inst {
|
|
|
|
unsigned src0 : 3;
|
|
|
|
unsigned op : 20;
|
2020-03-18 02:42:54 +00:00
|
|
|
} __attribute__((packed));
|
2019-04-22 04:41:09 +01:00
|
|
|
|
|
|
|
struct bifrost_add_inst {
|
|
|
|
unsigned src0 : 3;
|
|
|
|
unsigned op : 17;
|
2020-03-18 02:42:54 +00:00
|
|
|
} __attribute__((packed));
|
2019-04-22 04:41:09 +01:00
|
|
|
|
2020-03-02 21:42:36 +00:00
|
|
|
enum bifrost_outmod {
|
|
|
|
BIFROST_NONE = 0x0,
|
|
|
|
BIFROST_POS = 0x1,
|
|
|
|
BIFROST_SAT_SIGNED = 0x2,
|
|
|
|
BIFROST_SAT = 0x3,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum bifrost_roundmode {
|
2020-03-03 20:39:04 +00:00
|
|
|
BIFROST_RTE = 0x0, /* round to even */
|
|
|
|
BIFROST_RTP = 0x1, /* round to positive */
|
|
|
|
BIFROST_RTN = 0x2, /* round to negative */
|
|
|
|
BIFROST_RTZ = 0x3 /* round to zero */
|
2020-03-02 21:42:36 +00:00
|
|
|
};
|
|
|
|
|
2020-03-03 20:39:04 +00:00
|
|
|
/* NONE: Same as fmax() and fmin() -- return the other
|
|
|
|
* number if any number is NaN. Also always return +0 if
|
|
|
|
* one argument is +0 and the other is -0.
|
|
|
|
*
|
|
|
|
* NAN_WINS: Instead of never returning a NaN, always return
|
|
|
|
* one. The "greater"/"lesser" NaN is always returned, first
|
|
|
|
* by checking the sign and then the mantissa bits.
|
|
|
|
*
|
|
|
|
* SRC1_WINS: For max, implement src0 > src1 ? src0 : src1.
|
|
|
|
* For min, implement src0 < src1 ? src0 : src1. This
|
|
|
|
* includes handling NaN's and signedness of 0 differently
|
|
|
|
* from above, since +0 and -0 compare equal and comparisons
|
|
|
|
* always return false for NaN's. As a result, this mode is
|
|
|
|
* *not* commutative.
|
|
|
|
*
|
|
|
|
* SRC0_WINS: For max, implement src0 < src1 ? src1 : src0
|
|
|
|
* For min, implement src0 > src1 ? src1 : src0
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-03-03 01:51:03 +00:00
|
|
|
enum bifrost_minmax_mode {
|
|
|
|
BIFROST_MINMAX_NONE = 0x0,
|
|
|
|
BIFROST_NAN_WINS = 0x1,
|
|
|
|
BIFROST_SRC1_WINS = 0x2,
|
|
|
|
BIFROST_SRC0_WINS = 0x3,
|
|
|
|
};
|
|
|
|
|
2020-03-03 02:45:47 +00:00
|
|
|
enum bifrost_interp_mode {
|
|
|
|
BIFROST_INTERP_PER_FRAG = 0x0,
|
|
|
|
BIFROST_INTERP_CENTROID = 0x1,
|
|
|
|
BIFROST_INTERP_DEFAULT = 0x2,
|
|
|
|
BIFROST_INTERP_EXPLICIT = 0x3
|
|
|
|
};
|
|
|
|
|
2020-05-01 19:55:04 +01:00
|
|
|
/* Fixed location for gl_FragCoord.zw */
|
|
|
|
#define BIFROST_FRAGZ (23)
|
|
|
|
#define BIFROST_FRAGW (22)
|
|
|
|
|
2020-03-02 21:45:15 +00:00
|
|
|
enum branch_bit_size {
|
|
|
|
BR_SIZE_32 = 0,
|
|
|
|
BR_SIZE_16XX = 1,
|
|
|
|
BR_SIZE_16YY = 2,
|
|
|
|
// For the above combinations of bitsize and location, an extra bit is
|
|
|
|
// encoded via comparing the sources. The only possible source of ambiguity
|
|
|
|
// would be if the sources were the same, but then the branch condition
|
|
|
|
// would be always true or always false anyways, so we can ignore it. But
|
|
|
|
// this no longer works when comparing the y component to the x component,
|
|
|
|
// since it's valid to compare the y component of a source against its own
|
|
|
|
// x component. Instead, the extra bit is encoded via an extra bitsize.
|
|
|
|
BR_SIZE_16YX0 = 3,
|
|
|
|
BR_SIZE_16YX1 = 4,
|
|
|
|
BR_SIZE_32_AND_16X = 5,
|
|
|
|
BR_SIZE_32_AND_16Y = 6,
|
|
|
|
// Used for comparisons with zero and always-true, see below. I think this
|
|
|
|
// only works for integer comparisons.
|
|
|
|
BR_SIZE_ZERO = 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bifrost_regs {
|
|
|
|
unsigned uniform_const : 8;
|
|
|
|
unsigned reg3 : 6;
|
2020-09-20 14:53:14 +01:00
|
|
|
unsigned reg2 : 6;
|
2020-03-02 21:45:15 +00:00
|
|
|
unsigned reg0 : 5;
|
|
|
|
unsigned reg1 : 6;
|
|
|
|
unsigned ctrl : 4;
|
2020-03-18 02:42:54 +00:00
|
|
|
} __attribute__((packed));
|
2020-03-02 21:45:15 +00:00
|
|
|
|
2020-03-03 00:30:11 +00:00
|
|
|
enum bifrost_branch_cond {
|
|
|
|
BR_COND_LT = 0,
|
|
|
|
BR_COND_LE = 1,
|
|
|
|
BR_COND_GE = 2,
|
|
|
|
BR_COND_GT = 3,
|
|
|
|
// Equal vs. not-equal determined by src0/src1 comparison
|
|
|
|
BR_COND_EQ = 4,
|
|
|
|
// floating-point comparisons
|
|
|
|
// Becomes UNE when you flip the arguments
|
|
|
|
BR_COND_OEQ = 5,
|
|
|
|
// TODO what happens when you flip the arguments?
|
|
|
|
BR_COND_OGT = 6,
|
|
|
|
BR_COND_OLT = 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum bifrost_branch_code {
|
|
|
|
BR_ALWAYS = 63,
|
|
|
|
};
|
|
|
|
|
2020-05-28 17:39:42 +01:00
|
|
|
#define BIFROST_ADD_OP_BRANCH (0x0d000 >> 12)
|
|
|
|
|
2020-03-03 18:47:49 +00:00
|
|
|
struct bifrost_branch {
|
|
|
|
unsigned src0 : 3;
|
|
|
|
|
|
|
|
/* For BR_SIZE_ZERO, upper two bits become ctrl */
|
|
|
|
unsigned src1 : 3;
|
|
|
|
|
|
|
|
/* Offset source -- always uniform/const but
|
|
|
|
* theoretically could support indirect jumps? */
|
|
|
|
unsigned src2 : 3;
|
|
|
|
|
|
|
|
enum bifrost_branch_cond cond : 3;
|
|
|
|
enum branch_bit_size size : 3;
|
|
|
|
|
|
|
|
unsigned op : 5;
|
|
|
|
};
|
|
|
|
|
2020-03-12 18:16:22 +00:00
|
|
|
/* Clause packing */
|
|
|
|
|
|
|
|
struct bifrost_fmt1 {
|
|
|
|
unsigned ins_0 : 3;
|
|
|
|
unsigned tag : 5;
|
|
|
|
uint64_t ins_1 : 64;
|
|
|
|
unsigned ins_2 : 11;
|
|
|
|
uint64_t header : 45;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
#define BIFROST_FMT1_INSTRUCTIONS 0b00101
|
|
|
|
#define BIFROST_FMT1_FINAL 0b01001
|
|
|
|
#define BIFROST_FMT1_CONSTANTS 0b00001
|
|
|
|
|
2020-03-20 01:45:18 +00:00
|
|
|
#define BIFROST_FMTC_CONSTANTS 0b0011
|
|
|
|
#define BIFROST_FMTC_FINAL 0b0111
|
|
|
|
|
|
|
|
struct bifrost_fmt_constant {
|
|
|
|
unsigned pos : 4;
|
|
|
|
unsigned tag : 4;
|
|
|
|
uint64_t imm_1 : 60;
|
|
|
|
uint64_t imm_2 : 60;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2020-09-20 14:22:20 +01:00
|
|
|
/* 32-bit modes for slots 2/3, as encoded in the register block. Other values
|
|
|
|
* are reserved. First part specifies behaviour of slot 2 (Idle, Read, Write
|
|
|
|
* Full, Write Low, Write High), second part behaviour of slot 3, and the last
|
|
|
|
* part specifies the source for the write (FMA, ADD, or MIX for FMA/ADD).
|
|
|
|
*
|
2020-09-20 20:34:38 +01:00
|
|
|
* IDLE is a special mode disabling both slots, except for the first
|
2020-09-20 14:22:20 +01:00
|
|
|
* instruction in the clause which uses IDLE_1 for the same purpose.
|
2020-09-20 14:53:14 +01:00
|
|
|
*
|
|
|
|
* All fields 0 used as sentinel for reserved encoding, so IDLE(_1) have FMA
|
|
|
|
* set (and ignored) as a placeholder to differentiate from reserved.
|
2020-09-20 14:22:20 +01:00
|
|
|
*/
|
|
|
|
enum bifrost_reg_mode {
|
|
|
|
BIFROST_R_WL_FMA = 1,
|
|
|
|
BIFROST_R_WH_FMA = 2,
|
|
|
|
BIFROST_R_W_FMA = 3,
|
|
|
|
BIFROST_R_WL_ADD = 4,
|
|
|
|
BIFROST_R_WH_ADD = 5,
|
|
|
|
BIFROST_R_W_ADD = 6,
|
|
|
|
BIFROST_WL_WL_ADD = 7,
|
|
|
|
BIFROST_WL_WH_ADD = 8,
|
|
|
|
BIFROST_WL_W_ADD = 9,
|
|
|
|
BIFROST_WH_WL_ADD = 10,
|
|
|
|
BIFROST_WH_WH_ADD = 11,
|
|
|
|
BIFROST_WH_W_ADD = 12,
|
|
|
|
BIFROST_W_WL_ADD = 13,
|
|
|
|
BIFROST_W_WH_ADD = 14,
|
|
|
|
BIFROST_W_W_ADD = 15,
|
|
|
|
BIFROST_IDLE_1 = 16,
|
|
|
|
BIFROST_I_W_FMA = 17,
|
|
|
|
BIFROST_I_WL_FMA = 18,
|
|
|
|
BIFROST_I_WH_FMA = 19,
|
|
|
|
BIFROST_R_I = 20,
|
|
|
|
BIFROST_I_W_ADD = 21,
|
|
|
|
BIFROST_I_WL_ADD = 22,
|
|
|
|
BIFROST_I_WH_ADD = 23,
|
|
|
|
BIFROST_WL_WH_MIX = 24,
|
|
|
|
BIFROST_WH_WL_MIX = 26,
|
|
|
|
BIFROST_IDLE = 27,
|
|
|
|
};
|
|
|
|
|
2020-09-20 14:53:14 +01:00
|
|
|
enum bifrost_reg_op {
|
|
|
|
BIFROST_OP_IDLE = 0,
|
|
|
|
BIFROST_OP_READ = 1,
|
|
|
|
BIFROST_OP_WRITE = 2,
|
|
|
|
BIFROST_OP_WRITE_LO = 3,
|
|
|
|
BIFROST_OP_WRITE_HI = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bifrost_reg_ctrl_23 {
|
|
|
|
enum bifrost_reg_op slot2;
|
|
|
|
enum bifrost_reg_op slot3;
|
|
|
|
bool slot3_fma;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct bifrost_reg_ctrl_23 bifrost_reg_ctrl_lut[32] = {
|
|
|
|
[BIFROST_R_WL_FMA] = { BIFROST_OP_READ, BIFROST_OP_WRITE_LO, true },
|
|
|
|
[BIFROST_R_WH_FMA] = { BIFROST_OP_READ, BIFROST_OP_WRITE_HI, true },
|
|
|
|
[BIFROST_R_W_FMA] = { BIFROST_OP_READ, BIFROST_OP_WRITE, true },
|
|
|
|
[BIFROST_R_WL_ADD] = { BIFROST_OP_READ, BIFROST_OP_WRITE_LO, false },
|
|
|
|
[BIFROST_R_WH_ADD] = { BIFROST_OP_READ, BIFROST_OP_WRITE_HI, false },
|
|
|
|
[BIFROST_R_W_ADD] = { BIFROST_OP_READ, BIFROST_OP_WRITE, false },
|
|
|
|
[BIFROST_WL_WL_ADD] = { BIFROST_OP_WRITE_LO, BIFROST_OP_WRITE_LO, false },
|
|
|
|
[BIFROST_WL_WH_ADD] = { BIFROST_OP_WRITE_LO, BIFROST_OP_WRITE_HI, false },
|
|
|
|
[BIFROST_WL_W_ADD] = { BIFROST_OP_WRITE_LO, BIFROST_OP_WRITE, false },
|
|
|
|
[BIFROST_WH_WL_ADD] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE_LO, false },
|
|
|
|
[BIFROST_WH_WH_ADD] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE_HI, false },
|
|
|
|
[BIFROST_WH_W_ADD] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE, false },
|
|
|
|
[BIFROST_W_WL_ADD] = { BIFROST_OP_WRITE, BIFROST_OP_WRITE_LO, false },
|
|
|
|
[BIFROST_W_WH_ADD] = { BIFROST_OP_WRITE, BIFROST_OP_WRITE_HI, false },
|
|
|
|
[BIFROST_W_W_ADD] = { BIFROST_OP_WRITE, BIFROST_OP_WRITE, false },
|
|
|
|
[BIFROST_IDLE_1] = { BIFROST_OP_IDLE, BIFROST_OP_IDLE, true },
|
|
|
|
[BIFROST_I_W_FMA] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE, true },
|
|
|
|
[BIFROST_I_WL_FMA] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE_LO, true },
|
|
|
|
[BIFROST_I_WH_FMA] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE_HI, true },
|
|
|
|
[BIFROST_R_I] = { BIFROST_OP_READ, BIFROST_OP_IDLE, false },
|
|
|
|
[BIFROST_I_W_ADD] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE, false },
|
|
|
|
[BIFROST_I_WL_ADD] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE_LO, false },
|
|
|
|
[BIFROST_I_WH_ADD] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE_HI, false },
|
|
|
|
[BIFROST_WL_WH_MIX] = { BIFROST_OP_WRITE_LO, BIFROST_OP_WRITE_HI, false },
|
|
|
|
[BIFROST_WH_WL_MIX] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE_LO, false },
|
|
|
|
[BIFROST_IDLE] = { BIFROST_OP_IDLE, BIFROST_OP_IDLE, true },
|
|
|
|
};
|
|
|
|
|
2019-04-22 04:41:09 +01:00
|
|
|
#endif
|