mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-23 21:39:10 -04:00
bug fixes
This commit is contained in:
parent
0541433028
commit
de72a23fc6
6 changed files with 122 additions and 118 deletions
|
@ -17,8 +17,8 @@ VX_LDFLAGS += -lm
|
|||
|
||||
VX_SRCS = kernel.c
|
||||
|
||||
#CXXFLAGS += -std=c++11 -O2 -Wall -Wextra -pedantic -Wfatal-errors
|
||||
CXXFLAGS += -std=c++11 -O0 -g -Wall -Wextra -pedantic -Wfatal-errors
|
||||
#CXXFLAGS += -std=c++11 -O2 -Wall -Wextra -Wfatal-errors
|
||||
CXXFLAGS += -std=c++11 -O0 -g -Wall -Wextra -Wfatal-errors
|
||||
|
||||
CXXFLAGS += -I../../include
|
||||
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
#include "format.h"
|
||||
|
||||
struct SurfaceDesc {
|
||||
uint8_t Format;
|
||||
ePixelFormat Format;
|
||||
uint8_t *pBits;
|
||||
int32_t Width;
|
||||
int32_t Height;
|
||||
int32_t Pitch;
|
||||
uint32_t Width;
|
||||
uint32_t Height;
|
||||
uint32_t Pitch;
|
||||
};
|
||||
|
||||
class BlitTable {
|
||||
public:
|
||||
typedef void (*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);
|
||||
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) {
|
||||
|
@ -183,14 +183,14 @@ public:
|
|||
|
||||
private:
|
||||
template <ePixelFormat SrcFormat, ePixelFormat DstFormat>
|
||||
static void 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) {
|
||||
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;
|
||||
|
@ -211,14 +211,19 @@ private:
|
|||
|
||||
pbSrc += srcNextLine;
|
||||
pbDst += dstNextLine;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
static void 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) {
|
||||
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;
|
||||
|
@ -235,18 +240,20 @@ private:
|
|||
pbSrc += srcNextLine;
|
||||
pbDst += dstNextLine;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void 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*/)
|
||||
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::abort();
|
||||
std::cout << "Error: invalid format" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
PfnCopy copyFuncs_[FORMAT_COLOR_SIZE_][FORMAT_COLOR_SIZE_];
|
||||
|
|
|
@ -54,7 +54,7 @@ enum ePixelFormat {
|
|||
#define FORMAT_ARGB FORMAT_A8R8G8B8
|
||||
#define FORMAT_ARGB_ FORMAT_A4R4G4B4
|
||||
|
||||
template <uint32_t PixelFormat>
|
||||
template <ePixelFormat PixelFormat>
|
||||
struct TFormatInfo {};
|
||||
|
||||
template <>
|
||||
|
@ -462,7 +462,7 @@ public:
|
|||
|
||||
namespace Format {
|
||||
|
||||
inline static const FormatInfo &GetInfo(uint32_t pixelFormat) {
|
||||
inline static const FormatInfo &GetInfo(ePixelFormat pixelFormat) {
|
||||
static const FormatInfo sc_formatInfos[FORMAT_SIZE_] = {
|
||||
__formatInfo(FORMAT_UNKNOWN),
|
||||
__formatInfo(FORMAT_A8),
|
||||
|
@ -501,26 +501,26 @@ typedef ColorARGB (*pfn_convert_from)(const void *pIn);
|
|||
|
||||
typedef void (*pfn_convert_to)(void *pOut, const ColorARGB &in);
|
||||
|
||||
template <uint32_t PixelFormat>
|
||||
template <ePixelFormat PixelFormat>
|
||||
static uint32_t ConvertTo(const ColorARGB &color);
|
||||
|
||||
template <uint32_t PixelFormat>
|
||||
template <ePixelFormat PixelFormat>
|
||||
static void ConvertTo(void *pOut, const ColorARGB &in) {
|
||||
*reinterpret_cast<typename TFormatInfo<PixelFormat>::TYPE *>(pOut) =
|
||||
static_cast<typename TFormatInfo<PixelFormat>::TYPE>(
|
||||
ConvertTo<PixelFormat>(in));
|
||||
}
|
||||
|
||||
template <uint32_t PixelFormat, bool bForceAlpha>
|
||||
template <ePixelFormat PixelFormat, bool bForceAlpha>
|
||||
static ColorARGB ConvertFrom(uint32_t in);
|
||||
|
||||
template <uint32_t PixelFormat, bool bForceAlpha>
|
||||
template <ePixelFormat PixelFormat, bool bForceAlpha>
|
||||
static ColorARGB ConvertFrom(const void *pIn) {
|
||||
return ConvertFrom<PixelFormat, bForceAlpha>(
|
||||
*reinterpret_cast<const typename TFormatInfo<PixelFormat>::TYPE *>(pIn));
|
||||
}
|
||||
|
||||
inline static pfn_convert_to GetConvertTo(uint32_t pixelFormat) {
|
||||
inline static pfn_convert_to GetConvertTo(ePixelFormat pixelFormat) {
|
||||
switch (pixelFormat) {
|
||||
case FORMAT_A8:
|
||||
return &ConvertTo<FORMAT_A8>;
|
||||
|
@ -550,11 +550,13 @@ inline static pfn_convert_to GetConvertTo(uint32_t pixelFormat) {
|
|||
return &ConvertTo<FORMAT_D16>;
|
||||
case FORMAT_X8S8D16:
|
||||
return &ConvertTo<FORMAT_X8S8D16>;
|
||||
default:
|
||||
return &ConvertTo<FORMAT_UNKNOWN>;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline static pfn_convert_from GetConvertFrom(uint32_t pixelFormat,
|
||||
inline static pfn_convert_from GetConvertFrom(ePixelFormat pixelFormat,
|
||||
bool bForceAlpha) {
|
||||
if (bForceAlpha) {
|
||||
switch (pixelFormat) {
|
||||
|
@ -586,6 +588,8 @@ inline static pfn_convert_from GetConvertFrom(uint32_t pixelFormat,
|
|||
return &ConvertFrom<FORMAT_D16, false>;
|
||||
case FORMAT_X8S8D16:
|
||||
return &ConvertFrom<FORMAT_X8S8D16, false>;
|
||||
default:
|
||||
return &ConvertFrom<FORMAT_UNKNOWN, false>;
|
||||
}
|
||||
} else {
|
||||
switch (pixelFormat) {
|
||||
|
@ -617,13 +621,15 @@ inline static pfn_convert_from GetConvertFrom(uint32_t pixelFormat,
|
|||
return &ConvertFrom<FORMAT_D16, false>;
|
||||
case FORMAT_X8S8D16:
|
||||
return &ConvertFrom<FORMAT_X8S8D16, false>;
|
||||
default:
|
||||
return &ConvertFrom<FORMAT_UNKNOWN, false>;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline static uint32_t GetNativeFormat(uint32_t pixelFormat) {
|
||||
inline static uint32_t GetNativeFormat(ePixelFormat pixelFormat) {
|
||||
switch (pixelFormat) {
|
||||
case FORMAT_PAL4_B8G8R8:
|
||||
case FORMAT_PAL8_B8G8R8:
|
||||
|
@ -644,8 +650,10 @@ inline static uint32_t GetNativeFormat(uint32_t pixelFormat) {
|
|||
case FORMAT_PAL4_R5G5B5A1:
|
||||
case FORMAT_PAL8_R5G5B5A1:
|
||||
return FORMAT_R5G5B5A1;
|
||||
|
||||
default:
|
||||
return pixelFormat;
|
||||
}
|
||||
return pixelFormat;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
const char* kernel_file = "kernel.bin";
|
||||
const char* input_file = "palette64.tga";
|
||||
const char* output_file = "output.tga";
|
||||
int wrap = 0;
|
||||
int filter = 0;
|
||||
int wrap = 0;
|
||||
int filter = 0;
|
||||
float scale = 1.0f;
|
||||
int format = 0;
|
||||
int format = 0;
|
||||
ePixelFormat eformat = FORMAT_A8R8G8B8;
|
||||
|
||||
vx_device_h device = nullptr;
|
||||
vx_buffer_h buffer = nullptr;
|
||||
|
@ -51,9 +52,19 @@ static void parse_args(int argc, char **argv) {
|
|||
case 'w':
|
||||
wrap = std::atoi(optarg);
|
||||
break;
|
||||
case 'f':
|
||||
format = std::atoi(optarg);
|
||||
break;
|
||||
case 'f': {
|
||||
format = std::atoi(optarg);
|
||||
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;
|
||||
default:
|
||||
std::cout << "Error: invalid format: " << format << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
} break;
|
||||
case 'g':
|
||||
filter = std::atoi(optarg);
|
||||
break;
|
||||
|
@ -81,7 +92,11 @@ void cleanup() {
|
|||
}
|
||||
}
|
||||
|
||||
int run_test(const kernel_arg_t& kernel_arg, uint32_t buf_size, uint32_t width, uint32_t height, uint32_t bpp) {
|
||||
int run_test(const kernel_arg_t& kernel_arg,
|
||||
uint32_t buf_size,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t bpp) {
|
||||
// start device
|
||||
std::cout << "start device" << std::endl;
|
||||
RT_CHECK(vx_start(device));
|
||||
|
@ -109,8 +124,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;
|
||||
kernel_arg_t kernel_arg;
|
||||
std::vector<uint8_t> src_pixels;
|
||||
uint32_t src_width;
|
||||
uint32_t src_height;
|
||||
|
@ -119,14 +133,13 @@ int main(int argc, char *argv[]) {
|
|||
// parse command arguments
|
||||
parse_args(argc, argv);
|
||||
|
||||
// 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));
|
||||
// }
|
||||
|
||||
std::vector<uint8_t> tmp_pixels;
|
||||
RT_CHECK(LoadTGA(input_file, tmp_pixels, &src_width, &src_height));
|
||||
RT_CHECK(ConvertImage(src_pixels, tmp_pixels, src_width, src_height, FORMAT_A8R8G8B8, eformat));
|
||||
src_bpp = Format::GetInfo(eformat).BytePerPixel;
|
||||
|
||||
dump_image(src_pixels, src_width, src_height, src_bpp);
|
||||
|
||||
uint32_t src_bufsize = src_bpp * src_width * src_height;
|
||||
|
||||
uint32_t dst_width = (uint32_t)(src_width * scale);
|
||||
|
|
|
@ -3,11 +3,6 @@
|
|||
#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;
|
||||
int8_t colormaptype;
|
||||
|
@ -26,8 +21,7 @@ struct __attribute__((__packed__)) tga_header_t {
|
|||
int LoadTGA(const char *filename,
|
||||
std::vector<uint8_t> &pixels,
|
||||
uint32_t *width,
|
||||
uint32_t *height,
|
||||
uint32_t *bpp) {
|
||||
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;
|
||||
|
@ -76,7 +70,7 @@ int LoadTGA(const char *filename,
|
|||
ColorARGB color;
|
||||
switch (stride) {
|
||||
case 2:
|
||||
color = Format::ConvertFrom<FORMAT_A1R5G5B5, true>(src_bytes);
|
||||
color = Format::ConvertFrom<FORMAT_A1R5G5B5, true>(src_bytes);
|
||||
break;
|
||||
case 3:
|
||||
color = Format::ConvertFrom<FORMAT_R8G8B8, true>(src_bytes);
|
||||
|
@ -98,7 +92,6 @@ int LoadTGA(const char *filename,
|
|||
|
||||
*width = header.width;
|
||||
*height = header.height;
|
||||
*bpp = 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -168,19 +161,19 @@ void dump_image(const std::vector<uint8_t>& pixels, uint32_t width, uint32_t hei
|
|||
}
|
||||
}
|
||||
|
||||
int CopyBuffers(const SurfaceDesc &dstDesc,
|
||||
int CopyBuffers(SurfaceDesc &dstDesc,
|
||||
int32_t dstOffsetX,
|
||||
int32_t dstOffsetY,
|
||||
int32_t copyWidth,
|
||||
int32_t copyHeight,
|
||||
uint32_t copyWidth,
|
||||
uint32_t copyHeight,
|
||||
const SurfaceDesc &srcDesc,
|
||||
int32_t srcOffsetX,
|
||||
int32_t srcOffsetY) {
|
||||
|
||||
static const BlitTable s_blitTable;
|
||||
|
||||
if ((srcOffsetX >= srcDesc.Width) || (srcOffsetY >= srcDesc.Height) ||
|
||||
(dstOffsetX >= dstDesc.Width) || (dstOffsetY >= dstDesc.Height)) {
|
||||
if ((srcOffsetX >= (int32_t)srcDesc.Width) || (srcOffsetY >= (int32_t)srcDesc.Height) ||
|
||||
(dstOffsetX >= (int32_t)dstDesc.Width) || (dstOffsetY >= (int32_t)dstDesc.Height)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -200,43 +193,25 @@ int CopyBuffers(const SurfaceDesc &dstDesc,
|
|||
copyHeight = srcDesc.Height;
|
||||
}
|
||||
|
||||
s_blitTable.get(srcDesc.Format, dstDesc.Format)(
|
||||
dstDesc, dstOffsetX, dstOffsetY, copyWidth, copyHeight, srcDesc,
|
||||
srcOffsetX, srcOffsetY);
|
||||
|
||||
|
||||
return 0;
|
||||
return s_blitTable.get(srcDesc.Format, dstDesc.Format)(
|
||||
dstDesc, dstOffsetX, dstOffsetY, copyWidth, copyHeight, srcDesc,
|
||||
srcOffsetX, srcOffsetY);
|
||||
}
|
||||
|
||||
int ConvertImage(std::vector<uint8_t> &dst_pixels,
|
||||
std::vector<uint8_t>&src_pixels,
|
||||
uint32_t *bpp,
|
||||
int ConvertImage(std::vector<uint8_t>& dst_pixels,
|
||||
const std::vector<uint8_t>& src_pixels,
|
||||
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);
|
||||
ePixelFormat src_format,
|
||||
ePixelFormat dst_format) {
|
||||
|
||||
*bpp = CBSIZE(DstFormat);
|
||||
uint32_t src_pitch = Format::GetInfo(src_format).BytePerPixel * width;
|
||||
uint32_t dst_pitch = Format::GetInfo(dst_format).BytePerPixel * width;
|
||||
|
||||
int32_t src_pitch = CBSIZE(SrcFormat) * width;
|
||||
int32_t dst_pitch = CBSIZE(DstFormat) * width;
|
||||
dst_pixels.resize(dst_pitch * height);
|
||||
|
||||
const SurfaceDesc srcDesc = {SrcFormat,
|
||||
src_pixels.data(),
|
||||
int32_t(width),
|
||||
int32_t(height),
|
||||
src_pitch} ;
|
||||
SurfaceDesc srcDesc{src_format, (uint8_t*)src_pixels.data(), width, height, src_pitch};
|
||||
SurfaceDesc dstDesc{dst_format, dst_pixels.data(), width, height, dst_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;
|
||||
return CopyBuffers(dstDesc, 0, 0, width, height, srcDesc, 0, 0);
|
||||
}
|
|
@ -6,8 +6,7 @@
|
|||
int LoadTGA(const char *filename,
|
||||
std::vector<uint8_t> &pixels,
|
||||
uint32_t *width,
|
||||
uint32_t *height,
|
||||
uint32_t *bpp);
|
||||
uint32_t *height);
|
||||
|
||||
int SaveTGA(const char *filename,
|
||||
const std::vector<uint8_t> &pixels,
|
||||
|
@ -15,21 +14,23 @@ int SaveTGA(const char *filename,
|
|||
uint32_t height,
|
||||
uint32_t bpp);
|
||||
|
||||
int CopyBuffers(const SurfaceDesc &dstDesc,
|
||||
int CopyBuffers(SurfaceDesc &dstDesc,
|
||||
int32_t dstOffsetX,
|
||||
int32_t dstOffsetY,
|
||||
int32_t copyWidth,
|
||||
int32_t copyHeight,
|
||||
uint32_t copyWidth,
|
||||
uint32_t copyHeight,
|
||||
const SurfaceDesc &srcDesc,
|
||||
int32_t srcOffsetX,
|
||||
int32_t srcOffsetY);
|
||||
|
||||
int ConvertImage(std::vector<uint8_t> &dst_pixels,
|
||||
std::vector<uint8_t>&src_pixels,
|
||||
uint32_t *bpp,
|
||||
int ConvertImage(std::vector<uint8_t>& dst_pixels,
|
||||
const std::vector<uint8_t>& src_pixels,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint8_t src_format,
|
||||
uint8_t dst_format);
|
||||
ePixelFormat src_format,
|
||||
ePixelFormat dst_format);
|
||||
|
||||
void dump_image(const std::vector<uint8_t>& pixels, uint32_t width, uint32_t height, uint32_t bpp);
|
||||
void dump_image(const std::vector<uint8_t>& pixels,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t bpp);
|
Loading…
Add table
Add a link
Reference in a new issue