mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Merge pull request #204 from neobrain/bitfield_cleanup
Bitfield cleanup
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
// Copyright 2014 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
|
||||
// Copyright 2014 Tony Wasserka
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the owner nor the names of its contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
/*
|
||||
* Abstract bitfield class
|
||||
*
|
||||
* Allows endianness-independent access to individual bitfields within some raw
|
||||
* integer value. The assembly generated by this class is identical to the
|
||||
* usage of raw bitfields, so it's a perfectly fine replacement.
|
||||
*
|
||||
* For BitField<X,Y,Z>, X is the distance of the bitfield to the LSB of the
|
||||
* raw value, Y is the length in bits of the bitfield. Z is an integer type
|
||||
* which determines the sign of the bitfield. Z must have the same size as the
|
||||
* raw integer.
|
||||
*
|
||||
*
|
||||
* General usage:
|
||||
*
|
||||
* Create a new union with the raw integer value as a member.
|
||||
* Then for each bitfield you want to expose, add a BitField member
|
||||
* in the union. The template parameters are the bit offset and the number
|
||||
* of desired bits.
|
||||
*
|
||||
* Changes in the bitfield members will then get reflected in the raw integer
|
||||
* value and vice-versa.
|
||||
*
|
||||
*
|
||||
* Sample usage:
|
||||
*
|
||||
* union SomeRegister
|
||||
* {
|
||||
* u32 hex;
|
||||
*
|
||||
* BitField<0,7,u32> first_seven_bits; // unsigned
|
||||
* BitField<7,8,32> next_eight_bits; // unsigned
|
||||
* BitField<3,15,s32> some_signed_fields; // signed
|
||||
* };
|
||||
*
|
||||
* This is equivalent to the little-endian specific code:
|
||||
*
|
||||
* union SomeRegister
|
||||
* {
|
||||
* u32 hex;
|
||||
*
|
||||
* struct
|
||||
* {
|
||||
* u32 first_seven_bits : 7;
|
||||
* u32 next_eight_bits : 8;
|
||||
* };
|
||||
* struct
|
||||
* {
|
||||
* u32 : 3; // padding
|
||||
* s32 some_signed_fields : 15;
|
||||
* };
|
||||
* };
|
||||
*
|
||||
*
|
||||
* Caveats:
|
||||
*
|
||||
* BitField provides automatic casting from and to the storage type where
|
||||
* appropriate. However, when using non-typesafe functions like printf, an
|
||||
* explicit cast must be performed on the BitField object to make sure it gets
|
||||
* passed correctly, e.g.:
|
||||
* printf("Value: %d", (s32)some_register.some_signed_fields);
|
||||
*
|
||||
*/
|
||||
template<std::size_t position, std::size_t bits, typename T>
|
||||
struct BitField
|
||||
{
|
||||
private:
|
||||
// This constructor might be considered ambiguous:
|
||||
// Would it initialize the storage or just the bitfield?
|
||||
// Hence, delete it. Use the assignment operator to set bitfield values!
|
||||
BitField(T val) = delete;
|
||||
|
||||
public:
|
||||
// Force default constructor to be created
|
||||
// so that we can use this within unions
|
||||
BitField() = default;
|
||||
|
||||
BitField& operator=(T val)
|
||||
{
|
||||
storage = (storage & ~GetMask()) | ((val << position) & GetMask());
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T() const
|
||||
{
|
||||
if (std::numeric_limits<T>::is_signed)
|
||||
{
|
||||
std::size_t shift = 8 * sizeof(T) - bits;
|
||||
return (T)(((storage & GetMask()) << (shift - position)) >> shift);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T)((storage & GetMask()) >> position);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// StorageType is T for non-enum types and the underlying type of T if
|
||||
// T is an enumeration. Note that T is wrapped within an enable_if in the
|
||||
// former case to workaround compile errors which arise when using
|
||||
// std::underlying_type<T>::type directly.
|
||||
typedef typename std::conditional<std::is_enum<T>::value,
|
||||
std::underlying_type<T>,
|
||||
std::enable_if<true,T>>::type::type StorageType;
|
||||
|
||||
// Unsigned version of StorageType
|
||||
typedef typename std::make_unsigned<StorageType>::type StorageTypeU;
|
||||
|
||||
StorageType GetMask() const
|
||||
{
|
||||
return ((~(StorageTypeU)0) >> (8*sizeof(T) - bits)) << position;
|
||||
}
|
||||
|
||||
StorageType storage;
|
||||
|
||||
static_assert(bits + position <= 8 * sizeof(T), "Bitfield out of range");
|
||||
|
||||
// And, you know, just in case people specify something stupid like bits=position=0x80000000
|
||||
static_assert(position < 8 * sizeof(T), "Invalid position");
|
||||
static_assert(bits <= 8 * sizeof(T), "Invalid number of bits");
|
||||
static_assert(bits > 0, "Invalid number of bits");
|
||||
};
|
||||
@@ -46,6 +46,7 @@
|
||||
<ClInclude Include="Atomic.h" />
|
||||
<ClInclude Include="Atomic_GCC.h" />
|
||||
<ClInclude Include="Atomic_Win32.h" />
|
||||
<ClInclude Include="BitField.h" />
|
||||
<ClInclude Include="BreakPoints.h" />
|
||||
<ClInclude Include="CDUtils.h" />
|
||||
<ClInclude Include="ChunkFile.h" />
|
||||
@@ -143,4 +144,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<ClInclude Include="Atomic.h" />
|
||||
<ClInclude Include="Atomic_GCC.h" />
|
||||
<ClInclude Include="Atomic_Win32.h" />
|
||||
<ClInclude Include="BitField.h" />
|
||||
<ClInclude Include="BreakPoints.h" />
|
||||
<ClInclude Include="CDUtils.h" />
|
||||
<ClInclude Include="ChunkFile.h" />
|
||||
@@ -110,4 +111,4 @@
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -246,7 +246,7 @@ void FifoPlaybackAnalyzer::StoreEfbCopyRegion()
|
||||
UPE_Copy peCopy = m_BpMem.triggerEFBCopy;
|
||||
|
||||
u32 copyfmt = peCopy.tp_realFormat();
|
||||
bool bFromZBuffer = m_BpMem.zcontrol.pixel_format == PIXELFMT_Z24;
|
||||
bool bFromZBuffer = m_BpMem.zcontrol.pixel_format == PEControl::Z24;
|
||||
u32 address = bpmem.copyTexDest << 5;
|
||||
|
||||
u32 format = copyfmt;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "VideoBackends/D3D/PSTextureEncoder.h"
|
||||
#include "VideoBackends/D3D/Render.h"
|
||||
#include "VideoBackends/D3D/TextureCache.h"
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
|
||||
// "Static mode" will compile a new EFB encoder shader for every combination of
|
||||
// encoding configurations. It's compatible with Shader Model 4.
|
||||
@@ -1031,8 +1030,8 @@ void PSTextureEncoder::Shutdown()
|
||||
}
|
||||
|
||||
size_t PSTextureEncoder::Encode(u8* dst, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect, bool isIntensity,
|
||||
bool scaleByHalf)
|
||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||
bool isIntensity, bool scaleByHalf)
|
||||
{
|
||||
if (!m_ready) // Make sure we initialized OK
|
||||
return 0;
|
||||
@@ -1122,7 +1121,7 @@ size_t PSTextureEncoder::Encode(u8* dst, unsigned int dstFormat,
|
||||
|
||||
D3D::context->OMSetRenderTargets(1, &m_outRTV, nullptr);
|
||||
|
||||
ID3D11ShaderResourceView* pEFB = (srcFormat == PIXELFMT_Z24) ?
|
||||
ID3D11ShaderResourceView* pEFB = (srcFormat == PEControl::Z24) ?
|
||||
FramebufferManager::GetEFBDepthTexture()->GetSRV() :
|
||||
// FIXME: Instead of resolving EFB, it would be better to pick out a
|
||||
// single sample from each pixel. The game may break if it isn't
|
||||
@@ -1208,10 +1207,10 @@ static const char* INTENSITY_FUNC_NAMES[2] = {
|
||||
"Intensity_0", "Intensity_1"
|
||||
};
|
||||
|
||||
bool PSTextureEncoder::SetStaticShader(unsigned int dstFormat, unsigned int srcFormat,
|
||||
bool PSTextureEncoder::SetStaticShader(unsigned int dstFormat, PEControl::PixelFormat srcFormat,
|
||||
bool isIntensity, bool scaleByHalf)
|
||||
{
|
||||
size_t fetchNum = srcFormat;
|
||||
size_t fetchNum = static_cast<size_t>(srcFormat);
|
||||
size_t scaledFetchNum = scaleByHalf ? 1 : 0;
|
||||
size_t intensityNum = isIntensity ? 1 : 0;
|
||||
size_t generatorNum = dstFormat;
|
||||
@@ -1244,7 +1243,7 @@ bool PSTextureEncoder::SetStaticShader(unsigned int dstFormat, unsigned int srcF
|
||||
}
|
||||
|
||||
INFO_LOG(VIDEO, "Compiling efb encoding shader for dstFormat 0x%X, srcFormat %d, isIntensity %d, scaleByHalf %d",
|
||||
dstFormat, srcFormat, isIntensity ? 1 : 0, scaleByHalf ? 1 : 0);
|
||||
dstFormat, static_cast<int>(srcFormat), isIntensity ? 1 : 0, scaleByHalf ? 1 : 0);
|
||||
|
||||
// Shader permutation not found, so compile it
|
||||
D3DBlob* bytecode = nullptr;
|
||||
@@ -1258,7 +1257,7 @@ bool PSTextureEncoder::SetStaticShader(unsigned int dstFormat, unsigned int srcF
|
||||
if (!D3D::CompilePixelShader(EFB_ENCODE_PS, sizeof(EFB_ENCODE_PS), &bytecode, macros))
|
||||
{
|
||||
WARN_LOG(VIDEO, "EFB encoder shader for dstFormat 0x%X, srcFormat %d, isIntensity %d, scaleByHalf %d failed to compile",
|
||||
dstFormat, srcFormat, isIntensity ? 1 : 0, scaleByHalf ? 1 : 0);
|
||||
dstFormat, static_cast<int>(srcFormat), isIntensity ? 1 : 0, scaleByHalf ? 1 : 0);
|
||||
// Add dummy shader to map to prevent trying to compile over and
|
||||
// over again
|
||||
m_staticShaders[key] = nullptr;
|
||||
@@ -1369,9 +1368,9 @@ static const char* INTENSITY_CLASS_NAMES[2] = {
|
||||
};
|
||||
|
||||
bool PSTextureEncoder::SetDynamicShader(unsigned int dstFormat,
|
||||
unsigned int srcFormat, bool isIntensity, bool scaleByHalf)
|
||||
PEControl::PixelFormat srcFormat, bool isIntensity, bool scaleByHalf)
|
||||
{
|
||||
size_t fetchNum = srcFormat;
|
||||
size_t fetchNum = static_cast<size_t>(srcFormat);
|
||||
size_t scaledFetchNum = scaleByHalf ? 1 : 0;
|
||||
size_t intensityNum = isIntensity ? 1 : 0;
|
||||
size_t generatorNum = dstFormat;
|
||||
|
||||
@@ -32,8 +32,8 @@ public:
|
||||
void Init();
|
||||
void Shutdown();
|
||||
size_t Encode(u8* dst, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect, bool isIntensity,
|
||||
bool scaleByHalf);
|
||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||
bool isIntensity, bool scaleByHalf);
|
||||
|
||||
private:
|
||||
|
||||
@@ -54,15 +54,15 @@ private:
|
||||
// Stuff only used in static-linking mode (SM4.0-compatible)
|
||||
|
||||
bool InitStaticMode();
|
||||
bool SetStaticShader(unsigned int dstFormat, unsigned int srcFormat,
|
||||
bool isIntensity, bool scaleByHalf);
|
||||
bool SetStaticShader(unsigned int dstFormat,
|
||||
PEControl::PixelFormat srcFormat, bool isIntensity, bool scaleByHalf);
|
||||
|
||||
typedef unsigned int ComboKey; // Key for a shader combination
|
||||
|
||||
ComboKey MakeComboKey(unsigned int dstFormat, unsigned int srcFormat,
|
||||
bool isIntensity, bool scaleByHalf)
|
||||
ComboKey MakeComboKey(unsigned int dstFormat,
|
||||
PEControl::PixelFormat srcFormat, bool isIntensity, bool scaleByHalf)
|
||||
{
|
||||
return (dstFormat << 4) | (srcFormat << 2) | (isIntensity ? (1<<1) : 0)
|
||||
return (dstFormat << 4) | (static_cast<int>(srcFormat) << 2) | (isIntensity ? (1<<1) : 0)
|
||||
| (scaleByHalf ? (1<<0) : 0);
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ private:
|
||||
// Microsoft fixes their bloody HLSL compiler)
|
||||
|
||||
bool InitDynamicMode();
|
||||
bool SetDynamicShader(unsigned int dstFormat, unsigned int srcFormat,
|
||||
bool isIntensity, bool scaleByHalf);
|
||||
bool SetDynamicShader(unsigned int dstFormat,
|
||||
PEControl::PixelFormat srcFormat, bool isIntensity, bool scaleByHalf);
|
||||
|
||||
ID3D11PixelShader* m_dynamicShader;
|
||||
ID3D11ClassLinkage* m_classLinkage;
|
||||
|
||||
@@ -315,7 +315,7 @@ void Renderer::SetColorMask()
|
||||
UINT8 color_mask = 0;
|
||||
if (bpmem.alpha_test.TestResult() != AlphaTest::FAIL)
|
||||
{
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24))
|
||||
color_mask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
|
||||
if (bpmem.blendmode.colorupdate)
|
||||
color_mask |= D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_BLUE;
|
||||
@@ -409,7 +409,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
|
||||
|
||||
float val = *(float*)map.pData;
|
||||
u32 ret = 0;
|
||||
if (bpmem.zcontrol.pixel_format == PIXELFMT_RGB565_Z16)
|
||||
if (bpmem.zcontrol.pixel_format == PEControl::RGB565_Z16)
|
||||
{
|
||||
// if Z is in 16 bit format you must return a 16 bit integer
|
||||
ret = ((u32)(val * 0xffff));
|
||||
@@ -440,15 +440,15 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
|
||||
// check what to do with the alpha channel (GX_PokeAlphaRead)
|
||||
PixelEngine::UPEAlphaReadReg alpha_read_mode = PixelEngine::GetAlphaReadMode();
|
||||
|
||||
if (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24)
|
||||
if (bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24)
|
||||
{
|
||||
ret = RGBA8ToRGBA6ToRGBA8(ret);
|
||||
}
|
||||
else if (bpmem.zcontrol.pixel_format == PIXELFMT_RGB565_Z16)
|
||||
else if (bpmem.zcontrol.pixel_format == PEControl::RGB565_Z16)
|
||||
{
|
||||
ret = RGBA8ToRGB565ToRGBA8(ret);
|
||||
}
|
||||
if (bpmem.zcontrol.pixel_format != PIXELFMT_RGBA6_Z24)
|
||||
if (bpmem.zcontrol.pixel_format != PEControl::RGBA6_Z24)
|
||||
{
|
||||
ret |= 0xFF000000;
|
||||
}
|
||||
@@ -634,7 +634,7 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
{
|
||||
// Our render target always uses an alpha channel, so we need to override the blend functions to assume a destination alpha of 1 if the render target isn't supposed to have an alpha channel
|
||||
// Example: D3DBLEND_DESTALPHA needs to be D3DBLEND_ONE since the result without an alpha channel is assumed to always be 1.
|
||||
bool target_has_alpha = bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||
bool target_has_alpha = bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24;
|
||||
const D3D11_BLEND d3dSrcFactors[8] =
|
||||
{
|
||||
D3D11_BLEND_ZERO,
|
||||
|
||||
@@ -121,7 +121,7 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
|
||||
}
|
||||
|
||||
void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect,
|
||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||
const float *colmat)
|
||||
{
|
||||
@@ -159,9 +159,9 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
|
||||
// Create texture copy
|
||||
D3D::drawShadedTexQuad(
|
||||
(srcFormat == PIXELFMT_Z24) ? FramebufferManager::GetEFBDepthTexture()->GetSRV() : FramebufferManager::GetEFBColorTexture()->GetSRV(),
|
||||
(srcFormat == PEControl::Z24) ? FramebufferManager::GetEFBDepthTexture()->GetSRV() : FramebufferManager::GetEFBColorTexture()->GetSRV(),
|
||||
&sourcerect, Renderer::GetTargetWidth(), Renderer::GetTargetHeight(),
|
||||
(srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram(true) : PixelShaderCache::GetColorMatrixProgram(true),
|
||||
(srcFormat == PEControl::Z24) ? PixelShaderCache::GetDepthMatrixProgram(true) : PixelShaderCache::GetColorMatrixProgram(true),
|
||||
VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout());
|
||||
|
||||
D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), FramebufferManager::GetEFBDepthTexture()->GetDSV());
|
||||
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
unsigned int expanded_width, unsigned int levels) override;
|
||||
|
||||
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect,
|
||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||
const float *colmat) override;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
|
||||
namespace DX11
|
||||
@@ -111,8 +112,8 @@ public:
|
||||
virtual void Shutdown() = 0;
|
||||
// Returns size in bytes of encoded block of memory
|
||||
virtual size_t Encode(u8* dst, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect, bool isIntensity,
|
||||
bool scaleByHalf) = 0;
|
||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||
bool isIntensity, bool scaleByHalf) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -877,7 +877,7 @@ void Renderer::SetColorMask()
|
||||
{
|
||||
if (bpmem.blendmode.colorupdate)
|
||||
ColorMask = GL_TRUE;
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24))
|
||||
if (bpmem.blendmode.alphaupdate && (bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24))
|
||||
AlphaMask = GL_TRUE;
|
||||
}
|
||||
glColorMask(ColorMask, ColorMask, ColorMask, AlphaMask);
|
||||
@@ -989,7 +989,7 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
|
||||
// Scale the 32-bit value returned by glReadPixels to a 24-bit
|
||||
// value (GC uses a 24-bit Z-buffer).
|
||||
// TODO: in RE0 this value is often off by one, which causes lighting to disappear
|
||||
if (bpmem.zcontrol.pixel_format == PIXELFMT_RGB565_Z16)
|
||||
if (bpmem.zcontrol.pixel_format == PEControl::RGB565_Z16)
|
||||
{
|
||||
// if Z is in 16 bit format you must return a 16 bit integer
|
||||
z = z >> 16;
|
||||
@@ -1047,15 +1047,15 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
|
||||
// check what to do with the alpha channel (GX_PokeAlphaRead)
|
||||
PixelEngine::UPEAlphaReadReg alpha_read_mode = PixelEngine::GetAlphaReadMode();
|
||||
|
||||
if (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24)
|
||||
if (bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24)
|
||||
{
|
||||
color = RGBA8ToRGBA6ToRGBA8(color);
|
||||
}
|
||||
else if (bpmem.zcontrol.pixel_format == PIXELFMT_RGB565_Z16)
|
||||
else if (bpmem.zcontrol.pixel_format == PEControl::RGB565_Z16)
|
||||
{
|
||||
color = RGBA8ToRGB565ToRGBA8(color);
|
||||
}
|
||||
if (bpmem.zcontrol.pixel_format != PIXELFMT_RGBA6_Z24)
|
||||
if (bpmem.zcontrol.pixel_format != PEControl::RGBA6_Z24)
|
||||
{
|
||||
color |= 0xFF000000;
|
||||
}
|
||||
@@ -1207,7 +1207,7 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
{
|
||||
// Our render target always uses an alpha channel, so we need to override the blend functions to assume a destination alpha of 1 if the render target isn't supposed to have an alpha channel
|
||||
// Example: D3DBLEND_DESTALPHA needs to be D3DBLEND_ONE since the result without an alpha channel is assumed to always be 1.
|
||||
bool target_has_alpha = bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24;
|
||||
bool target_has_alpha = bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24;
|
||||
|
||||
bool useDstAlpha = !g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && target_has_alpha;
|
||||
bool useDualSource = useDstAlpha && g_ActiveConfig.backend_info.bSupportsDualSourceBlend;
|
||||
@@ -1279,18 +1279,18 @@ void Renderer::SetBlendMode(bool forceUpdate)
|
||||
// adjust alpha factors
|
||||
if (useDualSource)
|
||||
{
|
||||
srcidx = GX_BL_ONE;
|
||||
dstidx = GX_BL_ZERO;
|
||||
srcidx = BlendMode::ONE;
|
||||
dstidx = BlendMode::ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we can't use GL_DST_COLOR or GL_ONE_MINUS_DST_COLOR for source in alpha channel so use their alpha equivalent instead
|
||||
if (srcidx == GX_BL_DSTCLR) srcidx = GX_BL_DSTALPHA;
|
||||
if (srcidx == GX_BL_INVDSTCLR) srcidx = GX_BL_INVDSTALPHA;
|
||||
if (srcidx == BlendMode::DSTCLR) srcidx = BlendMode::DSTALPHA;
|
||||
if (srcidx == BlendMode::INVDSTCLR) srcidx = BlendMode::INVDSTALPHA;
|
||||
|
||||
// we can't use GL_SRC_COLOR or GL_ONE_MINUS_SRC_COLOR for destination in alpha channel so use their alpha equivalent instead
|
||||
if (dstidx == GX_BL_SRCCLR) dstidx = GX_BL_SRCALPHA;
|
||||
if (dstidx == GX_BL_INVSRCCLR) dstidx = GX_BL_INVSRCALPHA;
|
||||
if (dstidx == BlendMode::SRCCLR) dstidx = BlendMode::SRCALPHA;
|
||||
if (dstidx == BlendMode::INVSRCCLR) dstidx = BlendMode::INVSRCALPHA;
|
||||
}
|
||||
GLenum srcFactorAlpha = glSrcFactors[srcidx];
|
||||
GLenum dstFactorAlpha = glDestFactors[dstidx];
|
||||
|
||||
@@ -258,14 +258,14 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
|
||||
}
|
||||
|
||||
void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect,
|
||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||
const float *colmat)
|
||||
{
|
||||
g_renderer->ResetAPIState(); // reset any game specific settings
|
||||
|
||||
// Make sure to resolve anything we need to read from.
|
||||
const GLuint read_texture = (srcFormat == PIXELFMT_Z24) ?
|
||||
const GLuint read_texture = (srcFormat == PEControl::Z24) ?
|
||||
FramebufferManager::ResolveAndGetDepthTarget(srcRect) :
|
||||
FramebufferManager::ResolveAndGetRenderTarget(srcRect);
|
||||
|
||||
@@ -282,7 +282,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
|
||||
glViewport(0, 0, virtual_width, virtual_height);
|
||||
|
||||
if (srcFormat == PIXELFMT_Z24)
|
||||
if (srcFormat == PEControl::Z24)
|
||||
{
|
||||
s_DepthMatrixProgram.Bind();
|
||||
if (s_DepthCbufid != cbufid)
|
||||
@@ -298,7 +298,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
}
|
||||
|
||||
TargetRectangle R = g_renderer->ConvertEFBRectangle(srcRect);
|
||||
glUniform4f(srcFormat == PIXELFMT_Z24 ? s_DepthCopyPositionUniform : s_ColorCopyPositionUniform,
|
||||
glUniform4f(srcFormat == PEControl::Z24 ? s_DepthCopyPositionUniform : s_ColorCopyPositionUniform,
|
||||
R.left, R.top, R.right, R.bottom);
|
||||
GL_REPORT_ERRORD();
|
||||
|
||||
@@ -312,7 +312,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||
int encoded_size = TextureConverter::EncodeToRamFromTexture(
|
||||
addr,
|
||||
read_texture,
|
||||
srcFormat == PIXELFMT_Z24,
|
||||
srcFormat == PEControl::Z24,
|
||||
isIntensity,
|
||||
dstFormat,
|
||||
scaleByHalf,
|
||||
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
unsigned int expanded_width, unsigned int level) override;
|
||||
|
||||
void FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
||||
unsigned int srcFormat, const EFBRectangle& srcRect,
|
||||
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
|
||||
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
||||
const float *colmat) override;
|
||||
|
||||
|
||||
@@ -160,11 +160,11 @@ void SWBPWritten(int address, int newvalue)
|
||||
case BPMEM_TEV_REGISTER_L+6: // Reg 4
|
||||
{
|
||||
int regNum = (address >> 1 ) & 0x3;
|
||||
ColReg& reg = bpmem.tevregs[regNum].low;
|
||||
bool konst = reg.type;
|
||||
TevReg& reg = bpmem.tevregs[regNum];
|
||||
bool konst = reg.type_ra;
|
||||
|
||||
Rasterizer::SetTevReg(regNum, Tev::ALP_C, konst, reg.b); // A
|
||||
Rasterizer::SetTevReg(regNum, Tev::RED_C, konst, reg.a); // R
|
||||
Rasterizer::SetTevReg(regNum, Tev::ALP_C, konst, reg.alpha);
|
||||
Rasterizer::SetTevReg(regNum, Tev::RED_C, konst, reg.red);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -175,11 +175,11 @@ void SWBPWritten(int address, int newvalue)
|
||||
case BPMEM_TEV_REGISTER_H+6: // Reg 4
|
||||
{
|
||||
int regNum = (address >> 1 ) & 0x3;
|
||||
ColReg& reg = bpmem.tevregs[regNum].high;
|
||||
bool konst = reg.type;
|
||||
TevReg& reg = bpmem.tevregs[regNum];
|
||||
bool konst = reg.type_bg;
|
||||
|
||||
Rasterizer::SetTevReg(regNum, Tev::GRN_C, konst, reg.b); // G
|
||||
Rasterizer::SetTevReg(regNum, Tev::BLU_C, konst, reg.a); // B
|
||||
Rasterizer::SetTevReg(regNum, Tev::GRN_C, konst, reg.green);
|
||||
Rasterizer::SetTevReg(regNum, Tev::BLU_C, konst, reg.blue);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -413,17 +413,17 @@ void Tev::DrawAlphaCompare(TevStageCombiner::AlphaCombiner &ac)
|
||||
}
|
||||
}
|
||||
|
||||
static bool AlphaCompare(int alpha, int ref, int comp)
|
||||
static bool AlphaCompare(int alpha, int ref, AlphaTest::CompareMode comp)
|
||||
{
|
||||
switch (comp) {
|
||||
case ALPHACMP_ALWAYS: return true;
|
||||
case ALPHACMP_NEVER: return false;
|
||||
case ALPHACMP_LEQUAL: return alpha <= ref;
|
||||
case ALPHACMP_LESS: return alpha < ref;
|
||||
case ALPHACMP_GEQUAL: return alpha >= ref;
|
||||
case ALPHACMP_GREATER: return alpha > ref;
|
||||
case ALPHACMP_EQUAL: return alpha == ref;
|
||||
case ALPHACMP_NEQUAL: return alpha != ref;
|
||||
case AlphaTest::ALWAYS: return true;
|
||||
case AlphaTest::NEVER: return false;
|
||||
case AlphaTest::LEQUAL: return alpha <= ref;
|
||||
case AlphaTest::LESS: return alpha < ref;
|
||||
case AlphaTest::GEQUAL: return alpha >= ref;
|
||||
case AlphaTest::GREATER: return alpha > ref;
|
||||
case AlphaTest::EQUAL: return alpha == ref;
|
||||
case AlphaTest::NEQUAL: return alpha != ref;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1386,8 +1386,8 @@ void EncodeZ24halfscale(u8 *dst, u8 *src, u32 format)
|
||||
|
||||
void Encode(u8 *dest_ptr)
|
||||
{
|
||||
int pixelformat = bpmem.zcontrol.pixel_format;
|
||||
bool bFromZBuffer = pixelformat == PIXELFMT_Z24;
|
||||
auto pixelformat = bpmem.zcontrol.pixel_format;
|
||||
bool bFromZBuffer = pixelformat == PEControl::Z24;
|
||||
bool bIsIntensityFmt = bpmem.triggerEFBCopy.intensity_fmt > 0;
|
||||
u32 copyfmt = ((bpmem.triggerEFBCopy.target_pixel_format / 2) + ((bpmem.triggerEFBCopy.target_pixel_format & 1) * 8));
|
||||
|
||||
@@ -1409,24 +1409,24 @@ void Encode(u8 *dest_ptr)
|
||||
|
||||
if (bpmem.triggerEFBCopy.half_scale)
|
||||
{
|
||||
if (pixelformat == PIXELFMT_RGBA6_Z24)
|
||||
if (pixelformat == PEControl::RGBA6_Z24)
|
||||
EncodeRGBA6halfscale(dest_ptr, src, format);
|
||||
else if (pixelformat == PIXELFMT_RGB8_Z24)
|
||||
else if (pixelformat == PEControl::RGB8_Z24)
|
||||
EncodeRGB8halfscale(dest_ptr, src, format);
|
||||
else if (pixelformat == PIXELFMT_RGB565_Z16) // not supported
|
||||
else if (pixelformat == PEControl::RGB565_Z16) // not supported
|
||||
EncodeRGB8halfscale(dest_ptr, src, format);
|
||||
else if (pixelformat == PIXELFMT_Z24)
|
||||
else if (pixelformat == PEControl::Z24)
|
||||
EncodeZ24halfscale(dest_ptr, src, format);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pixelformat == PIXELFMT_RGBA6_Z24)
|
||||
if (pixelformat == PEControl::RGBA6_Z24)
|
||||
EncodeRGBA6(dest_ptr, src, format);
|
||||
else if (pixelformat == PIXELFMT_RGB8_Z24)
|
||||
else if (pixelformat == PEControl::RGB8_Z24)
|
||||
EncodeRGB8(dest_ptr, src, format);
|
||||
else if (pixelformat == PIXELFMT_RGB565_Z16) // not supported
|
||||
else if (pixelformat == PEControl::RGB565_Z16) // not supported
|
||||
EncodeRGB8(dest_ptr, src, format);
|
||||
else if (pixelformat == PIXELFMT_Z24)
|
||||
else if (pixelformat == PEControl::Z24)
|
||||
EncodeZ24(dest_ptr, src, format);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,10 +79,10 @@ void SetColorMask()
|
||||
g_renderer->SetColorMask();
|
||||
}
|
||||
|
||||
void CopyEFB(u32 dstAddr, unsigned int dstFormat, unsigned int srcFormat,
|
||||
void CopyEFB(u32 dstAddr, unsigned int dstFormat, PEControl::PixelFormat srcFormat,
|
||||
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf)
|
||||
{
|
||||
// bpmem.zcontrol.pixel_format to PIXELFMT_Z24 is when the game wants to copy from ZBuffer (Zbuffer uses 24-bit Format)
|
||||
// bpmem.zcontrol.pixel_format to PEControl::Z24 is when the game wants to copy from ZBuffer (Zbuffer uses 24-bit Format)
|
||||
if (g_ActiveConfig.bEFBCopyEnable)
|
||||
{
|
||||
TextureCache::CopyRenderTargetToTexture(dstAddr, dstFormat, srcFormat,
|
||||
@@ -111,11 +111,12 @@ void ClearScreen(const EFBRectangle &rc)
|
||||
bool colorEnable = bpmem.blendmode.colorupdate;
|
||||
bool alphaEnable = bpmem.blendmode.alphaupdate;
|
||||
bool zEnable = bpmem.zmode.updateenable;
|
||||
auto pixel_format = bpmem.zcontrol.pixel_format;
|
||||
|
||||
// (1): Disable unused color channels
|
||||
if (bpmem.zcontrol.pixel_format == PIXELFMT_RGB8_Z24 ||
|
||||
bpmem.zcontrol.pixel_format == PIXELFMT_RGB565_Z16 ||
|
||||
bpmem.zcontrol.pixel_format == PIXELFMT_Z24)
|
||||
if (pixel_format == PEControl::RGB8_Z24 ||
|
||||
pixel_format == PEControl::RGB565_Z16 ||
|
||||
pixel_format == PEControl::Z24)
|
||||
{
|
||||
alphaEnable = false;
|
||||
}
|
||||
@@ -126,11 +127,11 @@ void ClearScreen(const EFBRectangle &rc)
|
||||
u32 z = bpmem.clearZValue;
|
||||
|
||||
// (2) drop additional accuracy
|
||||
if (bpmem.zcontrol.pixel_format == PIXELFMT_RGBA6_Z24)
|
||||
if (pixel_format == PEControl::RGBA6_Z24)
|
||||
{
|
||||
color = RGBA8ToRGBA6ToRGBA8(color);
|
||||
}
|
||||
else if (bpmem.zcontrol.pixel_format == PIXELFMT_RGB565_Z16)
|
||||
else if (pixel_format == PEControl::RGB565_Z16)
|
||||
{
|
||||
color = RGBA8ToRGB565ToRGBA8(color);
|
||||
z = Z24ToZ16ToZ24(z);
|
||||
@@ -156,8 +157,8 @@ void OnPixelFormatChange()
|
||||
!g_ActiveConfig.backend_info.bSupportsFormatReinterpretation)
|
||||
return;
|
||||
|
||||
u32 old_format = Renderer::GetPrevPixelFormat();
|
||||
u32 new_format = bpmem.zcontrol.pixel_format;
|
||||
auto old_format = Renderer::GetPrevPixelFormat();
|
||||
auto new_format = bpmem.zcontrol.pixel_format;
|
||||
|
||||
// no need to reinterpret pixel data in these cases
|
||||
if (new_format == old_format || old_format == (unsigned int)-1)
|
||||
@@ -166,31 +167,31 @@ void OnPixelFormatChange()
|
||||
// Check for pixel format changes
|
||||
switch (old_format)
|
||||
{
|
||||
case PIXELFMT_RGB8_Z24:
|
||||
case PIXELFMT_Z24:
|
||||
case PEControl::RGB8_Z24:
|
||||
case PEControl::Z24:
|
||||
// Z24 and RGB8_Z24 are treated equal, so just return in this case
|
||||
if (new_format == PIXELFMT_RGB8_Z24 || new_format == PIXELFMT_Z24)
|
||||
if (new_format == PEControl::RGB8_Z24 || new_format == PEControl::Z24)
|
||||
goto skip;
|
||||
|
||||
if (new_format == PIXELFMT_RGBA6_Z24)
|
||||
if (new_format == PEControl::RGBA6_Z24)
|
||||
convtype = 0;
|
||||
else if (new_format == PIXELFMT_RGB565_Z16)
|
||||
else if (new_format == PEControl::RGB565_Z16)
|
||||
convtype = 1;
|
||||
break;
|
||||
|
||||
case PIXELFMT_RGBA6_Z24:
|
||||
if (new_format == PIXELFMT_RGB8_Z24 ||
|
||||
new_format == PIXELFMT_Z24)
|
||||
case PEControl::RGBA6_Z24:
|
||||
if (new_format == PEControl::RGB8_Z24 ||
|
||||
new_format == PEControl::Z24)
|
||||
convtype = 2;
|
||||
else if (new_format == PIXELFMT_RGB565_Z16)
|
||||
else if (new_format == PEControl::RGB565_Z16)
|
||||
convtype = 3;
|
||||
break;
|
||||
|
||||
case PIXELFMT_RGB565_Z16:
|
||||
if (new_format == PIXELFMT_RGB8_Z24 ||
|
||||
new_format == PIXELFMT_Z24)
|
||||
case PEControl::RGB565_Z16:
|
||||
if (new_format == PEControl::RGB8_Z24 ||
|
||||
new_format == PEControl::Z24)
|
||||
convtype = 4;
|
||||
else if (new_format == PIXELFMT_RGBA6_Z24)
|
||||
else if (new_format == PEControl::RGBA6_Z24)
|
||||
convtype = 5;
|
||||
break;
|
||||
|
||||
@@ -200,14 +201,14 @@ void OnPixelFormatChange()
|
||||
|
||||
if (convtype == -1)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Unhandled EFB format change: %d to %d\n", old_format, new_format);
|
||||
ERROR_LOG(VIDEO, "Unhandled EFB format change: %d to %d\n", static_cast<int>(old_format), static_cast<int>(new_format));
|
||||
goto skip;
|
||||
}
|
||||
|
||||
g_renderer->ReinterpretPixelData(convtype);
|
||||
|
||||
skip:
|
||||
DEBUG_LOG(VIDEO, "pixelfmt: pixel=%d, zc=%d", new_format, bpmem.zcontrol.zformat);
|
||||
DEBUG_LOG(VIDEO, "pixelfmt: pixel=%d, zc=%d", static_cast<int>(new_format), static_cast<int>(bpmem.zcontrol.zformat));
|
||||
|
||||
Renderer::StorePixelFormat(new_format);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ void SetBlendMode();
|
||||
void SetDitherMode();
|
||||
void SetLogicOpMode();
|
||||
void SetColorMask();
|
||||
void CopyEFB(u32 dstAddr, unsigned int dstFormat, unsigned int srcFormat,
|
||||
void CopyEFB(u32 dstAddr, unsigned int dstFormat, PEControl::PixelFormat srcFormat,
|
||||
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf);
|
||||
void ClearScreen(const EFBRectangle &rc);
|
||||
void OnPixelFormatChange();
|
||||
|
||||
@@ -92,7 +92,7 @@ void GetBPRegInfo(const u8* data, char* name, size_t name_size, char* desc, size
|
||||
case BPMEM_ZCOMPARE:
|
||||
{
|
||||
SetRegName(BPMEM_ZCOMPARE);
|
||||
PE_CONTROL config; config.hex = cmddata;
|
||||
PEControl config; config.hex = cmddata;
|
||||
const char* pixel_formats[] = { "RGB8_Z24", "RGBA6_Z24", "RGB565_Z16", "Z24", "Y8", "U8", "V8", "YUV420" };
|
||||
const char* zformats[] = { "linear", "compressed (near)", "compressed (mid)", "compressed (far)", "inv linear", "compressed (inv near)", "compressed (inv mid)", "compressed (inv far)" };
|
||||
snprintf(desc, desc_size, "EFB pixel format: %s\n"
|
||||
@@ -158,7 +158,7 @@ void GetBPRegInfo(const u8* data, char* name, size_t name_size, char* desc, size
|
||||
no_yes[copy.half_scale],
|
||||
no_yes[copy.scale_invert],
|
||||
no_yes[copy.clear],
|
||||
copy.frame_to_field,
|
||||
(u32)copy.frame_to_field,
|
||||
no_yes[copy.copy_to_xfb],
|
||||
no_yes[copy.intensity_fmt],
|
||||
no_yes[copy.auto_conv]);
|
||||
@@ -292,7 +292,7 @@ void GetBPRegInfo(const u8* data, char* name, size_t name_size, char* desc, size
|
||||
snprintf(desc, desc_size, "test 1: %s (ref: %#02x)\n"
|
||||
"test 2: %s (ref: %#02x)\n"
|
||||
"logic: %s\n",
|
||||
functions[test.comp0], test.ref0, functions[test.comp1], test.ref1, logic[test.logic]);
|
||||
functions[test.comp0], (int)test.ref0, functions[test.comp1], (int)test.ref1, logic[test.logic]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user