Skip to content

sega/powervr2.cpp: move renderer to threaded code #11208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions src/mame/sega/powervr2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,33 @@ void powervr2_device::softreset_w(offs_t offset, uint32_t data, uint32_t mem_mas
}
}

void powervr2_device::startrender_w(address_space &space, uint32_t data)
void powervr2_device::startrender_w(address_space& space, uint32_t data)
{
if (m_render_request)
{
int result;
do
{
result = osd_work_item_wait(m_render_request, 1000);
//printf("waiting\n");

} while (result == 0);
osd_work_item_release(m_render_request);
}

m_render_request = osd_work_item_queue(m_work_queue, blit_request_callback, (void*)this, 0);

dc_state *state = machine().driver_data<dc_state>();

// hacky end of render delay for Capcom games, otherwise they works at ~1/10 speed
int sanitycount = 1500;
endofrender_timer_isp->adjust(state->m_maincpu->cycles_to_attotime(sanitycount*25 + 2000000)); // hacky end of render delay for Capcom games, otherwise they works at ~1/10 speed
}


void powervr2_device::startrender_real_w(address_space &space)
{
//dc_state *state = machine().driver_data<dc_state>();
auto profile = g_profiler.start(PROFILER_USER1);

LOGTACMD("Start render, region=%08x, params=%08x\n", region_base, param_base);
Expand All @@ -1014,7 +1038,7 @@ void powervr2_device::startrender_w(address_space &space, uint32_t data)
grab[a].fbwsof1 = fb_w_sof1;
grab[a].fbwsof2 = fb_w_sof2;

rectangle clip(0, 1023, 0, 1023);
rectangle clip(0, 640, 0, 480);

// we've got a request to draw, so, draw to the accumulation buffer!
// this should really be done for each tile!
Expand Down Expand Up @@ -1074,16 +1098,26 @@ void powervr2_device::startrender_w(address_space &space, uint32_t data)
// vbl-in and expect that it completes after some time that vbl-out kicks in,
// in order to have enough time to execute logic stuff in the meantime.
// const u64 isp_completion = sanitycount * 25 + 500000;
const u64 isp_completion = sanitycount * 25 + 2000000;
LOGIRQ("[%d] ISP end of render start %d in %d cycles\n",
screen().frame_number(), screen().vpos(), isp_completion
);
endofrender_timer_isp->adjust(state->m_maincpu->cycles_to_attotime(isp_completion));
//const u64 isp_completion = sanitycount * 25 + 2000000;
//LOGIRQ("[%d] ISP end of render start %d in %d cycles\n",
// screen().frame_number(), screen().vpos(), isp_completion
//);
//endofrender_timer_isp->adjust(state->m_maincpu->cycles_to_attotime(isp_completion));
break;
}
}
}

void *powervr2_device::blit_request_callback(void *param, int threadid)
{
powervr2_device *object = reinterpret_cast<powervr2_device *>(param);

dc_state *state = object->machine().driver_data<dc_state>();
address_space &space = state->m_maincpu->space(AS_PROGRAM);

object->startrender_real_w(space);
return nullptr;
}

uint32_t powervr2_device::param_base_r()
{
Expand Down Expand Up @@ -4045,6 +4079,9 @@ void powervr2_device::device_start()
save_pointer(NAME(tafifo_buff),32);
save_item(NAME(scanline));
save_item(NAME(next_y));

m_work_queue = nullptr;
m_render_request = nullptr;
}

void powervr2_device::device_reset()
Expand Down Expand Up @@ -4082,6 +4119,8 @@ void powervr2_device::device_reset()
dc_state *state = machine().driver_data<dc_state>();
dc_texture_ram = state->dc_texture_ram.target();
dc_framebuffer_ram = state->dc_framebuffer_ram.target();

m_work_queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_HIGH_FREQ);
}

/* called by TIMER_ADD_PERIODIC, in driver sections (controlled by SPG, that's a PVR sub-device) */
Expand Down
4 changes: 4 additions & 0 deletions src/mame/sega/powervr2.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,16 @@ class powervr2_device : public device_t,
uint32_t tafifo_buff[32];
int scanline;
int next_y;
osd_work_queue *m_work_queue;
osd_work_item *m_render_request;
static void *blit_request_callback(void *param, int threadid);

uint32_t id_r();
uint32_t revision_r();
uint32_t softreset_r();
void softreset_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
void startrender_w(address_space &space, uint32_t data);
void startrender_real_w(address_space &space);
uint32_t param_base_r();
void param_base_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
uint32_t region_base_r();
Expand Down