Spirv_intrinsics: Add support of type specifier to spirv_type
Previously, spirv_type doesn't accept type specifier as its parameter. With this change, we can input non-array type specifier. This is because some SPIR-V type definition intructions often need to reference other SPIR-V types as its source operands. We add the support to facilitate such usage.
This commit is contained in:
parent
eaa7057768
commit
051f18c0cc
@ -4515,6 +4515,7 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
|
|||||||
|
|
||||||
std::vector<spv::IdImmediate> operands;
|
std::vector<spv::IdImmediate> operands;
|
||||||
for (const auto& typeParam : spirvType.typeParams) {
|
for (const auto& typeParam : spirvType.typeParams) {
|
||||||
|
if (typeParam.constant != nullptr) {
|
||||||
// Constant expression
|
// Constant expression
|
||||||
if (typeParam.constant->isLiteral()) {
|
if (typeParam.constant->isLiteral()) {
|
||||||
if (typeParam.constant->getBasicType() == glslang::EbtFloat) {
|
if (typeParam.constant->getBasicType() == glslang::EbtFloat) {
|
||||||
@ -4559,6 +4560,11 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
|
|||||||
assert(0); // Unexpected type
|
assert(0); // Unexpected type
|
||||||
} else
|
} else
|
||||||
operands.push_back({true, createSpvConstant(*typeParam.constant)});
|
operands.push_back({true, createSpvConstant(*typeParam.constant)});
|
||||||
|
} else {
|
||||||
|
// Type specifier
|
||||||
|
assert(typeParam.type != nullptr);
|
||||||
|
operands.push_back({true, convertGlslangToSpvType(*typeParam.type)});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(spirvInst.set == ""); // Currently, couldn't be extended instructions.
|
assert(spirvInst.set == ""); // Currently, couldn't be extended instructions.
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
spv.intrinsicsSpirvTypeWithTypeSpecifier.vert
|
||||||
|
// Module Version 10000
|
||||||
|
// Generated by (magic number): 8000b
|
||||||
|
// Id's are bound by 14
|
||||||
|
|
||||||
|
Capability Shader
|
||||||
|
Capability Int64
|
||||||
|
Capability PhysicalStorageBufferAddressesEXT
|
||||||
|
Extension "SPV_EXT_physical_storage_buffer"
|
||||||
|
Extension "SPV_KHR_physical_storage_buffer"
|
||||||
|
Extension "SPV_KHR_variable_pointers"
|
||||||
|
1: ExtInstImport "GLSL.std.450"
|
||||||
|
MemoryModel PhysicalStorageBuffer64EXT GLSL450
|
||||||
|
EntryPoint Vertex 4 "main"
|
||||||
|
Source GLSL 450
|
||||||
|
SourceExtension "GL_ARB_gpu_shader_int64"
|
||||||
|
SourceExtension "GL_EXT_buffer_reference"
|
||||||
|
SourceExtension "GL_EXT_spirv_intrinsics"
|
||||||
|
Name 4 "main"
|
||||||
|
Name 8 "value"
|
||||||
|
2: TypeVoid
|
||||||
|
3: TypeFunction 2
|
||||||
|
6: TypeInt 32 0
|
||||||
|
7: TypePointer Function 6(int)
|
||||||
|
9: TypeInt 64 0
|
||||||
|
10: 9(int64_t) Constant 1 0
|
||||||
|
11: TypePointer PhysicalStorageBufferEXT 6(int)
|
||||||
|
4(main): 2 Function None 3
|
||||||
|
5: Label
|
||||||
|
8(value): 7(ptr) Variable Function
|
||||||
|
12: 11(ptr) ConvertUToPtr 10
|
||||||
|
13: 6(int) Load 12 Aligned 32
|
||||||
|
Store 8(value) 13
|
||||||
|
Return
|
||||||
|
FunctionEnd
|
25
Test/spv.intrinsicsSpirvTypeWithTypeSpecifier.vert
Normal file
25
Test/spv.intrinsicsSpirvTypeWithTypeSpecifier.vert
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#version 450 core
|
||||||
|
|
||||||
|
#extension GL_ARB_gpu_shader_int64: enable
|
||||||
|
#extension GL_EXT_buffer_reference: enable
|
||||||
|
#extension GL_EXT_spirv_intrinsics: enable
|
||||||
|
|
||||||
|
#define CapabilityPhysicalStorageBufferAddresses 5347
|
||||||
|
#define StorageClassPhysicalStorageBuffer 5349
|
||||||
|
#define OpTypePointer 32
|
||||||
|
#define OpLoad 61
|
||||||
|
#define OpConvertUToPtr 120
|
||||||
|
|
||||||
|
#define uintStoragePtr spirv_type(extensions = ["SPV_EXT_physical_storage_buffer", "SPV_KHR_variable_pointers"], capabilities = [CapabilityPhysicalStorageBufferAddresses], id = OpTypePointer, StorageClassPhysicalStorageBuffer, uint)
|
||||||
|
|
||||||
|
// Just to enable the memory model of physical storage buffer
|
||||||
|
layout(buffer_reference, std430) buffer Dummy {
|
||||||
|
uint dummy;
|
||||||
|
};
|
||||||
|
|
||||||
|
spirv_instruction(id = OpLoad) uint loadUint(uintStoragePtr pointer, spirv_literal uint memoryOperands, spirv_literal uint alignment);
|
||||||
|
spirv_instruction(id = OpConvertUToPtr) uintStoragePtr convertToPtr(uint64_t value);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
uint value = loadUint(convertToPtr(1), 0x2, 32);
|
||||||
|
}
|
@ -98,12 +98,23 @@ struct TSpirvInstruction {
|
|||||||
struct TSpirvTypeParameter {
|
struct TSpirvTypeParameter {
|
||||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||||
|
|
||||||
TSpirvTypeParameter(const TIntermConstantUnion* arg) { constant = arg; }
|
TSpirvTypeParameter(const TIntermConstantUnion* arg)
|
||||||
|
{
|
||||||
|
constant = arg;
|
||||||
|
type = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const TSpirvTypeParameter& rhs) const { return constant == rhs.constant; }
|
TSpirvTypeParameter(const TType *arg)
|
||||||
|
{
|
||||||
|
constant = nullptr;
|
||||||
|
type = arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const TSpirvTypeParameter& rhs) const;
|
||||||
bool operator!=(const TSpirvTypeParameter& rhs) const { return !operator==(rhs); }
|
bool operator!=(const TSpirvTypeParameter& rhs) const { return !operator==(rhs); }
|
||||||
|
|
||||||
const TIntermConstantUnion* constant;
|
const TIntermConstantUnion* constant; // Constant expression
|
||||||
|
const TType* type; // Type specifier
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef TVector<TSpirvTypeParameter> TSpirvTypeParameters;
|
typedef TVector<TSpirvTypeParameter> TSpirvTypeParameters;
|
||||||
|
@ -486,6 +486,7 @@ public:
|
|||||||
TSpirvRequirement* mergeSpirvRequirements(const TSourceLoc& loc, TSpirvRequirement* spirvReq1,
|
TSpirvRequirement* mergeSpirvRequirements(const TSourceLoc& loc, TSpirvRequirement* spirvReq1,
|
||||||
TSpirvRequirement* spirvReq2);
|
TSpirvRequirement* spirvReq2);
|
||||||
TSpirvTypeParameters* makeSpirvTypeParameters(const TSourceLoc& loc, const TIntermConstantUnion* constant);
|
TSpirvTypeParameters* makeSpirvTypeParameters(const TSourceLoc& loc, const TIntermConstantUnion* constant);
|
||||||
|
TSpirvTypeParameters* makeSpirvTypeParameters(const TSourceLoc& loc, const TPublicType& type);
|
||||||
TSpirvTypeParameters* mergeSpirvTypeParameters(TSpirvTypeParameters* spirvTypeParams1,
|
TSpirvTypeParameters* mergeSpirvTypeParameters(TSpirvTypeParameters* spirvTypeParams1,
|
||||||
TSpirvTypeParameters* spirvTypeParams2);
|
TSpirvTypeParameters* spirvTypeParams2);
|
||||||
TSpirvInstruction* makeSpirvInstruction(const TSourceLoc& loc, const TString& name, const TString& value);
|
TSpirvInstruction* makeSpirvInstruction(const TSourceLoc& loc, const TString& name, const TString& value);
|
||||||
|
@ -45,6 +45,15 @@
|
|||||||
|
|
||||||
namespace glslang {
|
namespace glslang {
|
||||||
|
|
||||||
|
bool TSpirvTypeParameter::operator==(const TSpirvTypeParameter& rhs) const
|
||||||
|
{
|
||||||
|
if (constant != nullptr)
|
||||||
|
return constant->getConstArray() == rhs.constant->getConstArray();
|
||||||
|
|
||||||
|
assert(type != nullptr);
|
||||||
|
return *type == *rhs.type;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Handle SPIR-V requirements
|
// Handle SPIR-V requirements
|
||||||
//
|
//
|
||||||
@ -283,11 +292,16 @@ TSpirvTypeParameters* TParseContext::makeSpirvTypeParameters(const TSourceLoc& l
|
|||||||
constant->getBasicType() != EbtBool &&
|
constant->getBasicType() != EbtBool &&
|
||||||
constant->getBasicType() != EbtString)
|
constant->getBasicType() != EbtString)
|
||||||
error(loc, "this type not allowed", constant->getType().getBasicString(), "");
|
error(loc, "this type not allowed", constant->getType().getBasicString(), "");
|
||||||
else {
|
else
|
||||||
assert(constant);
|
|
||||||
spirvTypeParams->push_back(TSpirvTypeParameter(constant));
|
spirvTypeParams->push_back(TSpirvTypeParameter(constant));
|
||||||
|
|
||||||
|
return spirvTypeParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TSpirvTypeParameters* TParseContext::makeSpirvTypeParameters(const TSourceLoc& loc, const TPublicType& type)
|
||||||
|
{
|
||||||
|
TSpirvTypeParameters* spirvTypeParams = new TSpirvTypeParameters;
|
||||||
|
spirvTypeParams->push_back(TSpirvTypeParameter(new TType(type)));
|
||||||
return spirvTypeParams;
|
return spirvTypeParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4439,6 +4439,9 @@ spirv_type_parameter
|
|||||||
: constant_expression {
|
: constant_expression {
|
||||||
$$ = parseContext.makeSpirvTypeParameters($1->getLoc(), $1->getAsConstantUnion());
|
$$ = parseContext.makeSpirvTypeParameters($1->getLoc(), $1->getAsConstantUnion());
|
||||||
}
|
}
|
||||||
|
| type_specifier_nonarray {
|
||||||
|
$$ = parseContext.makeSpirvTypeParameters($1.loc, $1);
|
||||||
|
}
|
||||||
|
|
||||||
spirv_instruction_qualifier
|
spirv_instruction_qualifier
|
||||||
: SPIRV_INSTRUCTION LEFT_PAREN spirv_instruction_qualifier_list RIGHT_PAREN {
|
: SPIRV_INSTRUCTION LEFT_PAREN spirv_instruction_qualifier_list RIGHT_PAREN {
|
||||||
|
@ -4439,6 +4439,9 @@ spirv_type_parameter
|
|||||||
: constant_expression {
|
: constant_expression {
|
||||||
$$ = parseContext.makeSpirvTypeParameters($1->getLoc(), $1->getAsConstantUnion());
|
$$ = parseContext.makeSpirvTypeParameters($1->getLoc(), $1->getAsConstantUnion());
|
||||||
}
|
}
|
||||||
|
| type_specifier_nonarray {
|
||||||
|
$$ = parseContext.makeSpirvTypeParameters($1.loc, $1);
|
||||||
|
}
|
||||||
|
|
||||||
spirv_instruction_qualifier
|
spirv_instruction_qualifier
|
||||||
: SPIRV_INSTRUCTION LEFT_PAREN spirv_instruction_qualifier_list RIGHT_PAREN {
|
: SPIRV_INSTRUCTION LEFT_PAREN spirv_instruction_qualifier_list RIGHT_PAREN {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -398,6 +398,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||||||
"spv.intrinsicsSpirvStorageClass.rchit",
|
"spv.intrinsicsSpirvStorageClass.rchit",
|
||||||
"spv.intrinsicsSpirvType.rgen",
|
"spv.intrinsicsSpirvType.rgen",
|
||||||
"spv.intrinsicsSpirvTypeLocalVar.vert",
|
"spv.intrinsicsSpirvTypeLocalVar.vert",
|
||||||
|
"spv.intrinsicsSpirvTypeWithTypeSpecifier.vert",
|
||||||
"spv.invariantAll.vert",
|
"spv.invariantAll.vert",
|
||||||
"spv.layer.tese",
|
"spv.layer.tese",
|
||||||
"spv.layoutNested.vert",
|
"spv.layoutNested.vert",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user