From 1027225ac7ec8da0e471b633f358333c8a95b010 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Sat, 15 May 2021 10:52:55 -0400 Subject: Support for HW format conversions for RWTexture on CUDA (#1840) * #include an absolute path didn't work - because paths were taken to always be relative. * Fix for writing to RWTexture with half types on CUDA. * CUDA half functionality doc updates. * First pass support for sust.p RWTexture format conversion on write. * Tidy up implementation of $C. Made clamping mode #define able. * A simple test for RWTexture CUDA format conversion. --- source/slang/slang-syntax.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'source/slang/slang-syntax.cpp') diff --git a/source/slang/slang-syntax.cpp b/source/slang/slang-syntax.cpp index d5f2c13db..6b2140056 100644 --- a/source/slang/slang-syntax.cpp +++ b/source/slang/slang-syntax.cpp @@ -1186,38 +1186,40 @@ Module* getModule(Decl* decl) return moduleDecl->module; } -bool findImageFormatByName(char const* name, ImageFormat* outFormat) +static const ImageFormatInfo kImageFormatInfos[] = { - static const struct - { - char const* name; - ImageFormat format; - } kFormats[] = - { -#define FORMAT(NAME) { #NAME, ImageFormat::NAME }, +#define SLANG_IMAGE_FORMAT_INFO(TYPE, COUNT, SIZE) SLANG_SCALAR_TYPE_##TYPE, uint8_t(COUNT), uint8_t(SIZE) +#define FORMAT(NAME, OTHER) \ + { SLANG_IMAGE_FORMAT_INFO OTHER, UnownedStringSlice::fromLiteral(#NAME) }, #include "slang-image-format-defs.h" - }; +#undef FORMAT +#undef SLANG_IMAGE_FORMAT_INFO +}; - for( auto item : kFormats ) +bool findImageFormatByName(char const* inName, ImageFormat* outFormat) +{ + const UnownedStringSlice name(inName); + + for (Index i = 0; i < SLANG_COUNT_OF(kImageFormatInfos); ++i) { - if( strcmp(item.name, name) == 0 ) + const auto& info = kImageFormatInfos[i]; + if (info.name == name) { - *outFormat = item.format; + *outFormat = ImageFormat(i); return true; } } - return false; } char const* getGLSLNameForImageFormat(ImageFormat format) { - switch( format ) - { - default: return "unhandled"; -#define FORMAT(NAME) case ImageFormat::NAME: return #NAME; -#include "slang-image-format-defs.h" - } + return kImageFormatInfos[Index(format)].name.begin(); } + const ImageFormatInfo& getImageFormatInfo(ImageFormat format) + { + return kImageFormatInfos[Index(format)]; + } + } // namespace Slang -- cgit v1.2.3