Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to hlsl6 6 #61

Merged
merged 42 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fd8b9d2
wip: class inheritance support. 1st broad source inspection pass.
siliconvoodoo Aug 26, 2022
cdbb81c
WIP: core of the change. activate deep lookup (resolve inherited name…
siliconvoodoo Aug 30, 2022
efc6a5b
add miscelaneous utilities
siliconvoodoo Aug 30, 2022
2999ecd
Evolution of the lookup function to fixup seenats refering to inherit…
siliconvoodoo Aug 30, 2022
a588a26
Prepare some test cases to verify inheritance access understanding.
siliconvoodoo Aug 30, 2022
f85216b
Fixup of forgotten function-parameter-semantic when that parameter is…
siliconvoodoo Aug 31, 2022
20f24f3
fixup of symbol dependency ordering: UDT internal variables that got …
siliconvoodoo Aug 31, 2022
5a4478a
introduce class inheritance seenat advanced test
siliconvoodoo Aug 31, 2022
ad32008
add one OK test for the empty diamond case
siliconvoodoo Aug 31, 2022
4fddc15
Add an error case test to make sure the multi concrete base inheritan…
siliconvoodoo Sep 6, 2022
c632412
Updated copyright comment in export keyword script
siliconvoodoo Sep 12, 2022
5a927ba
Little refresh of RegisterVar to comment on the MeshIndex MeshIndex; …
siliconvoodoo Sep 12, 2022
8f045d1
That was an unfortunate bug dating back from May 2020 preventing qual…
siliconvoodoo Sep 13, 2022
0b8a9d2
fixup grun launch
siliconvoodoo Sep 13, 2022
5344d48
option with no range: improve message so that users have an immediate…
siliconvoodoo Sep 13, 2022
b4a2711
DRY
siliconvoodoo Sep 13, 2022
911670a
version up, and --ast must work in case of semantic troubles.
siliconvoodoo Sep 13, 2022
dffb0e1
fixup error message are off by one line
siliconvoodoo Sep 13, 2022
a69c1f5
add keywords:
siliconvoodoo Sep 13, 2022
de7146c
Fixup false positive error about many qualifiers on function return t…
siliconvoodoo Sep 13, 2022
e28a737
Added 16 bits scalars.
siliconvoodoo Sep 13, 2022
7ca1dce
mesh shader test from microsoft sample under MIT license.
siliconvoodoo Sep 13, 2022
b3518ad
Refactored system for line fixup of error reporting and line directiv…
siliconvoodoo Sep 14, 2022
1d0ae53
Not convinced about this Streamable solution, because of all the code…
siliconvoodoo Sep 15, 2022
ddebdcb
fixup regression about null character happening because of numeric ty…
siliconvoodoo Sep 16, 2022
3f683fa
fix test fail false negative, because of compatibility regression int…
siliconvoodoo Sep 16, 2022
29e6a68
modify the parser so that the AST doesnt make a difference between a …
siliconvoodoo Sep 16, 2022
182e42f
improve the emission test python to further split tokens
siliconvoodoo Sep 16, 2022
f0817fa
antlr regeneration
siliconvoodoo Sep 16, 2022
4d9b902
fixup some emission tests. still 5 failing. notably padding detection.
siliconvoodoo Sep 16, 2022
a243a88
fixup of all emission tests.
siliconvoodoo Sep 19, 2022
5f3a4c4
WIP, refactoring of type qualifiers.
siliconvoodoo Sep 19, 2022
e784515
Shuffling trick that allows to lower the red tests count from 14 to 3…
siliconvoodoo Sep 19, 2022
d2d3b12
fixup texture2DMS to texture2D mutator because of inclusion of unwant…
siliconvoodoo Sep 20, 2022
78e0c38
Fix curious self merge conflicts?
siliconvoodoo Sep 20, 2022
009f1af
fixup last merge problems (hopefully)
siliconvoodoo Sep 20, 2022
be834a5
Canonicalize qualifers emission to be done directly from within the t…
siliconvoodoo Sep 20, 2022
36cc9ae
address comments from pull request review PR #61
siliconvoodoo Oct 5, 2022
90b6c75
turns out, unordered_set has non-deterministic impact on emission pat…
siliconvoodoo Oct 5, 2022
1533362
change to lift the strict constraint imposed by the presence of commo…
siliconvoodoo Oct 5, 2022
b1d6567
regeneration of antlr
siliconvoodoo Oct 5, 2022
6318b08
fixup test issue emerging from change of dumpsym format regarding typ…
siliconvoodoo Oct 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Platform/Windows/src/DirectX12PlatformEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ namespace AZ::ShaderCompiler
const auto& samplerInfo = *memberInfo->m_samplerState;
if (!samplerInfo.m_isDynamic)
{
rootParam << " \"StaticSampler(s" << std::to_string(param.m_registerBinding.m_pair[querySet].m_registerIndex)
<< ", space = " << std::to_string(param.m_registerBinding.m_pair[querySet].m_logicalSpace)
<< ", visibility=SHADER_VISIBILITY_ALL"
<< samplerInfo << ")";
Streamable&& s{MakeOStreamStreamable{rootParam}};
s << " \"StaticSampler(s" << std::to_string(param.m_registerBinding.m_pair[querySet].m_registerIndex)
<< ", space = " << std::to_string(param.m_registerBinding.m_pair[querySet].m_logicalSpace)
<< ", visibility=SHADER_VISIBILITY_ALL"
<< samplerInfo << ")";
rootAttrList.push_back(rootParam.str());
}
}
Expand Down
3 changes: 2 additions & 1 deletion Platform/Windows/src/VulkanPlatformEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ namespace AZ::ShaderCompiler
stream << "#ifdef AZ_USE_SUBPASSINPUT\n";
inputAttachmentIndexAttribute->m_namespace = "vk";
inputAttachmentIndexAttribute->m_category = AttributeCategory::Sequence;
CodeEmitter::EmitAttribute(*inputAttachmentIndexAttribute, stream);
MakeOStreamStreamable soss(stream);
CodeEmitter::EmitAttribute(*inputAttachmentIndexAttribute, soss);
stream << "[[vk::binding(" << bindInfoRegisterIndex;
if (stringifiedLogicalSpace)
{
Expand Down
5 changes: 3 additions & 2 deletions launch_grun.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ if "%~1" == "" (
pushd

cd "%~dp0\src\generated\java"
set antlr4=java org.antlr.v4.Tool
set grun=java org.antlr.v4.gui.TestRig

SET CLASSPATH=.;"..\..\external\antlr-4.9.3-complete.jar";%CLASSPATH%
set grun=java -cp %CLASSPATH% org.antlr.v4.gui.TestRig
%grun% azsl compilationUnit -gui "%thepath%"

popd
Expand Down
79 changes: 62 additions & 17 deletions src/AzslcBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace AZ::ShaderCompiler
// Define emission for sampler states
// Reference: https://github.com/Microsoft/DirectXShaderCompiler/blob/master/tools/clang/unittests/HLSL/FunctionTest.cpp

std::ostream &operator << (std::ostream &out, const SamplerStateDesc::AddressMode& addressMode)
Streamable& operator << (Streamable& out, const SamplerStateDesc::AddressMode& addressMode)
{
return out << ((addressMode == SamplerStateDesc::AddressMode::Wrap) ? "TEXTURE_ADDRESS_WRAP"
: (addressMode == SamplerStateDesc::AddressMode::Clamp) ? "TEXTURE_ADDRESS_CLAMP"
Expand All @@ -78,7 +78,7 @@ namespace AZ::ShaderCompiler
: "TEXTURE_ADDRESS_MIRROR_ONCE");
}

std::ostream &operator << (std::ostream &out, const SamplerStateDesc::ComparisonFunc& compFunc)
Streamable& operator << (Streamable& out, const SamplerStateDesc::ComparisonFunc& compFunc)
{
return out << ((compFunc == SamplerStateDesc::ComparisonFunc::Never) ? "COMPARISON_NEVER"
: (compFunc == SamplerStateDesc::ComparisonFunc::Less) ? "COMPARISON_LESS"
Expand All @@ -90,14 +90,14 @@ namespace AZ::ShaderCompiler
: "COMPARISON_ALWAYS");
}

std::ostream &operator << (std::ostream &out, const SamplerStateDesc::BorderColor& borderColor)
Streamable& operator << (Streamable& out, const SamplerStateDesc::BorderColor& borderColor)
{
return out << ((borderColor == SamplerStateDesc::BorderColor::OpaqueBlack) ? "STATIC_BORDER_COLOR_OPAQUE_BLACK"
: (borderColor == SamplerStateDesc::BorderColor::OpaqueWhite) ? "STATIC_BORDER_COLOR_OPAQUE_WHITE"
: "STATIC_BORDER_COLOR_TRANSPARENT_BLACK");
}

std::ostream &operator << (std::ostream &out, const SamplerStateDesc& samplerDesc)
Streamable& operator << (Streamable& out, const SamplerStateDesc& samplerDesc)
{
// Resolving the filter is the hardest part of the emission
out << ", filter = FILTER_";
Expand Down Expand Up @@ -241,7 +241,7 @@ namespace AZ::ShaderCompiler
return pair;
}

std::ostream &operator << (std::ostream &out, const SamplerStateDesc::ReductionType& redcType)
Streamable& operator << (Streamable& out, const SamplerStateDesc::ReductionType& redcType)
{
return out << ((redcType == SamplerStateDesc::ReductionType::Comparison) ? "Comparison"
: (redcType == SamplerStateDesc::ReductionType::Filter) ? "Filter"
Expand Down Expand Up @@ -280,7 +280,7 @@ namespace AZ::ShaderCompiler
return token;
}

void Backend::GetTextInStream(misc::Interval interval, std::ostream& output) const
void Backend::EmitTranspiledTokens(misc::Interval interval, Streamable& output) const
{
ssize_t ii = interval.a;
while (ii <= interval.b)
Expand All @@ -291,12 +291,13 @@ namespace AZ::ShaderCompiler
}
}

string Backend::GetTextAsString(misc::Interval interval) const
string Backend::GetTranspiledTokens(misc::Interval interval) const
{
static std::stringstream ss;
ss.str({});
ss.clear();
GetTextInStream(interval, ss);
MakeOStreamStreamable soss(ss);
EmitTranspiledTokens(interval, soss);
return ss.str();
}

Expand All @@ -310,7 +311,7 @@ namespace AZ::ShaderCompiler
}

auto* initClause = varInfo->m_declNode->variableInitializer()->standardVariableInitializer();
return RemoveWhitespaces(GetTextAsString(initClause->getSourceInterval()));
return RemoveWhitespaces(GetTranspiledTokens(initClause->getSourceInterval()));
}

