From 2c2294d3310b24fd73cd41ec51338a736f3a2886 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 5 Sep 2023 23:26:59 +0800 Subject: SPIR-V image operations (#3163) * Add __truncate and __sampledType for spirv_asm Allows some texture tests to start passing * add __isVector Currently unused * Add 1-vector legalization pass (WIP) * Add capabilities for image types * neaten instruction dumping * add 1-vector test * Add a couple of cases to vec1 legalization * Remove texture tests from expected failures * comment * regenerate vs projects * Remove redundant define form synchapi emulation * refactoring image methods * All sample functions refactored * Remove incorrect glsl intrinsics Partially addresses https://github.com/shader-slang/slang/issues/3174 * __subscript image ops via writing funcs * Extract texture struct writing from core.meta.slang * Abstract out cuda intrinsic * Remvoe erroneous call to opDecorateIndex * spirv asm IR utils * Correct position of loads for SPIR-V asm inst operands * Raise constructors to global scope during spir-v legalization * Correct snippet output * Implement most texture sampling ops for SPIR-V * Legalize 1-vectors for glsl too * Make SPIR-V inst operands non-hoistable * Better 1-vector legalization * Put textures in ptrs for spirv * insert missing break * Add vec1 legalization test * Add some missing pieces to slang-ir-insts * Greatly neaten vec1 legalization * a * Neaten vec1 legalization * Add image read and write intrinsics for spir-v * Squash warnings * regenerate vs projects * Drop redundant guards * Drop 5 tests from expected failure list * Inst numbering changes to cross compile tests * vec1 legalization tests only on vk * Correct location of asm op emit * Inline constant in spirv-asm * Correct signedness for lane in wave intrinsics * Extract element from float1 for cuda * squash warnings * Neaten spirv-emit * dedupe more capabilities * warnings * neaten assert * comments * comments --- source/slang/slang-stdlib-textures.h | 112 +++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 source/slang/slang-stdlib-textures.h (limited to 'source/slang/slang-stdlib-textures.h') diff --git a/source/slang/slang-stdlib-textures.h b/source/slang/slang-stdlib-textures.h new file mode 100644 index 000000000..19008a3f0 --- /dev/null +++ b/source/slang/slang-stdlib-textures.h @@ -0,0 +1,112 @@ +#pragma once + +#include "slang-ir.h" +#include "slang-type-system-shared.h" +#include "../core/slang-string.h" + +namespace Slang +{ + +static const struct BaseTextureShapeInfo { + char const* shapeName; + TextureFlavor::Shape baseShape; + int coordCount; +} kBaseTextureShapes[] = { + { "1D", TextureFlavor::Shape::Shape1D, 1 }, + { "2D", TextureFlavor::Shape::Shape2D, 2 }, + { "3D", TextureFlavor::Shape::Shape3D, 3 }, + { "Cube", TextureFlavor::Shape::ShapeCube,3 }, +}; + +static const struct BaseTextureAccessInfo { + char const* name; + SlangResourceAccess access; +} kBaseTextureAccessLevels[] = { + { "", SLANG_RESOURCE_ACCESS_READ }, + { "RW", SLANG_RESOURCE_ACCESS_READ_WRITE }, + { "RasterizerOrdered", SLANG_RESOURCE_ACCESS_RASTER_ORDERED }, +}; + +static const struct TextureTypePrefixInfo +{ + char const* name; + bool combined; +} kTexturePrefixes[] = +{ + { "Texture", false }, + { "Sampler", true }, +}; + +struct TextureTypeInfo +{ + TextureTypeInfo( + TextureTypePrefixInfo const& prefixInfo, + BaseTextureShapeInfo const& base, + bool isArray, + bool isMultisample, + BaseTextureAccessInfo const& accessInfo, + StringBuilder& inSB, + String const& inPath); + + TextureTypePrefixInfo const& prefixInfo; + BaseTextureShapeInfo const& base; + bool isArray; + bool isMultisample; + BaseTextureAccessInfo const& accessInfo; + StringBuilder& sb; + String path; + + void emitTypeDecl(); + +private: + // + // Functions for writing specific parts of a definition + // + void writeQueryFunctions(); + void writeSubscriptFunctions(); + void writeSampleFunctions(); + void writeGatherExtensions(); + + // + // More general utilities + // + enum class ReadNoneMode + { + Never, + IfReadOnly, + Always + }; + + void writeFuncBody( + const char* funcName, + const String& glsl, + const String& cuda, + const String& spirv + ); + void writeFuncDecorations( + const String& glsl, + const String& cuda + ); + void writeFuncWithSig( + const char* funcName, + const String& sig, + const String& glsl = String{}, + const String& spirv = String{}, + const String& cuda = String{}, + const ReadNoneMode readNoneMode = ReadNoneMode::IfReadOnly + ); + void writeFunc( + const char* returnType, + const char* funcName, + const String& params, + const String& glsl = String{}, + const String& spirv = String{}, + const String& cuda = String{}, + const ReadNoneMode readNoneMode = ReadNoneMode::IfReadOnly + ); + + // A pointer to a string representing the current level of indentation + const char* i; +}; + +} -- cgit v1.2.3