From 71885de27c973a73b7d020f5ebbe86e16b86d7e4 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 18 Mar 2019 18:19:26 -0400 Subject: First pass support for half on vk (#912) * Look at getting half to work on vk. * Alter half test so can always produce consistent test results. * First pass working half on vk. * Improve comments for vulkan extensions around half. * Upgraded vulkan headers to v1.1.103 https://github.com/KhronosGroup/Vulkan-Headers * * Add getFeatures on Render interface * Vulkan renderer determines at startup if it can support half * Parse render-features on render-test * Small changes to half-calc.slang test. * Structured buffer half access works as expected for Vk, but isn't for dx12, so disable for now. * Require the half feature for renderers for the half-structured-buffer.slang test. * * Added ToolReturnCode to be more rigerous about how a return code is passed back from a tool * Added support for a tool being able to pass back an 'ignored' result. * Used enum codes to indicate meanings * Made spawnAndWait return a ToolReturnCode * Ignore tests that don't have required render-feature * Fix macro line continuation usage. * Check dx12 has half support. * Checking for half on dx12 - if CheckFeatureSupport fails, don't fail renderer initialization. * Fix typo. --- source/slang/emit.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index d2de479b4..84585f248 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -47,6 +47,8 @@ struct ExtensionUsageTracker StringBuilder glslExtensionRequireLines; ProfileVersion profileVersion = ProfileVersion::GLSL_110; + + bool hasHalfExtension = false; }; void requireGLSLExtension( @@ -76,6 +78,21 @@ void requireGLSLVersionImpl( } } +void requireGLSLHalfExtension(ExtensionUsageTracker* tracker) +{ + if (!tracker->hasHalfExtension) + { + // https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GL_EXT_shader_16bit_storage.txt + requireGLSLExtension(tracker, "GL_EXT_shader_16bit_storage"); + + // https://github.com/KhronosGroup/GLSL/blob/master/extensions/ext/GL_EXT_shader_explicit_arithmetic_types.txt + // Use GL_KHX_shader_explicit_arithmetic_types because that is what appears defined in glslang + requireGLSLExtension(tracker, "GL_KHX_shader_explicit_arithmetic_types"); + + tracker->hasHalfExtension = true; + } +} + // Shared state for an entire emit session struct SharedEmitContext @@ -810,7 +827,12 @@ struct EmitVisitor case kIROp_BoolType: Emit("b"); break; - case kIROp_HalfType: Emit("f16"); break; + case kIROp_HalfType: + { + _requireHalf(); + Emit("f16"); + break; + } case kIROp_DoubleType: Emit("d"); break; case kIROp_VectorType: @@ -1197,6 +1219,14 @@ struct EmitVisitor } } + void _requireHalf() + { + if (getTarget(context) == CodeGenTarget::GLSL) + { + requireGLSLHalfExtension(&context->shared->extensionUsageTracker); + } + } + void emitSimpleTypeImpl(IRType* type) { switch (type->op) @@ -1217,7 +1247,19 @@ struct EmitVisitor case kIROp_UIntType: Emit("uint"); return; case kIROp_UInt64Type: Emit("uint64_t"); return; - case kIROp_HalfType: Emit("half"); return; + case kIROp_HalfType: + { + _requireHalf(); + if (getTarget(context) == CodeGenTarget::GLSL) + { + Emit("float16_t"); + } + else + { + Emit("half"); + } + return; + } case kIROp_FloatType: Emit("float"); return; case kIROp_DoubleType: Emit("double"); return; -- cgit v1.2.3