void Backend::AppendOptionRange(Json::Value& varOption, const IdentifierUID& varUid, const VarInfo* varInfo, const Options& options) const
Expand Down Expand Up @@ -355,7 +356,7 @@ namespace AZ::ShaderCompiler
if (!rangeAttribute)
{
throw AzslcEmitterException(EMITTER_INTEGER_HAS_NO_RANGE,
none, none, ConcatString("Option (", varUid.m_name, ") must specify a range with a minimum and maximum values"));
none, none, ConcatString("Option (", varUid.m_name, ") must decorate declaration with an attribute [range(minimum value, maximum value)]"));
}

if (rangeAttribute->m_argList.size() != 2)
Expand Down Expand Up @@ -693,7 +694,8 @@ namespace AZ::ShaderCompiler
return rootSig;
}

const char* Backend::GetInputModifier(TypeQualifier typeQualifier)
//static
const char* Backend::GetInputModifier(const TypeQualifiers& typeQualifier)
{
const bool in = TypeHasStorageFlag(typeQualifier, StorageFlag::In);
const bool out = TypeHasStorageFlag(typeQualifier, StorageFlag::Out);
Expand All @@ -703,17 +705,60 @@ namespace AZ::ShaderCompiler
: (out ? "out" : ""));
}

string Backend::GetExtendedTypeInfo(const ExtendedTypeInfo& extTypeInfo, std::function<string(const TypeRefInfo&)> translator) const
// static
string Backend::GetTypeModifier(const ExtendedTypeInfo& typeInfo, const Options& options, Modifiers bannedFlags /*= {}*/)
{
string hlslString = "";
using namespace std::string_literals;
string modifiers;
bool isMatrix = typeInfo.m_coreType.m_arithmeticInfo.IsMatrix();
if (typeInfo.CheckHasStorageFlag(StorageFlag::ColumnMajor) && !(bannedFlags & StorageFlag::ColumnMajor))
{
modifiers = "column_major";
}
else if (typeInfo.CheckHasStorageFlag(StorageFlag::RowMajor) && !(bannedFlags & StorageFlag::RowMajor))
{
modifiers = "row_major";
}
else if (options.m_forceEmitMajor && isMatrix)
siliconvoodoo marked this conversation as resolved.
Show resolved Hide resolved
{
modifiers = options.m_forceMatrixRowMajor ? "row_major" : "column_major";
}

auto maybeSpace = [&modifiers](){ return modifiers.empty() ? "" : " "; };
using SF = StorageFlag;
static const StorageFlag toReEmit[] = {SF::Static, SF::Extern, SF::Inline,
SF::Const, SF::Volatile, SF::Precise, SF::Groupshared,
SF::Uniform, SF::Globallycoherent, SF::Unsigned};
for (int i = 0; i < std::size(toReEmit); ++i)
{
if (typeInfo.CheckHasStorageFlag(toReEmit[i]) && !(bannedFlags & toReEmit[i]))
{
modifiers += maybeSpace() + ToLower(StorageFlag::ToStr(toReEmit[i]));
}
}

if (typeInfo.CheckHasStorageFlag(StorageFlag::Other) && !(bannedFlags & StorageFlag::Other))
{
for (const auto& flag : typeInfo.m_qualifiers.m_others)
{
modifiers += " " + flag;
}
}

return modifiers;
}

