Basic shader cache.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <xenia/gpu/d3d11/d3d11_graphics_driver.h>
|
||||
|
||||
#include <xenia/gpu/gpu-private.h>
|
||||
#include <xenia/gpu/xenos/ucode_disassembler.h>
|
||||
#include <xenia/gpu/d3d11/d3d11_shader_cache.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
@@ -24,9 +24,12 @@ D3D11GraphicsDriver::D3D11GraphicsDriver(
|
||||
GraphicsDriver(memory) {
|
||||
device_ = device;
|
||||
device_->AddRef();
|
||||
|
||||
shader_cache_ = new D3D11ShaderCache(device_);
|
||||
}
|
||||
|
||||
D3D11GraphicsDriver::~D3D11GraphicsDriver() {
|
||||
delete shader_cache_;
|
||||
device_->Release();
|
||||
}
|
||||
|
||||
@@ -51,29 +54,20 @@ void D3D11GraphicsDriver::SetShader(
|
||||
uint32_t address,
|
||||
uint32_t start,
|
||||
uint32_t length) {
|
||||
// Swap shader words.
|
||||
uint32_t dword_count = length / 4;
|
||||
XEASSERT(dword_count <= 512);
|
||||
if (dword_count > 512) {
|
||||
XELOGGPU("D3D11: ignoring shader %d at %0.8X (%db): too long",
|
||||
type, address, length);
|
||||
return;
|
||||
}
|
||||
// Find or create shader in the cache.
|
||||
uint8_t* p = xe_memory_addr(memory_, address);
|
||||
uint32_t dwords[512] = {0};
|
||||
for (uint32_t n = 0; n < dword_count; n++) {
|
||||
dwords[n] = XEGETUINT32BE(p + n * 4);
|
||||
}
|
||||
Shader* shader = shader_cache_->FindOrCreate(
|
||||
type, p, length);
|
||||
|
||||
// Disassemble.
|
||||
const char* source = DisassembleShader(type, dwords, dword_count);
|
||||
char* source = shader->Disassemble();
|
||||
if (!source) {
|
||||
source = "<failed to disassemble>";
|
||||
}
|
||||
XELOGGPU("D3D11: set shader %d at %0.8X (%db):\n%s",
|
||||
type, address, length, source);
|
||||
if (source) {
|
||||
xe_free((void*)source);
|
||||
xe_free(source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace xe {
|
||||
namespace gpu {
|
||||
namespace d3d11 {
|
||||
|
||||
class D3D11ShaderCache;
|
||||
|
||||
|
||||
class D3D11GraphicsDriver : public GraphicsDriver {
|
||||
public:
|
||||
@@ -43,7 +45,9 @@ public:
|
||||
uint32_t index_count);
|
||||
|
||||
private:
|
||||
ID3D11Device* device_;
|
||||
ID3D11Device* device_;
|
||||
|
||||
D3D11ShaderCache* shader_cache_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -13,9 +13,16 @@
|
||||
using namespace xe;
|
||||
using namespace xe::gpu;
|
||||
using namespace xe::gpu::d3d11;
|
||||
using namespace xe::gpu::xenos;
|
||||
|
||||
|
||||
D3D11Shader::D3D11Shader() {
|
||||
D3D11Shader::D3D11Shader(
|
||||
ID3D11Device* device,
|
||||
XE_GPU_SHADER_TYPE type,
|
||||
const uint8_t* src_ptr, size_t length,
|
||||
uint64_t hash) :
|
||||
Shader(type, src_ptr, length, hash) {
|
||||
// TODO(benvanik): create shader/translate/etc.
|
||||
}
|
||||
|
||||
D3D11Shader::~D3D11Shader() {
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include <xenia/gpu/shader.h>
|
||||
|
||||
#include <d3d11.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
@@ -22,7 +24,11 @@ namespace d3d11 {
|
||||
|
||||
class D3D11Shader : public Shader {
|
||||
public:
|
||||
D3D11Shader();
|
||||
D3D11Shader(
|
||||
ID3D11Device* device,
|
||||
xenos::XE_GPU_SHADER_TYPE type,
|
||||
const uint8_t* src_ptr, size_t length,
|
||||
uint64_t hash);
|
||||
virtual ~D3D11Shader();
|
||||
};
|
||||
|
||||
|
||||
@@ -9,14 +9,30 @@
|
||||
|
||||
#include <xenia/gpu/d3d11/d3d11_shader_cache.h>
|
||||
|
||||
#include <xenia/gpu/d3d11/d3d11_shader.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::gpu;
|
||||
using namespace xe::gpu::d3d11;
|
||||
|
||||
|
||||
D3D11ShaderCache::D3D11ShaderCache() {
|
||||
D3D11ShaderCache::D3D11ShaderCache(ID3D11Device* device) {
|
||||
device_ = device;
|
||||
device_->AddRef();
|
||||
}
|
||||
|
||||
D3D11ShaderCache::~D3D11ShaderCache() {
|
||||
device_->Release();
|
||||
}
|
||||
|
||||
Shader* D3D11ShaderCache::CreateCore(
|
||||
xenos::XE_GPU_SHADER_TYPE type,
|
||||
const uint8_t* src_ptr, size_t length,
|
||||
uint32_t hash) {
|
||||
return new D3D11Shader(
|
||||
device_,
|
||||
type,
|
||||
src_ptr, length,
|
||||
hash);
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include <xenia/gpu/shader_cache.h>
|
||||
|
||||
#include <D3D11.h>
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
@@ -22,8 +24,17 @@ namespace d3d11 {
|
||||
|
||||
class D3D11ShaderCache : public ShaderCache {
|
||||
public:
|
||||
D3D11ShaderCache();
|
||||
D3D11ShaderCache(ID3D11Device* device);
|
||||
virtual ~D3D11ShaderCache();
|
||||
|
||||
protected:
|
||||
virtual Shader* CreateCore(
|
||||
xenos::XE_GPU_SHADER_TYPE type,
|
||||
const uint8_t* src_ptr, size_t length,
|
||||
uint32_t hash);
|
||||
|
||||
protected:
|
||||
ID3D11Device* device_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user