From 00bd481e001e8c0b8008eaff5a38fa37963e6f99 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 15 Aug 2023 20:28:42 +0800 Subject: SPIR-V WIP (#3064) * Add type layout for structured buffer * Default to generating spirv directly * vk test for compute simple * Add spirv-dis as a downstream compiler * Emit Array types in SPIR-V * makevector for spirv * Dump whole spirv module on validation failure * register array types todo, use emitTypeInst * Neater formatting for unhandled inst printing * break out emitCompositeConstruct * Correct array type generation * neaten * Allow getElement for vector * Remove unused * Allow predicating target intrinsics on types * Consider functions with intrinsics to have definitions We need to specialize these if they are predicated on types * Correct array type generation * makeArray for spir-v * replace getElement with getElementPtr for spirv * Correct translation of field access for spirv * Push layouts to types for spirv * Spirv intrinsics * operator now makes a pointer * Add structured buffer of struct test * Preserve type layout in spirv structured buffer legalization * neaten * makeVectorFromScalar for SPIRV * placeholder for layouts on param groups * More type safe spirv op construction * Know that constants and types only go in one section * Remove emitTypeInst * Add todo for spirv sampling * Add links to spirv documentation on emit functions * OpTypeImage support for SPIR-V * Add simpler texture test for spirv * s/spirv_direct/spirv/g * Allow several string literals in target_intrinsic * Handle global params without a var layour for SPIR-V For example groupshared vars * uint spirv asm type * Add todo for isDefinition It is currently too broad * Some atomic op spirv intrinsics * Strip ConstantBuffer wrappers for spirv * Add todo for matrix annotations * Do not associate decorations insts with spirv counterparts * Correct entry point parameter generation * Spelling * Assert that fieldAddress is returning a pointer * Add error for existential type layout getting to spir-v emit * Add IRTupleTypeLayout Unused so far * Allow getElementPtr to work with vectors * Correct target name in test * Hide default spirv direct behind a premake option --default-spirv-direct=true * Do not insert space at start of intrinsic def * Correct asm rendering in tests * remove redundant option * Emit directly from direct test * Add source language options for spirv-dis * Add comments to spirv dis * Add dead debug print for before spirv module * Correct asm rendering in tests * s/spirv_direct/spirv/g * Only specialize intrinsic functions with predicates * regenerate vs projects * squash warnings * squash warnings * remove duplication * Silence warnings from msvc * squash warnings * Overload for zero sized array * More msvc warnings * warnings * Add spirv-tools to path for tests * Do not be specific about dxc version for diag test * Normalize line endings from spirv-dis * Correct filecheck matches * Temporarily disable two spirv tests Failing on CI, undebuggable hang :/ * Do not emit storage class more than once for spirv snippet * Do not pass spir-v to spirv-dis by stdin * Do not get spirv-dis output via stream, use file * normalize file endings in spirv-dis output --- source/slang/slang-options.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'source/slang/slang-options.cpp') diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 85602b744..216040f98 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -99,6 +99,9 @@ enum class OptionKind GLSLForceScalarLayout, EnableEffectAnnotations, + + EmitSpirvViaGLSL, + EmitSpirvDirectly, // Downstream @@ -131,7 +134,6 @@ enum class OptionKind // Experimental - EmitSpirvDirectly, FileSystem, Heterogeneous, NoMangle, @@ -506,6 +508,17 @@ void initCommandOptions(CommandOptions& options) { OptionKind::EnableEffectAnnotations, "-enable-effect-annotations", nullptr, "Enables support for legacy effect annotation syntax."}, +#if defined(SLANG_CONFIG_DEFAULT_SPIRV_DIRECT) + { OptionKind::EmitSpirvViaGLSL, "-emit-spirv-via-glsl", nullptr, + "Generate SPIR-V output by compiling generated GLSL with glslang" }, + { OptionKind::EmitSpirvDirectly, "-emit-spirv-directly", nullptr, + "Generate SPIR-V output direclty (default)" }, +#else + { OptionKind::EmitSpirvViaGLSL, "-emit-spirv-via-glsl", nullptr, + "Generate SPIR-V output by compiling generated GLSL with glslang (default)" }, + { OptionKind::EmitSpirvDirectly, "-emit-spirv-directly", nullptr, + "Generate SPIR-V output direclty rather than by compiling generated GLSL with glslang" }, +#endif }; _addOptions(makeConstArrayView(targetOpts), options); @@ -583,9 +596,6 @@ void initCommandOptions(CommandOptions& options) const Option experimentalOpts[] = { - { OptionKind::EmitSpirvDirectly, "-emit-spirv-directly", nullptr, - "Generate SPIR-V output directly (otherwise through " - "GLSL and using the glslang compiler)"}, { OptionKind::FileSystem, "-file-system", "-file-system ", "Set the filesystem hook to use for a compile request."}, { OptionKind::Heterogeneous, "-heterogeneous", nullptr, "Output heterogeneity-related code." }, @@ -726,7 +736,7 @@ struct OptionsParser { CodeGenTarget format = CodeGenTarget::Unknown; ProfileVersion profileVersion = ProfileVersion::Unknown; - SlangTargetFlags targetFlags = 0; + SlangTargetFlags targetFlags = kDefaultTargetFlags; int targetID = -1; FloatingPointMode floatingPointMode = FloatingPointMode::Default; bool forceGLSLScalarLayout = false; @@ -2280,7 +2290,16 @@ SlangResult OptionsParser::_parse( // We retun an error so after this has successfully passed, we quit return SLANG_FAIL; } - case OptionKind::EmitSpirvDirectly: getCurrentTarget()->targetFlags |= SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; break; + case OptionKind::EmitSpirvViaGLSL: + { + getCurrentTarget()->targetFlags &= ~SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; + } + break; + case OptionKind::EmitSpirvDirectly: + { + getCurrentTarget()->targetFlags |= SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY; + } + break; case OptionKind::DefaultDownstreamCompiler: { -- cgit v1.2.3