Commit f99302c4 by Nicolas Capens Committed by Nicolas Capens

Remove the D3D9 and D3D8 source code

This code has no remaining known active uses. It has been archived in the 'legacy-d3d9' branch. Bug: b/139189696 Change-Id: I64bf27ff6c02be560963d7eab36c9c328bb280c5 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43232Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 498499b4
......@@ -5,7 +5,7 @@
Introduction
------------
SwiftShader is a high-performance CPU-based implementation of the Vulkan, OpenGL ES, and Direct3D 9 graphics APIs<sup>1</sup><sup>2</sup>. Its goal is to provide hardware independence for advanced 3D graphics.
SwiftShader is a high-performance CPU-based implementation of the Vulkan and OpenGL ES graphics APIs<sup>1</sup><sup>2</sup>. Its goal is to provide hardware independence for advanced 3D graphics.
Building
--------
......@@ -108,5 +108,5 @@ Disclaimer
----------
1. Trademarks are the property of their respective owners.
2. We do not claim official conformance with the Direct3D and OpenGL graphics APIs at this moment.
2. We do not claim official conformance with the OpenGL graphics API at this moment.
3. This is not an official Google product.
// 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
/////////////////////////////////////////////////////////////////////////////
// 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 "Debug.hpp"
int Trace::indent = 0;
// 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>
#define APPEND(x, y) x ## y
#define MACRO_APPEND(x, y) APPEND(x, y)
#define UNIQUE_IDENTIFIER(prefix) MACRO_APPEND(prefix, __COUNTER__)
struct Trace
{
Trace(const char *format, ...)
{
if(false)
{
FILE *file = fopen("debug.txt", "a");
if(file)
{
for(int i = 0; i < indent; i++) fprintf(file, " ");
va_list vararg;
va_start(vararg, format);
vfprintf(file, format, vararg);
va_end(vararg);
fclose(file);
}
}
indent++;
}
~Trace()
{
indent--;
}
static int indent;
};
#ifndef NDEBUG
#define TRACE(format, ...) Trace UNIQUE_IDENTIFIER(_tracer_)("[0x%0.8X]%s("format")\n", this, __FUNCTION__, __VA_ARGS__)
#define GTRACE(format, ...) Trace("%s("format")\n", __FUNCTION__, __VA_ARGS__)
#else
#define TRACE(...) ((void)0)
#define GTRACE(...) ((void)0)
#endif
#ifndef NDEBUG
#define ASSERT(expression) {if(!(expression)) Trace("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); assert(expression);}
#else
#define ASSERT assert
#endif
#ifndef NDEBUG
#define UNIMPLEMENTED() {Trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}
#else
#define UNIMPLEMENTED() ((void)0)
#endif
#ifndef NDEBUG
#define NOINTERFACE(iid) _NOINTERFACE(__FUNCTION__, iid)
inline long _NOINTERFACE(const char *function, const IID &iid)
{
Trace("\t! No interface {0x%0.8X, 0x%0.4X, 0x%0.4X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X, 0x%0.2X} for %s\n", iid.Data1, iid.Data2, iid.Data3, iid.Data4[0], iid.Data4[1], iid.Data4[2], iid.Data4[3], iid.Data4[4], iid.Data4[5], iid.Data4[6], iid.Data4[7], function);
return E_NOINTERFACE;
}
#else
#define NOINTERFACE(iid) E_NOINTERFACE
#endif
#ifndef NDEBUG
inline long INVALIDCALL()
{
Trace("\t! D3DERR_INVALIDCALL\n");
return D3DERR_INVALIDCALL;
}
#else
#define INVALIDCALL() D3DERR_INVALIDCALL
#endif
#ifndef NDEBUG
inline long OUTOFMEMORY()
{
Trace("\t! E_OUTOFMEMORY\n");
return E_OUTOFMEMORY;
}
#else
#define OUTOFMEMORY() E_OUTOFMEMORY
#endif
#ifndef NDEBUG
inline long OUTOFVIDEOMEMORY()
{
Trace("\t! D3DERR_OUTOFVIDEOMEMORY\n");
return D3DERR_OUTOFVIDEOMEMORY;
}
#else
#define OUTOFVIDEOMEMORY() D3DERR_OUTOFVIDEOMEMORY
#endif
#ifndef NDEBUG
inline long NOTAVAILABLE()
{
Trace("\t! D3DERR_NOTAVAILABLE\n");
return D3DERR_NOTAVAILABLE;
}
#else
#define NOTAVAILABLE() D3DERR_NOTAVAILABLE
#endif
#ifndef NDEBUG
inline long NOTFOUND()
{
Trace("\t! D3DERR_NOTFOUND\n");
return D3DERR_NOTFOUND;
}
#else
#define NOTFOUND() D3DERR_NOTFOUND
#endif
#ifndef NDEBUG
inline long MOREDATA()
{
Trace("\t! D3DERR_MOREDATA\n");
return D3DERR_MOREDATA;
}
#else
#define MOREDATA() D3DERR_MOREDATA
#endif
#ifndef NDEBUG
inline long FAIL()
{
Trace("\t! E_FAIL\n");
return E_FAIL;
}
#else
#define FAIL() E_FAIL
#endif
#endif // Debug_hpp
// 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);
~Direct3D8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3D8 methods
long __stdcall CheckDepthStencilMatch(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapterFormat, D3DFORMAT renderTargetFormat, D3DFORMAT depthStencilFormat) override;
long __stdcall CheckDeviceFormat(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT adapaterFormat, unsigned long usage, D3DRESOURCETYPE type, D3DFORMAT checkFormat) override;
long __stdcall CheckDeviceMultiSampleType(unsigned int adapter, D3DDEVTYPE deviceType, D3DFORMAT surfaceFormat, int windowed, D3DMULTISAMPLE_TYPE multiSampleType) override;
long __stdcall CheckDeviceType(unsigned int adapter, D3DDEVTYPE checkType, D3DFORMAT displayFormat, D3DFORMAT backBufferFormat, int windowed) override;
long __stdcall CreateDevice(unsigned int adapter, D3DDEVTYPE deviceType, HWND focusWindow, unsigned long behaviorFlags, D3DPRESENT_PARAMETERS *presentParameters, IDirect3DDevice8 **returnedDeviceInterface) override;
long __stdcall EnumAdapterModes(unsigned int adapter, unsigned int index, D3DDISPLAYMODE *mode) override;
unsigned int __stdcall GetAdapterCount() override;
long __stdcall GetAdapterDisplayMode(unsigned int adapter, D3DDISPLAYMODE *mode) override;
long __stdcall GetAdapterIdentifier(unsigned int adapter, unsigned long flags, D3DADAPTER_IDENTIFIER8 *identifier) override;
unsigned int __stdcall GetAdapterModeCount(unsigned int adapter) override;
HMONITOR __stdcall GetAdapterMonitor(unsigned int adapter) override;
long __stdcall GetDeviceCaps(unsigned int adapter, D3DDEVTYPE deviceType, D3DCAPS8 *caps) override;
long __stdcall RegisterSoftwareDevice(void *initializeFunction) override;
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;
}
unsigned long Direct3DBaseTexture8::SetLOD(unsigned 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);
~Direct3DBaseTexture8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DResource8 methods
long __stdcall FreePrivateData(const GUID &guid) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
void __stdcall PreLoad() override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
unsigned long __stdcall SetPriority(unsigned long newPriority) override;
unsigned long __stdcall GetPriority() override;
D3DRESOURCETYPE __stdcall GetType() override;
// IDirect3DBaseTexture8 methods
unsigned long __stdcall GetLevelCount() override;
unsigned long __stdcall GetLOD() override;
unsigned long __stdcall SetLOD(unsigned long newLOD) override;
// 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()
{
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;
}
}
}
}
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);
~Direct3DCubeTexture8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DResource8 methods
long __stdcall FreePrivateData(const GUID &guid) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
void __stdcall PreLoad() override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
unsigned long __stdcall SetPriority(unsigned long newPriority) override;
unsigned long __stdcall GetPriority() override;
D3DRESOURCETYPE __stdcall GetType() override;
// IDirect3DBaseTexture methods
unsigned long __stdcall GetLevelCount() override;
unsigned long __stdcall GetLOD() override;
unsigned long __stdcall SetLOD(unsigned long newLOD) override;
// IDirect3DCubeTexture8 methods
long __stdcall AddDirtyRect(D3DCUBEMAP_FACES face, const RECT *dirtyRect) override;
long __stdcall GetCubeMapSurface(D3DCUBEMAP_FACES face, unsigned int level , IDirect3DSurface8 **cubeMapSurface) override;
long __stdcall GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description) override;
long __stdcall LockRect(D3DCUBEMAP_FACES face, unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags) override;
long __stdcall UnlockRect(D3DCUBEMAP_FACES face, unsigned int level) override;
// 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);
~Direct3DIndexBuffer8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DResource8 methods
long __stdcall FreePrivateData(const GUID &guid) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
void __stdcall PreLoad() override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
unsigned long __stdcall SetPriority(unsigned long newPriority) override;
unsigned long __stdcall GetPriority() override;
D3DRESOURCETYPE __stdcall GetType() override;
// IDirect3DIndexBuffer8 methods
long __stdcall GetDesc(D3DINDEXBUFFER_DESC *description) override;
long __stdcall Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags) override;
long __stdcall Unlock() override;
// 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);
~Direct3DPixelShader8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
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);
~Direct3DResource8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DResource8 methods
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
long __stdcall FreePrivateData(const GUID &guid) override;
unsigned long __stdcall SetPriority(unsigned long newPriority) override;
unsigned long __stdcall GetPriority() override;
void __stdcall PreLoad() override;
D3DRESOURCETYPE __stdcall GetType() override;
// 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);
~Direct3DStateBlock8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
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, 1, 0, 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, multiSample, format));
}
Direct3DSurface8::~Direct3DSurface8()
{
resource->Release();
}
void *Direct3DSurface8::lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)
{
return Surface::lockInternal(x, y, z, lock, client);
}
void Direct3DSurface8::unlockInternal()
{
Surface::unlockInternal();
}
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 = memoryUsage(width, height, multiSample, format);
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, D3DMULTISAMPLE_TYPE multiSample, D3DFORMAT format)
{
return Surface::size(width, height, 1, 0, sampleCount(multiSample), 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);
~Direct3DSurface8() override;
// Surface methods
void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client) override;
void unlockInternal() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DSurface8 methods
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
long __stdcall FreePrivateData(const GUID &guid) override;
long __stdcall GetContainer(const IID &iid, void **container) override;
long __stdcall GetDesc(D3DSURFACE_DESC *desc) override;
long __stdcall LockRect(D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long Flags) override;
long __stdcall UnlockRect() override;
// Internal methods
static sw::Format translateFormat(D3DFORMAT format);
static int bytes(D3DFORMAT format);
private:
static unsigned int memoryUsage(int width, int height, D3DMULTISAMPLE_TYPE multiSample, 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
if(!sourceRect && !destRect) // FIXME: More cases?
{
frameBuffer->flip(destWindowOverride, backBuffer[0]);
}
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, backBuffer[0], sourceRect ? &sRect : nullptr, destRect ? &dRect : nullptr);
}
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);
~Direct3DSwapChain8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DSwapChain8 methods
long __stdcall Present(const RECT *sourceRect, const RECT *destRect, HWND destWindowOverride, const RGNDATA *dirtyRegion) override;
long __stdcall GetBackBuffer(unsigned int index, D3DBACKBUFFER_TYPE type, IDirect3DSurface8 **backBuffer) override;
// 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()
{
for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
{
if(surfaceLevel[level])
{
surfaceLevel[level]->unbind();
surfaceLevel[level] = 0;
}
}
}
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);
~Direct3DTexture8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DResource8 methods
long __stdcall FreePrivateData(const GUID &guid) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
void __stdcall PreLoad() override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
unsigned long __stdcall SetPriority(unsigned long newPriority) override;
unsigned long __stdcall GetPriority() override;
D3DRESOURCETYPE __stdcall GetType() override;
// IDirect3DBaseTexture methods
unsigned long __stdcall GetLevelCount() override;
unsigned long __stdcall GetLOD() override;
unsigned long __stdcall SetLOD(unsigned long newLOD) override;
// IDirect3DTexture8 methods
long __stdcall GetLevelDesc(unsigned int level, D3DSURFACE_DESC *description) override;
long __stdcall LockRect(unsigned int level, D3DLOCKED_RECT *lockedRect, const RECT *rect, unsigned long flags) override;
long __stdcall GetSurfaceLevel(unsigned int level, IDirect3DSurface8 **surface) override;
long __stdcall UnlockRect(unsigned int level) override;
long __stdcall AddDirtyRect(const RECT *dirtyRect) override;
// 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);
~Direct3DVertexBuffer8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DResource8 methods
long __stdcall FreePrivateData(const GUID &guid) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
void __stdcall PreLoad() override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
unsigned long __stdcall SetPriority(unsigned long newPriority) override;
unsigned long __stdcall GetPriority() override;
D3DRESOURCETYPE __stdcall GetType() override;
// IDirect3DVertexBuffer8 methods
long __stdcall Lock(unsigned int offset, unsigned int size, unsigned char **data, unsigned long flags) override;
long __stdcall Unlock() override;
long __stdcall GetDesc(D3DVERTEXBUFFER_DESC *description) override;
// 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);
~Direct3DVertexDeclaration8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// 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);
~Direct3DVertexShader8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// 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, 0, 1, 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();
}
void *Direct3DVolume8::lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)
{
return Surface::lockInternal(x, y, z, lock, client);
}
void Direct3DVolume8::unlockInternal()
{
Surface::unlockInternal();
}
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(), 0, getExternalFormat(), false);
lockedVolume->SlicePitch = sliceB(getWidth(), getHeight(), 0, 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, 0, 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_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);
~Direct3DVolume8() override;
// Surface methods
void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client) override;
void unlockInternal() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DVolume8 methods
long __stdcall FreePrivateData(const GUID &guid) override;
long __stdcall GetContainer(const IID &iid, void **container) override;
long __stdcall GetDesc(D3DVOLUME_DESC *description) override;
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
long __stdcall LockBox(D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags) override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall UnlockBox() override;
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()
{
for(int level = 0; level < sw::MIPMAP_LEVELS; level++)
{
if(volumeLevel[level])
{
volumeLevel[level]->unbind();
volumeLevel[level] = 0;
}
}
}
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);
~Direct3DVolumeTexture8() override;
// IUnknown methods
long __stdcall QueryInterface(const IID &iid, void **object) override;
unsigned long __stdcall AddRef() override;
unsigned long __stdcall Release() override;
// IDirect3DResource8 methods
long __stdcall FreePrivateData(const GUID &guid) override;
long __stdcall GetPrivateData(const GUID &guid, void *data, unsigned long *size) override;
void __stdcall PreLoad() override;
long __stdcall SetPrivateData(const GUID &guid, const void *data, unsigned long size, unsigned long flags) override;
long __stdcall GetDevice(IDirect3DDevice8 **device) override;
unsigned long __stdcall SetPriority(unsigned long newPriority) override;
unsigned long __stdcall GetPriority() override;
D3DRESOURCETYPE __stdcall GetType() override;
// IDirect3DBaseTexture methods
unsigned long __stdcall GetLevelCount() override;
unsigned long __stdcall GetLOD() override;
unsigned long __stdcall SetLOD(unsigned long newLOD) override;
// IDirect3DVolumeTexture8 methods
long __stdcall GetLevelDesc(unsigned int level, D3DVOLUME_DESC *description) override;
long __stdcall GetVolumeLevel(unsigned int level, IDirect3DVolume8 **volume) override;
long __stdcall LockBox(unsigned int level, D3DLOCKED_BOX *lockedVolume, const D3DBOX *box, unsigned long flags) override;
long __stdcall UnlockBox(unsigned int level) override;
long __stdcall AddDirtyBox(const D3DBOX *dirtyBox) override;
// 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
// 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 "Direct3D9.hpp"
#include "Direct3D9Ex.hpp"
#include "Debug.hpp"
#include "resource.h"
#include <stdio.h>
#include <assert.h>
namespace D3D9
{
class Direct3DShaderValidator9
{
public:
Direct3DShaderValidator9();
virtual ~Direct3DShaderValidator9();
virtual int __stdcall ValidateShader(long *shader, long *shader1, long *shader2, long *shader3);
virtual int __stdcall ValidateShader2(long *shader);
virtual int __stdcall ValidateShader3(long *shader, long *shader1, long *shader2, long *shader3);
virtual int __stdcall ValidateShader4(long *shader, long *shader1, long *shader2, long *shader3);
virtual int __stdcall ValidateShader5(long *shader, long *shader1, long *shader2);
virtual int __stdcall ValidateShader6(long *shader, long *shader1, long *shader2, long *shader3);
};
Direct3DShaderValidator9::Direct3DShaderValidator9()
{
}
Direct3DShaderValidator9::~Direct3DShaderValidator9()
{
}
int __stdcall Direct3DShaderValidator9::ValidateShader(long *shader, long *shader1, long *shader2, long *shader3) // FIXME
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader2(long *shader) // FIXME
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader3(long *shader, long *shader1, long *shader2, long *shader3)
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader4(long *shader, long *shader1, long *shader2, long *shader3)
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader5(long *shader, long *shader1, long *shader2) // FIXME
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
int __stdcall Direct3DShaderValidator9::ValidateShader6(long *shader, long *shader1, long *shader2, long *shader3) // FIXME
{
TRACE("");
UNIMPLEMENTED();
return true; // FIXME
}
}
static INT_PTR CALLBACK DebuggerWaitDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rect;
switch(uMsg)
{
case WM_INITDIALOG:
GetWindowRect(GetDesktopWindow(), &rect);
SetWindowPos(hwnd, HWND_TOP, rect.right / 2, rect.bottom / 2, 0, 0, SWP_NOSIZE);
SetTimer(hwnd, 1, 100, NULL);
return TRUE;
case WM_COMMAND:
if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hwnd, 0);
}
break;
case WM_TIMER:
if(IsDebuggerPresent())
{
EndDialog(hwnd, 0);
}
}
return FALSE;
}
static void WaitForDebugger(HINSTANCE instance)
{
if(!IsDebuggerPresent())
{
HRSRC dialog = FindResource(instance, MAKEINTRESOURCE(IDD_DIALOG1), RT_DIALOG);
DLGTEMPLATE *dialogTemplate = (DLGTEMPLATE*)LoadResource(instance, dialog);
DialogBoxIndirect(instance, dialogTemplate, NULL, DebuggerWaitDialogProc);
}
}
using namespace D3D9;
extern "C"
{
HINSTANCE dllInstance = 0;
int __stdcall DllMain(HINSTANCE instance, unsigned long reason, void *reserved)
{
#ifndef NDEBUG
if(dllInstance == 0)
{
FILE *file = fopen("debug.txt", "w"); // Clear debug log
if(file) fclose(file);
}
#endif
GTRACE("HINSTANCE instance = 0x%0.8p, unsigned long reason = %d, void *reserved = 0x%0.8p", instance, reason, reserved);
dllInstance = instance;
switch(reason)
{
case DLL_PROCESS_DETACH:
break;
case DLL_PROCESS_ATTACH:
#ifndef NDEBUG
WaitForDebugger(instance);
#endif
DisableThreadLibraryCalls(instance);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
default:
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return TRUE;
}
IDirect3D9 *__stdcall Direct3DCreate9(unsigned int version)
{
GTRACE("");
// D3D_SDK_VERSION check
if(version != (31 | 0x80000000) && // 9.0a/b DEBUG_INFO
version != 31 && // 9.0a/b
version != (32 | 0x80000000) && // 9.0c DEBUG_INFO
version != 32) // 9.0c
{
return 0;
}
IDirect3D9 *device = new D3D9::Direct3D9(version, dllInstance);
if(device)
{
device->AddRef();
}
return device;
}
HRESULT __stdcall Direct3DCreate9Ex(unsigned int version, IDirect3D9Ex **device)
{
// D3D_SDK_VERSION check
if(version != (31 | 0x80000000) && // 9.0a/b DEBUG_INFO
version != 31 && // 9.0a/b
version != (32 | 0x80000000) && // 9.0c DEBUG_INFO
version != 32) // 9.0c
{
return NOTAVAILABLE();
}
*device = new D3D9::Direct3D9Ex(version, dllInstance);
if(device)
{
(*device)->AddRef();
}
else
{
return OUTOFMEMORY();
}
return D3D_OK;
}
int __stdcall CheckFullscreen()
{
GTRACE("");
UNIMPLEMENTED();
return FALSE;
}
int __stdcall D3DPERF_BeginEvent(D3DCOLOR color, const wchar_t *name)
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
return -1;
}
int __stdcall D3DPERF_EndEvent()
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
return -1;
}
unsigned long __stdcall D3DPERF_GetStatus()
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
return 0;
}
int __stdcall D3DPERF_QueryRepeatFrame()
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
return FALSE;
}
void __stdcall D3DPERF_SetMarker(D3DCOLOR color, const wchar_t *name)
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
}
void __stdcall D3DPERF_SetOptions(unsigned long options)
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
}
void __stdcall D3DPERF_SetRegion(D3DCOLOR color, const wchar_t *name)
{
GTRACE("");
// UNIMPLEMENTED(); // PIX unsupported
}
void __cdecl DebugSetLevel(long level)
{
GTRACE("long level = %d", level);
// UNIMPLEMENTED(); // Debug output unsupported
}
void __cdecl DebugSetMute(long mute)
{
GTRACE("long mute = %d", mute);
// UNIMPLEMENTED(); // Debug output unsupported
}
void *__stdcall Direct3DShaderValidatorCreate9()
{
GTRACE("");
// UNIMPLEMENTED();
return 0;
// return new D3D9::Direct3DShaderValidator9();
}
void __stdcall PSGPError()
{
GTRACE("");
UNIMPLEMENTED();
}
void __stdcall PSGPSampleTexture()
{
GTRACE("");
UNIMPLEMENTED();
}
}
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "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
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"#include ""../Common/Version.h""\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
PRODUCTVERSION MAJOR_VERSION,MINOR_VERSION,BUILD_VERSION,BUILD_REVISION
FILEFLAGSMASK 0x1fL
#ifdef _DEBUG
FILEFLAGS 0x9L
#else
FILEFLAGS 0x8L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Google Inc."
VALUE "FileDescription", "SwiftShader Direct3D 9 Renderer"
VALUE "FileVersion", VERSION_STRING
VALUE "InternalName", "D3D9"
VALUE "LegalCopyright", "Copyright (C) 2016 Google Inc."
VALUE "OriginalFilename", "d3d9.dll"
VALUE "PrivateBuild", REVISION_STRING
VALUE "ProductName", "SwiftShader Direct3D 9 Renderer"
VALUE "ProductVersion", VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOGEX 0, 0, 129, 47
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Waiting for debugger"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,72,26,50,14
LTEXT "Attach a debugger or ESC to cancel",IDC_STATIC,7,7,115,8
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 122
TOPMARGIN, 7
BOTTOMMARGIN, 40
END
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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