From 3f48e1c0d84bf4909954154ad147559656e87516 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 19 Jul 2017 09:36:35 -0700 Subject: Try to improve handling of failures during compilation The change is mostly about trying to make sure the compiler "fails safe" when it encounters an internal assumption that isn't met. Most internal errors will now throw exceptions (yes, exceptions are evil, but this will work for now), and these get caught in `spCompile` so that they don't propagate to the user (they just see a message that compilation aborted due to an internal error). Subsequent changes are going to need to work on diagnosing as many of these situations as possible, so that users can at least know what construct in their code was unexpected or unhandled by the compiler. --- source/slang/type-layout.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'source/slang/type-layout.cpp') diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp index b4bf8949f..245993881 100644 --- a/source/slang/type-layout.cpp +++ b/source/slang/type-layout.cpp @@ -38,8 +38,11 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl case BaseType::Bool: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4, 4 ); + case BaseType::Double: + return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8, 8 ); + default: - assert(!"unimplemented"); + SLANG_UNEXPECTED("uhandled scalar type"); return SimpleLayoutInfo( LayoutResourceKind::Uniform, 0, 1 ); } } @@ -64,7 +67,7 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl case slang::TypeReflection::ScalarType::Float64: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8,8); default: - assert(!"unimplemented"); + SLANG_UNEXPECTED("unhandled scalar type"); return SimpleLayoutInfo(); } } @@ -164,7 +167,7 @@ struct GLSLConstantBufferLayoutRulesImpl : DefaultConstantBufferLayoutRulesImpl static SimpleLayoutInfo getGLSLVectorLayout( SimpleLayoutInfo elementInfo, size_t elementCount) { - assert(elementInfo.kind == LayoutResourceKind::Uniform); + SLANG_RELEASE_ASSERT(elementInfo.kind == LayoutResourceKind::Uniform); auto size = elementInfo.size * elementCount; SimpleLayoutInfo vectorInfo( LayoutResourceKind::Uniform, @@ -380,7 +383,7 @@ struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl case ShaderParameterKind::InputRenderTarget: // TODO: how to handle these? default: - assert(!"unimplemented"); + SLANG_UNEXPECTED("unhandled shader parameter kind"); return SimpleLayoutInfo(); } } @@ -601,7 +604,7 @@ static int GetElementCount(RefPtr val) // TODO(tfoley): do something sensible in this case return 0; } - assert(!"unexpected"); + SLANG_UNEXPECTED("unhandled integer literal kind"); return 0; } @@ -670,7 +673,7 @@ static SimpleLayoutInfo getParameterBlockLayoutInfo( } else { - assert(!"unexpected"); + SLANG_UNEXPECTED("unhandled parameter block type"); return SimpleLayoutInfo(); } } @@ -696,8 +699,8 @@ createParameterBlockTypeLayout( // and hence no uniform data). // typeLayout->uniformAlignment = parameterBlockInfo.alignment; - assert(!typeLayout->FindResourceInfo(LayoutResourceKind::Uniform)); - assert(typeLayout->uniformAlignment == 1); + SLANG_RELEASE_ASSERT(!typeLayout->FindResourceInfo(LayoutResourceKind::Uniform)); + SLANG_RELEASE_ASSERT(typeLayout->uniformAlignment == 1); // TODO(tfoley): There is a subtle question here of whether // a constant buffer declaration that then contains zero @@ -801,7 +804,7 @@ LayoutRulesImpl* getParameterBufferElementTypeLayoutRules( } else { - assert(!"unexpected"); + SLANG_UNEXPECTED("uhandled parameter block type"); return nullptr; } } @@ -843,8 +846,8 @@ createStructuredBufferTypeLayout( typeLayout->elementTypeLayout = elementTypeLayout; typeLayout->uniformAlignment = info.alignment; - assert(!typeLayout->FindResourceInfo(LayoutResourceKind::Uniform)); - assert(typeLayout->uniformAlignment == 1); + SLANG_RELEASE_ASSERT(!typeLayout->FindResourceInfo(LayoutResourceKind::Uniform)); + SLANG_RELEASE_ASSERT(typeLayout->uniformAlignment == 1); if( info.size != 0 ) { @@ -1211,7 +1214,7 @@ SimpleLayoutInfo GetLayoutImpl( continue; // We should not have already processed this resource type - assert(!fieldLayout->FindResourceInfo(fieldTypeResourceInfo.kind)); + SLANG_RELEASE_ASSERT(!fieldLayout->FindResourceInfo(fieldTypeResourceInfo.kind)); // The field will need offset information for this kind auto fieldResourceInfo = fieldLayout->AddResourceInfo(fieldTypeResourceInfo.kind); @@ -1258,7 +1261,7 @@ SimpleLayoutInfo GetLayoutImpl( } // catch-all case in case nothing matched - assert(!"unimplemented"); + SLANG_ASSERT(!"unimplemented"); SimpleLayoutInfo info; return GetSimpleLayoutImpl( info, -- cgit v1.2.3