wip broken

This commit is contained in:
Zack Buhman 2025-11-04 18:28:56 -06:00
parent 1c1e7483a7
commit 962b6548a6
17 changed files with 469 additions and 103 deletions

View File

@ -0,0 +1,12 @@
0x00007807,
0x02400000,
0xe400f400,
0x00000000,
0x00000000,
0x00000000,
0x00078005,
0x08020000,
0x08020000,
0x1c440220,
0x1c60c003,
0x00000005,

View File

@ -0,0 +1,8 @@
0x00f00203,
0x00d10001,
0x01248001,
0x01248001,
0x00f02203,
0x00d10021,
0x01248021,
0x01248021,

View File

@ -17,6 +17,7 @@ R500_COMMON = \
r500/display_controller.o \ r500/display_controller.o \
r500/indirect_buffer.o \ r500/indirect_buffer.o \
r500/shader.o \ r500/shader.o \
r500/texture.o \
drm/buffer.o \ drm/buffer.o \
drm/drm.o \ drm/drm.o \
file.o file.o

View File

@ -72,32 +72,3 @@ int create_flush_buffer(int fd)
assert(args.handle != 0); assert(args.handle != 0);
return args.handle; 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;
}

View File

@ -6,9 +6,6 @@ extern "C" {
int create_buffer(int fd, int buffer_size, void ** out_ptr); int create_buffer(int fd, int buffer_size, void ** out_ptr);
int create_flush_buffer(int fd); int create_flush_buffer(int fd);
int * load_textures(int fd,
const char ** textures,
int textures_length);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -37,7 +37,7 @@ void drm_radeon_cs(int fd,
}; };
for (int i = 0; i < texturebuffer_handles_length; i++) { 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], .handle = texturebuffer_handles[i],
.read_domains = 4, // RADEON_GEM_DOMAIN_VRAM .read_domains = 4, // RADEON_GEM_DOMAIN_VRAM
.write_domain = 4, // RADEON_GEM_DOMAIN_VRAM .write_domain = 4, // RADEON_GEM_DOMAIN_VRAM

View File

