Skip to content

Commit

Permalink
Tests for different pipeline + some associated api/error tweaks (#32)
Browse files Browse the repository at this point in the history
* Tests for different pipeline + some associated api/error tweaks

* Clean up some code

* Run format_code

* Update src/sgl/device/tests/test_pipeline_utils.slang

* Update src/sgl/device/tests/test_pipeline_utils.slang

* Remove tev show + fix vulkan test

* Add alpha coverage test for Vulkan

* Cleanup on pipeline tests

---------

Co-authored-by: Chris Cummings <[email protected]>
  • Loading branch information
ccummingsNV and Chris Cummings authored Jul 8, 2024
1 parent 0bcb14d commit 6fa4f1a
Show file tree
Hide file tree
Showing 7 changed files with 1,047 additions and 4 deletions.
2 changes: 1 addition & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endmacro()
# d3d12

add_library(d3d12 INTERFACE)
target_link_libraries(d3d12 INTERFACE dxgi.lib d3d12.lib)
target_link_libraries(d3d12 INTERFACE dxgi.lib d3d12.lib dxguid.lib)

# nanobind

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ target_sources(sgl PRIVATE
sgl/device/framebuffer.h
sgl/device/fwd.h
sgl/device/helpers.h
sgl/device/helpers.cpp
sgl/device/input_layout.cpp
sgl/device/input_layout.h
sgl/device/kernel.cpp
Expand Down
63 changes: 63 additions & 0 deletions src/sgl/device/helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: Apache-2.0
#include "helpers.h"

#include "sgl/core/config.h"
#include "sgl/core/macros.h"

#include <string>
#include <format>

#if SGL_HAS_D3D12
#include <dxgidebug.h>
#include <dxgi1_3.h>
#endif

namespace sgl {


// Reads last error from graphics layer.
std::string get_last_gfx_layer_error()
{
#if SGL_HAS_D3D12
IDXGIDebug* dxgiDebug = nullptr;
DXGIGetDebugInterface1(0, IID_PPV_ARGS(&dxgiDebug));
if (!dxgiDebug)
return "";

IDXGIInfoQueue* dxgiInfoQueue = nullptr;
dxgiDebug->QueryInterface(IID_PPV_ARGS(&dxgiInfoQueue));
if (!dxgiInfoQueue)
return "";

UINT64 messageCount = dxgiInfoQueue->GetNumStoredMessages(DXGI_DEBUG_ALL);
if (messageCount == 0)
return "";

SIZE_T messageLength = 0;
dxgiInfoQueue->GetMessage(DXGI_DEBUG_ALL, messageCount - 1, nullptr, &messageLength);
DXGI_INFO_QUEUE_MESSAGE* pMessage = (DXGI_INFO_QUEUE_MESSAGE*)malloc(messageLength);
dxgiInfoQueue->GetMessage(DXGI_DEBUG_ALL, messageCount - 1, pMessage, &messageLength);
auto res = std::string(pMessage->pDescription);
free(pMessage);
return res;
#else
// TODO: Get useful error information for other platforms if possible
return "";
#endif
}

// Builds the user friendly message that is passed into a slang failure exception,
// used by SLANG_CALL.
std::string build_slang_failed_message(const char* call, SlangResult result)
{
auto msg = std::format("Slang call {} failed with error: {}\n", call, result);
if (static_cast<uint32_t>(result) >= 0x80000000U) {
std::string gfx_error = get_last_gfx_layer_error();
if (!gfx_error.empty()) {
msg += "\nLast graphics layer error:\n" + gfx_error;
}
}
return msg;
}

} // namespace sgl
11 changes: 9 additions & 2 deletions src/sgl/device/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
#include "sgl/core/error.h"

#include <slang-gfx.h>
#include <format>


namespace sgl {
SGL_API std::string build_slang_failed_message(const char* call, SlangResult result);
}

#define SLANG_CALL(call) \
{ \
SlangResult result_ = call; \
if (SLANG_FAILED(result_)) \
SGL_THROW("Slang call {} failed with error: {}", #call, result_); \
if (SLANG_FAILED(result_)) { \
SGL_THROW(build_slang_failed_message(#call, result_)); \
} \
}
25 changes: 24 additions & 1 deletion src/sgl/device/python/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,22 @@ SGL_DICT_TO_DESC_FIELD(enable_conservative_rasterization, bool)
SGL_DICT_TO_DESC_FIELD(forced_sample_count, uint32_t)
SGL_DICT_TO_DESC_END()

SGL_DICT_TO_DESC_BEGIN(AspectBlendDesc)
SGL_DICT_TO_DESC_FIELD(src_factor, BlendFactor)
SGL_DICT_TO_DESC_FIELD(dst_factor, BlendFactor)
SGL_DICT_TO_DESC_FIELD(op, BlendOp)
SGL_DICT_TO_DESC_END()

SGL_DICT_TO_DESC_BEGIN(TargetBlendDesc)
SGL_DICT_TO_DESC_FIELD(enable_blend, bool)
SGL_DICT_TO_DESC_FIELD_DICT(color, AspectBlendDesc)
SGL_DICT_TO_DESC_FIELD_DICT(alpha, AspectBlendDesc)
SGL_DICT_TO_DESC_FIELD(logic_op, LogicOp)
SGL_DICT_TO_DESC_FIELD(write_mask, RenderTargetWriteMask)
SGL_DICT_TO_DESC_END()

SGL_DICT_TO_DESC_BEGIN(BlendDesc)
SGL_DICT_TO_DESC_FIELD(targets, std::vector<TargetBlendDesc>)
SGL_DICT_TO_DESC_FIELD_LIST(targets, TargetBlendDesc)
SGL_DICT_TO_DESC_FIELD(alpha_to_coverage_enable, bool)
SGL_DICT_TO_DESC_END()

Expand Down Expand Up @@ -178,12 +192,20 @@ SGL_PY_EXPORT(device_types)

nb::class_<AspectBlendDesc>(m, "AspectBlendDesc", D(AspectBlendDesc))
.def(nb::init<>())
.def(
"__init__",
[](AspectBlendDesc* self, nb::dict dict) { new (self) AspectBlendDesc(dict_to_AspectBlendDesc(dict)); }
)
.def_rw("src_factor", &AspectBlendDesc::src_factor, D(AspectBlendDesc, src_factor))
.def_rw("dst_factor", &AspectBlendDesc::dst_factor, D(AspectBlendDesc, dst_factor))
.def_rw("op", &AspectBlendDesc::op, D(AspectBlendDesc, op));

nb::class_<TargetBlendDesc>(m, "TargetBlendDesc", D(TargetBlendDesc))
.def(nb::init<>())
.def(
"__init__",
[](TargetBlendDesc* self, nb::dict dict) { new (self) TargetBlendDesc(dict_to_TargetBlendDesc(dict)); }
)
.def_rw("color", &TargetBlendDesc::color, D(TargetBlendDesc, color))
.def_rw("alpha", &TargetBlendDesc::alpha, D(TargetBlendDesc, alpha))
.def_rw("enable_blend", &TargetBlendDesc::enable_blend, D(TargetBlendDesc, enable_blend))
Expand All @@ -192,6 +214,7 @@ SGL_PY_EXPORT(device_types)

nb::class_<BlendDesc>(m, "BlendDesc", D(BlendDesc))
.def(nb::init<>())
.def("__init__", [](BlendDesc* self, nb::dict dict) { new (self) BlendDesc(dict_to_BlendDesc(dict)); })
.def_rw("targets", &BlendDesc::targets, D(BlendDesc, targets))
.def_rw(
"alpha_to_coverage_enable",
Expand Down
Loading

0 comments on commit 6fa4f1a

Please sign in to comment.