summaryrefslogtreecommitdiffstats
path: root/tools/render-test
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-03-05 14:53:44 -0500
committerGitHub <noreply@github.com>2019-03-05 14:53:44 -0500
commit3d5546600fb4c585b6f6f6dcdb5e122698d1225e (patch)
treea11fc783760fd6e4b03c05b40fd4ff2f11c582da /tools/render-test
parent890403f576a85a7dca90d9d20360cd73c9ec9604 (diff)
Hotfix/texture2d gather (#876)
* First pass test to see if GatherRed works. * Add support for generating R_Float32 textures. * Set default texture format. * * Alter the texture2d-gather to work with a R_Float32 texture * Add support for scalar Texture2d types with GatherXXX in stdlib * Remove some left over commented out test code from texture2d-gather.hlsl
Diffstat (limited to 'tools/render-test')
-rw-r--r--tools/render-test/shader-input-layout.cpp70
-rw-r--r--tools/render-test/shader-input-layout.h7
-rw-r--r--tools/render-test/shader-renderer-util.cpp5
3 files changed, 77 insertions, 5 deletions
diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp
index 5a2021b01..6d51a1980 100644
--- a/tools/render-test/shader-input-layout.cpp
+++ b/tools/render-test/shader-input-layout.cpp
@@ -208,10 +208,25 @@ namespace renderer_test
}
else if(word == "format")
{
+ Format format = Format::Unknown;
+
parser.Read("=");
auto formatWord = parser.ReadWord();
if(formatWord == "R_UInt32")
- entry.bufferDesc.format = Format::R_UInt32;
+ {
+ format = Format::R_UInt32;
+ }
+ else if (formatWord == "R_Float32")
+ {
+ format = Format::R_Float32;
+ }
+ else if (formatWord == "RGBA_Unorm_UInt8")
+ {
+ format = Format::RGBA_Unorm_UInt8;
+ }
+
+ entry.textureDesc.format = format;
+ entry.bufferDesc.format = format;
}
if (parser.LookAhead(","))
parser.Read(",");
@@ -265,15 +280,64 @@ namespace renderer_test
}
}
}
+ }
+
+ void generateTextureData(TextureData& output, const InputTextureDesc& desc)
+ {
+ switch (desc.format)
+ {
+ case Format::RGBA_Unorm_UInt8:
+ {
+ generateTextureDataRGB8(output, desc);
+ break;
+ }
+ case Format::R_Float32:
+ {
+ TextureData work;
+ generateTextureDataRGB8(work, desc);
+ output.textureSize = work.textureSize;
+ output.mipLevels = work.mipLevels;
+ output.arraySize = work.arraySize;
+ List<List<unsigned int>>& dstBuffer = output.dataBuffer;
+
+ int numMips = int(work.dataBuffer.Count());
+ dstBuffer.SetSize(numMips);
+
+ for (int i = 0; i < numMips; ++i)
+ {
+ const int numPixels = int(work.dataBuffer[i].Count());
+ const unsigned int* srcPixels = work.dataBuffer[i].Buffer();
+
+ dstBuffer[i].SetSize(numPixels);
+
+ float* dstPixels = (float*)dstBuffer[i].Buffer();
+
+ for (int j = 0; j < numPixels; ++j)
+ {
+ // Copy out red
+ const unsigned int srcPixel = srcPixels[j];
+ const float value = (srcPixel & 0xff) * 1.0f / 255;
+ dstPixels[j] = value;
+ }
+ }
+ break;
+ }
+ default:
+ {
+ SLANG_ASSERT(!"Unhandled format");
+ break;
+ }
+ }
}
- void generateTextureData(TextureData & output, const InputTextureDesc & inputDesc)
+
+ void generateTextureDataRGB8(TextureData& output, const InputTextureDesc& inputDesc)
{
int arrLen = inputDesc.arrayLength;
if (arrLen == 0)
arrLen = 1;
- List<List<unsigned int>> & dataBuffer = output.dataBuffer;
+ List<List<unsigned int>>& dataBuffer = output.dataBuffer;
int arraySize = arrLen;
if (inputDesc.isCube)
arraySize *= 6;
diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h
index 1044a6eea..d9188fadd 100644
--- a/tools/render-test/shader-input-layout.h
+++ b/tools/render-test/shader-input-layout.h
@@ -27,6 +27,9 @@ struct InputTextureDesc
bool isDepthTexture = false;
bool isRWTexture = false;
int size = 4;
+
+ Format format = Format::RGBA_Unorm_UInt8;
+
InputTextureContent content = InputTextureContent::One;
};
@@ -80,7 +83,9 @@ public:
void Parse(const char * source);
};
-void generateTextureData(TextureData & output, const InputTextureDesc & desc);
+void generateTextureDataRGB8(TextureData& output, const InputTextureDesc& desc);
+void generateTextureData(TextureData& output, const InputTextureDesc& desc);
+
} // namespace render_test
diff --git a/tools/render-test/shader-renderer-util.cpp b/tools/render-test/shader-renderer-util.cpp
index 0d0f8a3a5..3dc717c5b 100644
--- a/tools/render-test/shader-renderer-util.cpp
+++ b/tools/render-test/shader-renderer-util.cpp
@@ -28,7 +28,10 @@ void BindingStateImpl::apply(Renderer* renderer, PipelineType pipelineType)
TextureResource::Desc textureResourceDesc;
textureResourceDesc.init(Resource::Type::Unknown);
- textureResourceDesc.format = Format::RGBA_Unorm_UInt8;
+ // Default to RGBA_Unorm_UInt8
+ const Format format = (inputDesc.format == Format::Unknown) ? Format::RGBA_Unorm_UInt8 : inputDesc.format;
+
+ textureResourceDesc.format = format;
textureResourceDesc.numMipLevels = texData.mipLevels;
textureResourceDesc.arraySize = inputDesc.arrayLength;
textureResourceDesc.bindFlags = bindFlags;