@ -3,7 +3,7 @@
#define COLORBUFFER_RELOC_INDEX 0 #define COLORBUFFER_RELOC_INDEX 0
#define ZBUFFER_RELOC_INDEX 1 #define ZBUFFER_RELOC_INDEX 1
#define FLUSH_RELOC_INDEX 2 #define FLUSH_RELOC_INDEX 2
#define TEXTURE_RELOC_INDEX 3 #define TEXTUREBUFFER_RELOC_INDEX 3
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -17,6 +17,7 @@
#include "r500/indirect_buffer.h" #include "r500/indirect_buffer.h"
#include "r500/shader.h" #include "r500/shader.h"
#include "r500/display_controller.h" #include "r500/display_controller.h"
#include "r500/texture.h"
#include "drm/buffer.h" #include "drm/buffer.h"
#include "drm/drm.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[] = { const char * fragment_shader_paths[] = {
"clear.fs.bin", "clear.fs.bin",
"matrix_cubesphere.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])); const int fragment_shader_paths_length = (sizeof (fragment_shader_paths)) / (sizeof (fragment_shader_paths[0]));
struct shaders { void _3d_clear(const shaders& shaders)
struct shader_offset * vertex;
struct shader_offset * fragment;
int vertex_length;
int fragment_length;
};
void _3d_clear(struct shaders& shaders)
{ {
ib_rs_instructions(0); 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(); 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, const mat4x4& view_to_clip,
float theta) 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(); ib_texture__0();
@ -382,7 +376,7 @@ vec3 _3d_light(struct shaders& shaders,
return light_pos; return light_pos;
} }
void _3d_cube(struct shaders& shaders, void _3d_cube(const shaders& shaders,
const mat4x4& view_to_clip, const mat4x4& view_to_clip,
float theta, float theta,
const vec3& light_pos) 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(); ib_vap_stream_cntl__323();
@ -470,19 +472,28 @@ void _3d_cube(struct shaders& shaders,
_3d_cube_inner(trans, world_trans, light_pos); _3d_cube_inner(trans, world_trans, light_pos);
} }
int indirect_buffer(shaders& shaders, int indirect_buffer(const shaders& shaders,
float theta) float theta)
{ {
int width = 1600;
int height = 1200;
int pitch = width;
ib_ix = 0; ib_ix = 0;
ib_generic_initialization(); ib_generic_initialization();
ib_viewport(width, height);
ib_colorbuffer(COLORBUFFER_RELOC_INDEX, pitch, 0, 0);
T0V(GB_ENABLE, 0);
T0V(US_OUT_FMT_0 T0V(US_OUT_FMT_0
, US_OUT_FMT__OUT_FMT(0) // C4_8 , US_OUT_FMT__OUT_FMT(0) // C4_8
| US_OUT_FMT__C0_SEL(3) // Blue | US_OUT_FMT__C0_SEL__BLUE
| US_OUT_FMT__C1_SEL(2) // Green | US_OUT_FMT__C1_SEL__GREEN
| US_OUT_FMT__C2_SEL(1) // Red | US_OUT_FMT__C2_SEL__RED
| US_OUT_FMT__C3_SEL(0) // Alpha | US_OUT_FMT__C3_SEL__ALPHA
| US_OUT_FMT__OUT_SIGN(0) | US_OUT_FMT__OUT_SIGN(0)
); );
T0V(US_OUT_FMT_1 T0V(US_OUT_FMT_1
@ -491,12 +502,10 @@ int indirect_buffer(shaders& shaders,
T0V(US_OUT_FMT_2 T0V(US_OUT_FMT_2
, US_OUT_FMT__OUT_FMT(15) // render target is not used , 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 , 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_pvs_shaders(shaders.vertex, shaders.vertex_length);
load_us_shaders(shaders.fragment, shaders.fragment_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]); colorbuffer_handle[1] = create_buffer(fd, colorbuffer_size, &colorbuffer_ptr[1]);
zbuffer_handle = create_buffer(fd, colorbuffer_size, &zbuffer_ptr); zbuffer_handle = create_buffer(fd, colorbuffer_size, &zbuffer_ptr);
flush_handle = create_flush_buffer(fd); 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[0] %d\n", colorbuffer_handle[0]);
fprintf(stderr, "colorbuffer handle[1] %d\n", colorbuffer_handle[1]); fprintf(stderr, "colorbuffer handle[1] %d\n", colorbuffer_handle[1]);
@ -584,6 +600,8 @@ int main()
// next state // next state
theta += 0.01f; theta += 0.01f;
colorbuffer_ix = (colorbuffer_ix + 1) & 1; colorbuffer_ix = (colorbuffer_ix + 1) & 1;
break;
} }
close(fd); close(fd);

View File

@ -136,11 +136,6 @@ void ib_generic_initialization()
| GA_ROUND_MODE__GEOMETRY_MASK(0) | 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 T0V(GA_COLOR_CONTROL
, GA_COLOR_CONTROL__RGB0_SHADING(2) , GA_COLOR_CONTROL__RGB0_SHADING(2)
| GA_COLOR_CONTROL__ALPHA0_SHADING(2) | GA_COLOR_CONTROL__ALPHA0_SHADING(2)
@ -160,7 +155,6 @@ void ib_generic_initialization()
); );
T0V(GB_SELECT, 0x00000000); T0V(GB_SELECT, 0x00000000);
T0V(GB_ENABLE, 0x00000000);
T0V(GB_MSPOS0 T0V(GB_MSPOS0
, GB_MSPOS0__MS_X0(6) , GB_MSPOS0__MS_X0(6)
@ -278,33 +272,9 @@ void ib_generic_initialization()
T0V(US_W_FMT T0V(US_W_FMT
, US_W_FMT__W_FMT(0) // W is always zero , 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 TU(reloc_index * 4); // index into relocs array
T0V(RB3D_COLORPITCH0 T0V(RB3D_COLORPITCH0
, RB3D_COLORPITCH__COLORPITCH(1600 >> 1) , RB3D_COLORPITCH__COLORPITCH(pitch >> 1)
| RB3D_COLORPITCH__COLORFORMAT(6) // ARGB8888 | RB3D_COLORPITCH__COLORTILE(macrotile)
| RB3D_COLORPITCH__COLORMICROTILE(microtile)
| RB3D_COLORPITCH__COLORFORMAT__ARGB8888
); );
// The COLORPITCH NOP is ignored/not applied due to // The COLORPITCH NOP is ignored/not applied due to
// RADEON_CS_KEEP_TILING_FLAGS, but is still required. // 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 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 // ZB
@ -349,7 +351,7 @@ void ib_zbuffer(int reloc_index, int zfunc)
TU(reloc_index * 4); // index into relocs array TU(reloc_index * 4); // index into relocs array
T0V(ZB_DEPTHPITCH T0V(ZB_DEPTHPITCH
, ZB_DEPTHPITCH__DEPTHPITCH(1600 >> 2) , ZB_DEPTHPITCH__DEPTHPITCH(pitch >> 2)
| ZB_DEPTHPITCH__DEPTHMACROTILE(1) | ZB_DEPTHPITCH__DEPTHMACROTILE(1)
| ZB_DEPTHPITCH__DEPTHMICROTILE(1) | ZB_DEPTHPITCH__DEPTHMICROTILE(1)
); );
@ -518,7 +520,10 @@ void ib_texture__0()
T0V(TX_ENABLE, 0x00000000); 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 // TX
@ -528,17 +533,21 @@ void ib_texture__1(int reloc_index)
T0V(TX_ENABLE T0V(TX_ENABLE
, TX_ENABLE__TEX_0_ENABLE__ENABLE); , TX_ENABLE__TEX_0_ENABLE__ENABLE);
T0V(TX_FILTER0_0 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 | TX_FILTER0__MIN_FILTER__LINEAR
); );
T0V(TX_FILTER1_0 T0V(TX_FILTER1_0
, TX_FILTER1__LOD_BIAS(1) , TX_FILTER1__LOD_BIAS(1)
| TX_FILTER1__BORDER_FIX(1)
); );
T0V(TX_BORDER_COLOR_0, 0); T0V(TX_BORDER_COLOR_0, 0);
T0V(TX_FORMAT0_0 T0V(TX_FORMAT0_0
, TX_FORMAT0__TXWIDTH(1024 - 1) , TX_FORMAT0__TXWIDTH(width - 1)
| TX_FORMAT0__TXHEIGHT(1024 - 1) | TX_FORMAT0__TXHEIGHT(height - 1)
); );
T0V(TX_FORMAT1_0 T0V(TX_FORMAT1_0
@ -552,9 +561,8 @@ void ib_texture__1(int reloc_index)
T0V(TX_FORMAT2_0, 0); T0V(TX_FORMAT2_0, 0);
T0V(TX_OFFSET_0 T0V(TX_OFFSET_0
//, TX_OFFSET__MACRO_TILE(1) , TX_OFFSET__MACRO_TILE(macrotile)
//| TX_OFFSET__MICRO_TILE(1) | TX_OFFSET__MICRO_TILE(microtile)
, 0
); );
T3(_NOP, 0); T3(_NOP, 0);

View File

@ -55,11 +55,15 @@ extern union u32_f32 ib[16384];
extern volatile int ib_ix; extern volatile int ib_ix;
void ib_generic_initialization(); void ib_generic_initialization();
void ib_colorbuffer(int reloc_index); void ib_viewport(int width, int height);
void ib_zbuffer(int reloc_index, int zfunc); 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_rs_instructions(int count);
void ib_texture__0(); 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_vap_pvs(struct shader_offset * offset);
void ib_ga_us(struct shader_offset * offset); void ib_ga_us(struct shader_offset * offset);
void ib_vap_pvs_const_cntl(const float * consts, int size); void ib_vap_pvs_const_cntl(const float * consts, int size);

View File

@ -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 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 #ifdef __cplusplus
} }
#endif #endif

310
src/r500/texture.c Normal file
View File

@ -0,0 +1,310 @@
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#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;
}

21
src/r500/texture.h Normal file
View File

@ -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

8
src/texture_tile.fs.asm Normal file
View File

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

BIN
src/texture_tile.fs.bin Normal file

Binary file not shown.

1
src/texture_tile.vs.asm Normal file
View File

@ -0,0 +1 @@
out[0].xyzw = VE_ADD input[0].xyzw input[0].0000 ;

BIN
src/texture_tile.vs.bin Normal file

Binary file not shown.