diff --git a/shader_examples/mesa/gl_teximage2d.fs.txt b/shader_examples/mesa/gl_teximage2d.fs.txt new file mode 100644 index 0000000..241efcf --- /dev/null +++ b/shader_examples/mesa/gl_teximage2d.fs.txt @@ -0,0 +1,12 @@ +0x00007807, +0x02400000, +0xe400f400, +0x00000000, +0x00000000, +0x00000000, +0x00078005, +0x08020000, +0x08020000, +0x1c440220, +0x1c60c003, +0x00000005, diff --git a/shader_examples/mesa/gl_teximage2d.vs.txt b/shader_examples/mesa/gl_teximage2d.vs.txt new file mode 100644 index 0000000..d45b68e --- /dev/null +++ b/shader_examples/mesa/gl_teximage2d.vs.txt @@ -0,0 +1,8 @@ +0x00f00203, +0x00d10001, +0x01248001, +0x01248001, +0x00f02203, +0x00d10021, +0x01248021, +0x01248021, diff --git a/src/Makefile b/src/Makefile index d4b3875..b16eb33 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,6 +17,7 @@ R500_COMMON = \ r500/display_controller.o \ r500/indirect_buffer.o \ r500/shader.o \ + r500/texture.o \ drm/buffer.o \ drm/drm.o \ file.o diff --git a/src/drm/buffer.c b/src/drm/buffer.c index 7b0401d..e2270fd 100644 --- a/src/drm/buffer.c +++ b/src/drm/buffer.c @@ -72,32 +72,3 @@ int create_flush_buffer(int fd) assert(args.handle != 0); return args.handle; } - -int * load_textures(int fd, - const char ** textures, - int textures_length) -{ - int * texturebuffer_handle = (int *)malloc((sizeof (int)) * textures_length); - - for (int i = 0; i < textures_length; i++) { - int size = 0; - void * buf = file_read(textures[i], &size); - assert(buf != NULL); - - printf("load texture[%d]: %d\n", i, size); - - void * ptr = NULL; - int handle = create_buffer(fd, size, &ptr); - - for (int i = 0; i < size / 4; i++) { - ((uint32_t*)ptr)[i] = ((uint32_t*)buf)[i]; - } - asm volatile ("" ::: "memory"); - free(buf); - munmap(ptr, size); - - texturebuffer_handle[i] = handle; - } - - return texturebuffer_handle; -} diff --git a/src/drm/buffer.h b/src/drm/buffer.h index 1535132..4405a87 100644 --- a/src/drm/buffer.h +++ b/src/drm/buffer.h @@ -6,9 +6,6 @@ extern "C" { int create_buffer(int fd, int buffer_size, void ** out_ptr); int create_flush_buffer(int fd); -int * load_textures(int fd, - const char ** textures, - int textures_length); #ifdef __cplusplus } diff --git a/src/drm/drm.c b/src/drm/drm.c index 14233d6..f8ab256 100644 --- a/src/drm/drm.c +++ b/src/drm/drm.c @@ -37,7 +37,7 @@ void drm_radeon_cs(int fd, }; for (int i = 0; i < texturebuffer_handles_length; i++) { - relocs[3 + i] = (struct drm_radeon_cs_reloc){ + relocs[TEXTUREBUFFER_RELOC_INDEX + i] = (struct drm_radeon_cs_reloc){ .handle = texturebuffer_handles[i], .read_domains = 4, // RADEON_GEM_DOMAIN_VRAM .write_domain = 4, // RADEON_GEM_DOMAIN_VRAM diff --git a/src/drm/drm.h b/src/drm/drm.h index 7314dcd..ff312fa 100644 --- a/src/drm/drm.h +++ b/src/drm/drm.h @@ -3,7 +3,7 @@ #define COLORBUFFER_RELOC_INDEX 0 #define ZBUFFER_RELOC_INDEX 1 #define FLUSH_RELOC_INDEX 2 -#define TEXTURE_RELOC_INDEX 3 +#define TEXTUREBUFFER_RELOC_INDEX 3 #ifdef __cplusplus extern "C" { diff --git a/src/matrix_cubesphere.cpp b/src/matrix_cubesphere.cpp index cd60745..f9913e5 100644 --- a/src/matrix_cubesphere.cpp +++ b/src/matrix_cubesphere.cpp @@ -17,6 +17,7 @@ #include "r500/indirect_buffer.h" #include "r500/shader.h" #include "r500/display_controller.h" +#include "r500/texture.h" #include "drm/buffer.h" #include "drm/drm.h" @@ -41,18 +42,11 @@ const int vertex_shader_paths_length = (sizeof (vertex_shader_paths)) / (sizeof const char * fragment_shader_paths[] = { "clear.fs.bin", "matrix_cubesphere.fs.bin", - "light.fs.bin" + "light.fs.bin", }; const int fragment_shader_paths_length = (sizeof (fragment_shader_paths)) / (sizeof (fragment_shader_paths[0])); -struct shaders { - struct shader_offset * vertex; - struct shader_offset * fragment; - int vertex_length; - int fragment_length; -}; - -void _3d_clear(struct shaders& shaders) +void _3d_clear(const shaders& shaders) { ib_rs_instructions(0); @@ -67,7 +61,7 @@ void _3d_clear(struct shaders& shaders) // - ib_zbuffer(ZBUFFER_RELOC_INDEX, 7); // always + ib_zbuffer(ZBUFFER_RELOC_INDEX, 1600, 7); // always ib_texture__0(); @@ -298,7 +292,7 @@ void _3d_light_inner(mat4x4 trans) } } -vec3 _3d_light(struct shaders& shaders, +vec3 _3d_light(const shaders& shaders, const mat4x4& view_to_clip, float theta) { @@ -315,7 +309,7 @@ vec3 _3d_light(struct shaders& shaders, // - ib_zbuffer(ZBUFFER_RELOC_INDEX, 1); // less + ib_zbuffer(ZBUFFER_RELOC_INDEX, 1600, 1); // less ib_texture__0(); @@ -382,7 +376,7 @@ vec3 _3d_light(struct shaders& shaders, return light_pos; } -void _3d_cube(struct shaders& shaders, +void _3d_cube(const shaders& shaders, const mat4x4& view_to_clip, float theta, const vec3& light_pos) @@ -403,9 +397,17 @@ void _3d_cube(struct shaders& shaders, // - ib_zbuffer(ZBUFFER_RELOC_INDEX, 1); // less + ib_zbuffer(ZBUFFER_RELOC_INDEX, 1600, 1); // less - ib_texture__1(TEXTURE_RELOC_INDEX); + int width = 1024; + int height = 1024; + int macrotile = 0; + int microtile = 0; + int clamp = 0; // wrap/repeat + ib_texture__1(TEXTUREBUFFER_RELOC_INDEX, + width, height, + macrotile, microtile, + clamp); ib_vap_stream_cntl__323(); @@ -470,19 +472,28 @@ void _3d_cube(struct shaders& shaders, _3d_cube_inner(trans, world_trans, light_pos); } -int indirect_buffer(shaders& shaders, +int indirect_buffer(const shaders& shaders, float theta) { + int width = 1600; + int height = 1200; + int pitch = width; + ib_ix = 0; ib_generic_initialization(); + ib_viewport(width, height); + ib_colorbuffer(COLORBUFFER_RELOC_INDEX, pitch, 0, 0); + + T0V(GB_ENABLE, 0); + T0V(US_OUT_FMT_0 , US_OUT_FMT__OUT_FMT(0) // C4_8 - | US_OUT_FMT__C0_SEL(3) // Blue - | US_OUT_FMT__C1_SEL(2) // Green - | US_OUT_FMT__C2_SEL(1) // Red - | US_OUT_FMT__C3_SEL(0) // Alpha + | US_OUT_FMT__C0_SEL__BLUE + | US_OUT_FMT__C1_SEL__GREEN + | US_OUT_FMT__C2_SEL__RED + | US_OUT_FMT__C3_SEL__ALPHA | US_OUT_FMT__OUT_SIGN(0) ); T0V(US_OUT_FMT_1 @@ -491,12 +502,10 @@ int indirect_buffer(shaders& shaders, T0V(US_OUT_FMT_2 , US_OUT_FMT__OUT_FMT(15) // render target is not used ); - T0V(US_OUT_FMT_2 + T0V(US_OUT_FMT_3 , US_OUT_FMT__OUT_FMT(15) // render target is not used ); - ib_colorbuffer(COLORBUFFER_RELOC_INDEX); - load_pvs_shaders(shaders.vertex, shaders.vertex_length); load_us_shaders(shaders.fragment, shaders.fragment_length); @@ -559,7 +568,14 @@ int main() colorbuffer_handle[1] = create_buffer(fd, colorbuffer_size, &colorbuffer_ptr[1]); zbuffer_handle = create_buffer(fd, colorbuffer_size, &zbuffer_ptr); flush_handle = create_flush_buffer(fd); - texturebuffer_handle = load_textures(fd, textures, textures_length); + //texturebuffer_handle = load_textures(fd, textures, textures_length); + texturebuffer_handle = load_textures_tiled(fd, + zbuffer_handle, + flush_handle, + textures, + textures_length, + 1024, + 1024); fprintf(stderr, "colorbuffer handle[0] %d\n", colorbuffer_handle[0]); fprintf(stderr, "colorbuffer handle[1] %d\n", colorbuffer_handle[1]); @@ -584,6 +600,8 @@ int main() // next state theta += 0.01f; colorbuffer_ix = (colorbuffer_ix + 1) & 1; + + break; } close(fd); diff --git a/src/r500/indirect_buffer.c b/src/r500/indirect_buffer.c index 9cdd37a..cce0916 100644 --- a/src/r500/indirect_buffer.c +++ b/src/r500/indirect_buffer.c @@ -136,11 +136,6 @@ void ib_generic_initialization() | GA_ROUND_MODE__GEOMETRY_MASK(0) ); - T0Vf(GA_POINT_S0, 0.0f); - T0Vf(GA_POINT_T0, 1.0f); - T0Vf(GA_POINT_S1, 1.0f); - T0Vf(GA_POINT_T1, 0.0f); - T0V(GA_COLOR_CONTROL , GA_COLOR_CONTROL__RGB0_SHADING(2) | GA_COLOR_CONTROL__ALPHA0_SHADING(2) @@ -160,7 +155,6 @@ void ib_generic_initialization() ); T0V(GB_SELECT, 0x00000000); - T0V(GB_ENABLE, 0x00000000); T0V(GB_MSPOS0 , GB_MSPOS0__MS_X0(6) @@ -278,33 +272,9 @@ void ib_generic_initialization() T0V(US_W_FMT , US_W_FMT__W_FMT(0) // W is always zero ); - - ////////////////////////////////////////////////////////////////////////////// - // SC - ////////////////////////////////////////////////////////////////////////////// - - T0V(SC_SCISSOR0 - , SC_SCISSOR0__XS0(0) - | SC_SCISSOR0__YS0(0) - ); - T0V(SC_SCISSOR1 - , SC_SCISSOR1__XS1(1600 - 1) - | SC_SCISSOR1__YS1(1200 - 1) - ); - - ////////////////////////////////////////////////////////////////////////////// - // VAP - ////////////////////////////////////////////////////////////////////////////// - - T0Vf(VAP_VPORT_XSCALE, 800.0f); - T0Vf(VAP_VPORT_XOFFSET, 800.0f); - T0Vf(VAP_VPORT_YSCALE, -600.0f); - T0Vf(VAP_VPORT_YOFFSET, 600.0f); - T0Vf(VAP_VPORT_ZSCALE, 0.5f); - T0Vf(VAP_VPORT_ZOFFSET, 0.5f); } -void ib_colorbuffer(int reloc_index) +void ib_colorbuffer(int reloc_index, int pitch, int macrotile, int microtile) { ////////////////////////////////////////////////////////////////////////////// @@ -318,8 +288,10 @@ void ib_colorbuffer(int reloc_index) TU(reloc_index * 4); // index into relocs array T0V(RB3D_COLORPITCH0 - , RB3D_COLORPITCH__COLORPITCH(1600 >> 1) - | RB3D_COLORPITCH__COLORFORMAT(6) // ARGB8888 + , RB3D_COLORPITCH__COLORPITCH(pitch >> 1) + | RB3D_COLORPITCH__COLORTILE(macrotile) + | RB3D_COLORPITCH__COLORMICROTILE(microtile) + | RB3D_COLORPITCH__COLORFORMAT__ARGB8888 ); // The COLORPITCH NOP is ignored/not applied due to // RADEON_CS_KEEP_TILING_FLAGS, but is still required. @@ -327,7 +299,37 @@ void ib_colorbuffer(int reloc_index) TU(reloc_index * 4); // index into relocs array } -void ib_zbuffer(int reloc_index, int zfunc) +void ib_viewport(int width, int height) +{ + ////////////////////////////////////////////////////////////////////////////// + // SC + ////////////////////////////////////////////////////////////////////////////// + + T0V(SC_SCISSOR0 + , SC_SCISSOR0__XS0(0) + | SC_SCISSOR0__YS0(0) + ); + T0V(SC_SCISSOR1 + , SC_SCISSOR1__XS1(width - 1) + | SC_SCISSOR1__YS1(height - 1) + ); + + ////////////////////////////////////////////////////////////////////////////// + // VAP + ////////////////////////////////////////////////////////////////////////////// + + float x = ((float)width) * 0.5f; + float y = ((float)height) * 0.5f; + + T0Vf(VAP_VPORT_XSCALE, x); + T0Vf(VAP_VPORT_XOFFSET, x); + T0Vf(VAP_VPORT_YSCALE, -y); + T0Vf(VAP_VPORT_YOFFSET, y); + T0Vf(VAP_VPORT_ZSCALE, 0.5f); + T0Vf(VAP_VPORT_ZOFFSET, 0.5f); +} + +void ib_zbuffer(int reloc_index, int pitch, int zfunc) { ////////////////////////////////////////////////////////////////////////////// // ZB @@ -349,7 +351,7 @@ void ib_zbuffer(int reloc_index, int zfunc) TU(reloc_index * 4); // index into relocs array T0V(ZB_DEPTHPITCH - , ZB_DEPTHPITCH__DEPTHPITCH(1600 >> 2) + , ZB_DEPTHPITCH__DEPTHPITCH(pitch >> 2) | ZB_DEPTHPITCH__DEPTHMACROTILE(1) | ZB_DEPTHPITCH__DEPTHMICROTILE(1) ); @@ -518,7 +520,10 @@ void ib_texture__0() T0V(TX_ENABLE, 0x00000000); } -void ib_texture__1(int reloc_index) +void ib_texture__1(int reloc_index, + int width, int height, + int macrotile, int microtile, + int clamp) { ////////////////////////////////////////////////////////////////////////////// // TX @@ -528,17 +533,21 @@ void ib_texture__1(int reloc_index) T0V(TX_ENABLE , TX_ENABLE__TEX_0_ENABLE__ENABLE); + T0V(TX_FILTER0_0 - , TX_FILTER0__MAG_FILTER__LINEAR + , TX_FILTER0__CLAMP_S(clamp) + | TX_FILTER0__CLAMP_T(clamp) + | TX_FILTER0__MAG_FILTER__LINEAR | TX_FILTER0__MIN_FILTER__LINEAR ); T0V(TX_FILTER1_0 , TX_FILTER1__LOD_BIAS(1) + | TX_FILTER1__BORDER_FIX(1) ); T0V(TX_BORDER_COLOR_0, 0); T0V(TX_FORMAT0_0 - , TX_FORMAT0__TXWIDTH(1024 - 1) - | TX_FORMAT0__TXHEIGHT(1024 - 1) + , TX_FORMAT0__TXWIDTH(width - 1) + | TX_FORMAT0__TXHEIGHT(height - 1) ); T0V(TX_FORMAT1_0 @@ -552,9 +561,8 @@ void ib_texture__1(int reloc_index) T0V(TX_FORMAT2_0, 0); T0V(TX_OFFSET_0 - //, TX_OFFSET__MACRO_TILE(1) - //| TX_OFFSET__MICRO_TILE(1) - , 0 + , TX_OFFSET__MACRO_TILE(macrotile) + | TX_OFFSET__MICRO_TILE(microtile) ); T3(_NOP, 0); diff --git a/src/r500/indirect_buffer.h b/src/r500/indirect_buffer.h index 87db0c7..980015b 100644 --- a/src/r500/indirect_buffer.h +++ b/src/r500/indirect_buffer.h @@ -55,11 +55,15 @@ extern union u32_f32 ib[16384]; extern volatile int ib_ix; void ib_generic_initialization(); -void ib_colorbuffer(int reloc_index); -void ib_zbuffer(int reloc_index, int zfunc); +void ib_viewport(int width, int height); +void ib_colorbuffer(int reloc_index, int pitch, int macrotile, int microtile); +void ib_zbuffer(int reloc_index, int pitch, int zfunc); void ib_rs_instructions(int count); void ib_texture__0(); -void ib_texture__1(int reloc_index); +void ib_texture__1(int reloc_index, + int width, int height, + int macrotile, int microtile, + int clamp); void ib_vap_pvs(struct shader_offset * offset); void ib_ga_us(struct shader_offset * offset); void ib_vap_pvs_const_cntl(const float * consts, int size); diff --git a/src/r500/shader.h b/src/r500/shader.h index 8d7b960..bd64624 100644 --- a/src/r500/shader.h +++ b/src/r500/shader.h @@ -16,6 +16,13 @@ void load_us_shaders(struct shader_offset * offsets, int offsets_length); struct shader_offset * load_shaders(const char ** paths, int paths_length); +struct shaders { + struct shader_offset * vertex; + struct shader_offset * fragment; + int vertex_length; + int fragment_length; +}; + #ifdef __cplusplus } #endif diff --git a/src/r500/texture.c b/src/r500/texture.c new file mode 100644 index 0000000..c6bdfe3 --- /dev/null +++ b/src/r500/texture.c @@ -0,0 +1,310 @@ +#include +#include +#include +#include +#include + +#include "3d_registers.h" +#include "3d_registers_bits.h" + +#include "../drm/buffer.h" +#include "../drm/drm.h" +#include "../file.h" + +#include "texture.h" +#include "shader.h" +#include "indirect_buffer.h" + +#define TEXTURE_TILE_SHADER 0 + +static int _tile_texture(const struct shaders * shaders, + int input_reloc_index, + int output_reloc_index) +{ + int width = 1024; + int height = 1024; + int pitch = width; + float x = (float)width * 0.5f; + float y = (float)height * 0.5f; + + ib_ix = 0; + + ib_generic_initialization(); + + ib_viewport(width, height); + ib_colorbuffer(output_reloc_index, pitch, 1, 1); // macrotile, microtile + + T0V(US_OUT_FMT_0 + , US_OUT_FMT__OUT_FMT(0) // C4_8 + | US_OUT_FMT__C0_SEL__RED + | US_OUT_FMT__C1_SEL__GREEN + | US_OUT_FMT__C2_SEL__BLUE + | US_OUT_FMT__C3_SEL__ALPHA + | US_OUT_FMT__OUT_SIGN(0) + ); + T0V(US_OUT_FMT_1 + , US_OUT_FMT__OUT_FMT(15) // render target is not used + ); + T0V(US_OUT_FMT_2 + , US_OUT_FMT__OUT_FMT(15) // render target is not used + ); + T0V(US_OUT_FMT_3 + , US_OUT_FMT__OUT_FMT(15) // render target is not used + ); + + // GA + + T0V(GB_ENABLE + , GB_ENABLE__POINT_STUFF_ENABLE(1) + | GB_ENABLE__TEX0_SOURCE(2) // stuff with source texture coordinates s,t + ); + + T0Vf(GA_POINT_S0, 0.0f); + T0Vf(GA_POINT_T0, 1.0f); + T0Vf(GA_POINT_S1, 1.0f); + T0Vf(GA_POINT_T1, 0.0f); + + ////////////////////////////////////////////////////////////////////////////// + // RS + ////////////////////////////////////////////////////////////////////////////// + + int rs_instructions = 1; + + //ib_rs_instructions(0); + + T0V(RS_IP_0 + , RS_IP__TEX_PTR_S(0) + | RS_IP__TEX_PTR_T(1) + | RS_IP__TEX_PTR_R(62) // constant 0.0 + | RS_IP__TEX_PTR_Q(63) // constant 1.0 + ); + + T0V(RS_COUNT + , RS_COUNT__IT_COUNT(2) + | RS_COUNT__IC_COUNT(0) + | RS_COUNT__W_ADDR(0) + | RS_COUNT__HIRES_EN(1) + ); + + T0V(RS_INST_COUNT + , RS_INST_COUNT__INST_COUNT(rs_instructions - 1)); + + T0V(RS_INST_0 + , RS_INST__TEX_ID(0) + | RS_INST__TEX_CN(1) + | RS_INST__TEX_ADDR(0) + ); + + ////////////////////////////////////////////////////////////////////////////// + // VAP OUT + ////////////////////////////////////////////////////////////////////////////// + + T0V(VAP_OUT_VTX_FMT_0 + , VAP_OUT_VTX_FMT_0__VTX_POS_PRESENT(1) + ); + T0V(VAP_OUT_VTX_FMT_1 + , 0 + ); + + // + + T0V(ZB_CNTL, 0); + T0V(ZB_ZSTENCILCNTL, 0); + + // + + int macrotile = 0; + int microtile = 0; + int clamp = 2; // clamp to [0.0, 1.0] + ib_texture__1(input_reloc_index, + width, height, + macrotile, microtile, + clamp); + + ib_vap_stream_cntl__2(); + + T0V(US_PIXSIZE + , US_PIXSIZE__PIX_SIZE(1) + ); + + ib_ga_us(&shaders->fragment[TEXTURE_TILE_SHADER]); + ib_vap_pvs(&shaders->vertex[TEXTURE_TILE_SHADER]); + + ////////////////////////////////////////////////////////////////////////////// + // VAP + ////////////////////////////////////////////////////////////////////////////// + + T0V(VAP_CLIP_CNTL + , VAP_CLIP_CNTL__CLIP_DISABLE(1) + ); + + T0V(VAP_VTE_CNTL + , VAP_VTE_CNTL__VTX_XY_FMT(1) // disable W division + | VAP_VTE_CNTL__VTX_Z_FMT(1) // disable W division + ); + + T0V(VAP_CNTL_STATUS + , VAP_CNTL_STATUS__PVS_BYPASS(0) + ); + + ////////////////////////////////////////////////////////////////////////////// + // GA POINT SIZE + ////////////////////////////////////////////////////////////////////////////// + + T0V(GA_POINT_SIZE + , GA_POINT_SIZE__HEIGHT((int)(x * 12.0f)) + | GA_POINT_SIZE__WIDTH((int)(y * 12.0f)) + ); + + ////////////////////////////////////////////////////////////////////////////// + // 3D_DRAW + ////////////////////////////////////////////////////////////////////////////// + + const int dwords_per_vtx = 2; + + T0V(VAP_VTX_SIZE + , VAP_VTX_SIZE__DWORDS_PER_VTX(dwords_per_vtx) + ); + + const float center[] = { + x, y, + }; + const int vertex_count = 1; + T3(_3D_DRAW_IMMD_2, (1 + vertex_count * dwords_per_vtx) - 1); + TU( VAP_VF_CNTL__PRIM_TYPE(1) // point list + | VAP_VF_CNTL__PRIM_WALK(3) + | VAP_VF_CNTL__INDEX_SIZE(0) + | VAP_VF_CNTL__VTX_REUSE_DIS(0) + | VAP_VF_CNTL__DUAL_INDEX_MODE(0) + | VAP_VF_CNTL__USE_ALT_NUM_VERTS(0) + | VAP_VF_CNTL__NUM_VERTICES(vertex_count) + ); + for (int i = 0; i < 2; i++) { + TF(center[i]); + } + + ////////////////////////////////////////////////////////////////////////////// + // padding + ////////////////////////////////////////////////////////////////////////////// + + while ((ib_ix % 8) != 0) { + TU(0x80000000); + } + + return ib_ix; +} + +int * load_textures(int fd, + const char ** textures, + int textures_length) +{ + int * texturebuffer_handle = (int *)malloc((sizeof (int)) * textures_length); + + for (int i = 0; i < textures_length; i++) { + int size = 0; + void * buf = file_read(textures[i], &size); + assert(buf != NULL); + + printf("load texture[%d]: %d\n", i, size); + + void * ptr = NULL; + int handle = create_buffer(fd, size, &ptr); + + for (int i = 0; i < size / 4; i++) { + ((uint32_t*)ptr)[i] = ((uint32_t*)buf)[i]; + } + asm volatile ("" ::: "memory"); + free(buf); + munmap(ptr, size); + + texturebuffer_handle[i] = handle; + } + + return texturebuffer_handle; +} + +static void tile_texture(int fd, + const struct shaders * shaders, + int colorbuffer_handle, + int zbuffer_handle, + int flush_handle, + int texturebuffer_handle) +{ + int ib_dwords = _tile_texture(shaders, + TEXTUREBUFFER_RELOC_INDEX, // input + COLORBUFFER_RELOC_INDEX); // output + + drm_radeon_cs(fd, + colorbuffer_handle, + zbuffer_handle, + flush_handle, + &texturebuffer_handle, + 1, + ib_dwords); +} + +static const char * vertex_shader_paths[] = { + "texture_tile.vs.bin", +}; +static const int vertex_shader_paths_length = (sizeof (vertex_shader_paths)) / (sizeof (vertex_shader_paths[0])); +static const char * fragment_shader_paths[] = { + "texture_tile.fs.bin", +}; +static const int fragment_shader_paths_length = (sizeof (fragment_shader_paths)) / (sizeof (fragment_shader_paths[0])); + +int * load_textures_tiled(int fd, + int zbuffer_handle, + int flush_handle, + const char ** textures, + int textures_length, + int max_width, + int max_height) +{ + struct shaders shaders = { + .vertex = load_shaders(vertex_shader_paths, vertex_shader_paths_length), + .fragment = load_shaders(fragment_shader_paths, fragment_shader_paths_length), + .vertex_length = vertex_shader_paths_length, + .fragment_length = fragment_shader_paths_length, + }; + + // shaders + load_pvs_shaders(shaders.vertex, shaders.vertex_length); + load_us_shaders(shaders.fragment, shaders.fragment_length); + + int * texturebuffer_handle = (int *)malloc((sizeof (int)) * textures_length); + + int max_size = max_width * max_height * 4; + void * temp_ptr; + int temp_handle = create_buffer(fd, max_size, &temp_ptr); + + for (int i = 0; i < textures_length; i++) { + int size = 0; + void * buf = file_read(textures[i], &size); + assert(buf != NULL); + + printf("load tiled texture[%d]: %d\n", i, size); + + for (int i = 0; i < size / 4; i++) { + ((uint32_t*)temp_ptr)[i] = ((uint32_t*)buf)[i]; + } + asm volatile ("" ::: "memory"); + free(buf); + + assert(size <= max_size); + int handle = create_buffer(fd, size, NULL); + + tile_texture(fd, + &shaders, + handle, + zbuffer_handle, + flush_handle, + temp_handle); + + texturebuffer_handle[i] = handle; + } + sleep(1); + + munmap(temp_ptr, max_size); + + return texturebuffer_handle; +} diff --git a/src/r500/texture.h b/src/r500/texture.h new file mode 100644 index 0000000..6013beb --- /dev/null +++ b/src/r500/texture.h @@ -0,0 +1,21 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +int * load_textures(int fd, + const char ** textures, + int textures_length); + +int * load_textures_tiled(int fd, + int zbuffer_handle, + int flush_handle, + const char ** textures, + int textures_length, + int max_width, + int max_height); + +#ifdef __cplusplus +} +#endif diff --git a/src/texture_tile.fs.asm b/src/texture_tile.fs.asm new file mode 100644 index 0000000..3e534e8 --- /dev/null +++ b/src/texture_tile.fs.asm @@ -0,0 +1,8 @@ +TEX TEX_SEM_WAIT TEX_SEM_ACQUIRE + temp[0].rgba = LD tex[0].rgba temp[0].rgaa ; + +OUT TEX_SEM_WAIT +src0.a = temp[0], +src0.rgb = temp[0] : + out[0].a = MAX src0.a src0.a , + out[0].rgb = MAX src0.rgb src0.rgb ; diff --git a/src/texture_tile.fs.bin b/src/texture_tile.fs.bin new file mode 100644 index 0000000..bbfaa90 Binary files /dev/null and b/src/texture_tile.fs.bin differ diff --git a/src/texture_tile.vs.asm b/src/texture_tile.vs.asm new file mode 100644 index 0000000..e779e8c --- /dev/null +++ b/src/texture_tile.vs.asm @@ -0,0 +1 @@ +out[0].xyzw = VE_ADD input[0].xyzw input[0].0000 ; diff --git a/src/texture_tile.vs.bin b/src/texture_tile.vs.bin new file mode 100644 index 0000000..69e1685 Binary files /dev/null and b/src/texture_tile.vs.bin differ