Merge remote-tracking branch 'upstream/main' into Atom/santorac/MaterialTypeCleanup

This commit is contained in:
Chris Santora
2021-05-26 21:39:28 -07:00
383 changed files with 5109 additions and 2147 deletions
@@ -11,6 +11,8 @@
*/
#include <Atom/RPI.Edit/Shader/ShaderSourceData.h>
#include <Atom/RHI.Edit/Utils.h>
#include <Atom/RHI.Edit/ShaderCompilerArguments.h>
#include <AzCore/std/string/regex.h>
#include <AzFramework/StringFunc/StringFunc.h>
@@ -57,7 +59,7 @@ namespace AZ
bool ShaderSourceData::IsRhiBackendDisabled(const AZ::Name& rhiName) const
{
return AZStd::any_of(m_disabledRhiBackends.begin(), m_disabledRhiBackends.end(), [&](const AZStd::string& currentRhiName)
return AZStd::any_of(AZ_BEGIN_END(m_disabledRhiBackends), [&](const AZStd::string& currentRhiName)
{
return currentRhiName == rhiName.GetStringView();
});
@@ -72,19 +74,32 @@ namespace AZ
static void GetListOfMacroDefinitionNames(
const AZStd::string& stringWithArguments, AZStd::vector<AZStd::string>& macroDefinitionNames)
{
static const AZStd::regex macroRegex("-D\\s*(\\w+)", AZStd::regex::ECMAScript);
const AZStd::regex macroRegex(R"(-D\s*(\w+))", AZStd::regex::ECMAScript);
AZStd::cmatch match;
if (AZStd::regex_search(stringWithArguments.c_str(), match, macroRegex))
AZStd::string hayStack(stringWithArguments);
AZStd::smatch match;
while (AZStd::regex_search(hayStack.c_str(), match, macroRegex))
{
// First pattern is always the entire string
for (unsigned i = 1; i < match.size(); ++i)
{
if (match[i].matched)
{
macroDefinitionNames.push_back(match[i].str().c_str());
AZStd::string macroToAdd(match[i].str().c_str());
const bool isPresent = AZStd::any_of(AZ_BEGIN_END(macroDefinitionNames),
[&](AZStd::string_view macroName) -> bool
{
return macroToAdd == macroName;
}
);
if (isPresent)
{
continue;
}
macroDefinitionNames.push_back(macroToAdd);
}
}
hayStack = match.suffix();
}
}
@@ -103,19 +118,22 @@ namespace AZ
static void GetListOfMacroDefinitions(
const AZStd::string& stringWithArguments, AZStd::vector<AZStd::string>& macroDefinitions)
{
static const AZStd::regex macroRegex("-D\\s*(\\w+(=\\w+)?)", AZStd::regex::ECMAScript);
const AZStd::regex macroRegex(R"(-D\s*(\w+)(=\w+)?)", AZStd::regex::ECMAScript);
AZStd::cmatch match;
if (AZStd::regex_search(stringWithArguments.c_str(), match, macroRegex))
AZStd::string hayStack(stringWithArguments);
AZStd::smatch match;
while (AZStd::regex_search(hayStack.c_str(), match, macroRegex))
{
// First pattern is always the entire string
for (unsigned i = 1; i < match.size(); ++i)
if (match.size() > 1)
{
if (match[i].matched)
AZStd::string macro(match[1].str().c_str());
if (match.size() > 2)
{
macroDefinitions.push_back(match[i].str().c_str());
macro += match[2].str().c_str();
}
macroDefinitions.push_back(macro);
}
hayStack = match.suffix();
}
}
@@ -126,62 +144,27 @@ namespace AZ
return parsedMacroDefinitions;
}
// Helper.
// @arguments: A string with command line arguments for a console application of the form:
// "-<arg1> --<arg2> --<arg3>[=<value3>] ..."
// Example: "--use-spaces --namespace=vk"
// Returns: A list with just the [-|--]<argument name>:
// ["-<arg1>", "--<arg2>", "--arg3"]
// For the example shown above it will return this vector:
// ["--use-spaces", "--namespace"]
AZStd::vector<AZStd::string> GetListOfArgumentNames(const AZStd::string& arguments)
{
AZStd::vector<AZStd::string> listOfTokens;
AzFramework::StringFunc::Tokenize(arguments, listOfTokens);
AZStd::vector<AZStd::string> listOfArguments;
for (const AZStd::string& token : listOfTokens)
{
AZStd::vector<AZStd::string> splitArguments;
AzFramework::StringFunc::Tokenize(token, splitArguments, "=");
listOfArguments.push_back(splitArguments[0]);
}
return listOfArguments;
}
AZStd::string ShaderSourceData::SupervariantInfo::GetCustomizedArgumentsForAzslc(
const AZStd::string& initialAzslcCompilerArguments) const
{
static const AZStd::regex macroRegex("-D\\s*(\\w+(=\\S+)?)", AZStd::regex::ECMAScript);
const AZStd::regex macroRegex(R"(-D\s*(\w+(=\S+)?))", AZStd::regex::ECMAScript);
// We are only concerned with AZSLc arguments. Let's remove the C-Preprocessor macro definitions
// from @minusArguments.
const AZStd::string minusArguments = AZStd::regex_replace(m_minusArguments, macroRegex, "");
const AZStd::string plusArguments = AZStd::regex_replace(m_plusArguments, macroRegex, "");
AZStd::string azslcArgumentsToRemove = minusArguments + " " + plusArguments;
AZStd::vector<AZStd::string> azslcArgumentNamesToRemove = GetListOfArgumentNames(azslcArgumentsToRemove);
AZStd::vector<AZStd::string> azslcArgumentNamesToRemove = RHI::CommandLineArgumentUtils::GetListOfArgumentNames(azslcArgumentsToRemove);
// At this moment @azslcArgumentsToRemove contains arguments for AZSLc that can be of the form:
// -<arg>
// --<arg>[=<value>]
// We need to remove those from @initialAzslcCompilerArguments.
AZStd::string customizedArguments = initialAzslcCompilerArguments;
for (const AZStd::string& azslcArgumentName : azslcArgumentNamesToRemove)
{
AZStd::string regexStr = AZStd::string::format("%s(=\\S+)?", azslcArgumentName.c_str());
AZStd::regex replaceRegex(regexStr, AZStd::regex::ECMAScript);
customizedArguments = AZStd::regex_replace(customizedArguments, replaceRegex, "");
}
AZStd::string customizedArguments = RHI::CommandLineArgumentUtils::RemoveArgumentsFromCommandLineString(
azslcArgumentNamesToRemove, initialAzslcCompilerArguments);
customizedArguments += " " + plusArguments;
// Will contain the results that will be joined by a space.
// This is used to get a clean string to return without excess spaces.
AZStd::vector<AZStd::string> argumentList;
AzFramework::StringFunc::Tokenize(customizedArguments, argumentList, " \t\n");
customizedArguments.clear(); // Need to clear because Join appends.
AzFramework::StringFunc::Join(customizedArguments, argumentList.begin(), argumentList.end(), " ");
return customizedArguments;
return RHI::CommandLineArgumentUtils::RemoveExtraSpaces(customizedArguments);
}
@@ -211,6 +211,42 @@ namespace AZ
m_rhiPipelineState = m_pipelineState->GetRHIPipelineState();
}
void DynamicDrawContext::SetScene(Scene* scene)
{
AZ_Assert(scene, "SetScene called with an invalid scene");
if (!scene || m_scene == scene)
{
return;
}
m_scene = scene;
m_drawFilter = RHI::DrawFilterMaskDefaultValue;
// Reinitialize if it was initialized
if (m_initialized)
{
// Report warning if there were some draw data
AZ_Warning(
"DynamicDrawContext", m_cachedDrawItems.size() == 0,
"DynamicDrawContext::SetForScene should be called"
" when there is no cached draw data");
// Clear some cached data
FrameEnd();
m_cachedRhiPipelineStates.clear();
// Reinitialize
EndInit();
}
}
void DynamicDrawContext::SetRenderPipeline(RenderPipeline* pipeline)
{
AZ_Assert(pipeline, "SetRenderPipeline called with an invalid pipeline");
if (!pipeline)
{
return;
}
SetScene(pipeline->GetScene());
m_drawFilter = pipeline->GetDrawFilterMask();
}
bool DynamicDrawContext::IsReady()
{
return m_initialized;
@@ -51,6 +51,8 @@ namespace AZ
ViewportContext::~ViewportContext()
{
m_aboutToBeDestroyedEvent.Signal(m_id);
AzFramework::WindowNotificationBus::Handler::BusDisconnect();
AzFramework::ViewportRequestBus::Handler::BusDisconnect();
@@ -171,6 +173,21 @@ namespace AZ
handler.Connect(m_sceneChangedEvent);
}
void ViewportContext::ConnectCurrentPipelineChangedHandler(PipelineChangedEvent::Handler& handler)
{
handler.Connect(m_currentPipelineChangedEvent);
}
void ViewportContext::ConnectDefaultViewChangedHandler(ViewChangedEvent::Handler& handler)
{
handler.Connect(m_defaultViewChangedEvent);
}
void ViewportContext::ConnectAboutToBeDestroyedHandler(ViewportIdEvent::Handler& handler)
{
handler.Connect(m_aboutToBeDestroyedEvent);
}
const AZ::Matrix4x4& ViewportContext::GetCameraViewMatrix() const
{
return GetDefaultView()->GetWorldToViewMatrix();
@@ -214,6 +231,7 @@ namespace AZ
m_defaultView = view;
UpdatePipelineView();
m_defaultViewChangedEvent.Signal(view);
m_viewMatrixChangedEvent.Signal(view->GetWorldToViewMatrix());
m_projectionMatrixChangedEvent.Signal(view->GetViewToClipMatrix());
@@ -232,6 +250,7 @@ namespace AZ
if (!m_currentPipeline)
{
m_currentPipeline = m_rootScene ? m_rootScene->FindRenderPipelineForWindow(m_windowContext->GetWindowHandle()) : nullptr;
m_currentPipelineChangedEvent.Signal(m_currentPipeline);
}
if (auto pipeline = GetCurrentPipeline())