summaryrefslogtreecommitdiffstats
path: root/tools/render-test/shader-input-layout.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-01-29 09:02:55 -0500
committerGitHub <noreply@github.com>2020-01-29 09:02:55 -0500
commit58cea79d8622a08b0887dbfda8f8042e42679c8f (patch)
tree04c2e3e0ea1ec059b61e819987a2014e52050beb /tools/render-test/shader-input-layout.cpp
parent8b3e3beea66d9773adf11ea2e163577d649f3d7c (diff)
Feature/test for double behavior (#1186)
* Split out binding writing. * Pass in the entry type. * Take into account output type with -output-using-type Added GPULikeBindRoot Added dxbc-double-problem test. * Add the dxbc-double-problem test.
Diffstat (limited to 'tools/render-test/shader-input-layout.cpp')
-rw-r--r--tools/render-test/shader-input-layout.cpp178
1 files changed, 159 insertions, 19 deletions
diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp
index ee4f5fc2c..44021c08a 100644
--- a/tools/render-test/shader-input-layout.cpp
+++ b/tools/render-test/shader-input-layout.cpp
@@ -698,42 +698,182 @@ namespace renderer_test
}
}
-
- /* static */SlangResult ShaderInputLayout::writeBindings(const ShaderInputLayout& layout, const List<BindSet::Value*>& buffers, const String& fileName)
+ /* static */SlangResult ShaderInputLayout::writeBinding(BindRoot* bindRoot, const ShaderInputLayoutEntry& entry, const void* data, size_t sizeInBytes, WriterHelper writer)
{
- FILE * f = fopen(fileName.getBuffer(), "wb");
- if (!f)
+ typedef slang::TypeReflection::ScalarType ScalarType;
+
+ slang::TypeReflection::ScalarType scalarType = slang::TypeReflection::ScalarType::None;
+
+ slang::TypeLayoutReflection* typeLayout = nullptr;
+
+ if (bindRoot && entry.name.getLength())
{
- return SLANG_FAIL;
+ BindLocation location;
+ if (SLANG_SUCCEEDED(bindRoot->parse(entry.name, "", writer, location)))
+ {
+ // We should have the type of the item
+ typeLayout = location.m_typeLayout;
+ }
}
- const auto& entries = layout.entries;
+ slang::TypeLayoutReflection* elementTypeLayout = nullptr;
- for (int i = 0; i < entries.getCount(); ++i)
+ if (typeLayout)
{
- const auto& entry = entries[i];
- if (entry.isOutput)
+ switch (typeLayout->getKind())
{
- BindSet::Value* buffer = buffers[i];
+
+ //case slang::TypeReflection::Kind::Struct:
+ case slang::TypeReflection::Kind::Array:
+ case slang::TypeReflection::Kind::Matrix:
+ case slang::TypeReflection::Kind::Vector:
+ {
+ elementTypeLayout = typeLayout->getElementTypeLayout();
+ break;
+ }
+ case slang::TypeReflection::Kind::Scalar:
+ {
+ elementTypeLayout = typeLayout;
+ break;
+ }
+ case slang::TypeReflection::Kind::Resource:
+ {
+ elementTypeLayout = typeLayout->getElementTypeLayout();
+ break;
+ }
+ case slang::TypeReflection::Kind::TextureBuffer:
+ case slang::TypeReflection::Kind::ShaderStorageBuffer:
+ {
+ elementTypeLayout = typeLayout->getElementTypeLayout();
+ break;
+ }
+ }
+ }
- unsigned int* ptr = (unsigned int*)buffer->m_data;
+ if (elementTypeLayout)
+ {
+ scalarType = elementTypeLayout->getScalarType();
+ }
- const int size = int(entry.bufferData.getCount());
- // Must be the same size or less than allocated buffer
- SLANG_ASSERT(size * sizeof(unsigned int) <= buffer->m_sizeInBytes);
- for (int i = 0; i < size; ++i)
+ switch (scalarType)
+ {
+ // TODO(JS):
+ // Bool is here, because it's not clear across APIs how bool is laid out in memory
+ // Float16 is here as we don't have a convert Float16 to float function laying around
+ default:
+ case ScalarType::None:
+ case ScalarType::Void:
+ case ScalarType::Bool:
+ case ScalarType::Float16:
+ {
+ auto ptr = (const uint32_t*)data;
+ const size_t size = sizeInBytes / sizeof(ptr[0]);
+ for (size_t i = 0; i < size; ++i)
{
- unsigned int v = ptr[i];
-
- fprintf(f, "%X\n", v);
+ uint32_t v = ptr[i];
+ writer.print("%X\n", v);
+ }
+ break;
+ }
+ case ScalarType::UInt32:
+ {
+ auto ptr = (const uint32_t*)data;
+ const size_t size = sizeInBytes / sizeof(ptr[0]);
+ for (size_t i = 0; i < size; ++i)
+ {
+ uint32_t v = ptr[i];
+ writer.print("%u\n", v);
+ }
+ break;
+ }
+ case ScalarType::Int32:
+ {
+ auto ptr = (const int32_t*)data;
+ const size_t size = sizeInBytes / sizeof(ptr[0]);
+ for (size_t i = 0; i < size; ++i)
+ {
+ int32_t v = ptr[i];
+ writer.print("%i\n", v);
+ }
+ break;
+ }
+ case ScalarType::Int64:
+ {
+ auto ptr = (const int64_t*)data;
+ const size_t size = sizeInBytes / sizeof(ptr[0]);
+ for (size_t i = 0; i < size; ++i)
+ {
+ int64_t v = ptr[i];
+ writer.print("%" PRId64 "\n", v);
+ }
+ break;
+ }
+ case ScalarType::UInt64:
+ {
+ auto ptr = (const uint64_t*)data;
+ const size_t size = sizeInBytes / sizeof(ptr[0]);
+ for (size_t i = 0; i < size; ++i)
+ {
+ uint64_t v = ptr[i];
+ writer.print("%" PRIu64 "\n", v);
+ }
+ break;
+ }
+ case ScalarType::Float32:
+ {
+ auto ptr = (const float*)data;
+ const size_t size = sizeInBytes / sizeof(ptr[0]);
+ for (size_t i = 0; i < size; ++i)
+ {
+ const float v = ptr[i];
+ writer.print("%f\n", v);
}
+ break;
+ }
+ case ScalarType::Float64:
+ {
+ auto ptr = (const double*)data;
+ const size_t size = sizeInBytes / sizeof(ptr[0]);
+ for (size_t i = 0; i < size; ++i)
+ {
+ const double v = ptr[i];
+ writer.print("%f\n", v);
+ }
+ break;
}
}
- fclose(f);
+
return SLANG_OK;
}
+ /* static */SlangResult ShaderInputLayout::writeBindings(BindRoot* bindRoot, const ShaderInputLayout& layout, const List<BindSet::Value*>& buffers, WriterHelper writer)
+ {
+ const auto& entries = layout.entries;
+ for (int i = 0; i < entries.getCount(); ++i)
+ {
+ const auto& entry = entries[i];
+ if (entry.isOutput)
+ {
+ BindSet::Value* buffer = buffers[i];
+ writeBinding(bindRoot, entries[i], buffer->m_data, buffer->m_sizeInBytes, writer);
+ }
+ }
+
+ return SLANG_OK;
+ }
+
+ /* static */SlangResult ShaderInputLayout::writeBindings(BindRoot* bindRoot, const ShaderInputLayout& layout, const List<BindSet::Value*>& buffers, const String& fileName)
+ {
+ FILE * f = fopen(fileName.getBuffer(), "wb");
+ if (!f)
+ {
+ return SLANG_FAIL;
+ }
+ FileWriter fileWriter(f, WriterFlags(0));
+ return writeBindings(bindRoot, layout, buffers, &fileWriter);
+ }
+
void generateTextureData(TextureData& output, const InputTextureDesc& desc)
{
switch (desc.format)