diff options
| author | Yong He <yonghe@outlook.com> | 2021-01-19 09:10:15 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-19 09:10:15 -0800 |
| commit | c6fd4a5b35911f0f056f6e924a2dbc86e328cc46 (patch) | |
| tree | f89f84633ab9c66a8a96c87ae77e6c47e4ab6a29 | |
| parent | 1296c7bb55b14db24308f31cacdda7f7a71fc937 (diff) | |
Make `ShaderCursor` no longer depend on core. (#1661)
| -rw-r--r-- | tools/gfx-util/shader-cursor.cpp | 39 | ||||
| -rw-r--r-- | tools/gfx-util/shader-cursor.h | 27 | ||||
| -rw-r--r-- | tools/gfx/vulkan/render-vk.cpp | 12 | ||||
| -rw-r--r-- | tools/render-test/render-test-main.cpp | 12 |
4 files changed, 37 insertions, 53 deletions
diff --git a/tools/gfx-util/shader-cursor.cpp b/tools/gfx-util/shader-cursor.cpp index 65cf2f8ac..f80803bdd 100644 --- a/tools/gfx-util/shader-cursor.cpp +++ b/tools/gfx-util/shader-cursor.cpp @@ -20,7 +20,7 @@ Result gfx::ShaderCursor::getDereferenced(ShaderCursor& outCursor) const } } -Result ShaderCursor::getField(Slang::UnownedStringSlice const& name, ShaderCursor& outCursor) +Result ShaderCursor::getField(const char* name, const char* nameEnd, ShaderCursor& outCursor) { // If this cursor is invalid, then can't possible fetch a field. // @@ -40,7 +40,7 @@ Result ShaderCursor::getField(Slang::UnownedStringSlice const& name, ShaderCurso // // If there is no such field, we have an error. // - SlangInt fieldIndex = m_typeLayout->findFieldIndexByName(name.begin(), name.end()); + SlangInt fieldIndex = m_typeLayout->findFieldIndexByName(name, nameEnd); if (fieldIndex == -1) return SLANG_E_INVALID_ARG; @@ -110,7 +110,7 @@ Result ShaderCursor::getField(Slang::UnownedStringSlice const& name, ShaderCurso // to the *contents* of the constant buffer. // ShaderCursor d = getDereferenced(); - return d.getField(name, outCursor); + return d.getField(name, nameEnd, outCursor); } break; } @@ -118,7 +118,7 @@ Result ShaderCursor::getField(Slang::UnownedStringSlice const& name, ShaderCurso return SLANG_E_INVALID_ARG; } -ShaderCursor ShaderCursor::getElement(Slang::Index index) +ShaderCursor ShaderCursor::getElement(SlangInt index) { // TODO: need to auto-dereference various buffer types... @@ -140,27 +140,25 @@ ShaderCursor ShaderCursor::getElement(Slang::Index index) } -static int _peek(Slang::UnownedStringSlice const& slice) +static int _peek(const char* slice) { - const char* b = slice.begin(); - const char* e = slice.end(); - if (b == e) + const char* b = slice; + if (!b || !*b) return -1; return *b; } -static int _get(Slang::UnownedStringSlice& slice) +static int _get(const char*& slice) { - const char* b = slice.begin(); - const char* e = slice.end(); - if (b == e) + const char* b = slice; + if (!b || !*b) return -1; auto result = *b++; - slice = Slang::UnownedStringSlice(b, e); + slice = b; return result; } -Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCursor& ioCursor) +Result ShaderCursor::followPath(const char* path, ShaderCursor& ioCursor) { ShaderCursor cursor = ioCursor; @@ -172,7 +170,7 @@ Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCur }; int state = ALLOW_NAME | ALLOW_SUBSCRIPT; - Slang::UnownedStringSlice rest = path; + const char* rest = path; for (;;) { int c = _peek(rest); @@ -194,7 +192,7 @@ Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCur return SLANG_E_INVALID_ARG; _get(rest); - Slang::Index index = 0; + SlangInt index = 0; while (_peek(rest) != ']') { int d = _get(rest); @@ -218,7 +216,7 @@ Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCur } else { - const char* nameBegin = rest.begin(); + const char* nameBegin = rest; for (;;) { switch (_peek(rest)) @@ -234,9 +232,10 @@ Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCur } break; } - char const* nameEnd = rest.begin(); - Slang::UnownedStringSlice name(nameBegin, nameEnd); - cursor = cursor.getField(name); + char const* nameEnd = rest; + ShaderCursor newCursor; + cursor.getField(nameBegin, nameEnd, newCursor); + cursor = newCursor; state = ALLOW_DOT | ALLOW_SUBSCRIPT; continue; } diff --git a/tools/gfx-util/shader-cursor.h b/tools/gfx-util/shader-cursor.h index 82794be9a..3f5cfb090 100644 --- a/tools/gfx-util/shader-cursor.h +++ b/tools/gfx-util/shader-cursor.h @@ -1,7 +1,6 @@ #pragma once #include "tools/gfx/render.h" -#include "core/slang-basic.h" namespace gfx { @@ -54,34 +53,20 @@ struct ShaderCursor /// points at. /// /// If the operation succeeds, then the field cursor is written to `outCursor`. - Result getField(Slang::UnownedStringSlice const& name, ShaderCursor& outCursor); + Result getField(const char* nameBegin, const char* nameEnd, ShaderCursor& outCursor); - ShaderCursor getField(Slang::UnownedStringSlice const& name) + ShaderCursor getField(const char* name) { ShaderCursor cursor; - getField(name, cursor); + getField(name, nullptr, cursor); return cursor; } - ShaderCursor getField(Slang::String const& name) { return getField(name.getUnownedSlice()); } + ShaderCursor getElement(SlangInt index); - ShaderCursor getElement(Slang::Index index); + static Result followPath(const char* path, ShaderCursor& ioCursor); - static Result followPath(Slang::UnownedStringSlice const& path, ShaderCursor& ioCursor); - - static Result followPath(Slang::String const& path, ShaderCursor& ioCursor) - { - return followPath(path.getUnownedSlice(), ioCursor); - } - - ShaderCursor getPath(Slang::UnownedStringSlice const& path) - { - ShaderCursor result(*this); - followPath(path, result); - return result; - } - - ShaderCursor getPath(Slang::String const& path) + ShaderCursor getPath(const char* path) { ShaderCursor result(*this); followPath(path, result); diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index 382f12f85..4e43bf249 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -1723,8 +1723,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT { const TextureResource::Size mipSize = desc.size.calcMipSize(j); - const int rowSizeInBytes = calcRowSize(desc.format, mipSize.width); - const int numRows = calcNumRows(desc.format, mipSize.height); + auto rowSizeInBytes = calcRowSize(desc.format, mipSize.width); + auto numRows = calcNumRows(desc.format, mipSize.height); mipSizes.add(mipSize); @@ -1754,8 +1754,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT const auto& mipSize = mipSizes[j]; const ptrdiff_t srcRowStride = initData->mipRowStrides[j]; - const int dstRowSizeInBytes = calcRowSize(desc.format, mipSize.width); - const int numRows = calcNumRows(desc.format, mipSize.height); + auto dstRowSizeInBytes = calcRowSize(desc.format, mipSize.width); + auto numRows = calcNumRows(desc.format, mipSize.height); for (int k = 0; k < mipSize.depth; k++) { @@ -1787,8 +1787,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT { const auto& mipSize = mipSizes[j]; - const int rowSizeInBytes = calcRowSize(desc.format, mipSize.width); - const int numRows = calcNumRows(desc.format, mipSize.height); + auto rowSizeInBytes = calcRowSize(desc.format, mipSize.width); + auto numRows = calcNumRows(desc.format, mipSize.height); // https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkBufferImageCopy.html // bufferRowLength and bufferImageHeight specify the data in buffer memory as a subregion of a larger two- or three-dimensional image, diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp index 184373f0c..926887a77 100644 --- a/tools/render-test/render-test-main.cpp +++ b/tools/render-test/render-test-main.cpp @@ -190,13 +190,13 @@ SlangResult _assignVarsFromLayout( return SLANG_E_INVALID_ARG; } - auto entryCursor = rootCursor.getPath(entry.name); + auto entryCursor = rootCursor.getPath(entry.name.getBuffer()); if(!entryCursor.isValid()) { for(gfx::UInt i = 0; i < shaderObject->getEntryPointCount(); i++) { - entryCursor = ShaderCursor(shaderObject->getEntryPoint(i)).getPath(entry.name); + entryCursor = ShaderCursor(shaderObject->getEntryPoint(i)).getPath(entry.name.getBuffer()); if(entryCursor.isValid()) break; } @@ -839,10 +839,10 @@ Result RenderTestApp::writeScreen(const char* filename) size_t width = rowPitch / pixelSize; size_t height = bufferSize / rowPitch; surface.setUnowned( - width, - height, + (int)width, + (int)height, gfx::Format::RGBA_Unorm_UInt8, - rowPitch, + (int)rowPitch, buffer.getBuffer()); return PngSerializeUtil::write(filename, surface); } @@ -1286,7 +1286,7 @@ static SlangResult _innerMain(Slang::StdWriters* stdWriters, SlangSession* sessi for (auto & name : options.renderFeatures) requiredFeatureList.add(name.getBuffer()); desc.requiredFeatures = requiredFeatureList.getBuffer(); - desc.requiredFeatureCount = requiredFeatureList.getCount(); + desc.requiredFeatureCount = (int)requiredFeatureList.getCount(); desc.nvapiExtnSlot = int(nvapiExtnSlot); window = renderer_test::Window::create(); |
