mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-28 16:53:40 +01:00
Implement 3D textures for D3D11
This commit is contained in:
1 parent
e455d6bcfe
commit
0262fbc70a
5 files changed
+74
-26
No files matched your search
@@ -210,7 +210,11 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
|
||||
}
|
||||
} else {
|
||||
WRITE(p, "SamplerState samp : register(s0);\n");
|
||||
WRITE(p, "Texture2D<vec4> tex : register(t0);\n");
|
||||
if (texture3D) {
|
||||
WRITE(p, "Texture3D<vec4> tex : register(t0);\n");
|
||||
} else {
|
||||
WRITE(p, "Texture2D<vec4> tex : register(t0);\n");
|
||||
}
|
||||
if (readFramebufferTex) {
|
||||
// No sampler required, we Load
|
||||
WRITE(p, "Texture2D<vec4> fboTex : register(t1);\n");
|
||||
@@ -547,10 +551,18 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu
|
||||
|
||||
if (!shaderDepal) {
|
||||
if (compat.shaderLanguage == HLSL_D3D11) {
|
||||
if (doTextureProjection) {
|
||||
WRITE(p, " vec4 t = tex.Sample(samp, v_texcoord.xy / v_texcoord.z)%s;\n", bgraTexture ? ".bgra" : "");
|
||||
if (texture3D) {
|
||||
if (doTextureProjection) {
|
||||
WRITE(p, " vec4 t = tex.Sample(samp, vec3(v_texcoord.xy / v_texcoord.z, u_mipBias))%s;\n", bgraTexture ? ".bgra" : "");
|
||||
} else {
|
||||
WRITE(p, " vec4 t = tex.Sample(samp, vec3(%s.xy, u_mipBias))%s;\n", texcoord, bgraTexture ? ".bgra" : "");
|
||||
}
|
||||
} else {
|
||||
WRITE(p, " vec4 t = tex.Sample(samp, %s.xy)%s;\n", texcoord, bgraTexture ? ".bgra" : "");
|
||||
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) {
|
||||
|
||||
@@ -2177,10 +2177,6 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt
|
||||
entry->status &= ~TexCacheEntry::STATUS_NO_MIPS;
|
||||
}
|
||||
|
||||
if (plan.depth > 1) {
|
||||
entry->status |= TexCacheEntry::STATUS_3D;
|
||||
}
|
||||
|
||||
// Will be filled in again during decode.
|
||||
entry->status &= ~TexCacheEntry::STATUS_ALPHA_MASK;
|
||||
return true;
|
||||
|
||||
@@ -467,24 +467,46 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) {
|
||||
}
|
||||
|
||||
// We don't yet have mip generation, so clamp the number of levels to the ones we can load directly.
|
||||
int levels = std::min(plan.levelsToCreate, plan.levelsToLoad);
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc{};
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.ArraySize = 1;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Width = tw;
|
||||
desc.Height = th;
|
||||
desc.Format = dstFmt;
|
||||
desc.MipLevels = levels;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
int levels;;
|
||||
|
||||
ID3D11ShaderResourceView *view;
|
||||
ID3D11Texture2D *texture = DxTex(entry);
|
||||
ID3D11Resource *texture = DxTex(entry);
|
||||
_assert_(texture == nullptr);
|
||||
|
||||
ASSERT_SUCCESS(device_->CreateTexture2D(&desc, nullptr, &texture));
|
||||
if (plan.depth == 1) {
|
||||
ID3D11Texture2D *tex;
|
||||
D3D11_TEXTURE2D_DESC desc{};
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.ArraySize = 1;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Width = tw;
|
||||
desc.Height = th;
|
||||
desc.Format = dstFmt;
|
||||
desc.MipLevels = plan.levelsToCreate;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
|
||||
ASSERT_SUCCESS(device_->CreateTexture2D(&desc, nullptr, &tex));
|
||||
texture = tex;
|
||||
|
||||
levels = std::min(plan.levelsToCreate, plan.levelsToLoad);
|
||||
} else {
|
||||
ID3D11Texture3D *tex;
|
||||
D3D11_TEXTURE3D_DESC desc{};
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.Width = tw;
|
||||
desc.Height = th;
|
||||
desc.Depth = plan.depth;
|
||||
desc.Format = dstFmt;
|
||||
desc.MipLevels = 1;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
ASSERT_SUCCESS(device_->CreateTexture3D(&desc, nullptr, &tex));
|
||||
texture = tex;
|
||||
|
||||
levels = plan.depth;
|
||||
}
|
||||
|
||||
ASSERT_SUCCESS(device_->CreateShaderResourceView(texture, nullptr, &view));
|
||||
entry->texturePtr = texture;
|
||||
entry->textureView = view;
|
||||
@@ -525,11 +547,24 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) {
|
||||
|
||||
LoadTextureLevel(*entry, data, stride, *plan.replaced, srcLevel, plan.scaleFactor, texFmt, false);
|
||||
|
||||
ID3D11Texture2D *texture = DxTex(entry);
|
||||
context_->UpdateSubresource(texture, i, nullptr, data, stride, 0);
|
||||
if (plan.depth == 1) {
|
||||
context_->UpdateSubresource(texture, i, nullptr, data, stride, 0);
|
||||
} else {
|
||||
D3D11_BOX box{};
|
||||
box.front = i;
|
||||
box.back = i + 1;
|
||||
box.right = w * plan.scaleFactor;
|
||||
box.bottom = h * plan.scaleFactor;
|
||||
context_->UpdateSubresource(texture, 0, &box, data, stride, 0);
|
||||
}
|
||||
FreeAlignedMemory(data);
|
||||
}
|
||||
|
||||
// Signal that we support depth textures so use it as one.
|
||||
if (plan.depth > 1) {
|
||||
entry->status |= TexCacheEntry::STATUS_3D;
|
||||
}
|
||||
|
||||
if (levels == 1) {
|
||||
entry->status |= TexCacheEntry::STATUS_NO_MIPS;
|
||||
} else {
|
||||
|
||||
@@ -77,8 +77,8 @@ private:
|
||||
ID3D11Device *device_;
|
||||
ID3D11DeviceContext *context_;
|
||||
|
||||
ID3D11Texture2D *&DxTex(TexCacheEntry *entry) {
|
||||
return (ID3D11Texture2D *&)entry->texturePtr;
|
||||
ID3D11Resource *&DxTex(TexCacheEntry *entry) {
|
||||
return (ID3D11Resource *&)entry->texturePtr;
|
||||
}
|
||||
ID3D11ShaderResourceView *DxView(TexCacheEntry *entry) {
|
||||
return (ID3D11ShaderResourceView *)entry->textureView;
|
||||
|
||||
@@ -808,6 +808,11 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
|
||||
entry->vkTex->EndCreate(cmdInit, false, prevStage, layout);
|
||||
VK_PROFILE_END(vulkan, cmdInit, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT);
|
||||
|
||||
// Signal that we support depth textures so use it as one.
|
||||
if (plan.depth > 1) {
|
||||
entry->status |= TexCacheEntry::STATUS_3D;
|
||||
}
|
||||
|
||||
if (plan.replaced->Valid()) {
|
||||
entry->SetAlphaStatus(TexCacheEntry::TexStatus(plan.replaced->AlphaStatus()));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user