summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-04-16 10:34:26 -0700
committerGitHub <noreply@github.com>2021-04-16 10:34:26 -0700
commit79e92395f8ce3d92c446e3bb3250d19ce33decd5 (patch)
tree2ac277fa299200da72cf03a2b5b96338f66aee5d /tools
parentbad484d838590d0a2aaf1b5b8ac820634af2decb (diff)
Update `model-viewer` example and fixing compiler bugs. (#1795)
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp1
-rw-r--r--tools/gfx/slang-context.h1
-rw-r--r--tools/platform/model.cpp21
-rw-r--r--tools/platform/model.h22
-rw-r--r--tools/platform/platform-api.h23
-rw-r--r--tools/platform/window.h19
6 files changed, 50 insertions, 37 deletions
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index 15acb680c..e02f7d656 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -4804,6 +4804,7 @@ Result D3D12Device::createProgram(const IShaderProgram::Desc& desc, IShaderProgr
(SlangInt)i, 0, kernelCode.writeRef(), diagnostics.writeRef());
if (diagnostics)
{
+ printf("%s\n", diagnostics->getBufferPointer());
// TODO: report compile error.
}
SLANG_RETURN_ON_FAIL(compileResult);
diff --git a/tools/gfx/slang-context.h b/tools/gfx/slang-context.h
index d5bf261e4..be6539da5 100644
--- a/tools/gfx/slang-context.h
+++ b/tools/gfx/slang-context.h
@@ -34,6 +34,7 @@ namespace gfx
targetDesc.profile = globalSession->findProfile(targetProfile);
targetDesc.optimizationLevel = desc.optimizationLevel;
targetDesc.floatingPointMode = desc.floatingPointMode;
+ targetDesc.flags = desc.targetFlags;
slangSessionDesc.targetCount = 1;
slangSessionDesc.targets = &targetDesc;
SLANG_RETURN_ON_FAIL(globalSession->createSession(slangSessionDesc, session.writeRef()));
diff --git a/tools/platform/model.cpp b/tools/platform/model.cpp
index 54c171e54..fadfcc0e2 100644
--- a/tools/platform/model.cpp
+++ b/tools/platform/model.cpp
@@ -20,7 +20,10 @@
#include <unordered_map>
#include <unordered_set>
-namespace gfx {
+namespace platform {
+
+using namespace gfx;
+using namespace Slang;
// TinyObj provides a tuple type that bundles up indices, but doesn't
// provide equality comparison or hashing for that type. We'd like
@@ -70,11 +73,11 @@ bool operator==(SmoothingGroupVertexID const& left, SmoothingGroupVertexID const
namespace std
{
- template<> struct hash<gfx::ObjIndexKey>
+ template<> struct hash<platform::ObjIndexKey>
{
- size_t operator()(gfx::ObjIndexKey const& key) const
+ size_t operator()(platform::ObjIndexKey const& key) const
{
- gfx::Hasher hasher;
+ platform::Hasher hasher;
hasher.add(key.index.vertex_index);
hasher.add(key.index.normal_index);
hasher.add(key.index.texcoord_index);
@@ -82,11 +85,11 @@ namespace std
}
};
- template<> struct hash<gfx::SmoothingGroupVertexID>
+ template <> struct hash<platform::SmoothingGroupVertexID>
{
- size_t operator()(gfx::SmoothingGroupVertexID const& id) const
+ size_t operator()(platform::SmoothingGroupVertexID const& id) const
{
- gfx::Hasher hasher;
+ platform::Hasher hasher;
hasher.add(id.smoothingGroup);
hasher.add(id.positionID);
return hasher.state;
@@ -94,7 +97,7 @@ namespace std
};
}
-namespace gfx
+namespace platform
{
ComPtr<ITextureResource> loadTextureImage(
@@ -202,7 +205,7 @@ static std::string makeString(const char* start, const char* end)
return std::string(start, size_t(end - start));
}
-Result ModelLoader::load(
+SlangResult ModelLoader::load(
char const* inputPath,
void** outModel)
{
diff --git a/tools/platform/model.h b/tools/platform/model.h
index 8cff2c67d..b4aff9273 100644
--- a/tools/platform/model.h
+++ b/tools/platform/model.h
@@ -7,7 +7,9 @@
#include <vector>
#include <string>
-namespace gfx {
+#include "platform-api.h"
+
+namespace platform {
struct ModelLoader
{
@@ -17,7 +19,7 @@ struct ModelLoader
glm::vec3 specularColor;
float specularity;
- ComPtr<ITextureResource> diffuseMap;
+ Slang::ComPtr<gfx::ITextureResource> diffuseMap;
};
struct Vertex
@@ -39,9 +41,9 @@ struct ModelLoader
struct ModelData
{
- ComPtr<IBufferResource> vertexBuffer;
- ComPtr<IBufferResource> indexBuffer;
- PrimitiveTopology primitiveTopology;
+ Slang::ComPtr<gfx::IBufferResource> vertexBuffer;
+ Slang::ComPtr<gfx::IBufferResource> indexBuffer;
+ gfx::PrimitiveTopology primitiveTopology;
int vertexCount;
int indexCount;
int meshCount;
@@ -65,12 +67,12 @@ struct ModelLoader
FlipWinding = 1 << 0,
};
- ICallbacks* callbacks = nullptr;
- Slang::ComPtr<IDevice> device;
- LoadFlags loadFlags = 0;
- float scale = 1.0f;
+ ICallbacks* callbacks = nullptr;
+ gfx::IDevice* device;
+ LoadFlags loadFlags = 0;
+ float scale = 1.0f;
- Result load(char const* inputPath, void** outModel);
+ SLANG_PLATFORM_API SlangResult load(char const* inputPath, void** outModel);
};
diff --git a/tools/platform/platform-api.h b/tools/platform/platform-api.h
new file mode 100644
index 000000000..b04e5ffce
--- /dev/null
+++ b/tools/platform/platform-api.h
@@ -0,0 +1,23 @@
+#ifndef SLANG_PLATFORM_API_H
+#define SLANG_PLATFORM_API_H
+
+#if defined(SLANG_PLATFORM_DYNAMIC)
+# if defined(_MSC_VER)
+# ifdef SLANG_PLATFORM_DYNAMIC_EXPORT
+# define SLANG_PLATFORM_API SLANG_DLL_EXPORT
+# else
+# define SLANG_PLATFORM_API __declspec(dllimport)
+# endif
+# else
+// TODO: need to consider compiler capabilities
+//# ifdef SLANG_DYNAMIC_EXPORT
+# define SLANG_PLATFORM_API SLANG_DLL_EXPORT
+//# endif
+# endif
+#endif
+
+#ifndef SLANG_PLATFORM_API
+# define SLANG_PLATFORM_API
+#endif
+
+#endif
diff --git a/tools/platform/window.h b/tools/platform/window.h
index 65e0508b6..f80e21302 100644
--- a/tools/platform/window.h
+++ b/tools/platform/window.h
@@ -5,24 +5,7 @@
#include "source/core/slang-basic.h"
#include "source/core/slang-func-ptr.h"
-#if defined(SLANG_PLATFORM_DYNAMIC)
-# if defined(_MSC_VER)
-# ifdef SLANG_PLATFORM_DYNAMIC_EXPORT
-# define SLANG_PLATFORM_API SLANG_DLL_EXPORT
-# else
-# define SLANG_PLATFORM_API __declspec(dllimport)
-# endif
-# else
-// TODO: need to consider compiler capabilities
-//# ifdef SLANG_DYNAMIC_EXPORT
-# define SLANG_PLATFORM_API SLANG_DLL_EXPORT
-//# endif
-# endif
-#endif
-
-#ifndef SLANG_PLATFORM_API
-# define SLANG_PLATFORM_API
-#endif
+#include "platform-api.h"
namespace platform {