Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: DekoCompiler: Add OutputDkshToMemory method to output shader to memory #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions source/compiler_iface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,45 @@ void DekoCompiler::OutputDksh(const char* dkshFile)
}
}

void DekoCompiler::OutputDkshToMemory(void *buffer, uint32_t *size)
{
uint32_t offset = 0;

DkshHeader hdr = {};
hdr.magic = DKSH_MAGIC;
hdr.header_sz = sizeof(DkshHeader);
hdr.control_sz = Align256(sizeof(DkshHeader) + sizeof(DkshProgramHeader));
hdr.code_sz = Align256((m_stage != pipeline_stage_compute ? 0x80 : 0x00) + m_codeSize) + Align256(m_dataSize);
hdr.programs_off = sizeof(DkshHeader);
hdr.num_programs = 1;

memcpy((char *)buffer + offset, &hdr, sizeof(hdr));
offset += sizeof(hdr);
memcpy((char *)buffer + offset, &m_dkph, sizeof(m_dkph));
offset = Align256(offset + sizeof(m_dkph));

if (m_stage != pipeline_stage_compute)
{
static const char s_padding[s_shaderStartOffset] = "lol nvidia why did you make us waste space here";
memcpy((char *)buffer + offset, s_padding, sizeof(s_padding));
offset += sizeof(s_padding);
memcpy((char *)buffer + offset, &m_nvsh, sizeof(m_nvsh));
offset += sizeof(m_nvsh);
}

memcpy((char *)buffer + offset, m_code, m_codeSize);
offset = Align256(offset + m_codeSize);

if (m_dataSize)
{
memcpy((char *)buffer + offset, m_data, m_dataSize);
offset = Align256(offset + m_dataSize);
}

if (size)
*size = offset;
}

void DekoCompiler::OutputRawCode(const char* rawFile)
{
FILE* f = fopen(rawFile, "wb");
Expand Down
1 change: 1 addition & 0 deletions source/compiler_iface.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DekoCompiler

bool CompileGlsl(const char* glsl);
void OutputDksh(const char* dkshFile);
void OutputDkshToMemory(void *buffer, uint32_t *size);
void OutputRawCode(const char* rawFile);
void OutputTgsi(const char* tgsiFile);
};