summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-17 15:13:37 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-17 15:13:37 -0700
commitff4621460a98f34d74e4275841c313400cbda0dd (patch)
treea8f6a2334397ade3981f35d1ee764a4c325e0927 /source
parent0059ccb3997c2af87bc3f76524d8cd4787c20b7e (diff)
Handle `Buffer` types more like textures
Fixes #94 We'd been handling HLSL `Buffer` and `RWBuffer` in a one-off fashion, and that led to a lot of code duplication, and also to the issue that we weren't handling `RasterizerOrderedBuffer` at all. This change basically folds `Buffer` in so that it is conceptually a texture type (just with a unique shape). Hopefully all the other logic still works.
Diffstat (limited to 'source')
-rw-r--r--source/slang/emit.cpp1
-rw-r--r--source/slang/reflection.cpp17
-rw-r--r--source/slang/slang-stdlib.cpp70
-rw-r--r--source/slang/syntax.cpp6
-rw-r--r--source/slang/type-defs.h49
-rw-r--r--source/slang/type-layout.cpp4
-rw-r--r--source/slang/type-layout.h3
7 files changed, 69 insertions, 81 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index c6efa88dc..ef922c418 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -771,6 +771,7 @@ struct EmitVisitor
case TextureType::Shape2D: Emit("Texture2D"); break;
case TextureType::Shape3D: Emit("Texture3D"); break;
case TextureType::ShapeCube: Emit("TextureCube"); break;
+ case TextureType::ShapeBuffer: Emit("Buffer"); break;
default:
assert(!"unreachable");
break;
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp
index aaeae5595..18fa3362d 100644
--- a/source/slang/reflection.cpp
+++ b/source/slang/reflection.cpp
@@ -123,10 +123,6 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType)
return SLANG_TYPE_KIND_RESOURCE; \
} while(0)
- CASE(HLSLBufferType);
- CASE(HLSLRWBufferType);
- CASE(HLSLBufferType);
- CASE(HLSLRWBufferType);
CASE(HLSLStructuredBufferType);
CASE(HLSLRWStructuredBufferType);
CASE(HLSLAppendStructuredBufferType);
@@ -342,10 +338,6 @@ SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionTy
return SHAPE; \
} while(0)
- CASE(HLSLBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
- CASE(HLSLBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
CASE(HLSLRWStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
CASE(HLSLAppendStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_APPEND);
@@ -379,10 +371,6 @@ SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflection
return ACCESS; \
} while(0)
- CASE(HLSLBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
- CASE(HLSLBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
CASE(HLSLRWStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
CASE(HLSLAppendStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_APPEND);
@@ -419,11 +407,6 @@ SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangRefle
return convert(type->As<TYPE>()->elementType.Ptr()); \
} while(0)
- CASE(HLSLBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
- CASE(HLSLBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWBufferType, SLANG_TEXTURE_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
-
// TODO: structured buffer needs to expose type layout!
CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp
index 3de33f554..5800a5deb 100644
--- a/source/slang/slang-stdlib.cpp
+++ b/source/slang/slang-stdlib.cpp
@@ -50,17 +50,6 @@ __generic<T> __magic_type(HLSLAppendStructuredBufferType) struct AppendStructure
out uint stride);
};
-__generic<T> __magic_type(HLSLBufferType) struct Buffer
-{
- __intrinsic void GetDimensions(
- out uint dim);
-
- __intrinsic T Load(int location);
- __intrinsic T Load(int location, out uint status);
-
- __intrinsic __subscript(uint index) -> T;
-};
-
__magic_type(HLSLByteAddressBufferType) struct ByteAddressBuffer
{
__intrinsic void GetDimensions(
@@ -110,19 +99,6 @@ __generic<T, let N : int> __magic_type(HLSLOutputPatchType) struct OutputPatch
__intrinsic __subscript(uint index) -> T { set; }
};
-__generic<T> __magic_type(HLSLRWBufferType) struct RWBuffer
-{
- // Note(tfoley): duplication with declaration of `Buffer`
-
- __intrinsic void GetDimensions(
- out uint dim);
-
- __intrinsic T Load(int location);
- __intrinsic T Load(int location, out uint status);
-
- __intrinsic __subscript(uint index) -> T { get; set; }
-};
-
__magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer
{
// Note(tfoley): supports alll operations from `ByteAddressBuffer`
@@ -1985,10 +1961,6 @@ namespace Slang
StringBuilder sb;
-// sb << "__generic<T> __magic_type(PackedBuffer) struct PackedBuffer {};\n";
-// sb << "__generic<T> __magic_type(Uniform) struct Uniform {};\n";
-// sb << "__generic<T> __magic_type(Patch) struct Patch {};\n";
-
// Component-wise multiplication ops
for(auto op : binaryOps)
{
@@ -2019,6 +1991,48 @@ namespace Slang
}
}
+ //
+
+ // Buffer types
+
+ static const struct {
+ char const* name;
+ SlangResourceAccess access;
+ } kBaseBufferAccessLevels[] = {
+ { "", SLANG_RESOURCE_ACCESS_READ },
+ { "RW", SLANG_RESOURCE_ACCESS_READ_WRITE },
+ { "RasterizerOrdered", SLANG_RESOURCE_ACCESS_RASTER_ORDERED },
+ };
+ static const int kBaseBufferAccessLevelCount = sizeof(kBaseBufferAccessLevels) / sizeof(kBaseBufferAccessLevels[0]);
+
+ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa)
+ {
+
+ sb << "__generic<T> __magic_type(Texture, ";
+ sb << ResourceType::makeFlavor(ResourceType::Shape::ShapeBuffer, kBaseBufferAccessLevels[aa].access);
+ sb << ") struct ";
+ sb << kBaseBufferAccessLevels[aa].name;
+ sb << "Buffer {\n";
+
+ sb << "__intrinsic void GetDimensions(out uint dim);\n";
+
+ sb << "__intrinsic T Load(int location);\n";
+ sb << "__intrinsic T Load(int location, out uint status);\n";
+
+ sb << "__intrinsic __subscript(uint index) -> T";
+
+ if (kBaseBufferAccessLevels[aa].access != SLANG_RESOURCE_ACCESS_READ)
+ {
+ sb << " { get; set; }\n";
+ }
+ else
+ {
+ sb << ";\n";
+ }
+
+ sb << "};\n";
+ }
+
// Output a suitable `#line` directive to point at our raw stdlib code above
sb << "\n#line " << kHLSLLibIncludeStringLine << " \"" << getStdlibPath() << "\"\n";
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index 0d7a5ad74..503fbbb0e 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -421,13 +421,7 @@ void ExpressionType::accept(IValVisitor* visitor, void* extra)
CASE(GLSLOutputParameterBlockType, GLSLOutputParameterBlockType)
CASE(GLSLShaderStorageBufferType, GLSLShaderStorageBufferType)
- CASE(PackedBuffer, PackedBufferType)
- CASE(Uniform, UniformBufferType)
- CASE(Patch, PatchType)
-
- CASE(HLSLBufferType, HLSLBufferType)
CASE(HLSLStructuredBufferType, HLSLStructuredBufferType)
- CASE(HLSLRWBufferType, HLSLRWBufferType)
CASE(HLSLRWStructuredBufferType, HLSLRWStructuredBufferType)
CASE(HLSLAppendStructuredBufferType, HLSLAppendStructuredBufferType)
CASE(HLSLConsumeStructuredBufferType, HLSLConsumeStructuredBufferType)
diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h
index 461a27b18..138b0a849 100644
--- a/source/slang/type-defs.h
+++ b/source/slang/type-defs.h
@@ -91,16 +91,8 @@ protected:
)
END_SYNTAX_CLASS()
-
-SYNTAX_CLASS(TextureTypeBase, DeclRefType)
- // The type that results from fetching an element from this texture
- SYNTAX_FIELD(RefPtr<ExpressionType>, elementType)
-
- // Bits representing the kind of texture type we are looking at
- // (e.g., `Texture2DMS` vs. `TextureCubeArray`)
- RAW(typedef uint16_t Flavor;)
- FIELD(Flavor, flavor)
-
+// Base type for things we think of as "resources"
+ABSTRACT_SYNTAX_CLASS(ResourceTypeBase, DeclRefType)
RAW(
enum
{
@@ -132,7 +124,6 @@ RAW(
// No Shape3DArray
ShapeCubeArray = ShapeCube | ArrayFlag,
};
-
Shape GetBaseShape() const { return Shape(flavor & ShapeMask); }
bool isArray() const { return (flavor & ArrayFlag) != 0; }
@@ -142,14 +133,35 @@ RAW(
SlangResourceShape getShape() const { return flavor & 0xFF; }
SlangResourceAccess getAccess() const { return (flavor >> 8) & 0xFF; }
+ // Bits representing the kind of resource we are looking at
+ // (e.g., `Texture2DMS` vs. `TextureCubeArray`)
+ typedef uint16_t Flavor;
+
+ static Flavor makeFlavor(SlangResourceShape shape, SlangResourceAccess access)
+ {
+ return Flavor(shape | (access << 8));
+ }
+)
+ FIELD(Flavor, flavor)
+END_SYNTAX_CLASS()
+
+// Resources that contain "elements" that can be fetched
+ABSTRACT_SYNTAX_CLASS(ResourceType, ResourceTypeBase)
+ // The type that results from fetching an element from this resource
+ SYNTAX_FIELD(RefPtr<ExpressionType>, elementType)
+END_SYNTAX_CLASS()
+
+ABSTRACT_SYNTAX_CLASS(TextureTypeBase, ResourceType)
+RAW(
TextureTypeBase()
{}
TextureTypeBase(
Flavor flavor,
RefPtr<ExpressionType> elementType)
- : elementType(elementType)
- , flavor(flavor)
- {}
+ {
+ this->elementType = elementType;
+ this->flavor = flavor;
+ }
)
END_SYNTAX_CLASS()
@@ -213,17 +225,8 @@ END_SYNTAX_CLASS()
// in the element type.
SIMPLE_SYNTAX_CLASS(PointerLikeType, BuiltinGenericType)
-// Generic types used in existing Slang code
-// TODO(tfoley): check that these are actually working right...
-SIMPLE_SYNTAX_CLASS(PatchType, PointerLikeType)
-SIMPLE_SYNTAX_CLASS(StorageBufferType, BuiltinGenericType)
-SIMPLE_SYNTAX_CLASS(UniformBufferType, PointerLikeType)
-SIMPLE_SYNTAX_CLASS(PackedBufferType, BuiltinGenericType)
-
// HLSL buffer-type resources
-SIMPLE_SYNTAX_CLASS(HLSLBufferType, BuiltinGenericType)
-SIMPLE_SYNTAX_CLASS(HLSLRWBufferType, BuiltinGenericType)
SIMPLE_SYNTAX_CLASS(HLSLStructuredBufferType, BuiltinGenericType)
SIMPLE_SYNTAX_CLASS(HLSLRWStructuredBufferType, BuiltinGenericType)
diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp
index 6ca2d68fb..b4bf8949f 100644
--- a/source/slang/type-layout.cpp
+++ b/source/slang/type-layout.cpp
@@ -361,14 +361,12 @@ struct HLSLObjectLayoutRulesImpl : ObjectLayoutRulesImpl
case ShaderParameterKind::TextureUniformBuffer:
case ShaderParameterKind::StructuredBuffer:
- case ShaderParameterKind::SampledBuffer:
case ShaderParameterKind::RawBuffer:
case ShaderParameterKind::Buffer:
case ShaderParameterKind::Texture:
return SimpleLayoutInfo(LayoutResourceKind::ShaderResource, 1);
case ShaderParameterKind::MutableStructuredBuffer:
- case ShaderParameterKind::MutableSampledBuffer:
case ShaderParameterKind::MutableRawBuffer:
case ShaderParameterKind::MutableBuffer:
case ShaderParameterKind::MutableTexture:
@@ -1041,8 +1039,6 @@ SimpleLayoutInfo GetLayoutImpl(
type, rules, outTypeLayout); \
} while(0)
- CASE(HLSLBufferType, SampledBuffer);
- CASE(HLSLRWBufferType, MutableSampledBuffer);
CASE(HLSLByteAddressBufferType, RawBuffer);
CASE(HLSLRWByteAddressBufferType, MutableRawBuffer);
diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h
index d5c96abf2..81ca1350c 100644
--- a/source/slang/type-layout.h
+++ b/source/slang/type-layout.h
@@ -403,9 +403,6 @@ enum class ShaderParameterKind
StructuredBuffer,
MutableStructuredBuffer,
- SampledBuffer,
- MutableSampledBuffer,
-
RawBuffer,
MutableRawBuffer,