From 036e76921018f902b3cc484ed6cd184ad44f613c Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 7 Oct 2020 20:03:07 -0400 Subject: [PATCH] Fix an insane number of things with hsh refactoring --- NESEmulator/CNESEmulator.cpp | 11 +- Runtime/AutoMapper/CMappableObject.cpp | 36 ++--- Runtime/AutoMapper/CMappableObject.hpp | 10 +- Runtime/CMakeLists.txt | 23 +-- Runtime/CStateManager.cpp | 2 +- Runtime/Graphics/CBooRenderer.cpp | 4 +- Runtime/Graphics/CBooRenderer.hpp | 2 +- Runtime/Graphics/CGraphics.cpp | 39 ++--- Runtime/Graphics/CGraphics.hpp | 3 + Runtime/Graphics/CModel.hpp | 8 +- Runtime/Graphics/CModelBoo.cpp | 134 +++++++++++------- Runtime/Graphics/CTexture.hpp | 2 +- Runtime/Graphics/CTextureBoo.cpp | 16 +-- Runtime/Graphics/Shaders/CAABoxShader.cpp | 15 +- .../Graphics/Shaders/CColoredQuadFilter.cpp | 6 +- .../Graphics/Shaders/CColoredStripShader.hpp | 2 + Runtime/Graphics/Shaders/CDecalShaders.cpp | 6 +- .../Graphics/Shaders/CElementGenShaders.cpp | 18 +-- Runtime/Graphics/Shaders/CEnergyBarShader.cpp | 6 +- Runtime/Graphics/Shaders/CEnergyBarShader.hpp | 2 + Runtime/Graphics/Shaders/CEnvFxShaders.cpp | 2 +- .../Graphics/Shaders/CLineRendererShaders.cpp | 3 +- .../Graphics/Shaders/CMapSurfaceShader.cpp | 3 +- .../Graphics/Shaders/CMapSurfaceShader.hpp | 2 + .../Graphics/Shaders/CRadarPaintShader.cpp | 2 +- Runtime/Graphics/Shaders/CScanLinesFilter.hpp | 2 + Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp | 2 + .../Graphics/Shaders/CTextSupportShader.cpp | 4 +- .../Graphics/Shaders/CTexturedQuadFilter.cpp | 49 +++++-- .../Graphics/Shaders/CTexturedQuadFilter.hpp | 12 +- .../Graphics/Shaders/CThermalColdFilter.hpp | 2 + Runtime/Graphics/Shaders/CXRayBlurFilter.hpp | 6 +- Runtime/GuiSys/CGuiWidget.hpp | 3 + Runtime/GuiSys/CRasterFont.hpp | 2 +- Runtime/GuiSys/CTextRenderBuffer.cpp | 4 +- Runtime/GuiSys/CTextRenderBuffer.hpp | 2 + Runtime/MP1/MP1.cpp | 1 - Runtime/Particle/CParticleSwoosh.cpp | 1 + Runtime/World/CActorModelParticles.cpp | 2 +- Runtime/World/CFluidPlaneManager.hpp | 2 + Runtime/World/CWorldTransManager.cpp | 2 +- 41 files changed, 255 insertions(+), 198 deletions(-) diff --git a/NESEmulator/CNESEmulator.cpp b/NESEmulator/CNESEmulator.cpp index e36344f1e..ec112e1a2 100644 --- a/NESEmulator/CNESEmulator.cpp +++ b/NESEmulator/CNESEmulator.cpp @@ -269,7 +269,7 @@ void CNESEmulator::InitializeEmulator() { }; m_vbo = hsh::create_vertex_buffer(verts); m_uniBuf = hsh::create_dynamic_uniform_buffer(); - m_shadBind = CNESShader::BuildShaderDataBinding(m_vbo.get(), m_uniBuf.get(), m_texture.get()); + CNESShader::BuildShaderDataBinding(m_shadBind, m_vbo.get(), m_uniBuf.get(), m_texture.get()); // double useFreq = 223740; double useFreq = apuGetFrequency(); @@ -753,12 +753,11 @@ void CNESEmulator::Draw(const zeus::CColor& mulColor, bool filtering) { float widthFac = NESAspect / g_Viewport.aspect; - Uniform uniform = {zeus::CMatrix4f{}, mulColor}; - uniform.m_matrix[0][0] = widthFac; - m_uniBuf->load(&uniform, sizeof(Uniform)); + ViewBlock uniform = {zeus::CMatrix4f{}, mulColor}; + uniform.m_mv[0][0] = widthFac; + m_uniBuf.load(uniform); - CGraphics::SetShaderDataBinding(m_shadBind); - CGraphics::DrawArray(0, 4); + m_shadBind.draw(0, 4); } void CNESEmulator::LoadPassword(const u8* state) { diff --git a/Runtime/AutoMapper/CMappableObject.cpp b/Runtime/AutoMapper/CMappableObject.cpp index 90da291b8..a92598fc4 100644 --- a/Runtime/AutoMapper/CMappableObject.cpp +++ b/Runtime/AutoMapper/CMappableObject.cpp @@ -8,7 +8,7 @@ #include "Runtime/Graphics/CTexture.hpp" namespace urde { -std::array CMappableObject::skDoorVerts{}; +std::array CMappableObject::skDoorVerts{}; constexpr std::array DoorIndices{ 6, 4, 2, 0, 3, 1, 7, 5, 1, 0, 5, 4, 7, 6, 3, 2, 3, 2, 1, 0, 5, 4, 7, 6, @@ -118,10 +118,10 @@ void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha CLineRenderer& line = ds.m_outline; const u32* baseIdx = &DoorIndices[s * 4]; line.Reset(); - line.AddVertex(skDoorVerts[baseIdx[0]].m_pos, colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[1]].m_pos, colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[3]].m_pos, colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[2]].m_pos, colors.second, 1.f); + line.AddVertex(skDoorVerts[baseIdx[0]].pos, colors.second, 1.f); + line.AddVertex(skDoorVerts[baseIdx[1]].pos, colors.second, 1.f); + line.AddVertex(skDoorVerts[baseIdx[3]].pos, colors.second, 1.f); + line.AddVertex(skDoorVerts[baseIdx[2]].pos, colors.second, 1.f); line.Render(); } } else { @@ -188,10 +188,10 @@ void CMappableObject::DrawDoorSurface(int curArea, const CMapWorldInfo& mwInfo, CLineRenderer& line = ds.m_outline; const u32* baseIdx = &DoorIndices[surfIdx * 4]; line.Reset(); - line.AddVertex(skDoorVerts[baseIdx[0]].m_pos, colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[1]].m_pos, colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[3]].m_pos, colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[2]].m_pos, colors.second, 1.f); + line.AddVertex(skDoorVerts[baseIdx[0]].pos, colors.second, 1.f); + line.AddVertex(skDoorVerts[baseIdx[1]].pos, colors.second, 1.f); + line.AddVertex(skDoorVerts[baseIdx[3]].pos, colors.second, 1.f); + line.AddVertex(skDoorVerts[baseIdx[2]].pos, colors.second, 1.f); line.Render(); } @@ -236,7 +236,7 @@ bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& } } -hsh::owner> CMappableObject::g_doorVbo; +hsh::owner> CMappableObject::g_doorVbo; hsh::owner> CMappableObject::g_doorIbo; void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) { @@ -245,14 +245,14 @@ void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) { // Wrap door verts around -Z to build surface auto& doorVerts = skDoorVerts; - doorVerts[0].assign(-centerF[2], -centerF[1], 0.f); - doorVerts[1].assign(-centerF[2], -centerF[1], 2.f * centerF[0]); - doorVerts[2].assign(-centerF[2], centerF[1], 0.f); - doorVerts[3].assign(-centerF[2], centerF[1], 2.f * centerF[0]); - doorVerts[4].assign(.2f * -centerF[2], -centerF[1], 0.f); - doorVerts[5].assign(.2f * -centerF[2], -centerF[1], 2.f * centerF[0]); - doorVerts[6].assign(.2f * -centerF[2], centerF[1], 0.f); - doorVerts[7].assign(.2f * -centerF[2], centerF[1], 2.f * centerF[0]); + doorVerts[0] = {-centerF[2], -centerF[1], 0.f}; + doorVerts[1] = {-centerF[2], -centerF[1], 2.f * centerF[0]}; + doorVerts[2] = {-centerF[2], centerF[1], 0.f}; + doorVerts[3] = {-centerF[2], centerF[1], 2.f * centerF[0]}; + doorVerts[4] = {.2f * -centerF[2], -centerF[1], 0.f}; + doorVerts[5] = {.2f * -centerF[2], -centerF[1], 2.f * centerF[0]}; + doorVerts[6] = {.2f * -centerF[2], centerF[1], 0.f}; + doorVerts[7] = {.2f * -centerF[2], centerF[1], 2.f * centerF[0]}; g_doorVbo = hsh::create_vertex_buffer(skDoorVerts); g_doorIbo = hsh::create_index_buffer(DoorIndices); diff --git a/Runtime/AutoMapper/CMappableObject.hpp b/Runtime/AutoMapper/CMappableObject.hpp index c773b51c5..a2fe513d2 100644 --- a/Runtime/AutoMapper/CMappableObject.hpp +++ b/Runtime/AutoMapper/CMappableObject.hpp @@ -19,13 +19,7 @@ class CStateManager; class CMappableObject { public: - struct Vert { - hsh::float3 m_pos; - void assign(float x, float y, float z) { - m_pos = hsh::float3(x, y, z); - } - }; - static hsh::owner> g_doorVbo; + static hsh::owner> g_doorVbo; static hsh::owner> g_doorIbo; enum class EMappableObjectType { @@ -59,7 +53,7 @@ public: enum class EVisMode { Always, MapStationOrVisit, Visit, Never, MapStationOrVisit2 }; private: - static std::array skDoorVerts; + static std::array skDoorVerts; EMappableObjectType x0_type; EVisMode x4_visibilityMode; diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 997f12d85..9c0d10dc2 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -139,22 +139,13 @@ set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) set(RUNTIME_LIBRARIES RetroDataSpec AssetNameMapNull NESEmulator libjpeg-turbo jbus kabufuda discord-rpc logvisor) -if(MSVC) - # WTF MS???? LINK.EXE is unable to address static libraries larger than 4GB. - # This is a hack to split this large library in two. - add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A}) - add_runtime_common_library(RuntimeCommonB ${RUNTIME_SOURCES_B}) - target_include_directories(RuntimeCommonB PUBLIC ${RUNTIME_INCLUDES}) - target_link_libraries(RuntimeCommonB PUBLIC ${RUNTIME_LIBRARIES}) - target_link_libraries(RuntimeCommon PUBLIC RuntimeCommonB) - target_hsh(RuntimeCommon) - target_hsh(RuntimeCommonB) -else() - add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A} ${RUNTIME_SOURCES_B}) - target_include_directories(RuntimeCommon PUBLIC ${RUNTIME_INCLUDES}) - target_link_libraries(RuntimeCommon PUBLIC ${RUNTIME_LIBRARIES}) - target_hsh(RuntimeCommon) -endif() +add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A}) +add_runtime_common_library(RuntimeCommonB ${RUNTIME_SOURCES_B}) +target_include_directories(RuntimeCommonB PUBLIC ${RUNTIME_INCLUDES}) +target_link_libraries(RuntimeCommonB PUBLIC ${RUNTIME_LIBRARIES}) +target_link_libraries(RuntimeCommon PUBLIC RuntimeCommonB) +target_hsh(RuntimeCommon) +target_hsh(RuntimeCommonB) add_executable(urde CMain.hpp CMain.cpp) target_link_libraries(urde PUBLIC RuntimeCommon) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index b8831eee7..d37afdc8d 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -668,7 +668,7 @@ void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport, cam->GetFarClipDistance()); } -void CStateManager::'DrawWorld() { +void CStateManager::DrawWorld() { SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue); const CTimeProvider timeProvider(xf14_curTimeMod900); const SViewport backupViewport = g_Viewport; diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index 8d632f5c1..1ddc88cb6 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -693,8 +693,8 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac) GenerateFogVolumeRampTex(); GenerateSphereRampTex(); - m_ballShadowId = hsh::create_render_texture2d({skBallShadowIdSize, skBallShadowIdSize}, hsh::RGBA8_UNORM, 1, 0); - x14c_reflectionTex = hsh::create_render_texture2d({256, 256}, hsh::RGBA8_UNORM, 1, 0); + m_ballShadowId = hsh::create_render_texture2d({skBallShadowIdSize, skBallShadowIdSize}, 1, 0); + x14c_reflectionTex = hsh::create_render_texture2d({256, 256}, 1, 0); GenerateScanLinesVBO(); LoadThermoPalette(); diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index 3cd67be14..ce54c6a69 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -308,7 +308,7 @@ public: void BindReflectionDrawTarget() { x14c_reflectionTex.attach(); } void BindBallShadowIdTarget() { m_ballShadowId.attach(); } void ResolveBallShadowIdTarget() { - m_ballShadowId.resolve_color_binding(0, hsh::rect2d({0, 0}, {m_ballShadowIdW, m_ballShadowIdH}), false); + m_ballShadowId.resolve_color_binding(0, hsh::rect2d({0, 0}, {skBallShadowIdSize, skBallShadowIdSize}), false); } void FindOverlappingWorldModels(std::vector& modelBits, const zeus::CAABox& aabb) const; diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index d2fca99bc..cc0d6e67f 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -22,6 +22,7 @@ ERglCullMode gx_CullMode; std::array gx_AmbientColors; /// End GX state +hsh::owner CGraphics::g_SpareTexture; CGraphics::CProjectionState CGraphics::g_Proj; CGraphics::CFogState CGraphics::g_Fog; std::array CGraphics::g_ColorRegs{}; @@ -176,11 +177,6 @@ void CGraphics::SetModelMatrix(const zeus::CTransform& xf) { SetViewMatrix(); } -constexpr zeus::CMatrix4f PlusOneZ(1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 0.f, 0.f, 1.f); - -constexpr zeus::CMatrix4f VulkanCorrect(1.f, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 0.f, 0.f, 0.f, 0.5f, 0.5f + FLT_EPSILON, - 0.f, 0.f, 0.f, 1.f); - zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar, bool forRenderer) { CProjectionState st; @@ -199,14 +195,8 @@ zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float fpn = st.x18_far + st.x14_near; float fmn = st.x18_far - st.x14_near; - if (!forRenderer) { - return zeus::CMatrix4f(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, - 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); - } - - zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, - 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f); - return VulkanCorrect * mat2; + return zeus::CMatrix4f{2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, + 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f}; } zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { @@ -218,16 +208,9 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { float fpn = g_Proj.x18_far + g_Proj.x14_near; float fmn = g_Proj.x18_far - g_Proj.x14_near; - if (!forRenderer) { - return zeus::CMatrix4f(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, - tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, - 0.f, -1.f, 0.f); - } - - zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, - tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, - 0.f, -1.f, 0.f); - return VulkanCorrect * mat2; + return zeus::CMatrix4f{2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb, + tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f, + 0.f, -1.f, 0.f}; } else { float rml = g_Proj.x8_right - g_Proj.x4_left; float rpl = g_Proj.x8_right + g_Proj.x4_left; @@ -236,14 +219,8 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) { float fpn = g_Proj.x18_far + g_Proj.x14_near; float fmn = g_Proj.x18_far - g_Proj.x14_near; - if (!forRenderer) { - return zeus::CMatrix4f(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, - -fpn / fmn, 0.f, 0.f, 0.f, 1.f); - } - - zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, - -fpn / fmn, 0.f, 0.f, 0.f, 1.f); - return VulkanCorrect * mat2; + return zeus::CMatrix4f{2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn, + -fpn / fmn, 0.f, 0.f, 0.f, 1.f}; } } diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index 64a896449..36b9966ca 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -457,6 +457,7 @@ using BlendAttachmentExt = hsh::ColorComponentFlags( hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue | (Alpha != AlphaMode::NoAlpha ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>; + template using AdditiveAttachmentExt = hsh::pipeline::color_attachment::Factor, @@ -464,6 +465,7 @@ using AdditiveAttachmentExt = hsh::ColorComponentFlags( hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue | (Alpha != AlphaMode::NoAlpha ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>; + template using MultiplyAttachmentExt = hsh::pipeline::color_attachment::Factor, @@ -471,6 +473,7 @@ using MultiplyAttachmentExt = hsh::ColorComponentFlags( hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue | (Alpha != AlphaMode::NoAlpha ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>; + template using SubtractAttachmentExt = hsh::pipeline::color_attachment< hsh::SrcAlpha, hsh::One, hsh::ReverseSubtract, AlphaSrc::Factor, diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index 9a8443154..b9a444e70 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -176,7 +176,7 @@ private: ModelInstance m_ballShadowInstance; hsh::vertex_buffer_typeless m_staticVbo; - hsh::index_buffer m_staticIbo; + hsh::index_buffer_typeless m_staticIbo; hsh::texture2d m_lastDrawnShadowMap; hsh::texture2d m_lastDrawnOneTexture; @@ -203,7 +203,7 @@ public: ~CBooModel(); CBooModel(TToken& token, CModel* parent, std::vector* surfaces, SShader& shader, hsh::vertex_buffer_typeless vbo, - hsh::index_buffer ibo, + hsh::index_buffer_typeless ibo, const zeus::CAABox& aabb, u8 renderMask, int numInsts); static void MakeTexturesFromMats(const MaterialSet& matSet, @@ -307,9 +307,9 @@ public: zeus::CVector3f GetPoolVertex(size_t idx) const; size_t GetPoolNormalOffset(size_t idx) const; zeus::CVector3f GetPoolNormal(size_t idx) const; - void ApplyVerticesCPU(hsh::owner& vertBuf, + void ApplyVerticesCPU(hsh::dynamic_owner& vertBuf, const std::vector>& vn) const; - void RestoreVerticesCPU(hsh::owner& vertBuf) const; + void RestoreVerticesCPU(hsh::dynamic_owner& vertBuf) const; void _WarmupShaders(); static void WarmupShaders(const SObjectTag& cmdlTag); diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index df9ad0e87..7878b4deb 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -11,7 +11,6 @@ #include -#include #include #include #include @@ -124,26 +123,19 @@ void CBooModel::EnsureViewDepStateCached(const CBooModel& model, const CBooSurfa mtxsOut[1][3][0] = -surfPos.dot(v2) * f1 + 0.5f; mtxsOut[1][2][1] = f2; mtxsOut[1][3][1] = -modelToPlayerLocal.z() * f2; - switch (CGraphics::g_BooPlatform) { - case boo::IGraphicsDataFactory::Platform::OpenGL: - mtxsOut[1] = ReflectPostGL * mtxsOut[1]; - break; - default: - break; - } } } -boo::ObjToken CBooModel::g_shadowMap; +hsh::texture2d CBooModel::g_shadowMap; zeus::CTransform CBooModel::g_shadowTexXf; -boo::ObjToken CBooModel::g_disintegrateTexture; -boo::ObjToken CBooModel::g_reflectionCube; +hsh::texture2d CBooModel::g_disintegrateTexture; +hsh::texturecube CBooModel::g_reflectionCube; void CBooModel::EnableShadowMaps(hsh::texture2d map, const zeus::CTransform& texXf) { g_shadowMap = map; g_shadowTexXf = texXf; } -void CBooModel::DisableShadowMaps() { g_shadowMap = nullptr; } +void CBooModel::DisableShadowMaps() { g_shadowMap.reset(); } CBooModel::~CBooModel() { if (m_prev) @@ -155,13 +147,14 @@ CBooModel::~CBooModel() { } CBooModel::CBooModel(TToken& token, CModel* parent, std::vector* surfaces, SShader& shader, - hsh::vertex_buffer_typeless vbo, hsh::index_buffer ibo, const zeus::CAABox& aabb, + hsh::vertex_buffer_typeless vbo, hsh::index_buffer_typeless ibo, const zeus::CAABox& aabb, u8 renderMask, int numInsts) : m_modelTok(token) , m_model(parent) , x0_surfaces(surfaces) , x4_matSet(&shader.m_matSet) , m_geomLayout(&*shader.m_geomLayout) +, m_vtxFmt(m_model->GetHMDLMeta()) , m_matSetIdx(shader.m_matSetIdx) , x1c_textures(shader.x0_textures) , x20_aabb(aabb) @@ -302,11 +295,11 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) { /* Build geometry uniform buffer if shared not available */ hsh::uniform_buffer_typeless geomUniformBuf; if (sharedLayoutBuf >= 0) { - geomUniformBuf = m_geomLayout->GetSharedBuffer(sharedLayoutBuf); + geomUniformBuf = m_geomLayout->GetSharedBuffer(sharedLayoutBuf).get(); } else { auto CreateUBO = [&]() { newInst.m_geomUniformBuffer = hsh::create_dynamic_uniform_buffer>(); - geomUniformBuf = newInst.m_geomUniformBuffer; + geomUniformBuf = newInst.m_geomUniformBuffer.get(); }; switch (m_vtxFmt.NSkinSlots) { #define VERT_UNIFORM(nskins) \ @@ -376,7 +369,7 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) { for (const CBooSurface& surf : *x0_surfaces) { const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); - std::array, 12> texs{ + std::array texs{ g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_whiteTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->x220_sphereRamp.get(), @@ -386,12 +379,13 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) { for (const auto& ch : mat.chunks) { if (const auto* const pass = ch.get_if()) { auto search = x1c_textures.find(pass->texId.toUint32()); - boo::ObjToken btex; - if (search != x1c_textures.cend() && (btex = search->second.GetObj()->GetBooTexture())){ - texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex;} - } else if (const auto* const pass = ch.get_if()) { - boo::ObjToken btex = g_Renderer->GetColorTexture(zeus::CColor(pass->color)); - texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex; + hsh::texture2d tex; + if (search != x1c_textures.cend() && (tex = search->second.GetObj()->GetBooTexture())) { + texs[MaterialSet::Material::TexMapIdx(pass->type)] = tex; + } + } else if (const auto* const clr = ch.get_if()) { + hsh::texture2d tex = g_Renderer->GetColorTexture(clr->color); + texs[MaterialSet::Material::TexMapIdx(clr->type)] = tex; } } } @@ -412,8 +406,9 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) { bool useReflection = mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye(); if (useReflection) { - if (g_Renderer->x14c_reflectionTex) - texs[11] = g_Renderer->x14c_reflectionTex.get(); + if (g_Renderer->x14c_reflectionTex.Owner.IsValid()) { + // texs[11] = g_Renderer->x14c_reflectionTex.get_color(0); + } thisOffs[3] = curReflect; curReflect += 256; } else { @@ -1181,8 +1176,8 @@ static const u8* MemoryFromPartData(const u8*& dataCur, const u32*& secSizeCur) std::unique_ptr CModel::MakeNewInstance(int shaderIdx, int subInsts, bool lockParent) { if (shaderIdx >= x18_matSets.size()) shaderIdx = 0; - auto ret = std::make_unique(m_selfToken, this, &x8_surfaces, x18_matSets[shaderIdx], m_staticVbo, m_ibo, - m_aabb, (m_flags & 0x2) != 0, subInsts); + auto ret = std::make_unique(m_selfToken, this, &x8_surfaces, x18_matSets[shaderIdx], m_staticVbo.get(), + m_ibo.get(), m_aabb, (m_flags & 0x2) != 0, subInsts); if (lockParent) ret->LockParent(); return ret; @@ -1228,26 +1223,67 @@ CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* stor matSet.BuildShaders(m_hmdlMeta); } - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - /* Index buffer is always static */ - if (m_hmdlMeta.indexCount) - m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, m_hmdlMeta.indexCount); + /* Index buffer is always static */ + if (m_hmdlMeta.indexCount) + m_ibo = + hsh::create_index_buffer(hsh::detail::ArrayProxy{reinterpret_cast(iboData), m_hmdlMeta.indexCount}); - if (!m_hmdlMeta.bankCount) { - /* Non-skinned models use static vertex buffers shared with CBooModel instances */ - if (m_hmdlMeta.vertCount) - m_staticVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, m_hmdlMeta.vertStride, m_hmdlMeta.vertCount); - } else { - /* Skinned models use per-instance dynamic buffers for vertex manipulation effects */ - size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; - if (vboSz) { - m_dynamicVertexData.reset(new uint8_t[vboSz]); - memmove(m_dynamicVertexData.get(), vboData, vboSz); + if (!m_hmdlMeta.bankCount) { + /* Non-skinned models use static vertex buffers shared with CBooModel instances */ + if (m_hmdlMeta.vertCount) { + auto CreateVBO = [this, vboData]() { + using VertData = CModelShaders::VertData<0, NUVs, NWeights>; + assert(sizeof(VertData) != m_hmdlMeta.vertStride && "Vert data stride mismatch"); + m_staticVbo = hsh::create_vertex_buffer( + hsh::detail::ArrayProxy{reinterpret_cast(vboData), m_hmdlMeta.vertCount}); + }; +#define VERT_DATA(uvs) \ + switch (m_hmdlMeta.weightCount) { \ + case 0: \ + CreateVBO.operator()(); \ + break; \ + case 1: \ + CreateVBO.operator()(); \ + break; \ + case 2: \ + CreateVBO.operator()(); \ + break; \ + case 3: \ + CreateVBO.operator()(); \ + break; \ + case 4: \ + CreateVBO.operator()(); \ + break; \ + default: \ + assert(false && "Unhandled weight count"); \ + break; \ + } \ + break; + switch (m_hmdlMeta.uvCount) { + case 0: + VERT_DATA(0) + case 1: + VERT_DATA(1) + case 2: + VERT_DATA(2) + case 3: + VERT_DATA(3) + case 4: + VERT_DATA(4) +#undef VERT_DATA + default: + assert(false && "Unhandled UV count"); + break; } } - - return true; - } BooTrace); + } else { + /* Skinned models use per-instance dynamic buffers for vertex manipulation effects */ + size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; + if (vboSz) { + m_dynamicVertexData.reset(new uint8_t[vboSz]); + memmove(m_dynamicVertexData.get(), vboData, vboSz); + } + } const u32 surfCount = hecl::SBig(*reinterpret_cast(surfInfo)); x8_surfaces.reserve(surfCount); @@ -1315,9 +1351,9 @@ zeus::CVector3f CModel::GetPoolNormal(size_t idx) const { return {floats}; } -void CModel::ApplyVerticesCPU(hsh::owner& vertBuf, +void CModel::ApplyVerticesCPU(hsh::dynamic_owner& vertBuf, const std::vector>& vn) const { - u8* data = reinterpret_cast(vertBuf->map(m_hmdlMeta.vertStride * m_hmdlMeta.vertCount)); + u8* data = reinterpret_cast(vertBuf.map()); // m_hmdlMeta.vertStride * m_hmdlMeta.vertCount for (u32 i = 0; i < std::min(u32(vn.size()), m_hmdlMeta.vertCount); ++i) { const std::pair& avn = vn[i]; float* floats = reinterpret_cast(data + GetPoolVertexOffset(i)); @@ -1328,14 +1364,14 @@ void CModel::ApplyVerticesCPU(hsh::owner& vertBuf, floats[4] = avn.second.y(); floats[5] = avn.second.z(); } - vertBuf->unmap(); + vertBuf.unmap(); } -void CModel::RestoreVerticesCPU(hsh::owner& vertBuf) const { +void CModel::RestoreVerticesCPU(hsh::dynamic_owner& vertBuf) const { size_t size = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; - u8* data = reinterpret_cast(vertBuf->map(size)); + u8* data = reinterpret_cast(vertBuf.map()); // size memcpy(data, m_dynamicVertexData.get(), size); - vertBuf->unmap(); + vertBuf.unmap(); } void CModel::_WarmupShaders() { diff --git a/Runtime/Graphics/CTexture.hpp b/Runtime/Graphics/CTexture.hpp index 96a6260f5..fda1d5e3b 100644 --- a/Runtime/Graphics/CTexture.hpp +++ b/Runtime/Graphics/CTexture.hpp @@ -76,7 +76,7 @@ public: hsh::texture_typeless GetBooTexture() const { return m_booTex.get(); } hsh::texture_typeless GetPaletteTexture() const { return m_paletteTex.get(); } std::unique_ptr BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut, std::unique_ptr& paletteOut) const; - hsh::texture_typeless GetFontTexture(EFontType tp); + hsh::texture2d_array GetFontTexture(EFontType tp); const CTextureInfo* GetTextureInfo() const { return m_textureInfo; } }; diff --git a/Runtime/Graphics/CTextureBoo.cpp b/Runtime/Graphics/CTextureBoo.cpp index 682576e88..2bbd50f83 100644 --- a/Runtime/Graphics/CTextureBoo.cpp +++ b/Runtime/Graphics/CTextureBoo.cpp @@ -204,8 +204,8 @@ void CTexture::BuildIA8FromGCN(CInputStream& in) { }); } -static std::vector DecodePalette(int numEntries, CInputStream& in) { - std::vector ret; +static std::vector DecodePalette(int numEntries, CInputStream& in) { + std::vector ret; ret.reserve(numEntries); enum class EPaletteType { IA8, RGB565, RGB5A3 }; @@ -544,8 +544,8 @@ void CTexture::BuildC8Font(const void* data, EFontType ftype) { h /= 2; } - m_booTex = hsh::create_texture2d_array({x4_w, x6_h}, layerCount, hsh::R8_UNORM, x8_mips, [&](void* data, std::size_t size) { - std::memcpy(data, texels, size); + m_booTex = hsh::create_texture2d_array({x4_w, x6_h}, layerCount, hsh::RGBA8_UNORM, x8_mips, [&](void* data, std::size_t size) { + std::memcpy(data, buf.get(), size); }); } @@ -609,9 +609,9 @@ CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTex case ETexelFormat::RGBA8: BuildRGBA8FromGCN(r); break; - case ETexelFormat::CMPR: - BuildDXT1FromGCN(r); - break; +// case ETexelFormat::CMPR: +// BuildDXT1FromGCN(r); +// break; case ETexelFormat::RGBA8PC: BuildRGBA8(owned.get() + 12, length - 12); break; @@ -719,7 +719,7 @@ std::unique_ptr CTexture::BuildMemoryCardTex(u32& sizeOut, ETexelFormat& f return ret; } -hsh::texture_typeless CTexture::GetFontTexture(EFontType tp) { +hsh::texture2d_array CTexture::GetFontTexture(EFontType tp) { if (m_ftype != tp && x0_fmt == ETexelFormat::C8PC) { m_ftype = tp; BuildC8Font(m_otex.get() + 12, m_ftype); diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index 68b93f77b..c263cec3d 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -9,18 +9,16 @@ namespace urde { using namespace hsh::pipeline; -template -struct CAABoxShaderPipeline -: pipeline, ERglBlendModeAttachment, - ERglCullModeAttachment, ERglDepthCompareAttachment, depth_write> { +struct CAABoxShaderPipeline : pipeline, + ERglBlendModeAttachment, + ERglCullModeAttachment, + ERglDepthCompareAttachment, depth_write> { CAABoxShaderPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf) { this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f); this->color_out[0] = uniBuf->m_color; } }; -template struct CAABoxShaderPipeline; constexpr size_t VertexCount = 34; @@ -53,8 +51,7 @@ CAABoxShader::CAABoxShader(const zeus::CAABox& aabb) { m_vbo = hsh::create_vertex_buffer(verts); m_uniBuf = hsh::create_dynamic_uniform_buffer(); - m_dataBind.hsh_bind(CAABoxShaderPipeline(m_vbo.get(), m_uniBuf.get())); + m_dataBind.hsh_bind(CAABoxShaderPipeline(m_vbo.get(), m_uniBuf.get())); } void CAABoxShader::draw(const zeus::CColor& color) { diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp index 706adb4e8..68c58ae99 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp @@ -14,10 +14,13 @@ template struct CColoredQuadFilterPipeline : FilterPipeline { CColoredQuadFilterPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf) { - this->position = hsh::float4(vbo->m_pos, 1.f); + this->position = uniBuf->m_matrix * hsh::float4(vbo->m_pos, 1.f); this->color_out[0] = uniBuf->m_color; } }; +template struct CColoredQuadFilterPipeline; +template struct CColoredQuadFilterPipeline; +template struct CColoredQuadFilterPipeline; CColoredQuadFilter::CColoredQuadFilter(EFilterType type) { constexpr std::array verts{{ @@ -36,6 +39,7 @@ CColoredQuadFilter::CColoredQuadFilter(EFilterType type) { void CColoredQuadFilter::draw(const zeus::CColor& color, const zeus::CRectangle& rect) { SCOPED_GRAPHICS_DEBUG_GROUP("CColoredQuadFilter::draw", zeus::skMagenta); + m_uniform.m_matrix = zeus::CMatrix4f{}; m_uniform.m_matrix[0][0] = rect.size.x() * 2.f; m_uniform.m_matrix[1][1] = rect.size.y() * 2.f; m_uniform.m_matrix[3][0] = rect.position.x() * 2.f - 1.f; diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.hpp b/Runtime/Graphics/Shaders/CColoredStripShader.hpp index acdaad0c0..964766797 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.hpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.hpp @@ -1,5 +1,7 @@ #pragma once +#include "hsh/hsh.h" + #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" diff --git a/Runtime/Graphics/Shaders/CDecalShaders.cpp b/Runtime/Graphics/Shaders/CDecalShaders.cpp index f65d6c7d0..d7b5413f4 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.cpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.cpp @@ -15,8 +15,8 @@ struct CDecalShaderTexPipeline std::conditional_t, AdditiveAttachment<>>, BlendAttachment<>>, depth_compare, depth_write> { - CDecalShaderTexPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf, - hsh::texture2d tex) { + CDecalShaderTexPipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, + hsh::uniform_buffer uniBuf, hsh::texture2d tex) { this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; this->color_out[0] = vbo->color * uniBuf->moduColor * tex.sample(vbo->uvs[this->vertex_id]); if constexpr (RedToAlpha) { @@ -31,7 +31,7 @@ template struct CDecalShaderTexPipeline; template struct CDecalShaderNoTexPipeline : pipeline, BlendAttachment<>>, depth_compare, depth_write> { - CDecalShaderNoTexPipeline(hsh::vertex_buffer vbo, + CDecalShaderNoTexPipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, hsh::uniform_buffer uniBuf) { this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; this->color_out[0] = vbo->color * uniBuf->moduColor; diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.cpp b/Runtime/Graphics/Shaders/CElementGenShaders.cpp index e2aef0bab..994a96110 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.cpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.cpp @@ -33,7 +33,7 @@ using BlendModeAttachment = typename BlendModeAttachmentExt::t template struct CElementGenShadersTexPipeline : pipeline, BlendModeAttachment, depth_compare, depth_write> { - CElementGenShadersTexPipeline(hsh::vertex_buffer vbo, + CElementGenShadersTexPipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, hsh::uniform_buffer uniBuf, hsh::texture2d tex) { this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; this->color_out[0] = vbo->color * uniBuf->moduColor * tex.sample(vbo->uvs[this->vertex_id]); @@ -42,15 +42,14 @@ struct CElementGenShadersTexPipeline : pipeline, Bl } } }; -template struct CElementGenShadersTexPipeline; -template struct CElementGenShadersTexPipeline; -template struct CElementGenShadersTexPipeline; +template struct CElementGenShadersTexPipeline; +template struct CElementGenShadersTexPipeline; template struct CElementGenShadersIndTexPipeline : pipeline, BlendModeAttachment, depth_compare, depth_write> { - CElementGenShadersIndTexPipeline(hsh::vertex_buffer vbo, + CElementGenShadersIndTexPipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, hsh::uniform_buffer uniBuf, hsh::texture2d texrTex, hsh::texture2d tindTex, hsh::render_texture2d sceneTex) { this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; @@ -65,22 +64,19 @@ struct CElementGenShadersIndTexPipeline } } }; -template struct CElementGenShadersIndTexPipeline; -template struct CElementGenShadersIndTexPipeline; +template struct CElementGenShadersIndTexPipeline; template struct CElementGenShadersNoTexPipeline : pipeline, BlendModeAttachment, depth_compare, depth_write> { - CElementGenShadersNoTexPipeline(hsh::vertex_buffer vbo, + CElementGenShadersNoTexPipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, hsh::uniform_buffer uniBuf) { this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; this->color_out[0] = vbo->color * uniBuf->moduColor; } }; -template struct CElementGenShadersNoTexPipeline; -template struct CElementGenShadersNoTexPipeline; -template struct CElementGenShadersNoTexPipeline; +template struct CElementGenShadersNoTexPipeline; CElementGenShaders::EShaderClass CElementGenShaders::GetShaderClass(CElementGen& gen) { const auto* desc = gen.x1c_genDesc.GetObj(); diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp index a8561ecc0..cc376722a 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp @@ -61,19 +61,19 @@ void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector, std::conditional_t, MultiplyAttachment>, depth_compare, depth_write> { - CEnvFxShadersPipeline(hsh::vertex_buffer vbo, + CEnvFxShadersPipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, hsh::uniform_buffer envFxUniBuf, hsh::uniform_buffer fogUniBuf, hsh::texture2d texFlake, hsh::texture2d texEnv) { diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp index 3c838b847..3e2d94284 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp @@ -35,7 +35,7 @@ template struct CLineRendererNoTexPipeline : pipeline, BlendAttachment>, depth_compare> { - CLineRendererNoTexPipeline(hsh::vertex_buffer vbo, + CLineRendererNoTexPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf HSH_VAR_STAGE(fragment)) { this->position = vbo->pos; hsh::float4 colorIn = vbo->color * uniBuf->moduColor; @@ -46,6 +46,7 @@ struct CLineRendererNoTexPipeline template struct CLineRendererNoTexPipeline; template struct CLineRendererNoTexPipeline; template struct CLineRendererNoTexPipeline; +template struct CLineRendererNoTexPipeline; template struct CLineRendererNoTexPipeline; template struct CLineRendererNoTexPipeline; template struct CLineRendererNoTexPipeline; diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp index c158fc5b1..2630aea38 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp @@ -23,8 +23,7 @@ CMapSurfaceShader::CMapSurfaceShader(hsh::vertex_buffer vbo, hsh::index_bu void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) { SCOPED_GRAPHICS_DEBUG_GROUP("CMapSurfaceShader::draw", zeus::skMagenta); - Uniform uniform = {CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), color}; - m_uniBuf.load(uniform); + m_uniBuf.load({CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), color}); m_dataBind.draw_indexed(start, count); } diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp index 6dd1440fa..f3799567e 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp @@ -5,6 +5,8 @@ #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" +#include "hsh/hsh.h" + namespace urde { class CMapSurfaceShader { diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp index c2ba0171a..328c0368d 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp @@ -9,7 +9,7 @@ namespace urde { using namespace hsh::pipeline; struct CRadarPaintShaderPipeline : pipeline, AdditiveAttachment<>, depth_write> { - CRadarPaintShaderPipeline(hsh::vertex_buffer vbo, + CRadarPaintShaderPipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, hsh::uniform_buffer ubo, hsh::texture2d tex) { this->position = ubo->xf * hsh::float4(vbo->pos[this->vertex_id], 1.f); this->color_out[0] = vbo->color * tex.sample(vbo->uv[this->vertex_id]); diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp index 2cc47f99e..885f228e3 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp @@ -2,6 +2,8 @@ #include "Runtime/CToken.hpp" +#include "hsh/hsh.h" + #include "zeus/CColor.hpp" namespace urde { diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp index 7c94e8b38..5d8465b56 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp @@ -4,6 +4,8 @@ #include "Runtime/GCNTypes.hpp" +#include "hsh/hsh.h" + #include "zeus/CVector3f.hpp" namespace urde { diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.cpp b/Runtime/Graphics/Shaders/CTextSupportShader.cpp index e39db9e60..e55271c6e 100644 --- a/Runtime/Graphics/Shaders/CTextSupportShader.cpp +++ b/Runtime/Graphics/Shaders/CTextSupportShader.cpp @@ -33,7 +33,7 @@ using DrawFlagsAttachment = typename DrawFlagsAttachmentExt::type; template struct CTextSupportShaderCharacterPipeline : pipeline, DrawFlagsAttachment, depth_write, depth_compare> { - CTextSupportShaderCharacterPipeline(hsh::vertex_buffer vbo, + CTextSupportShaderCharacterPipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, hsh::uniform_buffer ubo, hsh::texture2d_array tex) { this->position = ubo->m_mvp * hsh::float4(vbo->m_pos[this->vertex_id], 1.f); hsh::float4 fontColor = ubo->m_uniformColor * vbo->m_fontColor; @@ -49,7 +49,7 @@ template struct CTextSupportShaderCharacterPipeline struct CTextSupportShaderImagePipeline : pipeline, DrawFlagsAttachment, depth_write, depth_compare> { - CTextSupportShaderImagePipeline(hsh::vertex_buffer vbo, + CTextSupportShaderImagePipeline(hsh::vertex_buffer vbo HSH_VAR_INSTANCE, hsh::uniform_buffer ubo, hsh::texture2d tex) { this->position = ubo->m_mvp * hsh::float4(vbo->m_pos[this->vertex_id], 1.f); // FIXME hsh bug: sampler appears to be completely ignored diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index 5c8190951..715681ac4 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -12,25 +12,51 @@ namespace urde { template struct CTexturedQuadFilterPipeline : FilterPipeline { CTexturedQuadFilterPipeline(hsh::vertex_buffer vbo, - hsh::uniform_buffer uniBuf, hsh::texture2d tex) { - this->position = hsh::float4(vbo->m_pos, 1.f); + hsh::uniform_buffer uniBuf, + hsh::texture2d tex) { + this->position = uniBuf->m_matrix * hsh::float4(vbo->m_pos, 1.f); if constexpr (TexAlpha) { - this->color_out[0] = uniBuf->m_color * tex.sample_bias(vbo->m_uv, uniBuf->m_lod, {}); + this->color_out[0] = uniBuf->m_color * tex.sample_bias(vbo->m_uv, uniBuf->m_lod); } else { this->color_out[0] = - uniBuf->m_color * hsh::float4(tex.sample_bias(vbo->m_uv, uniBuf->m_lod, {}).xyz(), 1.f); + uniBuf->m_color * hsh::float4(tex.sample_bias(vbo->m_uv, uniBuf->m_lod).xyz(), 1.f); } } }; +template struct CTexturedQuadFilterPipeline; +template struct CTexturedQuadFilterPipeline; +template struct CTexturedQuadFilterPipeline; -template -CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, Tex tex, ZTest ztest) +template +struct CTexturedQuadFilterRenderTexPipeline : FilterPipeline { + CTexturedQuadFilterRenderTexPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer uniBuf, + hsh::render_texture2d tex) { + this->position = uniBuf->m_matrix * hsh::float4(vbo->m_pos, 1.f); + if constexpr (TexAlpha) { + this->color_out[0] = uniBuf->m_color * tex.sample_bias(vbo->m_uv, uniBuf->m_lod); + } else { + this->color_out[0] = + uniBuf->m_color * hsh::float4(tex.sample_bias(vbo->m_uv, uniBuf->m_lod).xyz(), 1.f); + } + } +}; +template struct CTexturedQuadFilterRenderTexPipeline; + +CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, hsh::texture2d tex, ZTest ztest) : m_zTest(ztest) { m_vbo = hsh::create_dynamic_vertex_buffer(16); m_uniBuf = hsh::create_dynamic_uniform_buffer(); m_dataBind.hsh_bind(CTexturedQuadFilterPipeline(m_vbo.get(), m_uniBuf.get(), tex)); } +CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, hsh::render_texture2d tex, ZTest ztest) +: m_zTest(ztest) { + m_vbo = hsh::create_dynamic_vertex_buffer(16); + m_uniBuf = hsh::create_dynamic_uniform_buffer(); + m_dataBind.hsh_rend_bind(CTexturedQuadFilterRenderTexPipeline(m_vbo.get(), m_uniBuf.get(), tex)); +} + CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, TLockedToken tex, ZTest ztest) : CTexturedQuadFilter(type, (tex ? tex->GetBooTexture() : hsh::texture2d{}), ztest) { m_tex = tex; @@ -49,8 +75,10 @@ void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const z m_uniform.m_matrix[0][0] = rect.size.x() * 2.f; m_uniform.m_matrix[1][1] = rect.size.y() * 2.f; + m_uniform.m_matrix[2][2] = 1.f; m_uniform.m_matrix[3][0] = rect.position.x() * 2.f - 1.f; m_uniform.m_matrix[3][1] = rect.position.y() * 2.f - 1.f; + m_uniform.m_matrix[3][3] = 1.f; m_uniform.m_color = color; m_uniBuf.load(m_uniform); @@ -140,13 +168,18 @@ void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& col } } -template -CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, Tex tex) { +CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, hsh::texture2d tex) { m_vbo = hsh::create_dynamic_vertex_buffer(16); m_uniBuf = hsh::create_dynamic_uniform_buffer(); m_dataBind.hsh_bind_alpha(CTexturedQuadFilterPipeline(m_vbo.get(), m_uniBuf.get(), tex)); } +CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, hsh::render_texture2d tex) { + m_vbo = hsh::create_dynamic_vertex_buffer(16); + m_uniBuf = hsh::create_dynamic_uniform_buffer(); + m_dataBind.hsh_render_bind_alpha(CTexturedQuadFilterRenderTexPipeline(m_vbo.get(), m_uniBuf.get(), tex)); +} + CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex) : CTexturedQuadFilterAlpha(type, (tex ? tex->GetBooTexture() : hsh::texture2d{})) { m_tex = tex; diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index eca5d921e..fb52dea3f 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -2,6 +2,8 @@ #include "Runtime/CToken.hpp" +#include "hsh/hsh.h" + #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CRectangle.hpp" @@ -32,7 +34,7 @@ protected: hsh::dynamic_owner> m_vbo; hsh::dynamic_owner> m_uniBuf; hsh::binding m_dataBind; - Uniform m_uniform; + Uniform m_uniform{}; ZTest m_zTest; CTexturedQuadFilter() = default; @@ -40,8 +42,8 @@ protected: public: static constexpr zeus::CRectangle DefaultRect{0.f, 0.f, 1.f, 1.f}; explicit CTexturedQuadFilter(EFilterType type, TLockedToken tex, ZTest zTest = ZTest::None); - template - explicit CTexturedQuadFilter(EFilterType type, Tex tex, ZTest zTest = ZTest::None); + explicit CTexturedQuadFilter(EFilterType type, hsh::texture2d tex, ZTest zTest = ZTest::None); + explicit CTexturedQuadFilter(EFilterType type, hsh::render_texture2d tex, ZTest zTest = ZTest::None); CTexturedQuadFilter(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter& operator=(const CTexturedQuadFilter&) = delete; CTexturedQuadFilter(CTexturedQuadFilter&&) = default; @@ -56,8 +58,8 @@ public: class CTexturedQuadFilterAlpha : public CTexturedQuadFilter { public: explicit CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex); - template - explicit CTexturedQuadFilterAlpha(EFilterType type, Tex tex); + explicit CTexturedQuadFilterAlpha(EFilterType type, hsh::texture2d tex); + explicit CTexturedQuadFilterAlpha(EFilterType type, hsh::render_texture2d tex); }; } // namespace urde diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp index 2194d214c..423d44293 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp @@ -2,6 +2,8 @@ #include +#include "hsh/hsh.h" + #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp index 747a61eb4..47f8db92c 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -5,11 +5,13 @@ #include "Runtime/CToken.hpp" #include "zeus/CMatrix4f.hpp" +#include "hsh/hsh.h" + namespace urde { class CTexture; class CXRayBlurFilter { - friend struct CXRayBlurFilterPipeline; +public: struct Vert { hsh::float2 m_pos; hsh::float2 m_uv; @@ -17,6 +19,8 @@ class CXRayBlurFilter { struct Uniform { std::array m_uv; }; + +private: TLockedToken m_paletteTex; hsh::owner> m_vbo; hsh::dynamic_owner> m_uniBuf; diff --git a/Runtime/GuiSys/CGuiWidget.hpp b/Runtime/GuiSys/CGuiWidget.hpp index 26ccf959f..0e03b677f 100644 --- a/Runtime/GuiSys/CGuiWidget.hpp +++ b/Runtime/GuiSys/CGuiWidget.hpp @@ -8,6 +8,9 @@ #include "Runtime/IOStreams.hpp" #include "Runtime/GuiSys/CGuiObject.hpp" +// FIXME move extent/rect/etc to builtin_types +#include "hsh/hsh.h" + #include "zeus/CColor.hpp" #include "zeus/CTransform.hpp" #include "zeus/CVector3f.hpp" diff --git a/Runtime/GuiSys/CRasterFont.hpp b/Runtime/GuiSys/CRasterFont.hpp index 720e9dc56..ea0a8029c 100644 --- a/Runtime/GuiSys/CRasterFont.hpp +++ b/Runtime/GuiSys/CRasterFont.hpp @@ -148,7 +148,7 @@ public: const char16_t* str, int len) const; const CGlyph* GetGlyph(char16_t chr) const { return InternalGetGlyph(chr); } void GetSize(const CDrawStringOptions& opts, int& width, int& height, const char16_t* str, int len) const; - hsh::texture2d GetTexture() { + hsh::texture2d_array GetTexture() { return x80_texture->GetFontTexture(x2c_mode); } diff --git a/Runtime/GuiSys/CTextRenderBuffer.cpp b/Runtime/GuiSys/CTextRenderBuffer.cpp index 24be64008..2973df8ad 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.cpp +++ b/Runtime/GuiSys/CTextRenderBuffer.cpp @@ -57,7 +57,9 @@ void CTextRenderBuffer::CommitResources() { m_uniBuf2 = hsh::create_dynamic_uniform_buffer(); } for (BooFontCharacters& chs : m_fontCharacters) { - CTextSupportShader::BuildCharacterShaderBinding(*this, chs, m_drawFlags); + if (!chs.m_charData.empty()) { + CTextSupportShader::BuildCharacterShaderBinding(*this, chs, m_drawFlags); + } } for (BooImage& img : m_images) { CTextSupportShader::BuildImageShaderBinding(*this, img, m_drawFlags); diff --git a/Runtime/GuiSys/CTextRenderBuffer.hpp b/Runtime/GuiSys/CTextRenderBuffer.hpp index a806988a1..233a04a1c 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.hpp +++ b/Runtime/GuiSys/CTextRenderBuffer.hpp @@ -9,6 +9,8 @@ #include "Runtime/GuiSys/CFontImageDef.hpp" #include "Runtime/GuiSys/CGuiWidget.hpp" +#include "hsh/hsh.h" + #include "zeus/CColor.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CVector2f.hpp" diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 571eddb71..5c6436bdc 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -209,7 +209,6 @@ void CGameArchitectureSupport::specialKeyUp(boo2::Keycode key, boo2::KeyModifier CMain::CMain(IFactory* resFactory, CSimplePool* resStore, hsh::surface surface) : x128_globalObjects(std::make_unique(resFactory, resStore)) { - CGraphics::InitializeBoo(surface); xe4_gameplayResult = EGameplayResult::Playing; g_Main = this; } diff --git a/Runtime/Particle/CParticleSwoosh.cpp b/Runtime/Particle/CParticleSwoosh.cpp index 012386a84..7bcc838f7 100644 --- a/Runtime/Particle/CParticleSwoosh.cpp +++ b/Runtime/Particle/CParticleSwoosh.cpp @@ -74,6 +74,7 @@ CParticleSwoosh::CParticleSwoosh(const TToken& desc, int len m_cachedVerts.reserve(maxVerts); m_vertBuf = hsh::create_dynamic_vertex_buffer(maxVerts); m_uniformBuf = hsh::create_dynamic_uniform_buffer(); + CParticleSwooshShaders::BuildShaderDataBinding(*this); } } } diff --git a/Runtime/World/CActorModelParticles.cpp b/Runtime/World/CActorModelParticles.cpp index b3389203d..b548a4871 100644 --- a/Runtime/World/CActorModelParticles.cpp +++ b/Runtime/World/CActorModelParticles.cpp @@ -628,7 +628,7 @@ void CActorModelParticles::LightDudeOnFire(CActor& act) { const CTexture* CActorModelParticles::GetAshyTexture(const CActor& act) { auto iter = FindSystem(act.GetUniqueId()); if (iter != x0_items.cend() && iter->xdc_ashy && iter->xdc_ashy.IsLoaded()) { - iter->xdc_ashy->GetBooTexture()->setClampMode(boo::TextureClampMode::ClampToEdge); + //iter->xdc_ashy->GetBooTexture()->setClampMode(boo::TextureClampMode::ClampToEdge); return iter->xdc_ashy.GetObj(); } return nullptr; diff --git a/Runtime/World/CFluidPlaneManager.hpp b/Runtime/World/CFluidPlaneManager.hpp index a88cf169d..a299693d1 100644 --- a/Runtime/World/CFluidPlaneManager.hpp +++ b/Runtime/World/CFluidPlaneManager.hpp @@ -4,6 +4,8 @@ #include "Runtime/rstl.hpp" #include "Runtime/World/CRippleManager.hpp" +#include "hsh/hsh.h" + namespace urde { class CStateManager; diff --git a/Runtime/World/CWorldTransManager.cpp b/Runtime/World/CWorldTransManager.cpp index 067978fe8..a1c3b80d8 100644 --- a/Runtime/World/CWorldTransManager.cpp +++ b/Runtime/World/CWorldTransManager.cpp @@ -290,7 +290,7 @@ void CWorldTransManager::DrawEnabled() { DrawFirstPass(&lights); SClipScreenRect rect(g_Viewport); CGraphics::ResolveSpareTexture(rect); - CGraphics::g_BooMainCommandQueue->clearTarget(true, true); + hsh::clear_attachments(); DrawSecondPass(&lights); m_dissolve.drawCropped(zeus::CColor{1.f, 1.f, 1.f, 1.f - t}, 1.f); }