Merge branch 'graphics' of https://github.com/vortexgpgpu/vortex-dev into graphics

This commit is contained in:
Blaise Tine 2021-04-15 23:56:50 -04:00
commit 0541433028
4 changed files with 70 additions and 11 deletions

View file

@ -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<uint8_t> src_pixels_rgba8;
std::vector<uint8_t> 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<uint32_t>(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;

View file

@ -1,6 +1,12 @@
#include "utils.h"
#include <fstream>
#include <assert.h>
#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;
@ -198,5 +204,39 @@ int CopyBuffers(const SurfaceDesc &dstDesc,
dstDesc, dstOffsetX, dstOffsetY, copyWidth, copyHeight, srcDesc,
srcOffsetX, srcOffsetY);
return 0;
}
int ConvertImage(std::vector<uint8_t> &dst_pixels,
std::vector<uint8_t>&src_pixels,
uint32_t *bpp,
uint32_t width,
uint32_t height,
uint8_t src_format,
uint8_t 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;
const SurfaceDesc srcDesc = {SrcFormat,
src_pixels.data(),
int32_t(width),
int32_t(height),
src_pitch} ;
const SurfaceDesc dstDesc = {DstFormat,
dst_pixels.data(),
int32_t(width),
int32_t(height),
dst_pitch};
CopyBuffers(dstDesc, 0, 0, width, height, srcDesc, 0, 0);
return 0;
}

View file

@ -24,4 +24,12 @@ int CopyBuffers(const SurfaceDesc &dstDesc,
int32_t srcOffsetX,
int32_t srcOffsetY);
int ConvertImage(std::vector<uint8_t> &dst_pixels,
std::vector<uint8_t>&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<uint8_t>& pixels, uint32_t width, uint32_t height, uint32_t bpp);

View file

@ -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]);