Skip to content

Commit

Permalink
Fix /permissive- issues for Effects11
Browse files Browse the repository at this point in the history
This isn't our library but since Microsoft stopped developing it
adding patches shouldn't be an issue.
  • Loading branch information
Paxxi committed Oct 15, 2021
1 parent f373644 commit 07336f2
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 430 deletions.
8 changes: 5 additions & 3 deletions lib/win32/Effects11/Binary/SOParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class CSOParser
HRESULT Parse( _In_ uint32_t Stream, _In_z_ LPCSTR pString )
{
HRESULT hr = S_OK;
LPSTR pSemantic = nullptr;

m_pError[0] = 0;

Expand All @@ -122,7 +123,7 @@ class CSOParser
VN( m_SemanticString[Stream] = new char[len + 1] );
strcpy_s( m_SemanticString[Stream], len + 1, pString );

LPSTR pSemantic = m_SemanticString[Stream];
pSemantic = m_SemanticString[Stream];

while( true )
{
Expand Down Expand Up @@ -245,7 +246,8 @@ class CSOParser
_Analysis_assume_( ppSemantic && *ppSemantic );

HRESULT hr = S_OK;
LPSTR pColon = strchr( *ppSemantic, ':' );
LPSTR pColon = strchr( *ppSemantic, ':' );
int outputSlot = 0;

if( pColon == nullptr )
return S_OK;
Expand All @@ -258,7 +260,7 @@ class CSOParser
}

*pColon = '\0';
int outputSlot = atoi( *ppSemantic );
outputSlot = atoi(*ppSemantic);
if( outputSlot < 0 || outputSlot > 255 )
{
strcpy_s( m_pError, MAX_ERROR_SIZE,
Expand Down
3 changes: 3 additions & 0 deletions lib/win32/Effects11/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#include "EffectBinaryFormat.h"
#include "IUnknownImp.h"
#include "d3dxGlobal.h"

#include <cassert>

#ifdef _DEBUG
extern void __cdecl D3DXDebugPrintf(UINT lvl, _In_z_ _Printf_format_string_ LPCSTR szFormat, ...);
Expand Down
19 changes: 13 additions & 6 deletions lib/win32/Effects11/EffectAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ HRESULT WINAPI D3DX11CreateEffectFromFile( LPCWSTR pFileName, UINT FXFlags, ID3D

std::unique_ptr<uint8_t[]> fileData;
uint32_t size;
int result = 0;
CHAR* pstrName = nullptr;
HRESULT hr = LoadBinaryFromFile( pFileName, fileData, size );
if ( FAILED(hr) )
return hr;
Expand All @@ -140,15 +142,16 @@ HRESULT WINAPI D3DX11CreateEffectFromFile( LPCWSTR pFileName, UINT FXFlags, ID3D

// Create debug object name from input filename
CHAR strFileA[MAX_PATH];
int result = WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH, nullptr, FALSE );
result = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH,
nullptr, FALSE);
if ( !result )
{
DPF(0, "Failed to load effect file due to WC to MB conversion failure: %ls", pFileName);
hr = E_FAIL;
goto lExit;
}

const CHAR* pstrName = strrchr( strFileA, '\\' );
pstrName = strrchr(strFileA, '\\');
if (!pstrName)
{
pstrName = strFileA;
Expand Down Expand Up @@ -226,6 +229,8 @@ HRESULT D3DX11CompileEffectFromFile( LPCWSTR pFileName,
}

ID3DBlob *blob = nullptr;
CHAR* pstrName = nullptr;
int result = 0;

#if (D3D_COMPILER_VERSION >= 46) && ( !defined(WINAPI_FAMILY) || ( (WINAPI_FAMILY != WINAPI_FAMILY_APP) && (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) ) )

Expand All @@ -249,14 +254,15 @@ HRESULT D3DX11CompileEffectFromFile( LPCWSTR pFileName,

// Create debug object name from input filename
CHAR strFileA[MAX_PATH];
int result = WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH, nullptr, FALSE );
result = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH,
nullptr, FALSE);
if ( !result )
{
DPF(0, "Failed to load effect file due to WC to MB conversion failure: %ls", pFileName);
return E_FAIL;
}

const CHAR* pstrName = strrchr( strFileA, '\\' );
pstrName = strrchr(strFileA, '\\');
if (!pstrName)
{
pstrName = strFileA;
Expand Down Expand Up @@ -290,15 +296,16 @@ HRESULT D3DX11CompileEffectFromFile( LPCWSTR pFileName,
#if (D3D_COMPILER_VERSION >= 46) && ( !defined(WINAPI_FAMILY) || ( (WINAPI_FAMILY != WINAPI_FAMILY_APP) && (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) ) )
// Create debug object name from input filename
CHAR strFileA[MAX_PATH];
int result = WideCharToMultiByte( CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH, nullptr, FALSE );
result = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, pFileName, -1, strFileA, MAX_PATH,
nullptr, FALSE);
if ( !result )
{
DPF(0, "Failed to load effect file due to WC to MB conversion failure: %ls", pFileName);
hr = E_FAIL;
goto lExit;
}

const CHAR* pstrName = strrchr( strFileA, '\\' );
pstrName = strrchr(strFileA, '\\');
if (!pstrName)
{
pstrName = strFileA;
Expand Down
15 changes: 9 additions & 6 deletions lib/win32/Effects11/EffectLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ HRESULT CEffectLoader::LoadEffect(CEffect *pEffect, const void *pEffectBuffer, u
HRESULT hr = S_OK;
uint32_t i, varSize, cMemberDataBlocks;
CCheckedDword chkVariables = 0;
uint32_t oStructured = 0;

// Used for cloning
m_pvOldMemberInterfaces = nullptr;
Expand Down Expand Up @@ -875,7 +876,7 @@ HRESULT CEffectLoader::LoadEffect(CEffect *pEffect, const void *pEffectBuffer, u
VN( m_pEffect->m_pRenderTargetViews = PRIVATENEW SRenderTargetView[m_pHeader->cRenderTargetViews] );
VN( m_pEffect->m_pDepthStencilViews = PRIVATENEW SDepthStencilView[m_pHeader->cDepthStencilViews] );

uint32_t oStructured = m_pHeader->cbUnstructured + sizeof(SBinaryHeader5);
oStructured = m_pHeader->cbUnstructured + sizeof(SBinaryHeader5);
VHD( m_msStructured.Seek(oStructured), "Invalid pEffectBuffer: Missing structured data block." );
VH( m_msUnstructured.SetData(m_pData + sizeof(SBinaryHeader5), oStructured - sizeof(SBinaryHeader5)) );

Expand Down Expand Up @@ -994,7 +995,8 @@ HRESULT CEffectLoader::LoadTypeAndAddToPool(SType **ppType, uint32_t dwOffset)
uint8_t *pHashBuffer;
uint32_t hash;
SVariable *pTempMembers = nullptr;

uint32_t cElements = 0;

m_HashBuffer.Empty();

VHD( m_msUnstructured.ReadAtOffset(dwOffset, sizeof(SBinaryType), (void**) &psType), "Invalid pEffectBuffer: cannot read type." );
Expand All @@ -1006,7 +1008,7 @@ HRESULT CEffectLoader::LoadTypeAndAddToPool(SType **ppType, uint32_t dwOffset)
temporaryType.PackedSize = psType->PackedSize;

// sanity check elements, size, stride, etc.
uint32_t cElements = std::max<uint32_t>(1, temporaryType.Elements);
cElements = std::max<uint32_t>(1, temporaryType.Elements);
VBD( cElements * temporaryType.Stride == AlignToPowerOf2(temporaryType.TotalSize, SType::c_RegisterSize), "Invalid pEffectBuffer: invalid type size." );
VBD( temporaryType.Stride % SType::c_RegisterSize == 0, "Invalid pEffectBuffer: invalid type stride." );
VBD( temporaryType.PackedSize <= temporaryType.TotalSize && temporaryType.PackedSize % cElements == 0, "Invalid pEffectBuffer: invalid type packed size." );
Expand Down Expand Up @@ -2554,7 +2556,9 @@ HRESULT CEffectLoader::GrabShaderData(SShaderBlock *pShaderBlock)

SRange *pRange = nullptr;
CEffectVector<SConstantBuffer*> vTBuffers;

uint32_t NumInterfaces = 0;
uint32_t CurInterfaceParameter = 0;

//////////////////////////////////////////////////////////////////////////
// Step 1: iterate through the resource binding structures and build
// an "optimized" list of all of the dependencies
Expand Down Expand Up @@ -2793,8 +2797,7 @@ HRESULT CEffectLoader::GrabShaderData(SShaderBlock *pShaderBlock)
// Step 2: iterate through the interfaces and build
// an "optimized" list of all of the dependencies

uint32_t NumInterfaces = pShaderBlock->pReflectionData->pReflection->GetNumInterfaceSlots();
uint32_t CurInterfaceParameter = 0;
NumInterfaces = pShaderBlock->pReflectionData->pReflection->GetNumInterfaceSlots();
if( NumInterfaces > 0 )
{
assert( ShaderDesc.ConstantBuffers > 0 );
Expand Down
46 changes: 30 additions & 16 deletions lib/win32/Effects11/EffectNonRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,20 @@ _Use_decl_annotations_
HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
{
HRESULT hr = S_OK;
uint32_t CurMemberData = 0;
SConstantBuffer* pCB = nullptr;
SConstantBuffer* pCBLast = nullptr;
SRasterizerBlock* pRB = nullptr;
SRasterizerBlock* pRBLast = nullptr;
SSamplerBlock* pSampler = nullptr;
SSamplerBlock* pSamplerLast = nullptr;
ID3D11ClassLinkage* neededClassLinkage = nullptr;
SShaderBlock* pShader = nullptr;
SShaderBlock* pShaderLast = nullptr;
SDepthStencilBlock* pDS = nullptr;
SDepthStencilBlock* pDSLast = nullptr;
SBlendBlock* pBlend = nullptr;
SBlendBlock* pBlendLast = nullptr;

// Set new device
if (pDevice == nullptr)
Expand All @@ -1123,8 +1137,8 @@ HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
SetDebugObjectName(m_pClassLinkage,srcName);

// Create all constant buffers
SConstantBuffer *pCB = m_pCBs;
SConstantBuffer *pCBLast = m_pCBs + m_CBCount;
pCB = m_pCBs;
pCBLast = m_pCBs + m_CBCount;
for(; pCB != pCBLast; pCB++)
{
SAFE_RELEASE(pCB->pD3DObject);
Expand Down Expand Up @@ -1179,8 +1193,8 @@ HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
}

// Create all RasterizerStates
SRasterizerBlock *pRB = m_pRasterizerBlocks;
SRasterizerBlock *pRBLast = m_pRasterizerBlocks + m_RasterizerBlockCount;
pRB = m_pRasterizerBlocks;
pRBLast = m_pRasterizerBlocks + m_RasterizerBlockCount;
for(; pRB != pRBLast; pRB++)
{
SAFE_RELEASE(pRB->pRasterizerObject);
Expand All @@ -1194,8 +1208,8 @@ HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
}

// Create all DepthStencils
SDepthStencilBlock *pDS = m_pDepthStencilBlocks;
SDepthStencilBlock *pDSLast = m_pDepthStencilBlocks + m_DepthStencilBlockCount;
pDS = m_pDepthStencilBlocks;
pDSLast = m_pDepthStencilBlocks + m_DepthStencilBlockCount;
for(; pDS != pDSLast; pDS++)
{
SAFE_RELEASE(pDS->pDSObject);
Expand All @@ -1209,8 +1223,8 @@ HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
}

// Create all BlendStates
SBlendBlock *pBlend = m_pBlendBlocks;
SBlendBlock *pBlendLast = m_pBlendBlocks + m_BlendBlockCount;
pBlend = m_pBlendBlocks;
pBlendLast = m_pBlendBlocks + m_BlendBlockCount;
for(; pBlend != pBlendLast; pBlend++)
{
SAFE_RELEASE(pBlend->pBlendObject);
Expand All @@ -1224,8 +1238,8 @@ HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
}

// Create all Samplers
SSamplerBlock *pSampler = m_pSamplerBlocks;
SSamplerBlock *pSamplerLast = m_pSamplerBlocks + m_SamplerBlockCount;
pSampler = m_pSamplerBlocks;
pSamplerLast = m_pSamplerBlocks + m_SamplerBlockCount;
for(; pSampler != pSamplerLast; pSampler++)
{
SAFE_RELEASE(pSampler->pD3DObject);
Expand All @@ -1235,9 +1249,9 @@ HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
}

// Create all shaders
ID3D11ClassLinkage* neededClassLinkage = featureLevelGE11 ? m_pClassLinkage : nullptr;
SShaderBlock *pShader = m_pShaderBlocks;
SShaderBlock *pShaderLast = m_pShaderBlocks + m_ShaderBlockCount;
neededClassLinkage = featureLevelGE11 ? m_pClassLinkage : nullptr;
pShader = m_pShaderBlocks;
pShaderLast = m_pShaderBlocks + m_ShaderBlockCount;
for(; pShader != pShaderLast; pShader++)
{
SAFE_RELEASE(pShader->pD3DObject);
Expand Down Expand Up @@ -1303,7 +1317,6 @@ HRESULT CEffect::BindToDevice(ID3D11Device *pDevice, LPCSTR srcName)
}

// Initialize the member data pointers for all variables
uint32_t CurMemberData = 0;
for (uint32_t i = 0; i < m_VariableCount; ++ i)
{
if( m_pVariables[i].pMemberData )
Expand Down Expand Up @@ -1887,6 +1900,7 @@ HRESULT CEffect::CopyOptimizedTypePool( CEffect* pEffectSource, CPointerMappingT
{
HRESULT hr = S_OK;
CEffectHeap* pOptimizedTypeHeap = nullptr;
uint8_t* pReadTypes = nullptr;

assert( pEffectSource->m_pOptimizedTypeHeap != 0 );
_Analysis_assume_( pEffectSource->m_pOptimizedTypeHeap != 0 );
Expand All @@ -1899,7 +1913,7 @@ HRESULT CEffect::CopyOptimizedTypePool( CEffect* pEffectSource, CPointerMappingT
CPointerMappingTable::CIterator mapIter;

// first pass: move types over, build mapping table
uint8_t* pReadTypes = pEffectSource->m_pOptimizedTypeHeap->GetDataStart();
pReadTypes = pEffectSource->m_pOptimizedTypeHeap->GetDataStart();
while( pEffectSource->m_pOptimizedTypeHeap->IsInHeap( pReadTypes ) )
{
SPointerMapping ptrMapping;
Expand Down Expand Up @@ -2186,14 +2200,14 @@ HRESULT CEffect::CloneEffect(_In_ uint32_t Flags, _Outptr_ ID3DX11Effect** ppClo
HRESULT CEffect::OptimizeTypes(_Inout_ CPointerMappingTable *pMappingTable, _In_ bool Cloning)
{
HRESULT hr = S_OK;
uint32_t Members = m_pMemberInterfaces.GetSize();

// find all child types, point them to the new location
for (size_t i = 0; i < m_VariableCount; ++ i)
{
VH( RemapType((SType**)&m_pVariables[i].pType, pMappingTable) );
}

uint32_t Members = m_pMemberInterfaces.GetSize();
for( size_t i=0; i < Members; i++ )
{
if( m_pMemberInterfaces[i] != nullptr )
Expand Down
Loading

0 comments on commit 07336f2

Please sign in to comment.