Basic postshader translation to D3D11 works. On-the-fly switching seems broken though.

This commit is contained in:
Henrik Rydgard committed 2017-02-23 12:42:28 +01:00
1 parent e7612c13da
commit f1e015f577
5 files changed
+74 -15

No files matched your search

+13 -1
View File
@@ -58,6 +58,15 @@ void ShaderTranslationShutdown() {
glslang::FinalizeProcess();
}
std::string Preprocess(std::string code, ShaderLanguage lang) {
// This takes GL up to the version we need.
return code;
}
std::string Postprocess(std::string code, ShaderLanguage lang) {
return code;
}
bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShaderMetadata *destMetadata, std::string src, ShaderLanguage srcLang, Draw::ShaderStage stage, std::string *errorMessage) {
if (srcLang != GLSL_300 && srcLang != GLSL_140)
return false;
@@ -74,6 +83,8 @@ bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShade
EShLanguage shaderStage = GetLanguage(stage);
glslang::TShader shader(shaderStage);
std::string preprocessed = Preprocess(src, srcLang);
shaderStrings[0] = src.c_str();
shader.setStrings(shaderStrings, 1);
if (!shader.parse(&Resources, 100, EProfile::ECompatibilityProfile, false, false, messages)) {
@@ -134,7 +145,8 @@ bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShade
options.fixup_clipspace = true;
options.shader_model = 50;
hlsl.set_options(options);
*dest = hlsl.compile();
std::string raw = hlsl.compile();
*dest = Postprocess(raw, destLang);
return true;
}
#endif
+19 -8
View File
@@ -9,10 +9,10 @@
#include "D3D11Util.h"
static std::vector<uint8_t> CompileShaderToBytecode(const char *code, size_t codeSize, const char *target) {
static std::vector<uint8_t> CompileShaderToBytecode(const char *code, size_t codeSize, const char *target, UINT flags) {
ID3DBlob *compiledCode = nullptr;
ID3DBlob *errorMsgs = nullptr;
HRESULT result = ptr_D3DCompile(code, codeSize, nullptr, nullptr, nullptr, "main", target, 0, 0, &compiledCode, &errorMsgs);
HRESULT result = ptr_D3DCompile(code, codeSize, nullptr, nullptr, nullptr, "main", target, flags, 0, &compiledCode, &errorMsgs);
std::string errors;
if (errorMsgs) {
errors = std::string((const char *)errorMsgs->GetBufferPointer(), errorMsgs->GetBufferSize());
@@ -30,8 +30,8 @@ static std::vector<uint8_t> CompileShaderToBytecode(const char *code, size_t cod
return std::vector<uint8_t>();
}
ID3D11VertexShader *CreateVertexShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, std::vector<uint8_t> *byteCodeOut) {
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "vs_5_0");
ID3D11VertexShader *CreateVertexShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, std::vector<uint8_t> *byteCodeOut, UINT flags) {
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "vs_5_0", flags);
if (byteCode.empty())
return nullptr;
@@ -42,8 +42,8 @@ ID3D11VertexShader *CreateVertexShaderD3D11(ID3D11Device *device, const char *co
return vs;
}
ID3D11PixelShader *CreatePixelShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize) {
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "ps_5_0");
ID3D11PixelShader *CreatePixelShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, UINT flags) {
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "ps_5_0", flags);
if (byteCode.empty())
return nullptr;
@@ -52,8 +52,8 @@ ID3D11PixelShader *CreatePixelShaderD3D11(ID3D11Device *device, const char *code
return ps;
}
ID3D11ComputeShader *CreateComputeShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize) {
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "cs_5_0");
ID3D11ComputeShader *CreateComputeShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, UINT flags) {
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "cs_5_0", flags);
if (byteCode.empty())
return nullptr;
@@ -62,6 +62,17 @@ ID3D11ComputeShader *CreateComputeShaderD3D11(ID3D11Device *device, const char *
return cs;
}
ID3D11GeometryShader *CreateGeometryShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, UINT flags) {
std::vector<uint8_t> byteCode = CompileShaderToBytecode(code, codeSize, "gs_5_0", flags);
if (byteCode.empty())
return nullptr;
ID3D11GeometryShader *gs;
device->CreateGeometryShader(byteCode.data(), byteCode.size(), nullptr, &gs);
return gs;
}
void StockObjectsD3D11::Create(ID3D11Device *device) {
D3D11_BLEND_DESC blend_desc{};
blend_desc.RenderTarget[0].BlendEnable = false;
+4 -3
View File
@@ -64,9 +64,10 @@ private:
bool nextMapDiscard_ = false;
};
ID3D11VertexShader *CreateVertexShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, std::vector<uint8_t> *byteCodeOut);
ID3D11PixelShader *CreatePixelShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize);
ID3D11ComputeShader *CreateComputeShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize);
ID3D11VertexShader *CreateVertexShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, std::vector<uint8_t> *byteCodeOut, UINT flags = 0);
ID3D11PixelShader *CreatePixelShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, UINT flags = 0);
ID3D11ComputeShader *CreateComputeShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, UINT flags = 0);
ID3D11GeometryShader *CreateGeometryShaderD3D11(ID3D11Device *device, const char *code, size_t codeSize, UINT flags = 0);
class StockObjectsD3D11 {
public:
+37 -3
View File
@@ -15,6 +15,9 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <d3d11.h>
#include <D3Dcompiler.h>
#include "math/lin/matrix4x4.h"
#include "ext/native/thin3d/thin3d.h"
#include "base/basictypes.h"
@@ -81,6 +84,13 @@ const D3D11_INPUT_ELEMENT_DESC FramebufferManagerD3D11::g_QuadVertexElements[2]
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, },
};
// The current simple shader translator outputs everything as semantic texcoords, so let's just play along
// for simplicity.
const D3D11_INPUT_ELEMENT_DESC FramebufferManagerD3D11::g_PostVertexElements[2] = {
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, },
{ "TEXCOORD", 1, DXGI_FORMAT_R32G32_FLOAT, 0, 12, },
};
FramebufferManagerD3D11::FramebufferManagerD3D11(Draw::DrawContext *draw)
: FramebufferManagerCommon(draw) {
device_ = (ID3D11Device *)draw->GetNativeObject(Draw::NativeObject::DEVICE);
@@ -149,6 +159,16 @@ FramebufferManagerD3D11::~FramebufferManagerD3D11() {
if (drawPixelsTexView_)
drawPixelsTexView_->Release();
if (postVertexShader_) {
postVertexShader_->Release();
}
if (postPixelShader_) {
postPixelShader_->Release();
}
if (postInputLayout_) {
postInputLayout_->Release();
}
// FBO cleanup
for (auto it = tempFBOs_.begin(), end = tempFBOs_.end(); it != end; ++it) {
it->second.fbo->Release();
@@ -198,6 +218,19 @@ void FramebufferManagerD3D11::CompilePostShader() {
std::string vsSource;
std::string psSource;
if (postVertexShader_) {
postVertexShader_->Release();
postVertexShader_ = nullptr;
}
if (postPixelShader_) {
postPixelShader_->Release();
postPixelShader_ = nullptr;
}
if (postInputLayout_) {
postInputLayout_->Release();
postInputLayout_ = nullptr;
}
const ShaderInfo *shaderInfo = 0;
if (g_Config.sPostShaderName == "Off") {
return;
@@ -229,17 +262,18 @@ void FramebufferManagerD3D11::CompilePostShader() {
return;
}
UINT flags = D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
std::vector<uint8_t> byteCode;
postVertexShader_ = CreateVertexShaderD3D11(device_, vsSource.data(), vsSource.size(), &byteCode);
postVertexShader_ = CreateVertexShaderD3D11(device_, vsSource.data(), vsSource.size(), &byteCode, flags);
if (!postVertexShader_) {
return;
}
postPixelShader_ = CreatePixelShaderD3D11(device_, psSource.data(), psSource.size());
postPixelShader_ = CreatePixelShaderD3D11(device_, psSource.data(), psSource.size(), flags);
if (!postPixelShader_) {
postVertexShader_->Release();
return;
}
device_->CreateInputLayout(g_QuadVertexElements, 2, byteCode.data(), byteCode.size(), &postInputLayout_);
device_->CreateInputLayout(g_PostVertexElements, 2, byteCode.data(), byteCode.size(), &postInputLayout_);
usePostShader_ = true;
}
+1
View File
@@ -147,6 +147,7 @@ private:
ID3D11PixelShader *postPixelShader_ = nullptr;
ID3D11InputLayout *postInputLayout_ = nullptr;
ID3D11Buffer *postConstants_ = nullptr;
static const D3D11_INPUT_ELEMENT_DESC g_PostVertexElements[2];
// Used by post-processing shader
std::vector<Draw::Framebuffer *> extraFBOs_;