From 88b680f28a9d59268ea4e56df15ebcb80b0876f3 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Thu, 24 Sep 2015 16:41:21 -0700 Subject: [PATCH] don't reparse poly parameters between tri strips reusing the same global parameters --- src/emu/profiler.cc | 3 +- src/hw/holly/tile_renderer.cc | 135 ++++++++++++++++++---------------- src/hw/holly/tile_renderer.h | 3 +- 3 files changed, 75 insertions(+), 66 deletions(-) diff --git a/src/emu/profiler.cc b/src/emu/profiler.cc index d0e17ac6..03981f02 100644 --- a/src/emu/profiler.cc +++ b/src/emu/profiler.cc @@ -30,7 +30,8 @@ static float HueToRGB(float p, float q, float t) { return p; } -static void HSLToRGB(float h, float s, float l, uint8_t *r, uint8_t *g, uint8_t *b) { +static void HSLToRGB(float h, float s, float l, uint8_t *r, uint8_t *g, + uint8_t *b) { float fr, fg, fb; if (s == 0.0f) { diff --git a/src/hw/holly/tile_renderer.cc b/src/hw/holly/tile_renderer.cc index e9dd66b2..688bb93a 100644 --- a/src/hw/holly/tile_renderer.cc +++ b/src/hw/holly/tile_renderer.cc @@ -107,63 +107,7 @@ TileRenderer::TileRenderer(TextureProvider &texture_provider) : texture_provider_(texture_provider) {} void TileRenderer::RenderContext(const TileContext *tactx, Backend *rb) { - PROFILER_GPU("TileRenderer::RenderContext"); - - const uint8_t *data = tactx->data; - const uint8_t *end = tactx->data + tactx->size; - - Reset(); - - ParseBackground(tactx); - - while (data < end) { - PCW pcw = *(PCW *)data; - - // FIXME - // If Vertex Parameters with the "End of Strip" specification were not - // input, but parameters other than the Vertex Parameters were input, the - // polygon data in question is ignored and an interrupt signal is output. - - switch (pcw.para_type) { - // control params - case TA_PARAM_END_OF_LIST: - ParseEndOfList(tactx); - break; - - case TA_PARAM_USER_TILE_CLIP: - last_poly_ = nullptr; - last_vertex_ = nullptr; - break; - - case TA_PARAM_OBJ_LIST_SET: - LOG_FATAL("TA_PARAM_OBJ_LIST_SET unsupported"); - break; - - // global params - case TA_PARAM_POLY_OR_VOL: - ParsePolyParam(tactx, rb, reinterpret_cast(data)); - break; - - case TA_PARAM_SPRITE: - ParsePolyParam(tactx, rb, reinterpret_cast(data)); - break; - - // vertex params - case TA_PARAM_VERTEX: - ParseVertexParam(tactx, rb, - reinterpret_cast(data)); - break; - - default: - LOG_FATAL("Unhandled"); - break; - } - - data += TileAccelerator::GetParamSize(pcw, vertex_type_); - } - - // LOG_INFO("StartRender %d surfs, %d verts, %d bytes", num_surfs_, - // num_verts_, tactx->size); + ParseContext(tactx, rb); const Eigen::Matrix4f &projection = GetProjectionMatrix(tactx); rb->RenderSurfaces(projection, surfs_, num_surfs_, verts_, num_verts_, @@ -183,21 +127,28 @@ void TileRenderer::Reset() { last_sorted_surf_ = 0; } -Surface *TileRenderer::AllocSurf() { +Surface *TileRenderer::AllocSurf(bool copy_from_prev) { CHECK_LT(num_surfs_, MAX_SURFACES); // reuse previous surface if it wasn't completed, else, allocate a new one int id; if (last_vertex_ && !last_vertex_->type0.pcw.end_of_strip) { + CHECK(!copy_from_prev); id = num_surfs_ - 1; } else { id = num_surfs_++; } - // reset the surface + // either reset the surface state, or copy the state from the previous surface Surface *surf = &surfs_[id]; - new (surf) Surface(); + if (copy_from_prev) { + CHECK_GT(id, 0); + *surf = surfs_[id - 1]; + } else { + new (surf) Surface(); + } surf->first_vert = num_verts_; + surf->num_verts = 0; // default sort the surface sorted_surfs_[id] = id; @@ -274,7 +225,7 @@ void TileRenderer::ParseOffsetColor(float intensity, uint32_t *color) { void TileRenderer::ParseBackground(const TileContext *tactx) { // translate the surface - Surface *surf = AllocSurf(); + Surface *surf = AllocSurf(false); surf->texture = 0; surf->depth_write = !tactx->bg_isp.z_write_disable; @@ -355,7 +306,7 @@ void TileRenderer::ParsePolyParam(const TileContext *tactx, Backend *rb, vertex_type_ = TileAccelerator::GetVertexType(param->type0.pcw); // setup the new surface - Surface *surf = AllocSurf(); + Surface *surf = AllocSurf(false); surf->depth_write = !param->type0.isp_tsp.z_write_disable; surf->depth_func = TranslateDepthFunc(param->type0.isp_tsp.depth_compare_mode); @@ -439,8 +390,7 @@ void TileRenderer::ParseVertexParam(const TileContext *tactx, Backend *rb, // the next polygon may be input immediately after inputting a Vertex // Parameter for which "End of Strip" was specified. if (last_vertex_ && last_vertex_->type0.pcw.end_of_strip) { - // start a new surface - ParsePolyParam(tactx, rb, last_poly_); + AllocSurf(true); } last_vertex_ = param; @@ -651,6 +601,63 @@ void TileRenderer::ParseEndOfList(const TileContext *tactx) { last_sorted_surf_ = num_surfs_; } +void TileRenderer::ParseContext(const TileContext *tactx, Backend *rb) { + PROFILER_GPU("TileRenderer::ParseContext"); + + const uint8_t *data = tactx->data; + const uint8_t *end = tactx->data + tactx->size; + + Reset(); + + ParseBackground(tactx); + + while (data < end) { + PCW pcw = *(PCW *)data; + + // FIXME + // If Vertex Parameters with the "End of Strip" specification were not + // input, but parameters other than the Vertex Parameters were input, the + // polygon data in question is ignored and an interrupt signal is output. + + switch (pcw.para_type) { + // control params + case TA_PARAM_END_OF_LIST: + ParseEndOfList(tactx); + break; + + case TA_PARAM_USER_TILE_CLIP: + last_poly_ = nullptr; + last_vertex_ = nullptr; + break; + + case TA_PARAM_OBJ_LIST_SET: + LOG_FATAL("TA_PARAM_OBJ_LIST_SET unsupported"); + break; + + // global params + case TA_PARAM_POLY_OR_VOL: + ParsePolyParam(tactx, rb, reinterpret_cast(data)); + break; + + case TA_PARAM_SPRITE: + ParsePolyParam(tactx, rb, reinterpret_cast(data)); + break; + + // vertex params + case TA_PARAM_VERTEX: + ParseVertexParam(tactx, rb, + reinterpret_cast(data)); + break; + + default: + LOG_FATAL("Unhandled"); + break; + } + + data += TileAccelerator::GetParamSize(pcw, vertex_type_); + } +} + // Vertices coming into the TA are in window space, with the Z component being // 1/W. These coordinates need to be converted back to clip space in order to // be rendered with OpenGL, etc. While we want to perform an orthographic diff --git a/src/hw/holly/tile_renderer.h b/src/hw/holly/tile_renderer.h index 120f6e3e..32a68cc4 100644 --- a/src/hw/holly/tile_renderer.h +++ b/src/hw/holly/tile_renderer.h @@ -49,7 +49,7 @@ class TileRenderer { private: void Reset(); - renderer::Surface *AllocSurf(); + renderer::Surface *AllocSurf(bool copy_from_prev); renderer::Vertex *AllocVert(); void ParseColor(uint32_t base_color, uint32_t *color); void ParseColor(float r, float g, float b, float a, uint32_t *color); @@ -63,6 +63,7 @@ class TileRenderer { void ParseVertexParam(const TileContext *tactx, renderer::Backend *rb, const VertexParam *param); void ParseEndOfList(const TileContext *tactx); + void ParseContext(const TileContext *tactx, renderer::Backend *rb); Eigen::Matrix4f GetProjectionMatrix(const TileContext *tactx); renderer::TextureHandle RegisterTexture(const TileContext *tactx,