28 D3D11_SO_DECLARATION_ENTRY m_newEntry;
29 LPSTR m_SemanticString[D3D11_SO_BUFFER_SLOT_COUNT];
31 static const size_t MAX_ERROR_SIZE = 254;
32 char m_pError[ MAX_ERROR_SIZE + 1 ];
44 for(
size_t Stream = 0; Stream < D3D11_SO_STREAM_COUNT; ++Stream )
46 SAFE_DELETE_ARRAY( m_SemanticString[Stream] );
51 HRESULT Parse( _In_z_ LPCSTR pString )
54 return Parse( 0, pString );
58 HRESULT Parse( _In_z_ LPSTR pStreams[D3D11_SO_STREAM_COUNT] )
62 for( uint32_t iDecl=0; iDecl < D3D11_SO_STREAM_COUNT; ++iDecl )
64 hr = Parse( iDecl, pStreams[iDecl] );
68 sprintf_s( str, 16,
" in stream %u.", iDecl );
70 strcat_s( m_pError, MAX_ERROR_SIZE, str );
78 D3D11_SO_DECLARATION_ENTRY *GetDeclArray()
83 char* GetErrorString()
88 uint32_t GetDeclCount()
const 90 return m_vDecls.GetSize();
94 void GetStrides( uint32_t strides[4] )
96 size_t len = GetDeclCount();
97 strides[0] = strides[1] = strides[2] = strides[3] = 0;
99 for(
size_t i=0; i < len; i++ )
101 strides[m_vDecls[i].OutputSlot] += m_vDecls[i].ComponentCount *
sizeof(float);
108 HRESULT Parse( _In_ uint32_t Stream, _In_z_ LPCSTR pString )
114 if( pString ==
nullptr )
117 uint32_t len = (uint32_t)strlen( pString );
121 SAFE_DELETE_ARRAY( m_SemanticString[Stream] );
122 VN( m_SemanticString[Stream] =
new char[len + 1] );
123 strcpy_s( m_SemanticString[Stream], len + 1, pString );
125 LPSTR pSemantic = m_SemanticString[Stream];
130 LPSTR pSemi = strchr( pSemantic,
';' );
134 if( pSemi !=
nullptr )
141 pEnd = pSemantic + strlen( pSemantic );
143 while( isspace( (
unsigned char)*pSemantic ) )
145 while( pEnd > pSemantic && isspace( (
unsigned char)*pEnd ) )
151 if( *pSemantic !=
'\0' )
153 VH( AddSemantic( pSemantic ) );
154 m_newEntry.Stream = Stream;
156 VH( m_vDecls.Add( m_newEntry ) );
158 if( pSemi ==
nullptr )
160 pSemantic = pSemi + 1;
168 HRESULT AddSemantic( _Inout_z_ LPSTR pSemantic )
174 ZeroMemory( &m_newEntry,
sizeof(m_newEntry) );
175 VH( ConsumeOutputSlot( &pSemantic ) );
176 VH( ConsumeRegisterMask( pSemantic ) );
177 VH( ConsumeSemanticIndex( pSemantic ) );
180 if( strcmp(
"$SKIP", pSemantic ) != 0 )
182 m_newEntry.SemanticName = pSemantic;
190 HRESULT ConsumeRegisterMask( _Inout_z_ LPSTR pSemantic )
193 const char *pFullMask1 =
"xyzw";
194 const char *pFullMask2 =
"rgba";
196 size_t startComponent = 0;
201 pSemantic = strchr( pSemantic,
'.' );
203 if( pSemantic ==
nullptr )
205 m_newEntry.ComponentCount = 4;
212 stringLength = strlen( pSemantic );
213 p = strstr(pFullMask1, pSemantic );
216 startComponent = (uint32_t)( p - pFullMask1 );
220 p = strstr( pFullMask2, pSemantic );
222 startComponent = (uint32_t)( p - pFullMask2 );
225 sprintf_s( m_pError, MAX_ERROR_SIZE,
"ID3D11Effect::ParseSODecl - invalid mask declaration '%s'", pSemantic );
231 if( stringLength == 0 )
234 m_newEntry.StartComponent = (uint8_t)startComponent;
235 m_newEntry.ComponentCount = (uint8_t)stringLength;
242 HRESULT ConsumeOutputSlot( _Inout_z_ LPSTR* ppSemantic )
244 assert( ppSemantic && *ppSemantic );
245 _Analysis_assume_( ppSemantic && *ppSemantic );
248 LPSTR pColon = strchr( *ppSemantic,
':' );
250 if( pColon ==
nullptr )
253 if( pColon == *ppSemantic )
255 strcpy_s( m_pError, MAX_ERROR_SIZE,
256 "ID3D11Effect::ParseSODecl - Invalid output slot" );
261 int outputSlot = atoi( *ppSemantic );
262 if( outputSlot < 0 || outputSlot > 255 )
264 strcpy_s( m_pError, MAX_ERROR_SIZE,
265 "ID3D11Effect::ParseSODecl - Invalid output slot" );
268 m_newEntry.OutputSlot = (uint8_t)outputSlot;
270 while( *ppSemantic < pColon )
272 if( !isdigit( (
unsigned char)**ppSemantic ) )
274 sprintf_s( m_pError, MAX_ERROR_SIZE,
"ID3D11Effect::ParseSODecl - Non-digit '%c' in output slot", **ppSemantic );
283 while( isspace( (
unsigned char)**ppSemantic ) )
291 HRESULT ConsumeSemanticIndex( _Inout_z_ LPSTR pSemantic )
295 uint32_t uLen = (uint32_t)strlen( pSemantic );
298 while( uLen > 0 && isdigit( (
unsigned char)pSemantic[uLen - 1] ) )
301 if( isdigit( (
unsigned char)pSemantic[uLen] ) )
303 m_newEntry.SemanticIndex = atoi( pSemantic + uLen );
304 pSemantic[uLen] =
'\0';
308 m_newEntry.SemanticIndex = 0;
Definition: EffectBinaryFormat.h:16
Definition: SOParser.h:24