Address Lioncash's comments

This commit is contained in:
James Rowe 2018-02-05 20:31:50 -07:00
parent 9e16a3c449
commit 18456ff9e6
3 changed files with 30 additions and 33 deletions

View File

@ -1074,15 +1074,14 @@ bool RasterizerOpenGL::AccelerateTextureCopy(const GPU::Regs::DisplayTransferCon
SurfaceParams dst_params = *src_surface; SurfaceParams dst_params = *src_surface;
dst_params.addr = config.GetPhysicalOutputAddress(); dst_params.addr = config.GetPhysicalOutputAddress();
dst_params.width = src_rect.GetWidth() / src_surface->res_scale; dst_params.width = src_rect.GetWidth() / src_surface->res_scale;
dst_params.stride = dst_params.stride = dst_params.width + src_surface->PixelsInBytes(
dst_params.width + src_surface->is_tiled ? output_gap / 8 : output_gap);
src_surface->PixelsInBytes(src_surface->is_tiled ? output_gap / 8 : output_gap);
dst_params.height = src_rect.GetHeight() / src_surface->res_scale; dst_params.height = src_rect.GetHeight() / src_surface->res_scale;
dst_params.res_scale = src_surface->res_scale; dst_params.res_scale = src_surface->res_scale;
dst_params.UpdateParams(); dst_params.UpdateParams();
const bool load_gap = output_gap != 0; // Since we are going to invalidate the gap if there is // Since we are going to invalidate the gap if there is one, we will have to load it first
// one, we will have to load it first const bool load_gap = output_gap != 0;
MathUtil::Rectangle<u32> dst_rect; MathUtil::Rectangle<u32> dst_rect;
Surface dst_surface; Surface dst_surface;
std::tie(dst_surface, dst_rect) = std::tie(dst_surface, dst_rect) =
@ -1391,7 +1390,8 @@ void RasterizerOpenGL::SyncBlendColor() {
void RasterizerOpenGL::SyncFogColor() { void RasterizerOpenGL::SyncFogColor() {
const auto& regs = Pica::g_state.regs; const auto& regs = Pica::g_state.regs;
uniform_block_data.data.fog_color = { uniform_block_data.data.fog_color = {
regs.texturing.fog_color.r.Value() / 255.0f, regs.texturing.fog_color.g.Value() / 255.0f, regs.texturing.fog_color.r.Value() / 255.0f,
regs.texturing.fog_color.g.Value() / 255.0f,
regs.texturing.fog_color.b.Value() / 255.0f, regs.texturing.fog_color.b.Value() / 255.0f,
}; };
uniform_block_data.dirty = true; uniform_block_data.dirty = true;
@ -1419,7 +1419,8 @@ void RasterizerOpenGL::SyncProcTexNoise() {
Pica::float16::FromRaw(regs.proctex_noise_frequency.v).ToFloat32(), Pica::float16::FromRaw(regs.proctex_noise_frequency.v).ToFloat32(),
}; };
uniform_block_data.data.proctex_noise_a = { uniform_block_data.data.proctex_noise_a = {
regs.proctex_noise_u.amplitude / 4095.0f, regs.proctex_noise_v.amplitude / 4095.0f, regs.proctex_noise_u.amplitude / 4095.0f,
regs.proctex_noise_v.amplitude / 4095.0f,
}; };
uniform_block_data.data.proctex_noise_p = { uniform_block_data.data.proctex_noise_p = {
Pica::float16::FromRaw(regs.proctex_noise_u.phase).ToFloat32(), Pica::float16::FromRaw(regs.proctex_noise_u.phase).ToFloat32(),

View File

@ -60,15 +60,14 @@ static constexpr FormatTuple tex_tuple = {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE};
static const FormatTuple& GetFormatTuple(PixelFormat pixel_format) { static const FormatTuple& GetFormatTuple(PixelFormat pixel_format) {
const SurfaceType type = SurfaceParams::GetFormatType(pixel_format); const SurfaceType type = SurfaceParams::GetFormatType(pixel_format);
if (type == SurfaceType::Color) { if (type == SurfaceType::Color) {
ASSERT((size_t)pixel_format < fb_format_tuples.size()); ASSERT(static_cast<size_t>(pixel_format) < fb_format_tuples.size());
return fb_format_tuples[(unsigned int)pixel_format]; return fb_format_tuples[static_cast<unsigned int>(pixel_format)];
} else if (type == SurfaceType::Depth || type == SurfaceType::DepthStencil) { } else if (type == SurfaceType::Depth || type == SurfaceType::DepthStencil) {
size_t tuple_idx = (size_t)pixel_format - 14; size_t tuple_idx = static_cast<size_t>(pixel_format) - 14;
ASSERT(tuple_idx < depth_format_tuples.size()); ASSERT(tuple_idx < depth_format_tuples.size());
return depth_format_tuples[tuple_idx]; return depth_format_tuples[tuple_idx];
} else {
return tex_tuple;
} }
return tex_tuple;
} }
template <typename Map, typename Interval> template <typename Map, typename Interval>
@ -244,7 +243,6 @@ static bool BlitTextures(GLuint src_tex, const MathUtil::Rectangle<u32>& src_rec
state.ResetTexture(src_tex); state.ResetTexture(src_tex);
state.ResetTexture(dst_tex); state.ResetTexture(dst_tex);
// Keep track of previous framebuffer bindings
state.draw.read_framebuffer = read_fb_handle; state.draw.read_framebuffer = read_fb_handle;
state.draw.draw_framebuffer = draw_fb_handle; state.draw.draw_framebuffer = draw_fb_handle;
state.Apply(); state.Apply();
@ -355,7 +353,7 @@ static bool FillSurface(const Surface& surface, const u8* fill_data,
surface->texture.handle, 0); surface->texture.handle, 0);
u32 value_32bit; u32 value_32bit;
std::memcpy(&value_32bit, fill_data, 4); std::memcpy(&value_32bit, fill_data, sizeof(u32));
GLfloat value_float = (value_32bit & 0xFFFFFF) / 16777215.0f; // 2^24 - 1 GLfloat value_float = (value_32bit & 0xFFFFFF) / 16777215.0f; // 2^24 - 1
GLint value_int = (value_32bit >> 24); GLint value_int = (value_32bit >> 24);
@ -370,8 +368,8 @@ static bool FillSurface(const Surface& surface, const u8* fill_data,
SurfaceParams SurfaceParams::FromInterval(SurfaceInterval interval) const { SurfaceParams SurfaceParams::FromInterval(SurfaceInterval interval) const {
SurfaceParams params = *this; SurfaceParams params = *this;
const u32 tiled_size = is_tiled ? 8 : 1;
const u32 stride_tiled_bytes = BytesInPixels(stride * (is_tiled ? 8 : 1)); const u32 stride_tiled_bytes = BytesInPixels(stride * tiled_size);
PAddr aligned_start = PAddr aligned_start =
addr + Common::AlignDown(boost::icl::first(interval) - addr, stride_tiled_bytes); addr + Common::AlignDown(boost::icl::first(interval) - addr, stride_tiled_bytes);
PAddr aligned_end = PAddr aligned_end =
@ -389,9 +387,9 @@ SurfaceParams SurfaceParams::FromInterval(SurfaceInterval interval) const {
aligned_end = aligned_end =
addr + Common::AlignUp(boost::icl::last_next(interval) - addr, tiled_alignment); addr + Common::AlignUp(boost::icl::last_next(interval) - addr, tiled_alignment);
params.addr = aligned_start; params.addr = aligned_start;
params.width = PixelsInBytes(aligned_end - aligned_start) / (is_tiled ? 8 : 1); params.width = PixelsInBytes(aligned_end - aligned_start) / tiled_size;
params.stride = params.width; params.stride = params.width;
params.height = is_tiled ? 8 : 1; params.height = tiled_size;
} }
params.UpdateParams(); params.UpdateParams();
@ -410,7 +408,7 @@ SurfaceInterval SurfaceParams::GetSubRectInterval(MathUtil::Rectangle<u32> unsca
unscaled_rect.top = Common::AlignUp(unscaled_rect.top, 8) / 8; unscaled_rect.top = Common::AlignUp(unscaled_rect.top, 8) / 8;
} }
const u32 stride_tiled = (!is_tiled ? stride : stride * 8); const u32 stride_tiled = !is_tiled ? stride : stride * 8;
const u32 pixel_offset = const u32 pixel_offset =
stride_tiled * (!is_tiled ? unscaled_rect.bottom : (height / 8) - unscaled_rect.top) + stride_tiled * (!is_tiled ? unscaled_rect.bottom : (height / 8) - unscaled_rect.top) +
@ -448,10 +446,10 @@ MathUtil::Rectangle<u32> SurfaceParams::GetScaledSubRect(const SurfaceParams& su
} }
bool SurfaceParams::ExactMatch(const SurfaceParams& other_surface) const { bool SurfaceParams::ExactMatch(const SurfaceParams& other_surface) const {
return other_surface.addr == addr && other_surface.width == width && return std::tie(other_surface.addr, other_surface.width, other_surface.height,
other_surface.height == height && other_surface.stride == stride && other_surface.stride, other_surface.pixel_format, other_surface.is_tiled) ==
other_surface.pixel_format == pixel_format && pixel_format != PixelFormat::Invalid && std::tie(addr, width, height, stride, pixel_format, is_tiled) &&
other_surface.is_tiled == is_tiled; pixel_format != PixelFormat::Invalid;
} }
bool SurfaceParams::CanSubRect(const SurfaceParams& sub_surface) const { bool SurfaceParams::CanSubRect(const SurfaceParams& sub_surface) const {
@ -483,10 +481,8 @@ bool SurfaceParams::CanTexCopy(const SurfaceParams& texcopy_params) const {
texcopy_params.width % BytesInPixels(is_tiled ? 64 : 1) == 0 && texcopy_params.width % BytesInPixels(is_tiled ? 64 : 1) == 0 &&
(texcopy_params.height == 1 || texcopy_params.stride == tile_stride) && (texcopy_params.height == 1 || texcopy_params.stride == tile_stride) &&
((texcopy_params.addr - addr) % tile_stride) + texcopy_params.width <= tile_stride; ((texcopy_params.addr - addr) % tile_stride) + texcopy_params.width <= tile_stride;
} else {
return FromInterval(texcopy_params.GetInterval()).GetInterval() ==
texcopy_params.GetInterval();
} }
return FromInterval(texcopy_params.GetInterval()).GetInterval() == texcopy_params.GetInterval();
} }
bool CachedSurface::CanFill(const SurfaceParams& dest_surface, bool CachedSurface::CanFill(const SurfaceParams& dest_surface,
@ -688,9 +684,10 @@ void CachedSurface::FlushGLBuffer(PAddr flush_start, PAddr flush_end) {
if (backup_bytes) if (backup_bytes)
std::memcpy(&backup_data[0], &dst_buffer[coarse_start_offset], backup_bytes); std::memcpy(&backup_data[0], &dst_buffer[coarse_start_offset], backup_bytes);
for (u32 offset = coarse_start_offset; offset < end_offset; offset += fill_size) for (u32 offset = coarse_start_offset; offset < end_offset; offset += fill_size) {
std::memcpy(&dst_buffer[offset], &fill_data[0], std::memcpy(&dst_buffer[offset], &fill_data[0],
std::min(fill_size, end_offset - offset)); std::min(fill_size, end_offset - offset));
}
if (backup_bytes) if (backup_bytes)
std::memcpy(&dst_buffer[coarse_start_offset], &backup_data[0], backup_bytes); std::memcpy(&dst_buffer[coarse_start_offset], &backup_data[0], backup_bytes);
@ -1350,12 +1347,11 @@ SurfaceRect_Tuple RasterizerCacheOpenGL::GetTexCopySurface(const SurfaceParams&
SurfaceParams match_subrect; SurfaceParams match_subrect;
if (params.width != params.stride) { if (params.width != params.stride) {
const u32 tiled_size = match_surface->is_tiled ? 8 : 1;
match_subrect = params; match_subrect = params;
match_subrect.width = match_subrect.width = match_surface->PixelsInBytes(params.width) / tiled_size;
match_surface->PixelsInBytes(params.width) / (match_surface->is_tiled ? 8 : 1); match_subrect.stride = match_surface->PixelsInBytes(params.stride) / tiled_size;
match_subrect.stride = match_subrect.height *= tiled_size;
match_surface->PixelsInBytes(params.stride) / (match_surface->is_tiled ? 8 : 1);
match_subrect.height *= (match_surface->is_tiled ? 8 : 1);
} else { } else {
match_subrect = match_surface->FromInterval(params.GetInterval()); match_subrect = match_surface->FromInterval(params.GetInterval());
ASSERT(match_subrect.GetInterval() == params.GetInterval()); ASSERT(match_subrect.GetInterval() == params.GetInterval());

View File

@ -135,7 +135,7 @@ public:
if (handle == 0) if (handle == 0)
return; return;
glDeleteBuffers(1, &handle); glDeleteBuffers(1, &handle);
OpenGLState::GetCurState().OpenGLState::ResetBuffer(handle).Apply(); OpenGLState::GetCurState().ResetBuffer(handle).Apply();
handle = 0; handle = 0;
} }