Commit 17b29fd4 by Nicolas Capens

Add Direct3D 8 implementation.

Bug swiftshader:5 Change-Id: I6aec7237f2db6222702e828a2b9dae1a1a6ac9af Reviewed-on: https://swiftshader-review.googlesource.com/7191Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 5270fb39
...@@ -255,6 +255,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2Tools", "third_party\ ...@@ -255,6 +255,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2Tools", "third_party\
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES3Tools", "third_party\PowerVR_SDK\Tools\OGLES3\Build\WindowsVC2010\OGLES3Tools.vcxproj", "{9088FC9E-9843-4E0D-85D0-1B657AFC480A}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES3Tools", "third_party\PowerVR_SDK\Tools\OGLES3\Build\WindowsVC2010\OGLES3Tools.vcxproj", "{9088FC9E-9843-4E0D-85D0-1B657AFC480A}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D3D8", "src\D3D8\D3D8.vcxproj", "{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
...@@ -721,6 +723,15 @@ Global ...@@ -721,6 +723,15 @@ Global
{9088FC9E-9843-4E0D-85D0-1B657AFC480A}.Release|Win32.Build.0 = Release|Win32 {9088FC9E-9843-4E0D-85D0-1B657AFC480A}.Release|Win32.Build.0 = Release|Win32
{9088FC9E-9843-4E0D-85D0-1B657AFC480A}.Release|x64.ActiveCfg = Release|x64 {9088FC9E-9843-4E0D-85D0-1B657AFC480A}.Release|x64.ActiveCfg = Release|x64
{9088FC9E-9843-4E0D-85D0-1B657AFC480A}.Release|x64.Build.0 = Release|x64 {9088FC9E-9843-4E0D-85D0-1B657AFC480A}.Release|x64.Build.0 = Release|x64
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Debug|Win32.ActiveCfg = Debug|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Debug|Win32.Build.0 = Debug|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Debug|x64.ActiveCfg = Debug|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Profile|Win32.ActiveCfg = Profile|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Profile|Win32.Build.0 = Profile|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Profile|x64.ActiveCfg = Profile|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Release|Win32.ActiveCfg = Release|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Release|Win32.Build.0 = Release|Win32
{F18D5ABF-CA3A-4B74-BDB2-4A1956C86F18}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Capabilities_hpp
#define D3D8_Capabilities_hpp
#include <d3d8.h>
namespace D3D8
{
struct Capabilities
{
struct Surface
{
struct RenderTarget
{
static bool R8G8B8;
static bool R5G6B5;
static bool X1R5G5B5;
static bool A1R5G5B5;
static bool A4R4G4B4;
static bool R3G3B2;
static bool A8R3G3B2;
static bool X4R4G4B4;
static bool A8R8G8B8;
static bool X8R8G8B8;
static bool A8B8G8R8;
static bool X8B8G8R8;
// Integer HDR formats
static bool G16R16;
static bool A2B10G10R10;
};
struct DepthStencil
{
static bool D32;
static bool D24S8;
static bool D24X8;
static bool D16;
};
static bool A8;
static bool R5G6B5;
static bool X1R5G5B5;
static bool A1R5G5B5;
static bool A4R4G4B4;
static bool R3G3B2;
static bool A8R3G3B2;
static bool X4R4G4B4;
static bool R8G8B8;
static bool X8R8G8B8;
static bool A8R8G8B8;
static bool A8B8G8R8;
static bool X8B8G8R8;
// Paletted formats
static bool P8;
static bool A8P8;
// Integer HDR formats
static bool G16R16;
static bool A2B10G10R10;
// Compressed formats
static bool DXT1;
static bool DXT2;
static bool DXT3;
static bool DXT4;
static bool DXT5;
// Bump map formats
static bool V8U8;
static bool L6V5U5;
static bool X8L8V8U8;
static bool Q8W8V8U8;
static bool V16U16;
static bool A2W10V10U10;
// Luminance formats
static bool L8;
static bool A4L4;
static bool A8L8;
};
struct Volume
{
static bool A8;
static bool R5G6B5;
static bool X1R5G5B5;
static bool A1R5G5B5;
static bool A4R4G4B4;
static bool R3G3B2;
static bool A8R3G3B2;
static bool X4R4G4B4;
static bool R8G8B8;
static bool X8R8G8B8;
static bool A8R8G8B8;
static bool A8B8G8R8;
static bool X8B8G8R8;
// Paletted formats
static bool P8;
static bool A8P8;
// Integer HDR formats
static bool G16R16;
static bool A2B10G10R10;
// Compressed formats
static bool DXT1;
static bool DXT2;
static bool DXT3;
static bool DXT4;
static bool DXT5;
// Bump map formats
static bool V8U8;
static bool L6V5U5;
static bool X8L8V8U8;
static bool Q8W8V8U8;
static bool V16U16;
static bool A2W10V10U10;
// Luminance formats
static bool L8;
static bool A4L4;
static bool A8L8;
};
struct CubeMap
{
struct RenderTarget
{
static bool R8G8B8;
static bool R5G6B5;
static bool X1R5G5B5;
static bool A1R5G5B5;
static bool A4R4G4B4;
static bool R3G3B2;
static bool A8R3G3B2;
static bool X4R4G4B4;
static bool A8R8G8B8;
static bool X8R8G8B8;
static bool A8B8G8R8;
static bool X8B8G8R8;
// Integer HDR formats
static bool G16R16;
static bool A2B10G10R10;
};
struct DepthStencil
{
static bool D32;
static bool D24S8;
static bool D24X8;
static bool D16;
};
static bool A8;
static bool R5G6B5;
static bool X1R5G5B5;
static bool A1R5G5B5;
static bool A4R4G4B4;
static bool R3G3B2;
static bool A8R3G3B2;
static bool X4R4G4B4;
static bool R8G8B8;
static bool X8R8G8B8;
static bool A8R8G8B8;
static bool A8B8G8R8;
static bool X8B8G8R8;
// Paletted formats
static bool P8;
static bool A8P8;
// Integer HDR formats
static bool G16R16;
static bool A2B10G10R10;
// Compressed formats
static bool DXT1;
static bool DXT2;
static bool DXT3;
static bool DXT4;
static bool DXT5;
// Bump map formats
static bool V8U8;
static bool L6V5U5;
static bool X8L8V8U8;
static bool Q8W8V8U8;
static bool V16U16;
static bool A2W10V10U10;
// Luminance formats
static bool L8;
static bool A4L4;
static bool A8L8;
};
struct VolumeTexture
{
static bool A8;
static bool R5G6B5;
static bool X1R5G5B5;
static bool A1R5G5B5;
static bool A4R4G4B4;
static bool R3G3B2;
static bool A8R3G3B2;
static bool X4R4G4B4;
static bool R8G8B8;
static bool X8R8G8B8;
static bool A8R8G8B8;
static bool A8B8G8R8;
static bool X8B8G8R8;
// Paletted formats
static bool P8;
static bool A8P8;
// Integer HDR formats
static bool G16R16;
static bool A2B10G10R10;
// Compressed formats
static bool DXT1;
static bool DXT2;
static bool DXT3;
static bool DXT4;
static bool DXT5;
// Bump map formats
static bool V8U8;
static bool L6V5U5;
static bool X8L8V8U8;
static bool Q8W8V8U8;
static bool V16U16;
static bool A2W10V10U10;
// Luminance formats
static bool L8;
static bool A4L4;
static bool A8L8;
};
struct Texture
{
struct RenderTarget
{
static bool R8G8B8;
static bool R5G6B5;
static bool X1R5G5B5;
static bool A1R5G5B5;
static bool A4R4G4B4;
static bool R3G3B2;
static bool A8R3G3B2;
static bool X4R4G4B4;
static bool A8R8G8B8;
static bool X8R8G8B8;
static bool A8B8G8R8;
static bool X8B8G8R8;
// Integer HDR formats
static bool G16R16;
static bool A2B10G10R10;
};
struct DepthStencil
{
static bool D32;
static bool D24S8;
static bool D24X8;
static bool D16;
};
static bool A8;
static bool R5G6B5;
static bool X1R5G5B5;
static bool A1R5G5B5;
static bool A4R4G4B4;
static bool R3G3B2;
static bool A8R3G3B2;
static bool X4R4G4B4;
static bool R8G8B8;
static bool X8R8G8B8;
static bool A8R8G8B8;
static bool A8B8G8R8;
static bool X8B8G8R8;
// Paletted formats
static bool P8;
static bool A8P8;
// Integer HDR formats
static bool G16R16;
static bool A2B10G10R10;
// Compressed formats
static bool DXT1;
static bool DXT2;
static bool DXT3;
static bool DXT4;
static bool DXT5;
// Bump map formats
static bool V8U8;
static bool L6V5U5;
static bool X8L8V8U8;
static bool Q8W8V8U8;
static bool V16U16;
static bool A2W10V10U10;
// Luminance formats
static bool L8;
static bool A4L4;
static bool A8L8;
};
};
extern unsigned int pixelShaderVersion;
extern unsigned int vertexShaderVersion;
extern unsigned int textureMemory;
extern unsigned int maxAnisotropy;
}
#endif // D3D8_Capabilities_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3D8.hpp"
#include "resource.h"
#include <stdio.h>
#include <assert.h>
extern "C"
{
HINSTANCE dllInstance;
int __stdcall DllMain(HINSTANCE instance, unsigned long reason, void *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;
}
IDirect3D8 *__stdcall Direct3DCreate8(unsigned int version)
{
// D3D_SDK_VERSION check
if(version != 120 && // 8.0
version != 220) // 8.1
{
return 0;
}
#ifndef NDEBUG
FILE *file = fopen("debug.txt", "w"); // Clear debug log
fclose(file);
#endif
IDirect3D8 *device = new D3D8::Direct3D8(version, dllInstance);
if(device)
{
device->AddRef();
}
return device;
}
int __stdcall CheckFullscreen() // FIXME: __cdecl or __stdcall?
{
#ifndef NDEBUG
// ASSERT(false); // FIXME
#endif
return FALSE;
}
void __cdecl DebugSetMute(long mute) // FIXME: Return type
{
// ASSERT(false); // FIXME
}
int __stdcall ValidatePixelShader(long *shader, int x, int y, int z) // FIXME: __cdecl or __stdcall? // FIXME: Argument meanings
{
// ASSERT(false); // FIXME
return TRUE;
}
int __stdcall ValidateVertexShader(long *shader, int x, int y, int z) // FIXME: __cdecl or __stdcall? // FIXME: Argument meanings
{
// ASSERT(false); // FIXME
return TRUE;
}
}
// Microsoft Visual C++ generated resource script.
//
#include "resource1.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "Windows.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
"resource1.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"#include ""../Common/Version.h""\0"
END
3 TEXTINCLUDE
BEGIN
"\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", "Google Inc."
VALUE "FileDescription", "SwiftShader Direct3D 8 Renderer"
VALUE "FileVersion", VERSION_STRING
VALUE "InternalName", "D3D8"
VALUE "LegalCopyright", "Copyright (C) 2016 Google Inc."
VALUE "OriginalFilename", "d3d8.dll"
VALUE "PrivateBuild", REVISION_STRING
VALUE "ProductName", "SwiftShader Direct3D 8 Renderer"
VALUE "ProductVersion", VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
<?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="D3D8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3D8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DBaseTexture8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DCubeTexture8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DDevice8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DIndexBuffer8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DPixelShader8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DResource8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DStateBlock8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DSurface8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DSwapChain8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DTexture8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVertexBuffer8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVertexDeclaration8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVertexShader8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVolume8.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Direct3DVolumeTexture8.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="Direct3D8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DBaseTexture8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DCubeTexture8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DDevice8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DIndexBuffer8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DPixelShader8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DResource8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DStateBlock8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DSurface8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DSwapChain8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DTexture8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVertexBuffer8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVertexDeclaration8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVertexShader8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVolume8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Direct3DVolumeTexture8.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource1.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Unknown.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="D3D8.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="d3d8.def" />
</ItemGroup>
</Project>
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef Debug_hpp
#define Debug_hpp
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <d3d8.h>
#include <stdio.h>
#include <guiddef.h>
#include <assert.h>
void trace(const char *format, ...);
#ifndef NDEBUG
#define TRACE(format, ...) trace("[0x%0.8X]%s("format")\n", this, __FUNCTION__, ##__VA_ARGS__)
#else
#define TRACE(...) ((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
#endif // Debug_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3D8_hpp
#define D3D8_Direct3D8_hpp
#include "Unknown.hpp"
#include <stdio.h>
#include <initguid.h>
#include <d3d8.h>
namespace D3D8
{
class Direct3DDevice8;
class Direct3D8 : public IDirect3D8, protected Unknown
{
public:
Direct3D8(int version, const HINSTANCE instance);
virtual ~Direct3D8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3D8 methods
long __stdcall CheckDepthStencilMatch(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat);
long __stdcall CheckDeviceFormat(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapaterFormat, unsigned long usage, D3DRESOURCETYPE type, D3DFORMAT checkFormat);
long __stdcall CheckDeviceMultiSampleType(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT surfaceFormat, int windowed, D3DMULTISAMPLE_TYPE multiSampleType);
long __stdcall CheckDeviceType(unsigned int adapter, D3DDEVTYPE checkType, D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, int windowed);
long __stdcall CreateDevice(unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, unsigned long behaviorFlags, D3DPRESENT_PARAMETERS *presentParameters, IDirect3DDevice8 **returnedDeviceInterface);
long __stdcall EnumAdapterModes(unsigned int adapter, unsigned int index, D3DDISPLAYMODE *mode);
unsigned int __stdcall GetAdapterCount();
long __stdcall GetAdapterDisplayMode(unsigned int adapter, D3DDISPLAYMODE *mode);
long __stdcall GetAdapterIdentifier(unsigned int adapter, unsigned long flags, D3DADAPTER_IDENTIFIER8 *identifier);
unsigned int __stdcall GetAdapterModeCount(unsigned int adapter);
HMONITOR __stdcall GetAdapterMonitor(unsigned int adapter);
long __stdcall GetDeviceCaps(unsigned int adapter, D3DDEVTYPE deviceType, D3DCAPS8 *caps);
long __stdcall RegisterSoftwareDevice(void *initializeFunction);
private:
void loadSystemD3D8();
// Creation parameters
const int version;
const HINSTANCE instance;
DEVMODE *displayMode;
int numDisplayModes;
// Real D3D8 library and IDirect3D8 object
HMODULE d3d8Lib;
IDirect3D8 *d3d8;
};
}
#endif // D3D8_Direct3D8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DBaseTexture8.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
namespace D3D8
{
Direct3DBaseTexture8::Direct3DBaseTexture8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned long levels, unsigned long usage) : Direct3DResource8(device, type, 0), levels(levels), usage(usage)
{
filterType = D3DTEXF_LINEAR;
LOD = 0;
resource = new sw::Resource(0);
}
Direct3DBaseTexture8::~Direct3DBaseTexture8()
{
resource->destruct();
}
long Direct3DBaseTexture8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DBaseTexture8 ||
iid == IID_IDirect3DResource8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DBaseTexture8::AddRef()
{
TRACE("");
return Direct3DResource8::AddRef();
}
unsigned long Direct3DBaseTexture8::Release()
{
TRACE("");
return Direct3DResource8::Release();
}
long Direct3DBaseTexture8::FreePrivateData(const GUID &guid)
{
TRACE("");
return Direct3DResource8::FreePrivateData(guid);
}
long Direct3DBaseTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
TRACE("");
return Direct3DResource8::GetPrivateData(guid, data, size);
}
void Direct3DBaseTexture8::PreLoad()
{
TRACE("");
Direct3DResource8::PreLoad();
}
long Direct3DBaseTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
return Direct3DResource8::SetPrivateData(guid, data, size, flags);
}
long Direct3DBaseTexture8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
return Direct3DResource8::GetDevice(device);
}
unsigned long Direct3DBaseTexture8::SetPriority(unsigned long newPriority)
{
TRACE("");
return Direct3DResource8::SetPriority(newPriority);
}
unsigned long Direct3DBaseTexture8::GetPriority()
{
TRACE("");
return Direct3DResource8::GetPriority();
}
D3DRESOURCETYPE Direct3DBaseTexture8::GetType()
{
TRACE("");
return Direct3DResource8::GetType();
}
unsigned long Direct3DBaseTexture8::GetLevelCount()
{
TRACE("");
return levels;
}
unsigned long Direct3DBaseTexture8::GetLOD()
{
TRACE("");
return LOD;
}
long Direct3DBaseTexture8::SetLOD(long newLOD)
{
TRACE("");
LOD = newLOD;
return 0; // TODO
}
sw::Resource *Direct3DBaseTexture8::getResource() const
{
return resource;
}
unsigned long Direct3DBaseTexture8::getInternalLevelCount()
{
return levels;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DBaseTexture8_hpp
#define D3D8_Direct3DBaseTexture8_hpp
#include "Direct3DResource8.hpp"
#include <d3d8.h>
namespace sw
{
class Resource;
}
namespace D3D8
{
class Direct3DBaseTexture8 : public IDirect3DBaseTexture8, public Direct3DResource8
{
public:
Direct3DBaseTexture8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned long levels, unsigned long usage);
virtual ~Direct3DBaseTexture8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource8 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(IDirect3DDevice8 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DBaseTexture8 methods
unsigned long __stdcall GetLevelCount();
unsigned long __stdcall GetLOD();
long __stdcall SetLOD(long newLOD);
// Intenal methods
sw::Resource *getResource() const;
unsigned long getInternalLevelCount();
protected:
// Creation paramters
unsigned long levels; // Recalculated when 0
const unsigned long usage;
sw::Resource *resource;
private:
D3DTEXTUREFILTERTYPE filterType;
unsigned long LOD;
};
}
#endif // D3D8_Direct3DBaseTexture8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DCubeTexture8.hpp"
#include "Direct3DSurface8.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D8
{
Direct3DCubeTexture8::Direct3DCubeTexture8(Direct3DDevice8 *device, unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture8(device, D3DRTYPE_CUBETEXTURE, levels, usage), edgeLength(edgeLength), format(format), pool(pool)
{
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 < sw::MIPMAP_LEVELS; level++)
{
if(level < this->levels)
{
surfaceLevel[face][level] = new Direct3DSurface8(device, this, width, height, format, pool, D3DMULTISAMPLE_NONE, true, usage);
surfaceLevel[face][level]->bind();
}
else
{
surfaceLevel[face][level] = 0;
}
width = sw::max(1, width / 2);
height = sw::max(1, height / 2);
}
}
}
Direct3DCubeTexture8::~Direct3DCubeTexture8()
{
resource->lock(sw::DESTRUCT);
for(unsigned int face = 0; face < 6; face++)
{
for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
{
if(surfaceLevel[face][level])
{
surfaceLevel[face][level]->unbind();
surfaceLevel[face][level] = 0;
}
}
}
resource->unlock();
}
long Direct3DCubeTexture8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DCubeTexture8 ||
iid == IID_IDirect3DBaseTexture8 ||
iid == IID_IDirect3DResource8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DCubeTexture8::AddRef()
{
TRACE("");
return Direct3DBaseTexture8::AddRef();
}
unsigned long Direct3DCubeTexture8::Release()
{
TRACE("");
return Direct3DBaseTexture8::Release();
}
long Direct3DCubeTexture8::FreePrivateData(const GUID &guid)
{
TRACE("");
return Direct3DBaseTexture8::FreePrivateData(guid);
}
long Direct3DCubeTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
TRACE("");
return Direct3DBaseTexture8::GetPrivateData(guid, data, size);
}
void Direct3DCubeTexture8::PreLoad()
{
TRACE("");
Direct3DBaseTexture8::PreLoad();
}
long Direct3DCubeTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
return Direct3DBaseTexture8::SetPrivateData(guid, data, size, flags);
}
long Direct3DCubeTexture8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
return Direct3DBaseTexture8::GetDevice(device);
}
unsigned long Direct3DCubeTexture8::SetPriority(unsigned long newPriority)
{
TRACE("");
return Direct3DBaseTexture8::SetPriority(newPriority);
}
unsigned long Direct3DCubeTexture8::GetPriority()
{
TRACE("");
return Direct3DBaseTexture8::GetPriority();
}
D3DRESOURCETYPE Direct3DCubeTexture8::GetType()
{
TRACE("");
return Direct3DBaseTexture8::GetType();
}
unsigned long Direct3DCubeTexture8::GetLevelCount()
{
TRACE("");
return Direct3DBaseTexture8::GetLevelCount();
}
unsigned long Direct3DCubeTexture8::GetLOD()
{
TRACE("");
return Direct3DBaseTexture8::GetLOD();
}
unsigned long Direct3DCubeTexture8::SetLOD(unsigned long newLOD)
{
TRACE("");
return Direct3DBaseTexture8::SetLOD(newLOD);
}
long Direct3DCubeTexture8::AddDirtyRect(D3DCUBEMAP_FACES face, const RECT *dirtyRect)
{
TRACE("");
// UNIMPLEMENTED();
return D3D_OK;
}
long Direct3DCubeTexture8::GetCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level , IDirect3DSurface8 **cubeMapSurface)
{
TRACE("");
*cubeMapSurface = 0; // FIXME: Verify
if(face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
{
return INVALIDCALL();
}
surfaceLevel[face][level]->AddRef();
*cubeMapSurface = surfaceLevel[face][level];
return D3D_OK;
}
long Direct3DCubeTexture8::GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description)
{
TRACE("");
if(!description || level >= GetLevelCount() || !surfaceLevel[0][level])
{
return INVALIDCALL();
}
surfaceLevel[0][level]->GetDesc(description);
return D3D_OK;
}
long Direct3DCubeTexture8::LockRect(D3DCUBEMAP_FACES face, unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
{
TRACE("");
if(!lockedRect || face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
{
return INVALIDCALL();
}
surfaceLevel[face][level]->LockRect(lockedRect, rect, flags);
return D3D_OK;
}
long Direct3DCubeTexture8::UnlockRect(D3DCUBEMAP_FACES face, unsigned int level)
{
TRACE("");
if(face >= 6 || level >= GetLevelCount() || !surfaceLevel[face][level])
{
return INVALIDCALL();
}
return surfaceLevel[face][level]->UnlockRect();
}
Direct3DSurface8 *Direct3DCubeTexture8::getInternalCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level)
{
return surfaceLevel[face][level];
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DCubeTexture8_hpp
#define D3D8_Direct3DCubeTexture8_hpp
#include "Direct3DBaseTexture8.hpp"
#include "Config.hpp"
#include <d3d8.h>
namespace D3D8
{
class Direct3DSurface8;
class Direct3DCubeTexture8 : public IDirect3DCubeTexture8, public Direct3DBaseTexture8
{
public:
Direct3DCubeTexture8(Direct3DDevice8 *device, unsigned int edgeLength, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
virtual ~Direct3DCubeTexture8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource8 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(IDirect3DDevice8 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DBaseTexture methods
unsigned long __stdcall GetLevelCount();
unsigned long __stdcall GetLOD();
unsigned long __stdcall SetLOD(unsigned long newLOD);
// IDirect3DCubeTexture8 methods
long __stdcall AddDirtyRect(D3DCUBEMAP_FACES face, const RECT *dirtyRect);
long __stdcall GetCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level , IDirect3DSurface8 **cubeMapSurface);
long __stdcall GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description);
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);
// Internal methods
Direct3DSurface8 *getInternalCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level);
private:
// Creation parameters
const unsigned int edgeLength;
const D3DFORMAT format;
const D3DPOOL pool;
Direct3DSurface8 *surfaceLevel[6][sw::MIPMAP_LEVELS];
};
}
#endif // D3D8_Direct3D8_hpp
This source diff could not be displayed because it is too large. You can view the blob instead.
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DIndexBuffer8.hpp"
#include "Direct3DDevice8.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D8
{
Direct3DIndexBuffer8::Direct3DIndexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DResource8(device, D3DRTYPE_INDEXBUFFER, length), length(length), usage(usage), format(format), pool(pool)
{
indexBuffer = new sw::Resource(length + 16);
}
Direct3DIndexBuffer8::~Direct3DIndexBuffer8()
{
indexBuffer->destruct();
}
long Direct3DIndexBuffer8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DIndexBuffer8 ||
iid == IID_IDirect3DResource8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DIndexBuffer8::AddRef()
{
TRACE("");
return Direct3DResource8::AddRef();
}
unsigned long Direct3DIndexBuffer8::Release()
{
TRACE("");
return Direct3DResource8::Release();
}
long Direct3DIndexBuffer8::FreePrivateData(const GUID &guid)
{
TRACE("");
return Direct3DResource8::FreePrivateData(guid);
}
long Direct3DIndexBuffer8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
TRACE("");
return Direct3DResource8::GetPrivateData(guid, data, size);
}
void Direct3DIndexBuffer8::PreLoad()
{
TRACE("");
Direct3DResource8::PreLoad();
}
long Direct3DIndexBuffer8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
return Direct3DResource8::SetPrivateData(guid, data, size, flags);
}
long Direct3DIndexBuffer8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
return Direct3DResource8::GetDevice(device);
}
unsigned long Direct3DIndexBuffer8::SetPriority(unsigned long newPriority)
{
TRACE("");
return Direct3DResource8::SetPriority(newPriority);
}
unsigned long Direct3DIndexBuffer8::GetPriority()
{
TRACE("");
return Direct3DResource8::GetPriority();
}
D3DRESOURCETYPE Direct3DIndexBuffer8::GetType()
{
TRACE("");
return Direct3DResource8::GetType();
}
long Direct3DIndexBuffer8::GetDesc(D3DINDEXBUFFER_DESC *description)
{
TRACE("");
if(!description)
{
return INVALIDCALL();
}
description->Format = format;
description->Pool = pool;
description->Size = length;
description->Type = GetType();
description->Usage = usage;
return 0;
}
long Direct3DIndexBuffer8::Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags)
{
TRACE("");
if(offset == 0 && size == 0) // Lock whole buffer
{
size = length;
}
if(!data || offset + size > length)
{
return INVALIDCALL();
}
lockOffset = offset;
lockSize = size;
*data = (unsigned char*)indexBuffer->lock(sw::PUBLIC) + offset;
indexBuffer->unlock();
return D3D_OK;
}
long Direct3DIndexBuffer8::Unlock()
{
TRACE("");
return D3D_OK;
}
sw::Resource *Direct3DIndexBuffer8::getResource() const
{
return indexBuffer;
}
bool Direct3DIndexBuffer8::is32Bit() const
{
switch(format)
{
case D3DFMT_INDEX16:
return false;
case D3DFMT_INDEX32:
return true;
default:
ASSERT(false);
}
return false;
}
}
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DIndexBuffer8_hpp
#define D3D8_Direct3DIndexBuffer8_hpp
#include "Direct3DResource8.hpp"
#include <d3d8.h>
namespace sw
{
class Resource;
}
namespace D3D8
{
class Direct3DIndexBuffer8 : public IDirect3DIndexBuffer8, public Direct3DResource8
{
public:
Direct3DIndexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
virtual ~Direct3DIndexBuffer8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource8 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(IDirect3DDevice8 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DIndexBuffer8 methods
long __stdcall GetDesc(D3DINDEXBUFFER_DESC *description);
long __stdcall Lock(unsigned int offset, unsigned int size, unsigned char **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;
const D3DPOOL pool;
bool locked;
unsigned int lockOffset;
unsigned int lockSize;
unsigned char *lockData;
sw::Resource *indexBuffer;
};
}
#endif // D3D8_Direct3DIndexBuffer8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DPixelShader8.hpp"
#include "Debug.hpp"
namespace D3D8
{
Direct3DPixelShader8::Direct3DPixelShader8(Direct3DDevice8 *device, const unsigned long *shaderToken) : device(device), pixelShader(shaderToken)
{
const unsigned long *token = shaderToken;
size = 0;
while(shaderToken[size] != 0x0000FFFF)
{
size++;
}
size++;
this->shaderToken = new unsigned long[size];
memcpy(this->shaderToken, shaderToken, size * sizeof(unsigned long));
}
Direct3DPixelShader8::~Direct3DPixelShader8()
{
delete[] shaderToken;
shaderToken = 0;
}
long Direct3DPixelShader8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
ASSERT(false); // Internal object
return NOINTERFACE(iid);
}
unsigned long Direct3DPixelShader8::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DPixelShader8::Release()
{
TRACE("");
return Unknown::Release();
}
void Direct3DPixelShader8::GetFunction(void *data, unsigned int *size)
{
TRACE("");
if(data)
{
memcpy(data, shaderToken, this->size * 4);
}
*size = this->size * 4;
}
const sw::PixelShader *Direct3DPixelShader8::getPixelShader() const
{
return &pixelShader;
}
}
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DPixelShader8_hpp
#define D3D8_Direct3DPixelShader8_hpp
#include "PixelShader.hpp"
#include "Unknown.hpp"
namespace D3D8
{
class Direct3DDevice8;
class Direct3DPixelShader8 : public Unknown
{
public:
Direct3DPixelShader8(Direct3DDevice8 *device, const unsigned long *shaderToken);
virtual ~Direct3DPixelShader8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DPixelShader8 methods
void __stdcall GetFunction(void *data, unsigned int *size);
// Internal methods
const sw::PixelShader *getPixelShader() const;
private:
// Creation parameters
Direct3DDevice8 *const device;
unsigned long *shaderToken;
unsigned int size;
sw::PixelShader pixelShader;
};
}
#endif // D3D8_Direct3DPixelShader8_hpp
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DResource8.hpp"
#include "Direct3DDevice8.hpp"
#include "Debug.hpp"
namespace D3D8
{
unsigned int Direct3DResource8::memoryUsage = 0;
Direct3DResource8::PrivateData::PrivateData()
{
data = 0;
}
Direct3DResource8::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();
}
}
Direct3DResource8::PrivateData &Direct3DResource8::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;
}
Direct3DResource8::PrivateData::~PrivateData()
{
if(data && managed)
{
((IUnknown*)data)->Release();
}
delete[] data;
data = 0;
}
Direct3DResource8::Direct3DResource8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned int size) : device(device), type(type), size(size)
{
priority = 0;
memoryUsage += size;
}
Direct3DResource8::~Direct3DResource8()
{
memoryUsage -= size;
}
long Direct3DResource8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DResource8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DResource8::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DResource8::Release()
{
TRACE("");
return Unknown::Release();
}
long Direct3DResource8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
if(!device)
{
return INVALIDCALL();
}
this->device->AddRef();
*device = this->device;
return D3D_OK;
}
long Direct3DResource8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
privateData[guid] = PrivateData(data, size, flags == D3DSPD_IUNKNOWN);
return D3D_OK;
}
long Direct3DResource8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
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 Direct3DResource8::FreePrivateData(const GUID &guid)
{
TRACE("");
Iterator result = privateData.find(guid);
if(result == privateData.end())
{
return D3DERR_NOTFOUND;
}
privateData.erase(guid);
return D3D_OK;
}
unsigned long Direct3DResource8::SetPriority(unsigned long newPriority)
{
TRACE("");
unsigned long oldPriority = priority;
priority = newPriority;
return oldPriority;
}
unsigned long Direct3DResource8::GetPriority()
{
TRACE("");
return priority;
}
void Direct3DResource8::PreLoad()
{
TRACE("");
return; // FIXME: Anything to do?
}
D3DRESOURCETYPE Direct3DResource8::GetType()
{
TRACE("");
return type;
}
unsigned int Direct3DResource8::getMemoryUsage()
{
return memoryUsage;
}
}
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DResource8_hpp
#define D3D8_Direct3DResource8_hpp
#include "Unknown.hpp"
#include <d3d8.h>
#include <map>
namespace D3D8
{
class Direct3DDevice8;
class Direct3DResource8 : public IDirect3DResource8, public Unknown
{
public:
Direct3DResource8(Direct3DDevice8 *device, D3DRESOURCETYPE type, unsigned int size);
virtual ~Direct3DResource8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource8 methods
long __stdcall GetDevice(IDirect3DDevice8 **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();
protected:
// Creation parameters
Direct3DDevice8 *const device;
const D3DRESOURCETYPE type;
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 // D3D8_Direct3DResource8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DStateBlock8_hpp
#define D3D8_Direct3DStateBlock8_hpp
#include "Unknown.hpp"
#include <vector>
#include <d3d8.h>
namespace D3D8
{
class Direct3DDevice8;
class Direct3DBaseTexture8;
class Direct3DVertexBuffer8;
class Direct3DIndexBuffer8;
class Direct3DStateBlock8 : public Unknown
{
public:
Direct3DStateBlock8(Direct3DDevice8 *device, D3DSTATEBLOCKTYPE type);
virtual ~Direct3DStateBlock8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DStateBlock8 methods
long __stdcall Apply();
long __stdcall Capture();
long __stdcall GetDevice(IDirect3DDevice8 **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(Direct3DIndexBuffer8 *indexData, unsigned int baseVertexIndex);
void setLight(unsigned long index, const D3DLIGHT8 *light);
void setMaterial(const D3DMATERIAL8 *material);
void setPixelShader(unsigned long shaderHandle);
void setPixelShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count);
void setRenderState(D3DRENDERSTATETYPE state, unsigned long value);
void setScissorRect(const RECT *rect);
void setStreamSource(unsigned int stream, Direct3DVertexBuffer8 *data, unsigned int stride);
void setTexture(unsigned long stage, Direct3DBaseTexture8 *texture);
void setTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type, unsigned long value);
void setTransform(D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix);
void setViewport(const D3DVIEWPORT8 *viewport);
void setVertexShader(unsigned long shaderHandle);
void setVertexShaderConstant(unsigned int startRegister, const void *constantData, unsigned int count);
private:
// Individual states
void captureRenderState(D3DRENDERSTATETYPE state);
void captureTextureStageState(unsigned long stage, D3DTEXTURESTAGESTATETYPE type);
void captureTransform(D3DTRANSFORMSTATETYPE state);
// Pixel states
void capturePixelRenderStates();
void capturePixelTextureStates();
void capturePixelShaderStates();
// Vertex states
void captureVertexRenderStates();
void captureVertexTextureStates();
void captureLightStates();
void captureVertexShaderStates();
// All (remaining) states
void captureTextures();
void captureVertexTextures();
void captureDisplacementTextures();
void captureTexturePalette();
void captureVertexStreams();
void captureIndexBuffer();
void captureViewport();
void captureTransforms();
void captureTextureTransforms();
void captureClippingPlanes();
void captureMaterial();
// Creation parameters
Direct3DDevice8 *const device;
const D3DSTATEBLOCKTYPE type;
// State data
bool vertexShaderCaptured;
unsigned long vertexShaderHandle;
bool pixelShaderCaptured;
unsigned long pixelShaderHandle;
bool indexBufferCaptured;
Direct3DIndexBuffer8 *indexBuffer;
unsigned int baseVertexIndex;
bool renderStateCaptured[D3DRS_NORMALORDER + 1];
unsigned long renderState[D3DRS_NORMALORDER + 1];
bool textureStageStateCaptured[8][D3DTSS_RESULTARG + 1];
unsigned long textureStageState[8][D3DTSS_RESULTARG + 1];
bool streamSourceCaptured[16];
struct StreamSource
{
Direct3DVertexBuffer8 *vertexBuffer;
unsigned int stride;
};
StreamSource streamSource[16];
bool textureCaptured[8];
Direct3DBaseTexture8 *texture[8];
bool transformCaptured[512];
D3DMATRIX transform[512];
bool viewportCaptured;
D3DVIEWPORT8 viewport;
bool clipPlaneCaptured[6];
float clipPlane[6][4];
bool materialCaptured;
D3DMATERIAL8 material;
bool lightCaptured[8]; // FIXME: Unlimited index
D3DLIGHT8 light[8];
bool lightEnableCaptured[8]; // FIXME: Unlimited index
int lightEnableState[8];
float pixelShaderConstant[8][4];
float vertexShaderConstant[256][4];
bool scissorRectCaptured;
RECT scissorRect;
bool paletteNumberCaptured;
unsigned int paletteNumber;
void clear();
};
}
#endif // D3D8_Direct3DStateBlock8_hpp
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DSurface8.hpp"
#include "Direct3DBaseTexture8.hpp"
#include "Debug.hpp"
#include <malloc.h>
#include <assert.h>
extern bool quadLayoutEnabled;
namespace D3D8
{
static sw::Resource *getParentResource(Unknown *container)
{
Direct3DBaseTexture8 *baseTexture = dynamic_cast<Direct3DBaseTexture8*>(container);
if(baseTexture)
{
return baseTexture->getResource();
}
return 0;
}
int sampleCount(D3DMULTISAMPLE_TYPE multiSample)
{
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;
}
Direct3DSurface8::Direct3DSurface8(Direct3DDevice8 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, bool lockable, unsigned long usage) : Surface(getParentResource(container), width, height, sampleCount(multiSample), translateFormat(format), lockable, (usage & D3DUSAGE_RENDERTARGET) == D3DUSAGE_RENDERTARGET || (usage & D3DUSAGE_DEPTHSTENCIL) == D3DUSAGE_DEPTHSTENCIL), device(device), container(container), width(width), height(height), format(format), pool(pool), multiSample(multiSample), lockable(lockable), usage(usage)
{
parentTexture = dynamic_cast<Direct3DBaseTexture8*>(container);
resource = new Direct3DResource8(device, D3DRTYPE_SURFACE, memoryUsage(width, height, format));
}
Direct3DSurface8::~Direct3DSurface8()
{
resource->Release();
}
long Direct3DSurface8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DSurface8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DSurface8::AddRef()
{
TRACE("");
if(parentTexture)
{
return parentTexture->AddRef();
}
return Unknown::AddRef();
}
unsigned long Direct3DSurface8::Release()
{
TRACE("");
if(parentTexture)
{
return parentTexture->Release();
}
return Unknown::Release();
}
long Direct3DSurface8::FreePrivateData(const GUID &guid)
{
TRACE("");
return resource->FreePrivateData(guid);
}
long Direct3DSurface8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
TRACE("");
return resource->GetPrivateData(guid, data, size);
}
long Direct3DSurface8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
return resource->SetPrivateData(guid, data, size, flags);
}
long Direct3DSurface8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
return resource->GetDevice(device);
}
long Direct3DSurface8::LockRect(D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
{
TRACE("");
if(!lockedRect)
{
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);
}
unlockExternal();
return D3D_OK;
}
long Direct3DSurface8::UnlockRect()
{
TRACE("");
return D3D_OK;
}
long Direct3DSurface8::GetContainer(const IID &iid, void **container)
{
TRACE("");
if(!container)
{
return INVALIDCALL();
}
long result = this->container->QueryInterface(iid, container);
if(result == S_OK)
{
return D3D_OK;
}
return INVALIDCALL();
}
long Direct3DSurface8::GetDesc(D3DSURFACE_DESC *desc)
{
TRACE("");
if(!desc)
{
return INVALIDCALL();
}
desc->Format = format;
desc->Pool = pool;
desc->Type = D3DRTYPE_SURFACE;
desc->Height = height;
desc->Width = width;
desc->Size = size(getWidth(), getHeight(), getDepth(), getExternalFormat());
desc->MultiSampleType = multiSample;
desc->Usage = usage;
return D3D_OK;
}
sw::Format Direct3DSurface8::translateFormat(D3DFORMAT format)
{
switch(format)
{
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_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_G16R16: return sw::FORMAT_G16R16;
case D3DFMT_A2B10G10R10: return sw::FORMAT_A2B10G10R10;
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_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_L8: return sw::FORMAT_L8;
case D3DFMT_A4L4: return sw::FORMAT_A4L4;
case D3DFMT_A8L8: return sw::FORMAT_A8L8;
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;
default:
ASSERT(false);
}
return sw::FORMAT_NULL;
}
int Direct3DSurface8::bytes(D3DFORMAT format)
{
return Surface::bytes(translateFormat(format));
}
unsigned int Direct3DSurface8::memoryUsage(int width, int height, D3DFORMAT format)
{
return Surface::size(width, height, 1, translateFormat(format));
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DSurface8_hpp
#define D3D8_Direct3DSurface8_hpp
#include "Unknown.hpp"
#include "Surface.hpp"
#include <d3d8.h>
namespace D3D8
{
class Direct3DDevice8;
class Direct3DResource8;
class Direct3DBaseTexture8;
class Direct3DSurface8 : public IDirect3DSurface8, public Unknown, public sw::Surface
{
public:
Direct3DSurface8(Direct3DDevice8 *device, Unknown *container, int width, int height, D3DFORMAT format, D3DPOOL pool, D3DMULTISAMPLE_TYPE multiSample, bool lockable, unsigned long usage);
virtual ~Direct3DSurface8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DSurface8 methods
long __stdcall GetDevice(IDirect3DDevice8 **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);
long __stdcall GetContainer(const IID &iid, void **container);
long __stdcall GetDesc(D3DSURFACE_DESC *desc);
long __stdcall LockRect(D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long Flags);
long __stdcall UnlockRect();
// Internal methods
static sw::Format translateFormat(D3DFORMAT format);
static int bytes(D3DFORMAT format);
private:
static unsigned int memoryUsage(int width, int height, D3DFORMAT format); // FIXME: Surface::size
// Creation parameters
Direct3DDevice8 *const device;
Unknown *const container;
const int width;
const int height;
const D3DFORMAT format;
const D3DMULTISAMPLE_TYPE multiSample;
const D3DPOOL pool;
const bool lockable;
const unsigned long usage;
Direct3DBaseTexture8 *parentTexture;
Direct3DResource8 *resource;
};
}
#endif // D3D8_Direct3DSurface8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DSwapChain8.hpp"
#include "Direct3DDevice8.hpp"
#include "Config.hpp"
#include "Configurator.hpp"
#include "Debug.hpp"
#include "FrameBufferDD.hpp"
#include "FrameBufferGDI.hpp"
namespace D3D8
{
Direct3DSwapChain8::Direct3DSwapChain8(Direct3DDevice8 *device, D3DPRESENT_PARAMETERS *presentParameters) : device(device), presentParameters(*presentParameters)
{
frameBuffer = 0;
for(int i = 0; i < 3; i++)
{
backBuffer[i] = 0;
}
reset(presentParameters);
}
Direct3DSwapChain8::~Direct3DSwapChain8()
{
release();
}
long Direct3DSwapChain8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DSwapChain8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DSwapChain8::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DSwapChain8::Release()
{
TRACE("");
return Unknown::Release();
}
long Direct3DSwapChain8::Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion)
{
TRACE("");
#if PERF_PROFILE
profiler.nextFrame();
#endif
void *source = backBuffer[0]->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); // FIXME: External
sw::Format format = backBuffer[0]->getInternalFormat();
int stride = backBuffer[0]->getInternalPitchB();
if(!sourceRect && !destRect) // FIXME: More cases?
{
frameBuffer->flip(destWindowOverride, source, format, stride);
}
else // TODO: Check for SWAPEFFECT_COPY
{
sw::Rect sRect(0, 0, 0, 0);
sw::Rect dRect(0, 0, 0, 0);
if(sourceRect)
{
sRect.x0 = sourceRect->left;
sRect.y0 = sourceRect->top;
sRect.x1 = sourceRect->right;
sRect.y1 = sourceRect->bottom;
}
if(destRect)
{
dRect.x0 = destRect->left;
dRect.y0 = destRect->top;
dRect.x1 = destRect->right;
dRect.y1 = destRect->bottom;
}
frameBuffer->blit(destWindowOverride, source, sourceRect ? &sRect : nullptr, destRect ? &dRect : nullptr, format, stride);
}
backBuffer[0]->unlockInternal(); // FIXME: External
return D3D_OK;
}
long Direct3DSwapChain8::GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface8 **backBuffer)
{
TRACE("");
if(!backBuffer/* || type != D3DBACKBUFFER_TYPE_MONO*/)
{
return INVALIDCALL();
}
if(index >= 3 || this->backBuffer[index] == 0)
{
return INVALIDCALL();
}
this->backBuffer[index]->AddRef();
*backBuffer = this->backBuffer[index];
return D3D_OK;
}
void Direct3DSwapChain8::reset(D3DPRESENT_PARAMETERS *presentParameters)
{
release();
this->presentParameters = *presentParameters;
ASSERT(presentParameters->BackBufferCount <= 3); // Maximum of three back buffers
if(presentParameters->BackBufferCount == 0)
{
presentParameters->BackBufferCount = 1;
}
D3DDEVICE_CREATION_PARAMETERS creationParameters;
device->GetCreationParameters(&creationParameters);
HWND windowHandle = presentParameters->hDeviceWindow ? presentParameters->hDeviceWindow : creationParameters.hFocusWindow;
int width = 0;
int height = 0;
if(presentParameters->Windowed && (presentParameters->BackBufferHeight == 0 || presentParameters->BackBufferWidth == 0))
{
RECT rectangle;
GetClientRect(windowHandle, &rectangle);
width = rectangle.right - rectangle.left;
height = rectangle.bottom - rectangle.top;
}
else
{
width = presentParameters->BackBufferWidth;
height = presentParameters->BackBufferHeight;
}
frameBuffer = createFrameBufferWin(windowHandle, presentParameters->BackBufferWidth, presentParameters->BackBufferHeight, presentParameters->Windowed == FALSE, true);
lockable = presentParameters->Flags & D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
backBuffer[0] = 0;
backBuffer[1] = 0;
backBuffer[2] = 0;
for(int i = 0; i < (int)presentParameters->BackBufferCount; i++)
{
backBuffer[i] = new Direct3DSurface8(device, this, width, height, presentParameters->BackBufferFormat, D3DPOOL_DEFAULT, presentParameters->MultiSampleType, lockable, D3DUSAGE_RENDERTARGET);
backBuffer[i]->bind();
}
}
void Direct3DSwapChain8::release()
{
delete frameBuffer;
frameBuffer = 0;
for(int i = 0; i < 3; i++)
{
if(backBuffer[i])
{
backBuffer[i]->unbind();
backBuffer[i] = 0;
}
}
}
void Direct3DSwapChain8::screenshot(void *destBuffer)
{
frameBuffer->screenshot(destBuffer);
}
void Direct3DSwapChain8::setGammaRamp(sw::GammaRamp *gammaRamp, bool calibrate)
{
frameBuffer->setGammaRamp(gammaRamp, calibrate);
}
void Direct3DSwapChain8::getGammaRamp(sw::GammaRamp *gammaRamp)
{
frameBuffer->getGammaRamp(gammaRamp);
}
void *Direct3DSwapChain8::lockBackBuffer(int index)
{
return backBuffer[index]->lockInternal(0, 0, 0, sw::LOCK_READWRITE, sw::PUBLIC); // FIXME: External
}
void Direct3DSwapChain8::unlockBackBuffer(int index)
{
backBuffer[index]->unlockInternal(); // FIXME: External
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DSwapChain8_hpp
#define D3D8_Direct3DSwapChain8_hpp
#include "Unknown.hpp"
#include "Direct3DSurface8.hpp"
#include "FrameBufferWin.hpp"
#include <d3d8.h>
namespace D3D8
{
class Direct3DSwapChain8 : public IDirect3DSwapChain8, public Unknown
{
public:
Direct3DSwapChain8(Direct3DDevice8 *device, D3DPRESENT_PARAMETERS *presentParameters);
virtual ~Direct3DSwapChain8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DSwapChain8 methods
long __stdcall Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion);
long __stdcall GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface8 **backBuffer);
// Internal methods
void reset(D3DPRESENT_PARAMETERS *presentParameters);
void screenshot(void *destBuffer);
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
Direct3DDevice8 *const device;
D3DPRESENT_PARAMETERS presentParameters;
bool lockable;
sw::FrameBufferWin *frameBuffer;
public: // FIXME
Direct3DSurface8 *backBuffer[3]; // NOTE: Up to three
};
}
#endif // D3D8_Direct3DSwapChain8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DTexture8.hpp"
#include "Direct3DSurface8.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D8
{
Direct3DTexture8::Direct3DTexture8(Direct3DDevice8 *device, unsigned int width, unsigned int height, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture8(device, D3DRTYPE_TEXTURE, levels, usage), width(width), height(height), format(format), pool(pool)
{
if(levels == 0)
{
this->levels = sw::log2(sw::max((int)width, (int)height, 1)) + 1;
}
for(unsigned int level = 0; level < sw::MIPMAP_LEVELS; level++)
{
if(level < this->levels)
{
surfaceLevel[level] = new Direct3DSurface8(device, this, width, height, format, pool, D3DMULTISAMPLE_NONE, true, usage);
surfaceLevel[level]->bind();
}
else
{
surfaceLevel[level] = 0;
}
width = sw::max(1, (int)width / 2);
height = sw::max(1, (int)height / 2);
}
}
Direct3DTexture8::~Direct3DTexture8()
{
resource->lock(sw::DESTRUCT);
for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
{
if(surfaceLevel[level])
{
surfaceLevel[level]->unbind();
surfaceLevel[level] = 0;
}
}
resource->unlock();
}
long Direct3DTexture8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DTexture8 ||
iid == IID_IDirect3DBaseTexture8 ||
iid == IID_IDirect3DResource8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DTexture8::AddRef()
{
TRACE("");
return Direct3DBaseTexture8::AddRef();
}
unsigned long Direct3DTexture8::Release()
{
TRACE("");
return Direct3DBaseTexture8::Release();
}
long Direct3DTexture8::FreePrivateData(const GUID &guid)
{
TRACE("");
return Direct3DBaseTexture8::FreePrivateData(guid);
}
long Direct3DTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
TRACE("");
return Direct3DBaseTexture8::GetPrivateData(guid, data, size);
}
void Direct3DTexture8::PreLoad()
{
TRACE("");
Direct3DBaseTexture8::PreLoad();
}
long Direct3DTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
return Direct3DBaseTexture8::SetPrivateData(guid, data, size, flags);
}
long Direct3DTexture8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
return Direct3DBaseTexture8::GetDevice(device);
}
unsigned long Direct3DTexture8::SetPriority(unsigned long newPriority)
{
TRACE("");
return Direct3DBaseTexture8::SetPriority(newPriority);
}
unsigned long Direct3DTexture8::GetPriority()
{
TRACE("");
return Direct3DBaseTexture8::GetPriority();
}
D3DRESOURCETYPE Direct3DTexture8::GetType()
{
TRACE("");
return Direct3DBaseTexture8::GetType();
}
unsigned long Direct3DTexture8::GetLevelCount()
{
TRACE("");
return Direct3DBaseTexture8::GetLevelCount();
}
unsigned long Direct3DTexture8::GetLOD()
{
TRACE("");
return Direct3DBaseTexture8::GetLOD();
}
unsigned long Direct3DTexture8::SetLOD(unsigned long newLOD)
{
TRACE("");
return Direct3DBaseTexture8::SetLOD(newLOD);
}
long Direct3DTexture8::GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description)
{
TRACE("");
if(level >= GetLevelCount() || !surfaceLevel[level])
{
return INVALIDCALL();
}
return surfaceLevel[level]->GetDesc(description);
}
long Direct3DTexture8::LockRect(unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags)
{
TRACE("");
if(!lockedRect || level >= GetLevelCount() || !surfaceLevel[level])
{
return INVALIDCALL();
}
return surfaceLevel[level]->LockRect(lockedRect, rect, flags);
}
long Direct3DTexture8::GetSurfaceLevel(unsigned int level, IDirect3DSurface8 **surface)
{
TRACE("");
*surface = 0; // FIXME: Verify
if(level >= GetLevelCount() || !surfaceLevel[level])
{
return INVALIDCALL();
}
surfaceLevel[level]->AddRef();
*surface = surfaceLevel[level];
return D3D_OK;
}
long Direct3DTexture8::UnlockRect(unsigned int level)
{
TRACE("");
if(level >= GetLevelCount() || !surfaceLevel[level])
{
return INVALIDCALL();
}
return surfaceLevel[level]->UnlockRect();
}
long Direct3DTexture8::AddDirtyRect(const RECT *dirtyRect)
{
TRACE("");
// UNIMPLEMENTED();
return D3D_OK;
}
Direct3DSurface8 *Direct3DTexture8::getInternalSurfaceLevel(unsigned int level)
{
return surfaceLevel[level];
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DTexture8_hpp
#define D3D8_Direct3DTexture8_hpp
#include "Direct3DBaseTexture8.hpp"
#include "Direct3DSurface8.hpp"
#include "Config.hpp"
#include <d3d8.h>
namespace D3D8
{
class Direct3DTexture8 : public IDirect3DTexture8, public Direct3DBaseTexture8
{
public:
Direct3DTexture8(Direct3DDevice8 *device, unsigned int width, unsigned int height, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
virtual ~Direct3DTexture8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource8 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(IDirect3DDevice8 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DBaseTexture methods
unsigned long __stdcall GetLevelCount();
unsigned long __stdcall GetLOD();
unsigned long __stdcall SetLOD(unsigned long newLOD);
// IDirect3DTexture8 methods
long __stdcall GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description);
long __stdcall LockRect(unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags);
long __stdcall GetSurfaceLevel(unsigned int level, IDirect3DSurface8 **surface);
long __stdcall UnlockRect(unsigned int level);
long __stdcall AddDirtyRect(const RECT *dirtyRect);
// Internal methods
Direct3DSurface8 *getInternalSurfaceLevel(unsigned int level);
private:
// Creation parameters
const unsigned int width;
const unsigned int height;
const D3DFORMAT format;
const D3DPOOL pool;
Direct3DSurface8 *surfaceLevel[sw::MIPMAP_LEVELS];
};
}
#endif // D3D8_Direct3DTexture8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DVertexBuffer8.hpp"
#include "Direct3DDevice8.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D8
{
Direct3DVertexBuffer8::Direct3DVertexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, long FVF, D3DPOOL pool) : Direct3DResource8(device, D3DRTYPE_VERTEXBUFFER, length), length(length), usage(usage), FVF(FVF), pool(pool)
{
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;
}
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
ASSERT(length % stride == 0); // D3D vertex size calculated incorrectly // FIXME
}
vertexBuffer = new sw::Resource(length + 192 + 1024); // NOTE: Applications can 'overshoot' while writing vertices
}
Direct3DVertexBuffer8::~Direct3DVertexBuffer8()
{
vertexBuffer->destruct();
}
long Direct3DVertexBuffer8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DVertexBuffer8 ||
iid == IID_IDirect3DResource8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DVertexBuffer8::AddRef()
{
TRACE("");
return Direct3DResource8::AddRef();
}
unsigned long Direct3DVertexBuffer8::Release()
{
TRACE("");
return Direct3DResource8::Release();
}
long Direct3DVertexBuffer8::FreePrivateData(const GUID &guid)
{
TRACE("");
return Direct3DResource8::FreePrivateData(guid);
}
long Direct3DVertexBuffer8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
TRACE("");
return Direct3DResource8::GetPrivateData(guid, data, size);
}
void Direct3DVertexBuffer8::PreLoad()
{
TRACE("");
Direct3DResource8::PreLoad();
}
long Direct3DVertexBuffer8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
return Direct3DResource8::SetPrivateData(guid, data, size, flags);
}
long Direct3DVertexBuffer8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
return Direct3DResource8::GetDevice(device);
}
unsigned long Direct3DVertexBuffer8::SetPriority(unsigned long newPriority)
{
TRACE("");
return Direct3DResource8::SetPriority(newPriority);
}
unsigned long Direct3DVertexBuffer8::GetPriority()
{
TRACE("");
return Direct3DResource8::GetPriority();
}
D3DRESOURCETYPE Direct3DVertexBuffer8::GetType()
{
TRACE("");
return Direct3DResource8::GetType();
}
long Direct3DVertexBuffer8::Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags)
{
TRACE("");
if(offset == 0 && size == 0) // Lock whole buffer
{
size = length;
}
if(!data || offset + size > length)
{
return INVALIDCALL();
}
lockOffset = offset;
lockSize = size;
*data = (unsigned char*)vertexBuffer->lock(sw::PUBLIC) + offset;
vertexBuffer->unlock();
return D3D_OK;
}
long Direct3DVertexBuffer8::Unlock()
{
TRACE("");
return D3D_OK;
}
long Direct3DVertexBuffer8::GetDesc(D3DVERTEXBUFFER_DESC *description)
{
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 Direct3DVertexBuffer8::getLength() const
{
return length;
}
sw::Resource *Direct3DVertexBuffer8::getResource() const
{
return vertexBuffer;
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DVertexBuffer8_hpp
#define D3D8_Direct3DVertexBuffer8_hpp
#include "Direct3DResource8.hpp"
#include <d3d8.h>
namespace sw
{
class Resource;
}
namespace D3D8
{
class Direct3DVertexBuffer8 : public IDirect3DVertexBuffer8, public Direct3DResource8
{
public:
Direct3DVertexBuffer8(Direct3DDevice8 *device, unsigned int length, unsigned long usage, long FVF, D3DPOOL pool);
virtual ~Direct3DVertexBuffer8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource8 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(IDirect3DDevice8 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DVertexBuffer8 methods
long __stdcall Lock(unsigned int offset, unsigned int size, unsigned char **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;
const D3DPOOL pool;
unsigned int lockOffset;
unsigned int lockSize;
unsigned char *lockData;
sw::Resource *vertexBuffer;
};
}
#endif // D3D8_Direct3DVertexBuffer8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DVertexDeclaration8.hpp"
#include "Debug.hpp"
#include <d3d8types.h>
namespace D3D8
{
Direct3DVertexDeclaration8::Direct3DVertexDeclaration8(Direct3DDevice8 *device, const unsigned long *vertexElement) : device(device)
{
int size = sizeof(unsigned long);
const unsigned long *element = vertexElement;
while(*element != 0xFFFFFFFF)
{
size += sizeof(unsigned long);
element++;
}
declaration = new unsigned long[size / sizeof(unsigned long)];
memcpy(declaration, vertexElement, size);
}
Direct3DVertexDeclaration8::~Direct3DVertexDeclaration8()
{
delete[] declaration;
declaration = 0;
}
long Direct3DVertexDeclaration8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
ASSERT(false); // Internal object
return NOINTERFACE(iid);
}
unsigned long Direct3DVertexDeclaration8::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DVertexDeclaration8::Release()
{
TRACE("");
return Unknown::Release();
}
const unsigned long *Direct3DVertexDeclaration8::getDeclaration() const
{
return declaration;
}
}
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DVertexDeclaration8_hpp
#define D3D8_Direct3DVertexDeclaration8_hpp
#include "Unknown.hpp"
#include <d3d8.h>
namespace D3D8
{
class Direct3DDevice8;
class Direct3DVertexDeclaration8 : protected Unknown
{
public:
Direct3DVertexDeclaration8(Direct3DDevice8 *device, const unsigned long *vertexElements);
virtual ~Direct3DVertexDeclaration8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// Internal methods
const unsigned long *getDeclaration() const;
private:
// Creation parameters
Direct3DDevice8 *const device;
unsigned long *declaration;
};
}
#endif // D3D8_Direct3DVertexDeclaration8_hpp
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DVertexShader8.hpp"
#include "Debug.hpp"
namespace D3D8
{
Direct3DVertexShader8::Direct3DVertexShader8(Direct3DDevice8 *device, const unsigned long *declaration, const unsigned long *shaderToken) : device(device)
{
if(shaderToken)
{
vertexShader = new sw::VertexShader(shaderToken);
const unsigned long *token = shaderToken;
size = 0;
while(shaderToken[size] != 0x0000FFFF)
{
size++;
}
size++;
this->shaderToken = new unsigned long[size];
memcpy(this->shaderToken, shaderToken, size * sizeof(unsigned long));
}
else
{
vertexShader = 0;
this->shaderToken = 0;
}
this->declaration = new Direct3DVertexDeclaration8(device, declaration);
}
Direct3DVertexShader8::~Direct3DVertexShader8()
{
delete vertexShader;
vertexShader = 0;
delete[] shaderToken;
shaderToken = 0;
declaration->Release();
}
long Direct3DVertexShader8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
ASSERT(false); // Internal object
return NOINTERFACE(iid);
}
unsigned long Direct3DVertexShader8::AddRef()
{
TRACE("");
return Unknown::AddRef();
}
unsigned long Direct3DVertexShader8::Release()
{
TRACE("");
return Unknown::Release();
}
const sw::VertexShader *Direct3DVertexShader8::getVertexShader() const
{
return vertexShader;
}
const unsigned long *Direct3DVertexShader8::getDeclaration()
{
return declaration->getDeclaration();
}
}
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DVertexShader8_hpp
#define D3D8_Direct3DVertexShader8_hpp
#include "VertexShader.hpp"
#include "Direct3DVertexDeclaration8.hpp"
#include "Unknown.hpp"
namespace D3D8
{
class Direct3DDevice8;
class Direct3DVertexShader8 : public Unknown
{
public:
Direct3DVertexShader8(Direct3DDevice8 *device, const unsigned long *declaration, const unsigned long *shaderToken);
virtual ~Direct3DVertexShader8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// Internal methods
const sw::VertexShader *getVertexShader() const;
const unsigned long *getDeclaration();
private:
// Creation parameters
Direct3DDevice8 *const device;
Direct3DVertexDeclaration8 *declaration;
unsigned long *shaderToken;
unsigned int size;
sw::VertexShader *vertexShader;
};
}
#endif // D3D8_Direct3DVertexShader8_hpp
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DVolume8.hpp"
#include "Direct3DResource8.hpp"
#include "Direct3DVolumeTexture8.hpp"
#include "Direct3DSurface8.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D8
{
Direct3DVolume8::Direct3DVolume8(Direct3DDevice8 *device, Direct3DVolumeTexture8 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, bool lockable, unsigned long usage) : Surface(container->getResource(), width, height, depth, translateFormat(format), lockable, false), container(container), width(width), height(height), depth(depth), format(format), pool(pool), lockable(lockable), usage(usage)
{
resource = new Direct3DResource8(device, D3DRTYPE_VOLUME, memoryUsage(width, height, depth, format));
}
Direct3DVolume8::~Direct3DVolume8()
{
resource->Release();
}
long __stdcall Direct3DVolume8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DVolume8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long __stdcall Direct3DVolume8::AddRef()
{
TRACE("");
return container->AddRef();
}
unsigned long __stdcall Direct3DVolume8::Release()
{
TRACE("");
return container->Release();
}
long Direct3DVolume8::FreePrivateData(const GUID &guid)
{
TRACE("");
return resource->FreePrivateData(guid);
}
long Direct3DVolume8::GetContainer(const IID &iid, void **container)
{
TRACE("");
if(!container)
{
return INVALIDCALL();
}
long result = this->container->QueryInterface(iid, container);
if(result == S_OK)
{
return D3D_OK;
}
return INVALIDCALL();
}
long Direct3DVolume8::GetDesc(D3DVOLUME_DESC *description)
{
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 Direct3DVolume8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
return resource->GetDevice(device);
}
long Direct3DVolume8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
TRACE("");
return resource->GetPrivateData(guid, data, size);
}
long Direct3DVolume8::LockBox(D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags)
{
TRACE("");
if(!lockedVolume)
{
return INVALIDCALL();
}
lockedVolume->RowPitch = pitchB(getWidth(), getExternalFormat(), false);
lockedVolume->SlicePitch = sliceB(getWidth(), getHeight(), getExternalFormat(), false);
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);
}
unlockExternal();
return D3D_OK;
}
long Direct3DVolume8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
return SetPrivateData(guid, data, size, flags);
}
long Direct3DVolume8::UnlockBox()
{
TRACE("");
return D3D_OK;
}
sw::Format Direct3DVolume8::translateFormat(D3DFORMAT format)
{
return Direct3DSurface8::translateFormat(format);
}
unsigned int Direct3DVolume8::memoryUsage(int width, int height, int depth, D3DFORMAT format)
{
return Surface::size(width, height, depth, translateFormat(format));
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DVolume8_hpp
#define D3D8_Direct3DVolume8_hpp
#include "Unknown.hpp"
#include "Surface.hpp"
#include <d3d8.h>
namespace D3D8
{
class Direct3DDevice8;
class Direct3DResource8;
class Direct3DVolumeTexture8;
class Direct3DVolume8 : public IDirect3DVolume8, public Unknown, public sw::Surface
{
public:
Direct3DVolume8(Direct3DDevice8 *device, Direct3DVolumeTexture8 *container, int width, int height, int depth, D3DFORMAT format, D3DPOOL pool, bool locakble, unsigned long usage);
virtual ~Direct3DVolume8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DVolume8 methods
long __stdcall FreePrivateData(const GUID &guid);
long __stdcall GetContainer(const IID &iid, void **container);
long __stdcall GetDesc(D3DVOLUME_DESC *description);
long __stdcall GetDevice(IDirect3DDevice8 **device);
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size);
long __stdcall LockBox(D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags);
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags);
long __stdcall UnlockBox();
private:
static sw::Format translateFormat(D3DFORMAT format);
static unsigned int memoryUsage(int width, int height, int depth, D3DFORMAT format);
// Creation parameters
Direct3DVolumeTexture8 *const container;
const int width;
const int height;
const int depth;
const D3DFORMAT format;
const D3DPOOL pool;
const bool lockable;
const unsigned long usage;
Direct3DResource8 *resource;
};
}
#endif // D3D8_Direct3DVolume8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Direct3DVolumeTexture8.hpp"
#include "Direct3DVolume8.hpp"
#include "Resource.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D8
{
Direct3DVolumeTexture8::Direct3DVolumeTexture8(Direct3DDevice8 *device, unsigned int width, unsigned int height, unsigned int depth, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool) : Direct3DBaseTexture8(device, D3DRTYPE_VOLUMETEXTURE, levels, usage), width(width), height(height), depth(depth), format(format), pool(pool)
{
if(levels == 0)
{
this->levels = sw::log2(sw::max((int)width, (int)height, (int)depth, 1)) + 1;
}
for(unsigned int level = 0; level < sw::MIPMAP_LEVELS; level++)
{
if(level < this->levels)
{
volumeLevel[level] = new Direct3DVolume8(device, this, width, height, depth, format, pool, true, usage);
volumeLevel[level]->bind();
}
else
{
volumeLevel[level] = 0;
}
width = sw::max(1, (int)width / 2);
height = sw::max(1, (int)height / 2);
depth = sw::max(1, (int)depth / 2);
}
}
Direct3DVolumeTexture8::~Direct3DVolumeTexture8()
{
resource->lock(sw::DESTRUCT);
for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
{
if(volumeLevel[level])
{
volumeLevel[level]->unbind();
volumeLevel[level] = 0;
}
}
resource->unlock();
}
long Direct3DVolumeTexture8::QueryInterface(const IID &iid, void **object)
{
TRACE("");
if(iid == IID_IDirect3DVolumeTexture8 ||
iid == IID_IDirect3DBaseTexture8 ||
iid == IID_IDirect3DResource8 ||
iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Direct3DVolumeTexture8::AddRef()
{
TRACE("");
return Direct3DBaseTexture8::AddRef();
}
unsigned long Direct3DVolumeTexture8::Release()
{
TRACE("");
return Direct3DBaseTexture8::Release();
}
long Direct3DVolumeTexture8::FreePrivateData(const GUID &guid)
{
TRACE("");
return Direct3DBaseTexture8::FreePrivateData(guid);
}
long Direct3DVolumeTexture8::GetPrivateData(const GUID &guid, void *data, unsigned long *size)
{
TRACE("");
return Direct3DBaseTexture8::GetPrivateData(guid, data, size);
}
void Direct3DVolumeTexture8::PreLoad()
{
TRACE("");
Direct3DBaseTexture8::PreLoad();
}
long Direct3DVolumeTexture8::SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags)
{
TRACE("");
return Direct3DBaseTexture8::SetPrivateData(guid, data, size, flags);
}
long Direct3DVolumeTexture8::GetDevice(IDirect3DDevice8 **device)
{
TRACE("");
return Direct3DBaseTexture8::GetDevice(device);
}
unsigned long Direct3DVolumeTexture8::SetPriority(unsigned long newPriority)
{
TRACE("");
return Direct3DBaseTexture8::SetPriority(newPriority);
}
unsigned long Direct3DVolumeTexture8::GetPriority()
{
TRACE("");
return Direct3DBaseTexture8::GetPriority();
}
D3DRESOURCETYPE Direct3DVolumeTexture8::GetType()
{
TRACE("");
return Direct3DBaseTexture8::GetType();
}
unsigned long Direct3DVolumeTexture8::GetLevelCount()
{
TRACE("");
return Direct3DBaseTexture8::GetLevelCount();
}
unsigned long Direct3DVolumeTexture8::GetLOD()
{
TRACE("");
return Direct3DBaseTexture8::GetLOD();
}
unsigned long Direct3DVolumeTexture8::SetLOD(unsigned long newLOD)
{
TRACE("");
return Direct3DBaseTexture8::SetLOD(newLOD);
}
long Direct3DVolumeTexture8::GetVolumeLevel(unsigned int level, IDirect3DVolume8 **volume)
{
TRACE("");
*volume = 0; // FIXME: Verify
if(level >= GetLevelCount() || !volumeLevel[level])
{
return INVALIDCALL();
}
volumeLevel[level]->AddRef();
*volume = volumeLevel[level];
return D3D_OK;
}
long Direct3DVolumeTexture8::LockBox(unsigned int level, D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags)
{
TRACE("");
if(!lockedVolume || level >= GetLevelCount() || !volumeLevel[level])
{
return INVALIDCALL();
}
return volumeLevel[level]->LockBox(lockedVolume, box, flags);
}
long Direct3DVolumeTexture8::UnlockBox(unsigned int level)
{
TRACE("");
if(level >= GetLevelCount() || !volumeLevel[level])
{
return INVALIDCALL();
}
return volumeLevel[level]->UnlockBox();
}
long Direct3DVolumeTexture8::AddDirtyBox(const D3DBOX *dirtyBox)
{
TRACE("");
if(!dirtyBox)
{
return INVALIDCALL();
}
UNIMPLEMENTED();
return D3D_OK;
}
long Direct3DVolumeTexture8::GetLevelDesc(unsigned int level, D3DVOLUME_DESC *description)
{
TRACE("");
if(!description || level >= GetLevelCount() || !volumeLevel[level])
{
return INVALIDCALL();
}
volumeLevel[level]->GetDesc(description);
return D3D_OK;
}
Direct3DVolume8 *Direct3DVolumeTexture8::getInternalVolumeLevel(unsigned int level)
{
return volumeLevel[level];
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Direct3DVolumeTexture8_hpp
#define D3D8_Direct3DVolumeTexture8_hpp
#include "Direct3DBaseTexture8.hpp"
#include "Config.hpp"
#include <d3d8.h>
namespace D3D8
{
class Direct3DVolume8;
class Direct3DVolumeTexture8 : public IDirect3DVolumeTexture8, public Direct3DBaseTexture8
{
public:
Direct3DVolumeTexture8(Direct3DDevice8 *device, unsigned int width, unsigned int height, unsigned int depth, unsigned int levels, unsigned long usage, D3DFORMAT format, D3DPOOL pool);
virtual ~Direct3DVolumeTexture8();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IDirect3DResource8 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(IDirect3DDevice8 **device);
unsigned long __stdcall SetPriority(unsigned long newPriority);
unsigned long __stdcall GetPriority();
D3DRESOURCETYPE __stdcall GetType();
// IDirect3DBaseTexture methods
unsigned long __stdcall GetLevelCount();
unsigned long __stdcall GetLOD();
unsigned long __stdcall SetLOD(unsigned long newLOD);
// IDirect3DVolumeTexture8 methods
long __stdcall GetLevelDesc(unsigned int level, D3DVOLUME_DESC *description);
long __stdcall GetVolumeLevel(unsigned int level, IDirect3DVolume8 **volume);
long __stdcall LockBox(unsigned int level, D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags);
long __stdcall UnlockBox(unsigned int level);
long __stdcall AddDirtyBox(const D3DBOX *dirtyBox);
// Internal methods
Direct3DVolume8 *getInternalVolumeLevel(unsigned int level);
private:
// Creation parameters
const unsigned int width;
const unsigned int height;
const unsigned int depth;
const D3DFORMAT format;
const D3DPOOL pool;
Direct3DVolume8 *volumeLevel[sw::MIPMAP_LEVELS];
};
}
#endif // D3D8_Direct3DVolumeTexture8_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Unknown.hpp"
#include "Debug.hpp"
#include <assert.h>
namespace D3D8
{
Unknown::Unknown()
{
referenceCount = 0;
bindCount = 0;
}
Unknown::~Unknown()
{
ASSERT(referenceCount == 0);
ASSERT(bindCount == 0);
}
long Unknown::QueryInterface(const IID &iid, void **object)
{
if(iid == IID_IUnknown)
{
AddRef();
*object = this;
return S_OK;
}
*object = 0;
return NOINTERFACE(iid);
}
unsigned long Unknown::AddRef()
{
return InterlockedIncrement(&referenceCount);
}
unsigned long Unknown::Release()
{
int current = referenceCount;
if(referenceCount > 0)
{
current = InterlockedDecrement(&referenceCount);
}
if(referenceCount == 0 && bindCount == 0)
{
delete this;
}
return current;
}
void Unknown::bind()
{
InterlockedIncrement(&bindCount);
}
void Unknown::unbind()
{
ASSERT(bindCount > 0);
InterlockedDecrement(&bindCount);
if(referenceCount == 0 && bindCount == 0)
{
delete this;
}
}
}
\ No newline at end of file
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef D3D8_Unknown_hpp
#define D3D8_Unknown_hpp
#include <unknwn.h>
namespace D3D8
{
class Unknown : IUnknown
{
public:
Unknown();
virtual ~Unknown();
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// Internal methods
virtual void bind();
virtual void unbind();
private:
volatile long referenceCount;
volatile long bindCount;
};
}
#endif // D3D8_Unknown_hpp
LIBRARY D3D8
EXPORTS
CheckFullscreen @1
DebugSetMute @4
Direct3DCreate8 @5
ValidatePixelShader @2
ValidateVertexShader @3
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by D3D8-dll.rc
//
#define IDD_DIALOG1 104
#define IDD_DIALOG2 105
#define IDC_CHECK1 1001
#define IDC_SLIDER1 1002
#define IDC_CHECK2 1003
#define IDC_PROGRESS2 1006
#define IDC_PROGRESS3 1007
#define IDC_PROGRESS4 1008
#define IDC_PROGRESS5 1009
#define IDC_DATETIMEPICKER1 1011
#define IDC_CHECK3 1012
#define IDC_EDIT1 1013
#define IDC_EDIT2 1014
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 106
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1015
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by D3D8.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// //
// Generated from the TEXTINCLUDE 2 resource. // Generated from the TEXTINCLUDE 2 resource.
// //
#include "windows.h" #include "Windows.h"
#include "../Common/Version.h" #include "../Common/Version.h"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS #undef APSTUDIO_READONLY_SYMBOLS
......
...@@ -343,7 +343,7 @@ namespace D3D9 ...@@ -343,7 +343,7 @@ namespace D3D9
TRACE("unsigned long count = %d, const D3DRECT *rects = 0x%0.8p, unsigned long flags = 0x%0.8X, unsigned long color = 0x%0.8X, float z = %f, unsigned long stencil = %d", count, rects, flags, color, z, stencil); TRACE("unsigned long count = %d, const D3DRECT *rects = 0x%0.8p, unsigned long flags = 0x%0.8X, unsigned long color = 0x%0.8X, float z = %f, unsigned long stencil = %d", count, rects, flags, color, z, stencil);
if(rects == 0 && count != 0) if(!rects && count != 0)
{ {
return INVALIDCALL(); return INVALIDCALL();
} }
......
...@@ -184,7 +184,7 @@ namespace D3D9 ...@@ -184,7 +184,7 @@ namespace D3D9
dRect.y1 = destRect->bottom; dRect.y1 = destRect->bottom;
} }
frameBuffer->blit(window, source, sourceRect ? &sRect : 0, destRect ? &dRect : 0, format, stride); frameBuffer->blit(window, source, sourceRect ? &sRect : nullptr, destRect ? &dRect : nullptr, format, stride);
} }
backBuffer[0]->unlockInternal(); // FIXME: External backBuffer[0]->unlockInternal(); // FIXME: External
......
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