summaryrefslogtreecommitdiff
path: root/source/slang/emit.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-02-18 08:08:46 -0800
committerGitHub <noreply@github.com>2018-02-18 08:08:46 -0800
commit51cdcad24b5271ac8c0f816174c6a760e264ed9e (patch)
tree30beaa85671168ac2c73b08f4f20d894cbca88f9 /source/slang/emit.cpp
parent8c872597540b2287bc18d5723c7ae3b8832246b8 (diff)
stdlib fixes for Vulkan (#414)
* stdlib fixes for Vulkan - Make sure to emit `image*` instead of `texture*` for `RWTexture*` types - Change `GetDimensions` to call `imageSize` instead of `textureSize` when we use images - Always output a `layout(rgba32f)` for variables that translate to `image` types - TODO: we should emit an appropriate format based on the type, or let the user specify one - Fix GLSL translation for `any()` function (required boolean inputs) - Add GLSL translation for `GroupMemoryBarrierWithGroupSync()` - Map HLSL `groupshared` to GLSL `shared` These together are enough to get the Falor `ComputeShader` example to work. * fixup for warning
Diffstat (limited to 'source/slang/emit.cpp')
-rw-r--r--source/slang/emit.cpp87
1 files changed, 80 insertions, 7 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index e5fb6a8be..672798359 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -1015,7 +1015,17 @@ struct EmitVisitor
void emitGLSLTextureType(
RefPtr<TextureType> texType)
{
- emitGLSLTextureOrTextureSamplerType(texType, "texture");
+ switch(texType->getAccess())
+ {
+ case SLANG_RESOURCE_ACCESS_READ_WRITE:
+ case SLANG_RESOURCE_ACCESS_RASTER_ORDERED:
+ emitGLSLTextureOrTextureSamplerType(texType, "image");
+ break;
+
+ default:
+ emitGLSLTextureOrTextureSamplerType(texType, "texture");
+ break;
+ }
}
void emitGLSLTextureSamplerType(
@@ -1289,7 +1299,19 @@ struct EmitVisitor
void visitGroupSharedType(GroupSharedType* type, TypeEmitArg const& arg)
{
- Emit("groupshared ");
+ switch(getTarget(context))
+ {
+ case CodeGenTarget::HLSL:
+ Emit("groupshared ");
+ break;
+
+ case CodeGenTarget::GLSL:
+ Emit("shared ");
+ break;
+
+ default:
+ break;
+ }
emitTypeImpl(type->valueType, arg.declarator);
}
@@ -2275,7 +2297,6 @@ struct EmitVisitor
}
break;
-
default:
SLANG_UNEXPECTED("bad format in intrinsic definition");
break;
@@ -5454,6 +5475,28 @@ emitDeclImpl(decl, nullptr);
}
break;
+ case 'N':
+ {
+ // Extract the element count from a vector argument so that
+ // we can use it in the constructed expression.
+
+ SLANG_RELEASE_ASSERT(*cursor >= '0' && *cursor <= '9');
+ UInt argIndex = (*cursor++) - '0';
+ SLANG_RELEASE_ASSERT(argCount > argIndex);
+
+ auto vectorArg = args[argIndex].get();
+ if (auto vectorType = vectorArg->type->As<VectorExpressionType>())
+ {
+ auto elementCount = GetIntVal(vectorType->elementCount);
+ Emit(elementCount);
+ }
+ else
+ {
+ SLANG_UNEXPECTED("bad format in intrinsic definition");
+ }
+ }
+ break;
+
default:
SLANG_UNEXPECTED("bad format in intrinsic definition");
@@ -7090,13 +7133,43 @@ emitDeclImpl(decl, nullptr);
void emitIRVarModifiers(
EmitContext* ctx,
- VarLayout* layout)
+ VarLayout* layout,
+ Type* valueType)
{
if (!layout)
return;
emitIRMatrixLayoutModifiers(ctx, layout);
+ // As a special case, if we are emitting a GLSL declaration
+ // for an HLSL `RWTexture*` then we need to emit a `format` layout qualifier.
+ if(getTarget(context) == CodeGenTarget::GLSL)
+ {
+ if(auto resourceType = unwrapArray(valueType).As<TextureType>())
+ {
+ switch(resourceType->getAccess())
+ {
+ case SLANG_RESOURCE_ACCESS_READ_WRITE:
+ case SLANG_RESOURCE_ACCESS_RASTER_ORDERED:
+ {
+ // TODO: at this point we need to look at the element
+ // type and figure out what format we want.
+ //
+ // For now just hack it and assume a fixed format.
+ Emit("layout(rgba32f)");
+
+ // TODO: we also need a way for users to specify what
+ // the format should be explicitly, to avoid having
+ // to have us infer things...
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
if (ctx->shared->target == CodeGenTarget::GLSL)
{
// Layout-related modifiers need to come before the declaration,
@@ -7238,7 +7311,7 @@ emitDeclImpl(decl, nullptr);
if(fieldType->Equals(getSession()->getVoidType()))
continue;
- emitIRVarModifiers(ctx, fieldLayout);
+ emitIRVarModifiers(ctx, fieldLayout, fieldType);
emitIRType(ctx, fieldType, getIRName(ff));
@@ -7444,7 +7517,7 @@ emitDeclImpl(decl, nullptr);
auto layout = getVarLayout(ctx, varDecl);
- emitIRVarModifiers(ctx, layout);
+ emitIRVarModifiers(ctx, layout, varType);
#if 0
switch (addressSpace)
@@ -7597,7 +7670,7 @@ emitDeclImpl(decl, nullptr);
}
}
- emitIRVarModifiers(ctx, layout);
+ emitIRVarModifiers(ctx, layout, varType);
emitIRType(ctx, varType, getIRName(varDecl));