summaryrefslogtreecommitdiff
path: root/source/slang/type-defs.h
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/slang/type-defs.h
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/slang/type-defs.h')
-rw-r--r--source/slang/type-defs.h49
1 files changed, 26 insertions, 23 deletions
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)