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

[SPIR-V] Don't always force EXT_mesh_shader override #6194

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 8 additions & 14 deletions tools/clang/lib/SPIRV/FeatureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ FeatureManager::FeatureManager(DiagnosticsEngine &de,
: diags(de) {
allowedExtensions.resize(static_cast<unsigned>(Extension::Unknown) + 1);

if (opts.allowedExtensions.empty()) {
// If no explicit extension control from command line, use the default mode:
// allowing all extensions that are enabled by default.
allowAllKnownExtensions();
} else {
for (auto ext : opts.allowedExtensions)
allowExtension(ext);
}

targetEnvStr = opts.targetEnv;

llvm::Optional<spv_target_env> targetEnvOpt =
Expand All @@ -89,10 +80,13 @@ FeatureManager::FeatureManager(DiagnosticsEngine &de,
}
targetEnv = *targetEnvOpt;

// Override the default mesh extension to SPV_EXT_mesh_shader when the
// target environment is SPIR-V 1.4 or above
if (isTargetEnvSpirv1p4OrAbove()) {
allowExtension("SPV_EXT_mesh_shader");
if (opts.allowedExtensions.empty()) {
// If no explicit extension control from command line, use the default mode:
// allowing all extensions that are enabled by default.
allowAllKnownExtensions();
} else {
for (auto ext : opts.allowedExtensions)
allowExtension(ext);
}
}

Expand Down Expand Up @@ -349,7 +343,7 @@ bool FeatureManager::enabledByDefault(Extension ext) {
case Extension::EXT_mesh_shader:
// Enabling EXT_mesh_shader only when the target environment is SPIR-V 1.4
// or above
return false;
return isTargetEnvSpirv1p4OrAbove();
default:
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %dxc -T ms_6_5 -E main -fspv-target-env=vulkan1.1spirv1.4 %s -spirv | FileCheck %s
// CHECK: OpCapability MeshShadingEXT
// CHECK: OpExtension "SPV_EXT_mesh_shader"
// CHECK: OpEntryPoint MeshEXT %main "main" %gl_Position [[primind:%[0-9]+]]
// CHECK: OpExecutionMode %main LocalSize 64 1 1
// CHECK: OpExecutionMode %main OutputTrianglesNV
// CHECK: OpExecutionMode %main OutputVertices 81
// CHECK: OpExecutionMode %main OutputPrimitivesNV 128

// CHECK: OpDecorate %gl_Position BuiltIn Position
// CHECK: OpDecorate [[primind]] BuiltIn PrimitiveTriangleIndicesEXT

// Make sure that when spirv 1.4 or above is supported, and no extensions are explicitly requested, that
// we output SPIR-V using SPV_EXT_mesh_shader as the default mesh extension

struct MeshPerVertex {
float4 position : SV_Position;
};

#define NUM_THREADS 64
#define MAX_VERT 81
#define MAX_PRIM 128

[outputtopology("triangle")]
[numthreads(NUM_THREADS, 1, 1)]
void main(out vertices MeshPerVertex verts[MAX_VERT],
out indices uint3 primitiveInd[MAX_PRIM],
in uint tid : SV_DispatchThreadID)
{
// CHECK: OpSetMeshOutputsEXT %uint_81 %uint_128
SetMeshOutputCounts(MAX_VERT, MAX_PRIM);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %dxc -T ms_6_5 -E main -fspv-target-env=vulkan1.1spirv1.4 -fspv-extension=SPV_NV_mesh_shader %s -spirv | FileCheck %s
// CHECK: OpCapability MeshShadingNV
// CHECK: OpExtension "SPV_NV_mesh_shader"
// CHECK: OpEntryPoint MeshNV %main "main" %gl_Position [[primind:%[0-9]+]] [[primcount:%[0-9]+]]
// CHECK: OpExecutionMode %main LocalSize 32 1 1
// CHECK: OpExecutionMode %main OutputTrianglesNV
// CHECK: OpExecutionMode %main OutputVertices 81
// CHECK: OpExecutionMode %main OutputPrimitivesNV 128

// CHECK: OpDecorate %gl_Position BuiltIn Position
// CHECK: OpDecorate [[primind]] BuiltIn PrimitiveIndicesNV
// CHECK: OpDecorate [[primcount]] BuiltIn PrimitiveCountNV

// Make sure that when spirv 1.4 or above is supported, but we explicitly request SPV_NV_mesh_shader through -fpv-extension,
// that we output SPIR-V using SPV_NV_mesh_shader and don't override using the EXT extension

struct MeshPerVertex {
float4 position : SV_Position;
};

#define NUM_THREADS 32
#define MAX_VERT 81
#define MAX_PRIM 128

[outputtopology("triangle")]
[numthreads(NUM_THREADS, 1, 1)]
void main(out vertices MeshPerVertex verts[MAX_VERT],
out indices uint3 primitiveInd[MAX_PRIM],
in uint tid : SV_DispatchThreadID)
{
SetMeshOutputCounts(MAX_VERT, MAX_PRIM);
}
Loading