mirror of https://github.com/AxioDL/metaforce.git
Per-stage shader hashing
This commit is contained in:
parent
5e60131062
commit
b7aa3e06d2
|
@ -8,15 +8,18 @@ class CStopwatch {
|
|||
|
||||
public:
|
||||
CStopwatch() : m_start(std::chrono::steady_clock::now()) {}
|
||||
void report(const char* name) const {
|
||||
printf("%s %f\n", name,
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - m_start).count() /
|
||||
1000000.f);
|
||||
double report(const char* name) const {
|
||||
double t = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - m_start).count() / 1000000.0;
|
||||
printf("%s %f\n", name, t);
|
||||
return t;
|
||||
}
|
||||
void reportReset(const char* name) {
|
||||
double reportReset(const char* name) {
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
printf("%s %f\n", name, std::chrono::duration_cast<std::chrono::microseconds>(now - m_start).count() / 1000000.f);
|
||||
double t = std::chrono::duration_cast<std::chrono::microseconds>(now - m_start).count() / 1000000.0;
|
||||
printf("%s %f\n", name, t);
|
||||
m_start = now;
|
||||
return t;
|
||||
}
|
||||
};
|
||||
} // namespace urde
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "Graphics/CLight.hpp"
|
||||
#include "hecl/HMDLMeta.hpp"
|
||||
#include "hecl/Runtime.hpp"
|
||||
#include "hecl/CVarManager.hpp"
|
||||
#include "boo/graphicsdev/Metal.hpp"
|
||||
#include "Shaders/CModelShaders.hpp"
|
||||
#include "Graphics/CBooRenderer.hpp"
|
||||
|
@ -372,8 +373,8 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
|
|||
texs[8] = g_disintegrateTexture;
|
||||
else
|
||||
texs[8] = g_Renderer->x220_sphereRamp.get();
|
||||
} else if (idx == EExtendedShader::LightingCubeReflection ||
|
||||
idx == EExtendedShader::LightingCubeReflectionWorldShadow) {
|
||||
} else if (hecl::com_cubemaps->toBoolean() && (idx == EExtendedShader::LightingCubeReflection ||
|
||||
idx == EExtendedShader::LightingCubeReflectionWorldShadow)) {
|
||||
if (m_lastDrawnReflectionCube)
|
||||
texs[11] = m_lastDrawnReflectionCube.get();
|
||||
else
|
||||
|
@ -531,8 +532,17 @@ void CBooModel::DrawSurfaces(const CModelFlags& flags) const {
|
|||
static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data, const CModelFlags& flags) {
|
||||
bool noZWrite = flags.m_noZWrite || !data.flags.depthWrite();
|
||||
|
||||
/* Ensure cubemap extension shaders fall back to non-cubemap equivalents if necessary */
|
||||
EExtendedShader intermediateExtended = flags.m_extendedShader;
|
||||
if (!hecl::com_cubemaps->toBoolean() || g_Renderer->IsThermalVisorHotPass() || g_Renderer->IsThermalVisorActive()) {
|
||||
if (intermediateExtended == EExtendedShader::LightingCubeReflection)
|
||||
intermediateExtended = EExtendedShader::Lighting;
|
||||
else if (intermediateExtended == EExtendedShader::LightingCubeReflectionWorldShadow)
|
||||
intermediateExtended = EExtendedShader::WorldShadow;
|
||||
}
|
||||
|
||||
EExtendedShader extended = EExtendedShader::Flat;
|
||||
if (flags.m_extendedShader == EExtendedShader::Lighting) {
|
||||
if (intermediateExtended == EExtendedShader::Lighting) {
|
||||
/* Transform lighting into thermal cold if the thermal visor is active */
|
||||
if (g_Renderer->IsThermalVisorHotPass())
|
||||
return EExtendedShader::LightingAlphaWrite;
|
||||
|
@ -578,8 +588,8 @@ static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data,
|
|||
} else {
|
||||
extended = EExtendedShader::Lighting;
|
||||
}
|
||||
} else if (flags.m_extendedShader < EExtendedShader::MAX) {
|
||||
extended = flags.m_extendedShader;
|
||||
} else if (intermediateExtended < EExtendedShader::MAX) {
|
||||
extended = intermediateExtended;
|
||||
}
|
||||
|
||||
return extended;
|
||||
|
@ -936,7 +946,7 @@ boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFl
|
|||
return {};
|
||||
|
||||
/* Invalidate instances if new shadow being drawn */
|
||||
if ((flags.m_extendedShader == EExtendedShader::WorldShadow ||
|
||||
if ((flags.m_extendedShader == EExtendedShader::WorldShadow ||
|
||||
flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) &&
|
||||
m_lastDrawnShadowMap != g_shadowMap) {
|
||||
const_cast<CBooModel*>(this)->m_lastDrawnShadowMap = g_shadowMap;
|
||||
|
@ -950,7 +960,7 @@ boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFl
|
|||
}
|
||||
|
||||
/* Invalidate instances if new reflection cube being drawn */
|
||||
if ((flags.m_extendedShader == EExtendedShader::LightingCubeReflection ||
|
||||
if (hecl::com_cubemaps->toBoolean() && (flags.m_extendedShader == EExtendedShader::LightingCubeReflection ||
|
||||
flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) &&
|
||||
m_lastDrawnReflectionCube != g_reflectionCube) {
|
||||
const_cast<CBooModel*>(this)->m_lastDrawnReflectionCube = g_reflectionCube;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "CModelShaders.hpp"
|
||||
#include "Graphics/CLight.hpp"
|
||||
#include "hecl/Pipeline.hpp"
|
||||
#include "CStopwatch.hpp"
|
||||
|
||||
namespace urde {
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
namespace hecl {
|
||||
extern CVar* com_enableCheats;
|
||||
extern CVar* com_developer;
|
||||
extern CVar* com_cubemaps;
|
||||
}; // namespace hecl
|
||||
|
||||
namespace urde {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "Graphics/CBooRenderer.hpp"
|
||||
#include "CTimeProvider.hpp"
|
||||
#include "Graphics/CSkinnedModel.hpp"
|
||||
#include "hecl/CVarManager.hpp"
|
||||
|
||||
namespace urde {
|
||||
static CMaterialList MakeActorMaterialList(const CMaterialList& materialList, const CActorParameters& params) {
|
||||
|
@ -432,10 +433,12 @@ void CActor::_CreateShadow() {
|
|||
}
|
||||
|
||||
void CActor::_CreateReflectionCube() {
|
||||
CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
|
||||
m_reflectionCube = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS);
|
||||
return true;
|
||||
} BooTrace);
|
||||
if (hecl::com_cubemaps->toBoolean()) {
|
||||
CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
|
||||
m_reflectionCube = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS);
|
||||
return true;
|
||||
} BooTrace);
|
||||
}
|
||||
}
|
||||
|
||||
void CActor::SetCallTouch(bool callTouch) { xe5_28_callTouch = callTouch; }
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Character/CActorLights.hpp"
|
||||
#include "GuiSys/CStringTable.hpp"
|
||||
#include "Audio/CSfxManager.hpp"
|
||||
#include "hecl/CVarManager.hpp"
|
||||
|
||||
namespace urde {
|
||||
|
||||
|
@ -234,39 +235,41 @@ void CWorldTransManager::DrawEnabled() {
|
|||
CActorLights lights(0, zeus::skZero3f, 4, 4, 0, 0, 0, 0.1f);
|
||||
lights.BuildFakeLightList(x4_modelData->x1a0_lights, zeus::CColor{0.1f, 0.1f, 0.1f, 1.0f});
|
||||
|
||||
SViewport backupVp = g_Viewport;
|
||||
constexpr float width = CUBEMAP_RES;
|
||||
CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[0], 0);
|
||||
g_Renderer->SetViewport(0, 0, width, width);
|
||||
g_Renderer->SetPerspective(90.f, width, width, 0.2f, 750.f);
|
||||
if (m_reflectionCube[0]) {
|
||||
SViewport backupVp = g_Viewport;
|
||||
constexpr float width = CUBEMAP_RES;
|
||||
CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[0], 0);
|
||||
g_Renderer->SetViewport(0, 0, width, width);
|
||||
g_Renderer->SetPerspective(90.f, width, width, 0.2f, 750.f);
|
||||
|
||||
if (x0_curTime < x4_modelData->x1d4_dissolveEndTime) {
|
||||
zeus::CTransform mainCamXf =
|
||||
if (x0_curTime < x4_modelData->x1d4_dissolveEndTime) {
|
||||
zeus::CTransform mainCamXf =
|
||||
zeus::CTransform::RotateZ(zeus::degToRad(zeus::clamp(0.f, x0_curTime / 25.f, 100.f) * 360.f + 180.f - 90.f));
|
||||
for (int face = 0; face < 6; ++face) {
|
||||
CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[0], face);
|
||||
CGraphics::g_BooMainCommandQueue->clearTarget();
|
||||
zeus::CTransform camXf = zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], zeus::CVector3f(0.f, 0.f, 1.5f));
|
||||
g_Renderer->SetWorldViewpoint(camXf);
|
||||
DrawPlatformModels(&lights);
|
||||
for (int face = 0; face < 6; ++face) {
|
||||
CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[0], face);
|
||||
CGraphics::g_BooMainCommandQueue->clearTarget();
|
||||
zeus::CTransform camXf = zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], zeus::CVector3f(0.f, 0.f, 1.5f));
|
||||
g_Renderer->SetWorldViewpoint(camXf);
|
||||
DrawPlatformModels(&lights);
|
||||
}
|
||||
CGraphics::g_BooMainCommandQueue->generateMipmaps(m_reflectionCube[0]);
|
||||
}
|
||||
CGraphics::g_BooMainCommandQueue->generateMipmaps(m_reflectionCube[0]);
|
||||
}
|
||||
if (x0_curTime > x4_modelData->x1d0_dissolveStartTime) {
|
||||
zeus::CTransform mainCamXf = zeus::CTransform::RotateZ(zeus::degToRad(
|
||||
if (x0_curTime > x4_modelData->x1d0_dissolveStartTime) {
|
||||
zeus::CTransform mainCamXf = zeus::CTransform::RotateZ(zeus::degToRad(
|
||||
48.f * zeus::clamp(0.f, (x0_curTime - x4_modelData->x1d0_dissolveStartTime + 2.f) / 5.f, 1.f) + 180.f - 24.f));
|
||||
for (int face = 0; face < 6; ++face) {
|
||||
CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[1], face);
|
||||
CGraphics::g_BooMainCommandQueue->clearTarget();
|
||||
zeus::CTransform camXf = zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], zeus::CVector3f(0.f, 0.f, 1.5f));
|
||||
g_Renderer->SetWorldViewpoint(camXf);
|
||||
DrawPlatformModels(&lights);
|
||||
for (int face = 0; face < 6; ++face) {
|
||||
CGraphics::g_BooMainCommandQueue->setRenderTarget(m_reflectionCube[1], face);
|
||||
CGraphics::g_BooMainCommandQueue->clearTarget();
|
||||
zeus::CTransform camXf = zeus::CTransform(mainCamXf.basis * CGraphics::skCubeBasisMats[face], zeus::CVector3f(0.f, 0.f, 1.5f));
|
||||
g_Renderer->SetWorldViewpoint(camXf);
|
||||
DrawPlatformModels(&lights);
|
||||
}
|
||||
CGraphics::g_BooMainCommandQueue->generateMipmaps(m_reflectionCube[1]);
|
||||
}
|
||||
CGraphics::g_BooMainCommandQueue->generateMipmaps(m_reflectionCube[1]);
|
||||
}
|
||||
|
||||
CBooRenderer::BindMainDrawTarget();
|
||||
g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height);
|
||||
CBooRenderer::BindMainDrawTarget();
|
||||
g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height);
|
||||
}
|
||||
|
||||
float wsAspect = CWideScreenFilter::SetViewportToMatch(1.f);
|
||||
|
||||
|
@ -378,7 +381,7 @@ void CWorldTransManager::EnableTransition(const CAnimRes& samusRes, CAssetId pla
|
|||
x30_type = ETransType::Enabled;
|
||||
x4_modelData.reset(new SModelDatas(samusRes));
|
||||
|
||||
if (!m_reflectionCube[0])
|
||||
if (!m_reflectionCube[0] && hecl::com_cubemaps->toBoolean())
|
||||
CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
|
||||
m_reflectionCube[0] = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS);
|
||||
m_reflectionCube[1] = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS);
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
const boo::AdditionalPipelineInfo PipelineInfo;
|
||||
bool HasTessellation;
|
||||
static constexpr bool HasHash = false;
|
||||
static constexpr uint64_t Hash() { return 0; }
|
||||
static constexpr bool HasStageHash = false;
|
||||
const SFluidPlaneShaderInfo& info() const { return m_info; }
|
||||
};
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
const boo::VertexFormatInfo VtxFmt;
|
||||
const boo::AdditionalPipelineInfo PipelineInfo;
|
||||
static constexpr bool HasHash = false;
|
||||
static constexpr uint64_t Hash() { return 0; }
|
||||
static constexpr bool HasStageHash = false;
|
||||
const SFluidPlaneDoorShaderInfo& info() const { return m_info; }
|
||||
};
|
||||
|
||||
|
|
|
@ -32,9 +32,14 @@ struct SModelShadersInfo {
|
|||
|
||||
class Shader_CModelShaders : public hecl::GeneralShader {
|
||||
const SModelShadersInfo& m_info;
|
||||
uint64_t m_vertHash, m_fragHash;
|
||||
static uint64_t BuildVertHash(const SModelShadersInfo& in);
|
||||
static uint64_t BuildFragHash(const SModelShadersInfo& in);
|
||||
public:
|
||||
Shader_CModelShaders(const SModelShadersInfo& in)
|
||||
: m_info(in)
|
||||
, m_vertHash(BuildVertHash(in))
|
||||
, m_fragHash(BuildFragHash(in))
|
||||
, VtxFmt(in.m_vtxFmt)
|
||||
, PipelineInfo(in.m_additionalInfo) {}
|
||||
|
||||
|
@ -42,8 +47,12 @@ public:
|
|||
const boo::AdditionalPipelineInfo PipelineInfo;
|
||||
static constexpr bool HasHash = true;
|
||||
uint64_t Hash() const { return m_info.m_hash; }
|
||||
static constexpr bool HasStageHash = true;
|
||||
template <typename S> uint64_t StageHash() const;
|
||||
const SModelShadersInfo& info() const { return m_info; }
|
||||
};
|
||||
template <> inline uint64_t Shader_CModelShaders::StageHash<hecl::PipelineStage::Vertex>() const { return m_vertHash; }
|
||||
template <> inline uint64_t Shader_CModelShaders::StageHash<hecl::PipelineStage::Fragment>() const { return m_fragHash; }
|
||||
|
||||
template <typename P, typename S>
|
||||
class StageObject_CModelShaders : public hecl::StageBinary<P, S> {
|
||||
|
|
|
@ -141,6 +141,39 @@ static std::string _BuildVS(const SModelShadersInfo& info) {
|
|||
return vertOut.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void _Hash(XXH64_state_t& st, T val) {
|
||||
XXH64_update(&st, &val, sizeof(val));
|
||||
}
|
||||
|
||||
uint64_t Shader_CModelShaders::BuildVertHash(const SModelShadersInfo& info) {
|
||||
XXH64_state_t st;
|
||||
XXH64_reset(&st, 0);
|
||||
_Hash(st, info.m_tag.getColorCount());
|
||||
_Hash(st, info.m_tag.getUvCount());
|
||||
_Hash(st, info.m_tag.getSkinSlotCount());
|
||||
_Hash(st, info.m_tag.getWeightCount());
|
||||
for (const auto& chunk : info.m_material.chunks) {
|
||||
if (auto passChunk = chunk.get_if<SModelShadersInfo::Material::PASS>()) {
|
||||
_Hash(st, passChunk->type);
|
||||
_Hash(st, passChunk->uvAnimType);
|
||||
_Hash(st, passChunk->source);
|
||||
_Hash(st, passChunk->shouldNormalizeUv());
|
||||
} else if (auto clrChunk = chunk.get_if<SModelShadersInfo::Material::CLR>()) {
|
||||
_Hash(st, clrChunk->type);
|
||||
}
|
||||
}
|
||||
_Hash(st, info.m_extension.noReflection);
|
||||
_Hash(st, info.m_tag.getReflectionType());
|
||||
for (size_t i = 0; i < info.m_extension.texCount; ++i) {
|
||||
const auto& extTex = info.m_extension.texs[i];
|
||||
_Hash(st, extTex.mtxIdx);
|
||||
_Hash(st, extTex.src);
|
||||
_Hash(st, extTex.normalize);
|
||||
}
|
||||
return XXH64_digest(&st);
|
||||
}
|
||||
|
||||
static std::string _BuildFS(const SModelShadersInfo& info) {
|
||||
std::stringstream fragOut;
|
||||
fragOut << CMODELSHADERS_COMMON_GLSL_SV;
|
||||
|
@ -197,6 +230,29 @@ static std::string _BuildFS(const SModelShadersInfo& info) {
|
|||
return fragOut.str();
|
||||
}
|
||||
|
||||
uint64_t Shader_CModelShaders::BuildFragHash(const SModelShadersInfo& info) {
|
||||
XXH64_state_t st;
|
||||
XXH64_reset(&st, 0);
|
||||
XXH64_update(&st, info.m_extension.shaderMacro, strlen(info.m_extension.shaderMacro));
|
||||
_Hash(st, info.m_material.shaderType);
|
||||
_Hash(st, info.m_additionalInfo.srcFac);
|
||||
_Hash(st, info.m_additionalInfo.dstFac);
|
||||
for (const auto& chunk : info.m_material.chunks) {
|
||||
if (auto passChunk = chunk.get_if<SModelShadersInfo::Material::PASS>()) {
|
||||
_Hash(st, passChunk->alpha);
|
||||
_Hash(st, passChunk->type);
|
||||
} else if (auto clrChunk = chunk.get_if<SModelShadersInfo::Material::CLR>()) {
|
||||
_Hash(st, clrChunk->type);
|
||||
}
|
||||
}
|
||||
_Hash(st, info.m_tag.getAlphaTest());
|
||||
_Hash(st, info.m_extension.forceAlphaTest);
|
||||
_Hash(st, info.m_extension.diffuseOnly);
|
||||
_Hash(st, info.m_extension.noReflection);
|
||||
_Hash(st, info.m_tag.getReflectionType());
|
||||
return XXH64_digest(&st);
|
||||
}
|
||||
|
||||
template <>
|
||||
std::string StageObject_CModelShaders<hecl::PlatformType::OpenGL, hecl::PipelineStage::Vertex>::BuildShader(
|
||||
const SModelShadersInfo& in) {
|
||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
|||
Subproject commit b435752ebb2238cd103257d1d05cd827416036df
|
||||
Subproject commit 3cf0712f03b8be7d29b151a36a53d5ece415cab8
|
Loading…
Reference in New Issue