Fix assorted bugs caught by MSVC's debug STL, and some crashes, apparently from shaders without uniforms?

This commit is contained in:
Henrik Rydgard 2016-11-17 00:39:42 +01:00
Родитель 8ba9a3283c
Коммит 374d6ae984
8 изменённых файлов: 31 добавлений и 17 удалений

Просмотреть файл

@ -66,18 +66,20 @@ void HLSLCrossCompilerContext::DoDataTypeAnalysis(ShaderPhase *psPhase)
void HLSLCrossCompilerContext::ClearDependencyData()
{
if (!psDependencies)
return;
switch (psShader->eShaderType)
{
case PIXEL_SHADER:
{
psDependencies->ClearCrossDependencyData();
break;
}
case HULL_SHADER:
{
psDependencies->eTessPartitioning = TESSELLATOR_PARTITIONING_UNDEFINED;
psDependencies->eTessOutPrim = TESSELLATOR_OUTPUT_UNDEFINED;
break;
break;
}
default:
break;

Просмотреть файл

@ -28,15 +28,15 @@ namespace HLSLcc
using namespace std;
res.clear();
Instruction *i = &phase.psInst[0];
// A stack of loopinfo elements (stored in res)
list<LoopInfo *> loopStack;
// Storage for dummy LoopInfo elements to be used for switch-cases. We don't want them cluttering the Loops list so store them here.
list<LoopInfo> dummyLIForSwitches;
while (i != &*phase.psInst.end())
for (auto &inst : phase.psInst)
{
Instruction *i = &inst;
if (i->eOpcode == OPCODE_LOOP)
{
LoopInfo *currLoopInfo = &*res.insert(res.end(), LoopInfo());
@ -75,7 +75,6 @@ namespace HLSLcc
li->m_ExitPoints.push_back(i);
}
}
i++;
}
}
@ -348,6 +347,9 @@ namespace HLSLcc
Loops loops;
BuildLoopInfo(phase, loops);
if (!loops.size())
return;
std::for_each(loops.begin(), loops.end(), [&phase](LoopInfo &li)
{
// Some sanity checks: start and end points must be initialized, we shouldn't have any switches here, and each loop must have at least one exit point

Просмотреть файл

@ -1,4 +1,4 @@
#include <algorithm>
#include "internal_includes/Operand.h"
#include "internal_includes/debug.h"
#include "internal_includes/HLSLccToolkit.h"

Просмотреть файл

@ -402,7 +402,7 @@ static void ReadResources(const uint32_t* pui32Tokens,//in
psShaderInfo->psResourceBindings.clear();
psShaderInfo->psResourceBindings.resize(ui32NumResourceBindings);
psResBindings = &psShaderInfo->psResourceBindings[0];
psResBindings = !psShaderInfo->psResourceBindings.empty() ? &psShaderInfo->psResourceBindings[0] : nullptr;
for(i=0; i < ui32NumResourceBindings; ++i)
{
@ -415,7 +415,7 @@ static void ReadResources(const uint32_t* pui32Tokens,//in
psShaderInfo->psConstantBuffers.clear();
psShaderInfo->psConstantBuffers.resize(ui32NumConstantBuffers);
psConstantBuffers = &psShaderInfo->psConstantBuffers[0];
psConstantBuffers = ui32NumConstantBuffers ? &psShaderInfo->psConstantBuffers[0] : nullptr;
for(i=0; i < ui32NumConstantBuffers; ++i)
{

Просмотреть файл

@ -249,7 +249,7 @@ static void DeclareInput(
if (psShader->eShaderType != VERTEX_SHADER && (psContext->flags & HLSLCC_FLAG_SEPARABLE_SHADER_OBJECTS))
addLocation = true;
if (addLocation)
if (addLocation && psContext->psDependencies)
{
std::ostringstream oss;
oss << "layout(location = " << psContext->psDependencies->GetVaryingLocation(std::string(InputName), psShader->eShaderType, true) << ") ";
@ -262,7 +262,9 @@ static void DeclareInput(
// Do the reflection report on vertex shader inputs
if (psShader->eShaderType == VERTEX_SHADER)
{
psContext->m_Reflection.OnInputBinding(std::string(InputName), psContext->psDependencies->GetVaryingLocation(std::string(InputName), VERTEX_SHADER, true));
uint32_t varyingLoc = psContext->psDependencies ?
psContext->psDependencies->GetVaryingLocation(std::string(InputName), VERTEX_SHADER, true) : -1;
psContext->m_Reflection.OnInputBinding(std::string(InputName), varyingLoc);
}
switch (eIndexDim)
@ -835,8 +837,10 @@ static void DeclareUBOConstants(HLSLCrossCompilerContext* psContext, const uint3
/* [layout (location = X)] uniform vec4 HLSLConstantBufferName[numConsts]; */
if ((psContext->flags & HLSLCC_FLAG_VULKAN_BINDINGS) != 0)
{
GLSLCrossDependencyData::VulkanResourceBinding binding = psContext->psDependencies->GetVulkanResourceBinding(Name, false, 1);
bformata(glsl, "layout(set = %d, binding = %d, std140) ", binding.first, binding.second);
if (psContext->psDependencies) {
GLSLCrossDependencyData::VulkanResourceBinding binding = psContext->psDependencies->GetVulkanResourceBinding(Name, false, 1);
bformata(glsl, "layout(set = %d, binding = %d, std140) ", binding.first, binding.second);
}
}
else
{
@ -1224,8 +1228,10 @@ static void TranslateResourceTexture(HLSLCrossCompilerContext* psContext, const
std::string tname = TextureSamplerName(&psShader->sInfo, psDecl->asOperands[0].ui32RegisterNumber, *i, 0);
if ((psContext->flags & HLSLCC_FLAG_VULKAN_BINDINGS) != 0)
{
GLSLCrossDependencyData::VulkanResourceBinding binding = psContext->psDependencies->GetVulkanResourceBinding(tname);
bformata(glsl, "layout(set = %d, binding = %d) ", binding.first, binding.second);
if (psContext->psDependencies) {
GLSLCrossDependencyData::VulkanResourceBinding binding = psContext->psDependencies->GetVulkanResourceBinding(tname);
bformata(glsl, "layout(set = %d, binding = %d) ", binding.first, binding.second);
}
}
bcatcstr(glsl, "uniform ");
bcatcstr(glsl, samplerPrecision);
@ -1260,8 +1266,10 @@ static void TranslateResourceTexture(HLSLCrossCompilerContext* psContext, const
if ((psContext->flags & HLSLCC_FLAG_VULKAN_BINDINGS) != 0)
{
GLSLCrossDependencyData::VulkanResourceBinding binding = psContext->psDependencies->GetVulkanResourceBinding(tname);
bformata(glsl, "layout(set = %d, binding = %d) ", binding.first, binding.second);
if (psContext->psDependencies) {
GLSLCrossDependencyData::VulkanResourceBinding binding = psContext->psDependencies->GetVulkanResourceBinding(tname);
bformata(glsl, "layout(set = %d, binding = %d) ", binding.first, binding.second);
}
}
bcatcstr(glsl, "uniform ");
bcatcstr(glsl, samplerPrecision);

Просмотреть файл

@ -1,3 +1,4 @@
#include <algorithm>
#include "internal_includes/toGLSLOperand.h"
#include "internal_includes/HLSLccToolkit.h"
#include "internal_includes/HLSLCrossCompilerContext.h"

Просмотреть файл

@ -1024,7 +1024,7 @@ void ToMetal::TranslateDeclaration(const Declaration* psDecl)
if (psContext->psShader->eShaderType == VERTEX_SHADER)
{
std::ostringstream oss;
uint32_t loc = psContext->psDependencies->GetVaryingLocation(name, VERTEX_SHADER, true);
uint32_t loc = psContext->psDependencies ? psContext->psDependencies->GetVaryingLocation(name, VERTEX_SHADER, true) : -1;
oss << "attribute(" << loc << ")";
semantic = oss.str();
psContext->m_Reflection.OnInputBinding(name, loc);

Просмотреть файл

@ -1,3 +1,4 @@
#include <algorithm>
#include <stdio.h>
#include "internal_includes/HLSLccToolkit.h"
#include "internal_includes/HLSLCrossCompilerContext.h"