Commit ee16f0de by Nicolas Capens

Add back the D3D9 code from before the April 2014 code dump.

Bug 22533227 Change-Id: Ib669fcd6a644c79b3a9e8f5dcf7da278d75cefef Reviewed-on: https://swiftshader-review.googlesource.com/3730Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 074c6417
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3D9.hpp"
#include "Direct3D9Ex.hpp"
#include "Debug.hpp"
#include "resource.h"
#include <stdio.h>
#include <assert.h>
namespace D3D9
{
class Direct3DShaderValidator9
{
public:
Direct3DShaderValidator9();
virtual ~Direct3DShaderValidator9();
virtual int __stdcall ValidateShader(long *shader, long *shader1, long *shader2, long *shader3);
virtual int __stdcall ValidateShader2(long *shader);
virtual int __stdcall ValidateShader3(long *shader, long *shader1, long *shader2, long *shader3);
virtual int __stdcall ValidateShader4(long *shader, long *shader1, long *shader2, long *shader3);
virtual int __stdcall ValidateShader5(long *shader, long *shader1, long *shader2);
virtual int __stdcall ValidateShader6(long *shader, long *shader1, long *shader2, long *shader3);
};
Direct3DShaderValidator9::Direct3DShaderValidator9()
{
}
Direct3DShaderValidator9::~Direct3DShaderValidator9()
{
}
int __stdcall Direct3DShaderValidator9::ValidateShader(long *shader, long *shader1, long *shader2, long *shader3) // FIXME
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader2(long *shader) // FIXME
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader3(long *shader, long *shader1, long *shader2, long *shader3)
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader4(long *shader, long *shader1, long *shader2, long *shader3)
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader5(long *shader, long *shader1, long *shader2) // FIXME
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader6(long *shader, long *shader1, long *shader2, long *shader3) // FIXME
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
}
using namespace D3D9;
extern "C"
{
HINSTANCE dllInstance = 0;
int __stdcall DllMain(HINSTANCE instance, unsigned long reason, void *reserved)
{
#ifndef NDEBUG
if(dllInstance == 0)
{
FILE *file = fopen("debug.txt", "w"); // Clear debug log
fclose(file);
}
#endif
GTRACE("HINSTANCE instance = 0x%0.8p, unsigned long reason = %d, void *reserved = 0x%0.8p", instance, reason, reserved);
dllInstance = instance;
switch(reason)
{
case DLL_PROCESS_DETACH:
break;
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(instance);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
default:
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return TRUE;
}
IDirect3D9 *__stdcall Direct3DCreate9(unsigned int version)
{
GTRACE("");
// D3D_SDK_VERSION check
if(version != (31 | 0x80000000) && // 9.0a/b DEBUG_INFO
version != 31 && // 9.0a/b
version != (32 | 0x80000000) && // 9.0c DEBUG_INFO
version != 32) // 9.0c
{
return 0;
}
IDirect3D9 *device = new D3D9::Direct3D9(version, dllInstance);
if(device)
{
device->AddRef();
}
return device;
}
HRESULT __stdcall Direct3DCreate9Ex(unsigned int version, IDirect3D9Ex **device)
{
// D3D_SDK_VERSION check
if(version != (31 | 0x80000000) && // 9.0a/b DEBUG_INFO
version != 31 && // 9.0a/b
version != (32 | 0x80000000) && // 9.0c DEBUG_INFO
version != 32) // 9.0c
{
return NOTAVAILABLE();
}
*device = new D3D9::Direct3D9Ex(version, dllInstance);
if(device)
{
(*device)->AddRef();
}
else
{
return OUTOFMEMORY();
}
return D3D_OK;
}
int __stdcall CheckFullscreen()
{
GTRACE("");
UNIMPLEMENTED();
return FALSE;
}
int __stdcall D3DPERF_BeginEvent(D3DCOLOR color, const wchar_t *name)
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
return -1;
}
int __stdcall D3DPERF_EndEvent()
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
return -1;
}
unsigned long __stdcall D3DPERF_GetStatus()
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
return 0;
}
int __stdcall D3DPERF_QueryRepeatFrame()
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
return FALSE;
}
void __stdcall D3DPERF_SetMarker(D3DCOLOR color, const wchar_t *name)
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
}
void __stdcall D3DPERF_SetOptions(unsigned long options)
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
}
void __stdcall D3DPERF_SetRegion(D3DCOLOR color, const wchar_t *name)
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
}
void __cdecl DebugSetLevel(long level)
{
GTRACE("long level = %d", level);
// UNIMPLEMENTED(); // Debug output unsupported
}
void __cdecl DebugSetMute(long mute)
{
GTRACE("long mute = %d", mute);
// UNIMPLEMENTED(); // Debug output unsupported
}
void *__stdcall Direct3DShaderValidatorCreate9()
{
GTRACE("");
// UNIMPLEMENTED();
return 0;
// return new D3D9::Direct3DShaderValidator9();
}
void __stdcall PSGPError()
{
GTRACE("");
UNIMPLEMENTED();
}
void __stdcall PSGPSampleTexture()
{
GTRACE("");
UNIMPLEMENTED();
}
}
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
#include "../Common/Version.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"#include ""../Common/Version.h""\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
PRODUCTVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
FILEFLAGSMASK 0x1fL
#ifdef _DEBUG
FILEFLAGS 0x9L
#else
FILEFLAGS 0x8L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "TransGaming"
VALUE "FileDescription", "SwiftShader Direct3D 9 Software Renderer"
VALUE "FileVersion", VERSION_STRING
VALUE "InternalName", "D3D9"
VALUE "LegalCopyright", "Copyright (C) 2011 TransGaming Inc."
VALUE "OriginalFilename", "d3d9.dll"
VALUE "PrivateBuild", REVISION_STRING
VALUE "ProductName", "SwiftShader Direct3D 9 Software Renderer"
VALUE "ProductVersion", VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Capabilities.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="D3D9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Debug.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3D9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3D9Ex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DBaseTexture9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DCubeTexture9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DDevice9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DDevice9Ex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DIndexBuffer9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DPixelShader9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DQuery9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DResource9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DStateBlock9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DSurface9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DSwapChain9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DTexture9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVertexBuffer9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVertexDeclaration9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVertexShader9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVolume9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVolumeTexture9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SwiftShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Unknown.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Capabilities.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Debug.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3D9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3D9Ex.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DBaseTexture9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DCubeTexture9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DDevice9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DDevice9Ex.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DIndexBuffer9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DPixelShader9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DQuery9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DResource9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DStateBlock9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DSurface9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DSwapChain9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DTexture9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVertexBuffer9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVertexDeclaration9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVertexShader9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVolume9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVolumeTexture9.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SwiftShader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SwiftShader.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Unknown.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="D3D9.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="d3d9.def" />
</ItemGroup>
</Project>
\ No newline at end of file
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Debug.hpp"
int Trace::indent = 0;
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef Debug_hpp
#define Debug_hpp
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <d3d9.h>
#include <stdio.h>
#include <guiddef.h>
#include <assert.h>
#define APPEND(x, y) x ## y
#define MACRO_APPEND(x, y) APPEND(x, y)
#define UNIQUE_IDENTIFIER(prefix) MACRO_APPEND(prefix, __COUNTER__)
struct Trace
{
Trace(const char *format, ...)
{
if(false)
{
FILE *file = fopen("debug.txt", "a");
if(file)
{
for(int i = 0; i < indent; i++) fprintf(file, " ");
va_list vararg;
va_start(vararg, format);
vfprintf(file, format, vararg);
va_end(vararg);
fclose(file);
}
}
indent++;
}
~Trace()
{
indent--;
}
static int indent;
};
#ifndef NDEBUG
#define TRACE(format, ...) Trace UNIQUE_IDENTIFIER(_tracer_)("[0x%0.8X]%s("format")\n", this, __FUNCTION__, __VA_ARGS__)
#define GTRACE(format, ...) Trace("%s("format")\n", __FUNCTION__, __VA_ARGS__)
#else
#define TRACE(...) ((void)0)
#define GTRACE(...) ((void)0)
#endif
#ifndef NDEBUG
#define ASSERT(expression) {if(!(expression)) Trace("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); assert(expression);}
#else
#define ASSERT assert
#endif
#ifndef NDEBUG
#define UNIMPLEMENTED() {Trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}
#else
#define UNIMPLEMENTED() ((void)0)
#endif
#ifndef NDEBUG
#define NOINTERFACE(iid) _NOINTERFACE(__FUNCTION__, iid)
inline long _NOINTERFACE(const char *function, const IID &iid)
{
Trace("\t! No interface {0x%0.8X, 0x%0.4X, 0x%0.4X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X} for %s\n", iid.Data1, iid.Data2, iid.Data3, iid.Data4[0], iid.Data4[1], iid.Data4[2], iid.Data4[3], iid.Data4[4], iid.Data4[5], iid.Data4[6], iid.Data4[7], function);
return E_NOINTERFACE;
}
#else
#define NOINTERFACE(iid) E_NOINTERFACE
#endif
#ifndef NDEBUG
inline long INVALIDCALL()
{
Trace("\t! D3DERR_INVALIDCALL\n");
return D3DERR_INVALIDCALL;
}
#else
#define INVALIDCALL() D3DERR_INVALIDCALL
#endif
#ifndef NDEBUG
inline long OUTOFMEMORY()
{
Trace("\t! E_OUTOFMEMORY\n");
return E_OUTOFMEMORY;
}
#else
#define OUTOFMEMORY() E_OUTOFMEMORY
#endif
#ifndef NDEBUG
inline long OUTOFVIDEOMEMORY()
{
Trace("\t! D3DERR_OUTOFVIDEOMEMORY\n");
return D3DERR_OUTOFVIDEOMEMORY;
}
#else
#define OUTOFVIDEOMEMORY() D3DERR_OUTOFVIDEOMEMORY
#endif
#ifndef NDEBUG
inline long NOTAVAILABLE()
{
Trace("\t! D3DERR_NOTAVAILABLE\n");
return D3DERR_NOTAVAILABLE;
}
#else
#define NOTAVAILABLE() D3DERR_NOTAVAILABLE
#endif
#ifndef NDEBUG
inline long NOTFOUND()
{
Trace("\t! D3DERR_NOTFOUND\n");
return D3DERR_NOTFOUND;
}
#else
#define NOTFOUND() D3DERR_NOTFOUND
#endif
#ifndef NDEBUG
inline long MOREDATA()
{
Trace("\t! D3DERR_MOREDATA\n");
return D3DERR_MOREDATA;
}
#else
#define MOREDATA() D3DERR_MOREDATA
#endif
#ifndef NDEBUG
inline long FAIL()
{
Trace("\t! E_FAIL\n");
return E_FAIL;
}
#else
#define FAIL() E_FAIL
#endif
#endif // Debug_hpp
This source diff could not be displayed because it is too large. You can view the blob instead.
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3D9_hpp
#define D3D9_Direct3D9_hpp
#include "Unknown.hpp"
#include <stdio.h>
#include <d3d9.h>
namespace D3D9
{
class Direct3DDevice9;
class Direct3D9 : public IDirect3D9, public Unknown
{
public:
Direct3D9(int version, const HINSTANCE instance);
virtual ~Direct3D9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3D9 methods
long __stdcall RegisterSoftwareDevice(void *initializeFunction);
unsigned int __stdcall GetAdapterCount();
long __stdcall GetAdapterIdentifier(unsigned int adapter, unsigned long flags, D3DADAPTER_IDENTIFIER9 *identifier);
unsigned int __stdcall GetAdapterModeCount(unsigned int adapter, D3DFORMAT format);
long __stdcall EnumAdapterModes(unsigned int adapter, D3DFORMAT format, unsigned int index, D3DDISPLAYMODE *mode);
long __stdcall GetAdapterDisplayMode(unsigned int adapter, D3DDISPLAYMODE *mode);
long __stdcall CheckDeviceType(unsigned int adapter, D3DDEVTYPE checkType, D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, int windowed);
long __stdcall CheckDeviceFormat(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, unsigned long usage, D3DRESOURCETYPE type, D3DFORMAT checkFormat);
long __stdcall CheckDeviceMultiSampleType(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT surfaceFormat, int windowed, D3DMULTISAMPLE_TYPE multiSampleType, unsigned long *qualityLevels);
long __stdcall CheckDepthStencilMatch(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat);
long __stdcall CheckDeviceFormatConversion(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT sourceFormat, D3DFORMAT targetFormat);
long __stdcall GetDeviceCaps(unsigned int adapter, D3DDEVTYPE deviceType, D3DCAPS9 *caps);
HMONITOR __stdcall GetAdapterMonitor(unsigned int adapter);
long __stdcall CreateDevice(unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, unsigned long behaviorFlags, D3DPRESENT_PARAMETERS *presentParameters, IDirect3DDevice9 **returnedDeviceInterface);
protected:
// Creation parameters
const int version;
const HINSTANCE instance;
// Real D3D9 library
HMODULE d3d9Lib;
private:
void loadSystemD3D9();
DEVMODE *displayMode;
int numDisplayModes;
bool disableAlphaMode; // Disable A8R8G8B8 display mode support
bool disable10BitMode; // Disable A2R10G10B10 display mode support
//Real IDirect3D9 object
IDirect3D9 *d3d9;
};
}
#endif // D3D9_Direct3D9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3D9Ex_hpp
#define D3D9_Direct3D9Ex_hpp
#include "Direct3D9.hpp"
//#include <stdio.h>
#include <d3d9.h>
namespace D3D9
{
class Direct3DDevice9;
class Direct3D9Ex : public IDirect3D9Ex, public Direct3D9
{
public:
Direct3D9Ex(int version, const HINSTANCE instance);
virtual ~Direct3D9Ex();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3D9 methods
long __stdcall RegisterSoftwareDevice(void *initializeFunction);
unsigned int __stdcall GetAdapterCount();
long __stdcall GetAdapterIdentifier(unsigned int adapter, unsigned long flags, D3DADAPTER_IDENTIFIER9 *identifier);
unsigned int __stdcall GetAdapterModeCount(unsigned int adapter, D3DFORMAT format);
long __stdcall EnumAdapterModes(unsigned int adapter, D3DFORMAT format, unsigned int index, D3DDISPLAYMODE *mode);
long __stdcall GetAdapterDisplayMode(unsigned int adapter, D3DDISPLAYMODE *mode);
long __stdcall CheckDeviceType(unsigned int adapter, D3DDEVTYPE checkType, D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, int windowed);
long __stdcall CheckDeviceFormat(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, unsigned long usage, D3DRESOURCETYPE type, D3DFORMAT checkFormat);
long __stdcall CheckDeviceMultiSampleType(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT surfaceFormat, int windowed, D3DMULTISAMPLE_TYPE multiSampleType, unsigned long *qualityLevels);
long __stdcall CheckDepthStencilMatch(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat);
long __stdcall CheckDeviceFormatConversion(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT sourceFormat, D3DFORMAT targetFormat);
long __stdcall GetDeviceCaps(unsigned int adapter, D3DDEVTYPE deviceType, D3DCAPS9 *caps);
HMONITOR __stdcall GetAdapterMonitor(unsigned int adapter);
long __stdcall CreateDevice(unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, unsigned long behaviorFlags, D3DPRESENT_PARAMETERS *presentParameters, IDirect3DDevice9 **returnedDeviceInterface);
// IDirect3D9Ex methods
unsigned int __stdcall GetAdapterModeCountEx(unsigned int adapter, const D3DDISPLAYMODEFILTER *filter);
long __stdcall EnumAdapterModesEx(unsigned int adapter, const D3DDISPLAYMODEFILTER *filter, unsigned int index, D3DDISPLAYMODEEX *mode);
long __stdcall GetAdapterDisplayModeEx(unsigned int adapter, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation);
long __stdcall CreateDeviceEx(unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, DWORD behaviorFlags, D3DPRESENT_PARAMETERS *presentParameters, D3DDISPLAYMODEEX *fullscreenDisplayMode, IDirect3DDevice9Ex **returnedDeviceInterface);
long __stdcall GetAdapterLUID(unsigned int adapter, LUID *luid);
private:
void loadSystemD3D9ex();
// Real IDirect3D9Ex object
IDirect3D9Ex *d3d9ex;
};
}
#endif // D3D9_Direct3D9Ex_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DBaseTexture9.hpp"
#include "Direct3DDevice9.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D9
{
Direct3DBaseTexture9::Direct3DBaseTexture9(Direct3DDevice9 *device, D3DRESOURCETYPE type, D3DFORMAT format, D3DPOOL pool, unsigned long levels, unsigned long usage) : Direct3DResource9(device, type, pool, 0), format(format), levels(levels), usage(usage)
{
filterType = D3DTEXF_LINEAR;
LOD = 0;
resource = new sw::Resource(0);
}
Direct3DBaseTexture9::~Direct3DBaseTexture9()
{
resource->destruct();
}
long Direct3DBaseTexture9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DBaseTexture9 ||
iid == IID_IDirect3DResource9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DBaseTexture9::AddRef()
{
TRACE("");
return Direct3DResource9::AddRef();
}
unsigned long Direct3DBaseTexture9::Release()
{
TRACE("");
return Direct3DResource9::Release();
}
long Direct3DBaseTexture9::FreePrivateData(const GUID &guid)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::FreePrivateData(guid);
}
long Direct3DBaseTexture9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetPrivateData(guid, data, size);
}
void Direct3DBaseTexture9::PreLoad()
{
CriticalSection cs(device);
TRACE("");
Direct3DResource9::PreLoad();
}
long Direct3DBaseTexture9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::SetPrivateData(guid, data, size, flags);
}
long Direct3DBaseTexture9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
return Direct3DResource9::GetDevice(device);
}
unsigned long Direct3DBaseTexture9::SetPriority(unsigned long newPriority)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::SetPriority(newPriority);
}
unsigned long Direct3DBaseTexture9::GetPriority()
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetPriority();
}
D3DRESOURCETYPE Direct3DBaseTexture9::GetType()
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetType();
}
D3DTEXTUREFILTERTYPE Direct3DBaseTexture9::GetAutoGenFilterType()
{
CriticalSection cs(device);
TRACE("");
if(usage & D3DUSAGE_AUTOGENMIPMAP)
{
return filterType;
}
else
{
return D3DTEXF_NONE;
}
}
unsigned long Direct3DBaseTexture9::GetLevelCount()
{
CriticalSection cs(device);
TRACE("");
if(usage & D3DUSAGE_AUTOGENMIPMAP)
{
return 1;
}
return levels;
}
unsigned long Direct3DBaseTexture9::GetLOD()
{
CriticalSection cs(device);
TRACE("");
if(pool & D3DPOOL_MANAGED)
{
return LOD;
}
else
{
return 0;
}
}
long Direct3DBaseTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE filterType)
{
CriticalSection cs(device);
TRACE("");
if(usage & D3DUSAGE_AUTOGENMIPMAP)
{
this->filterType = filterType; // FIXME: Check if valid
// FIXME: Dirty the mipmap chain
return D3D_OK;
}
else
{
return D3DTEXF_NONE;
}
}
unsigned long Direct3DBaseTexture9::SetLOD(unsigned long newLOD)
{
CriticalSection cs(device);
TRACE("");
unsigned long oldLOD = LOD;
LOD = newLOD < levels ? newLOD : levels - 1;
if(pool & D3DPOOL_MANAGED)
{
return oldLOD;
}
else
{
return 0;
}
}
void Direct3DBaseTexture9::GenerateMipSubLevels()
{
CriticalSection cs(device);
TRACE("");
}
sw::Resource *Direct3DBaseTexture9::getResource() const
{
return resource;
}
unsigned long Direct3DBaseTexture9::getInternalLevelCount() const
{
return levels;
}
unsigned long Direct3DBaseTexture9::getUsage() const
{
return usage;
}
D3DFORMAT Direct3DBaseTexture9::getFormat() const
{
return format;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DBaseTexture9_hpp
#define D3D9_Direct3DBaseTexture9_hpp
#include "Direct3DResource9.hpp"
#include <d3d9.h>
namespace sw
{
class Resource;
}
namespace D3D9
{
class Direct3DBaseTexture9 : public IDirect3DBaseTexture9, public Direct3DResource9
{
public:
Direct3DBaseTexture9(Direct3DDevice9 *device, D3DRESOURCETYPE type, D3DFORMAT format, D3DPOOL pool, unsigned long levels, unsigned long usage);
virtual ~Direct3DBaseTexture9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource9 methods
long __stdcall GetDevice(IDirect3DDevice9 **device);
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
long __stdcall FreePrivateData(const GUID &guid);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
void __stdcall PreLoad();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DBaseTexture9 methods
unsigned long __stdcall SetLOD(unsigned long newLOD);
unsigned long __stdcall GetLOD();
unsigned long __stdcall GetLevelCount();
long __stdcall SetAutoGenFilterType(D3DTEXTUREFILTERTYPE filterType);
D3DTEXTUREFILTERTYPE __stdcall GetAutoGenFilterType();
void __stdcall GenerateMipSubLevels();
// Intenal methods
sw::Resource *getResource() const;
unsigned long getInternalLevelCount() const;
unsigned long getUsage() const;
D3DFORMAT getFormat() const;
protected:
// Creation parameters
unsigned long levels; // Recalculated when 0
const unsigned long usage;
const D3DFORMAT format;
sw::Resource *resource;
private:
D3DTEXTUREFILTERTYPE filterType;
unsigned long LOD;
};
}
#endif // D3D9_Direct3DBaseTexture9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DCubeTexture9.hpp"
#include "Direct3DDevice9.hpp"
#include "Direct3DSurface9.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D9
{
Direct3DCubeTexture9::Direct3DCubeTexture9(Direct3DDevice9 *device, unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture9(device, D3DRTYPE_CUBETEXTURE, format, pool, levels, usage), edgeLength(edgeLength)
{
if(levels == 0)
{
this->levels = sw::log2(sw::max((int)edgeLength, 1)) + 1;
}
for(unsigned int face = 0; face < 6; face++)
{
int width = edgeLength;
int height = edgeLength;
for(unsigned int level = 0; level < MIPMAP_LEVELS; level++)
{
if(level < this->levels)
{
surfaceLevel[face][level] = new Direct3DSurface9(device, this, width, height, format, pool, D3DMULTISAMPLE_NONE, 0, false, usage);
surfaceLevel[face][level]->bind();
}
else
{
surfaceLevel[face][level] = 0;
}
width = sw::max(1, width / 2);
height = sw::max(1, height / 2);
}
}
}
Direct3DCubeTexture9::~Direct3DCubeTexture9()
{
resource->lock(sw::DESTRUCT);
for(unsigned int face = 0; face < 6; face++)
{
for(int level = 0; level < MIPMAP_LEVELS; level++)
{
if(surfaceLevel[face][level])
{
surfaceLevel[face][level]->unbind();
surfaceLevel[face][level] = 0;
}
}
}
resource->unlock();
}
long Direct3DCubeTexture9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DCubeTexture9 ||
iid == IID_IDirect3DBaseTexture9 ||
iid == IID_IDirect3DResource9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DCubeTexture9::AddRef()
{
TRACE("");
return Direct3DBaseTexture9::AddRef();
}
unsigned long Direct3DCubeTexture9::Release()
{
TRACE("");
return Direct3DBaseTexture9::Release();
}
long Direct3DCubeTexture9::FreePrivateData(const GUID &guid)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::FreePrivateData(guid);
}
long Direct3DCubeTexture9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetPrivateData(guid, data, size);
}
void Direct3DCubeTexture9::PreLoad()
{
CriticalSection cs(device);
TRACE("");
Direct3DBaseTexture9::PreLoad();
}
long Direct3DCubeTexture9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::SetPrivateData(guid, data, size, flags);
}
long Direct3DCubeTexture9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
return Direct3DBaseTexture9::GetDevice(device);
}
unsigned long Direct3DCubeTexture9::SetPriority(unsigned long newPriority)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::SetPriority(newPriority);
}
unsigned long Direct3DCubeTexture9::GetPriority()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetPriority();
}
D3DRESOURCETYPE Direct3DCubeTexture9::GetType()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetType();
}
void Direct3DCubeTexture9::GenerateMipSubLevels()
{
CriticalSection cs(device);
TRACE("");
if(!(usage & D3DUSAGE_AUTOGENMIPMAP))
{
return;
}
resource->lock(sw::PUBLIC);
for(unsigned int face = 0; face < 6; face++)
{
if(!surfaceLevel[face][0]->hasDirtyMipmaps())
{
continue;
}
for(unsigned int i = 0; i < levels - 1; i++)
{
device->stretchRect(surfaceLevel[face][i], 0, surfaceLevel[face][i + 1], 0, GetAutoGenFilterType());
}
surfaceLevel[face][0]->cleanMipmaps();
}
resource->unlock();
}
D3DTEXTUREFILTERTYPE Direct3DCubeTexture9::GetAutoGenFilterType()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetAutoGenFilterType();
}
unsigned long Direct3DCubeTexture9::GetLevelCount()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetLevelCount();
}
unsigned long Direct3DCubeTexture9::GetLOD()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetLOD();
}
long Direct3DCubeTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE filterType)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::SetAutoGenFilterType(filterType);
}
unsigned long Direct3DCubeTexture9::SetLOD(unsigned long newLOD)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::SetLOD(newLOD);
}
long Direct3DCubeTexture9::AddDirtyRect(D3DCUBEMAP_FACES face, const RECT *dirtyRect)
{
CriticalSection cs(device);
TRACE("");
// UNIMPLEMENTED();
return D3D_OK;
}
long Direct3DCubeTexture9::GetCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level, IDirect3DSurface9 **cubeMapSurface)
{
CriticalSection cs(device);
TRACE("");
*cubeMapSurface = 0;
if(face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
{
return INVALIDCALL();
}
surfaceLevel[face][level]->AddRef();
*cubeMapSurface = surfaceLevel[face][level];
return D3D_OK;
}
long Direct3DCubeTexture9::GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description)
{
CriticalSection cs(device);
TRACE("");
if(!description || level >= GetLevelCount() || !surfaceLevel[0][level])
{
return INVALIDCALL();
}
return surfaceLevel[0][level]->GetDesc(description);
}
long Direct3DCubeTexture9::LockRect(D3DCUBEMAP_FACES face, unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
if(!lockedRect || face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
{
return INVALIDCALL();
}
return surfaceLevel[face][level]->LockRect(lockedRect, rect, flags);
}
long Direct3DCubeTexture9::UnlockRect(D3DCUBEMAP_FACES face, unsigned int level)
{
CriticalSection cs(device);
TRACE("");
if(face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
{
return INVALIDCALL();
}
return surfaceLevel[face][level]->UnlockRect();
}
Direct3DSurface9 *Direct3DCubeTexture9::getInternalCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level)
{
return surfaceLevel[face][level];
}
}
\ No newline at end of file
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DCubeTexture9_hpp
#define D3D9_Direct3DCubeTexture9_hpp
#include "Direct3DBaseTexture9.hpp"
#include "Config.hpp"
#include <d3d9.h>
namespace D3D9
{
class Direct3DSurface9;
class Direct3DCubeTexture9 : public IDirect3DCubeTexture9, public Direct3DBaseTexture9
{
public:
Direct3DCubeTexture9(Direct3DDevice9 *device, unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
virtual ~Direct3DCubeTexture9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource9 methods
long __stdcall GetDevice(IDirect3DDevice9 **device);
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
long __stdcall FreePrivateData(const GUID &guid);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
void __stdcall PreLoad();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DBaseTexture9 methods
unsigned long __stdcall SetLOD(unsigned long newLOD);
unsigned long __stdcall GetLOD();
unsigned long __stdcall GetLevelCount();
long __stdcall SetAutoGenFilterType(D3DTEXTUREFILTERTYPE filterType);
D3DTEXTUREFILTERTYPE __stdcall GetAutoGenFilterType();
void __stdcall GenerateMipSubLevels();
// IDirect3DCubeTexture9 methods
long __stdcall GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description);
long __stdcall GetCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level, IDirect3DSurface9 **cubeMapSurface);
long __stdcall LockRect(D3DCUBEMAP_FACES face, unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags);
long __stdcall UnlockRect(D3DCUBEMAP_FACES face, unsigned int level);
long __stdcall AddDirtyRect(D3DCUBEMAP_FACES face, const RECT *dirtyRect);
// Internal methods
Direct3DSurface9 *getInternalCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level);
private:
// Creation parameters
const unsigned int edgeLength;
Direct3DSurface9 *surfaceLevel[6][MIPMAP_LEVELS];
};
}
#endif // D3D9_Direct3D9_hpp
This source diff could not be displayed because it is too large. You can view the blob instead.
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DIndexBuffer9.hpp"
#include "Direct3DDevice9.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D9
{
Direct3DIndexBuffer9::Direct3DIndexBuffer9(Direct3DDevice9 *device, unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DResource9(device, D3DRTYPE_INDEXBUFFER, pool, length), length(length), usage(usage), format(format)
{
indexBuffer = new sw::Resource(length + 16);
lockCount = 0;
}
Direct3DIndexBuffer9::~Direct3DIndexBuffer9()
{
indexBuffer->destruct();
}
long Direct3DIndexBuffer9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DIndexBuffer9 ||
iid == IID_IDirect3DResource9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DIndexBuffer9::AddRef()
{
TRACE("");
return Direct3DResource9::AddRef();
}
unsigned long Direct3DIndexBuffer9::Release()
{
TRACE("");
return Direct3DResource9::Release();
}
long Direct3DIndexBuffer9::FreePrivateData(const GUID &guid)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::FreePrivateData(guid);
}
long Direct3DIndexBuffer9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetPrivateData(guid, data, size);
}
void Direct3DIndexBuffer9::PreLoad()
{
CriticalSection cs(device);
TRACE("");
Direct3DResource9::PreLoad();
}
long Direct3DIndexBuffer9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::SetPrivateData(guid, data, size, flags);
}
long Direct3DIndexBuffer9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
return Direct3DResource9::GetDevice(device);
}
unsigned long Direct3DIndexBuffer9::SetPriority(unsigned long newPriority)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::SetPriority(newPriority);
}
unsigned long Direct3DIndexBuffer9::GetPriority()
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetPriority();
}
D3DRESOURCETYPE Direct3DIndexBuffer9::GetType()
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetType();
}
long Direct3DIndexBuffer9::GetDesc(D3DINDEXBUFFER_DESC *description)
{
CriticalSection cs(device);
TRACE("");
if(!description)
{
return INVALIDCALL();
}
description->Format = format;
description->Pool = pool;
description->Size = length;
description->Type = GetType();
description->Usage = usage;
return 0;
}
long Direct3DIndexBuffer9::Lock(unsigned int offset, unsigned int size, void **data, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
if(offset == 0 && size == 0) // Lock whole buffer
{
size = length;
}
if(!data || offset > length || offset + size > length)
{
return INVALIDCALL();
}
void *buffer;
if(flags & D3DLOCK_DISCARD/* && usage & D3DUSAGE_DYNAMIC*/)
{
indexBuffer->destruct();
indexBuffer = new sw::Resource(length + 16);
buffer = (void*)indexBuffer->getBuffer();
}
else if(flags & D3DLOCK_NOOVERWRITE/* && usage & D3DUSAGE_DYNAMIC*/)
{
buffer = (void*)indexBuffer->getBuffer();
}
else
{
buffer = indexBuffer->lock(sw::PUBLIC);
lockCount++;
}
*data = (unsigned char*)buffer + offset;
return D3D_OK;
}
long Direct3DIndexBuffer9::Unlock()
{
CriticalSection cs(device);
TRACE("");
if(lockCount > 0)
{
indexBuffer->unlock();
lockCount--;
}
return D3D_OK;
}
sw::Resource *Direct3DIndexBuffer9::getResource() const
{
return indexBuffer;
}
bool Direct3DIndexBuffer9::is32Bit() const
{
switch(format)
{
case D3DFMT_INDEX16:
return false;
case D3DFMT_INDEX32:
return true;
default:
ASSERT(false);
}
return false;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DIndexBuffer9_hpp
#define D3D9_Direct3DIndexBuffer9_hpp
#include "Direct3DResource9.hpp"
#include <d3d9.h>
namespace sw
{
class Resource;
}
namespace D3D9
{
class Direct3DIndexBuffer9 : public IDirect3DIndexBuffer9, public Direct3DResource9
{
public:
Direct3DIndexBuffer9(Direct3DDevice9 *device, unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
virtual ~Direct3DIndexBuffer9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource9 methods
long __stdcall FreePrivateData(const GUID &guid);
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
void __stdcall PreLoad();
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
long __stdcall GetDevice(IDirect3DDevice9 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DIndexBuffer9 methods
long __stdcall GetDesc(D3DINDEXBUFFER_DESC *description);
long __stdcall Lock(unsigned int offset, unsigned int size, void **data, unsigned long flags);
long __stdcall Unlock();
// Internal methods
sw::Resource *getResource() const;
bool is32Bit() const;
private:
// Creation parameters
const unsigned int length;
const long usage;
const D3DFORMAT format;
sw::Resource *indexBuffer;
int lockCount;
};
}
#endif // D3D9_Direct3DIndexBuffer9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DPixelShader9.hpp"
#include "Direct3DDevice9.hpp"
#include "Debug.hpp"
namespace D3D9
{
Direct3DPixelShader9::Direct3DPixelShader9(Direct3DDevice9 *device, const unsigned long *shaderToken) : device(device), pixelShader(shaderToken)
{
}
Direct3DPixelShader9::~Direct3DPixelShader9()
{
}
long Direct3DPixelShader9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DPixelShader9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DPixelShader9::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DPixelShader9::Release()
{
TRACE("");
return Unknown::Release();
}
long Direct3DPixelShader9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
if(!device)
{
return INVALIDCALL();
}
this->device->AddRef();
*device = this->device;
return D3D_OK;
}
long Direct3DPixelShader9::GetFunction(void *data, unsigned int *size)
{
CriticalSection cs(device);
TRACE("");
if(!size)
{
return INVALIDCALL();
}
pixelShader.getFunction(data, size);
return D3D_OK;
}
const sw::PixelShader *Direct3DPixelShader9::getPixelShader() const
{
return &pixelShader;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DPixelShader9_hpp
#define D3D9_Direct3DPixelShader9_hpp
#include "Unknown.hpp"
#include "PixelShader.hpp"
#include <d3d9.h>
namespace D3D9
{
class Direct3DDevice9;
class Direct3DPixelShader9 : public IDirect3DPixelShader9, public Unknown
{
public:
Direct3DPixelShader9(Direct3DDevice9 *device, const unsigned long *shaderToken);
virtual ~Direct3DPixelShader9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DPixelShader9 methods
long __stdcall GetDevice(IDirect3DDevice9 **device);
long __stdcall GetFunction(void *data, unsigned int *size);
// Internal methods
const sw::PixelShader *getPixelShader() const;
private:
// Creation parameters
Direct3DDevice9 *const device;
sw::PixelShader pixelShader;
};
}
#endif // D3D9_Direct3DPixelShader9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DQuery9.hpp"
#include "Direct3DDevice9.hpp"
#include "Timer.hpp"
#include "Renderer.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D9
{
Direct3DQuery9::Direct3DQuery9(Direct3DDevice9 *device, D3DQUERYTYPE type) : device(device), type(type)
{
if(type == D3DQUERYTYPE_OCCLUSION)
{
query = new sw::Query();
}
else
{
query = 0;
}
}
Direct3DQuery9::~Direct3DQuery9()
{
if(query)
{
device->removeQuery(query);
delete query;
}
}
long Direct3DQuery9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DQuery9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DQuery9::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DQuery9::Release()
{
TRACE("");
return Unknown::Release();
}
long __stdcall Direct3DQuery9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
if(!device)
{
return INVALIDCALL();
}
this->device->AddRef();
*device = this->device;
return D3D_OK;
}
D3DQUERYTYPE Direct3DQuery9::GetType()
{
CriticalSection cs(device);
return type;
}
unsigned long Direct3DQuery9::GetDataSize()
{
CriticalSection cs(device);
TRACE("");
switch(type)
{
case D3DQUERYTYPE_VCACHE: return sizeof(D3DDEVINFO_VCACHE);
case D3DQUERYTYPE_RESOURCEMANAGER: return sizeof(D3DDEVINFO_RESOURCEMANAGER);
case D3DQUERYTYPE_VERTEXSTATS: return sizeof(D3DDEVINFO_D3DVERTEXSTATS);
case D3DQUERYTYPE_EVENT: return sizeof(BOOL);
case D3DQUERYTYPE_OCCLUSION: return sizeof(DWORD);
case D3DQUERYTYPE_TIMESTAMP: return sizeof(UINT64);
case D3DQUERYTYPE_TIMESTAMPDISJOINT: return sizeof(BOOL);
case D3DQUERYTYPE_TIMESTAMPFREQ: return sizeof(UINT64);
case D3DQUERYTYPE_PIPELINETIMINGS: return sizeof(D3DDEVINFO_D3D9PIPELINETIMINGS);
case D3DQUERYTYPE_INTERFACETIMINGS: return sizeof(D3DDEVINFO_D3D9INTERFACETIMINGS);
case D3DQUERYTYPE_VERTEXTIMINGS: return sizeof(D3DDEVINFO_D3D9STAGETIMINGS);
case D3DQUERYTYPE_PIXELTIMINGS: return sizeof(D3DDEVINFO_D3D9PIPELINETIMINGS);
case D3DQUERYTYPE_BANDWIDTHTIMINGS: return sizeof(D3DDEVINFO_D3D9BANDWIDTHTIMINGS);
case D3DQUERYTYPE_CACHEUTILIZATION: return sizeof(D3DDEVINFO_D3D9CACHEUTILIZATION);
default:
ASSERT(false);
}
return D3D_OK;
}
long Direct3DQuery9::Issue(unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END)
{
return INVALIDCALL();
}
switch(type)
{
case D3DQUERYTYPE_VCACHE: if(flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_RESOURCEMANAGER: if(flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_VERTEXSTATS: if(flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_EVENT:
if(flags == D3DISSUE_END)
{
// device->renderer->synchronize(); // FIXME
}
else return INVALIDCALL();
break;
case D3DQUERYTYPE_OCCLUSION:
if(flags == D3DISSUE_BEGIN)
{
query->begin();
device->addQuery(query);
device->setOcclusionEnabled(true);
}
else // flags == D3DISSUE_END
{
query->end();
device->removeQuery(query);
device->setOcclusionEnabled(false);
}
break;
case D3DQUERYTYPE_TIMESTAMP: if(flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_TIMESTAMPDISJOINT: if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_TIMESTAMPFREQ: if(flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_PIPELINETIMINGS: if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_INTERFACETIMINGS: if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_VERTEXTIMINGS: if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_PIXELTIMINGS: if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_BANDWIDTHTIMINGS: if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
case D3DQUERYTYPE_CACHEUTILIZATION: if(flags != D3DISSUE_BEGIN && flags != D3DISSUE_END) return INVALIDCALL(); break;
default:
ASSERT(false);
}
return D3D_OK;
}
long Direct3DQuery9::GetData(void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("void *data = %p, unsigned long size = %d, unsigned long flags = %d", data, size, flags);
if(query && query->building)
{
return INVALIDCALL();
}
bool signaled = !query || query->reference == 0;
if(size && signaled)
{
if(!data)
{
return INVALIDCALL();
}
// FIXME: Check size
switch(type)
{
case D3DQUERYTYPE_VCACHE:
{
D3DDEVINFO_VCACHE vcache;
vcache.Pattern = 'CACH';
vcache.OptMethod = 1; // Vertex-cache based optimization
vcache.CacheSize = 16;
vcache.MagicNumber = 8;
*(D3DDEVINFO_VCACHE*)data = vcache;
}
break;
case D3DQUERYTYPE_RESOURCEMANAGER: UNIMPLEMENTED(); break;
case D3DQUERYTYPE_VERTEXSTATS: UNIMPLEMENTED(); break;
case D3DQUERYTYPE_EVENT: *(BOOL*)data = TRUE; break; // FIXME
case D3DQUERYTYPE_OCCLUSION:
*(DWORD*)data = query->data;
break;
case D3DQUERYTYPE_TIMESTAMP: *(UINT64*)data = sw::Timer::counter(); break; // FIXME: Verify behaviour
case D3DQUERYTYPE_TIMESTAMPDISJOINT: *(BOOL*)data = FALSE; break; // FIXME: Verify behaviour
case D3DQUERYTYPE_TIMESTAMPFREQ: *(UINT64*)data = sw::Timer::frequency(); break; // FIXME: Verify behaviour
case D3DQUERYTYPE_PIPELINETIMINGS: UNIMPLEMENTED(); break;
case D3DQUERYTYPE_INTERFACETIMINGS: UNIMPLEMENTED(); break;
case D3DQUERYTYPE_VERTEXTIMINGS: UNIMPLEMENTED(); break;
case D3DQUERYTYPE_PIXELTIMINGS: UNIMPLEMENTED(); break;
case D3DQUERYTYPE_BANDWIDTHTIMINGS: UNIMPLEMENTED(); break;
case D3DQUERYTYPE_CACHEUTILIZATION: UNIMPLEMENTED(); break;
default:
ASSERT(false);
}
}
return signaled ? S_OK : S_FALSE;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DQuery9_hpp
#define D3D9_Direct3DQuery9_hpp
#include "Unknown.hpp"
#include "Renderer.hpp"
#include <d3d9.h>
namespace D3D9
{
class Direct3DDevice9;
class Direct3DQuery9 : public IDirect3DQuery9, public Unknown
{
public:
Direct3DQuery9(Direct3DDevice9 *device, D3DQUERYTYPE type);
virtual ~Direct3DQuery9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DQuery9 methods
long __stdcall GetDevice(IDirect3DDevice9 **device);
D3DQUERYTYPE __stdcall GetType();
unsigned long __stdcall GetDataSize();
long __stdcall Issue(unsigned long flags);
long __stdcall GetData(void *data, unsigned long size, unsigned long flags);
private:
// Creation parameters
Direct3DDevice9 *const device;
const D3DQUERYTYPE type;
sw::Query *query;
};
}
#endif // D3D9_Direct3DQuery9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DResource9.hpp"
#include "Direct3DDevice9.hpp"
#include "Debug.hpp"
namespace D3D9
{
unsigned int Direct3DResource9::memoryUsage = 0;
Direct3DResource9::PrivateData::PrivateData()
{
data = 0;
}
Direct3DResource9::PrivateData::PrivateData(const void *data, int size, bool managed)
{
this->size = size;
this->managed = managed;
this->data = (void*)new unsigned char[size];
memcpy(this->data, data, size);
if(managed)
{
((IUnknown*)data)->AddRef();
}
}
Direct3DResource9::PrivateData &Direct3DResource9::PrivateData::operator=(const PrivateData &privateData)
{
size = privateData.size;
managed = privateData.managed;
if(data)
{
if(managed)
{
((IUnknown*)data)->Release();
}
delete[] data;
}
data = (void*)new unsigned char[size];
memcpy(data, privateData.data, size);
return *this;
}
Direct3DResource9::PrivateData::~PrivateData()
{
if(data && managed)
{
((IUnknown*)data)->Release();
}
delete[] data;
data = 0;
}
Direct3DResource9::Direct3DResource9(Direct3DDevice9 *device, D3DRESOURCETYPE type, D3DPOOL pool, unsigned int size) : device(device), type(type), pool(pool), size(size)
{
priority = 0;
if(pool == D3DPOOL_DEFAULT)
{
memoryUsage += size;
}
}
Direct3DResource9::~Direct3DResource9()
{
if(pool == D3DPOOL_DEFAULT)
{
memoryUsage -= size;
}
}
long Direct3DResource9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DResource9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DResource9::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DResource9::Release()
{
TRACE("");
return Unknown::Release();
}
long Direct3DResource9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
if(!device)
{
return INVALIDCALL();
}
this->device->AddRef();
*device = this->device;
return D3D_OK;
}
long Direct3DResource9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
privateData[guid] = PrivateData(data, size, flags == D3DSPD_IUNKNOWN);
return D3D_OK;
}
long Direct3DResource9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
CriticalSection cs(device);
TRACE("");
Iterator result = privateData.find(guid);
if(result == privateData.end())
{
return NOTFOUND();
}
if(result->second.size > *size)
{
return MOREDATA();
}
memcpy(data, result->second.data, result->second.size);
return D3D_OK;
}
long Direct3DResource9::FreePrivateData(const GUID &guid)
{
CriticalSection cs(device);
TRACE("");
Iterator result = privateData.find(guid);
if(result == privateData.end())
{
return D3DERR_NOTFOUND;
}
privateData.erase(guid);
return D3D_OK;
}
unsigned long Direct3DResource9::SetPriority(unsigned long newPriority)
{
CriticalSection cs(device);
TRACE("");
unsigned long oldPriority = priority;
priority = newPriority;
return oldPriority;
}
unsigned long Direct3DResource9::GetPriority()
{
CriticalSection cs(device);
TRACE("");
return priority;
}
void Direct3DResource9::PreLoad()
{
CriticalSection cs(device);
TRACE("");
}
D3DRESOURCETYPE Direct3DResource9::GetType()
{
CriticalSection cs(device);
TRACE("");
return type;
}
unsigned int Direct3DResource9::getMemoryUsage()
{
return memoryUsage;
}
D3DPOOL Direct3DResource9::getPool() const
{
return pool;
}
}
\ No newline at end of file
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DResource9_hpp
#define D3D9_Direct3DResource9_hpp
#include "Unknown.hpp"
#include <d3d9.h>
#include <map>
namespace D3D9
{
class Direct3DDevice9;
class Direct3DResource9 : public IDirect3DResource9, public Unknown
{
public:
Direct3DResource9(Direct3DDevice9 *device, D3DRESOURCETYPE type, D3DPOOL pool, unsigned int size);
virtual ~Direct3DResource9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource9 methods
long __stdcall GetDevice(IDirect3DDevice9 **device);
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
long __stdcall FreePrivateData(const GUID &guid);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
void __stdcall PreLoad();
D3DRESOURCETYPE __stdcall GetType();
// Internal methods
static unsigned int getMemoryUsage();
D3DPOOL getPool() const;
protected:
// Creation parameters
Direct3DDevice9 *const device;
const D3DRESOURCETYPE type;
const D3DPOOL pool;
const unsigned int size;
private:
unsigned long priority;
struct PrivateData
{
PrivateData();
PrivateData(const void *data, int size, bool managed);
~PrivateData();
PrivateData &operator=(const PrivateData &privateData);
void *data;
unsigned long size;
bool managed; // IUnknown interface
};
struct CompareGUID
{
bool operator()(const GUID& left, const GUID& right) const
{
return memcmp(&left, &right, sizeof(GUID)) < 0;
}
};
typedef std::map<GUID, PrivateData, CompareGUID> PrivateDataMap;
typedef PrivateDataMap::iterator Iterator;
PrivateDataMap privateData;
static unsigned int memoryUsage;
};
}
#endif // D3D9_Direct3DResource9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DStateBlock9_hpp
#define D3D9_Direct3DStateBlock9_hpp
#include "Unknown.hpp"
#include <vector>
#include <d3d9.h>
namespace D3D9
{
class Direct3DDevice9;
class Direct3DVertexDeclaration9;
class Direct3DIndexBuffer9;
class Direct3DVertexBuffer9;
class Direct3DBaseTexture9;
class Direct3DPixelShader9;
class Direct3DVertexShader9;
class Direct3DStateBlock9 : public IDirect3DStateBlock9, public Unknown
{
public:
Direct3DStateBlock9(Direct3DDevice9 *device, D3DSTATEBLOCKTYPE type);
virtual ~Direct3DStateBlock9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DStateBlock9 methods
long __stdcall Apply();
long __stdcall Capture();
long __stdcall GetDevice(IDirect3DDevice9 **device);
// Internal methods
void lightEnable(unsigned long index, int enable);
void setClipPlane(unsigned long index, const float *plane);
void setCurrentTexturePalette(unsigned int paletteNumber);
void setFVF(unsigned long FVF);
void setIndices(Direct3DIndexBuffer9 *indexData);
void setLight(unsigned long index, const D3DLIGHT9 *light);
void setMaterial(const D3DMATERIAL9 *material);
void setNPatchMode(float segments);
void setPixelShader(Direct3DPixelShader9 *shader);
void setPixelShaderConstantB(unsigned int startRegister, const int *constantData, unsigned int count);
void setPixelShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
void setPixelShaderConstantI(unsigned int startRegister, const int *constantData, unsigned int count);
void setRenderState(D3DRENDERSTATETYPE state, unsigned long value);
void setSamplerState(unsigned long index, D3DSAMPLERSTATETYPE state, unsigned long value);
void setScissorRect(const RECT *rect);
void setStreamSource(unsigned int stream, Direct3DVertexBuffer9 *data, unsigned int offset, unsigned int stride);
void setStreamSourceFreq(unsigned int streamNumber, unsigned int divider);
void setTexture(unsigned long index, Direct3DBaseTexture9 *texture);
void setTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long value);
void setTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix);
void setViewport(const D3DVIEWPORT9 *viewport);
void setVertexDeclaration(Direct3DVertexDeclaration9 *declaration);
void setVertexShader(Direct3DVertexShader9 *shader);
void setVertexShaderConstantB(unsigned int startRegister, const int *constantData, unsigned int count);
void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
void setVertexShaderConstantI(unsigned int startRegister, const int *constantData, unsigned int count);
private:
// Individual states
void captureRenderState(D3DRENDERSTATETYPE state);
void captureSamplerState(unsigned long index, D3DSAMPLERSTATETYPE state);
void captureTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type);
void captureTransform(D3DTRANSFORMSTATETYPE state);
// Pixel states
void capturePixelRenderStates();
void capturePixelTextureStates();
void capturePixelSamplerStates();
void capturePixelShaderStates();
// Vertex states
void captureVertexRenderStates();
void captureVertexSamplerStates();
void captureVertexTextureStates();
void captureNPatchMode();
void captureLightStates();
void captureVertexShaderStates();
void captureStreamSourceFrequencies();
void captureVertexDeclaration();
void captureFVF();
// All (remaining) states
void captureTextures();
void captureTexturePalette();
void captureVertexStreams();
void captureIndexBuffer();
void captureViewport();
void captureScissorRectangle();
void captureTransforms();
void captureTextureTransforms();
void captureClippingPlanes();
void captureMaterial();
// Creation parameters
Direct3DDevice9 *const device;
const D3DSTATEBLOCKTYPE type;
// State data
bool vertexDeclarationCaptured;
Direct3DVertexDeclaration9 *vertexDeclaration;
bool fvfCaptured;
unsigned long FVF;
bool indexBufferCaptured;
Direct3DIndexBuffer9 *indexBuffer;
bool renderStateCaptured[D3DRS_BLENDOPALPHA + 1];
unsigned long renderState[D3DRS_BLENDOPALPHA + 1];
bool nPatchModeCaptured;
float nPatchMode;
bool textureStageStateCaptured[8][D3DTSS_CONSTANT + 1];
unsigned long textureStageState[8][D3DTSS_CONSTANT + 1];
bool samplerStateCaptured[16 + 4][D3DSAMP_DMAPOFFSET + 1];
unsigned long samplerState[16 + 4][D3DSAMP_DMAPOFFSET + 1];
bool streamSourceCaptured[16];
struct StreamSource
{
Direct3DVertexBuffer9 *vertexBuffer;
unsigned int offset;
unsigned int stride;
};
StreamSource streamSource[16];
bool streamSourceFrequencyCaptured[16];
unsigned int streamSourceFrequency[16];
bool textureCaptured[16 + 4];
Direct3DBaseTexture9 *texture[16 + 4];
bool transformCaptured[512];
D3DMATRIX transform[512];
bool materialCaptured;
D3DMATERIAL9 material;
bool lightCaptured[8]; // FIXME: Unlimited index
D3DLIGHT9 light[8];
bool lightEnableCaptured[8]; // FIXME: Unlimited index
int lightEnableState[8];
bool pixelShaderCaptured;
Direct3DPixelShader9 *pixelShader;
bool vertexShaderCaptured;
Direct3DVertexShader9 *vertexShader;
bool viewportCaptured;
D3DVIEWPORT9 viewport;
float pixelShaderConstantF[224][4];
int pixelShaderConstantI[16][4];
int pixelShaderConstantB[16];
float vertexShaderConstantF[256][4];
int vertexShaderConstantI[16][4];
int vertexShaderConstantB[16];
bool clipPlaneCaptured[6];
float clipPlane[6][4];
bool scissorRectCaptured;
RECT scissorRect;
bool paletteNumberCaptured;
unsigned int paletteNumber;
void clear();
};
}
#endif // D3D9_Direct3DStateBlock9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DSurface9.hpp"
#include "Direct3DDevice9.hpp"
#include "Direct3DBaseTexture9.hpp"
#include "Capabilities.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <malloc.h>
#include <assert.h>
extern bool quadLayoutEnabled;
namespace D3D9
{
sw::Resource *getParentResource(Unknown *container)
{
Direct3DBaseTexture9 *baseTexture = dynamic_cast<Direct3DBaseTexture9*>(container);
if(baseTexture)
{
return baseTexture->getResource();
}
return 0;
}
int sampleCount(D3DMULTISAMPLE_TYPE multiSample, unsigned int quality)
{
if(multiSample == D3DMULTISAMPLE_NONMASKABLE)
{
switch(quality)
{
case 0: return 2;
case 1: return 4;
case 2: return 8;
case 3: return 16;
}
}
else if(multiSample == D3DMULTISAMPLE_2_SAMPLES)
{
return 2;
}
else if(multiSample == D3DMULTISAMPLE_4_SAMPLES)
{
return 4;
}
else if(multiSample == D3DMULTISAMPLE_8_SAMPLES)
{
return 8;
}
else if(multiSample == D3DMULTISAMPLE_16_SAMPLES)
{
return 16;
}
return 1;
}
bool isLockable(D3DPOOL pool, unsigned long usage, bool lockableOverride)
{
return (pool != D3DPOOL_DEFAULT) || (usage & D3DUSAGE_DYNAMIC) || lockableOverride;
}
Direct3DSurface9::Direct3DSurface9(Direct3DDevice9 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, unsigned int quality, bool lockableOverride, unsigned long usage) : Direct3DResource9(device, D3DRTYPE_SURFACE, pool, memoryUsage(width, height, format)), Surface(getParentResource(container), width, height, sampleCount(multiSample, quality), translateFormat(format), isLockable(pool, usage, lockableOverride), (usage & D3DUSAGE_RENDERTARGET) || (usage & D3DUSAGE_DEPTHSTENCIL)), container(container), width(width), height(height), format(format), pool(pool), multiSample(multiSample), quality(quality), lockable(isLockable(pool, usage, lockableOverride)), usage(usage)
{
parentTexture = dynamic_cast<Direct3DBaseTexture9*>(container);
}
Direct3DSurface9::~Direct3DSurface9()
{
}
long Direct3DSurface9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DSurface9 ||
iid == IID_IDirect3DResource9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DSurface9::AddRef()
{
TRACE("");
if(parentTexture)
{
return parentTexture->AddRef();
}
return Direct3DResource9::AddRef();
}
unsigned long Direct3DSurface9::Release()
{
TRACE("");
if(parentTexture)
{
return parentTexture->Release();
}
return Direct3DResource9::Release();
}
long Direct3DSurface9::FreePrivateData(const GUID &guid)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::FreePrivateData(guid);
}
long Direct3DSurface9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetPrivateData(guid, data, size);
}
void Direct3DSurface9::PreLoad()
{
CriticalSection cs(device);
TRACE("");
Direct3DResource9::PreLoad();
}
long Direct3DSurface9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::SetPrivateData(guid, data, size, flags);
}
long Direct3DSurface9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
return Direct3DResource9::GetDevice(device);
}
unsigned long Direct3DSurface9::SetPriority(unsigned long newPriority)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::SetPriority(newPriority);
}
unsigned long Direct3DSurface9::GetPriority()
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetPriority();
}
D3DRESOURCETYPE Direct3DSurface9::GetType()
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetType();
}
long Direct3DSurface9::GetDC(HDC *deviceContext)
{
CriticalSection cs(device);
TRACE("");
if(!deviceContext)
{
return INVALIDCALL();
}
UNIMPLEMENTED();
return D3D_OK;
}
long Direct3DSurface9::ReleaseDC(HDC deviceContext)
{
CriticalSection cs(device);
TRACE("");
UNIMPLEMENTED();
return D3D_OK;
}
long Direct3DSurface9::LockRect(D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
{
CriticalSection cs(device);
TRACE("D3DLOCKED_RECT *lockedRect = 0x%0.8p, const RECT *rect = 0x%0.8p, unsigned long flags = %d", lockedRect, rect, flags);
if(!lockedRect)
{
return INVALIDCALL();
}
lockedRect->Pitch = 0;
lockedRect->pBits = 0;
if(!lockable)
{
return INVALIDCALL();
}
lockedRect->Pitch = getExternalPitchB();
sw::Lock lock = sw::LOCK_READWRITE;
if(flags & D3DLOCK_DISCARD)
{
lock = sw::LOCK_DISCARD;
}
if(flags & D3DLOCK_READONLY)
{
lock = sw::LOCK_READONLY;
}
if(rect)
{
lockedRect->pBits = lockExternal(rect->left, rect->top, 0, lock, sw::PUBLIC);
}
else
{
lockedRect->pBits = lockExternal(0, 0, 0, lock, sw::PUBLIC);
}
return D3D_OK;
}
long Direct3DSurface9::UnlockRect()
{
CriticalSection cs(device);
TRACE("");
unlockExternal();
return D3D_OK;
}
long Direct3DSurface9::GetContainer(const IID &iid, void **container)
{
CriticalSection cs(device);
TRACE("");
if(!container)
{
return INVALIDCALL();
}
long result = this->container->QueryInterface(iid, container);
if(result == S_OK)
{
return D3D_OK;
}
return INVALIDCALL();
}
long Direct3DSurface9::GetDesc(D3DSURFACE_DESC *description)
{
CriticalSection cs(device);
TRACE("");
if(!description)
{
return INVALIDCALL();
}
description->Format = format;
description->Pool = pool;
description->Type = D3DRTYPE_SURFACE;
description->Height = height;
description->Width = width;
description->MultiSampleType = multiSample;
description->MultiSampleQuality = quality;
description->Usage = usage;
return D3D_OK;
}
sw::Format Direct3DSurface9::translateFormat(D3DFORMAT format)
{
switch(format)
{
#if S3TC_SUPPORT
case D3DFMT_NULL: return sw::FORMAT_NULL;
case D3DFMT_DXT1: return sw::FORMAT_DXT1;
case D3DFMT_DXT2: return sw::FORMAT_DXT3;
case D3DFMT_DXT3: return sw::FORMAT_DXT3;
case D3DFMT_DXT4: return sw::FORMAT_DXT5;
case D3DFMT_DXT5: return sw::FORMAT_DXT5;
case D3DFMT_ATI1: return sw::FORMAT_ATI1;
case D3DFMT_ATI2: return sw::FORMAT_ATI2;
#endif
case D3DFMT_R3G3B2: return sw::FORMAT_R3G3B2;
case D3DFMT_A8R3G3B2: return sw::FORMAT_A8R3G3B2;
case D3DFMT_X4R4G4B4: return sw::FORMAT_X4R4G4B4;
case D3DFMT_A4R4G4B4: return sw::FORMAT_A4R4G4B4;
case D3DFMT_A8R8G8B8: return sw::FORMAT_A8R8G8B8;
case D3DFMT_A8B8G8R8: return sw::FORMAT_A8B8G8R8;
case D3DFMT_G16R16: return sw::FORMAT_G16R16;
case D3DFMT_A2R10G10B10: return sw::FORMAT_A2R10G10B10;
case D3DFMT_A2B10G10R10: return sw::FORMAT_A2B10G10R10;
case D3DFMT_A16B16G16R16: return sw::FORMAT_A16B16G16R16;
case D3DFMT_P8: return sw::FORMAT_P8;
case D3DFMT_A8P8: return sw::FORMAT_A8P8;
case D3DFMT_A8: return sw::FORMAT_A8;
case D3DFMT_R5G6B5: return sw::FORMAT_R5G6B5;
case D3DFMT_X1R5G5B5: return sw::FORMAT_X1R5G5B5;
case D3DFMT_A1R5G5B5: return sw::FORMAT_A1R5G5B5;
case D3DFMT_R8G8B8: return sw::FORMAT_R8G8B8;
case D3DFMT_X8R8G8B8: return sw::FORMAT_X8R8G8B8;
case D3DFMT_X8B8G8R8: return sw::FORMAT_X8B8G8R8;
case D3DFMT_V8U8: return sw::FORMAT_V8U8;
case D3DFMT_L6V5U5: return sw::FORMAT_L6V5U5;
case D3DFMT_Q8W8V8U8: return sw::FORMAT_Q8W8V8U8;
case D3DFMT_X8L8V8U8: return sw::FORMAT_X8L8V8U8;
case D3DFMT_A2W10V10U10: return sw::FORMAT_A2W10V10U10;
case D3DFMT_V16U16: return sw::FORMAT_V16U16;
case D3DFMT_Q16W16V16U16: return sw::FORMAT_Q16W16V16U16;
case D3DFMT_L8: return sw::FORMAT_L8;
case D3DFMT_A4L4: return sw::FORMAT_A4L4;
case D3DFMT_L16: return sw::FORMAT_L16;
case D3DFMT_A8L8: return sw::FORMAT_A8L8;
case D3DFMT_R16F: return sw::FORMAT_R16F;
case D3DFMT_G16R16F: return sw::FORMAT_G16R16F;
case D3DFMT_A16B16G16R16F: return sw::FORMAT_A16B16G16R16F;
case D3DFMT_R32F: return sw::FORMAT_R32F;
case D3DFMT_G32R32F: return sw::FORMAT_G32R32F;
case D3DFMT_A32B32G32R32F: return sw::FORMAT_A32B32G32R32F;
case D3DFMT_D16: return sw::FORMAT_D16;
case D3DFMT_D32: return sw::FORMAT_D32;
case D3DFMT_D24X8: return sw::FORMAT_D24X8;
case D3DFMT_D24S8: return sw::FORMAT_D24S8;
case D3DFMT_D24FS8: return sw::FORMAT_D24FS8;
case D3DFMT_D32F_LOCKABLE: return sw::FORMAT_D32F_LOCKABLE;
case D3DFMT_DF24: return sw::FORMAT_DF24;
case D3DFMT_DF16: return sw::FORMAT_DF16;
case D3DFMT_INTZ: return sw::FORMAT_INTZ;
default:
ASSERT(false);
}
return sw::FORMAT_NULL;
}
int Direct3DSurface9::bytes(D3DFORMAT format)
{
return Surface::bytes(translateFormat(format));
}
unsigned int Direct3DSurface9::memoryUsage(int width, int height, D3DFORMAT format)
{
return Surface::size(width, height, 1, translateFormat(format));
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DSurface9_hpp
#define D3D9_Direct3DSurface9_hpp
#include "Direct3DResource9.hpp"
#include "Surface.hpp"
#include <d3d9.h>
namespace D3D9
{
class Direct3DBaseTexture9;
class Direct3DSurface9 : public IDirect3DSurface9, public Direct3DResource9, public sw::Surface
{
public:
Direct3DSurface9(Direct3DDevice9 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, unsigned int quality, bool lockableOverride, unsigned long usage);
virtual ~Direct3DSurface9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource9 methods
long __stdcall FreePrivateData(const GUID &guid);
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
void __stdcall PreLoad();
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
long __stdcall GetDevice(IDirect3DDevice9 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DSurface9 methods
long __stdcall GetDC(HDC *deviceContext);
long __stdcall ReleaseDC(HDC deviceContext);
long __stdcall LockRect(D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long Flags);
long __stdcall UnlockRect();
long __stdcall GetContainer(const IID &iid, void **container);
long __stdcall GetDesc(D3DSURFACE_DESC *desc);
// Internal methods
static sw::Format translateFormat(D3DFORMAT format);
static int bytes(D3DFORMAT format);
private:
static unsigned int memoryUsage(int width, int height, D3DFORMAT format);
// Creation parameters
Unknown *const container;
const int width;
const int height;
const D3DFORMAT format;
const D3DMULTISAMPLE_TYPE multiSample;
const unsigned int quality;
const D3DPOOL pool;
const bool lockable;
const unsigned long usage;
Direct3DBaseTexture9 *parentTexture;
};
}
#endif // D3D9_Direct3DSurface9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DSwapChain9.hpp"
#include "Direct3DDevice9.hpp"
#include "Renderer.hpp"
#include "Timer.hpp"
#include "Resource.hpp"
#include "Configurator.hpp"
#include "Debug.hpp"
#include "FrameBufferDD.hpp"
#include "FrameBufferGDI.hpp"
namespace D3D9
{
Direct3DSwapChain9::Direct3DSwapChain9(Direct3DDevice9 *device, D3DPRESENT_PARAMETERS *presentParameters) : device(device), presentParameters(*presentParameters)
{
frameBuffer = 0;
for(int i = 0; i < 3; i++)
{
backBuffer[i] = 0;
}
reset(presentParameters);
}
Direct3DSwapChain9::~Direct3DSwapChain9()
{
release();
}
long Direct3DSwapChain9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DSwapChain9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DSwapChain9::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DSwapChain9::Release()
{
TRACE("");
return Unknown::Release();
}
long Direct3DSwapChain9::Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
#if PERF_PROFILE
profiler.nextFrame();
#endif
#if PERF_HUD
sw::Renderer *renderer = device->renderer;
static int64_t frame = sw::Timer::ticks();
int64_t frameTime = sw::Timer::ticks() - frame;
frame = sw::Timer::ticks();
if(frameTime > 0)
{
unsigned int *frameBuffer = (unsigned int*)lockBackBuffer(0); // FIXME: Don't assume A8R8G8B8 mode
unsigned int stride = backBuffer[0]->getInternalPitchP();
int thread;
for(thread = 0; thread < renderer->getThreadCount(); thread++)
{
int64_t drawTime = renderer->getVertexTime(thread) + renderer->getSetupTime(thread) + renderer->getPixelTime(thread);
int vertexPercentage = sw::clamp((int)(100 * renderer->getVertexTime(thread) / frameTime), 0, 100);
int setupPercentage = sw::clamp((int)(100 * renderer->getSetupTime(thread) / frameTime), 0, 100);
int pixelPercentage = sw::clamp((int)(100 * renderer->getPixelTime(thread) / frameTime), 0, 100);
for(int i = 0; i < 100; i++)
{
frameBuffer[thread * stride + i] = 0x00000000;
}
unsigned int *buffer = frameBuffer;
for(int i = 0; i < vertexPercentage; i++)
{
buffer[thread * stride] = 0x000000FF;
buffer++;
}
for(int i = 0; i < setupPercentage; i++)
{
buffer[thread * stride] = 0x0000FF00;
buffer++;
}
for(int i = 0; i < pixelPercentage; i++)
{
buffer[thread * stride] = 0x00FF0000;
buffer++;
}
frameBuffer[thread * stride + 100] = 0x00FFFFFF;
}
for(int i = 0; i <= 100; i++)
{
frameBuffer[thread * stride + i] = 0x00FFFFFF;
}
unlockBackBuffer(0);
}
renderer->resetTimers();
#endif
HWND window = destWindowOverride ? destWindowOverride : presentParameters.hDeviceWindow;
void *source = backBuffer[0]->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); // FIXME: External
bool HDR = backBuffer[0]->getInternalFormat() == sw::FORMAT_A16B16G16R16;
POINT point;
GetCursorPos(&point);
ScreenToClient(window, &point);
frameBuffer->setCursorPosition(point.x, point.y);
if(!sourceRect && !destRect) // FIXME: More cases?
{
frameBuffer->flip(window, source, HDR);
}
else // FIXME: Check for SWAPEFFECT_COPY
{
sw::Rect sRect = {0};
sw::Rect dRect = {0};
if(sourceRect)
{
sRect.left = sourceRect->left;
sRect.top = sourceRect->top;
sRect.right = sourceRect->right;
sRect.bottom = sourceRect->bottom;
}
if(destRect)
{
dRect.left = destRect->left;
dRect.top = destRect->top;
dRect.right = destRect->right;
dRect.bottom = destRect->bottom;
}
frameBuffer->blit(window, source, sourceRect ? &sRect : 0, destRect ? &dRect : 0, HDR);
}
backBuffer[0]->unlockInternal(); // FIXME: External
return D3D_OK;
}
long Direct3DSwapChain9::GetFrontBufferData(IDirect3DSurface9 *destSurface)
{
CriticalSection cs(device);
TRACE("");
if(!destSurface)
{
return INVALIDCALL();
}
sw::Surface *dest = static_cast<Direct3DSurface9*>(destSurface);
void *buffer = dest->lockExternal(0, 0, 0, sw::LOCK_WRITEONLY, sw::PRIVATE);
frameBuffer->screenshot(buffer);
dest->unlockExternal();
return D3D_OK;
}
long Direct3DSwapChain9::GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface9 **backBuffer)
{
CriticalSection cs(device);
TRACE("");
if(!backBuffer/* || type != D3DBACKBUFFER_TYPE_MONO*/)
{
return INVALIDCALL();
}
*backBuffer = 0;
if(index >= 3 || this->backBuffer[index] == 0)
{
return INVALIDCALL();
}
*backBuffer = this->backBuffer[index];
this->backBuffer[index]->AddRef();
return D3D_OK;
}
long Direct3DSwapChain9::GetRasterStatus(D3DRASTER_STATUS *rasterStatus)
{
CriticalSection cs(device);
TRACE("");
if(!rasterStatus)
{
return INVALIDCALL();
}
bool inVerticalBlank;
unsigned int scanline;
bool supported = frameBuffer->getScanline(inVerticalBlank, scanline);
if(supported)
{
rasterStatus->InVBlank = inVerticalBlank;
rasterStatus->ScanLine = scanline;
}
else
{
return INVALIDCALL();
}
return D3D_OK;
}
long Direct3DSwapChain9::GetDisplayMode(D3DDISPLAYMODE *displayMode)
{
CriticalSection cs(device);
TRACE("");
if(!displayMode)
{
return INVALIDCALL();
}
device->getAdapterDisplayMode(D3DADAPTER_DEFAULT, displayMode);
return D3D_OK;
}
long Direct3DSwapChain9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
if(!device)
{
return INVALIDCALL();
}
this->device->AddRef();
*device = this->device;
return D3D_OK;
}
long Direct3DSwapChain9::GetPresentParameters(D3DPRESENT_PARAMETERS *presentParameters)
{
CriticalSection cs(device);
TRACE("");
if(!presentParameters)
{
return INVALIDCALL();
}
*presentParameters = this->presentParameters;
return D3D_OK;
}
void Direct3DSwapChain9::reset(D3DPRESENT_PARAMETERS *presentParameters)
{
release();
ASSERT(presentParameters->BackBufferCount <= 3); // Maximum of three back buffers
if(presentParameters->BackBufferCount == 0)
{
presentParameters->BackBufferCount = 1;
}
if(presentParameters->BackBufferFormat == D3DFMT_UNKNOWN)
{
D3DDISPLAYMODE displayMode;
GetDisplayMode(&displayMode);
presentParameters->BackBufferFormat = displayMode.Format;
}
D3DDEVICE_CREATION_PARAMETERS creationParameters;
device->GetCreationParameters(&creationParameters);
HWND windowHandle = presentParameters->hDeviceWindow ? presentParameters->hDeviceWindow : creationParameters.hFocusWindow;
if(presentParameters->Windowed && (presentParameters->BackBufferHeight == 0 || presentParameters->BackBufferWidth == 0))
{
RECT rectangle;
GetClientRect(windowHandle, &rectangle);
presentParameters->BackBufferWidth = rectangle.right - rectangle.left;
presentParameters->BackBufferHeight = rectangle.bottom - rectangle.top;
}
lockable = presentParameters->Flags & D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
sw::Configurator ini("SwiftShader.ini");
int api = ini.getInteger("Testing", "FrameBufferAPI", 1);
if(api == 0)
{
frameBuffer = new sw::FrameBufferDD(windowHandle, presentParameters->BackBufferWidth, presentParameters->BackBufferHeight, presentParameters->Windowed == FALSE);
}
else if(api == 1)
{
frameBuffer = new sw::FrameBufferGDI(windowHandle, presentParameters->BackBufferWidth, presentParameters->BackBufferHeight, presentParameters->Windowed == FALSE);
}
else ASSERT(false);
backBuffer[0] = 0;
backBuffer[1] = 0;
backBuffer[2] = 0;
for(int i = 0; i < (int)presentParameters->BackBufferCount; i++)
{
backBuffer[i] = new Direct3DSurface9(device, this, presentParameters->BackBufferWidth, presentParameters->BackBufferHeight, presentParameters->BackBufferFormat, D3DPOOL_DEFAULT, presentParameters->MultiSampleType, presentParameters->MultiSampleQuality, lockable, D3DUSAGE_RENDERTARGET);
backBuffer[i]->bind();
}
this->presentParameters = *presentParameters;
}
void Direct3DSwapChain9::release()
{
delete frameBuffer;
frameBuffer = 0;
for(int i = 0; i < 3; i++)
{
if(backBuffer[i])
{
backBuffer[i]->unbind();
backBuffer[i] = 0;
}
}
}
void Direct3DSwapChain9::setGammaRamp(sw::GammaRamp *gammaRamp, bool calibrate)
{
frameBuffer->setGammaRamp(gammaRamp, calibrate);
}
void Direct3DSwapChain9::getGammaRamp(sw::GammaRamp *gammaRamp)
{
frameBuffer->getGammaRamp(gammaRamp);
}
void *Direct3DSwapChain9::lockBackBuffer(int index)
{
return backBuffer[index]->lockInternal(0, 0, 0, sw::LOCK_READWRITE, sw::PUBLIC); // FIXME: External
}
void Direct3DSwapChain9::unlockBackBuffer(int index)
{
backBuffer[index]->unlockInternal(); // FIXME: External
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DSwapChain9_hpp
#define D3D9_Direct3DSwapChain9_hpp
#include "Unknown.hpp"
#include "Direct3DSurface9.hpp"
#include "FrameBuffer.hpp"
#include <d3d9.h>
namespace D3D9
{
class Direct3DDevice9;
class Direct3DSwapChain9 : public IDirect3DSwapChain9, public Unknown
{
public:
Direct3DSwapChain9(Direct3DDevice9 *device, D3DPRESENT_PARAMETERS *presentParameters);
virtual ~Direct3DSwapChain9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DSwapChain9 methods
long __stdcall Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion, unsigned long flags);
long __stdcall GetFrontBufferData(IDirect3DSurface9 *destSurface);
long __stdcall GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface9 **backBuffer);
long __stdcall GetRasterStatus(D3DRASTER_STATUS *rasterStatus);
long __stdcall GetDisplayMode(D3DDISPLAYMODE *displayMode);
long __stdcall GetDevice(IDirect3DDevice9 **device);
long __stdcall GetPresentParameters(D3DPRESENT_PARAMETERS *presentParameters);
// Internal methods
void reset(D3DPRESENT_PARAMETERS *presentParameters);
void setGammaRamp(sw::GammaRamp *gammaRamp, bool calibrate);
void getGammaRamp(sw::GammaRamp *gammaRamp);
void *lockBackBuffer(int index);
void unlockBackBuffer(int index);
private:
void release();
// Creation parameters
Direct3DDevice9 *const device;
D3DPRESENT_PARAMETERS presentParameters;
bool lockable;
sw::FrameBuffer *frameBuffer;
public: // FIXME
Direct3DSurface9 *backBuffer[3];
};
}
#endif // D3D9_Direct3DSwapChain9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DTexture9.hpp"
#include "Direct3DDevice9.hpp"
#include "Direct3DSurface9.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D9
{
Direct3DTexture9::Direct3DTexture9(Direct3DDevice9 *device, unsigned int width, unsigned int height, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture9(device, D3DRTYPE_TEXTURE, format, pool, levels, usage), width(width), height(height)
{
if(levels == 0)
{
this->levels = sw::log2(sw::max((int)width, (int)height, 1)) + 1;
}
for(unsigned int level = 0; level < MIPMAP_LEVELS; level++)
{
if(level < this->levels)
{
surfaceLevel[level] = new Direct3DSurface9(device, this, width, height, format, pool, D3DMULTISAMPLE_NONE, 0, false, usage);
surfaceLevel[level]->bind();
}
else
{
surfaceLevel[level] = 0;
}
width = sw::max(1, (int)width / 2);
height = sw::max(1, (int)height / 2);
}
}
Direct3DTexture9::~Direct3DTexture9()
{
resource->lock(sw::DESTRUCT);
for(int level = 0; level < MIPMAP_LEVELS; level++)
{
if(surfaceLevel[level])
{
surfaceLevel[level]->unbind();
surfaceLevel[level] = 0;
}
}
resource->unlock();
}
long Direct3DTexture9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DTexture9 ||
iid == IID_IDirect3DBaseTexture9 ||
iid == IID_IDirect3DResource9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DTexture9::AddRef()
{
TRACE("");
return Direct3DBaseTexture9::AddRef();
}
unsigned long Direct3DTexture9::Release()
{
TRACE("");
return Direct3DBaseTexture9::Release();
}
long Direct3DTexture9::FreePrivateData(const GUID &guid)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::FreePrivateData(guid);
}
long Direct3DTexture9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetPrivateData(guid, data, size);
}
void Direct3DTexture9::PreLoad()
{
CriticalSection cs(device);
TRACE("");
Direct3DBaseTexture9::PreLoad();
}
long Direct3DTexture9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::SetPrivateData(guid, data, size, flags);
}
long Direct3DTexture9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("IDirect3DDevice9 **device = 0x%0.8p", device);
return Direct3DBaseTexture9::GetDevice(device);
}
unsigned long Direct3DTexture9::SetPriority(unsigned long newPriority)
{
CriticalSection cs(device);
TRACE("unsigned long newPriority = %d", newPriority);
return Direct3DBaseTexture9::SetPriority(newPriority);
}
unsigned long Direct3DTexture9::GetPriority()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetPriority();
}
D3DRESOURCETYPE Direct3DTexture9::GetType()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetType();
}
void Direct3DTexture9::GenerateMipSubLevels()
{
CriticalSection cs(device);
TRACE("");
if(!(usage & D3DUSAGE_AUTOGENMIPMAP) || !surfaceLevel[0]->hasDirtyMipmaps())
{
return;
}
resource->lock(sw::PUBLIC);
for(unsigned int i = 0; i < levels - 1; i++)
{
device->stretchRect(surfaceLevel[i], 0, surfaceLevel[i + 1], 0, GetAutoGenFilterType());
}
surfaceLevel[0]->cleanMipmaps();
resource->unlock();
}
D3DTEXTUREFILTERTYPE Direct3DTexture9::GetAutoGenFilterType()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetAutoGenFilterType();
}
unsigned long Direct3DTexture9::GetLevelCount()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetLevelCount();
}
unsigned long Direct3DTexture9::GetLOD()
{
CriticalSection cs(device);
TRACE("");
return Direct3DBaseTexture9::GetLOD();
}
long Direct3DTexture9::SetAutoGenFilterType(D3DTEXTUREFILTERTYPE filterType)
{
CriticalSection cs(device);
TRACE("D3DTEXTUREFILTERTYPE filterType = %d", filterType);
return Direct3DBaseTexture9::SetAutoGenFilterType(filterType);
}
unsigned long Direct3DTexture9::SetLOD(unsigned long newLOD)
{
CriticalSection cs(device);
TRACE("unsigned long newLOD = %d", newLOD);
return Direct3DBaseTexture9::SetLOD(newLOD);
}
long Direct3DTexture9::GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description)
{
CriticalSection cs(device);
TRACE("unsigned int level = %d, D3DSURFACE_DESC *description = 0x%0.8p", level, description);
if(!description || level >= GetLevelCount() || !surfaceLevel[level])
{
return INVALIDCALL();
}
return surfaceLevel[level]->GetDesc(description);
}
long Direct3DTexture9::LockRect(unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
{
CriticalSection cs(device);
TRACE("unsigned int level = %d, D3DLOCKED_RECT *lockedRect = 0x%0.8p, const RECT *rect = 0x%0.8p, unsigned long flags = %d", level, lockedRect, rect, flags);
if(!lockedRect || level >= GetLevelCount() || !surfaceLevel[level])
{
return INVALIDCALL();
}
return surfaceLevel[level]->LockRect(lockedRect, rect, flags);
}
long Direct3DTexture9::GetSurfaceLevel(unsigned int level, IDirect3DSurface9 **surface)
{
CriticalSection cs(device);
TRACE("unsigned int level = %d, IDirect3DSurface9 **surface = 0x%0.8p", level, surface);
*surface = 0;
if(level >= GetLevelCount() || !surfaceLevel[level])
{
return INVALIDCALL();
}
surfaceLevel[level]->AddRef();
*surface = surfaceLevel[level];
return D3D_OK;
}
long Direct3DTexture9::UnlockRect(unsigned int level)
{
CriticalSection cs(device);
TRACE("unsigned int level = %d", level);
if(level >= GetLevelCount() || !surfaceLevel[level])
{
return INVALIDCALL();
}
return surfaceLevel[level]->UnlockRect();
}
long Direct3DTexture9::AddDirtyRect(const RECT *dirtyRect)
{
CriticalSection cs(device);
TRACE("");
// UNIMPLEMENTED();
return D3D_OK;
}
Direct3DSurface9 *Direct3DTexture9::getInternalSurfaceLevel(unsigned int level)
{
return surfaceLevel[level];
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DTexture9_hpp
#define D3D9_Direct3DTexture9_hpp
#include "Direct3DBaseTexture9.hpp"
#include "Config.hpp"
#include <d3d9.h>
namespace D3D9
{
class Direct3DSurface9;
class Direct3DTexture9 : public IDirect3DTexture9, public Direct3DBaseTexture9
{
public:
Direct3DTexture9(Direct3DDevice9 *device, unsigned int width, unsigned int height, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
virtual ~Direct3DTexture9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource9 methods
long __stdcall GetDevice(IDirect3DDevice9 **device);
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
long __stdcall FreePrivateData(const GUID &guid);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
void __stdcall PreLoad();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DBaseTexture9 methods
unsigned long __stdcall SetLOD(unsigned long newLOD);
unsigned long __stdcall GetLOD();
unsigned long __stdcall GetLevelCount();
long __stdcall SetAutoGenFilterType(D3DTEXTUREFILTERTYPE filterType);
D3DTEXTUREFILTERTYPE __stdcall GetAutoGenFilterType();
void __stdcall GenerateMipSubLevels();
// IDirect3DTexture9 methods
long __stdcall GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description);
long __stdcall GetSurfaceLevel(unsigned int level, IDirect3DSurface9 **surface);
long __stdcall LockRect(unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags);
long __stdcall UnlockRect(unsigned int level);
long __stdcall AddDirtyRect(const RECT *dirtyRect);
// Internal methods
Direct3DSurface9 *getInternalSurfaceLevel(unsigned int level);
private:
// Creation parameters
const unsigned int width;
const unsigned int height;
Direct3DSurface9 *surfaceLevel[MIPMAP_LEVELS];
};
}
#endif // D3D9_Direct3DTexture9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DVertexBuffer9.hpp"
#include "Direct3DDevice9.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D9
{
Direct3DVertexBuffer9::Direct3DVertexBuffer9(Direct3DDevice9 *device, unsigned int length, unsigned long usage, long FVF, D3DPOOL pool) : Direct3DResource9(device, D3DRTYPE_VERTEXBUFFER, pool, length), length(length), usage(usage), FVF(FVF)
{
if(FVF)
{
unsigned int stride = 0;
switch(FVF & D3DFVF_POSITION_MASK)
{
case D3DFVF_XYZ: stride += 12; break;
case D3DFVF_XYZRHW: stride += 16; break;
case D3DFVF_XYZB1: stride += 16; break;
case D3DFVF_XYZB2: stride += 20; break;
case D3DFVF_XYZB3: stride += 24; break;
case D3DFVF_XYZB4: stride += 28; break;
case D3DFVF_XYZB5: stride += 32; break;
case D3DFVF_XYZW: stride += 16; break;
}
if(FVF & D3DFVF_NORMAL) stride += 12;
if(FVF & D3DFVF_PSIZE) stride += 4;
if(FVF & D3DFVF_DIFFUSE) stride += 4;
if(FVF & D3DFVF_SPECULAR) stride += 4;
switch((FVF & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT)
{
case 8: stride += 4 + 4 * ((1 + (FVF >> 30)) % 4);
case 7: stride += 4 + 4 * ((1 + (FVF >> 28)) % 4);
case 6: stride += 4 + 4 * ((1 + (FVF >> 26)) % 4);
case 5: stride += 4 + 4 * ((1 + (FVF >> 24)) % 4);
case 4: stride += 4 + 4 * ((1 + (FVF >> 22)) % 4);
case 3: stride += 4 + 4 * ((1 + (FVF >> 20)) % 4);
case 2: stride += 4 + 4 * ((1 + (FVF >> 18)) % 4);
case 1: stride += 4 + 4 * ((1 + (FVF >> 16)) % 4);
case 0: break;
default:
ASSERT(false);
}
ASSERT(length >= stride); // FIXME
}
vertexBuffer = new sw::Resource(length + 192 + 1024); // NOTE: Applications can 'overshoot' while writing vertices
lockCount = 0;
}
Direct3DVertexBuffer9::~Direct3DVertexBuffer9()
{
vertexBuffer->destruct();
}
long Direct3DVertexBuffer9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DVertexBuffer9 ||
iid == IID_IDirect3DResource9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DVertexBuffer9::AddRef()
{
TRACE("");
return Direct3DResource9::AddRef();
}
unsigned long Direct3DVertexBuffer9::Release()
{
TRACE("");
return Direct3DResource9::Release();
}
long Direct3DVertexBuffer9::FreePrivateData(const GUID &guid)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::FreePrivateData(guid);
}
long Direct3DVertexBuffer9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetPrivateData(guid, data, size);
}
void Direct3DVertexBuffer9::PreLoad()
{
CriticalSection cs(device);
TRACE("");
Direct3DResource9::PreLoad();
}
long Direct3DVertexBuffer9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::SetPrivateData(guid, data, size, flags);
}
long Direct3DVertexBuffer9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
return Direct3DResource9::GetDevice(device);
}
unsigned long Direct3DVertexBuffer9::SetPriority(unsigned long newPriority)
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::SetPriority(newPriority);
}
unsigned long Direct3DVertexBuffer9::GetPriority()
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetPriority();
}
D3DRESOURCETYPE Direct3DVertexBuffer9::GetType()
{
CriticalSection cs(device);
TRACE("");
return Direct3DResource9::GetType();
}
long Direct3DVertexBuffer9::Lock(unsigned int offset, unsigned int size, void **data, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
if(offset == 0 && size == 0) // Lock whole buffer
{
size = length;
}
if(!data || offset + size > length)
{
return INVALIDCALL();
}
void *buffer;
if(flags & D3DLOCK_DISCARD/* && usage & D3DUSAGE_DYNAMIC*/)
{
vertexBuffer->destruct();
vertexBuffer = new sw::Resource(length + 192 + 1024); // NOTE: Applications can 'overshoot' while writing vertices
buffer = (void*)vertexBuffer->getBuffer();
}
else if(flags & D3DLOCK_NOOVERWRITE/* && usage & D3DUSAGE_DYNAMIC*/)
{
buffer = (void*)vertexBuffer->getBuffer();
}
else
{
buffer = vertexBuffer->lock(sw::PUBLIC);
lockCount++;
}
*data = (unsigned char*)buffer + offset;
return D3D_OK;
}
long Direct3DVertexBuffer9::Unlock()
{
CriticalSection cs(device);
TRACE("");
if(lockCount > 0)
{
vertexBuffer->unlock();
lockCount--;
}
return D3D_OK;
}
long Direct3DVertexBuffer9::GetDesc(D3DVERTEXBUFFER_DESC *description)
{
CriticalSection cs(device);
TRACE("");
if(!description)
{
return INVALIDCALL();
}
description->FVF = FVF;
description->Format = D3DFMT_VERTEXDATA;
description->Pool = pool;
description->Size = length;
description->Type = D3DRTYPE_VERTEXBUFFER;
description->Usage = usage;
return D3D_OK;
}
int Direct3DVertexBuffer9::getLength() const
{
return length;
}
sw::Resource *Direct3DVertexBuffer9::getResource() const
{
return vertexBuffer;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DVertexBuffer9_hpp
#define D3D9_Direct3DVertexBuffer9_hpp
#include "Direct3DResource9.hpp"
#include <d3d9.h>
namespace sw
{
class Resource;
}
namespace D3D9
{
class Direct3DVertexBuffer9 : public IDirect3DVertexBuffer9, public Direct3DResource9
{
public:
Direct3DVertexBuffer9(Direct3DDevice9 *device, unsigned int length, unsigned long usage, long FVF, D3DPOOL pool);
virtual ~Direct3DVertexBuffer9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource9 methods
long __stdcall FreePrivateData(const GUID &guid);
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
void __stdcall PreLoad();
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
long __stdcall GetDevice(IDirect3DDevice9 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DVertexBuffer9 methods
long __stdcall Lock(unsigned int offset, unsigned int size, void **data, unsigned long flags);
long __stdcall Unlock();
long __stdcall GetDesc(D3DVERTEXBUFFER_DESC *description);
// Internal methods
int getLength() const;
sw::Resource *getResource() const;
private:
// Creation parameters
const unsigned int length;
const long usage;
const long FVF;
sw::Resource *vertexBuffer;
int lockCount;
};
}
#endif // D3D9_Direct3DVertexBuffer9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DVertexDeclaration9_hpp
#define D3D9_Direct3DVertexDeclaration9_hpp
#include "Unknown.hpp"
#include <d3d9.h>
namespace D3D9
{
class Direct3DDevice9;
class Direct3DVertexDeclaration9 : public IDirect3DVertexDeclaration9, public Unknown
{
public:
Direct3DVertexDeclaration9(Direct3DDevice9 *device, const D3DVERTEXELEMENT9 *vertexElements);
Direct3DVertexDeclaration9(Direct3DDevice9 *device, unsigned long FVF);
virtual ~Direct3DVertexDeclaration9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DVertexDeclaration9 methods
long __stdcall GetDevice(IDirect3DDevice9 **device);
long __stdcall GetDeclaration(D3DVERTEXELEMENT9 *declaration, unsigned int *numElements);
// Internal methods
unsigned long getFVF() const;
bool isPreTransformed() const;
private:
unsigned long computeFVF(); // If equivalent to FVF, else 0
// Creation parameters
Direct3DDevice9 *const device;
D3DVERTEXELEMENT9 *vertexElement;
int numElements;
unsigned long FVF;
bool preTransformed;
};
}
#endif // D3D9_Direct3DVertexDeclaration9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DVertexShader9.hpp"
#include "Direct3DDevice9.hpp"
#include "Debug.hpp"
namespace D3D9
{
Direct3DVertexShader9::Direct3DVertexShader9(Direct3DDevice9 *device, const unsigned long *shaderToken) : device(device), vertexShader(shaderToken)
{
}
Direct3DVertexShader9::~Direct3DVertexShader9()
{
}
long Direct3DVertexShader9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DVertexShader9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DVertexShader9::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DVertexShader9::Release()
{
TRACE("");
return Unknown::Release();
}
long Direct3DVertexShader9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
if(!device)
{
return INVALIDCALL();
}
this->device->AddRef();
*device = this->device;
return D3D_OK;
}
long Direct3DVertexShader9::GetFunction(void *data, unsigned int *size)
{
CriticalSection cs(device);
TRACE("");
if(!size)
{
return INVALIDCALL();
}
vertexShader.getFunction(data, size);
return D3D_OK;
}
const sw::VertexShader *Direct3DVertexShader9::getVertexShader() const
{
return &vertexShader;
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef D3D9_Direct3DVertexShader9_hpp
#define D3D9_Direct3DVertexShader9_hpp
#include "Unknown.hpp"
#include "VertexShader.hpp"
#include <d3d9.h>
namespace D3D9
{
class Direct3DDevice9;
class Direct3DVertexShader9 : public IDirect3DVertexShader9, public Unknown
{
public:
Direct3DVertexShader9(Direct3DDevice9 *device, const unsigned long *shaderToken);
virtual ~Direct3DVertexShader9();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DVertexShader9 methods
long __stdcall GetDevice(IDirect3DDevice9 **device);
long __stdcall GetFunction(void *data, unsigned int *size);
// Internal methods
const sw::VertexShader *getVertexShader() const;
private:
// Creation parameters
Direct3DDevice9 *const device;
sw::VertexShader vertexShader;
};
}
#endif // D3D9_Direct3DVertexShader9_hpp
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2011 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "Direct3DVolume9.hpp"
#include "Direct3DDevice9.hpp"
#include "Direct3DResource9.hpp"
#include "Direct3DVolumeTexture9.hpp"
#include "Direct3DSurface9.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D9
{
bool isLockable(D3DPOOL pool, unsigned long usage)
{
return (pool != D3DPOOL_DEFAULT) || (usage & D3DUSAGE_DYNAMIC);
}
Direct3DVolume9::Direct3DVolume9(Direct3DDevice9 *device, Direct3DVolumeTexture9 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, unsigned long usage) : device(device), Surface(container->getResource(), width, height, depth, translateFormat(format), isLockable(pool, usage), false), container(container), width(width), height(height), depth(depth), format(format), pool(pool), lockable(isLockable(pool, usage)), usage(usage)
{
resource = new Direct3DResource9(device, D3DRTYPE_VOLUME, pool, memoryUsage(width, height, depth, format));
resource->bind();
}
Direct3DVolume9::~Direct3DVolume9()
{
resource->unbind();
}
long __stdcall Direct3DVolume9::QueryInterface(const IID &iid, void **object)
{
CriticalSection cs(device);
TRACE("");
if(iid == IID_IDirect3DVolume9 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long __stdcall Direct3DVolume9::AddRef()
{
TRACE("");
return container->AddRef();
}
unsigned long __stdcall Direct3DVolume9::Release()
{
TRACE("");
return container->Release();
}
long Direct3DVolume9::FreePrivateData(const GUID &guid)
{
CriticalSection cs(device);
TRACE("");
return resource->FreePrivateData(guid);
}
long Direct3DVolume9::GetContainer(const IID &iid, void **container)
{
CriticalSection cs(device);
TRACE("");
if(!container)
{
return INVALIDCALL();
}
long result = this->container->QueryInterface(iid, container);
if(result == S_OK)
{
return D3D_OK;
}
return INVALIDCALL();
}
long Direct3DVolume9::GetDesc(D3DVOLUME_DESC *description)
{
CriticalSection cs(device);
TRACE("");
if(!description)
{
return INVALIDCALL();
}
description->Format = format;
description->Type = D3DRTYPE_VOLUME;
description->Usage = usage;
description->Pool = pool;
description->Width = width;
description->Height = height;
description->Depth = depth;
return D3D_OK;
}
long Direct3DVolume9::GetDevice(IDirect3DDevice9 **device)
{
CriticalSection cs(this->device);
TRACE("");
return resource->GetDevice(device);
}
long Direct3DVolume9::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
CriticalSection cs(device);
TRACE("");
return resource->GetPrivateData(guid, data, size);
}
long Direct3DVolume9::LockBox(D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
if(!lockedVolume)
{
return INVALIDCALL();
}
lockedVolume->RowPitch = 0;
lockedVolume->SlicePitch = 0;
lockedVolume->pBits = 0;
if(!lockable)
{
return INVALIDCALL();
}
lockedVolume->RowPitch = getExternalPitchB();
lockedVolume->SlicePitch = getExternalSliceB();
sw::Lock lock = sw::LOCK_READWRITE;
if(flags & D3DLOCK_DISCARD)
{
lock = sw::LOCK_DISCARD;
}
if(flags & D3DLOCK_READONLY)
{
lock = sw::LOCK_READONLY;
}
if(box)
{
lockedVolume->pBits = lockExternal(box->Left, box->Top, box->Front, lock, sw::PUBLIC);
}
else
{
lockedVolume->pBits = lockExternal(0, 0, 0, lock, sw::PUBLIC);
}
return D3D_OK;
}
long Direct3DVolume9::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
CriticalSection cs(device);
TRACE("");
return resource->SetPrivateData(guid, data, size, flags);
}
long Direct3DVolume9::UnlockBox()
{
CriticalSection cs(device);
TRACE("");
unlockExternal();
return D3D_OK;
}
sw::Format Direct3DVolume9::translateFormat(D3DFORMAT format)
{
return Direct3DSurface9::translateFormat(format);
}
unsigned int Direct3DVolume9::memoryUsage(int width, int height, int depth, D3DFORMAT format)
{
return Surface::size(width, height, depth, translateFormat(format));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment