diff --git a/hw/rtl/tex_unit/VX_tex_lsu_arb.v b/hw/rtl/tex_unit/VX_tex_lsu_arb.v deleted file mode 100644 index 04e742e8..00000000 --- a/hw/rtl/tex_unit/VX_tex_lsu_arb.v +++ /dev/null @@ -1,128 +0,0 @@ -`include "../cache/VX_cache_define.vh" - -module VX_tex_lsu_arb #( - parameter NUM_REQS = 1, - parameter LANES = 1, - parameter WORD_SIZE = 1, - parameter TAG_IN_WIDTH = 1, - parameter TAG_OUT_WIDTH = 1, - parameter LOG_NUM_REQS = `CLOG2(NUM_REQS) -) ( - input wire clk, - input wire reset, - - // input requests - input wire [NUM_REQS-1:0][LANES-1:0] req_valid_in, - input wire [NUM_REQS-1:0][LANES-1:0] req_rw_in, - input wire [NUM_REQS-1:0][LANES-1:0][WORD_SIZE-1:0] req_byteen_in, - input wire [NUM_REQS-1:0][LANES-1:0][`WORD_ADDR_WIDTH-1:0] req_addr_in, - input wire [NUM_REQS-1:0][LANES-1:0][`WORD_WIDTH-1:0] req_data_in, - input wire [NUM_REQS-1:0][LANES-1:0][TAG_IN_WIDTH-1:0] req_tag_in, - output wire [NUM_REQS-1:0][LANES-1:0] req_ready_in, - - // output request - output wire [LANES-1:0] req_valid_out, - output wire [LANES-1:0] req_rw_out, - output wire [LANES-1:0][WORD_SIZE-1:0] req_byteen_out, - output wire [LANES-1:0][`WORD_ADDR_WIDTH-1:0] req_addr_out, - output wire [LANES-1:0][`WORD_WIDTH-1:0] req_data_out, - output wire [LANES-1:0][TAG_OUT_WIDTH-1:0] req_tag_out, - input wire [LANES-1:0] req_ready_out, - - // input response - input wire [LANES-1:0] rsp_valid_in, - input wire [LANES-1:0][`WORD_WIDTH-1:0] rsp_data_in, - input wire [TAG_OUT_WIDTH-1:0] rsp_tag_in, - output wire rsp_ready_in, - - // output responses - output wire [NUM_REQS-1:0][LANES-1:0] rsp_valid_out, - output wire [NUM_REQS-1:0][LANES-1:0][`WORD_WIDTH-1:0] rsp_data_out, - output wire [NUM_REQS-1:0][TAG_IN_WIDTH-1:0] rsp_tag_out, - input wire [NUM_REQS-1:0] rsp_ready_out -); - localparam REQ_DATAW = LANES * (1 + TAG_IN_WIDTH + `WORD_ADDR_WIDTH + 1 + WORD_SIZE + `WORD_WIDTH); - - if (NUM_REQS > 1) begin - - wire [NUM_REQS-1:0][REQ_DATAW-1:0] req_merged_data_in; - wire [NUM_REQS-1:0] req_valid_in_any; - - for (genvar i = 0; i < NUM_REQS; i++) begin - assign req_merged_data_in[i] = {req_valid_in[i], req_tag_in[i], req_addr_in[i], req_rw_in[i], req_byteen_in[i], req_data_in[i]}; - assign req_valid_in_any[i] = (| req_valid_in[i]); - end - - wire sel_valid; - wire [LOG_NUM_REQS-1:0] sel_idx; - wire [NUM_REQS-1:0] sel_1hot; - - wire sel_enable = (| req_ready_out); - - VX_rr_arbiter #( - .NUM_REQS(NUM_REQS), - .LOCK_ENABLE(1) - ) sel_arb ( - .clk (clk), - .reset (reset), - .requests (req_valid_in_any), - .enable (sel_enable), - .grant_valid (sel_valid), - .grant_index (sel_idx), - .grant_onehot (sel_1hot) - ); - - wire [LANES-1:0] req_valid_out_unqual; - wire [LANES-1:0][TAG_IN_WIDTH-1:0] req_tag_out_unqual; - - assign {req_valid_out_unqual, req_tag_out_unqual, req_addr_out, req_rw_out, req_byteen_out, req_data_out} = req_merged_data_in[sel_idx]; - - assign req_valid_out = req_valid_out_unqual & {LANES{sel_valid}}; - - for (genvar i = 0; i < LANES; i++) begin - assign req_tag_out[i] = {req_tag_out_unqual[i], sel_idx}; - end - - for (genvar i = 0; i < NUM_REQS; i++) begin - assign req_ready_in[i] = req_ready_out & {LANES{sel_1hot[i]}}; - end - - /////////////////////////////////////////////////////////////////////// - - wire [LOG_NUM_REQS-1:0] rsp_sel = rsp_tag_in[LOG_NUM_REQS-1:0]; - - reg [NUM_REQS-1:0][LANES-1:0] rsp_valid_out_unqual; - always @(*) begin - rsp_valid_out_unqual = '0; - rsp_valid_out_unqual[rsp_sel] = rsp_valid_in; - end - assign rsp_valid_out = rsp_valid_out_unqual; - - for (genvar i = 0; i < NUM_REQS; i++) begin - assign rsp_data_out[i] = rsp_data_in; - assign rsp_tag_out[i] = rsp_tag_in[LOG_NUM_REQS +: TAG_IN_WIDTH]; - end - - assign rsp_ready_in = rsp_ready_out[rsp_sel]; - - end else begin - - `UNUSED_VAR (clk) - `UNUSED_VAR (reset) - - assign req_valid_out = req_valid_in; - assign req_tag_out = req_tag_in; - assign req_addr_out = req_addr_in; - assign req_rw_out = req_rw_in; - assign req_byteen_out = req_byteen_in; - assign req_data_out = req_data_in; - assign req_ready_in = req_ready_out; - - assign rsp_valid_out = rsp_valid_in; - assign rsp_tag_out = rsp_tag_in; - assign rsp_data_out = rsp_data_in; - assign rsp_ready_in = rsp_ready_out; - - end - -endmodule \ No newline at end of file diff --git a/tests/regression/tex/Makefile b/tests/regression/tex/Makefile index 25cd1f61..a4d2b32c 100644 --- a/tests/regression/tex/Makefile +++ b/tests/regression/tex/Makefile @@ -19,13 +19,15 @@ 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 -LDFLAGS += -L$(VORTEX_DRV_PATH)/stub -lvortex +LDFLAGS += -L$(VORTEX_DRV_PATH)/stub -lvortex -lz PROJECT = tex -SRCS = main.cpp utils.cpp +SRCS = main.cpp utils.cpp tga.cpp lupng.c all: $(PROJECT) kernel.bin kernel.dump diff --git a/tests/regression/tex/flower.tga b/tests/regression/tex/earth.png similarity index 59% rename from tests/regression/tex/flower.tga rename to tests/regression/tex/earth.png index 94c9c57d..d329a0aa 100644 Binary files a/tests/regression/tex/flower.tga and b/tests/regression/tex/earth.png differ diff --git a/tests/regression/tex/earth.tga b/tests/regression/tex/earth.tga deleted file mode 100644 index 3c6782e1..00000000 Binary files a/tests/regression/tex/earth.tga and /dev/null differ diff --git a/tests/regression/tex/flower.png b/tests/regression/tex/flower.png new file mode 100644 index 00000000..29468a86 Binary files /dev/null and b/tests/regression/tex/flower.png differ diff --git a/tests/regression/tex/football.tga b/tests/regression/tex/football.tga deleted file mode 100644 index a5544ec7..00000000 Binary files a/tests/regression/tex/football.tga and /dev/null differ diff --git a/tests/regression/tex/main.cpp b/tests/regression/tex/main.cpp index b57f18e4..39ffea0c 100644 --- a/tests/regression/tex/main.cpp +++ b/tests/regression/tex/main.cpp @@ -22,8 +22,8 @@ /////////////////////////////////////////////////////////////////////////////// const char* kernel_file = "kernel.bin"; -const char* input_file = "palette64.tga"; -const char* output_file = "output.tga"; +const char* input_file = "palette64.png"; +const char* output_file = "output.png"; int wrap = 0; int filter = 0; float scale = 1.0f; @@ -101,8 +101,7 @@ void cleanup() { int run_test(const kernel_arg_t& kernel_arg, uint32_t buf_size, uint32_t width, - uint32_t height, - uint32_t bpp) { + uint32_t height) { auto time_start = std::chrono::high_resolution_clock::now(); // start device @@ -130,7 +129,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); - RT_CHECK(SaveTGA(output_file, dst_pixels, width, height, bpp)); + RT_CHECK(SaveImage(output_file, FORMAT_A8R8G8B8, dst_pixels, width, height)); return 0; } @@ -140,13 +139,11 @@ int main(int argc, char *argv[]) { std::vector src_pixels; uint32_t src_width; uint32_t src_height; - uint32_t src_bpp; - + // parse command arguments parse_args(argc, argv); - std::vector tmp_pixels; - RT_CHECK(LoadTGA(input_file, tmp_pixels, &src_width, &src_height)); + RT_CHECK(LoadImage(input_file, eformat, src_pixels, &src_width, &src_height)); // check power of two support if (!ISPOW2(src_width) || !ISPOW2(src_height)) { @@ -154,8 +151,7 @@ int main(int argc, char *argv[]) { return -1; } - RT_CHECK(ConvertImage(src_pixels, tmp_pixels, src_width, src_height, FORMAT_A8R8G8B8, eformat)); - src_bpp = Format::GetInfo(eformat).BytePerPixel; + uint32_t src_bpp = Format::GetInfo(eformat).BytePerPixel; //dump_image(src_pixels, src_width, src_height, src_bpp); @@ -248,7 +244,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, dst_bpp)); + RT_CHECK(run_test(kernel_arg, dst_bufsize, dst_width, dst_height)); // cleanup std::cout << "cleanup" << std::endl; diff --git a/tests/regression/tex/palette16.png b/tests/regression/tex/palette16.png new file mode 100644 index 00000000..34ab80d5 Binary files /dev/null and b/tests/regression/tex/palette16.png differ diff --git a/tests/regression/tex/palette16.tga b/tests/regression/tex/palette16.tga deleted file mode 100644 index 2653f445..00000000 Binary files a/tests/regression/tex/palette16.tga and /dev/null differ diff --git a/tests/regression/tex/palette4.png b/tests/regression/tex/palette4.png new file mode 100644 index 00000000..be0979e1 Binary files /dev/null and b/tests/regression/tex/palette4.png differ diff --git a/tests/regression/tex/palette4.tga b/tests/regression/tex/palette4.tga deleted file mode 100644 index c342c47f..00000000 Binary files a/tests/regression/tex/palette4.tga and /dev/null differ diff --git a/tests/regression/tex/palette64.png b/tests/regression/tex/palette64.png new file mode 100644 index 00000000..aa497e3e Binary files /dev/null and b/tests/regression/tex/palette64.png differ diff --git a/tests/regression/tex/palette64.tga b/tests/regression/tex/palette64.tga deleted file mode 100644 index ea9bcd97..00000000 Binary files a/tests/regression/tex/palette64.tga and /dev/null differ diff --git a/tests/regression/tex/rainbow.png b/tests/regression/tex/rainbow.png new file mode 100644 index 00000000..ec0c117b Binary files /dev/null and b/tests/regression/tex/rainbow.png differ diff --git a/tests/regression/tex/rainbow.tga b/tests/regression/tex/rainbow.tga deleted file mode 100644 index 0250201d..00000000 Binary files a/tests/regression/tex/rainbow.tga and /dev/null differ diff --git a/tests/regression/tex/soccer.png b/tests/regression/tex/soccer.png new file mode 100644 index 00000000..5d57ee82 Binary files /dev/null and b/tests/regression/tex/soccer.png differ diff --git a/tests/regression/tex/toad.png b/tests/regression/tex/toad.png new file mode 100644 index 00000000..fe82cad7 Binary files /dev/null and b/tests/regression/tex/toad.png differ diff --git a/tests/regression/tex/toad.tga b/tests/regression/tex/toad.tga deleted file mode 100644 index 1903c5c3..00000000 Binary files a/tests/regression/tex/toad.tga and /dev/null differ diff --git a/tests/regression/tex/utils.cpp b/tests/regression/tex/utils.cpp index 46f0862c..8a2ff760 100644 --- a/tests/regression/tex/utils.cpp +++ b/tests/regression/tex/utils.cpp @@ -1,146 +1,123 @@ #include "utils.h" -#include #include +#include +#include "blitter.h" #include "format.h" +#include "tga.h" +#include "lupng.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; -}; +std::string getFileExt(const std::string& str) { + auto i = str.rfind('.'); + if (i != std::string::npos) { + return str.substr(i+1); + } + return(""); +} -int LoadTGA(const char *filename, - std::vector &pixels, - uint32_t *width, - uint32_t *height) { - 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; - } +bool iequals(const std::string& a, const std::string& b) { + auto sz = a.size(); + if (b.size() != sz) + return false; + for (size_t i = 0; i < sz; ++i) { + if (tolower(a[i]) != tolower(b[i])) + return false; + } + return true; +} - tga_header_t header; - ifs.read(reinterpret_cast(&header), sizeof(tga_header_t)); - if (ifs.fail()) { - std::cerr << "invalid TGA file header!" << std::endl; - return -1; - } +int LoadImage(const char *filename, + ePixelFormat format, + std::vector &pixels, + uint32_t *width, + uint32_t *height) { + uint32_t img_width; + uint32_t img_height; + uint32_t img_bpp; - 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: { - auto stride = header.bitsperpixel / 8; - std::vector staging(stride * header.width * header.height); - - // Read pixels data - ifs.read((char*)staging.data(), staging.size()); - if (ifs.fail()) { - std::cerr << "invalid TGA file!" << std::endl; + auto ext = getFileExt(filename); + if (iequals(ext, "tga")) { + int ret = LoadTGA(filename, pixels, &img_width, &img_height, &img_bpp); + if (ret) + 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; } - - // format conversion to RGBA - pixels.resize(4 * header.width * header.height); - const uint8_t* src_bytes = staging.data(); - uint32_t* dst_bytes = (uint32_t*)pixels.data(); - for (const uint8_t* const src_end = src_bytes + staging.size(); - src_bytes != src_end; - src_bytes += stride) { - ColorARGB color; - switch (stride) { - case 2: - color = Format::ConvertFrom(src_bytes); - break; - case 3: - color = Format::ConvertFrom(src_bytes); - break; - case 4: - color = Format::ConvertFrom(src_bytes); - break; - default: - std::abort(); - } - *dst_bytes++ = color; - } - break; - } - default: - std::cerr << "unsupported TGA bitsperpixel!" << std::endl; + 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); + } else { + std::cerr << "invalid file extension: " << ext << "!" << std::endl; return -1; - } + } - *width = header.width; - *height = header.height; + ePixelFormat img_format; + switch (img_bpp) { + case 1: + img_format = FORMAT_A8; + break; + case 2: + img_format = FORMAT_A1R5G5B5; + break; + case 3: + img_format = FORMAT_R8G8B8; + break; + case 4: + img_format = FORMAT_A8R8G8B8; + break; + default: + std::abort(); + } + if (img_format != format) { + // format conversion to RGBA + std::vector staging; + int ret = ConvertImage(staging, pixels, img_width, img_height, img_format, format); + if (ret) + return ret; + pixels.swap(staging); + } + + *width = img_width; + *height = img_height; + return 0; } -int SaveTGA(const char *filename, - const std::vector &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; +int SaveImage(const char *filename, + ePixelFormat format, + const std::vector &pixels, + uint32_t width, + uint32_t height) { + uint32_t bpp = Format::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); + } else { + std::cerr << "invalid file extension: " << ext << "!" << 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(&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; } diff --git a/tests/regression/tex/utils.h b/tests/regression/tex/utils.h index 2e7f7d7c..48b1ad55 100644 --- a/tests/regression/tex/utils.h +++ b/tests/regression/tex/utils.h @@ -1,7 +1,7 @@ #include #include #include -#include "blitter.h" +#include "surfacedesc.h" #define ISPOW2(x) (((x) != 0) && (0 == ((x) & ((x) - 1)))) @@ -9,16 +9,17 @@ inline uint32_t ilog2 (uint32_t value) { return (uint32_t)(sizeof(uint32_t) * 8UL) - (uint32_t)__builtin_clzl((value << 1) - 1UL) - 1; } -int LoadTGA(const char *filename, - std::vector &pixels, - uint32_t *width, - uint32_t *height); +int LoadImage(const char *filename, + ePixelFormat format, + std::vector &pixels, + uint32_t *width, + uint32_t *height); -int SaveTGA(const char *filename, - const std::vector &pixels, - uint32_t width, - uint32_t height, - uint32_t bpp); +int SaveImage(const char *filename, + ePixelFormat format, + const std::vector &pixels, + uint32_t width, + uint32_t height); int CopyBuffers(SurfaceDesc &dstDesc, int32_t dstOffsetX,