tex_unit update

This commit is contained in:
Blaise Tine
2021-03-30 07:01:45 -04:00
parent 28ee19779c
commit 79fcdf7a28
20 changed files with 756 additions and 626 deletions

View File

@@ -9,7 +9,7 @@ struct kernel_arg_t {
uint32_t src_height;
uint32_t src_stride;
uint32_t src_pitch;
uint32_t src_ptr;
uint8_t src_ptr;
uint32_t dst_width;
uint32_t dst_height;
uint32_t dst_stride;

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

View File

@@ -16,18 +16,19 @@ struct tile_arg_t {
void kernel_body(int task_id, void* arg) {
struct tile_arg_t* _arg = (struct tile_arg_t*)(arg);
uint32_t xoffset = task_id * _arg->tile_width;
uint32_t xoffset = 0;
uint32_t yoffset = task_id * _arg->tile_height;
uint32_t* dst_ptr = (uint32_t*)_arg->karg.dst_ptr + xoffset + yoffset * _arg->karg.dst_pitch;
uint8_t* dst_ptr = (uint8_t*)(_arg->karg.dst_ptr + xoffset * _arg->karg.dst_stride + yoffset * _arg->karg.dst_pitch);
float fu = xoffset * _arg->deltaX;
float fv = yoffset * _arg->deltaY;
for (uint32_t y = 0; y < _arg->tile_height; ++y) {
uint32_t* dst_row = (uint32_t*)dst_ptr;
for (uint32_t x = 0; x < _arg->tile_width; ++x) {
int32_t u = (int32_t)(fu * (1<<20));
int32_t v = (int32_t)(fv * (1<<20));
dst_ptr[x] = vx_tex(0, u, v, 0x0);
dst_row[x] = vx_tex(0, u, v, 0x0);
fu += _arg->deltaX;
}
dst_ptr += _arg->karg.dst_pitch;

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -20,7 +20,7 @@
///////////////////////////////////////////////////////////////////////////////
const char* kernel_file = "kernel.bin";
const char* input_file = "sample.tga";
const char* input_file = "palette.tga";
const char* output_file = "output.tga";
float scale = 1.0f;
@@ -69,7 +69,7 @@ void cleanup() {
}
}
int run_test(const kernel_arg_t& kernel_arg, uint32_t buf_size, uint32_t width, uint32_t height, uint32_t dst_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));
@@ -83,14 +83,15 @@ int run_test(const kernel_arg_t& kernel_arg, uint32_t buf_size, uint32_t width,
RT_CHECK(vx_copy_from_dev(buffer, kernel_arg.dst_ptr, buf_size, 0));
std::vector<uint8_t> dst_pixels(buf_size);
auto buf_ptr = (int8_t*)vx_host_ptr(buffer);
auto buf_ptr = (uint8_t*)vx_host_ptr(buffer);
for (uint32_t i = 0; i < buf_size; ++i) {
dst_pixels[i] = buf_ptr[i];
}
// save output image
std::cout << "save output image" << std::endl;
RT_CHECK(SaveTGA(output_file, dst_pixels, width, height, dst_bpp));
dump_image(dst_pixels, width, height, bpp);
RT_CHECK(SaveTGA(output_file, dst_pixels, width, height, bpp));
return 0;
}
@@ -106,6 +107,7 @@ int main(int argc, char *argv[]) {
parse_args(argc, argv);
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;
uint32_t dst_width = (uint32_t)(src_width * scale);
@@ -122,9 +124,9 @@ int main(int argc, char *argv[]) {
RT_CHECK(vx_dev_caps(device, VX_CAPS_MAX_WARPS, &max_warps));
RT_CHECK(vx_dev_caps(device, VX_CAPS_MAX_THREADS, &max_threads));
uint32_t num_tasks = max_cores * max_warps * max_threads;
uint32_t num_tasks = max_cores * max_warps * max_threads / 4;
std::cout << "number of tasks: " << num_tasks << std::endl;
std::cout << "number of tasks: " << std::dec << num_tasks << std::endl;
std::cout << "source buffer: width=" << src_width << ", heigth=" << src_height << ", size=" << src_bufsize << " bytes" << std::endl;
std::cout << "destination buffer: width=" << dst_width << ", heigth=" << dst_height << ", size=" << dst_bufsize << " bytes" << std::endl;
@@ -138,8 +140,8 @@ int main(int argc, char *argv[]) {
RT_CHECK(vx_alloc_dev_mem(device, src_bufsize, &src_addr));
RT_CHECK(vx_alloc_dev_mem(device, dst_bufsize, &dst_addr));
std::cout << "src_addr=" << std::hex << src_addr << std::endl;
std::cout << "dst_addr=" << std::hex << dst_addr << std::endl;
std::cout << "src_addr=0x" << std::hex << src_addr << std::endl;
std::cout << "dst_addr=0x" << std::hex << dst_addr << std::endl;
// allocate staging shared memory
std::cout << "allocate shared memory" << std::endl;
@@ -154,13 +156,13 @@ int main(int argc, char *argv[]) {
kernel_arg.src_width = src_width;
kernel_arg.src_height = src_height;
kernel_arg.src_stride = src_bpp;
kernel_arg.src_pitch = src_bpp * src_width * src_height;
kernel_arg.src_pitch = src_bpp * src_width;
kernel_arg.src_ptr = src_addr;
kernel_arg.dst_width = dst_width;
kernel_arg.dst_height = dst_height;
kernel_arg.dst_stride = dst_bpp;
kernel_arg.dst_pitch = dst_bpp * dst_width * dst_height;
kernel_arg.dst_pitch = dst_bpp * dst_width;
kernel_arg.dst_ptr = dst_addr;
auto buf_ptr = (int*)vx_host_ptr(buffer);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -1,5 +1,6 @@
#include "utils.h"
#include <fstream>
#include <assert.h>
struct __attribute__((__packed__)) tga_header_t {
int8_t idlength;
@@ -108,8 +109,35 @@ int SaveTGA(const char *filename,
header.bitsperpixel = bpp * 8;
header.imagedescriptor = 0;
ofs.write(reinterpret_cast<char *>(&header), sizeof(tga_header_t));
ofs.write((const char*)pixels.data(), pixels.size());
ofs.write(reinterpret_cast<char *>(&header), sizeof(tga_header_t));
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;
}
void dump_image(const std::vector<uint8_t>& pixels, uint32_t width, uint32_t height, uint32_t bpp) {
assert(width * height * bpp == pixels.size());
const uint8_t* pixel_bytes = pixels.data();
for (uint32_t y = 0; y < height; ++y) {
for (uint32_t x = 0; x < width; ++x) {
uint32_t pixel32 = 0;
for (uint32_t b = 0; b < bpp; ++b) {
uint32_t pixel8 = *pixel_bytes++;
pixel32 |= pixel8 << (b * 8);
}
if (x) std::cout << ", ";
std::cout << std::hex << pixel32;
}
std::cout << std::endl;
}
}

View File

@@ -12,4 +12,6 @@ int SaveTGA(const char *filename,
const std::vector<uint8_t> &pixels,
uint32_t width,
uint32_t height,
uint32_t bpp);
uint32_t bpp);
void dump_image(const std::vector<uint8_t>& pixels, uint32_t width, uint32_t height, uint32_t bpp);