summaryrefslogtreecommitdiffstats
path: root/tools/gfx-unit-test
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gfx-unit-test')
-rw-r--r--tools/gfx-unit-test/clear-texture-test.cpp2
-rw-r--r--tools/gfx-unit-test/format-unit-tests.cpp10
-rw-r--r--tools/gfx-unit-test/get-buffer-resource-handle-test.cpp3
-rw-r--r--tools/gfx-unit-test/get-supported-resource-states-test.cpp6
-rw-r--r--tools/gfx-unit-test/root-shader-parameter.cpp2
-rw-r--r--tools/gfx-unit-test/sampler-array.cpp160
-rw-r--r--tools/gfx-unit-test/sampler-array.slang32
7 files changed, 207 insertions, 8 deletions
diff --git a/tools/gfx-unit-test/clear-texture-test.cpp b/tools/gfx-unit-test/clear-texture-test.cpp
index 13db72402..4ad82f313 100644
--- a/tools/gfx-unit-test/clear-texture-test.cpp
+++ b/tools/gfx-unit-test/clear-texture-test.cpp
@@ -41,6 +41,8 @@ namespace gfx_test
rtvDesc.type = IResourceView::Type::RenderTarget;
rtvDesc.format = Format::R32G32B32A32_FLOAT;
rtvDesc.renderTarget.shape = IResource::Type::Texture2D;
+ rtvDesc.subresourceRange.layerCount = 1;
+ rtvDesc.subresourceRange.mipLevelCount = 1;
rtv = device->createTextureView(srcTexture, rtvDesc);
{
diff --git a/tools/gfx-unit-test/format-unit-tests.cpp b/tools/gfx-unit-test/format-unit-tests.cpp
index 1a885174f..8d3d07221 100644
--- a/tools/gfx-unit-test/format-unit-tests.cpp
+++ b/tools/gfx-unit-test/format-unit-tests.cpp
@@ -209,8 +209,8 @@ namespace gfx_test
0.0f, 0.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f, 1.0f));
}
- // Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this test.
- if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
+ // Ignore this test since it is not supported by swiftshader and nvidia's driver.
+ if (false)
{
float texData[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.5f };
@@ -351,8 +351,8 @@ namespace gfx_test
0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u));
}
- // Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this test.
- if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
+ // Ignore this test since validation layer reports that it is unsupported.
+ if (false)
{
uint32_t texData[] = { 255u, 0u, 0u, 0u, 255u, 0u,
0u, 0u, 255u, 127u, 127u, 127u };
@@ -488,7 +488,7 @@ namespace gfx_test
}
// Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this test.
- if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
+ if (false)
{
int32_t texData[] = { 255, 0, 0, 0, 255, 0,
0, 0, 255, 127, 127, 127 };
diff --git a/tools/gfx-unit-test/get-buffer-resource-handle-test.cpp b/tools/gfx-unit-test/get-buffer-resource-handle-test.cpp
index dc0da830a..36b6b3cad 100644
--- a/tools/gfx-unit-test/get-buffer-resource-handle-test.cpp
+++ b/tools/gfx-unit-test/get-buffer-resource-handle-test.cpp
@@ -16,7 +16,6 @@ namespace gfx_test
void getBufferResourceHandleTestImpl(IDevice* device, UnitTestContext* context)
{
const int numberCount = 1;
- float initialData[] = { 0.0f };
IBufferResource::Desc bufferDesc = {};
bufferDesc.sizeInBytes = numberCount * sizeof(float);
bufferDesc.format = gfx::Format::Unknown;
@@ -32,7 +31,7 @@ namespace gfx_test
ComPtr<IBufferResource> buffer;
GFX_CHECK_CALL_ABORT(device->createBufferResource(
bufferDesc,
- (void*)initialData,
+ nullptr,
buffer.writeRef()));
InteropHandle handle;
diff --git a/tools/gfx-unit-test/get-supported-resource-states-test.cpp b/tools/gfx-unit-test/get-supported-resource-states-test.cpp
index d1573d3fd..209cf1ba5 100644
--- a/tools/gfx-unit-test/get-supported-resource-states-test.cpp
+++ b/tools/gfx-unit-test/get-supported-resource-states-test.cpp
@@ -112,6 +112,12 @@ namespace
for (uint32_t i = 1; i < (uint32_t)Format::CountOf; ++i)
{
auto baseFormat = (Format)i;
+ FormatInfo info;
+ gfxGetFormatInfo(baseFormat, &info);
+ // Ignore 3-channel textures for now since validation layer seem to report unsupported errors there.
+ if (info.channelCount == 3)
+ continue;
+
auto format = gfxIsTypelessFormat(baseFormat) ? convertTypelessFormat(baseFormat) : baseFormat;
GFX_CHECK_CALL_ABORT(device->getFormatSupportedResourceStates(format, &formatSupportedStates));
diff --git a/tools/gfx-unit-test/root-shader-parameter.cpp b/tools/gfx-unit-test/root-shader-parameter.cpp
index a7b92843d..b01cb62f3 100644
--- a/tools/gfx-unit-test/root-shader-parameter.cpp
+++ b/tools/gfx-unit-test/root-shader-parameter.cpp
@@ -9,7 +9,7 @@ using namespace gfx;
namespace gfx_test
{
- ComPtr<IBufferResource> createBuffer(IDevice* device, uint32_t content)
+ static ComPtr<IBufferResource> createBuffer(IDevice* device, uint32_t content)
{
ComPtr<IBufferResource> buffer;
IBufferResource::Desc bufferDesc = {};
diff --git a/tools/gfx-unit-test/sampler-array.cpp b/tools/gfx-unit-test/sampler-array.cpp
new file mode 100644
index 000000000..58e48e13d
--- /dev/null
+++ b/tools/gfx-unit-test/sampler-array.cpp
@@ -0,0 +1,160 @@
+#include "tools/unit-test/slang-unit-test.h"
+
+#include "slang-gfx.h"
+#include "gfx-test-util.h"
+#include "tools/gfx-util/shader-cursor.h"
+#include "source/core/slang-basic.h"
+
+using namespace gfx;
+
+namespace gfx_test
+{
+ static ComPtr<IBufferResource> createBuffer(IDevice* device, uint32_t content)
+ {
+ ComPtr<IBufferResource> buffer;
+ IBufferResource::Desc bufferDesc = {};
+ bufferDesc.sizeInBytes = sizeof(uint32_t);
+ bufferDesc.format = gfx::Format::Unknown;
+ bufferDesc.elementSize = sizeof(float);
+ bufferDesc.allowedStates = ResourceStateSet(
+ ResourceState::ShaderResource,
+ ResourceState::UnorderedAccess,
+ ResourceState::CopyDestination,
+ ResourceState::CopySource);
+ bufferDesc.defaultState = ResourceState::UnorderedAccess;
+ bufferDesc.memoryType = MemoryType::DeviceLocal;
+
+ ComPtr<IBufferResource> numbersBuffer;
+ GFX_CHECK_CALL_ABORT(
+ device->createBufferResource(bufferDesc, (void*)&content, buffer.writeRef()));
+
+ return buffer;
+ }
+ void samplerArrayTestImpl(IDevice* device, UnitTestContext* context)
+ {
+ Slang::ComPtr<ITransientResourceHeap> transientHeap;
+ ITransientResourceHeap::Desc transientHeapDesc = {};
+ transientHeapDesc.constantBufferSize = 4096;
+ GFX_CHECK_CALL_ABORT(
+ device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef()));
+
+ ComPtr<IShaderProgram> shaderProgram;
+ slang::ProgramLayout* slangReflection;
+ GFX_CHECK_CALL_ABORT(loadComputeProgram(device, shaderProgram, "sampler-array", "computeMain", slangReflection));
+
+ ComputePipelineStateDesc pipelineDesc = {};
+ pipelineDesc.program = shaderProgram.get();
+ ComPtr<gfx::IPipelineState> pipelineState;
+ GFX_CHECK_CALL_ABORT(
+ device->createComputePipelineState(pipelineDesc, pipelineState.writeRef()));
+
+ Slang::List<ComPtr<ISamplerState>> samplers;
+ Slang::List<ComPtr<IResourceView>> srvs;
+ ComPtr<IResourceView> uav;
+ ComPtr<ITextureResource> texture;
+ ComPtr<IBufferResource> buffer = createBuffer(device, 0);
+
+ {
+ IResourceView::Desc viewDesc = {};
+ viewDesc.type = IResourceView::Type::UnorderedAccess;
+ viewDesc.format = Format::Unknown;
+ GFX_CHECK_CALL_ABORT(
+ device->createBufferView(buffer, nullptr, viewDesc, uav.writeRef()));
+ }
+ {
+ ITextureResource::Desc textureDesc = {};
+ textureDesc.type = IResource::Type::Texture2D;
+ textureDesc.format = Format::R8G8B8A8_UNORM;
+ textureDesc.size.width = 2;
+ textureDesc.size.height = 2;
+ textureDesc.size.depth = 1;
+ textureDesc.numMipLevels = 2;
+ textureDesc.memoryType = MemoryType::DeviceLocal;
+ textureDesc.defaultState = ResourceState::ShaderResource;
+ textureDesc.allowedStates.add(ResourceState::CopyDestination);
+ uint32_t data[] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
+ ITextureResource::SubresourceData subResourceData[2] = {{data, 8, 16}, {data, 8, 16}};
+ GFX_CHECK_CALL_ABORT(
+ device->createTextureResource(textureDesc, subResourceData, texture.writeRef()));
+ }
+ for (uint32_t i = 0; i < 32; i++)
+ {
+ ComPtr<IResourceView> srv;
+ IResourceView::Desc viewDesc = {};
+ viewDesc.type = IResourceView::Type::ShaderResource;
+ viewDesc.format = Format::R8G8B8A8_UNORM;
+ viewDesc.subresourceRange.layerCount = 1;
+ viewDesc.subresourceRange.mipLevelCount = 1;
+ GFX_CHECK_CALL_ABORT(
+ device->createTextureView(texture, viewDesc, srv.writeRef()));
+ srvs.add(srv);
+ }
+
+ for (uint32_t i = 0; i < 32; i++)
+ {
+ ISamplerState::Desc desc = {};
+ ComPtr<ISamplerState> sampler;
+ GFX_CHECK_CALL_ABORT(device->createSamplerState(desc, sampler.writeRef()));
+ samplers.add(sampler);
+ }
+
+ ComPtr<IShaderObject> rootObject;
+ device->createMutableRootShaderObject(shaderProgram, rootObject.writeRef());
+
+ ComPtr<IShaderObject> g;
+ device->createMutableShaderObject(
+ slangReflection->findTypeByName("S0"), ShaderObjectContainerType::None, g.writeRef());
+
+ ComPtr<IShaderObject> s1;
+ device->createMutableShaderObject(
+ slangReflection->findTypeByName("S1"), ShaderObjectContainerType::None, s1.writeRef());
+
+ {
+ auto cursor = ShaderCursor(s1);
+ for (uint32_t i = 0; i < 32; i++)
+ {
+ cursor["samplers"][i].setSampler(samplers[i]);
+ cursor["tex"][i].setResource(srvs[i]);
+ }
+ cursor["data"].setData(1.0f);
+ }
+
+ {
+ auto cursor = ShaderCursor(g);
+ cursor["s"].setObject(s1);
+ cursor["data"].setData(2.0f);
+ }
+
+ {
+ auto cursor = ShaderCursor(rootObject);
+ cursor["g"].setObject(g);
+ cursor["buffer"].setResource(uav);
+ }
+
+ {
+ ICommandQueue::Desc queueDesc = { ICommandQueue::QueueType::Graphics };
+ auto queue = device->createCommandQueue(queueDesc);
+
+ auto commandBuffer = transientHeap->createCommandBuffer();
+ {
+ auto encoder = commandBuffer->encodeComputeCommands();
+ auto root = encoder->bindPipeline(pipelineState);
+ root->copyFrom(rootObject, transientHeap);
+ encoder->dispatchCompute(1, 1, 1);
+ encoder->endEncoding();
+ }
+
+ commandBuffer->close();
+ queue->executeCommandBuffer(commandBuffer);
+ queue->waitOnHost();
+ }
+
+ compareComputeResult(
+ device, buffer, Slang::makeArray<float>(4.0f));
+ }
+
+ SLANG_UNIT_TEST(samplerArrayVulkan)
+ {
+ runTestImpl(samplerArrayTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan);
+ }
+}
diff --git a/tools/gfx-unit-test/sampler-array.slang b/tools/gfx-unit-test/sampler-array.slang
new file mode 100644
index 000000000..1439f6cdd
--- /dev/null
+++ b/tools/gfx-unit-test/sampler-array.slang
@@ -0,0 +1,32 @@
+// sampler-array.slang
+
+// Test sampler array parameters.
+
+struct S1
+{
+ Texture2D tex[32];
+ SamplerState samplers[32];
+ float data;
+ float test(int i)
+ {
+ return tex[i].SampleLevel(samplers[i], float2(0.0, 0.0), 0.0).x + data;
+ }
+}
+
+struct S0
+{
+ float data;
+ RaytracingAccelerationStructure acc;
+ ParameterBlock<S1> s;
+}
+
+ParameterBlock<S0> g;
+RWStructuredBuffer<float> buffer;
+
+[shader("compute")]
+[numthreads(1,1,1)]
+void computeMain(
+ uint3 sv_dispatchThreadID : SV_DispatchThreadID)
+{
+ buffer[0] = g.data * g.s.test(sv_dispatchThreadID.x);
+}