From 951c516615eb04b1e676927eff54bcfc531e91aa Mon Sep 17 00:00:00 2001 From: Krishna Yalamarthy Date: Tue, 13 Apr 2021 06:29:20 -0400 Subject: [PATCH 1/2] minor format change ; tex demo copy image added --- driver/tests/tex_demo/main.cpp | 19 +++++++++--- driver/tests/tex_demo/utils.cpp | 54 +++++++++++++++++++++++++++++++++ driver/tests/tex_demo/utils.h | 8 +++++ hw/rtl/tex_unit/VX_tex_format.v | 14 ++++----- 4 files changed, 84 insertions(+), 11 deletions(-) diff --git a/driver/tests/tex_demo/main.cpp b/driver/tests/tex_demo/main.cpp index 60b74867..e6544d95 100644 --- a/driver/tests/tex_demo/main.cpp +++ b/driver/tests/tex_demo/main.cpp @@ -25,18 +25,19 @@ const char* output_file = "output.tga"; int wrap = 0; int filter = 0; float scale = 1.0f; +int format = 0; vx_device_h device = nullptr; 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 filter] [-h: help]" << std::endl; + std::cout << "Usage: [-k: kernel] [-i image] [-o image] [-s scale] [-w wrap] [-f format] [-g filter] [-h: help]" << std::endl; } static void parse_args(int argc, char **argv) { int c; - while ((c = getopt(argc, argv, "i:o:k:w:f:h?")) != -1) { + while ((c = getopt(argc, argv, "i:o:k:w:f:g:h?")) != -1) { switch (c) { case 'i': input_file = optarg; @@ -51,6 +52,9 @@ static void parse_args(int argc, char **argv) { wrap = std::atoi(optarg); break; case 'f': + format = std::atoi(optarg); + break; + case 'g': filter = std::atoi(optarg); break; case 'k': @@ -106,6 +110,7 @@ int run_test(const kernel_arg_t& kernel_arg, uint32_t buf_size, uint32_t width, int main(int argc, char *argv[]) { kernel_arg_t kernel_arg; + std::vector src_pixels_rgba8; std::vector src_pixels; uint32_t src_width; uint32_t src_height; @@ -114,7 +119,13 @@ int main(int argc, char *argv[]) { // parse command arguments parse_args(argc, argv); - RT_CHECK(LoadTGA(input_file, src_pixels, &src_width, &src_height, &src_bpp)); + // if (format){ + RT_CHECK(LoadTGA(input_file, src_pixels_rgba8, &src_width, &src_height, &src_bpp)); + RT_CHECK(ConvertImage(src_pixels, src_pixels_rgba8, &src_bpp, src_width, src_height, 0, format)); + // } else { + // RT_CHECK(LoadTGA(input_file, src_pixels, &src_width, &src_height, &src_bpp)); + // } + dump_image(src_pixels, src_width, src_height, src_bpp); uint32_t src_bufsize = src_bpp * src_width * src_height; @@ -160,7 +171,7 @@ int main(int argc, char *argv[]) { std::cout << "upload kernel argument" << std::endl; { kernel_arg.num_tasks = std::min(num_tasks, dst_height); - kernel_arg.format = (src_bpp == 1) ? 5 : (src_bpp == 2) ? 1 : 0; + kernel_arg.format = format; kernel_arg.filter = filter; kernel_arg.wrap = wrap; diff --git a/driver/tests/tex_demo/utils.cpp b/driver/tests/tex_demo/utils.cpp index 304693b2..468b7524 100644 --- a/driver/tests/tex_demo/utils.cpp +++ b/driver/tests/tex_demo/utils.cpp @@ -1,6 +1,12 @@ #include "utils.h" #include #include +#include "format.h" + +#define TEX_FORMAT(x) (x==0) ? FORMAT_A8R8G8B8 :(x==1) ? FORMAT_R5G6B5 : (x==2) ? FORMAT_R4G4B4A4 :(x==3) ? FORMAT_A8L8 :(x==4) ? FORMAT_L8 : FORMAT_A8 + +#define CBSIZE(x) (x==FORMAT_A8R8G8B8) ? 4 : (x==FORMAT_R5G6B5) ? 2 : (x==FORMAT_R4G4B4A4) ? 2 : (x==FORMAT_A8L8) ? 2 : 1 + struct __attribute__((__packed__)) tga_header_t { int8_t idlength; @@ -193,10 +199,58 @@ int CopyBuffers(const SurfaceDesc &dstDesc, if (copyHeight > srcDesc.Height) { copyHeight = srcDesc.Height; } + std::cout << "There" << std::endl; s_blitTable.get(srcDesc.Format, dstDesc.Format)( dstDesc, dstOffsetX, dstOffsetY, copyWidth, copyHeight, srcDesc, srcOffsetX, srcOffsetY); + std::cout << "There2" << std::endl; + + + return 0; +} + +int ConvertImage(std::vector &dst_pixels, + std::vector&src_pixels, + uint32_t *bpp, + uint32_t width, + uint32_t height, + uint8_t src_format, + uint8_t dst_format) { + + uint8_t SrcFormat = TEX_FORMAT(src_format); + uint8_t DstFormat = TEX_FORMAT(dst_format); + + *bpp = CBSIZE(DstFormat); + + int32_t src_pitch = CBSIZE(SrcFormat) * width; + int32_t dst_pitch = CBSIZE(DstFormat) * width; + +// struct SurfaceDesc { +// uint8_t Format; +// uint8_t *pBits; +// int32_t Width; +// int32_t Height; +// int32_t Pitch; +// }; + + const SurfaceDesc srcDesc = {SrcFormat, + (uint8_t*)(src_pixels.data()), + int32_t(width), + int32_t(height), + src_pitch} ; + + const SurfaceDesc dstDesc = {DstFormat, + (uint8_t*)(dst_pixels.data()), + int32_t(width), + int32_t(height), + dst_pitch}; + std::cout << "Here" << std::endl; + + + CopyBuffers(dstDesc, 0, 0, width, height, srcDesc, 0, 0); + + std::cout << "Here" << std::endl; return 0; } \ No newline at end of file diff --git a/driver/tests/tex_demo/utils.h b/driver/tests/tex_demo/utils.h index d22a662b..4cf69935 100644 --- a/driver/tests/tex_demo/utils.h +++ b/driver/tests/tex_demo/utils.h @@ -24,4 +24,12 @@ int CopyBuffers(const SurfaceDesc &dstDesc, int32_t srcOffsetX, int32_t srcOffsetY); +int ConvertImage(std::vector &dst_pixels, + std::vector&src_pixels, + uint32_t *bpp, + uint32_t width, + uint32_t height, + uint8_t src_format, + uint8_t dst_format); + void dump_image(const std::vector& pixels, uint32_t width, uint32_t height, uint32_t bpp); \ No newline at end of file diff --git a/hw/rtl/tex_unit/VX_tex_format.v b/hw/rtl/tex_unit/VX_tex_format.v index b8168822..e3e7351d 100644 --- a/hw/rtl/tex_unit/VX_tex_format.v +++ b/hw/rtl/tex_unit/VX_tex_format.v @@ -14,16 +14,16 @@ module VX_tex_format #( always @(*) begin case (format) `TEX_FORMAT_R5G6B5: begin - texel_out_r[07:00] = `TEX_COLOR_BITS'(texel_in[4:0]); - texel_out_r[15:08] = `TEX_COLOR_BITS'(texel_in[10:5]); - texel_out_r[23:16] = `TEX_COLOR_BITS'(texel_in[15:11]); + texel_out_r[07:00] = `TEX_COLOR_BITS'({texel_in[15:11],texel_in[15:13]}); + texel_out_r[15:08] = `TEX_COLOR_BITS'({texel_in[10:5],texel_in[10:9]}); + texel_out_r[23:16] = `TEX_COLOR_BITS'({texel_in[4:0],texel_in[4:2]}); texel_out_r[31:24] = {`TEX_COLOR_BITS{1'b1}}; end `TEX_FORMAT_R4G4B4A4: begin - texel_out_r[07:00] = `TEX_COLOR_BITS'(texel_in[3:0]); - texel_out_r[15:08] = `TEX_COLOR_BITS'(texel_in[7:4]); - texel_out_r[23:16] = `TEX_COLOR_BITS'(texel_in[11:8]); - texel_out_r[31:24] = `TEX_COLOR_BITS'(texel_in[15:12]); + texel_out_r[07:00] = `TEX_COLOR_BITS'({texel_in[11:8],texel_in[15:12]}); + texel_out_r[15:08] = `TEX_COLOR_BITS'({2{texel_in[7:4]}}); + texel_out_r[23:16] = `TEX_COLOR_BITS'({2{texel_in[3:0]}}); + texel_out_r[31:24] = `TEX_COLOR_BITS'({2{texel_in[15:12]}}); end `TEX_FORMAT_L8A8: begin texel_out_r[07:00] = `TEX_COLOR_BITS'(texel_in[7:0]); From 10182ebb7edb3b7ac9e5ecd1c808d5419ec9f439 Mon Sep 17 00:00:00 2001 From: Krishna Yalamarthy Date: Tue, 13 Apr 2021 06:46:21 -0400 Subject: [PATCH 2/2] minor update --- driver/tests/tex_demo/utils.cpp | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/driver/tests/tex_demo/utils.cpp b/driver/tests/tex_demo/utils.cpp index 468b7524..9ca68d7a 100644 --- a/driver/tests/tex_demo/utils.cpp +++ b/driver/tests/tex_demo/utils.cpp @@ -199,12 +199,10 @@ int CopyBuffers(const SurfaceDesc &dstDesc, if (copyHeight > srcDesc.Height) { copyHeight = srcDesc.Height; } - std::cout << "There" << std::endl; s_blitTable.get(srcDesc.Format, dstDesc.Format)( dstDesc, dstOffsetX, dstOffsetY, copyWidth, copyHeight, srcDesc, srcOffsetX, srcOffsetY); - std::cout << "There2" << std::endl; return 0; @@ -218,39 +216,27 @@ int ConvertImage(std::vector &dst_pixels, uint8_t src_format, uint8_t dst_format) { - uint8_t SrcFormat = TEX_FORMAT(src_format); - uint8_t DstFormat = TEX_FORMAT(dst_format); + ePixelFormat SrcFormat = TEX_FORMAT(src_format); + ePixelFormat DstFormat = TEX_FORMAT(dst_format); *bpp = CBSIZE(DstFormat); int32_t src_pitch = CBSIZE(SrcFormat) * width; int32_t dst_pitch = CBSIZE(DstFormat) * width; -// struct SurfaceDesc { -// uint8_t Format; -// uint8_t *pBits; -// int32_t Width; -// int32_t Height; -// int32_t Pitch; -// }; - const SurfaceDesc srcDesc = {SrcFormat, - (uint8_t*)(src_pixels.data()), + src_pixels.data(), int32_t(width), int32_t(height), src_pitch} ; const SurfaceDesc dstDesc = {DstFormat, - (uint8_t*)(dst_pixels.data()), + dst_pixels.data(), int32_t(width), int32_t(height), dst_pitch}; - std::cout << "Here" << std::endl; - CopyBuffers(dstDesc, 0, 0, width, height, srcDesc, 0, 0); - std::cout << "Here" << std::endl; - return 0; } \ No newline at end of file