Skip to content

Commit

Permalink
Using a safer header cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
feiy committed Jul 9, 2020
1 parent b649a80 commit 48d8062
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace VkInline
#endif

bool m_verbose;
std::unordered_map<std::string, const char*> m_header_map;
std::unordered_map<std::string, std::string> m_header_map;
std::vector<std::string> m_code_blocks;

std::string m_header_of_dynamic_code;
Expand Down
22 changes: 11 additions & 11 deletions glslc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ const TBuiltInResource DefaultTBuiltInResource =

class BuiltInIncluder : public glslang::TShader::Includer
{
const std::unordered_map<std::string, const char*>* m_headers;
const std::unordered_map<std::string, std::string>* m_headers;
public:
BuiltInIncluder(const std::unordered_map<std::string, const char*>* headers = nullptr)
BuiltInIncluder(const std::unordered_map<std::string, std::string>* headers = nullptr)
{
m_headers = headers;
}
Expand All @@ -130,7 +130,7 @@ class BuiltInIncluder : public glslang::TShader::Includer
auto iter = m_headers->find(headerName);
if (iter != m_headers->end())
{
IncludeResult* result = new IncludeResult(headerName, iter->second, strlen(iter->second), nullptr);
IncludeResult* result = new IncludeResult(headerName, iter->second.c_str(), iter->second.length(), nullptr);
return result;
}
}
Expand All @@ -143,7 +143,7 @@ class BuiltInIncluder : public glslang::TShader::Includer
}
};

bool GLSL2SPV(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV, EShLanguage ShaderType)
bool GLSL2SPV(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV, EShLanguage ShaderType)
{
glslang::InitializeProcess();
glslang::TShader Shader(ShaderType);
Expand Down Expand Up @@ -214,37 +214,37 @@ bool GLSL2SPV(const char* InputCString, const std::unordered_map<std::string, co

}

bool GLSL2SPV_Compute(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV)
bool GLSL2SPV_Compute(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV)
{
return GLSL2SPV(InputCString, headers, SpirV, EShLangCompute);
}

bool GLSL2SPV_Vertex(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV)
bool GLSL2SPV_Vertex(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV)
{
return GLSL2SPV(InputCString, headers, SpirV, EShLangVertex);
}

bool GLSL2SPV_Fragment(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV)
bool GLSL2SPV_Fragment(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV)
{
return GLSL2SPV(InputCString, headers, SpirV, EShLangFragment);
}

bool GLSL2SPV_Raygen(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV)
bool GLSL2SPV_Raygen(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV)
{
return GLSL2SPV(InputCString, headers, SpirV, EShLangRayGen);
}

bool GLSL2SPV_Miss(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV)
bool GLSL2SPV_Miss(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV)
{
return GLSL2SPV(InputCString, headers, SpirV, EShLangMiss);
}

bool GLSL2SPV_ClosestHit(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV)
bool GLSL2SPV_ClosestHit(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV)
{
return GLSL2SPV(InputCString, headers, SpirV, EShLangClosestHit);
}

bool GLSL2SPV_Intersect(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV)
bool GLSL2SPV_Intersect(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV)
{
return GLSL2SPV(InputCString, headers, SpirV, EShLangIntersect);
}
6 changes: 3 additions & 3 deletions internal/impl_context.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ using namespace SPIRV_CROSS_NAMESPACE;
#include <unqlite.h>
#include "crc64.h"

bool GLSL2SPV_Compute(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Vertex(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Fragment(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Compute(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Vertex(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Fragment(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV);

namespace VkInline
{
Expand Down
8 changes: 4 additions & 4 deletions internal/impl_context_ex.inl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bool GLSL2SPV_Raygen(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Miss(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_ClosestHit(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Intersect(const char* InputCString, const std::unordered_map<std::string, const char*>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Raygen(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Miss(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_ClosestHit(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV);
bool GLSL2SPV_Intersect(const char* InputCString, const std::unordered_map<std::string, std::string>* headers, std::vector<unsigned int>& SpirV);

namespace VkInline
{
Expand Down
3 changes: 2 additions & 1 deletion python/VkInline/SVBuffer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .Native import ffi, native
from .ShaderViewable import ShaderViewable
import ctypes

class SVBuffer(ShaderViewable):
def __init__(self, elem_type, size, ptr_host_data=None):
Expand All @@ -21,6 +22,6 @@ def from_host(self, ptr_host_data):
native.n_svbuffer_from_host(self.m_cptr, ffi.cast("void *", ptr_host_data))

def to_host(self, ptr_host_data, begin = 0, end = -1):
native.n_svbuffer_to_host(self.m_cptr, ffi.cast("void *", ptr_host_data), begin, end)
native.n_svbuffer_to_host(self.m_cptr, ffi.cast("void *", ptr_host_data), ctypes.c_ulonglong(begin).value, ctypes.c_ulonglong(end).value)


0 comments on commit 48d8062

Please sign in to comment.