mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-19 05:52:11 +01:00
[d3d9] Use new flat shading state for DXSO shaders
This commit is contained in:
parent
dfdb729476
commit
8f1024c094
@ -2098,13 +2098,9 @@ namespace dxvk {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case D3DRS_SHADEMODE:
|
case D3DRS_SHADEMODE:
|
||||||
if (m_state.pixelShader != nullptr) {
|
m_flags.set(
|
||||||
BindShader<DxsoProgramType::PixelShader>(
|
D3D9DeviceFlag::DirtyFFPixelShader,
|
||||||
GetCommonShader(m_state.pixelShader),
|
D3D9DeviceFlag::DirtyRasterizerState);
|
||||||
GetPixelShaderPermutation());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_flags.set(D3D9DeviceFlag::DirtyFFPixelShader);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case D3DRS_TWEENFACTOR:
|
case D3DRS_TWEENFACTOR:
|
||||||
@ -2685,8 +2681,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
if (m_state.pixelShader != nullptr) {
|
if (m_state.pixelShader != nullptr) {
|
||||||
BindShader<DxsoProgramTypes::PixelShader>(
|
BindShader<DxsoProgramTypes::PixelShader>(
|
||||||
GetCommonShader(m_state.pixelShader),
|
GetCommonShader(m_state.pixelShader));
|
||||||
GetPixelShaderPermutation());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dst->GetMapMode() == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER) {
|
if (dst->GetMapMode() == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER) {
|
||||||
@ -2873,10 +2868,7 @@ namespace dxvk {
|
|||||||
m_flags.clr(D3D9DeviceFlag::DirtyProgVertexShader);
|
m_flags.clr(D3D9DeviceFlag::DirtyProgVertexShader);
|
||||||
m_flags.set(D3D9DeviceFlag::DirtyFFVertexShader);
|
m_flags.set(D3D9DeviceFlag::DirtyFFVertexShader);
|
||||||
|
|
||||||
BindShader<DxsoProgramTypes::VertexShader>(
|
BindShader<DxsoProgramTypes::VertexShader>(GetCommonShader(shader));
|
||||||
GetCommonShader(shader),
|
|
||||||
GetVertexShaderPermutation());
|
|
||||||
|
|
||||||
m_vsShaderMasks = newShader->GetShaderMask();
|
m_vsShaderMasks = newShader->GetShaderMask();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -3204,10 +3196,7 @@ namespace dxvk {
|
|||||||
if (shader != nullptr) {
|
if (shader != nullptr) {
|
||||||
m_flags.set(D3D9DeviceFlag::DirtyFFPixelShader);
|
m_flags.set(D3D9DeviceFlag::DirtyFFPixelShader);
|
||||||
|
|
||||||
BindShader<DxsoProgramTypes::PixelShader>(
|
BindShader<DxsoProgramTypes::PixelShader>(GetCommonShader(shader));
|
||||||
GetCommonShader(shader),
|
|
||||||
GetPixelShaderPermutation());
|
|
||||||
|
|
||||||
m_psShaderMasks = newShader->GetShaderMask();
|
m_psShaderMasks = newShader->GetShaderMask();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -5721,6 +5710,7 @@ namespace dxvk {
|
|||||||
state.depthClipEnable = true;
|
state.depthClipEnable = true;
|
||||||
state.frontFace = VK_FRONT_FACE_CLOCKWISE;
|
state.frontFace = VK_FRONT_FACE_CLOCKWISE;
|
||||||
state.polygonMode = DecodeFillMode(D3DFILLMODE(rs[D3DRS_FILLMODE]));
|
state.polygonMode = DecodeFillMode(D3DFILLMODE(rs[D3DRS_FILLMODE]));
|
||||||
|
state.flatShading = m_state.renderStates[D3DRS_SHADEMODE] == D3DSHADE_FLAT;
|
||||||
|
|
||||||
EmitCs([
|
EmitCs([
|
||||||
cState = state
|
cState = state
|
||||||
@ -6032,8 +6022,7 @@ namespace dxvk {
|
|||||||
m_flags.set(D3D9DeviceFlag::DirtyInputLayout);
|
m_flags.set(D3D9DeviceFlag::DirtyInputLayout);
|
||||||
|
|
||||||
BindShader<DxsoProgramType::VertexShader>(
|
BindShader<DxsoProgramType::VertexShader>(
|
||||||
GetCommonShader(m_state.vertexShader),
|
GetCommonShader(m_state.vertexShader));
|
||||||
GetVertexShaderPermutation());
|
|
||||||
}
|
}
|
||||||
UploadConstants<DxsoProgramTypes::VertexShader>();
|
UploadConstants<DxsoProgramTypes::VertexShader>();
|
||||||
|
|
||||||
@ -6123,10 +6112,9 @@ namespace dxvk {
|
|||||||
|
|
||||||
template <DxsoProgramType ShaderStage>
|
template <DxsoProgramType ShaderStage>
|
||||||
void D3D9DeviceEx::BindShader(
|
void D3D9DeviceEx::BindShader(
|
||||||
const D3D9CommonShader* pShaderModule,
|
const D3D9CommonShader* pShaderModule) {
|
||||||
D3D9ShaderPermutation Permutation) {
|
|
||||||
EmitCs([
|
EmitCs([
|
||||||
cShader = pShaderModule->GetShader(Permutation)
|
cShader = pShaderModule->GetShader()
|
||||||
] (DxvkContext* ctx) mutable {
|
] (DxvkContext* ctx) mutable {
|
||||||
constexpr VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
|
constexpr VkShaderStageFlagBits stage = GetShaderStage(ShaderStage);
|
||||||
ctx->bindShader<stage>(std::move(cShader));
|
ctx->bindShader<stage>(std::move(cShader));
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include "d3d9_swvp_emu.h"
|
#include "d3d9_swvp_emu.h"
|
||||||
|
|
||||||
#include "d3d9_spec_constants.h"
|
#include "d3d9_spec_constants.h"
|
||||||
#include "d3d9_shader_permutations.h"
|
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -871,8 +870,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
template <DxsoProgramType ShaderStage>
|
template <DxsoProgramType ShaderStage>
|
||||||
void BindShader(
|
void BindShader(
|
||||||
const D3D9CommonShader* pShaderModule,
|
const D3D9CommonShader* pShaderModule);
|
||||||
D3D9ShaderPermutation Permutation);
|
|
||||||
|
|
||||||
void BindInputLayout();
|
void BindInputLayout();
|
||||||
|
|
||||||
@ -973,17 +971,6 @@ namespace dxvk {
|
|||||||
return m_behaviorFlags & (D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
|
return m_behaviorFlags & (D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr D3D9ShaderPermutation GetVertexShaderPermutation() {
|
|
||||||
return D3D9ShaderPermutations::None;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline D3D9ShaderPermutation GetPixelShaderPermutation() {
|
|
||||||
if (unlikely(m_state.renderStates[D3DRS_SHADEMODE] == D3DSHADE_FLAT))
|
|
||||||
return D3D9ShaderPermutations::FlatShade;
|
|
||||||
|
|
||||||
return D3D9ShaderPermutations::None;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DetermineConstantLayouts(bool canSWVP);
|
void DetermineConstantLayouts(bool canSWVP);
|
||||||
|
|
||||||
D3D9BufferSlice AllocUPBuffer(VkDeviceSize size);
|
D3D9BufferSlice AllocUPBuffer(VkDeviceSize size);
|
||||||
|
@ -56,7 +56,7 @@ namespace dxvk {
|
|||||||
const D3D9ConstantLayout& constantLayout = ShaderStage == VK_SHADER_STAGE_VERTEX_BIT
|
const D3D9ConstantLayout& constantLayout = ShaderStage == VK_SHADER_STAGE_VERTEX_BIT
|
||||||
? pDevice->GetVertexConstantLayout()
|
? pDevice->GetVertexConstantLayout()
|
||||||
: pDevice->GetPixelConstantLayout();
|
: pDevice->GetPixelConstantLayout();
|
||||||
m_shaders = pModule->compile(*pDxsoModuleInfo, name, AnalysisInfo, constantLayout);
|
m_shader = pModule->compile(*pDxsoModuleInfo, name, AnalysisInfo, constantLayout);
|
||||||
m_isgn = pModule->isgn();
|
m_isgn = pModule->isgn();
|
||||||
m_usedSamplers = pModule->usedSamplers();
|
m_usedSamplers = pModule->usedSamplers();
|
||||||
|
|
||||||
@ -73,25 +73,17 @@ namespace dxvk {
|
|||||||
m_constants = pModule->constants();
|
m_constants = pModule->constants();
|
||||||
m_maxDefinedConst = pModule->maxDefinedConstant();
|
m_maxDefinedConst = pModule->maxDefinedConstant();
|
||||||
|
|
||||||
m_shaders[0]->setShaderKey(Key);
|
m_shader->setShaderKey(Key);
|
||||||
|
|
||||||
if (m_shaders[1] != nullptr) {
|
|
||||||
// Lets lie about the shader key type for the state cache.
|
|
||||||
m_shaders[1]->setShaderKey({ VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, Key.sha1() });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dumpPath.size() != 0) {
|
if (dumpPath.size() != 0) {
|
||||||
std::ofstream dumpStream(
|
std::ofstream dumpStream(
|
||||||
str::tows(str::format(dumpPath, "/", name, ".spv").c_str()).c_str(),
|
str::tows(str::format(dumpPath, "/", name, ".spv").c_str()).c_str(),
|
||||||
std::ios_base::binary | std::ios_base::trunc);
|
std::ios_base::binary | std::ios_base::trunc);
|
||||||
|
|
||||||
m_shaders[0]->dump(dumpStream);
|
m_shader->dump(dumpStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
pDevice->GetDXVKDevice()->registerShader(m_shaders[0]);
|
pDevice->GetDXVKDevice()->registerShader(m_shader);
|
||||||
|
|
||||||
if (m_shaders[1] != nullptr && m_shaders[1] != m_shaders[0])
|
|
||||||
pDevice->GetDXVKDevice()->registerShader(m_shaders[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "d3d9_resource.h"
|
#include "d3d9_resource.h"
|
||||||
#include "../dxso/dxso_module.h"
|
#include "../dxso/dxso_module.h"
|
||||||
#include "d3d9_shader_permutations.h"
|
|
||||||
#include "d3d9_util.h"
|
#include "d3d9_util.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
@ -33,12 +32,12 @@ namespace dxvk {
|
|||||||
DxsoModule* pModule);
|
DxsoModule* pModule);
|
||||||
|
|
||||||
|
|
||||||
Rc<DxvkShader> GetShader(D3D9ShaderPermutation Permutation) const {
|
Rc<DxvkShader> GetShader() const {
|
||||||
return m_shaders[Permutation];
|
return m_shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetName() const {
|
std::string GetName() const {
|
||||||
return m_shaders[D3D9ShaderPermutations::None]->debugName();
|
return m_shader->debugName();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<uint8_t>& GetBytecode() const {
|
const std::vector<uint8_t>& GetBytecode() const {
|
||||||
@ -69,7 +68,7 @@ namespace dxvk {
|
|||||||
DxsoDefinedConstants m_constants;
|
DxsoDefinedConstants m_constants;
|
||||||
uint32_t m_maxDefinedConst;
|
uint32_t m_maxDefinedConst;
|
||||||
|
|
||||||
DxsoPermutations m_shaders;
|
Rc<DxvkShader> m_shader;
|
||||||
|
|
||||||
std::vector<uint8_t> m_bytecode;
|
std::vector<uint8_t> m_bytecode;
|
||||||
|
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "d3d9_include.h"
|
|
||||||
|
|
||||||
namespace dxvk {
|
|
||||||
|
|
||||||
class DxvkShader;
|
|
||||||
|
|
||||||
namespace D3D9ShaderPermutations {
|
|
||||||
enum D3D9ShaderPermutation {
|
|
||||||
None,
|
|
||||||
FlatShade,
|
|
||||||
Count
|
|
||||||
};
|
|
||||||
}
|
|
||||||
using D3D9ShaderPermutation = D3D9ShaderPermutations::D3D9ShaderPermutation;
|
|
||||||
|
|
||||||
using DxsoPermutations = std::array<Rc<DxvkShader>, D3D9ShaderPermutations::Count>;
|
|
||||||
|
|
||||||
}
|
|
@ -219,32 +219,7 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DxsoPermutations DxsoCompiler::compile() {
|
Rc<DxvkShader> DxsoCompiler::compile() {
|
||||||
DxsoPermutations permutations = { };
|
|
||||||
|
|
||||||
// Create the shader module object
|
|
||||||
permutations[D3D9ShaderPermutations::None] = compileShader();
|
|
||||||
|
|
||||||
// If we need to add more permuations, might be worth making a copy of module
|
|
||||||
// before we do anything more. :-)
|
|
||||||
if (m_programInfo.type() == DxsoProgramType::PixelShader) {
|
|
||||||
if (m_ps.diffuseColorIn)
|
|
||||||
m_module.decorate(m_ps.diffuseColorIn, spv::DecorationFlat);
|
|
||||||
|
|
||||||
if (m_ps.specularColorIn)
|
|
||||||
m_module.decorate(m_ps.specularColorIn, spv::DecorationFlat);
|
|
||||||
|
|
||||||
if (m_ps.diffuseColorIn || m_ps.specularColorIn)
|
|
||||||
permutations[D3D9ShaderPermutations::FlatShade] = compileShader();
|
|
||||||
else
|
|
||||||
permutations[D3D9ShaderPermutations::FlatShade] = permutations[D3D9ShaderPermutations::None];
|
|
||||||
}
|
|
||||||
|
|
||||||
return permutations;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Rc<DxvkShader> DxsoCompiler::compileShader() {
|
|
||||||
DxvkShaderCreateInfo info;
|
DxvkShaderCreateInfo info;
|
||||||
info.stage = m_programInfo.shaderStage();
|
info.stage = m_programInfo.shaderStage();
|
||||||
info.bindingCount = m_bindings.size();
|
info.bindingCount = m_bindings.size();
|
||||||
@ -254,6 +229,9 @@ namespace dxvk {
|
|||||||
info.pushConstOffset = m_pushConstOffset;
|
info.pushConstOffset = m_pushConstOffset;
|
||||||
info.pushConstSize = m_pushConstSize;
|
info.pushConstSize = m_pushConstSize;
|
||||||
|
|
||||||
|
if (m_programInfo.type() == DxsoProgramTypes::PixelShader)
|
||||||
|
info.flatShadingInputs = m_ps.flatShadingMask;
|
||||||
|
|
||||||
return new DxvkShader(info, m_module.compile());
|
return new DxvkShader(info, m_module.compile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3396,10 +3374,8 @@ void DxsoCompiler::emitControlFlowGenericLoop(
|
|||||||
workingReg.id = m_module.opSelect(getVectorTypeId(workingReg.type), pointInfo.isSprite, pointCoord, workingReg.id);
|
workingReg.id = m_module.opSelect(getVectorTypeId(workingReg.type), pointInfo.isSprite, pointCoord, workingReg.id);
|
||||||
|
|
||||||
if (m_programInfo.type() == DxsoProgramType::PixelShader && elem.semantic.usage == DxsoUsage::Color) {
|
if (m_programInfo.type() == DxsoProgramType::PixelShader && elem.semantic.usage == DxsoUsage::Color) {
|
||||||
if (elem.semantic.usageIndex == 0)
|
if (elem.semantic.usageIndex < 2)
|
||||||
m_ps.diffuseColorIn = inputPtr.id;
|
m_ps.flatShadingMask |= 1u << slot;
|
||||||
else if (elem.semantic.usageIndex == 1)
|
|
||||||
m_ps.specularColorIn = inputPtr.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_module.opStore(indexPtr.id, workingReg.id);
|
m_module.opStore(indexPtr.id, workingReg.id);
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "dxso_util.h"
|
#include "dxso_util.h"
|
||||||
|
|
||||||
#include "../d3d9/d3d9_constant_layout.h"
|
#include "../d3d9/d3d9_constant_layout.h"
|
||||||
#include "../d3d9/d3d9_shader_permutations.h"
|
|
||||||
#include "../d3d9/d3d9_spec_constants.h"
|
#include "../d3d9/d3d9_spec_constants.h"
|
||||||
#include "../spirv/spirv_module.h"
|
#include "../spirv/spirv_module.h"
|
||||||
|
|
||||||
@ -177,8 +176,7 @@ namespace dxvk {
|
|||||||
uint32_t killState = 0;
|
uint32_t killState = 0;
|
||||||
uint32_t builtinLaneId = 0;
|
uint32_t builtinLaneId = 0;
|
||||||
|
|
||||||
uint32_t diffuseColorIn = 0;
|
uint32_t flatShadingMask = 0;
|
||||||
uint32_t specularColorIn = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DxsoCfgBlockIf {
|
struct DxsoCfgBlockIf {
|
||||||
@ -243,7 +241,7 @@ namespace dxvk {
|
|||||||
* \brief Compiles the shader
|
* \brief Compiles the shader
|
||||||
* \returns The final shader objects
|
* \returns The final shader objects
|
||||||
*/
|
*/
|
||||||
DxsoPermutations compile();
|
Rc<DxvkShader> compile();
|
||||||
|
|
||||||
const DxsoIsgn& isgn() { return m_isgn; }
|
const DxsoIsgn& isgn() { return m_isgn; }
|
||||||
const DxsoIsgn& osgn() { return m_osgn; }
|
const DxsoIsgn& osgn() { return m_osgn; }
|
||||||
@ -626,8 +624,6 @@ namespace dxvk {
|
|||||||
return this->emitRegisterLoad(lookup, writeMask);
|
return this->emitRegisterLoad(lookup, writeMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rc<DxvkShader> compileShader();
|
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
// Handle shader ops
|
// Handle shader ops
|
||||||
void emitDcl(const DxsoInstructionContext& ctx);
|
void emitDcl(const DxsoInstructionContext& ctx);
|
||||||
|
@ -21,7 +21,7 @@ namespace dxvk {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
DxsoPermutations DxsoModule::compile(
|
Rc<DxvkShader> DxsoModule::compile(
|
||||||
const DxsoModuleInfo& moduleInfo,
|
const DxsoModuleInfo& moduleInfo,
|
||||||
const std::string& fileName,
|
const std::string& fileName,
|
||||||
const DxsoAnalysisInfo& analysis,
|
const DxsoAnalysisInfo& analysis,
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "dxso_analysis.h"
|
#include "dxso_analysis.h"
|
||||||
|
|
||||||
#include "../d3d9/d3d9_constant_layout.h"
|
#include "../d3d9/d3d9_constant_layout.h"
|
||||||
#include "../d3d9/d3d9_shader_permutations.h"
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ namespace dxvk {
|
|||||||
* the compiled SPIR-V for debugging purposes.
|
* the compiled SPIR-V for debugging purposes.
|
||||||
* \returns The compiled shader object
|
* \returns The compiled shader object
|
||||||
*/
|
*/
|
||||||
DxsoPermutations compile(
|
Rc<DxvkShader> compile(
|
||||||
const DxsoModuleInfo& moduleInfo,
|
const DxsoModuleInfo& moduleInfo,
|
||||||
const std::string& fileName,
|
const std::string& fileName,
|
||||||
const DxsoAnalysisInfo& analysis,
|
const DxsoAnalysisInfo& analysis,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user