Skip to content

Commit 629993e

Browse files
author
Tim Jones
committed
Initial commit
0 parents  commit 629993e

File tree

2,715 files changed

+364890
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,715 files changed

+364890
-0
lines changed

.gitignore

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
11+
[Dd]ebug*/
12+
[Rr]elease/
13+
14+
build/
15+
16+
17+
[Tt]est[Rr]esult
18+
[Bb]uild[Ll]og.*
19+
20+
*_i.c
21+
*_p.c
22+
*.ilk
23+
*.meta
24+
*.obj
25+
*.pch
26+
*.pdb
27+
*.pgc
28+
*.pgd
29+
*.rsp
30+
*.sbr
31+
*.tlb
32+
*.tli
33+
*.tlh
34+
*.tmp
35+
*.vspscc
36+
*.vssscc
37+
.builds
38+
39+
*.pidb
40+
41+
*.log
42+
*.scc
43+
# Visual C++ cache files
44+
ipch/
45+
*.aps
46+
*.ncb
47+
*.opensdf
48+
*.sdf
49+
50+
# Visual Studio profiler
51+
*.psess
52+
*.vsp
53+
54+
# Guidance Automation Toolkit
55+
*.gpState
56+
57+
# ReSharper is a .NET coding add-in
58+
_ReSharper*/
59+
60+
*.[Rr]e[Ss]harper
61+
62+
# NCrunch
63+
*.ncrunch*
64+
.*crunch*.local.xml
65+
66+
# Installshield output folder
67+
[Ee]xpress
68+
69+
# DocProject is a documentation generator add-in
70+
DocProject/buildhelp/
71+
DocProject/Help/*.HxT
72+
DocProject/Help/*.HxC
73+
DocProject/Help/*.hhc
74+
DocProject/Help/*.hhk
75+
DocProject/Help/*.hhp
76+
DocProject/Help/Html2
77+
DocProject/Help/html
78+
79+
# Click-Once directory
80+
publish
81+
82+
# Publish Web Output
83+
*.Publish.xml
84+
85+
# Others
86+
[Bb]in
87+
[Oo]bj
88+
sql
89+
TestResults
90+
[Tt]est[Rr]esult*
91+
*.Cache
92+
ClientBin
93+
[Ss]tyle[Cc]op.*
94+
~$*
95+
*.dbmdl
96+
97+
*.[Pp]ublish.xml
98+
99+
Generated_Code #added for RIA/Silverlight projects
100+
101+
# Backup & report files from converting an old project file to a newer
102+
# Visual Studio version. Backup files are not needed, because we have git ;-)
103+
_UpgradeReport_Files/
104+
Backup*/
105+
UpgradeLog*.XML
106+
107+
# NuGet
108+
packages/

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
SlimShader
2+
==========
3+
4+
SlimShader is a Direct3D shader bytecode parser for .NET and C++. This is the repository for the C++ version; the .NET version can be found at
5+
[tgjones/slimshader](https://github.com/tgjones/slimshader).
6+
7+
Usage
8+
-----
9+
10+
```cpp
11+
auto fileBytes = ReadFileBytes("CompiledShader.o");
12+
auto bytecodeContainer = DxbcContainer::Parse(fileBytes);
13+
14+
cout << bytecodeContainer.GetInputSignature()->GetParameters().size() << endl;
15+
cout << bytecodeContainer.GetStatistics()->GetInstructionCount() << endl;
16+
cout << bytecodeContainer.GetStatistics()->GetStaticFlowControlCount() << endl;
17+
cout << bytecodeContainer.GetShader()->GetTokens().size() << endl;
18+
```
19+
20+
Acknowledgements
21+
----------------
22+
23+
* SlimShader uses several test shaders from the [HLSLCrossCompiler](https://github.com/James-Jones/HLSLCrossCompiler) project,
24+
by kind permission of [James Jones](https://github.com/James-Jones).
25+
* The [Nuclex Framework](https://devel.nuclex.org/framework), in particular the
26+
[HlslShaderReflector class](https://devel.nuclex.org/framework/browser/graphics/Nuclex.Graphics.Native/trunk/Source/Introspection/HlslShaderReflector.cpp),
27+
was very helpful when figuring out the RDEF, ISGN and OSGN chunks.
28+
* The [Wine](https://github.com/mirrors/wine) project, in particular Wine's [shader reflection code](http://source.winehq.org/source/dlls/d3dcompiler_43/reflection.c),
29+
had some good tips for decoding the STAT chunk.
30+
* [FXDIS](http://code.google.com/p/fxdis-d3d1x/) was useful to look at when getting started, but the techniques used
31+
in that project (casting raw bytes to struct types) don't translate well from C++ to C#.
32+
* For the SHDR chunk, I mostly just used D3D11TokenizedProgramFormat.hpp, a header file that comes with the Windows DDK.
33+
34+
License
35+
-------
36+
37+
SlimShader is released under the [MIT License](http://www.opensource.org/licenses/MIT).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
Copyright (c) Marshall Clow 2008-2012.
3+
4+
Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
Revision history:
8+
27 June 2009 mtc First version
9+
23 Oct 2010 mtc Added predicate version
10+
11+
*/
12+
13+
/// \file clamp.hpp
14+
/// \brief Clamp algorithm
15+
/// \author Marshall Clow
16+
///
17+
/// Suggested by olafvdspek in https://svn.boost.org/trac/boost/ticket/3215
18+
19+
#ifndef BOOST_ALGORITHM_CLAMP_HPP
20+
#define BOOST_ALGORITHM_CLAMP_HPP
21+
22+
#include <functional> // For std::less
23+
#include <iterator> // For std::iterator_traits
24+
#include <cassert>
25+
26+
#include <boost/range/begin.hpp>
27+
#include <boost/range/end.hpp>
28+
#include <boost/mpl/identity.hpp> // for identity
29+
#include <boost/utility/enable_if.hpp> // for boost::disable_if
30+
31+
namespace boost { namespace algorithm {
32+
33+
/// \fn clamp ( T const& val,
34+
/// typename boost::mpl::identity<T>::type const& lo,
35+
/// typename boost::mpl::identity<T>::type const& hi, Pred p )
36+
/// \return the value "val" brought into the range [ lo, hi ]
37+
/// using the comparison predicate p.
38+
/// If p ( val, lo ) return lo.
39+
/// If p ( hi, val ) return hi.
40+
/// Otherwise, return the original value.
41+
///
42+
/// \param val The value to be clamped
43+
/// \param lo The lower bound of the range to be clamped to
44+
/// \param hi The upper bound of the range to be clamped to
45+
/// \param p A predicate to use to compare the values.
46+
/// p ( a, b ) returns a boolean.
47+
///
48+
template<typename T, typename Pred>
49+
T const & clamp ( T const& val,
50+
typename boost::mpl::identity<T>::type const & lo,
51+
typename boost::mpl::identity<T>::type const & hi, Pred p )
52+
{
53+
// assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they might be equal
54+
return p ( val, lo ) ? lo : p ( hi, val ) ? hi : val;
55+
}
56+
57+
58+
/// \fn clamp ( T const& val,
59+
/// typename boost::mpl::identity<T>::type const& lo,
60+
/// typename boost::mpl::identity<T>::type const& hi )
61+
/// \return the value "val" brought into the range [ lo, hi ].
62+
/// If the value is less than lo, return lo.
63+
/// If the value is greater than "hi", return hi.
64+
/// Otherwise, return the original value.
65+
///
66+
/// \param val The value to be clamped
67+
/// \param lo The lower bound of the range to be clamped to
68+
/// \param hi The upper bound of the range to be clamped to
69+
///
70+
template<typename T>
71+
T const& clamp ( const T& val,
72+
typename boost::mpl::identity<T>::type const & lo,
73+
typename boost::mpl::identity<T>::type const & hi )
74+
{
75+
return (clamp) ( val, lo, hi, std::less<T>());
76+
}
77+
78+
/// \fn clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
79+
/// std::iterator_traits<InputIterator>::value_type lo,
80+
/// std::iterator_traits<InputIterator>::value_type hi )
81+
/// \return clamp the sequence of values [first, last) into [ lo, hi ]
82+
///
83+
/// \param first The start of the range of values
84+
/// \param last One past the end of the range of input values
85+
/// \param out An output iterator to write the clamped values into
86+
/// \param lo The lower bound of the range to be clamped to
87+
/// \param hi The upper bound of the range to be clamped to
88+
///
89+
template<typename InputIterator, typename OutputIterator>
90+
OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
91+
typename std::iterator_traits<InputIterator>::value_type lo,
92+
typename std::iterator_traits<InputIterator>::value_type hi )
93+
{
94+
// this could also be written with bind and std::transform
95+
while ( first != last )
96+
*out++ = clamp ( *first++, lo, hi );
97+
return out;
98+
}
99+
100+
/// \fn clamp_range ( const Range &r, OutputIterator out,
101+
/// typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type lo,
102+
/// typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type hi )
103+
/// \return clamp the sequence of values [first, last) into [ lo, hi ]
104+
///
105+
/// \param r The range of values to be clamped
106+
/// \param out An output iterator to write the clamped values into
107+
/// \param lo The lower bound of the range to be clamped to
108+
/// \param hi The upper bound of the range to be clamped to
109+
///
110+
template<typename Range, typename OutputIterator>
111+
typename boost::disable_if_c<boost::is_same<Range, OutputIterator>::value, OutputIterator>::type
112+
clamp_range ( const Range &r, OutputIterator out,
113+
typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type lo,
114+
typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type hi )
115+
{
116+
return clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi );
117+
}
118+
119+
120+
/// \fn clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
121+
/// std::iterator_traits<InputIterator>::value_type lo,
122+
/// std::iterator_traits<InputIterator>::value_type hi, Pred p )
123+
/// \return clamp the sequence of values [first, last) into [ lo, hi ]
124+
/// using the comparison predicate p.
125+
///
126+
/// \param first The start of the range of values
127+
/// \param last One past the end of the range of input values
128+
/// \param out An output iterator to write the clamped values into
129+
/// \param lo The lower bound of the range to be clamped to
130+
/// \param hi The upper bound of the range to be clamped to
131+
/// \param p A predicate to use to compare the values.
132+
/// p ( a, b ) returns a boolean.
133+
134+
///
135+
template<typename InputIterator, typename OutputIterator, typename Pred>
136+
OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
137+
typename std::iterator_traits<InputIterator>::value_type lo,
138+
typename std::iterator_traits<InputIterator>::value_type hi, Pred p )
139+
{
140+
// this could also be written with bind and std::transform
141+
while ( first != last )
142+
*out++ = clamp ( *first++, lo, hi, p );
143+
return out;
144+
}
145+
146+
/// \fn clamp_range ( const Range &r, OutputIterator out,
147+
/// typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type lo,
148+
/// typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type hi,
149+
/// Pred p )
150+
/// \return clamp the sequence of values [first, last) into [ lo, hi ]
151+
/// using the comparison predicate p.
152+
///
153+
/// \param r The range of values to be clamped
154+
/// \param out An output iterator to write the clamped values into
155+
/// \param lo The lower bound of the range to be clamped to
156+
/// \param hi The upper bound of the range to be clamped to
157+
/// \param p A predicate to use to compare the values.
158+
/// p ( a, b ) returns a boolean.
159+
//
160+
// Disable this template if the first two parameters are the same type;
161+
// In that case, the user will get the two iterator version.
162+
template<typename Range, typename OutputIterator, typename Pred>
163+
typename boost::disable_if_c<boost::is_same<Range, OutputIterator>::value, OutputIterator>::type
164+
clamp_range ( const Range &r, OutputIterator out,
165+
typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type lo,
166+
typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type hi,
167+
Pred p )
168+
{
169+
return clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi, p );
170+
}
171+
172+
173+
}}
174+
175+
#endif // BOOST_ALGORITHM_CLAMP_HPP

0 commit comments

Comments
 (0)