<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scientific Ninja &#187; slimdx</title>
	<atom:link href="http://scientificninja.com/tag/slimdx/feed" rel="self" type="application/rss+xml" />
	<link>http://scientificninja.com</link>
	<description></description>
	<lastBuildDate>Tue, 27 Jul 2010 02:58:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>SlimDX June 2010 Released</title>
		<link>http://scientificninja.com/blog/slimdx-june-2010-released</link>
		<comments>http://scientificninja.com/blog/slimdx-june-2010-released#comments</comments>
		<pubDate>Mon, 05 Jul 2010 16:05:47 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://scientificninja.com/?p=959</guid>
		<description><![CDATA[Actually it was released last week, when it still was actually June, so I&#8217;m a little late to this party. Mike did the official release thread on GDNet this time around in which he calls out the major changes, including .NET 4.0 support, cleaner access to the shader compiler interfaces, and a much more robust [...]]]></description>
			<content:encoded><![CDATA[<p>Actually it was released last week, when it still was actually June, so I&#8217;m a little late to this party. Mike did <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=575638">the official release thread</a> on GDNet this time around in which he calls out the major changes, including .NET 4.0 support, cleaner access to the shader compiler interfaces, and a much more robust DirectWrite implementation.</p>

<p>Also, in an effort to try and get a better sense of our users and community, we&#8217;ve put together this quick <a href="http://www.surveymonkey.com/s/6LW9QXG">SlimDX developer survey</a> and would appreciate your time in filling it out if you use, have used, or are considering using SlimDX for anything.</p>

<p>Finally, we&#8217;ve received several queries through various channels about contributing to SlimDX, especially the upcoming version 2.0 redesign. If you are at all interested in participating in or simply observing the discussions about the redesign, you should join the <a href="http://groups.google.com/group/slimdx-devel">slimdx-devel</a> mailing list.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/slimdx-june-2010-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thoughts on SlimDX 2: Object Lifetime</title>
		<link>http://scientificninja.com/blog/thoughts-on-slimdx-2-object-lifetime</link>
		<comments>http://scientificninja.com/blog/thoughts-on-slimdx-2-object-lifetime#comments</comments>
		<pubDate>Wed, 31 Mar 2010 02:14:32 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[com]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://scientificninja.com/?p=866</guid>
		<description><![CDATA[This will likely be my last post on the subject of the major changes coming in SlimDX 2 for a little while. My last few posts have focused on issues we&#8217;re fairly certain will be relevant to the new API (as will this post) &#8212; but we don&#8217;t have everything planned out yet. We have [...]]]></description>
			<content:encoded><![CDATA[<p>This will likely be my last post on the subject of the major changes coming in SlimDX 2 for a little while. My last <a href="http://scientificninja.com/blog/thoughts-on-slimdx-2-interfaces">few</a> <a href="http://scientificninja.com/blog/thoughts-on-slimdx-2-assembly-design">posts</a> have focused on issues we&#8217;re fairly certain will be relevant to the new API (as will this post) &#8212; but we don&#8217;t have <em>everything</em> planned out yet. We have a few ideas we&#8217;d like to experiment with, but we&#8217;re going to have to take some time to prototype them and mess around before we can commit to any one solution. Indeed, there are even a few unanswered questions about the topic I&#8217;m going to talk about today.</p>

<p>That topic is how we&#8217;re not going to use IDisposable any longer.</p>

<p>More specifically, we&#8217;re not going to use it <em>as much</em>. Almost every SlimDX 1 object implements IDisposable, because IDisposable is all about cleaning up unmanaged resources and SlimDX objects are, for the most part, exactly that. But the sort of resources IDisposable is geared towards are those with very explicit lifetimes: you create it, do your thing, and then Dispose() of it. C# using-blocks allow you to implement this exact pattern for locally-held objects quite efficiently.</p>

<p>Long-time readers will recall that our IDisposable wrappers around COM objects have caused us a lot of trouble in the past, largely because the interface&#8217;s contract does not really jive with COM&#8217;s reference counting. To account for this, we implemented an object table based loosely on the same principles that the <a href="http://msdn.microsoft.com/en-us/library/8bwh56xe.aspx">.NET RCW</a> uses &#8212; specifically, we tried to maintain exactly one COM reference to any object known to SlimDX so that we could do the correct thing when Dispose() was called. This eventually led us to an overly-complicated system burdened with multiple creation code paths and inconsistent ownership semantics.</p>

<p>Our solution is to, essentially, side-step the issue entirely and just expose the reference counting directly. All SlimDX 2 objects that are backed by actual COM interfaces implement IComObject, which provides the familiar-looking methods AddReference() and Release(). For the trivial scenarios where you just want quick, scoped access to a COM object, we&#8217;ll be providing a simple IDisposable utility wrapper you can use in conjunction with a using-block to automatically drop the reference count when appropriate.</p>

<p>While it first might seem like this change is a step <em>backwards</em>, we think that it&#8217;s an improvement in the long run: it obviates the need for the exceedingly complex object ownership rules that existed with SlimDX 1 (which, we suspect, most of our users were getting wrong). Plus, it makes the SlimDX ownership semantics match those of the already-familiar native API.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/thoughts-on-slimdx-2-object-lifetime/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hargreaves on Breaking Changes</title>
		<link>http://scientificninja.com/blog/hargreaves-on-breaking-changes</link>
		<comments>http://scientificninja.com/blog/hargreaves-on-breaking-changes#comments</comments>
		<pubDate>Wed, 17 Mar 2010 05:19:02 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[slimdx]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://scientificninja.com/?p=852</guid>
		<description><![CDATA[Shawn Hargreaves has been writing about the upcoming changes in XNA 4.0 (interesting stuff). The topic is obviously one that resonates with me given my own recent posts. I particularly enjoyed this post. Back in 2007, when SlimDX was a young API, we had the luxury of having very few serious users. When we realized [...]]]></description>
			<content:encoded><![CDATA[<p>Shawn Hargreaves has been writing about <a href="http://blogs.msdn.com/shawnhar/archive/2010/03/16/breaking-changes-in-xna-game-studio-4-0.aspx">the upcoming changes in XNA 4.0</a> (interesting stuff). The topic is obviously one that resonates with me given <a href="http://scientificninja.com/blog/thoughts-on-slimdx-2">my own</a> <a href="http://scientificninja.com/blog/thoughts-on-slimdx-2-interfaces">recent</a> <a href="http://scientificninja.com/blog/thoughts-on-slimdx-2-assembly-design">posts</a>.</p>

<p><a href="http://blogs.msdn.com/shawnhar/archive/2010/03/05/backward-compatibility.aspx">I particularly enjoyed this post</a>. Back in 2007, when SlimDX was a young API, we had the luxury of having very few serious users. When we realized we&#8217;d screwed something up, we just changed it, and it didn&#8217;t matter how much that change would impact a client code. There were no clients.</p>

<p>But now, three years later, that&#8217;s no longer the case. We have quite a few users; SlimDX has been used in commercially released <a href="http://www.arcengames.com/aiwar_features.php">games</a> and <a href="http://www.ventuz.com/">applications</a>, and helps power internal content production tools used by professional studios like <a href="http://zipperint.com/">Zipper Interactive</a>. We no longer have the luxury of implementing sweeping changes on a whim, no matter how correct they may be. We have practical realities to consider: providing sufficient advance warning and documentation. Developing upgrade paths. Transitioning deprecated versions of the API to &#8220;support mode&#8221; for an appropriate period of time.</p>

<p>I believe that breaking changes are for the best when they actually improve the overall health of the API. But they&#8217;re also pretty scary.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/hargreaves-on-breaking-changes/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thoughts on SlimDX 2: Assembly Design</title>
		<link>http://scientificninja.com/blog/thoughts-on-slimdx-2-assembly-design</link>
		<comments>http://scientificninja.com/blog/thoughts-on-slimdx-2-assembly-design#comments</comments>
		<pubDate>Sun, 14 Mar 2010 18:12:53 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[c++/cli]]></category>
		<category><![CDATA[clr]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://scientificninja.com/?p=834</guid>
		<description><![CDATA[SlimDX 1 is contained in a single, monolithic C++/CLI assembly. SlimDX 2 is structured differently: it is split up into both public and private DLLs. The public DLL, which will be directly referenced by client code, is written in C# and contains the definitions for all the interfaces, enumerations, et cetera. The private DLL, written [...]]]></description>
			<content:encoded><![CDATA[<p>SlimDX 1 is contained in a single, monolithic C++/CLI assembly. SlimDX 2 is structured differently: it is split up into both public and private DLLs. The public DLL, which will be directly referenced by client code, is written in C# and contains the definitions for all the interfaces, enumerations, et cetera. The private DLL, written in C++/CLI, contains the interface implementations and all our internal machinery.</p>

<p>The primary motivation for organizing the library in this fashion was to eliminate the problems with building “Any CPU” applications using SlimDX.</p>

<p>Managed applications built in “Any CPU” mode are essentially asking the CLR to load them as processes most-appropriate to the host machine: if you’re running on the x64 architecture, you get a 64-bit process. On x86, you&#8217;d get a 32-bit process.</p>

<p>For native code, however, the target architecture needs to be decided at compile-time, which is why there are distinct 32-bit and 64-bit versions of the SlimDX assembly. Unfortunately, <a href="http://blogs.msdn.com/oldnewthing/archive/2008/10/20/9006720.aspx">you cannot load a 32-bit DLL into a 64-bit process</a>.</p>

<p>If you’re using the copies of SlimDX that our installer places in the GAC, you can avoid running afoul of this problem by editing your <code>.csproj</code>. If you’re a user who prefers to reference the SlimDX DLLs themselves, you are out of luck. You have to pick a specific version to reference, and you have to set the machine type of your project to match.</p>

<p>By using a two-part distribution, we can ship a public assembly configured for “Any CPU” use. This assembly can detect whether 32- or 64-bit code would be more appropriate and load the correct private implementation DLL into your process.</p>

<p>This approach also allows us to write more of SlimDX in C#, which is far more pleasant language to work with than C++/CLI, and has a much better toolchain.</p>

<p>It also lets us improve the health of the code we do need to write in C++/CLI. Because of a peculiarity in how templates (not generics) interact with managed types, the presence of a template type anywhere in a class hierarchy results in a complete lack of IntelliSense support for that class hierarchy&#8230; but there’s a lot of redundant boilerplate code in SlimDX, exactly the kind of code one would like to use templates to write just once. We had to compromise and use macros to provide that code for SlimDX 1.</p>

<p>However, with the split-assembly approach &#8212; along with with our adoption of interfaces &#8212; the classes “polluted” by templates exist entirely in the private assembly and are never exposed by their concrete types; the lack of IntelliSense becomes a non-issue.</p>

<p>There is one small downside, unfortunately. Since the implementation DLL is loaded manually, clients who reference and ship private copies of SlimDX (that is, anyone not using the GAC version) will need to add or link the SlimDX implementation DLLs (and PDBs) in their <code>.csproj</code> files in order to allow the build system to copy those files into the directory of the built application.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/thoughts-on-slimdx-2-assembly-design/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Thoughts on SlimDX 2: Interfaces</title>
		<link>http://scientificninja.com/blog/thoughts-on-slimdx-2-interfaces</link>
		<comments>http://scientificninja.com/blog/thoughts-on-slimdx-2-interfaces#comments</comments>
		<pubDate>Sun, 07 Mar 2010 05:32:43 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://scientificninja.com/?p=824</guid>
		<description><![CDATA[One of the biggest changes we&#8217;re going to make in SlimDX 2 concerns our use of interface types (specifically, our lack thereof). In the current version of SlimDX, the API consists almost entirely of concrete classes. However, there are advantages to exposing interfaces instead &#8212; improved testability of the public API and code depending on [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest changes we&#8217;re going to make in SlimDX 2 concerns our use of interface types (specifically, our lack thereof). In the current version of SlimDX, the API consists almost entirely of concrete classes. However, there are advantages to exposing interfaces instead &#8212; improved testability of the public API and code depending on it, for example, as well as the potential for some back-end improvements to code health. There are two major main concerns involved in redesigning SlimDX to use interfaces:</p>

<p>The first is the question of how one initially obtains an interface. SlimDX 1 uses the constructors of its concrete objects to enable users to obtain new instances. Thus, in SlimDX 1 you would obtain a texture instance by doing new Texture2D( device, &#8230; ). This constructor will invoke the native ID3D10Device::CreateTexture(). In SlimDX 2, we&#8217;ll present a model that mirrors the native interface more closely, with an IDevice interface that demands a CreateTexture method.</p>

<p>To handle bootstrapping &#8212; obtaining that first interface &#8212; we&#8217;ll expose so-called &#8220;API objects&#8221; that will represent each of the primary subsystems SlimDX exposes to native code (for example, there will be a Direct3D10Api object that will let you obtain the initial D3D10 device interface. These API objects will also be a convenient location to present many of the native free functions. SlimDX doesn&#8217;t expose all of these now, and the ones it does provide are often tucked away, seldom-seen static members of one class or another.</p>

<p>The other half of the problem is translating those interfaces back into concrete, usable objects when they are passed back to SlimDX for one reason or another.</p>

<p>We <em>could</em> simply downcast the interface to the concrete type, but that relies on the assumption that such a cast would always succeed &#8212; and that isn&#8217;t true in general. SlimDX has always supported interoperation with other DirectX-wrapping managed libraries, and to make the assumption that our interfaces were only ever implemented by our own library would work against that.</p>

<p>Fortunately, as a result of that interoperability feature, we&#8217;ve had to have all of our objects expose their IUnknown or similar native pointer (wrapped up in a System.IntPtr). Thus, we can rely on an accessor for that pointer being available from the interfaces, and we can use that to obtain the actual interface we&#8217;re interested in working with in the SlimDX code.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/thoughts-on-slimdx-2-interfaces/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thoughts on SlimDX 2</title>
		<link>http://scientificninja.com/blog/thoughts-on-slimdx-2</link>
		<comments>http://scientificninja.com/blog/thoughts-on-slimdx-2#comments</comments>
		<pubDate>Thu, 04 Mar 2010 02:30:43 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://scientificninja.com/?p=735</guid>
		<description><![CDATA[SlimDX is has become a pretty comprehensive API, but the fact still remains that it is a version-one iteration of the product, and like all version-one iterations, it has issues. In particular, some of the more insidious bugs and poorly-considered design decisions are starting to become increasingly more uncomfortable to deal with. Since no good [...]]]></description>
			<content:encoded><![CDATA[<p>SlimDX is has become a pretty comprehensive API, but the fact still remains that it is a version-one iteration of the product, and like all version-one iterations, it has issues. In particular, some of the more insidious bugs and poorly-considered design decisions are starting to become increasingly more uncomfortable to deal with. Since no good solutions exist for some of these problems that will preserve the existing public interface, we&#8217;ve been thinking about what a version-two iteration of SlimDX will look like. There are quite a few aspects of the API we&#8217;d like to improve for the next version, and over the next few days I&#8217;m going to talk about some of them.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/thoughts-on-slimdx-2/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SlimDX February 2010 Released</title>
		<link>http://scientificninja.com/blog/slimdx-february-2010-released</link>
		<comments>http://scientificninja.com/blog/slimdx-february-2010-released#comments</comments>
		<pubDate>Sat, 20 Feb 2010 01:39:33 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://scientificninja.com/?p=782</guid>
		<description><![CDATA[Microsoft released the February 2010 DirectX SDK last week, and so we on the SlimDX team now present you with the February 2010 SlimDX SDK. There aren&#8217;t many major changes in the DirectX SDK this time around&#8211; PIX has gained some improvements, including better support for dealing with D3D11, and XNAMath got a few bug [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft released the <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=2c7da5fb-ffbb-4af6-8c66-651cbd28ca15">February 2010 DirectX SDK</a> last week, and so we on the SlimDX team now present you with the <a href="http://slimdx.org/download_feb10.php">February 2010 SlimDX SDK</a>.</p>

<p>There aren&#8217;t many major changes in the DirectX SDK this time around&#8211; PIX has gained some improvements, including better support for dealing with D3D11, and XNAMath got a few bug fixes, but most other changes are relatively minor. However, the SlimDX SDK includes some interesting changes (a full summary can be found in our <a href="http://slimdx.org/latestdocs/Default.aspx?topic=SlimDX+Software+Development+Kit%2fWhat%27s+Changed+in+the+February+2010+SDK">release notes</a>).</p>

<h5>Ownership and Disposal</h5>

<p>We made some modifications to certain interfaces to help clarify the ownership/disposal semantics of those interfaces under typical usage scenarios. In particular, we changed the ownership rules for <code>GetBackBuffer</code> so that users must call <code>Dispose</code> on the returned object themselves, and we changed how surfaces are constructed from swap chains (using the static <code>FromSwapChain</code> method on the <code>Surface</code> interface). These changes were made to alleviate some issues caused by unclear ownership semantics, leading users to not know when it was appropriate to <code>Dispose</code> of an interface, and in some cases making it impossible to correctly clean up a resource.</p>

<h5>New Subsystems</h5>

<p>August&#8217;s SDK release included DirectWrite wrappers, but they were severely lacking. We&#8217;ve implemented significantly more of the DirectWrite interface for this month&#8217;s release, although by our estimate we&#8217;re still missing about half of the subsystem.</p>

<p>We&#8217;ve also added wrappers for the XAPO API.</p>

<h5>Decreased Subsystem Interdependence</h5>

<p>D3D11 shares a few interfaces (and constants) with D3D10, so in the previous SlimDX release one would need to reference both namespaces to effectively utilize D3D11 functionality in some cases (involving, for example, the <code>ShaderBytecode</code> class). For February, we&#8217;ve split those shared interfaces into 10 and 11 versions, so this should no longer be necessary.</p>

<h5>Revamped Sample Framework</h5>

<p>Finally, as I have discussed previously, we had plans to rewrite the sample framework and the associated sample set. There were many problems with the previous sample framework, mostly centering on its similarity to XNA (which caused many users to interpret it as a reusable &#8220;game&#8221; framework and try to use it for real applications). It isn&#8217;t our intention to be providing that kind of a framework in SlimDX, so the new sample framework is significantly more bare-bones. We have removed most of the old samples from the distribution, replacing them with more narrowly-focused samples illustrating some specific basic concepts that we receive a lot of questions about &#8212; specifically, dealing with losing the device and resizing the window in D3D9 (illustrated by the framework itself) and in setting up depth and alpha blend states in D3D10 (illustrated by the SimpleMesh10 sample).</p>

<p>Unfortunately we didn&#8217;t have the time to complete everything we would have liked to have done with the new sample framework for this release, but we&#8217;ll be continuing to add samples of increased complexity in future releases.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/slimdx-february-2010-released/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing SlimBuffer</title>
		<link>http://scientificninja.com/blog/introducing-slimbuffer</link>
		<comments>http://scientificninja.com/blog/introducing-slimbuffer#comments</comments>
		<pubDate>Mon, 11 Jan 2010 07:39:05 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[c++/cli]]></category>
		<category><![CDATA[slimbuffer]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://jpetrie.webfactional.com/?p=51</guid>
		<description><![CDATA[Before I returned to Pennsylvania for the holidays, I rather quietly made the initial commit to the SlimBuffer Subversion repository. SlimBuffer is a very straightforward API for creating and manipulating native-memory buffers from managed code. While there exist ways to do this directly &#8212; via unsafe blocks (in some languages) or various methods of the [...]]]></description>
			<content:encoded><![CDATA[<p>Before I returned to Pennsylvania for the holidays, I rather quietly made the initial commit to the <a href="http://code.google.com/p/slimbuffer">SlimBuffer Subversion repository</a>.</p>

<p>SlimBuffer is a very straightforward API for creating and manipulating native-memory buffers from managed code. While there exist ways to do this directly &#8212; via unsafe blocks (in some languages) or various methods of the System.Marshal class &#8212; those methods are usually inelegant, inefficient, or both. SlimBuffer is written in C++/CLI for maximum efficiency and does what it does in a very clean, expressive manner.</p>

<p>If you&#8217;ve used <a href="http://slimdx.org">SlimDX</a>&#8216;s DataStream class, you already have a basic idea of what SlimBuffer&#8217;s MemoryBuffer class is like. Indeed, DataStream is the conceptual basis for much of MemoryBuffer, and the <em>problems</em> with DataStream provided the impetus to spin off the SlimBuffer project.</p>

<p>The big difference is that MemoryBuffer is not a subclass of System.IO.Stream. Our original decision to make DataStream a stream was a poor one. It forced certain conventions on us that, as development and usage of our API progressed, became restrictive. For example, the lack of distinct read and write positions causes users to have to remember to &#8220;rewind&#8221; many streams before handing them back to SlimDX. MemoryBuffer is beholden to no such interface restrictions &#8212; save for those of IDisposable, but that&#8217;s a given since unmanaged resources are involved.</p>

<p>MemoryBuffer also allows for allocator customization, similar to that offered by the standard C++ containers. As of now, there is a <a href="http://code.google.com/p/slimbuffer/source/browse/trunk/Products/SlimBuffer/Source/CrtAllocator.h">default allocator</a> that uses new and delete, as well as a simple <a href="http://code.google.com/p/slimbuffer/source/browse/trunk/Products/SlimBuffer/Source/DelegateAllocator.h">delegating allocator</a>.</p>

<p>SlimDX 2.0 will be replacing DataStream with MemoryBuffer, but the class (and some of the interesting tidbits I have planned for it) can be extremely useful on its own, so we&#8217;ve created a dedicated project for it. This way users who aren&#8217;t using other aspects of SlimDX can still take advantage of what SlimBuffer provides.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/introducing-slimbuffer/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rethinking the SlimDX Sample Framework</title>
		<link>http://scientificninja.com/blog/rethinking-the-slimdx-sample-framework</link>
		<comments>http://scientificninja.com/blog/rethinking-the-slimdx-sample-framework#comments</comments>
		<pubDate>Tue, 16 Jun 2009 11:55:39 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://jpetrie.webfactional.com/?p=21</guid>
		<description><![CDATA[The SlimDX sample situation is currently pretty disorganized: some of our samples are checked in to the Subversion repository, but others are just referenced from issues in our issue tracker. Not all the samples use our internal sample framework, either, and the framework itself has a few issues. But as SlimDX becomes more and more [...]]]></description>
			<content:encoded><![CDATA[<p>The SlimDX sample situation is currently pretty disorganized: some of our samples are checked in to the Subversion repository, but others are just referenced from issues in our <a href="http://code.google.com/p/slimdx/issues/list">issue tracker</a>. Not all the samples use our internal sample framework, either, and the framework itself has a few issues. But as SlimDX becomes more and more stable, and begins to really approach complete parity with the native APIs, we have an opportunity to revisit problems like this one and clean things up.</p>

<p>In the future, our intention is to create a firm split between official and community samples. Only the former will be checked into source control. The community samples will be hosted on <a href="http://slimdx.org/">our website</a> somewhere, and when warranted we will fold appropriate community samples into the official distribution, after appropriate modification. One of the things we want to ensure is that the official samples have a uniform style (to make them easy to follow and compare) and that they meet certain quality criteria.</p>

<p>The other thing we&#8217;re going to do is refactor the sample framework itself. The current framework feels like a &#8220;mini-XNA,&#8221; which has caused some users to adopt it as a more generalized &#8220;game&#8221; framework, which is problematic for us. We do not want to be in the business of writing &#8212; more importantly, of maintaining &#8212; anything resembling an <em>engine</em>. There are other projects out there that fit that bill; SlimDX is a lightweight wrapper, and we want to preserve its minimalist ideals even across aspects of the project that are not the core library itself.</p>

<p>The <em>sample</em> framework should be about making it easy for us to build <em>samples</em>. The native SDK uses a pretty robust sample framework, and we&#8217;ve seen that hamper it as an educational tool. When the sample is trying to demonstrate some concept or technique, it should demonstrate that in the language of the API itself. API calls should be used as often as is reasonable in order to demonstrate &#8216;<a href="http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html">the simplest thing that could work</a>,&#8217; which is usually what a user is looking at the sample code <em>for</em>.</p>

<p>Basically, we want a relative lack of abstraction. Users are just going to peel away the abstraction layers anyway, so we&#8217;d just be creating more work for them.</p>

<p>It&#8217;s still going to be a framework, though! We&#8217;re still going to wrap the creation of the primary window and the &#8216;game loop,&#8217; and we&#8217;ll provide extensibility points allowing a sample to customize the main phases of application execution: pre-initialization configuration, initialization and resource load, logic update, render update, and shutdown/cleanup. Simplifying such boilerplate code, code that is not directly related to the primary tasks one would use SlimDX for, is perfectly acceptable.</p>

<p>Similarly, we&#8217;ll probably wrap mesh loading (especially since there is no built-in method for creating <a href="http://msdn.microsoft.com/en-us/library/bb173897(VS.85).aspx">ID3DX10Mesh</a> objects from a file, and we&#8217;d like to use the same source assets when possible for homogeneity) and similar ancillary operations.</p>

<p>UI is another interesting issue. The native sample framework supports a simple collection of UI controls for tweaking parameters for a sample. I&#8217;d rather not implement (and thus maintain) a similar system in SlimDX, but the alternative of using Windows Forms controls means that tweaking won&#8217;t be available in samples running in fullscreen mode, which is a deal-breaker. So we&#8217;ll support a small set of basic controls useful for tweaking parameter values in the new framework as well.</p>

<p>These framework changes probably won&#8217;t make it into the next release (if indeed the next release is this month, as we suspect), but you should see them in the release immediately following that at the latest&#8230; as well as some other interesting changes. And of course, you can always live on the bleeding edge and work from <a href="http://code.google.com/p/slimdx/source/list">the head of our repository</a>.</p>

<p>In other SlimDX news, <a href="http://www.arcengames.com/">Arcen Games, LLC</a> recently released AI War: Fleet Command. I&#8217;ve posted about this on Twitter already, and SlimDX lead <a href="http://ventspace.wordpress.com/2009/06/15/highlight-ai-war/">Promit Roy has beaten me to the punch on a blog post</a>, but I&#8217;ll repeat it here for the benefit of other readers: AI War is the first game available for purchase that was built using SlimDX! This is <em>very</em> cool. Developer <a href="http://christophermpark.blogspot.com/2009/06/choosing-directx-platform-in-c.html">Chris Park has written about</a> his experience evaluating rendering solutions for C# projects, explaining how he ultimately chose SlimDX&#8230; head over and give his blog a read, and when you&#8217;re done, be sure to check out the game itself!</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/rethinking-the-slimdx-sample-framework/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>COM and SlimDX, Part 2</title>
		<link>http://scientificninja.com/blog/com-and-slimdx-part-2</link>
		<comments>http://scientificninja.com/blog/com-and-slimdx-part-2#comments</comments>
		<pubDate>Mon, 17 Mar 2008 09:05:24 +0000</pubDate>
		<dc:creator>Josh Petrie</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[c++/cli]]></category>
		<category><![CDATA[slimdx]]></category>

		<guid isPermaLink="false">http://jpetrie.webfactional.com/?p=19</guid>
		<description><![CDATA[Earlier, in &#8220;COM and SlimDX, Part 1,&#8221; I discussed an early design decision that was made in SlimDX that prevented us from supporting the idiomatic C# pattern for disposal of unmanaged resources. In closing, I mentioned that our new solution, while a huge leap forward, still had some problems. Today we&#8217;ll discuss them. SlimDX supports [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier, in <a href="http://scientificninja.com/com-and-slimdx-part-1">&#8220;COM and SlimDX, Part 1,&#8221;</a> I discussed an early design decision that was made in SlimDX that prevented us from supporting the idiomatic C# pattern for disposal of unmanaged resources. In closing, I mentioned that our new solution, while a huge leap forward, still had some problems.</p>

<p>Today we&#8217;ll discuss them.</p>

<p>SlimDX supports the ability to share &#8212; in a sense &#8212; the native objects of other APIs using <a href="http://msdn2.microsoft.com/en-us/library/system.intptr(VS.71).aspx">System.IntPtr</a>, an opaque managed representation of a pointer or handle. All SlimDX COM objects expose their native pointer as an IntPtr. They can also be constructed from IntPtrs.</p>

<p>With the old SlimDX design, we only ran into two serious issues with this process. The first was that since IntPtrs are entirely opaque, we&#8217;d more-or-less trust the user to construct the correct type and pass the correct pointer. Sure, we performed a QueryInterface(), but that may not have been the best idea in retrospect &#8212; there are known scenarios (for example, see <a href="http://forums.xna.com/thread/28827.aspx">here</a> and <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=457958">here</a>) where DirectX objects don&#8217;t behave the way you might expect a COM interface to behave &#8212; and so our code might have occasionally failed in situations it should not have.</p>

<p>The second issue was that we used these IntPtr constructors internally, occasionally in scenarios where it was impractical to know the proper type to construct. Remember the GetDevice example from last time? In Direct3D10, there&#8217;s a similar method for resource views (<a href="http://msdn2.microsoft.com/en-us/library/bb173877(VS.85).aspx">GetResource()</a>) that is used to get a pointer to the resource that the view object is looking at. The method is a member of the <a href="http://msdn2.microsoft.com/en-us/library/bb173876(VS.85).aspx">ID3D10View</a> base class, so naturally we placed it in the analagous SlimDX.Direct3D10.ResourceView class. The implementation would have looked something like:
<pre class="brush: cpp;">
Resource^ ResourceView::GetResource()
{
  ID3D10Resource* resource = 0;
  NativeComInterface-&gt;GetResource( &amp;resource );
  return gcnew Resource( IntPtr( resource ) ); 
}
</pre></p>

<p>The problem with this approach is that it logically &#8220;slices&#8221; the object. This is similar to <a href="http://en.wikipedia.org/wiki/Slicing">slicing in, say, C++</a> except that the underlying object is not physical destroyed, only the way you can interact with that object reference. In other words, even if the ID3D10Resource* returned from the native call pointed to a derived ID3D10Texture2D, it would be an error to downcast the managed Resource reference to a managed Texture2D reference, because we statically constructed a Resource, <em>not</em> a Texture2D.</p>

<p>A solution to this is a factory-type construction process &#8212; fortunately for us, most of the types involved here had base class methods that would indicate the actual runtime type of the object somehow &#8212; even though that would mean we&#8217;d have to push most implementation of the method lower in the class hierarchy. That was the solution we were considering, until the object table was brought up, which neatly solved the whole issue for us.</p>

<p>Almost.</p>

<p>You see, there&#8217;s one final caveat. The reason the object table eliminates the need for a factory is that it stores the native pointer as the key, and the actual runtime managed instance as the value. Thus, the aforementioned code snippet becomes a table lookup instead of a gcnew statement. The problem rears its ugly little head when you consider the possibility that the table lookup can <em>fail to find the key</em>. At first that might seem impossible (and thus not worth handling) because the view can&#8217;t be created with a resource, and given the existence of the object table, the only way the resource can cease to exist before the view is if the programmer intentionally disposed of it. This would be a programmer error, which is generally something we do not concern ourselves with handling gracefully (that is, we&#8217;d throw an exception indicating the programmer is a dim bulb, rather than try to bravely soldier on).</p>

<p>Unfortunately, since SlimDX can exchange native resources with other APIs via IntPtr, it&#8217;s possible to get into this sticky situation rather easily &#8212; simply construct a new ResourceView using an exposed IntPtr. SlimDX will correctly handle the ResourceView, incrementing the native reference count and placing an entry in the object table. But SlimDX won&#8217;t know about the original resource, so if you call GetResource() on the view, SlimDX will not find the Resource&#8217;s key in the table. What will happen, in that case, is that SlimDX will treat the object as a new one, increment the native reference count, and add an object table entry. This is unfortunate because the user now has to Dispose() of that resource, even though they didn&#8217;t explictly allocate it with new.</p>

<p>We&#8217;re currently considering this a pathological use case, and aren&#8217;t addressing the issue. Users doing that kind of advanced interop with SlimDX will simply need to be aware of the problem and the non-standard call to Dispose() they&#8217;ll need to make. I do believe it is a fixable issue, but the fix isn&#8217;t in the March release since it will not adversely affect the majority of our user base &#8212; you&#8217;ll have to wait for June, if we&#8217;re even able to remedy it all. In the interim, however, it&#8217;s important to be aware of the dangers that lurk in the shady corners of the API.</p>
]]></content:encoded>
			<wfw:commentRss>http://scientificninja.com/blog/com-and-slimdx-part-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
