mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 21:39:52 +00:00
Merge pull request #13609 from hrydgard/merge-glsl-hlsl-fragment-shadergens
Merge GLSL and HLSL fragment shader generators into one generic
This commit is contained in:
commit
45218ec73d
@ -1235,8 +1235,6 @@ set(GPU_GLES
|
|||||||
GPU/GLES/DepthBufferGLES.cpp
|
GPU/GLES/DepthBufferGLES.cpp
|
||||||
GPU/GLES/GPU_GLES.cpp
|
GPU/GLES/GPU_GLES.cpp
|
||||||
GPU/GLES/GPU_GLES.h
|
GPU/GLES/GPU_GLES.h
|
||||||
GPU/GLES/FragmentShaderGeneratorGLES.cpp
|
|
||||||
GPU/GLES/FragmentShaderGeneratorGLES.h
|
|
||||||
GPU/GLES/FragmentTestCacheGLES.cpp
|
GPU/GLES/FragmentTestCacheGLES.cpp
|
||||||
GPU/GLES/FragmentTestCacheGLES.h
|
GPU/GLES/FragmentTestCacheGLES.h
|
||||||
GPU/GLES/FramebufferManagerGLES.cpp
|
GPU/GLES/FramebufferManagerGLES.cpp
|
||||||
@ -1300,8 +1298,6 @@ set(GPU_D3D9
|
|||||||
GPU/Directx9/TextureCacheDX9.h
|
GPU/Directx9/TextureCacheDX9.h
|
||||||
GPU/Directx9/TextureScalerDX9.cpp
|
GPU/Directx9/TextureScalerDX9.cpp
|
||||||
GPU/Directx9/TextureScalerDX9.h
|
GPU/Directx9/TextureScalerDX9.h
|
||||||
GPU/Directx9/FragmentShaderGeneratorHLSL.cpp
|
|
||||||
GPU/Directx9/FragmentShaderGeneratorHLSL.h
|
|
||||||
GPU/Directx9/VertexShaderGeneratorHLSL.cpp
|
GPU/Directx9/VertexShaderGeneratorHLSL.cpp
|
||||||
GPU/Directx9/VertexShaderGeneratorHLSL.h
|
GPU/Directx9/VertexShaderGeneratorHLSL.h
|
||||||
)
|
)
|
||||||
@ -1342,6 +1338,8 @@ set(GPU_SOURCES
|
|||||||
${GPU_NEON}
|
${GPU_NEON}
|
||||||
GPU/Common/DepalettizeShaderCommon.cpp
|
GPU/Common/DepalettizeShaderCommon.cpp
|
||||||
GPU/Common/DepalettizeShaderCommon.h
|
GPU/Common/DepalettizeShaderCommon.h
|
||||||
|
GPU/Common/FragmentShaderGenerator.cpp
|
||||||
|
GPU/Common/FragmentShaderGenerator.h
|
||||||
GPU/Common/FramebufferManagerCommon.cpp
|
GPU/Common/FramebufferManagerCommon.cpp
|
||||||
GPU/Common/FramebufferManagerCommon.h
|
GPU/Common/FramebufferManagerCommon.h
|
||||||
GPU/Common/GPUDebugInterface.cpp
|
GPU/Common/GPUDebugInterface.cpp
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#include "ppsspp_config.h"
|
#include "ppsspp_config.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include "Common/CommonWindows.h"
|
#include "Common/CommonWindows.h"
|
||||||
#include "Common/GPU/D3D9/D3DCompilerLoader.h"
|
#include "Common/GPU/D3D9/D3DCompilerLoader.h"
|
||||||
#include "Common/GPU/D3D9/D3D9ShaderCompiler.h"
|
#include "Common/GPU/D3D9/D3D9ShaderCompiler.h"
|
||||||
#include "Common/CommonFuncs.h"
|
#include "Common/CommonFuncs.h"
|
||||||
#include "Common/SysError.h"
|
#include "Common/SysError.h"
|
||||||
|
#include "Common/Log.h"
|
||||||
|
#include "Common/StringUtils.h"
|
||||||
|
|
||||||
struct ID3DXConstantTable;
|
struct ID3DXConstantTable;
|
||||||
|
|
||||||
namespace DX9 {
|
LPD3DBLOB CompileShaderToByteCodeD3D9(const char *code, const char *target, std::string *errorMessage) {
|
||||||
|
|
||||||
bool CompilePixelShader(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPIXELSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage) {
|
|
||||||
LPD3DBLOB pShaderCode = nullptr;
|
LPD3DBLOB pShaderCode = nullptr;
|
||||||
LPD3DBLOB pErrorMsg = nullptr;
|
LPD3DBLOB pErrorMsg = nullptr;
|
||||||
|
|
||||||
@ -23,77 +23,58 @@ bool CompilePixelShader(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPI
|
|||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
"main",
|
"main",
|
||||||
"ps_2_0",
|
target,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
&pShaderCode,
|
&pShaderCode,
|
||||||
&pErrorMsg);
|
&pErrorMsg);
|
||||||
|
|
||||||
if (pErrorMsg) {
|
if (pErrorMsg) {
|
||||||
errorMessage = (CHAR *)pErrorMsg->GetBufferPointer();
|
*errorMessage = std::string((CHAR *)pErrorMsg->GetBufferPointer());
|
||||||
|
|
||||||
|
OutputDebugStringUTF8(LineNumberString(std::string(code)).c_str());
|
||||||
|
OutputDebugStringUTF8(errorMessage->c_str());
|
||||||
|
|
||||||
pErrorMsg->Release();
|
pErrorMsg->Release();
|
||||||
} else if (FAILED(hr)) {
|
if (pShaderCode) {
|
||||||
errorMessage = GetStringErrorMsg(hr);
|
|
||||||
} else {
|
|
||||||
errorMessage = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(hr) || !pShaderCode) {
|
|
||||||
if (pShaderCode)
|
|
||||||
pShaderCode->Release();
|
pShaderCode->Release();
|
||||||
return false;
|
pShaderCode = nullptr;
|
||||||
|
}
|
||||||
|
} else if (FAILED(hr)) {
|
||||||
|
*errorMessage = GetStringErrorMsg(hr);
|
||||||
|
if (pShaderCode) {
|
||||||
|
pShaderCode->Release();
|
||||||
|
pShaderCode = nullptr;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
*errorMessage = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create pixel shader.
|
return pShaderCode;
|
||||||
device->CreatePixelShader( (DWORD*)pShaderCode->GetBufferPointer(),
|
|
||||||
pShader );
|
|
||||||
|
|
||||||
pShaderCode->Release();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompileVertexShader(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage) {
|
bool CompilePixelShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPIXELSHADER9 *pShader, std::string *errorMessage) {
|
||||||
LPD3DBLOB pShaderCode = nullptr;
|
LPD3DBLOB pShaderCode = CompileShaderToByteCodeD3D9(code, "ps_2_0", errorMessage);
|
||||||
LPD3DBLOB pErrorMsg = nullptr;
|
if (pShaderCode) {
|
||||||
|
// Create pixel shader.
|
||||||
// Compile pixel shader.
|
device->CreatePixelShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
|
||||||
HRESULT hr = dyn_D3DCompile(code,
|
pShaderCode->Release();
|
||||||
(UINT)strlen(code),
|
return true;
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
"main",
|
|
||||||
"vs_2_0",
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
&pShaderCode,
|
|
||||||
&pErrorMsg);
|
|
||||||
|
|
||||||
if (pErrorMsg) {
|
|
||||||
errorMessage = (CHAR *)pErrorMsg->GetBufferPointer();
|
|
||||||
pErrorMsg->Release();
|
|
||||||
} else if (FAILED(hr)) {
|
|
||||||
errorMessage = GetStringErrorMsg(hr);
|
|
||||||
} else {
|
} else {
|
||||||
errorMessage = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(hr) || !pShaderCode) {
|
|
||||||
if (pShaderCode)
|
|
||||||
pShaderCode->Release();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create pixel shader.
|
|
||||||
device->CreateVertexShader( (DWORD*)pShaderCode->GetBufferPointer(),
|
|
||||||
pShader );
|
|
||||||
|
|
||||||
pShaderCode->Release();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
bool CompileVertexShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, std::string *errorMessage) {
|
||||||
|
LPD3DBLOB pShaderCode = CompileShaderToByteCodeD3D9(code, "vs_2_0", errorMessage);
|
||||||
|
if (pShaderCode) {
|
||||||
|
// Create vertex shader.
|
||||||
|
device->CreateVertexShader((DWORD*)pShaderCode->GetBufferPointer(), pShader);
|
||||||
|
pShaderCode->Release();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Common/CommonWindows.h"
|
#include "Common/CommonWindows.h"
|
||||||
|
#include "Common/GPU/D3D9/D3DCompilerLoader.h"
|
||||||
|
|
||||||
#include <initguid.h>
|
#include <initguid.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -8,9 +9,7 @@
|
|||||||
|
|
||||||
struct ID3DXConstantTable;
|
struct ID3DXConstantTable;
|
||||||
|
|
||||||
namespace DX9 {
|
LPD3DBLOB CompileShaderToByteCodeD3D9(const char *code, const char *target, std::string *errorMessage);
|
||||||
|
|
||||||
bool CompilePixelShader(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPIXELSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage);
|
bool CompilePixelShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DPIXELSHADER9 *pShader, std::string *errorMessage);
|
||||||
bool CompileVertexShader(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage);
|
bool CompileVertexShaderD3D9(LPDIRECT3DDEVICE9 device, const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, std::string *errorMessage);
|
||||||
|
|
||||||
} // namespace DX9
|
|
||||||
|
@ -354,6 +354,8 @@ void CheckGLExtensions() {
|
|||||||
gl_extensions.EXT_draw_instanced = g_set_gl_extensions.count("GL_EXT_draw_instanced") != 0;
|
gl_extensions.EXT_draw_instanced = g_set_gl_extensions.count("GL_EXT_draw_instanced") != 0;
|
||||||
gl_extensions.ARB_draw_instanced = g_set_gl_extensions.count("GL_ARB_draw_instanced") != 0;
|
gl_extensions.ARB_draw_instanced = g_set_gl_extensions.count("GL_ARB_draw_instanced") != 0;
|
||||||
gl_extensions.ARB_cull_distance = g_set_gl_extensions.count("GL_ARB_cull_distance") != 0;
|
gl_extensions.ARB_cull_distance = g_set_gl_extensions.count("GL_ARB_cull_distance") != 0;
|
||||||
|
gl_extensions.ARB_depth_clamp = g_set_gl_extensions.count("GL_ARB_depth_clamp") != 0;
|
||||||
|
gl_extensions.ARB_uniform_buffer_object = g_set_gl_extensions.count("GL_ARB_uniform_buffer_object") != 0;
|
||||||
|
|
||||||
if (gl_extensions.IsGLES) {
|
if (gl_extensions.IsGLES) {
|
||||||
gl_extensions.OES_texture_npot = g_set_gl_extensions.count("GL_OES_texture_npot") != 0;
|
gl_extensions.OES_texture_npot = g_set_gl_extensions.count("GL_OES_texture_npot") != 0;
|
||||||
@ -498,10 +500,10 @@ void CheckGLExtensions() {
|
|||||||
}
|
}
|
||||||
if (gl_extensions.VersionGEThan(3, 1)) {
|
if (gl_extensions.VersionGEThan(3, 1)) {
|
||||||
gl_extensions.ARB_draw_instanced = true;
|
gl_extensions.ARB_draw_instanced = true;
|
||||||
// ARB_uniform_buffer_object = true;
|
gl_extensions.ARB_uniform_buffer_object = true;
|
||||||
}
|
}
|
||||||
if (gl_extensions.VersionGEThan(3, 2)) {
|
if (gl_extensions.VersionGEThan(3, 2)) {
|
||||||
// ARB_depth_clamp = true;
|
gl_extensions.ARB_depth_clamp = true;
|
||||||
}
|
}
|
||||||
if (gl_extensions.VersionGEThan(3, 3)) {
|
if (gl_extensions.VersionGEThan(3, 3)) {
|
||||||
gl_extensions.ARB_blend_func_extended = true;
|
gl_extensions.ARB_blend_func_extended = true;
|
||||||
@ -541,6 +543,8 @@ void CheckGLExtensions() {
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (!gl_extensions.IsGLES && !gl_extensions.IsCoreContext) {
|
if (!gl_extensions.IsGLES && !gl_extensions.IsCoreContext) {
|
||||||
// Apple doesn't allow OpenGL 3.x+ in compatibility contexts.
|
// Apple doesn't allow OpenGL 3.x+ in compatibility contexts.
|
||||||
|
// TODO: But are we still ever creating these on Apple? Would really
|
||||||
|
// like to kill this ForceGL2 flag.
|
||||||
gl_extensions.ForceGL2 = true;
|
gl_extensions.ForceGL2 = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,6 +64,8 @@ struct GLExtensions {
|
|||||||
bool ARB_draw_instanced;
|
bool ARB_draw_instanced;
|
||||||
bool ARB_buffer_storage;
|
bool ARB_buffer_storage;
|
||||||
bool ARB_cull_distance;
|
bool ARB_cull_distance;
|
||||||
|
bool ARB_depth_clamp;
|
||||||
|
bool ARB_uniform_buffer_object;
|
||||||
|
|
||||||
// EXT
|
// EXT
|
||||||
bool EXT_swap_control_tear;
|
bool EXT_swap_control_tear;
|
||||||
|
@ -279,7 +279,7 @@ void GLQueueRunner::RunInitSteps(const std::vector<GLRInitStep> &steps, bool ski
|
|||||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
std::string infoLog = GetInfoLog(shader, glGetShaderiv, glGetShaderInfoLog);
|
std::string infoLog = GetInfoLog(shader, glGetShaderiv, glGetShaderInfoLog);
|
||||||
#ifdef __ANDROID__
|
#if PPSSPP_PLATFORM(ANDROID)
|
||||||
ERROR_LOG(G3D, "Error in shader compilation! %s\n", infoLog.c_str());
|
ERROR_LOG(G3D, "Error in shader compilation! %s\n", infoLog.c_str());
|
||||||
ERROR_LOG(G3D, "Shader source:\n%s\n", (const char *)code);
|
ERROR_LOG(G3D, "Shader source:\n%s\n", (const char *)code);
|
||||||
#endif
|
#endif
|
||||||
|
@ -923,6 +923,11 @@ static std::string surface_transforms_to_string(VkSurfaceTransformFlagsKHR trans
|
|||||||
|
|
||||||
bool VulkanContext::InitSwapchain() {
|
bool VulkanContext::InitSwapchain() {
|
||||||
VkResult res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_devices_[physical_device_], surface_, &surfCapabilities_);
|
VkResult res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_devices_[physical_device_], surface_, &surfCapabilities_);
|
||||||
|
if (res == VK_ERROR_SURFACE_LOST_KHR) {
|
||||||
|
// Not much to do.
|
||||||
|
ERROR_LOG(G3D, "VK: Surface lost in InitSwapchain");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
_dbg_assert_(res == VK_SUCCESS);
|
_dbg_assert_(res == VK_SUCCESS);
|
||||||
uint32_t presentModeCount;
|
uint32_t presentModeCount;
|
||||||
res = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_devices_[physical_device_], surface_, &presentModeCount, nullptr);
|
res = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_devices_[physical_device_], surface_, &presentModeCount, nullptr);
|
||||||
@ -1172,24 +1177,43 @@ EShLanguage FindLanguage(const VkShaderStageFlagBits shader_type) {
|
|||||||
|
|
||||||
// Compile a given string containing GLSL into SPV for use by VK
|
// Compile a given string containing GLSL into SPV for use by VK
|
||||||
// Return value of false means an error was encountered.
|
// Return value of false means an error was encountered.
|
||||||
bool GLSLtoSPV(const VkShaderStageFlagBits shader_type,
|
bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *sourceCode, GLSLVariant variant,
|
||||||
const char *pshader,
|
std::vector<unsigned int> &spirv, std::string *errorMessage) {
|
||||||
std::vector<unsigned int> &spirv, std::string *errorMessage) {
|
|
||||||
|
|
||||||
glslang::TProgram program;
|
glslang::TProgram program;
|
||||||
const char *shaderStrings[1];
|
const char *shaderStrings[1];
|
||||||
EProfile profile = ECoreProfile;
|
|
||||||
int defaultVersion = 450;
|
|
||||||
TBuiltInResource Resources;
|
TBuiltInResource Resources;
|
||||||
init_resources(Resources);
|
init_resources(Resources);
|
||||||
|
|
||||||
// Enable SPIR-V and Vulkan rules when parsing GLSL
|
int defaultVersion;
|
||||||
EShMessages messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
|
EShMessages messages;
|
||||||
|
EProfile profile;
|
||||||
|
|
||||||
|
switch (variant) {
|
||||||
|
case GLSLVariant::VULKAN:
|
||||||
|
// Enable SPIR-V and Vulkan rules when parsing GLSL
|
||||||
|
messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
|
||||||
|
defaultVersion = 450;
|
||||||
|
profile = ECoreProfile;
|
||||||
|
break;
|
||||||
|
case GLSLVariant::GL140:
|
||||||
|
messages = (EShMessages)(EShMsgDefault);
|
||||||
|
defaultVersion = 140;
|
||||||
|
profile = ECompatibilityProfile;
|
||||||
|
break;
|
||||||
|
case GLSLVariant::GLES300:
|
||||||
|
messages = (EShMessages)(EShMsgDefault);
|
||||||
|
defaultVersion = 300;
|
||||||
|
profile = EEsProfile;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
EShLanguage stage = FindLanguage(shader_type);
|
EShLanguage stage = FindLanguage(shader_type);
|
||||||
glslang::TShader shader(stage);
|
glslang::TShader shader(stage);
|
||||||
|
|
||||||
shaderStrings[0] = pshader;
|
shaderStrings[0] = sourceCode;
|
||||||
shader.setStrings(shaderStrings, 1);
|
shader.setStrings(shaderStrings, 1);
|
||||||
|
|
||||||
if (!shader.parse(&Resources, defaultVersion, profile, false, true, messages)) {
|
if (!shader.parse(&Resources, defaultVersion, profile, false, true, messages)) {
|
||||||
|
@ -367,7 +367,14 @@ void TransitionImageLayout2(VkCommandBuffer cmd, VkImage image, int baseMip, int
|
|||||||
// GLSL compiler
|
// GLSL compiler
|
||||||
void init_glslang();
|
void init_glslang();
|
||||||
void finalize_glslang();
|
void finalize_glslang();
|
||||||
bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *pshader, std::vector<uint32_t> &spirv, std::string *errorMessage = nullptr);
|
|
||||||
|
enum class GLSLVariant {
|
||||||
|
VULKAN,
|
||||||
|
GL140,
|
||||||
|
GLES300,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool GLSLtoSPV(const VkShaderStageFlagBits shader_type, const char *sourceCode, GLSLVariant variant, std::vector<uint32_t> &spirv, std::string *errorMessage);
|
||||||
|
|
||||||
const char *VulkanResultToString(VkResult res);
|
const char *VulkanResultToString(VkResult res);
|
||||||
std::string FormatDriverVersion(const VkPhysicalDeviceProperties &props);
|
std::string FormatDriverVersion(const VkPhysicalDeviceProperties &props);
|
||||||
|
@ -215,7 +215,9 @@ bool VKShaderModule::Compile(VulkanContext *vulkan, ShaderLanguage language, con
|
|||||||
// We'll need this to free it later.
|
// We'll need this to free it later.
|
||||||
source_ = (const char *)data;
|
source_ = (const char *)data;
|
||||||
std::vector<uint32_t> spirv;
|
std::vector<uint32_t> spirv;
|
||||||
if (!GLSLtoSPV(vkstage_, source_.c_str(), spirv)) {
|
std::string errorMessage;
|
||||||
|
if (!GLSLtoSPV(vkstage_, source_.c_str(), GLSLVariant::VULKAN, spirv, &errorMessage)) {
|
||||||
|
INFO_LOG(G3D, "Shader compile to module failed: %s", errorMessage.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,12 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "Common/Log.h"
|
||||||
#include "Common/TimeUtil.h"
|
#include "Common/TimeUtil.h"
|
||||||
|
|
||||||
namespace net {
|
namespace net {
|
||||||
|
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -45,7 +47,6 @@ void Shutdown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DNSResolve(const std::string &host, const std::string &service, addrinfo **res, std::string &error, DNSType type) {
|
bool DNSResolve(const std::string &host, const std::string &service, addrinfo **res, std::string &error, DNSType type) {
|
||||||
|
|
||||||
#if PPSSPP_PLATFORM(SWITCH)
|
#if PPSSPP_PLATFORM(SWITCH)
|
||||||
// Force IPv4 lookups.
|
// Force IPv4 lookups.
|
||||||
if (type == DNSType::IPV6) {
|
if (type == DNSType::IPV6) {
|
||||||
|
@ -234,7 +234,6 @@ enum NativeModuleStatus {
|
|||||||
|
|
||||||
class PSPModule : public KernelObject {
|
class PSPModule : public KernelObject {
|
||||||
public:
|
public:
|
||||||
PSPModule() : textStart(0), textEnd(0), libstub(0), libstubend(0), memoryBlockAddr(0), isFake(false), modulePtr(0) {}
|
|
||||||
~PSPModule() {
|
~PSPModule() {
|
||||||
if (memoryBlockAddr) {
|
if (memoryBlockAddr) {
|
||||||
// If it's either below user memory, or using a high kernel bit, it's in kernel.
|
// If it's either below user memory, or using a high kernel bit, it's in kernel.
|
||||||
@ -431,20 +430,19 @@ public:
|
|||||||
std::vector<VarSymbolExport> exportedVars;
|
std::vector<VarSymbolExport> exportedVars;
|
||||||
std::vector<VarSymbolImport> importedVars;
|
std::vector<VarSymbolImport> importedVars;
|
||||||
std::set<std::string> impExpModuleNames;
|
std::set<std::string> impExpModuleNames;
|
||||||
|
|
||||||
// Keep track of the code region so we can throw out analysis results
|
// Keep track of the code region so we can throw out analysis results
|
||||||
// when unloaded.
|
// when unloaded.
|
||||||
u32 textStart;
|
u32 textStart = 0;
|
||||||
u32 textEnd;
|
u32 textEnd = 0;
|
||||||
|
|
||||||
// Keep track of the libstub pointers so we can recheck on load state.
|
// Keep track of the libstub pointers so we can recheck on load state.
|
||||||
u32 libstub;
|
u32 libstub = 0;
|
||||||
u32 libstubend;
|
u32 libstubend = 0;
|
||||||
|
|
||||||
u32 memoryBlockAddr;
|
u32 memoryBlockAddr = 0;
|
||||||
u32 memoryBlockSize;
|
u32 memoryBlockSize = 0;
|
||||||
u32 modulePtr;
|
u32 modulePtr = 0;
|
||||||
bool isFake;
|
bool isFake = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
KernelObject *__KernelModuleObject()
|
KernelObject *__KernelModuleObject()
|
||||||
|
@ -331,15 +331,7 @@ void ADSREnvelope::SetSimpleEnvelope(u32 ADSREnv1, u32 ADSREnv2) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SasInstance::SasInstance()
|
SasInstance::SasInstance() {
|
||||||
: maxVoices(PSP_SAS_VOICES_MAX),
|
|
||||||
sampleRate(44100),
|
|
||||||
outputMode(PSP_SAS_OUTPUTMODE_MIXED),
|
|
||||||
mixBuffer(0),
|
|
||||||
sendBuffer(0),
|
|
||||||
sendBufferDownsampled(0),
|
|
||||||
sendBufferProcessed(0),
|
|
||||||
grainSize(0) {
|
|
||||||
#ifdef AUDIO_TO_FILE
|
#ifdef AUDIO_TO_FILE
|
||||||
audioDump = fopen("D:\\audio.raw", "wb");
|
audioDump = fopen("D:\\audio.raw", "wb");
|
||||||
#endif
|
#endif
|
||||||
|
@ -282,16 +282,16 @@ public:
|
|||||||
int GetGrainSize() const { return grainSize; }
|
int GetGrainSize() const { return grainSize; }
|
||||||
int EstimateMixUs();
|
int EstimateMixUs();
|
||||||
|
|
||||||
int maxVoices;
|
int maxVoices = PSP_SAS_VOICES_MAX;
|
||||||
int sampleRate;
|
int sampleRate = 44100;
|
||||||
int outputMode;
|
int outputMode = PSP_SAS_OUTPUTMODE_MIXED;
|
||||||
|
|
||||||
int *mixBuffer;
|
int *mixBuffer = nullptr;
|
||||||
int *sendBuffer;
|
int *sendBuffer = nullptr;
|
||||||
s16 *sendBufferDownsampled;
|
s16 *sendBufferDownsampled = nullptr;
|
||||||
s16 *sendBufferProcessed;
|
s16 *sendBufferProcessed = nullptr;
|
||||||
|
|
||||||
FILE *audioDump;
|
FILE *audioDump = nullptr;
|
||||||
|
|
||||||
void Mix(u32 outAddr, u32 inAddr = 0, int leftVol = 0, int rightVol = 0);
|
void Mix(u32 outAddr, u32 inAddr = 0, int leftVol = 0, int rightVol = 0);
|
||||||
void MixVoice(SasVoice &voice);
|
void MixVoice(SasVoice &voice);
|
||||||
@ -310,6 +310,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
SasReverb reverb_;
|
SasReverb reverb_;
|
||||||
int grainSize;
|
int grainSize = 0;
|
||||||
int16_t mixTemp_[PSP_SAS_MAX_GRAIN * 4 + 2 + 8]; // some extra margin for very high pitches.
|
int16_t mixTemp_[PSP_SAS_MAX_GRAIN * 4 + 2 + 8]; // some extra margin for very high pitches.
|
||||||
};
|
};
|
||||||
|
@ -164,7 +164,7 @@ void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat, ShaderLang
|
|||||||
void GenerateDepalShaderFloat(char *buffer, GEBufferFormat pixelFormat, ShaderLanguage lang) {
|
void GenerateDepalShaderFloat(char *buffer, GEBufferFormat pixelFormat, ShaderLanguage lang) {
|
||||||
char *p = buffer;
|
char *p = buffer;
|
||||||
|
|
||||||
const char *modFunc = lang == HLSL_DX9 ? "fmod" : "mod";
|
const char *modFunc = lang == HLSL_D3D9 ? "fmod" : "mod";
|
||||||
|
|
||||||
char lookupMethod[128] = "index.r";
|
char lookupMethod[128] = "index.r";
|
||||||
char offset[128] = "";
|
char offset[128] = "";
|
||||||
@ -305,7 +305,7 @@ void GenerateDepalShaderFloat(char *buffer, GEBufferFormat pixelFormat, ShaderLa
|
|||||||
WRITE(p, " float coord = (%s * %f)%s;\n", lookupMethod, index_multiplier, offset);
|
WRITE(p, " float coord = (%s * %f)%s;\n", lookupMethod, index_multiplier, offset);
|
||||||
WRITE(p, " gl_FragColor = texture2D(pal, vec2(coord, 0.0));\n");
|
WRITE(p, " gl_FragColor = texture2D(pal, vec2(coord, 0.0));\n");
|
||||||
WRITE(p, "}\n");
|
WRITE(p, "}\n");
|
||||||
} else if (lang == HLSL_DX9) {
|
} else if (lang == HLSL_D3D9) {
|
||||||
WRITE(p, "sampler tex: register(s0);\n");
|
WRITE(p, "sampler tex: register(s0);\n");
|
||||||
WRITE(p, "sampler pal: register(s1);\n");
|
WRITE(p, "sampler pal: register(s1);\n");
|
||||||
WRITE(p, "float4 main(float2 v_texcoord0 : TEXCOORD0) : COLOR0 {\n");
|
WRITE(p, "float4 main(float2 v_texcoord0 : TEXCOORD0) : COLOR0 {\n");
|
||||||
@ -326,7 +326,7 @@ void GenerateDepalShader(char *buffer, GEBufferFormat pixelFormat, ShaderLanguag
|
|||||||
case HLSL_D3D11:
|
case HLSL_D3D11:
|
||||||
GenerateDepalShader300(buffer, pixelFormat, language);
|
GenerateDepalShader300(buffer, pixelFormat, language);
|
||||||
break;
|
break;
|
||||||
case HLSL_DX9:
|
case HLSL_D3D9:
|
||||||
GenerateDepalShaderFloat(buffer, pixelFormat, language);
|
GenerateDepalShaderFloat(buffer, pixelFormat, language);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -26,28 +26,50 @@
|
|||||||
#include "GPU/Common/GPUStateUtils.h"
|
#include "GPU/Common/GPUStateUtils.h"
|
||||||
#include "GPU/Common/ShaderId.h"
|
#include "GPU/Common/ShaderId.h"
|
||||||
#include "GPU/Common/ShaderUniforms.h"
|
#include "GPU/Common/ShaderUniforms.h"
|
||||||
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
#include "GPU/GLES/FramebufferManagerGLES.h"
|
|
||||||
#include "GPU/GLES/ShaderManagerGLES.h"
|
|
||||||
#include "GPU/ge_constants.h"
|
#include "GPU/ge_constants.h"
|
||||||
#include "GPU/GPUState.h"
|
#include "GPU/GPUState.h"
|
||||||
|
|
||||||
#define WRITE p+=sprintf
|
#define WRITE p+=sprintf
|
||||||
|
|
||||||
static const char *vulkan_glsl_preamble =
|
const char *vulkan_glsl_preamble_fs =
|
||||||
"#version 450\n"
|
"#version 450\n"
|
||||||
"#extension GL_ARB_separate_shader_objects : enable\n"
|
"#extension GL_ARB_separate_shader_objects : enable\n"
|
||||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
"#extension GL_ARB_shading_language_420pack : enable\n"
|
||||||
"#extension GL_ARB_conservative_depth : enable\n"
|
"#extension GL_ARB_conservative_depth : enable\n"
|
||||||
"#extension GL_ARB_shader_image_load_store : enable\n"
|
"#extension GL_ARB_shader_image_load_store : enable\n"
|
||||||
"#define splat3(x) vec3(x)\n\n";
|
"#define splat3(x) vec3(x)\n"
|
||||||
|
"#define lowp\n"
|
||||||
|
"#define mediump\n"
|
||||||
|
"#define highp\n"
|
||||||
|
"#define DISCARD discard\n"
|
||||||
|
"\n";
|
||||||
|
|
||||||
bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLShaderCompat &compat, uint64_t *uniformMask, std::string *errorString) {
|
const char *hlsl_preamble_fs =
|
||||||
|
"#define vec2 float2\n"
|
||||||
|
"#define vec3 float3\n"
|
||||||
|
"#define vec4 float4\n"
|
||||||
|
"#define uvec3 uint3\n"
|
||||||
|
"#define ivec3 int3\n"
|
||||||
|
"#define splat3(x) float3(x, x, x)\n"
|
||||||
|
"#define mix lerp\n"
|
||||||
|
"#define mod(x, y) fmod(x, y)\n";
|
||||||
|
|
||||||
|
const char *hlsl_d3d11_preamble_fs =
|
||||||
|
"#define DISCARD discard\n"
|
||||||
|
"#define DISCARD_BELOW(x) clip(x);\n";
|
||||||
|
const char *hlsl_d3d9_preamble_fs =
|
||||||
|
"#define DISCARD clip(-1)\n"
|
||||||
|
"#define DISCARD_BELOW(x) clip(x)\n";
|
||||||
|
|
||||||
|
|
||||||
|
bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLanguageDesc &compat, uint64_t *uniformMask, std::string *errorString) {
|
||||||
*uniformMask = 0;
|
*uniformMask = 0;
|
||||||
|
errorString->clear();
|
||||||
|
|
||||||
bool highpFog = false;
|
bool highpFog = false;
|
||||||
bool highpTexcoord = false;
|
bool highpTexcoord = false;
|
||||||
bool enableFragmentTestCache = g_Config.bFragmentTestCache && !compat.vulkan;
|
bool enableFragmentTestCache = g_Config.bFragmentTestCache && ShaderLanguageIsOpenGL(compat.shaderLanguage);
|
||||||
|
|
||||||
if (compat.gles) {
|
if (compat.gles) {
|
||||||
// PowerVR needs highp to do the fog in MHU correctly.
|
// PowerVR needs highp to do the fog in MHU correctly.
|
||||||
@ -60,13 +82,22 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
|
|
||||||
char *p = buffer;
|
char *p = buffer;
|
||||||
|
|
||||||
if (compat.vulkan) {
|
switch (compat.shaderLanguage) {
|
||||||
WRITE(p, "%s", vulkan_glsl_preamble);
|
case ShaderLanguage::GLSL_VULKAN:
|
||||||
WRITE(p, "#define lowp\n");
|
WRITE(p, "%s", vulkan_glsl_preamble_fs);
|
||||||
WRITE(p, "#define mediump\n");
|
break;
|
||||||
WRITE(p, "#define highp\n");
|
case ShaderLanguage::HLSL_D3D11:
|
||||||
} else {
|
WRITE(p, "%s", hlsl_preamble_fs);
|
||||||
|
WRITE(p, "%s", hlsl_d3d11_preamble_fs);
|
||||||
|
break;
|
||||||
|
case ShaderLanguage::HLSL_D3D9:
|
||||||
|
WRITE(p, "%s", hlsl_preamble_fs);
|
||||||
|
WRITE(p, "%s", hlsl_d3d9_preamble_fs);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// OpenGL
|
||||||
WRITE(p, "#version %d%s\n", compat.glslVersionNumber, compat.gles ? " es" : "");
|
WRITE(p, "#version %d%s\n", compat.glslVersionNumber, compat.gles ? " es" : "");
|
||||||
|
WRITE(p, "#define DISCARD discard\n");
|
||||||
|
|
||||||
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE && gl_extensions.EXT_blend_func_extended) {
|
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE && gl_extensions.EXT_blend_func_extended) {
|
||||||
WRITE(p, "#extension GL_EXT_blend_func_extended : require\n");
|
WRITE(p, "#extension GL_EXT_blend_func_extended : require\n");
|
||||||
@ -102,6 +133,7 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
bool doTextureAlpha = id.Bit(FS_BIT_TEXALPHA);
|
bool doTextureAlpha = id.Bit(FS_BIT_TEXALPHA);
|
||||||
bool doFlatShading = id.Bit(FS_BIT_FLATSHADE);
|
bool doFlatShading = id.Bit(FS_BIT_FLATSHADE);
|
||||||
bool shaderDepal = id.Bit(FS_BIT_SHADER_DEPAL);
|
bool shaderDepal = id.Bit(FS_BIT_SHADER_DEPAL);
|
||||||
|
bool bgraTexture = id.Bit(FS_BIT_BGRA_TEXTURE);
|
||||||
|
|
||||||
GEComparison alphaTestFunc = (GEComparison)id.Bits(FS_BIT_ALPHA_TEST_FUNC, 3);
|
GEComparison alphaTestFunc = (GEComparison)id.Bits(FS_BIT_ALPHA_TEST_FUNC, 3);
|
||||||
GEComparison colorTestFunc = (GEComparison)id.Bits(FS_BIT_COLOR_TEST_FUNC, 2);
|
GEComparison colorTestFunc = (GEComparison)id.Bits(FS_BIT_COLOR_TEST_FUNC, 2);
|
||||||
@ -120,13 +152,13 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
bool isModeClear = id.Bit(FS_BIT_CLEARMODE);
|
bool isModeClear = id.Bit(FS_BIT_CLEARMODE);
|
||||||
|
|
||||||
const char *shading = "";
|
const char *shading = "";
|
||||||
if (compat.glslES30 || compat.vulkan)
|
if (compat.glslES30 || compat.shaderLanguage == ShaderLanguage::GLSL_VULKAN)
|
||||||
shading = doFlatShading ? "flat" : "";
|
shading = doFlatShading ? "flat" : "";
|
||||||
|
|
||||||
bool earlyFragmentTests = ((!enableAlphaTest && !enableColorTest) || testForceToZero) && !gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT);
|
bool earlyFragmentTests = ((!enableAlphaTest && !enableColorTest) || testForceToZero) && !gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT);
|
||||||
bool useAdrenoBugWorkaround = id.Bit(FS_BIT_NO_DEPTH_CANNOT_DISCARD_STENCIL);
|
bool useAdrenoBugWorkaround = id.Bit(FS_BIT_NO_DEPTH_CANNOT_DISCARD_STENCIL);
|
||||||
|
|
||||||
if (compat.vulkan) {
|
if (compat.shaderLanguage == ShaderLanguage::GLSL_VULKAN) {
|
||||||
if (earlyFragmentTests) {
|
if (earlyFragmentTests) {
|
||||||
WRITE(p, "layout (early_fragment_tests) in;\n");
|
WRITE(p, "layout (early_fragment_tests) in;\n");
|
||||||
} else if (useAdrenoBugWorkaround && !gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) {
|
} else if (useAdrenoBugWorkaround && !gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) {
|
||||||
@ -169,7 +201,137 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
|
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
|
||||||
WRITE(p, "layout (location = 0, index = 1) out vec4 fragColor1;\n");
|
WRITE(p, "layout (location = 0, index = 1) out vec4 fragColor1;\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else if (compat.shaderLanguage == HLSL_D3D11 || compat.shaderLanguage == HLSL_D3D9) {
|
||||||
|
if (compat.shaderLanguage == HLSL_D3D9) {
|
||||||
|
if (doTexture)
|
||||||
|
WRITE(p, "sampler tex : register(s0);\n");
|
||||||
|
if (!isModeClear && replaceBlend > REPLACE_BLEND_STANDARD) {
|
||||||
|
if (replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
||||||
|
WRITE(p, "vec2 u_fbotexSize : register(c%i);\n", CONST_PS_FBOTEXSIZE);
|
||||||
|
WRITE(p, "sampler fbotex : register(s1);\n");
|
||||||
|
}
|
||||||
|
if (replaceBlendFuncA >= GE_SRCBLEND_FIXA) {
|
||||||
|
WRITE(p, "float3 u_blendFixA : register(c%i);\n", CONST_PS_BLENDFIXA);
|
||||||
|
}
|
||||||
|
if (replaceBlendFuncB >= GE_DSTBLEND_FIXB) {
|
||||||
|
WRITE(p, "float3 u_blendFixB : register(c%i);\n", CONST_PS_BLENDFIXB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needShaderTexClamp && doTexture) {
|
||||||
|
WRITE(p, "vec4 u_texclamp : register(c%i);\n", CONST_PS_TEXCLAMP);
|
||||||
|
if (textureAtOffset) {
|
||||||
|
WRITE(p, "vec2 u_texclampoff : register(c%i);\n", CONST_PS_TEXCLAMPOFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enableAlphaTest || enableColorTest) {
|
||||||
|
WRITE(p, "vec4 u_alphacolorref : register(c%i);\n", CONST_PS_ALPHACOLORREF);
|
||||||
|
WRITE(p, "vec4 u_alphacolormask : register(c%i);\n", CONST_PS_ALPHACOLORMASK);
|
||||||
|
}
|
||||||
|
if (stencilToAlpha && replaceAlphaWithStencilType == STENCIL_VALUE_UNIFORM) {
|
||||||
|
WRITE(p, "float u_stencilReplaceValue : register(c%i);\n", CONST_PS_STENCILREPLACE);
|
||||||
|
}
|
||||||
|
if (doTexture && texFunc == GE_TEXFUNC_BLEND) {
|
||||||
|
WRITE(p, "float3 u_texenv : register(c%i);\n", CONST_PS_TEXENV);
|
||||||
|
}
|
||||||
|
if (enableFog) {
|
||||||
|
WRITE(p, "float3 u_fogcolor : register(c%i);\n", CONST_PS_FOGCOLOR);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
WRITE(p, "SamplerState samp : register(s0);\n");
|
||||||
|
WRITE(p, "Texture2D<vec4> tex : register(t0);\n");
|
||||||
|
if (!isModeClear && replaceBlend > REPLACE_BLEND_STANDARD) {
|
||||||
|
if (replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
||||||
|
// No sampler required, we Load
|
||||||
|
WRITE(p, "Texture2D<vec4> fboTex : register(t1);\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WRITE(p, "cbuffer base : register(b0) {\n%s};\n", cb_baseStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enableAlphaTest) {
|
||||||
|
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||||
|
WRITE(p, "int roundAndScaleTo255i(float x) { return int(floor(x * 255.0f + 0.5f)); }\n");
|
||||||
|
} else {
|
||||||
|
// D3D11 level 9 gets to take this path.
|
||||||
|
WRITE(p, "float roundAndScaleTo255f(float x) { return floor(x * 255.0f + 0.5f); }\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (enableColorTest) {
|
||||||
|
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||||
|
WRITE(p, "uvec3 roundAndScaleTo255iv(float3 x) { return uvec3(floor(x * 255.0f + 0.5f)); }\n");
|
||||||
|
} else {
|
||||||
|
WRITE(p, "vec3 roundAndScaleTo255v(float3 x) { return floor(x * 255.0f + 0.5f); }\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WRITE(p, "struct PS_IN {\n");
|
||||||
|
if (doTexture) {
|
||||||
|
WRITE(p, " vec3 v_texcoord: TEXCOORD0;\n");
|
||||||
|
}
|
||||||
|
const char *colorInterpolation = doFlatShading && compat.shaderLanguage == HLSL_D3D11 ? "nointerpolation " : "";
|
||||||
|
WRITE(p, " %svec4 v_color0: COLOR0;\n", colorInterpolation);
|
||||||
|
if (lmode) {
|
||||||
|
WRITE(p, " vec3 v_color1: COLOR1;\n");
|
||||||
|
}
|
||||||
|
if (enableFog) {
|
||||||
|
WRITE(p, " float v_fogdepth: TEXCOORD1;\n");
|
||||||
|
}
|
||||||
|
if (compat.shaderLanguage == HLSL_D3D11 && ((replaceBlend == REPLACE_BLEND_COPY_FBO) || gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT))) {
|
||||||
|
WRITE(p, " vec4 pixelPos : SV_POSITION;\n");
|
||||||
|
}
|
||||||
|
WRITE(p, "};\n");
|
||||||
|
|
||||||
|
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||||
|
WRITE(p, "struct PS_OUT {\n");
|
||||||
|
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
|
||||||
|
WRITE(p, " vec4 target : SV_Target0;\n");
|
||||||
|
WRITE(p, " vec4 target1 : SV_Target1;\n");
|
||||||
|
} else {
|
||||||
|
WRITE(p, " vec4 target : SV_Target;\n");
|
||||||
|
}
|
||||||
|
if (gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) {
|
||||||
|
WRITE(p, " float depth : SV_DEPTH;\n");
|
||||||
|
}
|
||||||
|
WRITE(p, "};\n");
|
||||||
|
}
|
||||||
|
} else if (compat.shaderLanguage == HLSL_D3D9) {
|
||||||
|
if (doTexture)
|
||||||
|
WRITE(p, "sampler tex : register(s0);\n");
|
||||||
|
if (!isModeClear && replaceBlend > REPLACE_BLEND_STANDARD) {
|
||||||
|
if (replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
||||||
|
WRITE(p, "vec2 u_fbotexSize : register(c%i);\n", CONST_PS_FBOTEXSIZE);
|
||||||
|
WRITE(p, "sampler fbotex : register(s1);\n");
|
||||||
|
}
|
||||||
|
if (replaceBlendFuncA >= GE_SRCBLEND_FIXA) {
|
||||||
|
WRITE(p, "float3 u_blendFixA : register(c%i);\n", CONST_PS_BLENDFIXA);
|
||||||
|
}
|
||||||
|
if (replaceBlendFuncB >= GE_DSTBLEND_FIXB) {
|
||||||
|
WRITE(p, "float3 u_blendFixB : register(c%i);\n", CONST_PS_BLENDFIXB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (needShaderTexClamp && doTexture) {
|
||||||
|
WRITE(p, "vec4 u_texclamp : register(c%i);\n", CONST_PS_TEXCLAMP);
|
||||||
|
if (textureAtOffset) {
|
||||||
|
WRITE(p, "vec2 u_texclampoff : register(c%i);\n", CONST_PS_TEXCLAMPOFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enableAlphaTest || enableColorTest) {
|
||||||
|
WRITE(p, "vec4 u_alphacolorref : register(c%i);\n", CONST_PS_ALPHACOLORREF);
|
||||||
|
WRITE(p, "vec4 u_alphacolormask : register(c%i);\n", CONST_PS_ALPHACOLORMASK);
|
||||||
|
}
|
||||||
|
if (stencilToAlpha && replaceAlphaWithStencilType == STENCIL_VALUE_UNIFORM) {
|
||||||
|
WRITE(p, "float u_stencilReplaceValue : register(c%i);\n", CONST_PS_STENCILREPLACE);
|
||||||
|
}
|
||||||
|
if (doTexture && texFunc == GE_TEXFUNC_BLEND) {
|
||||||
|
WRITE(p, "float3 u_texenv : register(c%i);\n", CONST_PS_TEXENV);
|
||||||
|
}
|
||||||
|
if (enableFog) {
|
||||||
|
WRITE(p, "float3 u_fogcolor : register(c%i);\n", CONST_PS_FOGCOLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) {
|
||||||
if (shaderDepal && gl_extensions.IsGLES) {
|
if (shaderDepal && gl_extensions.IsGLES) {
|
||||||
WRITE(p, "precision highp int;\n");
|
WRITE(p, "precision highp int;\n");
|
||||||
}
|
}
|
||||||
@ -283,7 +445,27 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
WRITE(p, "float mymod(float a, float b) { return a - b * floor(a / b); }\n");
|
WRITE(p, "float mymod(float a, float b) { return a - b * floor(a / b); }\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, "void main() {\n");
|
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||||
|
WRITE(p, "PS_OUT main( PS_IN In ) {\n");
|
||||||
|
WRITE(p, " PS_OUT outfragment;\n");
|
||||||
|
} else if (compat.shaderLanguage == HLSL_D3D9) {
|
||||||
|
WRITE(p, "vec4 main( PS_IN In ) : COLOR {\n");
|
||||||
|
} else {
|
||||||
|
WRITE(p, "void main() {\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compat.shaderLanguage == HLSL_D3D11 || compat.shaderLanguage == HLSL_D3D9) {
|
||||||
|
WRITE(p, " vec4 v_color0 = In.v_color0;\n");
|
||||||
|
if (lmode)
|
||||||
|
WRITE(p, " vec3 v_color1 = In.v_color1;\n");
|
||||||
|
if (enableFog) {
|
||||||
|
WRITE(p, " float v_fogdepth = In.v_fogdepth;\n");
|
||||||
|
}
|
||||||
|
if (doTexture) {
|
||||||
|
WRITE(p, " vec3 v_texcoord = In.v_texcoord;\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (isModeClear) {
|
if (isModeClear) {
|
||||||
// Clear mode does not allow any fancy shading.
|
// Clear mode does not allow any fancy shading.
|
||||||
WRITE(p, " vec4 v = v_color0;\n");
|
WRITE(p, " vec4 v = v_color0;\n");
|
||||||
@ -298,7 +480,7 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (doTexture) {
|
if (doTexture) {
|
||||||
const char *texcoord = "v_texcoord";
|
char texcoord[64] = "v_texcoord";
|
||||||
// TODO: Not sure the right way to do this for projection.
|
// TODO: Not sure the right way to do this for projection.
|
||||||
// This path destroys resolution on older PowerVR no matter what I do if projection is needed,
|
// This path destroys resolution on older PowerVR no matter what I do if projection is needed,
|
||||||
// so we disable it on SGX 540 and lesser, and live with the consequences.
|
// so we disable it on SGX 540 and lesser, and live with the consequences.
|
||||||
@ -337,17 +519,31 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, " vec2 fixedcoord = vec2(%s, %s);\n", ucoord.c_str(), vcoord.c_str());
|
WRITE(p, " vec2 fixedcoord = vec2(%s, %s);\n", ucoord.c_str(), vcoord.c_str());
|
||||||
texcoord = "fixedcoord";
|
truncate_cpy(texcoord, "fixedcoord");
|
||||||
// We already projected it.
|
// We already projected it.
|
||||||
doTextureProjection = false;
|
doTextureProjection = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shaderDepal) {
|
if (!shaderDepal) {
|
||||||
if (doTextureProjection) {
|
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||||
WRITE(p, " vec4 t = %sProj(tex, %s);\n", compat.texture, texcoord);
|
if (doTextureProjection) {
|
||||||
|
WRITE(p, " vec4 t = tex.Sample(samp, v_texcoord.xy / v_texcoord.z)%s;\n", bgraTexture ? ".bgra" : "");
|
||||||
|
} else {
|
||||||
|
WRITE(p, " vec4 t = tex.Sample(samp, %s.xy)%s;\n", texcoord, bgraTexture ? ".bgra" : "");
|
||||||
|
}
|
||||||
|
} else if (compat.shaderLanguage == HLSL_D3D9) {
|
||||||
|
if (doTextureProjection) {
|
||||||
|
WRITE(p, " vec4 t = tex2Dproj(tex, vec4(v_texcoord.x, v_texcoord.y, 0, v_texcoord.z))%s;\n", bgraTexture ? ".bgra" : "");
|
||||||
|
} else {
|
||||||
|
WRITE(p, " vec4 t = tex2D(tex, %s.xy)%s;\n", texcoord, bgraTexture ? ".bgra" : "");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " vec4 t = %s(tex, %s.xy);\n", compat.texture, texcoord);
|
if (doTextureProjection) {
|
||||||
}
|
WRITE(p, " vec4 t = %sProj(tex, %s);\n", compat.texture, texcoord);
|
||||||
|
} else {
|
||||||
|
WRITE(p, " vec4 t = %s(tex, %s.xy);\n", compat.texture, texcoord);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (doTextureProjection) {
|
if (doTextureProjection) {
|
||||||
// We don't use textureProj because we need better control and it's probably not much of a savings anyway.
|
// We don't use textureProj because we need better control and it's probably not much of a savings anyway.
|
||||||
@ -510,24 +706,21 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
if (enableFog) {
|
if (enableFog) {
|
||||||
WRITE(p, " float fogCoef = clamp(v_fogdepth, 0.0, 1.0);\n");
|
WRITE(p, " float fogCoef = clamp(v_fogdepth, 0.0, 1.0);\n");
|
||||||
WRITE(p, " v = mix(vec4(u_fogcolor, v.a), v, fogCoef);\n");
|
WRITE(p, " v = mix(vec4(u_fogcolor, v.a), v, fogCoef);\n");
|
||||||
// WRITE(p, " v.x = v_depth;\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texture access is at half texels [0.5/256, 255.5/256], but colors are normalized [0, 255].
|
// Texture access is at half texels [0.5/256, 255.5/256], but colors are normalized [0, 255].
|
||||||
// So we have to scale to account for the difference.
|
// So we have to scale to account for the difference.
|
||||||
std::string alphaTestXCoord = "0";
|
char alphaTestXCoord[64] = "0";
|
||||||
if (enableFragmentTestCache) {
|
if (enableFragmentTestCache) {
|
||||||
if (enableColorTest && !colorTestAgainstZero) {
|
if (enableColorTest && !colorTestAgainstZero) {
|
||||||
WRITE(p, " vec4 vScale256 = v * %f + %f;\n", 255.0 / 256.0, 0.5 / 256.0);
|
WRITE(p, " vec4 vScale256 = v * %f + %f;\n", 255.0 / 256.0, 0.5 / 256.0);
|
||||||
alphaTestXCoord = "vScale256.a";
|
truncate_cpy(alphaTestXCoord, "vScale256.a");
|
||||||
} else if (enableAlphaTest && !alphaTestAgainstZero) {
|
} else if (enableAlphaTest && !alphaTestAgainstZero) {
|
||||||
char temp[64];
|
snprintf(alphaTestXCoord, sizeof(alphaTestXCoord), "v.a * %f + %f", 255.0 / 256.0, 0.5 / 256.0);
|
||||||
snprintf(temp, sizeof(temp), "v.a * %f + %f", 255.0 / 256.0, 0.5 / 256.0);
|
|
||||||
alphaTestXCoord = temp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *discardStatement = testForceToZero ? "v.a = 0.0;" : "discard;";
|
const char *discardStatement = testForceToZero ? "v.a = 0.0;" : "DISCARD;";
|
||||||
if (enableAlphaTest) {
|
if (enableAlphaTest) {
|
||||||
if (alphaTestAgainstZero) {
|
if (alphaTestAgainstZero) {
|
||||||
// When testing against 0 (extremely common), we can avoid some math.
|
// When testing against 0 (extremely common), we can avoid some math.
|
||||||
@ -543,7 +736,7 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
WRITE(p, " %s\n", discardStatement);
|
WRITE(p, " %s\n", discardStatement);
|
||||||
}
|
}
|
||||||
} else if (enableFragmentTestCache) {
|
} else if (enableFragmentTestCache) {
|
||||||
WRITE(p, " float aResult = %s(testtex, vec2(%s, 0)).a;\n", compat.texture, alphaTestXCoord.c_str());
|
WRITE(p, " float aResult = %s(testtex, vec2(%s, 0)).a;\n", compat.texture, alphaTestXCoord);
|
||||||
WRITE(p, " if (aResult < 0.5) %s\n", discardStatement);
|
WRITE(p, " if (aResult < 0.5) %s\n", discardStatement);
|
||||||
} else {
|
} else {
|
||||||
const char *alphaTestFuncs[] = { "#", "#", " != ", " == ", " >= ", " > ", " <= ", " < " };
|
const char *alphaTestFuncs[] = { "#", "#", " != ", " == ", " >= ", " > ", " <= ", " < " };
|
||||||
@ -593,10 +786,23 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
} else {
|
} else {
|
||||||
const char *colorTestFuncs[] = { "#", "#", " != ", " == " };
|
const char *colorTestFuncs[] = { "#", "#", " != ", " == " };
|
||||||
if (colorTestFuncs[colorTestFunc][0] != '#') {
|
if (colorTestFuncs[colorTestFunc][0] != '#') {
|
||||||
if (compat.bitwiseOps) {
|
// TODO: Unify these paths better.
|
||||||
|
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||||
|
const char *test = colorTestFuncs[colorTestFunc];
|
||||||
|
WRITE(p, " uvec3 v_scaled = roundAndScaleTo255iv(v.rgb);\n");
|
||||||
|
WRITE(p, " uvec3 v_masked = v_scaled & u_alphacolormask.rgb;\n");
|
||||||
|
WRITE(p, " uvec3 colorTestRef = u_alphacolorref.rgb & u_alphacolormask.rgb;\n");
|
||||||
|
// We have to test the components separately, or we get incorrect results. See #10629.
|
||||||
|
WRITE(p, " if (v_masked.r %s colorTestRef.r && v_masked.g %s colorTestRef.g && v_masked.b %s colorTestRef.b) %s\n", test, test, test, discardStatement);
|
||||||
|
} else if (compat.shaderLanguage == HLSL_D3D9) {
|
||||||
|
const char *test = colorTestFuncs[colorTestFunc];
|
||||||
|
// TODO: Use a texture to lookup bitwise ops instead?
|
||||||
|
WRITE(p, " vec3 colortest = roundAndScaleTo255v(v.rgb);\n");
|
||||||
|
WRITE(p, " if ((colortest.r %s u_alphacolorref.r) && (colortest.g %s u_alphacolorref.g) && (colortest.b %s u_alphacolorref.b)) %s\n", test, test, test, discardStatement);
|
||||||
|
} else if (compat.bitwiseOps) {
|
||||||
// Apparently GLES3 does not support vector bitwise ops.
|
// Apparently GLES3 does not support vector bitwise ops.
|
||||||
WRITE(p, " ivec3 v_scaled = roundAndScaleTo255iv(v.rgb);\n");
|
WRITE(p, " ivec3 v_scaled = roundAndScaleTo255iv(v.rgb);\n");
|
||||||
if (compat.vulkan) {
|
if (compat.shaderLanguage == GLSL_VULKAN) {
|
||||||
// TODO: Use this for GL as well?
|
// TODO: Use this for GL as well?
|
||||||
WRITE(p, " if ((v_scaled & u_alphacolormask.rgb) %s (u_alphacolorref.rgb & u_alphacolormask.rgb)) %s\n", colorTestFuncs[colorTestFunc], discardStatement);
|
WRITE(p, " if ((v_scaled & u_alphacolormask.rgb) %s (u_alphacolorref.rgb & u_alphacolormask.rgb)) %s\n", colorTestFuncs[colorTestFunc], discardStatement);
|
||||||
} else {
|
} else {
|
||||||
@ -646,10 +852,12 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
WRITE(p, " v.rgb = v.rgb * %s;\n", srcFactor);
|
WRITE(p, " v.rgb = v.rgb * %s;\n", srcFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
if (replaceBlend == REPLACE_BLEND_COPY_FBO && compat.shaderLanguage != HLSL_D3D9) {
|
||||||
// If we have NV_shader_framebuffer_fetch / EXT_shader_framebuffer_fetch, we skip the blit.
|
// If we have NV_shader_framebuffer_fetch / EXT_shader_framebuffer_fetch, we skip the blit.
|
||||||
// We can just read the prev value more directly.
|
// We can just read the prev value more directly.
|
||||||
if (gstate_c.Supports(GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH)) {
|
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||||
|
WRITE(p, " vec4 destColor = fboTex.Load(int3((int)In.pixelPos.x, (int)In.pixelPos.y, 0));\n");
|
||||||
|
} else if (gstate_c.Supports(GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH)) {
|
||||||
WRITE(p, " lowp vec4 destColor = %s;\n", compat.lastFragData);
|
WRITE(p, " lowp vec4 destColor = %s;\n", compat.lastFragData);
|
||||||
} else if (!compat.texelFetch) {
|
} else if (!compat.texelFetch) {
|
||||||
WRITE(p, " lowp vec4 destColor = %s(fbotex, gl_FragCoord.xy * u_fbotexSize.xy);\n", compat.texture);
|
WRITE(p, " lowp vec4 destColor = %s(fbotex, gl_FragCoord.xy * u_fbotexSize.xy);\n", compat.texture);
|
||||||
@ -657,34 +865,34 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
WRITE(p, " lowp vec4 destColor = %s(fbotex, ivec2(gl_FragCoord.x, gl_FragCoord.y), 0);\n", compat.texelFetch);
|
WRITE(p, " lowp vec4 destColor = %s(fbotex, ivec2(gl_FragCoord.x, gl_FragCoord.y), 0);\n", compat.texelFetch);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *srcFactor = "splat3(1.0)";
|
const char *srcFactor = nullptr;
|
||||||
const char *dstFactor = "splat3(0.0)";
|
const char *dstFactor = nullptr;
|
||||||
|
|
||||||
switch (replaceBlendFuncA) {
|
switch (replaceBlendFuncA) {
|
||||||
case GE_SRCBLEND_DSTCOLOR: srcFactor = "destColor.rgb"; break;
|
case GE_SRCBLEND_DSTCOLOR: srcFactor = "destColor.rgb"; break;
|
||||||
case GE_SRCBLEND_INVDSTCOLOR: srcFactor = "(splat3(1.0) - destColor.rgb)"; break;
|
case GE_SRCBLEND_INVDSTCOLOR: srcFactor = "(splat3(1.0) - destColor.rgb)"; break;
|
||||||
case GE_SRCBLEND_SRCALPHA: srcFactor = "splat3(v.a)"; break;
|
case GE_SRCBLEND_SRCALPHA: srcFactor = "v.aaa"; break;
|
||||||
case GE_SRCBLEND_INVSRCALPHA: srcFactor = "splat3(1.0 - v.a)"; break;
|
case GE_SRCBLEND_INVSRCALPHA: srcFactor = "splat3(1.0 - v.a)"; break;
|
||||||
case GE_SRCBLEND_DSTALPHA: srcFactor = "splat3(destColor.a)"; break;
|
case GE_SRCBLEND_DSTALPHA: srcFactor = "destColor.aaa"; break;
|
||||||
case GE_SRCBLEND_INVDSTALPHA: srcFactor = "splat3(1.0 - destColor.a)"; break;
|
case GE_SRCBLEND_INVDSTALPHA: srcFactor = "splat3(1.0) - destColor.aaa"; break;
|
||||||
case GE_SRCBLEND_DOUBLESRCALPHA: srcFactor = "splat3(v.a * 2.0)"; break;
|
case GE_SRCBLEND_DOUBLESRCALPHA: srcFactor = "v.aaa * 2.0"; break;
|
||||||
case GE_SRCBLEND_DOUBLEINVSRCALPHA: srcFactor = "splat3(1.0 - v.a * 2.0)"; break;
|
case GE_SRCBLEND_DOUBLEINVSRCALPHA: srcFactor = "splat3(1.0) - v.aaa * 2.0"; break;
|
||||||
case GE_SRCBLEND_DOUBLEDSTALPHA: srcFactor = "splat3(destColor.a * 2.0)"; break;
|
case GE_SRCBLEND_DOUBLEDSTALPHA: srcFactor = "destColor.aaa * 2.0"; break;
|
||||||
case GE_SRCBLEND_DOUBLEINVDSTALPHA: srcFactor = "splat3(1.0 - destColor.a * 2.0)"; break;
|
case GE_SRCBLEND_DOUBLEINVDSTALPHA: srcFactor = "splat3(1.0) - destColor.aaa * 2.0"; break;
|
||||||
case GE_SRCBLEND_FIXA: srcFactor = "u_blendFixA"; break;
|
case GE_SRCBLEND_FIXA: srcFactor = "u_blendFixA"; break;
|
||||||
default: srcFactor = "u_blendFixA"; break;
|
default: srcFactor = "u_blendFixA"; break;
|
||||||
}
|
}
|
||||||
switch (replaceBlendFuncB) {
|
switch (replaceBlendFuncB) {
|
||||||
case GE_DSTBLEND_SRCCOLOR: dstFactor = "v.rgb"; break;
|
case GE_DSTBLEND_SRCCOLOR: dstFactor = "v.rgb"; break;
|
||||||
case GE_DSTBLEND_INVSRCCOLOR: dstFactor = "(splat3(1.0) - v.rgb)"; break;
|
case GE_DSTBLEND_INVSRCCOLOR: dstFactor = "(splat3(1.0) - v.rgb)"; break;
|
||||||
case GE_DSTBLEND_SRCALPHA: dstFactor = "splat3(v.a)"; break;
|
case GE_DSTBLEND_SRCALPHA: dstFactor = "v.aaa"; break;
|
||||||
case GE_DSTBLEND_INVSRCALPHA: dstFactor = "splat3(1.0 - v.a)"; break;
|
case GE_DSTBLEND_INVSRCALPHA: dstFactor = "splat3(1.0) - v.aaa"; break;
|
||||||
case GE_DSTBLEND_DSTALPHA: dstFactor = "splat3(destColor.a)"; break;
|
case GE_DSTBLEND_DSTALPHA: dstFactor = "destColor.aaa"; break;
|
||||||
case GE_DSTBLEND_INVDSTALPHA: dstFactor = "splat3(1.0 - destColor.a)"; break;
|
case GE_DSTBLEND_INVDSTALPHA: dstFactor = "splat3(1.0) - destColor.aaa"; break;
|
||||||
case GE_DSTBLEND_DOUBLESRCALPHA: dstFactor = "splat3(v.a * 2.0)"; break;
|
case GE_DSTBLEND_DOUBLESRCALPHA: dstFactor = "v.aaa * 2.0"; break;
|
||||||
case GE_DSTBLEND_DOUBLEINVSRCALPHA: dstFactor = "splat3(1.0 - v.a * 2.0)"; break;
|
case GE_DSTBLEND_DOUBLEINVSRCALPHA: dstFactor = "splat3(1.0) - v.aaa * 2.0"; break;
|
||||||
case GE_DSTBLEND_DOUBLEDSTALPHA: dstFactor = "splat3(destColor.a * 2.0)"; break;
|
case GE_DSTBLEND_DOUBLEDSTALPHA: dstFactor = "destColor.aaa * 2.0"; break;
|
||||||
case GE_DSTBLEND_DOUBLEINVDSTALPHA: dstFactor = "splat3(1.0 - destColor.a * 2.0)"; break;
|
case GE_DSTBLEND_DOUBLEINVDSTALPHA: dstFactor = "splat3(1.0) - destColor.aaa * 2.0"; break;
|
||||||
case GE_DSTBLEND_FIXB: dstFactor = "u_blendFixB"; break;
|
case GE_DSTBLEND_FIXB: dstFactor = "u_blendFixB"; break;
|
||||||
default: dstFactor = "u_blendFixB"; break;
|
default: dstFactor = "u_blendFixB"; break;
|
||||||
}
|
}
|
||||||
@ -719,36 +927,33 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string replacedAlpha = "0.0";
|
char replacedAlpha[64] = "0.0";
|
||||||
char replacedAlphaTemp[64] = "";
|
|
||||||
if (stencilToAlpha != REPLACE_ALPHA_NO) {
|
if (stencilToAlpha != REPLACE_ALPHA_NO) {
|
||||||
switch (replaceAlphaWithStencilType) {
|
switch (replaceAlphaWithStencilType) {
|
||||||
case STENCIL_VALUE_UNIFORM:
|
case STENCIL_VALUE_UNIFORM:
|
||||||
replacedAlpha = "u_stencilReplaceValue";
|
truncate_cpy(replacedAlpha, "u_stencilReplaceValue");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STENCIL_VALUE_ZERO:
|
case STENCIL_VALUE_ZERO:
|
||||||
replacedAlpha = "0.0";
|
truncate_cpy(replacedAlpha, "0.0");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STENCIL_VALUE_ONE:
|
case STENCIL_VALUE_ONE:
|
||||||
case STENCIL_VALUE_INVERT:
|
case STENCIL_VALUE_INVERT:
|
||||||
// In invert, we subtract by one, but we want to output one here.
|
// In invert, we subtract by one, but we want to output one here.
|
||||||
replacedAlpha = "1.0";
|
truncate_cpy(replacedAlpha, "1.0");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STENCIL_VALUE_INCR_4:
|
case STENCIL_VALUE_INCR_4:
|
||||||
case STENCIL_VALUE_DECR_4:
|
case STENCIL_VALUE_DECR_4:
|
||||||
// We're adding/subtracting, just by the smallest value in 4-bit.
|
// We're adding/subtracting, just by the smallest value in 4-bit.
|
||||||
snprintf(replacedAlphaTemp, sizeof(replacedAlphaTemp), "%f", 1.0 / 15.0);
|
snprintf(replacedAlpha, sizeof(replacedAlpha), "%f", 1.0 / 15.0);
|
||||||
replacedAlpha = replacedAlphaTemp;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STENCIL_VALUE_INCR_8:
|
case STENCIL_VALUE_INCR_8:
|
||||||
case STENCIL_VALUE_DECR_8:
|
case STENCIL_VALUE_DECR_8:
|
||||||
// We're adding/subtracting, just by the smallest value in 8-bit.
|
// We're adding/subtracting, just by the smallest value in 8-bit.
|
||||||
snprintf(replacedAlphaTemp, sizeof(replacedAlphaTemp), "%f", 1.0 / 255.0);
|
snprintf(replacedAlpha, sizeof(replacedAlpha), "%f", 1.0 / 255.0);
|
||||||
replacedAlpha = replacedAlphaTemp;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STENCIL_VALUE_KEEP:
|
case STENCIL_VALUE_KEEP:
|
||||||
@ -759,16 +964,15 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
|
|
||||||
switch (stencilToAlpha) {
|
switch (stencilToAlpha) {
|
||||||
case REPLACE_ALPHA_DUALSOURCE:
|
case REPLACE_ALPHA_DUALSOURCE:
|
||||||
WRITE(p, " %s = vec4(v.rgb, %s);\n", compat.fragColor0, replacedAlpha.c_str());
|
// Handled at the end.
|
||||||
WRITE(p, " %s = vec4(0.0, 0.0, 0.0, v.a);\n", compat.fragColor1);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REPLACE_ALPHA_YES:
|
case REPLACE_ALPHA_YES:
|
||||||
WRITE(p, " %s = vec4(v.rgb, %s);\n", compat.fragColor0, replacedAlpha.c_str());
|
WRITE(p, " v.a = %s;\n", replacedAlpha);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REPLACE_ALPHA_NO:
|
case REPLACE_ALPHA_NO:
|
||||||
WRITE(p, " %s = v;\n", compat.fragColor0);
|
// Nothing to do.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -779,10 +983,10 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
LogicOpReplaceType replaceLogicOpType = (LogicOpReplaceType)id.Bits(FS_BIT_REPLACE_LOGIC_OP_TYPE, 2);
|
LogicOpReplaceType replaceLogicOpType = (LogicOpReplaceType)id.Bits(FS_BIT_REPLACE_LOGIC_OP_TYPE, 2);
|
||||||
switch (replaceLogicOpType) {
|
switch (replaceLogicOpType) {
|
||||||
case LOGICOPTYPE_ONE:
|
case LOGICOPTYPE_ONE:
|
||||||
WRITE(p, " %s.rgb = vec3(1.0, 1.0, 1.0);\n", compat.fragColor0);
|
WRITE(p, " v.rgb = splat3(1.0);\n");
|
||||||
break;
|
break;
|
||||||
case LOGICOPTYPE_INVERT:
|
case LOGICOPTYPE_INVERT:
|
||||||
WRITE(p, " %s.rgb = vec3(1.0, 1.0, 1.0) - %s.rgb;\n", compat.fragColor0, compat.fragColor0);
|
WRITE(p, " v.rgb = splat3(1.0) - v.rgb;\n");
|
||||||
break;
|
break;
|
||||||
case LOGICOPTYPE_NORMAL:
|
case LOGICOPTYPE_NORMAL:
|
||||||
break;
|
break;
|
||||||
@ -814,6 +1018,19 @@ bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLSha
|
|||||||
WRITE(p, " gl_FragDepth = gl_FragCoord.z;\n");
|
WRITE(p, " gl_FragDepth = gl_FragCoord.z;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
|
||||||
|
WRITE(p, " %s = vec4(v.rgb, %s);\n", compat.fragColor0, replacedAlpha);
|
||||||
|
WRITE(p, " %s = vec4(0.0, 0.0, 0.0, v.a);\n", compat.fragColor1);
|
||||||
|
} else if (compat.shaderLanguage != HLSL_D3D9) {
|
||||||
|
WRITE(p, " %s = v;\n", compat.fragColor0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||||
|
WRITE(p, " return outfragment;\n");
|
||||||
|
} else if (compat.shaderLanguage == HLSL_D3D9) {
|
||||||
|
WRITE(p, " return v;\n");
|
||||||
|
}
|
||||||
|
|
||||||
WRITE(p, "}\n");
|
WRITE(p, "}\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
@ -17,10 +17,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "GPU/Common/ShaderId.h"
|
|
||||||
#include "GPU/Common/ShaderCommon.h"
|
#include "GPU/Common/ShaderCommon.h"
|
||||||
|
|
||||||
bool GenerateFragmentShaderHLSL(const FShaderID &id, char *buffer, ShaderLanguage lang, std::string *errorString);
|
struct FShaderID;
|
||||||
|
|
||||||
|
// D3D9 constants
|
||||||
|
|
||||||
#define CONST_PS_TEXENV 0
|
#define CONST_PS_TEXENV 0
|
||||||
#define CONST_PS_ALPHACOLORREF 1
|
#define CONST_PS_ALPHACOLORREF 1
|
||||||
@ -35,3 +36,5 @@ bool GenerateFragmentShaderHLSL(const FShaderID &id, char *buffer, ShaderLanguag
|
|||||||
|
|
||||||
// For stencil upload
|
// For stencil upload
|
||||||
#define CONST_PS_STENCILVALUE 10
|
#define CONST_PS_STENCILVALUE 10
|
||||||
|
|
||||||
|
bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLanguageDesc &compat, uint64_t *uniformMask, std::string *errorString);
|
@ -372,7 +372,7 @@ Draw::Pipeline *PresentationCommon::CreatePipeline(std::vector<Draw::ShaderModul
|
|||||||
Semantic pos = SEM_POSITION;
|
Semantic pos = SEM_POSITION;
|
||||||
Semantic tc = SEM_TEXCOORD0;
|
Semantic tc = SEM_TEXCOORD0;
|
||||||
// Shader translation marks these both as "TEXCOORDs" on HLSL...
|
// Shader translation marks these both as "TEXCOORDs" on HLSL...
|
||||||
if (postShader && (lang_ == HLSL_D3D11 || lang_ == HLSL_DX9)) {
|
if (postShader && (lang_ == HLSL_D3D11 || lang_ == HLSL_D3D9)) {
|
||||||
pos = SEM_TEXCOORD0;
|
pos = SEM_TEXCOORD0;
|
||||||
tc = SEM_TEXCOORD1;
|
tc = SEM_TEXCOORD1;
|
||||||
}
|
}
|
||||||
@ -488,7 +488,7 @@ Draw::ShaderModule *PresentationCommon::CompileShaderModule(Draw::ShaderStage st
|
|||||||
case GLSL_VULKAN:
|
case GLSL_VULKAN:
|
||||||
mappedLang = Draw::ShaderLanguage::GLSL_VULKAN;
|
mappedLang = Draw::ShaderLanguage::GLSL_VULKAN;
|
||||||
break;
|
break;
|
||||||
case HLSL_DX9:
|
case HLSL_D3D9:
|
||||||
mappedLang = Draw::ShaderLanguage::HLSL_D3D9;
|
mappedLang = Draw::ShaderLanguage::HLSL_D3D9;
|
||||||
break;
|
break;
|
||||||
case HLSL_D3D11:
|
case HLSL_D3D11:
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#undef new
|
#undef new
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "ext/glslang/SPIRV/GlslangToSpv.h"
|
#include "ext/glslang/SPIRV/GlslangToSpv.h"
|
||||||
|
|
||||||
#include "ShaderCommon.h"
|
#include "ShaderCommon.h"
|
||||||
@ -102,21 +101,77 @@ void init_resources(TBuiltInResource &Resources) {
|
|||||||
Resources.limits.generalConstantMatrixVectorIndexing = 1;
|
Resources.limits.generalConstantMatrixVectorIndexing = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLSLShaderCompat::SetupForVulkan() {
|
ShaderLanguageDesc::ShaderLanguageDesc(ShaderLanguage lang) {
|
||||||
fragColor0 = "fragColor0";
|
shaderLanguage = lang;
|
||||||
fragColor1 = "fragColor1";
|
switch (lang) {
|
||||||
varying_fs = "in";
|
case GLSL_140:
|
||||||
varying_vs = "out";
|
// Just used in the shader test, and as a basis for the others in DetectShaderLanguage.
|
||||||
attribute = "in";
|
glslVersionNumber = 110;
|
||||||
bitwiseOps = true;
|
attribute = "attribute";
|
||||||
framebufferFetchExtension = nullptr;
|
varying_vs = "varying";
|
||||||
gles = false;
|
varying_fs = "varying";
|
||||||
glslES30 = true;
|
fragColor0 = "gl_FragColor";
|
||||||
glslVersionNumber = 450;
|
fragColor1 = "fragColor1";
|
||||||
lastFragData = nullptr;
|
texture = "texture2D";
|
||||||
texture = "texture";
|
texelFetch = nullptr;
|
||||||
texelFetch = "texelFetch";
|
bitwiseOps = false;
|
||||||
vulkan = true;
|
lastFragData = nullptr;
|
||||||
forceMatrix4x4 = false;
|
gles = false;
|
||||||
coefsFromBuffers = true;
|
forceMatrix4x4 = true;
|
||||||
|
break;
|
||||||
|
case GLSL_300:
|
||||||
|
// Just used in the shader test.
|
||||||
|
glslVersionNumber = 300; // GLSL ES 3.0
|
||||||
|
varying_vs = "out";
|
||||||
|
varying_fs = "in";
|
||||||
|
attribute = "in";
|
||||||
|
fragColor0 = "fragColor0";
|
||||||
|
fragColor1 = "fragColor1";
|
||||||
|
texture = "texture";
|
||||||
|
texelFetch = nullptr;
|
||||||
|
bitwiseOps = false;
|
||||||
|
lastFragData = nullptr;
|
||||||
|
gles = false;
|
||||||
|
forceMatrix4x4 = true;
|
||||||
|
glslES30 = true;
|
||||||
|
bitwiseOps = true;
|
||||||
|
texelFetch = "texelFetch";
|
||||||
|
break;
|
||||||
|
case GLSL_VULKAN:
|
||||||
|
fragColor0 = "fragColor0";
|
||||||
|
fragColor1 = "fragColor1";
|
||||||
|
varying_fs = "in";
|
||||||
|
varying_vs = "out";
|
||||||
|
attribute = "in";
|
||||||
|
bitwiseOps = true;
|
||||||
|
framebufferFetchExtension = nullptr;
|
||||||
|
gles = false;
|
||||||
|
glslES30 = true;
|
||||||
|
glslVersionNumber = 450;
|
||||||
|
lastFragData = nullptr;
|
||||||
|
texture = "texture";
|
||||||
|
texelFetch = "texelFetch";
|
||||||
|
forceMatrix4x4 = false;
|
||||||
|
coefsFromBuffers = true;
|
||||||
|
break;
|
||||||
|
case HLSL_D3D9:
|
||||||
|
case HLSL_D3D11:
|
||||||
|
fragColor0 = "outfragment.target";
|
||||||
|
fragColor1 = "outfragment.target1";
|
||||||
|
varying_fs = "in";
|
||||||
|
varying_vs = "out";
|
||||||
|
attribute = "in";
|
||||||
|
bitwiseOps = lang == HLSL_D3D11;
|
||||||
|
framebufferFetchExtension = nullptr;
|
||||||
|
gles = false;
|
||||||
|
glslES30 = true;
|
||||||
|
glslVersionNumber = 0;
|
||||||
|
lastFragData = nullptr;
|
||||||
|
texture = "texture";
|
||||||
|
texelFetch = "texelFetch";
|
||||||
|
forceMatrix4x4 = false;
|
||||||
|
coefsFromBuffers = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,13 +25,17 @@ namespace Draw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum ShaderLanguage {
|
enum ShaderLanguage {
|
||||||
GLSL_140,
|
GLSL_140, // really covers a lot more. This set of languages is not good.
|
||||||
GLSL_300,
|
GLSL_300,
|
||||||
GLSL_VULKAN,
|
GLSL_VULKAN,
|
||||||
HLSL_DX9,
|
HLSL_D3D9,
|
||||||
HLSL_D3D11,
|
HLSL_D3D11,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool ShaderLanguageIsOpenGL(ShaderLanguage lang) {
|
||||||
|
return lang == GLSL_140 || lang == GLSL_300;
|
||||||
|
}
|
||||||
|
|
||||||
enum DebugShaderType {
|
enum DebugShaderType {
|
||||||
SHADER_TYPE_VERTEX = 0,
|
SHADER_TYPE_VERTEX = 0,
|
||||||
SHADER_TYPE_FRAGMENT = 1,
|
SHADER_TYPE_FRAGMENT = 1,
|
||||||
@ -138,25 +142,25 @@ enum DoLightComputation {
|
|||||||
LIGHT_FULL,
|
LIGHT_FULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GLSLShaderCompat {
|
struct ShaderLanguageDesc {
|
||||||
int glslVersionNumber;
|
explicit ShaderLanguageDesc(ShaderLanguage lang);
|
||||||
bool gles;
|
|
||||||
bool vulkan;
|
|
||||||
const char *varying_fs;
|
|
||||||
const char *varying_vs;
|
|
||||||
const char *attribute;
|
|
||||||
const char *fragColor0;
|
|
||||||
const char *fragColor1;
|
|
||||||
const char *texture;
|
|
||||||
const char *texelFetch;
|
|
||||||
const char *lastFragData;
|
|
||||||
const char *framebufferFetchExtension;
|
|
||||||
bool glslES30;
|
|
||||||
bool bitwiseOps;
|
|
||||||
bool forceMatrix4x4;
|
|
||||||
bool coefsFromBuffers;
|
|
||||||
|
|
||||||
void SetupForVulkan();
|
int glslVersionNumber = 0;
|
||||||
|
ShaderLanguage shaderLanguage;
|
||||||
|
bool gles = false;
|
||||||
|
const char *varying_fs = nullptr;
|
||||||
|
const char *varying_vs = nullptr;
|
||||||
|
const char *attribute = nullptr;
|
||||||
|
const char *fragColor0 = nullptr;
|
||||||
|
const char *fragColor1 = nullptr;
|
||||||
|
const char *texture = nullptr;
|
||||||
|
const char *texelFetch = nullptr;
|
||||||
|
const char *lastFragData = nullptr;
|
||||||
|
const char *framebufferFetchExtension = nullptr;
|
||||||
|
bool glslES30 = false;
|
||||||
|
bool bitwiseOps = false;
|
||||||
|
bool forceMatrix4x4 = false;
|
||||||
|
bool coefsFromBuffers = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// PSP vertex format.
|
// PSP vertex format.
|
||||||
|
@ -164,10 +164,9 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void SetBits(int bit, int count, int value) {
|
void SetBits(int bit, int count, int value) {
|
||||||
if (value != 0) {
|
const int mask = (1 << count) - 1;
|
||||||
const int mask = (1 << count) - 1;
|
const int shifted_mask = mask << (bit & 31);
|
||||||
d[bit >> 5] |= (value & mask) << (bit & 31);
|
d[bit >> 5] = (d[bit >> 5] & ~shifted_mask) | ((value & mask) << (bit & 31));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ float u_video : register(c5);
|
|||||||
// Should probably do it in the source shader instead and then back translate to old style GLSL, but
|
// Should probably do it in the source shader instead and then back translate to old style GLSL, but
|
||||||
// SPIRV-Cross currently won't compile with the Android NDK so I can't be bothered.
|
// SPIRV-Cross currently won't compile with the Android NDK so I can't be bothered.
|
||||||
std::string Postprocess(std::string code, ShaderLanguage lang, Draw::ShaderStage stage) {
|
std::string Postprocess(std::string code, ShaderLanguage lang, Draw::ShaderStage stage) {
|
||||||
if (lang != HLSL_D3D11 && lang != HLSL_DX9)
|
if (lang != HLSL_D3D11 && lang != HLSL_D3D9)
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
@ -134,18 +134,18 @@ std::string Postprocess(std::string code, ShaderLanguage lang, Draw::ShaderStage
|
|||||||
// Output the uniform buffer.
|
// Output the uniform buffer.
|
||||||
if (lang == HLSL_D3D11)
|
if (lang == HLSL_D3D11)
|
||||||
out << cbufferDecl;
|
out << cbufferDecl;
|
||||||
else if (lang == HLSL_DX9)
|
else if (lang == HLSL_D3D9)
|
||||||
out << d3d9RegisterDecl;
|
out << d3d9RegisterDecl;
|
||||||
|
|
||||||
// Alright, now let's go through it line by line and zap the single uniforms.
|
// Alright, now let's go through it line by line and zap the single uniforms.
|
||||||
std::string line;
|
std::string line;
|
||||||
std::stringstream instream(code);
|
std::stringstream instream(code);
|
||||||
while (std::getline(instream, line)) {
|
while (std::getline(instream, line)) {
|
||||||
if (line == "uniform sampler2D sampler0;" && lang == HLSL_DX9) {
|
if (line == "uniform sampler2D sampler0;" && lang == HLSL_D3D9) {
|
||||||
out << "sampler2D sampler0 : register(s0);\n";
|
out << "sampler2D sampler0 : register(s0);\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (line == "uniform sampler2D sampler1;" && lang == HLSL_DX9) {
|
if (line == "uniform sampler2D sampler1;" && lang == HLSL_D3D9) {
|
||||||
out << "sampler2D sampler1 : register(s1);\n";
|
out << "sampler2D sampler1 : register(s1);\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -291,7 +291,7 @@ bool TranslateShader(std::string *dest, ShaderLanguage destLang, TranslatedShade
|
|||||||
|
|
||||||
switch (destLang) {
|
switch (destLang) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
case HLSL_DX9:
|
case HLSL_D3D9:
|
||||||
{
|
{
|
||||||
spirv_cross::CompilerHLSL hlsl(spirv);
|
spirv_cross::CompilerHLSL hlsl(spirv);
|
||||||
spirv_cross::CompilerHLSL::Options options{};
|
spirv_cross::CompilerHLSL::Options options{};
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
#include "GPU/Common/VertexDecoderCommon.h"
|
#include "GPU/Common/VertexDecoderCommon.h"
|
||||||
#include "GPU/Common/DrawEngineCommon.h"
|
#include "GPU/Common/DrawEngineCommon.h"
|
||||||
#include "GPU/Common/GPUStateUtils.h"
|
#include "GPU/Common/GPUStateUtils.h"
|
||||||
#include "GPU/Directx9/FragmentShaderGeneratorHLSL.h"
|
|
||||||
#include "GPU/D3D11/StateMappingD3D11.h"
|
#include "GPU/D3D11/StateMappingD3D11.h"
|
||||||
#include "GPU/D3D11/D3D11Util.h"
|
#include "GPU/D3D11/D3D11Util.h"
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ static const char *vscode =
|
|||||||
"struct VS_IN {\n"
|
"struct VS_IN {\n"
|
||||||
" float4 ObjPos : POSITION;\n"
|
" float4 ObjPos : POSITION;\n"
|
||||||
" float2 Uv : TEXCOORD0;\n"
|
" float2 Uv : TEXCOORD0;\n"
|
||||||
"};"
|
"};\n"
|
||||||
"struct VS_OUT {\n"
|
"struct VS_OUT {\n"
|
||||||
" float2 Uv : TEXCOORD0;\n"
|
" float2 Uv : TEXCOORD0;\n"
|
||||||
" float4 ProjPos : SV_Position;\n"
|
" float4 ProjPos : SV_Position;\n"
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
#include "GPU/GPUState.h"
|
#include "GPU/GPUState.h"
|
||||||
#include "GPU/ge_constants.h"
|
#include "GPU/ge_constants.h"
|
||||||
#include "GPU/D3D11/ShaderManagerD3D11.h"
|
#include "GPU/D3D11/ShaderManagerD3D11.h"
|
||||||
#include "GPU/Directx9/FragmentShaderGeneratorHLSL.h"
|
|
||||||
#include "GPU/Directx9/VertexShaderGeneratorHLSL.h"
|
#include "GPU/Directx9/VertexShaderGeneratorHLSL.h"
|
||||||
#include "GPU/D3D11/D3D11Util.h"
|
#include "GPU/D3D11/D3D11Util.h"
|
||||||
|
|
||||||
@ -90,7 +89,7 @@ std::string D3D11VertexShader::GetShaderString(DebugShaderStringType type) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShaderManagerD3D11::ShaderManagerD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context, D3D_FEATURE_LEVEL featureLevel)
|
ShaderManagerD3D11::ShaderManagerD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context, D3D_FEATURE_LEVEL featureLevel)
|
||||||
: ShaderManagerCommon(draw), device_(device), context_(context), featureLevel_(featureLevel), lastVShader_(nullptr), lastFShader_(nullptr) {
|
: ShaderManagerCommon(draw), device_(device), context_(context), featureLevel_(featureLevel), compat_(ShaderLanguage::HLSL_D3D11) {
|
||||||
codeBuffer_ = new char[16384];
|
codeBuffer_ = new char[16384];
|
||||||
memset(&ub_base, 0, sizeof(ub_base));
|
memset(&ub_base, 0, sizeof(ub_base));
|
||||||
memset(&ub_lights, 0, sizeof(ub_lights));
|
memset(&ub_lights, 0, sizeof(ub_lights));
|
||||||
@ -222,7 +221,8 @@ void ShaderManagerD3D11::GetShaders(int prim, u32 vertType, D3D11VertexShader **
|
|||||||
if (fsIter == fsCache_.end()) {
|
if (fsIter == fsCache_.end()) {
|
||||||
// Fragment shader not in cache. Let's compile it.
|
// Fragment shader not in cache. Let's compile it.
|
||||||
std::string genErrorString;
|
std::string genErrorString;
|
||||||
GenerateFragmentShaderHLSL(FSID, codeBuffer_, HLSL_D3D11, &genErrorString);
|
uint64_t uniformMask;
|
||||||
|
GenerateFragmentShader(FSID, codeBuffer_, compat_, &uniformMask, &genErrorString);
|
||||||
fs = new D3D11FragmentShader(device_, featureLevel_, FSID, codeBuffer_, useHWTransform);
|
fs = new D3D11FragmentShader(device_, featureLevel_, FSID, codeBuffer_, useHWTransform);
|
||||||
fsCache_[FSID] = fs;
|
fsCache_[FSID] = fs;
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "GPU/Common/ShaderCommon.h"
|
#include "GPU/Common/ShaderCommon.h"
|
||||||
#include "GPU/Common/ShaderId.h"
|
#include "GPU/Common/ShaderId.h"
|
||||||
#include "GPU/Common/ShaderUniforms.h"
|
#include "GPU/Common/ShaderUniforms.h"
|
||||||
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
|
|
||||||
class D3D11Context;
|
class D3D11Context;
|
||||||
class D3D11PushBuffer;
|
class D3D11PushBuffer;
|
||||||
@ -109,6 +110,7 @@ private:
|
|||||||
ID3D11Device *device_;
|
ID3D11Device *device_;
|
||||||
ID3D11DeviceContext *context_;
|
ID3D11DeviceContext *context_;
|
||||||
D3D_FEATURE_LEVEL featureLevel_;
|
D3D_FEATURE_LEVEL featureLevel_;
|
||||||
|
ShaderLanguageDesc compat_;
|
||||||
|
|
||||||
typedef std::map<FShaderID, D3D11FragmentShader *> FSCache;
|
typedef std::map<FShaderID, D3D11FragmentShader *> FSCache;
|
||||||
FSCache fsCache_;
|
FSCache fsCache_;
|
||||||
@ -128,8 +130,8 @@ private:
|
|||||||
ID3D11Buffer *push_lights;
|
ID3D11Buffer *push_lights;
|
||||||
ID3D11Buffer *push_bones;
|
ID3D11Buffer *push_bones;
|
||||||
|
|
||||||
D3D11FragmentShader *lastFShader_;
|
D3D11FragmentShader *lastFShader_ = nullptr;
|
||||||
D3D11VertexShader *lastVShader_;
|
D3D11VertexShader *lastVShader_ = nullptr;
|
||||||
|
|
||||||
FShaderID lastFSID_;
|
FShaderID lastFSID_;
|
||||||
VShaderID lastVSID_;
|
VShaderID lastVSID_;
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include "Core/Reporting.h"
|
#include "Core/Reporting.h"
|
||||||
#include "GPU/Common/StencilCommon.h"
|
#include "GPU/Common/StencilCommon.h"
|
||||||
#include "GPU/D3D11/FramebufferManagerD3D11.h"
|
#include "GPU/D3D11/FramebufferManagerD3D11.h"
|
||||||
#include "GPU/Directx9/FragmentShaderGeneratorHLSL.h"
|
|
||||||
#include "GPU/D3D11/ShaderManagerD3D11.h"
|
#include "GPU/D3D11/ShaderManagerD3D11.h"
|
||||||
#include "GPU/D3D11/TextureCacheD3D11.h"
|
#include "GPU/D3D11/TextureCacheD3D11.h"
|
||||||
#include "GPU/D3D11/D3D11Util.h"
|
#include "GPU/D3D11/D3D11Util.h"
|
||||||
|
@ -52,10 +52,10 @@ VS_OUT main(VS_IN input) {
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
DepalShaderCacheDX9::DepalShaderCacheDX9(Draw::DrawContext *draw) : vertexShader_(nullptr) {
|
DepalShaderCacheDX9::DepalShaderCacheDX9(Draw::DrawContext *draw) {
|
||||||
device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);
|
device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);
|
||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
if (!DX9::CompileVertexShader(device_, depalVShaderHLSL, &vertexShader_, nullptr, errorMessage)) {
|
if (!CompileVertexShaderD3D9(device_, depalVShaderHLSL, &vertexShader_, &errorMessage)) {
|
||||||
ERROR_LOG(G3D, "error compling depal vshader: %s", errorMessage.c_str());
|
ERROR_LOG(G3D, "error compling depal vshader: %s", errorMessage.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,11 +152,11 @@ LPDIRECT3DPIXELSHADER9 DepalShaderCacheDX9::GetDepalettizePixelShader(uint32_t c
|
|||||||
|
|
||||||
char *buffer = new char[2048];
|
char *buffer = new char[2048];
|
||||||
|
|
||||||
GenerateDepalShader(buffer, pixelFormat, HLSL_DX9);
|
GenerateDepalShader(buffer, pixelFormat, HLSL_D3D9);
|
||||||
|
|
||||||
LPDIRECT3DPIXELSHADER9 pshader;
|
LPDIRECT3DPIXELSHADER9 pshader;
|
||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
if (!CompilePixelShader(device_, buffer, &pshader, NULL, errorMessage)) {
|
if (!CompilePixelShaderD3D9(device_, buffer, &pshader, &errorMessage)) {
|
||||||
ERROR_LOG(G3D, "Failed to compile depal pixel shader: %s\n\n%s", buffer, errorMessage.c_str());
|
ERROR_LOG(G3D, "Failed to compile depal pixel shader: %s\n\n%s", buffer, errorMessage.c_str());
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -54,9 +54,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
LPDIRECT3DDEVICE9 device_;
|
LPDIRECT3DDEVICE9 device_;
|
||||||
LPDIRECT3DVERTEXSHADER9 vertexShader_;
|
LPDIRECT3DVERTEXSHADER9 vertexShader_ = nullptr;
|
||||||
std::map<u32, DepalShaderDX9 *> cache_;
|
std::map<u32, DepalShaderDX9 *> cache_;
|
||||||
std::map<u32, DepalTextureDX9 *> texCache_;
|
std::map<u32, DepalTextureDX9 *> texCache_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -1,556 +0,0 @@
|
|||||||
// Copyright (c) 2012- PPSSPP Project.
|
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, version 2.0 or later versions.
|
|
||||||
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License 2.0 for more details.
|
|
||||||
|
|
||||||
// A copy of the GPL 2.0 should have been included with the program.
|
|
||||||
// If not, see http://www.gnu.org/licenses/
|
|
||||||
|
|
||||||
// Official git repository and contact information can be found at
|
|
||||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
#include "Core/Reporting.h"
|
|
||||||
#include "Core/Config.h"
|
|
||||||
#include "GPU/Directx9/FragmentShaderGeneratorHLSL.h"
|
|
||||||
#include "GPU/ge_constants.h"
|
|
||||||
#include "GPU/Common/GPUStateUtils.h"
|
|
||||||
#include "GPU/GPUState.h"
|
|
||||||
#include "GPU/Common/ShaderUniforms.h"
|
|
||||||
|
|
||||||
#define WRITE p+=sprintf
|
|
||||||
|
|
||||||
// #define DEBUG_SHADER
|
|
||||||
|
|
||||||
// Missing: Z depth range
|
|
||||||
// Also, logic ops etc, of course, as they are not supported in DX9.
|
|
||||||
bool GenerateFragmentShaderHLSL(const FShaderID &id, char *buffer, ShaderLanguage lang, std::string *errorString) {
|
|
||||||
char *p = buffer;
|
|
||||||
|
|
||||||
bool lmode = id.Bit(FS_BIT_LMODE);
|
|
||||||
bool doTexture = id.Bit(FS_BIT_DO_TEXTURE);
|
|
||||||
bool enableFog = id.Bit(FS_BIT_ENABLE_FOG);
|
|
||||||
bool enableAlphaTest = id.Bit(FS_BIT_ALPHA_TEST);
|
|
||||||
|
|
||||||
bool alphaTestAgainstZero = id.Bit(FS_BIT_ALPHA_AGAINST_ZERO);
|
|
||||||
bool enableColorTest = id.Bit(FS_BIT_COLOR_TEST);
|
|
||||||
bool colorTestAgainstZero = id.Bit(FS_BIT_COLOR_AGAINST_ZERO);
|
|
||||||
bool enableColorDoubling = id.Bit(FS_BIT_COLOR_DOUBLE);
|
|
||||||
bool doTextureProjection = id.Bit(FS_BIT_DO_TEXTURE_PROJ);
|
|
||||||
bool doTextureAlpha = id.Bit(FS_BIT_TEXALPHA);
|
|
||||||
bool doFlatShading = id.Bit(FS_BIT_FLATSHADE);
|
|
||||||
bool isModeClear = id.Bit(FS_BIT_CLEARMODE);
|
|
||||||
|
|
||||||
bool bgraTexture = id.Bit(FS_BIT_BGRA_TEXTURE);
|
|
||||||
|
|
||||||
GEComparison alphaTestFunc = (GEComparison)id.Bits(FS_BIT_ALPHA_TEST_FUNC, 3);
|
|
||||||
GEComparison colorTestFunc = (GEComparison)id.Bits(FS_BIT_COLOR_TEST_FUNC, 2);
|
|
||||||
bool needShaderTexClamp = id.Bit(FS_BIT_SHADER_TEX_CLAMP);
|
|
||||||
|
|
||||||
ReplaceBlendType replaceBlend = static_cast<ReplaceBlendType>(id.Bits(FS_BIT_REPLACE_BLEND, 3));
|
|
||||||
ReplaceAlphaType stencilToAlpha = static_cast<ReplaceAlphaType>(id.Bits(FS_BIT_STENCIL_TO_ALPHA, 2));
|
|
||||||
|
|
||||||
GETexFunc texFunc = (GETexFunc)id.Bits(FS_BIT_TEXFUNC, 3);
|
|
||||||
bool textureAtOffset = id.Bit(FS_BIT_TEXTURE_AT_OFFSET);
|
|
||||||
|
|
||||||
GEBlendSrcFactor replaceBlendFuncA = (GEBlendSrcFactor)id.Bits(FS_BIT_BLENDFUNC_A, 4);
|
|
||||||
GEBlendDstFactor replaceBlendFuncB = (GEBlendDstFactor)id.Bits(FS_BIT_BLENDFUNC_B, 4);
|
|
||||||
GEBlendMode replaceBlendEq = (GEBlendMode)id.Bits(FS_BIT_BLENDEQ, 3);
|
|
||||||
|
|
||||||
StencilValueType replaceAlphaWithStencilType = (StencilValueType)id.Bits(FS_BIT_REPLACE_ALPHA_WITH_STENCIL_TYPE, 4);
|
|
||||||
|
|
||||||
// Output some compatibility defines
|
|
||||||
switch (lang) {
|
|
||||||
case ShaderLanguage::HLSL_DX9:
|
|
||||||
WRITE(p, "#define DISCARD clip(-1)\n");
|
|
||||||
break;
|
|
||||||
case ShaderLanguage::HLSL_D3D11:
|
|
||||||
WRITE(p, "#define DISCARD discard\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
WRITE(p, "#define vec2 float2\n");
|
|
||||||
WRITE(p, "#define vec3 float3\n");
|
|
||||||
WRITE(p, "#define vec4 float4\n");
|
|
||||||
WRITE(p, "#define splat3(x) float3(x, x, x)\n");
|
|
||||||
|
|
||||||
if (lang == HLSL_DX9) {
|
|
||||||
if (doTexture)
|
|
||||||
WRITE(p, "sampler tex : register(s0);\n");
|
|
||||||
if (!isModeClear && replaceBlend > REPLACE_BLEND_STANDARD) {
|
|
||||||
if (replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
|
||||||
WRITE(p, "float2 u_fbotexSize : register(c%i);\n", CONST_PS_FBOTEXSIZE);
|
|
||||||
WRITE(p, "sampler fbotex : register(s1);\n");
|
|
||||||
}
|
|
||||||
if (replaceBlendFuncA >= GE_SRCBLEND_FIXA) {
|
|
||||||
WRITE(p, "float3 u_blendFixA : register(c%i);\n", CONST_PS_BLENDFIXA);
|
|
||||||
}
|
|
||||||
if (replaceBlendFuncB >= GE_DSTBLEND_FIXB) {
|
|
||||||
WRITE(p, "float3 u_blendFixB : register(c%i);\n", CONST_PS_BLENDFIXB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (gstate_c.needShaderTexClamp && doTexture) {
|
|
||||||
WRITE(p, "float4 u_texclamp : register(c%i);\n", CONST_PS_TEXCLAMP);
|
|
||||||
if (textureAtOffset) {
|
|
||||||
WRITE(p, "float2 u_texclampoff : register(c%i);\n", CONST_PS_TEXCLAMPOFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableAlphaTest || enableColorTest) {
|
|
||||||
WRITE(p, "float4 u_alphacolorref : register(c%i);\n", CONST_PS_ALPHACOLORREF);
|
|
||||||
WRITE(p, "float4 u_alphacolormask : register(c%i);\n", CONST_PS_ALPHACOLORMASK);
|
|
||||||
}
|
|
||||||
if (stencilToAlpha && replaceAlphaWithStencilType == STENCIL_VALUE_UNIFORM) {
|
|
||||||
WRITE(p, "float u_stencilReplaceValue : register(c%i);\n", CONST_PS_STENCILREPLACE);
|
|
||||||
}
|
|
||||||
if (doTexture && texFunc == GE_TEXFUNC_BLEND) {
|
|
||||||
WRITE(p, "float3 u_texenv : register(c%i);\n", CONST_PS_TEXENV);
|
|
||||||
}
|
|
||||||
if (enableFog) {
|
|
||||||
WRITE(p, "float3 u_fogcolor : register(c%i);\n", CONST_PS_FOGCOLOR);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
WRITE(p, "SamplerState samp : register(s0);\n");
|
|
||||||
WRITE(p, "Texture2D<float4> tex : register(t0);\n");
|
|
||||||
if (!isModeClear && replaceBlend > REPLACE_BLEND_STANDARD) {
|
|
||||||
if (replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
|
||||||
// No sampler required, we Load
|
|
||||||
WRITE(p, "Texture2D<float4> fboTex : register(t1);\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WRITE(p, "cbuffer base : register(b0) {\n%s};\n", cb_baseStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableAlphaTest) {
|
|
||||||
if (lang == HLSL_D3D11) {
|
|
||||||
WRITE(p, "int roundAndScaleTo255i(float x) { return int(floor(x * 255.0f + 0.5f)); }\n");
|
|
||||||
} else {
|
|
||||||
// D3D11 level 9 gets to take this path.
|
|
||||||
WRITE(p, "float roundAndScaleTo255f(float x) { return floor(x * 255.0f + 0.5f); }\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (enableColorTest) {
|
|
||||||
if (lang == HLSL_D3D11) {
|
|
||||||
WRITE(p, "uint3 roundAndScaleTo255iv(float3 x) { return uint3(floor(x * 255.0f + 0.5f)); }\n");
|
|
||||||
} else {
|
|
||||||
WRITE(p, "float3 roundAndScaleTo255v(float3 x) { return floor(x * 255.0f + 0.5f); }\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WRITE(p, "struct PS_IN {\n");
|
|
||||||
if (doTexture) {
|
|
||||||
WRITE(p, " float3 v_texcoord: TEXCOORD0;\n");
|
|
||||||
}
|
|
||||||
const char *colorInterpolation = doFlatShading && lang == HLSL_D3D11 ? "nointerpolation " : "";
|
|
||||||
WRITE(p, " %sfloat4 v_color0: COLOR0;\n", colorInterpolation);
|
|
||||||
if (lmode) {
|
|
||||||
WRITE(p, " float3 v_color1: COLOR1;\n");
|
|
||||||
}
|
|
||||||
if (enableFog) {
|
|
||||||
WRITE(p, " float v_fogdepth: TEXCOORD1;\n");
|
|
||||||
}
|
|
||||||
if (lang == HLSL_D3D11 && ((replaceBlend == REPLACE_BLEND_COPY_FBO) || gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT))) {
|
|
||||||
WRITE(p, " float4 pixelPos : SV_POSITION;\n");
|
|
||||||
}
|
|
||||||
WRITE(p, "};\n");
|
|
||||||
|
|
||||||
if (lang == HLSL_DX9) {
|
|
||||||
WRITE(p, "float4 main( PS_IN In ) : COLOR {\n");
|
|
||||||
} else {
|
|
||||||
WRITE(p, "struct PS_OUT {\n");
|
|
||||||
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
|
|
||||||
WRITE(p, " float4 target : SV_Target0;\n");
|
|
||||||
WRITE(p, " float4 target1 : SV_Target1;\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WRITE(p, " float4 target : SV_Target;\n");
|
|
||||||
}
|
|
||||||
if (gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) {
|
|
||||||
WRITE(p, " float depth : SV_DEPTH;\n");
|
|
||||||
}
|
|
||||||
WRITE(p, "};\n");
|
|
||||||
WRITE(p, "PS_OUT main( PS_IN In ) {\n");
|
|
||||||
WRITE(p, " PS_OUT outfragment;\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isModeClear) {
|
|
||||||
// Clear mode does not allow any fancy shading.
|
|
||||||
WRITE(p, " float4 v = In.v_color0;\n");
|
|
||||||
} else {
|
|
||||||
const char *secondary = "";
|
|
||||||
// Secondary color for specular on top of texture
|
|
||||||
if (lmode) {
|
|
||||||
WRITE(p, " float4 s = float4(In.v_color1, 0);\n");
|
|
||||||
secondary = " + s";
|
|
||||||
} else {
|
|
||||||
secondary = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doTexture) {
|
|
||||||
const char *texcoord = "In.v_texcoord";
|
|
||||||
// TODO: Not sure the right way to do this for projection.
|
|
||||||
if (needShaderTexClamp) {
|
|
||||||
// We may be clamping inside a larger surface (tex = 64x64, buffer=480x272).
|
|
||||||
// We may also be wrapping in such a surface, or either one in a too-small surface.
|
|
||||||
// Obviously, clamping to a smaller surface won't work. But better to clamp to something.
|
|
||||||
std::string ucoord = "In.v_texcoord.x";
|
|
||||||
std::string vcoord = "In.v_texcoord.y";
|
|
||||||
if (doTextureProjection) {
|
|
||||||
ucoord = "(In.v_texcoord.x / In.v_texcoord.z)";
|
|
||||||
vcoord = "(In.v_texcoord.y / In.v_texcoord.z)";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id.Bit(FS_BIT_CLAMP_S)) {
|
|
||||||
ucoord = "clamp(" + ucoord + ", u_texclamp.z, u_texclamp.x - u_texclamp.z)";
|
|
||||||
} else {
|
|
||||||
ucoord = "fmod(" + ucoord + ", u_texclamp.x)";
|
|
||||||
}
|
|
||||||
if (id.Bit(FS_BIT_CLAMP_T)) {
|
|
||||||
vcoord = "clamp(" + vcoord + ", u_texclamp.w, u_texclamp.y - u_texclamp.w)";
|
|
||||||
} else {
|
|
||||||
vcoord = "fmod(" + vcoord + ", u_texclamp.y)";
|
|
||||||
}
|
|
||||||
if (textureAtOffset) {
|
|
||||||
ucoord = "(" + ucoord + " + u_texclampoff.x)";
|
|
||||||
vcoord = "(" + vcoord + " + u_texclampoff.y)";
|
|
||||||
}
|
|
||||||
|
|
||||||
WRITE(p, " float2 fixedcoord = float2(%s, %s);\n", ucoord.c_str(), vcoord.c_str());
|
|
||||||
texcoord = "fixedcoord";
|
|
||||||
// We already projected it.
|
|
||||||
doTextureProjection = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lang == HLSL_D3D11) {
|
|
||||||
if (doTextureProjection) {
|
|
||||||
WRITE(p, " float4 t = tex.Sample(samp, In.v_texcoord.xy / In.v_texcoord.z)%s;\n", bgraTexture ? ".bgra" : "");
|
|
||||||
} else {
|
|
||||||
WRITE(p, " float4 t = tex.Sample(samp, %s.xy)%s;\n", texcoord, bgraTexture ? ".bgra" : "");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (doTextureProjection) {
|
|
||||||
WRITE(p, " float4 t = tex2Dproj(tex, float4(In.v_texcoord.x, In.v_texcoord.y, 0, In.v_texcoord.z))%s;\n", bgraTexture ? ".bgra" : "");
|
|
||||||
} else {
|
|
||||||
WRITE(p, " float4 t = tex2D(tex, %s.xy)%s;\n", texcoord, bgraTexture ? ".bgra" : "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WRITE(p, " float4 p = In.v_color0;\n");
|
|
||||||
|
|
||||||
if (doTextureAlpha) { // texfmt == RGBA
|
|
||||||
switch (texFunc) {
|
|
||||||
case GE_TEXFUNC_MODULATE:
|
|
||||||
WRITE(p, " float4 v = p * t%s;\n", secondary); break;
|
|
||||||
case GE_TEXFUNC_DECAL:
|
|
||||||
WRITE(p, " float4 v = float4(lerp(p.rgb, t.rgb, t.a), p.a)%s;\n", secondary); break;
|
|
||||||
case GE_TEXFUNC_BLEND:
|
|
||||||
WRITE(p, " float4 v = float4(lerp(p.rgb, u_texenv.rgb, t.rgb), p.a * t.a)%s;\n", secondary); break;
|
|
||||||
case GE_TEXFUNC_REPLACE:
|
|
||||||
WRITE(p, " float4 v = t%s;\n", secondary); break;
|
|
||||||
case GE_TEXFUNC_ADD:
|
|
||||||
case GE_TEXFUNC_UNKNOWN1:
|
|
||||||
case GE_TEXFUNC_UNKNOWN2:
|
|
||||||
case GE_TEXFUNC_UNKNOWN3:
|
|
||||||
WRITE(p, " float4 v = float4(p.rgb + t.rgb, p.a * t.a)%s;\n", secondary); break;
|
|
||||||
default:
|
|
||||||
WRITE(p, " float4 v = p;\n"); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else { // texfmt == RGB
|
|
||||||
switch (texFunc) {
|
|
||||||
case GE_TEXFUNC_MODULATE:
|
|
||||||
WRITE(p, " float4 v = float4(t.rgb * p.rgb, p.a)%s;\n", secondary); break;
|
|
||||||
case GE_TEXFUNC_DECAL:
|
|
||||||
WRITE(p, " float4 v = float4(t.rgb, p.a)%s;\n", secondary); break;
|
|
||||||
case GE_TEXFUNC_BLEND:
|
|
||||||
WRITE(p, " float4 v = float4(lerp(p.rgb, u_texenv.rgb, t.rgb), p.a)%s;\n", secondary); break;
|
|
||||||
case GE_TEXFUNC_REPLACE:
|
|
||||||
WRITE(p, " float4 v = float4(t.rgb, p.a)%s;\n", secondary); break;
|
|
||||||
case GE_TEXFUNC_ADD:
|
|
||||||
case GE_TEXFUNC_UNKNOWN1:
|
|
||||||
case GE_TEXFUNC_UNKNOWN2:
|
|
||||||
case GE_TEXFUNC_UNKNOWN3:
|
|
||||||
WRITE(p, " float4 v = float4(p.rgb + t.rgb, p.a)%s;\n", secondary); break;
|
|
||||||
default:
|
|
||||||
WRITE(p, " float4 v = p;\n"); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableColorDoubling) {
|
|
||||||
// This happens before fog is applied.
|
|
||||||
WRITE(p, " v.rgb = clamp(v.rgb * 2.0, 0.0, 1.0);\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No texture mapping
|
|
||||||
WRITE(p, " float4 v = In.v_color0 %s;\n", secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableFog) {
|
|
||||||
WRITE(p, " float fogCoef = clamp(In.v_fogdepth, 0.0, 1.0);\n");
|
|
||||||
WRITE(p, " v = lerp(float4(u_fogcolor, v.a), v, fogCoef);\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableAlphaTest) {
|
|
||||||
if (alphaTestAgainstZero) {
|
|
||||||
// When testing against 0 (extremely common), we can avoid some math.
|
|
||||||
// 0.002 is approximately half of 1.0 / 255.0.
|
|
||||||
if (alphaTestFunc == GE_COMP_NOTEQUAL || alphaTestFunc == GE_COMP_GREATER) {
|
|
||||||
WRITE(p, " clip(v.a - 0.002);\n");
|
|
||||||
} else if (alphaTestFunc != GE_COMP_NEVER) {
|
|
||||||
// Anything else is a test for == 0. Happens sometimes, actually...
|
|
||||||
WRITE(p, " clip(-v.a + 0.002);\n");
|
|
||||||
} else {
|
|
||||||
// NEVER has been logged as used by games, although it makes little sense - statically failing.
|
|
||||||
// Maybe we could discard the drawcall, but it's pretty rare. Let's just statically discard here.
|
|
||||||
WRITE(p, " DISCARD;\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const char *alphaTestFuncs[] = { "#", "#", " != ", " == ", " >= ", " > ", " <= ", " < " }; // never/always don't make sense
|
|
||||||
if (alphaTestFuncs[alphaTestFunc][0] != '#') {
|
|
||||||
// TODO: Rewrite this to use clip() appropriately (like, clip(v.a - u_alphacolorref.a))
|
|
||||||
if (lang == HLSL_D3D11) {
|
|
||||||
WRITE(p, " if ((roundAndScaleTo255i(v.a) & u_alphacolormask.a) %s u_alphacolorref.a) discard;\n", alphaTestFuncs[alphaTestFunc]);
|
|
||||||
} else {
|
|
||||||
// TODO: Use a texture to lookup bitwise ops?
|
|
||||||
WRITE(p, " if (roundAndScaleTo255f(v.a) %s u_alphacolorref.a) DISCARD;\n", alphaTestFuncs[alphaTestFunc]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// This means NEVER. See above.
|
|
||||||
WRITE(p, " DISCARD;\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enableColorTest) {
|
|
||||||
if (colorTestAgainstZero) {
|
|
||||||
// When testing against 0 (common), we can avoid some math.
|
|
||||||
// 0.002 is approximately half of 1.0 / 255.0.
|
|
||||||
if (colorTestFunc == GE_COMP_NOTEQUAL) {
|
|
||||||
WRITE(p, " if (v.r < 0.002 && v.g < 0.002 && v.b < 0.002) DISCARD;\n");
|
|
||||||
} else if (colorTestFunc != GE_COMP_NEVER) {
|
|
||||||
// Anything else is a test for == 0.
|
|
||||||
WRITE(p, " if (v.r > 0.002 || v.g > 0.002 || v.b > 0.002) DISCARD;\n");
|
|
||||||
} else {
|
|
||||||
// NEVER has been logged as used by games, although it makes little sense - statically failing.
|
|
||||||
// Maybe we could discard the drawcall, but it's pretty rare. Let's just statically discard here.
|
|
||||||
WRITE(p, " DISCARD;\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const char *colorTestFuncs[] = { "#", "#", " != ", " == " }; // never/always don't make sense
|
|
||||||
if (colorTestFuncs[colorTestFunc][0] != '#') {
|
|
||||||
const char *test = colorTestFuncs[colorTestFunc];
|
|
||||||
if (lang == HLSL_D3D11) {
|
|
||||||
WRITE(p, " uint3 v_scaled = roundAndScaleTo255iv(v.rgb);\n");
|
|
||||||
WRITE(p, " uint3 v_masked = v_scaled & u_alphacolormask.rgb;\n");
|
|
||||||
WRITE(p, " uint3 colorTestRef = u_alphacolorref.rgb & u_alphacolormask.rgb;\n");
|
|
||||||
// We have to test the components separately, or we get incorrect results. See #10629.
|
|
||||||
WRITE(p, " if (v_masked.r %s colorTestRef.r && v_masked.g %s colorTestRef.g && v_masked.b %s colorTestRef.b) DISCARD;\n", test, test, test);
|
|
||||||
} else {
|
|
||||||
// TODO: Use a texture to lookup bitwise ops instead?
|
|
||||||
WRITE(p, " float3 colortest = roundAndScaleTo255v(v.rgb);\n");
|
|
||||||
WRITE(p, " if ((colortest.r %s u_alphacolorref.r) && (colortest.g %s u_alphacolorref.g) && (colortest.b %s u_alphacolorref.b)) DISCARD;\n", test, test, test);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WRITE(p, " DISCARD;\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (replaceBlend == REPLACE_BLEND_2X_SRC) {
|
|
||||||
WRITE(p, " v.rgb = v.rgb * 2.0;\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (replaceBlend == REPLACE_BLEND_PRE_SRC || replaceBlend == REPLACE_BLEND_PRE_SRC_2X_ALPHA) {
|
|
||||||
const char *srcFactor = "ERROR";
|
|
||||||
switch (replaceBlendFuncA) {
|
|
||||||
case GE_SRCBLEND_DSTCOLOR: srcFactor = "ERROR"; break;
|
|
||||||
case GE_SRCBLEND_INVDSTCOLOR: srcFactor = "ERROR"; break;
|
|
||||||
case GE_SRCBLEND_SRCALPHA: srcFactor = "splat3(v.a)"; break;
|
|
||||||
case GE_SRCBLEND_INVSRCALPHA: srcFactor = "splat3(1.0 - v.a)"; break;
|
|
||||||
case GE_SRCBLEND_DSTALPHA: srcFactor = "ERROR"; break;
|
|
||||||
case GE_SRCBLEND_INVDSTALPHA: srcFactor = "ERROR"; break;
|
|
||||||
case GE_SRCBLEND_DOUBLESRCALPHA: srcFactor = "splat3(v.a * 2.0)"; break;
|
|
||||||
case GE_SRCBLEND_DOUBLEINVSRCALPHA: srcFactor = "splat3(1.0 - v.a * 2.0)"; break;
|
|
||||||
// PRE_SRC for REPLACE_BLEND_PRE_SRC_2X_ALPHA means "double the src."
|
|
||||||
// It's close to the same, but clamping can still be an issue.
|
|
||||||
case GE_SRCBLEND_DOUBLEDSTALPHA: srcFactor = "splat3(2.0)"; break;
|
|
||||||
case GE_SRCBLEND_DOUBLEINVDSTALPHA: srcFactor = "ERROR"; break;
|
|
||||||
case GE_SRCBLEND_FIXA: srcFactor = "u_blendFixA"; break;
|
|
||||||
default: srcFactor = "u_blendFixA"; break;
|
|
||||||
}
|
|
||||||
if (!strcmp(srcFactor, "ERROR")) {
|
|
||||||
*errorString = "Bad srcfactor in replace blend";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
WRITE(p, " v.rgb = v.rgb * %s;\n", srcFactor);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lang == HLSL_D3D11 && replaceBlend == REPLACE_BLEND_COPY_FBO) {
|
|
||||||
WRITE(p, " float4 destColor = fboTex.Load(int3((int)In.pixelPos.x, (int)In.pixelPos.y, 0));\n");
|
|
||||||
|
|
||||||
const char *srcFactor = nullptr;
|
|
||||||
const char *dstFactor = nullptr;
|
|
||||||
|
|
||||||
switch (replaceBlendFuncA) {
|
|
||||||
case GE_SRCBLEND_DSTCOLOR: srcFactor = "destColor.rgb"; break;
|
|
||||||
case GE_SRCBLEND_INVDSTCOLOR: srcFactor = "(splat3(1.0) - destColor.rgb)"; break;
|
|
||||||
case GE_SRCBLEND_SRCALPHA: srcFactor = "v.aaa"; break;
|
|
||||||
case GE_SRCBLEND_INVSRCALPHA: srcFactor = "splat3(1.0) - v.aaa"; break;
|
|
||||||
case GE_SRCBLEND_DSTALPHA: srcFactor = "float3(destColor.aaa)"; break;
|
|
||||||
case GE_SRCBLEND_INVDSTALPHA: srcFactor = "splat3(1.0) - destColor.aaa"; break;
|
|
||||||
case GE_SRCBLEND_DOUBLESRCALPHA: srcFactor = "v.aaa * 2.0"; break;
|
|
||||||
case GE_SRCBLEND_DOUBLEINVSRCALPHA: srcFactor = "splat3(1.0) - v.aaa * 2.0"; break;
|
|
||||||
case GE_SRCBLEND_DOUBLEDSTALPHA: srcFactor = "destColor.aaa * 2.0"; break;
|
|
||||||
case GE_SRCBLEND_DOUBLEINVDSTALPHA: srcFactor = "splat3(1.0) - destColor.aaa * 2.0"; break;
|
|
||||||
case GE_SRCBLEND_FIXA: srcFactor = "u_blendFixA"; break;
|
|
||||||
default: srcFactor = "u_blendFixA"; break;
|
|
||||||
}
|
|
||||||
switch (replaceBlendFuncB) {
|
|
||||||
case GE_DSTBLEND_SRCCOLOR: dstFactor = "v.rgb"; break;
|
|
||||||
case GE_DSTBLEND_INVSRCCOLOR: dstFactor = "(splat3(1.0) - v.rgb)"; break;
|
|
||||||
case GE_DSTBLEND_SRCALPHA: dstFactor = "v.aaa"; break;
|
|
||||||
case GE_DSTBLEND_INVSRCALPHA: dstFactor = "splat3(1.0) - v.aaa"; break;
|
|
||||||
case GE_DSTBLEND_DSTALPHA: dstFactor = "destColor.aaa"; break;
|
|
||||||
case GE_DSTBLEND_INVDSTALPHA: dstFactor = "splat3(1.0) - destColor.aaa"; break;
|
|
||||||
case GE_DSTBLEND_DOUBLESRCALPHA: dstFactor = "v.aaa * 2.0"; break;
|
|
||||||
case GE_DSTBLEND_DOUBLEINVSRCALPHA: dstFactor = "splat3(1.0) - v.aaa * 2.0"; break;
|
|
||||||
case GE_DSTBLEND_DOUBLEDSTALPHA: dstFactor = "destColor.aaa * 2.0"; break;
|
|
||||||
case GE_DSTBLEND_DOUBLEINVDSTALPHA: dstFactor = "splat3(1.0) - destColor.aaa * 2.0"; break;
|
|
||||||
case GE_DSTBLEND_FIXB: dstFactor = "u_blendFixB"; break;
|
|
||||||
default: dstFactor = "u_blendFixB"; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (replaceBlendEq) {
|
|
||||||
case GE_BLENDMODE_MUL_AND_ADD:
|
|
||||||
WRITE(p, " v.rgb = v.rgb * %s + destColor.rgb * %s;\n", srcFactor, dstFactor);
|
|
||||||
break;
|
|
||||||
case GE_BLENDMODE_MUL_AND_SUBTRACT:
|
|
||||||
WRITE(p, " v.rgb = v.rgb * %s - destColor.rgb * %s;\n", srcFactor, dstFactor);
|
|
||||||
break;
|
|
||||||
case GE_BLENDMODE_MUL_AND_SUBTRACT_REVERSE:
|
|
||||||
WRITE(p, " v.rgb = destColor.rgb * %s - v.rgb * %s;\n", dstFactor, srcFactor);
|
|
||||||
break;
|
|
||||||
case GE_BLENDMODE_MIN:
|
|
||||||
WRITE(p, " v.rgb = min(v.rgb, destColor.rgb);\n");
|
|
||||||
break;
|
|
||||||
case GE_BLENDMODE_MAX:
|
|
||||||
WRITE(p, " v.rgb = max(v.rgb, destColor.rgb);\n");
|
|
||||||
break;
|
|
||||||
case GE_BLENDMODE_ABSDIFF:
|
|
||||||
WRITE(p, " v.rgb = abs(v.rgb - destColor.rgb);\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*errorString = "Bad replace blend eq";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can do REPLACE_BLEND_COPY_FBO in ps_2_0, but need to apply viewport in the vertex shader
|
|
||||||
// so that we can have the output position here to sample the texture at.
|
|
||||||
|
|
||||||
if (replaceBlend == REPLACE_BLEND_2X_ALPHA || replaceBlend == REPLACE_BLEND_PRE_SRC_2X_ALPHA) {
|
|
||||||
WRITE(p, " v.a = v.a * 2.0;\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string replacedAlpha = "0.0";
|
|
||||||
char replacedAlphaTemp[64] = "";
|
|
||||||
if (stencilToAlpha != REPLACE_ALPHA_NO) {
|
|
||||||
switch (replaceAlphaWithStencilType) {
|
|
||||||
case STENCIL_VALUE_UNIFORM:
|
|
||||||
replacedAlpha = "u_stencilReplaceValue";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STENCIL_VALUE_ZERO:
|
|
||||||
replacedAlpha = "0.0";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STENCIL_VALUE_ONE:
|
|
||||||
case STENCIL_VALUE_INVERT:
|
|
||||||
// In invert, we subtract by one, but we want to output one here.
|
|
||||||
replacedAlpha = "1.0";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STENCIL_VALUE_INCR_4:
|
|
||||||
case STENCIL_VALUE_DECR_4:
|
|
||||||
// We're adding/subtracting, just by the smallest value in 4-bit.
|
|
||||||
snprintf(replacedAlphaTemp, sizeof(replacedAlphaTemp), "%f", 1.0 / 15.0);
|
|
||||||
replacedAlpha = replacedAlphaTemp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STENCIL_VALUE_INCR_8:
|
|
||||||
case STENCIL_VALUE_DECR_8:
|
|
||||||
// We're adding/subtracting, just by the smallest value in 8-bit.
|
|
||||||
snprintf(replacedAlphaTemp, sizeof(replacedAlphaTemp), "%f", 1.0 / 255.0);
|
|
||||||
replacedAlpha = replacedAlphaTemp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STENCIL_VALUE_KEEP:
|
|
||||||
// Do nothing. We'll mask out the alpha using color mask.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (stencilToAlpha) {
|
|
||||||
case REPLACE_ALPHA_YES:
|
|
||||||
WRITE(p, " v.a = %s;\n", replacedAlpha.c_str());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case REPLACE_ALPHA_NO:
|
|
||||||
// Do nothing, v is already fine.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogicOpReplaceType replaceLogicOpType = (LogicOpReplaceType)id.Bits(FS_BIT_REPLACE_LOGIC_OP_TYPE, 2);
|
|
||||||
switch (replaceLogicOpType) {
|
|
||||||
case LOGICOPTYPE_ONE:
|
|
||||||
WRITE(p, " v.rgb = splat3(1.0);\n");
|
|
||||||
break;
|
|
||||||
case LOGICOPTYPE_INVERT:
|
|
||||||
WRITE(p, " v.rgb = splat3(1.0) - v.rgb;\n");
|
|
||||||
break;
|
|
||||||
case LOGICOPTYPE_NORMAL:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) {
|
|
||||||
const double scale = DepthSliceFactor() * 65535.0;
|
|
||||||
|
|
||||||
WRITE(p, " float z = In.pixelPos.z;\n");
|
|
||||||
if (gstate_c.Supports(GPU_SUPPORTS_ACCURATE_DEPTH)) {
|
|
||||||
// We center the depth with an offset, but only its fraction matters.
|
|
||||||
// When (DepthSliceFactor() - 1) is odd, it will be 0.5, otherwise 0.
|
|
||||||
if (((int)(DepthSliceFactor() - 1.0f) & 1) == 1) {
|
|
||||||
WRITE(p, " z = (floor((z * %f) - (1.0 / 2.0)) + (1.0 / 2.0)) * (1.0 / %f);\n", scale, scale);
|
|
||||||
} else {
|
|
||||||
WRITE(p, " z = floor(z * %f) * (1.0 / %f);\n", scale, scale);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
WRITE(p, " z = (1.0/65535.0) * floor(z * 65535.0);\n");
|
|
||||||
}
|
|
||||||
WRITE(p, " outfragment.depth = z;\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lang == HLSL_D3D11) {
|
|
||||||
if (stencilToAlpha == REPLACE_ALPHA_DUALSOURCE) {
|
|
||||||
WRITE(p, " outfragment.target = float4(v.rgb, %s);\n", replacedAlpha.c_str());
|
|
||||||
WRITE(p, " outfragment.target1 = float4(0.0, 0.0, 0.0, v.a);\n");
|
|
||||||
WRITE(p, " return outfragment;\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WRITE(p, " outfragment.target = v;\n");
|
|
||||||
WRITE(p, " return outfragment;\n");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
WRITE(p, " return v;\n");
|
|
||||||
}
|
|
||||||
WRITE(p, "}\n");
|
|
||||||
return true;
|
|
||||||
}
|
|
@ -52,7 +52,7 @@ static const char *vscode = R"(
|
|||||||
struct VS_IN {
|
struct VS_IN {
|
||||||
float4 ObjPos : POSITION;
|
float4 ObjPos : POSITION;
|
||||||
float2 Uv : TEXCOORD0;
|
float2 Uv : TEXCOORD0;
|
||||||
};"
|
};
|
||||||
struct VS_OUT {
|
struct VS_OUT {
|
||||||
float4 ProjPos : POSITION;
|
float4 ProjPos : POSITION;
|
||||||
float2 Uv : TEXCOORD0;
|
float2 Uv : TEXCOORD0;
|
||||||
@ -88,11 +88,11 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
|
|||||||
device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);
|
device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE);
|
||||||
deviceEx_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE_EX);
|
deviceEx_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE_EX);
|
||||||
std::string errorMsg;
|
std::string errorMsg;
|
||||||
if (!CompileVertexShader(device_, vscode, &pFramebufferVertexShader, nullptr, errorMsg)) {
|
if (!CompileVertexShaderD3D9(device_, vscode, &pFramebufferVertexShader, &errorMsg)) {
|
||||||
OutputDebugStringA(errorMsg.c_str());
|
OutputDebugStringA(errorMsg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CompilePixelShader(device_, pscode, &pFramebufferPixelShader, nullptr, errorMsg)) {
|
if (!CompilePixelShaderD3D9(device_, pscode, &pFramebufferPixelShader, &errorMsg)) {
|
||||||
OutputDebugStringA(errorMsg.c_str());
|
OutputDebugStringA(errorMsg.c_str());
|
||||||
if (pFramebufferVertexShader) {
|
if (pFramebufferVertexShader) {
|
||||||
pFramebufferVertexShader->Release();
|
pFramebufferVertexShader->Release();
|
||||||
@ -116,7 +116,7 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
|
|||||||
|
|
||||||
ShaderTranslationInit();
|
ShaderTranslationInit();
|
||||||
|
|
||||||
presentation_->SetLanguage(HLSL_DX9);
|
presentation_->SetLanguage(HLSL_D3D9);
|
||||||
preferredPixelsFormat_ = Draw::DataFormat::B8G8R8A8_UNORM;
|
preferredPixelsFormat_ = Draw::DataFormat::B8G8R8A8_UNORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define SHADERLOG
|
//#define SHADERLOG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -41,6 +41,7 @@
|
|||||||
#include "GPU/GPUState.h"
|
#include "GPU/GPUState.h"
|
||||||
#include "GPU/ge_constants.h"
|
#include "GPU/ge_constants.h"
|
||||||
#include "GPU/Common/ShaderUniforms.h"
|
#include "GPU/Common/ShaderUniforms.h"
|
||||||
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
#include "GPU/Directx9/ShaderManagerDX9.h"
|
#include "GPU/Directx9/ShaderManagerDX9.h"
|
||||||
#include "GPU/Directx9/DrawEngineDX9.h"
|
#include "GPU/Directx9/DrawEngineDX9.h"
|
||||||
#include "GPU/Directx9/FramebufferManagerDX9.h"
|
#include "GPU/Directx9/FramebufferManagerDX9.h"
|
||||||
@ -57,7 +58,7 @@ PSShader::PSShader(LPDIRECT3DDEVICE9 device, FShaderID id, const char *code) : i
|
|||||||
bool success;
|
bool success;
|
||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
|
|
||||||
success = CompilePixelShader(device, code, &shader, NULL, errorMessage);
|
success = CompilePixelShaderD3D9(device, code, &shader, &errorMessage);
|
||||||
|
|
||||||
if (!errorMessage.empty()) {
|
if (!errorMessage.empty()) {
|
||||||
if (success) {
|
if (success) {
|
||||||
@ -107,7 +108,7 @@ VSShader::VSShader(LPDIRECT3DDEVICE9 device, VShaderID id, const char *code, boo
|
|||||||
bool success;
|
bool success;
|
||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
|
|
||||||
success = CompileVertexShader(device, code, &shader, NULL, errorMessage);
|
success = CompileVertexShaderD3D9(device, code, &shader, &errorMessage);
|
||||||
if (!errorMessage.empty()) {
|
if (!errorMessage.empty()) {
|
||||||
if (success) {
|
if (success) {
|
||||||
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
||||||
@ -510,8 +511,8 @@ void ShaderManagerDX9::VSUpdateUniforms(u64 dirtyUniforms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShaderManagerDX9::ShaderManagerDX9(Draw::DrawContext *draw, LPDIRECT3DDEVICE9 device)
|
ShaderManagerDX9::ShaderManagerDX9(Draw::DrawContext *draw, LPDIRECT3DDEVICE9 device)
|
||||||
: ShaderManagerCommon(draw), device_(device), lastVShader_(nullptr), lastPShader_(nullptr) {
|
: ShaderManagerCommon(draw), device_(device), compat_(HLSL_D3D9) {
|
||||||
codeBuffer_ = new char[16384];
|
codeBuffer_ = new char[32768];
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderManagerDX9::~ShaderManagerDX9() {
|
ShaderManagerDX9::~ShaderManagerDX9() {
|
||||||
@ -588,7 +589,7 @@ VSShader *ShaderManagerDX9::ApplyShader(bool useHWTransform, bool useHWTessellat
|
|||||||
if (vsIter == vsCache_.end()) {
|
if (vsIter == vsCache_.end()) {
|
||||||
// Vertex shader not in cache. Let's compile it.
|
// Vertex shader not in cache. Let's compile it.
|
||||||
std::string genErrorString;
|
std::string genErrorString;
|
||||||
if (GenerateVertexShaderHLSL(VSID, codeBuffer_, HLSL_DX9, &genErrorString)) {
|
if (GenerateVertexShaderHLSL(VSID, codeBuffer_, HLSL_D3D9, &genErrorString)) {
|
||||||
vs = new VSShader(device_, VSID, codeBuffer_, useHWTransform);
|
vs = new VSShader(device_, VSID, codeBuffer_, useHWTransform);
|
||||||
}
|
}
|
||||||
if (!vs || vs->Failed()) {
|
if (!vs || vs->Failed()) {
|
||||||
@ -611,7 +612,7 @@ VSShader *ShaderManagerDX9::ApplyShader(bool useHWTransform, bool useHWTessellat
|
|||||||
// next time and we'll do this over and over...
|
// next time and we'll do this over and over...
|
||||||
|
|
||||||
// Can still work with software transform.
|
// Can still work with software transform.
|
||||||
bool success = GenerateVertexShaderHLSL(VSID, codeBuffer_, HLSL_DX9, &genErrorString);
|
bool success = GenerateVertexShaderHLSL(VSID, codeBuffer_, HLSL_D3D9, &genErrorString);
|
||||||
_assert_(success);
|
_assert_(success);
|
||||||
vs = new VSShader(device_, VSID, codeBuffer_, false);
|
vs = new VSShader(device_, VSID, codeBuffer_, false);
|
||||||
}
|
}
|
||||||
@ -627,7 +628,8 @@ VSShader *ShaderManagerDX9::ApplyShader(bool useHWTransform, bool useHWTessellat
|
|||||||
if (fsIter == fsCache_.end()) {
|
if (fsIter == fsCache_.end()) {
|
||||||
// Fragment shader not in cache. Let's compile it.
|
// Fragment shader not in cache. Let's compile it.
|
||||||
std::string errorString;
|
std::string errorString;
|
||||||
bool success = GenerateFragmentShaderHLSL(FSID, codeBuffer_, HLSL_DX9, &errorString);
|
uint64_t uniformMask;
|
||||||
|
bool success = GenerateFragmentShader(FSID, codeBuffer_, compat_, &uniformMask, &errorString);
|
||||||
// We're supposed to handle all possible cases.
|
// We're supposed to handle all possible cases.
|
||||||
_assert_(success);
|
_assert_(success);
|
||||||
fs = new PSShader(device_, FSID, codeBuffer_);
|
fs = new PSShader(device_, FSID, codeBuffer_);
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "Common/Common.h"
|
#include "Common/Common.h"
|
||||||
#include "GPU/Directx9/VertexShaderGeneratorHLSL.h"
|
#include "GPU/Directx9/VertexShaderGeneratorHLSL.h"
|
||||||
#include "GPU/Directx9/FragmentShaderGeneratorHLSL.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
#include "GPU/Common/ShaderCommon.h"
|
#include "GPU/Common/ShaderCommon.h"
|
||||||
#include "GPU/Common/ShaderId.h"
|
#include "GPU/Common/ShaderId.h"
|
||||||
#include "Common/Math/lin/matrix4x4.h"
|
#include "Common/Math/lin/matrix4x4.h"
|
||||||
@ -112,14 +112,15 @@ private:
|
|||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
LPDIRECT3DDEVICE9 device_;
|
LPDIRECT3DDEVICE9 device_;
|
||||||
|
ShaderLanguageDesc compat_;
|
||||||
|
|
||||||
FShaderID lastFSID_;
|
FShaderID lastFSID_;
|
||||||
VShaderID lastVSID_;
|
VShaderID lastVSID_;
|
||||||
|
|
||||||
char *codeBuffer_;
|
char *codeBuffer_;
|
||||||
|
|
||||||
VSShader *lastVShader_;
|
VSShader *lastVShader_ = nullptr;
|
||||||
PSShader *lastPShader_;
|
PSShader *lastPShader_ = nullptr;
|
||||||
|
|
||||||
typedef std::map<FShaderID, PSShader *> FSCache;
|
typedef std::map<FShaderID, PSShader *> FSCache;
|
||||||
FSCache fsCache_;
|
FSCache fsCache_;
|
||||||
|
@ -132,7 +132,7 @@ bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, StencilUploa
|
|||||||
// TODO: Helper with logging?
|
// TODO: Helper with logging?
|
||||||
if (!stencilUploadPS_) {
|
if (!stencilUploadPS_) {
|
||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
bool success = CompilePixelShader(device_, stencil_ps, &stencilUploadPS_, NULL, errorMessage);
|
bool success = CompilePixelShaderD3D9(device_, stencil_ps, &stencilUploadPS_, &errorMessage);
|
||||||
if (!errorMessage.empty()) {
|
if (!errorMessage.empty()) {
|
||||||
if (success) {
|
if (success) {
|
||||||
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
||||||
@ -154,7 +154,7 @@ bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, StencilUploa
|
|||||||
}
|
}
|
||||||
if (!stencilUploadVS_) {
|
if (!stencilUploadVS_) {
|
||||||
std::string errorMessage;
|
std::string errorMessage;
|
||||||
bool success = CompileVertexShader(device_, stencil_vs, &stencilUploadVS_, NULL, errorMessage);
|
bool success = CompileVertexShaderD3D9(device_, stencil_vs, &stencilUploadVS_, &errorMessage);
|
||||||
if (!errorMessage.empty()) {
|
if (!errorMessage.empty()) {
|
||||||
if (success) {
|
if (success) {
|
||||||
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
||||||
|
@ -34,13 +34,13 @@
|
|||||||
static const char * const boneWeightAttrDecl[9] = {
|
static const char * const boneWeightAttrDecl[9] = {
|
||||||
"#ERROR#",
|
"#ERROR#",
|
||||||
"float a_w1:TEXCOORD1;\n",
|
"float a_w1:TEXCOORD1;\n",
|
||||||
"float2 a_w1:TEXCOORD1;\n",
|
"vec2 a_w1:TEXCOORD1;\n",
|
||||||
"float3 a_w1:TEXCOORD1;\n",
|
"vec3 a_w1:TEXCOORD1;\n",
|
||||||
"float4 a_w1:TEXCOORD1;\n",
|
"vec4 a_w1:TEXCOORD1;\n",
|
||||||
"float4 a_w1:TEXCOORD1;\n float a_w2:TEXCOORD2;\n",
|
"vec4 a_w1:TEXCOORD1;\n float a_w2:TEXCOORD2;\n",
|
||||||
"float4 a_w1:TEXCOORD1;\n float2 a_w2:TEXCOORD2;\n",
|
"vec4 a_w1:TEXCOORD1;\n vec2 a_w2:TEXCOORD2;\n",
|
||||||
"float4 a_w1:TEXCOORD1;\n float3 a_w2:TEXCOORD2;\n",
|
"vec4 a_w1:TEXCOORD1;\n vec3 a_w2:TEXCOORD2;\n",
|
||||||
"float4 a_w1:TEXCOORD1;\n float4 a_w2:TEXCOORD2;\n",
|
"vec4 a_w1:TEXCOORD1;\n vec4 a_w2:TEXCOORD2;\n",
|
||||||
};
|
};
|
||||||
|
|
||||||
bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage lang, std::string *errorString) {
|
bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage lang, std::string *errorString) {
|
||||||
@ -104,9 +104,11 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
WRITE(p, "#define vec2 float2\n");
|
WRITE(p, "#define vec2 float2\n");
|
||||||
WRITE(p, "#define vec3 float3\n");
|
WRITE(p, "#define vec3 float3\n");
|
||||||
WRITE(p, "#define vec4 float4\n");
|
WRITE(p, "#define vec4 float4\n");
|
||||||
WRITE(p, "#define splat3(x) float3(x, x, x)\n");
|
WRITE(p, "#define mat4 float4x4\n");
|
||||||
|
WRITE(p, "#define mat3x4 float4x3\n"); // note how the conventions are backwards
|
||||||
|
WRITE(p, "#define splat3(x) vec3(x, x, x)\n");
|
||||||
|
|
||||||
if (lang == HLSL_DX9) {
|
if (lang == HLSL_D3D9) {
|
||||||
WRITE(p, "#pragma warning( disable : 3571 )\n");
|
WRITE(p, "#pragma warning( disable : 3571 )\n");
|
||||||
if (isModeThrough) {
|
if (isModeThrough) {
|
||||||
WRITE(p, "float4x4 u_proj_through : register(c%i);\n", CONST_VS_PROJ_THROUGH);
|
WRITE(p, "float4x4 u_proj_through : register(c%i);\n", CONST_VS_PROJ_THROUGH);
|
||||||
@ -116,69 +118,69 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (enableFog) {
|
if (enableFog) {
|
||||||
WRITE(p, "float2 u_fogcoef : register(c%i);\n", CONST_VS_FOGCOEF);
|
WRITE(p, "vec2 u_fogcoef : register(c%i);\n", CONST_VS_FOGCOEF);
|
||||||
}
|
}
|
||||||
if (useHWTransform || !hasColor)
|
if (useHWTransform || !hasColor)
|
||||||
WRITE(p, "float4 u_matambientalpha : register(c%i);\n", CONST_VS_MATAMBIENTALPHA); // matambient + matalpha
|
WRITE(p, "vec4 u_matambientalpha : register(c%i);\n", CONST_VS_MATAMBIENTALPHA); // matambient + matalpha
|
||||||
|
|
||||||
if (useHWTransform) {
|
if (useHWTransform) {
|
||||||
// When transforming by hardware, we need a great deal more uniforms...
|
// When transforming by hardware, we need a great deal more uniforms...
|
||||||
WRITE(p, "float4x3 u_world : register(c%i);\n", CONST_VS_WORLD);
|
WRITE(p, "mat3x4 u_world : register(c%i);\n", CONST_VS_WORLD);
|
||||||
WRITE(p, "float4x3 u_view : register(c%i);\n", CONST_VS_VIEW);
|
WRITE(p, "mat3x4 u_view : register(c%i);\n", CONST_VS_VIEW);
|
||||||
if (doTextureTransform)
|
if (doTextureTransform)
|
||||||
WRITE(p, "float4x3 u_texmtx : register(c%i);\n", CONST_VS_TEXMTX);
|
WRITE(p, "mat3x4 u_texmtx : register(c%i);\n", CONST_VS_TEXMTX);
|
||||||
if (enableBones) {
|
if (enableBones) {
|
||||||
#ifdef USE_BONE_ARRAY
|
#ifdef USE_BONE_ARRAY
|
||||||
WRITE(p, "float4x3 u_bone[%i] : register(c%i);\n", numBones, CONST_VS_BONE0);
|
WRITE(p, "mat3x4 u_bone[%i] : register(c%i);\n", numBones, CONST_VS_BONE0);
|
||||||
#else
|
#else
|
||||||
for (int i = 0; i < numBoneWeights; i++) {
|
for (int i = 0; i < numBoneWeights; i++) {
|
||||||
WRITE(p, "float4x3 u_bone%i : register(c%i);\n", i, CONST_VS_BONE0 + i * 3);
|
WRITE(p, "mat3x4 u_bone%i : register(c%i);\n", i, CONST_VS_BONE0 + i * 3);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (doTexture) {
|
if (doTexture) {
|
||||||
WRITE(p, "float4 u_uvscaleoffset : register(c%i);\n", CONST_VS_UVSCALEOFFSET);
|
WRITE(p, "vec4 u_uvscaleoffset : register(c%i);\n", CONST_VS_UVSCALEOFFSET);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
if (doLight[i] != LIGHT_OFF) {
|
if (doLight[i] != LIGHT_OFF) {
|
||||||
// This is needed for shade mapping
|
// This is needed for shade mapping
|
||||||
WRITE(p, "float3 u_lightpos%i : register(c%i);\n", i, CONST_VS_LIGHTPOS + i);
|
WRITE(p, "vec3 u_lightpos%i : register(c%i);\n", i, CONST_VS_LIGHTPOS + i);
|
||||||
}
|
}
|
||||||
if (doLight[i] == LIGHT_FULL) {
|
if (doLight[i] == LIGHT_FULL) {
|
||||||
GELightType type = static_cast<GELightType>(id.Bits(VS_BIT_LIGHT0_TYPE + 4 * i, 2));
|
GELightType type = static_cast<GELightType>(id.Bits(VS_BIT_LIGHT0_TYPE + 4 * i, 2));
|
||||||
GELightComputation comp = static_cast<GELightComputation>(id.Bits(VS_BIT_LIGHT0_COMP + 4 * i, 2));
|
GELightComputation comp = static_cast<GELightComputation>(id.Bits(VS_BIT_LIGHT0_COMP + 4 * i, 2));
|
||||||
|
|
||||||
if (type != GE_LIGHTTYPE_DIRECTIONAL)
|
if (type != GE_LIGHTTYPE_DIRECTIONAL)
|
||||||
WRITE(p, "float3 u_lightatt%i : register(c%i);\n", i, CONST_VS_LIGHTATT + i);
|
WRITE(p, "vec3 u_lightatt%i : register(c%i);\n", i, CONST_VS_LIGHTATT + i);
|
||||||
|
|
||||||
if (type == GE_LIGHTTYPE_SPOT || type == GE_LIGHTTYPE_UNKNOWN) {
|
if (type == GE_LIGHTTYPE_SPOT || type == GE_LIGHTTYPE_UNKNOWN) {
|
||||||
WRITE(p, "float3 u_lightdir%i : register(c%i);\n", i, CONST_VS_LIGHTDIR + i);
|
WRITE(p, "vec3 u_lightdir%i : register(c%i);\n", i, CONST_VS_LIGHTDIR + i);
|
||||||
WRITE(p, "float4 u_lightangle_spotCoef%i : register(c%i);\n", i, CONST_VS_LIGHTANGLE_SPOTCOEF + i);
|
WRITE(p, "vec4 u_lightangle_spotCoef%i : register(c%i);\n", i, CONST_VS_LIGHTANGLE_SPOTCOEF + i);
|
||||||
}
|
}
|
||||||
WRITE(p, "float3 u_lightambient%i : register(c%i);\n", i, CONST_VS_LIGHTAMBIENT + i);
|
WRITE(p, "vec3 u_lightambient%i : register(c%i);\n", i, CONST_VS_LIGHTAMBIENT + i);
|
||||||
WRITE(p, "float3 u_lightdiffuse%i : register(c%i);\n", i, CONST_VS_LIGHTDIFFUSE + i);
|
WRITE(p, "vec3 u_lightdiffuse%i : register(c%i);\n", i, CONST_VS_LIGHTDIFFUSE + i);
|
||||||
|
|
||||||
if (comp == GE_LIGHTCOMP_BOTH) {
|
if (comp == GE_LIGHTCOMP_BOTH) {
|
||||||
WRITE(p, "float3 u_lightspecular%i : register(c%i);\n", i, CONST_VS_LIGHTSPECULAR + i);
|
WRITE(p, "vec3 u_lightspecular%i : register(c%i);\n", i, CONST_VS_LIGHTSPECULAR + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enableLighting) {
|
if (enableLighting) {
|
||||||
WRITE(p, "float4 u_ambient : register(c%i);\n", CONST_VS_AMBIENT);
|
WRITE(p, "vec4 u_ambient : register(c%i);\n", CONST_VS_AMBIENT);
|
||||||
if ((matUpdate & 2) == 0 || !hasColor)
|
if ((matUpdate & 2) == 0 || !hasColor)
|
||||||
WRITE(p, "float3 u_matdiffuse : register(c%i);\n", CONST_VS_MATDIFFUSE);
|
WRITE(p, "vec3 u_matdiffuse : register(c%i);\n", CONST_VS_MATDIFFUSE);
|
||||||
// if ((matUpdate & 4) == 0)
|
// if ((matUpdate & 4) == 0)
|
||||||
WRITE(p, "float4 u_matspecular : register(c%i);\n", CONST_VS_MATSPECULAR); // Specular coef is contained in alpha
|
WRITE(p, "vec4 u_matspecular : register(c%i);\n", CONST_VS_MATSPECULAR); // Specular coef is contained in alpha
|
||||||
WRITE(p, "float3 u_matemissive : register(c%i);\n", CONST_VS_MATEMISSIVE);
|
WRITE(p, "vec3 u_matemissive : register(c%i);\n", CONST_VS_MATEMISSIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isModeThrough && gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
if (!isModeThrough && gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
||||||
WRITE(p, "float4 u_depthRange : register(c%i);\n", CONST_VS_DEPTHRANGE);
|
WRITE(p, "vec4 u_depthRange : register(c%i);\n", CONST_VS_DEPTHRANGE);
|
||||||
}
|
}
|
||||||
if (!isModeThrough) {
|
if (!isModeThrough) {
|
||||||
WRITE(p, "float4 u_cullRangeMin : register(c%i);\n", CONST_VS_CULLRANGEMIN);
|
WRITE(p, "vec4 u_cullRangeMin : register(c%i);\n", CONST_VS_CULLRANGEMIN);
|
||||||
WRITE(p, "float4 u_cullRangeMax : register(c%i);\n", CONST_VS_CULLRANGEMAX);
|
WRITE(p, "vec4 u_cullRangeMax : register(c%i);\n", CONST_VS_CULLRANGEMAX);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, "cbuffer base : register(b0) {\n%s};\n", cb_baseStr);
|
WRITE(p, "cbuffer base : register(b0) {\n%s};\n", cb_baseStr);
|
||||||
@ -199,54 +201,54 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
WRITE(p, " %s", boneWeightAttrDecl[numBoneWeights]);
|
WRITE(p, " %s", boneWeightAttrDecl[numBoneWeights]);
|
||||||
}
|
}
|
||||||
if (doTexture && hasTexcoord) {
|
if (doTexture && hasTexcoord) {
|
||||||
WRITE(p, " float2 texcoord : TEXCOORD0;\n");
|
WRITE(p, " vec2 texcoord : TEXCOORD0;\n");
|
||||||
}
|
}
|
||||||
if (hasColor) {
|
if (hasColor) {
|
||||||
WRITE(p, " float4 color0 : COLOR0;\n");
|
WRITE(p, " vec4 color0 : COLOR0;\n");
|
||||||
}
|
}
|
||||||
if (hasNormal) {
|
if (hasNormal) {
|
||||||
WRITE(p, " float3 normal : NORMAL;\n");
|
WRITE(p, " vec3 normal : NORMAL;\n");
|
||||||
}
|
}
|
||||||
WRITE(p, " float3 position : POSITION;\n");
|
WRITE(p, " vec3 position : POSITION;\n");
|
||||||
WRITE(p, "};\n");
|
WRITE(p, "};\n");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, "struct VS_IN {\n");
|
WRITE(p, "struct VS_IN {\n");
|
||||||
WRITE(p, " float4 position : POSITION;\n");
|
WRITE(p, " vec4 position : POSITION;\n");
|
||||||
if (doTexture && hasTexcoord) {
|
if (doTexture && hasTexcoord) {
|
||||||
if (doTextureTransform && !isModeThrough) {
|
if (doTextureTransform && !isModeThrough) {
|
||||||
texCoordInVec3 = true;
|
texCoordInVec3 = true;
|
||||||
WRITE(p, " float3 texcoord : TEXCOORD0;\n");
|
WRITE(p, " vec3 texcoord : TEXCOORD0;\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
WRITE(p, " float2 texcoord : TEXCOORD0;\n");
|
WRITE(p, " vec2 texcoord : TEXCOORD0;\n");
|
||||||
}
|
}
|
||||||
if (hasColor) {
|
if (hasColor) {
|
||||||
WRITE(p, " float4 color0 : COLOR0;\n");
|
WRITE(p, " vec4 color0 : COLOR0;\n");
|
||||||
}
|
}
|
||||||
// only software transform supplies color1 as vertex data
|
// only software transform supplies color1 as vertex data
|
||||||
if (lmode) {
|
if (lmode) {
|
||||||
WRITE(p, " float4 color1 : COLOR1;\n");
|
WRITE(p, " vec4 color1 : COLOR1;\n");
|
||||||
}
|
}
|
||||||
WRITE(p, "};\n");
|
WRITE(p, "};\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, "struct VS_OUT {\n");
|
WRITE(p, "struct VS_OUT {\n");
|
||||||
if (doTexture) {
|
if (doTexture) {
|
||||||
WRITE(p, " float3 v_texcoord : TEXCOORD0;\n");
|
WRITE(p, " vec3 v_texcoord : TEXCOORD0;\n");
|
||||||
}
|
}
|
||||||
const char *colorInterpolation = doFlatShading && lang == HLSL_D3D11 ? "nointerpolation " : "";
|
const char *colorInterpolation = doFlatShading && lang == HLSL_D3D11 ? "nointerpolation " : "";
|
||||||
WRITE(p, " %sfloat4 v_color0 : COLOR0;\n", colorInterpolation);
|
WRITE(p, " %svec4 v_color0 : COLOR0;\n", colorInterpolation);
|
||||||
if (lmode)
|
if (lmode)
|
||||||
WRITE(p, " float3 v_color1 : COLOR1;\n");
|
WRITE(p, " vec3 v_color1 : COLOR1;\n");
|
||||||
|
|
||||||
if (enableFog) {
|
if (enableFog) {
|
||||||
WRITE(p, " float v_fogdepth: TEXCOORD1;\n");
|
WRITE(p, " float v_fogdepth: TEXCOORD1;\n");
|
||||||
}
|
}
|
||||||
if (lang == HLSL_DX9) {
|
if (lang == HLSL_D3D9) {
|
||||||
WRITE(p, " float4 gl_Position : POSITION;\n");
|
WRITE(p, " vec4 gl_Position : POSITION;\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " float4 gl_Position : SV_Position;\n");
|
WRITE(p, " vec4 gl_Position : SV_Position;\n");
|
||||||
}
|
}
|
||||||
WRITE(p, "};\n");
|
WRITE(p, "};\n");
|
||||||
|
|
||||||
@ -255,12 +257,12 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
if (!isModeThrough && gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
if (!isModeThrough && gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
||||||
// Apply the projection and viewport to get the Z buffer value, floor to integer, undo the viewport and projection.
|
// Apply the projection and viewport to get the Z buffer value, floor to integer, undo the viewport and projection.
|
||||||
// The Z range in D3D is different but we compensate for that using parameters.
|
// The Z range in D3D is different but we compensate for that using parameters.
|
||||||
WRITE(p, "\nfloat4 depthRoundZVP(float4 v) {\n");
|
WRITE(p, "\nvec4 depthRoundZVP(vec4 v) {\n");
|
||||||
WRITE(p, " float z = v.z / v.w;\n");
|
WRITE(p, " float z = v.z / v.w;\n");
|
||||||
WRITE(p, " z = (z * u_depthRange.x + u_depthRange.y);\n");
|
WRITE(p, " z = (z * u_depthRange.x + u_depthRange.y);\n");
|
||||||
WRITE(p, " z = floor(z);\n");
|
WRITE(p, " z = floor(z);\n");
|
||||||
WRITE(p, " z = (z - u_depthRange.z) * u_depthRange.w;\n");
|
WRITE(p, " z = (z - u_depthRange.z) * u_depthRange.w;\n");
|
||||||
WRITE(p, " return float4(v.x, v.y, z * v.w, v.w);\n");
|
WRITE(p, " return vec4(v.x, v.y, z * v.w, v.w);\n");
|
||||||
WRITE(p, "}\n\n");
|
WRITE(p, "}\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,15 +270,15 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
if (doSpline || doBezier) {
|
if (doSpline || doBezier) {
|
||||||
if (lang == HLSL_D3D11) {
|
if (lang == HLSL_D3D11) {
|
||||||
WRITE(p, "struct TessData {\n");
|
WRITE(p, "struct TessData {\n");
|
||||||
WRITE(p, " float3 pos; float pad1;\n");
|
WRITE(p, " vec3 pos; float pad1;\n");
|
||||||
WRITE(p, " float2 tex; float2 pad2;\n");
|
WRITE(p, " vec2 tex; vec2 pad2;\n");
|
||||||
WRITE(p, " float4 col;\n");
|
WRITE(p, " vec4 col;\n");
|
||||||
WRITE(p, "};\n");
|
WRITE(p, "};\n");
|
||||||
WRITE(p, "StructuredBuffer<TessData> tess_data : register(t0);\n");
|
WRITE(p, "StructuredBuffer<TessData> tess_data : register(t0);\n");
|
||||||
|
|
||||||
WRITE(p, "struct TessWeight {\n");
|
WRITE(p, "struct TessWeight {\n");
|
||||||
WRITE(p, " float4 basis;\n");
|
WRITE(p, " vec4 basis;\n");
|
||||||
WRITE(p, " float4 deriv;\n");
|
WRITE(p, " vec4 deriv;\n");
|
||||||
WRITE(p, "};\n");
|
WRITE(p, "};\n");
|
||||||
WRITE(p, "StructuredBuffer<TessWeight> tess_weights_u : register(t1);\n");
|
WRITE(p, "StructuredBuffer<TessWeight> tess_weights_u : register(t1);\n");
|
||||||
WRITE(p, "StructuredBuffer<TessWeight> tess_weights_v : register(t2);\n");
|
WRITE(p, "StructuredBuffer<TessWeight> tess_weights_v : register(t2);\n");
|
||||||
@ -284,7 +286,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
|
|
||||||
const char *init[3] = { "0.0, 0.0", "0.0, 0.0, 0.0", "0.0, 0.0, 0.0, 0.0" };
|
const char *init[3] = { "0.0, 0.0", "0.0, 0.0, 0.0", "0.0, 0.0, 0.0, 0.0" };
|
||||||
for (int i = 2; i <= 4; i++) {
|
for (int i = 2; i <= 4; i++) {
|
||||||
// Define 3 types float2, float3, float4
|
// Define 3 types vec2, vec3, vec4
|
||||||
WRITE(p, "float%d tess_sample(in float%d points[16], float4x4 weights) {\n", i, i);
|
WRITE(p, "float%d tess_sample(in float%d points[16], float4x4 weights) {\n", i, i);
|
||||||
WRITE(p, " float%d pos = float%d(%s);\n", i, i, init[i - 2]);
|
WRITE(p, " float%d pos = float%d(%s);\n", i, i, init[i - 2]);
|
||||||
for (int v = 0; v < 4; ++v) {
|
for (int v = 0; v < 4; ++v) {
|
||||||
@ -296,26 +298,26 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
WRITE(p, "}\n");
|
WRITE(p, "}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, "float4x4 outerProduct(float4 u, float4 v) {\n");
|
WRITE(p, "float4x4 outerProduct(vec4 u, vec4 v) {\n");
|
||||||
WRITE(p, " return mul((float4x1)v, (float1x4)u);\n");
|
WRITE(p, " return mul((float4x1)v, (float1x4)u);\n");
|
||||||
WRITE(p, "}\n");
|
WRITE(p, "}\n");
|
||||||
|
|
||||||
WRITE(p, "struct Tess {\n");
|
WRITE(p, "struct Tess {\n");
|
||||||
WRITE(p, " float3 pos;\n");
|
WRITE(p, " vec3 pos;\n");
|
||||||
if (doTexture)
|
if (doTexture)
|
||||||
WRITE(p, " float2 tex;\n");
|
WRITE(p, " vec2 tex;\n");
|
||||||
WRITE(p, " float4 col;\n");
|
WRITE(p, " vec4 col;\n");
|
||||||
if (hasNormalTess)
|
if (hasNormalTess)
|
||||||
WRITE(p, " float3 nrm;\n");
|
WRITE(p, " vec3 nrm;\n");
|
||||||
WRITE(p, "};\n");
|
WRITE(p, "};\n");
|
||||||
|
|
||||||
WRITE(p, "void tessellate(in VS_IN In, out Tess tess) {\n");
|
WRITE(p, "void tessellate(in VS_IN In, out Tess tess) {\n");
|
||||||
WRITE(p, " int2 point_pos = int2(In.position.z, In.normal.z)%s;\n", doBezier ? " * 3" : "");
|
WRITE(p, " int2 point_pos = int2(In.position.z, In.normal.z)%s;\n", doBezier ? " * 3" : "");
|
||||||
WRITE(p, " int2 weight_idx = int2(In.position.xy);\n");
|
WRITE(p, " int2 weight_idx = int2(In.position.xy);\n");
|
||||||
// Load 4x4 control points
|
// Load 4x4 control points
|
||||||
WRITE(p, " float3 _pos[16];\n");
|
WRITE(p, " vec3 _pos[16];\n");
|
||||||
WRITE(p, " float2 _tex[16];\n");
|
WRITE(p, " vec2 _tex[16];\n");
|
||||||
WRITE(p, " float4 _col[16];\n");
|
WRITE(p, " vec4 _col[16];\n");
|
||||||
WRITE(p, " int index;\n");
|
WRITE(p, " int index;\n");
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
@ -329,8 +331,8 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Basis polynomials as weight coefficients
|
// Basis polynomials as weight coefficients
|
||||||
WRITE(p, " float4 basis_u = tess_weights_u[weight_idx.x].basis;\n");
|
WRITE(p, " vec4 basis_u = tess_weights_u[weight_idx.x].basis;\n");
|
||||||
WRITE(p, " float4 basis_v = tess_weights_v[weight_idx.y].basis;\n");
|
WRITE(p, " vec4 basis_v = tess_weights_v[weight_idx.y].basis;\n");
|
||||||
WRITE(p, " float4x4 basis = outerProduct(basis_u, basis_v);\n");
|
WRITE(p, " float4x4 basis = outerProduct(basis_u, basis_v);\n");
|
||||||
|
|
||||||
// Tessellate
|
// Tessellate
|
||||||
@ -347,11 +349,11 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
WRITE(p, " tess.col = u_matambientalpha;\n");
|
WRITE(p, " tess.col = u_matambientalpha;\n");
|
||||||
if (hasNormalTess) {
|
if (hasNormalTess) {
|
||||||
// Derivatives as weight coefficients
|
// Derivatives as weight coefficients
|
||||||
WRITE(p, " float4 deriv_u = tess_weights_u[weight_idx.x].deriv;\n");
|
WRITE(p, " vec4 deriv_u = tess_weights_u[weight_idx.x].deriv;\n");
|
||||||
WRITE(p, " float4 deriv_v = tess_weights_v[weight_idx.y].deriv;\n");
|
WRITE(p, " vec4 deriv_v = tess_weights_v[weight_idx.y].deriv;\n");
|
||||||
|
|
||||||
WRITE(p, " float3 du = tess_sample(_pos, outerProduct(deriv_u, basis_v));\n");
|
WRITE(p, " vec3 du = tess_sample(_pos, outerProduct(deriv_u, basis_v));\n");
|
||||||
WRITE(p, " float3 dv = tess_sample(_pos, outerProduct(basis_u, deriv_v));\n");
|
WRITE(p, " vec3 dv = tess_sample(_pos, outerProduct(basis_u, deriv_v));\n");
|
||||||
WRITE(p, " tess.nrm = normalize(cross(du, dv));\n");
|
WRITE(p, " tess.nrm = normalize(cross(du, dv));\n");
|
||||||
}
|
}
|
||||||
WRITE(p, "}\n");
|
WRITE(p, "}\n");
|
||||||
@ -365,7 +367,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
if (texCoordInVec3) {
|
if (texCoordInVec3) {
|
||||||
WRITE(p, " Out.v_texcoord = In.texcoord;\n");
|
WRITE(p, " Out.v_texcoord = In.texcoord;\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " Out.v_texcoord = float3(In.texcoord, 1.0);\n");
|
WRITE(p, " Out.v_texcoord = vec3(In.texcoord, 1.0);\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasColor) {
|
if (hasColor) {
|
||||||
@ -375,29 +377,29 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
} else {
|
} else {
|
||||||
WRITE(p, " Out.v_color0 = In.u_matambientalpha;\n");
|
WRITE(p, " Out.v_color0 = In.u_matambientalpha;\n");
|
||||||
if (lmode)
|
if (lmode)
|
||||||
WRITE(p, " Out.v_color1 = float3(0.0);\n");
|
WRITE(p, " Out.v_color1 = vec3(0.0);\n");
|
||||||
}
|
}
|
||||||
if (enableFog) {
|
if (enableFog) {
|
||||||
WRITE(p, " Out.v_fogdepth = In.position.w;\n");
|
WRITE(p, " Out.v_fogdepth = In.position.w;\n");
|
||||||
}
|
}
|
||||||
if (lang == HLSL_D3D11) {
|
if (lang == HLSL_D3D11) {
|
||||||
if (isModeThrough) {
|
if (isModeThrough) {
|
||||||
WRITE(p, " float4 outPos = mul(u_proj_through, float4(In.position.xyz, 1.0));\n");
|
WRITE(p, " float4 outPos = mul(u_proj_through, vec4(In.position.xyz, 1.0));\n");
|
||||||
} else {
|
} else {
|
||||||
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
||||||
WRITE(p, " float4 outPos = depthRoundZVP(mul(u_proj, float4(In.position.xyz, 1.0)));\n");
|
WRITE(p, " vec4 outPos = depthRoundZVP(mul(u_proj, vec4(In.position.xyz, 1.0)));\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " float4 outPos = mul(u_proj, float4(In.position.xyz, 1.0));\n");
|
WRITE(p, " vec4 outPos = mul(u_proj, vec4(In.position.xyz, 1.0));\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isModeThrough) {
|
if (isModeThrough) {
|
||||||
WRITE(p, " float4 outPos = mul(float4(In.position.xyz, 1.0), u_proj_through);\n");
|
WRITE(p, " vec4 outPos = mul(vec4(In.position.xyz, 1.0), u_proj_through);\n");
|
||||||
} else {
|
} else {
|
||||||
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
||||||
WRITE(p, " float4 outPos = depthRoundZVP(mul(float4(In.position.xyz, 1.0), u_proj));\n");
|
WRITE(p, " vec4 outPos = depthRoundZVP(mul(vec4(In.position.xyz, 1.0), u_proj));\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " float4 outPos = mul(float4(In.position.xyz, 1.0), u_proj);\n");
|
WRITE(p, " vec4 outPos = mul(vec4(In.position.xyz, 1.0), u_proj);\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -409,18 +411,18 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
WRITE(p, " Tess tess;\n");
|
WRITE(p, " Tess tess;\n");
|
||||||
WRITE(p, " tessellate(In, tess);\n");
|
WRITE(p, " tessellate(In, tess);\n");
|
||||||
|
|
||||||
WRITE(p, " float3 worldpos = mul(float4(tess.pos.xyz, 1.0), u_world);\n");
|
WRITE(p, " vec3 worldpos = mul(vec4(tess.pos.xyz, 1.0), u_world);\n");
|
||||||
if (hasNormalTess)
|
if (hasNormalTess)
|
||||||
WRITE(p, " float3 worldnormal = normalize(mul(float4(%stess.nrm, 0.0), u_world));\n", flipNormalTess ? "-" : "");
|
WRITE(p, " vec3 worldnormal = normalize(mul(vec4(%stess.nrm, 0.0), u_world));\n", flipNormalTess ? "-" : "");
|
||||||
else
|
else
|
||||||
WRITE(p, " float3 worldnormal = float3(0.0, 0.0, 1.0);\n");
|
WRITE(p, " vec3 worldnormal = vec3(0.0, 0.0, 1.0);\n");
|
||||||
} else {
|
} else {
|
||||||
// No skinning, just standard T&L.
|
// No skinning, just standard T&L.
|
||||||
WRITE(p, " float3 worldpos = mul(float4(In.position.xyz, 1.0), u_world);\n");
|
WRITE(p, " vec3 worldpos = mul(vec4(In.position.xyz, 1.0), u_world);\n");
|
||||||
if (hasNormal)
|
if (hasNormal)
|
||||||
WRITE(p, " float3 worldnormal = normalize(mul(float4(%sIn.normal, 0.0), u_world));\n", flipNormal ? "-" : "");
|
WRITE(p, " vec3 worldnormal = normalize(mul(vec4(%sIn.normal, 0.0), u_world));\n", flipNormal ? "-" : "");
|
||||||
else
|
else
|
||||||
WRITE(p, " float3 worldnormal = float3(0.0, 0.0, 1.0);\n");
|
WRITE(p, " vec3 worldnormal = vec3(0.0, 0.0, 1.0);\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
static const char * const boneWeightAttr[8] = {
|
static const char * const boneWeightAttr[8] = {
|
||||||
@ -430,7 +432,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
|
|
||||||
if (lang == HLSL_D3D11) {
|
if (lang == HLSL_D3D11) {
|
||||||
if (numBoneWeights == 1)
|
if (numBoneWeights == 1)
|
||||||
WRITE(p, " float4x3 skinMatrix = mul(In.a_w1, u_bone[0])");
|
WRITE(p, " mat3x4 skinMatrix = mul(In.a_w1, u_bone[0])");
|
||||||
else
|
else
|
||||||
WRITE(p, " float4x3 skinMatrix = mul(In.a_w1.x, u_bone[0])");
|
WRITE(p, " float4x3 skinMatrix = mul(In.a_w1.x, u_bone[0])");
|
||||||
for (int i = 1; i < numBoneWeights; i++) {
|
for (int i = 1; i < numBoneWeights; i++) {
|
||||||
@ -457,32 +459,32 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
WRITE(p, ";\n");
|
WRITE(p, ";\n");
|
||||||
|
|
||||||
// Trying to simplify this results in bugs in LBP...
|
// Trying to simplify this results in bugs in LBP...
|
||||||
WRITE(p, " float3 skinnedpos = mul(float4(In.position.xyz, 1.0), skinMatrix);\n");
|
WRITE(p, " vec3 skinnedpos = mul(float4(In.position.xyz, 1.0), skinMatrix);\n");
|
||||||
WRITE(p, " float3 worldpos = mul(float4(skinnedpos, 1.0), u_world);\n");
|
WRITE(p, " vec3 worldpos = mul(float4(skinnedpos, 1.0), u_world);\n");
|
||||||
|
|
||||||
if (hasNormal) {
|
if (hasNormal) {
|
||||||
WRITE(p, " float3 skinnednormal = mul(float4(%sIn.normal, 0.0), skinMatrix);\n", flipNormal ? "-" : "");
|
WRITE(p, " vec3 skinnednormal = mul(float4(%sIn.normal, 0.0), skinMatrix);\n", flipNormal ? "-" : "");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " float3 skinnednormal = mul(float4(0.0, 0.0, %s1.0, 0.0), skinMatrix);\n", flipNormal ? "-" : "");
|
WRITE(p, " vec3 skinnednormal = mul(float4(0.0, 0.0, %s1.0, 0.0), skinMatrix);\n", flipNormal ? "-" : "");
|
||||||
}
|
}
|
||||||
WRITE(p, " float3 worldnormal = normalize(mul(float4(skinnednormal, 0.0), u_world));\n");
|
WRITE(p, " vec3 worldnormal = normalize(mul(float4(skinnednormal, 0.0), u_world));\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, " float4 viewPos = float4(mul(float4(worldpos, 1.0), u_view), 1.0);\n");
|
WRITE(p, " vec4 viewPos = vec4(mul(vec4(worldpos, 1.0), u_view), 1.0);\n");
|
||||||
|
|
||||||
if (lang == HLSL_D3D11) {
|
if (lang == HLSL_D3D11) {
|
||||||
// Final view and projection transforms.
|
// Final view and projection transforms.
|
||||||
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
||||||
WRITE(p, " float4 outPos = depthRoundZVP(mul(u_proj, viewPos));\n");
|
WRITE(p, " vec4 outPos = depthRoundZVP(mul(u_proj, viewPos));\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " float4 outPos = mul(u_proj, viewPos);\n");
|
WRITE(p, " vec4 outPos = mul(u_proj, viewPos);\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Final view and projection transforms.
|
// Final view and projection transforms.
|
||||||
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) {
|
||||||
WRITE(p, " float4 outPos = depthRoundZVP(mul(viewPos, u_proj));\n");
|
WRITE(p, " vec4 outPos = depthRoundZVP(mul(viewPos, u_proj));\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " float4 outPos = mul(viewPos, u_proj);\n");
|
WRITE(p, " vec4 outPos = mul(viewPos, u_proj);\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,7 +505,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
bool distanceNeeded = false;
|
bool distanceNeeded = false;
|
||||||
bool anySpots = false;
|
bool anySpots = false;
|
||||||
if (enableLighting) {
|
if (enableLighting) {
|
||||||
WRITE(p, " float4 lightSum0 = u_ambient * %s + float4(u_matemissive, 0.0);\n", ambientStr);
|
WRITE(p, " vec4 lightSum0 = u_ambient * %s + float4(u_matemissive, 0.0);\n", ambientStr);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
GELightType type = static_cast<GELightType>(id.Bits(VS_BIT_LIGHT0_TYPE + 4 * i, 2));
|
GELightType type = static_cast<GELightType>(id.Bits(VS_BIT_LIGHT0_TYPE + 4 * i, 2));
|
||||||
@ -520,11 +522,11 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!specularIsZero) {
|
if (!specularIsZero) {
|
||||||
WRITE(p, " float3 lightSum1 = 0;\n");
|
WRITE(p, " vec3 lightSum1 = 0;\n");
|
||||||
}
|
}
|
||||||
if (!diffuseIsZero) {
|
if (!diffuseIsZero) {
|
||||||
WRITE(p, " float3 toLight;\n");
|
WRITE(p, " vec3 toLight;\n");
|
||||||
WRITE(p, " float3 diffuse;\n");
|
WRITE(p, " vec3 diffuse;\n");
|
||||||
}
|
}
|
||||||
if (distanceNeeded) {
|
if (distanceNeeded) {
|
||||||
WRITE(p, " float distance;\n");
|
WRITE(p, " float distance;\n");
|
||||||
@ -576,13 +578,13 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
timesLightScale = "";
|
timesLightScale = "";
|
||||||
break;
|
break;
|
||||||
case GE_LIGHTTYPE_POINT:
|
case GE_LIGHTTYPE_POINT:
|
||||||
WRITE(p, " lightScale = clamp(1.0 / dot(u_lightatt%i, float3(1.0, distance, distance*distance)), 0.0, 1.0);\n", i);
|
WRITE(p, " lightScale = clamp(1.0 / dot(u_lightatt%i, vec3(1.0, distance, distance*distance)), 0.0, 1.0);\n", i);
|
||||||
break;
|
break;
|
||||||
case GE_LIGHTTYPE_SPOT:
|
case GE_LIGHTTYPE_SPOT:
|
||||||
case GE_LIGHTTYPE_UNKNOWN:
|
case GE_LIGHTTYPE_UNKNOWN:
|
||||||
WRITE(p, " angle = length(u_lightdir%i) == 0.0 ? 0.0 : dot(normalize(u_lightdir%i), toLight);\n", i, i);
|
WRITE(p, " angle = length(u_lightdir%i) == 0.0 ? 0.0 : dot(normalize(u_lightdir%i), toLight);\n", i, i);
|
||||||
WRITE(p, " if (angle >= u_lightangle_spotCoef%i.x) {\n", i);
|
WRITE(p, " if (angle >= u_lightangle_spotCoef%i.x) {\n", i);
|
||||||
WRITE(p, " lightScale = clamp(1.0 / dot(u_lightatt%i, float3(1.0, distance, distance*distance)), 0.0, 1.0) * (u_lightangle_spotCoef%i.y <= 0.0 ? 1.0 : pow(angle, u_lightangle_spotCoef%i.y));\n", i, i, i);
|
WRITE(p, " lightScale = clamp(1.0 / dot(u_lightatt%i, vec3(1.0, distance, distance*distance)), 0.0, 1.0) * (u_lightangle_spotCoef%i.y <= 0.0 ? 1.0 : pow(angle, u_lightangle_spotCoef%i.y));\n", i, i, i);
|
||||||
WRITE(p, " } else {\n");
|
WRITE(p, " } else {\n");
|
||||||
WRITE(p, " lightScale = 0.0;\n");
|
WRITE(p, " lightScale = 0.0;\n");
|
||||||
WRITE(p, " }\n");
|
WRITE(p, " }\n");
|
||||||
@ -595,7 +597,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
WRITE(p, " diffuse = (u_lightdiffuse%i * %s) * max(ldot, 0.0);\n", i, diffuseStr);
|
WRITE(p, " diffuse = (u_lightdiffuse%i * %s) * max(ldot, 0.0);\n", i, diffuseStr);
|
||||||
if (doSpecular) {
|
if (doSpecular) {
|
||||||
WRITE(p, " if (ldot >= 0.0) {\n");
|
WRITE(p, " if (ldot >= 0.0) {\n");
|
||||||
WRITE(p, " ldot = dot(normalize(toLight + float3(0.0, 0.0, 1.0)), worldnormal);\n");
|
WRITE(p, " ldot = dot(normalize(toLight + vec3(0.0, 0.0, 1.0)), worldnormal);\n");
|
||||||
WRITE(p, " if (u_matspecular.a <= 0.0) {\n");
|
WRITE(p, " if (u_matspecular.a <= 0.0) {\n");
|
||||||
WRITE(p, " ldot = 1.0;\n");
|
WRITE(p, " ldot = 1.0;\n");
|
||||||
WRITE(p, " } else {\n");
|
WRITE(p, " } else {\n");
|
||||||
@ -614,7 +616,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
WRITE(p, " Out.v_color0 = clamp(lightSum0, 0.0, 1.0);\n");
|
WRITE(p, " Out.v_color0 = clamp(lightSum0, 0.0, 1.0);\n");
|
||||||
// v_color1 only exists when lmode = 1.
|
// v_color1 only exists when lmode = 1.
|
||||||
if (specularIsZero) {
|
if (specularIsZero) {
|
||||||
WRITE(p, " Out.v_color1 = float3(0, 0, 0);\n");
|
WRITE(p, " Out.v_color1 = splat3(0.0);\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " Out.v_color1 = clamp(lightSum1, 0.0, 1.0);\n");
|
WRITE(p, " Out.v_color1 = clamp(lightSum1, 0.0, 1.0);\n");
|
||||||
}
|
}
|
||||||
@ -647,17 +649,17 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
if (scaleUV) {
|
if (scaleUV) {
|
||||||
if (hasTexcoord) {
|
if (hasTexcoord) {
|
||||||
if (doBezier || doSpline)
|
if (doBezier || doSpline)
|
||||||
WRITE(p, " Out.v_texcoord = float3(tess.tex.xy * u_uvscaleoffset.xy + u_uvscaleoffset.zw, 0.0);\n");
|
WRITE(p, " Out.v_texcoord = vec3(tess.tex.xy * u_uvscaleoffset.xy + u_uvscaleoffset.zw, 0.0);\n");
|
||||||
else
|
else
|
||||||
WRITE(p, " Out.v_texcoord = float3(In.texcoord.xy * u_uvscaleoffset.xy, 0.0);\n");
|
WRITE(p, " Out.v_texcoord = vec3(In.texcoord.xy * u_uvscaleoffset.xy, 0.0);\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " Out.v_texcoord = splat3(0.0);\n");
|
WRITE(p, " Out.v_texcoord = splat3(0.0);\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (hasTexcoord) {
|
if (hasTexcoord) {
|
||||||
WRITE(p, " Out.v_texcoord = float3(In.texcoord.xy * u_uvscaleoffset.xy + u_uvscaleoffset.zw, 0.0);\n");
|
WRITE(p, " Out.v_texcoord = vec3(In.texcoord.xy * u_uvscaleoffset.xy + u_uvscaleoffset.zw, 0.0);\n");
|
||||||
} else {
|
} else {
|
||||||
WRITE(p, " Out.v_texcoord = float3(u_uvscaleoffset.zw, 0.0);\n");
|
WRITE(p, " Out.v_texcoord = vec3(u_uvscaleoffset.zw, 0.0);\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -667,32 +669,32 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
std::string temp_tc;
|
std::string temp_tc;
|
||||||
switch (uvProjMode) {
|
switch (uvProjMode) {
|
||||||
case GE_PROJMAP_POSITION: // Use model space XYZ as source
|
case GE_PROJMAP_POSITION: // Use model space XYZ as source
|
||||||
temp_tc = "float4(In.position.xyz, 1.0)";
|
temp_tc = "vec4(In.position.xyz, 1.0)";
|
||||||
break;
|
break;
|
||||||
case GE_PROJMAP_UV: // Use unscaled UV as source
|
case GE_PROJMAP_UV: // Use unscaled UV as source
|
||||||
{
|
{
|
||||||
if (hasTexcoord) {
|
if (hasTexcoord) {
|
||||||
temp_tc = StringFromFormat("float4(In.texcoord.xy, 0.0, 1.0)");
|
temp_tc = StringFromFormat("vec4(In.texcoord.xy, 0.0, 1.0)");
|
||||||
} else {
|
} else {
|
||||||
temp_tc = "float4(0.0, 0.0, 0.0, 1.0)";
|
temp_tc = "vec4(0.0, 0.0, 0.0, 1.0)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GE_PROJMAP_NORMALIZED_NORMAL: // Use normalized transformed normal as source
|
case GE_PROJMAP_NORMALIZED_NORMAL: // Use normalized transformed normal as source
|
||||||
if (hasNormal)
|
if (hasNormal)
|
||||||
temp_tc = flipNormal ? "float4(normalize(-In.normal), 1.0)" : "float4(normalize(In.normal), 1.0)";
|
temp_tc = flipNormal ? "vec4(normalize(-In.normal), 1.0)" : "vec4(normalize(In.normal), 1.0)";
|
||||||
else
|
else
|
||||||
temp_tc = "float4(0.0, 0.0, 1.0, 1.0)";
|
temp_tc = "vec4(0.0, 0.0, 1.0, 1.0)";
|
||||||
break;
|
break;
|
||||||
case GE_PROJMAP_NORMAL: // Use non-normalized transformed normal as source
|
case GE_PROJMAP_NORMAL: // Use non-normalized transformed normal as source
|
||||||
if (hasNormal)
|
if (hasNormal)
|
||||||
temp_tc = flipNormal ? "float4(-In.normal, 1.0)" : "float4(In.normal, 1.0)";
|
temp_tc = flipNormal ? "vec4(-In.normal, 1.0)" : "vec4(In.normal, 1.0)";
|
||||||
else
|
else
|
||||||
temp_tc = "float4(0.0, 0.0, 1.0, 1.0)";
|
temp_tc = "vec4(0.0, 0.0, 1.0, 1.0)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Transform by texture matrix. XYZ as we are doing projection mapping.
|
// Transform by texture matrix. XYZ as we are doing projection mapping.
|
||||||
WRITE(p, " Out.v_texcoord.xyz = mul(%s, u_texmtx) * float3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str());
|
WRITE(p, " Out.v_texcoord.xyz = mul(%s, u_texmtx) * vec3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -700,7 +702,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
{
|
{
|
||||||
std::string lightFactor0 = StringFromFormat("(length(u_lightpos%i) == 0.0 ? worldnormal.z : dot(normalize(u_lightpos%i), worldnormal))", ls0, ls0);
|
std::string lightFactor0 = StringFromFormat("(length(u_lightpos%i) == 0.0 ? worldnormal.z : dot(normalize(u_lightpos%i), worldnormal))", ls0, ls0);
|
||||||
std::string lightFactor1 = StringFromFormat("(length(u_lightpos%i) == 0.0 ? worldnormal.z : dot(normalize(u_lightpos%i), worldnormal))", ls1, ls1);
|
std::string lightFactor1 = StringFromFormat("(length(u_lightpos%i) == 0.0 ? worldnormal.z : dot(normalize(u_lightpos%i), worldnormal))", ls1, ls1);
|
||||||
WRITE(p, " Out.v_texcoord = float3(u_uvscaleoffset.xy * float2(1.0 + %s, 1.0 + %s) * 0.5, 1.0);\n", lightFactor0.c_str(), lightFactor1.c_str());
|
WRITE(p, " Out.v_texcoord = vec3(u_uvscaleoffset.xy * vec2(1.0 + %s, 1.0 + %s) * 0.5, 1.0);\n", lightFactor0.c_str(), lightFactor1.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -718,7 +720,7 @@ bool GenerateVertexShaderHLSL(const VShaderID &id, char *buffer, ShaderLanguage
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isModeThrough && gstate_c.Supports(GPU_SUPPORTS_VS_RANGE_CULLING)) {
|
if (!isModeThrough && gstate_c.Supports(GPU_SUPPORTS_VS_RANGE_CULLING)) {
|
||||||
WRITE(p, " float3 projPos = outPos.xyz / outPos.w;\n");
|
WRITE(p, " vec3 projPos = outPos.xyz / outPos.w;\n");
|
||||||
// Vertex range culling doesn't happen when depth is clamped, so only do this if in range.
|
// Vertex range culling doesn't happen when depth is clamped, so only do this if in range.
|
||||||
WRITE(p, " if (u_cullRangeMin.w <= 0.0 || (projPos.z >= u_cullRangeMin.z && projPos.z <= u_cullRangeMax.z)) {\n");
|
WRITE(p, " if (u_cullRangeMin.w <= 0.0 || (projPos.z >= u_cullRangeMin.z && projPos.z <= u_cullRangeMax.z)) {\n");
|
||||||
const char *outMin = "projPos.x < u_cullRangeMin.x || projPos.y < u_cullRangeMin.y || projPos.z < u_cullRangeMin.z";
|
const char *outMin = "projPos.x < u_cullRangeMin.x || projPos.y < u_cullRangeMin.y || projPos.z < u_cullRangeMin.z";
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include "GPU/Common/VertexDecoderCommon.h"
|
#include "GPU/Common/VertexDecoderCommon.h"
|
||||||
#include "GPU/Common/DrawEngineCommon.h"
|
#include "GPU/Common/DrawEngineCommon.h"
|
||||||
#include "GPU/Common/GPUStateUtils.h"
|
#include "GPU/Common/GPUStateUtils.h"
|
||||||
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
|
|
||||||
class LinkedShader;
|
class LinkedShader;
|
||||||
class ShaderManagerGLES;
|
class ShaderManagerGLES;
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
// Copyright (c) 2012- PPSSPP Project.
|
|
||||||
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, version 2.0 or later versions.
|
|
||||||
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License 2.0 for more details.
|
|
||||||
|
|
||||||
// A copy of the GPL 2.0 should have been included with the program.
|
|
||||||
// If not, see http://www.gnu.org/licenses/
|
|
||||||
|
|
||||||
// Official git repository and contact information can be found at
|
|
||||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "GPU/Common/ShaderCommon.h"
|
|
||||||
|
|
||||||
struct FShaderID;
|
|
||||||
|
|
||||||
bool GenerateFragmentShaderGLSL(const FShaderID &id, char *buffer, const GLSLShaderCompat &compat, uint64_t *uniformMask, std::string *errorString);
|
|
@ -571,7 +571,7 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShaderManagerGLES::ShaderManagerGLES(Draw::DrawContext *draw)
|
ShaderManagerGLES::ShaderManagerGLES(Draw::DrawContext *draw)
|
||||||
: ShaderManagerCommon(draw), lastShader_(nullptr), shaderSwitchDirtyUniforms_(0), diskCacheDirty_(false), fsCache_(16), vsCache_(16) {
|
: ShaderManagerCommon(draw), compat_(GLSL_140), fsCache_(16), vsCache_(16) {
|
||||||
render_ = (GLRenderManager *)draw->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
render_ = (GLRenderManager *)draw->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
||||||
codeBuffer_ = new char[16384];
|
codeBuffer_ = new char[16384];
|
||||||
lastFSID_.set_invalid();
|
lastFSID_.set_invalid();
|
||||||
@ -584,28 +584,24 @@ ShaderManagerGLES::~ShaderManagerGLES() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ShaderManagerGLES::DetectShaderLanguage() {
|
void ShaderManagerGLES::DetectShaderLanguage() {
|
||||||
GLSLShaderCompat &compat = compat_;
|
ShaderLanguageDesc &compat = compat_;
|
||||||
compat.attribute = "attribute";
|
|
||||||
compat.varying_vs = "varying";
|
|
||||||
compat.varying_fs = "varying";
|
|
||||||
compat.fragColor0 = "gl_FragColor";
|
|
||||||
compat.fragColor1 = "fragColor1";
|
|
||||||
compat.texture = "texture2D";
|
|
||||||
compat.texelFetch = nullptr;
|
|
||||||
compat.bitwiseOps = false;
|
|
||||||
compat.lastFragData = nullptr;
|
|
||||||
compat.gles = gl_extensions.IsGLES;
|
compat.gles = gl_extensions.IsGLES;
|
||||||
compat.forceMatrix4x4 = true;
|
|
||||||
|
|
||||||
if (compat.gles) {
|
if (compat.gles) {
|
||||||
if (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300)) {
|
if (gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300)) {
|
||||||
|
compat.shaderLanguage = ShaderLanguage::GLSL_300;
|
||||||
compat.glslVersionNumber = 300; // GLSL ES 3.0
|
compat.glslVersionNumber = 300; // GLSL ES 3.0
|
||||||
compat.fragColor0 = "fragColor0";
|
compat.fragColor0 = "fragColor0";
|
||||||
compat.texture = "texture";
|
compat.texture = "texture";
|
||||||
compat.glslES30 = true;
|
compat.glslES30 = true;
|
||||||
compat.bitwiseOps = true;
|
compat.bitwiseOps = true;
|
||||||
compat.texelFetch = "texelFetch";
|
compat.texelFetch = "texelFetch";
|
||||||
|
compat.varying_vs = "out";
|
||||||
|
compat.varying_fs = "in";
|
||||||
|
compat.attribute = "in";
|
||||||
} else {
|
} else {
|
||||||
|
compat.shaderLanguage = ShaderLanguage::GLSL_140;
|
||||||
compat.glslVersionNumber = 100; // GLSL ES 1.0
|
compat.glslVersionNumber = 100; // GLSL ES 1.0
|
||||||
if (gl_extensions.EXT_gpu_shader4) {
|
if (gl_extensions.EXT_gpu_shader4) {
|
||||||
compat.bitwiseOps = true;
|
compat.bitwiseOps = true;
|
||||||
@ -619,18 +615,24 @@ void ShaderManagerGLES::DetectShaderLanguage() {
|
|||||||
} else {
|
} else {
|
||||||
if (!gl_extensions.ForceGL2 || gl_extensions.IsCoreContext) {
|
if (!gl_extensions.ForceGL2 || gl_extensions.IsCoreContext) {
|
||||||
if (gl_extensions.VersionGEThan(3, 3, 0)) {
|
if (gl_extensions.VersionGEThan(3, 3, 0)) {
|
||||||
|
compat.shaderLanguage = ShaderLanguage::GLSL_300;
|
||||||
compat.glslVersionNumber = 330;
|
compat.glslVersionNumber = 330;
|
||||||
compat.fragColor0 = "fragColor0";
|
compat.fragColor0 = "fragColor0";
|
||||||
compat.texture = "texture";
|
compat.texture = "texture";
|
||||||
compat.glslES30 = true;
|
compat.glslES30 = true;
|
||||||
compat.bitwiseOps = true;
|
compat.bitwiseOps = true;
|
||||||
compat.texelFetch = "texelFetch";
|
compat.texelFetch = "texelFetch";
|
||||||
|
compat.varying_vs = "out";
|
||||||
|
compat.varying_fs = "in";
|
||||||
|
compat.attribute = "in";
|
||||||
} else if (gl_extensions.VersionGEThan(3, 0, 0)) {
|
} else if (gl_extensions.VersionGEThan(3, 0, 0)) {
|
||||||
|
compat.shaderLanguage = ShaderLanguage::GLSL_140;
|
||||||
compat.glslVersionNumber = 130;
|
compat.glslVersionNumber = 130;
|
||||||
compat.fragColor0 = "fragColor0";
|
compat.fragColor0 = "fragColor0";
|
||||||
compat.bitwiseOps = true;
|
compat.bitwiseOps = true;
|
||||||
compat.texelFetch = "texelFetch";
|
compat.texelFetch = "texelFetch";
|
||||||
} else {
|
} else {
|
||||||
|
compat.shaderLanguage = ShaderLanguage::GLSL_140;
|
||||||
compat.glslVersionNumber = 110;
|
compat.glslVersionNumber = 110;
|
||||||
if (gl_extensions.EXT_gpu_shader4) {
|
if (gl_extensions.EXT_gpu_shader4) {
|
||||||
compat.bitwiseOps = true;
|
compat.bitwiseOps = true;
|
||||||
@ -656,12 +658,6 @@ void ShaderManagerGLES::DetectShaderLanguage() {
|
|||||||
compat.lastFragData = "gl_LastFragColorARM";
|
compat.lastFragData = "gl_LastFragColorARM";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compat.glslES30 || gl_extensions.IsCoreContext) {
|
|
||||||
compat.varying_vs = "out";
|
|
||||||
compat.varying_fs = "in";
|
|
||||||
compat.attribute = "in";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderManagerGLES::Clear() {
|
void ShaderManagerGLES::Clear() {
|
||||||
@ -712,7 +708,7 @@ void ShaderManagerGLES::DirtyLastShader() {
|
|||||||
Shader *ShaderManagerGLES::CompileFragmentShader(FShaderID FSID) {
|
Shader *ShaderManagerGLES::CompileFragmentShader(FShaderID FSID) {
|
||||||
uint64_t uniformMask;
|
uint64_t uniformMask;
|
||||||
std::string errorString;
|
std::string errorString;
|
||||||
if (!GenerateFragmentShaderGLSL(FSID, codeBuffer_, compat_, &uniformMask, &errorString)) {
|
if (!GenerateFragmentShader(FSID, codeBuffer_, compat_, &uniformMask, &errorString)) {
|
||||||
ERROR_LOG(G3D, "Shader gen error: %s", errorString.c_str());
|
ERROR_LOG(G3D, "Shader gen error: %s", errorString.c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "GPU/Common/ShaderCommon.h"
|
#include "GPU/Common/ShaderCommon.h"
|
||||||
#include "GPU/Common/ShaderId.h"
|
#include "GPU/Common/ShaderId.h"
|
||||||
#include "GPU/GLES/VertexShaderGeneratorGLES.h"
|
#include "GPU/GLES/VertexShaderGeneratorGLES.h"
|
||||||
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
|
|
||||||
class Shader;
|
class Shader;
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ private:
|
|||||||
typedef std::vector<LinkedShaderCacheEntry> LinkedShaderCache;
|
typedef std::vector<LinkedShaderCacheEntry> LinkedShaderCache;
|
||||||
|
|
||||||
GLRenderManager *render_;
|
GLRenderManager *render_;
|
||||||
GLSLShaderCompat compat_{};
|
ShaderLanguageDesc compat_;
|
||||||
LinkedShaderCache linkedShaderCache_;
|
LinkedShaderCache linkedShaderCache_;
|
||||||
|
|
||||||
bool lastVShaderSame_;
|
bool lastVShaderSame_;
|
||||||
@ -204,8 +204,8 @@ private:
|
|||||||
FShaderID lastFSID_;
|
FShaderID lastFSID_;
|
||||||
VShaderID lastVSID_;
|
VShaderID lastVSID_;
|
||||||
|
|
||||||
LinkedShader *lastShader_;
|
LinkedShader *lastShader_ = nullptr;
|
||||||
u64 shaderSwitchDirtyUniforms_;
|
u64 shaderSwitchDirtyUniforms_ = 0;
|
||||||
char *codeBuffer_;
|
char *codeBuffer_;
|
||||||
|
|
||||||
typedef DenseHashMap<FShaderID, Shader *, nullptr> FSCache;
|
typedef DenseHashMap<FShaderID, Shader *, nullptr> FSCache;
|
||||||
@ -214,7 +214,7 @@ private:
|
|||||||
typedef DenseHashMap<VShaderID, Shader *, nullptr> VSCache;
|
typedef DenseHashMap<VShaderID, Shader *, nullptr> VSCache;
|
||||||
VSCache vsCache_;
|
VSCache vsCache_;
|
||||||
|
|
||||||
bool diskCacheDirty_;
|
bool diskCacheDirty_ = false;
|
||||||
struct {
|
struct {
|
||||||
std::vector<VShaderID> vert;
|
std::vector<VShaderID> vert;
|
||||||
std::vector<FShaderID> frag;
|
std::vector<FShaderID> frag;
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include "GPU/GLES/ShaderManagerGLES.h"
|
#include "GPU/GLES/ShaderManagerGLES.h"
|
||||||
#include "GPU/GLES/TextureCacheGLES.h"
|
#include "GPU/GLES/TextureCacheGLES.h"
|
||||||
#include "GPU/GLES/FramebufferManagerGLES.h"
|
#include "GPU/GLES/FramebufferManagerGLES.h"
|
||||||
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
|
|
||||||
static const GLushort glBlendFactorLookup[(size_t)BlendFactor::COUNT] = {
|
static const GLushort glBlendFactorLookup[(size_t)BlendFactor::COUNT] = {
|
||||||
GL_ZERO,
|
GL_ZERO,
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#include "GPU/GPUState.h"
|
#include "GPU/GPUState.h"
|
||||||
#include "GPU/GLES/TextureCacheGLES.h"
|
#include "GPU/GLES/TextureCacheGLES.h"
|
||||||
#include "GPU/GLES/FramebufferManagerGLES.h"
|
#include "GPU/GLES/FramebufferManagerGLES.h"
|
||||||
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
#include "GPU/GLES/DepalettizeShaderGLES.h"
|
#include "GPU/GLES/DepalettizeShaderGLES.h"
|
||||||
#include "GPU/GLES/ShaderManagerGLES.h"
|
#include "GPU/GLES/ShaderManagerGLES.h"
|
||||||
#include "GPU/GLES/DrawEngineGLES.h"
|
#include "GPU/GLES/DrawEngineGLES.h"
|
||||||
|
@ -99,13 +99,13 @@ static const char * const boneWeightDecl[9] = {
|
|||||||
"layout(location = 3) in vec4 w1;\nlayout(location = 4) in vec4 w2;\n",
|
"layout(location = 3) in vec4 w1;\nlayout(location = 4) in vec4 w2;\n",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *vulkan_glsl_preamble =
|
const char *vulkan_glsl_preamble_vs =
|
||||||
"#version 450\n"
|
"#version 450\n"
|
||||||
"#extension GL_ARB_separate_shader_objects : enable\n"
|
"#extension GL_ARB_separate_shader_objects : enable\n"
|
||||||
"#extension GL_ARB_shading_language_420pack : enable\n"
|
"#extension GL_ARB_shading_language_420pack : enable\n"
|
||||||
"#define splat3(x) vec3(x)\n\n";
|
"#define splat3(x) vec3(x)\n\n";
|
||||||
|
|
||||||
bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShaderCompat &compat, uint32_t *attrMask, uint64_t *uniformMask, std::string *errorString) {
|
bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const ShaderLanguageDesc &compat, uint32_t *attrMask, uint64_t *uniformMask, std::string *errorString) {
|
||||||
*attrMask = 0;
|
*attrMask = 0;
|
||||||
*uniformMask = 0;
|
*uniformMask = 0;
|
||||||
|
|
||||||
@ -113,8 +113,8 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
bool highpTexcoord = false;
|
bool highpTexcoord = false;
|
||||||
|
|
||||||
char *p = buffer;
|
char *p = buffer;
|
||||||
if (compat.vulkan) {
|
if (compat.shaderLanguage == GLSL_VULKAN) {
|
||||||
WRITE(p, "%s", vulkan_glsl_preamble);
|
WRITE(p, "%s", vulkan_glsl_preamble_vs);
|
||||||
} else {
|
} else {
|
||||||
if (compat.gles) {
|
if (compat.gles) {
|
||||||
// PowerVR needs highp to do the fog in MHU correctly.
|
// PowerVR needs highp to do the fog in MHU correctly.
|
||||||
@ -126,13 +126,13 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
WRITE(p, "#define splat3(x) vec3(x)\n");
|
WRITE(p, "#define splat3(x) vec3(x)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compat.vulkan && gl_extensions.EXT_gpu_shader4) {
|
if (ShaderLanguageIsOpenGL(compat.shaderLanguage) && gl_extensions.EXT_gpu_shader4) {
|
||||||
WRITE(p, "#extension GL_EXT_gpu_shader4 : enable\n");
|
WRITE(p, "#extension GL_EXT_gpu_shader4 : enable\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compat.gles) {
|
if (compat.gles) {
|
||||||
WRITE(p, "precision highp float;\n");
|
WRITE(p, "precision highp float;\n");
|
||||||
} else if (!compat.vulkan) {
|
} else if (compat.shaderLanguage != GLSL_VULKAN) {
|
||||||
WRITE(p, "#define lowp\n");
|
WRITE(p, "#define lowp\n");
|
||||||
WRITE(p, "#define mediump\n");
|
WRITE(p, "#define mediump\n");
|
||||||
WRITE(p, "#define highp\n");
|
WRITE(p, "#define highp\n");
|
||||||
@ -175,7 +175,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
bool hasNormalTess = id.Bit(VS_BIT_HAS_NORMAL_TESS);
|
bool hasNormalTess = id.Bit(VS_BIT_HAS_NORMAL_TESS);
|
||||||
bool flipNormalTess = id.Bit(VS_BIT_NORM_REVERSE_TESS);
|
bool flipNormalTess = id.Bit(VS_BIT_NORM_REVERSE_TESS);
|
||||||
|
|
||||||
if (compat.vulkan) {
|
if (compat.shaderLanguage == GLSL_VULKAN) {
|
||||||
WRITE(p, "\n");
|
WRITE(p, "\n");
|
||||||
WRITE(p, "layout (std140, set = 0, binding = 3) uniform baseVars {\n%s};\n", ub_baseStr);
|
WRITE(p, "layout (std140, set = 0, binding = 3) uniform baseVars {\n%s};\n", ub_baseStr);
|
||||||
if (enableLighting || doShadeMapping)
|
if (enableLighting || doShadeMapping)
|
||||||
@ -185,7 +185,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *shading = "";
|
const char *shading = "";
|
||||||
if (compat.glslES30 || compat.vulkan)
|
if (compat.glslES30 || compat.shaderLanguage == GLSL_VULKAN)
|
||||||
shading = doFlatShading ? "flat " : "";
|
shading = doFlatShading ? "flat " : "";
|
||||||
|
|
||||||
DoLightComputation doLight[4] = { LIGHT_OFF, LIGHT_OFF, LIGHT_OFF, LIGHT_OFF };
|
DoLightComputation doLight[4] = { LIGHT_OFF, LIGHT_OFF, LIGHT_OFF, LIGHT_OFF };
|
||||||
@ -204,7 +204,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
int boneWeightScale = id.Bits(VS_BIT_WEIGHT_FMTSCALE, 2);
|
int boneWeightScale = id.Bits(VS_BIT_WEIGHT_FMTSCALE, 2);
|
||||||
bool texcoordInVec3 = false;
|
bool texcoordInVec3 = false;
|
||||||
|
|
||||||
if (compat.vulkan) {
|
if (compat.shaderLanguage == GLSL_VULKAN) {
|
||||||
if (enableBones) {
|
if (enableBones) {
|
||||||
numBoneWeights = 1 + id.Bits(VS_BIT_BONES, 3);
|
numBoneWeights = 1 + id.Bits(VS_BIT_BONES, 3);
|
||||||
WRITE(p, "%s", boneWeightDecl[numBoneWeights]);
|
WRITE(p, "%s", boneWeightDecl[numBoneWeights]);
|
||||||
@ -307,15 +307,10 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
*uniformMask |= DIRTY_TEXMATRIX;
|
*uniformMask |= DIRTY_TEXMATRIX;
|
||||||
}
|
}
|
||||||
if (enableBones) {
|
if (enableBones) {
|
||||||
#ifdef USE_BONE_ARRAY
|
|
||||||
WRITE(p, "uniform mediump mat4 u_bone[%i];\n", numBoneWeights);
|
|
||||||
*uniformMask |= DIRTY_BONE_UNIFORMS;
|
|
||||||
#else
|
|
||||||
for (int i = 0; i < numBoneWeights; i++) {
|
for (int i = 0; i < numBoneWeights; i++) {
|
||||||
WRITE(p, "uniform mat4 u_bone%i;\n", i);
|
WRITE(p, "uniform mat4 u_bone%i;\n", i);
|
||||||
*uniformMask |= DIRTY_BONEMATRIX0 << i;
|
*uniformMask |= DIRTY_BONEMATRIX0 << i;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if (doTexture) {
|
if (doTexture) {
|
||||||
WRITE(p, "uniform vec4 u_uvscaleoffset;\n");
|
WRITE(p, "uniform vec4 u_uvscaleoffset;\n");
|
||||||
@ -415,7 +410,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
if (doBezier || doSpline) {
|
if (doBezier || doSpline) {
|
||||||
*uniformMask |= DIRTY_BEZIERSPLINE;
|
*uniformMask |= DIRTY_BEZIERSPLINE;
|
||||||
|
|
||||||
if (compat.vulkan) {
|
if (compat.shaderLanguage == GLSL_VULKAN) {
|
||||||
WRITE(p, "struct TessData {\n");
|
WRITE(p, "struct TessData {\n");
|
||||||
WRITE(p, " vec4 pos;\n");
|
WRITE(p, " vec4 pos;\n");
|
||||||
WRITE(p, " vec4 uv;\n");
|
WRITE(p, " vec4 uv;\n");
|
||||||
@ -615,14 +610,14 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
|
|
||||||
// Uncomment this to screw up bone shaders to check the vertex shader software fallback
|
// Uncomment this to screw up bone shaders to check the vertex shader software fallback
|
||||||
// WRITE(p, "THIS SHOULD ERROR! #error");
|
// WRITE(p, "THIS SHOULD ERROR! #error");
|
||||||
if (numBoneWeights == 1 && !compat.vulkan)
|
if (numBoneWeights == 1 && compat.shaderLanguage != GLSL_VULKAN)
|
||||||
WRITE(p, " %s skinMatrix = w1 * u_bone0", boneMatrix);
|
WRITE(p, " %s skinMatrix = w1 * u_bone0", boneMatrix);
|
||||||
else
|
else
|
||||||
WRITE(p, " %s skinMatrix = w1.x * u_bone0", boneMatrix);
|
WRITE(p, " %s skinMatrix = w1.x * u_bone0", boneMatrix);
|
||||||
for (int i = 1; i < numBoneWeights; i++) {
|
for (int i = 1; i < numBoneWeights; i++) {
|
||||||
const char *weightAttr = boneWeightAttr[i];
|
const char *weightAttr = boneWeightAttr[i];
|
||||||
// workaround for "cant do .x of scalar" issue
|
// workaround for "cant do .x of scalar" issue
|
||||||
if (!compat.vulkan) {
|
if (compat.shaderLanguage != GLSL_VULKAN) {
|
||||||
if (numBoneWeights == 1 && i == 0) weightAttr = "w1";
|
if (numBoneWeights == 1 && i == 0) weightAttr = "w1";
|
||||||
if (numBoneWeights == 5 && i == 4) weightAttr = "w2";
|
if (numBoneWeights == 5 && i == 4) weightAttr = "w2";
|
||||||
}
|
}
|
||||||
@ -895,7 +890,7 @@ bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShade
|
|||||||
WRITE(p, " }\n");
|
WRITE(p, " }\n");
|
||||||
}
|
}
|
||||||
WRITE(p, " gl_Position = outPos;\n");
|
WRITE(p, " gl_Position = outPos;\n");
|
||||||
if (compat.vulkan) {
|
if (compat.shaderLanguage == GLSL_VULKAN) {
|
||||||
WRITE(p, " gl_PointSize = 1.0;\n");
|
WRITE(p, " gl_PointSize = 1.0;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,4 +21,4 @@
|
|||||||
|
|
||||||
struct VShaderID;
|
struct VShaderID;
|
||||||
|
|
||||||
bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const GLSLShaderCompat &compat, uint32_t *attrMask, uint64_t *uniformMask, std::string *errorString);
|
bool GenerateVertexShaderGLSL(const VShaderID &id, char *buffer, const ShaderLanguageDesc &compat, uint32_t *attrMask, uint64_t *uniformMask, std::string *errorString);
|
||||||
|
@ -340,6 +340,7 @@
|
|||||||
<ClInclude Include="..\ext\xbrz\xbrz.h" />
|
<ClInclude Include="..\ext\xbrz\xbrz.h" />
|
||||||
<ClInclude Include="Common\DepalettizeShaderCommon.h" />
|
<ClInclude Include="Common\DepalettizeShaderCommon.h" />
|
||||||
<ClInclude Include="Common\DrawEngineCommon.h" />
|
<ClInclude Include="Common\DrawEngineCommon.h" />
|
||||||
|
<ClInclude Include="Common\FragmentShaderGenerator.h" />
|
||||||
<ClInclude Include="Common\FramebufferManagerCommon.h" />
|
<ClInclude Include="Common\FramebufferManagerCommon.h" />
|
||||||
<ClInclude Include="Common\GPUDebugInterface.h" />
|
<ClInclude Include="Common\GPUDebugInterface.h" />
|
||||||
<ClInclude Include="Common\GPUStateUtils.h" />
|
<ClInclude Include="Common\GPUStateUtils.h" />
|
||||||
@ -385,7 +386,6 @@
|
|||||||
<ClInclude Include="Directx9\DepalettizeShaderDX9.h" />
|
<ClInclude Include="Directx9\DepalettizeShaderDX9.h" />
|
||||||
<ClInclude Include="Directx9\FramebufferManagerDX9.h" />
|
<ClInclude Include="Directx9\FramebufferManagerDX9.h" />
|
||||||
<ClInclude Include="Directx9\GPU_DX9.h" />
|
<ClInclude Include="Directx9\GPU_DX9.h" />
|
||||||
<ClInclude Include="Directx9\FragmentShaderGeneratorHLSL.h" />
|
|
||||||
<ClInclude Include="Directx9\ShaderManagerDX9.h" />
|
<ClInclude Include="Directx9\ShaderManagerDX9.h" />
|
||||||
<ClInclude Include="Directx9\TextureCacheDX9.h" />
|
<ClInclude Include="Directx9\TextureCacheDX9.h" />
|
||||||
<ClInclude Include="Directx9\TextureScalerDX9.h" />
|
<ClInclude Include="Directx9\TextureScalerDX9.h" />
|
||||||
@ -399,12 +399,6 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="GLES\FragmentShaderGeneratorGLES.h">
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="GLES\FragmentTestCacheGLES.h">
|
<ClInclude Include="GLES\FragmentTestCacheGLES.h">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||||
@ -489,6 +483,7 @@
|
|||||||
<ClCompile Include="..\ext\xbrz\xbrz.cpp" />
|
<ClCompile Include="..\ext\xbrz\xbrz.cpp" />
|
||||||
<ClCompile Include="Common\DepalettizeShaderCommon.cpp" />
|
<ClCompile Include="Common\DepalettizeShaderCommon.cpp" />
|
||||||
<ClCompile Include="Common\DrawEngineCommon.cpp" />
|
<ClCompile Include="Common\DrawEngineCommon.cpp" />
|
||||||
|
<ClCompile Include="Common\FragmentShaderGenerator.cpp" />
|
||||||
<ClCompile Include="Common\FramebufferManagerCommon.cpp" />
|
<ClCompile Include="Common\FramebufferManagerCommon.cpp" />
|
||||||
<ClCompile Include="Common\GPUDebugInterface.cpp" />
|
<ClCompile Include="Common\GPUDebugInterface.cpp" />
|
||||||
<ClCompile Include="Common\GPUStateUtils.cpp" />
|
<ClCompile Include="Common\GPUStateUtils.cpp" />
|
||||||
@ -560,7 +555,6 @@
|
|||||||
<ClCompile Include="Directx9\DepalettizeShaderDX9.cpp" />
|
<ClCompile Include="Directx9\DepalettizeShaderDX9.cpp" />
|
||||||
<ClCompile Include="Directx9\FramebufferManagerDX9.cpp" />
|
<ClCompile Include="Directx9\FramebufferManagerDX9.cpp" />
|
||||||
<ClCompile Include="Directx9\GPU_DX9.cpp" />
|
<ClCompile Include="Directx9\GPU_DX9.cpp" />
|
||||||
<ClCompile Include="Directx9\FragmentShaderGeneratorHLSL.cpp" />
|
|
||||||
<ClCompile Include="Directx9\ShaderManagerDX9.cpp" />
|
<ClCompile Include="Directx9\ShaderManagerDX9.cpp" />
|
||||||
<ClCompile Include="Directx9\StateMappingDX9.cpp" />
|
<ClCompile Include="Directx9\StateMappingDX9.cpp" />
|
||||||
<ClCompile Include="Directx9\StencilBufferDX9.cpp" />
|
<ClCompile Include="Directx9\StencilBufferDX9.cpp" />
|
||||||
@ -582,12 +576,6 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="GLES\FragmentShaderGeneratorGLES.cpp">
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="GLES\FragmentTestCacheGLES.cpp">
|
<ClCompile Include="GLES\FragmentTestCacheGLES.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</ExcludedFromBuild>
|
||||||
|
@ -186,9 +186,6 @@
|
|||||||
<ClInclude Include="GLES\TextureScalerGLES.h">
|
<ClInclude Include="GLES\TextureScalerGLES.h">
|
||||||
<Filter>GLES</Filter>
|
<Filter>GLES</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="GLES\FragmentShaderGeneratorGLES.h">
|
|
||||||
<Filter>GLES</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="GLES\DepalettizeShaderGLES.h">
|
<ClInclude Include="GLES\DepalettizeShaderGLES.h">
|
||||||
<Filter>GLES</Filter>
|
<Filter>GLES</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -273,8 +270,8 @@
|
|||||||
<ClInclude Include="Directx9\VertexShaderGeneratorHLSL.h">
|
<ClInclude Include="Directx9\VertexShaderGeneratorHLSL.h">
|
||||||
<Filter>DirectX9</Filter>
|
<Filter>DirectX9</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Directx9\FragmentShaderGeneratorHLSL.h">
|
<ClInclude Include="Common\FragmentShaderGenerator.h">
|
||||||
<Filter>DirectX9</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -446,9 +443,6 @@
|
|||||||
<ClCompile Include="GLES\StencilBufferGLES.cpp">
|
<ClCompile Include="GLES\StencilBufferGLES.cpp">
|
||||||
<Filter>GLES</Filter>
|
<Filter>GLES</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="GLES\FragmentShaderGeneratorGLES.cpp">
|
|
||||||
<Filter>GLES</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="GLES\DepalettizeShaderGLES.cpp">
|
<ClCompile Include="GLES\DepalettizeShaderGLES.cpp">
|
||||||
<Filter>GLES</Filter>
|
<Filter>GLES</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -548,8 +542,8 @@
|
|||||||
<ClCompile Include="Directx9\VertexShaderGeneratorHLSL.cpp">
|
<ClCompile Include="Directx9\VertexShaderGeneratorHLSL.cpp">
|
||||||
<Filter>DirectX9</Filter>
|
<Filter>DirectX9</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Directx9\FragmentShaderGeneratorHLSL.cpp">
|
<ClCompile Include="Common\FragmentShaderGenerator.cpp">
|
||||||
<Filter>DirectX9</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -76,7 +76,7 @@ SoftGPU::SoftGPU(GraphicsContext *gfxCtx, Draw::DrawContext *draw)
|
|||||||
break;
|
break;
|
||||||
case GPUBackend::DIRECT3D9:
|
case GPUBackend::DIRECT3D9:
|
||||||
ShaderTranslationInit();
|
ShaderTranslationInit();
|
||||||
presentation_->SetLanguage(HLSL_DX9);
|
presentation_->SetLanguage(HLSL_D3D9);
|
||||||
break;
|
break;
|
||||||
case GPUBackend::DIRECT3D11:
|
case GPUBackend::DIRECT3D11:
|
||||||
ShaderTranslationInit();
|
ShaderTranslationInit();
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
#include "GPU/Vulkan/ShaderManagerVulkan.h"
|
#include "GPU/Vulkan/ShaderManagerVulkan.h"
|
||||||
#include "GPU/Vulkan/DrawEngineVulkan.h"
|
#include "GPU/Vulkan/DrawEngineVulkan.h"
|
||||||
#include "GPU/Vulkan/FramebufferManagerVulkan.h"
|
#include "GPU/Vulkan/FramebufferManagerVulkan.h"
|
||||||
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
#include "GPU/GLES/VertexShaderGeneratorGLES.h"
|
#include "GPU/GLES/VertexShaderGeneratorGLES.h"
|
||||||
|
|
||||||
VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id, const char *code)
|
VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id, const char *code)
|
||||||
@ -53,7 +53,7 @@ VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id,
|
|||||||
OutputDebugStringA(LineNumberString(code).c_str());
|
OutputDebugStringA(LineNumberString(code).c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool success = GLSLtoSPV(VK_SHADER_STAGE_FRAGMENT_BIT, code, spirv, &errorMessage);
|
bool success = GLSLtoSPV(VK_SHADER_STAGE_FRAGMENT_BIT, code, GLSLVariant::VULKAN, spirv, &errorMessage);
|
||||||
if (!errorMessage.empty()) {
|
if (!errorMessage.empty()) {
|
||||||
if (success) {
|
if (success) {
|
||||||
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
||||||
@ -109,7 +109,7 @@ VulkanVertexShader::VulkanVertexShader(VulkanContext *vulkan, VShaderID id, cons
|
|||||||
#ifdef SHADERLOG
|
#ifdef SHADERLOG
|
||||||
OutputDebugStringA(LineNumberString(code).c_str());
|
OutputDebugStringA(LineNumberString(code).c_str());
|
||||||
#endif
|
#endif
|
||||||
bool success = GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, code, spirv, &errorMessage);
|
bool success = GLSLtoSPV(VK_SHADER_STAGE_VERTEX_BIT, code, GLSLVariant::VULKAN, spirv, &errorMessage);
|
||||||
if (!errorMessage.empty()) {
|
if (!errorMessage.empty()) {
|
||||||
if (success) {
|
if (success) {
|
||||||
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
||||||
@ -158,7 +158,7 @@ std::string VulkanVertexShader::GetShaderString(DebugShaderStringType type) cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShaderManagerVulkan::ShaderManagerVulkan(Draw::DrawContext *draw, VulkanContext *vulkan)
|
ShaderManagerVulkan::ShaderManagerVulkan(Draw::DrawContext *draw, VulkanContext *vulkan)
|
||||||
: ShaderManagerCommon(draw), vulkan_(vulkan), lastVShader_(nullptr), lastFShader_(nullptr), fsCache_(16), vsCache_(16) {
|
: ShaderManagerCommon(draw), vulkan_(vulkan), compat_(GLSL_VULKAN), fsCache_(16), vsCache_(16) {
|
||||||
codeBuffer_ = new char[16384];
|
codeBuffer_ = new char[16384];
|
||||||
uboAlignment_ = vulkan_->GetPhysicalDeviceProperties().properties.limits.minUniformBufferOffsetAlignment;
|
uboAlignment_ = vulkan_->GetPhysicalDeviceProperties().properties.limits.minUniformBufferOffsetAlignment;
|
||||||
memset(&ub_base, 0, sizeof(ub_base));
|
memset(&ub_base, 0, sizeof(ub_base));
|
||||||
@ -168,8 +168,6 @@ ShaderManagerVulkan::ShaderManagerVulkan(Draw::DrawContext *draw, VulkanContext
|
|||||||
static_assert(sizeof(ub_base) <= 512, "ub_base grew too big");
|
static_assert(sizeof(ub_base) <= 512, "ub_base grew too big");
|
||||||
static_assert(sizeof(ub_lights) <= 512, "ub_lights grew too big");
|
static_assert(sizeof(ub_lights) <= 512, "ub_lights grew too big");
|
||||||
static_assert(sizeof(ub_bones) <= 384, "ub_bones grew too big");
|
static_assert(sizeof(ub_bones) <= 384, "ub_bones grew too big");
|
||||||
|
|
||||||
compat_.SetupForVulkan();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderManagerVulkan::~ShaderManagerVulkan() {
|
ShaderManagerVulkan::~ShaderManagerVulkan() {
|
||||||
@ -280,7 +278,7 @@ void ShaderManagerVulkan::GetShaders(int prim, u32 vertType, VulkanVertexShader
|
|||||||
// Fragment shader not in cache. Let's compile it.
|
// Fragment shader not in cache. Let's compile it.
|
||||||
std::string genErrorString;
|
std::string genErrorString;
|
||||||
uint64_t uniformMask = 0; // Not used
|
uint64_t uniformMask = 0; // Not used
|
||||||
bool success = GenerateFragmentShaderGLSL(FSID, codeBuffer_, compat_, &uniformMask, &genErrorString);
|
bool success = GenerateFragmentShader(FSID, codeBuffer_, compat_, &uniformMask, &genErrorString);
|
||||||
_assert_(success);
|
_assert_(success);
|
||||||
fs = new VulkanFragmentShader(vulkan_, FSID, codeBuffer_);
|
fs = new VulkanFragmentShader(vulkan_, FSID, codeBuffer_);
|
||||||
fsCache_.Insert(FSID, fs);
|
fsCache_.Insert(FSID, fs);
|
||||||
@ -390,8 +388,6 @@ bool ShaderManagerVulkan::LoadCache(FILE *f) {
|
|||||||
if (header.featureFlags != gstate_c.featureFlags)
|
if (header.featureFlags != gstate_c.featureFlags)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
GLSLShaderCompat compat{};
|
|
||||||
compat.SetupForVulkan();
|
|
||||||
for (int i = 0; i < header.numVertexShaders; i++) {
|
for (int i = 0; i < header.numVertexShaders; i++) {
|
||||||
VShaderID id;
|
VShaderID id;
|
||||||
if (fread(&id, sizeof(id), 1, f) != 1) {
|
if (fread(&id, sizeof(id), 1, f) != 1) {
|
||||||
@ -402,7 +398,7 @@ bool ShaderManagerVulkan::LoadCache(FILE *f) {
|
|||||||
std::string genErrorString;
|
std::string genErrorString;
|
||||||
uint32_t attributeMask = 0;
|
uint32_t attributeMask = 0;
|
||||||
uint64_t uniformMask = 0;
|
uint64_t uniformMask = 0;
|
||||||
if (!GenerateVertexShaderGLSL(id, codeBuffer_, compat, &attributeMask, &uniformMask, &genErrorString)) {
|
if (!GenerateVertexShaderGLSL(id, codeBuffer_, compat_, &attributeMask, &uniformMask, &genErrorString)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
VulkanVertexShader *vs = new VulkanVertexShader(vulkan_, id, codeBuffer_, useHWTransform);
|
VulkanVertexShader *vs = new VulkanVertexShader(vulkan_, id, codeBuffer_, useHWTransform);
|
||||||
@ -418,7 +414,7 @@ bool ShaderManagerVulkan::LoadCache(FILE *f) {
|
|||||||
}
|
}
|
||||||
std::string genErrorString;
|
std::string genErrorString;
|
||||||
uint64_t uniformMask = 0;
|
uint64_t uniformMask = 0;
|
||||||
if (!GenerateFragmentShaderGLSL(id, codeBuffer_, compat, &uniformMask, &genErrorString)) {
|
if (!GenerateFragmentShader(id, codeBuffer_, compat_, &uniformMask, &genErrorString)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
VulkanFragmentShader *fs = new VulkanFragmentShader(vulkan_, id, codeBuffer_);
|
VulkanFragmentShader *fs = new VulkanFragmentShader(vulkan_, id, codeBuffer_);
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "GPU/Common/ShaderCommon.h"
|
#include "GPU/Common/ShaderCommon.h"
|
||||||
#include "GPU/Common/ShaderId.h"
|
#include "GPU/Common/ShaderId.h"
|
||||||
#include "GPU/GLES/VertexShaderGeneratorGLES.h"
|
#include "GPU/GLES/VertexShaderGeneratorGLES.h"
|
||||||
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
#include "GPU/Vulkan/VulkanUtil.h"
|
#include "GPU/Vulkan/VulkanUtil.h"
|
||||||
#include "Common/Math/lin/matrix4x4.h"
|
#include "Common/Math/lin/matrix4x4.h"
|
||||||
#include "GPU/Common/ShaderUniforms.h"
|
#include "GPU/Common/ShaderUniforms.h"
|
||||||
@ -131,7 +131,7 @@ private:
|
|||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
VulkanContext *vulkan_;
|
VulkanContext *vulkan_;
|
||||||
GLSLShaderCompat compat_{};
|
ShaderLanguageDesc compat_;
|
||||||
|
|
||||||
typedef DenseHashMap<FShaderID, VulkanFragmentShader *, nullptr> FSCache;
|
typedef DenseHashMap<FShaderID, VulkanFragmentShader *, nullptr> FSCache;
|
||||||
FSCache fsCache_;
|
FSCache fsCache_;
|
||||||
@ -147,8 +147,8 @@ private:
|
|||||||
UB_VS_Lights ub_lights;
|
UB_VS_Lights ub_lights;
|
||||||
UB_VS_Bones ub_bones;
|
UB_VS_Bones ub_bones;
|
||||||
|
|
||||||
VulkanFragmentShader *lastFShader_;
|
VulkanFragmentShader *lastFShader_ = nullptr;
|
||||||
VulkanVertexShader *lastVShader_;
|
VulkanVertexShader *lastVShader_ = nullptr;
|
||||||
|
|
||||||
FShaderID lastFSID_;
|
FShaderID lastFSID_;
|
||||||
VShaderID lastVSID_;
|
VShaderID lastVSID_;
|
||||||
|
@ -368,7 +368,7 @@ VkPipeline Vulkan2D::GetPipeline(VkRenderPass rp, VkShaderModule vs, VkShaderMod
|
|||||||
|
|
||||||
VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, std::string *error) {
|
VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, std::string *error) {
|
||||||
std::vector<uint32_t> spirv;
|
std::vector<uint32_t> spirv;
|
||||||
bool success = GLSLtoSPV(stage, code, spirv, error);
|
bool success = GLSLtoSPV(stage, code, GLSLVariant::VULKAN, spirv, error);
|
||||||
if (!error->empty()) {
|
if (!error->empty()) {
|
||||||
if (success) {
|
if (success) {
|
||||||
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
ERROR_LOG(G3D, "Warnings in shader compilation!");
|
||||||
|
@ -381,6 +381,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\GPU\Common\DepalettizeShaderCommon.h" />
|
<ClInclude Include="..\..\GPU\Common\DepalettizeShaderCommon.h" />
|
||||||
<ClInclude Include="..\..\GPU\Common\DrawEngineCommon.h" />
|
<ClInclude Include="..\..\GPU\Common\DrawEngineCommon.h" />
|
||||||
|
<ClInclude Include="..\..\GPU\Common\FragmentShaderGenerator.h" />
|
||||||
<ClInclude Include="..\..\GPU\Common\FramebufferManagerCommon.h" />
|
<ClInclude Include="..\..\GPU\Common\FramebufferManagerCommon.h" />
|
||||||
<ClInclude Include="..\..\GPU\Common\PresentationCommon.h" />
|
<ClInclude Include="..\..\GPU\Common\PresentationCommon.h" />
|
||||||
<ClInclude Include="..\..\GPU\Common\GPUDebugInterface.h" />
|
<ClInclude Include="..\..\GPU\Common\GPUDebugInterface.h" />
|
||||||
@ -416,7 +417,6 @@
|
|||||||
<ClInclude Include="..\..\GPU\Debugger\Record.h" />
|
<ClInclude Include="..\..\GPU\Debugger\Record.h" />
|
||||||
<ClInclude Include="..\..\GPU\Debugger\RecordFormat.h" />
|
<ClInclude Include="..\..\GPU\Debugger\RecordFormat.h" />
|
||||||
<ClInclude Include="..\..\GPU\Debugger\Stepping.h" />
|
<ClInclude Include="..\..\GPU\Debugger\Stepping.h" />
|
||||||
<ClInclude Include="..\..\GPU\Directx9\FragmentShaderGeneratorHLSL.h" />
|
|
||||||
<ClInclude Include="..\..\GPU\Directx9\VertexShaderGeneratorHLSL.h" />
|
<ClInclude Include="..\..\GPU\Directx9\VertexShaderGeneratorHLSL.h" />
|
||||||
<ClInclude Include="..\..\GPU\GeDisasm.h" />
|
<ClInclude Include="..\..\GPU\GeDisasm.h" />
|
||||||
<ClInclude Include="..\..\GPU\ge_constants.h" />
|
<ClInclude Include="..\..\GPU\ge_constants.h" />
|
||||||
@ -438,6 +438,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\GPU\Common\DepalettizeShaderCommon.cpp" />
|
<ClCompile Include="..\..\GPU\Common\DepalettizeShaderCommon.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Common\DrawEngineCommon.cpp" />
|
<ClCompile Include="..\..\GPU\Common\DrawEngineCommon.cpp" />
|
||||||
|
<ClCompile Include="..\..\GPU\Common\FragmentShaderGenerator.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Common\FramebufferManagerCommon.cpp" />
|
<ClCompile Include="..\..\GPU\Common\FramebufferManagerCommon.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Common\PresentationCommon.cpp" />
|
<ClCompile Include="..\..\GPU\Common\PresentationCommon.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Common\GPUDebugInterface.cpp" />
|
<ClCompile Include="..\..\GPU\Common\GPUDebugInterface.cpp" />
|
||||||
@ -476,7 +477,6 @@
|
|||||||
<ClCompile Include="..\..\GPU\Debugger\Playback.cpp" />
|
<ClCompile Include="..\..\GPU\Debugger\Playback.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Debugger\Record.cpp" />
|
<ClCompile Include="..\..\GPU\Debugger\Record.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Debugger\Stepping.cpp" />
|
<ClCompile Include="..\..\GPU\Debugger\Stepping.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Directx9\FragmentShaderGeneratorHLSL.cpp" />
|
|
||||||
<ClCompile Include="..\..\GPU\Directx9\VertexShaderGeneratorHLSL.cpp" />
|
<ClCompile Include="..\..\GPU\Directx9\VertexShaderGeneratorHLSL.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\GeConstants.cpp" />
|
<ClCompile Include="..\..\GPU\GeConstants.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\GeDisasm.cpp" />
|
<ClCompile Include="..\..\GPU\GeDisasm.cpp" />
|
||||||
@ -523,4 +523,4 @@
|
|||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
@ -41,7 +41,6 @@
|
|||||||
<ClCompile Include="..\..\GPU\Debugger\Playback.cpp" />
|
<ClCompile Include="..\..\GPU\Debugger\Playback.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Debugger\Record.cpp" />
|
<ClCompile Include="..\..\GPU\Debugger\Record.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Debugger\Stepping.cpp" />
|
<ClCompile Include="..\..\GPU\Debugger\Stepping.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Directx9\FragmentShaderGeneratorHLSL.cpp" />
|
|
||||||
<ClCompile Include="..\..\GPU\Directx9\VertexShaderGeneratorHLSL.cpp" />
|
<ClCompile Include="..\..\GPU\Directx9\VertexShaderGeneratorHLSL.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\GeConstants.cpp" />
|
<ClCompile Include="..\..\GPU\GeConstants.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\GeDisasm.cpp" />
|
<ClCompile Include="..\..\GPU\GeDisasm.cpp" />
|
||||||
@ -57,6 +56,7 @@
|
|||||||
<ClCompile Include="..\..\GPU\Software\TransformUnit.cpp" />
|
<ClCompile Include="..\..\GPU\Software\TransformUnit.cpp" />
|
||||||
<ClCompile Include="pch.cpp" />
|
<ClCompile Include="pch.cpp" />
|
||||||
<ClCompile Include="..\..\GPU\Software\RasterizerRectangle.cpp" />
|
<ClCompile Include="..\..\GPU\Software\RasterizerRectangle.cpp" />
|
||||||
|
<ClCompile Include="..\..\GPU\Common\FragmentShaderGenerator.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\GPU\Common\DepalettizeShaderCommon.h" />
|
<ClInclude Include="..\..\GPU\Common\DepalettizeShaderCommon.h" />
|
||||||
@ -96,7 +96,6 @@
|
|||||||
<ClInclude Include="..\..\GPU\Debugger\Record.h" />
|
<ClInclude Include="..\..\GPU\Debugger\Record.h" />
|
||||||
<ClInclude Include="..\..\GPU\Debugger\RecordFormat.h" />
|
<ClInclude Include="..\..\GPU\Debugger\RecordFormat.h" />
|
||||||
<ClInclude Include="..\..\GPU\Debugger\Stepping.h" />
|
<ClInclude Include="..\..\GPU\Debugger\Stepping.h" />
|
||||||
<ClInclude Include="..\..\GPU\Directx9\FragmentShaderGeneratorHLSL.h" />
|
|
||||||
<ClInclude Include="..\..\GPU\Directx9\VertexShaderGeneratorHLSL.h" />
|
<ClInclude Include="..\..\GPU\Directx9\VertexShaderGeneratorHLSL.h" />
|
||||||
<ClInclude Include="..\..\GPU\GeDisasm.h" />
|
<ClInclude Include="..\..\GPU\GeDisasm.h" />
|
||||||
<ClInclude Include="..\..\GPU\ge_constants.h" />
|
<ClInclude Include="..\..\GPU\ge_constants.h" />
|
||||||
@ -114,5 +113,6 @@
|
|||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
<ClInclude Include="targetver.h" />
|
<ClInclude Include="targetver.h" />
|
||||||
<ClInclude Include="..\..\GPU\Software\RasterizerRectangle.h" />
|
<ClInclude Include="..\..\GPU\Software\RasterizerRectangle.h" />
|
||||||
|
<ClInclude Include="..\..\GPU\Common\FragmentShaderGenerator.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -306,6 +306,7 @@ EXEC_AND_LIB_FILES := \
|
|||||||
$(SRC)/GPU/GeConstants.cpp \
|
$(SRC)/GPU/GeConstants.cpp \
|
||||||
$(SRC)/GPU/GeDisasm.cpp \
|
$(SRC)/GPU/GeDisasm.cpp \
|
||||||
$(SRC)/GPU/Common/DepalettizeShaderCommon.cpp \
|
$(SRC)/GPU/Common/DepalettizeShaderCommon.cpp \
|
||||||
|
$(SRC)/GPU/Common/FragmentShaderGenerator.cpp \
|
||||||
$(SRC)/GPU/Common/FramebufferManagerCommon.cpp \
|
$(SRC)/GPU/Common/FramebufferManagerCommon.cpp \
|
||||||
$(SRC)/GPU/Common/PresentationCommon.cpp \
|
$(SRC)/GPU/Common/PresentationCommon.cpp \
|
||||||
$(SRC)/GPU/Common/GPUDebugInterface.cpp \
|
$(SRC)/GPU/Common/GPUDebugInterface.cpp \
|
||||||
@ -340,7 +341,6 @@ EXEC_AND_LIB_FILES := \
|
|||||||
$(SRC)/GPU/GLES/StateMappingGLES.cpp.arm \
|
$(SRC)/GPU/GLES/StateMappingGLES.cpp.arm \
|
||||||
$(SRC)/GPU/GLES/ShaderManagerGLES.cpp.arm \
|
$(SRC)/GPU/GLES/ShaderManagerGLES.cpp.arm \
|
||||||
$(SRC)/GPU/GLES/VertexShaderGeneratorGLES.cpp.arm \
|
$(SRC)/GPU/GLES/VertexShaderGeneratorGLES.cpp.arm \
|
||||||
$(SRC)/GPU/GLES/FragmentShaderGeneratorGLES.cpp.arm \
|
|
||||||
$(SRC)/GPU/GLES/FragmentTestCacheGLES.cpp.arm \
|
$(SRC)/GPU/GLES/FragmentTestCacheGLES.cpp.arm \
|
||||||
$(SRC)/GPU/GLES/TextureScalerGLES.cpp \
|
$(SRC)/GPU/GLES/TextureScalerGLES.cpp \
|
||||||
$(SRC)/GPU/Null/NullGpu.cpp \
|
$(SRC)/GPU/Null/NullGpu.cpp \
|
||||||
|
@ -248,6 +248,7 @@ SOURCES_CXX += \
|
|||||||
$(GPUDIR)/Debugger/Playback.cpp \
|
$(GPUDIR)/Debugger/Playback.cpp \
|
||||||
$(GPUDIR)/Debugger/Record.cpp \
|
$(GPUDIR)/Debugger/Record.cpp \
|
||||||
$(GPUDIR)/Debugger/Stepping.cpp \
|
$(GPUDIR)/Debugger/Stepping.cpp \
|
||||||
|
$(GPUDIR)/Common/FragmentShaderGenerator.cpp \
|
||||||
$(GPUDIR)/Common/TextureCacheCommon.cpp \
|
$(GPUDIR)/Common/TextureCacheCommon.cpp \
|
||||||
$(GPUDIR)/Common/TextureScalerCommon.cpp \
|
$(GPUDIR)/Common/TextureScalerCommon.cpp \
|
||||||
$(GPUDIR)/Common/SoftwareTransformCommon.cpp \
|
$(GPUDIR)/Common/SoftwareTransformCommon.cpp \
|
||||||
@ -271,7 +272,6 @@ SOURCES_CXX += \
|
|||||||
$(GPUDIR)/GLES/VertexShaderGeneratorGLES.cpp \
|
$(GPUDIR)/GLES/VertexShaderGeneratorGLES.cpp \
|
||||||
$(GPUDIR)/GLES/DrawEngineGLES.cpp \
|
$(GPUDIR)/GLES/DrawEngineGLES.cpp \
|
||||||
$(GPUDIR)/GLES/GPU_GLES.cpp \
|
$(GPUDIR)/GLES/GPU_GLES.cpp \
|
||||||
$(GPUDIR)/GLES/FragmentShaderGeneratorGLES.cpp \
|
|
||||||
$(GPUDIR)/GLES/FragmentTestCacheGLES.cpp \
|
$(GPUDIR)/GLES/FragmentTestCacheGLES.cpp \
|
||||||
$(GPUDIR)/GLES/FramebufferManagerGLES.cpp \
|
$(GPUDIR)/GLES/FramebufferManagerGLES.cpp \
|
||||||
$(GPUDIR)/GLES/TextureCacheGLES.cpp \
|
$(GPUDIR)/GLES/TextureCacheGLES.cpp \
|
||||||
@ -661,7 +661,6 @@ ifeq ($(PLATFORM_EXT), win32)
|
|||||||
SOURCES_CXX += \
|
SOURCES_CXX += \
|
||||||
$(GPUDIR)/Directx9/DepalettizeShaderDX9.cpp \
|
$(GPUDIR)/Directx9/DepalettizeShaderDX9.cpp \
|
||||||
$(GPUDIR)/Directx9/DrawEngineDX9.cpp \
|
$(GPUDIR)/Directx9/DrawEngineDX9.cpp \
|
||||||
$(GPUDIR)/Directx9/FragmentShaderGeneratorHLSL.cpp \
|
|
||||||
$(GPUDIR)/Directx9/FramebufferManagerDX9.cpp \
|
$(GPUDIR)/Directx9/FramebufferManagerDX9.cpp \
|
||||||
$(GPUDIR)/Directx9/GPU_DX9.cpp \
|
$(GPUDIR)/Directx9/GPU_DX9.cpp \
|
||||||
$(GPUDIR)/Directx9/ShaderManagerDX9.cpp \
|
$(GPUDIR)/Directx9/ShaderManagerDX9.cpp \
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
#include "GPU/Common/ShaderId.h"
|
#include "GPU/Common/ShaderId.h"
|
||||||
#include "GPU/Common/ShaderCommon.h"
|
#include "GPU/Common/ShaderCommon.h"
|
||||||
|
#include "GPU/Common/GPUStateUtils.h"
|
||||||
#include "Common/Data/Random/Rng.h"
|
#include "Common/Data/Random/Rng.h"
|
||||||
|
|
||||||
#include "GPU/Vulkan/VulkanContext.h"
|
#include "GPU/Vulkan/VulkanContext.h"
|
||||||
|
|
||||||
#include "GPU/Directx9/FragmentShaderGeneratorHLSL.h"
|
#include "GPU/Common/FragmentShaderGenerator.h"
|
||||||
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
|
||||||
|
|
||||||
#include "GPU/Directx9/VertexShaderGeneratorHLSL.h"
|
#include "GPU/Directx9/VertexShaderGeneratorHLSL.h"
|
||||||
#include "GPU/GLES/VertexShaderGeneratorGLES.h"
|
#include "GPU/GLES/VertexShaderGeneratorGLES.h"
|
||||||
@ -20,76 +20,98 @@
|
|||||||
#include "GPU/D3D9/D3DCompilerLoader.h"
|
#include "GPU/D3D9/D3DCompilerLoader.h"
|
||||||
#include "GPU/D3D9/D3D9ShaderCompiler.h"
|
#include "GPU/D3D9/D3D9ShaderCompiler.h"
|
||||||
|
|
||||||
|
|
||||||
bool GenerateFShader(FShaderID id, char *buffer, ShaderLanguage lang, std::string *errorString) {
|
bool GenerateFShader(FShaderID id, char *buffer, ShaderLanguage lang, std::string *errorString) {
|
||||||
|
uint64_t uniformMask;
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
case ShaderLanguage::HLSL_D3D11:
|
|
||||||
return GenerateFragmentShaderHLSL(id, buffer, ShaderLanguage::HLSL_D3D11, errorString);
|
|
||||||
case ShaderLanguage::HLSL_DX9:
|
|
||||||
GenerateFragmentShaderHLSL(id, buffer, ShaderLanguage::HLSL_DX9, errorString);
|
|
||||||
// TODO: Need a device :( Returning false here so it doesn't get tried.
|
|
||||||
return false;
|
|
||||||
case ShaderLanguage::GLSL_VULKAN:
|
case ShaderLanguage::GLSL_VULKAN:
|
||||||
{
|
{
|
||||||
GLSLShaderCompat compat{};
|
ShaderLanguageDesc compat(ShaderLanguage::GLSL_VULKAN);
|
||||||
compat.SetupForVulkan();
|
return GenerateFragmentShader(id, buffer, compat, &uniformMask, errorString);
|
||||||
uint64_t uniformMask;
|
|
||||||
return GenerateFragmentShaderGLSL(id, buffer, compat, &uniformMask, errorString);
|
|
||||||
}
|
}
|
||||||
case ShaderLanguage::GLSL_140:
|
case ShaderLanguage::GLSL_140:
|
||||||
|
{
|
||||||
|
ShaderLanguageDesc compat(ShaderLanguage::GLSL_140);
|
||||||
|
return GenerateFragmentShader(id, buffer, compat, &uniformMask, errorString);
|
||||||
|
}
|
||||||
case ShaderLanguage::GLSL_300:
|
case ShaderLanguage::GLSL_300:
|
||||||
// TODO: Need a device - except that maybe glslang could be used to verify these ....
|
{
|
||||||
return false;
|
ShaderLanguageDesc compat(ShaderLanguage::GLSL_140);
|
||||||
|
return GenerateFragmentShader(id, buffer, compat, &uniformMask, errorString);
|
||||||
|
}
|
||||||
|
case ShaderLanguage::HLSL_D3D9:
|
||||||
|
{
|
||||||
|
ShaderLanguageDesc compat(ShaderLanguage::HLSL_D3D9);
|
||||||
|
return GenerateFragmentShader(id, buffer, compat, &uniformMask, errorString);
|
||||||
|
}
|
||||||
|
case ShaderLanguage::HLSL_D3D11:
|
||||||
|
{
|
||||||
|
ShaderLanguageDesc compat(ShaderLanguage::HLSL_D3D11);
|
||||||
|
return GenerateFragmentShader(id, buffer, compat, &uniformMask, errorString);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GenerateVShader(VShaderID id, char *buffer, ShaderLanguage lang, std::string *errorString) {
|
bool GenerateVShader(VShaderID id, char *buffer, ShaderLanguage lang, std::string *errorString) {
|
||||||
|
uint32_t attrMask;
|
||||||
|
uint64_t uniformMask;
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
case ShaderLanguage::HLSL_D3D11:
|
|
||||||
return GenerateVertexShaderHLSL(id, buffer, ShaderLanguage::HLSL_D3D11, errorString);
|
|
||||||
case ShaderLanguage::HLSL_DX9:
|
|
||||||
GenerateVertexShaderHLSL(id, buffer, ShaderLanguage::HLSL_DX9, errorString);
|
|
||||||
// TODO: Need a device :( Returning false here so it doesn't get tried.
|
|
||||||
return false;
|
|
||||||
// return DX9::GenerateFragmentShaderHLSL(id, buffer, ShaderLanguage::HLSL_DX9);
|
|
||||||
case ShaderLanguage::GLSL_VULKAN:
|
case ShaderLanguage::GLSL_VULKAN:
|
||||||
{
|
{
|
||||||
GLSLShaderCompat compat{};
|
ShaderLanguageDesc compat(ShaderLanguage::GLSL_VULKAN);
|
||||||
compat.SetupForVulkan();
|
|
||||||
uint32_t attrMask;
|
|
||||||
uint64_t uniformMask;
|
|
||||||
return GenerateVertexShaderGLSL(id, buffer, compat, &attrMask, &uniformMask, errorString);
|
return GenerateVertexShaderGLSL(id, buffer, compat, &attrMask, &uniformMask, errorString);
|
||||||
}
|
}
|
||||||
|
case ShaderLanguage::GLSL_140:
|
||||||
|
{
|
||||||
|
ShaderLanguageDesc compat(ShaderLanguage::GLSL_140);
|
||||||
|
return GenerateVertexShaderGLSL(id, buffer, compat, &attrMask, &uniformMask, errorString);
|
||||||
|
}
|
||||||
|
case ShaderLanguage::GLSL_300:
|
||||||
|
{
|
||||||
|
ShaderLanguageDesc compat(ShaderLanguage::GLSL_140);
|
||||||
|
return GenerateVertexShaderGLSL(id, buffer, compat, &attrMask, &uniformMask, errorString);
|
||||||
|
}
|
||||||
|
case ShaderLanguage::HLSL_D3D9:
|
||||||
|
{
|
||||||
|
//ShaderLanguageDesc compat(ShaderLanguage::HLSL_D3D9);
|
||||||
|
return GenerateVertexShaderHLSL(id, buffer, ShaderLanguage::HLSL_D3D9, errorString);
|
||||||
|
}
|
||||||
|
case ShaderLanguage::HLSL_D3D11:
|
||||||
|
{
|
||||||
|
//ShaderLanguageDesc compat(ShaderLanguage::HLSL_D3D11);
|
||||||
|
return GenerateVertexShaderHLSL(id, buffer, ShaderLanguage::HLSL_D3D11, errorString);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TestCompileShader(const char *buffer, ShaderLanguage lang, bool vertex) {
|
bool TestCompileShader(const char *buffer, ShaderLanguage lang, bool vertex, std::string *errorMessage) {
|
||||||
|
std::vector<uint32_t> spirv;
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
case ShaderLanguage::HLSL_D3D11:
|
case ShaderLanguage::HLSL_D3D11:
|
||||||
{
|
{
|
||||||
auto output = CompileShaderToBytecodeD3D11(buffer, strlen(buffer), vertex ? "vs_4_0" : "ps_4_0", 0);
|
auto output = CompileShaderToBytecodeD3D11(buffer, strlen(buffer), vertex ? "vs_4_0" : "ps_4_0", 0);
|
||||||
return !output.empty();
|
return !output.empty();
|
||||||
}
|
}
|
||||||
case ShaderLanguage::HLSL_DX9:
|
case ShaderLanguage::HLSL_D3D9:
|
||||||
return false;
|
|
||||||
case ShaderLanguage::GLSL_VULKAN:
|
|
||||||
{
|
{
|
||||||
std::vector<uint32_t> spirv;
|
LPD3DBLOB blob = CompileShaderToByteCodeD3D9(buffer, vertex ? "vs_2_0" : "ps_2_0", errorMessage);
|
||||||
std::string errorMessage;
|
if (blob) {
|
||||||
bool result = GLSLtoSPV(vertex ? VK_SHADER_STAGE_VERTEX_BIT : VK_SHADER_STAGE_FRAGMENT_BIT, buffer, spirv, &errorMessage);
|
blob->Release();
|
||||||
if (!result) {
|
return true;
|
||||||
printf("GLSLtoSPV ERROR:\n%s\n\n", errorMessage.c_str());
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ShaderLanguage::GLSL_VULKAN:
|
||||||
|
return GLSLtoSPV(vertex ? VK_SHADER_STAGE_VERTEX_BIT : VK_SHADER_STAGE_FRAGMENT_BIT, buffer, GLSLVariant::VULKAN, spirv, errorMessage);
|
||||||
case ShaderLanguage::GLSL_140:
|
case ShaderLanguage::GLSL_140:
|
||||||
return false;
|
return GLSLtoSPV(vertex ? VK_SHADER_STAGE_VERTEX_BIT : VK_SHADER_STAGE_FRAGMENT_BIT, buffer, GLSLVariant::GL140, spirv, errorMessage);
|
||||||
case ShaderLanguage::GLSL_300:
|
case ShaderLanguage::GLSL_300:
|
||||||
return false;
|
return GLSLtoSPV(vertex ? VK_SHADER_STAGE_VERTEX_BIT : VK_SHADER_STAGE_FRAGMENT_BIT, buffer, GLSLVariant::GLES300, spirv, errorMessage);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -111,7 +133,7 @@ void PrintDiff(const char *a, const char *b) {
|
|||||||
printf("a: %s\n", a_lines[i].c_str());
|
printf("a: %s\n", a_lines[i].c_str());
|
||||||
printf("b: %s\n", b_lines[i].c_str());
|
printf("b: %s\n", b_lines[i].c_str());
|
||||||
printf("...continues...\n");
|
printf("...continues...\n");
|
||||||
for (size_t j = i + 1; j < i + 5 && j < a_lines.size(); j++) {
|
for (size_t j = i + 1; j < i + 5 && j < a_lines.size() && j < b_lines.size(); j++) {
|
||||||
printf("a: %s\n", a_lines[j].c_str());
|
printf("a: %s\n", a_lines[j].c_str());
|
||||||
printf("b: %s\n", b_lines[j].c_str());
|
printf("b: %s\n", b_lines[j].c_str());
|
||||||
}
|
}
|
||||||
@ -128,11 +150,11 @@ bool TestShaderGenerators() {
|
|||||||
LoadD3DCompilerDynamic();
|
LoadD3DCompilerDynamic();
|
||||||
|
|
||||||
ShaderLanguage languages[] = {
|
ShaderLanguage languages[] = {
|
||||||
ShaderLanguage::GLSL_VULKAN,
|
ShaderLanguage::HLSL_D3D9,
|
||||||
ShaderLanguage::HLSL_D3D11,
|
ShaderLanguage::HLSL_D3D11,
|
||||||
|
ShaderLanguage::GLSL_VULKAN,
|
||||||
ShaderLanguage::GLSL_140,
|
ShaderLanguage::GLSL_140,
|
||||||
ShaderLanguage::GLSL_300,
|
ShaderLanguage::GLSL_300,
|
||||||
ShaderLanguage::HLSL_DX9,
|
|
||||||
};
|
};
|
||||||
const int numLanguages = ARRAY_SIZE(languages);
|
const int numLanguages = ARRAY_SIZE(languages);
|
||||||
|
|
||||||
@ -145,6 +167,72 @@ bool TestShaderGenerators() {
|
|||||||
int successes = 0;
|
int successes = 0;
|
||||||
int count = 700;
|
int count = 700;
|
||||||
|
|
||||||
|
// Generate a bunch of random fragment shader IDs, try to generate shader source.
|
||||||
|
// Then compile it and check that it's ok.
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
uint32_t bottom = rng.R32();
|
||||||
|
uint32_t top = rng.R32();
|
||||||
|
FShaderID id;
|
||||||
|
id.d[0] = bottom;
|
||||||
|
id.d[1] = top;
|
||||||
|
|
||||||
|
// bits we don't need to test because they are irrelevant on d3d11
|
||||||
|
id.SetBit(FS_BIT_NO_DEPTH_CANNOT_DISCARD_STENCIL, false);
|
||||||
|
id.SetBit(FS_BIT_SHADER_DEPAL, false);
|
||||||
|
|
||||||
|
// DX9 disabling:
|
||||||
|
if (static_cast<ReplaceAlphaType>(id.Bits(FS_BIT_STENCIL_TO_ALPHA, 2)) == ReplaceAlphaType::REPLACE_ALPHA_DUALSOURCE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool generateSuccess[numLanguages]{};
|
||||||
|
std::string genErrorString[numLanguages];
|
||||||
|
|
||||||
|
for (int j = 0; j < numLanguages; j++) {
|
||||||
|
generateSuccess[j] = GenerateFShader(id, buffer[j], languages[j], &genErrorString[j]);
|
||||||
|
if (!genErrorString[j].empty()) {
|
||||||
|
printf("%s\n", genErrorString[j].c_str());
|
||||||
|
}
|
||||||
|
// We ignore the contents of the error string here, not even gonna try to compile if it errors.
|
||||||
|
}
|
||||||
|
|
||||||
|
// KEEPING FOR REUSE LATER: Defunct temporary test.
|
||||||
|
/*
|
||||||
|
if (generateSuccess[0] != generateSuccess[1]) {
|
||||||
|
printf("mismatching success! %s %s\n", genErrorString[0].c_str(), genErrorString[1].c_str());
|
||||||
|
printf("%s\n", buffer[0]);
|
||||||
|
printf("%s\n", buffer[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (generateSuccess[0] && strcmp(buffer[0], buffer[1])) {
|
||||||
|
printf("mismatching shaders! a=glsl b=hlsl\n");
|
||||||
|
PrintDiff(buffer[0], buffer[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (generateSuccess[2] && strcmp(buffer[2], buffer[3])) {
|
||||||
|
printf("mismatching shaders! a=glsl b=hlsl\n");
|
||||||
|
PrintDiff(buffer[2], buffer[3]);
|
||||||
|
return 1;
|
||||||
|
}*/
|
||||||
|
// Now that we have the strings ready for easy comparison (buffer,4 in the watch window),
|
||||||
|
// let's try to compile them.
|
||||||
|
for (int j = 0; j < numLanguages; j++) {
|
||||||
|
if (generateSuccess[j]) {
|
||||||
|
std::string errorMessage;
|
||||||
|
if (!TestCompileShader(buffer[j], languages[j], false, &errorMessage)) {
|
||||||
|
printf("Error compiling fragment shader:\n\n%s\n\n%s\n", LineNumberString(buffer[j]).c_str(), errorMessage.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
successes++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%d/%d fragment shaders generated (it's normal that it's not all, there are invalid bit combos)\n", successes, count * numLanguages);
|
||||||
|
|
||||||
|
successes = 0;
|
||||||
|
count = 200;
|
||||||
|
|
||||||
|
/*
|
||||||
// Generate a bunch of random vertex shader IDs, try to generate shader source.
|
// Generate a bunch of random vertex shader IDs, try to generate shader source.
|
||||||
// Then compile it and check that it's ok.
|
// Then compile it and check that it's ok.
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
@ -163,7 +251,7 @@ bool TestShaderGenerators() {
|
|||||||
printf("%s\n", genErrorString[j].c_str());
|
printf("%s\n", genErrorString[j].c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
// KEEPING FOR REUSE LATER: Defunct temporary test: Compare GLSL-in-Vulkan-mode vs Vulkan
|
// KEEPING FOR REUSE LATER: Defunct temporary test: Compare GLSL-in-Vulkan-mode vs Vulkan
|
||||||
if (generateSuccess[0] != generateSuccess[1]) {
|
if (generateSuccess[0] != generateSuccess[1]) {
|
||||||
printf("mismatching success! '%s' '%s'\n", genErrorString[0].c_str(), genErrorString[1].c_str());
|
printf("mismatching success! '%s' '%s'\n", genErrorString[0].c_str(), genErrorString[1].c_str());
|
||||||
@ -172,18 +260,18 @@ bool TestShaderGenerators() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (generateSuccess[0] && strcmp(buffer[0], buffer[1])) {
|
if (generateSuccess[0] && strcmp(buffer[0], buffer[1])) {
|
||||||
printf("mismatching shaders! a=glsl b=vulkan\n");
|
printf("mismatching shaders!\n");
|
||||||
PrintDiff(buffer[0], buffer[1]);
|
PrintDiff(buffer[0], buffer[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Now that we have the strings ready for easy comparison (buffer,4 in the watch window),
|
// Now that we have the strings ready for easy comparison (buffer,4 in the watch window),
|
||||||
// let's try to compile them.
|
// let's try to compile them.
|
||||||
for (int j = 0; j < numLanguages; j++) {
|
for (int j = 0; j < numLanguages; j++) {
|
||||||
if (generateSuccess[j]) {
|
if (generateSuccess[j]) {
|
||||||
if (!TestCompileShader(buffer[j], languages[j], true)) {
|
std::string errorMessage;
|
||||||
printf("Error compiling vertex shader:\n\n%s\n\n", LineNumberString(buffer[j]).c_str());
|
if (!TestCompileShader(buffer[j], languages[j], true, &errorMessage)) {
|
||||||
|
printf("Error compiling vertex shader:\n\n%s\n\n%s\n", LineNumberString(buffer[j]).c_str(), errorMessage.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
successes++;
|
successes++;
|
||||||
@ -195,59 +283,9 @@ bool TestShaderGenerators() {
|
|||||||
|
|
||||||
successes = 0;
|
successes = 0;
|
||||||
count = 200;
|
count = 200;
|
||||||
|
*/
|
||||||
|
|
||||||
// Generate a bunch of random fragment shader IDs, try to generate shader source.
|
_CrtCheckMemory();
|
||||||
// Then compile it and check that it's ok.
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
uint32_t bottom = rng.R32();
|
|
||||||
uint32_t top = rng.R32();
|
|
||||||
FShaderID id;
|
|
||||||
id.d[0] = bottom;
|
|
||||||
id.d[1] = top;
|
|
||||||
|
|
||||||
bool generateSuccess[numLanguages]{};
|
|
||||||
std::string genErrorString[numLanguages];
|
|
||||||
|
|
||||||
for (int j = 0; j < numLanguages; j++) {
|
|
||||||
generateSuccess[j] = GenerateFShader(id, buffer[j], languages[j], &genErrorString[j]);
|
|
||||||
if (!genErrorString[j].empty()) {
|
|
||||||
printf("%s\n", genErrorString[j].c_str());
|
|
||||||
}
|
|
||||||
// We ignore the contents of the error string here, not even gonna try to compile if it errors.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// KEEPING FOR REUSE LATER: Defunct temporary test: Compare GLSL-in-Vulkan-mode vs Vulkan
|
|
||||||
if (generateSuccess[0] != generateSuccess[1]) {
|
|
||||||
printf("mismatching success! %s %s\n", genErrorString[0].c_str(), genErrorString[1].c_str());
|
|
||||||
printf("%s\n", buffer[0]);
|
|
||||||
printf("%s\n", buffer[1]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (generateSuccess[0] && strcmp(buffer[0], buffer[1])) {
|
|
||||||
printf("mismatching shaders!\n");
|
|
||||||
PrintDiff(buffer[0], buffer[1]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Now that we have the strings ready for easy comparison (buffer,4 in the watch window),
|
|
||||||
// let's try to compile them.
|
|
||||||
for (int j = 0; j < numLanguages; j++) {
|
|
||||||
if (generateSuccess[j]) {
|
|
||||||
if (!TestCompileShader(buffer[j], languages[j], false)) {
|
|
||||||
printf("Error compiling fragment shader:\n\n%s\n\n", LineNumberString(buffer[j]).c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
successes++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%d/%d fragment shaders generated (it's normal that it's not all, there are invalid bit combos)\n", successes, count * numLanguages);
|
|
||||||
|
|
||||||
successes = 0;
|
|
||||||
count = 200;
|
|
||||||
|
|
||||||
for (int i = 0; i < numLanguages; i++) {
|
for (int i = 0; i < numLanguages; i++) {
|
||||||
delete[] buffer[i];
|
delete[] buffer[i];
|
||||||
|
Loading…
Reference in New Issue
Block a user