string Backend::GetExtendedTypeInfo(const ExtendedTypeInfo& extTypeInfo, const Options& options, Modifiers banned, std::function<string(const TypeRefInfo&)> translator) const
{
string hlslString = GetTypeModifier(extTypeInfo, options, banned);
hlslString += hlslString.empty() ? "" : " ";
if (extTypeInfo.m_coreType.m_typeClass == TypeClass::Alias)
{
hlslString = GetExtendedTypeInfo(m_ir->GetSymbolSubAs<TypeAliasInfo>(extTypeInfo.m_coreType.m_typeId.GetName())->m_canonicalType, translator);
hlslString += GetExtendedTypeInfo(m_ir->GetSymbolSubAs<TypeAliasInfo>(extTypeInfo.m_coreType.m_typeId.GetName())->m_canonicalType, options, banned, translator);
}
else if (HasGenericParameter(extTypeInfo.m_coreType.m_typeClass) || !extTypeInfo.m_genericParameter.IsEmpty())
{
hlslString = translator(extTypeInfo.m_coreType)
hlslString += translator(extTypeInfo.m_coreType)
+ "<" + translator(extTypeInfo.m_genericParameter);
if (extTypeInfo.m_genericDims.IsArray())
{
Expand All @@ -723,7 +768,7 @@ namespace AZ::ShaderCompiler
}
else
{
hlslString = translator(extTypeInfo.m_coreType);
hlslString += translator(extTypeInfo.m_coreType);
}

return hlslString;
Expand Down Expand Up @@ -751,7 +796,7 @@ namespace AZ::ShaderCompiler
}

// GetTotalSize of each member of the structure
uint32_t size = varInfo.m_typeInfoExt.GetTotalSize(options.m_packDataBuffers, options.m_emitRowMajor);
uint32_t size = varInfo.m_typeInfoExt.GetTotalSize(options.m_packDataBuffers, options.m_forceMatrixRowMajor);

numberOf32bitRootConstants += (size / 4);
}
Expand Down
42 changes: 23 additions & 19 deletions src/AzslcBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include "AzslcListener.h"
#include "NewLineCounterStream.h"

