cocogfx fixes and refactoring

This commit is contained in:
Blaise Tine 2021-11-25 13:58:09 -05:00
parent a671e1a05d
commit b995843a5b
44 changed files with 339 additions and 3921 deletions

View file

@ -1,10 +1,11 @@
all:
$(MAKE) -C third_party
$(MAKE) -C hw
$(MAKE) -C sim
$(MAKE) -C driver
$(MAKE) -C runtime
$(MAKE) -C tests
clean:
$(MAKE) -C hw clean
$(MAKE) -C sim clean

View file

@ -24,11 +24,12 @@
`define TEX_BLEND_FRAC 8
`define TEX_BLEND_ONE (2 ** `TEX_BLEND_FRAC)
`define TEX_FORMAT_R8G8B8A8 `TEX_FORMAT_BITS'(0)
`define TEX_FORMAT_A8R8G8B8 `TEX_FORMAT_BITS'(0)
`define TEX_FORMAT_R5G6B5 `TEX_FORMAT_BITS'(1)
`define TEX_FORMAT_R4G4B4A4 `TEX_FORMAT_BITS'(2)
`define TEX_FORMAT_L8A8 `TEX_FORMAT_BITS'(3)
`define TEX_FORMAT_L8 `TEX_FORMAT_BITS'(4)
`define TEX_FORMAT_A8 `TEX_FORMAT_BITS'(5)
`define TEX_FORMAT_A1R5G5B5 `TEX_FORMAT_BITS'(2)
`define TEX_FORMAT_A4R4G4B4 `TEX_FORMAT_BITS'(3)
`define TEX_FORMAT_A8L8 `TEX_FORMAT_BITS'(4)
`define TEX_FORMAT_L8 `TEX_FORMAT_BITS'(5)
`define TEX_FORMAT_A8 `TEX_FORMAT_BITS'(6)
`endif

View file

@ -13,25 +13,31 @@ module VX_tex_format #(
always @(*) begin
case (format)
`TEX_FORMAT_R8G8B8A8: begin
`TEX_FORMAT_A8R8G8B8: begin
texel_out_r[07:00] = texel_in[7:0];
texel_out_r[15:08] = texel_in[15:8];
texel_out_r[23:16] = texel_in[23:16];
texel_out_r[31:24] = texel_in[31:24];
end
`TEX_FORMAT_R5G6B5: begin
texel_out_r[07:00] = {texel_in[15:11], texel_in[15:13]};
texel_out_r[07:00] = {texel_in[4:0], texel_in[4:2]};
texel_out_r[15:08] = {texel_in[10:5], texel_in[10:9]};
texel_out_r[23:16] = {texel_in[4:0], texel_in[4:2]};
texel_out_r[23:16] = {texel_in[15:11], texel_in[15:13]};
texel_out_r[31:24] = 8'hff;
end
`TEX_FORMAT_R4G4B4A4: begin
texel_out_r[07:00] = {texel_in[11:8], texel_in[15:12]};
`TEX_FORMAT_A1R5G5B5: begin
texel_out_r[07:00] = {texel_in[4:0], texel_in[4:2]};
texel_out_r[15:08] = {texel_in[9:5], texel_in[9:7]};
texel_out_r[23:16] = {texel_in[14:10], texel_in[14:12]};
texel_out_r[31:24] = {8{texel_in[15]}};
end
`TEX_FORMAT_A4R4G4B4: begin
texel_out_r[07:00] = {2{texel_in[3:0]}};
texel_out_r[15:08] = {2{texel_in[7:4]}};
texel_out_r[23:16] = {2{texel_in[3:0]}};
texel_out_r[23:16] = {2{texel_in[11:8]}};
texel_out_r[31:24] = {2{texel_in[15:12]}};
end
`TEX_FORMAT_L8A8: begin
`TEX_FORMAT_A8L8: begin
texel_out_r[07:00] = texel_in[7:0];
texel_out_r[15:08] = texel_in[7:0];
texel_out_r[23:16] = texel_in[7:0];
@ -45,9 +51,9 @@ module VX_tex_format #(
end
//`TEX_FORMAT_A8
default: begin
texel_out_r[07:00] = 0;
texel_out_r[15:08] = 0;
texel_out_r[23:16] = 0;
texel_out_r[07:00] = 8'hff;
texel_out_r[15:08] = 8'hff;
texel_out_r[23:16] = 8'hff;
texel_out_r[31:24] = texel_in[7:0];
end
endcase

View file

@ -12,13 +12,14 @@ module VX_tex_stride #(
always @(*) begin
case (format)
`TEX_FORMAT_A8: log_stride_r = 0;
`TEX_FORMAT_L8: log_stride_r = 0;
`TEX_FORMAT_L8A8: log_stride_r = 1;
`TEX_FORMAT_R5G6B5: log_stride_r = 1;
`TEX_FORMAT_R4G4B4A4: log_stride_r = 1;
//`TEX_FORMAT_R8G8B8A8
default: log_stride_r = 2;
`TEX_FORMAT_A8R8G8B8: log_stride_r = 2;
`TEX_FORMAT_R5G6B5,
`TEX_FORMAT_A1R5G5B5,
`TEX_FORMAT_A4R4G4B4,
`TEX_FORMAT_A8L8: log_stride_r = 1;
// `TEX_FORMAT_L8:
// `TEX_FORMAT_A8:
default: log_stride_r = 0;
endcase
end

View file

@ -2,6 +2,7 @@ PROJECT = Core
TOP_LEVEL_ENTITY = VX_core
SRC_FILE = VX_core.v
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = VX_fpu_fpga
TOP_LEVEL_ENTITY = VX_fpu_fpga
SRC_FILE = VX_fpu_fpga.v
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
RTL_INCLUDE = $(FPU_INCLUDE);$(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces
PROJECT_FILES = $(PROJECT).qpf $(PROJECT).qsf

View file

@ -2,6 +2,7 @@ PROJECT = VX_pipeline
TOP_LEVEL_ENTITY = VX_pipeline
SRC_FILE = VX_pipeline.v
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = vortex_afu
TOP_LEVEL_ENTITY = vortex_afu
SRC_FILE = vortex_afu.sv
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(RTL_DIR)/afu;$(RTL_DIR)/afu/ccip;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = vortex_afu
TOP_LEVEL_ENTITY = vortex_afu
SRC_FILE = vortex_afu.sv
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(RTL_DIR)/afu;$(RTL_DIR)/afu/ccip;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = vortex_afu
TOP_LEVEL_ENTITY = vortex_afu
SRC_FILE = vortex_afu.sv
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH=$(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(RTL_DIR)/afu;$(RTL_DIR)/afu/ccip;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = vortex_afu
TOP_LEVEL_ENTITY = vortex_afu
SRC_FILE = vortex_afu.sv
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(RTL_DIR)/afu;$(RTL_DIR)/afu/ccip;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = vortex_afu
TOP_LEVEL_ENTITY = vortex_afu
SRC_FILE = vortex_afu.sv
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(RTL_DIR)/afu;$(RTL_DIR)/afu/ccip;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -1,7 +1,8 @@
PROJECT = vortex_afu
TOP_LEVEL_ENTITY = vortex_afu
SRC_FILE = vortex_afu.sv
RTL_DIR=../../../../rtl
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
#FAMILY = "Arria 10"
#DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FAMILY = "Stratix 10"
DEVICE = 1SX280HN2F43E2VG
FPU_CORE_PATH=$(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(RTL_DIR)/afu;$(RTL_DIR)/afu/ccip;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = vortex_afu
TOP_LEVEL_ENTITY = vortex_afu
SRC_FILE = vortex_afu.sv
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(RTL_DIR)/afu;$(RTL_DIR)/afu/ccip;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = Unittest
TOP_LEVEL_ENTITY = VX_core_req_bank_sel
SRC_FILE = VX_core_req_bank_sel.v
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -2,6 +2,7 @@ PROJECT = Vortex
TOP_LEVEL_ENTITY = Vortex
SRC_FILE = Vortex.sv
RTL_DIR = ../../../../rtl
THIRD_PARTY_DIR = ../../../../../third_party
FAMILY = "Arria 10"
DEVICE = 10AX115N3F40E2SG
@ -11,7 +12,7 @@ FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/arria10
#DEVICE = 1SX280HN2F43E2VG
#FPU_CORE_PATH = $(RTL_DIR)/fp_cores/altera/stratix10
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(RTL_DIR)/fp_cores/fpnew/src;$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include;$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src
FPU_INCLUDE = $(RTL_DIR)/fp_cores;$(FPU_CORE_PATH);$(THIRD_PARTY_DIR)/fpnew/src;$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include;$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src
TEX_INCLUDE = $(RTL_DIR)/tex_unit
RTL_INCLUDE = $(RTL_DIR);$(RTL_DIR)/libs;$(RTL_DIR)/interfaces;$(RTL_DIR)/cache;$(FPU_INCLUDE);$(TEX_INCLUDE)

View file

@ -26,7 +26,7 @@ $(PROJECT).dump: $(PROJECT).a
$(CC) $(CFLAGS) -c $< -o $@
$(PROJECT).a: $(OBJS)
$(AR) rcs $(PROJECT).a $^
$(AR) rcs $@ $^
.depend: $(SRCS)
$(CC) $(CFLAGS) -MM $^ > .depend;

View file

@ -1,11 +1,9 @@
all:
$(MAKE) -C common
$(MAKE) -C simX
$(MAKE) -C rtlsim
$(MAKE) -C vlsim
clean:
$(MAKE) -C common clean
$(MAKE) -C simX clean
$(MAKE) -C rtlsim clean
$(MAKE) -C vlsim clean

View file

@ -1,5 +0,0 @@
all:
SPECIALIZE_TYPE=RISCV SOFTFLOAT_OPTS="-fPIC -DSOFTFLOAT_ROUND_ODD -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32" $(MAKE) -C softfloat/build/Linux-x86_64-GCC
clean:
$(MAKE) -C softfloat/build/Linux-x86_64-GCC clean

View file

@ -1,419 +0,0 @@
#pragma once
#include <cstdint>
#include <cstdlib>
#include <assert.h>
template <uint32_t F, typename T = int32_t>
class Fixed {
private:
template <uint32_t F2, typename T2>
struct Cast {
private:
template <bool isF2Bigger, bool isT2Bigger> struct Tag {};
inline static T Convert(T2 value, Tag<false, false>) {
return static_cast<T>(value) << (F - F2);
}
inline static T Convert(T2 value, Tag<false, true>) {
return static_cast<T>(value) >> (F2 - F);
}
inline static T Convert(T2 value, Tag<true, false>) {
return static_cast<T>(value << (F - F2));
}
inline static T Convert(T2 value, Tag<true, true>) {
return static_cast<T>(value >> (F2 - F));
}
public:
inline static T Convert(T2 value) {
return Convert(value, Tag<(sizeof(T2) > sizeof(T)), (F2 > F)>{});
}
};
public:
using data_type = T;
static constexpr uint32_t FRAC = F;
static constexpr uint32_t INT = sizeof(T) * 8 - FRAC;
static constexpr uint32_t HFRAC = FRAC >> 1;
static constexpr T ONE = static_cast<T>(1) << FRAC;
static constexpr T MASK = ONE - 1;
static constexpr T IMASK = ~MASK;
static constexpr T HALF = ONE >> 1;
static constexpr T TWO = ONE << 1;
Fixed() {}
explicit Fixed(int64_t rhs)
: data_(static_cast<T>(rhs << FRAC)) {
assert((static_cast<int64_t>(rhs) << FRAC) == data_);
}
explicit Fixed(uint64_t rhs)
: data_(static_cast<T>(rhs << FRAC)) {
assert((static_cast<int64_t>(rhs) << FRAC) == data_);
}
explicit Fixed(int32_t rhs)
: data_(static_cast<T>(rhs << FRAC)) {
assert((static_cast<int64_t>(rhs) << FRAC) == data_);
}
explicit Fixed(uint32_t rhs)
: data_(static_cast<T>(rhs << FRAC)) {
assert((static_cast<int64_t>(rhs) << FRAC) == data_);
}
explicit Fixed(int16_t rhs)
: data_(static_cast<T>(rhs << FRAC)) {
assert((static_cast<int64_t>(rhs) << FRAC) == data_);
}
explicit Fixed(uint16_t rhs)
: data_(static_cast<T>(rhs << FRAC)) {
assert((static_cast<int64_t>(rhs) << FRAC) == data_);
}
explicit Fixed(int8_t rhs)
: data_(static_cast<T>(rhs << FRAC)) {
assert((static_cast<int64_t>(rhs) << FRAC) == data_);
}
explicit Fixed(uint8_t rhs)
: data_(static_cast<T>(rhs << FRAC)) {
assert((static_cast<int64_t>(rhs) << FRAC) == data_);
}
template <uint32_t F2, typename T2>
explicit Fixed(Fixed<F2, T2> rhs)
: data_(Cast<F2, T2>::Convert(rhs.data()))
{}
explicit Fixed(float rhs)
: data_(static_cast<T>(rhs * ONE)) {
assert(data_ == static_cast<T>(rhs * ONE));
}
bool operator==(Fixed rhs) const {
return (data_ == rhs.data_);
}
bool operator!=(Fixed rhs) const {
return (data_ != rhs.data_);
}
bool operator<(Fixed rhs) const {
return (data_ < rhs.data_);
}
bool operator<=(Fixed rhs) const {
return (data_ <= rhs.data_);
}
bool operator>(Fixed rhs) const {
return (data_ > rhs.data_);
}
bool operator>=(Fixed rhs) const {
return (data_ >= rhs.data_);
}
Fixed operator-() const {
return make(-data_);
}
Fixed operator+=(Fixed rhs) {
*this = (*this) + rhs;
return *this;
}
Fixed operator-=(Fixed rhs) {
*this = (*this) - rhs;
return *this;
}
Fixed operator*=(Fixed rhs) {
*this = (*this) * rhs;
return *this;
}
Fixed operator/=(Fixed rhs) {
*this = (*this) / rhs;
return *this;
}
template <uint32_t F2, typename T2>
Fixed operator*=(Fixed<F2, T2> rhs) {
*this = (*this) * rhs;
return *this;
}
template <uint32_t F2, typename T2>
Fixed operator/=(Fixed<F2, T2> rhs) {
*this = (*this) / rhs;
return *this;
}
Fixed operator*=(int32_t rhs) {
*this = (*this) * rhs;
return *this;
}
Fixed operator*=(uint32_t rhs) {
*this = (*this) * rhs;
return *this;
}
Fixed operator*=(float rhs) {
*this = (*this) * rhs;
return *this;
}
Fixed operator/=(int32_t rhs) {
*this = (*this) / rhs;
return *this;
}
Fixed operator/=(uint32_t rhs) {
*this = (*this) / rhs;
return *this;
}
Fixed operator/=(float rhs) {
*this = (*this) / rhs;
return *this;
}
friend Fixed operator+(Fixed lhs, Fixed rhs) {
assert((static_cast<int64_t>(lhs.data_) + rhs.data_) ==
(lhs.data_ + rhs.data_));
return Fixed::make(lhs.data_ + rhs.data_);
}
friend Fixed operator-(Fixed lhs, Fixed rhs) {
assert((static_cast<int64_t>(lhs.data_) - rhs.data_) ==
(lhs.data_ - rhs.data_));
return Fixed::make(lhs.data_ - rhs.data_);
}
friend Fixed operator*(Fixed lhs, Fixed rhs) {
return Fixed::make((static_cast<int64_t>(lhs.data_) * rhs.data_) >> FRAC);
}
template <uint32_t F2, typename T2>
friend Fixed operator*(Fixed lhs, Fixed<F2, T2> rhs) {
return Fixed::make((static_cast<int64_t>(lhs.data_) * rhs.data()) >> F2);
}
friend Fixed operator/(Fixed lhs, Fixed rhs) {
assert(rhs.data_ != 0);
return Fixed::make((static_cast<int64_t>(lhs.data_) << FRAC) / rhs.data_);
}
template <uint32_t F2, typename T2>
friend Fixed operator/(Fixed lhs, Fixed<F2, T2> rhs) {
assert(rhs.data() != 0);
return Fixed::make((static_cast<int64_t>(lhs.data_) << F2) / rhs.data());
}
friend Fixed operator*(Fixed lhs, float rhs) {
return static_cast<float>(lhs) * rhs;
}
friend Fixed operator*(float lhs, Fixed rhs) {
return lhs * static_cast<float>(rhs);
}
friend Fixed operator/(Fixed lhs, float rhs) {
return static_cast<float>(lhs) / rhs;
}
friend Fixed operator/(float lhs, Fixed rhs) {
return lhs / static_cast<float>(rhs);
}
friend Fixed operator*(Fixed lhs, char rhs) {
return lhs * static_cast<int32_t>(rhs);
}
friend Fixed operator*(char lhs, Fixed rhs) {
return rhs * lhs;
}
friend Fixed operator/(Fixed lhs, char rhs) {
return lhs / static_cast<int32_t>(rhs);
}
friend Fixed operator/(char lhs, Fixed rhs) {
return rhs / lhs;
}
friend Fixed operator*(Fixed lhs, uint8_t rhs) {
return lhs * static_cast<int32_t>(rhs);
}
friend Fixed operator*(uint8_t lhs, Fixed rhs) {
return rhs * lhs;
}
friend Fixed operator/(Fixed lhs, uint8_t rhs) {
return lhs / static_cast<int32_t>(rhs);
}
friend Fixed operator/(uint8_t lhs, Fixed rhs) {
return rhs / lhs;
}
friend Fixed operator*(Fixed lhs, short rhs) {
return lhs * static_cast<int32_t>(rhs);
}
friend Fixed operator*(short lhs, Fixed rhs) {
return rhs * lhs;
}
friend Fixed operator/(Fixed lhs, short rhs) {
return lhs / static_cast<int32_t>(rhs);
}
friend Fixed operator/(short lhs, Fixed rhs) {
return rhs / lhs;
}
friend Fixed operator*(Fixed lhs, uint16_t rhs) {
return lhs * static_cast<int32_t>(rhs);
}
friend Fixed operator*(uint16_t lhs, Fixed rhs) {
return rhs * lhs;
}
friend Fixed operator/(Fixed lhs, uint16_t rhs) {
return lhs / static_cast<int32_t>(rhs);
}
friend Fixed operator/(uint16_t lhs, Fixed rhs) {
return rhs / lhs;
}
friend Fixed operator*(Fixed lhs, int32_t rhs) {
auto value = static_cast<T>(lhs.data_ * rhs);
assert((lhs.data_ * static_cast<int64_t>(rhs)) == value);
return Fixed::make(value);
}
friend Fixed operator*(int32_t lhs, Fixed rhs) {
return rhs * lhs;
}
friend Fixed operator/(Fixed lhs, int32_t rhs) {
assert(rhs);
auto value = static_cast<T>(lhs.data_ / rhs);
return Fixed::make(value);
}
friend Fixed operator/(int32_t lhs, Fixed rhs) {
return rhs / lhs;
}
friend Fixed operator*(Fixed lhs, uint32_t rhs) {
auto value = static_cast<T>(lhs.data_ << rhs);
assert((lhs.data_ << static_cast<int64_t>(rhs)) == value);
return Fixed::make(value);
}
friend Fixed operator*(uint32_t lhs, Fixed rhs) {
return rhs * lhs;
}
friend Fixed operator/(Fixed lhs, uint32_t rhs) {
assert(rhs);
auto value = static_cast<T>(lhs.data_ / rhs);
return Fixed::make(value);
}
friend Fixed operator/(uint32_t lhs, Fixed rhs) {
return rhs / lhs;
}
friend Fixed operator<<(Fixed lhs, int32_t rhs) {
auto value = static_cast<T>(lhs.data_ << rhs);
assert((lhs.data_ << static_cast<int64_t>(rhs)) == value);
return Fixed::make(value);
}
friend Fixed operator>>(Fixed lhs, int32_t rhs) {
auto value = static_cast<T>(lhs.data_ >> rhs);
return Fixed::make(value);
}
friend Fixed operator<<(Fixed lhs, uint32_t rhs) {
auto value = static_cast<T>(lhs.data_ << rhs);
assert((lhs.data_ << static_cast<int64_t>(rhs)) == value);
return Fixed::make(value);
}
friend Fixed operator>>(Fixed lhs, uint32_t rhs) {
auto value = static_cast<T>(lhs.data_ >> rhs);
return Fixed::make(value);
}
static Fixed make(T value) {
Fixed ret;
ret.data_ = value;
return ret;
}
explicit operator int64_t() const {
return static_cast<int64_t>(data_ >> F);
}
explicit operator uint64_t() const {
return static_cast<uint64_t>(data_ >> F);
}
explicit operator int32_t() const {
return static_cast<int32_t>(data_ >> F);
}
explicit operator uint32_t() const {
return static_cast<uint32_t>(data_ >> F);
}
explicit operator int16_t() const {
return static_cast<int16_t>(data_ >> F);
}
explicit operator uint16_t() const {
return static_cast<uint16_t>(data_ >> F);
}
explicit operator int8_t() const {
return static_cast<int8_t>(data_ >> F);
}
explicit operator uint8_t() const {
return static_cast<uint8_t>(data_ >> F);
}
template <uint32_t F2, typename T2>
explicit operator Fixed<F2, T2>() const {
return Fixed<F2, T2>(*this);
}
explicit operator float() const {
return static_cast<float>(data_) / (static_cast<T>(1) << F);
}
T data() const {
return data_;
}
private:
T data_;
};

View file

@ -3,8 +3,8 @@
extern "C" {
#include <softfloat.h>
#include <softfloat/source/include/internals.h>
#include <softfloat/source/RISCV/specialize.h>
#include <internals.h>
#include <../RISCV/specialize.h>
}
#define F32_SIGN 0x80000000

View file

@ -1,10 +1,11 @@
#pragma once
#include <cstdint>
#include <cstdlib>
#include <fixed.h>
#include <bitmanip.h>
using namespace cocogfx;
enum class WrapMode {
Clamp,
Repeat,
@ -12,10 +13,11 @@ enum class WrapMode {
};
enum class TexFormat {
R8G8B8A8,
R5G6B5,
R4G4B4A4,
L8A8,
A8R8G8B8,
R5G6B5,
A1R5G5B5,
A4R4G4B4,
A8L8,
L8,
A8,
};
@ -34,11 +36,12 @@ T Clamp(Fixed<F,T> fx, WrapMode mode) {
inline uint32_t Stride(TexFormat format) {
switch (format) {
case TexFormat::R8G8B8A8:
case TexFormat::A8R8G8B8:
return 4;
case TexFormat::R5G6B5:
case TexFormat::R4G4B4A4:
case TexFormat::L8A8:
case TexFormat::A1R5G5B5:
case TexFormat::A4R4G4B4:
case TexFormat::A8L8:
return 2;
case TexFormat::L8:
case TexFormat::A8:
@ -53,61 +56,68 @@ inline void Unpack8888(TexFormat format,
uint32_t texel,
uint32_t* lo,
uint32_t* hi) {
int r, g, b, a;
switch (format) {
case TexFormat::R8G8B8A8:
*lo = texel & 0x00ff00ff;
*hi = (texel >> 8) & 0x00ff00ff;
case TexFormat::A8R8G8B8:
r = (texel >> 16) & 0xff;
g = (texel >> 8) & 0xff;
b = texel & 0xff;
a = texel >> 24;
break;
case TexFormat::R5G6B5:
case TexFormat::R4G4B4A4:
*lo = texel;
*hi= 0;
case TexFormat::R5G6B5:
r = ((texel >> 11) << 3) | (texel >> 13);
g = ((texel >> 3) & 0xfc) | ((texel >> 9) & 0x3);
b = ((texel & 0x1f) << 3) | ((texel & 0x1c) >> 2);
a = 0xff;
break;
case TexFormat::L8A8:
*lo = (texel | (texel << 8)) & 0x00ff00ff;
*hi = 0;
case TexFormat::A1R5G5B5:
r = ((texel >> 7) & 0xf8) | ((texel << 1) >> 13);
g = ((texel >> 2) & 0xf8) | ((texel >> 7) & 7);
b = ((texel & 0x1f) << 3) | ((texel & 0x1c) >> 2);
a = 0xff * (texel >> 15);
break;
case TexFormat::A4R4G4B4:
r = ((texel >> 4) & 0xf0) | ((texel >> 8) & 0x0f);
g = ((texel & 0xf0) >> 0) | ((texel & 0xf0) >> 4);
b = ((texel & 0x0f) << 4) | ((texel & 0x0f) >> 0);
a = ((texel >> 8) & 0xf0) | (texel >> 12);
break;
case TexFormat::A8L8:
r = texel & 0xff;
g = r;
b = r;
a = texel >> 8;
break;
case TexFormat::L8:
*lo = (texel | (texel << 16)) & 0x07e0f81f;
*hi = 0;
r = texel & 0xff;
g = r;
b = r;
a = 0xff;
break;
case TexFormat::A8:
*lo = (texel | (texel << 12)) & 0x0f0f0f0f;
*hi = 0;
r = 0xff;
g = 0xff;
b = 0xff;
a = texel & 0xff;
break;
default:
std::abort();
}
}
*lo = (r << 16) + b;
*hi = (a << 16) + g;
}
inline uint32_t Pack8888(TexFormat format, uint32_t lo, uint32_t hi) {
switch (format) {
case TexFormat::R8G8B8A8:
return (hi << 8) | lo;
case TexFormat::R5G6B5:
case TexFormat::R4G4B4A4:
return lo;
case TexFormat::L8A8:
return (lo | (lo >> 8)) & 0xffff;
case TexFormat::L8:
return (lo | (lo >> 16)) & 0xffff;
case TexFormat::A8:
return (lo | (lo >> 12)) & 0xffff;
default:
std::abort();
return 0;
}
inline void Unpack8888(uint32_t texel, uint32_t* lo, uint32_t* hi) {
*lo = texel & 0x00ff00ff;
*hi = (texel >> 8) & 0x00ff00ff;
}
inline void Lerp8888(uint32_t al,
uint32_t ah,
uint32_t bl,
uint32_t bh,
uint32_t frac,
uint32_t* lo,
uint32_t* hi) {
*lo = (al + (((bl - al) * frac) >> 8)) & 0x00ff00ff;
*hi = (ah + (((bh - ah) * frac) >> 8)) & 0x00ff00ff;
inline uint32_t Pack8888(uint32_t lo, uint32_t hi) {
return (hi << 8) | lo;
}
inline uint32_t Lerp8888(uint32_t a, uint32_t b, uint32_t f) {
return (a + (((b - a) * f) >> 8)) & 0x00ff00ff;
}
template <uint32_t F, typename T = int32_t>
@ -185,25 +195,28 @@ inline uint32_t TexFilterLinear(
) {
uint32_t c01l, c01h;
{
uint32_t c0l, c0h;
uint32_t c1l, c1h;
uint32_t c0l, c0h, c1l, c1h;
Unpack8888(format, texel00, &c0l, &c0h);
Unpack8888(format, texel01, &c1l, &c1h);
Lerp8888(c0l, c0h, c1l, c1h, alpha, &c01l, &c01h);
c01l = Lerp8888(c0l, c1l, alpha);
c01h = Lerp8888(c0h, c1h, alpha);
}
uint32_t c23l, c23h;
{
uint32_t c2l, c2h;
uint32_t c3l, c3h;
uint32_t c2l, c2h, c3l, c3h;
Unpack8888(format, texel10, &c2l, &c2h);
Unpack8888(format, texel11, &c3l, &c3h);
Lerp8888(c2l, c2h, c3l, c3h, alpha, &c23l, &c23h);
c23l = Lerp8888(c2l, c3l, alpha);
c23h = Lerp8888(c2h, c3h, alpha);
}
uint32_t cl, ch;
Lerp8888(c01l, c01h, c23l, c23h, beta, &cl, &ch);
uint32_t color = Pack8888(TexFormat::R8G8B8A8, cl, ch);
uint32_t color;
{
uint32_t cl = Lerp8888(c01l, c23l, beta);
uint32_t ch = Lerp8888(c01h, c23h, beta);
color = Pack8888(cl, ch);
}
//printf("*** texel00=0x%x, texel01=0x%x, texel10=0x%x, texel11=0x%x, color=0x%x\n", texel00, texel01, texel10, texel11, color);
@ -211,9 +224,12 @@ inline uint32_t TexFilterLinear(
}
inline uint32_t TexFilterPoint(TexFormat format, uint32_t texel) {
uint32_t cl, ch;
Unpack8888(format, texel, &cl, &ch);
uint32_t color = Pack8888(TexFormat::R8G8B8A8, cl, ch);
uint32_t color;
{
uint32_t cl, ch;
Unpack8888(format, texel, &cl, &ch);
color = Pack8888(cl, ch);
}
//printf("*** texel=0x%x, color=0x%x\n", texel, color);

View file

@ -1,12 +1,13 @@
RTL_DIR=../../hw/rtl
DPI_DIR=../../hw/dpi
RTL_DIR = ../../hw/rtl
DPI_DIR = ../../hw/dpi
THIRD_PARTY_DIR = ../../third_party
CXXFLAGS += -std=c++11 -Wall -Wextra -Wfatal-errors -Wno-array-bounds
CXXFLAGS += -fPIC -Wno-maybe-uninitialized
CXXFLAGS += -I../../../hw -I../../common
CXXFLAGS += -I../../common/softfloat/source/include
CXXFLAGS += -I../$(THIRD_PARTY_DIR)/softfloat/source/include
LDFLAGS += ../../common/softfloat/build/Linux-x86_64-GCC/softfloat.a
LDFLAGS += ../$(THIRD_PARTY_DIR)/softfloat/build/Linux-x86_64-GCC/softfloat.a
# control RTL debug tracing states
DBG_TRACE_FLAGS += -DDBG_TRACE_PIPELINE
@ -24,7 +25,7 @@ DBG_TRACE_FLAGS += -DDBG_TRACE_TEX
DBG_FLAGS += $(DBG_TRACE_FLAGS)
FPU_INCLUDE = -I$(RTL_DIR)/fp_cores -I$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include -I$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src -I$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl -I$(RTL_DIR)/fp_cores/fpnew/src
FPU_INCLUDE = -I$(RTL_DIR)/fp_cores -I$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include -I$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src -I$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl -I$(THIRD_PARTY_DIR)/fpnew/src
TEX_INCLUDE = -I$(RTL_DIR)/tex_unit
RTL_INCLUDE = -I$(RTL_DIR) -I$(DPI_DIR) -I$(RTL_DIR)/libs -I$(RTL_DIR)/interfaces -I$(RTL_DIR)/cache -I$(RTL_DIR)/simulate $(FPU_INCLUDE) $(TEX_INCLUDE)
@ -90,7 +91,7 @@ $(PROJECT): $(SRCS)
static: $(SRCS)
verilator --build $(VL_FLAGS) $(SRCS) -CFLAGS '$(CXXFLAGS)' -LDFLAGS '$(LDFLAGS)'
$(AR) rcs lib$(PROJECT).a obj_dir/*.o ../common/softfloat/build/Linux-x86_64-GCC/*.o
$(AR) rcs lib$(PROJECT).a obj_dir/*.o $(THIRD_PARTY_DIR)/softfloat/build/Linux-x86_64-GCC/*.o
clean-static:
rm -rf lib$(PROJECT).a obj_dir

View file

@ -1,12 +1,14 @@
RTL_DIR = ../hw/rtl
THIRD_PARTY_DIR = ../../third_party
CXXFLAGS += -std=c++11 -Wall -Wextra -Wfatal-errors
CXXFLAGS += -fPIC -Wno-maybe-uninitialized
CXXFLAGS += -I. -I../common -I../../hw
CXXFLAGS += -I../common/softfloat/source/include
CXXFLAGS += -I$(THIRD_PARTY_DIR)/softfloat/source/include
CXXFLAGS += -I$(THIRD_PARTY_DIR)/cocogfx/include
CXXFLAGS += $(CONFIGS)
LDFLAGS += ../common/softfloat/build/Linux-x86_64-GCC/softfloat.a
LDFLAGS += $(THIRD_PARTY_DIR)/softfloat/build/Linux-x86_64-GCC/softfloat.a -L$(THIRD_PARTY_DIR)/cocogfx -lcocogfx
TOP = vx_cache_sim
@ -38,7 +40,7 @@ obj_dir/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
static: $(OBJS)
$(AR) rcs lib$(PROJECT).a $(OBJS) ../common/softfloat/build/Linux-x86_64-GCC/*.o
$(AR) rcs lib$(PROJECT).a $(OBJS) $(THIRD_PARTY_DIR)/softfloat/build/Linux-x86_64-GCC/*.o
.depend: $(SRCS)
$(CXX) $(CXXFLAGS) -MM $^ > .depend;

View file

@ -4,6 +4,7 @@
#include <VX_config.h>
using namespace vortex;
using namespace cocogfx;
enum class FilterMode {
Point,

View file

@ -1,13 +1,14 @@
RTL_DIR = ../../hw/rtl
DPI_DIR = ../../hw/dpi
SCRIPT_DIR=../../hw/scripts
SCRIPT_DIR = ../../hw/scripts
THIRD_PARTY_DIR = ../../third_party
CXXFLAGS += -std=c++11 -Wall -Wextra -Wfatal-errors -Wno-array-bounds
CXXFLAGS += -fPIC -Wno-maybe-uninitialized
CXXFLAGS += -I.. -I../../../hw -I../../common
CXXFLAGS += -I../../common/softfloat/source/include
CXXFLAGS += -I../$(THIRD_PARTY_DIR)/softfloat/source/include
LDFLAGS += -shared ../../common/softfloat/build/Linux-x86_64-GCC/softfloat.a
LDFLAGS += -shared ../$(THIRD_PARTY_DIR)/softfloat/build/Linux-x86_64-GCC/softfloat.a
# control RTL debug tracing states
DBG_TRACE_FLAGS += -DDBG_TRACE_PIPELINE
@ -29,7 +30,7 @@ SRCS = ../common/util.cpp ../common/mem.cpp ../common/rvfloats.cpp
SRCS += $(DPI_DIR)/util_dpi.cpp $(DPI_DIR)/float_dpi.cpp
SRCS += fpga.cpp opae_sim.cpp
FPU_INCLUDE = -I$(RTL_DIR)/fp_cores -I$(RTL_DIR)/fp_cores/fpnew/src/common_cells/include -I$(RTL_DIR)/fp_cores/fpnew/src/common_cells/src -I$(RTL_DIR)/fp_cores/fpnew/src/fpu_div_sqrt_mvp/hdl -I$(RTL_DIR)/fp_cores/fpnew/src
FPU_INCLUDE = -I$(RTL_DIR)/fp_cores -I$(THIRD_PARTY_DIR)/fpnew/src/common_cells/include -I$(THIRD_PARTY_DIR)/fpnew/src/common_cells/src -I$(THIRD_PARTY_DIR)/fpnew/src/fpu_div_sqrt_mvp/hdl -I$(THIRD_PARTY_DIR)/fpnew/src
TEX_INCLUDE = -I$(RTL_DIR)/tex_unit
RTL_INCLUDE = -I$(RTL_DIR) -I$(DPI_DIR) -I$(RTL_DIR)/libs -I$(RTL_DIR)/interfaces -I$(RTL_DIR)/cache $(FPU_INCLUDE) $(TEX_INCLUDE)
RTL_INCLUDE += -I$(RTL_DIR)/afu -I$(RTL_DIR)/afu/ccip
@ -98,7 +99,7 @@ $(PROJECT).so: $(SRCS) vortex_afu.h
static: $(SRCS) vortex_afu.h
verilator --build $(VL_FLAGS) $(SRCS) -CFLAGS '$(CXXFLAGS)' -LDFLAGS '$(LDFLAGS)'
$(AR) rcs $(PROJECT).a obj_dir/*.o ../common/softfloat/build/Linux-x86_64-GCC/*.o
$(AR) rcs $(PROJECT).a obj_dir/*.o $(THIRD_PARTY_DIR)/softfloat/build/Linux-x86_64-GCC/*.o
clean-static:
rm -rf $(PROJECT).a obj_dir vortex_afu.h

49
sim/vlsim/vortex_afu.h Normal file
View file

@ -0,0 +1,49 @@
// auto-generated by gen_config.py. DO NOT EDIT
// Generated at 2021-11-25 13:43:13.259966
// Translated from VX_config.vh:
#ifndef __VORTEX_AFU__
#define __VORTEX_AFU__
#define PLATFORM_PROVIDES_LOCAL_MEMORY
#ifndef PLATFORM_PARAM_LOCAL_MEMORY_BANKS
#define PLATFORM_PARAM_LOCAL_MEMORY_BANKS 2
#endif
#ifndef PLATFORM_PARAM_LOCAL_MEMORY_ADDR_WIDTH
#define PLATFORM_PARAM_LOCAL_MEMORY_ADDR_WIDTH 26
#endif
#ifndef PLATFORM_PARAM_LOCAL_MEMORY_DATA_WIDTH
#define PLATFORM_PARAM_LOCAL_MEMORY_DATA_WIDTH 512
#endif
#ifndef PLATFORM_PARAM_LOCAL_MEMORY_BURST_CNT_WIDTH
#define PLATFORM_PARAM_LOCAL_MEMORY_BURST_CNT_WIDTH 4
#endif
#define AFU_ACCEL_NAME "vortex_afu"
#define AFU_ACCEL_UUID 0x35f9452b_25c2_434c_93d5_6f8c60db361c
#define AFU_IMAGE_CMD_MEM_READ 1
#define AFU_IMAGE_CMD_MEM_WRITE 2
#define AFU_IMAGE_CMD_RUN 3
#define AFU_IMAGE_MMIO_CMD_TYPE 10
#define AFU_IMAGE_MMIO_DATA_SIZE 16
#define AFU_IMAGE_MMIO_IO_ADDR 12
#define AFU_IMAGE_MMIO_MEM_ADDR 14
#define AFU_IMAGE_MMIO_SCOPE_READ 20
#define AFU_IMAGE_MMIO_SCOPE_WRITE 22
#define AFU_IMAGE_MMIO_DEV_CAPS 24
#define AFU_IMAGE_MMIO_STATUS 18
#define AFU_IMAGE_POWER 0
#define AFU_TOP_IFC "ccip_std_afu_avalon_mm"
#endif

View file

@ -10,7 +10,7 @@ VX_DP = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-objdump
VX_CP = $(RISCV_TOOLCHAIN_PATH)/bin/riscv32-unknown-elf-objcopy
VX_CFLAGS += -std=c++11 -march=rv32imf -mabi=ilp32f -O3 -Wstack-usage=1024 -ffreestanding -nostartfiles -fdata-sections -ffunction-sections
VX_CFLAGS += -DENABLE_SW -I$(VORTEX_RT_PATH)/include -I$(VORTEX_RT_PATH)/../hw -I$(VORTEX_RT_PATH)/../sim/common
VX_CFLAGS += -DENABLE_SW -I$(VORTEX_RT_PATH)/include -I$(VORTEX_RT_PATH)/../hw -I$(VORTEX_RT_PATH)/../sim/common -I$(VORTEX_RT_PATH)/../third_party/cocogfx/include
VX_LDFLAGS += -Wl,-Bstatic,-T,$(VORTEX_RT_PATH)/linker/vx_link.ld -Wl,--gc-sections $(VORTEX_RT_PATH)/libvortexrt.a
@ -19,15 +19,13 @@ VX_SRCS = kernel.c
#CXXFLAGS += -std=c++11 -O2 -Wall -Wextra -Wfatal-errors
CXXFLAGS += -std=c++11 -O0 -g -Wall -Wextra -Wfatal-errors
CXXFLAGS += -DLUPNG_USE_ZLIB
CXXFLAGS += -I$(VORTEX_DRV_PATH)/include -I$(VORTEX_RT_PATH)/../hw -I$(VORTEX_RT_PATH)/../sim/common -I$(VORTEX_RT_PATH)/../third_party/cocogfx/include
CXXFLAGS += -I$(VORTEX_DRV_PATH)/include -I$(VORTEX_RT_PATH)/../hw -I$(VORTEX_RT_PATH)/../sim/common
LDFLAGS += -L$(VORTEX_DRV_PATH)/stub -lvortex -lz
LDFLAGS += -L$(VORTEX_DRV_PATH)/stub -lvortex $(VORTEX_RT_PATH)/../third_party/cocogfx/libcocogfx.a -lz
PROJECT = tex
SRCS = main.cpp utils.cpp tga.cpp lupng.c
SRCS = main.cpp utils.cpp
all: $(PROJECT) kernel.bin kernel.dump

View file

@ -1,268 +0,0 @@
//
// Copyright (c) Blaise Tine. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools
// installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR
// INDEMNITIES.
//
#pragma once
#include "surfacedesc.h"
class BlitTable {
public:
typedef int (*PfnCopy)(const SurfaceDesc &dstDesc,
uint32_t dstOffsetX,
uint32_t dstOffsetY,
uint32_t copyWidth,
uint32_t copyHeight,
const SurfaceDesc &srcDesc,
uint32_t srcOffsetX,
uint32_t srcOffsetY);
BlitTable() {
for (uint32_t s = 0; s < FORMAT_COLOR_SIZE_; ++s) {
for (uint32_t d = 0; d < FORMAT_COLOR_SIZE_; ++d) {
copyFuncs_[s][d] = CopyInvalid;
}
}
for (uint32_t s = 0; s < FORMAT_COLOR_SIZE_; ++s) {
switch (s) {
case FORMAT_A8:
case FORMAT_L8:
copyFuncs_[s][s] = CopyFast<uint8_t>;
break;
case FORMAT_A8L8:
copyFuncs_[FORMAT_A8L8][FORMAT_A8] = Copy<FORMAT_A8L8, FORMAT_A8>;
copyFuncs_[FORMAT_A8L8][FORMAT_A8L8] = CopyFast<uint16_t>;
break;
case FORMAT_R5G6B5:
copyFuncs_[FORMAT_R5G6B5][FORMAT_L8] = Copy<FORMAT_R5G6B5, FORMAT_L8>;
copyFuncs_[FORMAT_R5G6B5][FORMAT_R5G6B5] = CopyFast<uint16_t>;
copyFuncs_[FORMAT_R5G6B5][FORMAT_R8G8B8] =
Copy<FORMAT_R5G6B5, FORMAT_R8G8B8>;
copyFuncs_[FORMAT_R5G6B5][FORMAT_B8G8R8] =
Copy<FORMAT_R5G6B5, FORMAT_B8G8R8>;
copyFuncs_[FORMAT_R5G6B5][FORMAT_A8B8G8R8] =
Copy<FORMAT_R5G6B5, FORMAT_A8B8G8R8>;
copyFuncs_[FORMAT_R5G6B5][FORMAT_A8R8G8B8] =
Copy<FORMAT_R5G6B5, FORMAT_A8R8G8B8>;
break;
case FORMAT_A1R5G5B5:
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_A8] =
Copy<FORMAT_A1R5G5B5, FORMAT_A8>;
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_L8] =
Copy<FORMAT_A1R5G5B5, FORMAT_L8>;
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_A8L8] =
Copy<FORMAT_A1R5G5B5, FORMAT_A8L8>;
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_R8G8B8] =
Copy<FORMAT_A1R5G5B5, FORMAT_R8G8B8>;
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_A8R8G8B8] =
Copy<FORMAT_A1R5G5B5, FORMAT_A8R8G8B8>;
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_R5G5B5A1] =
Copy<FORMAT_A1R5G5B5, FORMAT_R5G5B5A1>;
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_R4G4B4A4] =
Copy<FORMAT_A1R5G5B5, FORMAT_R4G4B4A4>;
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_B8G8R8] =
Copy<FORMAT_A1R5G5B5, FORMAT_B8G8R8>;
copyFuncs_[FORMAT_A1R5G5B5][FORMAT_A8B8G8R8] =
Copy<FORMAT_A1R5G5B5, FORMAT_A8B8G8R8>;
break;
case FORMAT_A4R4G4B4:
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_A8] =
Copy<FORMAT_A4R4G4B4, FORMAT_A8>;
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_L8] =
Copy<FORMAT_A4R4G4B4, FORMAT_L8>;
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_A8L8] =
Copy<FORMAT_A4R4G4B4, FORMAT_A8L8>;
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_R8G8B8] =
Copy<FORMAT_A4R4G4B4, FORMAT_R8G8B8>;
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_A8R8G8B8] =
Copy<FORMAT_A4R4G4B4, FORMAT_A8R8G8B8>;
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_R5G5B5A1] =
Copy<FORMAT_A4R4G4B4, FORMAT_R5G5B5A1>;
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_R4G4B4A4] =
Copy<FORMAT_A4R4G4B4, FORMAT_R4G4B4A4>;
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_B8G8R8] =
Copy<FORMAT_A4R4G4B4, FORMAT_B8G8R8>;
copyFuncs_[FORMAT_A4R4G4B4][FORMAT_A8B8G8R8] =
Copy<FORMAT_A4R4G4B4, FORMAT_A8B8G8R8>;
break;
case FORMAT_R8G8B8:
copyFuncs_[FORMAT_R8G8B8][FORMAT_L8] = Copy<FORMAT_R8G8B8, FORMAT_L8>;
copyFuncs_[FORMAT_R8G8B8][FORMAT_R5G6B5] =
Copy<FORMAT_R8G8B8, FORMAT_R5G6B5>;
copyFuncs_[FORMAT_R8G8B8][FORMAT_R8G8B8] = CopyFast<uint24_t>;
copyFuncs_[FORMAT_R8G8B8][FORMAT_B8G8R8] =
Copy<FORMAT_R8G8B8, FORMAT_B8G8R8>;
copyFuncs_[FORMAT_R8G8B8][FORMAT_A8B8G8R8] =
Copy<FORMAT_R8G8B8, FORMAT_A8B8G8R8>;
copyFuncs_[FORMAT_R8G8B8][FORMAT_A8R8G8B8] =
Copy<FORMAT_R8G8B8, FORMAT_A8R8G8B8>;
break;
case FORMAT_A8R8G8B8:
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_A8] =
Copy<FORMAT_A8R8G8B8, FORMAT_A8>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_L8] =
Copy<FORMAT_A8R8G8B8, FORMAT_L8>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_A8L8] =
Copy<FORMAT_A8R8G8B8, FORMAT_A8L8>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_R5G6B5] =
Copy<FORMAT_A8R8G8B8, FORMAT_R5G6B5>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_R8G8B8] =
Copy<FORMAT_A8R8G8B8, FORMAT_R8G8B8>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_A8R8G8B8] = CopyFast<uint32_t>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_R5G5B5A1] =
Copy<FORMAT_A8R8G8B8, FORMAT_R5G5B5A1>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_R4G4B4A4] =
Copy<FORMAT_A8R8G8B8, FORMAT_R4G4B4A4>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_B8G8R8] =
Copy<FORMAT_A8R8G8B8, FORMAT_B8G8R8>;
copyFuncs_[FORMAT_A8R8G8B8][FORMAT_A8B8G8R8] =
Copy<FORMAT_A8R8G8B8, FORMAT_A8B8G8R8>;
break;
case FORMAT_R5G5B5A1:
copyFuncs_[FORMAT_R5G5B5A1][FORMAT_A8] =
Copy<FORMAT_R5G5B5A1, FORMAT_A8>;
copyFuncs_[FORMAT_R5G5B5A1][FORMAT_L8] =
Copy<FORMAT_R5G5B5A1, FORMAT_L8>;
copyFuncs_[FORMAT_R5G5B5A1][FORMAT_A8L8] =
Copy<FORMAT_R5G5B5A1, FORMAT_A8L8>;
copyFuncs_[FORMAT_R5G5B5A1][FORMAT_RGB] =
Copy<FORMAT_R5G5B5A1, FORMAT_RGB>;
copyFuncs_[FORMAT_R5G5B5A1][FORMAT_ARGB] =
Copy<FORMAT_R5G5B5A1, FORMAT_ARGB>;
break;
case FORMAT_R4G4B4A4:
copyFuncs_[FORMAT_R4G4B4A4][FORMAT_A8] =
Copy<FORMAT_R4G4B4A4, FORMAT_A8>;
copyFuncs_[FORMAT_R4G4B4A4][FORMAT_L8] =
Copy<FORMAT_R4G4B4A4, FORMAT_L8>;
copyFuncs_[FORMAT_R4G4B4A4][FORMAT_A8L8] =
Copy<FORMAT_R4G4B4A4, FORMAT_A8L8>;
copyFuncs_[FORMAT_R4G4B4A4][FORMAT_RGB] =
Copy<FORMAT_R4G4B4A4, FORMAT_RGB>;
copyFuncs_[FORMAT_R4G4B4A4][FORMAT_ARGB] =
Copy<FORMAT_R4G4B4A4, FORMAT_ARGB>;
break;
case FORMAT_B8G8R8:
copyFuncs_[FORMAT_B8G8R8][FORMAT_L8] = Copy<FORMAT_B8G8R8, FORMAT_L8>;
copyFuncs_[FORMAT_B8G8R8][FORMAT_RGB] = Copy<FORMAT_B8G8R8, FORMAT_RGB>;
break;
case FORMAT_A8B8G8R8:
copyFuncs_[FORMAT_A8B8G8R8][FORMAT_A8] =
Copy<FORMAT_A8B8G8R8, FORMAT_A8>;
copyFuncs_[FORMAT_A8B8G8R8][FORMAT_L8] =
Copy<FORMAT_A8B8G8R8, FORMAT_L8>;
copyFuncs_[FORMAT_A8B8G8R8][FORMAT_A8L8] =
Copy<FORMAT_A8B8G8R8, FORMAT_A8L8>;
copyFuncs_[FORMAT_A8B8G8R8][FORMAT_RGB] =
Copy<FORMAT_A8B8G8R8, FORMAT_RGB>;
copyFuncs_[FORMAT_A8B8G8R8][FORMAT_ARGB] =
Copy<FORMAT_A8B8G8R8, FORMAT_ARGB>;
break;
}
}
}
PfnCopy get(uint32_t srcFormat, uint32_t dstFormat) const {
assert(srcFormat < FORMAT_COLOR_SIZE_);
assert(dstFormat < FORMAT_COLOR_SIZE_);
return copyFuncs_[srcFormat][dstFormat];
}
private:
template <ePixelFormat SrcFormat, ePixelFormat DstFormat>
static int Copy(const SurfaceDesc &dstDesc,
uint32_t dstOffsetX,
uint32_t dstOffsetY,
uint32_t copyWidth,
uint32_t copyHeight,
const SurfaceDesc &srcDesc,
uint32_t srcOffsetX,
uint32_t srcOffsetY) {
auto srcBPP = TFormatInfo<SrcFormat>::CBSIZE;
auto dstBPP = TFormatInfo<DstFormat>::CBSIZE;
auto srcNextLine = srcDesc.Pitch;
auto dstNextLine = dstDesc.Pitch;
auto pbSrc = srcDesc.pBits + srcOffsetX * srcBPP + srcOffsetY * srcDesc.Pitch;
auto pbDst = dstDesc.pBits + dstOffsetX * dstBPP + dstOffsetY * dstDesc.Pitch;
while (copyHeight--) {
auto pSrc = reinterpret_cast<const typename TFormatInfo<SrcFormat>::TYPE *>(pbSrc);
for (auto *pDst = reinterpret_cast<typename TFormatInfo<DstFormat>::TYPE *>(
pbDst),
*const pEnd = pDst + copyWidth;
pDst != pEnd; ++pDst, ++pSrc) {
auto tmp = Format::ConvertFrom<SrcFormat, true>(pSrc);
Format::ConvertTo<DstFormat>(pDst, tmp);
}
pbSrc += srcNextLine;
pbDst += dstNextLine;
}
return 0;
}
template <typename Type>
static int CopyFast(const SurfaceDesc &dstDesc,
uint32_t dstOffsetX,
uint32_t dstOffsetY,
uint32_t copyWidth,
uint32_t copyHeight,
const SurfaceDesc &srcDesc,
uint32_t srcOffsetX,
uint32_t srcOffsetY) {
auto nBPP = sizeof(Type);
auto srcNextLine = srcDesc.Pitch;
auto dstNextLine = dstDesc.Pitch;
auto pbSrc = srcDesc.pBits + srcOffsetX * nBPP + srcOffsetY * srcDesc.Pitch;
auto pbDst = dstDesc.pBits + dstOffsetX * nBPP + dstOffsetY * dstDesc.Pitch;
while (copyHeight--) {
auto pSrc = reinterpret_cast<const Type *>(pbSrc);
for (auto *pDst = reinterpret_cast<Type *>(pbDst), *const pEnd = pDst + copyWidth;
pDst != pEnd; ++pDst, ++pSrc) {
*pDst = *pSrc;
}
pbSrc += srcNextLine;
pbDst += dstNextLine;
}
return 0;
}
static int CopyInvalid(const SurfaceDesc & /*dstDesc*/,
uint32_t /*dstOffsetX*/,
uint32_t /*dstOffsetY*/,
uint32_t /*copyWidth*/,
uint32_t /*copyHeight*/,
const SurfaceDesc & /*srcDesc*/,
uint32_t /*srcOffsetX*/,
uint32_t /*srcOffsetY*/)
{
std::cout << "Error: invalid format" << std::endl;
return -1;
}
PfnCopy copyFuncs_[FORMAT_COLOR_SIZE_][FORMAT_COLOR_SIZE_];
};

View file

@ -1,68 +0,0 @@
//
// Copyright (c) Blaise Tine. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools
// installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR
// INDEMNITIES.
//
#pragma once
#include <cstdint>
#include <assert.h>
struct ColorARGB {
union {
struct {
uint32_t value;
};
struct {
uint8_t b, g, r, a;
};
struct {
uint8_t m[4];
};
};
ColorARGB() {}
ColorARGB(int a, int r, int g, int b) {
assert((a >= 0) && (a <= 0xff));
assert((r >= 0) && (r <= 0xff));
assert((g >= 0) && (g <= 0xff));
assert((b >= 0) && (b <= 0xff));
this->b = static_cast<uint8_t>(b);
this->g = static_cast<uint8_t>(g);
this->r = static_cast<uint8_t>(r);
this->a = static_cast<uint8_t>(a);
}
ColorARGB(int r, int g, int b) {
assert((r >= 0) && (r <= 0xff));
assert((g >= 0) && (g <= 0xff));
assert((b >= 0) && (b <= 0xff));
this->b = static_cast<uint8_t>(b);
this->g = static_cast<uint8_t>(g);
this->r = static_cast<uint8_t>(r);
}
ColorARGB(int value) {
this->value = value;
}
void operator=(const ColorARGB &rhs) {
this->value = rhs.value;
}
operator uint32_t() const {
return this->value;
}
};

View file

@ -15,7 +15,6 @@ typedef struct {
uint8_t src_logwidth;
uint8_t src_logheight;
uint32_t src_addr;
float lod;
uint32_t mip_offs[TEX_LOD_MAX+1];
uint32_t dst_width;
uint32_t dst_height;

File diff suppressed because it is too large Load diff

View file

@ -1,37 +0,0 @@
//
// Copyright (c) Blaise Tine. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools
// installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR
// INDEMNITIES.
//
#pragma once
#include <cstdint>
struct uint24_t {
uint8_t m[3];
explicit uint24_t(uint32_t value) {
m[0] = (value >> 0) & 0xff;
m[1] = (value >> 8) & 0xff;
m[2] = (value >> 16) & 0xff;
}
explicit uint24_t(uint8_t x, uint8_t y, uint8_t z) {
m[0] = x;
m[1] = y;
m[2] = z;
}
operator uint32_t() const {
return (m[2] << 16) | (m[1] << 8) | m[0];
}
};

View file

@ -10,6 +10,7 @@ typedef struct {
uint32_t tile_height;
float deltaX;
float deltaY;
float minification;
} tile_arg_t;
template <typename T, T Start, T End>
@ -35,10 +36,10 @@ void kernel_body(int task_id, tile_arg_t* arg) {
uint8_t* dst_ptr = (uint8_t*)(state->dst_addr + xoffset * state->dst_stride + yoffset * state->dst_pitch);
Fixed<16> xlod(state->lod);
Fixed<16> xj(arg->minification);
/*vx_printf("task_id=%d, deltaX=%f, deltaY=%f, tile_width=%d, tile_height=%d\n",
task_id, arg->deltaX, arg->deltaY, arg->tile_width, arg->tile_height);*/
/*vx_printf("task_id=%d, tile_width=%d, tile_height=%d, deltaX=%f, deltaY=%f, minification=%f\n",
task_id, arg->tile_width, arg->tile_height, arg->deltaX, arg->deltaY, arg->minification);*/
float fv = (yoffset + 0.5f) * arg->deltaY;
for (uint32_t y = 0; y < arg->tile_height; ++y) {
@ -47,13 +48,7 @@ void kernel_body(int task_id, tile_arg_t* arg) {
for (uint32_t x = 0; x < arg->tile_width; ++x) {
Fixed<TEX_FXD_FRAC> xu(fu);
Fixed<TEX_FXD_FRAC> xv(fv);
uint32_t color;
#ifdef ENABLE_SW
if (state->use_sw)
color = tex_load_sw(state, xu, xv, xlod);
else
#endif
color = tex_load_hw(state, xu, xv, xlod);
uint32_t color = tex_load(state, xu, xv, xj);
//vx_printf("task_id=%d, x=%d, y=%d, fu=%f, fv=%f, xu=0x%x, xv=0x%x, color=0x%x\n", task_id, x, y, fu, fv, xu.data(), xv.data(), color);
dst_row[x] = color;
fu += arg->deltaX;
@ -76,7 +71,7 @@ int main() {
csr_write(CSR_TEX(0, TEX_STATE_ADDR), arg->src_addr);
static_for_t<int, 0, TEX_LOD_MAX+1>()([&](int i) {
csr_write(CSR_TEX(0, TEX_STATE_MIPOFF(i)), arg->mip_offs[i]);
});
});
tile_arg_t targ;
targ.state = arg;
@ -84,6 +79,14 @@ int main() {
targ.tile_height = (arg->dst_height + arg->num_tasks - 1) / arg->num_tasks;
targ.deltaX = 1.0f / arg->dst_width;
targ.deltaY = 1.0f / arg->dst_height;
{
uint32_t src_width = (1 << arg->src_logwidth);
uint32_t src_height = (1 << arg->src_logheight);
float width_ratio = float(src_width) / arg->dst_width;
float height_ratio = float(src_height) / arg->dst_height;
targ.minification = std::max<float>(width_ratio, height_ratio);
}
vx_spawn_tasks(arg->num_tasks, (vx_spawn_tasks_cb)kernel_body, &targ);
/*for (uint32_t t=0; t < arg->num_tasks; ++t) {

File diff suppressed because it is too large Load diff

View file

@ -1,186 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Jan Solanti
*
* 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 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.
*/
#ifdef __cplusplus
extern "C" {
#endif
#pragma once
#if defined(_MSC_VER) && (_MSC_VER < 1600)
typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
#else
#include <stdlib.h>
#include <stdint.h>
#endif
typedef struct {
int32_t width;
int32_t height;
uint8_t channels;
uint8_t depth; /* must be 8 or 16 */
size_t dataSize;
uint8_t *data;
} LuImage;
typedef size_t (*PngReadProc)(void *outPtr, size_t size, size_t count, void *userPtr);
typedef size_t (*PngWriteProc)(const void *inPtr, size_t size, size_t count, void *userPtr);
typedef void* (*PngAllocProc)(size_t size, void *userPtr);
typedef void (*PngFreeProc)(void *ptr, void *userPtr);
typedef void (*PngWarnProc)(void *userPtr, const char *fmt, ...);
typedef struct {
/* loader */
PngReadProc readProc;
void *readProcUserPtr;
int skipSig;
/* writer */
PngWriteProc writeProc;
void *writeProcUserPtr;
int compressionLevel;
/* memory allocation */
PngAllocProc allocProc;
void *allocProcUserPtr;
PngFreeProc freeProc;
void *freeProcUserPtr;
/* warnings/error output */
PngWarnProc warnProc; /* set to NULL to disable output altogether */
void *warnProcUserPtr;
/* special case: avoid allocating a LuImage when loading or creating
* an image, just use this one */
LuImage *overrideImage;
} LuUserContext;
/**
* Initializes a LuUserContext to use the defaul malloc implementation.
*
* @param userCtx the LuUserContext to initialize
*/
void luUserContextInitDefault(LuUserContext *userCtx);
/**
* Creates a new Image object with the specified attributes.
* The data store of the Image is allocated but its contents are undefined.
* Only 8 and 16 bits deep images with 1-4 channels are supported.
*
* @param buffer pointer to an existing buffer (which may already contain the
* image data), or NULL to internally allocate a new buffer
* @param userCtx the user context (with the memory allocator function
* pointers to use), or NULL to use the default allocator
* (malloc).
*/
LuImage *luImageCreate(size_t width, size_t height, uint8_t channels, uint8_t depth,
uint8_t *buffer, const LuUserContext *usrCtx);
/**
* Releases the memory associated with the given Image object.
*
* @param userCtx the user context (with the memory deallocator function
* pointers to use), or NULL to use the default deallocator
* (free). The deallocator should match the ones used for
* allocation.
*/
void luImageRelease(LuImage *img, const LuUserContext *usrCtx);
/**
* Extracts the raw image buffer form a LuImage and releases the
* then-orphaned LuImage object. This can be used if you want to use
* the image data in your own structures.
*
* @param userCtx the user context (with the memory deallocator function
* pointers to use), or NULL to use the default deallocator
* (free). The deallocator should match the ones used for
* allocation.
*/
uint8_t *luImageExtractBufAndRelease(LuImage *img, const LuUserContext *userCtx);
/**
* Decodes a PNG image from a file
*
* @param filename the file name (optionally with full path) to read from.
* @param userCtx the user context (with the memory allocator function
* pointers to use), or NULL to use the default allocator
* (malloc).
*/
LuImage *luPngReadFile(const char *filename, LuUserContext *userCtx);
/**
* Decodes a PNG image with the provided read function into a LuImage struct
*
* @param readProc a function pointer to a user-defined function to use for
* reading the PNG data.
* @param userPtr an opaque pointer provided as an argument to readProc
* @param skipSig don't verify PNG signature - the bytes have already been
* removed from the input stream
*/
LuImage *luPngRead(PngReadProc readProc, void *userPtr, int skipSig);
/**
* Decodes a PNG image with the provided user context into a LuImage struct
*
* @param userCtx the LuUserContext to use
*/
LuImage *luPngReadUC(const LuUserContext *userCtx);
/**
* Encodes a LuImage struct to PNG and writes it out to a file.
*
* @param filename the file name (optionally with full path) to write to.
* Existing files will be overwritten!
* @param img the LuImage to encode
*/
int luPngWriteFile(const char *filename, const LuImage *img);
/**
* Encodes a LuImage struct to PNG and writes it out using a user-defined write
* function.
*
* @param writeProc a function pointer to a user-defined function that will be
* used for writing the final PNG data.
* @param userPtr an opaque pointer provided as an argument to writeProc
* @param img the LuImage to encode
*/
int luPngWrite(PngWriteProc writeProc, void *userPtr, const LuImage *img);
/**
* Encodes a LuImage struct to PNG and writes it out with the provided user
* context.
*
* @param userCtx the LuUserContext to use
* @param img the LuImage to encode
*/
int luPngWriteUC(const LuUserContext *userCtx, const LuImage *img);
#ifdef __cplusplus
}
#endif

View file

@ -9,6 +9,8 @@
#include "common.h"
#include "utils.h"
using namespace cocogfx;
#define RT_CHECK(_expr) \
do { \
int _ret = _expr; \
@ -29,7 +31,6 @@ int filter = 0; // 0-> point, 1->bilinear, 2->trilinear
float scale = 1.0f;
int format = 0;
bool use_sw = false;
float lod = 1.0f; // >= 1.0f
ePixelFormat eformat = FORMAT_A8R8G8B8;
vx_device_h device = nullptr;
@ -37,18 +38,18 @@ vx_buffer_h buffer = nullptr;
static void show_usage() {
std::cout << "Vortex Texture Test." << std::endl;
std::cout << "Usage: [-k: kernel] [-i image] [-o image] [-s scale] [-w wrap] [-f format] [-g filter] [-l lod] [-z no_hw] [-h: help]" << std::endl;
std::cout << "Usage: [-k: kernel] [-i image] [-o image] [-s scale] [-w wrap] [-f format] [-g filter] [-z no_hw] [-h: help]" << std::endl;
}
static void parse_args(int argc, char **argv) {
int c;
while ((c = getopt(argc, argv, "zi:o:k:w:f:g:h?")) != -1) {
while ((c = getopt(argc, argv, "zi:o:k:w:f:g:s:h?")) != -1) {
switch (c) {
case 'i':
input_file = optarg;
input_file = optarg;
break;
case 'o':
output_file = optarg;
output_file = optarg;
break;
case 's':
scale = std::stof(optarg, NULL);
@ -56,9 +57,6 @@ static void parse_args(int argc, char **argv) {
case 'w':
wrap = std::atoi(optarg);
break;
case 'l':
lod = std::stof(optarg, NULL);
break;
case 'z':
use_sw = true;
break;
@ -67,9 +65,11 @@ static void parse_args(int argc, char **argv) {
switch (format) {
case 0: eformat = FORMAT_A8R8G8B8; break;
case 1: eformat = FORMAT_R5G6B5; break;
case 2: eformat = FORMAT_R4G4B4A4; break;
case 3: eformat = FORMAT_L8; break;
case 4: eformat = FORMAT_A8; break;
case 2: eformat = FORMAT_A1R5G5B5; break;
case 3: eformat = FORMAT_A4R4G4B4; break;
case 4: eformat = FORMAT_A8L8; break;
case 5: eformat = FORMAT_L8; break;
case 6: eformat = FORMAT_A8; break;
default:
std::cout << "Error: invalid format: " << format << std::endl;
exit(1);
@ -105,7 +105,9 @@ void cleanup() {
int run_test(const kernel_arg_t& kernel_arg,
uint32_t buf_size,
uint32_t width,
uint32_t height) {
uint32_t height,
uint32_t bpp) {
(void)bpp;
auto time_start = std::chrono::high_resolution_clock::now();
// start device
@ -132,7 +134,7 @@ int run_test(const kernel_arg_t& kernel_arg,
// save output image
std::cout << "save output image" << std::endl;
//dump_image(dst_pixels, width, height, bpp);
//dump_image(dst_pixels, width, height, bpp);
RT_CHECK(SaveImage(output_file, FORMAT_A8R8G8B8, dst_pixels, width, height));
return 0;
@ -151,11 +153,9 @@ int main(int argc, char *argv[]) {
{
std::vector<uint8_t> staging;
RT_CHECK(LoadImage(input_file, eformat, staging, &src_width, &src_height));
RT_CHECK(GenerateMipmaps(src_pixels, mip_offsets, staging, eformat, src_width, src_height));
//uint32_t src_bpp = Format::GetInfo(eformat).BytePerPixel;
//dump_image(src_pixels, src_pixels.size() / src_bpp, 1, src_bpp);
uint32_t src_bpp = GetInfo(eformat).BytePerPixel;
//dump_image(staging, src_width, src_height, src_bpp);
RT_CHECK(GenerateMipmaps(src_pixels, mip_offsets, staging, eformat, src_width, src_height, src_width * src_bpp));
}
// check power of two support
@ -167,12 +167,6 @@ int main(int argc, char *argv[]) {
uint32_t src_logwidth = log2ceil(src_width);
uint32_t src_logheight = log2ceil(src_height);
uint32_t src_max_lod = std::max(src_logwidth, src_logheight);
if (lod > src_max_lod) {
std::cout << "Error: out-of-bound level-of-detail: lod=" << lod << ", source image=" << src_max_lod << std::endl;
return -1;
}
uint32_t src_bufsize = src_pixels.size();
uint32_t dst_width = (uint32_t)(src_width * scale);
@ -227,7 +221,6 @@ int main(int argc, char *argv[]) {
kernel_arg.src_logwidth = src_logwidth;
kernel_arg.src_logheight = src_logheight;
kernel_arg.src_addr = src_addr;
kernel_arg.lod = lod;
for (uint32_t i = 0; i < mip_offsets.size(); ++i) {
assert(i < TEX_LOD_MAX);
@ -267,7 +260,7 @@ int main(int argc, char *argv[]) {
// run tests
std::cout << "run tests" << std::endl;
RT_CHECK(run_test(kernel_arg, dst_bufsize, dst_width, dst_height));
RT_CHECK(run_test(kernel_arg, dst_bufsize, dst_width, dst_height, dst_bpp));
// cleanup
std::cout << "cleanup" << std::endl;

View file

@ -1,25 +0,0 @@
//
// Copyright (c) Blaise Tine. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools
// installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR
// INDEMNITIES.
//
#pragma once
#include "format.h"
struct SurfaceDesc {
ePixelFormat Format;
uint8_t *pBits;
uint32_t Width;
uint32_t Height;
uint32_t Pitch;
};

View file

@ -4,14 +4,30 @@
#include <texturing.h>
#include "common.h"
inline uint32_t texel_read(uint8_t* address, uint32_t stride) {
using namespace cocogfx;
inline void texel_read(uint32_t* texels,
uint8_t** addresses,
uint32_t count,
uint32_t stride) {
switch (stride) {
case 1: return *(uint8_t*)address;
case 2: return *(uint16_t*)address;
case 4: return *(uint32_t*)address;
case 1:
for (uint32_t i = 0; i < count; ++i) {
texels[i] = *(uint8_t*)addresses[i];
}
break;
case 2:
for (uint32_t i = 0; i < count; ++i) {
texels[i] = *(uint16_t*)addresses[i];
}
break;
case 4:
for (uint32_t i = 0; i < count; ++i) {
texels[i] = *(uint32_t*)addresses[i];
}
break;
default:
std::abort();
return 0;
}
}
@ -34,32 +50,35 @@ inline uint32_t vx_tex_sw(kernel_arg_t* state,
// addressing
uint32_t offset00, offset01, offset10, offset11;
uint32_t alpha, beta;
uint8_t* addr[4];
uint32_t texel[4];
TexAddressLinear(xu, xv, log_width, log_height, wrapu, wrapv,
&offset00, &offset01, &offset10, &offset11, &alpha, &beta);
uint8_t* addr00 = base_addr + offset00 * stride;
uint8_t* addr01 = base_addr + offset01 * stride;
uint8_t* addr10 = base_addr + offset10 * stride;
uint8_t* addr11 = base_addr + offset11 * stride;
addr[0] = base_addr + offset00 * stride;
addr[1] = base_addr + offset01 * stride;
addr[2] = base_addr + offset10 * stride;
addr[3] = base_addr + offset11 * stride;
// memory lookup
uint32_t texel00 = texel_read(addr00, stride);
uint32_t texel01 = texel_read(addr01, stride);
uint32_t texel10 = texel_read(addr10, stride);
uint32_t texel11 = texel_read(addr11, stride);
// memory fetch
texel_read(texel, addr, 4, stride);
// filtering
color = TexFilterLinear(
format, texel00, texel01, texel10, texel11, alpha, beta);
format, texel[0], texel[1], texel[2], texel[3], alpha, beta);
} else {
// addressing
uint32_t offset;
uint8_t* addr;
uint32_t texel;
TexAddressPoint(xu, xv, log_width, log_height, wrapu, wrapv, &offset);
uint8_t* addr = base_addr + offset * stride;
addr = base_addr + offset * stride;
// memory lookup
uint32_t texel = texel_read(addr, stride);
// memory fetch
texel_read(&texel, &addr, 1, stride);
// filtering
color = TexFilterPoint(format, texel);
@ -67,56 +86,40 @@ inline uint32_t vx_tex_sw(kernel_arg_t* state,
return color;
}
inline uint32_t tex_load_hw(kernel_arg_t* state,
Fixed<TEX_FXD_FRAC> xu,
Fixed<TEX_FXD_FRAC> xv,
Fixed<16> xlod) {
inline uint32_t tex_load(kernel_arg_t* state,
Fixed<TEX_FXD_FRAC> xu,
Fixed<TEX_FXD_FRAC> xv,
Fixed<16> xj) {
uint32_t color;
int32_t ilod = std::max<int32_t>(xlod.data(), Fixed<16>::ONE);
uint32_t lod = std::min<uint32_t>(log2floor(ilod) - 16, TEX_LOD_MAX);
uint32_t j = std::max<int32_t>(xj.data(), Fixed<16>::ONE);
uint32_t l = std::min<uint32_t>(log2floor(j) - 16, TEX_LOD_MAX);
if (state->filter == 2) {
uint32_t lod_n = std::min<uint32_t>(lod + 1, TEX_LOD_MAX);
uint32_t frac = ilod >> (lod + 16 - 8);
uint32_t texel0 = vx_tex(0, xu.data(), xv.data(), lod);
uint32_t texel1 = vx_tex(0, xu.data(), xv.data(), lod_n);
uint32_t ln = std::min<uint32_t>(l + 1, TEX_LOD_MAX);
uint32_t f = (j - (1 << (l + 16))) >> (l + 16 - 8);
uint32_t texel0, texel1;
if (state->use_sw) {
texel0 = vx_tex_sw(state, xu, xv, l);
texel1 = vx_tex_sw(state, xu, xv, ln);
} else {
texel0 = vx_tex(0, xu.data(), xv.data(), l);
texel1 = vx_tex(0, xu.data(), xv.data(), ln);
}
uint32_t cl, ch;
{
uint32_t c0l, c0h;
uint32_t c1l, c1h;
Unpack8888(TexFormat::R8G8B8A8, texel0, &c0l, &c0h);
Unpack8888(TexFormat::R8G8B8A8, texel1, &c1l, &c1h);
Lerp8888(c0l, c0h, c1l, c1h, frac, &cl, &ch);
uint32_t c0l, c0h, c1l, c1h;
Unpack8888(texel0, &c0l, &c0h);
Unpack8888(texel1, &c1l, &c1h);
cl = Lerp8888(c0l, c1l, f);
ch = Lerp8888(c0h, c1h, f);
}
color = Pack8888(TexFormat::R8G8B8A8, cl, ch);
color = Pack8888(cl, ch);
//vx_printf("j=0x%x, l=%d, ln=%d, f=%d, texel0=0x%x, texel1=0x%x, color=0x%x\n", j, l, ln, f, texel0, texel1, color);
} else {
color = vx_tex(0, xu.data(), xv.data(), lod);
}
return color;
}
inline uint32_t tex_load_sw(kernel_arg_t* state,
Fixed<TEX_FXD_FRAC> xu,
Fixed<TEX_FXD_FRAC> xv,
Fixed<16> xlod) {
uint32_t color;
int32_t ilod = std::max<int32_t>(xlod.data(), Fixed<16>::ONE);
uint32_t lod = std::min<uint32_t>(log2floor(ilod) - 16, TEX_LOD_MAX);
if (state->filter == 2) {
uint32_t lod_n = std::min<uint32_t>(lod + 1, TEX_LOD_MAX);
uint32_t frac = ilod >> (lod + 16 - 8);
uint32_t texel0 = vx_tex_sw(state, xu, xv, lod);
uint32_t texel1 = vx_tex_sw(state, xu, xv, lod_n);
uint32_t cl, ch;
{
uint32_t c0l, c0h;
uint32_t c1l, c1h;
Unpack8888(TexFormat::R8G8B8A8, texel0, &c0l, &c0h);
Unpack8888(TexFormat::R8G8B8A8, texel1, &c1l, &c1h);
Lerp8888(c0l, c0h, c1l, c1h, frac, &cl, &ch);
if (state->use_sw) {
color = vx_tex_sw(state, xu, xv, l);
} else {
color = vx_tex(0, xu.data(), xv.data(), l);
}
color = Pack8888(TexFormat::R8G8B8A8, cl, ch);
} else {
color = vx_tex_sw(state, xu, xv, lod);
}
return color;
}

View file

@ -1,122 +0,0 @@
#include "tga.h"
#include <fstream>
#include <iostream>
#include "format.h"
struct __attribute__((__packed__)) tga_header_t {
int8_t idlength;
int8_t colormaptype;
int8_t imagetype;
int16_t colormaporigin;
int16_t colormaplength;
int8_t colormapdepth;
int16_t xoffset;
int16_t yoffset;
int16_t width;
int16_t height;
int8_t bitsperpixel;
int8_t imagedescriptor;
};
int LoadTGA(const char *filename,
std::vector<uint8_t> &pixels,
uint32_t *width,
uint32_t *height,
uint32_t *bpp) {
std::ifstream ifs(filename, std::ios::in | std::ios::binary);
if (!ifs.is_open()) {
std::cerr << "couldn't open file: " << filename << "!" << std::endl;
return -1;
}
tga_header_t header;
ifs.read(reinterpret_cast<char *>(&header), sizeof(tga_header_t));
if (ifs.fail()) {
std::cerr << "invalid TGA file header!" << std::endl;
return -1;
}
if (header.imagetype != 2) {
std::cerr << "unsupported TGA encoding format!" << std::endl;
return -1;
}
ifs.seekg(header.idlength, std::ios::cur); // skip string
if (ifs.fail()) {
std::cerr << "invalid TGA file!" << std::endl;
return -1;
}
switch (header.bitsperpixel) {
case 16:
case 24:
case 32: {
// Read pixels data
auto stride = header.bitsperpixel / 8;
pixels.resize(stride * header.width * header.height);
ifs.read((char*)pixels.data(), pixels.size());
if (ifs.fail()) {
std::cerr << "invalid TGA file!" << std::endl;
return -1;
}
*bpp = stride;
break;
}
default:
std::cerr << "unsupported TGA bitsperpixel!" << std::endl;
return -1;
}
*width = header.width;
*height = header.height;
return 0;
}
int SaveTGA(const char *filename,
const std::vector<uint8_t> &pixels,
uint32_t width,
uint32_t height,
uint32_t bpp) {
std::ofstream ofs(filename, std::ios::out | std::ios::binary);
if (!ofs.is_open()) {
std::cerr << "couldn't create file: " << filename << "!" << std::endl;
return -1;
}
if (bpp < 2 || bpp > 4) {
std::cerr << "unsupported pixel stride: " << bpp << "!" << std::endl;
return -1;
}
tga_header_t header;
header.idlength = 0;
header.colormaptype = 0; // no palette
header.imagetype = 2; // color mapped data
header.colormaporigin = 0;
header.colormaplength = 0;
header.colormapdepth = 0;
header.xoffset = 0;
header.yoffset = 0;
header.width = width;
header.height = height;
header.bitsperpixel = bpp * 8;
header.imagedescriptor = 0;
// write header
ofs.write(reinterpret_cast<char *>(&header), sizeof(tga_header_t));
// write pixel data
uint32_t pitch = bpp * width;
const uint8_t* pixel_bytes = pixels.data() + (height - 1) * pitch;
for (uint32_t y = 0; y < height; ++y) {
const uint8_t* pixel_row = pixel_bytes;
for (uint32_t x = 0; x < width; ++x) {
ofs.write((const char*)pixel_row, bpp);
pixel_row += bpp;
}
pixel_bytes -= pitch;
}
return 0;
}

View file

@ -1,14 +0,0 @@
#include <cstdint>
#include <vector>
int LoadTGA(const char *filename,
std::vector<uint8_t> &pixels,
uint32_t *width,
uint32_t *height,
uint32_t *bpp);
int SaveTGA(const char *filename,
const std::vector<uint8_t> &pixels,
uint32_t width,
uint32_t height,
uint32_t bpp);

View file

@ -1,10 +1,12 @@
#include "utils.h"
#include <assert.h>
#include <cstring>
#include "blitter.h"
#include "format.h"
#include "tga.h"
#include "lupng.h"
#include <string>
#include <iostream>
#include <iomanip>
#include <tga.h>
#include <png.h>
using namespace cocogfx;
std::string getFileExt(const std::string& str) {
auto i = str.rfind('.');
@ -41,22 +43,9 @@ int LoadImage(const char *filename,
return ret;
} else
if (iequals(ext, "png")) {
auto image = luPngReadFile(filename, NULL);
if (image == NULL)
return -1;
if (image->depth != 8
|| (image->channels != 3
&& image->channels != 4)) {
luImageRelease(image, NULL);
std::cerr << "invalid png file format!" << std::endl;
return -1;
}
pixels.resize(image->channels * image->width * image->height);
memcpy(pixels.data(), image->data, pixels.size());
img_width = image->width;
img_height = image->height;
img_bpp = image->channels;
luImageRelease(image, NULL);
int ret = LoadPNG(filename, pixels, &img_width, &img_height, &img_bpp);
if (ret)
return ret;
} else {
std::cerr << "invalid file extension: " << ext << "!" << std::endl;
return -1;
@ -83,7 +72,7 @@ int LoadImage(const char *filename,
if (img_format != format) {
// format conversion to RGBA
std::vector<uint8_t> staging;
int ret = ConvertImage(staging, pixels, img_width, img_height, img_format, format);
int ret = ConvertImage(staging, format, pixels, img_format, img_width, img_height, img_width * img_bpp);
if (ret)
return ret;
pixels.swap(staging);
@ -100,19 +89,13 @@ int SaveImage(const char *filename,
const std::vector<uint8_t> &pixels,
uint32_t width,
uint32_t height) {
uint32_t bpp = Format::GetInfo(format).BytePerPixel;
uint32_t bpp = GetInfo(format).BytePerPixel;
auto ext = getFileExt(filename);
if (iequals(ext, "tga")) {
return SaveTGA(filename, pixels, width, height, bpp);
} else
if (iequals(ext, "png")) {
LuImage image;
image.width = width;
image.height = height;
image.depth = 8;
image.channels = bpp;
image.data = (uint8_t*)pixels.data();
return luPngWriteFile(filename, &image);
return SavePNG(filename, pixels, width, height, bpp);
} else {
std::cerr << "invalid file extension: " << ext << "!" << std::endl;
return -1;
@ -132,171 +115,8 @@ void dump_image(const std::vector<uint8_t>& pixels, uint32_t width, uint32_t hei
pixel32 |= pixel8 << (b * 8);
}
if (x) std::cout << ", ";
std::cout << std::hex << pixel32;
std::cout << std::hex << std::setw(bpp * 2) << std::setfill('0') << pixel32;
}
std::cout << std::endl;
}
}
int CopyBuffers(SurfaceDesc &dstDesc,
int32_t dstOffsetX,
int32_t dstOffsetY,
uint32_t copyWidth,
uint32_t copyHeight,
const SurfaceDesc &srcDesc,
int32_t srcOffsetX,
int32_t srcOffsetY) {
static const BlitTable s_blitTable;
if ((srcOffsetX >= (int32_t)srcDesc.Width) || (srcOffsetY >= (int32_t)srcDesc.Height) ||
(dstOffsetX >= (int32_t)dstDesc.Width) || (dstOffsetY >= (int32_t)dstDesc.Height)) {
return -1;
}
if (copyWidth > dstDesc.Width) {
copyWidth = dstDesc.Width;
}
if (copyWidth > srcDesc.Width) {
copyWidth = srcDesc.Width;
}
if (copyHeight > dstDesc.Height) {
copyHeight = dstDesc.Height;
}
if (copyHeight > srcDesc.Height) {
copyHeight = srcDesc.Height;
}
return s_blitTable.get(srcDesc.Format, dstDesc.Format)(
dstDesc, dstOffsetX, dstOffsetY, copyWidth, copyHeight, srcDesc,
srcOffsetX, srcOffsetY);
}
int ConvertImage(std::vector<uint8_t>& dst_pixels,
const std::vector<uint8_t>& src_pixels,
uint32_t width,
uint32_t height,
ePixelFormat src_format,
ePixelFormat dst_format) {
uint32_t src_pitch = Format::GetInfo(src_format).BytePerPixel * width;
uint32_t dst_pitch = Format::GetInfo(dst_format).BytePerPixel * width;
dst_pixels.resize(dst_pitch * height);
SurfaceDesc srcDesc{src_format, (uint8_t*)src_pixels.data(), width, height, src_pitch};
SurfaceDesc dstDesc{dst_format, dst_pixels.data(), width, height, dst_pitch};
return CopyBuffers(dstDesc, 0, 0, width, height, srcDesc, 0, 0);
}
int GenerateMipmaps(std::vector<uint8_t>& dst_pixels,
std::vector<uint32_t>& mip_offsets,
const std::vector<uint8_t>& src_pixels,
ePixelFormat format,
uint32_t src_width,
uint32_t src_height) {
std::vector<uint8_t> src_staging, dst_staging;
const std::vector<uint8_t> *pSrcPixels;
std::vector<uint8_t> *pDstPixels;
// convert source image if needed
bool need_conversion = (format != FORMAT_A8R8G8B8);
if (need_conversion) {
ConvertImage(src_staging, src_pixels, src_width, src_height, format, FORMAT_A8R8G8B8);
pSrcPixels = &src_staging;
pDstPixels = &dst_staging;
} else {
pSrcPixels = &src_pixels;
pDstPixels = &dst_pixels;
}
uint32_t src_logwidth = log2ceil(src_width);
uint32_t src_logheight = log2ceil(src_height);
uint32_t max_lod = std::max(src_logwidth, src_logheight) + 1;
mip_offsets.resize(max_lod);
// Calculate mipmaps buffer size
uint32_t dst_height = 1;
uint32_t dst_width = 0;
for (uint32_t lod = 0, w = src_width, h = src_height; lod < max_lod; ++lod) {
assert((w > 0) || (w > 0));
uint32_t pw = std::max<int>(w, 1);
uint32_t ph = std::max<int>(h, 1);
mip_offsets.at(lod) = dst_width;
dst_width += pw * ph;
w >>= 1;
h >>= 1;
}
// allocate mipmap
pDstPixels->resize(dst_width * 4);
// generate mipmaps
{
auto pSrc = reinterpret_cast<const uint32_t*>(pSrcPixels->data());
auto pDst = reinterpret_cast<uint32_t*>(pDstPixels->data());
// copy level 0
memcpy(pDst, pSrc, pSrcPixels->size());
assert(pSrcPixels->size() == 4 * src_width * src_height);
pSrc = pDst;
pDst += src_width * src_height;
// copy lower levels
for (uint32_t lod = 1, w = (src_width/2), h = (src_height/2); lod < max_lod;) {
assert((w > 0) || (w > 0));
uint32_t pw = std::max<int>(w, 1);
uint32_t ph = std::max<int>(h, 1);
for (uint32_t y = 0; y < pw; ++y) {
auto v0 = 2 * y;
auto v1 = 2 * y + ((ph > 1) ? 1 : 0);
auto pSrc0 = pSrc + v0 * (2 * pw);
auto pSrc1 = pSrc + v1 * (2 * pw);
for (uint32_t x = 0; x <pw; ++x) {
auto u0 = 2 * x;
auto u1 = 2 * x + ((pw > 1) ? 1 : 0);
auto c00 = Format::ConvertFrom<FORMAT_A8R8G8B8, false>(pSrc0 + u0);
auto c01 = Format::ConvertFrom<FORMAT_A8R8G8B8, false>(pSrc0 + u1);
auto c10 = Format::ConvertFrom<FORMAT_A8R8G8B8, false>(pSrc1 + u0);
auto c11 = Format::ConvertFrom<FORMAT_A8R8G8B8, false>(pSrc1 + u1);
const ColorARGB color((c00.a + c01.a + c10.a + c11.a+2) >> 2,
(c00.r + c01.r + c10.r + c11.r+2) >> 2,
(c00.g + c01.g + c10.g + c11.g+2) >> 2,
(c00.b + c01.b + c10.b + c11.b+2) >> 2);
uint32_t ncolor;
Format::ConvertTo<FORMAT_A8R8G8B8>(&ncolor, color);
pDst[x + y * pw] = ncolor;
}
}
++lod;
pSrc = pDst;
pDst += pw * ph;
w >>= 1;
h >>= 1;
}
assert((pDst - reinterpret_cast<uint32_t*>(pDstPixels->data())) == dst_width);
}
// convert destination image if needed
if (need_conversion) {
ConvertImage(dst_staging, dst_staging, dst_width, dst_height, FORMAT_A8R8G8B8, format);
}
uint32_t bpp = Format::GetInfo(format).BytePerPixel;
for (auto& offset : mip_offsets) {
offset *= bpp;
}
return 0;
}

View file

@ -1,44 +1,21 @@
#include <cstdint>
#include <vector>
#include <iostream>
#include <format.h>
#include <blitter.h>
#include <bitmanip.h>
#include "surfacedesc.h"
int LoadImage(const char *filename,
ePixelFormat format,
cocogfx::ePixelFormat format,
std::vector<uint8_t> &pixels,
uint32_t *width,
uint32_t *height);
int SaveImage(const char *filename,
ePixelFormat format,
cocogfx::ePixelFormat format,
const std::vector<uint8_t> &pixels,
uint32_t width,
uint32_t height);
int CopyBuffers(SurfaceDesc &dstDesc,
int32_t dstOffsetX,
int32_t dstOffsetY,
uint32_t copyWidth,
uint32_t copyHeight,
const SurfaceDesc &srcDesc,
int32_t srcOffsetX,
int32_t srcOffsetY);
int ConvertImage(std::vector<uint8_t>& dst_pixels,
const std::vector<uint8_t>& src_pixels,
uint32_t width,
uint32_t height,
ePixelFormat src_format,
ePixelFormat dst_format);
int GenerateMipmaps(std::vector<uint8_t>& dst_pixels,
std::vector<uint32_t>& mip_offsets,
const std::vector<uint8_t>& src_pixels,
ePixelFormat format,
uint32_t src_width,
uint32_t src_height);
void dump_image(const std::vector<uint8_t>& pixels,
uint32_t width,
uint32_t height,

15
third_party/Makefile vendored Normal file
View file

@ -0,0 +1,15 @@
all: fpnew cocogfx softfloat
fpnew:
cocogfx:
$(MAKE) -C cocogfx
softfloat:
SPECIALIZE_TYPE=RISCV SOFTFLOAT_OPTS="-fPIC -DSOFTFLOAT_ROUND_ODD -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32" $(MAKE) -C softfloat/build/Linux-x86_64-GCC
clean:
$(MAKE) clean -C cocogfx
$(MAKE) -C softfloat/build/Linux-x86_64-GCC clean
.PHONY: all fpnew cocogfx softfloat