Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit Resource Bindings in OpenGL #51

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,4 @@ set(CMAKE_C_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
add_subdirectory(Core)
add_subdirectory(Tests)
add_subdirectory(Tools)
if(SC_WITH_CSHARP)
add_subdirectory(Wrapper)
endif()
add_subdirectory(Wrapper)
gongminmin marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 19 additions & 1 deletion Source/Core/ShaderConductor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,23 @@ namespace
const char* functionName = "DxcCreateInstance";

#ifdef _WIN32
m_dxcompilerDll = ::LoadLibraryA(dllName);
HMODULE hm = NULL;
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) "DllMain",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(LPCSTR)"DllMain"
can be changed to
TEXT("DllMain")
to make it compatible to both MBCS and UNICODE. Or just use GetModuleHandleExA without C-style case to DllMain. Same as GetModuleFileName below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that it is interesting.

&hm) != 0)
{
char path[MAX_PATH];
if (GetModuleFileName(hm, path, sizeof(path)) != 0)
{
PathRemoveFileSpec(path);
char finalPath[MAX_PATH];
m_dxcompilerDll = ::LoadLibraryA(PathCombine(finalPath, path, dllName));
}
}

if (m_dxcompilerDll == nullptr)
{
m_dxcompilerDll = ::LoadLibraryA(dllName);
}
#else
m_dxcompilerDll = ::dlopen(dllName, RTLD_LAZY);
#endif
Expand Down Expand Up @@ -719,6 +735,8 @@ namespace

for (auto& remap : compiler->get_combined_image_samplers())
{
uint32_t binding = compiler->get_decoration(remap.image_id, spv::DecorationBinding); // or sampler_id.
compiler->set_decoration(remap.combined_id, spv::DecorationBinding, binding);
compiler->set_name(remap.combined_id,
"SPIRV_Cross_Combined" + compiler->get_name(remap.image_id) + compiler->get_name(remap.sampler_id));
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Tests/Data/Expected/ToneMapping_PS.310.essl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ layout(binding = 0, std140) uniform type_cbPS
highp float lumStrength;
} cbPS;

uniform highp sampler2D SPIRV_Cross_CombinedcolorTexpointSampler;
uniform highp sampler2D SPIRV_Cross_CombinedbloomTexlinearSampler;
uniform highp sampler2D SPIRV_Cross_CombinedlumTexpointSampler;
layout(binding = 0) uniform highp sampler2D SPIRV_Cross_CombinedcolorTexpointSampler;
layout(binding = 2) uniform highp sampler2D SPIRV_Cross_CombinedbloomTexlinearSampler;
layout(binding = 1) uniform highp sampler2D SPIRV_Cross_CombinedlumTexpointSampler;

layout(location = 0) in highp vec2 in_var_TEXCOORD0;
layout(location = 0) out highp vec4 out_var_SV_Target;
Expand Down
34 changes: 19 additions & 15 deletions Source/Wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,28 @@ add_dependencies(${DLL_NAME} ShaderConductor)

set_target_properties(${DLL_NAME} PROPERTIES FOLDER "Wrapper")

set(CSHARP_TEST CSharpPinvoke)
if(SC_WITH_CSHARP)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be:
if(NOT SC_WITH_CSHARP)
return()
endif()
to avoid indent most lines in this file.


set(SOURCE_FILES
Program.cs
Wrapper.cs
)
set(CSHARP_TEST CSharpPinvoke)

set(DATA_FILES
shader.hlsl
)
set(SOURCE_FILES
Program.cs
Wrapper.cs
)

set_source_files_properties(${DATA_FILES}
PROPERTIES VS_TOOL_OVERRIDE "None"
VS_COPY_TO_OUT_DIR "PreserveNewest"
)
set(DATA_FILES
shader.hlsl
)

set_source_files_properties(${DATA_FILES}
PROPERTIES VS_TOOL_OVERRIDE "None"
VS_COPY_TO_OUT_DIR "PreserveNewest"
)

add_executable(${CSHARP_TEST} ${SOURCE_FILES} ${DATA_FILES})
add_dependencies(${CSHARP_TEST} ShaderConductorWrapper)

add_executable(${CSHARP_TEST} ${SOURCE_FILES} ${DATA_FILES})
add_dependencies(${CSHARP_TEST} ShaderConductorWrapper)
set_target_properties(${CSHARP_TEST} PROPERTIES FOLDER "Wrapper")

set_target_properties(${CSHARP_TEST} PROPERTIES FOLDER "Wrapper")
endif()

1 change: 1 addition & 0 deletions Source/Wrapper/Native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "Native.h"
#include <ShaderConductor/ShaderConductor.hpp>
#include <cstring>
#include <iostream>

using namespace ShaderConductor;
Expand Down
33 changes: 24 additions & 9 deletions Source/Wrapper/Native.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,27 @@ struct DisassembleDescription
int binarySize;
};

#define DLLEXPORT extern "C" __declspec(dllexport)

DLLEXPORT void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, ResultDescription* result);
DLLEXPORT void Disassemble(DisassembleDescription* source, ResultDescription* result);

DLLEXPORT ShaderConductorBlob* CreateShaderConductorBlob(const void* data, int size);
DLLEXPORT void DestroyShaderConductorBlob(ShaderConductorBlob* blob);
DLLEXPORT const void* GetShaderConductorBlobData(ShaderConductorBlob* blob);
DLLEXPORT int GetShaderConductorBlobSize(ShaderConductorBlob* blob);
#if defined(__clang__)
#define SC_SYMBOL_EXPORT __attribute__((__visibility__("default")))
#define SC_SYMBOL_IMPORT
#elif defined(__GNUC__)
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
#define SC_SYMBOL_EXPORT __attribute__((__dllexport__))
#define SC_SYMBOL_IMPORT __attribute__((__dllimport__))
#else
#define SC_SYMBOL_EXPORT __attribute__((__visibility__("default")))
#define SC_SYMBOL_IMPORT
#endif
#elif defined(_MSC_VER)
#define SC_SYMBOL_EXPORT __declspec(dllexport)
#define SC_SYMBOL_IMPORT __declspec(dllimport)
#endif

extern "C" SC_SYMBOL_EXPORT void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target,
ResultDescription* result);
extern "C" SC_SYMBOL_EXPORT void Disassemble(DisassembleDescription* source, ResultDescription* result);

extern "C" SC_SYMBOL_EXPORT ShaderConductorBlob* CreateShaderConductorBlob(const void* data, int size);
extern "C" SC_SYMBOL_EXPORT void DestroyShaderConductorBlob(ShaderConductorBlob* blob);
extern "C" SC_SYMBOL_EXPORT const void* GetShaderConductorBlobData(ShaderConductorBlob* blob);
extern "C" SC_SYMBOL_EXPORT int GetShaderConductorBlobSize(ShaderConductorBlob* blob);
3 changes: 2 additions & 1 deletion Source/Wrapper/shader.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cbuffer Matrices : register(b0)

Texture2D DiffuseTexture : register(t0);
SamplerState Sampler : register(s0);
Texture2D DiffuseTexture2 : register(t1);

struct VS_IN
{
Expand Down Expand Up @@ -36,5 +37,5 @@ PS_IN VS(VS_IN input)

float4 PS(PS_IN input) : SV_Target
{
return DiffuseTexture.Sample(Sampler, input.tex);
return DiffuseTexture.Sample(Sampler, input.tex) + DiffuseTexture2.Sample(Sampler, input.tex);
}