#include "jsoncpp/dist/json/json.h"

Expand All @@ -30,7 +31,7 @@ namespace AZ::ShaderCompiler
bool m_useUniqueIndices = false;
bool m_emitConstantBufferBody = false;
bool m_emitRootSig = false;
bool m_emitRowMajor = false; //!< False by default (HLSL standard)
bool m_forceMatrixRowMajor = false; //!< False by default (HLSL standard)
bool m_forceEmitMajor = false; //!< True if either -Zpc or -Zpr was specified
bool m_padRootConstantCB = false; //!< If True, the emitted root constant CB will padded to 16-byte boundary.
bool m_skipAlignmentValidation = false; //! < If True, disables validation of a known DXC issue when certain word or 2-words size variables are preceded by some MatrixRxC variables.
Expand Down Expand Up @@ -132,25 +133,33 @@ namespace AZ::ShaderCompiler
class Backend
{
public:
Backend(IntermediateRepresentation* ir, TokenStream* tokens, std::ostream& out)
: m_ir(ir), m_tokens(tokens), m_out(out)
Backend(IntermediateRepresentation* ir, TokenStream* tokens)
: m_ir(ir), m_tokens(tokens)
{}

//! Gets the IntermediateRepresentation object
const IntermediateRepresentation* GetIR() const { return m_ir; }

//! Make a string that lists all type qualifiers/modifiers in HLSL format
static string GetTypeModifier(const ExtendedTypeInfo&, const Options& options, Modifiers bannedFlags = {});

//! Get HLSL form of in/out modifiers
static const char* GetInputModifier(const TypeQualifiers& typeQualifier);

//! Fabricate a HLSL snippet that represents the type stored in typeInfo. Relevant options relate to matrix qualifiers.
//! \param banned is the Flag you can setup to list a collection of type qualifiers you don't want to reproduce.
string GetExtendedTypeInfo(const ExtendedTypeInfo& extTypeInfo, const Options& options, Modifiers banned, std::function<string(const TypeRefInfo&)> translator) const;

protected:
//! Obtains a supplement emitter which provides per-platform emission functionality.
const PlatformEmitter& GetPlatformEmitter() const;

//! Gets the next and increments tokenIndex. TokenIndex must be in the [misc::Interval.a, misc::Interval.b] range. Token cannot be nullptr.
auto GetNextToken(ssize_t& tokenIndex, size_t channel = Token::DEFAULT_CHANNEL) const -> antlr4::Token*;

//! Extract an interval of text out of the source token stream, and append it to @output
virtual void GetTextInStream(misc::Interval interval, std::ostream& output) const;
virtual void EmitTranspiledTokens(misc::Interval interval, Streamable& output) const;

//! Extract an interval of text out of the source token stream
string GetTextAsString(misc::Interval interval) const;
string GetTranspiledTokens(misc::Interval interval) const;

string GetInitializerClause(const AZ::ShaderCompiler::VarInfo* varInfo) const;

Expand All @@ -166,13 +175,8 @@ namespace AZ::ShaderCompiler

Json::Value GetVariantList(const Options& options, bool includeEmpty = false) const;

static const char* GetInputModifier(TypeQualifier typeQualifier);

string GetExtendedTypeInfo(const ExtendedTypeInfo& extTypeInfo, std::function<string(const TypeRefInfo&)> translator) const;

std::ostream& m_out;
IntermediateRepresentation* m_ir;
TokenStream* m_tokens;
IntermediateRepresentation* m_ir;
TokenStream* m_tokens;
};

// independent utility functions
Expand All @@ -196,9 +200,9 @@ namespace AZ::ShaderCompiler
// don't use for HLSL emission (this doesn't go through translation)
string UnmangleTrimedName(const ExtendedTypeInfo& extTypeInfo);

std::ostream &operator << (std::ostream &out, const SamplerStateDesc::AddressMode& addressMode);
std::ostream &operator << (std::ostream &out, const SamplerStateDesc::ComparisonFunc& compFunc);
std::ostream &operator << (std::ostream &out, const SamplerStateDesc::BorderColor& borderColor);
std::ostream &operator << (std::ostream &out, const SamplerStateDesc& samplerDesc);
std::ostream &operator << (std::ostream &out, const SamplerStateDesc::ReductionType& redcType);
Streamable& operator << (Streamable& out, const SamplerStateDesc::AddressMode& addressMode);
Streamable& operator << (Streamable& out, const SamplerStateDesc::ComparisonFunc& compFunc);
Streamable& operator << (Streamable& out, const SamplerStateDesc::BorderColor& borderColor);
Streamable& operator << (Streamable& out, const SamplerStateDesc& samplerDesc);
Streamable& operator << (Streamable& out, const SamplerStateDesc::ReductionType& redcType);
}
Loading