core: add core_start_render3
This commit is contained in:
parent
1d38f53963
commit
ddd7e1dcb6
@ -14,7 +14,7 @@
|
||||
#include "holly/ta_bits.hpp"
|
||||
#include "holly/region_array.hpp"
|
||||
#include "holly/background.hpp"
|
||||
#include "holly/texture_memory_alloc.hpp"
|
||||
#include "holly/texture_memory_alloc3.hpp"
|
||||
#include "memorymap.hpp"
|
||||
|
||||
#include "geometry/wiffle.hpp"
|
||||
@ -50,7 +50,8 @@ void transform(ta_parameter_writer& parameter,
|
||||
const vec3 lights[3])
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| para_control::list_type::translucent
|
||||
// | obj_control::texture
|
||||
| obj_control::col_type::floating_color
|
||||
| obj_control::gouraud;
|
||||
|
||||
@ -59,7 +60,8 @@ void transform(ta_parameter_writer& parameter,
|
||||
|
||||
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::fog_control::no_fog;
|
||||
| tsp_instruction_word::fog_control::no_fog
|
||||
| tsp_instruction_word::use_alpha;
|
||||
|
||||
parameter.append<ta_global_parameter::polygon_type_0>() =
|
||||
ta_global_parameter::polygon_type_0(parameter_control_word,
|
||||
@ -147,105 +149,26 @@ void transform(ta_parameter_writer& parameter,
|
||||
y += 240.f;
|
||||
z = 1 / z;
|
||||
|
||||
float scale_nx = ((n.x - -1) / (1 - -1)) * (1 - 0);
|
||||
float scale_ny = ((n.y - -1) / (1 - -1)) * (1 - 0);
|
||||
float scale_nz = ((n.z - -1) / (1 - -1)) * (1 - 0);
|
||||
float scale_z = ((point.z - -46) / (46 - -46)) * (1 - 0);
|
||||
|
||||
bool end_of_strip = i == strip_length - 1;
|
||||
|
||||
parameter.append<ta_vertex_parameter::polygon_type_1>() =
|
||||
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
|
||||
x, y, z,
|
||||
1.0,
|
||||
//(point.z + 1) * 90, // alpha
|
||||
//__builtin_fabs(n.x), // r
|
||||
//__builtin_fabs(n.y), // g
|
||||
//__builtin_fabs(n.z) // b
|
||||
1 - scale_z,
|
||||
1 - scale_z,
|
||||
1 - scale_z
|
||||
scale_z, // alpha
|
||||
scale_nx, // r
|
||||
scale_ny, // g
|
||||
scale_nz // b
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void transform2(ta_parameter_writer& parameter,
|
||||
const vec3& pos,
|
||||
const vec4& color)
|
||||
{
|
||||
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
|
||||
| para_control::list_type::opaque
|
||||
| obj_control::col_type::floating_color
|
||||
| obj_control::gouraud;
|
||||
|
||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
|
||||
| isp_tsp_instruction_word::culling_mode::no_culling;
|
||||
|
||||
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
|
||||
| tsp_instruction_word::dst_alpha_instr::zero
|
||||
| tsp_instruction_word::fog_control::no_fog;
|
||||
|
||||
parameter.append<ta_global_parameter::polygon_type_0>() =
|
||||
ta_global_parameter::polygon_type_0(parameter_control_word,
|
||||
isp_tsp_instruction_word,
|
||||
tsp_instruction_word,
|
||||
0, // texture_control_word
|
||||
0, // data_size_for_sort_dma
|
||||
0 // next_address_for_sort_dma
|
||||
);
|
||||
|
||||
constexpr vec3 triangle[] = {
|
||||
{ 0.f, -1.f, 0.f},
|
||||
{-1.f, 1.f, 0.f},
|
||||
{ 1.f, 1.f, 0.f},
|
||||
};
|
||||
|
||||
constexpr uint32_t strip_length = 3;
|
||||
for (uint32_t i = 0; i < strip_length; i++) {
|
||||
float x = triangle[i].x;
|
||||
float y = triangle[i].y;
|
||||
float z = triangle[i].z;
|
||||
|
||||
x *= 0.2;
|
||||
y *= 0.2;
|
||||
z *= 0.2;
|
||||
|
||||
x += pos.x;
|
||||
y += pos.y;
|
||||
z += pos.z;
|
||||
|
||||
// camera transform
|
||||
z += 40;
|
||||
|
||||
// perspective
|
||||
x = x / z;
|
||||
y = y / z;
|
||||
|
||||
// screen space transform
|
||||
x *= 240.f;
|
||||
y *= 240.f;
|
||||
x += 320.f;
|
||||
y += 240.f;
|
||||
z = 1 / z;
|
||||
|
||||
bool end_of_strip = i == strip_length - 1;
|
||||
parameter.append<ta_vertex_parameter::polygon_type_1>() =
|
||||
ta_vertex_parameter::polygon_type_1(polygon_vertex_parameter_control_word(end_of_strip),
|
||||
x, y, z,
|
||||
color.w, // alpha
|
||||
color.x, // r
|
||||
color.y, // g
|
||||
color.z // b
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void init_texture_memory(const struct opb_size& opb_size)
|
||||
{
|
||||
region_array2(640 / 32, // width
|
||||
480 / 32, // height
|
||||
opb_size
|
||||
);
|
||||
background_parameter(0xffc0c0c0);
|
||||
}
|
||||
|
||||
uint32_t _ta_parameter_buf[((32 * 8192) + 32) / 4];
|
||||
uint32_t ta_parameter_buf[((32 * 8192) + 32) / 4]
|
||||
__attribute__((aligned(32)));
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -253,27 +176,29 @@ void main()
|
||||
|
||||
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
|
||||
// This is mandatory for ch2-dma to the ta fifo polygon converter.
|
||||
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
|
||||
|
||||
constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list
|
||||
| ta_alloc_ctrl::tm_opb::no_list
|
||||
| ta_alloc_ctrl::t_opb::no_list
|
||||
| ta_alloc_ctrl::t_opb::_16x4byte
|
||||
| ta_alloc_ctrl::om_opb::no_list
|
||||
| ta_alloc_ctrl::o_opb::_16x4byte;
|
||||
| ta_alloc_ctrl::o_opb::no_list;
|
||||
|
||||
constexpr struct opb_size opb_size = { .opaque = 16 * 4
|
||||
, .opaque_modifier = 0
|
||||
, .translucent = 0
|
||||
, .translucent_modifier = 0
|
||||
, .punch_through = 0
|
||||
};
|
||||
const int render_passes = 1;
|
||||
const struct opb_size opb_size[render_passes] = {
|
||||
{
|
||||
.opaque = 0,
|
||||
.opaque_modifier = 0,
|
||||
.translucent = 16 * 4,
|
||||
.translucent_modifier = 0,
|
||||
.punch_through = 0
|
||||
}
|
||||
};
|
||||
|
||||
holly.SOFTRESET = softreset::pipeline_soft_reset
|
||||
| softreset::ta_soft_reset;
|
||||
holly.SOFTRESET = 0;
|
||||
|
||||
core_init();
|
||||
init_texture_memory(opb_size);
|
||||
|
||||
uint32_t frame_ix = 0;
|
||||
|
||||
@ -284,11 +209,30 @@ void main()
|
||||
{0.f, 0.f, 0.f},
|
||||
};
|
||||
|
||||
const int framebuffer_width = 640;
|
||||
const int framebuffer_height = 480;
|
||||
const int tile_width = framebuffer_width / 32;
|
||||
const int tile_height = framebuffer_height / 32;
|
||||
|
||||
region_array_multipass(tile_width,
|
||||
tile_height,
|
||||
opb_size,
|
||||
render_passes,
|
||||
texture_memory_alloc.region_array[0].start,
|
||||
texture_memory_alloc.object_list[0].start);
|
||||
|
||||
background_parameter2(texture_memory_alloc.background[0].start,
|
||||
0xffc0c0c0);
|
||||
|
||||
while (1) {
|
||||
ta_polygon_converter_init(opb_size.total(),
|
||||
ta_alloc,
|
||||
640 / 32,
|
||||
480 / 32);
|
||||
ta_polygon_converter_init2(texture_memory_alloc.isp_tsp_parameters[0].start,
|
||||
texture_memory_alloc.isp_tsp_parameters[0].end,
|
||||
texture_memory_alloc.object_list[0].start,
|
||||
texture_memory_alloc.object_list[0].end,
|
||||
opb_size[0].total(),
|
||||
ta_alloc,
|
||||
tile_width,
|
||||
tile_height);
|
||||
|
||||
float theta2 = 3.14 * 2 * sin(theta / 7);
|
||||
|
||||
@ -305,21 +249,44 @@ void main()
|
||||
for (uint32_t i = 0; i < MODEL::num_faces; i++) {
|
||||
transform(parameter, i, theta, lights);
|
||||
}
|
||||
/*
|
||||
transform2(parameter, lights[0], {1.f, 0.f, 0.f, 1.f});
|
||||
transform2(parameter, lights[1], {0.f, 1.f, 0.f, 1.f});
|
||||
transform2(parameter, lights[2], {0.f, 0.f, 1.f, 1.f});
|
||||
*/
|
||||
|
||||
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
||||
ta_polygon_converter_transfer(ta_parameter_buf, parameter.offset);
|
||||
ta_wait_opaque_list();
|
||||
core_start_render(frame_ix);
|
||||
ta_wait_translucent_list();
|
||||
|
||||
holly.FB_W_CTRL = fb_w_ctrl::fb_packmode::_8888_argb_32bit;
|
||||
uint32_t bytes_per_pixel = 4;
|
||||
core_start_render3(texture_memory_alloc.region_array[0].start,
|
||||
texture_memory_alloc.isp_tsp_parameters[0].start,
|
||||
texture_memory_alloc.background[0].start,
|
||||
//texture_memory_alloc.framebuffer[0].start,
|
||||
0x100'0000 | texture_memory_alloc.texture.start, // 64-bit area
|
||||
framebuffer_width,
|
||||
bytes_per_pixel);
|
||||
core_wait_end_of_render_video();
|
||||
|
||||
|
||||
|
||||
while (!spg_status::vsync(holly.SPG_STATUS));
|
||||
core_flip(frame_ix);
|
||||
holly.FB_R_SOF1 = texture_memory_alloc.framebuffer[0].start;
|
||||
while (spg_status::vsync(holly.SPG_STATUS));
|
||||
|
||||
theta += half_degree;
|
||||
frame_ix = (frame_ix + 1) & 1;
|
||||
/*
|
||||
holly.FB_R_CTRL = fb_r_ctrl::vclk_div::pclk_vclk_1
|
||||
| fb_r_ctrl::fb_depth::_0888_rgb_32bit
|
||||
| fb_r_ctrl::fb_enable;
|
||||
|
||||
holly.FB_R_SIZE = fb_r_size::fb_modulus(1)
|
||||
| fb_r_size::fb_y_size(480 - 3)
|
||||
| fb_r_size::fb_x_size((640 * 32) / 32 - 1);
|
||||
*/
|
||||
|
||||
//theta += half_degree;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -110,6 +110,30 @@ void core_start_render2(uint32_t region_array_start,
|
||||
holly.STARTRENDER = 1;
|
||||
}
|
||||
|
||||
void core_start_render3(uint32_t region_array_start,
|
||||
uint32_t isp_tsp_parameters_start,
|
||||
uint32_t background_start,
|
||||
uint32_t frame_address,
|
||||
uint32_t frame_width, // in pixels
|
||||
uint32_t bytes_per_pixel
|
||||
)
|
||||
{
|
||||
holly.REGION_BASE = region_array_start;
|
||||
holly.PARAM_BASE = isp_tsp_parameters_start;
|
||||
|
||||
uint32_t background_offset = background_start - isp_tsp_parameters_start;
|
||||
holly.ISP_BACKGND_T = isp_backgnd_t::tag_address(background_offset / 4)
|
||||
| isp_backgnd_t::tag_offset(0)
|
||||
| isp_backgnd_t::skip(1);
|
||||
holly.ISP_BACKGND_D = _i(1.f/100000.f);
|
||||
|
||||
holly.FB_W_LINESTRIDE = (frame_width * bytes_per_pixel) / 8;
|
||||
|
||||
holly.FB_W_SOF1 = frame_address;
|
||||
|
||||
holly.STARTRENDER = 1;
|
||||
}
|
||||
|
||||
void core_wait_end_of_render_video()
|
||||
{
|
||||
/*
|
||||
|
@ -14,5 +14,13 @@ void core_start_render2(uint32_t region_array_start,
|
||||
uint32_t frame_width // in pixels
|
||||
);
|
||||
|
||||
void core_start_render3(uint32_t region_array_start,
|
||||
uint32_t isp_tsp_parameters_start,
|
||||
uint32_t background_start,
|
||||
uint32_t frame_address,
|
||||
uint32_t frame_width, // in pixels
|
||||
uint32_t bytes_per_pixel
|
||||
);
|
||||
|
||||
void core_wait_end_of_render_video();
|
||||
void core_flip(uint32_t frame_ix);
|
||||
|
@ -207,12 +207,12 @@ def parse_object_lists(mem, region_array_entry):
|
||||
parse_object_list(mem, region_array_entry.punch_through_list_pointer)
|
||||
|
||||
|
||||
region_array = 0x296000
|
||||
framebuffer = 0x200000
|
||||
region_array = 0x10_0000
|
||||
framebuffer = 0x11_0000
|
||||
region_array_entries = list(parse_region_array(mem, region_array))
|
||||
|
||||
for region_array_entry in region_array_entries:
|
||||
parse_object_lists(mem, region_array_entry)
|
||||
|
||||
#with open('framebuffer.data', 'wb') as f:
|
||||
# f.write(mem[framebuffer:framebuffer + 640 * 480 * 2])
|
||||
with open('framebuffer.data', 'wb') as f:
|
||||
f.write(mem[framebuffer:framebuffer + 640 * 480 * 4])
|
||||
|
Loading…
x
Reference in New Issue
Block a user