Commit e8fe8b0d by Rex Xu

Implement extension GL_NV_shader_atomic_int64

parent f21c173a
......@@ -4749,12 +4749,12 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv
case glslang::EOpAtomicMin:
case glslang::EOpImageAtomicMin:
case glslang::EOpAtomicCounterMin:
opCode = typeProxy == glslang::EbtUint ? spv::OpAtomicUMin : spv::OpAtomicSMin;
opCode = (typeProxy == glslang::EbtUint || typeProxy == glslang::EbtUint64) ? spv::OpAtomicUMin : spv::OpAtomicSMin;
break;
case glslang::EOpAtomicMax:
case glslang::EOpImageAtomicMax:
case glslang::EOpAtomicCounterMax:
opCode = typeProxy == glslang::EbtUint ? spv::OpAtomicUMax : spv::OpAtomicSMax;
opCode = (typeProxy == glslang::EbtUint || typeProxy == glslang::EbtUint64) ? spv::OpAtomicUMax : spv::OpAtomicSMax;
break;
case glslang::EOpAtomicAnd:
case glslang::EOpImageAtomicAnd:
......@@ -4795,6 +4795,9 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv
break;
}
if (typeProxy == glslang::EbtInt64 || typeProxy == glslang::EbtUint64)
builder.addCapability(spv::CapabilityInt64Atomics);
// Sort out the operands
// - mapping from glslang -> SPV
// - there are extra SPV operands with no glslang source
......
#version 450 core
#extension GL_ARB_gpu_shader_int64: enable
#extension GL_NV_shader_atomic_int64: enable
layout(local_size_x = 16, local_size_y = 16) in;
layout(binding = 0) buffer Buffer
{
int64_t i64;
uint64_t u64;
} buf;
struct Struct
{
int64_t i64;
uint64_t u64;
};
shared Struct s;
void main()
{
const int64_t i64c = -24;
const uint64_t u64c = 0xF00000000F;
// Test shader storage block
int64_t i64 = 0;
uint64_t u64 = 0;
i64 += atomicMin(buf.i64, i64c);
u64 += atomicMin(buf.u64, u64c);
i64 += atomicMax(buf.i64, i64c);
u64 += atomicMax(buf.u64, u64c);
i64 += atomicAnd(buf.i64, i64c);
u64 += atomicAnd(buf.u64, u64c);
i64 += atomicOr(buf.i64, i64c);
u64 += atomicOr(buf.u64, u64c);
i64 += atomicXor(buf.i64, i64c);
u64 += atomicXor(buf.u64, u64c);
i64 += atomicAdd(buf.i64, i64c);
i64 += atomicExchange(buf.i64, i64c);
i64 += atomicCompSwap(buf.i64, i64c, i64);
buf.i64 = i64;
buf.u64 = u64;
// Test shared variable
i64 = 0;
u64 = 0;
i64 += atomicMin(s.i64, i64c);
u64 += atomicMin(s.u64, u64c);
i64 += atomicMax(s.i64, i64c);
u64 += atomicMax(s.u64, u64c);
i64 += atomicAnd(s.i64, i64c);
u64 += atomicAnd(s.u64, u64c);
i64 += atomicOr(s.i64, i64c);
u64 += atomicOr(s.u64, u64c);
i64 += atomicXor(s.i64, i64c);
u64 += atomicXor(s.u64, u64c);
i64 += atomicAdd(s.i64, i64c);
i64 += atomicExchange(s.i64, i64c);
i64 += atomicCompSwap(s.i64, i64c, i64);
s.i64 = i64;
s.u64 = u64;
}
......@@ -923,6 +923,32 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
"\n");
}
#ifdef NV_EXTENSIONS
if (profile != EEsProfile && version >= 440) {
commonBuiltins.append(
"uint64_t atomicMin(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicMin(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicMax(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicMax(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicAnd(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicAnd(coherent volatile inout int64_t, int64_t);"
"uint64_t atomicOr (coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicOr (coherent volatile inout int64_t, int64_t);"
"uint64_t atomicXor(coherent volatile inout uint64_t, uint64_t);"
" int64_t atomicXor(coherent volatile inout int64_t, int64_t);"
" int64_t atomicAdd(coherent volatile inout int64_t, int64_t);"
" int64_t atomicExchange(coherent volatile inout int64_t, int64_t);"
" int64_t atomicCompSwap(coherent volatile inout int64_t, int64_t, int64_t);"
"\n");
}
#endif
if ((profile == EEsProfile && version >= 310) ||
(profile != EEsProfile && version >= 450)) {
commonBuiltins.append(
......
......@@ -1551,6 +1551,23 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan
break;
}
#ifdef NV_EXTENSIONS
case EOpAtomicAdd:
case EOpAtomicMin:
case EOpAtomicMax:
case EOpAtomicAnd:
case EOpAtomicOr:
case EOpAtomicXor:
case EOpAtomicExchange:
case EOpAtomicCompSwap:
{
if (arg0->getType().getBasicType() == EbtInt64 || arg0->getType().getBasicType() == EbtUint64)
requireExtensions(loc, 1, &E_GL_NV_shader_atomic_int64, fnCandidate.getName().c_str());
break;
}
#endif
case EOpInterpolateAtCentroid:
case EOpInterpolateAtSample:
case EOpInterpolateAtOffset:
......
......@@ -211,6 +211,7 @@ void TParseVersions::initializeExtensionBehavior()
extensionBehavior[E_GL_NV_viewport_array2] = EBhDisable;
extensionBehavior[E_GL_NV_stereo_view_rendering] = EBhDisable;
extensionBehavior[E_GL_NVX_multiview_per_view_attributes] = EBhDisable;
extensionBehavior[E_GL_NV_shader_atomic_int64] = EBhDisable;
#endif
// AEP
......@@ -343,6 +344,7 @@ void TParseVersions::getPreamble(std::string& preamble)
"#define GL_NV_sample_mask_override_coverage 1\n"
"#define GL_NV_geometry_shader_passthrough 1\n"
"#define GL_NV_viewport_array2 1\n"
"#define GL_NV_shader_atomic_int64 1\n"
#endif
;
......
......@@ -182,6 +182,7 @@ const char* const E_SPV_NV_geometry_shader_passthrough = "GL_NV_geometr
const char* const E_GL_NV_viewport_array2 = "GL_NV_viewport_array2";
const char* const E_GL_NV_stereo_view_rendering = "GL_NV_stereo_view_rendering";
const char* const E_GL_NVX_multiview_per_view_attributes = "GL_NVX_multiview_per_view_attributes";
const char* const E_GL_NV_shader_atomic_int64 = "GL_NV_shader_atomic_int64";
// Arrays of extensions for the above viewportEXTs duplications
......
......@@ -410,7 +410,7 @@ INSTANTIATE_TEST_CASE_P(
"spv.int16.frag",
"spv.shaderBallotAMD.comp",
"spv.shaderFragMaskAMD.frag",
"spv.textureGatherBiasLod.frag"
"spv.textureGatherBiasLod.frag",
})),
FileNameAsCustomTestSuffix
);
......@@ -428,6 +428,7 @@ INSTANTIATE_TEST_CASE_P(
"spv.stereoViewRendering.tesc",
"spv.multiviewPerViewAttributes.vert",
"spv.multiviewPerViewAttributes.tesc",
"spv.atomicInt64.comp",
})),
FileNameAsCustomTestSuffix
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment