Skip to content
Merged
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
27 changes: 11 additions & 16 deletions ShaderConverter/ShaderConv/ShaderConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ HRESULT ShaderConverterAPI::ConvertTLShader(ConvertTLShaderArgs& args)
if (SUCCEEDED(hr) && m_pTranslator)
{
const CTLVertexShaderDesc desc(args.vsInputDecl, args.shaderSettings);
CCodeBlob* pCodeBlob;

CComPtr<CCodeBlob> pCodeBlob;
hr = m_pTranslator->TranslateTLVS(&desc, &pCodeBlob);
if (SUCCEEDED(hr) && pCodeBlob)
{
Expand Down Expand Up @@ -103,7 +103,7 @@ HRESULT ShaderConverterAPI::ConvertShader(ConvertShaderArgs& args)
VSInputDecls* pVSin = args.pVsInputDecl;
VSOutputDecls* pVSout = args.pVsOutputDecl;
const RasterStates& rasterState = args.rasterStates;
CCodeBlob* pBlob = nullptr;
CComPtr<CCodeBlob> pCodeBlob;

if (m_pTranslator == nullptr)
{
Expand Down Expand Up @@ -135,7 +135,7 @@ HRESULT ShaderConverterAPI::ConvertShader(ConvertShaderArgs& args)
*pVSin = pDesc->GetInputDecls();
memcpy(pVSout, &pDesc->GetOutputDecls(), sizeof(*pVSout));

hr = m_pTranslator->TranslateVS(pDesc, rasterState, &pBlob);
hr = m_pTranslator->TranslateVS(pDesc, rasterState, &pCodeBlob);

for (UINT i = 0; i < ARRAYSIZE(args.m_inlineConsts); i++)
{
Expand Down Expand Up @@ -170,7 +170,7 @@ HRESULT ShaderConverterAPI::ConvertShader(ConvertShaderArgs& args)

VSOutputDecls updatedInputDecls;
pDesc->UpdateInputDecls(*pPSin, rasterState, &updatedInputDecls);
hr = m_pTranslator->TranslatePS(pDesc, rasterState, updatedInputDecls, &pBlob);
hr = m_pTranslator->TranslatePS(pDesc, rasterState, updatedInputDecls, &pCodeBlob);

AddAllAddedSystemSemantics(updatedInputDecls, args.AddedSystemSemantics);

Expand All @@ -192,22 +192,22 @@ HRESULT ShaderConverterAPI::ConvertShader(ConvertShaderArgs& args)
args.totalInstructionsEmitted = translationData.NumInstructionsEmitted;
args.totalExtraInstructionsEmitted = translationData.NumExtraInstructionsEmitted;

if (SUCCEEDED(hr) && pBlob)
if (SUCCEEDED(hr) && pCodeBlob)
{
// DXBC needs to be 4 byte aligned for dxilconv
UINT padding = 0;
UINT bufferSizeMod4 = pBlob->GetBufferSize() % 4;
UINT bufferSizeMod4 = pCodeBlob->GetBufferSize() % 4;
if (bufferSizeMod4 != 0)
{
padding = 4 - bufferSizeMod4;
}
hr = AllocTemporarySpace(args.convertedByteCode, pBlob->GetBufferSize());
hr = AllocTemporarySpace(args.convertedByteCode, pCodeBlob->GetBufferSize());
if (SUCCEEDED(hr))
{
memcpy(args.convertedByteCode.m_pByteCode, pBlob->GetBufferPointer(), pBlob->GetBufferSize());
memcpy(args.convertedByteCode.m_pByteCode, pCodeBlob->GetBufferPointer(), pCodeBlob->GetBufferSize());
if (padding > 0)
{
ZeroMemory((BYTE*)args.convertedByteCode.m_pByteCode + pBlob->GetBufferSize(), padding);
ZeroMemory((BYTE*)args.convertedByteCode.m_pByteCode + pCodeBlob->GetBufferSize(), padding);
}
}
else
Expand All @@ -217,11 +217,6 @@ HRESULT ShaderConverterAPI::ConvertShader(ConvertShaderArgs& args)
}
}

if (pBlob)
{
pBlob->Release();
}

return hr;
}

Expand All @@ -231,7 +226,7 @@ HRESULT ShaderConverterAPI::CreateGeometryShader(CreateGeometryShaderArgs& args)

CGeometryShaderDesc geoDesc = CGeometryShaderDesc(args.m_ApiVersion, args.m_ShaderSettings, args.m_VsOutputDecls, args.m_RasterStates);

CCodeBlob* pCodeBlob = {};
CComPtr<CCodeBlob> pCodeBlob;

// Translate the shader code from HLSL 2.0 to 4.0
hr = m_pTranslator->TranslateGS(&geoDesc, &pCodeBlob);
Expand Down
1 change: 1 addition & 0 deletions ShaderConverter/ShaderConv/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#undef WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <atlbase.h>
#include <strsafe.h>
#include <ShaderConvCommon.h>

Expand Down
Loading