summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-11-10 05:32:14 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-11-10 05:32:14 +0000
commitac6a8dd8fb1ee2b2b20733da7d421fce303d2d70 (patch)
tree80fb1ef85b6483edd2a627b2f96c961648e532d3
parentA bunch of minor updates (diff)
parentImplemented render pass input attachment test Metal reference (diff)
downloadDiligentCore-ac6a8dd8fb1ee2b2b20733da7d421fce303d2d70.tar.gz
DiligentCore-ac6a8dd8fb1ee2b2b20733da7d421fce303d2d70.zip
Merge branch 'master' into ray_tracing
# Conflicts: # Graphics/GraphicsEngine/interface/RenderDevice.h
-rw-r--r--Graphics/GraphicsEngine/interface/RenderDevice.h34
-rw-r--r--Graphics/GraphicsEngine/interface/Shader.h3
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp8
-rw-r--r--Graphics/GraphicsEngineOpenGL/interface/EngineFactoryOpenGL.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp9
-rw-r--r--Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp9
-rw-r--r--Tests/DiligentCoreAPITest/include/InlineShaders/ComputeShaderTestMSL.h61
-rw-r--r--Tests/DiligentCoreAPITest/include/InlineShaders/DrawCommandTestMSL.h109
-rw-r--r--Tests/DiligentCoreAPITest/include/Metal/TestingSwapChainMtl.hpp3
-rw-r--r--Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp69
-rw-r--r--Tests/DiligentCoreAPITest/src/ClearRenderTargetTest.cpp7
-rw-r--r--Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp12
-rw-r--r--Tests/DiligentCoreAPITest/src/Metal/ClearRenderTargetReferenceMtl.mm24
-rw-r--r--Tests/DiligentCoreAPITest/src/Metal/ComputeShaderReferenceMtl.mm37
-rw-r--r--Tests/DiligentCoreAPITest/src/Metal/DrawCommandReferenceMtl.mm241
-rw-r--r--Tests/DiligentCoreAPITest/src/Metal/TestingSwapChainMtl.mm32
-rw-r--r--Tests/DiligentCoreAPITest/src/RenderPassTest.cpp32
-rw-r--r--Tests/IncludeTest/GraphicsEngineD3D11/EngineFactoryD3D11H_test.c2
-rw-r--r--Tests/IncludeTest/GraphicsEngineD3D12/EngineFactoryD3D12H_test.c2
-rw-r--r--Tests/IncludeTest/GraphicsEngineOpenGL/EngineFactoryOpenGLH_test.c2
-rw-r--r--Tests/IncludeTest/GraphicsEngineVk/EngineFactoryVkH_test.c2
24 files changed, 584 insertions, 122 deletions
diff --git a/Graphics/GraphicsEngine/interface/RenderDevice.h b/Graphics/GraphicsEngine/interface/RenderDevice.h
index 49ab30e7..ac30d615 100644
--- a/Graphics/GraphicsEngine/interface/RenderDevice.h
+++ b/Graphics/GraphicsEngine/interface/RenderDevice.h
@@ -332,24 +332,24 @@ DILIGENT_END_INTERFACE
#if DILIGENT_C_INTERFACE
// clang-format off
-
-# define IRenderDevice_CreateBuffer(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateBuffer, This, __VA_ARGS__)
-# define IRenderDevice_CreateShader(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateShader, This, __VA_ARGS__)
-# define IRenderDevice_CreateTexture(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateTexture, This, __VA_ARGS__)
-# define IRenderDevice_CreateSampler(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateSampler, This, __VA_ARGS__)
-# define IRenderDevice_CreateResourceMapping(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateResourceMapping, This, __VA_ARGS__)
-# define IRenderDevice_CreateGraphicsPipelineState(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateGraphicsPipelineState, This, __VA_ARGS__)
-# define IRenderDevice_CreateComputePipelineState(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateComputePipelineState, This, __VA_ARGS__)
+# define IRenderDevice_CreateBuffer(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateBuffer, This, __VA_ARGS__)
+# define IRenderDevice_CreateShader(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateShader, This, __VA_ARGS__)
+# define IRenderDevice_CreateTexture(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateTexture, This, __VA_ARGS__)
+# define IRenderDevice_CreateSampler(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateSampler, This, __VA_ARGS__)
+# define IRenderDevice_CreateResourceMapping(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateResourceMapping, This, __VA_ARGS__)
+# define IRenderDevice_CreateGraphicsPipelineState(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateGraphicsPipelineState, This, __VA_ARGS__)
+# define IRenderDevice_CreateComputePipelineState(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateComputePipelineState, This, __VA_ARGS__)
# define IRenderDevice_CreateRayTracingPipelineState(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateRayTracingPipelineState, This, __VA_ARGS__)
-# define IRenderDevice_CreateFence(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateFence, This, __VA_ARGS__)
-# define IRenderDevice_CreateQuery(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateQuery, This, __VA_ARGS__)
-# define IRenderDevice_GetDeviceCaps(This) CALL_IFACE_METHOD(RenderDevice, GetDeviceCaps, This)
-# define IRenderDevice_GetTextureFormatInfo(This, ...) CALL_IFACE_METHOD(RenderDevice, GetTextureFormatInfo, This, __VA_ARGS__)
-# define IRenderDevice_GetTextureFormatInfoExt(This, ...) CALL_IFACE_METHOD(RenderDevice, GetTextureFormatInfoExt, This, __VA_ARGS__)
-# define IRenderDevice_ReleaseStaleResources(This, ...) CALL_IFACE_METHOD(RenderDevice, ReleaseStaleResources, This, __VA_ARGS__)
-# define IRenderDevice_IdleGPU(This) CALL_IFACE_METHOD(RenderDevice, IdleGPU, This)
-# define IRenderDevice_GetEngineFactory(This) CALL_IFACE_METHOD(RenderDevice, GetEngineFactory, This)
-
+# define IRenderDevice_CreateFence(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateFence, This, __VA_ARGS__)
+# define IRenderDevice_CreateQuery(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateQuery, This, __VA_ARGS__)
+# define IRenderDevice_CreateRenderPass(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateRenderPass, This, __VA_ARGS__)
+# define IRenderDevice_CreateFramebuffer(This, ...) CALL_IFACE_METHOD(RenderDevice, CreateFramebuffer, This, __VA_ARGS__)
+# define IRenderDevice_GetDeviceCaps(This) CALL_IFACE_METHOD(RenderDevice, GetDeviceCaps, This)
+# define IRenderDevice_GetTextureFormatInfo(This, ...) CALL_IFACE_METHOD(RenderDevice, GetTextureFormatInfo, This, __VA_ARGS__)
+# define IRenderDevice_GetTextureFormatInfoExt(This, ...) CALL_IFACE_METHOD(RenderDevice, GetTextureFormatInfoExt, This, __VA_ARGS__)
+# define IRenderDevice_ReleaseStaleResources(This, ...) CALL_IFACE_METHOD(RenderDevice, ReleaseStaleResources, This, __VA_ARGS__)
+# define IRenderDevice_IdleGPU(This) CALL_IFACE_METHOD(RenderDevice, IdleGPU, This)
+# define IRenderDevice_GetEngineFactory(This) CALL_IFACE_METHOD(RenderDevice, GetEngineFactory, This)
// clang-format on
#endif
diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h
index fddffeba..a2bc518d 100644
--- a/Graphics/GraphicsEngine/interface/Shader.h
+++ b/Graphics/GraphicsEngine/interface/Shader.h
@@ -77,6 +77,9 @@ DILIGENT_TYPED_ENUM(SHADER_SOURCE_LANGUAGE, Uint32)
/// The source language is GLSL
SHADER_SOURCE_LANGUAGE_GLSL,
+ /// The source language is Metal shading language (MSL)
+ SHADER_SOURCE_LANGUAGE_MSL,
+
/// The source language is GLSL that should be compiled verbatim
/// By default the engine prepends GLSL shader source code with platform-specific
diff --git a/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h b/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h
index f58dbd27..f5ccb59f 100644
--- a/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h
+++ b/Graphics/GraphicsEngineD3D11/interface/EngineFactoryD3D11.h
@@ -176,7 +176,7 @@ DILIGENT_END_INTERFACE
typedef struct IEngineFactoryD3D11* (*GetEngineFactoryD3D11Type)();
-inline GetEngineFactoryD3D11Type LoadGraphicsEngineD3D11()
+inline GetEngineFactoryD3D11Type DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineD3D11)()
{
return (GetEngineFactoryD3D11Type)LoadEngineDll("GraphicsEngineD3D11", "GetEngineFactoryD3D11");
}
diff --git a/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h b/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h
index b90f3aa0..cc2ca2ee 100644
--- a/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h
+++ b/Graphics/GraphicsEngineD3D12/interface/EngineFactoryD3D12.h
@@ -198,7 +198,7 @@ DILIGENT_END_INTERFACE
typedef struct IEngineFactoryD3D12* (*GetEngineFactoryD3D12Type)();
-inline GetEngineFactoryD3D12Type LoadGraphicsEngineD3D12()
+inline GetEngineFactoryD3D12Type DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineD3D12)()
{
return (GetEngineFactoryD3D12Type)LoadEngineDll("GraphicsEngineD3D12", "GetEngineFactoryD3D12");
}
diff --git a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
index d00d72d5..940249cd 100644
--- a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
@@ -547,3 +547,11 @@ IEngineFactoryD3D12* GetEngineFactoryD3D12()
}
} // namespace Diligent
+
+extern "C"
+{
+ Diligent::IEngineFactoryD3D12* Diligent_GetEngineFactoryD3D12()
+ {
+ return Diligent::GetEngineFactoryD3D12();
+ }
+}
diff --git a/Graphics/GraphicsEngineOpenGL/interface/EngineFactoryOpenGL.h b/Graphics/GraphicsEngineOpenGL/interface/EngineFactoryOpenGL.h
index cff83e54..6f005bfa 100644
--- a/Graphics/GraphicsEngineOpenGL/interface/EngineFactoryOpenGL.h
+++ b/Graphics/GraphicsEngineOpenGL/interface/EngineFactoryOpenGL.h
@@ -105,7 +105,7 @@ DILIGENT_END_INTERFACE
typedef struct IEngineFactoryOpenGL* (*GetEngineFactoryOpenGLType)();
-inline GetEngineFactoryOpenGLType LoadGraphicsEngineOpenGL()
+inline GetEngineFactoryOpenGLType DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineOpenGL)()
{
return (GetEngineFactoryOpenGLType)LoadEngineDll("GraphicsEngineOpenGL", "GetEngineFactoryOpenGL");
}
diff --git a/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp b/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp
index dacd1fe3..118a4bcf 100644
--- a/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/EngineFactoryOpenGL.cpp
@@ -302,3 +302,12 @@ Diligent::IEngineFactoryOpenGL* GetEngineFactoryOpenGL()
}
} // namespace Diligent
+
+extern "C"
+{
+ API_QUALIFIER
+ Diligent::IEngineFactoryOpenGL* Diligent_GetEngineFactoryOpenGL()
+ {
+ return Diligent::GetEngineFactoryOpenGL();
+ }
+}
diff --git a/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h b/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h
index be79c99f..0c5e347a 100644
--- a/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h
+++ b/Graphics/GraphicsEngineVulkan/interface/EngineFactoryVk.h
@@ -117,7 +117,7 @@ DILIGENT_END_INTERFACE
typedef struct IEngineFactoryVk* (*GetEngineFactoryVkType)();
-inline GetEngineFactoryVkType LoadGraphicsEngineVk()
+inline GetEngineFactoryVkType DILIGENT_GLOBAL_FUNCTION(LoadGraphicsEngineVk)()
{
return (GetEngineFactoryVkType)LoadEngineDll("GraphicsEngineVk", "GetEngineFactoryVk");
}
diff --git a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
index 44cf52e3..705cdede 100644
--- a/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/EngineFactoryVk.cpp
@@ -636,3 +636,12 @@ IEngineFactoryVk* GetEngineFactoryVk()
}
} // namespace Diligent
+
+extern "C"
+{
+ API_QUALIFIER
+ Diligent::IEngineFactoryVk* Diligent_GetEngineFactoryVk()
+ {
+ return Diligent::GetEngineFactoryVk();
+ }
+}
diff --git a/Tests/DiligentCoreAPITest/include/InlineShaders/ComputeShaderTestMSL.h b/Tests/DiligentCoreAPITest/include/InlineShaders/ComputeShaderTestMSL.h
new file mode 100644
index 00000000..f2751400
--- /dev/null
+++ b/Tests/DiligentCoreAPITest/include/InlineShaders/ComputeShaderTestMSL.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2019-2020 Diligent Graphics LLC
+ * Copyright 2015-2019 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#include <string>
+
+namespace
+{
+
+namespace MSL
+{
+
+// clang-format off
+const std::string FillTextureCS{
+R"(
+#include <metal_stdlib>
+#include <simd/simd.h>
+
+using namespace metal;
+
+kernel void CSMain(texture2d<float, access::write> g_tex2DUAV [[texture(0)]],
+ uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
+{
+ if (gl_GlobalInvocationID.x < g_tex2DUAV.get_width() &&
+ gl_GlobalInvocationID.y < g_tex2DUAV.get_height())
+ {
+ g_tex2DUAV.write(float4(float2(gl_GlobalInvocationID.xy % uint2(256u)) / 256.0, 0.0, 1.0),
+ uint2(gl_GlobalInvocationID.xy));
+
+ }
+}
+)"
+};
+// clang-format on
+
+} // namespace MSL
+
+} // namespace
diff --git a/Tests/DiligentCoreAPITest/include/InlineShaders/DrawCommandTestMSL.h b/Tests/DiligentCoreAPITest/include/InlineShaders/DrawCommandTestMSL.h
new file mode 100644
index 00000000..27a8e781
--- /dev/null
+++ b/Tests/DiligentCoreAPITest/include/InlineShaders/DrawCommandTestMSL.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2019-2020 Diligent Graphics LLC
+ * Copyright 2015-2019 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#include <string>
+
+namespace
+{
+
+namespace MSL
+{
+
+// clang-format off
+
+const std::string DrawTestFunctions{
+R"(
+
+#include <metal_stdlib>
+#include <simd/simd.h>
+
+using namespace metal;
+
+struct VSOut
+{
+ float3 Color [[user(locn0)]];
+ float4 Position [[position]];
+};
+
+vertex VSOut TrisVS(uint VertexId [[vertex_id]])
+{
+ float4 Pos[6] =
+ {
+ float4(-1.0, -0.5, 0.0, 1.0),
+ float4(-0.5, 0.5, 0.0, 1.0),
+ float4(0.0, -0.5, 0.0, 1.0),
+ float4(0.0, -0.5, 0.0, 1.0),
+ float4(0.5, 0.5, 0.0, 1.0),
+ float4(1.0, -0.5, 0.0, 1.0)
+ };
+ float3 Col[6] =
+ {
+ float3(1.0, 0.0, 0.0),
+ float3(0.0, 1.0, 0.0),
+ float3(0.0, 0.0, 1.0),
+ float3(1.0, 0.0, 0.0),
+ float3(0.0, 1.0, 0.0),
+ float3(0.0, 0.0, 1.0)
+ };
+
+ VSOut out = {};
+ out.Position = Pos[VertexId];
+ out.Color = Col[VertexId];
+ return out;
+}
+
+struct FSOut
+{
+ float4 Color [[color(0)]];
+};
+
+fragment FSOut TrisFS(VSOut in [[stage_in]])
+{
+ FSOut out = {float4(in.Color.rgb, 1.0)};
+ return out;
+}
+
+fragment FSOut InptAttFS(VSOut in [[stage_in]],
+ texture2d<float> SubpassInput [[texture(0)]])
+{
+ FSOut out;
+
+ out.Color.rgb = in.Color.rgb * 0.125;
+ out.Color.rgb += (float3(1.0, 1.0, 1.0) - SubpassInput.read(uint2(in.Position.xy)).brg) * 0.875;
+ out.Color.a = 1.0;
+
+ return out;
+}
+
+)"
+};
+
+// clang-format on
+
+} // namespace MSL
+
+} // namespace
diff --git a/Tests/DiligentCoreAPITest/include/Metal/TestingSwapChainMtl.hpp b/Tests/DiligentCoreAPITest/include/Metal/TestingSwapChainMtl.hpp
index 6b957789..aac8083e 100644
--- a/Tests/DiligentCoreAPITest/include/Metal/TestingSwapChainMtl.hpp
+++ b/Tests/DiligentCoreAPITest/include/Metal/TestingSwapChainMtl.hpp
@@ -25,6 +25,8 @@
* of the possibility of such damages.
*/
+#include <Metal/MTLBuffer.h>
+
#include "TestingSwapChainBase.hpp"
namespace Diligent
@@ -47,6 +49,7 @@ public:
virtual void TakeSnapshot() override final;
private:
+ id<MTLBuffer> m_MtlStagingBuffer;
};
} // namespace Testing
diff --git a/Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp b/Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp
index 542ee119..d69eb9c2 100644
--- a/Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp
+++ b/Tests/DiligentCoreAPITest/src/BrokenShaderTest.cpp
@@ -35,14 +35,40 @@ using namespace Diligent::Testing;
namespace
{
-static const char g_BrokenShaderSource[] = R"(
+static const char g_BrokenHLSL[] = R"(
void VSMain(out float4 pos : SV_POSITION)
{
pos = float3(0.0, 0.0, 0.0, 0.0);
}
)";
-TEST(Shader, CompilationFailure)
+static const char g_BrokenGLSL[] = R"(
+void VSMain()
+{
+ gl_Position = vec3(0.0, 0.0, 0.0);
+}
+)";
+
+static const char g_BrokenMSL[] = R"(
+#include <metal_stdlib>
+#include <simd/simd.h>
+
+using namespace metal;
+
+struct VSOut
+{
+ float4 pos [[position]];
+};
+
+vertex VSOut vs_main()
+{
+ VSOut out = {};
+ out.pos = float3(0.0, 0.0, 0.0);
+ return out;
+}
+)";
+
+void TestBrokenShader(const char* Source, const char* Name, SHADER_SOURCE_LANGUAGE SourceLanguage, int ErrorAllowance)
{
auto* pEnv = TestingEnvironment::GetInstance();
auto* pDevice = pEnv->GetDevice();
@@ -50,18 +76,18 @@ TEST(Shader, CompilationFailure)
TestingEnvironment::ScopedReset EnvironmentAutoReset;
ShaderCreateInfo Attrs;
- Attrs.Source = g_BrokenShaderSource;
+ Attrs.Source = Source;
Attrs.EntryPoint = "VSMain";
Attrs.Desc.ShaderType = SHADER_TYPE_VERTEX;
- Attrs.Desc.Name = "Broken shader test";
- Attrs.SourceLanguage = SHADER_SOURCE_LANGUAGE_HLSL;
+ Attrs.Desc.Name = Name;
+ Attrs.SourceLanguage = SourceLanguage;
Attrs.ShaderCompiler = pEnv->GetDefaultCompiler(Attrs.SourceLanguage);
Attrs.UseCombinedTextureSamplers = true;
IDataBlob* pErrors = nullptr;
Attrs.ppCompilerOutput = &pErrors;
- pEnv->SetErrorAllowance(pDevice->GetDeviceCaps().IsVulkanDevice() ? 3 : 2, "\n\nNo worries, testing broken shader...\n\n");
+ pEnv->SetErrorAllowance(ErrorAllowance, "\n\nNo worries, testing broken shader...\n\n");
RefCntAutoPtr<IShader> pBrokenShader;
pDevice->CreateShader(Attrs, &pBrokenShader);
EXPECT_FALSE(pBrokenShader);
@@ -71,4 +97,35 @@ TEST(Shader, CompilationFailure)
pErrors->Release();
}
+TEST(Shader, BrokenHLSL)
+{
+ const auto& deviceCaps = TestingEnvironment::GetInstance()->GetDevice()->GetDeviceCaps();
+ // HLSL is supported in all backends
+ TestBrokenShader(g_BrokenHLSL, "Broken HLSL test", SHADER_SOURCE_LANGUAGE_HLSL,
+ deviceCaps.IsGLDevice() || deviceCaps.IsD3DDevice() ? 2 : 3);
+}
+
+TEST(Shader, BrokenGLSL)
+{
+ const auto& deviceCaps = TestingEnvironment::GetInstance()->GetDevice()->GetDeviceCaps();
+ if (deviceCaps.IsD3DDevice())
+ {
+ GTEST_SKIP() << "GLSL is not supported in Direct3D";
+ }
+
+ TestBrokenShader(g_BrokenGLSL, "Broken GLSL test", SHADER_SOURCE_LANGUAGE_GLSL,
+ deviceCaps.IsGLDevice() ? 2 : 3);
+}
+
+TEST(Shader, BrokenMSL)
+{
+ const auto& deviceCaps = TestingEnvironment::GetInstance()->GetDevice()->GetDeviceCaps();
+ if (!deviceCaps.IsMetalDevice())
+ {
+ GTEST_SKIP() << "MSL is only supported in Metal";
+ }
+
+ TestBrokenShader(g_BrokenMSL, "Broken MSL test", SHADER_SOURCE_LANGUAGE_MSL, 2);
+}
+
} // namespace
diff --git a/Tests/DiligentCoreAPITest/src/ClearRenderTargetTest.cpp b/Tests/DiligentCoreAPITest/src/ClearRenderTargetTest.cpp
index 51f50492..676b4140 100644
--- a/Tests/DiligentCoreAPITest/src/ClearRenderTargetTest.cpp
+++ b/Tests/DiligentCoreAPITest/src/ClearRenderTargetTest.cpp
@@ -58,7 +58,7 @@ void ClearRenderTargetReferenceVk(ISwapChain* pSwapChain, const float ClearColor
#endif
#if METAL_SUPPORTED
-
+void ClearRenderTargetReferenceMtl(ISwapChain* pSwapChain, const float ClearColor[]);
#endif
} // namespace Testing
@@ -102,7 +102,12 @@ void ClearRenderTargetReference(IRenderDevice* pDevice,
case RENDER_DEVICE_TYPE_VULKAN:
ClearRenderTargetReferenceVk(pSwapChain, ClearColor);
break;
+#endif
+#if METAL_SUPPORTED
+ case RENDER_DEVICE_TYPE_METAL:
+ ClearRenderTargetReferenceMtl(pSwapChain, ClearColor);
+ break;
#endif
default:
diff --git a/Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp b/Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp
index c42f6e81..d229c606 100644
--- a/Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp
+++ b/Tests/DiligentCoreAPITest/src/DrawCommandTest.cpp
@@ -287,13 +287,15 @@ protected:
ASSERT_NE(pPS, nullptr);
}
- PSODesc.Name = "Draw command test";
+ PSODesc.Name = "Draw command test - procedural tris";
PSOCreateInfo.pVS = pProceduralVS;
PSOCreateInfo.pPS = pPS;
pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &sm_pDrawProceduralPSO);
ASSERT_NE(sm_pDrawProceduralPSO, nullptr);
+ PSODesc.Name = "Draw command test";
+
InputLayoutDesc LayoutDesc;
// clang-format off
LayoutElement Elems[] =
@@ -302,6 +304,7 @@ protected:
LayoutElement{ 1, 0, 3, VT_FLOAT32}
};
// clang-format on
+
GraphicsPipeline.InputLayout.LayoutElements = Elems;
GraphicsPipeline.InputLayout.NumElements = _countof(Elems);
@@ -309,13 +312,14 @@ protected:
PSOCreateInfo.pPS = pPS;
GraphicsPipeline.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &sm_pDrawPSO);
+ ASSERT_NE(sm_pDrawPSO, nullptr);
- PSODesc.Name = "Draw command test - 2x stride";
+ PSODesc.Name = "Draw command test - 2x VB stride";
Elems[0].Stride = sizeof(Vertex) * 2;
pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &sm_pDraw_2xStride_PSO);
-
+ ASSERT_NE(sm_pDraw_2xStride_PSO, nullptr);
PSODesc.Name = "Instanced draw command test";
// clang-format off
@@ -326,11 +330,13 @@ protected:
LayoutElement{ 2, 1, 4, VT_FLOAT32, false, INPUT_ELEMENT_FREQUENCY_PER_INSTANCE}
};
// clang-format on
+
GraphicsPipeline.InputLayout.LayoutElements = InstancedElems;
GraphicsPipeline.InputLayout.NumElements = _countof(InstancedElems);
PSOCreateInfo.pVS = pInstancedVS;
pDevice->CreateGraphicsPipelineState(PSOCreateInfo, &sm_pDrawInstancedPSO);
+ ASSERT_NE(sm_pDrawInstancedPSO, nullptr);
}
static void TearDownTestSuite()
diff --git a/Tests/DiligentCoreAPITest/src/Metal/ClearRenderTargetReferenceMtl.mm b/Tests/DiligentCoreAPITest/src/Metal/ClearRenderTargetReferenceMtl.mm
index 5c140e00..977b039d 100644
--- a/Tests/DiligentCoreAPITest/src/Metal/ClearRenderTargetReferenceMtl.mm
+++ b/Tests/DiligentCoreAPITest/src/Metal/ClearRenderTargetReferenceMtl.mm
@@ -29,6 +29,7 @@
#include "Metal/TestingSwapChainMtl.hpp"
#include "DeviceContextMtl.h"
+#include "TextureViewMtl.h"
namespace Diligent
{
@@ -38,8 +39,27 @@ namespace Testing
void ClearRenderTargetReferenceMtl(ISwapChain* pSwapChain, const float ClearColor[])
{
- //auto* pEnv = TestingEnvironmentMtl::GetInstance();
- //auto* pContext = pEnv->GetDeviceContext();
+ auto* const pEnv = TestingEnvironmentMtl::GetInstance();
+ auto const mtlCommandQueue = pEnv->GetMtlCommandQueue();
+
+ auto* pTestingSwapChainMtl = ValidatedCast<TestingSwapChainMtl>(pSwapChain);
+
+ auto* pRTV = pTestingSwapChainMtl->GetCurrentBackBufferRTV();
+ auto* mtlTexture = ValidatedCast<ITextureViewMtl>(pRTV)->GetMtlTexture();
+
+ id <MTLCommandBuffer> mtlCommandBuffer = [mtlCommandQueue commandBuffer];
+
+ MTLRenderPassDescriptor* renderPassDesc =
+ [MTLRenderPassDescriptor renderPassDescriptor];
+ renderPassDesc.colorAttachments[0].texture = mtlTexture;
+ renderPassDesc.colorAttachments[0].loadAction = MTLLoadActionClear;
+ renderPassDesc.colorAttachments[0].clearColor =
+ MTLClearColorMake(ClearColor[0], ClearColor[1], ClearColor[2], ClearColor[3]);
+ renderPassDesc.colorAttachments[0].storeAction = MTLStoreActionStore;
+ id <MTLRenderCommandEncoder> renderEncoder =
+ [mtlCommandBuffer renderCommandEncoderWithDescriptor:renderPassDesc];
+ [renderEncoder endEncoding];
+ [mtlCommandBuffer commit];
}
} // namespace Testing
diff --git a/Tests/DiligentCoreAPITest/src/Metal/ComputeShaderReferenceMtl.mm b/Tests/DiligentCoreAPITest/src/Metal/ComputeShaderReferenceMtl.mm
index 6341ecdb..489f36f2 100644
--- a/Tests/DiligentCoreAPITest/src/Metal/ComputeShaderReferenceMtl.mm
+++ b/Tests/DiligentCoreAPITest/src/Metal/ComputeShaderReferenceMtl.mm
@@ -29,8 +29,9 @@
#include "Metal/TestingSwapChainMtl.hpp"
#include "DeviceContextMtl.h"
+#include "TextureViewMtl.h"
-//#include "InlineShaders/ComputeShaderTestGLSL.h"
+#include "InlineShaders/ComputeShaderTestMSL.h"
namespace Diligent
{
@@ -40,9 +41,37 @@ namespace Testing
void ComputeShaderReferenceMtl(ISwapChain* pSwapChain)
{
- //auto* pEnv = TestingEnvironmentMtl::GetInstance();
- //auto vkDevice = pEnv->GetVkDevice();
- //auto* pContext = pEnv->GetDeviceContext();
+ auto* const pEnv = TestingEnvironmentMtl::GetInstance();
+ auto const mtlDevice = pEnv->GetMtlDevice();
+
+ auto* progSrc = [NSString stringWithUTF8String:MSL::FillTextureCS.c_str()];
+ NSError *errors = nil;
+ id <MTLLibrary> library = [mtlDevice newLibraryWithSource:progSrc
+ options:nil
+ error:&errors];
+ ASSERT_TRUE(library != nil);
+ id <MTLFunction> computeFunc = [library newFunctionWithName:@"CSMain"];
+ ASSERT_TRUE(computeFunc != nil);
+ auto* computePipeline = [mtlDevice newComputePipelineStateWithFunction:computeFunc error:&errors];
+ ASSERT_TRUE(computePipeline != nil);
+
+ auto* pTestingSwapChainMtl = ValidatedCast<TestingSwapChainMtl>(pSwapChain);
+ auto* pUAV = pTestingSwapChainMtl->GetCurrentBackBufferUAV();
+ auto* mtlTexture = ValidatedCast<ITextureViewMtl>(pUAV)->GetMtlTexture();
+ const auto& SCDesc = pTestingSwapChainMtl->GetDesc();
+
+ auto* mtlCommandQueue = pEnv->GetMtlCommandQueue();
+ id <MTLCommandBuffer> mtlCommandBuffer = [mtlCommandQueue commandBuffer];
+ auto* cmdEncoder = [mtlCommandBuffer computeCommandEncoder];
+ ASSERT_TRUE(cmdEncoder != nil);
+
+ [cmdEncoder setComputePipelineState:computePipeline];
+ [cmdEncoder setTexture:mtlTexture atIndex:0];
+ [cmdEncoder dispatchThreadgroups:MTLSizeMake((SCDesc.Width + 15) / 16, (SCDesc.Height + 15) / 16, 1)
+ threadsPerThreadgroup:MTLSizeMake(16, 16, 1)];
+
+ [cmdEncoder endEncoding];
+ [mtlCommandBuffer commit];
}
} // namespace Testing
diff --git a/Tests/DiligentCoreAPITest/src/Metal/DrawCommandReferenceMtl.mm b/Tests/DiligentCoreAPITest/src/Metal/DrawCommandReferenceMtl.mm
index 763e90f0..f5a3d4fb 100644
--- a/Tests/DiligentCoreAPITest/src/Metal/DrawCommandReferenceMtl.mm
+++ b/Tests/DiligentCoreAPITest/src/Metal/DrawCommandReferenceMtl.mm
@@ -25,10 +25,14 @@
* of the possibility of such damages.
*/
+#include <Metal/Metal.h>
+
#include "Metal/TestingEnvironmentMtl.hpp"
#include "Metal/TestingSwapChainMtl.hpp"
-//#include "InlineShaders/DrawCommandTestMSL.h"
+#include "TextureViewMtl.h"
+
+#include "InlineShaders/DrawCommandTestMSL.h"
namespace Diligent
{
@@ -43,110 +47,195 @@ class TriangleRenderer
{
public:
- TriangleRenderer(const std::string& FSSource)
+ TriangleRenderer(NSString* fragEntry, Uint32 SampleCount = 1)
{
- auto* pEnv = TestingEnvironmentMtl::GetInstance();
+ auto* const pEnv = TestingEnvironmentMtl::GetInstance();
+ auto* const mtlDevice = pEnv->GetMtlDevice();
+
+ auto* progSrc = [NSString stringWithUTF8String:MSL::DrawTestFunctions.c_str()];
+ NSError *errors = nil;
+ id <MTLLibrary> library = [mtlDevice newLibraryWithSource:progSrc
+ options:nil
+ error:&errors];
+ if (library == nil)
+ {
+ LOG_ERROR_AND_THROW("Failed to create Metal library: ", [errors.localizedDescription cStringUsingEncoding:NSUTF8StringEncoding]);
+ }
+ id <MTLFunction> vertFunc = [library newFunctionWithName:@"TrisVS"];
+ id <MTLFunction> fragFunc = [library newFunctionWithName:fragEntry];
+ MTLRenderPipelineDescriptor* renderPipelineDesc =
+ [[MTLRenderPipelineDescriptor alloc] init];
+ renderPipelineDesc.vertexFunction = vertFunc;
+ renderPipelineDesc.fragmentFunction = fragFunc;
+ const auto& SCDesc = pEnv->GetSwapChain()->GetDesc();
+ MTLPixelFormat pixelFormat = MTLPixelFormatInvalid;
+ switch (SCDesc.ColorBufferFormat)
+ {
+ case TEX_FORMAT_RGBA8_UNORM:
+ pixelFormat = MTLPixelFormatRGBA8Unorm;
+ break;
+
+ default:
+ UNSUPPORTED("Unexpected swap chain color format");
+ }
+ renderPipelineDesc.sampleCount = SampleCount;
+ renderPipelineDesc.colorAttachments[0].pixelFormat = pixelFormat;
+ m_MtlPipeline = [mtlDevice
+ newRenderPipelineStateWithDescriptor:renderPipelineDesc error:&errors];
}
~TriangleRenderer()
{
}
- void Draw(Uint32 Width, Uint32 Height, const float* pClearColor)
+ void Draw(id <MTLRenderCommandEncoder> renderEncoder)
{
- //auto* pEnv = TestingEnvironmentGL::GetInstance();
- /*
- id <MTLDevice> device = MTLCreateSystemDefaultDevice();
-
- id <MTLCommandQueue> commandQueue = [device newCommandQueue];
- id <MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
-
- MTLRenderPassDescriptor *renderPassDesc
- = [MTLRenderPassDescriptor renderPassDescriptor];
- renderPassDesc.colorAttachments[0].texture = currentTexture;
- renderPassDesc.colorAttachments[0].loadAction = MTLLoadActionClear;
- renderPassDesc.colorAttachments[0].clearColor = MTLClearColorMake(0.0,1.0,1.0,1.0);
- id <MTLRenderCommandEncoder> renderEncoder =
- [commandBuffer renderCommandEncoderWithDescriptor:renderPassDesc];
-
- static const float posData[] = {
- 0.0f, 0.33f, 0.0f, 1.f,
- -0.33f, -0.33f, 0.0f, 1.f,
- 0.33f, -0.33f, 0.0f, 1.f,
- };
- static const float colData[] = {
- 1.f, 0.f, 0.f, 1.f,
- 0.f, 1.f, 0.f, 1.f,
- 0.f, 0.f, 1.f, 1.f,
- };
- id <MTLBuffer> posBuf = [device newBufferWithBytes:posData
- length:sizeof(posData) options:nil];
- id <MTLBuffer> colBuf = [device newBufferWithBytes:colorData
- length:sizeof(colData) options:nil];
- [renderEncoder setVertexBuffer:posBuf offset:0 atIndex:0];
- [renderEncoder setVertexBuffer:colBuf offset:0 atIndex:1];
-
- NSError *errors;
- id <MTLLibrary> library = [device newLibraryWithSource:progSrc options:nil
- error:&errors];
- id <MTLFunction> vertFunc = [library newFunctionWithName:@"hello_vertex"];
- id <MTLFunction> fragFunc = [library newFunctionWithName:@"hello_fragment"];
- MTLRenderPipelineDescriptor *renderPipelineDesc
- = [[MTLRenderPipelineDescriptor alloc] init];
- renderPipelineDesc.vertexFunction = vertFunc;
- renderPipelineDesc.fragmentFunction = fragFunc;
- renderPipelineDesc.colorAttachments[0].pixelFormat = currentTexture.pixelFormat;
- id <MTLRenderPipelineState> pipeline = [device
- newRenderPipelineStateWithDescriptor:renderPipelineDesc error:&errors];
- [renderEncoder setRenderPipelineState:pipeline];
+ [renderEncoder setRenderPipelineState:m_MtlPipeline];
[renderEncoder drawPrimitives:MTLPrimitiveTypeTriangle
- vertexStart:0 vertexCount:3];
+ vertexStart:0 vertexCount:6];
[renderEncoder endEncoding];
- [commandBuffer commit];
- */
}
private:
+ id<MTLRenderPipelineState> m_MtlPipeline;
};
} // namespace
void RenderDrawCommandReferenceMtl(ISwapChain* pSwapChain, const float* pClearColor)
{
- //auto* pEnv = TestingEnvironmentMtl::GetInstance();
- //auto* pContext = pEnv->GetDeviceContext();
- //auto* pTestingSwapChainMtl = ValidatedCast<TestingSwapChainMtl>(pSwapChain);
+ auto* const pEnv = TestingEnvironmentMtl::GetInstance();
+ auto* const mtlCommandQueue = pEnv->GetMtlCommandQueue();
- //TriRenderer.Draw(SCDesc.Width, SCDesc.Height, pClearColor);
+ auto* pTestingSwapChainMtl = ValidatedCast<TestingSwapChainMtl>(pSwapChain);
+ const auto& SCDesc = pTestingSwapChainMtl->GetDesc();
- // Make sure Diligent Engine will reset all GL states
- //pContext->InvalidateState();
-}
+ auto* pRTV = pTestingSwapChainMtl->GetCurrentBackBufferRTV();
+ auto* mtlBackBuffer = ValidatedCast<ITextureViewMtl>(pRTV)->GetMtlTexture();
-void RenderPassMSResolveReferenceMtl(ISwapChain* pSwapChain, const float* pClearColor)
-{
- //auto* pEnv = TestingEnvironmentMtl:GetInstance();
- //auto* pContext = pEnv->GetDeviceContext();
- //auto* pTestingSwapChainGL = ValidatedCast<TestingSwapChainMtl>(pSwapChain);
+ id <MTLCommandBuffer> mtlCommandBuffer = [mtlCommandQueue commandBuffer];
+
+ constexpr float Zero[4] = {};
+ if (pClearColor == nullptr)
+ pClearColor = Zero;
- //const auto& SCDesc = pTestingSwapChainGL->GetDesc();
+ MTLRenderPassDescriptor* renderPassDesc =
+ [MTLRenderPassDescriptor renderPassDescriptor];
+ renderPassDesc.colorAttachments[0].texture = mtlBackBuffer;
+ renderPassDesc.colorAttachments[0].loadAction = MTLLoadActionClear;
+ renderPassDesc.colorAttachments[0].clearColor = MTLClearColorMake(pClearColor[0], pClearColor[1], pClearColor[2], pClearColor[3]);
+ renderPassDesc.colorAttachments[0].storeAction = MTLStoreActionStore;
+ id <MTLRenderCommandEncoder> renderEncoder =
+ [mtlCommandBuffer renderCommandEncoderWithDescriptor:renderPassDesc];
+ [renderEncoder setViewport:MTLViewport{0, 0, (double) SCDesc.Width, (double) SCDesc.Height, 0, 1}];
- //TriangleRenderer TriRenderer{GLSL::DrawTest_FS};
+ TriangleRenderer TriRenderer{@"TrisFS"};
+ TriRenderer.Draw(renderEncoder);
- // Make sure Diligent Engine will reset all GL states
- //pContext->InvalidateState();
+ [mtlCommandBuffer commit];
}
-void RenderPassInputAttachmentReferenceMtl(ISwapChain* pSwapChain, const float* pClearColor)
+void RenderPassMSResolveReferenceMtl(ISwapChain* pSwapChain, const float* pClearColor)
{
- //auto* pEnv = TestingEnvironmentMtl::GetInstance();
- //auto* pContext = pEnv->GetDeviceContext();
- //auto* pTestingSwapChainMtl = ValidatedCast<TestingSwapChainMtl>(pSwapChain);
-
- //const auto& SCDesc = pTestingSwapChainMtl->GetDesc();
+ auto* const pEnv = TestingEnvironmentMtl::GetInstance();
+ auto* const mtlCommandQueue = pEnv->GetMtlCommandQueue();
+ auto* const mtlDevice = pEnv->GetMtlDevice();
+
+ auto* pTestingSwapChainMtl = ValidatedCast<TestingSwapChainMtl>(pSwapChain);
+ const auto& SCDesc = pTestingSwapChainMtl->GetDesc();
+
+ auto* pRTV = pTestingSwapChainMtl->GetCurrentBackBufferRTV();
+ auto* mtlBackBuffer = ValidatedCast<ITextureViewMtl>(pRTV)->GetMtlTexture();
+
+ constexpr Uint32 SampleCount = 4;
+
+ MTLTextureDescriptor* msTextureDescriptor = [[MTLTextureDescriptor alloc] init];
+ msTextureDescriptor.textureType = MTLTextureType2DMultisample;
+ msTextureDescriptor.width = SCDesc.Width;
+ msTextureDescriptor.height = SCDesc.Height;
+ msTextureDescriptor.sampleCount = SampleCount;
+ msTextureDescriptor.pixelFormat = mtlBackBuffer.pixelFormat;
+ msTextureDescriptor.arrayLength = 1;
+ msTextureDescriptor.mipmapLevelCount = 1;
+ msTextureDescriptor.storageMode = MTLStorageModePrivate;
+ msTextureDescriptor.allowGPUOptimizedContents = true;
+ msTextureDescriptor.usage = MTLTextureUsageRenderTarget;
+ auto mtlMSTexture = [mtlDevice newTextureWithDescriptor:msTextureDescriptor];
+ ASSERT_TRUE(mtlMSTexture != nil);
+
+ id <MTLCommandBuffer> mtlCommandBuffer = [mtlCommandQueue commandBuffer];
+
+ MTLRenderPassDescriptor* renderPassDesc =
+ [MTLRenderPassDescriptor renderPassDescriptor];
+ renderPassDesc.colorAttachments[0].texture = mtlMSTexture;
+ renderPassDesc.colorAttachments[0].loadAction = MTLLoadActionClear;
+ renderPassDesc.colorAttachments[0].clearColor = MTLClearColorMake(pClearColor[0], pClearColor[1], pClearColor[2], pClearColor[3]);
+ renderPassDesc.colorAttachments[0].storeAction = MTLStoreActionMultisampleResolve;
+ renderPassDesc.colorAttachments[0].resolveTexture = mtlBackBuffer;
+ id <MTLRenderCommandEncoder> renderEncoder =
+ [mtlCommandBuffer renderCommandEncoderWithDescriptor:renderPassDesc];
+ [renderEncoder setViewport:MTLViewport{0, 0, (double) SCDesc.Width, (double) SCDesc.Height, 0, 1}];
+
+ TriangleRenderer TriRenderer{@"TrisFS", SampleCount};
+ TriRenderer.Draw(renderEncoder);
+
+ [mtlCommandBuffer commit];
+}
- // Make sure Diligent Engine will reset all GL states
- //pContext->InvalidateState();
+void RenderPassInputAttachmentReferenceMtl(ISwapChain* pSwapChain, const float* pClearColor)
+{
+ auto* const pEnv = TestingEnvironmentMtl::GetInstance();
+ auto* const mtlCommandQueue = pEnv->GetMtlCommandQueue();
+ auto* const mtlDevice = pEnv->GetMtlDevice();
+
+ auto* pTestingSwapChainMtl = ValidatedCast<TestingSwapChainMtl>(pSwapChain);
+ const auto& SCDesc = pTestingSwapChainMtl->GetDesc();
+
+ auto* pRTV = pTestingSwapChainMtl->GetCurrentBackBufferRTV();
+ auto* mtlBackBuffer = ValidatedCast<ITextureViewMtl>(pRTV)->GetMtlTexture();
+
+ MTLTextureDescriptor* inptAttTextureDescriptor = [[MTLTextureDescriptor alloc] init];
+ inptAttTextureDescriptor.textureType = MTLTextureType2D;
+ inptAttTextureDescriptor.width = SCDesc.Width;
+ inptAttTextureDescriptor.height = SCDesc.Height;
+ inptAttTextureDescriptor.pixelFormat = mtlBackBuffer.pixelFormat;
+ inptAttTextureDescriptor.arrayLength = 1;
+ inptAttTextureDescriptor.mipmapLevelCount = 1;
+ inptAttTextureDescriptor.storageMode = MTLStorageModePrivate;
+ inptAttTextureDescriptor.allowGPUOptimizedContents = true;
+ inptAttTextureDescriptor.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead;
+ auto mtlInputAttachment = [mtlDevice newTextureWithDescriptor:inptAttTextureDescriptor];
+ ASSERT_TRUE(mtlInputAttachment != nil);
+
+ id <MTLCommandBuffer> mtlCommandBuffer = [mtlCommandQueue commandBuffer];
+
+ MTLRenderPassDescriptor* subpass0Desc =
+ [MTLRenderPassDescriptor renderPassDescriptor];
+ subpass0Desc.colorAttachments[0].texture = mtlInputAttachment;
+ subpass0Desc.colorAttachments[0].loadAction = MTLLoadActionClear;
+ subpass0Desc.colorAttachments[0].clearColor = MTLClearColorMake(0, 0, 0, 0);
+ subpass0Desc.colorAttachments[0].storeAction = MTLStoreActionStore;
+ id <MTLRenderCommandEncoder> renderEncoder =
+ [mtlCommandBuffer renderCommandEncoderWithDescriptor:subpass0Desc];
+ [renderEncoder setViewport:MTLViewport{0, 0, (double) SCDesc.Width, (double) SCDesc.Height, 0, 1}];
+
+ TriangleRenderer TriRenderer{@"TrisFS"};
+ TriRenderer.Draw(renderEncoder);
+
+ MTLRenderPassDescriptor* subpass1Desc =
+ [MTLRenderPassDescriptor renderPassDescriptor];
+ subpass1Desc.colorAttachments[0].texture = mtlBackBuffer;
+ subpass1Desc.colorAttachments[0].loadAction = MTLLoadActionClear;
+ subpass1Desc.colorAttachments[0].clearColor = MTLClearColorMake(pClearColor[0], pClearColor[1], pClearColor[2], pClearColor[3]);
+ subpass1Desc.colorAttachments[0].storeAction = MTLStoreActionStore;
+ renderEncoder = [mtlCommandBuffer renderCommandEncoderWithDescriptor:subpass1Desc];
+ [renderEncoder setViewport:MTLViewport{0, 0, (double) SCDesc.Width, (double) SCDesc.Height, 0, 1}];
+
+ TriangleRenderer TriRendererInptAtt{@"InptAttFS"};
+ [renderEncoder setFragmentTexture:mtlInputAttachment atIndex:0];
+ TriRendererInptAtt.Draw(renderEncoder);
+
+ [mtlCommandBuffer commit];
}
} // namespace Testing
diff --git a/Tests/DiligentCoreAPITest/src/Metal/TestingSwapChainMtl.mm b/Tests/DiligentCoreAPITest/src/Metal/TestingSwapChainMtl.mm
index ccf5592e..c6f93759 100644
--- a/Tests/DiligentCoreAPITest/src/Metal/TestingSwapChainMtl.mm
+++ b/Tests/DiligentCoreAPITest/src/Metal/TestingSwapChainMtl.mm
@@ -25,11 +25,14 @@
* of the possibility of such damages.
*/
+#include <Metal/Metal.h>
+
#include "Metal/TestingSwapChainMtl.hpp"
#include "Metal/TestingEnvironmentMtl.hpp"
#include "RenderDeviceMtl.h"
#include "DeviceContextMtl.h"
+#include "TextureViewMtl.h"
namespace Diligent
{
@@ -48,6 +51,10 @@ TestingSwapChainMtl::TestingSwapChainMtl(IReferenceCounters* pRefCounters,
SCDesc //
}
{
+ auto mtlDevice = pEnv->GetMtlDevice();
+ m_MtlStagingBuffer =
+ [mtlDevice newBufferWithLength:SCDesc.Width * SCDesc.Height * 4
+ options:MTLResourceStorageModeManaged];
}
TestingSwapChainMtl::~TestingSwapChainMtl()
@@ -56,6 +63,31 @@ TestingSwapChainMtl::~TestingSwapChainMtl()
void TestingSwapChainMtl::TakeSnapshot()
{
+ auto* pEnv = TestingEnvironmentMtl::GetInstance();
+ auto mtlCommandQueue = pEnv->GetMtlCommandQueue();
+
+ auto* pRTV = ValidatedCast<ITextureViewMtl>(GetCurrentBackBufferRTV());
+ auto mtlTexture = pRTV->GetMtlTexture();
+
+ m_ReferenceDataPitch = m_SwapChainDesc.Height * 4;
+ m_ReferenceData.resize(m_SwapChainDesc.Width * m_ReferenceDataPitch);
+
+ auto commandBuffer = [mtlCommandQueue commandBuffer];
+ auto blitEncoder = [commandBuffer blitCommandEncoder];
+ [blitEncoder copyFromTexture:mtlTexture
+ sourceSlice:0
+ sourceLevel:0
+ sourceOrigin:MTLOrigin{0,0,0}
+ sourceSize:MTLSize{m_SwapChainDesc.Width, m_SwapChainDesc.Height, 1}
+ toBuffer:m_MtlStagingBuffer
+ destinationOffset:0
+ destinationBytesPerRow:m_ReferenceDataPitch
+ destinationBytesPerImage:0];
+ [blitEncoder synchronizeResource:m_MtlStagingBuffer];
+ [blitEncoder endEncoding];
+ [commandBuffer commit];
+ [commandBuffer waitUntilCompleted];
+ memcpy(m_ReferenceData.data(), [m_MtlStagingBuffer contents], m_ReferenceData.size());
}
void CreateTestingSwapChainMtl(TestingEnvironmentMtl* pEnv,
diff --git a/Tests/DiligentCoreAPITest/src/RenderPassTest.cpp b/Tests/DiligentCoreAPITest/src/RenderPassTest.cpp
index 0298a500..24145cd9 100644
--- a/Tests/DiligentCoreAPITest/src/RenderPassTest.cpp
+++ b/Tests/DiligentCoreAPITest/src/RenderPassTest.cpp
@@ -65,7 +65,9 @@ void RenderPassInputAttachmentReferenceVk(ISwapChain* pSwapChain, const float* p
#endif
#if METAL_SUPPORTED
-
+void RenderDrawCommandReferenceMtl(ISwapChain* pSwapChain, const float* pClearColor);
+void RenderPassMSResolveReferenceMtl(ISwapChain* pSwapChain, const float* pClearColor);
+void RenderPassInputAttachmentReferenceMtl(ISwapChain* pSwapChain, const float* pClearColor);
#endif
} // namespace Testing
@@ -472,17 +474,19 @@ TEST_F(RenderPassTest, CreateRenderPassAndFramebuffer)
RPBeginInfo.StateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_TRANSITION;
pContext->BeginRenderPass(RPBeginInfo);
- if (DeviceType != RENDER_DEVICE_TYPE_D3D12)
+ if (DeviceType != RENDER_DEVICE_TYPE_D3D12 &&
+ DeviceType != RENDER_DEVICE_TYPE_METAL)
{
- // ClearDepthStencil is not allowed inside a render pass in Direct3D12
+ // ClearDepthStencil is not allowed inside a render pass in Direct3D12 and Metal
pContext->ClearDepthStencil(pTexViews[3], CLEAR_DEPTH_FLAG, 1.0, 0, RESOURCE_STATE_TRANSITION_MODE_VERIFY);
}
pContext->NextSubpass();
- if (DeviceType != RENDER_DEVICE_TYPE_D3D12)
+ if (DeviceType != RENDER_DEVICE_TYPE_D3D12 &&
+ DeviceType != RENDER_DEVICE_TYPE_METAL)
{
- // ClearRenderTarget is not allowed inside a render pass in Direct3D12
+ // ClearRenderTarget is not allowed inside a render pass in Direct3D12 and Metal
float ClearColor[] = {0, 0, 0, 0};
pContext->ClearRenderTarget(pTexViews[4], ClearColor, RESOURCE_STATE_TRANSITION_MODE_VERIFY);
}
@@ -534,6 +538,12 @@ TEST_F(RenderPassTest, Draw)
break;
#endif
+#if METAL_SUPPORTED
+ case RENDER_DEVICE_TYPE_METAL:
+ RenderDrawCommandReferenceMtl(pSwapChain, ClearColor);
+ break;
+#endif
+
default:
LOG_ERROR_AND_THROW("Unsupported device type");
}
@@ -637,6 +647,12 @@ TEST_F(RenderPassTest, MSResolve)
break;
#endif
+#if METAL_SUPPORTED
+ case RENDER_DEVICE_TYPE_METAL:
+ RenderPassMSResolveReferenceMtl(pSwapChain, ClearColor);
+ break;
+#endif
+
default:
LOG_ERROR_AND_THROW("Unsupported device type");
}
@@ -774,6 +790,12 @@ TEST_F(RenderPassTest, InputAttachment)
break;
#endif
+#if METAL_SUPPORTED
+ case RENDER_DEVICE_TYPE_METAL:
+ RenderPassInputAttachmentReferenceMtl(pSwapChain, ClearColor);
+ break;
+#endif
+
default:
LOG_ERROR_AND_THROW("Unsupported device type");
}
diff --git a/Tests/IncludeTest/GraphicsEngineD3D11/EngineFactoryD3D11H_test.c b/Tests/IncludeTest/GraphicsEngineD3D11/EngineFactoryD3D11H_test.c
index 12c58064..5cbab2e5 100644
--- a/Tests/IncludeTest/GraphicsEngineD3D11/EngineFactoryD3D11H_test.c
+++ b/Tests/IncludeTest/GraphicsEngineD3D11/EngineFactoryD3D11H_test.c
@@ -39,7 +39,7 @@
void TestEngineFactoryD3D11CInterface()
{
- GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = LoadGraphicsEngineD3D11();
+ GetEngineFactoryD3D11Type GetEngineFactoryD3D11 = Diligent_LoadGraphicsEngineD3D11();
struct IEngineFactoryD3D11* pFactory = GetEngineFactoryD3D11();
struct EngineD3D11CreateInfo EngineCI = {0};
IRenderDevice* pDevice = NULL;
diff --git a/Tests/IncludeTest/GraphicsEngineD3D12/EngineFactoryD3D12H_test.c b/Tests/IncludeTest/GraphicsEngineD3D12/EngineFactoryD3D12H_test.c
index 6d986fec..01bea75d 100644
--- a/Tests/IncludeTest/GraphicsEngineD3D12/EngineFactoryD3D12H_test.c
+++ b/Tests/IncludeTest/GraphicsEngineD3D12/EngineFactoryD3D12H_test.c
@@ -39,7 +39,7 @@
void TestEngineFactoryD3D12CInterface()
{
- GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = LoadGraphicsEngineD3D12();
+ GetEngineFactoryD3D12Type GetEngineFactoryD3D12 = Diligent_LoadGraphicsEngineD3D12();
struct IEngineFactoryD3D12* pFactory = GetEngineFactoryD3D12();
struct EngineD3D12CreateInfo EngineCI = {0};
IRenderDevice* pDevice = NULL;
diff --git a/Tests/IncludeTest/GraphicsEngineOpenGL/EngineFactoryOpenGLH_test.c b/Tests/IncludeTest/GraphicsEngineOpenGL/EngineFactoryOpenGLH_test.c
index 06758d24..89c5d847 100644
--- a/Tests/IncludeTest/GraphicsEngineOpenGL/EngineFactoryOpenGLH_test.c
+++ b/Tests/IncludeTest/GraphicsEngineOpenGL/EngineFactoryOpenGLH_test.c
@@ -33,7 +33,7 @@
void TestEngineFactoryGL_CInterface()
{
#if EXPLICITLY_LOAD_ENGINE_GL_DLL
- GetEngineFactoryOpenGLType GetEngineFactoryGL = LoadGraphicsEngineOpenGL();
+ GetEngineFactoryOpenGLType GetEngineFactoryGL = Diligent_LoadGraphicsEngineOpenGL();
IEngineFactoryOpenGL* pFactory = GetEngineFactoryGL();
#else
IEngineFactoryOpenGL* pFactory = Diligent_GetEngineFactoryOpenGL();
diff --git a/Tests/IncludeTest/GraphicsEngineVk/EngineFactoryVkH_test.c b/Tests/IncludeTest/GraphicsEngineVk/EngineFactoryVkH_test.c
index fa888524..72ec2186 100644
--- a/Tests/IncludeTest/GraphicsEngineVk/EngineFactoryVkH_test.c
+++ b/Tests/IncludeTest/GraphicsEngineVk/EngineFactoryVkH_test.c
@@ -36,7 +36,7 @@
void TestEngineFactoryVk_CInterface()
{
#if EXPLICITLY_LOAD_ENGINE_VK_DLL
- GetEngineFactoryVkType GetEngineFactoryVk = LoadGraphicsEngineVk();
+ GetEngineFactoryVkType GetEngineFactoryVk = Diligent_LoadGraphicsEngineVk();
IEngineFactoryVk* pFactory = GetEngineFactoryVk();
#else
IEngineFactoryVk* pFactory = Diligent_GetEngineFactoryVk();