Integrating latest from github/staging

Integrating up through commit 5e1bdae
This commit is contained in:
alexpete
2021-03-26 14:31:50 -07:00
parent 9c54341af8
commit 36c4e827bd
764 changed files with 11453 additions and 20251 deletions
+2 -2
View File
@@ -902,7 +902,7 @@ void ShadersOptimizeHelper(CallableT setupParserBin, const char* logString)
{
setupParserBin();
CryLogAlways("\nStarting shaders optimizing for %s...", logString);
AZStd::string str = "@cache@/" + gRenDev->m_cEF.m_ShadersCache;
AZStd::string str = "@usercache@/" + gRenDev->m_cEF.m_ShadersCache;
iLog->Log("Optimize shader cache folder: '%s'", gRenDev->m_cEF.m_ShadersCache.c_str());
gRenDev->m_cEF.mfOptimiseShaders(str.c_str(), false);
}
@@ -2396,7 +2396,7 @@ void CRenderer::InitRenderer()
CV_r_ShaderCompilerFolderSuffix = REGISTER_STRING("r_ShaderCompilerFolderSuffix", "", VF_NULL,
"Usage: r_ShaderCompilerFolderSuffix suffix \n"
"Default is empty. Set to some other value to append this suffix to the sys_game_folder when compiling shaders");
"Default is empty. Set to some other value to append this suffix to the project name when compiling shaders");
{
const SFileVersion& ver = gEnv->pSystem->GetFileVersion();
@@ -20,6 +20,7 @@
#include <AzCore/Socket/AzSocket.h>
#include <AzCore/NativeUI/NativeUIRequests.h>
#include <AzCore/PlatformId/PlatformId.h>
#include <AzCore/Utils/Utils.h>
#include <AzFramework/Network/SocketConnection.h>
#include <AzFramework/Asset/AssetSystemTypes.h>
@@ -306,23 +307,20 @@ namespace NRemoteCompiler
m_RequestLineRootFolder = "";
ICVar* pGameFolder = gEnv->pConsole->GetCVar("sys_game_folder");
auto projectName = AZ::Utils::GetProjectName();
ICVar* pCompilerFolderSuffix = CRenderer::CV_r_ShaderCompilerFolderSuffix;
if (pGameFolder)
if (!projectName.empty())
{
string folder = pGameFolder->GetString();
folder.Trim();
if (!folder.empty())
if (pCompilerFolderSuffix)
{
if (pCompilerFolderSuffix)
{
string suffix = pCompilerFolderSuffix->GetString();
suffix.Trim();
folder.append(suffix);
}
m_RequestLineRootFolder = folder + string("/");
string suffix = pCompilerFolderSuffix->GetString();
suffix.Trim();
projectName.append(suffix);
}
projectName.append("/");
m_RequestLineRootFolder.assign(projectName.c_str(), projectName.size());
}
if (m_RequestLineRootFolder.empty())
@@ -13,16 +13,61 @@
#include <AzTest/AzTest.h>
#include <AzCore/UnitTest/TestTypes.h>
#include <AzCore/Memory/AllocatorScope.h>
#include <AzCore/Settings/SettingsRegistry.h>
#include <AzCore/UnitTest/UnitTest.h>
#include "Mocks/IConsoleMock.h"
#include "Mocks/ICVarMock.h"
#include "Mocks/ISystemMock.h"
#include "RemoteCompiler.h"
namespace AZ
{
class SettingsRegistrySimpleMock;
using NiceSettingsRegistrySimpleMock = ::testing::NiceMock<SettingsRegistrySimpleMock>;
class SettingsRegistrySimpleMock : public AZ::SettingsRegistryInterface
{
public:
MOCK_CONST_METHOD1(GetType, Type(AZStd::string_view));
MOCK_CONST_METHOD2(Visit, bool(Visitor&, AZStd::string_view));
MOCK_CONST_METHOD2(Visit, bool(const VisitorCallback&, AZStd::string_view));
MOCK_METHOD1(RegisterNotifier, NotifyEventHandler(const NotifyCallback&));
MOCK_METHOD1(RegisterNotifier, NotifyEventHandler(NotifyCallback&&));
MOCK_CONST_METHOD2(Get, bool(bool&, AZStd::string_view));
MOCK_CONST_METHOD2(Get, bool(s64&, AZStd::string_view));
MOCK_CONST_METHOD2(Get, bool(u64&, AZStd::string_view));
MOCK_CONST_METHOD2(Get, bool(double&, AZStd::string_view));
MOCK_CONST_METHOD2(Get, bool(AZStd::string&, AZStd::string_view));
MOCK_CONST_METHOD2(Get, bool(FixedValueString&, AZStd::string_view));
MOCK_CONST_METHOD3(GetObject, bool(void*, Uuid, AZStd::string_view));
MOCK_METHOD2(Set, bool(AZStd::string_view, bool));
MOCK_METHOD2(Set, bool(AZStd::string_view, s64));
MOCK_METHOD2(Set, bool(AZStd::string_view, u64));
MOCK_METHOD2(Set, bool(AZStd::string_view, double));
MOCK_METHOD2(Set, bool(AZStd::string_view, AZStd::string_view));
MOCK_METHOD2(Set, bool(AZStd::string_view, const char*));
MOCK_METHOD3(SetObject, bool(AZStd::string_view, const void*, Uuid));
MOCK_METHOD1(Remove, bool(AZStd::string_view));
MOCK_METHOD3(MergeCommandLineArgument, bool(AZStd::string_view, AZStd::string_view, const CommandLineArgumentSettings&));
MOCK_METHOD2(MergeSettings, bool(AZStd::string_view, Format));
MOCK_METHOD4(MergeSettingsFile, bool(AZStd::string_view, Format, AZStd::string_view, AZStd::vector<char>*));
MOCK_METHOD5(
MergeSettingsFolder,
bool(AZStd::string_view, const Specializations&, AZStd::string_view, AZStd::string_view, AZStd::vector<char>*));
};
} // namespace AZ
namespace NRemoteCompiler
{
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::DoAll;
using SystemAllocatorScope = AZ::AllocatorScope<AZ::LegacyAllocator, CryStringAllocator>;
@@ -65,9 +110,12 @@ namespace NRemoteCompiler
SystemAllocatorScope::ActivateAllocators();
m_priorEnv = gEnv;
m_priorSettingsRegistry = AZ::SettingsRegistry::Get();
m_data.reset(new DataMembers);
AZ::SettingsRegistry::Register(&m_data->m_settings);
ON_CALL(m_data->m_console, GetCVar(_))
.WillByDefault(Return(&m_data->m_cvarMock));
@@ -89,6 +137,11 @@ namespace NRemoteCompiler
void TearDown() override
{
gEnv = m_priorEnv;
AZ::SettingsRegistry::Unregister(&m_data->m_settings);
if (m_priorSettingsRegistry)
{
AZ::SettingsRegistry::Register(m_priorSettingsRegistry);
}
m_data.reset();
SystemAllocatorScope::DeactivateAllocators();
AllocatorsTestFixture::TearDown();
@@ -99,12 +152,14 @@ namespace NRemoteCompiler
NiceMock<SystemMock> m_system;
NiceMock<ConsoleMock> m_console;
NiceMock<CVarMock> m_cvarMock;
AZ::NiceSettingsRegistrySimpleMock m_settings;
SSystemGlobalEnvironment m_stubEnv;
};
AZStd::unique_ptr<DataMembers> m_data;
SSystemGlobalEnvironment* m_priorEnv = nullptr;
AZ::SettingsRegistryInterface* m_priorSettingsRegistry = nullptr;
};
// allow punch through to PRIVATE functions so that they do not need to be made PUBLIC.
@@ -130,7 +185,9 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_Constructor_WithNoGameName_Fails)
{
EXPECT_CALL(m_data->m_cvarMock, GetString());
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString regResult;
EXPECT_CALL(m_data->m_settings, Get(regResult, _));
AZ_TEST_START_TRACE_SUPPRESSION;
ShaderSrvUnitTestAccessor srv;
@@ -140,8 +197,10 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_Constructor_WithValidGameName_Succeeds)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
}
@@ -149,11 +208,12 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_EncapsulateRequestInEngineConnectionProtocol_EmptyData_Fails)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
std::vector<uint8> testVector;
@@ -165,11 +225,12 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_EncapsulateRequestInEngineConnectionProtocol_ValidData_EmptyServerList_Fails)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillRepeatedly(Return("")); // empty server list
@@ -186,11 +247,12 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_EncapsulateRequestInEngineConnectionProtocol_ValidInputs_Succeeds)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
// After this, it will repeatedly call get cvar to get the server address:
const char* testList = "10.20.30.40";
@@ -207,11 +269,12 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_SendRequestViaEngineConnection_EmptyData_Fails)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
// After this, it will repeatedly call get cvar to get the server address:
const char* testList = "10.20.30.40";
@@ -221,7 +284,7 @@ namespace NRemoteCompiler
std::vector<uint8> testVector;
std::string testString("empty");
// test for empty data - recvfailed expected (error emitted)
// test for empty data - RecvFailed expected (error emitted)
AZ_TEST_START_TRACE_SUPPRESSION;
testString = "empty";
testVector.assign(testString.begin(), testString.end());
@@ -232,11 +295,12 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_SendRequestViaEngineConnection_IncompleteData_Fails)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
// After this, it will repeatedly call get cvar to get the server address:
const char* testList = "10.20.30.40";
@@ -247,7 +311,7 @@ namespace NRemoteCompiler
std::string testString("incomplete");
testVector.assign(testString.begin(), testString.end());
// test for incomplete data - recvfailed expected
// test for incomplete data - RecvFailed expected
AZ_TEST_START_TRACE_SUPPRESSION;
EXPECT_EQ(srv.SendRequestViaEngineConnection(testVector), EServerError::ESRecvFailed);
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
@@ -256,11 +320,12 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_SendRequestViaEngineConnection_CorruptData_Fails)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
// After this, it will repeatedly call get cvar to get the server address:
const char* testList = "10.20.30.40";
@@ -271,7 +336,7 @@ namespace NRemoteCompiler
std::string testString("corrupt");
testVector.assign(testString.begin(), testString.end());
// test for incomplete data - recvfailed expected
// test for incomplete data - RecvFailed expected
AZ_TEST_START_TRACE_SUPPRESSION;
EXPECT_EQ(srv.SendRequestViaEngineConnection(testVector), EServerError::ESRecvFailed);
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
@@ -280,11 +345,12 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_SendRequestViaEngineConnection_CompileError_Fails_ReturnsText)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
// After this, it will repeatedly call get cvar to get the server address:
const char* testList = "10.20.30.40";
@@ -294,11 +360,11 @@ namespace NRemoteCompiler
std::vector<uint8> testVector;
std::string testString("corrupt");
testVector.assign(testString.begin(), testString.end());
// test for an actual compile error - decompressed compile erro rexpected to be attached.
// test for an actual compile error - decompressed compile error expected to be attached.
testString = "compile_failure";
testVector.assign(testString.begin(), testString.end());
EXPECT_EQ(srv.SendRequestViaEngineConnection(testVector), EServerError::ESCompileError);
// validate hte compile erorr decompressed successfully
// validate the compile error decompressed successfully
const char* expected_decode = "decompressed_plaintext";
EXPECT_EQ(testVector.size(), strlen(expected_decode));
EXPECT_EQ(memcmp(testVector.data(), expected_decode, strlen(expected_decode)), 0);
@@ -307,11 +373,12 @@ namespace NRemoteCompiler
TEST_F(RemoteCompilerTest, CShaderSrv_SendRequestViaEngineConnection_ValidInput_Succeeds_ReturnsText)
{
// when we construct the server it calls get on the game name
EXPECT_CALL(m_data->m_cvarMock, GetString())
.WillOnce(Return("StarterGame"));
using namespace ::testing;
AZ::SettingsRegistryInterface::FixedValueString projectName;
EXPECT_CALL(m_data->m_settings, Get(projectName, _))
.WillOnce(DoAll(testing::SetArgReferee<0>("StarterGame"), Return(true)));
ShaderSrvUnitTestAccessor srv;
// After this, it will repeatedly call get cvar to get the server address:
const char* testList = "10.20.30.40";
@@ -375,7 +375,7 @@ void CShaderMan::mfInitShadersCacheMissLog()
// create valid path
gEnv->pCryPak->MakeDir(g_szTestResults);
m_ShaderCacheMissPath = string("@cache@\\Shaders\\ShaderCacheMisses.txt"); // do we want this here, or maybe in @log@ ?
m_ShaderCacheMissPath = string("@usercache@\\Shaders\\ShaderCacheMisses.txt"); // do we want this here, or maybe in @log@ ?
// load data which is already stored
AZ::IO::HandleType fileHandle = AZ::IO::InvalidHandle;
@@ -2175,9 +2175,10 @@ void CShaderMan::mfOptimiseShaders(const char* szFolder, bool bForce)
for (i = 0; i < Names.size(); i++)
{
const char* szName = Names[i].c_str();
if (!strncmp(szName, "@cache@/", 7))
constexpr AZStd::string_view userCache = "@usercache@/";
if (szName == userCache)
{
szName += 7;
szName += userCache.size();
}
pCache = CHWShader::mfInitCache(szName, NULL, false, 0, false);
if (!pCache || !pCache->m_pRes[CACHE_USER])
@@ -1589,7 +1589,7 @@ void CShaderMan::mfInit (void)
#else
m_ShadersCache = CONCAT_PATHS(g_shaderCache, "D3D11");
#endif
m_szCachePath = "@cache@/";
m_szCachePath = "@usercache@/";
if (CRenderer::CV_r_shadersImport == 3)
{
@@ -162,7 +162,7 @@ bool CShaderSerialize::OpenSResource(const char* szName, SSShaderRes* pSR, CSha
stack_string szReadOnly = szName;
// ShaderCacheGen behavior:
// CACHE_READONLY is not really used when exporting the .fxb, so we append the @cache@ alias to the relative shader path
// CACHE_READONLY is not really used when exporting the .fxb, so we append the @usercache@ alias to the relative shader path
// here as well. We cannot just leave this as the relative Shaders/Cache/Foo.fxb value because then it creates a new
// file in the asset cache as @assets@/Shaders/Cache/Foo.fxb, which is illegal (since only AP has the authority to write here)
// Game runtime behavior:
@@ -3490,7 +3490,7 @@ void CHWShader_D3D::mfSaveCGFile(const char* scr, const char* path)
}
else
{
sprintf_s(name, "@cache@/shaders/fxerror/%s(GL%llx)/(LT%x)(RT%llx)/(MD%x)(MDV%x)(PSS%llx)(ST%llx).cg", GetName(), m_pCurInst->m_Ident.m_GLMask, m_pCurInst->m_Ident.m_LightMask, m_pCurInst->m_Ident.m_RTMask, m_pCurInst->m_Ident.m_MDMask, m_pCurInst->m_Ident.m_MDVMask, m_pCurInst->m_Ident.m_pipelineState.opaque, m_pCurInst->m_Ident.m_STMask);
sprintf_s(name, "@usercache@/shaders/fxerror/%s(GL%llx)/(LT%x)(RT%llx)/(MD%x)(MDV%x)(PSS%llx)(ST%llx).cg", GetName(), m_pCurInst->m_Ident.m_GLMask, m_pCurInst->m_Ident.m_LightMask, m_pCurInst->m_Ident.m_RTMask, m_pCurInst->m_Ident.m_MDMask, m_pCurInst->m_Ident.m_MDVMask, m_pCurInst->m_Ident.m_pipelineState.opaque, m_pCurInst->m_Ident.m_STMask);
}
AZ::IO::HandleType fileHandle;
@@ -4672,7 +4672,7 @@ bool CAsyncShaderTask::CompileAsyncShader(SShaderAsyncInfo* pAsync)
CryFixedStringT<1024> hlslPath;
// Create a directory for this shader type, strip the .fxcb extension from the folder name
shaderSourceOutputFolder.Format("@cache@/%s",pAsync->m_pShader->m_pDevCache->m_Name.c_str());
shaderSourceOutputFolder.Format("@usercache@/%s",pAsync->m_pShader->m_pDevCache->m_Name.c_str());
PathUtil::RemoveExtension(shaderSourceOutputFolder);
gEnv->pFileIO->CreatePath(shaderSourceOutputFolder);
@@ -70,6 +70,7 @@
#endif
#include "../Common/RenderCapabilities.h"
#include <AzCore/Utils/Utils.h>
#ifdef WIN32
// Count monitors helper
@@ -1634,8 +1635,8 @@ WIN_HWND CD3D9Renderer::Init([[maybe_unused]] int x, [[maybe_unused]] int y, int
iLog->Log ("Direct3D driver is creating...");
iLog->Log ("Crytek Direct3D driver version %4.2f (%s <%s>)", VERSION_D3D, __DATE__, __TIME__);
const char* sGameName = iConsole->GetCVar("sys_game_name")->GetString();
cry_strcpy(m_WinTitle, sGameName);
auto projectName = AZ::Utils::GetProjectName();
cry_strcpy(m_WinTitle, projectName.c_str());
iLog->Log ("Creating window called '%s' (%dx%d)", m_WinTitle, width, height);