minor updates

This commit is contained in:
Blaise Tine 2023-03-19 21:19:39 -04:00
parent 601a3e49b0
commit 693c13b636
34 changed files with 81 additions and 76 deletions

View file

@ -10,9 +10,10 @@ module VX_lerp_fx #(
input wire [F-1:0] frac,
output wire [N-1:0] out
);
wire [F-1:0] sub = F'(-1) - frac;
wire [N+F:0] tmp = in1 * sub + in2 * frac;
wire [F-1:0] One = {F{1'b1}};
wire [F-1:0] Half = One >> 1;
wire [F-1:0] sub = One - frac;
wire [N+F:0] tmp = in1 * sub + in2 * frac + (N+F+1)'(Half);
assign out = N'((tmp + (tmp >> F)) >> F);
endmodule

View file

@ -60,19 +60,19 @@ module VX_rop_blend_multadd #(
always @(*) begin
case (mode_rgb)
`ROP_BLEND_MODE_ADD: begin
sum_r = prod_src_r + prod_dst_r;
sum_g = prod_src_g + prod_dst_g;
sum_b = prod_src_b + prod_dst_b;
sum_r = prod_src_r + prod_dst_r + 16'hff;
sum_g = prod_src_g + prod_dst_g + 16'hff;
sum_b = prod_src_b + prod_dst_b + 16'hff;
end
`ROP_BLEND_MODE_SUB: begin
sum_r = prod_src_r - prod_dst_r;
sum_g = prod_src_g - prod_dst_g;
sum_b = prod_src_b - prod_dst_b;
sum_r = prod_src_r - prod_dst_r + 16'hff;
sum_g = prod_src_g - prod_dst_g + 16'hff;
sum_b = prod_src_b - prod_dst_b + 16'hff;
end
`ROP_BLEND_MODE_REV_SUB: begin
sum_r = prod_dst_r - prod_src_r;
sum_g = prod_dst_g - prod_src_g;
sum_b = prod_dst_b - prod_src_b;
sum_r = prod_dst_r - prod_src_r + 16'hff;
sum_g = prod_dst_g - prod_src_g + 16'hff;
sum_b = prod_dst_b - prod_src_b + 16'hff;
end
default: begin
sum_r = 'x;
@ -82,13 +82,13 @@ module VX_rop_blend_multadd #(
endcase
case (mode_a)
`ROP_BLEND_MODE_ADD: begin
sum_a = prod_src_a + prod_dst_a;
sum_a = prod_src_a + prod_dst_a + 16'hff;
end
`ROP_BLEND_MODE_SUB: begin
sum_a = prod_src_a - prod_dst_a;
sum_a = prod_src_a - prod_dst_a + 16'hff;
end
`ROP_BLEND_MODE_REV_SUB: begin
sum_a = prod_dst_a - prod_src_a;
sum_a = prod_dst_a - prod_src_a + 16'hff;
end
default: begin
sum_a = 'x;
@ -98,7 +98,7 @@ module VX_rop_blend_multadd #(
reg [15:0] clamp_r, clamp_g, clamp_b, clamp_a;
// clamp to (0, 255 * 255)
// clamp to (0, 255 * 256)
always @(*) begin
case (mode_rgb)
`ROP_BLEND_MODE_ADD: begin

View file

@ -5,11 +5,9 @@
#ifdef LLVM_VORTEX
#include <vx_print.h>
#include <vx_intrinsics.h>
#else
#include <stdio.h>
#define vx_printf printf
#define __UNIFORM__
#endif
using namespace cocogfx;
@ -21,20 +19,30 @@ static FloatE fxZero(0);
namespace {
template <uint32_t F, typename T = int32_t>
T TextureWrap(TFixed<F,T> fx, uint32_t __UNIFORM__ wrap) {
template <uint32_t F>
int32_t TextureWrap(TFixed<F> fx, uint32_t wrap) {
int32_t ret;
switch (wrap) {
case TEX_WRAP_CLAMP: return (fx.data() < 0) ? 0 : ((fx.data() > TFixed<F,T>::MASK) ? TFixed<F,T>::MASK : fx.data());
case TEX_WRAP_REPEAT: return (fx.data() & TFixed<F,T>::MASK);
case TEX_WRAP_MIRROR: return (bit_get(fx.data(), TFixed<F,T>::FRAC) ? ~fx.data() : fx.data());
default:
assert(false);
return 0;
case TEX_WRAP_CLAMP:
ret = fx.data() & -(fx.data() >= 0);
ret |= ((TFixed<F>::MASK - ret) >> 31);
break;
case TEX_WRAP_REPEAT:
ret = fx.data();
break;
case TEX_WRAP_MIRROR:
ret = fx.data() ^ ((fx.data() << (31-F)) >> 31);
break;
}
return ret & TFixed<F>::MASK;
}
inline uint32_t FormatStride(uint32_t __UNIFORM__ format) {
inline uint32_t FormatStride(uint32_t format) {
switch (format) {
default:
assert(false);
case TEX_FORMAT_A8R8G8B8:
return 4;
case TEX_FORMAT_R5G6B5:
@ -45,15 +53,14 @@ inline uint32_t FormatStride(uint32_t __UNIFORM__ format) {
case TEX_FORMAT_L8:
case TEX_FORMAT_A8:
return 1;
default:
assert(false);
return 0;
}
}
inline void Unpack8888(uint32_t __UNIFORM__ format, uint32_t texel, uint32_t* lo, uint32_t* hi) {
inline void Unpack8888(uint32_t format, uint32_t texel, uint32_t* lo, uint32_t* hi) {
uint32_t r, g, b, a;
switch (format) {
default:
assert(false);
case TEX_FORMAT_A8R8G8B8:
r = (texel >> 16) & 0xff;
g = (texel >> 8) & 0xff;
@ -95,9 +102,7 @@ inline void Unpack8888(uint32_t __UNIFORM__ format, uint32_t texel, uint32_t* lo
g = 0xff;
b = 0xff;
a = texel & 0xff;
break;
default:
assert(false);
break;
}
*lo = (r << 16) + b;
*hi = (a << 16) + g;
@ -233,12 +238,12 @@ void TextureSampler::configure(const TexDCRS& dcrs) {
}
uint32_t TextureSampler::read(uint32_t stage, int32_t u, int32_t v, uint32_t lod) const {
auto mip_off = dcrs_.read(stage, DCR_TEX_MIPOFF(lod));
auto __UNIFORM__ base_addr = dcrs_.read(stage, DCR_TEX_ADDR);
auto __UNIFORM__ logdim = dcrs_.read(stage, DCR_TEX_LOGDIM);
auto __UNIFORM__ format = dcrs_.read(stage, DCR_TEX_FORMAT);
auto __UNIFORM__ filter = dcrs_.read(stage, DCR_TEX_FILTER);
auto __UNIFORM__ wrap = dcrs_.read(stage, DCR_TEX_WRAP);
auto mip_off = dcrs_.read(stage, DCR_TEX_MIPOFF(lod));
auto base_addr = dcrs_.read(stage, DCR_TEX_ADDR);
auto logdim = dcrs_.read(stage, DCR_TEX_LOGDIM);
auto format = dcrs_.read(stage, DCR_TEX_FORMAT);
auto filter = dcrs_.read(stage, DCR_TEX_FILTER);
auto wrap = dcrs_.read(stage, DCR_TEX_WRAP);
base_addr += mip_off;
@ -254,6 +259,8 @@ uint32_t TextureSampler::read(uint32_t stage, int32_t u, int32_t v, uint32_t lod
auto xv = TFixed<TEX_FXD_FRAC>::make(v);
switch (filter) {
default:
assert(false);
case TEX_FILTER_BILINEAR: {
// addressing
uint32_t offset00, offset01, offset10, offset11;
@ -290,9 +297,6 @@ uint32_t TextureSampler::read(uint32_t stage, int32_t u, int32_t v, uint32_t lod
auto color = TexFilterPoint(format, texel);
return color;
}
default:
assert(false);
return 0;
}
}
@ -300,7 +304,7 @@ uint32_t TextureSampler::read(uint32_t stage, int32_t u, int32_t v, uint32_t lod
namespace {
bool DoCompare(uint32_t __UNIFORM__ func, uint32_t a, uint32_t b) {
bool DoCompare(uint32_t func, uint32_t a, uint32_t b) {
switch (func) {
default:
assert(false);
@ -323,7 +327,7 @@ bool DoCompare(uint32_t __UNIFORM__ func, uint32_t a, uint32_t b) {
}
}
uint32_t DoStencilOp(uint32_t __UNIFORM__ op, uint32_t ref, uint32_t val) {
uint32_t DoStencilOp(uint32_t op, uint32_t ref, uint32_t val) {
switch (op) {
default:
assert(false);
@ -346,7 +350,7 @@ uint32_t DoStencilOp(uint32_t __UNIFORM__ op, uint32_t ref, uint32_t val) {
}
}
uint32_t DoLogicOp(uint32_t __UNIFORM__ op, uint32_t src, uint32_t dst) {
uint32_t DoLogicOp(uint32_t op, uint32_t src, uint32_t dst) {
switch (op) {
default:
assert(false);
@ -385,7 +389,7 @@ uint32_t DoLogicOp(uint32_t __UNIFORM__ op, uint32_t src, uint32_t dst) {
}
}
ColorARGB DoBlendFunc(uint32_t __UNIFORM__ func,
ColorARGB DoBlendFunc(uint32_t func,
ColorARGB src,
ColorARGB dst,
ColorARGB cst) {
@ -457,7 +461,7 @@ ColorARGB DoBlendFunc(uint32_t __UNIFORM__ func,
}
}
ColorARGB DoBlendMode(uint32_t __UNIFORM__ mode,
ColorARGB DoBlendMode(uint32_t mode,
uint32_t logic_op,
ColorARGB src,
ColorARGB dst,
@ -468,24 +472,24 @@ ColorARGB DoBlendMode(uint32_t __UNIFORM__ mode,
assert(false);
case ROP_BLEND_MODE_ADD:
return ColorARGB(
Div255(std::min<int>(src.a * s.a + dst.a * d.a, 0xFF00)),
Div255(std::min<int>(src.r * s.r + dst.r * d.r, 0xFF00)),
Div255(std::min<int>(src.g * s.g + dst.g * d.g, 0xFF00)),
Div255(std::min<int>(src.b * s.b + dst.b * d.b, 0xFF00))
Div255(std::min<int>(src.a * s.a + dst.a * d.a + 0x80, 0xFF00)),
Div255(std::min<int>(src.r * s.r + dst.r * d.r + 0x80, 0xFF00)),
Div255(std::min<int>(src.g * s.g + dst.g * d.g + 0x80, 0xFF00)),
Div255(std::min<int>(src.b * s.b + dst.b * d.b + 0x80, 0xFF00))
);
case ROP_BLEND_MODE_SUB:
return ColorARGB(
Div255(std::max<int>(src.a * s.a - dst.a * d.a, 0x0)),
Div255(std::max<int>(src.r * s.r - dst.r * d.r, 0x0)),
Div255(std::max<int>(src.g * s.g - dst.g * d.g, 0x0)),
Div255(std::max<int>(src.b * s.b - dst.b * d.b, 0x0))
Div255(std::max<int>(src.a * s.a - dst.a * d.a + 0x80, 0x0)),
Div255(std::max<int>(src.r * s.r - dst.r * d.r + 0x80, 0x0)),
Div255(std::max<int>(src.g * s.g - dst.g * d.g + 0x80, 0x0)),
Div255(std::max<int>(src.b * s.b - dst.b * d.b + 0x80, 0x0))
);
case ROP_BLEND_MODE_REV_SUB:
return ColorARGB(
Div255(std::max<int>(dst.a * d.a - src.a * s.a, 0x0)),
Div255(std::max<int>(dst.r * d.r - src.r * s.r, 0x0)),
Div255(std::max<int>(dst.g * d.g - src.g * s.g, 0x0)),
Div255(std::max<int>(dst.b * d.b - src.b * s.b, 0x0))
Div255(std::max<int>(dst.a * d.a - src.a * s.a + 0x80, 0x0)),
Div255(std::max<int>(dst.r * d.r - src.r * s.r + 0x80, 0x0)),
Div255(std::max<int>(dst.g * d.g - src.g * s.g + 0x80, 0x0)),
Div255(std::max<int>(dst.b * d.b - src.b * s.b + 0x80, 0x0))
);
case ROP_BLEND_MODE_MIN:
return ColorARGB(
@ -544,7 +548,7 @@ void DepthTencil::configure(const RopDCRS& dcrs) {
&& (stencil_back_zfail_ == ROP_STENCIL_OP_KEEP));
}
bool DepthTencil::test(uint32_t __UNIFORM__ is_backface,
bool DepthTencil::test(uint32_t is_backface,
uint32_t depth,
uint32_t depthstencil_val,
uint32_t* depthstencil_result) const {

View file

@ -68,7 +68,7 @@ inline uint32_t Pack8888(uint32_t lo, uint32_t hi) {
}
inline uint32_t Lerp8888(uint32_t a, uint32_t b, uint32_t f) {
uint32_t p = a * (0xff - f) + b * f;
uint32_t p = a * (0xff - f) + b * f + 0x00800080;
uint32_t q = (p >> 8) & 0x00ff00ff;
return ((p + q) >> 8) & 0x00ff00ff;
}
@ -320,4 +320,4 @@ protected:
uint32_t scissor_bottom_;
};
} // namespace graphics
} // namespace graphics

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

View file

@ -99,12 +99,12 @@ public:
void write(unsigned x,
unsigned y,
unsigned __UNIFORM__ is_backface,
unsigned is_backface,
unsigned color,
unsigned depth) const {
auto __UNIFORM__ blend_enabled = blender_.enabled();
auto __UNIFORM__ depth_enabled = depthStencil_.depth_enabled();
auto __UNIFORM__ stencil_enabled = depthStencil_.stencil_enabled(is_backface);
auto blend_enabled = blender_.enabled();
auto depth_enabled = depthStencil_.depth_enabled();
auto stencil_enabled = depthStencil_.stencil_enabled(is_backface);
uint32_t depthstencil;
uint32_t dst_depthstencil;
@ -124,9 +124,9 @@ public:
private:
void read(bool __UNIFORM__ depth_enable,
bool __UNIFORM__ stencil_enable,
bool __UNIFORM__ blend_enable,
void read(bool depth_enable,
bool stencil_enable,
bool blend_enable,
uint32_t x,
uint32_t y,
uint32_t* depthstencil,
@ -142,10 +142,10 @@ private:
}
}
void write(bool __UNIFORM__ depth_enable,
bool __UNIFORM__ stencil_enable,
void write(bool depth_enable,
bool stencil_enable,
bool ds_passed,
bool __UNIFORM__ is_backface,
bool is_backface,
uint32_t dst_depthstencil,
uint32_t dst_color,
uint32_t x,
@ -197,8 +197,8 @@ public:
private:
static void memory_cb(uint32_t* out,
const uint32_t* addr,
uint32_t __UNIFORM__ stride,
uint32_t __UNIFORM__ size,
uint32_t stride,
uint32_t size,
void* /*cb_arg*/) {
switch (stride) {
case 4:

View file

@ -320,7 +320,7 @@ void shader_function_sw_rast_cb(uint32_t pos_mask,
}
}
void shader_function_sw(int task_id, kernel_arg_t* /*__UNIFORM__ arg*/) {
void shader_function_sw(int task_id, kernel_arg_t* /*arg*/) {
g_gpu_sw.render(task_id);
}
#endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Before After
Before After

View file

@ -16,8 +16,8 @@ typedef struct {
static void memory_cb(uint32_t* out,
const uint32_t* addr,
uint32_t __UNIFORM__ stride,
uint32_t __UNIFORM__ size,
uint32_t stride,
uint32_t size,
void* /*cb_arg*/) {
switch (stride) {
case 4:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 B

After

Width:  |  Height:  |  Size: 106 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 B

After

Width:  |  Height:  |  Size: 106 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 B

After

Width:  |  Height:  |  Size: 94 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 B

After

Width:  |  Height:  |  Size: 94 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 973 B

After

Width:  |  Height:  |  Size: 871 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 973 B

After

Width:  |  Height:  |  Size: 871 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Before After
Before After