mirror of https://github.com/AxioDL/boo.git
Refactor GLSL shader bindings
This commit is contained in:
parent
5c91ba8da7
commit
44e8317d49
|
@ -20,7 +20,6 @@ class GLDataFactory : public IGraphicsDataFactory
|
||||||
static ThreadLocalPtr<struct GLData> m_deferredData;
|
static ThreadLocalPtr<struct GLData> m_deferredData;
|
||||||
std::unordered_set<struct GLData*> m_committedData;
|
std::unordered_set<struct GLData*> m_committedData;
|
||||||
std::mutex m_committedMutex;
|
std::mutex m_committedMutex;
|
||||||
std::vector<int> m_texUnis;
|
|
||||||
void destroyData(IGraphicsData*);
|
void destroyData(IGraphicsData*);
|
||||||
void destroyAllData();
|
void destroyAllData();
|
||||||
public:
|
public:
|
||||||
|
@ -54,7 +53,7 @@ public:
|
||||||
IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements);
|
IVertexFormat* newVertexFormat(size_t elementCount, const VertexElementDescriptor* elements);
|
||||||
|
|
||||||
IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource,
|
IShaderPipeline* newShaderPipeline(const char* vertSource, const char* fragSource,
|
||||||
size_t texCount, const char* texArrayName,
|
size_t texCount, const char** texNames,
|
||||||
size_t uniformBlockCount, const char** uniformBlockNames,
|
size_t uniformBlockCount, const char** uniformBlockNames,
|
||||||
BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
|
BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
|
||||||
bool depthTest, bool depthWrite, bool backfaceCulling);
|
bool depthTest, bool depthWrite, bool backfaceCulling);
|
||||||
|
|
|
@ -437,7 +437,7 @@ static const GLenum BLEND_FACTOR_TABLE[] =
|
||||||
|
|
||||||
IShaderPipeline* GLDataFactory::Context::newShaderPipeline
|
IShaderPipeline* GLDataFactory::Context::newShaderPipeline
|
||||||
(const char* vertSource, const char* fragSource,
|
(const char* vertSource, const char* fragSource,
|
||||||
size_t texCount, const char* texArrayName,
|
size_t texCount, const char** texNames,
|
||||||
size_t uniformBlockCount, const char** uniformBlockNames,
|
size_t uniformBlockCount, const char** uniformBlockNames,
|
||||||
BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
|
BlendFactor srcFac, BlendFactor dstFac, Primitive prim,
|
||||||
bool depthTest, bool depthWrite, bool backfaceCulling)
|
bool depthTest, bool depthWrite, bool backfaceCulling)
|
||||||
|
@ -511,17 +511,15 @@ IShaderPipeline* GLDataFactory::Context::newShaderPipeline
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texCount && texArrayName)
|
if (texCount && texNames)
|
||||||
{
|
{
|
||||||
GLint texLoc = glGetUniformLocation(shader.m_prog, texArrayName);
|
for (int i=0 ; i<texCount ; ++i)
|
||||||
if (texLoc < 0)
|
|
||||||
Log.report(logvisor::Error, "unable to find sampler variable '%s'", texArrayName);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (texCount > m_parent.m_texUnis.size())
|
GLint texLoc = glGetUniformLocation(shader.m_prog, texNames[i]);
|
||||||
for (size_t i=m_parent.m_texUnis.size() ; i<texCount ; ++i)
|
if (texLoc < 0)
|
||||||
m_parent.m_texUnis.push_back(i);
|
Log.report(logvisor::Error, "unable to find sampler variable '%s'", texNames[i]);
|
||||||
glUniform1iv(texLoc, m_parent.m_texUnis.size(), m_parent.m_texUnis.data());
|
else
|
||||||
|
glUniform1i(texLoc, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1258,7 +1258,7 @@ class VulkanTextureD : public ITextureD
|
||||||
texCreateInfo.arrayLayers = 1;
|
texCreateInfo.arrayLayers = 1;
|
||||||
texCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
texCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
texCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
texCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
texCreateInfo.initialLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
texCreateInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
texCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
texCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
texCreateInfo.queueFamilyIndexCount = 0;
|
texCreateInfo.queueFamilyIndexCount = 0;
|
||||||
texCreateInfo.pQueueFamilyIndices = nullptr;
|
texCreateInfo.pQueueFamilyIndices = nullptr;
|
||||||
|
@ -1274,7 +1274,6 @@ class VulkanTextureD : public ITextureD
|
||||||
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_gpuTex[i]));
|
ThrowIfFailed(vk::CreateImage(ctx->m_dev, &texCreateInfo, nullptr, &m_gpuTex[i]));
|
||||||
|
|
||||||
m_descInfo[i].sampler = ctx->m_linearSampler;
|
m_descInfo[i].sampler = ctx->m_linearSampler;
|
||||||
m_descInfo[i].imageView = m_gpuView[i];
|
|
||||||
m_descInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
m_descInfo[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1334,6 +1333,8 @@ public:
|
||||||
/* create image view */
|
/* create image view */
|
||||||
viewInfo.image = m_gpuTex[i];
|
viewInfo.image = m_gpuTex[i];
|
||||||
ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewInfo, nullptr, &m_gpuView[i]));
|
ThrowIfFailed(vk::CreateImageView(ctx->m_dev, &viewInfo, nullptr, &m_gpuView[i]));
|
||||||
|
|
||||||
|
m_descInfo[i].imageView = m_gpuView[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1758,7 +1759,7 @@ class VulkanShaderPipeline : public IShaderPipeline
|
||||||
depthStencilInfo.flags = 0;
|
depthStencilInfo.flags = 0;
|
||||||
depthStencilInfo.depthTestEnable = depthTest;
|
depthStencilInfo.depthTestEnable = depthTest;
|
||||||
depthStencilInfo.depthWriteEnable = depthWrite;
|
depthStencilInfo.depthWriteEnable = depthWrite;
|
||||||
depthStencilInfo.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
|
depthStencilInfo.depthCompareOp = VK_COMPARE_OP_GREATER_OR_EQUAL;
|
||||||
depthStencilInfo.front.compareOp = VK_COMPARE_OP_ALWAYS;
|
depthStencilInfo.front.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||||
depthStencilInfo.back.compareOp = VK_COMPARE_OP_ALWAYS;
|
depthStencilInfo.back.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||||
|
|
||||||
|
@ -2672,7 +2673,7 @@ void VulkanTextureD::update(int b)
|
||||||
vk::UnmapMemory(m_q->m_ctx->m_dev, m_cpuMem);
|
vk::UnmapMemory(m_q->m_ctx->m_dev, m_cpuMem);
|
||||||
|
|
||||||
SetImageLayout(cmdBuf, m_gpuTex[b], VK_IMAGE_ASPECT_COLOR_BIT,
|
SetImageLayout(cmdBuf, m_gpuTex[b], VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, 1);
|
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, 1);
|
||||||
|
|
||||||
/* Put the copy command into the command buffer */
|
/* Put the copy command into the command buffer */
|
||||||
|
@ -2742,7 +2743,7 @@ VulkanDataFactory::VulkanDataFactory(IGraphicsContext* parent, VulkanContext* ct
|
||||||
layoutBindings[i].binding = i;
|
layoutBindings[i].binding = i;
|
||||||
layoutBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
layoutBindings[i].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||||
layoutBindings[i].descriptorCount = 1;
|
layoutBindings[i].descriptorCount = 1;
|
||||||
layoutBindings[i].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
|
layoutBindings[i].stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
layoutBindings[i].pImmutableSamplers = nullptr;
|
layoutBindings[i].pImmutableSamplers = nullptr;
|
||||||
}
|
}
|
||||||
for (int i=BOO_GLSL_MAX_UNIFORM_COUNT ; i<BOO_GLSL_MAX_UNIFORM_COUNT+BOO_GLSL_MAX_TEXTURE_COUNT ; ++i)
|
for (int i=BOO_GLSL_MAX_UNIFORM_COUNT ; i<BOO_GLSL_MAX_UNIFORM_COUNT+BOO_GLSL_MAX_TEXTURE_COUNT ; ++i)
|
||||||
|
@ -2850,10 +2851,16 @@ IShaderPipeline* VulkanDataFactory::Context::newShaderPipeline
|
||||||
Log.report(logvisor::Fatal, "unable to link shader program\n%s", prog.getInfoLog());
|
Log.report(logvisor::Fatal, "unable to link shader program\n%s", prog.getInfoLog());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
glslang::GlslangToSpv(*prog.getIntermediate(EShLangVertex), vertBlobOut);
|
if (vertBlobOut.empty())
|
||||||
//spv::Disassemble(std::cerr, vertBlobOut);
|
{
|
||||||
glslang::GlslangToSpv(*prog.getIntermediate(EShLangFragment), fragBlobOut);
|
glslang::GlslangToSpv(*prog.getIntermediate(EShLangVertex), vertBlobOut);
|
||||||
//spv::Disassemble(std::cerr, fragBlobOut);
|
//spv::Disassemble(std::cerr, vertBlobOut);
|
||||||
|
}
|
||||||
|
if (fragBlobOut.empty())
|
||||||
|
{
|
||||||
|
glslang::GlslangToSpv(*prog.getIntermediate(EShLangFragment), fragBlobOut);
|
||||||
|
//spv::Disassemble(std::cerr, fragBlobOut);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VkShaderModuleCreateInfo smCreateInfo = {};
|
VkShaderModuleCreateInfo smCreateInfo = {};
|
||||||
|
|
|
@ -420,10 +420,12 @@ public:
|
||||||
sigemptyset(&s.sa_mask);
|
sigemptyset(&s.sa_mask);
|
||||||
s.sa_flags = 0;
|
s.sa_flags = 0;
|
||||||
sigaction(SIGINT, &s, nullptr);
|
sigaction(SIGINT, &s, nullptr);
|
||||||
|
sigaction(SIGUSR2, &s, nullptr);
|
||||||
|
|
||||||
sigset_t waitmask, origmask;
|
sigset_t waitmask, origmask;
|
||||||
sigemptyset(&waitmask);
|
sigemptyset(&waitmask);
|
||||||
sigaddset(&waitmask, SIGINT);
|
sigaddset(&waitmask, SIGINT);
|
||||||
|
sigaddset(&waitmask, SIGUSR2);
|
||||||
pthread_sigmask(SIG_BLOCK, &waitmask, &origmask);
|
pthread_sigmask(SIG_BLOCK, &waitmask, &origmask);
|
||||||
|
|
||||||
/* Spawn client thread */
|
/* Spawn client thread */
|
||||||
|
@ -437,7 +439,7 @@ public:
|
||||||
innerLk.unlock();
|
innerLk.unlock();
|
||||||
initcv.notify_one();
|
initcv.notify_one();
|
||||||
clientReturn = m_callback.appMain(this);
|
clientReturn = m_callback.appMain(this);
|
||||||
pthread_kill(mainThread, SIGINT);
|
pthread_kill(mainThread, SIGUSR2);
|
||||||
});
|
});
|
||||||
initcv.wait(outerLk);
|
initcv.wait(outerLk);
|
||||||
|
|
||||||
|
@ -450,7 +452,7 @@ public:
|
||||||
FD_SET(m_dbusFd, &fds);
|
FD_SET(m_dbusFd, &fds);
|
||||||
if (pselect(m_maxFd+1, &fds, NULL, NULL, NULL, &origmask) < 0)
|
if (pselect(m_maxFd+1, &fds, NULL, NULL, NULL, &origmask) < 0)
|
||||||
{
|
{
|
||||||
/* SIGINT handled here */
|
/* SIGINT/SIGUSR2 handled here */
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,15 +296,17 @@ struct TestApplicationCallback : IApplicationCallback
|
||||||
"#version 330\n"
|
"#version 330\n"
|
||||||
BOO_GLSL_BINDING_HEAD
|
BOO_GLSL_BINDING_HEAD
|
||||||
"precision highp float;\n"
|
"precision highp float;\n"
|
||||||
"TBINDING0 uniform sampler2D texs[1];\n"
|
"TBINDING0 uniform sampler2D tex;\n"
|
||||||
"layout(location=0) out vec4 out_frag;\n"
|
"layout(location=0) out vec4 out_frag;\n"
|
||||||
"in vec2 out_uv;\n"
|
"in vec2 out_uv;\n"
|
||||||
"void main()\n"
|
"void main()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" out_frag = texture(texs[0], out_uv);\n"
|
" out_frag = texture(tex, out_uv);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
pipeline = glF.newShaderPipeline(VS, FS, 1, "texs", 0, nullptr,
|
static const char* texName = "tex";
|
||||||
|
|
||||||
|
pipeline = glF.newShaderPipeline(VS, FS, 1, &texName, 0, nullptr,
|
||||||
BlendFactor::One, BlendFactor::Zero,
|
BlendFactor::One, BlendFactor::Zero,
|
||||||
Primitive::TriStrips, true, true, false);
|
Primitive::TriStrips, true, true, false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue