Skip to content

[spirv] Support globals structs of Textures/Samplers - #2994

Merged
Ehsan (ehsannas) merged 7 commits into
microsoft:masterfrom
ehsannas:resources_in_global_structs_rebased
Jun 30, 2020
Merged

Ehsan (ehsannas) merged 7 commits into
microsoft:masterfrom
ehsannas:resources_in_global_structs_rebased

Conversation

@ehsannas

Copy link
Copy Markdown
Contributor

Fixes #2695

@ehsannas Ehsan (ehsannas) added the spirv Work related to SPIR-V label Jun 24, 2020
@ehsannas Ehsan (ehsannas) self-assigned this Jun 24, 2020
@AppVeyorBot

Copy link
Copy Markdown

@jaebaek Jaebaek Seo (jaebaek) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing the issue. It looks mostly good and I have a few questions for minor issues.

Comment thread tools/clang/lib/SPIRV/AstTypeProbe.cpp Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this while statement based on the comment in the line 1225 isResourceType does remove arrayness for the field if needed.?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yes. Done.

Comment thread tools/clang/lib/SPIRV/AstTypeProbe.cpp Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not clearly remember how we handled spirv1.3 or above but I want to doublecheck it will be ok to set it as only Uniform storage class, not StorageBuffer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function (getStorageClassForExternVar) is basically the exact logic taken out of createExternVar here:

SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var) {
auto storageClass = spv::StorageClass::UniformConstant;
auto rule = SpirvLayoutRule::Void;
bool isACRWSBuffer = false; // Whether is {Append|Consume|RW}StructuredBuffer
if (var->getAttr<HLSLGroupSharedAttr>()) {
// For CS groupshared variables
storageClass = spv::StorageClass::Workgroup;
} else if (isResourceType(var)) {
// See through the possible outer arrays
QualType resourceType = var->getType();
while (resourceType->isArrayType()) {
resourceType = resourceType->getAsArrayTypeUnsafe()->getElementType();
}
const llvm::StringRef typeName =
resourceType->getAs<RecordType>()->getDecl()->getName();
// These types are all translated into OpTypeStruct with BufferBlock
// decoration. They should follow standard storage buffer layout,
// which GLSL std430 rules statisfies.
if (typeName == "StructuredBuffer" || typeName == "ByteAddressBuffer" ||
typeName == "RWByteAddressBuffer") {
storageClass = spv::StorageClass::Uniform;
rule = spirvOptions.sBufferLayoutRule;
} else if (typeName == "RWStructuredBuffer" ||
typeName == "AppendStructuredBuffer" ||
typeName == "ConsumeStructuredBuffer") {
storageClass = spv::StorageClass::Uniform;
rule = spirvOptions.sBufferLayoutRule;
isACRWSBuffer = true;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR contains multiple commits. Reading each commit separately might make reviewing it easier. Thanks

@AppVeyorBot

Copy link
Copy Markdown

@ehsannas
Ehsan (ehsannas) force-pushed the resources_in_global_structs_rebased branch from fd4e090 to d82057c Compare June 27, 2020 01:47
@AppVeyorBot

Copy link
Copy Markdown

@ehsannas
Ehsan (ehsannas) force-pushed the resources_in_global_structs_rebased branch from d82057c to 54c562f Compare June 29, 2020 18:48
@ehsannas

Copy link
Copy Markdown
Contributor Author

Rebased against latest master. This should therefore pick up the latest spirv-tools

@AppVeyorBot

Copy link
Copy Markdown

@jaebaek Jaebaek Seo (jaebaek) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked each commit. LGTM. Thanks!

@ehsannas
Ehsan (ehsannas) merged commit d72c5fd into microsoft:master Jun 30, 2020
@ehsannas
Ehsan (ehsannas) deleted the resources_in_global_structs_rebased branch June 30, 2020 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spirv Work related to SPIR-V

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SPIR-V] global struct variables containing only resources get placed in uniform buffer

3 participants